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