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