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