Salome HOME
Merge branch 'hydro/imps_2015' into V7_dev
[modules/geom.git] / src / RepairGUI / RepairGUI_ShapeProcessDlg.cxx
index 7933c155228f3e80d63a9613cdaeaf731bd3c97f..71d3ce0f2cfc476c1eb4772ca4a10b106dff07b8 100755 (executable)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2014  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2015  CEA/DEN, EDF R&D, OPEN CASCADE
 //
 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
 #include <SUIT_ResourceMgr.h>
 #include <SUIT_MessageBox.h>
 #include <SALOME_ListIO.hxx>
+#include "utilities.h"
 
 #include <Basics_Utils.hxx>
+#include "utilities.h"
 
 #include <TCollection_AsciiString.hxx>
 #include <TColStd_MapOfInteger.hxx>
@@ -97,6 +99,10 @@ void RepairGUI_ShapeProcessDlg::init()
   // layout the two group boxes in the middle, add a list of operations
   QGroupBox* anOperGr = new QGroupBox( tr( "GEOM_OPERATIONS" ), centralWidget() );
 
+  // "select all" button
+  mySelectAll = new QCheckBox( tr( "SELECT_ALL" ), anOperGr );
+  mySelectAll->setTristate( true );
+  
   // operations list widget
   myOpList = new QListWidget( anOperGr );
   myOpList->setSortingEnabled( false );
@@ -104,6 +110,7 @@ void RepairGUI_ShapeProcessDlg::init()
 
   QVBoxLayout* aOperLay = new QVBoxLayout( anOperGr );
   aOperLay->setMargin( 9 );
+  aOperLay->addWidget( mySelectAll );
   aOperLay->addWidget( myOpList );
 
   QGroupBox* aParamsGr = new QGroupBox( tr( "GEOM_PARAMETERS" ), centralWidget() );
@@ -162,10 +169,10 @@ void RepairGUI_ShapeProcessDlg::init()
       myDropSmallSolidsVolChk = new QCheckBox( tr("VOLUME_TOL"), w );
       myDropSmallSolidsWidTol = new SalomeApp_DoubleSpinBox( w );
       myDropSmallSolidsVolTol = new SalomeApp_DoubleSpinBox( w );
-      initSpinBox( myDropSmallSolidsWidTol, 0., 100., 1e-7, "len_tol_precision" );
-      initSpinBox( myDropSmallSolidsVolTol, 0., 100., 1e-7, "len_tol_precision" );
-      myDropSmallSolidsWidTol->setValue( 1e-7 );
-      myDropSmallSolidsVolTol->setValue( 1e-7 );
+      initSpinBox( myDropSmallSolidsWidTol, 0., 1e3, 1., "len_tol_precision" );
+      initSpinBox( myDropSmallSolidsVolTol, 0., 1e9, 1., "len_tol_precision" );
+      myDropSmallSolidsWidTol->setValue( 1 );
+      myDropSmallSolidsVolTol->setValue( 1e3 );
       myDropSmallSolidsVolChk->setChecked( true );
       myDropSmallSolidsWidTol->setEnabled( false );
       myDropSmallSolidsMergeChk = new QCheckBox( tr("TO_MERGE_SOLIDS"), w );
@@ -259,6 +266,7 @@ void RepairGUI_ShapeProcessDlg::init()
 
       myBSplineDegree = new SalomeApp_IntSpinBox( w );
       myBSplineSegments = new SalomeApp_IntSpinBox( w );
+      initSpinBox( myBSplineSegments, 1, 1000, 1);      
       myBSpline2DCont = new QComboBox( w );
       myBSpline2DCont->addItems( aContinueties );
       myBSpline3DCont = new QComboBox( w );
@@ -346,16 +354,18 @@ void RepairGUI_ShapeProcessDlg::init()
 
   connect( myOpList, SIGNAL( currentRowChanged( int )),      myStack, SLOT( setCurrentIndex( int )));
   connect( myOpList, SIGNAL( itemChanged( QListWidgetItem* )),  this, SLOT( operatorChecked( QListWidgetItem* )));
+  connect( mySelectAll, SIGNAL( stateChanged( int ) ), this, SLOT( onSelectAll( int )));
 
   adjustSize();
   loadDefaults(); // init dialog fields with values from resource file
   //myOpList->setCurrentRow( myOpList->findItem( 0 );
   reset();
 
-  myStack->setCurrentIndex( 0 );
+  myOpList->setCurrentRow(0);
 
   initName( tr( "PROCESS_SHAPE_NEW_OBJ_NAME" ));
   selectionChanged();
+  updateSelectAll();
 }
 
 //=================================================================================
@@ -563,14 +573,23 @@ void RepairGUI_ShapeProcessDlg::setValue( QWidget* theControl, const QString& th
 QString RepairGUI_ShapeProcessDlg::getValue( QWidget* theControl ) const
 {
   if ( theControl ) {
-    if ( qobject_cast<SalomeApp_DoubleSpinBox*>( theControl ))
+    if ( qobject_cast<SalomeApp_DoubleSpinBox*>( theControl )) {
+      if ( ( theControl == myDropSmallSolidsWidTol || theControl == myDropSmallSolidsVolTol ) && !theControl->isEnabled() ) {
+        // VSR: stupid workaround about ShapeProcessAPI:
+        // specific processing for optional parameters of DropSmallSolids operator
+        return QString::number( Precision::Infinite() );
+      }
       return QString::number( qobject_cast<SalomeApp_DoubleSpinBox*>( theControl )->value() );
-    else if ( qobject_cast<SalomeApp_IntSpinBox*>( theControl ))
+    }
+    else if ( qobject_cast<SalomeApp_IntSpinBox*>( theControl )) {
       return QString::number( qobject_cast<SalomeApp_IntSpinBox*>( theControl )->value() );
-    else if ( qobject_cast<QComboBox*>( theControl ))
+    }
+    else if ( qobject_cast<QComboBox*>( theControl )) {
       return qobject_cast<QComboBox*>( theControl )->currentText();
-    else if ( qobject_cast<QCheckBox*>( theControl ))
+    }
+    else if ( qobject_cast<QCheckBox*>( theControl )) {
       return qobject_cast<QCheckBox*>( theControl )->isChecked() ? "1" : "0";
+    }
   }   
   return 0;
 }
@@ -705,17 +724,14 @@ bool RepairGUI_ShapeProcessDlg::execute( ObjectList& objects )
 GEOM::string_array* RepairGUI_ShapeProcessDlg::getActiveOperators()
 {
   GEOM::string_array_var anOperators = new GEOM::string_array();
-  QStringList aCheckedList;
 
-  for ( int i = 0; i < myOpList->count(); i++ ) {
+  int j = 0, n = myOpList->count();
+  anOperators->length( n );
+  for ( int i = 0; i < n; i++ ) {
     if ( myOpList->item( i )->checkState() == Qt::Checked )
-      aCheckedList << myOpList->item( i )->text();
+      anOperators[j++] = myOpList->item( i )->text().toLatin1().constData();
   }
-
-  anOperators->length( aCheckedList.count() );
-
-  for ( int i = 0; i < aCheckedList.count(); i++ )
-    anOperators[i] = aCheckedList[i].toLatin1().constData();
+  anOperators->length( j );
 
   return anOperators._retn();
 }
@@ -732,7 +748,7 @@ QWidget* RepairGUI_ShapeProcessDlg::getControl( const QString& theParam )
   else if ( theParam == "FixFaceSize.Tolerance" )                 return myFixFaceSizeTol;
   else if ( theParam == "DropSmallEdges.Tolerance3d" )            return myDropSmallEdgesTol3D;
   else if ( theParam == "DropSmallSolids.WidthFactorThreshold" )  return myDropSmallSolidsWidTol;
-  else if ( theParam == "DropSmallSolids.VolumeThreshold" )       return myDropSmallSolidsWidTol;
+  else if ( theParam == "DropSmallSolids.VolumeThreshold" )       return myDropSmallSolidsVolTol;
   else if ( theParam == "DropSmallSolids.MergeSolids" )           return myDropSmallSolidsMergeChk;
   else if ( theParam == "BSplineRestriction.SurfaceMode" )        return myBSplineSurfModeChk;
   else if ( theParam == "BSplineRestriction.Curve3dMode" )        return myBSpline3DCurveChk;
@@ -824,18 +840,21 @@ GEOM::string_array* RepairGUI_ShapeProcessDlg::getParameters( const GEOM::string
 
   // calculate the length of parameters
   for ( i = 0, j = 0; i < theOperators.length(); i++ )
-    j += myValMap[ QString( theOperators[i] ) ].size();
+    j += myValMap[ QString( theOperators[i].in() ) ].size();
   
   // set the new length of paremeters
   aParams->length( j );
 
   // fill the parameters
   for ( i = 0, j = 0; i < theOperators.length(); i++ ) {
-    QStringList aValLst = myValMap[ QString( theOperators[i] ) ];
-    for ( QStringList::Iterator it = aValLst.begin(); it != aValLst.end(); ++it )
-      aParams[j++] = CORBA::string_dup( (*it).toLatin1().constData() );
+    QStringList aParamLst = myValMap[ QString( theOperators[i].in() ) ];
+    foreach ( QString aParam, aParamLst ) {
+      aParams[j++] = CORBA::string_dup( aParam.toLatin1().constData() );
+    }
   }
 
+  aParams->length( j );
+
   return aParams._retn();
 }
 
@@ -851,7 +870,7 @@ GEOM::string_array* RepairGUI_ShapeProcessDlg::getValues( const GEOM::string_arr
 
   for ( int i = 0; i < theParams.length(); i++ ) {
     QWidget* aCtrl = getControl( (const char*)theParams[i] );
-    if ( aCtrl && aCtrl->isEnabled() )
+    if ( aCtrl )
       aValues[i] = get_convert( (const char*)theParams[i], getValue( aCtrl ));
   }
 
@@ -940,6 +959,50 @@ void RepairGUI_ShapeProcessDlg::operatorChecked( QListWidgetItem * item )
 {
   if ( item && item->checkState() == Qt::Checked )
   {
+    item->setSelected(true);
     myStack->setCurrentIndex( myOpList->row( item ));
   }
+  updateSelectAll();
+}
+
+void RepairGUI_ShapeProcessDlg::updateSelectAll()
+{
+  Qt::CheckState state = myOpList->count() > 0 ? myOpList->item(0)->checkState() : Qt::Unchecked;
+  for ( int i = 1; i < myOpList->count(); i++ ) {
+    if ( myOpList->item(i)->checkState() != state ) {
+      state = Qt::PartiallyChecked;
+      break;
+    }
+  }
+  mySelectAll->blockSignals( true );
+  mySelectAll->setCheckState( state );
+  mySelectAll->blockSignals( false );
+}
+
+void RepairGUI_ShapeProcessDlg::onSelectAll( int state )
+{
+  if ( state == Qt::PartiallyChecked ) { 
+    mySelectAll->setCheckState( Qt::Checked );
+    return;
+  }
+  myOpList->blockSignals( true );
+  for ( int i = 0; i < myOpList->count(); i++ ) {
+    myOpList->item(i)->setCheckState( (Qt::CheckState)state  );
+  }
+  myOpList->blockSignals( false );
+}
+
+//=================================================================================
+// function : getSourceObjects
+// purpose  : virtual method to get source objects
+//=================================================================================
+QList<GEOM::GeomObjPtr> RepairGUI_ShapeProcessDlg::getSourceObjects()
+{
+  QList<GEOM::GeomObjPtr> res;
+  GEOM::ListOfGO aListPtr(myObjects);
+  for (int i = 0; i < aListPtr.length(); i++) {
+    GEOM::GeomObjPtr aGeomObjPtr(aListPtr[i]);
+    res << aGeomObjPtr;
+  }
+  return res;
 }