Salome HOME
Qt4 porting. There are nonsignificant zeros in fields of some dialog boxes, if a...
[modules/geom.git] / src / RepairGUI / RepairGUI_ShapeProcessDlg.cxx
1 // GEOM GEOMGUI : GUI for Geometry component
2 //
3 // Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
5 // 
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. 
10 // 
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. 
15 // 
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 
19 // 
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 // File   : RepairGUI_ShapeProcessDlg.cxx
23 // Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
24 //
25
26 #include "RepairGUI_ShapeProcessDlg.h"
27
28 #include <DlgRef.h>
29 #include <GeometryGUI.h>
30 #include <GEOMBase.h>
31 #include <GEOMImpl_Types.hxx>
32 #include <QtxDoubleSpinBox.h>
33
34 #include <SalomeApp_Application.h>
35 #include <LightApp_SelectionMgr.h>
36 #include <SUIT_Session.h>
37 #include <SUIT_ResourceMgr.h>
38 #include <SUIT_MessageBox.h>
39 #include <SALOME_ListIteratorOfListIO.hxx>
40 #include <SALOME_ListIO.hxx>
41
42 #include <TCollection_AsciiString.hxx>
43 #include <TColStd_MapOfInteger.hxx>
44
45 #include <QListWidget>
46 #include <QStackedLayout>
47
48 //=================================================================================
49 // class    : RepairGUI_ShapeProcessDlg()
50 // purpose  : Constructs a RepairGUI_ShapeProcessDlg  which is a child of 'parent', with the
51 //            name 'name' and widget flags set to 'f'.
52 //            The dialog will by default be modeless, unless you set 'modal' to
53 //            TRUE to construct a modal dialog.
54 //=================================================================================
55 RepairGUI_ShapeProcessDlg::RepairGUI_ShapeProcessDlg( GeometryGUI* theGeometryGUI, QWidget* parent,
56                                                       bool modal )
57   : GEOMBase_Skeleton( theGeometryGUI, parent, modal )
58 {
59   setHelpFileName( "shape_processing_operation_page.html" );
60   init();
61 }
62
63 //=================================================================================
64 // function : ~RepairGUI_ShapeProcessDlg()
65 // purpose  : Destroys the object and frees any allocated resources
66 //=================================================================================
67 RepairGUI_ShapeProcessDlg::~RepairGUI_ShapeProcessDlg()
68 {
69 }
70
71 //=================================================================================
72 // function : Init()
73 // purpose  :
74 //=================================================================================
75 void RepairGUI_ShapeProcessDlg::init()
76 {
77   //myGeomGUI->SetState( 0 );
78
79   initParamsValues();
80   initSelection();
81         
82   setWindowTitle( tr( "GEOM_SHAPEPROCESS_TITLE" ) );
83
84   mainFrame()->GroupConstructors->hide();
85   
86   // select widget on the top 
87   mySelectWdgt = new DlgRef_1Sel( centralWidget() );
88   mySelectWdgt->GroupBox1->setTitle( tr( "GEOM_SHAPE" ) );
89   mySelectWdgt->TextLabel1->setText( tr( "GEOM_SELECTED_OBJECTS" ) );
90   mySelectWdgt->PushButton1->setIcon( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
91   mySelectWdgt->LineEdit1->setReadOnly( true );
92
93   // layout the two group boxes in the middle, add a list of operations
94   QGroupBox* anOperGr = new QGroupBox( tr( "GEOM_OPERATIONS" ), centralWidget() );
95
96   // operations list widget
97   myOpList = new QListWidget( anOperGr );
98   myOpList->setSortingEnabled( false );
99   myOpList->setSizePolicy( QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Expanding ) );
100
101   QVBoxLayout* aOperLay = new QVBoxLayout( anOperGr );
102   aOperLay->setMargin( 9 );
103   aOperLay->addWidget( myOpList );
104
105   QGroupBox* aParamsGr = new QGroupBox( tr( "GEOM_PARAMETERS" ), centralWidget() );
106
107   // add a widget stack to the parameters group box
108   QStackedLayout* aStack = new QStackedLayout( aParamsGr );
109
110   // continueties values..
111   QStringList aContinueties = QString( "C0,G1,C1,G2,C2,C3,CN" ).split( "," );
112
113   // fill in the widgets
114   for ( int i = 0; i < myOpLst.count(); i++ ) {
115     QListWidgetItem* item = new QListWidgetItem( myOpLst[i] );
116     item->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsUserCheckable );
117     item->setCheckState( Qt::Unchecked );
118     myOpList->addItem( item );
119
120     QWidget* w;
121     if ( myOpLst[i] == "FixShape" ) {
122       // FixShape
123       w = new QWidget( aParamsGr );
124       QGridLayout* aLay = new QGridLayout( w );
125       aLay->setMargin( 9 ); aLay->setSpacing( 6 );
126       
127       myFixShapeTol3D = new QtxDoubleSpinBox( 0., 100., 1e-7, 10, 10, w );
128       myFixShapeMaxTol3D = new QtxDoubleSpinBox( 0., 100., 1e-7, 10, 10, w );
129       
130       aLay->addWidget( new QLabel( tr( "GEOM_3D_TOLERANCE" ), w ), 0, 0 );
131       aLay->addWidget( myFixShapeTol3D, 0, 1 );
132       aLay->addWidget( new QLabel( tr( "GEOM_MAX_3D_TOLERANCE" ), w ), 1, 0 );
133       aLay->addWidget( myFixShapeMaxTol3D, 1, 1 );
134       aLay->setRowStretch( aLay->rowCount(), 5 );
135     }
136     else if ( myOpLst[i] == "FixFaceSize" ) {
137       // FixFaceSize  
138       w = new QWidget( aParamsGr );
139       QGridLayout* aLay = new QGridLayout( w );
140       aLay->setMargin( 9 ); aLay->setSpacing( 6 );
141       
142       myFixFaceSizeTol = new QtxDoubleSpinBox( 0., 100., 1e-7, 10, 10, w );
143       
144       aLay->addWidget( new QLabel( tr( "GEOM_TOLERANCE" ), w ), 0, 0 );
145       aLay->addWidget( myFixFaceSizeTol, 0, 1 );
146       aLay->setRowStretch( aLay->rowCount(), 5 );
147     }
148     else if ( myOpLst[i] == "DropSmallEdges" ) {
149       // DropSmallEdges
150       w = new QWidget( aParamsGr );
151       QGridLayout* aLay = new QGridLayout( w );
152       aLay->setMargin( 9 ); aLay->setSpacing( 6 );
153       
154       myDropSmallEdgesTol3D = new QtxDoubleSpinBox( 0., 100., 1e-7, 10, 10, w );
155   
156       aLay->addWidget( new QLabel( tr( "GEOM_3D_TOLERANCE" ), w ), 0, 0 );
157       aLay->addWidget( myDropSmallEdgesTol3D, 0, 1 );
158       aLay->setRowStretch( aLay->rowCount(), 5 );
159     }
160     else if ( myOpLst[i] == "SplitAngle" ) {
161       // SplitAngle
162       w = new QWidget( aParamsGr );
163       QGridLayout* aLay = new QGridLayout( w );
164       aLay->setMargin( 9 ); aLay->setSpacing( 6 );
165       
166       mySplitAngleAngle = new QtxDoubleSpinBox(  0, 360, 1, 10, 10, w );
167       mySplitAngleMaxTol = new QtxDoubleSpinBox( 0., 100., 1e-7, 10, 10, w );
168       
169       aLay->addWidget( new QLabel( tr( "GEOM_ANGLE_1" ), w ), 0, 0 );
170       aLay->addWidget( mySplitAngleAngle, 0, 1 );
171       aLay->addWidget( new QLabel( tr( "GEOM_MAX_TOLERANCE" ), w ), 1, 0 );
172       aLay->addWidget( mySplitAngleMaxTol, 1, 1 );
173       aLay->setRowStretch( aLay->rowCount(), 5 );
174     }
175     else if ( myOpLst[i] == "SplitClosedFaces" ) {
176       // SplitClosedFaces
177       w = new QWidget( aParamsGr );
178       QGridLayout* aLay = new QGridLayout( w );
179       aLay->setMargin( 9 ); aLay->setSpacing( 6 );
180       
181       mySplitClosedFacesNum = new QSpinBox( w );
182   
183       aLay->addWidget( new QLabel( tr( "GEOM_NUM_SPLIT_POINTS" ), w ), 0, 0 );
184       aLay->addWidget( mySplitClosedFacesNum, 0, 1 );
185       aLay->setRowStretch( aLay->rowCount(), 5 );
186     }      
187     else if ( myOpLst[i] == "SplitContinuity" ) {
188       // SplitContinuity
189       w = new QWidget( aParamsGr );
190       QGridLayout* aLay = new QGridLayout( w );
191       aLay->setMargin( 9 ); aLay->setSpacing( 6 );
192
193       mySplitContTol3D = new QtxDoubleSpinBox(  0., 100., 1e-7, 10, 10, w );
194       mySplitContSurfCont = new QComboBox( w );
195       mySplitContSurfCont->addItems( aContinueties );
196       mySplitContCurvCont = new QComboBox( w );
197       mySplitContCurvCont->addItems( aContinueties );
198       
199       aLay->addWidget( new QLabel( tr( "GEOM_3D_TOLERANCE" ), w ), 0, 0 );
200       aLay->addWidget( mySplitContTol3D, 0, 1 );
201       aLay->addWidget( new QLabel( tr( "GEOM_SURFACE_CONTINUTY" ), w ), 1, 0 );
202       aLay->addWidget( mySplitContSurfCont, 1, 1 );
203       aLay->addWidget( new QLabel( tr( "GEOM_CURVE_CONTINUTY" ), w ), 2, 0 );
204       aLay->addWidget( mySplitContCurvCont, 2, 1 );
205       aLay->setRowStretch( aLay->rowCount(), 5 );
206     }
207     else if ( myOpLst[i] == "BSplineRestriction" ) {
208       // BSplineRestriction
209       w = new QWidget( aParamsGr );
210       QGridLayout* aLay = new QGridLayout( w );
211       aLay->setMargin( 9 ); aLay->setSpacing( 6 );
212
213       myBSplineSurfModeChk = new QCheckBox( tr("GEOM_SURFACE_MODE"), w );
214       myBSpline3DCurveChk = new QCheckBox( tr("GEOM_3D_CURVE_MODE"), w );
215       myBSpline2DCurveChk = new QCheckBox( tr("GEOM_2D_CURVE_MODE"), w );
216
217       myBSplineTol3D = new QtxDoubleSpinBox(  0., 100., 1e-7, 10, 10, w );
218       
219       myBSplineTol2D = new QtxDoubleSpinBox( 0., 100., 1e-7, 10, 10, w );
220
221       myBSplineDegree = new QSpinBox( w );
222       myBSplineSegments = new QSpinBox( w );
223       myBSpline2DCont = new QComboBox( w );
224       myBSpline2DCont->addItems( aContinueties );
225       myBSpline3DCont = new QComboBox( w );
226       myBSpline3DCont->addItems( aContinueties );
227       
228       myBSplineSurfModeChk->setChecked( true );
229       myBSpline3DCurveChk->setChecked( true );
230       myBSpline2DCurveChk->setChecked( true );
231
232       aLay->addWidget( myBSplineSurfModeChk, 0, 0 );
233       aLay->addWidget( myBSpline3DCurveChk,  1, 0 );
234       aLay->addWidget( myBSpline2DCurveChk,  2, 0 );
235       aLay->addWidget( new QLabel( tr( "GEOM_3D_TOLERANCE" ), w ), 3, 0 );
236       aLay->addWidget( myBSplineTol3D, 3, 1 );
237       aLay->addWidget( new QLabel( tr( "GEOM_2D_TOLERANCE" ), w ), 4, 0 );
238       aLay->addWidget( myBSplineTol2D, 4, 1 );
239       aLay->addWidget( new QLabel( tr( "GEOM_REQUIRED_DEGREE" ), w ), 5, 0 );
240       aLay->addWidget( myBSplineDegree, 5, 1 );
241       aLay->addWidget( new QLabel( tr( "GEOM_REQUIRED_NUM_SEGMENTS" ), w ), 6, 0 );
242       aLay->addWidget( myBSplineSegments, 6, 1 );
243       aLay->addWidget( new QLabel( tr( "GEOM_3D_CONTINUTY" ), w ), 7, 0 );
244       aLay->addWidget( myBSpline3DCont, 7, 1 );
245       aLay->addWidget( new QLabel( tr( "GEOM_2D_CONTINUTY" ), w ), 8, 0 );
246       aLay->addWidget( myBSpline2DCont, 8, 1 );
247       aLay->setRowStretch( aLay->rowCount(), 5 );
248     }
249     else if ( myOpLst[i] == "ToBezier" ) {
250       // ToBezier
251       w = new QWidget( aParamsGr );
252       QGridLayout* aLay = new QGridLayout( w );
253       aLay->setMargin( 9 ); aLay->setSpacing( 6 );
254
255       myToBezierSurfModeChk = new QCheckBox( tr("GEOM_SURFACE_MODE"), w );
256       myToBezier3DCurveChk = new QCheckBox( tr("GEOM_3D_CURVE_MODE"), w );
257       myToBezier2DCurveChk = new QCheckBox( tr("GEOM_2D_CURVE_MODE"), w );
258   
259       myToBezierMaxTol = new QtxDoubleSpinBox(  0., 100., 1e-7, 10, 10, w );
260
261       aLay->addWidget( myToBezierSurfModeChk, 0, 0 );
262       aLay->addWidget( myToBezier3DCurveChk, 1, 0 );
263       aLay->addWidget( myToBezier2DCurveChk, 2, 0 );
264       aLay->addWidget( new QLabel( tr( "GEOM_MAX_TOLERANCE" ), w ), 3, 0 );
265       aLay->addWidget( myToBezierMaxTol, 3, 1 );
266       aLay->setRowStretch( aLay->rowCount(), 5 );
267     }
268     else if ( myOpLst[i] == "SameParameter" ) {
269       // SameParameter
270       w = new QWidget( aParamsGr );
271       QGridLayout* aLay = new QGridLayout( w );
272       aLay->setMargin( 9 ); aLay->setSpacing( 6 );
273
274       mySameParameterTol3D = new QtxDoubleSpinBox( 0., 100., 1e-7, 10, 10, w );
275       
276       aLay->addWidget( new QLabel( tr( "GEOM_3D_TOLERANCE" ), w ), 0, 0 );
277       aLay->addWidget( mySameParameterTol3D, 0, 1 );
278       aLay->setRowStretch( aLay->rowCount(), 5 );
279     }
280     else {
281       w = new QWidget( aParamsGr ); // dumb widget
282     }
283     aStack->insertWidget( i, w );
284   }
285
286   QGridLayout* layout = new QGridLayout( centralWidget() );
287   layout->setMargin( 0 ); layout->setSpacing( 6 );
288   layout->addWidget( mySelectWdgt, 0, 0, 1, 2 );
289   layout->addWidget( anOperGr,     1, 0 );
290   layout->addWidget( aParamsGr,    1, 1 );
291
292   // signals and slots connections
293   connect( buttonOk(),    SIGNAL( clicked() ), this, SLOT( onOk() ) );
294   connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( onApply() ) );
295
296   connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
297            SIGNAL( currentSelectionChanged() ), this, SLOT( selectionChanged() ) );
298
299   connect( mySelectWdgt->PushButton1, SIGNAL( clicked() ),       this, SLOT( selectClicked() ) );
300   connect( mySelectWdgt->LineEdit1,   SIGNAL( returnPressed() ), this, SLOT( lineEditReturnPressed() ) );
301
302   connect( myToBezierSurfModeChk,     SIGNAL( toggled( bool ) ), this, SLOT( advOptionToggled( bool ) ) );
303
304   connect( myOpList, SIGNAL( currentRowChanged( int ) ), aStack, SLOT( setCurrentIndex( int ) ) );
305
306   adjustSize();
307   loadDefaults(); // init dialog fields with values from resource file
308   //myOpList->setCurrentRow( myOpList->findItem( 0 );
309   reset();
310
311   initName( tr( "PROCESS_SHAPE_NEW_OBJ_NAME" ) );
312 }
313
314 //=================================================================================
315 // function : onOk()
316 // purpose  : Same than click on apply but close this dialog.
317 //=================================================================================
318 void RepairGUI_ShapeProcessDlg::onOk()
319 {
320   if ( onApply() )
321     ClickOnCancel();
322 }
323
324 //=================================================================================
325 // function : onApply()
326 // purpose  :
327 //=================================================================================
328 bool RepairGUI_ShapeProcessDlg::onApply()
329 {
330   if ( !onAccept() )
331     return false;
332
333   initName();
334
335   reset();
336   initSelection();
337   
338   return true;
339 }
340
341
342 //=================================================================================
343 // function : selectionChanged()
344 // purpose  : Called when selection as changed or other case
345 //          : used only by SelectButtonC1A1 (LineEditC1A1)
346 //=================================================================================
347 void RepairGUI_ShapeProcessDlg::selectionChanged()
348 {
349   reset();
350         
351   LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
352   SALOME_ListIO aSelList;
353   aSelMgr->selectedObjects(aSelList);
354
355   Standard_Boolean aRes = Standard_False;
356   int i = 0;
357   myObjects->length(aSelList.Extent());
358   for (SALOME_ListIteratorOfListIO anIt (aSelList); anIt.More(); anIt.Next()) {
359     GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( anIt.Value(), aRes );
360     if ( !CORBA::is_nil( aSelectedObject ) && aRes )
361         myObjects[i++] = aSelectedObject;
362   }
363   myObjects->length( i );
364   if ( i == 1 )
365     mySelectWdgt->LineEdit1->setText( GEOMBase::GetName( myObjects[0] ) );
366   else if ( i > 0 )
367     mySelectWdgt->LineEdit1->setText( QString::number( i ) + "_" + tr( "GEOM_OBJECTS" ) );
368 }
369
370
371 //=================================================================================
372 // function : selectClicked()
373 // purpose  :
374 //=================================================================================
375 void RepairGUI_ShapeProcessDlg::selectClicked()
376 {
377   myEditCurrentArgument = mySelectWdgt->LineEdit1;
378   mySelectWdgt->LineEdit1->setFocus();
379   selectionChanged();
380 }
381
382
383 //=================================================================================
384 // function : lineEditReturnPressed()
385 // purpose  :
386 //=================================================================================
387 void RepairGUI_ShapeProcessDlg::lineEditReturnPressed()
388 {
389   GEOMBase_Skeleton::LineEditReturnPressed();
390 }
391
392
393 //=================================================================================
394 // function : activate()
395 // purpose  :
396 //=================================================================================
397 void RepairGUI_ShapeProcessDlg::activate()
398 {
399   GEOMBase_Skeleton::ActivateThisDialog();
400   connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication( ) ))->selectionMgr(),
401            SIGNAL( currentSelectionChanged() ), this, SLOT( selectionChanged() ) );
402         
403   reset();
404   //myGeomGUI->SetState( 0 );
405   initSelection();
406 }
407
408
409 //=================================================================================
410 // function : enterEvent()
411 // purpose  : Mouse enter onto the dialog to activate it
412 //=================================================================================
413 void RepairGUI_ShapeProcessDlg::enterEvent( QEvent* )
414 {
415   if ( !mainFrame()->GroupBoxName->isEnabled() )
416     activate();
417 }
418
419
420 //=================================================================================
421 // function : reset()
422 // purpose  : Completely reset the state of method including local context
423 //=================================================================================
424 void RepairGUI_ShapeProcessDlg::reset()
425 {
426   myObjects = new GEOM::ListOfGO();
427   myObjects->length( 0 );       
428   mySelectWdgt->LineEdit1->setText( "" );
429 }
430
431
432 //=================================================================================
433 // function : get_convert
434 // purpose  : conversion of angle values to radians (non-angle values are not converted)
435 //=================================================================================
436 const char* get_convert( const char* theParam, const QString& theValue )
437 {
438   if ( !strcmp( theParam, "SplitAngle.Angle" ) ) {
439     double doubleValue = theValue.toDouble() * PI / 180;
440     return CORBA::string_dup( QString::number( doubleValue ).toLatin1().constData() );
441   }
442   return CORBA::string_dup( theValue.toLatin1().constData() );
443 }
444
445 //=================================================================================
446 // function : set_convert
447 // purpose  : conversion of angle values to degrees (non-angle values are not converted)
448 //=================================================================================
449 const char* set_convert( const char* theParam, const char* theValue )
450 {
451   if ( !strcmp( theParam, "SplitAngle.Angle" ) ) {
452     double doubleValue = atof( theValue ) * 180 / PI;
453     TCollection_AsciiString str( doubleValue );
454     return CORBA::string_dup( str.ToCString() );
455   }
456   return CORBA::string_dup( theValue );
457 }
458
459 //=================================================================================
460 // function : loadDefaults()
461 // purpose  : initialize "values"-fields with default values retrieved from IHealingOperations
462 //=================================================================================
463 void RepairGUI_ShapeProcessDlg::loadDefaults()
464 {
465   GEOM::GEOM_IHealingOperations_var anOp = myGeomGUI->GetGeomGen()->GetIHealingOperations( getStudyId() );
466   GEOM::string_array_var anOperators, aParams, aValues;
467   anOp->GetShapeProcessParameters( anOperators, aParams, aValues );
468
469   // check the default items-operators
470   for ( int i = 0; i < anOperators->length(); i++ ) {
471     //MESSAGE("-->"<<(const char*)anOperators[i]);
472     QList<QListWidgetItem*> items = myOpList->findItems ( (const char*)anOperators[i], Qt::MatchFixedString );
473     if ( items.count() ) 
474       ( items[0] )->setCheckState( Qt::Checked );
475   }
476
477   // Retrieve default parameters for ALL operators
478   for ( int i = 0; i < myOpList->count(); i++ ) {
479     CORBA::String_var anOperator = CORBA::string_dup( myOpList->item( i )->text().toLatin1().constData() );
480     anOp->GetOperatorParameters( anOperator.in(), aParams, aValues );
481
482     // set default values of parameters
483     if ( aParams->length() != aValues->length() )
484       continue;
485
486     for ( int j = 0; j < aParams->length(); j++ ) {
487       QWidget* aCtrl = getControl( (const char*)aParams[j] );
488       const char* aValue = set_convert( (const char*)aParams[j], aValues[j] );
489       setValue( aCtrl, aValue );
490     }
491   }
492 }
493
494 //=================================================================================
495 // function : setValue()
496 // purpose  : set value in the proper way
497 //=================================================================================
498 void RepairGUI_ShapeProcessDlg::setValue( QWidget* theControl, const QString& theValue )
499 {
500   if ( theControl && !theValue.isNull() ) {
501     if ( qobject_cast<QtxDoubleSpinBox*>( theControl ) )
502       qobject_cast<QtxDoubleSpinBox*>( theControl )->setValue( theValue.toDouble() );
503     else if ( qobject_cast<QSpinBox*>( theControl ) )
504       qobject_cast<QSpinBox*>( theControl )->setValue( theValue.toInt() );
505     else if ( qobject_cast<QComboBox*>( theControl ) )
506       qobject_cast<QComboBox*>( theControl )->setEditText( theValue );
507     else if ( qobject_cast<QCheckBox*>( theControl ) )
508       qobject_cast<QCheckBox*>( theControl )->setChecked( theValue.toInt() != 0 );
509   }
510 }
511
512 //=================================================================================
513 // function : getValue()
514 // purpose  : get value in the proper way
515 //=================================================================================
516 QString RepairGUI_ShapeProcessDlg::getValue( QWidget* theControl ) const
517 {
518   if ( theControl ) {
519     if ( qobject_cast<QtxDoubleSpinBox*>( theControl ) )
520       return QString::number( qobject_cast<QtxDoubleSpinBox*>( theControl )->value() );
521     else if ( qobject_cast<QSpinBox*>( theControl ) )
522       return QString::number( qobject_cast<QSpinBox*>( theControl )->value() );
523     else if ( qobject_cast<QComboBox*>( theControl ) )
524       return qobject_cast<QComboBox*>( theControl )->currentText();
525     else if ( qobject_cast<QCheckBox*>( theControl ) )
526       return qobject_cast<QCheckBox*>( theControl )->isChecked() ? "1" : "0";
527   }   
528   return 0;
529 }
530
531 //=================================================================================
532 // function : createOperation
533 // purpose  :
534 //=================================================================================
535 GEOM::GEOM_IOperations_ptr RepairGUI_ShapeProcessDlg::createOperation()
536 {
537   return getGeomEngine()->GetIHealingOperations( getStudyId() );
538 }
539
540 //=================================================================================
541 // function : isValid
542 // purpose  :
543 //=================================================================================
544 bool RepairGUI_ShapeProcessDlg::isValid( QString& msg )
545 {
546   bool error = false;
547   GEOM::string_array_var anOperators = getActiveOperators();
548   if ( !myObjects->length() ) {
549     msg += tr( "ERROR_NO_OBJECTS" );
550     error = true;
551   }
552   if ( !anOperators->length() ) {
553     if ( error ) 
554       msg += "\n";
555     msg += tr( "ERROR_NO_OPERATORS" );
556     error = true;
557   }
558   return !error;
559 }
560
561 //=================================================================================
562 // function : execute
563 // purpose  :
564 //=================================================================================
565 bool RepairGUI_ShapeProcessDlg::execute( ObjectList& objects )
566 {
567   GEOM::string_array_var anOperators = getActiveOperators();
568   GEOM::string_array_var aParams = getParameters( anOperators );
569   GEOM::string_array_var aValues = getValues( aParams );
570
571   /*//-- check --
572   int z;
573         MESSAGE("Objects : ");
574         for ( z = 0; z < myObjects->length(); z++ )
575                 MESSAGE(myObjects[z]->GetName() << " ");
576         MESSAGE("\nOperators : ");
577         for ( z = 0; z < anOperators->length(); z++ )
578                 MESSAGE(anOperators[z] << " ");
579         MESSAGE("\nParameters : ");
580         for ( z = 0; z < aParams->length(); z++ )
581                 MESSAGE(aParams[z] << " ");
582         MESSAGE("\nValues : ");
583         for ( z = 0; z < aValues->length(); z ++ )
584                 MESSAGE(aValues[z] << " ");
585         MESSAGE("\n");
586   */// -----------
587
588   QStringList anErrorObjNames;
589   for ( int i = 0; i < myObjects->length(); i++ ) {
590     GEOM::GEOM_Object_var obj = myObjects[i];
591     GEOM::GEOM_Object_var anObj = GEOM::GEOM_IHealingOperations::_narrow( getOperation() )->
592       ProcessShape( obj, anOperators, aParams, aValues );
593     if ( anObj->_is_nil() )
594       anErrorObjNames << GEOMBase::GetName( obj );
595     else
596       objects.push_back( anObj._retn() );
597   }
598
599   if ( !anErrorObjNames.empty() )
600     MESSAGE( "ERRORS occured while processing the following objects: " << anErrorObjNames.join( " " ).toLatin1().data() );
601     
602   return anErrorObjNames.size() < myObjects->length(); // true if at least one object was OK, false if ALL objects were nil after Healing.
603 }
604
605 //=================================================================================
606 // function : getActiveOperators
607 // purpose  :
608 //=================================================================================
609 GEOM::string_array* RepairGUI_ShapeProcessDlg::getActiveOperators()
610 {
611   GEOM::string_array_var anOperators = new GEOM::string_array();
612   QStringList aCheckedList;
613
614   for ( int i = 0; i < myOpList->count(); i++ ) {
615     if ( myOpList->item( i )->checkState() == Qt::Checked )
616       aCheckedList << myOpList->item( i )->text();
617   }
618
619   anOperators->length( aCheckedList.count() );
620
621   for ( int i = 0; i < aCheckedList.count(); i++ )
622     anOperators[i] = CORBA::string_dup( aCheckedList[i].toLatin1().constData() );
623                  
624   return anOperators._retn();
625 }
626
627 //=================================================================================
628 // function : getcontrol
629 // purpose  :
630 //=================================================================================
631 QWidget* RepairGUI_ShapeProcessDlg::getControl( const QString& theParam )
632 {
633   if ( theParam == "SplitAngle.Angle" )                           return mySplitAngleAngle;
634   else if ( theParam == "SplitAngle.MaxTolerance" )               return mySplitAngleMaxTol;
635   else if ( theParam == "SplitClosedFaces.NbSplitPoints" )        return mySplitClosedFacesNum;
636   else if ( theParam == "FixFaceSize.Tolerance" )                 return myFixFaceSizeTol;
637   else if ( theParam == "DropSmallEdges.Tolerance3d" )            return myDropSmallEdgesTol3D;
638   else if ( theParam == "BSplineRestriction.SurfaceMode" )        return myBSplineSurfModeChk;
639   else if ( theParam == "BSplineRestriction.Curve3dMode" )        return myBSpline3DCurveChk;
640   else if ( theParam == "BSplineRestriction.Curve2dMode" )        return myBSpline2DCurveChk;
641   else if ( theParam == "BSplineRestriction.Tolerance3d" )        return myBSplineTol3D;
642   else if ( theParam == "BSplineRestriction.Tolerance2d" )        return myBSplineTol2D;
643   else if ( theParam == "BSplineRestriction.RequiredDegree" )     return myBSplineDegree;
644   else if ( theParam == "BSplineRestriction.RequiredNbSegments" ) return myBSplineSegments;
645   else if ( theParam == "BSplineRestriction.Continuity3d" )       return myBSpline3DCont;
646   else if ( theParam == "BSplineRestriction.Continuity2d" )       return myBSpline2DCont;
647   else if ( theParam == "SplitContinuity.Tolerance3d" )           return mySplitContTol3D;
648   else if ( theParam == "SplitContinuity.SurfaceContinuity" )     return mySplitContSurfCont;
649   else if ( theParam == "SplitContinuity.CurveContinuity" )       return mySplitContCurvCont;
650   else if ( theParam == "ToBezier.SurfaceMode" )                  return myToBezierSurfModeChk;
651   else if ( theParam == "ToBezier.Curve3dMode" )                  return myToBezier3DCurveChk;
652   else if ( theParam == "ToBezier.Curve2dMode" )                  return myToBezier2DCurveChk;
653   else if ( theParam == "ToBezier.MaxTolerance" )                 return myToBezierMaxTol;
654   else if ( theParam == "SameParameter.Tolerance3d" )             return mySameParameterTol3D;
655   else if ( theParam == "FixShape.Tolerance3d" )                  return myFixShapeTol3D;
656   else if ( theParam == "FixShape.MaxTolerance3d" )               return myFixShapeMaxTol3D;
657   return 0;
658 }
659
660 //=================================================================================
661 // function : getParameters
662 // purpose  :
663 //=================================================================================
664 void RepairGUI_ShapeProcessDlg::initParamsValues()
665 {
666   if ( myOpLst.count() )
667     return;  // already filled
668
669   myOpLst << "FixShape";
670   myValMap["FixShape"] << "FixShape.Tolerance3d";
671   myValMap["FixShape"] << "FixShape.MaxTolerance3d";
672
673   myOpLst << "FixFaceSize";
674   myValMap["FixFaceSize"] << "FixFaceSize.Tolerance";
675
676   myOpLst << "DropSmallEdges";
677   myValMap["DropSmallEdges"] << "DropSmallEdges.Tolerance3d";
678
679   myOpLst << "SplitAngle";
680   myValMap["SplitAngle"] << "SplitAngle.Angle";
681   myValMap["SplitAngle"] << "SplitAngle.MaxTolerance";
682
683   myOpLst << "SplitClosedFaces";
684   myValMap["SplitClosedFaces"] << "SplitClosedFaces.NbSplitPoints";
685
686   myOpLst << "SplitContinuity";
687   myValMap["SplitContinuity"] << "SplitContinuity.Tolerance3d";
688   myValMap["SplitContinuity"] << "SplitContinuity.SurfaceContinuity";
689   myValMap["SplitContinuity"] << "SplitContinuity.CurveContinuity";
690
691   myOpLst << "BSplineRestriction";
692   myValMap["BSplineRestriction"] << "BSplineRestriction.SurfaceMode";
693   myValMap["BSplineRestriction"] << "BSplineRestriction.Curve3dMode";
694   myValMap["BSplineRestriction"] << "BSplineRestriction.Curve2dMode";
695   myValMap["BSplineRestriction"] << "BSplineRestriction.Tolerance3d";
696   myValMap["BSplineRestriction"] << "BSplineRestriction.Tolerance2d";
697   myValMap["BSplineRestriction"] << "BSplineRestriction.RequiredDegree";
698   myValMap["BSplineRestriction"] << "BSplineRestriction.RequiredNbSegments";
699   myValMap["BSplineRestriction"] << "BSplineRestriction.Continuity3d";
700   myValMap["BSplineRestriction"] << "BSplineRestriction.Continuity2d";
701
702   myOpLst << "ToBezier";
703   myValMap["ToBezier"] << "ToBezier.SurfaceMode";
704   myValMap["ToBezier"] << "ToBezier.Curve3dMode";
705   myValMap["ToBezier"] << "ToBezier.Curve2dMode";
706   myValMap["ToBezier"] << "ToBezier.MaxTolerance";
707
708   myOpLst << "SameParameter";
709   myValMap["SameParameter"] << "SameParameter.Tolerance3d";
710 }
711
712 //=================================================================================
713 // function : getParameters
714 // purpose  :
715 //=================================================================================
716 GEOM::string_array* RepairGUI_ShapeProcessDlg::getParameters( const GEOM::string_array& theOperators )
717 {
718   GEOM::string_array_var aParams = new GEOM::string_array();
719   int i = 0, j = 0;
720
721   // calculate the length of parameters
722   for ( i = 0, j = 0; i < theOperators.length(); i++ )
723     j += myValMap[ QString( theOperators[i] ) ].size();
724   
725   // set the new length of paremeters
726   aParams->length( j );
727
728   // fill the parameters
729   for ( i = 0, j = 0; i < theOperators.length(); i++ ) {
730     QStringList aValLst = myValMap[ QString( theOperators[i] ) ];
731     for ( QStringList::Iterator it = aValLst.begin(); it != aValLst.end(); ++it )
732       aParams[j++] = CORBA::string_dup( (*it).toLatin1().constData() );
733   }
734
735   return aParams._retn();
736 }
737
738
739 //=================================================================================
740 // function : getValues
741 // purpose  :
742 //=================================================================================
743 GEOM::string_array* RepairGUI_ShapeProcessDlg::getValues( const GEOM::string_array& theParams )
744 {
745   GEOM::string_array_var aValues = new GEOM::string_array();
746   aValues->length( theParams.length() );
747     
748   for ( int i = 0; i < theParams.length(); i++ ) {
749     QWidget* aCtrl = getControl( (const char*)theParams[i] );
750     if ( aCtrl )
751       aValues[i] = get_convert( (const char*)theParams[i], getValue( aCtrl ) );
752   }
753     
754   return aValues._retn();
755 }
756
757 //=================================================================================
758 // function : initSelection
759 // purpose  : set selection of ALL shape types except vertexes
760 //=================================================================================
761 void RepairGUI_ShapeProcessDlg::initSelection()
762 {
763   TColStd_MapOfInteger aTypes;
764   aTypes.Add( GEOM_COMPOUND );
765   aTypes.Add( GEOM_SOLID );
766   aTypes.Add( GEOM_SHELL );
767   aTypes.Add( GEOM_FACE );
768   aTypes.Add( GEOM_WIRE );
769   aTypes.Add( GEOM_EDGE );
770   globalSelection( aTypes );
771 }
772
773 //=================================================================================
774 // function : advOptionToggled
775 // purpose  : this slot is used to warn the user about possible consequences
776 //            of enabling some advanced options
777 //=================================================================================
778 void RepairGUI_ShapeProcessDlg::advOptionToggled( bool on )
779 {
780   QAbstractButton* btn = (QAbstractButton*)sender();
781   if ( on && btn->isCheckable() &&
782        SUIT_MessageBox::warning( this,
783                                  tr( "GEOM_WRN_WARNING" ), tr( "TIME_CONSUMING" ),
784                                  SUIT_MessageBox::Yes | SUIT_MessageBox::No ) == SUIT_MessageBox::No )
785     btn->toggle();
786 }