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