1 // Copyright (C) 2007-2020 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>
43 #include "utilities.h"
45 #include <Basics_Utils.hxx>
46 #include "utilities.h"
48 #include <TCollection_AsciiString.hxx>
49 #include <TColStd_MapOfInteger.hxx>
51 #include <QListWidget>
52 #include <QStackedLayout>
54 //=================================================================================
55 // class : RepairGUI_ShapeProcessDlg()
56 // purpose : Constructs a RepairGUI_ShapeProcessDlg which is a child of 'parent', with the
57 // name 'name' and widget flags set to 'f'.
58 // The dialog will by default be modeless, unless you set 'modal' to
59 // TRUE to construct a modal dialog.
60 //=================================================================================
61 RepairGUI_ShapeProcessDlg::RepairGUI_ShapeProcessDlg( GeometryGUI* theGeometryGUI, QWidget* parent,
63 : GEOMBase_Skeleton( theGeometryGUI, parent, modal )
65 setHelpFileName( "shape_processing_operation_page.html" );
69 //=================================================================================
70 // function : ~RepairGUI_ShapeProcessDlg()
71 // purpose : Destroys the object and frees any allocated resources
72 //=================================================================================
73 RepairGUI_ShapeProcessDlg::~RepairGUI_ShapeProcessDlg()
77 //=================================================================================
80 //=================================================================================
81 void RepairGUI_ShapeProcessDlg::init()
83 //myGeomGUI->SetState( 0 );
88 setWindowTitle( tr( "GEOM_SHAPEPROCESS_TITLE" ));
90 mainFrame()->GroupConstructors->hide();
92 // select widget on the top
93 mySelectWdgt = new DlgRef_1Sel( centralWidget() );
94 mySelectWdgt->GroupBox1->setTitle( tr( "GEOM_SHAPE" ));
95 mySelectWdgt->TextLabel1->setText( tr( "GEOM_SELECTED_OBJECTS" ));
96 mySelectWdgt->PushButton1->setIcon( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_SELECT" )));
97 mySelectWdgt->LineEdit1->setReadOnly( true );
99 // layout the two group boxes in the middle, add a list of operations
100 QGroupBox* anOperGr = new QGroupBox( tr( "GEOM_OPERATIONS" ), centralWidget() );
102 // "select all" button
103 mySelectAll = new QCheckBox( tr( "SELECT_ALL" ), anOperGr );
104 mySelectAll->setTristate( true );
106 // operations list widget
107 myOpList = new QListWidget( anOperGr );
108 myOpList->setSortingEnabled( false );
109 myOpList->setSizePolicy( QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Expanding ));
111 QVBoxLayout* aOperLay = new QVBoxLayout( anOperGr );
112 aOperLay->setMargin( 9 );
113 aOperLay->addWidget( mySelectAll );
114 aOperLay->addWidget( myOpList );
116 QGroupBox* aParamsGr = new QGroupBox( tr( "GEOM_PARAMETERS" ), centralWidget() );
118 // add a widget stack to the parameters group box
119 myStack = new QStackedLayout( aParamsGr );
121 // continueties values..
122 QStringList aContinueties = QString( "C0,G1,C1,G2,C2,C3,CN" ).split( "," );
124 // fill in the widgets
125 for ( int i = 0; i < myOpLst.count(); i++ ) {
126 QListWidgetItem* item = new QListWidgetItem( myOpLst[i] );
127 item->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsUserCheckable );
128 item->setCheckState( Qt::Unchecked );
129 myOpList->addItem( item );
132 if ( myOpLst[i] == "FixShape" ) {
134 w = new QWidget( aParamsGr );
135 QGridLayout* aLay = new QGridLayout( w );
136 aLay->setMargin( 9 ); aLay->setSpacing( 6 );
138 myFixShapeTol3D = new SalomeApp_DoubleSpinBox( w );
139 initSpinBox( myFixShapeTol3D, 0., 100., 1e-7, "len_tol_precision" );
140 myFixShapeMaxTol3D = new SalomeApp_DoubleSpinBox( w );
141 initSpinBox( myFixShapeMaxTol3D, 0., 100., 1e-7, "len_tol_precision" );
143 aLay->addWidget( new QLabel( tr( "GEOM_3D_TOLERANCE" ), w ), 0, 0 );
144 aLay->addWidget( myFixShapeTol3D, 0, 1 );
145 aLay->addWidget( new QLabel( tr( "GEOM_MAX_3D_TOLERANCE" ), w ), 1, 0 );
146 aLay->addWidget( myFixShapeMaxTol3D, 1, 1 );
147 aLay->setRowStretch( aLay->rowCount(), 5 );
149 else if ( myOpLst[i] == "FixFaceSize" ) {
151 w = new QWidget( aParamsGr );
152 QGridLayout* aLay = new QGridLayout( w );
153 aLay->setMargin( 9 ); aLay->setSpacing( 6 );
155 myFixFaceSizeTol = new SalomeApp_DoubleSpinBox( w );
156 initSpinBox( myFixFaceSizeTol, 0., 100., 1e-7, "len_tol_precision" );
158 aLay->addWidget( new QLabel( tr( "GEOM_TOLERANCE" ), w ), 0, 0 );
159 aLay->addWidget( myFixFaceSizeTol, 0, 1 );
160 aLay->setRowStretch( aLay->rowCount(), 5 );
162 else if ( myOpLst[i] == "DropSmallSolids" ) {
164 w = new QWidget( aParamsGr );
165 QGridLayout* aLay = new QGridLayout( w );
166 aLay->setMargin( 9 ); aLay->setSpacing( 6 );
168 myDropSmallSolidsWidChk = new QCheckBox( tr("WIDTH_FACTOR_TOL"), w );
169 myDropSmallSolidsVolChk = new QCheckBox( tr("VOLUME_TOL"), w );
170 myDropSmallSolidsWidTol = new SalomeApp_DoubleSpinBox( w );
171 myDropSmallSolidsVolTol = new SalomeApp_DoubleSpinBox( w );
172 initSpinBox( myDropSmallSolidsWidTol, 0., 1e3, 1., "len_tol_precision" );
173 initSpinBox( myDropSmallSolidsVolTol, 0., 1e9, 1., "len_tol_precision" );
174 myDropSmallSolidsWidTol->setValue( 1 );
175 myDropSmallSolidsVolTol->setValue( 1e3 );
176 myDropSmallSolidsVolChk->setChecked( true );
177 myDropSmallSolidsWidTol->setEnabled( false );
178 myDropSmallSolidsMergeChk = new QCheckBox( tr("TO_MERGE_SOLIDS"), w );
180 aLay->addWidget( myDropSmallSolidsWidChk, 0, 0 );
181 aLay->addWidget( myDropSmallSolidsWidTol, 0, 1 );
182 aLay->addWidget( myDropSmallSolidsVolChk, 1, 0 );
183 aLay->addWidget( myDropSmallSolidsVolTol, 1, 1 );
184 aLay->addWidget( myDropSmallSolidsMergeChk, 2, 0, 1, 2 );
186 aLay->setRowStretch( aLay->rowCount(), 5 );
188 else if ( myOpLst[i] == "DropSmallEdges" ) {
190 w = new QWidget( aParamsGr );
191 QGridLayout* aLay = new QGridLayout( w );
192 aLay->setMargin( 9 ); aLay->setSpacing( 6 );
194 myDropSmallEdgesTol3D = new SalomeApp_DoubleSpinBox( w );
195 initSpinBox( myDropSmallEdgesTol3D, 0., 100., 1e-7, "len_tol_precision" );
197 aLay->addWidget( new QLabel( tr( "GEOM_3D_TOLERANCE" ), w ), 0, 0 );
198 aLay->addWidget( myDropSmallEdgesTol3D, 0, 1 );
199 aLay->setRowStretch( aLay->rowCount(), 5 );
201 else if ( myOpLst[i] == "SplitAngle" ) {
203 w = new QWidget( aParamsGr );
204 QGridLayout* aLay = new QGridLayout( w );
205 aLay->setMargin( 9 ); aLay->setSpacing( 6 );
207 mySplitAngleAngle = new SalomeApp_DoubleSpinBox( w );
208 initSpinBox( mySplitAngleAngle, 0, 360, 1, "angle_precision" );
209 mySplitAngleMaxTol = new SalomeApp_DoubleSpinBox( w );
210 initSpinBox( mySplitAngleMaxTol, 0., 100., 1e-7, "ang_tol_precision" );
212 aLay->addWidget( new QLabel( tr( "GEOM_ANGLE_1" ), w ), 0, 0 );
213 aLay->addWidget( mySplitAngleAngle, 0, 1 );
214 aLay->addWidget( new QLabel( tr( "GEOM_MAX_TOLERANCE" ), w ), 1, 0 );
215 aLay->addWidget( mySplitAngleMaxTol, 1, 1 );
216 aLay->setRowStretch( aLay->rowCount(), 5 );
218 else if ( myOpLst[i] == "SplitClosedFaces" ) {
220 w = new QWidget( aParamsGr );
221 QGridLayout* aLay = new QGridLayout( w );
222 aLay->setMargin( 9 ); aLay->setSpacing( 6 );
224 mySplitClosedFacesNum = new SalomeApp_IntSpinBox( w );
226 aLay->addWidget( new QLabel( tr( "GEOM_NUM_SPLIT_POINTS" ), w ), 0, 0 );
227 aLay->addWidget( mySplitClosedFacesNum, 0, 1 );
228 aLay->setRowStretch( aLay->rowCount(), 5 );
230 else if ( myOpLst[i] == "SplitContinuity" ) {
232 w = new QWidget( aParamsGr );
233 QGridLayout* aLay = new QGridLayout( w );
234 aLay->setMargin( 9 ); aLay->setSpacing( 6 );
236 mySplitContTol3D = new SalomeApp_DoubleSpinBox( w );
237 initSpinBox( mySplitContTol3D, 0., 100., 1e-7, "len_tol_precision" );
238 mySplitContSurfCont = new QComboBox( w );
239 mySplitContSurfCont->addItems( aContinueties );
240 mySplitContCurvCont = new QComboBox( w );
241 mySplitContCurvCont->addItems( aContinueties );
243 aLay->addWidget( new QLabel( tr( "GEOM_3D_TOLERANCE" ), w ), 0, 0 );
244 aLay->addWidget( mySplitContTol3D, 0, 1 );
245 aLay->addWidget( new QLabel( tr( "GEOM_SURFACE_CONTINUTY" ), w ), 1, 0 );
246 aLay->addWidget( mySplitContSurfCont, 1, 1 );
247 aLay->addWidget( new QLabel( tr( "GEOM_CURVE_CONTINUTY" ), w ), 2, 0 );
248 aLay->addWidget( mySplitContCurvCont, 2, 1 );
249 aLay->setRowStretch( aLay->rowCount(), 5 );
251 else if ( myOpLst[i] == "BSplineRestriction" ) {
252 // BSplineRestriction
253 w = new QWidget( aParamsGr );
254 QGridLayout* aLay = new QGridLayout( w );
255 aLay->setMargin( 9 ); aLay->setSpacing( 6 );
257 myBSplineSurfModeChk = new QCheckBox( tr("GEOM_SURFACE_MODE"), w );
258 myBSpline3DCurveChk = new QCheckBox( tr("GEOM_3D_CURVE_MODE"), w );
259 myBSpline2DCurveChk = new QCheckBox( tr("GEOM_2D_CURVE_MODE"), w );
261 myBSplineTol3D = new SalomeApp_DoubleSpinBox( w );
262 initSpinBox( myBSplineTol3D, 0., 100., 1e-7, "len_tol_precision" );
264 myBSplineTol2D = new SalomeApp_DoubleSpinBox( w );
265 initSpinBox( myBSplineTol2D, 0., 100., 1e-7, "param_tol_precision" );
267 myBSplineDegree = new SalomeApp_IntSpinBox( w );
268 myBSplineSegments = new SalomeApp_IntSpinBox( w );
269 initSpinBox( myBSplineSegments, 1, 1000, 1);
270 myBSpline2DCont = new QComboBox( w );
271 myBSpline2DCont->addItems( aContinueties );
272 myBSpline3DCont = new QComboBox( w );
273 myBSpline3DCont->addItems( aContinueties );
275 myBSplineSurfModeChk->setChecked( true );
276 myBSpline3DCurveChk->setChecked( true );
277 myBSpline2DCurveChk->setChecked( true );
279 aLay->addWidget( myBSplineSurfModeChk, 0, 0 );
280 aLay->addWidget( myBSpline3DCurveChk, 1, 0 );
281 aLay->addWidget( myBSpline2DCurveChk, 2, 0 );
282 aLay->addWidget( new QLabel( tr( "GEOM_3D_TOLERANCE" ), w ), 3, 0 );
283 aLay->addWidget( myBSplineTol3D, 3, 1 );
284 aLay->addWidget( new QLabel( tr( "GEOM_2D_TOLERANCE" ), w ), 4, 0 );
285 aLay->addWidget( myBSplineTol2D, 4, 1 );
286 aLay->addWidget( new QLabel( tr( "GEOM_REQUIRED_DEGREE" ), w ), 5, 0 );
287 aLay->addWidget( myBSplineDegree, 5, 1 );
288 aLay->addWidget( new QLabel( tr( "GEOM_REQUIRED_NUM_SEGMENTS" ), w ), 6, 0 );
289 aLay->addWidget( myBSplineSegments, 6, 1 );
290 aLay->addWidget( new QLabel( tr( "GEOM_3D_CONTINUTY" ), w ), 7, 0 );
291 aLay->addWidget( myBSpline3DCont, 7, 1 );
292 aLay->addWidget( new QLabel( tr( "GEOM_2D_CONTINUTY" ), w ), 8, 0 );
293 aLay->addWidget( myBSpline2DCont, 8, 1 );
294 aLay->setRowStretch( aLay->rowCount(), 5 );
296 else if ( myOpLst[i] == "ToBezier" ) {
298 w = new QWidget( aParamsGr );
299 QGridLayout* aLay = new QGridLayout( w );
300 aLay->setMargin( 9 ); aLay->setSpacing( 6 );
302 myToBezierSurfModeChk = new QCheckBox( tr("GEOM_SURFACE_MODE"), w );
303 myToBezier3DCurveChk = new QCheckBox( tr("GEOM_3D_CURVE_MODE"), w );
304 myToBezier2DCurveChk = new QCheckBox( tr("GEOM_2D_CURVE_MODE"), w );
306 myToBezierMaxTol = new SalomeApp_DoubleSpinBox( w );
307 initSpinBox( myToBezierMaxTol, 0., 100., 1e-7, "len_tol_precision" );
309 aLay->addWidget( myToBezierSurfModeChk, 0, 0 );
310 aLay->addWidget( myToBezier3DCurveChk, 1, 0 );
311 aLay->addWidget( myToBezier2DCurveChk, 2, 0 );
312 aLay->addWidget( new QLabel( tr( "GEOM_MAX_TOLERANCE" ), w ), 3, 0 );
313 aLay->addWidget( myToBezierMaxTol, 3, 1 );
314 aLay->setRowStretch( aLay->rowCount(), 5 );
316 else if ( myOpLst[i] == "SameParameter" ) {
318 w = new QWidget( aParamsGr );
319 QGridLayout* aLay = new QGridLayout( w );
320 aLay->setMargin( 9 ); aLay->setSpacing( 6 );
322 mySameParameterTol3D = new SalomeApp_DoubleSpinBox( w );
323 initSpinBox( mySameParameterTol3D, 0., 100., 1e-7, "len_tol_precision" );
325 aLay->addWidget( new QLabel( tr( "GEOM_3D_TOLERANCE" ), w ), 0, 0 );
326 aLay->addWidget( mySameParameterTol3D, 0, 1 );
327 aLay->setRowStretch( aLay->rowCount(), 5 );
330 w = new QWidget( aParamsGr ); // dumb widget
332 myStack->insertWidget( i, w );
335 QGridLayout* layout = new QGridLayout( centralWidget() );
336 layout->setMargin( 0 ); layout->setSpacing( 6 );
337 layout->addWidget( mySelectWdgt, 0, 0, 1, 2 );
338 layout->addWidget( anOperGr, 1, 0 );
339 layout->addWidget( aParamsGr, 1, 1 );
341 // signals and slots connections
342 connect( buttonOk(), SIGNAL( clicked() ), this, SLOT( onOk() ));
343 connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( onApply() ));
345 connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ))->selectionMgr(),
346 SIGNAL( currentSelectionChanged() ), this, SLOT( selectionChanged() ));
348 connect( mySelectWdgt->PushButton1, SIGNAL( clicked() ), this, SLOT( selectClicked() ));
349 connect( mySelectWdgt->LineEdit1, SIGNAL( returnPressed() ), this, SLOT( lineEditReturnPressed() ));
351 connect( myToBezierSurfModeChk, SIGNAL( toggled( bool )), this, SLOT( advOptionToggled( bool )));
352 connect( myDropSmallSolidsWidChk, SIGNAL( toggled( bool )), this, SLOT( advOptionToggled( bool )));
353 connect( myDropSmallSolidsVolChk, SIGNAL( toggled( bool )), this, SLOT( advOptionToggled( bool )));
355 connect( myOpList, SIGNAL( currentRowChanged( int )), myStack, SLOT( setCurrentIndex( int )));
356 connect( myOpList, SIGNAL( itemChanged( QListWidgetItem* )), this, SLOT( operatorChecked( QListWidgetItem* )));
357 connect( mySelectAll, SIGNAL( stateChanged( int ) ), this, SLOT( onSelectAll( int )));
360 loadDefaults(); // init dialog fields with values from resource file
361 //myOpList->setCurrentRow( myOpList->findItem( 0 );
364 myOpList->setCurrentRow(0);
366 initName( tr( "PROCESS_SHAPE_NEW_OBJ_NAME" ));
371 //=================================================================================
373 // purpose : Same than click on apply but close this dialog.
374 //=================================================================================
375 void RepairGUI_ShapeProcessDlg::onOk()
377 setIsApplyAndClose( true );
382 //=================================================================================
383 // function : onApply()
385 //=================================================================================
386 bool RepairGUI_ShapeProcessDlg::onApply()
400 //=================================================================================
401 // function : selectionChanged()
402 // purpose : Called when selection as changed or other case
403 // : used only by SelectButtonC1A1 (LineEditC1A1)
404 //=================================================================================
405 void RepairGUI_ShapeProcessDlg::selectionChanged()
409 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
410 SALOME_ListIO aSelList;
411 aSelMgr->selectedObjects(aSelList);
414 myObjects->length(aSelList.Extent());
415 for (SALOME_ListIteratorOfListIO anIt (aSelList); anIt.More(); anIt.Next()) {
416 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( anIt.Value() );
417 if ( !CORBA::is_nil( aSelectedObject ))
418 myObjects[i++] = aSelectedObject;
420 myObjects->length( i );
422 mySelectWdgt->LineEdit1->setText( GEOMBase::GetName( myObjects[0] ));
424 mySelectWdgt->LineEdit1->setText( QString::number( i ) + "_" + tr( "GEOM_OBJECTS" ));
428 //=================================================================================
429 // function : selectClicked()
431 //=================================================================================
432 void RepairGUI_ShapeProcessDlg::selectClicked()
434 myEditCurrentArgument = mySelectWdgt->LineEdit1;
435 mySelectWdgt->LineEdit1->setFocus();
440 //=================================================================================
441 // function : lineEditReturnPressed()
443 //=================================================================================
444 void RepairGUI_ShapeProcessDlg::lineEditReturnPressed()
446 GEOMBase_Skeleton::LineEditReturnPressed();
450 //=================================================================================
451 // function : activate()
453 //=================================================================================
454 void RepairGUI_ShapeProcessDlg::activate()
456 GEOMBase_Skeleton::ActivateThisDialog();
457 connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication( )))->selectionMgr(),
458 SIGNAL( currentSelectionChanged() ), this, SLOT( selectionChanged() ));
461 //myGeomGUI->SetState( 0 );
466 //=================================================================================
467 // function : enterEvent()
468 // purpose : Mouse enter onto the dialog to activate it
469 //=================================================================================
470 void RepairGUI_ShapeProcessDlg::enterEvent( QEvent* )
472 if ( !mainFrame()->GroupBoxName->isEnabled() )
477 //=================================================================================
478 // function : reset()
479 // purpose : Completely reset the state of method including local context
480 //=================================================================================
481 void RepairGUI_ShapeProcessDlg::reset()
483 myObjects = new GEOM::ListOfGO();
484 myObjects->length( 0 );
485 mySelectWdgt->LineEdit1->setText( "" );
489 //=================================================================================
490 // function : get_convert
491 // purpose : conversion of angle values to radians (non-angle values are not converted)
492 //=================================================================================
493 const char* get_convert( const char* theParam, const QString& theValue )
495 if ( !strcmp( theParam, "SplitAngle.Angle" )) {
496 double doubleValue = theValue.toDouble() * M_PI / 180.;
497 return CORBA::string_dup( QString::number( doubleValue ).toLatin1().constData() );
499 return CORBA::string_dup( theValue.toLatin1().constData() );
502 //=================================================================================
503 // function : set_convert
504 // purpose : conversion of angle values to degrees (non-angle values are not converted)
505 //=================================================================================
506 QString set_convert( const char* theParam, const char* theValue )
508 if ( !strcmp( theParam, "SplitAngle.Angle" )) {
509 Kernel_Utils::Localizer loc;
510 double doubleValue = atof( theValue ) * 180. / M_PI;
511 return QString::number( doubleValue );
513 return QString( theValue );
516 //=================================================================================
517 // function : loadDefaults()
518 // purpose : initialize "values"-fields with default values retrieved from IHealingOperations
519 //=================================================================================
520 void RepairGUI_ShapeProcessDlg::loadDefaults()
522 GEOM::GEOM_IHealingOperations_var anOp = myGeomGUI->GetGeomGen()->GetIHealingOperations();
523 GEOM::string_array_var anOperators, aParams, aValues;
524 anOp->GetShapeProcessParameters( anOperators, aParams, aValues );
526 // check the default items-operators
527 for ( int i = 0; i < anOperators->length(); i++ ) {
528 //MESSAGE("-->"<<(const char*)anOperators[i]);
529 QList<QListWidgetItem*> items = myOpList->findItems ( (const char*)anOperators[i], Qt::MatchFixedString );
531 ( items[0] )->setCheckState( Qt::Checked );
534 // Retrieve default parameters for ALL operators
535 for ( int i = 0; i < myOpList->count(); i++ )
537 QString anOperator = myOpList->item( i )->text();
538 anOp->GetOperatorParameters( anOperator.toLatin1().constData(), aParams, aValues );
540 // set default values of parameters
541 if ( aParams->length() != aValues->length() )
544 for ( int j = 0; j < aParams->length(); j++ ) {
545 QWidget* aCtrl = getControl( (const char*)aParams[j] );
546 setValue( aCtrl, set_convert( (const char*)aParams[j], aValues[j] ));
551 //=================================================================================
552 // function : setValue()
553 // purpose : set value in the proper way
554 //=================================================================================
555 void RepairGUI_ShapeProcessDlg::setValue( QWidget* theControl, const QString& theValue )
557 if ( theControl && !theValue.isNull() ) {
558 if ( qobject_cast<SalomeApp_DoubleSpinBox*>( theControl ))
559 qobject_cast<SalomeApp_DoubleSpinBox*>( theControl )->setValue( theValue.toDouble() );
560 else if ( qobject_cast<SalomeApp_IntSpinBox*>( theControl ))
561 qobject_cast<SalomeApp_IntSpinBox*>( theControl )->setValue( theValue.toInt() );
562 else if ( qobject_cast<QComboBox*>( theControl ))
563 qobject_cast<QComboBox*>( theControl )->setEditText( theValue );
564 else if ( qobject_cast<QCheckBox*>( theControl ))
565 qobject_cast<QCheckBox*>( theControl )->setChecked( theValue.toInt() != 0 );
569 //=================================================================================
570 // function : getValue()
571 // purpose : get value in the proper way
572 //=================================================================================
573 QString RepairGUI_ShapeProcessDlg::getValue( QWidget* theControl ) const
576 if ( qobject_cast<SalomeApp_DoubleSpinBox*>( theControl )) {
577 if ( ( theControl == myDropSmallSolidsWidTol || theControl == myDropSmallSolidsVolTol ) && !theControl->isEnabled() ) {
578 // VSR: stupid workaround about ShapeProcessAPI:
579 // specific processing for optional parameters of DropSmallSolids operator
580 return QString::number( Precision::Infinite() );
582 return QString::number( qobject_cast<SalomeApp_DoubleSpinBox*>( theControl )->value() );
584 else if ( qobject_cast<SalomeApp_IntSpinBox*>( theControl )) {
585 return QString::number( qobject_cast<SalomeApp_IntSpinBox*>( theControl )->value() );
587 else if ( qobject_cast<QComboBox*>( theControl )) {
588 return qobject_cast<QComboBox*>( theControl )->currentText();
590 else if ( qobject_cast<QCheckBox*>( theControl )) {
591 return qobject_cast<QCheckBox*>( theControl )->isChecked() ? "1" : "0";
597 //=================================================================================
598 // function : getText()
599 // purpose : get text in the proper way
600 //=================================================================================
601 QString RepairGUI_ShapeProcessDlg::getText( QWidget* theControl ) const
604 if ( qobject_cast<SalomeApp_DoubleSpinBox*>( theControl ))
605 return qobject_cast<SalomeApp_DoubleSpinBox*>( theControl )->text();
606 else if ( qobject_cast<SalomeApp_IntSpinBox*>( theControl ))
607 return qobject_cast<SalomeApp_IntSpinBox*>( theControl )->text();
609 return QString::null;
612 //=================================================================================
613 // function : createOperation
615 //=================================================================================
616 GEOM::GEOM_IOperations_ptr RepairGUI_ShapeProcessDlg::createOperation()
618 return getGeomEngine()->GetIHealingOperations();
621 //=================================================================================
622 // function : isValid
624 //=================================================================================
625 bool RepairGUI_ShapeProcessDlg::isValid( QString& msg )
628 QMapIterator<QString,QStringList> aMapIter( myValMap );
629 while( aMapIter.hasNext() ) {
631 const QStringList& aList = aMapIter.value();
632 QListIterator<QString> aListIter( aList );
633 while( aListIter.hasNext() ) {
634 const QString& aParam = aListIter.next();
635 QWidget* aControl = getControl( aParam );
636 if ( !aControl->isEnabled() ) continue;
637 if ( qobject_cast<SalomeApp_DoubleSpinBox*>( aControl ))
638 ok = qobject_cast<SalomeApp_DoubleSpinBox*>( aControl )->isValid( msg, !IsPreview() ) && ok;
639 else if ( qobject_cast<SalomeApp_IntSpinBox*>( aControl ))
640 ok = qobject_cast<SalomeApp_IntSpinBox*>( aControl )->isValid( msg, !IsPreview() ) && ok;
645 GEOM::string_array_var anOperators = getActiveOperators();
646 if ( !myObjects->length() ) {
647 msg += tr( "ERROR_NO_OBJECTS" );
650 if ( !anOperators->length() ) {
653 msg += tr( "ERROR_NO_OPERATORS" );
659 //=================================================================================
660 // function : execute
662 //=================================================================================
663 bool RepairGUI_ShapeProcessDlg::execute( ObjectList& objects )
665 GEOM::string_array_var anOperators = getActiveOperators();
666 GEOM::string_array_var aParams = getParameters( anOperators );
667 GEOM::string_array_var aValues = getValues( aParams );
671 MESSAGE("Objects : ");
672 for ( z = 0; z < myObjects->length(); z++ )
673 MESSAGE(myObjects[z]->GetName() << " ");
674 MESSAGE("\nOperators : ");
675 for ( z = 0; z < anOperators->length(); z++ )
676 MESSAGE(anOperators[z] << " ");
677 MESSAGE("\nParameters : ");
678 for ( z = 0; z < aParams->length(); z++ )
679 MESSAGE(aParams[z] << " ");
680 MESSAGE("\nValues : ");
681 for ( z = 0; z < aValues->length(); z ++ )
682 MESSAGE(aValues[z] << " ");
686 QStringList anErrorObjNames;
687 for ( int i = 0; i < myObjects->length(); i++ ) {
688 GEOM::GEOM_Object_var obj = myObjects[i];
689 GEOM::GEOM_IHealingOperations_var anOper = GEOM::GEOM_IHealingOperations::_narrow( getOperation() );
690 GEOM::GEOM_Object_var anObj = anOper->ProcessShape( obj, anOperators, aParams, aValues );
691 if ( anObj->_is_nil() )
692 anErrorObjNames << GEOMBase::GetName( obj );
697 QStringList aParameters;
699 for ( int i = 0; i < anOperators->length(); i++ )
700 aParameters << QString( anOperators[i] );
702 for ( int i = 0; i < aParams->length(); i++ )
703 aParameters << QString( aParams[i] );
705 aParameters << getTexts( aParams );
706 anObj->SetParameters(aParameters.join(":").toUtf8().constData());
708 RepairGUI::ShowStatistics( anOper, this );
710 objects.push_back( anObj._retn() );
714 if ( !anErrorObjNames.empty() )
715 MESSAGE( "ERRORS occurred while processing the following objects: " << anErrorObjNames.join( " " ).toLatin1().data() );
717 return anErrorObjNames.size() < myObjects->length(); // true if at least one object was OK, false if ALL objects were nil after Healing.
720 //=================================================================================
721 // function : getActiveOperators
723 //=================================================================================
724 GEOM::string_array* RepairGUI_ShapeProcessDlg::getActiveOperators()
726 GEOM::string_array_var anOperators = new GEOM::string_array();
728 int j = 0, n = myOpList->count();
729 anOperators->length( n );
730 for ( int i = 0; i < n; i++ ) {
731 if ( myOpList->item( i )->checkState() == Qt::Checked )
732 anOperators[j++] = myOpList->item( i )->text().toLatin1().constData();
734 anOperators->length( j );
736 return anOperators._retn();
739 //=================================================================================
740 // function : getcontrol
742 //=================================================================================
743 QWidget* RepairGUI_ShapeProcessDlg::getControl( const QString& theParam )
745 if ( theParam == "SplitAngle.Angle" ) return mySplitAngleAngle;
746 else if ( theParam == "SplitAngle.MaxTolerance" ) return mySplitAngleMaxTol;
747 else if ( theParam == "SplitClosedFaces.NbSplitPoints" ) return mySplitClosedFacesNum;
748 else if ( theParam == "FixFaceSize.Tolerance" ) return myFixFaceSizeTol;
749 else if ( theParam == "DropSmallEdges.Tolerance3d" ) return myDropSmallEdgesTol3D;
750 else if ( theParam == "DropSmallSolids.WidthFactorThreshold" ) return myDropSmallSolidsWidTol;
751 else if ( theParam == "DropSmallSolids.VolumeThreshold" ) return myDropSmallSolidsVolTol;
752 else if ( theParam == "DropSmallSolids.MergeSolids" ) return myDropSmallSolidsMergeChk;
753 else if ( theParam == "BSplineRestriction.SurfaceMode" ) return myBSplineSurfModeChk;
754 else if ( theParam == "BSplineRestriction.Curve3dMode" ) return myBSpline3DCurveChk;
755 else if ( theParam == "BSplineRestriction.Curve2dMode" ) return myBSpline2DCurveChk;
756 else if ( theParam == "BSplineRestriction.Tolerance3d" ) return myBSplineTol3D;
757 else if ( theParam == "BSplineRestriction.Tolerance2d" ) return myBSplineTol2D;
758 else if ( theParam == "BSplineRestriction.RequiredDegree" ) return myBSplineDegree;
759 else if ( theParam == "BSplineRestriction.RequiredNbSegments" ) return myBSplineSegments;
760 else if ( theParam == "BSplineRestriction.Continuity3d" ) return myBSpline3DCont;
761 else if ( theParam == "BSplineRestriction.Continuity2d" ) return myBSpline2DCont;
762 else if ( theParam == "SplitContinuity.Tolerance3d" ) return mySplitContTol3D;
763 else if ( theParam == "SplitContinuity.SurfaceContinuity" ) return mySplitContSurfCont;
764 else if ( theParam == "SplitContinuity.CurveContinuity" ) return mySplitContCurvCont;
765 else if ( theParam == "ToBezier.SurfaceMode" ) return myToBezierSurfModeChk;
766 else if ( theParam == "ToBezier.Curve3dMode" ) return myToBezier3DCurveChk;
767 else if ( theParam == "ToBezier.Curve2dMode" ) return myToBezier2DCurveChk;
768 else if ( theParam == "ToBezier.MaxTolerance" ) return myToBezierMaxTol;
769 else if ( theParam == "SameParameter.Tolerance3d" ) return mySameParameterTol3D;
770 else if ( theParam == "FixShape.Tolerance3d" ) return myFixShapeTol3D;
771 else if ( theParam == "FixShape.MaxTolerance3d" ) return myFixShapeMaxTol3D;
775 //=================================================================================
776 // function : getParameters
778 //=================================================================================
779 void RepairGUI_ShapeProcessDlg::initParamsValues()
781 if ( myOpLst.count() )
782 return; // already filled
784 myOpLst << "FixShape";
785 myValMap["FixShape"] << "FixShape.Tolerance3d";
786 myValMap["FixShape"] << "FixShape.MaxTolerance3d";
788 myOpLst << "FixFaceSize";
789 myValMap["FixFaceSize"] << "FixFaceSize.Tolerance";
791 myOpLst << "DropSmallEdges";
792 myValMap["DropSmallEdges"] << "DropSmallEdges.Tolerance3d";
794 myOpLst << "DropSmallSolids";
795 myValMap["DropSmallSolids"] << "DropSmallSolids.WidthFactorThreshold";
796 myValMap["DropSmallSolids"] << "DropSmallSolids.VolumeThreshold";
797 myValMap["DropSmallSolids"] << "DropSmallSolids.MergeSolids";
799 myOpLst << "SplitAngle";
800 myValMap["SplitAngle"] << "SplitAngle.Angle";
801 myValMap["SplitAngle"] << "SplitAngle.MaxTolerance";
803 myOpLst << "SplitClosedFaces";
804 myValMap["SplitClosedFaces"] << "SplitClosedFaces.NbSplitPoints";
806 myOpLst << "SplitContinuity";
807 myValMap["SplitContinuity"] << "SplitContinuity.Tolerance3d";
808 myValMap["SplitContinuity"] << "SplitContinuity.SurfaceContinuity";
809 myValMap["SplitContinuity"] << "SplitContinuity.CurveContinuity";
811 myOpLst << "BSplineRestriction";
812 myValMap["BSplineRestriction"] << "BSplineRestriction.SurfaceMode";
813 myValMap["BSplineRestriction"] << "BSplineRestriction.Curve3dMode";
814 myValMap["BSplineRestriction"] << "BSplineRestriction.Curve2dMode";
815 myValMap["BSplineRestriction"] << "BSplineRestriction.Tolerance3d";
816 myValMap["BSplineRestriction"] << "BSplineRestriction.Tolerance2d";
817 myValMap["BSplineRestriction"] << "BSplineRestriction.RequiredDegree";
818 myValMap["BSplineRestriction"] << "BSplineRestriction.RequiredNbSegments";
819 myValMap["BSplineRestriction"] << "BSplineRestriction.Continuity3d";
820 myValMap["BSplineRestriction"] << "BSplineRestriction.Continuity2d";
822 myOpLst << "ToBezier";
823 myValMap["ToBezier"] << "ToBezier.SurfaceMode";
824 myValMap["ToBezier"] << "ToBezier.Curve3dMode";
825 myValMap["ToBezier"] << "ToBezier.Curve2dMode";
826 myValMap["ToBezier"] << "ToBezier.MaxTolerance";
828 myOpLst << "SameParameter";
829 myValMap["SameParameter"] << "SameParameter.Tolerance3d";
832 //=================================================================================
833 // function : getParameters
835 //=================================================================================
836 GEOM::string_array* RepairGUI_ShapeProcessDlg::getParameters( const GEOM::string_array& theOperators )
838 GEOM::string_array_var aParams = new GEOM::string_array();
841 // calculate the length of parameters
842 for ( i = 0, j = 0; i < theOperators.length(); i++ )
843 j += myValMap[ QString( theOperators[i].in() ) ].size();
845 // set the new length of parameters
846 aParams->length( j );
848 // fill the parameters
849 for ( i = 0, j = 0; i < theOperators.length(); i++ ) {
850 QStringList aParamLst = myValMap[ QString( theOperators[i].in() ) ];
851 foreach ( QString aParam, aParamLst ) {
852 aParams[j++] = CORBA::string_dup( aParam.toLatin1().constData() );
856 aParams->length( j );
858 return aParams._retn();
862 //=================================================================================
863 // function : getValues
865 //=================================================================================
866 GEOM::string_array* RepairGUI_ShapeProcessDlg::getValues( const GEOM::string_array& theParams )
868 GEOM::string_array_var aValues = new GEOM::string_array();
869 aValues->length( theParams.length() );
871 for ( int i = 0; i < theParams.length(); i++ ) {
872 QWidget* aCtrl = getControl( (const char*)theParams[i] );
874 aValues[i] = get_convert( (const char*)theParams[i], getValue( aCtrl ));
877 return aValues._retn();
880 //=================================================================================
881 // function : getTexts
883 //=================================================================================
884 QStringList RepairGUI_ShapeProcessDlg::getTexts( const GEOM::string_array& theParams )
888 for ( int i = 0; i < theParams.length(); i++ ) {
889 QWidget* aCtrl = getControl( (const char*)theParams[i] );
892 QString aText = getText( aCtrl );
893 if( !aText.isNull() )
894 aTexts.append( aText );
901 //=================================================================================
902 // function : initSelection
903 // purpose : set selection of ALL shape types except vertexes
904 //=================================================================================
905 void RepairGUI_ShapeProcessDlg::initSelection()
907 TColStd_MapOfInteger aTypes;
908 aTypes.Add( GEOM_COMPOUND );
909 aTypes.Add( GEOM_SOLID );
910 aTypes.Add( GEOM_SHELL );
911 aTypes.Add( GEOM_FACE );
912 aTypes.Add( GEOM_WIRE );
913 aTypes.Add( GEOM_EDGE );
914 globalSelection( aTypes );
917 //=================================================================================
918 // function : advOptionToggled
919 // purpose : this slot is used to warn the user about possible consequences
920 // of enabling some advanced options
921 //=================================================================================
922 void RepairGUI_ShapeProcessDlg::advOptionToggled( bool on )
924 QAbstractButton* btn = (QAbstractButton*)sender();
925 if ( btn == myToBezierSurfModeChk )
927 if ( on && btn->isCheckable() &&
928 SUIT_MessageBox::warning( this,
929 tr( "GEOM_WRN_WARNING" ), tr( "TIME_CONSUMING" ),
930 SUIT_MessageBox::Yes | SUIT_MessageBox::No ) == SUIT_MessageBox::No )
934 // either myDropSmallSolidsWidChk or myDropSmallSolidsVolChk must be checked
935 if ( btn == myDropSmallSolidsWidChk )
937 myDropSmallSolidsWidTol->setEnabled( on );
939 myDropSmallSolidsVolChk->setChecked( true );
940 myDropSmallSolidsVolTol->setEnabled( true );
943 if ( btn == myDropSmallSolidsVolChk )
945 myDropSmallSolidsVolTol->setEnabled( on );
947 myDropSmallSolidsWidChk->setChecked( true );
948 myDropSmallSolidsWidTol->setEnabled( true );
953 //=======================================================================
954 //function : operatorChecked
955 //purpose : show parameters of a selected operator
956 //=======================================================================
958 void RepairGUI_ShapeProcessDlg::operatorChecked( QListWidgetItem * item )
960 if ( item && item->checkState() == Qt::Checked )
962 item->setSelected(true);
963 myStack->setCurrentIndex( myOpList->row( item ));
968 void RepairGUI_ShapeProcessDlg::updateSelectAll()
970 Qt::CheckState state = myOpList->count() > 0 ? myOpList->item(0)->checkState() : Qt::Unchecked;
971 for ( int i = 1; i < myOpList->count(); i++ ) {
972 if ( myOpList->item(i)->checkState() != state ) {
973 state = Qt::PartiallyChecked;
977 mySelectAll->blockSignals( true );
978 mySelectAll->setCheckState( state );
979 mySelectAll->blockSignals( false );
982 void RepairGUI_ShapeProcessDlg::onSelectAll( int state )
984 if ( state == Qt::PartiallyChecked ) {
985 mySelectAll->setCheckState( Qt::Checked );
988 myOpList->blockSignals( true );
989 for ( int i = 0; i < myOpList->count(); i++ ) {
990 myOpList->item(i)->setCheckState( (Qt::CheckState)state );
992 myOpList->blockSignals( false );
995 //=================================================================================
996 // function : getSourceObjects
997 // purpose : virtual method to get source objects
998 //=================================================================================
999 QList<GEOM::GeomObjPtr> RepairGUI_ShapeProcessDlg::getSourceObjects()
1001 QList<GEOM::GeomObjPtr> res;
1002 GEOM::ListOfGO aListPtr(myObjects);
1003 for (int i = 0; i < aListPtr.length(); i++) {
1004 GEOM::GeomObjPtr aGeomObjPtr(aListPtr[i]);