1 // Copyright (C) 2007-2008 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.
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
22 // GEOM GEOMGUI : GUI for Geometry component
23 // File : RepairGUI_ShapeProcessDlg.cxx
24 // Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
26 #include "RepairGUI_ShapeProcessDlg.h"
29 #include <GeometryGUI.h>
31 #include <GEOMImpl_Types.hxx>
32 #include <QtxDoubleSpinBox.h>
34 #include <SalomeApp_Application.h>
35 #include <SalomeApp_DoubleSpinBox.h>
36 #include <SalomeApp_IntSpinBox.h>
37 #include <LightApp_SelectionMgr.h>
38 #include <SUIT_Session.h>
39 #include <SUIT_ResourceMgr.h>
40 #include <SUIT_MessageBox.h>
41 #include <SALOME_ListIteratorOfListIO.hxx>
42 #include <SALOME_ListIO.hxx>
44 #include <TCollection_AsciiString.hxx>
45 #include <TColStd_MapOfInteger.hxx>
47 #include <QListWidget>
48 #include <QStackedLayout>
50 //=================================================================================
51 // class : RepairGUI_ShapeProcessDlg()
52 // purpose : Constructs a RepairGUI_ShapeProcessDlg which is a child of 'parent', with the
53 // name 'name' and widget flags set to 'f'.
54 // The dialog will by default be modeless, unless you set 'modal' to
55 // TRUE to construct a modal dialog.
56 //=================================================================================
57 RepairGUI_ShapeProcessDlg::RepairGUI_ShapeProcessDlg( GeometryGUI* theGeometryGUI, QWidget* parent,
59 : GEOMBase_Skeleton( theGeometryGUI, parent, modal )
61 setHelpFileName( "shape_processing_operation_page.html" );
65 //=================================================================================
66 // function : ~RepairGUI_ShapeProcessDlg()
67 // purpose : Destroys the object and frees any allocated resources
68 //=================================================================================
69 RepairGUI_ShapeProcessDlg::~RepairGUI_ShapeProcessDlg()
73 //=================================================================================
76 //=================================================================================
77 void RepairGUI_ShapeProcessDlg::init()
79 //myGeomGUI->SetState( 0 );
84 setWindowTitle( tr( "GEOM_SHAPEPROCESS_TITLE" ) );
86 mainFrame()->GroupConstructors->hide();
88 // select widget on the top
89 mySelectWdgt = new DlgRef_1Sel( centralWidget() );
90 mySelectWdgt->GroupBox1->setTitle( tr( "GEOM_SHAPE" ) );
91 mySelectWdgt->TextLabel1->setText( tr( "GEOM_SELECTED_OBJECTS" ) );
92 mySelectWdgt->PushButton1->setIcon( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
93 mySelectWdgt->LineEdit1->setReadOnly( true );
95 // layout the two group boxes in the middle, add a list of operations
96 QGroupBox* anOperGr = new QGroupBox( tr( "GEOM_OPERATIONS" ), centralWidget() );
98 // operations list widget
99 myOpList = new QListWidget( anOperGr );
100 myOpList->setSortingEnabled( false );
101 myOpList->setSizePolicy( QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Expanding ) );
103 QVBoxLayout* aOperLay = new QVBoxLayout( anOperGr );
104 aOperLay->setMargin( 9 );
105 aOperLay->addWidget( myOpList );
107 QGroupBox* aParamsGr = new QGroupBox( tr( "GEOM_PARAMETERS" ), centralWidget() );
109 // add a widget stack to the parameters group box
110 QStackedLayout* aStack = new QStackedLayout( aParamsGr );
112 // continueties values..
113 QStringList aContinueties = QString( "C0,G1,C1,G2,C2,C3,CN" ).split( "," );
115 // fill in the widgets
116 for ( int i = 0; i < myOpLst.count(); i++ ) {
117 QListWidgetItem* item = new QListWidgetItem( myOpLst[i] );
118 item->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsUserCheckable );
119 item->setCheckState( Qt::Unchecked );
120 myOpList->addItem( item );
123 if ( myOpLst[i] == "FixShape" ) {
125 w = new QWidget( aParamsGr );
126 QGridLayout* aLay = new QGridLayout( w );
127 aLay->setMargin( 9 ); aLay->setSpacing( 6 );
129 myFixShapeTol3D = new SalomeApp_DoubleSpinBox( 0., 100., 1e-7, 10, 10, w );
130 myFixShapeMaxTol3D = new SalomeApp_DoubleSpinBox( 0., 100., 1e-7, 10, 10, w );
132 aLay->addWidget( new QLabel( tr( "GEOM_3D_TOLERANCE" ), w ), 0, 0 );
133 aLay->addWidget( myFixShapeTol3D, 0, 1 );
134 aLay->addWidget( new QLabel( tr( "GEOM_MAX_3D_TOLERANCE" ), w ), 1, 0 );
135 aLay->addWidget( myFixShapeMaxTol3D, 1, 1 );
136 aLay->setRowStretch( aLay->rowCount(), 5 );
138 else if ( myOpLst[i] == "FixFaceSize" ) {
140 w = new QWidget( aParamsGr );
141 QGridLayout* aLay = new QGridLayout( w );
142 aLay->setMargin( 9 ); aLay->setSpacing( 6 );
144 myFixFaceSizeTol = new SalomeApp_DoubleSpinBox( 0., 100., 1e-7, 10, 10, w );
146 aLay->addWidget( new QLabel( tr( "GEOM_TOLERANCE" ), w ), 0, 0 );
147 aLay->addWidget( myFixFaceSizeTol, 0, 1 );
148 aLay->setRowStretch( aLay->rowCount(), 5 );
150 else if ( myOpLst[i] == "DropSmallEdges" ) {
152 w = new QWidget( aParamsGr );
153 QGridLayout* aLay = new QGridLayout( w );
154 aLay->setMargin( 9 ); aLay->setSpacing( 6 );
156 myDropSmallEdgesTol3D = new SalomeApp_DoubleSpinBox( 0., 100., 1e-7, 10, 10, w );
158 aLay->addWidget( new QLabel( tr( "GEOM_3D_TOLERANCE" ), w ), 0, 0 );
159 aLay->addWidget( myDropSmallEdgesTol3D, 0, 1 );
160 aLay->setRowStretch( aLay->rowCount(), 5 );
162 else if ( myOpLst[i] == "SplitAngle" ) {
164 w = new QWidget( aParamsGr );
165 QGridLayout* aLay = new QGridLayout( w );
166 aLay->setMargin( 9 ); aLay->setSpacing( 6 );
168 mySplitAngleAngle = new SalomeApp_DoubleSpinBox( 0, 360, 1, 10, 10, w );
169 mySplitAngleMaxTol = new SalomeApp_DoubleSpinBox( 0., 100., 1e-7, 10, 10, w );
171 aLay->addWidget( new QLabel( tr( "GEOM_ANGLE_1" ), w ), 0, 0 );
172 aLay->addWidget( mySplitAngleAngle, 0, 1 );
173 aLay->addWidget( new QLabel( tr( "GEOM_MAX_TOLERANCE" ), w ), 1, 0 );
174 aLay->addWidget( mySplitAngleMaxTol, 1, 1 );
175 aLay->setRowStretch( aLay->rowCount(), 5 );
177 else if ( myOpLst[i] == "SplitClosedFaces" ) {
179 w = new QWidget( aParamsGr );
180 QGridLayout* aLay = new QGridLayout( w );
181 aLay->setMargin( 9 ); aLay->setSpacing( 6 );
183 mySplitClosedFacesNum = new SalomeApp_IntSpinBox( w );
185 aLay->addWidget( new QLabel( tr( "GEOM_NUM_SPLIT_POINTS" ), w ), 0, 0 );
186 aLay->addWidget( mySplitClosedFacesNum, 0, 1 );
187 aLay->setRowStretch( aLay->rowCount(), 5 );
189 else if ( myOpLst[i] == "SplitContinuity" ) {
191 w = new QWidget( aParamsGr );
192 QGridLayout* aLay = new QGridLayout( w );
193 aLay->setMargin( 9 ); aLay->setSpacing( 6 );
195 mySplitContTol3D = new SalomeApp_DoubleSpinBox( 0., 100., 1e-7, 10, 10, w );
196 mySplitContSurfCont = new QComboBox( w );
197 mySplitContSurfCont->addItems( aContinueties );
198 mySplitContCurvCont = new QComboBox( w );
199 mySplitContCurvCont->addItems( aContinueties );
201 aLay->addWidget( new QLabel( tr( "GEOM_3D_TOLERANCE" ), w ), 0, 0 );
202 aLay->addWidget( mySplitContTol3D, 0, 1 );
203 aLay->addWidget( new QLabel( tr( "GEOM_SURFACE_CONTINUTY" ), w ), 1, 0 );
204 aLay->addWidget( mySplitContSurfCont, 1, 1 );
205 aLay->addWidget( new QLabel( tr( "GEOM_CURVE_CONTINUTY" ), w ), 2, 0 );
206 aLay->addWidget( mySplitContCurvCont, 2, 1 );
207 aLay->setRowStretch( aLay->rowCount(), 5 );
209 else if ( myOpLst[i] == "BSplineRestriction" ) {
210 // BSplineRestriction
211 w = new QWidget( aParamsGr );
212 QGridLayout* aLay = new QGridLayout( w );
213 aLay->setMargin( 9 ); aLay->setSpacing( 6 );
215 myBSplineSurfModeChk = new QCheckBox( tr("GEOM_SURFACE_MODE"), w );
216 myBSpline3DCurveChk = new QCheckBox( tr("GEOM_3D_CURVE_MODE"), w );
217 myBSpline2DCurveChk = new QCheckBox( tr("GEOM_2D_CURVE_MODE"), w );
219 myBSplineTol3D = new SalomeApp_DoubleSpinBox( 0., 100., 1e-7, 10, 10, w );
221 myBSplineTol2D = new SalomeApp_DoubleSpinBox( 0., 100., 1e-7, 10, 10, w );
223 myBSplineDegree = new SalomeApp_IntSpinBox( w );
224 myBSplineSegments = new SalomeApp_IntSpinBox( w );
225 myBSpline2DCont = new QComboBox( w );
226 myBSpline2DCont->addItems( aContinueties );
227 myBSpline3DCont = new QComboBox( w );
228 myBSpline3DCont->addItems( aContinueties );
230 myBSplineSurfModeChk->setChecked( true );
231 myBSpline3DCurveChk->setChecked( true );
232 myBSpline2DCurveChk->setChecked( true );
234 aLay->addWidget( myBSplineSurfModeChk, 0, 0 );
235 aLay->addWidget( myBSpline3DCurveChk, 1, 0 );
236 aLay->addWidget( myBSpline2DCurveChk, 2, 0 );
237 aLay->addWidget( new QLabel( tr( "GEOM_3D_TOLERANCE" ), w ), 3, 0 );
238 aLay->addWidget( myBSplineTol3D, 3, 1 );
239 aLay->addWidget( new QLabel( tr( "GEOM_2D_TOLERANCE" ), w ), 4, 0 );
240 aLay->addWidget( myBSplineTol2D, 4, 1 );
241 aLay->addWidget( new QLabel( tr( "GEOM_REQUIRED_DEGREE" ), w ), 5, 0 );
242 aLay->addWidget( myBSplineDegree, 5, 1 );
243 aLay->addWidget( new QLabel( tr( "GEOM_REQUIRED_NUM_SEGMENTS" ), w ), 6, 0 );
244 aLay->addWidget( myBSplineSegments, 6, 1 );
245 aLay->addWidget( new QLabel( tr( "GEOM_3D_CONTINUTY" ), w ), 7, 0 );
246 aLay->addWidget( myBSpline3DCont, 7, 1 );
247 aLay->addWidget( new QLabel( tr( "GEOM_2D_CONTINUTY" ), w ), 8, 0 );
248 aLay->addWidget( myBSpline2DCont, 8, 1 );
249 aLay->setRowStretch( aLay->rowCount(), 5 );
251 else if ( myOpLst[i] == "ToBezier" ) {
253 w = new QWidget( aParamsGr );
254 QGridLayout* aLay = new QGridLayout( w );
255 aLay->setMargin( 9 ); aLay->setSpacing( 6 );
257 myToBezierSurfModeChk = new QCheckBox( tr("GEOM_SURFACE_MODE"), w );
258 myToBezier3DCurveChk = new QCheckBox( tr("GEOM_3D_CURVE_MODE"), w );
259 myToBezier2DCurveChk = new QCheckBox( tr("GEOM_2D_CURVE_MODE"), w );
261 myToBezierMaxTol = new SalomeApp_DoubleSpinBox( 0., 100., 1e-7, 10, 10, w );
263 aLay->addWidget( myToBezierSurfModeChk, 0, 0 );
264 aLay->addWidget( myToBezier3DCurveChk, 1, 0 );
265 aLay->addWidget( myToBezier2DCurveChk, 2, 0 );
266 aLay->addWidget( new QLabel( tr( "GEOM_MAX_TOLERANCE" ), w ), 3, 0 );
267 aLay->addWidget( myToBezierMaxTol, 3, 1 );
268 aLay->setRowStretch( aLay->rowCount(), 5 );
270 else if ( myOpLst[i] == "SameParameter" ) {
272 w = new QWidget( aParamsGr );
273 QGridLayout* aLay = new QGridLayout( w );
274 aLay->setMargin( 9 ); aLay->setSpacing( 6 );
276 mySameParameterTol3D = new SalomeApp_DoubleSpinBox( 0., 100., 1e-7, 10, 10, w );
278 aLay->addWidget( new QLabel( tr( "GEOM_3D_TOLERANCE" ), w ), 0, 0 );
279 aLay->addWidget( mySameParameterTol3D, 0, 1 );
280 aLay->setRowStretch( aLay->rowCount(), 5 );
283 w = new QWidget( aParamsGr ); // dumb widget
285 aStack->insertWidget( i, w );
288 QGridLayout* layout = new QGridLayout( centralWidget() );
289 layout->setMargin( 0 ); layout->setSpacing( 6 );
290 layout->addWidget( mySelectWdgt, 0, 0, 1, 2 );
291 layout->addWidget( anOperGr, 1, 0 );
292 layout->addWidget( aParamsGr, 1, 1 );
294 // signals and slots connections
295 connect( buttonOk(), SIGNAL( clicked() ), this, SLOT( onOk() ) );
296 connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( onApply() ) );
298 connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
299 SIGNAL( currentSelectionChanged() ), this, SLOT( selectionChanged() ) );
301 connect( mySelectWdgt->PushButton1, SIGNAL( clicked() ), this, SLOT( selectClicked() ) );
302 connect( mySelectWdgt->LineEdit1, SIGNAL( returnPressed() ), this, SLOT( lineEditReturnPressed() ) );
304 connect( myToBezierSurfModeChk, SIGNAL( toggled( bool ) ), this, SLOT( advOptionToggled( bool ) ) );
306 connect( myOpList, SIGNAL( currentRowChanged( int ) ), aStack, SLOT( setCurrentIndex( int ) ) );
309 loadDefaults(); // init dialog fields with values from resource file
310 //myOpList->setCurrentRow( myOpList->findItem( 0 );
313 initName( tr( "PROCESS_SHAPE_NEW_OBJ_NAME" ) );
316 //=================================================================================
318 // purpose : Same than click on apply but close this dialog.
319 //=================================================================================
320 void RepairGUI_ShapeProcessDlg::onOk()
326 //=================================================================================
327 // function : onApply()
329 //=================================================================================
330 bool RepairGUI_ShapeProcessDlg::onApply()
344 //=================================================================================
345 // function : selectionChanged()
346 // purpose : Called when selection as changed or other case
347 // : used only by SelectButtonC1A1 (LineEditC1A1)
348 //=================================================================================
349 void RepairGUI_ShapeProcessDlg::selectionChanged()
353 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
354 SALOME_ListIO aSelList;
355 aSelMgr->selectedObjects(aSelList);
357 Standard_Boolean aRes = Standard_False;
359 myObjects->length(aSelList.Extent());
360 for (SALOME_ListIteratorOfListIO anIt (aSelList); anIt.More(); anIt.Next()) {
361 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( anIt.Value(), aRes );
362 if ( !CORBA::is_nil( aSelectedObject ) && aRes )
363 myObjects[i++] = aSelectedObject;
365 myObjects->length( i );
367 mySelectWdgt->LineEdit1->setText( GEOMBase::GetName( myObjects[0] ) );
369 mySelectWdgt->LineEdit1->setText( QString::number( i ) + "_" + tr( "GEOM_OBJECTS" ) );
373 //=================================================================================
374 // function : selectClicked()
376 //=================================================================================
377 void RepairGUI_ShapeProcessDlg::selectClicked()
379 myEditCurrentArgument = mySelectWdgt->LineEdit1;
380 mySelectWdgt->LineEdit1->setFocus();
385 //=================================================================================
386 // function : lineEditReturnPressed()
388 //=================================================================================
389 void RepairGUI_ShapeProcessDlg::lineEditReturnPressed()
391 GEOMBase_Skeleton::LineEditReturnPressed();
395 //=================================================================================
396 // function : activate()
398 //=================================================================================
399 void RepairGUI_ShapeProcessDlg::activate()
401 GEOMBase_Skeleton::ActivateThisDialog();
402 connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication( ) ))->selectionMgr(),
403 SIGNAL( currentSelectionChanged() ), this, SLOT( selectionChanged() ) );
406 //myGeomGUI->SetState( 0 );
411 //=================================================================================
412 // function : enterEvent()
413 // purpose : Mouse enter onto the dialog to activate it
414 //=================================================================================
415 void RepairGUI_ShapeProcessDlg::enterEvent( QEvent* )
417 if ( !mainFrame()->GroupBoxName->isEnabled() )
422 //=================================================================================
423 // function : reset()
424 // purpose : Completely reset the state of method including local context
425 //=================================================================================
426 void RepairGUI_ShapeProcessDlg::reset()
428 myObjects = new GEOM::ListOfGO();
429 myObjects->length( 0 );
430 mySelectWdgt->LineEdit1->setText( "" );
434 //=================================================================================
435 // function : get_convert
436 // purpose : conversion of angle values to radians (non-angle values are not converted)
437 //=================================================================================
438 const char* get_convert( const char* theParam, const QString& theValue )
440 if ( !strcmp( theParam, "SplitAngle.Angle" ) ) {
441 double doubleValue = theValue.toDouble() * PI / 180;
442 return CORBA::string_dup( QString::number( doubleValue ).toLatin1().constData() );
444 return CORBA::string_dup( theValue.toLatin1().constData() );
447 //=================================================================================
448 // function : set_convert
449 // purpose : conversion of angle values to degrees (non-angle values are not converted)
450 //=================================================================================
451 const char* set_convert( const char* theParam, const char* theValue )
453 if ( !strcmp( theParam, "SplitAngle.Angle" ) ) {
454 double doubleValue = atof( theValue ) * 180 / PI;
455 TCollection_AsciiString str( doubleValue );
456 return CORBA::string_dup( str.ToCString() );
458 return CORBA::string_dup( theValue );
461 //=================================================================================
462 // function : loadDefaults()
463 // purpose : initialize "values"-fields with default values retrieved from IHealingOperations
464 //=================================================================================
465 void RepairGUI_ShapeProcessDlg::loadDefaults()
467 GEOM::GEOM_IHealingOperations_var anOp = myGeomGUI->GetGeomGen()->GetIHealingOperations( getStudyId() );
468 GEOM::string_array_var anOperators, aParams, aValues;
469 anOp->GetShapeProcessParameters( anOperators, aParams, aValues );
471 // check the default items-operators
472 for ( int i = 0; i < anOperators->length(); i++ ) {
473 //MESSAGE("-->"<<(const char*)anOperators[i]);
474 QList<QListWidgetItem*> items = myOpList->findItems ( (const char*)anOperators[i], Qt::MatchFixedString );
476 ( items[0] )->setCheckState( Qt::Checked );
479 // Retrieve default parameters for ALL operators
480 for ( int i = 0; i < myOpList->count(); i++ ) {
481 CORBA::String_var anOperator = CORBA::string_dup( myOpList->item( i )->text().toLatin1().constData() );
482 anOp->GetOperatorParameters( anOperator.in(), aParams, aValues );
484 // set default values of parameters
485 if ( aParams->length() != aValues->length() )
488 for ( int j = 0; j < aParams->length(); j++ ) {
489 QWidget* aCtrl = getControl( (const char*)aParams[j] );
490 const char* aValue = set_convert( (const char*)aParams[j], aValues[j] );
491 setValue( aCtrl, aValue );
496 //=================================================================================
497 // function : setValue()
498 // purpose : set value in the proper way
499 //=================================================================================
500 void RepairGUI_ShapeProcessDlg::setValue( QWidget* theControl, const QString& theValue )
502 if ( theControl && !theValue.isNull() ) {
503 if ( qobject_cast<SalomeApp_DoubleSpinBox*>( theControl ) )
504 qobject_cast<SalomeApp_DoubleSpinBox*>( theControl )->setValue( theValue.toDouble() );
505 else if ( qobject_cast<SalomeApp_IntSpinBox*>( theControl ) )
506 qobject_cast<SalomeApp_IntSpinBox*>( theControl )->setValue( theValue.toInt() );
507 else if ( qobject_cast<QComboBox*>( theControl ) )
508 qobject_cast<QComboBox*>( theControl )->setEditText( theValue );
509 else if ( qobject_cast<QCheckBox*>( theControl ) )
510 qobject_cast<QCheckBox*>( theControl )->setChecked( theValue.toInt() != 0 );
514 //=================================================================================
515 // function : getValue()
516 // purpose : get value in the proper way
517 //=================================================================================
518 QString RepairGUI_ShapeProcessDlg::getValue( QWidget* theControl ) const
521 if ( qobject_cast<SalomeApp_DoubleSpinBox*>( theControl ) )
522 return QString::number( qobject_cast<SalomeApp_DoubleSpinBox*>( theControl )->value() );
523 else if ( qobject_cast<SalomeApp_IntSpinBox*>( theControl ) )
524 return QString::number( qobject_cast<SalomeApp_IntSpinBox*>( theControl )->value() );
525 else if ( qobject_cast<QComboBox*>( theControl ) )
526 return qobject_cast<QComboBox*>( theControl )->currentText();
527 else if ( qobject_cast<QCheckBox*>( theControl ) )
528 return qobject_cast<QCheckBox*>( theControl )->isChecked() ? "1" : "0";
533 //=================================================================================
534 // function : getText()
535 // purpose : get text in the proper way
536 //=================================================================================
537 QString RepairGUI_ShapeProcessDlg::getText( QWidget* theControl ) const
540 if ( qobject_cast<SalomeApp_DoubleSpinBox*>( theControl ) )
541 return qobject_cast<SalomeApp_DoubleSpinBox*>( theControl )->text();
542 else if ( qobject_cast<SalomeApp_IntSpinBox*>( theControl ) )
543 return qobject_cast<SalomeApp_IntSpinBox*>( theControl )->text();
545 return QString::null;
548 //=================================================================================
549 // function : createOperation
551 //=================================================================================
552 GEOM::GEOM_IOperations_ptr RepairGUI_ShapeProcessDlg::createOperation()
554 return getGeomEngine()->GetIHealingOperations( getStudyId() );
557 //=================================================================================
558 // function : isValid
560 //=================================================================================
561 bool RepairGUI_ShapeProcessDlg::isValid( QString& msg )
564 QMapIterator<QString,QStringList> aMapIter( myValMap );
565 while( aMapIter.hasNext() ) {
567 const QStringList& aList = aMapIter.value();
568 QListIterator<QString> aListIter( aList );
569 while( aListIter.hasNext() ) {
570 const QString& aParam = aListIter.next();
571 QWidget* aControl = getControl( aParam );
572 if ( qobject_cast<SalomeApp_DoubleSpinBox*>( aControl ) )
573 ok = qobject_cast<SalomeApp_DoubleSpinBox*>( aControl )->isValid( msg, !IsPreview() ) && ok;
574 else if ( qobject_cast<SalomeApp_IntSpinBox*>( aControl ) )
575 ok = qobject_cast<SalomeApp_IntSpinBox*>( aControl )->isValid( msg, !IsPreview() ) && ok;
580 GEOM::string_array_var anOperators = getActiveOperators();
581 if ( !myObjects->length() ) {
582 msg += tr( "ERROR_NO_OBJECTS" );
585 if ( !anOperators->length() ) {
588 msg += tr( "ERROR_NO_OPERATORS" );
594 //=================================================================================
595 // function : execute
597 //=================================================================================
598 bool RepairGUI_ShapeProcessDlg::execute( ObjectList& objects )
600 GEOM::string_array_var anOperators = getActiveOperators();
601 GEOM::string_array_var aParams = getParameters( anOperators );
602 GEOM::string_array_var aValues = getValues( aParams );
606 MESSAGE("Objects : ");
607 for ( z = 0; z < myObjects->length(); z++ )
608 MESSAGE(myObjects[z]->GetName() << " ");
609 MESSAGE("\nOperators : ");
610 for ( z = 0; z < anOperators->length(); z++ )
611 MESSAGE(anOperators[z] << " ");
612 MESSAGE("\nParameters : ");
613 for ( z = 0; z < aParams->length(); z++ )
614 MESSAGE(aParams[z] << " ");
615 MESSAGE("\nValues : ");
616 for ( z = 0; z < aValues->length(); z ++ )
617 MESSAGE(aValues[z] << " ");
621 QStringList anErrorObjNames;
622 for ( int i = 0; i < myObjects->length(); i++ ) {
623 GEOM::GEOM_Object_var obj = myObjects[i];
624 GEOM::GEOM_Object_var anObj = GEOM::GEOM_IHealingOperations::_narrow( getOperation() )->
625 ProcessShape( obj, anOperators, aParams, aValues );
626 if ( anObj->_is_nil() )
627 anErrorObjNames << GEOMBase::GetName( obj );
632 QStringList aParameters;
634 for ( int i = 0; i < anOperators->length(); i++ )
635 aParameters << QString( anOperators[i] );
637 for ( int i = 0; i < aParams->length(); i++ )
638 aParameters << QString( aParams[i] );
640 aParameters << getTexts( aParams );
641 anObj->SetParameters(GeometryGUI::JoinObjectParameters(aParameters));
643 objects.push_back( anObj._retn() );
647 if ( !anErrorObjNames.empty() )
648 MESSAGE( "ERRORS occured while processing the following objects: " << anErrorObjNames.join( " " ).toLatin1().data() );
650 return anErrorObjNames.size() < myObjects->length(); // true if at least one object was OK, false if ALL objects were nil after Healing.
653 //=================================================================================
654 // function : getActiveOperators
656 //=================================================================================
657 GEOM::string_array* RepairGUI_ShapeProcessDlg::getActiveOperators()
659 GEOM::string_array_var anOperators = new GEOM::string_array();
660 QStringList aCheckedList;
662 for ( int i = 0; i < myOpList->count(); i++ ) {
663 if ( myOpList->item( i )->checkState() == Qt::Checked )
664 aCheckedList << myOpList->item( i )->text();
667 anOperators->length( aCheckedList.count() );
669 for ( int i = 0; i < aCheckedList.count(); i++ )
670 anOperators[i] = CORBA::string_dup( aCheckedList[i].toLatin1().constData() );
672 return anOperators._retn();
675 //=================================================================================
676 // function : getcontrol
678 //=================================================================================
679 QWidget* RepairGUI_ShapeProcessDlg::getControl( const QString& theParam )
681 if ( theParam == "SplitAngle.Angle" ) return mySplitAngleAngle;
682 else if ( theParam == "SplitAngle.MaxTolerance" ) return mySplitAngleMaxTol;
683 else if ( theParam == "SplitClosedFaces.NbSplitPoints" ) return mySplitClosedFacesNum;
684 else if ( theParam == "FixFaceSize.Tolerance" ) return myFixFaceSizeTol;
685 else if ( theParam == "DropSmallEdges.Tolerance3d" ) return myDropSmallEdgesTol3D;
686 else if ( theParam == "BSplineRestriction.SurfaceMode" ) return myBSplineSurfModeChk;
687 else if ( theParam == "BSplineRestriction.Curve3dMode" ) return myBSpline3DCurveChk;
688 else if ( theParam == "BSplineRestriction.Curve2dMode" ) return myBSpline2DCurveChk;
689 else if ( theParam == "BSplineRestriction.Tolerance3d" ) return myBSplineTol3D;
690 else if ( theParam == "BSplineRestriction.Tolerance2d" ) return myBSplineTol2D;
691 else if ( theParam == "BSplineRestriction.RequiredDegree" ) return myBSplineDegree;
692 else if ( theParam == "BSplineRestriction.RequiredNbSegments" ) return myBSplineSegments;
693 else if ( theParam == "BSplineRestriction.Continuity3d" ) return myBSpline3DCont;
694 else if ( theParam == "BSplineRestriction.Continuity2d" ) return myBSpline2DCont;
695 else if ( theParam == "SplitContinuity.Tolerance3d" ) return mySplitContTol3D;
696 else if ( theParam == "SplitContinuity.SurfaceContinuity" ) return mySplitContSurfCont;
697 else if ( theParam == "SplitContinuity.CurveContinuity" ) return mySplitContCurvCont;
698 else if ( theParam == "ToBezier.SurfaceMode" ) return myToBezierSurfModeChk;
699 else if ( theParam == "ToBezier.Curve3dMode" ) return myToBezier3DCurveChk;
700 else if ( theParam == "ToBezier.Curve2dMode" ) return myToBezier2DCurveChk;
701 else if ( theParam == "ToBezier.MaxTolerance" ) return myToBezierMaxTol;
702 else if ( theParam == "SameParameter.Tolerance3d" ) return mySameParameterTol3D;
703 else if ( theParam == "FixShape.Tolerance3d" ) return myFixShapeTol3D;
704 else if ( theParam == "FixShape.MaxTolerance3d" ) return myFixShapeMaxTol3D;
708 //=================================================================================
709 // function : getParameters
711 //=================================================================================
712 void RepairGUI_ShapeProcessDlg::initParamsValues()
714 if ( myOpLst.count() )
715 return; // already filled
717 myOpLst << "FixShape";
718 myValMap["FixShape"] << "FixShape.Tolerance3d";
719 myValMap["FixShape"] << "FixShape.MaxTolerance3d";
721 myOpLst << "FixFaceSize";
722 myValMap["FixFaceSize"] << "FixFaceSize.Tolerance";
724 myOpLst << "DropSmallEdges";
725 myValMap["DropSmallEdges"] << "DropSmallEdges.Tolerance3d";
727 myOpLst << "SplitAngle";
728 myValMap["SplitAngle"] << "SplitAngle.Angle";
729 myValMap["SplitAngle"] << "SplitAngle.MaxTolerance";
731 myOpLst << "SplitClosedFaces";
732 myValMap["SplitClosedFaces"] << "SplitClosedFaces.NbSplitPoints";
734 myOpLst << "SplitContinuity";
735 myValMap["SplitContinuity"] << "SplitContinuity.Tolerance3d";
736 myValMap["SplitContinuity"] << "SplitContinuity.SurfaceContinuity";
737 myValMap["SplitContinuity"] << "SplitContinuity.CurveContinuity";
739 myOpLst << "BSplineRestriction";
740 myValMap["BSplineRestriction"] << "BSplineRestriction.SurfaceMode";
741 myValMap["BSplineRestriction"] << "BSplineRestriction.Curve3dMode";
742 myValMap["BSplineRestriction"] << "BSplineRestriction.Curve2dMode";
743 myValMap["BSplineRestriction"] << "BSplineRestriction.Tolerance3d";
744 myValMap["BSplineRestriction"] << "BSplineRestriction.Tolerance2d";
745 myValMap["BSplineRestriction"] << "BSplineRestriction.RequiredDegree";
746 myValMap["BSplineRestriction"] << "BSplineRestriction.RequiredNbSegments";
747 myValMap["BSplineRestriction"] << "BSplineRestriction.Continuity3d";
748 myValMap["BSplineRestriction"] << "BSplineRestriction.Continuity2d";
750 myOpLst << "ToBezier";
751 myValMap["ToBezier"] << "ToBezier.SurfaceMode";
752 myValMap["ToBezier"] << "ToBezier.Curve3dMode";
753 myValMap["ToBezier"] << "ToBezier.Curve2dMode";
754 myValMap["ToBezier"] << "ToBezier.MaxTolerance";
756 myOpLst << "SameParameter";
757 myValMap["SameParameter"] << "SameParameter.Tolerance3d";
760 //=================================================================================
761 // function : getParameters
763 //=================================================================================
764 GEOM::string_array* RepairGUI_ShapeProcessDlg::getParameters( const GEOM::string_array& theOperators )
766 GEOM::string_array_var aParams = new GEOM::string_array();
769 // calculate the length of parameters
770 for ( i = 0, j = 0; i < theOperators.length(); i++ )
771 j += myValMap[ QString( theOperators[i] ) ].size();
773 // set the new length of paremeters
774 aParams->length( j );
776 // fill the parameters
777 for ( i = 0, j = 0; i < theOperators.length(); i++ ) {
778 QStringList aValLst = myValMap[ QString( theOperators[i] ) ];
779 for ( QStringList::Iterator it = aValLst.begin(); it != aValLst.end(); ++it )
780 aParams[j++] = CORBA::string_dup( (*it).toLatin1().constData() );
783 return aParams._retn();
787 //=================================================================================
788 // function : getValues
790 //=================================================================================
791 GEOM::string_array* RepairGUI_ShapeProcessDlg::getValues( const GEOM::string_array& theParams )
793 GEOM::string_array_var aValues = new GEOM::string_array();
794 aValues->length( theParams.length() );
796 for ( int i = 0; i < theParams.length(); i++ ) {
797 QWidget* aCtrl = getControl( (const char*)theParams[i] );
799 aValues[i] = get_convert( (const char*)theParams[i], getValue( aCtrl ) );
802 return aValues._retn();
805 //=================================================================================
806 // function : getTexts
808 //=================================================================================
809 QStringList RepairGUI_ShapeProcessDlg::getTexts( const GEOM::string_array& theParams )
813 for ( int i = 0; i < theParams.length(); i++ ) {
814 QWidget* aCtrl = getControl( (const char*)theParams[i] );
817 QString aText = getText( aCtrl );
818 if( !aText.isNull() )
819 aTexts.append( aText );
826 //=================================================================================
827 // function : initSelection
828 // purpose : set selection of ALL shape types except vertexes
829 //=================================================================================
830 void RepairGUI_ShapeProcessDlg::initSelection()
832 TColStd_MapOfInteger aTypes;
833 aTypes.Add( GEOM_COMPOUND );
834 aTypes.Add( GEOM_SOLID );
835 aTypes.Add( GEOM_SHELL );
836 aTypes.Add( GEOM_FACE );
837 aTypes.Add( GEOM_WIRE );
838 aTypes.Add( GEOM_EDGE );
839 globalSelection( aTypes );
842 //=================================================================================
843 // function : advOptionToggled
844 // purpose : this slot is used to warn the user about possible consequences
845 // of enabling some advanced options
846 //=================================================================================
847 void RepairGUI_ShapeProcessDlg::advOptionToggled( bool on )
849 QAbstractButton* btn = (QAbstractButton*)sender();
850 if ( on && btn->isCheckable() &&
851 SUIT_MessageBox::warning( this,
852 tr( "GEOM_WRN_WARNING" ), tr( "TIME_CONSUMING" ),
853 SUIT_MessageBox::Yes | SUIT_MessageBox::No ) == SUIT_MessageBox::No )