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