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>
46 #include <TCollection_AsciiString.hxx>
47 #include <TColStd_MapOfInteger.hxx>
49 #include <QListWidget>
50 #include <QStackedLayout>
52 //=================================================================================
53 // class : RepairGUI_ShapeProcessDlg()
54 // purpose : Constructs a RepairGUI_ShapeProcessDlg which is a child of 'parent', with the
55 // name 'name' and widget flags set to 'f'.
56 // The dialog will by default be modeless, unless you set 'modal' to
57 // TRUE to construct a modal dialog.
58 //=================================================================================
59 RepairGUI_ShapeProcessDlg::RepairGUI_ShapeProcessDlg( GeometryGUI* theGeometryGUI, QWidget* parent,
61 : GEOMBase_Skeleton( theGeometryGUI, parent, modal )
63 setHelpFileName( "shape_processing_operation_page.html" );
67 //=================================================================================
68 // function : ~RepairGUI_ShapeProcessDlg()
69 // purpose : Destroys the object and frees any allocated resources
70 //=================================================================================
71 RepairGUI_ShapeProcessDlg::~RepairGUI_ShapeProcessDlg()
75 //=================================================================================
78 //=================================================================================
79 void RepairGUI_ShapeProcessDlg::init()
81 //myGeomGUI->SetState( 0 );
86 setWindowTitle( tr( "GEOM_SHAPEPROCESS_TITLE" ));
88 mainFrame()->GroupConstructors->hide();
90 // select widget on the top
91 mySelectWdgt = new DlgRef_1Sel( centralWidget() );
92 mySelectWdgt->GroupBox1->setTitle( tr( "GEOM_SHAPE" ));
93 mySelectWdgt->TextLabel1->setText( tr( "GEOM_SELECTED_OBJECTS" ));
94 mySelectWdgt->PushButton1->setIcon( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_SELECT" )));
95 mySelectWdgt->LineEdit1->setReadOnly( true );
97 // layout the two group boxes in the middle, add a list of operations
98 QGroupBox* anOperGr = new QGroupBox( tr( "GEOM_OPERATIONS" ), centralWidget() );
100 // operations list widget
101 myOpList = new QListWidget( anOperGr );
102 myOpList->setSortingEnabled( false );
103 myOpList->setSizePolicy( QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Expanding ));
105 QVBoxLayout* aOperLay = new QVBoxLayout( anOperGr );
106 aOperLay->setMargin( 9 );
107 aOperLay->addWidget( myOpList );
109 QGroupBox* aParamsGr = new QGroupBox( tr( "GEOM_PARAMETERS" ), centralWidget() );
111 // add a widget stack to the parameters group box
112 myStack = new QStackedLayout( aParamsGr );
114 // continueties values..
115 QStringList aContinueties = QString( "C0,G1,C1,G2,C2,C3,CN" ).split( "," );
117 // fill in the widgets
118 for ( int i = 0; i < myOpLst.count(); i++ ) {
119 QListWidgetItem* item = new QListWidgetItem( myOpLst[i] );
120 item->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsUserCheckable );
121 item->setCheckState( Qt::Unchecked );
122 myOpList->addItem( item );
125 if ( myOpLst[i] == "FixShape" ) {
127 w = new QWidget( aParamsGr );
128 QGridLayout* aLay = new QGridLayout( w );
129 aLay->setMargin( 9 ); aLay->setSpacing( 6 );
131 myFixShapeTol3D = new SalomeApp_DoubleSpinBox( w );
132 initSpinBox( myFixShapeTol3D, 0., 100., 1e-7, "len_tol_precision" );
133 myFixShapeMaxTol3D = new SalomeApp_DoubleSpinBox( w );
134 initSpinBox( myFixShapeMaxTol3D, 0., 100., 1e-7, "len_tol_precision" );
136 aLay->addWidget( new QLabel( tr( "GEOM_3D_TOLERANCE" ), w ), 0, 0 );
137 aLay->addWidget( myFixShapeTol3D, 0, 1 );
138 aLay->addWidget( new QLabel( tr( "GEOM_MAX_3D_TOLERANCE" ), w ), 1, 0 );
139 aLay->addWidget( myFixShapeMaxTol3D, 1, 1 );
140 aLay->setRowStretch( aLay->rowCount(), 5 );
142 else if ( myOpLst[i] == "FixFaceSize" ) {
144 w = new QWidget( aParamsGr );
145 QGridLayout* aLay = new QGridLayout( w );
146 aLay->setMargin( 9 ); aLay->setSpacing( 6 );
148 myFixFaceSizeTol = new SalomeApp_DoubleSpinBox( w );
149 initSpinBox( myFixFaceSizeTol, 0., 100., 1e-7, "len_tol_precision" );
151 aLay->addWidget( new QLabel( tr( "GEOM_TOLERANCE" ), w ), 0, 0 );
152 aLay->addWidget( myFixFaceSizeTol, 0, 1 );
153 aLay->setRowStretch( aLay->rowCount(), 5 );
155 else if ( myOpLst[i] == "DropSmallSolids" ) {
157 w = new QWidget( aParamsGr );
158 QGridLayout* aLay = new QGridLayout( w );
159 aLay->setMargin( 9 ); aLay->setSpacing( 6 );
161 myDropSmallSolidsWidChk = new QCheckBox( tr("WIDTH_FACTOR_TOL"), w );
162 myDropSmallSolidsVolChk = new QCheckBox( tr("VOLUME_TOL"), w );
163 myDropSmallSolidsWidTol = new SalomeApp_DoubleSpinBox( w );
164 myDropSmallSolidsVolTol = new SalomeApp_DoubleSpinBox( w );
165 initSpinBox( myDropSmallSolidsWidTol, 0., 100., 1e-7, "len_tol_precision" );
166 initSpinBox( myDropSmallSolidsVolTol, 0., 100., 1e-7, "len_tol_precision" );
167 myDropSmallSolidsWidTol->setValue( 1e-7 );
168 myDropSmallSolidsVolTol->setValue( 1e-7 );
169 myDropSmallSolidsVolChk->setChecked( true );
170 myDropSmallSolidsWidTol->setEnabled( false );
171 myDropSmallSolidsMergeChk = new QCheckBox( tr("TO_MERGE_SOLIDS"), w );
173 aLay->addWidget( myDropSmallSolidsWidChk, 0, 0 );
174 aLay->addWidget( myDropSmallSolidsWidTol, 0, 1 );
175 aLay->addWidget( myDropSmallSolidsVolChk, 1, 0 );
176 aLay->addWidget( myDropSmallSolidsVolTol, 1, 1 );
177 aLay->addWidget( myDropSmallSolidsMergeChk, 2, 0, 1, 2 );
179 aLay->setRowStretch( aLay->rowCount(), 5 );
181 else if ( myOpLst[i] == "DropSmallEdges" ) {
183 w = new QWidget( aParamsGr );
184 QGridLayout* aLay = new QGridLayout( w );
185 aLay->setMargin( 9 ); aLay->setSpacing( 6 );
187 myDropSmallEdgesTol3D = new SalomeApp_DoubleSpinBox( w );
188 initSpinBox( myDropSmallEdgesTol3D, 0., 100., 1e-7, "len_tol_precision" );
190 aLay->addWidget( new QLabel( tr( "GEOM_3D_TOLERANCE" ), w ), 0, 0 );
191 aLay->addWidget( myDropSmallEdgesTol3D, 0, 1 );
192 aLay->setRowStretch( aLay->rowCount(), 5 );
194 else if ( myOpLst[i] == "SplitAngle" ) {
196 w = new QWidget( aParamsGr );
197 QGridLayout* aLay = new QGridLayout( w );
198 aLay->setMargin( 9 ); aLay->setSpacing( 6 );
200 mySplitAngleAngle = new SalomeApp_DoubleSpinBox( w );
201 initSpinBox( mySplitAngleAngle, 0, 360, 1, "angle_precision" );
202 mySplitAngleMaxTol = new SalomeApp_DoubleSpinBox( w );
203 initSpinBox( mySplitAngleMaxTol, 0., 100., 1e-7, "ang_tol_precision" );
205 aLay->addWidget( new QLabel( tr( "GEOM_ANGLE_1" ), w ), 0, 0 );
206 aLay->addWidget( mySplitAngleAngle, 0, 1 );
207 aLay->addWidget( new QLabel( tr( "GEOM_MAX_TOLERANCE" ), w ), 1, 0 );
208 aLay->addWidget( mySplitAngleMaxTol, 1, 1 );
209 aLay->setRowStretch( aLay->rowCount(), 5 );
211 else if ( myOpLst[i] == "SplitClosedFaces" ) {
213 w = new QWidget( aParamsGr );
214 QGridLayout* aLay = new QGridLayout( w );
215 aLay->setMargin( 9 ); aLay->setSpacing( 6 );
217 mySplitClosedFacesNum = new SalomeApp_IntSpinBox( w );
219 aLay->addWidget( new QLabel( tr( "GEOM_NUM_SPLIT_POINTS" ), w ), 0, 0 );
220 aLay->addWidget( mySplitClosedFacesNum, 0, 1 );
221 aLay->setRowStretch( aLay->rowCount(), 5 );
223 else if ( myOpLst[i] == "SplitContinuity" ) {
225 w = new QWidget( aParamsGr );
226 QGridLayout* aLay = new QGridLayout( w );
227 aLay->setMargin( 9 ); aLay->setSpacing( 6 );
229 mySplitContTol3D = new SalomeApp_DoubleSpinBox( w );
230 initSpinBox( mySplitContTol3D, 0., 100., 1e-7, "len_tol_precision" );
231 mySplitContSurfCont = new QComboBox( w );
232 mySplitContSurfCont->addItems( aContinueties );
233 mySplitContCurvCont = new QComboBox( w );
234 mySplitContCurvCont->addItems( aContinueties );
236 aLay->addWidget( new QLabel( tr( "GEOM_3D_TOLERANCE" ), w ), 0, 0 );
237 aLay->addWidget( mySplitContTol3D, 0, 1 );
238 aLay->addWidget( new QLabel( tr( "GEOM_SURFACE_CONTINUTY" ), w ), 1, 0 );
239 aLay->addWidget( mySplitContSurfCont, 1, 1 );
240 aLay->addWidget( new QLabel( tr( "GEOM_CURVE_CONTINUTY" ), w ), 2, 0 );
241 aLay->addWidget( mySplitContCurvCont, 2, 1 );
242 aLay->setRowStretch( aLay->rowCount(), 5 );
244 else if ( myOpLst[i] == "BSplineRestriction" ) {
245 // BSplineRestriction
246 w = new QWidget( aParamsGr );
247 QGridLayout* aLay = new QGridLayout( w );
248 aLay->setMargin( 9 ); aLay->setSpacing( 6 );
250 myBSplineSurfModeChk = new QCheckBox( tr("GEOM_SURFACE_MODE"), w );
251 myBSpline3DCurveChk = new QCheckBox( tr("GEOM_3D_CURVE_MODE"), w );
252 myBSpline2DCurveChk = new QCheckBox( tr("GEOM_2D_CURVE_MODE"), w );
254 myBSplineTol3D = new SalomeApp_DoubleSpinBox( w );
255 initSpinBox( myBSplineTol3D, 0., 100., 1e-7, "len_tol_precision" );
257 myBSplineTol2D = new SalomeApp_DoubleSpinBox( w );
258 initSpinBox( myBSplineTol2D, 0., 100., 1e-7, "param_tol_precision" );
260 myBSplineDegree = new SalomeApp_IntSpinBox( w );
261 myBSplineSegments = new SalomeApp_IntSpinBox( w );
262 myBSpline2DCont = new QComboBox( w );
263 myBSpline2DCont->addItems( aContinueties );
264 myBSpline3DCont = new QComboBox( w );
265 myBSpline3DCont->addItems( aContinueties );
267 myBSplineSurfModeChk->setChecked( true );
268 myBSpline3DCurveChk->setChecked( true );
269 myBSpline2DCurveChk->setChecked( true );
271 aLay->addWidget( myBSplineSurfModeChk, 0, 0 );
272 aLay->addWidget( myBSpline3DCurveChk, 1, 0 );
273 aLay->addWidget( myBSpline2DCurveChk, 2, 0 );
274 aLay->addWidget( new QLabel( tr( "GEOM_3D_TOLERANCE" ), w ), 3, 0 );
275 aLay->addWidget( myBSplineTol3D, 3, 1 );
276 aLay->addWidget( new QLabel( tr( "GEOM_2D_TOLERANCE" ), w ), 4, 0 );
277 aLay->addWidget( myBSplineTol2D, 4, 1 );
278 aLay->addWidget( new QLabel( tr( "GEOM_REQUIRED_DEGREE" ), w ), 5, 0 );
279 aLay->addWidget( myBSplineDegree, 5, 1 );
280 aLay->addWidget( new QLabel( tr( "GEOM_REQUIRED_NUM_SEGMENTS" ), w ), 6, 0 );
281 aLay->addWidget( myBSplineSegments, 6, 1 );
282 aLay->addWidget( new QLabel( tr( "GEOM_3D_CONTINUTY" ), w ), 7, 0 );
283 aLay->addWidget( myBSpline3DCont, 7, 1 );
284 aLay->addWidget( new QLabel( tr( "GEOM_2D_CONTINUTY" ), w ), 8, 0 );
285 aLay->addWidget( myBSpline2DCont, 8, 1 );
286 aLay->setRowStretch( aLay->rowCount(), 5 );
288 else if ( myOpLst[i] == "ToBezier" ) {
290 w = new QWidget( aParamsGr );
291 QGridLayout* aLay = new QGridLayout( w );
292 aLay->setMargin( 9 ); aLay->setSpacing( 6 );
294 myToBezierSurfModeChk = new QCheckBox( tr("GEOM_SURFACE_MODE"), w );
295 myToBezier3DCurveChk = new QCheckBox( tr("GEOM_3D_CURVE_MODE"), w );
296 myToBezier2DCurveChk = new QCheckBox( tr("GEOM_2D_CURVE_MODE"), w );
298 myToBezierMaxTol = new SalomeApp_DoubleSpinBox( w );
299 initSpinBox( myToBezierMaxTol, 0., 100., 1e-7, "len_tol_precision" );
301 aLay->addWidget( myToBezierSurfModeChk, 0, 0 );
302 aLay->addWidget( myToBezier3DCurveChk, 1, 0 );
303 aLay->addWidget( myToBezier2DCurveChk, 2, 0 );
304 aLay->addWidget( new QLabel( tr( "GEOM_MAX_TOLERANCE" ), w ), 3, 0 );
305 aLay->addWidget( myToBezierMaxTol, 3, 1 );
306 aLay->setRowStretch( aLay->rowCount(), 5 );
308 else if ( myOpLst[i] == "SameParameter" ) {
310 w = new QWidget( aParamsGr );
311 QGridLayout* aLay = new QGridLayout( w );
312 aLay->setMargin( 9 ); aLay->setSpacing( 6 );
314 mySameParameterTol3D = new SalomeApp_DoubleSpinBox( w );
315 initSpinBox( mySameParameterTol3D, 0., 100., 1e-7, "len_tol_precision" );
317 aLay->addWidget( new QLabel( tr( "GEOM_3D_TOLERANCE" ), w ), 0, 0 );
318 aLay->addWidget( mySameParameterTol3D, 0, 1 );
319 aLay->setRowStretch( aLay->rowCount(), 5 );
322 w = new QWidget( aParamsGr ); // dumb widget
324 myStack->insertWidget( i, w );
327 QGridLayout* layout = new QGridLayout( centralWidget() );
328 layout->setMargin( 0 ); layout->setSpacing( 6 );
329 layout->addWidget( mySelectWdgt, 0, 0, 1, 2 );
330 layout->addWidget( anOperGr, 1, 0 );
331 layout->addWidget( aParamsGr, 1, 1 );
333 // signals and slots connections
334 connect( buttonOk(), SIGNAL( clicked() ), this, SLOT( onOk() ));
335 connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( onApply() ));
337 connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ))->selectionMgr(),
338 SIGNAL( currentSelectionChanged() ), this, SLOT( selectionChanged() ));
340 connect( mySelectWdgt->PushButton1, SIGNAL( clicked() ), this, SLOT( selectClicked() ));
341 connect( mySelectWdgt->LineEdit1, SIGNAL( returnPressed() ), this, SLOT( lineEditReturnPressed() ));
343 connect( myToBezierSurfModeChk, SIGNAL( toggled( bool )), this, SLOT( advOptionToggled( bool )));
344 connect( myDropSmallSolidsWidChk, SIGNAL( toggled( bool )), this, SLOT( advOptionToggled( bool )));
345 connect( myDropSmallSolidsVolChk, SIGNAL( toggled( bool )), this, SLOT( advOptionToggled( bool )));
347 connect( myOpList, SIGNAL( currentRowChanged( int )), myStack, SLOT( setCurrentIndex( int )));
348 connect( myOpList, SIGNAL( itemChanged( QListWidgetItem* )), this, SLOT( operatorChecked( QListWidgetItem* )));
351 loadDefaults(); // init dialog fields with values from resource file
352 //myOpList->setCurrentRow( myOpList->findItem( 0 );
355 myStack->setCurrentIndex( 0 );
357 initName( tr( "PROCESS_SHAPE_NEW_OBJ_NAME" ));
361 //=================================================================================
363 // purpose : Same than click on apply but close this dialog.
364 //=================================================================================
365 void RepairGUI_ShapeProcessDlg::onOk()
367 setIsApplyAndClose( true );
372 //=================================================================================
373 // function : onApply()
375 //=================================================================================
376 bool RepairGUI_ShapeProcessDlg::onApply()
390 //=================================================================================
391 // function : selectionChanged()
392 // purpose : Called when selection as changed or other case
393 // : used only by SelectButtonC1A1 (LineEditC1A1)
394 //=================================================================================
395 void RepairGUI_ShapeProcessDlg::selectionChanged()
399 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
400 SALOME_ListIO aSelList;
401 aSelMgr->selectedObjects(aSelList);
404 myObjects->length(aSelList.Extent());
405 for (SALOME_ListIteratorOfListIO anIt (aSelList); anIt.More(); anIt.Next()) {
406 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( anIt.Value() );
407 if ( !CORBA::is_nil( aSelectedObject ))
408 myObjects[i++] = aSelectedObject;
410 myObjects->length( i );
412 mySelectWdgt->LineEdit1->setText( GEOMBase::GetName( myObjects[0] ));
414 mySelectWdgt->LineEdit1->setText( QString::number( i ) + "_" + tr( "GEOM_OBJECTS" ));
418 //=================================================================================
419 // function : selectClicked()
421 //=================================================================================
422 void RepairGUI_ShapeProcessDlg::selectClicked()
424 myEditCurrentArgument = mySelectWdgt->LineEdit1;
425 mySelectWdgt->LineEdit1->setFocus();
430 //=================================================================================
431 // function : lineEditReturnPressed()
433 //=================================================================================
434 void RepairGUI_ShapeProcessDlg::lineEditReturnPressed()
436 GEOMBase_Skeleton::LineEditReturnPressed();
440 //=================================================================================
441 // function : activate()
443 //=================================================================================
444 void RepairGUI_ShapeProcessDlg::activate()
446 GEOMBase_Skeleton::ActivateThisDialog();
447 connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication( )))->selectionMgr(),
448 SIGNAL( currentSelectionChanged() ), this, SLOT( selectionChanged() ));
451 //myGeomGUI->SetState( 0 );
456 //=================================================================================
457 // function : enterEvent()
458 // purpose : Mouse enter onto the dialog to activate it
459 //=================================================================================
460 void RepairGUI_ShapeProcessDlg::enterEvent( QEvent* )
462 if ( !mainFrame()->GroupBoxName->isEnabled() )
467 //=================================================================================
468 // function : reset()
469 // purpose : Completely reset the state of method including local context
470 //=================================================================================
471 void RepairGUI_ShapeProcessDlg::reset()
473 myObjects = new GEOM::ListOfGO();
474 myObjects->length( 0 );
475 mySelectWdgt->LineEdit1->setText( "" );
479 //=================================================================================
480 // function : get_convert
481 // purpose : conversion of angle values to radians (non-angle values are not converted)
482 //=================================================================================
483 const char* get_convert( const char* theParam, const QString& theValue )
485 if ( !strcmp( theParam, "SplitAngle.Angle" )) {
486 double doubleValue = theValue.toDouble() * M_PI / 180.;
487 return CORBA::string_dup( QString::number( doubleValue ).toLatin1().constData() );
489 return CORBA::string_dup( theValue.toLatin1().constData() );
492 //=================================================================================
493 // function : set_convert
494 // purpose : conversion of angle values to degrees (non-angle values are not converted)
495 //=================================================================================
496 QString set_convert( const char* theParam, const char* theValue )
498 if ( !strcmp( theParam, "SplitAngle.Angle" )) {
499 Kernel_Utils::Localizer loc;
500 double doubleValue = atof( theValue ) * 180. / M_PI;
501 return QString::number( doubleValue );
503 return QString( theValue );
506 //=================================================================================
507 // function : loadDefaults()
508 // purpose : initialize "values"-fields with default values retrieved from IHealingOperations
509 //=================================================================================
510 void RepairGUI_ShapeProcessDlg::loadDefaults()
512 GEOM::GEOM_IHealingOperations_var anOp = myGeomGUI->GetGeomGen()->GetIHealingOperations( getStudyId() );
513 GEOM::string_array_var anOperators, aParams, aValues;
514 anOp->GetShapeProcessParameters( anOperators, aParams, aValues );
516 // check the default items-operators
517 for ( int i = 0; i < anOperators->length(); i++ ) {
518 //MESSAGE("-->"<<(const char*)anOperators[i]);
519 QList<QListWidgetItem*> items = myOpList->findItems ( (const char*)anOperators[i], Qt::MatchFixedString );
521 ( items[0] )->setCheckState( Qt::Checked );
524 // Retrieve default parameters for ALL operators
525 for ( int i = 0; i < myOpList->count(); i++ )
527 QString anOperator = myOpList->item( i )->text();
528 anOp->GetOperatorParameters( anOperator.toLatin1().constData(), aParams, aValues );
530 // set default values of parameters
531 if ( aParams->length() != aValues->length() )
534 for ( int j = 0; j < aParams->length(); j++ ) {
535 QWidget* aCtrl = getControl( (const char*)aParams[j] );
536 setValue( aCtrl, set_convert( (const char*)aParams[j], aValues[j] ));
541 //=================================================================================
542 // function : setValue()
543 // purpose : set value in the proper way
544 //=================================================================================
545 void RepairGUI_ShapeProcessDlg::setValue( QWidget* theControl, const QString& theValue )
547 if ( theControl && !theValue.isNull() ) {
548 if ( qobject_cast<SalomeApp_DoubleSpinBox*>( theControl ))
549 qobject_cast<SalomeApp_DoubleSpinBox*>( theControl )->setValue( theValue.toDouble() );
550 else if ( qobject_cast<SalomeApp_IntSpinBox*>( theControl ))
551 qobject_cast<SalomeApp_IntSpinBox*>( theControl )->setValue( theValue.toInt() );
552 else if ( qobject_cast<QComboBox*>( theControl ))
553 qobject_cast<QComboBox*>( theControl )->setEditText( theValue );
554 else if ( qobject_cast<QCheckBox*>( theControl ))
555 qobject_cast<QCheckBox*>( theControl )->setChecked( theValue.toInt() != 0 );
559 //=================================================================================
560 // function : getValue()
561 // purpose : get value in the proper way
562 //=================================================================================
563 QString RepairGUI_ShapeProcessDlg::getValue( QWidget* theControl ) const
566 if ( qobject_cast<SalomeApp_DoubleSpinBox*>( theControl ))
567 return QString::number( qobject_cast<SalomeApp_DoubleSpinBox*>( theControl )->value() );
568 else if ( qobject_cast<SalomeApp_IntSpinBox*>( theControl ))
569 return QString::number( qobject_cast<SalomeApp_IntSpinBox*>( theControl )->value() );
570 else if ( qobject_cast<QComboBox*>( theControl ))
571 return qobject_cast<QComboBox*>( theControl )->currentText();
572 else if ( qobject_cast<QCheckBox*>( theControl ))
573 return qobject_cast<QCheckBox*>( theControl )->isChecked() ? "1" : "0";
578 //=================================================================================
579 // function : getText()
580 // purpose : get text in the proper way
581 //=================================================================================
582 QString RepairGUI_ShapeProcessDlg::getText( QWidget* theControl ) const
585 if ( qobject_cast<SalomeApp_DoubleSpinBox*>( theControl ))
586 return qobject_cast<SalomeApp_DoubleSpinBox*>( theControl )->text();
587 else if ( qobject_cast<SalomeApp_IntSpinBox*>( theControl ))
588 return qobject_cast<SalomeApp_IntSpinBox*>( theControl )->text();
590 return QString::null;
593 //=================================================================================
594 // function : createOperation
596 //=================================================================================
597 GEOM::GEOM_IOperations_ptr RepairGUI_ShapeProcessDlg::createOperation()
599 return getGeomEngine()->GetIHealingOperations( getStudyId() );
602 //=================================================================================
603 // function : isValid
605 //=================================================================================
606 bool RepairGUI_ShapeProcessDlg::isValid( QString& msg )
609 QMapIterator<QString,QStringList> aMapIter( myValMap );
610 while( aMapIter.hasNext() ) {
612 const QStringList& aList = aMapIter.value();
613 QListIterator<QString> aListIter( aList );
614 while( aListIter.hasNext() ) {
615 const QString& aParam = aListIter.next();
616 QWidget* aControl = getControl( aParam );
617 if ( !aControl->isEnabled() ) continue;
618 if ( qobject_cast<SalomeApp_DoubleSpinBox*>( aControl ))
619 ok = qobject_cast<SalomeApp_DoubleSpinBox*>( aControl )->isValid( msg, !IsPreview() ) && ok;
620 else if ( qobject_cast<SalomeApp_IntSpinBox*>( aControl ))
621 ok = qobject_cast<SalomeApp_IntSpinBox*>( aControl )->isValid( msg, !IsPreview() ) && ok;
626 GEOM::string_array_var anOperators = getActiveOperators();
627 if ( !myObjects->length() ) {
628 msg += tr( "ERROR_NO_OBJECTS" );
631 if ( !anOperators->length() ) {
634 msg += tr( "ERROR_NO_OPERATORS" );
640 //=================================================================================
641 // function : execute
643 //=================================================================================
644 bool RepairGUI_ShapeProcessDlg::execute( ObjectList& objects )
646 GEOM::string_array_var anOperators = getActiveOperators();
647 GEOM::string_array_var aParams = getParameters( anOperators );
648 GEOM::string_array_var aValues = getValues( aParams );
652 MESSAGE("Objects : ");
653 for ( z = 0; z < myObjects->length(); z++ )
654 MESSAGE(myObjects[z]->GetName() << " ");
655 MESSAGE("\nOperators : ");
656 for ( z = 0; z < anOperators->length(); z++ )
657 MESSAGE(anOperators[z] << " ");
658 MESSAGE("\nParameters : ");
659 for ( z = 0; z < aParams->length(); z++ )
660 MESSAGE(aParams[z] << " ");
661 MESSAGE("\nValues : ");
662 for ( z = 0; z < aValues->length(); z ++ )
663 MESSAGE(aValues[z] << " ");
667 QStringList anErrorObjNames;
668 for ( int i = 0; i < myObjects->length(); i++ ) {
669 GEOM::GEOM_Object_var obj = myObjects[i];
670 GEOM::GEOM_IHealingOperations_var anOper = GEOM::GEOM_IHealingOperations::_narrow( getOperation() );
671 GEOM::GEOM_Object_var anObj = anOper->ProcessShape( obj, anOperators, aParams, aValues );
672 if ( anObj->_is_nil() )
673 anErrorObjNames << GEOMBase::GetName( obj );
678 QStringList aParameters;
680 for ( int i = 0; i < anOperators->length(); i++ )
681 aParameters << QString( anOperators[i] );
683 for ( int i = 0; i < aParams->length(); i++ )
684 aParameters << QString( aParams[i] );
686 aParameters << getTexts( aParams );
687 anObj->SetParameters(aParameters.join(":").toLatin1().constData());
689 RepairGUI::ShowStatistics( anOper, this );
691 objects.push_back( anObj._retn() );
695 if ( !anErrorObjNames.empty() )
696 MESSAGE( "ERRORS occured while processing the following objects: " << anErrorObjNames.join( " " ).toLatin1().data() );
698 return anErrorObjNames.size() < myObjects->length(); // true if at least one object was OK, false if ALL objects were nil after Healing.
701 //=================================================================================
702 // function : getActiveOperators
704 //=================================================================================
705 GEOM::string_array* RepairGUI_ShapeProcessDlg::getActiveOperators()
707 GEOM::string_array_var anOperators = new GEOM::string_array();
708 QStringList aCheckedList;
710 for ( int i = 0; i < myOpList->count(); i++ ) {
711 if ( myOpList->item( i )->checkState() == Qt::Checked )
712 aCheckedList << myOpList->item( i )->text();
715 anOperators->length( aCheckedList.count() );
717 for ( int i = 0; i < aCheckedList.count(); i++ )
718 anOperators[i] = aCheckedList[i].toLatin1().constData();
720 return anOperators._retn();
723 //=================================================================================
724 // function : getcontrol
726 //=================================================================================
727 QWidget* RepairGUI_ShapeProcessDlg::getControl( const QString& theParam )
729 if ( theParam == "SplitAngle.Angle" ) return mySplitAngleAngle;
730 else if ( theParam == "SplitAngle.MaxTolerance" ) return mySplitAngleMaxTol;
731 else if ( theParam == "SplitClosedFaces.NbSplitPoints" ) return mySplitClosedFacesNum;
732 else if ( theParam == "FixFaceSize.Tolerance" ) return myFixFaceSizeTol;
733 else if ( theParam == "DropSmallEdges.Tolerance3d" ) return myDropSmallEdgesTol3D;
734 else if ( theParam == "DropSmallSolids.WidthFactorThreshold" ) return myDropSmallSolidsWidTol;
735 else if ( theParam == "DropSmallSolids.VolumeThreshold" ) return myDropSmallSolidsWidTol;
736 else if ( theParam == "DropSmallSolids.MergeSolids" ) return myDropSmallSolidsMergeChk;
737 else if ( theParam == "BSplineRestriction.SurfaceMode" ) return myBSplineSurfModeChk;
738 else if ( theParam == "BSplineRestriction.Curve3dMode" ) return myBSpline3DCurveChk;
739 else if ( theParam == "BSplineRestriction.Curve2dMode" ) return myBSpline2DCurveChk;
740 else if ( theParam == "BSplineRestriction.Tolerance3d" ) return myBSplineTol3D;
741 else if ( theParam == "BSplineRestriction.Tolerance2d" ) return myBSplineTol2D;
742 else if ( theParam == "BSplineRestriction.RequiredDegree" ) return myBSplineDegree;
743 else if ( theParam == "BSplineRestriction.RequiredNbSegments" ) return myBSplineSegments;
744 else if ( theParam == "BSplineRestriction.Continuity3d" ) return myBSpline3DCont;
745 else if ( theParam == "BSplineRestriction.Continuity2d" ) return myBSpline2DCont;
746 else if ( theParam == "SplitContinuity.Tolerance3d" ) return mySplitContTol3D;
747 else if ( theParam == "SplitContinuity.SurfaceContinuity" ) return mySplitContSurfCont;
748 else if ( theParam == "SplitContinuity.CurveContinuity" ) return mySplitContCurvCont;
749 else if ( theParam == "ToBezier.SurfaceMode" ) return myToBezierSurfModeChk;
750 else if ( theParam == "ToBezier.Curve3dMode" ) return myToBezier3DCurveChk;
751 else if ( theParam == "ToBezier.Curve2dMode" ) return myToBezier2DCurveChk;
752 else if ( theParam == "ToBezier.MaxTolerance" ) return myToBezierMaxTol;
753 else if ( theParam == "SameParameter.Tolerance3d" ) return mySameParameterTol3D;
754 else if ( theParam == "FixShape.Tolerance3d" ) return myFixShapeTol3D;
755 else if ( theParam == "FixShape.MaxTolerance3d" ) return myFixShapeMaxTol3D;
759 //=================================================================================
760 // function : getParameters
762 //=================================================================================
763 void RepairGUI_ShapeProcessDlg::initParamsValues()
765 if ( myOpLst.count() )
766 return; // already filled
768 myOpLst << "FixShape";
769 myValMap["FixShape"] << "FixShape.Tolerance3d";
770 myValMap["FixShape"] << "FixShape.MaxTolerance3d";
772 myOpLst << "FixFaceSize";
773 myValMap["FixFaceSize"] << "FixFaceSize.Tolerance";
775 myOpLst << "DropSmallEdges";
776 myValMap["DropSmallEdges"] << "DropSmallEdges.Tolerance3d";
778 myOpLst << "DropSmallSolids";
779 myValMap["DropSmallSolids"] << "DropSmallSolids.WidthFactorThreshold";
780 myValMap["DropSmallSolids"] << "DropSmallSolids.VolumeThreshold";
781 myValMap["DropSmallSolids"] << "DropSmallSolids.MergeSolids";
783 myOpLst << "SplitAngle";
784 myValMap["SplitAngle"] << "SplitAngle.Angle";
785 myValMap["SplitAngle"] << "SplitAngle.MaxTolerance";
787 myOpLst << "SplitClosedFaces";
788 myValMap["SplitClosedFaces"] << "SplitClosedFaces.NbSplitPoints";
790 myOpLst << "SplitContinuity";
791 myValMap["SplitContinuity"] << "SplitContinuity.Tolerance3d";
792 myValMap["SplitContinuity"] << "SplitContinuity.SurfaceContinuity";
793 myValMap["SplitContinuity"] << "SplitContinuity.CurveContinuity";
795 myOpLst << "BSplineRestriction";
796 myValMap["BSplineRestriction"] << "BSplineRestriction.SurfaceMode";
797 myValMap["BSplineRestriction"] << "BSplineRestriction.Curve3dMode";
798 myValMap["BSplineRestriction"] << "BSplineRestriction.Curve2dMode";
799 myValMap["BSplineRestriction"] << "BSplineRestriction.Tolerance3d";
800 myValMap["BSplineRestriction"] << "BSplineRestriction.Tolerance2d";
801 myValMap["BSplineRestriction"] << "BSplineRestriction.RequiredDegree";
802 myValMap["BSplineRestriction"] << "BSplineRestriction.RequiredNbSegments";
803 myValMap["BSplineRestriction"] << "BSplineRestriction.Continuity3d";
804 myValMap["BSplineRestriction"] << "BSplineRestriction.Continuity2d";
806 myOpLst << "ToBezier";
807 myValMap["ToBezier"] << "ToBezier.SurfaceMode";
808 myValMap["ToBezier"] << "ToBezier.Curve3dMode";
809 myValMap["ToBezier"] << "ToBezier.Curve2dMode";
810 myValMap["ToBezier"] << "ToBezier.MaxTolerance";
812 myOpLst << "SameParameter";
813 myValMap["SameParameter"] << "SameParameter.Tolerance3d";
816 //=================================================================================
817 // function : getParameters
819 //=================================================================================
820 GEOM::string_array* RepairGUI_ShapeProcessDlg::getParameters( const GEOM::string_array& theOperators )
822 GEOM::string_array_var aParams = new GEOM::string_array();
825 // calculate the length of parameters
826 for ( i = 0, j = 0; i < theOperators.length(); i++ )
827 j += myValMap[ QString( theOperators[i] ) ].size();
829 // set the new length of paremeters
830 aParams->length( j );
832 // fill the parameters
833 for ( i = 0, j = 0; i < theOperators.length(); i++ ) {
834 QStringList aValLst = myValMap[ QString( theOperators[i] ) ];
835 for ( QStringList::Iterator it = aValLst.begin(); it != aValLst.end(); ++it )
836 aParams[j++] = CORBA::string_dup( (*it).toLatin1().constData() );
839 return aParams._retn();
843 //=================================================================================
844 // function : getValues
846 //=================================================================================
847 GEOM::string_array* RepairGUI_ShapeProcessDlg::getValues( const GEOM::string_array& theParams )
849 GEOM::string_array_var aValues = new GEOM::string_array();
850 aValues->length( theParams.length() );
852 for ( int i = 0; i < theParams.length(); i++ ) {
853 QWidget* aCtrl = getControl( (const char*)theParams[i] );
854 if ( aCtrl && aCtrl->isEnabled() )
855 aValues[i] = get_convert( (const char*)theParams[i], getValue( aCtrl ));
858 return aValues._retn();
861 //=================================================================================
862 // function : getTexts
864 //=================================================================================
865 QStringList RepairGUI_ShapeProcessDlg::getTexts( const GEOM::string_array& theParams )
869 for ( int i = 0; i < theParams.length(); i++ ) {
870 QWidget* aCtrl = getControl( (const char*)theParams[i] );
873 QString aText = getText( aCtrl );
874 if( !aText.isNull() )
875 aTexts.append( aText );
882 //=================================================================================
883 // function : initSelection
884 // purpose : set selection of ALL shape types except vertexes
885 //=================================================================================
886 void RepairGUI_ShapeProcessDlg::initSelection()
888 TColStd_MapOfInteger aTypes;
889 aTypes.Add( GEOM_COMPOUND );
890 aTypes.Add( GEOM_SOLID );
891 aTypes.Add( GEOM_SHELL );
892 aTypes.Add( GEOM_FACE );
893 aTypes.Add( GEOM_WIRE );
894 aTypes.Add( GEOM_EDGE );
895 globalSelection( aTypes );
898 //=================================================================================
899 // function : advOptionToggled
900 // purpose : this slot is used to warn the user about possible consequences
901 // of enabling some advanced options
902 //=================================================================================
903 void RepairGUI_ShapeProcessDlg::advOptionToggled( bool on )
905 QAbstractButton* btn = (QAbstractButton*)sender();
906 if ( btn == myToBezierSurfModeChk )
908 if ( on && btn->isCheckable() &&
909 SUIT_MessageBox::warning( this,
910 tr( "GEOM_WRN_WARNING" ), tr( "TIME_CONSUMING" ),
911 SUIT_MessageBox::Yes | SUIT_MessageBox::No ) == SUIT_MessageBox::No )
915 // either myDropSmallSolidsWidChk or myDropSmallSolidsVolChk must be checked
916 if ( btn == myDropSmallSolidsWidChk )
918 myDropSmallSolidsWidTol->setEnabled( on );
920 myDropSmallSolidsVolChk->setChecked( true );
921 myDropSmallSolidsVolTol->setEnabled( true );
924 if ( btn == myDropSmallSolidsVolChk )
926 myDropSmallSolidsVolTol->setEnabled( on );
928 myDropSmallSolidsWidChk->setChecked( true );
929 myDropSmallSolidsWidTol->setEnabled( true );
934 //=======================================================================
935 //function : operatorChecked
936 //purpose : show parameters of a selected operator
937 //=======================================================================
939 void RepairGUI_ShapeProcessDlg::operatorChecked( QListWidgetItem * item )
941 if ( item && item->checkState() == Qt::Checked )
943 myStack->setCurrentIndex( myOpList->row( item ));