Salome HOME
22763: [EDF] Shape processing
[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   myStack = 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] == "DropSmallSolids" ) {
156       // DropSmallSolids
157       w = new QWidget( aParamsGr );
158       QGridLayout* aLay = new QGridLayout( w );
159       aLay->setMargin( 9 ); aLay->setSpacing( 6 );
160
161       myDropSmallSolidsWidChk = new QCheckBox( tr("WIDTH_FACTOR_TOL"), w );
162       myDropSmallSolidsVolChk = new QCheckBox( tr("VOLUME_TOL"), w );
163       myDropSmallSolidsWidTol = new SalomeApp_DoubleSpinBox( w );
164       myDropSmallSolidsVolTol = new SalomeApp_DoubleSpinBox( w );
165       initSpinBox( myDropSmallSolidsWidTol, 0., 100., 1e-7, "len_tol_precision" );
166       initSpinBox( myDropSmallSolidsVolTol, 0., 100., 1e-7, "len_tol_precision" );
167       myDropSmallSolidsWidTol->setValue( 1e-7 );
168       myDropSmallSolidsVolTol->setValue( 1e-7 );
169       myDropSmallSolidsVolChk->setChecked( true );
170       myDropSmallSolidsWidTol->setEnabled( false );
171       myDropSmallSolidsMergeChk = new QCheckBox( tr("TO_MERGE_SOLIDS"), w );
172   
173       aLay->addWidget( myDropSmallSolidsWidChk, 0, 0 );
174       aLay->addWidget( myDropSmallSolidsWidTol, 0, 1 );
175       aLay->addWidget( myDropSmallSolidsVolChk, 1, 0 );
176       aLay->addWidget( myDropSmallSolidsVolTol, 1, 1 );
177       aLay->addWidget( myDropSmallSolidsMergeChk, 2, 0, 1, 2 );
178
179       aLay->setRowStretch( aLay->rowCount(), 5 );
180     }
181     else if ( myOpLst[i] == "DropSmallEdges" ) {
182       // DropSmallEdges
183       w = new QWidget( aParamsGr );
184       QGridLayout* aLay = new QGridLayout( w );
185       aLay->setMargin( 9 ); aLay->setSpacing( 6 );
186       
187       myDropSmallEdgesTol3D = new SalomeApp_DoubleSpinBox( w );
188       initSpinBox( myDropSmallEdgesTol3D, 0., 100., 1e-7, "len_tol_precision" );
189   
190       aLay->addWidget( new QLabel( tr( "GEOM_3D_TOLERANCE" ), w ), 0, 0 );
191       aLay->addWidget( myDropSmallEdgesTol3D, 0, 1 );
192       aLay->setRowStretch( aLay->rowCount(), 5 );
193     }
194     else if ( myOpLst[i] == "SplitAngle" ) {
195       // SplitAngle
196       w = new QWidget( aParamsGr );
197       QGridLayout* aLay = new QGridLayout( w );
198       aLay->setMargin( 9 ); aLay->setSpacing( 6 );
199       
200       mySplitAngleAngle = new SalomeApp_DoubleSpinBox( w );
201       initSpinBox( mySplitAngleAngle, 0, 360, 1, "angle_precision" );      
202       mySplitAngleMaxTol = new SalomeApp_DoubleSpinBox( w );
203       initSpinBox( mySplitAngleMaxTol, 0., 100., 1e-7, "ang_tol_precision" );      
204       
205       aLay->addWidget( new QLabel( tr( "GEOM_ANGLE_1" ), w ), 0, 0 );
206       aLay->addWidget( mySplitAngleAngle, 0, 1 );
207       aLay->addWidget( new QLabel( tr( "GEOM_MAX_TOLERANCE" ), w ), 1, 0 );
208       aLay->addWidget( mySplitAngleMaxTol, 1, 1 );
209       aLay->setRowStretch( aLay->rowCount(), 5 );
210     }
211     else if ( myOpLst[i] == "SplitClosedFaces" ) {
212       // SplitClosedFaces
213       w = new QWidget( aParamsGr );
214       QGridLayout* aLay = new QGridLayout( w );
215       aLay->setMargin( 9 ); aLay->setSpacing( 6 );
216       
217       mySplitClosedFacesNum = new SalomeApp_IntSpinBox( w );
218   
219       aLay->addWidget( new QLabel( tr( "GEOM_NUM_SPLIT_POINTS" ), w ), 0, 0 );
220       aLay->addWidget( mySplitClosedFacesNum, 0, 1 );
221       aLay->setRowStretch( aLay->rowCount(), 5 );
222     }      
223     else if ( myOpLst[i] == "SplitContinuity" ) {
224       // SplitContinuity
225       w = new QWidget( aParamsGr );
226       QGridLayout* aLay = new QGridLayout( w );
227       aLay->setMargin( 9 ); aLay->setSpacing( 6 );
228
229       mySplitContTol3D = new SalomeApp_DoubleSpinBox( w );
230       initSpinBox( mySplitContTol3D, 0., 100., 1e-7, "len_tol_precision" );
231       mySplitContSurfCont = new QComboBox( w );
232       mySplitContSurfCont->addItems( aContinueties );
233       mySplitContCurvCont = new QComboBox( w );
234       mySplitContCurvCont->addItems( aContinueties );
235       
236       aLay->addWidget( new QLabel( tr( "GEOM_3D_TOLERANCE" ), w ), 0, 0 );
237       aLay->addWidget( mySplitContTol3D, 0, 1 );
238       aLay->addWidget( new QLabel( tr( "GEOM_SURFACE_CONTINUTY" ), w ), 1, 0 );
239       aLay->addWidget( mySplitContSurfCont, 1, 1 );
240       aLay->addWidget( new QLabel( tr( "GEOM_CURVE_CONTINUTY" ), w ), 2, 0 );
241       aLay->addWidget( mySplitContCurvCont, 2, 1 );
242       aLay->setRowStretch( aLay->rowCount(), 5 );
243     }
244     else if ( myOpLst[i] == "BSplineRestriction" ) {
245       // BSplineRestriction
246       w = new QWidget( aParamsGr );
247       QGridLayout* aLay = new QGridLayout( w );
248       aLay->setMargin( 9 ); aLay->setSpacing( 6 );
249
250       myBSplineSurfModeChk = new QCheckBox( tr("GEOM_SURFACE_MODE"), w );
251       myBSpline3DCurveChk = new QCheckBox( tr("GEOM_3D_CURVE_MODE"), w );
252       myBSpline2DCurveChk = new QCheckBox( tr("GEOM_2D_CURVE_MODE"), w );
253
254       myBSplineTol3D = new SalomeApp_DoubleSpinBox( w );
255       initSpinBox( myBSplineTol3D, 0., 100., 1e-7, "len_tol_precision" );
256       
257       myBSplineTol2D = new SalomeApp_DoubleSpinBox( w );
258       initSpinBox( myBSplineTol2D, 0., 100., 1e-7, "param_tol_precision" );      
259
260       myBSplineDegree = new SalomeApp_IntSpinBox( w );
261       myBSplineSegments = new SalomeApp_IntSpinBox( w );
262       myBSpline2DCont = new QComboBox( w );
263       myBSpline2DCont->addItems( aContinueties );
264       myBSpline3DCont = new QComboBox( w );
265       myBSpline3DCont->addItems( aContinueties );
266       
267       myBSplineSurfModeChk->setChecked( true );
268       myBSpline3DCurveChk->setChecked( true );
269       myBSpline2DCurveChk->setChecked( true );
270
271       aLay->addWidget( myBSplineSurfModeChk, 0, 0 );
272       aLay->addWidget( myBSpline3DCurveChk,  1, 0 );
273       aLay->addWidget( myBSpline2DCurveChk,  2, 0 );
274       aLay->addWidget( new QLabel( tr( "GEOM_3D_TOLERANCE" ), w ), 3, 0 );
275       aLay->addWidget( myBSplineTol3D, 3, 1 );
276       aLay->addWidget( new QLabel( tr( "GEOM_2D_TOLERANCE" ), w ), 4, 0 );
277       aLay->addWidget( myBSplineTol2D, 4, 1 );
278       aLay->addWidget( new QLabel( tr( "GEOM_REQUIRED_DEGREE" ), w ), 5, 0 );
279       aLay->addWidget( myBSplineDegree, 5, 1 );
280       aLay->addWidget( new QLabel( tr( "GEOM_REQUIRED_NUM_SEGMENTS" ), w ), 6, 0 );
281       aLay->addWidget( myBSplineSegments, 6, 1 );
282       aLay->addWidget( new QLabel( tr( "GEOM_3D_CONTINUTY" ), w ), 7, 0 );
283       aLay->addWidget( myBSpline3DCont, 7, 1 );
284       aLay->addWidget( new QLabel( tr( "GEOM_2D_CONTINUTY" ), w ), 8, 0 );
285       aLay->addWidget( myBSpline2DCont, 8, 1 );
286       aLay->setRowStretch( aLay->rowCount(), 5 );
287     }
288     else if ( myOpLst[i] == "ToBezier" ) {
289       // ToBezier
290       w = new QWidget( aParamsGr );
291       QGridLayout* aLay = new QGridLayout( w );
292       aLay->setMargin( 9 ); aLay->setSpacing( 6 );
293
294       myToBezierSurfModeChk = new QCheckBox( tr("GEOM_SURFACE_MODE"), w );
295       myToBezier3DCurveChk = new QCheckBox( tr("GEOM_3D_CURVE_MODE"), w );
296       myToBezier2DCurveChk = new QCheckBox( tr("GEOM_2D_CURVE_MODE"), w );
297   
298       myToBezierMaxTol = new SalomeApp_DoubleSpinBox( w );
299       initSpinBox( myToBezierMaxTol, 0., 100., 1e-7, "len_tol_precision" );            
300
301       aLay->addWidget( myToBezierSurfModeChk, 0, 0 );
302       aLay->addWidget( myToBezier3DCurveChk, 1, 0 );
303       aLay->addWidget( myToBezier2DCurveChk, 2, 0 );
304       aLay->addWidget( new QLabel( tr( "GEOM_MAX_TOLERANCE" ), w ), 3, 0 );
305       aLay->addWidget( myToBezierMaxTol, 3, 1 );
306       aLay->setRowStretch( aLay->rowCount(), 5 );
307     }
308     else if ( myOpLst[i] == "SameParameter" ) {
309       // SameParameter
310       w = new QWidget( aParamsGr );
311       QGridLayout* aLay = new QGridLayout( w );
312       aLay->setMargin( 9 ); aLay->setSpacing( 6 );
313
314       mySameParameterTol3D = new SalomeApp_DoubleSpinBox( w );
315       initSpinBox( mySameParameterTol3D, 0., 100., 1e-7, "len_tol_precision" );            
316       
317       aLay->addWidget( new QLabel( tr( "GEOM_3D_TOLERANCE" ), w ), 0, 0 );
318       aLay->addWidget( mySameParameterTol3D, 0, 1 );
319       aLay->setRowStretch( aLay->rowCount(), 5 );
320     }
321     else {
322       w = new QWidget( aParamsGr ); // dumb widget
323     }
324     myStack->insertWidget( i, w );
325   }
326
327   QGridLayout* layout = new QGridLayout( centralWidget() );
328   layout->setMargin( 0 ); layout->setSpacing( 6 );
329   layout->addWidget( mySelectWdgt, 0, 0, 1, 2 );
330   layout->addWidget( anOperGr,     1, 0 );
331   layout->addWidget( aParamsGr,    1, 1 );
332
333   // signals and slots connections
334   connect( buttonOk(),    SIGNAL( clicked() ), this, SLOT( onOk() ));
335   connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( onApply() ));
336
337   connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ))->selectionMgr(),
338            SIGNAL( currentSelectionChanged() ), this, SLOT( selectionChanged() ));
339
340   connect( mySelectWdgt->PushButton1, SIGNAL( clicked() ),       this, SLOT( selectClicked() ));
341   connect( mySelectWdgt->LineEdit1,   SIGNAL( returnPressed() ), this, SLOT( lineEditReturnPressed() ));
342
343   connect( myToBezierSurfModeChk,     SIGNAL( toggled( bool )), this, SLOT( advOptionToggled( bool )));
344   connect( myDropSmallSolidsWidChk,   SIGNAL( toggled( bool )), this, SLOT( advOptionToggled( bool )));
345   connect( myDropSmallSolidsVolChk,   SIGNAL( toggled( bool )), this, SLOT( advOptionToggled( bool )));
346
347   connect( myOpList, SIGNAL( currentRowChanged( int )),      myStack, SLOT( setCurrentIndex( int )));
348   connect( myOpList, SIGNAL( itemChanged( QListWidgetItem* )),  this, SLOT( operatorChecked( QListWidgetItem* )));
349
350   adjustSize();
351   loadDefaults(); // init dialog fields with values from resource file
352   //myOpList->setCurrentRow( myOpList->findItem( 0 );
353   reset();
354
355   myStack->setCurrentIndex( 0 );
356
357   initName( tr( "PROCESS_SHAPE_NEW_OBJ_NAME" ));
358   selectionChanged();
359 }
360
361 //=================================================================================
362 // function : onOk()
363 // purpose  : Same than click on apply but close this dialog.
364 //=================================================================================
365 void RepairGUI_ShapeProcessDlg::onOk()
366 {
367   setIsApplyAndClose( true );
368   if ( onApply() )
369     ClickOnCancel();
370 }
371
372 //=================================================================================
373 // function : onApply()
374 // purpose  :
375 //=================================================================================
376 bool RepairGUI_ShapeProcessDlg::onApply()
377 {
378   if ( !onAccept() )
379     return false;
380
381   initName();
382
383   reset();
384   initSelection();
385   
386   return true;
387 }
388
389
390 //=================================================================================
391 // function : selectionChanged()
392 // purpose  : Called when selection as changed or other case
393 //          : used only by SelectButtonC1A1 (LineEditC1A1)
394 //=================================================================================
395 void RepairGUI_ShapeProcessDlg::selectionChanged()
396 {
397   reset();
398         
399   LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
400   SALOME_ListIO aSelList;
401   aSelMgr->selectedObjects(aSelList);
402
403   int i = 0;
404   myObjects->length(aSelList.Extent());
405   for (SALOME_ListIteratorOfListIO anIt (aSelList); anIt.More(); anIt.Next()) {
406     GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( anIt.Value() );
407     if ( !CORBA::is_nil( aSelectedObject ))
408       myObjects[i++] = aSelectedObject;
409   }
410   myObjects->length( i );
411   if ( i == 1 )
412     mySelectWdgt->LineEdit1->setText( GEOMBase::GetName( myObjects[0] ));
413   else if ( i > 0 )
414     mySelectWdgt->LineEdit1->setText( QString::number( i ) + "_" + tr( "GEOM_OBJECTS" ));
415 }
416
417
418 //=================================================================================
419 // function : selectClicked()
420 // purpose  :
421 //=================================================================================
422 void RepairGUI_ShapeProcessDlg::selectClicked()
423 {
424   myEditCurrentArgument = mySelectWdgt->LineEdit1;
425   mySelectWdgt->LineEdit1->setFocus();
426   selectionChanged();
427 }
428
429
430 //=================================================================================
431 // function : lineEditReturnPressed()
432 // purpose  :
433 //=================================================================================
434 void RepairGUI_ShapeProcessDlg::lineEditReturnPressed()
435 {
436   GEOMBase_Skeleton::LineEditReturnPressed();
437 }
438
439
440 //=================================================================================
441 // function : activate()
442 // purpose  :
443 //=================================================================================
444 void RepairGUI_ShapeProcessDlg::activate()
445 {
446   GEOMBase_Skeleton::ActivateThisDialog();
447   connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication( )))->selectionMgr(),
448            SIGNAL( currentSelectionChanged() ), this, SLOT( selectionChanged() ));
449         
450   reset();
451   //myGeomGUI->SetState( 0 );
452   initSelection();
453 }
454
455
456 //=================================================================================
457 // function : enterEvent()
458 // purpose  : Mouse enter onto the dialog to activate it
459 //=================================================================================
460 void RepairGUI_ShapeProcessDlg::enterEvent( QEvent* )
461 {
462   if ( !mainFrame()->GroupBoxName->isEnabled() )
463     activate();
464 }
465
466
467 //=================================================================================
468 // function : reset()
469 // purpose  : Completely reset the state of method including local context
470 //=================================================================================
471 void RepairGUI_ShapeProcessDlg::reset()
472 {
473   myObjects = new GEOM::ListOfGO();
474   myObjects->length( 0 );       
475   mySelectWdgt->LineEdit1->setText( "" );
476 }
477
478
479 //=================================================================================
480 // function : get_convert
481 // purpose  : conversion of angle values to radians (non-angle values are not converted)
482 //=================================================================================
483 const char* get_convert( const char* theParam, const QString& theValue )
484 {
485   if ( !strcmp( theParam, "SplitAngle.Angle" )) {
486     double doubleValue = theValue.toDouble() * M_PI / 180.;
487     return CORBA::string_dup( QString::number( doubleValue ).toLatin1().constData() );
488   }
489   return CORBA::string_dup( theValue.toLatin1().constData() );
490 }
491
492 //=================================================================================
493 // function : set_convert
494 // purpose  : conversion of angle values to degrees (non-angle values are not converted)
495 //=================================================================================
496 QString set_convert( const char* theParam, const char* theValue )
497 {
498   if ( !strcmp( theParam, "SplitAngle.Angle" )) {
499     Kernel_Utils::Localizer loc;
500     double doubleValue = atof( theValue ) * 180. / M_PI;
501     return QString::number( doubleValue );
502   }
503   return QString( theValue );
504 }
505
506 //=================================================================================
507 // function : loadDefaults()
508 // purpose  : initialize "values"-fields with default values retrieved from IHealingOperations
509 //=================================================================================
510 void RepairGUI_ShapeProcessDlg::loadDefaults()
511 {
512   GEOM::GEOM_IHealingOperations_var anOp = myGeomGUI->GetGeomGen()->GetIHealingOperations( getStudyId() );
513   GEOM::string_array_var anOperators, aParams, aValues;
514   anOp->GetShapeProcessParameters( anOperators, aParams, aValues );
515
516   // check the default items-operators
517   for ( int i = 0; i < anOperators->length(); i++ ) {
518     //MESSAGE("-->"<<(const char*)anOperators[i]);
519     QList<QListWidgetItem*> items = myOpList->findItems ( (const char*)anOperators[i], Qt::MatchFixedString );
520     if ( items.count() ) 
521       ( items[0] )->setCheckState( Qt::Checked );
522   }
523
524   // Retrieve default parameters for ALL operators
525   for ( int i = 0; i < myOpList->count(); i++ )
526   {
527     QString anOperator = myOpList->item( i )->text();
528     anOp->GetOperatorParameters( anOperator.toLatin1().constData(), aParams, aValues );
529
530     // set default values of parameters
531     if ( aParams->length() != aValues->length() )
532       continue;
533
534     for ( int j = 0; j < aParams->length(); j++ ) {
535       QWidget* aCtrl = getControl( (const char*)aParams[j] );
536       setValue( aCtrl, set_convert( (const char*)aParams[j], aValues[j] ));
537     }
538   }
539 }
540
541 //=================================================================================
542 // function : setValue()
543 // purpose  : set value in the proper way
544 //=================================================================================
545 void RepairGUI_ShapeProcessDlg::setValue( QWidget* theControl, const QString& theValue )
546 {
547   if ( theControl && !theValue.isNull() ) {
548     if ( qobject_cast<SalomeApp_DoubleSpinBox*>( theControl ))
549       qobject_cast<SalomeApp_DoubleSpinBox*>( theControl )->setValue( theValue.toDouble() );
550     else if ( qobject_cast<SalomeApp_IntSpinBox*>( theControl ))
551       qobject_cast<SalomeApp_IntSpinBox*>( theControl )->setValue( theValue.toInt() );
552     else if ( qobject_cast<QComboBox*>( theControl ))
553       qobject_cast<QComboBox*>( theControl )->setEditText( theValue );
554     else if ( qobject_cast<QCheckBox*>( theControl ))
555       qobject_cast<QCheckBox*>( theControl )->setChecked( theValue.toInt() != 0 );
556   }
557 }
558
559 //=================================================================================
560 // function : getValue()
561 // purpose  : get value in the proper way
562 //=================================================================================
563 QString RepairGUI_ShapeProcessDlg::getValue( QWidget* theControl ) const
564 {
565   if ( theControl ) {
566     if ( qobject_cast<SalomeApp_DoubleSpinBox*>( theControl ))
567       return QString::number( qobject_cast<SalomeApp_DoubleSpinBox*>( theControl )->value() );
568     else if ( qobject_cast<SalomeApp_IntSpinBox*>( theControl ))
569       return QString::number( qobject_cast<SalomeApp_IntSpinBox*>( theControl )->value() );
570     else if ( qobject_cast<QComboBox*>( theControl ))
571       return qobject_cast<QComboBox*>( theControl )->currentText();
572     else if ( qobject_cast<QCheckBox*>( theControl ))
573       return qobject_cast<QCheckBox*>( theControl )->isChecked() ? "1" : "0";
574   }   
575   return 0;
576 }
577
578 //=================================================================================
579 // function : getText()
580 // purpose  : get text in the proper way
581 //=================================================================================
582 QString RepairGUI_ShapeProcessDlg::getText( QWidget* theControl ) const
583 {
584   if ( theControl ) {
585     if ( qobject_cast<SalomeApp_DoubleSpinBox*>( theControl ))
586       return qobject_cast<SalomeApp_DoubleSpinBox*>( theControl )->text();
587     else if ( qobject_cast<SalomeApp_IntSpinBox*>( theControl ))
588       return qobject_cast<SalomeApp_IntSpinBox*>( theControl )->text();
589   }   
590   return QString::null;
591 }
592
593 //=================================================================================
594 // function : createOperation
595 // purpose  :
596 //=================================================================================
597 GEOM::GEOM_IOperations_ptr RepairGUI_ShapeProcessDlg::createOperation()
598 {
599   return getGeomEngine()->GetIHealingOperations( getStudyId() );
600 }
601
602 //=================================================================================
603 // function : isValid
604 // purpose  :
605 //=================================================================================
606 bool RepairGUI_ShapeProcessDlg::isValid( QString& msg )
607 {
608   bool ok = true;
609   QMapIterator<QString,QStringList> aMapIter( myValMap );
610   while( aMapIter.hasNext() ) {
611     aMapIter.next();
612     const QStringList& aList = aMapIter.value();
613     QListIterator<QString> aListIter( aList );
614     while( aListIter.hasNext() ) {
615       const QString& aParam = aListIter.next();
616       QWidget* aControl = getControl( aParam );
617       if ( !aControl->isEnabled() ) continue;
618       if ( qobject_cast<SalomeApp_DoubleSpinBox*>( aControl ))
619         ok = qobject_cast<SalomeApp_DoubleSpinBox*>( aControl )->isValid( msg, !IsPreview() ) && ok;
620       else if ( qobject_cast<SalomeApp_IntSpinBox*>( aControl ))
621         ok = qobject_cast<SalomeApp_IntSpinBox*>( aControl )->isValid( msg, !IsPreview() ) && ok;
622     }
623   }
624
625   bool error = false;
626   GEOM::string_array_var anOperators = getActiveOperators();
627   if ( !myObjects->length() ) {
628     msg += tr( "ERROR_NO_OBJECTS" );
629     error = true;
630   }
631   if ( !anOperators->length() ) {
632     if ( error ) 
633       msg += "\n";
634     msg += tr( "ERROR_NO_OPERATORS" );
635     error = true;
636   }
637   return !error && ok;
638 }
639
640 //=================================================================================
641 // function : execute
642 // purpose  :
643 //=================================================================================
644 bool RepairGUI_ShapeProcessDlg::execute( ObjectList& objects )
645 {
646   GEOM::string_array_var anOperators = getActiveOperators();
647   GEOM::string_array_var aParams = getParameters( anOperators );
648   GEOM::string_array_var aValues = getValues( aParams );
649
650   /*//-- check --
651   int z;
652         MESSAGE("Objects : ");
653         for ( z = 0; z < myObjects->length(); z++ )
654                 MESSAGE(myObjects[z]->GetName() << " ");
655         MESSAGE("\nOperators : ");
656         for ( z = 0; z < anOperators->length(); z++ )
657                 MESSAGE(anOperators[z] << " ");
658         MESSAGE("\nParameters : ");
659         for ( z = 0; z < aParams->length(); z++ )
660                 MESSAGE(aParams[z] << " ");
661         MESSAGE("\nValues : ");
662         for ( z = 0; z < aValues->length(); z ++ )
663                 MESSAGE(aValues[z] << " ");
664         MESSAGE("\n");
665   */// -----------
666
667   QStringList anErrorObjNames;
668   for ( int i = 0; i < myObjects->length(); i++ ) {
669     GEOM::GEOM_Object_var obj = myObjects[i];
670     GEOM::GEOM_IHealingOperations_var anOper = GEOM::GEOM_IHealingOperations::_narrow( getOperation() );
671     GEOM::GEOM_Object_var anObj = anOper->ProcessShape( obj, anOperators, aParams, aValues );
672     if ( anObj->_is_nil() )
673       anErrorObjNames << GEOMBase::GetName( obj );
674     else
675     {
676       if ( !IsPreview() )
677       {
678         QStringList aParameters;
679
680         for ( int i = 0; i < anOperators->length(); i++ )
681           aParameters << QString( anOperators[i] );
682
683         for ( int i = 0; i < aParams->length(); i++ )
684           aParameters << QString( aParams[i] );
685
686         aParameters << getTexts( aParams );
687         anObj->SetParameters(aParameters.join(":").toLatin1().constData());
688
689         RepairGUI::ShowStatistics( anOper, this );
690       }
691       objects.push_back( anObj._retn() );
692     }
693   }
694
695   if ( !anErrorObjNames.empty() )
696     MESSAGE( "ERRORS occured while processing the following objects: " << anErrorObjNames.join( " " ).toLatin1().data() );
697     
698   return anErrorObjNames.size() < myObjects->length(); // true if at least one object was OK, false if ALL objects were nil after Healing.
699 }
700
701 //=================================================================================
702 // function : getActiveOperators
703 // purpose  :
704 //=================================================================================
705 GEOM::string_array* RepairGUI_ShapeProcessDlg::getActiveOperators()
706 {
707   GEOM::string_array_var anOperators = new GEOM::string_array();
708   QStringList aCheckedList;
709
710   for ( int i = 0; i < myOpList->count(); i++ ) {
711     if ( myOpList->item( i )->checkState() == Qt::Checked )
712       aCheckedList << myOpList->item( i )->text();
713   }
714
715   anOperators->length( aCheckedList.count() );
716
717   for ( int i = 0; i < aCheckedList.count(); i++ )
718     anOperators[i] = aCheckedList[i].toLatin1().constData();
719
720   return anOperators._retn();
721 }
722
723 //=================================================================================
724 // function : getcontrol
725 // purpose  :
726 //=================================================================================
727 QWidget* RepairGUI_ShapeProcessDlg::getControl( const QString& theParam )
728 {
729   if ( theParam == "SplitAngle.Angle" )                           return mySplitAngleAngle;
730   else if ( theParam == "SplitAngle.MaxTolerance" )               return mySplitAngleMaxTol;
731   else if ( theParam == "SplitClosedFaces.NbSplitPoints" )        return mySplitClosedFacesNum;
732   else if ( theParam == "FixFaceSize.Tolerance" )                 return myFixFaceSizeTol;
733   else if ( theParam == "DropSmallEdges.Tolerance3d" )            return myDropSmallEdgesTol3D;
734   else if ( theParam == "DropSmallSolids.WidthFactorThreshold" )  return myDropSmallSolidsWidTol;
735   else if ( theParam == "DropSmallSolids.VolumeThreshold" )       return myDropSmallSolidsWidTol;
736   else if ( theParam == "DropSmallSolids.MergeSolids" )           return myDropSmallSolidsMergeChk;
737   else if ( theParam == "BSplineRestriction.SurfaceMode" )        return myBSplineSurfModeChk;
738   else if ( theParam == "BSplineRestriction.Curve3dMode" )        return myBSpline3DCurveChk;
739   else if ( theParam == "BSplineRestriction.Curve2dMode" )        return myBSpline2DCurveChk;
740   else if ( theParam == "BSplineRestriction.Tolerance3d" )        return myBSplineTol3D;
741   else if ( theParam == "BSplineRestriction.Tolerance2d" )        return myBSplineTol2D;
742   else if ( theParam == "BSplineRestriction.RequiredDegree" )     return myBSplineDegree;
743   else if ( theParam == "BSplineRestriction.RequiredNbSegments" ) return myBSplineSegments;
744   else if ( theParam == "BSplineRestriction.Continuity3d" )       return myBSpline3DCont;
745   else if ( theParam == "BSplineRestriction.Continuity2d" )       return myBSpline2DCont;
746   else if ( theParam == "SplitContinuity.Tolerance3d" )           return mySplitContTol3D;
747   else if ( theParam == "SplitContinuity.SurfaceContinuity" )     return mySplitContSurfCont;
748   else if ( theParam == "SplitContinuity.CurveContinuity" )       return mySplitContCurvCont;
749   else if ( theParam == "ToBezier.SurfaceMode" )                  return myToBezierSurfModeChk;
750   else if ( theParam == "ToBezier.Curve3dMode" )                  return myToBezier3DCurveChk;
751   else if ( theParam == "ToBezier.Curve2dMode" )                  return myToBezier2DCurveChk;
752   else if ( theParam == "ToBezier.MaxTolerance" )                 return myToBezierMaxTol;
753   else if ( theParam == "SameParameter.Tolerance3d" )             return mySameParameterTol3D;
754   else if ( theParam == "FixShape.Tolerance3d" )                  return myFixShapeTol3D;
755   else if ( theParam == "FixShape.MaxTolerance3d" )               return myFixShapeMaxTol3D;
756   return 0;
757 }
758
759 //=================================================================================
760 // function : getParameters
761 // purpose  :
762 //=================================================================================
763 void RepairGUI_ShapeProcessDlg::initParamsValues()
764 {
765   if ( myOpLst.count() )
766     return;  // already filled
767
768   myOpLst << "FixShape";
769   myValMap["FixShape"] << "FixShape.Tolerance3d";
770   myValMap["FixShape"] << "FixShape.MaxTolerance3d";
771
772   myOpLst << "FixFaceSize";
773   myValMap["FixFaceSize"] << "FixFaceSize.Tolerance";
774
775   myOpLst << "DropSmallEdges";
776   myValMap["DropSmallEdges"] << "DropSmallEdges.Tolerance3d";
777
778   myOpLst << "DropSmallSolids";
779   myValMap["DropSmallSolids"] << "DropSmallSolids.WidthFactorThreshold";
780   myValMap["DropSmallSolids"] << "DropSmallSolids.VolumeThreshold";
781   myValMap["DropSmallSolids"] << "DropSmallSolids.MergeSolids";
782
783   myOpLst << "SplitAngle";
784   myValMap["SplitAngle"] << "SplitAngle.Angle";
785   myValMap["SplitAngle"] << "SplitAngle.MaxTolerance";
786
787   myOpLst << "SplitClosedFaces";
788   myValMap["SplitClosedFaces"] << "SplitClosedFaces.NbSplitPoints";
789
790   myOpLst << "SplitContinuity";
791   myValMap["SplitContinuity"] << "SplitContinuity.Tolerance3d";
792   myValMap["SplitContinuity"] << "SplitContinuity.SurfaceContinuity";
793   myValMap["SplitContinuity"] << "SplitContinuity.CurveContinuity";
794
795   myOpLst << "BSplineRestriction";
796   myValMap["BSplineRestriction"] << "BSplineRestriction.SurfaceMode";
797   myValMap["BSplineRestriction"] << "BSplineRestriction.Curve3dMode";
798   myValMap["BSplineRestriction"] << "BSplineRestriction.Curve2dMode";
799   myValMap["BSplineRestriction"] << "BSplineRestriction.Tolerance3d";
800   myValMap["BSplineRestriction"] << "BSplineRestriction.Tolerance2d";
801   myValMap["BSplineRestriction"] << "BSplineRestriction.RequiredDegree";
802   myValMap["BSplineRestriction"] << "BSplineRestriction.RequiredNbSegments";
803   myValMap["BSplineRestriction"] << "BSplineRestriction.Continuity3d";
804   myValMap["BSplineRestriction"] << "BSplineRestriction.Continuity2d";
805
806   myOpLst << "ToBezier";
807   myValMap["ToBezier"] << "ToBezier.SurfaceMode";
808   myValMap["ToBezier"] << "ToBezier.Curve3dMode";
809   myValMap["ToBezier"] << "ToBezier.Curve2dMode";
810   myValMap["ToBezier"] << "ToBezier.MaxTolerance";
811
812   myOpLst << "SameParameter";
813   myValMap["SameParameter"] << "SameParameter.Tolerance3d";
814 }
815
816 //=================================================================================
817 // function : getParameters
818 // purpose  :
819 //=================================================================================
820 GEOM::string_array* RepairGUI_ShapeProcessDlg::getParameters( const GEOM::string_array& theOperators )
821 {
822   GEOM::string_array_var aParams = new GEOM::string_array();
823   int i = 0, j = 0;
824
825   // calculate the length of parameters
826   for ( i = 0, j = 0; i < theOperators.length(); i++ )
827     j += myValMap[ QString( theOperators[i] ) ].size();
828   
829   // set the new length of paremeters
830   aParams->length( j );
831
832   // fill the parameters
833   for ( i = 0, j = 0; i < theOperators.length(); i++ ) {
834     QStringList aValLst = myValMap[ QString( theOperators[i] ) ];
835     for ( QStringList::Iterator it = aValLst.begin(); it != aValLst.end(); ++it )
836       aParams[j++] = CORBA::string_dup( (*it).toLatin1().constData() );
837   }
838
839   return aParams._retn();
840 }
841
842
843 //=================================================================================
844 // function : getValues
845 // purpose  :
846 //=================================================================================
847 GEOM::string_array* RepairGUI_ShapeProcessDlg::getValues( const GEOM::string_array& theParams )
848 {
849   GEOM::string_array_var aValues = new GEOM::string_array();
850   aValues->length( theParams.length() );
851
852   for ( int i = 0; i < theParams.length(); i++ ) {
853     QWidget* aCtrl = getControl( (const char*)theParams[i] );
854     if ( aCtrl && aCtrl->isEnabled() )
855       aValues[i] = get_convert( (const char*)theParams[i], getValue( aCtrl ));
856   }
857
858   return aValues._retn();
859 }
860
861 //=================================================================================
862 // function : getTexts
863 // purpose  :
864 //=================================================================================
865 QStringList RepairGUI_ShapeProcessDlg::getTexts( const GEOM::string_array& theParams )
866 {
867   QStringList aTexts;
868     
869   for ( int i = 0; i < theParams.length(); i++ ) {
870     QWidget* aCtrl = getControl( (const char*)theParams[i] );
871     if ( aCtrl )
872     {
873       QString aText = getText( aCtrl );
874       if( !aText.isNull() )
875         aTexts.append( aText );
876     }
877   }
878     
879   return aTexts;
880 }
881
882 //=================================================================================
883 // function : initSelection
884 // purpose  : set selection of ALL shape types except vertexes
885 //=================================================================================
886 void RepairGUI_ShapeProcessDlg::initSelection()
887 {
888   TColStd_MapOfInteger aTypes;
889   aTypes.Add( GEOM_COMPOUND );
890   aTypes.Add( GEOM_SOLID );
891   aTypes.Add( GEOM_SHELL );
892   aTypes.Add( GEOM_FACE );
893   aTypes.Add( GEOM_WIRE );
894   aTypes.Add( GEOM_EDGE );
895   globalSelection( aTypes );
896 }
897
898 //=================================================================================
899 // function : advOptionToggled
900 // purpose  : this slot is used to warn the user about possible consequences
901 //            of enabling some advanced options
902 //=================================================================================
903 void RepairGUI_ShapeProcessDlg::advOptionToggled( bool on )
904 {
905   QAbstractButton* btn = (QAbstractButton*)sender();
906   if ( btn == myToBezierSurfModeChk )
907   {
908     if ( on && btn->isCheckable() &&
909          SUIT_MessageBox::warning( this,
910                                    tr( "GEOM_WRN_WARNING" ), tr( "TIME_CONSUMING" ),
911                                    SUIT_MessageBox::Yes | SUIT_MessageBox::No ) == SUIT_MessageBox::No )
912       btn->toggle();
913   }
914
915   // either myDropSmallSolidsWidChk or myDropSmallSolidsVolChk must be checked
916   if ( btn == myDropSmallSolidsWidChk )
917   {
918     myDropSmallSolidsWidTol->setEnabled( on );
919     if ( !on ) {
920       myDropSmallSolidsVolChk->setChecked( true );
921       myDropSmallSolidsVolTol->setEnabled( true );
922     }
923   }
924   if ( btn == myDropSmallSolidsVolChk )
925   {
926     myDropSmallSolidsVolTol->setEnabled( on );
927     if ( !on ) {
928       myDropSmallSolidsWidChk->setChecked( true );
929       myDropSmallSolidsWidTol->setEnabled( true );
930     }
931   }
932 }
933
934 //=======================================================================
935 //function : operatorChecked
936 //purpose  : show parameters of a selected operator
937 //=======================================================================
938
939 void RepairGUI_ShapeProcessDlg::operatorChecked( QListWidgetItem * item )
940 {
941   if ( item && item->checkState() == Qt::Checked )
942   {
943     myStack->setCurrentIndex( myOpList->row( item ));
944   }
945 }