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