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