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