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