1 // Copyright (C) 2007-2014 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // GEOM GEOMGUI : GUI for Geometry component
24 // File : RepairGUI_ShapeProcessDlg.cxx
25 // Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
27 #include "RepairGUI_ShapeProcessDlg.h"
30 #include "GeometryGUI.h"
32 #include "GEOMImpl_Types.hxx"
33 #include "RepairGUI.h"
35 #include <SalomeApp_Application.h>
36 #include <SalomeApp_DoubleSpinBox.h>
37 #include <SalomeApp_IntSpinBox.h>
38 #include <LightApp_SelectionMgr.h>
39 #include <SUIT_Session.h>
40 #include <SUIT_ResourceMgr.h>
41 #include <SUIT_MessageBox.h>
42 #include <SALOME_ListIO.hxx>
44 #include <Basics_Utils.hxx>
45 #include "utilities.h"
47 #include <TCollection_AsciiString.hxx>
48 #include <TColStd_MapOfInteger.hxx>
50 #include <QListWidget>
51 #include <QStackedLayout>
53 //=================================================================================
54 // class : RepairGUI_ShapeProcessDlg()
55 // purpose : Constructs a RepairGUI_ShapeProcessDlg which is a child of 'parent', with the
56 // name 'name' and widget flags set to 'f'.
57 // The dialog will by default be modeless, unless you set 'modal' to
58 // TRUE to construct a modal dialog.
59 //=================================================================================
60 RepairGUI_ShapeProcessDlg::RepairGUI_ShapeProcessDlg( GeometryGUI* theGeometryGUI, QWidget* parent,
62 : GEOMBase_Skeleton( theGeometryGUI, parent, modal )
64 setHelpFileName( "shape_processing_operation_page.html" );
68 //=================================================================================
69 // function : ~RepairGUI_ShapeProcessDlg()
70 // purpose : Destroys the object and frees any allocated resources
71 //=================================================================================
72 RepairGUI_ShapeProcessDlg::~RepairGUI_ShapeProcessDlg()
76 //=================================================================================
79 //=================================================================================
80 void RepairGUI_ShapeProcessDlg::init()
82 //myGeomGUI->SetState( 0 );
87 setWindowTitle( tr( "GEOM_SHAPEPROCESS_TITLE" ));
89 mainFrame()->GroupConstructors->hide();
91 // select widget on the top
92 mySelectWdgt = new DlgRef_1Sel( centralWidget() );
93 mySelectWdgt->GroupBox1->setTitle( tr( "GEOM_SHAPE" ));
94 mySelectWdgt->TextLabel1->setText( tr( "GEOM_SELECTED_OBJECTS" ));
95 mySelectWdgt->PushButton1->setIcon( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_SELECT" )));
96 mySelectWdgt->LineEdit1->setReadOnly( true );
98 // layout the two group boxes in the middle, add a list of operations
99 QGroupBox* anOperGr = new QGroupBox( tr( "GEOM_OPERATIONS" ), centralWidget() );
101 // "select all" button
102 mySelectAll = new QCheckBox( tr( "SELECT_ALL" ), anOperGr );
103 mySelectAll->setTristate( true );
105 // operations list widget
106 myOpList = new QListWidget( anOperGr );
107 myOpList->setSortingEnabled( false );
108 myOpList->setSizePolicy( QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Expanding ));
110 QVBoxLayout* aOperLay = new QVBoxLayout( anOperGr );
111 aOperLay->setMargin( 9 );
112 aOperLay->addWidget( mySelectAll );
113 aOperLay->addWidget( myOpList );
115 QGroupBox* aParamsGr = new QGroupBox( tr( "GEOM_PARAMETERS" ), centralWidget() );
117 // add a widget stack to the parameters group box
118 myStack = new QStackedLayout( aParamsGr );
120 // continueties values..
121 QStringList aContinueties = QString( "C0,G1,C1,G2,C2,C3,CN" ).split( "," );
123 // fill in the widgets
124 for ( int i = 0; i < myOpLst.count(); i++ ) {
125 QListWidgetItem* item = new QListWidgetItem( myOpLst[i] );
126 item->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsUserCheckable );
127 item->setCheckState( Qt::Unchecked );
128 myOpList->addItem( item );
131 if ( myOpLst[i] == "FixShape" ) {
133 w = new QWidget( aParamsGr );
134 QGridLayout* aLay = new QGridLayout( w );
135 aLay->setMargin( 9 ); aLay->setSpacing( 6 );
137 myFixShapeTol3D = new SalomeApp_DoubleSpinBox( w );
138 initSpinBox( myFixShapeTol3D, 0., 100., 1e-7, "len_tol_precision" );
139 myFixShapeMaxTol3D = new SalomeApp_DoubleSpinBox( w );
140 initSpinBox( myFixShapeMaxTol3D, 0., 100., 1e-7, "len_tol_precision" );
142 aLay->addWidget( new QLabel( tr( "GEOM_3D_TOLERANCE" ), w ), 0, 0 );
143 aLay->addWidget( myFixShapeTol3D, 0, 1 );
144 aLay->addWidget( new QLabel( tr( "GEOM_MAX_3D_TOLERANCE" ), w ), 1, 0 );
145 aLay->addWidget( myFixShapeMaxTol3D, 1, 1 );
146 aLay->setRowStretch( aLay->rowCount(), 5 );
148 else if ( myOpLst[i] == "FixFaceSize" ) {
150 w = new QWidget( aParamsGr );
151 QGridLayout* aLay = new QGridLayout( w );
152 aLay->setMargin( 9 ); aLay->setSpacing( 6 );
154 myFixFaceSizeTol = new SalomeApp_DoubleSpinBox( w );
155 initSpinBox( myFixFaceSizeTol, 0., 100., 1e-7, "len_tol_precision" );
157 aLay->addWidget( new QLabel( tr( "GEOM_TOLERANCE" ), w ), 0, 0 );
158 aLay->addWidget( myFixFaceSizeTol, 0, 1 );
159 aLay->setRowStretch( aLay->rowCount(), 5 );
161 else if ( myOpLst[i] == "DropSmallSolids" ) {
163 w = new QWidget( aParamsGr );
164 QGridLayout* aLay = new QGridLayout( w );
165 aLay->setMargin( 9 ); aLay->setSpacing( 6 );
167 myDropSmallSolidsWidChk = new QCheckBox( tr("WIDTH_FACTOR_TOL"), w );
168 myDropSmallSolidsVolChk = new QCheckBox( tr("VOLUME_TOL"), w );
169 myDropSmallSolidsWidTol = new SalomeApp_DoubleSpinBox( w );
170 myDropSmallSolidsVolTol = new SalomeApp_DoubleSpinBox( w );
171 initSpinBox( myDropSmallSolidsWidTol, 0., 1e3, 1., "len_tol_precision" );
172 initSpinBox( myDropSmallSolidsVolTol, 0., 1e9, 1., "len_tol_precision" );
173 myDropSmallSolidsWidTol->setValue( 1 );
174 myDropSmallSolidsVolTol->setValue( 1e3 );
175 myDropSmallSolidsVolChk->setChecked( true );
176 myDropSmallSolidsWidTol->setEnabled( false );
177 myDropSmallSolidsMergeChk = new QCheckBox( tr("TO_MERGE_SOLIDS"), w );
179 aLay->addWidget( myDropSmallSolidsWidChk, 0, 0 );
180 aLay->addWidget( myDropSmallSolidsWidTol, 0, 1 );
181 aLay->addWidget( myDropSmallSolidsVolChk, 1, 0 );
182 aLay->addWidget( myDropSmallSolidsVolTol, 1, 1 );
183 aLay->addWidget( myDropSmallSolidsMergeChk, 2, 0, 1, 2 );
185 aLay->setRowStretch( aLay->rowCount(), 5 );
187 else if ( myOpLst[i] == "DropSmallEdges" ) {
189 w = new QWidget( aParamsGr );
190 QGridLayout* aLay = new QGridLayout( w );
191 aLay->setMargin( 9 ); aLay->setSpacing( 6 );
193 myDropSmallEdgesTol3D = new SalomeApp_DoubleSpinBox( w );
194 initSpinBox( myDropSmallEdgesTol3D, 0., 100., 1e-7, "len_tol_precision" );
196 aLay->addWidget( new QLabel( tr( "GEOM_3D_TOLERANCE" ), w ), 0, 0 );
197 aLay->addWidget( myDropSmallEdgesTol3D, 0, 1 );
198 aLay->setRowStretch( aLay->rowCount(), 5 );
200 else if ( myOpLst[i] == "SplitAngle" ) {
202 w = new QWidget( aParamsGr );
203 QGridLayout* aLay = new QGridLayout( w );
204 aLay->setMargin( 9 ); aLay->setSpacing( 6 );
206 mySplitAngleAngle = new SalomeApp_DoubleSpinBox( w );
207 initSpinBox( mySplitAngleAngle, 0, 360, 1, "angle_precision" );
208 mySplitAngleMaxTol = new SalomeApp_DoubleSpinBox( w );
209 initSpinBox( mySplitAngleMaxTol, 0., 100., 1e-7, "ang_tol_precision" );
211 aLay->addWidget( new QLabel( tr( "GEOM_ANGLE_1" ), w ), 0, 0 );
212 aLay->addWidget( mySplitAngleAngle, 0, 1 );
213 aLay->addWidget( new QLabel( tr( "GEOM_MAX_TOLERANCE" ), w ), 1, 0 );
214 aLay->addWidget( mySplitAngleMaxTol, 1, 1 );
215 aLay->setRowStretch( aLay->rowCount(), 5 );
217 else if ( myOpLst[i] == "SplitClosedFaces" ) {
219 w = new QWidget( aParamsGr );
220 QGridLayout* aLay = new QGridLayout( w );
221 aLay->setMargin( 9 ); aLay->setSpacing( 6 );
223 mySplitClosedFacesNum = new SalomeApp_IntSpinBox( w );
225 aLay->addWidget( new QLabel( tr( "GEOM_NUM_SPLIT_POINTS" ), w ), 0, 0 );
226 aLay->addWidget( mySplitClosedFacesNum, 0, 1 );
227 aLay->setRowStretch( aLay->rowCount(), 5 );
229 else if ( myOpLst[i] == "SplitContinuity" ) {
231 w = new QWidget( aParamsGr );
232 QGridLayout* aLay = new QGridLayout( w );
233 aLay->setMargin( 9 ); aLay->setSpacing( 6 );
235 mySplitContTol3D = new SalomeApp_DoubleSpinBox( w );
236 initSpinBox( mySplitContTol3D, 0., 100., 1e-7, "len_tol_precision" );
237 mySplitContSurfCont = new QComboBox( w );
238 mySplitContSurfCont->addItems( aContinueties );
239 mySplitContCurvCont = new QComboBox( w );
240 mySplitContCurvCont->addItems( aContinueties );
242 aLay->addWidget( new QLabel( tr( "GEOM_3D_TOLERANCE" ), w ), 0, 0 );
243 aLay->addWidget( mySplitContTol3D, 0, 1 );
244 aLay->addWidget( new QLabel( tr( "GEOM_SURFACE_CONTINUTY" ), w ), 1, 0 );
245 aLay->addWidget( mySplitContSurfCont, 1, 1 );
246 aLay->addWidget( new QLabel( tr( "GEOM_CURVE_CONTINUTY" ), w ), 2, 0 );
247 aLay->addWidget( mySplitContCurvCont, 2, 1 );
248 aLay->setRowStretch( aLay->rowCount(), 5 );
250 else if ( myOpLst[i] == "BSplineRestriction" ) {
251 // BSplineRestriction
252 w = new QWidget( aParamsGr );
253 QGridLayout* aLay = new QGridLayout( w );
254 aLay->setMargin( 9 ); aLay->setSpacing( 6 );
256 myBSplineSurfModeChk = new QCheckBox( tr("GEOM_SURFACE_MODE"), w );
257 myBSpline3DCurveChk = new QCheckBox( tr("GEOM_3D_CURVE_MODE"), w );
258 myBSpline2DCurveChk = new QCheckBox( tr("GEOM_2D_CURVE_MODE"), w );
260 myBSplineTol3D = new SalomeApp_DoubleSpinBox( w );
261 initSpinBox( myBSplineTol3D, 0., 100., 1e-7, "len_tol_precision" );
263 myBSplineTol2D = new SalomeApp_DoubleSpinBox( w );
264 initSpinBox( myBSplineTol2D, 0., 100., 1e-7, "param_tol_precision" );
266 myBSplineDegree = new SalomeApp_IntSpinBox( w );
267 myBSplineSegments = new SalomeApp_IntSpinBox( w );
268 initSpinBox( myBSplineSegments, 1, 1000, 1);
269 myBSpline2DCont = new QComboBox( w );
270 myBSpline2DCont->addItems( aContinueties );
271 myBSpline3DCont = new QComboBox( w );
272 myBSpline3DCont->addItems( aContinueties );
274 myBSplineSurfModeChk->setChecked( true );
275 myBSpline3DCurveChk->setChecked( true );
276 myBSpline2DCurveChk->setChecked( true );
278 aLay->addWidget( myBSplineSurfModeChk, 0, 0 );
279 aLay->addWidget( myBSpline3DCurveChk, 1, 0 );
280 aLay->addWidget( myBSpline2DCurveChk, 2, 0 );
281 aLay->addWidget( new QLabel( tr( "GEOM_3D_TOLERANCE" ), w ), 3, 0 );
282 aLay->addWidget( myBSplineTol3D, 3, 1 );
283 aLay->addWidget( new QLabel( tr( "GEOM_2D_TOLERANCE" ), w ), 4, 0 );
284 aLay->addWidget( myBSplineTol2D, 4, 1 );
285 aLay->addWidget( new QLabel( tr( "GEOM_REQUIRED_DEGREE" ), w ), 5, 0 );
286 aLay->addWidget( myBSplineDegree, 5, 1 );
287 aLay->addWidget( new QLabel( tr( "GEOM_REQUIRED_NUM_SEGMENTS" ), w ), 6, 0 );
288 aLay->addWidget( myBSplineSegments, 6, 1 );
289 aLay->addWidget( new QLabel( tr( "GEOM_3D_CONTINUTY" ), w ), 7, 0 );
290 aLay->addWidget( myBSpline3DCont, 7, 1 );
291 aLay->addWidget( new QLabel( tr( "GEOM_2D_CONTINUTY" ), w ), 8, 0 );
292 aLay->addWidget( myBSpline2DCont, 8, 1 );
293 aLay->setRowStretch( aLay->rowCount(), 5 );
295 else if ( myOpLst[i] == "ToBezier" ) {
297 w = new QWidget( aParamsGr );
298 QGridLayout* aLay = new QGridLayout( w );
299 aLay->setMargin( 9 ); aLay->setSpacing( 6 );
301 myToBezierSurfModeChk = new QCheckBox( tr("GEOM_SURFACE_MODE"), w );
302 myToBezier3DCurveChk = new QCheckBox( tr("GEOM_3D_CURVE_MODE"), w );
303 myToBezier2DCurveChk = new QCheckBox( tr("GEOM_2D_CURVE_MODE"), w );
305 myToBezierMaxTol = new SalomeApp_DoubleSpinBox( w );
306 initSpinBox( myToBezierMaxTol, 0., 100., 1e-7, "len_tol_precision" );
308 aLay->addWidget( myToBezierSurfModeChk, 0, 0 );
309 aLay->addWidget( myToBezier3DCurveChk, 1, 0 );
310 aLay->addWidget( myToBezier2DCurveChk, 2, 0 );
311 aLay->addWidget( new QLabel( tr( "GEOM_MAX_TOLERANCE" ), w ), 3, 0 );
312 aLay->addWidget( myToBezierMaxTol, 3, 1 );
313 aLay->setRowStretch( aLay->rowCount(), 5 );
315 else if ( myOpLst[i] == "SameParameter" ) {
317 w = new QWidget( aParamsGr );
318 QGridLayout* aLay = new QGridLayout( w );
319 aLay->setMargin( 9 ); aLay->setSpacing( 6 );
321 mySameParameterTol3D = new SalomeApp_DoubleSpinBox( w );
322 initSpinBox( mySameParameterTol3D, 0., 100., 1e-7, "len_tol_precision" );
324 aLay->addWidget( new QLabel( tr( "GEOM_3D_TOLERANCE" ), w ), 0, 0 );
325 aLay->addWidget( mySameParameterTol3D, 0, 1 );
326 aLay->setRowStretch( aLay->rowCount(), 5 );
329 w = new QWidget( aParamsGr ); // dumb widget
331 myStack->insertWidget( i, w );
334 QGridLayout* layout = new QGridLayout( centralWidget() );
335 layout->setMargin( 0 ); layout->setSpacing( 6 );
336 layout->addWidget( mySelectWdgt, 0, 0, 1, 2 );
337 layout->addWidget( anOperGr, 1, 0 );
338 layout->addWidget( aParamsGr, 1, 1 );
340 // signals and slots connections
341 connect( buttonOk(), SIGNAL( clicked() ), this, SLOT( onOk() ));
342 connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( onApply() ));
344 connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ))->selectionMgr(),
345 SIGNAL( currentSelectionChanged() ), this, SLOT( selectionChanged() ));
347 connect( mySelectWdgt->PushButton1, SIGNAL( clicked() ), this, SLOT( selectClicked() ));
348 connect( mySelectWdgt->LineEdit1, SIGNAL( returnPressed() ), this, SLOT( lineEditReturnPressed() ));
350 connect( myToBezierSurfModeChk, SIGNAL( toggled( bool )), this, SLOT( advOptionToggled( bool )));
351 connect( myDropSmallSolidsWidChk, SIGNAL( toggled( bool )), this, SLOT( advOptionToggled( bool )));
352 connect( myDropSmallSolidsVolChk, SIGNAL( toggled( bool )), this, SLOT( advOptionToggled( bool )));
354 connect( myOpList, SIGNAL( currentRowChanged( int )), myStack, SLOT( setCurrentIndex( int )));
355 connect( myOpList, SIGNAL( itemChanged( QListWidgetItem* )), this, SLOT( operatorChecked( QListWidgetItem* )));
356 connect( mySelectAll, SIGNAL( stateChanged( int ) ), this, SLOT( onSelectAll( int )));
359 loadDefaults(); // init dialog fields with values from resource file
360 //myOpList->setCurrentRow( myOpList->findItem( 0 );
363 myStack->setCurrentIndex( 0 );
365 initName( tr( "PROCESS_SHAPE_NEW_OBJ_NAME" ));
370 //=================================================================================
372 // purpose : Same than click on apply but close this dialog.
373 //=================================================================================
374 void RepairGUI_ShapeProcessDlg::onOk()
376 setIsApplyAndClose( true );
381 //=================================================================================
382 // function : onApply()
384 //=================================================================================
385 bool RepairGUI_ShapeProcessDlg::onApply()
399 //=================================================================================
400 // function : selectionChanged()
401 // purpose : Called when selection as changed or other case
402 // : used only by SelectButtonC1A1 (LineEditC1A1)
403 //=================================================================================
404 void RepairGUI_ShapeProcessDlg::selectionChanged()
408 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
409 SALOME_ListIO aSelList;
410 aSelMgr->selectedObjects(aSelList);
413 myObjects->length(aSelList.Extent());
414 for (SALOME_ListIteratorOfListIO anIt (aSelList); anIt.More(); anIt.Next()) {
415 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( anIt.Value() );
416 if ( !CORBA::is_nil( aSelectedObject ))
417 myObjects[i++] = aSelectedObject;
419 myObjects->length( i );
421 mySelectWdgt->LineEdit1->setText( GEOMBase::GetName( myObjects[0] ));
423 mySelectWdgt->LineEdit1->setText( QString::number( i ) + "_" + tr( "GEOM_OBJECTS" ));
427 //=================================================================================
428 // function : selectClicked()
430 //=================================================================================
431 void RepairGUI_ShapeProcessDlg::selectClicked()
433 myEditCurrentArgument = mySelectWdgt->LineEdit1;
434 mySelectWdgt->LineEdit1->setFocus();
439 //=================================================================================
440 // function : lineEditReturnPressed()
442 //=================================================================================
443 void RepairGUI_ShapeProcessDlg::lineEditReturnPressed()
445 GEOMBase_Skeleton::LineEditReturnPressed();
449 //=================================================================================
450 // function : activate()
452 //=================================================================================
453 void RepairGUI_ShapeProcessDlg::activate()
455 GEOMBase_Skeleton::ActivateThisDialog();
456 connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication( )))->selectionMgr(),
457 SIGNAL( currentSelectionChanged() ), this, SLOT( selectionChanged() ));
460 //myGeomGUI->SetState( 0 );
465 //=================================================================================
466 // function : enterEvent()
467 // purpose : Mouse enter onto the dialog to activate it
468 //=================================================================================
469 void RepairGUI_ShapeProcessDlg::enterEvent( QEvent* )
471 if ( !mainFrame()->GroupBoxName->isEnabled() )
476 //=================================================================================
477 // function : reset()
478 // purpose : Completely reset the state of method including local context
479 //=================================================================================
480 void RepairGUI_ShapeProcessDlg::reset()
482 myObjects = new GEOM::ListOfGO();
483 myObjects->length( 0 );
484 mySelectWdgt->LineEdit1->setText( "" );
488 //=================================================================================
489 // function : get_convert
490 // purpose : conversion of angle values to radians (non-angle values are not converted)
491 //=================================================================================
492 const char* get_convert( const char* theParam, const QString& theValue )
494 if ( !strcmp( theParam, "SplitAngle.Angle" )) {
495 double doubleValue = theValue.toDouble() * M_PI / 180.;
496 return CORBA::string_dup( QString::number( doubleValue ).toLatin1().constData() );
498 return CORBA::string_dup( theValue.toLatin1().constData() );
501 //=================================================================================
502 // function : set_convert
503 // purpose : conversion of angle values to degrees (non-angle values are not converted)
504 //=================================================================================
505 QString set_convert( const char* theParam, const char* theValue )
507 if ( !strcmp( theParam, "SplitAngle.Angle" )) {
508 Kernel_Utils::Localizer loc;
509 double doubleValue = atof( theValue ) * 180. / M_PI;
510 return QString::number( doubleValue );
512 return QString( theValue );
515 //=================================================================================
516 // function : loadDefaults()
517 // purpose : initialize "values"-fields with default values retrieved from IHealingOperations
518 //=================================================================================
519 void RepairGUI_ShapeProcessDlg::loadDefaults()
521 GEOM::GEOM_IHealingOperations_var anOp = myGeomGUI->GetGeomGen()->GetIHealingOperations( getStudyId() );
522 GEOM::string_array_var anOperators, aParams, aValues;
523 anOp->GetShapeProcessParameters( anOperators, aParams, aValues );
525 // check the default items-operators
526 for ( int i = 0; i < anOperators->length(); i++ ) {
527 //MESSAGE("-->"<<(const char*)anOperators[i]);
528 QList<QListWidgetItem*> items = myOpList->findItems ( (const char*)anOperators[i], Qt::MatchFixedString );
530 ( items[0] )->setCheckState( Qt::Checked );
533 // Retrieve default parameters for ALL operators
534 for ( int i = 0; i < myOpList->count(); i++ )
536 QString anOperator = myOpList->item( i )->text();
537 anOp->GetOperatorParameters( anOperator.toLatin1().constData(), aParams, aValues );
539 // set default values of parameters
540 if ( aParams->length() != aValues->length() )
543 for ( int j = 0; j < aParams->length(); j++ ) {
544 QWidget* aCtrl = getControl( (const char*)aParams[j] );
545 setValue( aCtrl, set_convert( (const char*)aParams[j], aValues[j] ));
550 //=================================================================================
551 // function : setValue()
552 // purpose : set value in the proper way
553 //=================================================================================
554 void RepairGUI_ShapeProcessDlg::setValue( QWidget* theControl, const QString& theValue )
556 if ( theControl && !theValue.isNull() ) {
557 if ( qobject_cast<SalomeApp_DoubleSpinBox*>( theControl ))
558 qobject_cast<SalomeApp_DoubleSpinBox*>( theControl )->setValue( theValue.toDouble() );
559 else if ( qobject_cast<SalomeApp_IntSpinBox*>( theControl ))
560 qobject_cast<SalomeApp_IntSpinBox*>( theControl )->setValue( theValue.toInt() );
561 else if ( qobject_cast<QComboBox*>( theControl ))
562 qobject_cast<QComboBox*>( theControl )->setEditText( theValue );
563 else if ( qobject_cast<QCheckBox*>( theControl ))
564 qobject_cast<QCheckBox*>( theControl )->setChecked( theValue.toInt() != 0 );
568 //=================================================================================
569 // function : getValue()
570 // purpose : get value in the proper way
571 //=================================================================================
572 QString RepairGUI_ShapeProcessDlg::getValue( QWidget* theControl ) const
575 if ( qobject_cast<SalomeApp_DoubleSpinBox*>( theControl )) {
576 if ( ( theControl == myDropSmallSolidsWidTol || theControl == myDropSmallSolidsVolTol ) && !theControl->isEnabled() ) {
577 // VSR: stupid workaround about ShapeProcessAPI:
578 // specific processing for optional parameters of DropSmallSolids operator
579 return QString::number( Precision::Infinite() );
581 return QString::number( qobject_cast<SalomeApp_DoubleSpinBox*>( theControl )->value() );
583 else if ( qobject_cast<SalomeApp_IntSpinBox*>( theControl )) {
584 return QString::number( qobject_cast<SalomeApp_IntSpinBox*>( theControl )->value() );
586 else if ( qobject_cast<QComboBox*>( theControl )) {
587 return qobject_cast<QComboBox*>( theControl )->currentText();
589 else if ( qobject_cast<QCheckBox*>( theControl )) {
590 return qobject_cast<QCheckBox*>( theControl )->isChecked() ? "1" : "0";
596 //=================================================================================
597 // function : getText()
598 // purpose : get text in the proper way
599 //=================================================================================
600 QString RepairGUI_ShapeProcessDlg::getText( QWidget* theControl ) const
603 if ( qobject_cast<SalomeApp_DoubleSpinBox*>( theControl ))
604 return qobject_cast<SalomeApp_DoubleSpinBox*>( theControl )->text();
605 else if ( qobject_cast<SalomeApp_IntSpinBox*>( theControl ))
606 return qobject_cast<SalomeApp_IntSpinBox*>( theControl )->text();
608 return QString::null;
611 //=================================================================================
612 // function : createOperation
614 //=================================================================================
615 GEOM::GEOM_IOperations_ptr RepairGUI_ShapeProcessDlg::createOperation()
617 return getGeomEngine()->GetIHealingOperations( getStudyId() );
620 //=================================================================================
621 // function : isValid
623 //=================================================================================
624 bool RepairGUI_ShapeProcessDlg::isValid( QString& msg )
627 QMapIterator<QString,QStringList> aMapIter( myValMap );
628 while( aMapIter.hasNext() ) {
630 const QStringList& aList = aMapIter.value();
631 QListIterator<QString> aListIter( aList );
632 while( aListIter.hasNext() ) {
633 const QString& aParam = aListIter.next();
634 QWidget* aControl = getControl( aParam );
635 if ( !aControl->isEnabled() ) continue;
636 if ( qobject_cast<SalomeApp_DoubleSpinBox*>( aControl ))
637 ok = qobject_cast<SalomeApp_DoubleSpinBox*>( aControl )->isValid( msg, !IsPreview() ) && ok;
638 else if ( qobject_cast<SalomeApp_IntSpinBox*>( aControl ))
639 ok = qobject_cast<SalomeApp_IntSpinBox*>( aControl )->isValid( msg, !IsPreview() ) && ok;
644 GEOM::string_array_var anOperators = getActiveOperators();
645 if ( !myObjects->length() ) {
646 msg += tr( "ERROR_NO_OBJECTS" );
649 if ( !anOperators->length() ) {
652 msg += tr( "ERROR_NO_OPERATORS" );
658 //=================================================================================
659 // function : execute
661 //=================================================================================
662 bool RepairGUI_ShapeProcessDlg::execute( ObjectList& objects )
664 GEOM::string_array_var anOperators = getActiveOperators();
665 GEOM::string_array_var aParams = getParameters( anOperators );
666 GEOM::string_array_var aValues = getValues( aParams );
670 MESSAGE("Objects : ");
671 for ( z = 0; z < myObjects->length(); z++ )
672 MESSAGE(myObjects[z]->GetName() << " ");
673 MESSAGE("\nOperators : ");
674 for ( z = 0; z < anOperators->length(); z++ )
675 MESSAGE(anOperators[z] << " ");
676 MESSAGE("\nParameters : ");
677 for ( z = 0; z < aParams->length(); z++ )
678 MESSAGE(aParams[z] << " ");
679 MESSAGE("\nValues : ");
680 for ( z = 0; z < aValues->length(); z ++ )
681 MESSAGE(aValues[z] << " ");
685 QStringList anErrorObjNames;
686 for ( int i = 0; i < myObjects->length(); i++ ) {
687 GEOM::GEOM_Object_var obj = myObjects[i];
688 GEOM::GEOM_IHealingOperations_var anOper = GEOM::GEOM_IHealingOperations::_narrow( getOperation() );
689 GEOM::GEOM_Object_var anObj = anOper->ProcessShape( obj, anOperators, aParams, aValues );
690 if ( anObj->_is_nil() )
691 anErrorObjNames << GEOMBase::GetName( obj );
696 QStringList aParameters;
698 for ( int i = 0; i < anOperators->length(); i++ )
699 aParameters << QString( anOperators[i] );
701 for ( int i = 0; i < aParams->length(); i++ )
702 aParameters << QString( aParams[i] );
704 aParameters << getTexts( aParams );
705 anObj->SetParameters(aParameters.join(":").toLatin1().constData());
707 RepairGUI::ShowStatistics( anOper, this );
709 objects.push_back( anObj._retn() );
713 if ( !anErrorObjNames.empty() )
714 MESSAGE( "ERRORS occured while processing the following objects: " << anErrorObjNames.join( " " ).toLatin1().data() );
716 return anErrorObjNames.size() < myObjects->length(); // true if at least one object was OK, false if ALL objects were nil after Healing.
719 //=================================================================================
720 // function : getActiveOperators
722 //=================================================================================
723 GEOM::string_array* RepairGUI_ShapeProcessDlg::getActiveOperators()
725 GEOM::string_array_var anOperators = new GEOM::string_array();
727 int j = 0, n = myOpList->count();
728 anOperators->length( n );
729 for ( int i = 0; i < n; i++ ) {
730 if ( myOpList->item( i )->checkState() == Qt::Checked )
731 anOperators[j++] = myOpList->item( i )->text().toLatin1().constData();
733 anOperators->length( j );
735 return anOperators._retn();
738 //=================================================================================
739 // function : getcontrol
741 //=================================================================================
742 QWidget* RepairGUI_ShapeProcessDlg::getControl( const QString& theParam )
744 if ( theParam == "SplitAngle.Angle" ) return mySplitAngleAngle;
745 else if ( theParam == "SplitAngle.MaxTolerance" ) return mySplitAngleMaxTol;
746 else if ( theParam == "SplitClosedFaces.NbSplitPoints" ) return mySplitClosedFacesNum;
747 else if ( theParam == "FixFaceSize.Tolerance" ) return myFixFaceSizeTol;
748 else if ( theParam == "DropSmallEdges.Tolerance3d" ) return myDropSmallEdgesTol3D;
749 else if ( theParam == "DropSmallSolids.WidthFactorThreshold" ) return myDropSmallSolidsWidTol;
750 else if ( theParam == "DropSmallSolids.VolumeThreshold" ) return myDropSmallSolidsVolTol;
751 else if ( theParam == "DropSmallSolids.MergeSolids" ) return myDropSmallSolidsMergeChk;
752 else if ( theParam == "BSplineRestriction.SurfaceMode" ) return myBSplineSurfModeChk;
753 else if ( theParam == "BSplineRestriction.Curve3dMode" ) return myBSpline3DCurveChk;
754 else if ( theParam == "BSplineRestriction.Curve2dMode" ) return myBSpline2DCurveChk;
755 else if ( theParam == "BSplineRestriction.Tolerance3d" ) return myBSplineTol3D;
756 else if ( theParam == "BSplineRestriction.Tolerance2d" ) return myBSplineTol2D;
757 else if ( theParam == "BSplineRestriction.RequiredDegree" ) return myBSplineDegree;
758 else if ( theParam == "BSplineRestriction.RequiredNbSegments" ) return myBSplineSegments;
759 else if ( theParam == "BSplineRestriction.Continuity3d" ) return myBSpline3DCont;
760 else if ( theParam == "BSplineRestriction.Continuity2d" ) return myBSpline2DCont;
761 else if ( theParam == "SplitContinuity.Tolerance3d" ) return mySplitContTol3D;
762 else if ( theParam == "SplitContinuity.SurfaceContinuity" ) return mySplitContSurfCont;
763 else if ( theParam == "SplitContinuity.CurveContinuity" ) return mySplitContCurvCont;
764 else if ( theParam == "ToBezier.SurfaceMode" ) return myToBezierSurfModeChk;
765 else if ( theParam == "ToBezier.Curve3dMode" ) return myToBezier3DCurveChk;
766 else if ( theParam == "ToBezier.Curve2dMode" ) return myToBezier2DCurveChk;
767 else if ( theParam == "ToBezier.MaxTolerance" ) return myToBezierMaxTol;
768 else if ( theParam == "SameParameter.Tolerance3d" ) return mySameParameterTol3D;
769 else if ( theParam == "FixShape.Tolerance3d" ) return myFixShapeTol3D;
770 else if ( theParam == "FixShape.MaxTolerance3d" ) return myFixShapeMaxTol3D;
774 //=================================================================================
775 // function : getParameters
777 //=================================================================================
778 void RepairGUI_ShapeProcessDlg::initParamsValues()
780 if ( myOpLst.count() )
781 return; // already filled
783 myOpLst << "FixShape";
784 myValMap["FixShape"] << "FixShape.Tolerance3d";
785 myValMap["FixShape"] << "FixShape.MaxTolerance3d";
787 myOpLst << "FixFaceSize";
788 myValMap["FixFaceSize"] << "FixFaceSize.Tolerance";
790 myOpLst << "DropSmallEdges";
791 myValMap["DropSmallEdges"] << "DropSmallEdges.Tolerance3d";
793 myOpLst << "DropSmallSolids";
794 myValMap["DropSmallSolids"] << "DropSmallSolids.WidthFactorThreshold";
795 myValMap["DropSmallSolids"] << "DropSmallSolids.VolumeThreshold";
796 myValMap["DropSmallSolids"] << "DropSmallSolids.MergeSolids";
798 myOpLst << "SplitAngle";
799 myValMap["SplitAngle"] << "SplitAngle.Angle";
800 myValMap["SplitAngle"] << "SplitAngle.MaxTolerance";
802 myOpLst << "SplitClosedFaces";
803 myValMap["SplitClosedFaces"] << "SplitClosedFaces.NbSplitPoints";
805 myOpLst << "SplitContinuity";
806 myValMap["SplitContinuity"] << "SplitContinuity.Tolerance3d";
807 myValMap["SplitContinuity"] << "SplitContinuity.SurfaceContinuity";
808 myValMap["SplitContinuity"] << "SplitContinuity.CurveContinuity";
810 myOpLst << "BSplineRestriction";
811 myValMap["BSplineRestriction"] << "BSplineRestriction.SurfaceMode";
812 myValMap["BSplineRestriction"] << "BSplineRestriction.Curve3dMode";
813 myValMap["BSplineRestriction"] << "BSplineRestriction.Curve2dMode";
814 myValMap["BSplineRestriction"] << "BSplineRestriction.Tolerance3d";
815 myValMap["BSplineRestriction"] << "BSplineRestriction.Tolerance2d";
816 myValMap["BSplineRestriction"] << "BSplineRestriction.RequiredDegree";
817 myValMap["BSplineRestriction"] << "BSplineRestriction.RequiredNbSegments";
818 myValMap["BSplineRestriction"] << "BSplineRestriction.Continuity3d";
819 myValMap["BSplineRestriction"] << "BSplineRestriction.Continuity2d";
821 myOpLst << "ToBezier";
822 myValMap["ToBezier"] << "ToBezier.SurfaceMode";
823 myValMap["ToBezier"] << "ToBezier.Curve3dMode";
824 myValMap["ToBezier"] << "ToBezier.Curve2dMode";
825 myValMap["ToBezier"] << "ToBezier.MaxTolerance";
827 myOpLst << "SameParameter";
828 myValMap["SameParameter"] << "SameParameter.Tolerance3d";
831 //=================================================================================
832 // function : getParameters
834 //=================================================================================
835 GEOM::string_array* RepairGUI_ShapeProcessDlg::getParameters( const GEOM::string_array& theOperators )
837 GEOM::string_array_var aParams = new GEOM::string_array();
840 // calculate the length of parameters
841 for ( i = 0, j = 0; i < theOperators.length(); i++ )
842 j += myValMap[ QString( theOperators[i].in() ) ].size();
844 // set the new length of paremeters
845 aParams->length( j );
847 // fill the parameters
848 for ( i = 0, j = 0; i < theOperators.length(); i++ ) {
849 QStringList aParamLst = myValMap[ QString( theOperators[i].in() ) ];
850 foreach ( QString aParam, aParamLst ) {
851 aParams[j++] = CORBA::string_dup( aParam.toLatin1().constData() );
855 aParams->length( j );
857 return aParams._retn();
861 //=================================================================================
862 // function : getValues
864 //=================================================================================
865 GEOM::string_array* RepairGUI_ShapeProcessDlg::getValues( const GEOM::string_array& theParams )
867 GEOM::string_array_var aValues = new GEOM::string_array();
868 aValues->length( theParams.length() );
870 for ( int i = 0; i < theParams.length(); i++ ) {
871 QWidget* aCtrl = getControl( (const char*)theParams[i] );
873 aValues[i] = get_convert( (const char*)theParams[i], getValue( aCtrl ));
876 return aValues._retn();
879 //=================================================================================
880 // function : getTexts
882 //=================================================================================
883 QStringList RepairGUI_ShapeProcessDlg::getTexts( const GEOM::string_array& theParams )
887 for ( int i = 0; i < theParams.length(); i++ ) {
888 QWidget* aCtrl = getControl( (const char*)theParams[i] );
891 QString aText = getText( aCtrl );
892 if( !aText.isNull() )
893 aTexts.append( aText );
900 //=================================================================================
901 // function : initSelection
902 // purpose : set selection of ALL shape types except vertexes
903 //=================================================================================
904 void RepairGUI_ShapeProcessDlg::initSelection()
906 TColStd_MapOfInteger aTypes;
907 aTypes.Add( GEOM_COMPOUND );
908 aTypes.Add( GEOM_SOLID );
909 aTypes.Add( GEOM_SHELL );
910 aTypes.Add( GEOM_FACE );
911 aTypes.Add( GEOM_WIRE );
912 aTypes.Add( GEOM_EDGE );
913 globalSelection( aTypes );
916 //=================================================================================
917 // function : advOptionToggled
918 // purpose : this slot is used to warn the user about possible consequences
919 // of enabling some advanced options
920 //=================================================================================
921 void RepairGUI_ShapeProcessDlg::advOptionToggled( bool on )
923 QAbstractButton* btn = (QAbstractButton*)sender();
924 if ( btn == myToBezierSurfModeChk )
926 if ( on && btn->isCheckable() &&
927 SUIT_MessageBox::warning( this,
928 tr( "GEOM_WRN_WARNING" ), tr( "TIME_CONSUMING" ),
929 SUIT_MessageBox::Yes | SUIT_MessageBox::No ) == SUIT_MessageBox::No )
933 // either myDropSmallSolidsWidChk or myDropSmallSolidsVolChk must be checked
934 if ( btn == myDropSmallSolidsWidChk )
936 myDropSmallSolidsWidTol->setEnabled( on );
938 myDropSmallSolidsVolChk->setChecked( true );
939 myDropSmallSolidsVolTol->setEnabled( true );
942 if ( btn == myDropSmallSolidsVolChk )
944 myDropSmallSolidsVolTol->setEnabled( on );
946 myDropSmallSolidsWidChk->setChecked( true );
947 myDropSmallSolidsWidTol->setEnabled( true );
952 //=======================================================================
953 //function : operatorChecked
954 //purpose : show parameters of a selected operator
955 //=======================================================================
957 void RepairGUI_ShapeProcessDlg::operatorChecked( QListWidgetItem * item )
959 if ( item && item->checkState() == Qt::Checked )
961 myStack->setCurrentIndex( myOpList->row( item ));
966 void RepairGUI_ShapeProcessDlg::updateSelectAll()
968 Qt::CheckState state = myOpList->count() > 0 ? myOpList->item(0)->checkState() : Qt::Unchecked;
969 for ( int i = 1; i < myOpList->count(); i++ ) {
970 if ( myOpList->item(i)->checkState() != state ) {
971 state = Qt::PartiallyChecked;
975 mySelectAll->blockSignals( true );
976 mySelectAll->setCheckState( state );
977 mySelectAll->blockSignals( false );
980 void RepairGUI_ShapeProcessDlg::onSelectAll( int state )
982 if ( state == Qt::PartiallyChecked ) {
983 mySelectAll->setCheckState( Qt::Checked );
986 myOpList->blockSignals( true );
987 for ( int i = 0; i < myOpList->count(); i++ ) {
988 myOpList->item(i)->setCheckState( (Qt::CheckState)state );
990 myOpList->blockSignals( false );