]> SALOME platform Git repositories - modules/geom.git/blob - src/RepairGUI/RepairGUI_ShapeProcessDlg.cxx
Salome HOME
Fix issue 0020479: EDF 1116 GEOM: Create a group, "Add" button is inactive but "Selec...
[modules/geom.git] / src / RepairGUI / RepairGUI_ShapeProcessDlg.cxx
1 //  Copyright (C) 2007-2008  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.
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 //  GEOM GEOMGUI : GUI for Geometry component
23 //  File   : RepairGUI_ShapeProcessDlg.cxx
24 //  Author : Lucien PIGNOLONI
25 //  Module : GEOM
26 //  $Header$
27 //
28 #include "RepairGUI_ShapeProcessDlg.h"
29
30 #include "GEOMImpl_Types.hxx"
31
32 #include "SalomeApp_Application.h"
33 #include "LightApp_SelectionMgr.h"
34 #include "SUIT_Session.h"
35 #include "SALOME_ListIteratorOfListIO.hxx"
36 #include "SALOME_ListIO.hxx"
37
38 #include <TCollection_AsciiString.hxx>
39 #include <TColStd_MapOfInteger.hxx>
40
41 #include <qheader.h>
42 #include <qlabel.h>
43 #include <qmessagebox.h>
44
45 using namespace std;
46
47 //=================================================================================
48 // class    : RepairGUI_ShapeProcessDlg()
49 // purpose  : Constructs a RepairGUI_ShapeProcessDlg  which is a child of 'parent', with the
50 //            name 'name' and widget flags set to 'f'.
51 //            The dialog will by default be modeless, unless you set 'modal' to
52 //            TRUE to construct a modal dialog.
53 //=================================================================================
54 RepairGUI_ShapeProcessDlg::RepairGUI_ShapeProcessDlg(GeometryGUI* theGeometryGUI, QWidget* parent,
55                                                      const char* name, bool modal, WFlags fl)
56   :GEOMBase_Skeleton(theGeometryGUI, parent, name, modal, WStyle_Customize |
57                      WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
58 {
59   setHelpFileName("shape_processing_operation_page.html");
60   init();
61 }
62
63 //=================================================================================
64 // function : ~RepairGUI_ShapeProcessDlg()
65 // purpose  : Destroys the object and frees any allocated resources
66 //=================================================================================
67 RepairGUI_ShapeProcessDlg::~RepairGUI_ShapeProcessDlg()
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( buttonOk,     SIGNAL(clicked()), this, SLOT(onOk()) );
300   connect( buttonApply,  SIGNAL(clicked()), this, SLOT(onApply()) );
301
302   connect( ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),  
303            SIGNAL(currentSelectionChanged()), this, SLOT(selectionChanged()) );
304   connect( myOpList,     SIGNAL(selectionChanged()), this, SLOT(operationChanged()) );
305
306   connect( mySelectWdgt->PushButton1, SIGNAL(clicked()), this, SLOT(selectClicked()) );
307   connect( mySelectWdgt->LineEdit1,   SIGNAL(returnPressed()), this, SLOT(lineEditReturnPressed()) );
308
309   connect( myToBezierSurfModeChk,     SIGNAL(toggled(bool)), SLOT(advOptionToggled(bool)) );
310
311   adjustSize();
312   loadDefaults(); // init dialog fields with values from resource file
313   myOpList->setSelected( myOpList->findItem( "FixShape", 0 ), true );
314   reset();
315
316   initName( tr( "PROCESS_SHAPE_NEW_OBJ_NAME" ) );
317 }
318
319 //=================================================================================
320 // function : operationChanged()
321 // purpose  : 
322 //=================================================================================
323 void RepairGUI_ShapeProcessDlg::operationChanged()
324 {
325   QListViewItem* anItem = myOpList->selectedItem();
326   if ( anItem )
327   {
328     int id = myOpLst.findIndex( anItem->text(0) );
329     if ( id > -1 )
330       myStack->raiseWidget( id );
331   }
332 }
333
334 //=================================================================================
335 // function : onOk()
336 // purpose  : Same than click on apply but close this dialog.
337 //=================================================================================
338 void RepairGUI_ShapeProcessDlg::onOk()
339 {
340   if (onApply())
341     ClickOnCancel();
342 }
343
344 //=================================================================================
345 // function : onApply()
346 // purpose  :
347 //=================================================================================
348 bool RepairGUI_ShapeProcessDlg::onApply()
349 {
350   if ( !onAccept() )
351     return false;
352
353   initName();
354
355   reset();
356   initSelection();
357   
358   return true;
359 }
360
361
362 //=================================================================================
363 // function : selectionChanged()
364 // purpose  : Called when selection as changed or other case
365 //          : used only by SelectButtonC1A1 (LineEditC1A1)
366 //=================================================================================
367 void RepairGUI_ShapeProcessDlg::selectionChanged()
368 {
369         reset();
370         
371   Standard_Boolean aRes = Standard_False;
372   int i = 0;
373   myObjects->length( IObjectCount() );
374   for ( SALOME_ListIteratorOfListIO anIt( selectedIO() ); anIt.More(); anIt.Next() )
375   {
376     GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( anIt.Value(), aRes );
377     if ( !CORBA::is_nil( aSelectedObject ) && aRes )
378         myObjects[i++] = aSelectedObject;
379   }
380   myObjects->length( i );
381   if ( i == 1 )
382     mySelectWdgt->LineEdit1->setText( GEOMBase::GetName( myObjects[0] ) );
383   else if ( i > 0 )
384     mySelectWdgt->LineEdit1->setText( QString::number( i ) + "_" + tr( "GEOM_OBJECTS" ) );
385 }
386
387
388 //=================================================================================
389 // function : selectClicked()
390 // purpose  :
391 //=================================================================================
392 void RepairGUI_ShapeProcessDlg::selectClicked()
393 {
394   myEditCurrentArgument = mySelectWdgt->LineEdit1;
395   mySelectWdgt->LineEdit1->setFocus();
396   selectionChanged();
397 }
398
399
400 //=================================================================================
401 // function : lineEditReturnPressed()
402 // purpose  :
403 //=================================================================================
404 void RepairGUI_ShapeProcessDlg::lineEditReturnPressed()
405 {
406   GEOMBase_Skeleton::LineEditReturnPressed();
407 }
408
409
410 //=================================================================================
411 // function : activate()
412 // purpose  :
413 //=================================================================================
414 void RepairGUI_ShapeProcessDlg::activate()
415 {
416   GEOMBase_Skeleton::ActivateThisDialog();
417   connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), 
418           SIGNAL(currentSelectionChanged()), this, SLOT(selectionChanged()));
419         
420   reset();
421   //myGeomGUI->SetState( 0 );
422   initSelection();
423 }
424
425
426 //=================================================================================
427 // function : enterEvent()
428 // purpose  : Mouse enter onto the dialog to activate it
429 //=================================================================================
430 void RepairGUI_ShapeProcessDlg::enterEvent(QEvent* e)
431 {
432   if ( !GroupConstructors->isEnabled() )
433     activate();
434 }
435
436
437 //=================================================================================
438 // function : closeEvent()
439 // purpose  : same than click on cancel button
440 //=================================================================================
441 void RepairGUI_ShapeProcessDlg::closeEvent(QCloseEvent* e)
442 {
443   //myGeomGUI->SetState( -1 );
444   GEOMBase_Skeleton::closeEvent( e );
445 }
446
447
448 //=================================================================================
449 // function : reset()
450 // purpose  : Completely reset the state of method including local context
451 //=================================================================================
452 void RepairGUI_ShapeProcessDlg::reset()
453 {
454   myObjects = new GEOM::ListOfGO();
455   myObjects->length( 0 );       
456   mySelectWdgt->LineEdit1->setText("");
457 }
458
459
460 //=================================================================================
461 // function : get_convert
462 // purpose  : conversion of angle values to radians (non-angle values are not converted)
463 //=================================================================================
464 const char* get_convert( const char* theParam, const char* theValue )
465 {
466   if ( !strcmp( theParam, "SplitAngle.Angle" ) )
467   {
468     double doubleValue = atof( theValue ) * PI / 180;
469     TCollection_AsciiString str( doubleValue );
470     return CORBA::string_dup( str.ToCString() );
471   }
472   return CORBA::string_dup( theValue );
473 }
474
475 //=================================================================================
476 // function : set_convert
477 // purpose  : conversion of angle values to degrees (non-angle values are not converted)
478 //=================================================================================
479 const char* set_convert( const char* theParam, const char* theValue )
480 {
481   if ( !strcmp( theParam, "SplitAngle.Angle" ) )
482   {
483     double doubleValue = atof( theValue ) * 180 / PI;
484     TCollection_AsciiString str( doubleValue );
485     return CORBA::string_dup( str.ToCString() );
486   }
487   return CORBA::string_dup( theValue );
488 }
489
490 //=================================================================================
491 // function : loadDefaults()
492 // purpose  : initialize "values"-fields with default values retrieved from IHealingOperations
493 //=================================================================================
494 void RepairGUI_ShapeProcessDlg::loadDefaults()
495 {
496   GEOM::GEOM_IHealingOperations_var anOp = myGeomGUI->GetGeomGen()->GetIHealingOperations( getStudyId() );
497   GEOM::string_array_var anOperators, aParams, aValues;
498   anOp->GetShapeProcessParameters( anOperators, aParams, aValues );
499
500   // check the default items-operators
501   int i;
502   for ( i = 0; i < anOperators->length(); i++ )
503   {
504     //MESSAGE("-->"<<(const char*)anOperators[i]);
505     QListViewItem* anItem = myOpList->findItem( (const char*)anOperators[i], 0 );
506     if ( anItem /*&& anItem->inherits( "QCheckListItem" )*/ )
507       ((QCheckListItem*) anItem)->setOn( true );
508   }
509
510   // Retrieve default parameters for ALL operators
511   for ( QListViewItemIterator it(myOpList); it.current(); ++it ) {
512     CORBA::String_var anOperator = CORBA::string_dup( it.current()->text( 0 ).latin1() );
513     anOp->GetOperatorParameters( anOperator.in(), aParams, aValues );
514
515     // set default values of parameters
516     if ( aParams->length() != aValues->length() )
517       continue;
518     for ( i = 0; i < aParams->length(); i++ ) {
519       QWidget* aCtrl = getControl( (const char*)aParams[i] );
520       const char* aValue = set_convert( (const char*)aParams[i], aValues[i] );
521       setValue( aCtrl, aValue );
522     }
523   }
524 }
525
526 //=================================================================================
527 // function : setValue()
528 // purpose  : set value in the proper way
529 //=================================================================================
530 void RepairGUI_ShapeProcessDlg::setValue( QWidget* theControl, const char* theValue )
531 {
532   if ( theControl == NULL || theValue == NULL )
533     return;
534
535   if ( theControl->isA( "QtxDblSpinBox" ) )
536     ((QtxDblSpinBox*)theControl)->setValue( QString( theValue ).toDouble() );
537   else if ( theControl->isA( "QSpinBox" ) )
538     ((QSpinBox*)theControl)->setValue( QString( theValue ).toInt() );
539   else if ( theControl->isA( "QComboBox" ) )
540     ((QComboBox*)theControl)->setCurrentText( QString( theValue ) );
541   else if ( theControl->isA( "QCheckBox" ) )
542     ((QCheckBox*)theControl)->setChecked( QString( theValue ).toInt() != 0 );
543 }
544
545 //=================================================================================
546 // function : getValue()
547 // purpose  : get value in the proper way
548 //=================================================================================
549 const char* RepairGUI_ShapeProcessDlg::getValue( QWidget* theControl ) const
550 {
551   if ( theControl == NULL )
552     return "";
553
554   if ( theControl->isA( "QtxDblSpinBox" ) )
555     return ((QtxDblSpinBox*)theControl)->text().latin1();
556   else if ( theControl->isA( "QSpinBox" ) )
557     return ((QSpinBox*)theControl)->text().latin1();
558   else if ( theControl->isA( "QComboBox" ) )
559     return ((QComboBox*)theControl)->currentText().latin1();
560   else if ( theControl->isA( "QCheckBox" ) )
561     return ((QCheckBox*)theControl)->isChecked() ? "1" : "0";
562   
563   return "";
564 }
565
566 //=================================================================================
567 // function : createOperation
568 // purpose  :
569 //=================================================================================
570 GEOM::GEOM_IOperations_ptr RepairGUI_ShapeProcessDlg::createOperation()
571 {
572   return getGeomEngine()->GetIHealingOperations( getStudyId() );
573 }
574
575 //=================================================================================
576 // function : isValid
577 // purpose  :
578 //=================================================================================
579 bool RepairGUI_ShapeProcessDlg::isValid( QString& msg )
580 {
581   bool error = false;
582   GEOM::string_array_var anOperators = getActiveOperators();
583   if ( !myObjects->length() )
584   {
585     msg += tr( "ERROR_NO_OBJECTS" );
586     error = true;
587   }
588   if ( !anOperators->length() )
589   {
590     if ( error ) 
591       msg += "\n";
592     msg += tr( "ERROR_NO_OPERATORS" );
593     error = true;
594   }
595   return !error;
596 }
597
598 //=================================================================================
599 // function : execute
600 // purpose  :
601 //=================================================================================
602 bool RepairGUI_ShapeProcessDlg::execute( ObjectList& objects )
603 {
604   GEOM::string_array_var anOperators = getActiveOperators();
605   GEOM::string_array_var aParams = getParameters( anOperators );
606   GEOM::string_array_var aValues = getValues( aParams );
607
608   /*//-- check --
609   int z;
610         MESSAGE("Objects : ");
611         for ( z = 0; z < myObjects->length(); z++ )
612                 MESSAGE(myObjects[z]->GetName() << " ");
613         MESSAGE("\nOperators : ");
614         for ( z = 0; z < anOperators->length(); z++ )
615                 MESSAGE(anOperators[z] << " ");
616         MESSAGE("\nParameters : ");
617         for ( z = 0; z < aParams->length(); z++ )
618                 MESSAGE(aParams[z] << " ");
619         MESSAGE("\nValues : ");
620         for ( z = 0; z < aValues->length(); z ++ )
621                 MESSAGE(aValues[z] << " ");
622         MESSAGE("\n");
623   */// -----------
624
625   QStringList anErrorObjNames;
626   for ( int i = 0; i < myObjects->length(); i++ )
627   {
628     GEOM::GEOM_Object_var obj = myObjects[i];
629     GEOM::GEOM_Object_var anObj = GEOM::GEOM_IHealingOperations::_narrow( getOperation() )->ProcessShape(
630         obj, anOperators, aParams, aValues );
631     if ( anObj->_is_nil() )
632       anErrorObjNames << GEOMBase::GetName( obj );
633     else
634       objects.push_back( anObj._retn() );
635   }
636
637   if ( !anErrorObjNames.empty() )
638     MESSAGE("ERRORS occured while processing the following objects: " << anErrorObjNames.join( " " ));
639     
640   return anErrorObjNames.size() < myObjects->length(); // true if at least one object was OK, false if ALL objects were nil after Healing.
641 }
642
643 //=================================================================================
644 // function : getActiveOperators
645 // purpose  :
646 //=================================================================================
647 GEOM::string_array* RepairGUI_ShapeProcessDlg::getActiveOperators()
648 {
649   GEOM::string_array_var anOperators = new GEOM::string_array();
650     QStringList aCheckedList;
651   QStringList::Iterator it;
652   for ( it = myOpLst.begin(); it != myOpLst.end(); ++it )
653     if ( ((QCheckListItem*)myOpList->findItem( *it, 0 ))->isOn() )
654       aCheckedList << *it;
655   anOperators->length( aCheckedList.size() );
656   int i = 0;
657   for ( it = aCheckedList.begin(); it != aCheckedList.end(); ++it )
658     anOperators[i++] = CORBA::string_dup( (*it).latin1() );             
659                  
660   return anOperators._retn();
661 }
662
663 //=================================================================================
664 // function : getcontrol
665 // purpose  :
666 //=================================================================================
667 QWidget* RepairGUI_ShapeProcessDlg::getControl( const char* theParam )
668 {
669         string aParam = theParam;
670   if ( aParam == "SplitAngle.Angle" )                           return mySplitAngleAngle;
671   else if ( aParam == "SplitAngle.MaxTolerance" )               return mySplitAngleMaxTol;
672   else if ( aParam == "SplitClosedFaces.NbSplitPoints" )        return mySplitClosedFacesNum;
673   else if ( aParam == "FixFaceSize.Tolerance" )                 return myFixFaceSizeTol;
674   else if ( aParam == "DropSmallEdges.Tolerance3d" )            return myDropSmallEdgesTol3D;
675   else if ( aParam == "BSplineRestriction.SurfaceMode" )        return myBSplineSurfModeChk;
676   else if ( aParam == "BSplineRestriction.Curve3dMode" )        return myBSpline3DCurveChk;
677   else if ( aParam == "BSplineRestriction.Curve2dMode" )        return myBSpline2DCurveChk;
678   else if ( aParam == "BSplineRestriction.Tolerance3d" )        return myBSplineTol3D;
679   else if ( aParam == "BSplineRestriction.Tolerance2d" )        return myBSplineTol2D;
680   else if ( aParam == "BSplineRestriction.RequiredDegree" )     return myBSplineDegree;
681   else if ( aParam == "BSplineRestriction.RequiredNbSegments" ) return myBSplineSegments;
682   else if ( aParam == "BSplineRestriction.Continuity3d" )       return myBSpline3DCont;
683   else if ( aParam == "BSplineRestriction.Continuity2d" )       return myBSpline2DCont;
684   else if ( aParam == "SplitContinuity.Tolerance3d" )           return mySplitContTol3D;
685   else if ( aParam == "SplitContinuity.SurfaceContinuity" )     return mySplitContSurfCont;
686   else if ( aParam == "SplitContinuity.CurveContinuity" )       return mySplitContCurvCont;
687   else if ( aParam == "ToBezier.SurfaceMode" )                  return myToBezierSurfModeChk;
688   else if ( aParam == "ToBezier.Curve3dMode" )                  return myToBezier3DCurveChk;
689   else if ( aParam == "ToBezier.Curve2dMode" )                  return myToBezier2DCurveChk;
690   else if ( aParam == "ToBezier.MaxTolerance" )                 return myToBezierMaxTol;
691   else if ( aParam == "SameParameter.Tolerance3d" )             return mySameParameterTol3D;
692   else if ( aParam == "FixShape.Tolerance3d" )                  return myFixShapeTol3D;
693   else if ( aParam == "FixShape.MaxTolerance3d" )               return myFixShapeMaxTol3D;
694   return NULL;
695 }
696
697 //=================================================================================
698 // function : getParameters
699 // purpose  :
700 //=================================================================================
701 void RepairGUI_ShapeProcessDlg::initParamsValues()
702 {
703   myOpLst << "FixShape";
704   myValMap["FixShape"] << "FixShape.Tolerance3d";
705   myValMap["FixShape"] << "FixShape.MaxTolerance3d";
706
707   myOpLst << "FixFaceSize";
708   myValMap["FixFaceSize"] << "FixFaceSize.Tolerance";
709
710   myOpLst << "DropSmallEdges";
711   myValMap["DropSmallEdges"] << "DropSmallEdges.Tolerance3d";
712
713   myOpLst << "SplitAngle";
714   myValMap["SplitAngle"] << "SplitAngle.Angle";
715   myValMap["SplitAngle"] << "SplitAngle.MaxTolerance";
716
717   myOpLst << "SplitClosedFaces";
718   myValMap["SplitClosedFaces"] << "SplitClosedFaces.NbSplitPoints";
719
720   myOpLst << "SplitContinuity";
721   myValMap["SplitContinuity"] << "SplitContinuity.Tolerance3d";
722   myValMap["SplitContinuity"] << "SplitContinuity.SurfaceContinuity";
723   myValMap["SplitContinuity"] << "SplitContinuity.CurveContinuity";
724
725   myOpLst << "BSplineRestriction";
726   myValMap["BSplineRestriction"] << "BSplineRestriction.SurfaceMode";
727   myValMap["BSplineRestriction"] << "BSplineRestriction.Curve3dMode";
728   myValMap["BSplineRestriction"] << "BSplineRestriction.Curve2dMode";
729   myValMap["BSplineRestriction"] << "BSplineRestriction.Tolerance3d";
730   myValMap["BSplineRestriction"] << "BSplineRestriction.Tolerance2d";
731   myValMap["BSplineRestriction"] << "BSplineRestriction.RequiredDegree";
732   myValMap["BSplineRestriction"] << "BSplineRestriction.RequiredNbSegments";
733   myValMap["BSplineRestriction"] << "BSplineRestriction.Continuity3d";
734   myValMap["BSplineRestriction"] << "BSplineRestriction.Continuity2d";
735
736   myOpLst << "ToBezier";
737   myValMap["ToBezier"] << "ToBezier.SurfaceMode";
738   myValMap["ToBezier"] << "ToBezier.Curve3dMode";
739   myValMap["ToBezier"] << "ToBezier.Curve2dMode";
740   myValMap["ToBezier"] << "ToBezier.MaxTolerance";
741
742   myOpLst << "SameParameter";
743   myValMap["SameParameter"] << "SameParameter.Tolerance3d";
744 }
745
746 //=================================================================================
747 // function : getParameters
748 // purpose  :
749 //=================================================================================
750 GEOM::string_array* RepairGUI_ShapeProcessDlg::getParameters( const GEOM::string_array& theOperators )
751 {
752         GEOM::string_array_var aParams = new GEOM::string_array();
753         int i( 0 ), j( 0 );
754
755         // calculate the length of parameters
756         for ( i = 0, j = 0; i < theOperators.length(); i++ )
757           j+= myValMap[QString((const char*)theOperators[i])].size();
758
759         // set the new length of paremeters
760         aParams->length( j );
761
762         // fill the parameters
763         for ( i = 0, j = 0; i < theOperators.length(); i++ )
764         {
765                 QStringList aValLst = myValMap[QString( (const char*)theOperators[i] )];
766                 for ( QStringList::Iterator it = aValLst.begin(); it != aValLst.end(); ++it )
767         aParams[j++] = CORBA::string_dup( (*it).latin1() );
768         }
769
770         return aParams._retn();
771 }
772
773
774 //=================================================================================
775 // function : getValues
776 // purpose  :
777 //=================================================================================
778 GEOM::string_array* RepairGUI_ShapeProcessDlg::getValues( const GEOM::string_array& theParams )
779 {
780   GEOM::string_array_var aValues = new GEOM::string_array();
781   aValues->length( theParams.length() );
782     
783   for ( int i = 0; i < theParams.length(); i++ )
784   {
785     QWidget* aCtrl = getControl( (const char*)theParams[i] );
786     if ( aCtrl )
787       aValues[i] = get_convert( (const char*)theParams[i], getValue( aCtrl ) );
788   }
789     
790   return aValues._retn();
791 }
792
793 //=================================================================================
794 // function : initSelection
795 // purpose  : set selection of ALL shape types except vertexes
796 //=================================================================================
797 void RepairGUI_ShapeProcessDlg::initSelection()
798 {
799   TColStd_MapOfInteger aTypes;
800   aTypes.Add( GEOM_COMPOUND );
801   aTypes.Add( GEOM_SOLID );
802   aTypes.Add( GEOM_SHELL );
803   aTypes.Add( GEOM_FACE );
804   aTypes.Add( GEOM_WIRE );
805   aTypes.Add( GEOM_EDGE );
806   globalSelection( aTypes );
807 }
808
809 //=================================================================================
810 // function : advOptionToggled
811 // purpose  : this slot is used to warn the user about possible consequences
812 //            of enabling some advanced options
813 //=================================================================================
814 void RepairGUI_ShapeProcessDlg::advOptionToggled( bool on )
815 {
816   QButton* btn = (QButton*)sender();
817   if ( on && btn->isToggleButton() &&
818        QMessageBox::warning(myGeomGUI->getApp()->desktop(),
819                             tr( "GEOM_WRN_WARNING" ), tr( "TIME_CONSUMING" ),
820                             QMessageBox::Yes, QMessageBox::No ) == QMessageBox::No )
821     btn->toggle();
822 }