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