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., 1e3, 1., "len_tol_precision" );
166       initSpinBox( myDropSmallSolidsVolTol, 0., 1e9, 1., "len_tol_precision" );
167       myDropSmallSolidsWidTol->setValue( 1 );
168       myDropSmallSolidsVolTol->setValue( 1e3 );
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       if ( ( theControl == myDropSmallSolidsWidTol || theControl == myDropSmallSolidsVolTol ) && !theControl->isEnabled() ) {
568         // VSR: stupid workaround about ShapeProcessAPI:
569         // specific processing for optional parameters of DropSmallSolids operator
570         return QString::number( Precision::Infinite() );
571       }
572       return QString::number( qobject_cast<SalomeApp_DoubleSpinBox*>( theControl )->value() );
573     }
574     else if ( qobject_cast<SalomeApp_IntSpinBox*>( theControl )) {
575       return QString::number( qobject_cast<SalomeApp_IntSpinBox*>( theControl )->value() );
576     }
577     else if ( qobject_cast<QComboBox*>( theControl )) {
578       return qobject_cast<QComboBox*>( theControl )->currentText();
579     }
580     else if ( qobject_cast<QCheckBox*>( theControl )) {
581       return qobject_cast<QCheckBox*>( theControl )->isChecked() ? "1" : "0";
582     }
583   }   
584   return 0;
585 }
586
587 //=================================================================================
588 // function : getText()
589 // purpose  : get text in the proper way
590 //=================================================================================
591 QString RepairGUI_ShapeProcessDlg::getText( QWidget* theControl ) const
592 {
593   if ( theControl ) {
594     if ( qobject_cast<SalomeApp_DoubleSpinBox*>( theControl ))
595       return qobject_cast<SalomeApp_DoubleSpinBox*>( theControl )->text();
596     else if ( qobject_cast<SalomeApp_IntSpinBox*>( theControl ))
597       return qobject_cast<SalomeApp_IntSpinBox*>( theControl )->text();
598   }   
599   return QString::null;
600 }
601
602 //=================================================================================
603 // function : createOperation
604 // purpose  :
605 //=================================================================================
606 GEOM::GEOM_IOperations_ptr RepairGUI_ShapeProcessDlg::createOperation()
607 {
608   return getGeomEngine()->GetIHealingOperations( getStudyId() );
609 }
610
611 //=================================================================================
612 // function : isValid
613 // purpose  :
614 //=================================================================================
615 bool RepairGUI_ShapeProcessDlg::isValid( QString& msg )
616 {
617   bool ok = true;
618   QMapIterator<QString,QStringList> aMapIter( myValMap );
619   while( aMapIter.hasNext() ) {
620     aMapIter.next();
621     const QStringList& aList = aMapIter.value();
622     QListIterator<QString> aListIter( aList );
623     while( aListIter.hasNext() ) {
624       const QString& aParam = aListIter.next();
625       QWidget* aControl = getControl( aParam );
626       if ( !aControl->isEnabled() ) continue;
627       if ( qobject_cast<SalomeApp_DoubleSpinBox*>( aControl ))
628         ok = qobject_cast<SalomeApp_DoubleSpinBox*>( aControl )->isValid( msg, !IsPreview() ) && ok;
629       else if ( qobject_cast<SalomeApp_IntSpinBox*>( aControl ))
630         ok = qobject_cast<SalomeApp_IntSpinBox*>( aControl )->isValid( msg, !IsPreview() ) && ok;
631     }
632   }
633
634   bool error = false;
635   GEOM::string_array_var anOperators = getActiveOperators();
636   if ( !myObjects->length() ) {
637     msg += tr( "ERROR_NO_OBJECTS" );
638     error = true;
639   }
640   if ( !anOperators->length() ) {
641     if ( error ) 
642       msg += "\n";
643     msg += tr( "ERROR_NO_OPERATORS" );
644     error = true;
645   }
646   return !error && ok;
647 }
648
649 //=================================================================================
650 // function : execute
651 // purpose  :
652 //=================================================================================
653 bool RepairGUI_ShapeProcessDlg::execute( ObjectList& objects )
654 {
655   GEOM::string_array_var anOperators = getActiveOperators();
656   GEOM::string_array_var aParams = getParameters( anOperators );
657   GEOM::string_array_var aValues = getValues( aParams );
658
659   /*//-- check --
660   int z;
661         MESSAGE("Objects : ");
662         for ( z = 0; z < myObjects->length(); z++ )
663                 MESSAGE(myObjects[z]->GetName() << " ");
664         MESSAGE("\nOperators : ");
665         for ( z = 0; z < anOperators->length(); z++ )
666                 MESSAGE(anOperators[z] << " ");
667         MESSAGE("\nParameters : ");
668         for ( z = 0; z < aParams->length(); z++ )
669                 MESSAGE(aParams[z] << " ");
670         MESSAGE("\nValues : ");
671         for ( z = 0; z < aValues->length(); z ++ )
672                 MESSAGE(aValues[z] << " ");
673         MESSAGE("\n");
674   */// -----------
675
676   QStringList anErrorObjNames;
677   for ( int i = 0; i < myObjects->length(); i++ ) {
678     GEOM::GEOM_Object_var obj = myObjects[i];
679     GEOM::GEOM_IHealingOperations_var anOper = GEOM::GEOM_IHealingOperations::_narrow( getOperation() );
680     GEOM::GEOM_Object_var anObj = anOper->ProcessShape( obj, anOperators, aParams, aValues );
681     if ( anObj->_is_nil() )
682       anErrorObjNames << GEOMBase::GetName( obj );
683     else
684     {
685       if ( !IsPreview() )
686       {
687         QStringList aParameters;
688
689         for ( int i = 0; i < anOperators->length(); i++ )
690           aParameters << QString( anOperators[i] );
691
692         for ( int i = 0; i < aParams->length(); i++ )
693           aParameters << QString( aParams[i] );
694
695         aParameters << getTexts( aParams );
696         anObj->SetParameters(aParameters.join(":").toLatin1().constData());
697
698         RepairGUI::ShowStatistics( anOper, this );
699       }
700       objects.push_back( anObj._retn() );
701     }
702   }
703
704   if ( !anErrorObjNames.empty() )
705     MESSAGE( "ERRORS occured while processing the following objects: " << anErrorObjNames.join( " " ).toLatin1().data() );
706     
707   return anErrorObjNames.size() < myObjects->length(); // true if at least one object was OK, false if ALL objects were nil after Healing.
708 }
709
710 //=================================================================================
711 // function : getActiveOperators
712 // purpose  :
713 //=================================================================================
714 GEOM::string_array* RepairGUI_ShapeProcessDlg::getActiveOperators()
715 {
716   GEOM::string_array_var anOperators = new GEOM::string_array();
717
718   int j = 0, n = myOpList->count();
719   anOperators->length( n );
720   for ( int i = 0; i < n; i++ ) {
721     if ( myOpList->item( i )->checkState() == Qt::Checked )
722       anOperators[j++] = myOpList->item( i )->text().toLatin1().constData();
723   }
724   anOperators->length( j );
725
726   return anOperators._retn();
727 }
728
729 //=================================================================================
730 // function : getcontrol
731 // purpose  :
732 //=================================================================================
733 QWidget* RepairGUI_ShapeProcessDlg::getControl( const QString& theParam )
734 {
735   if ( theParam == "SplitAngle.Angle" )                           return mySplitAngleAngle;
736   else if ( theParam == "SplitAngle.MaxTolerance" )               return mySplitAngleMaxTol;
737   else if ( theParam == "SplitClosedFaces.NbSplitPoints" )        return mySplitClosedFacesNum;
738   else if ( theParam == "FixFaceSize.Tolerance" )                 return myFixFaceSizeTol;
739   else if ( theParam == "DropSmallEdges.Tolerance3d" )            return myDropSmallEdgesTol3D;
740   else if ( theParam == "DropSmallSolids.WidthFactorThreshold" )  return myDropSmallSolidsWidTol;
741   else if ( theParam == "DropSmallSolids.VolumeThreshold" )       return myDropSmallSolidsVolTol;
742   else if ( theParam == "DropSmallSolids.MergeSolids" )           return myDropSmallSolidsMergeChk;
743   else if ( theParam == "BSplineRestriction.SurfaceMode" )        return myBSplineSurfModeChk;
744   else if ( theParam == "BSplineRestriction.Curve3dMode" )        return myBSpline3DCurveChk;
745   else if ( theParam == "BSplineRestriction.Curve2dMode" )        return myBSpline2DCurveChk;
746   else if ( theParam == "BSplineRestriction.Tolerance3d" )        return myBSplineTol3D;
747   else if ( theParam == "BSplineRestriction.Tolerance2d" )        return myBSplineTol2D;
748   else if ( theParam == "BSplineRestriction.RequiredDegree" )     return myBSplineDegree;
749   else if ( theParam == "BSplineRestriction.RequiredNbSegments" ) return myBSplineSegments;
750   else if ( theParam == "BSplineRestriction.Continuity3d" )       return myBSpline3DCont;
751   else if ( theParam == "BSplineRestriction.Continuity2d" )       return myBSpline2DCont;
752   else if ( theParam == "SplitContinuity.Tolerance3d" )           return mySplitContTol3D;
753   else if ( theParam == "SplitContinuity.SurfaceContinuity" )     return mySplitContSurfCont;
754   else if ( theParam == "SplitContinuity.CurveContinuity" )       return mySplitContCurvCont;
755   else if ( theParam == "ToBezier.SurfaceMode" )                  return myToBezierSurfModeChk;
756   else if ( theParam == "ToBezier.Curve3dMode" )                  return myToBezier3DCurveChk;
757   else if ( theParam == "ToBezier.Curve2dMode" )                  return myToBezier2DCurveChk;
758   else if ( theParam == "ToBezier.MaxTolerance" )                 return myToBezierMaxTol;
759   else if ( theParam == "SameParameter.Tolerance3d" )             return mySameParameterTol3D;
760   else if ( theParam == "FixShape.Tolerance3d" )                  return myFixShapeTol3D;
761   else if ( theParam == "FixShape.MaxTolerance3d" )               return myFixShapeMaxTol3D;
762   return 0;
763 }
764
765 //=================================================================================
766 // function : getParameters
767 // purpose  :
768 //=================================================================================
769 void RepairGUI_ShapeProcessDlg::initParamsValues()
770 {
771   if ( myOpLst.count() )
772     return;  // already filled
773
774   myOpLst << "FixShape";
775   myValMap["FixShape"] << "FixShape.Tolerance3d";
776   myValMap["FixShape"] << "FixShape.MaxTolerance3d";
777
778   myOpLst << "FixFaceSize";
779   myValMap["FixFaceSize"] << "FixFaceSize.Tolerance";
780
781   myOpLst << "DropSmallEdges";
782   myValMap["DropSmallEdges"] << "DropSmallEdges.Tolerance3d";
783
784   myOpLst << "DropSmallSolids";
785   myValMap["DropSmallSolids"] << "DropSmallSolids.WidthFactorThreshold";
786   myValMap["DropSmallSolids"] << "DropSmallSolids.VolumeThreshold";
787   myValMap["DropSmallSolids"] << "DropSmallSolids.MergeSolids";
788
789   myOpLst << "SplitAngle";
790   myValMap["SplitAngle"] << "SplitAngle.Angle";
791   myValMap["SplitAngle"] << "SplitAngle.MaxTolerance";
792
793   myOpLst << "SplitClosedFaces";
794   myValMap["SplitClosedFaces"] << "SplitClosedFaces.NbSplitPoints";
795
796   myOpLst << "SplitContinuity";
797   myValMap["SplitContinuity"] << "SplitContinuity.Tolerance3d";
798   myValMap["SplitContinuity"] << "SplitContinuity.SurfaceContinuity";
799   myValMap["SplitContinuity"] << "SplitContinuity.CurveContinuity";
800
801   myOpLst << "BSplineRestriction";
802   myValMap["BSplineRestriction"] << "BSplineRestriction.SurfaceMode";
803   myValMap["BSplineRestriction"] << "BSplineRestriction.Curve3dMode";
804   myValMap["BSplineRestriction"] << "BSplineRestriction.Curve2dMode";
805   myValMap["BSplineRestriction"] << "BSplineRestriction.Tolerance3d";
806   myValMap["BSplineRestriction"] << "BSplineRestriction.Tolerance2d";
807   myValMap["BSplineRestriction"] << "BSplineRestriction.RequiredDegree";
808   myValMap["BSplineRestriction"] << "BSplineRestriction.RequiredNbSegments";
809   myValMap["BSplineRestriction"] << "BSplineRestriction.Continuity3d";
810   myValMap["BSplineRestriction"] << "BSplineRestriction.Continuity2d";
811
812   myOpLst << "ToBezier";
813   myValMap["ToBezier"] << "ToBezier.SurfaceMode";
814   myValMap["ToBezier"] << "ToBezier.Curve3dMode";
815   myValMap["ToBezier"] << "ToBezier.Curve2dMode";
816   myValMap["ToBezier"] << "ToBezier.MaxTolerance";
817
818   myOpLst << "SameParameter";
819   myValMap["SameParameter"] << "SameParameter.Tolerance3d";
820 }
821
822 //=================================================================================
823 // function : getParameters
824 // purpose  :
825 //=================================================================================
826 GEOM::string_array* RepairGUI_ShapeProcessDlg::getParameters( const GEOM::string_array& theOperators )
827 {
828   GEOM::string_array_var aParams = new GEOM::string_array();
829   int i = 0, j = 0;
830
831   // calculate the length of parameters
832   for ( i = 0, j = 0; i < theOperators.length(); i++ )
833     j += myValMap[ QString( theOperators[i].in() ) ].size();
834   
835   // set the new length of paremeters
836   aParams->length( j );
837
838   // fill the parameters
839   for ( i = 0, j = 0; i < theOperators.length(); i++ ) {
840     QStringList aParamLst = myValMap[ QString( theOperators[i].in() ) ];
841     foreach ( QString aParam, aParamLst ) {
842       aParams[j++] = CORBA::string_dup( aParam.toLatin1().constData() );
843     }
844   }
845
846   aParams->length( j );
847
848   return aParams._retn();
849 }
850
851
852 //=================================================================================
853 // function : getValues
854 // purpose  :
855 //=================================================================================
856 GEOM::string_array* RepairGUI_ShapeProcessDlg::getValues( const GEOM::string_array& theParams )
857 {
858   GEOM::string_array_var aValues = new GEOM::string_array();
859   aValues->length( theParams.length() );
860
861   for ( int i = 0; i < theParams.length(); i++ ) {
862     QWidget* aCtrl = getControl( (const char*)theParams[i] );
863     if ( aCtrl )
864       aValues[i] = get_convert( (const char*)theParams[i], getValue( aCtrl ));
865   }
866
867   return aValues._retn();
868 }
869
870 //=================================================================================
871 // function : getTexts
872 // purpose  :
873 //=================================================================================
874 QStringList RepairGUI_ShapeProcessDlg::getTexts( const GEOM::string_array& theParams )
875 {
876   QStringList aTexts;
877     
878   for ( int i = 0; i < theParams.length(); i++ ) {
879     QWidget* aCtrl = getControl( (const char*)theParams[i] );
880     if ( aCtrl )
881     {
882       QString aText = getText( aCtrl );
883       if( !aText.isNull() )
884         aTexts.append( aText );
885     }
886   }
887     
888   return aTexts;
889 }
890
891 //=================================================================================
892 // function : initSelection
893 // purpose  : set selection of ALL shape types except vertexes
894 //=================================================================================
895 void RepairGUI_ShapeProcessDlg::initSelection()
896 {
897   TColStd_MapOfInteger aTypes;
898   aTypes.Add( GEOM_COMPOUND );
899   aTypes.Add( GEOM_SOLID );
900   aTypes.Add( GEOM_SHELL );
901   aTypes.Add( GEOM_FACE );
902   aTypes.Add( GEOM_WIRE );
903   aTypes.Add( GEOM_EDGE );
904   globalSelection( aTypes );
905 }
906
907 //=================================================================================
908 // function : advOptionToggled
909 // purpose  : this slot is used to warn the user about possible consequences
910 //            of enabling some advanced options
911 //=================================================================================
912 void RepairGUI_ShapeProcessDlg::advOptionToggled( bool on )
913 {
914   QAbstractButton* btn = (QAbstractButton*)sender();
915   if ( btn == myToBezierSurfModeChk )
916   {
917     if ( on && btn->isCheckable() &&
918          SUIT_MessageBox::warning( this,
919                                    tr( "GEOM_WRN_WARNING" ), tr( "TIME_CONSUMING" ),
920                                    SUIT_MessageBox::Yes | SUIT_MessageBox::No ) == SUIT_MessageBox::No )
921       btn->toggle();
922   }
923
924   // either myDropSmallSolidsWidChk or myDropSmallSolidsVolChk must be checked
925   if ( btn == myDropSmallSolidsWidChk )
926   {
927     myDropSmallSolidsWidTol->setEnabled( on );
928     if ( !on ) {
929       myDropSmallSolidsVolChk->setChecked( true );
930       myDropSmallSolidsVolTol->setEnabled( true );
931     }
932   }
933   if ( btn == myDropSmallSolidsVolChk )
934   {
935     myDropSmallSolidsVolTol->setEnabled( on );
936     if ( !on ) {
937       myDropSmallSolidsWidChk->setChecked( true );
938       myDropSmallSolidsWidTol->setEnabled( true );
939     }
940   }
941 }
942
943 //=======================================================================
944 //function : operatorChecked
945 //purpose  : show parameters of a selected operator
946 //=======================================================================
947
948 void RepairGUI_ShapeProcessDlg::operatorChecked( QListWidgetItem * item )
949 {
950   if ( item && item->checkState() == Qt::Checked )
951   {
952     myStack->setCurrentIndex( myOpList->row( item ));
953   }
954 }