]> SALOME platform Git repositories - modules/geom.git/blob - src/OperationGUI/OperationGUI_FilletDlg.cxx
Salome HOME
ae49d6c2e014a2253809a80b7cac1e59c0dae5aa
[modules/geom.git] / src / OperationGUI / OperationGUI_FilletDlg.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   : OperationGUI_FilletDlg.cxx
25 //  Author : Damien COQUERET
26 //  Module : GEOM
27 //  $Header$
28
29 #include "OperationGUI_FilletDlg.h"
30 #include "DlgRef_1Sel1Spin.h"
31 #include "DlgRef_2Sel1Spin.h"
32 #include "QAD_Desktop.h"
33 #include "qpixmap.h"
34 #include <TColStd_IndexedMapOfInteger.hxx>
35 #include <list>
36
37 #include "GEOMImpl_Types.hxx"
38
39 //=================================================================================
40 // class    : OperationGUI_FilletDlg()
41 // purpose  : Constructs a OperationGUI_FilletDlg which is a child of 'parent', with the 
42 //            name 'name' and widget flags set to 'f'.
43 //            The dialog will by default be modeless, unless you set 'modal' to
44 //            TRUE to construct a modal dialog.
45 //=================================================================================
46 OperationGUI_FilletDlg::OperationGUI_FilletDlg( QWidget* parent, SALOME_Selection* Sel )
47   :GEOMBase_Skeleton( parent, "OperationGUI_FilletDlg", Sel, false,
48      WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
49 {
50   myConstructorId = -1;
51   mySelection = Sel;
52   
53   QPixmap image0( QAD_Desktop::getResourceManager()->loadPixmap( "GEOM", tr( "ICON_DLG_FILLET_ALL" ) ) );
54   QPixmap image1( QAD_Desktop::getResourceManager()->loadPixmap( "GEOM", tr( "ICON_DLG_FILLET_EDGE" ) ) );
55   QPixmap image2( QAD_Desktop::getResourceManager()->loadPixmap( "GEOM", tr( "ICON_DLG_FILLET_FACE" ) ) );
56   
57   QPixmap iconSelect( QAD_Desktop::getResourceManager()->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
58
59   setCaption( tr( "GEOM_FILLET_TITLE" ) );
60
61   /***************************************************************/
62   GroupConstructors->setTitle( tr( "GEOM_FILLET" ) );
63   RadioButton1->setPixmap( image0 );
64   RadioButton2->setPixmap( image1 );
65   RadioButton3->setPixmap( image2 );
66
67   Group1 = new DlgRef_1Sel1Spin( this, "Group1" );
68   Group1->GroupBox1->setTitle( tr( "GEOM_FILLET_ALL" ) );
69   Group1->TextLabel1->setText( tr( "GEOM_MAIN_OBJECT" ) );
70   Group1->TextLabel2->setText( tr( "GEOM_RADIUS" ) );
71   Group1->PushButton1->setPixmap( iconSelect );
72   Group1->LineEdit1->setReadOnly( true );
73
74   Group2 = new DlgRef_2Sel1Spin( this, "Group2" );
75   Group2->GroupBox1->setTitle( tr( "GEOM_FILLET_EDGES" ) );
76   Group2->TextLabel1->setText( tr( "GEOM_MAIN_OBJECT" ) );
77   Group2->TextLabel2->setText( tr( "SELECTED_EDGES" ) );
78   Group2->TextLabel3->setText( tr( "GEOM_RADIUS" ) );
79   Group2->PushButton1->setPixmap( iconSelect );
80   Group2->PushButton2->setPixmap( iconSelect );
81   Group2->LineEdit1->setReadOnly( true );
82   Group2->LineEdit2->setReadOnly( true );
83
84   Group3 = new DlgRef_2Sel1Spin( this, "Group3" );
85   Group3->GroupBox1->setTitle(tr( "GEOM_FILLET_FACES" ) );
86   Group3->TextLabel1->setText(tr( "GEOM_MAIN_OBJECT" ) );
87   Group3->TextLabel2->setText(tr( "SELECTED_FACES" ) );
88   Group3->TextLabel3->setText(tr( "GEOM_RADIUS" ) );
89   Group3->PushButton1->setPixmap( iconSelect );
90   Group3->PushButton2->setPixmap( iconSelect );
91   Group3->LineEdit1->setReadOnly( true );
92   Group3->LineEdit2->setReadOnly( true );
93
94   Layout1->addWidget( Group1, 2, 0 );
95   Layout1->addWidget( Group2, 2, 0 );
96   Layout1->addWidget( Group3, 2, 0 );
97   /***************************************************************/
98
99   double SpecificStep = 10.0;
100   Group1->SpinBox_DX->RangeStepAndValidator(0.001, 999.999, SpecificStep, 3);
101   Group2->SpinBox_DX->RangeStepAndValidator(0.001, 999.999, SpecificStep, 3);
102   Group3->SpinBox_DX->RangeStepAndValidator(0.001, 999.999, SpecificStep, 3);
103
104   /* Initialisations */
105   Init( mySelection );
106 }
107
108
109 //=================================================================================
110 // function : ~OperationGUI_FilletDlg()
111 // purpose  : Destroys the object and frees any allocated resources
112 //=================================================================================
113 OperationGUI_FilletDlg::~OperationGUI_FilletDlg()
114 {  
115 }
116
117
118 //=================================================================================
119 // function : Init()
120 // purpose  :
121 //=================================================================================
122 void OperationGUI_FilletDlg::Init( SALOME_Selection* Sel )
123 {
124   mySelection = Sel;
125   myConstructorId = -1;
126   reset();
127   RadioButton1->setChecked( true );
128   myEditCurrentArgument = Group1->LineEdit1;
129
130   // main buttons
131   connect( buttonOk   , SIGNAL( clicked() ), this, SLOT( ClickOnOk()    ) );
132   connect( buttonApply, SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
133
134   // group box
135   connect( GroupConstructors, SIGNAL( clicked( int ) ), this, SLOT( ConstructorsClicked( int ) ) );
136
137   // push buttons
138   connect(Group1->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
139   connect(Group2->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
140   connect(Group3->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
141   connect(Group2->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
142   connect(Group3->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
143
144   // line edits
145   connect(Group1->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
146   connect(Group2->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
147   connect(Group3->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
148
149   // spin boxes  
150   connect(Group1->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
151   connect(Group2->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
152   connect(Group3->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
153
154     // selection
155   connect( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
156   
157
158   initName( tr( "GEOM_FILLET" ) );
159
160   Group2->hide();
161   Group3->hide();
162   Group1->show();
163
164   this->show();
165 }
166
167
168 //=================================================================================
169 // function : ConstructorsClicked()
170 // purpose  : Radio button management
171 //=================================================================================
172 void OperationGUI_FilletDlg::ConstructorsClicked( int constructorId )
173 {
174   if ( QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() != VIEW_OCC )
175   {
176     RadioButton1->setChecked( true );
177     return;
178   }
179
180   if ( myConstructorId == constructorId )
181     return;
182
183   // Get radius from previous widget
184   double R = 5;
185   if      ( myConstructorId == 0 ) R = Group1->SpinBox_DX->GetValue();
186   else if ( myConstructorId == 1 ) R = Group2->SpinBox_DX->GetValue();
187   else                             R = Group3->SpinBox_DX->GetValue();
188
189   myConstructorId = constructorId;
190
191   switch ( constructorId )
192   {
193     case 0:
194         Group1->show();
195         Group2->hide();
196         Group3->hide();
197         Group1->SpinBox_DX->SetValue( R );
198     break;
199     case 1:
200         Group1->hide();
201         Group2->show();
202         Group3->hide();
203         Group2->SpinBox_DX->SetValue( R );
204     break;
205     case 2:
206         Group1->hide();
207         Group2->hide();
208         Group3->show();
209         Group3->SpinBox_DX->SetValue( R );
210     break;
211     default:
212     break;
213   }
214
215   if      ( constructorId == 0 ) myEditCurrentArgument = Group1->LineEdit1;
216   else if ( constructorId == 1 ) myEditCurrentArgument = Group2->LineEdit1;
217   else                           myEditCurrentArgument = Group3->LineEdit1;
218
219   activateSelection();
220   enableWidgets();
221
222   if ( !myShape->_is_nil() )
223   {
224     myEditCurrentArgument->setText( GEOMBase::GetName( myShape ) );
225     GEOMBase_Skeleton::LineEditReturnPressed();
226   }
227   else
228     myEditCurrentArgument->setText( "" );
229
230   displayPreview();  
231 }
232
233
234 //=================================================================================
235 // function : ClickOnOk()
236 // purpose  :
237 //=================================================================================
238 void OperationGUI_FilletDlg::ClickOnOk()
239 {
240   if ( ClickOnApply() )
241     ClickOnCancel();
242 }
243
244
245 //=================================================================================
246 // function : ClickOnApply()
247 // purpose  :
248 //=================================================================================
249 bool OperationGUI_FilletDlg::ClickOnApply()
250 {
251     if ( !onAccept() )
252     return false;
253
254   initName();
255   return true;
256 }
257
258 //=================================================================================
259 // function : SelectionIntoArgument()
260 // purpose  : Called when selection has changed
261 //=================================================================================
262 void OperationGUI_FilletDlg::SelectionIntoArgument()
263 {
264   erasePreview();
265   myEditCurrentArgument->setText( "" );
266
267   // If selection of main object is activated
268   if ( myEditCurrentArgument == Group1->LineEdit1 ||
269        myEditCurrentArgument == Group2->LineEdit1 ||
270        myEditCurrentArgument == Group3->LineEdit1 )
271   {
272     if ( mySelection->IObjectCount() == 1 )
273     {
274       Standard_Boolean aResult = Standard_False;
275       GEOM::GEOM_Object_var anObj =
276         GEOMBase::ConvertIOinGEOMObject( mySelection->firstIObject(), aResult );
277
278       if ( aResult && !anObj->_is_nil() )
279       {
280         myShape = anObj;
281         myEditCurrentArgument->setText( GEOMBase::GetName( anObj ) );
282         displayPreview();
283         enableWidgets();
284         return;
285       }
286     }
287
288     myShape = GEOM::GEOM_Object::_nil();
289     enableWidgets();
290   }
291   // If face or edge selection is activated
292   else if ( myEditCurrentArgument == Group2->LineEdit2 ||
293             myEditCurrentArgument == Group3->LineEdit2 )
294   {
295     if ( mySelection->IObjectCount() == 1 )
296     {
297       Standard_Boolean aResult = Standard_False;
298       GEOM::GEOM_Object_var anObj =
299         GEOMBase::ConvertIOinGEOMObject( mySelection->firstIObject(), aResult );
300
301       if ( aResult && !anObj->_is_nil() )
302       {
303          TColStd_IndexedMapOfInteger anIndexes;
304          mySelection->GetIndex( mySelection->firstIObject(), anIndexes );
305
306          if ( anIndexes.Extent() > 0 )
307          {
308            QString aName;
309            if ( anIndexes.Extent() == 1 )
310            {
311              int anIndex = anIndexes( 1 );
312
313              aName = QString( GEOMBase::GetName( anObj ) ) + QString( ":%1" ).arg( anIndex );
314            }
315            else
316              aName = tr( "GEOM_MEN_POPUP_NAME" ).arg( anIndexes.Extent() );
317
318            myEditCurrentArgument->setText( aName );
319
320            if ( myConstructorId == 1 )
321              myEdges = anIndexes;
322            else
323              myFaces = anIndexes;
324            
325            displayPreview();
326            return;
327          }
328       }
329     }
330     myFaces.Clear();
331   }
332 }
333
334
335 //=================================================================================
336 // function : LineEditReturnPressed()
337 // purpose  :
338 //=================================================================================
339 void OperationGUI_FilletDlg::LineEditReturnPressed()
340 {
341   QLineEdit* send = ( QLineEdit* )sender();
342   
343   if ( send == Group1->LineEdit1 )
344     myEditCurrentArgument = Group1->LineEdit1;
345   else if ( send == Group2->LineEdit1 )
346     myEditCurrentArgument = Group2->LineEdit1;
347   else if ( send == Group3->LineEdit1 )
348     myEditCurrentArgument = Group3->LineEdit1;
349   else
350     return;
351
352   GEOMBase_Skeleton::LineEditReturnPressed();
353   return;
354 }
355
356
357 //=================================================================================
358 // function : SetEditCurrentArgument()
359 // purpose  :
360 //=================================================================================
361 void OperationGUI_FilletDlg::SetEditCurrentArgument()
362 {
363   QPushButton* send = (QPushButton*)sender();
364
365   if ( send == Group1->PushButton1 )
366   {
367     Group1->LineEdit1->setFocus();
368     myEditCurrentArgument = Group1->LineEdit1;
369   }
370   else if( send == Group2->PushButton1 )
371   {
372     Group2->LineEdit1->setFocus();
373     myEditCurrentArgument = Group2->LineEdit1;
374   }
375   else if( send == Group2->PushButton2 )
376   {
377     Group2->LineEdit2->setFocus();
378     myEditCurrentArgument = Group2->LineEdit2;
379   }
380   else if ( send == Group3->PushButton1 )
381   {
382     Group3->LineEdit1->setFocus();
383     myEditCurrentArgument = Group3->LineEdit1;
384   }
385   else if( send == Group3->PushButton2 )
386   {
387     Group3->LineEdit1->setFocus();
388     myEditCurrentArgument = Group3->LineEdit2;
389   }
390
391   activateSelection();
392 }
393
394
395 //=================================================================================
396 // function : DeactivateActiveDialog()
397 // purpose  :
398 //=================================================================================
399 void OperationGUI_FilletDlg::DeactivateActiveDialog()
400 {
401   GEOMBase_Skeleton::DeactivateActiveDialog();
402   return;
403 }
404
405
406 //=================================================================================
407 // function : ActivateThisDialog()
408 // purpose  :
409 //=================================================================================
410 void OperationGUI_FilletDlg::ActivateThisDialog()
411 {
412   GEOMBase_Skeleton::ActivateThisDialog();
413
414   connect( mySelection, SIGNAL(currentSelectionChanged()),
415            this, SLOT( SelectionIntoArgument() ) );
416
417   activateSelection();
418   displayPreview();
419 }
420
421
422 //=================================================================================
423 // function : enterEvent()
424 // purpose  :
425 //=================================================================================
426 void OperationGUI_FilletDlg::enterEvent( QEvent* e )
427 {
428   if ( !GroupConstructors->isEnabled() )
429     this->ActivateThisDialog();
430 }
431
432 //=================================================================================
433 // function : ValueChangedInSpinBox()
434 // purpose  :
435 //=================================================================================
436 void OperationGUI_FilletDlg::ValueChangedInSpinBox( double newValue )
437 {
438   displayPreview();
439 }
440
441 //=================================================================================
442 // function : reset()
443 // purpose  :
444 //=================================================================================
445 void OperationGUI_FilletDlg::reset()
446 {
447   // Set Initial values of spinboxes
448   Group1->SpinBox_DX->SetValue( 5 );
449   Group2->SpinBox_DX->SetValue( 5 );
450   Group3->SpinBox_DX->SetValue( 5 );
451
452   Group1->LineEdit1->setText( "" );
453   Group2->LineEdit1->setText( "" );
454   Group2->LineEdit2->setText( "" );
455   Group3->LineEdit1->setText( "" );
456   Group3->LineEdit2->setText( "" );
457
458   // constructor id
459   int aConstructorId = getConstructorId();
460
461   if      ( aConstructorId == 0 ) myEditCurrentArgument = Group1->LineEdit1;
462   else if ( aConstructorId == 1 ) myEditCurrentArgument = Group2->LineEdit1;
463   else                            myEditCurrentArgument = Group3->LineEdit1;
464
465   myShape = GEOM::GEOM_Object::_nil();
466
467   myFaces.Clear();
468   myEdges.Clear();
469
470   erasePreview( true );
471
472   activateSelection();
473
474   enableWidgets();
475 }
476
477 //=================================================================================
478 // function : getConstructorId()
479 // purpose  :
480 //=================================================================================
481 int OperationGUI_FilletDlg::getConstructorId() const
482 {
483   return GroupConstructors->id( GroupConstructors->selected() );
484 }
485
486 //=================================================================================
487 // function : activateSelection
488 // purpose  : Activate selection in accordance with myEditCurrentArgument
489 //=================================================================================
490 void OperationGUI_FilletDlg::activateSelection()
491 {
492
493   if ( !myShape->_is_nil() && myEditCurrentArgument == Group2->LineEdit2 )
494     localSelection( myShape, TopAbs_EDGE );
495   else if ( !myShape->_is_nil() && myEditCurrentArgument == Group3->LineEdit2 )
496     localSelection( myShape, TopAbs_FACE );
497   else
498   {
499     TColStd_MapOfInteger aMap;
500     aMap.Add( GEOM_SHELL );
501     aMap.Add( GEOM_SOLID );
502     aMap.Add( GEOM_COMPOUND );
503     globalSelection( aMap );
504   }
505
506   SelectionIntoArgument();
507 }
508
509 //=================================================================================
510 // function : enableWidgets
511 // purpose  : Enable widgets of faces in accordance with value of main object
512 //=================================================================================
513 void OperationGUI_FilletDlg::enableWidgets()
514 {
515   int anId = getConstructorId();
516
517   bool toEnable = !myShape->_is_nil();
518
519   if ( anId == 1 )
520   {
521     Group2->LineEdit2->setEnabled( toEnable );
522     Group2->PushButton2->setEnabled( toEnable );
523     
524     if ( !toEnable )
525     {
526       Group2->LineEdit2->setText( "" );
527       myEdges.Clear();
528     }
529   }
530   else if ( anId == 2 )
531   {
532     Group3->LineEdit2->setEnabled( toEnable );
533     Group3->PushButton2->setEnabled( toEnable );
534
535     if ( !toEnable )
536     {
537       Group3->LineEdit2->setText( "" );
538       myFaces.Clear();
539     }
540   }
541 }
542
543 //=================================================================================
544 // function : createOperation
545 // purpose  :
546 //=================================================================================
547 GEOM::GEOM_IOperations_ptr OperationGUI_FilletDlg::createOperation()
548 {
549   return getGeomEngine()->GetILocalOperations( getStudyId() );
550 }
551
552 //=================================================================================
553 // function : ClickOnApply()
554 // purpose  : Verify validity of input data
555 //=================================================================================
556 bool OperationGUI_FilletDlg::isValid( QString& )
557 {
558   switch ( getConstructorId() )
559   {
560     case 0: return !myShape->_is_nil();
561     case 1: return !myShape->_is_nil() && myEdges.Extent() > 0;
562     case 2: return !myShape->_is_nil() && myFaces.Extent() > 0;
563     default: return false;
564   }
565 }
566
567 //=================================================================================
568 // function : execute
569 // purpose  :
570 //=================================================================================
571 bool OperationGUI_FilletDlg::execute( ObjectList& objects )
572 {
573   GEOM::GEOM_Object_var anObj;
574
575   int anId = getConstructorId();
576   if ( anId == 0 )
577     anObj = GEOM::GEOM_ILocalOperations::_narrow(
578       getOperation() )->MakeFilletAll( myShape,
579                                        getRadius() );
580   else if ( anId == 1 )
581   {
582     GEOM::ListOfLong_var aList = new GEOM::ListOfLong;
583     aList->length( myEdges.Extent() );
584
585     for ( int i = 1, n = myEdges.Extent(); i <= n; i++ )
586       aList[ i - 1 ] = myEdges( i );
587
588     anObj = GEOM::GEOM_ILocalOperations::_narrow(
589       getOperation() )->MakeFilletEdges( myShape, getRadius(), aList );
590   }
591   else if ( anId == 2 )
592   {
593     int i = 0;
594     GEOM::ListOfLong_var aList = new GEOM::ListOfLong;
595     aList->length( myFaces.Extent() );
596
597     for ( int i = 1, n = myFaces.Extent(); i <= n; i++ )
598       aList[ i - 1 ] = myFaces( i );
599
600     anObj = GEOM::GEOM_ILocalOperations::_narrow(
601       getOperation() )->MakeFilletFaces( myShape, getRadius(), aList );
602   }
603
604   if ( !anObj->_is_nil() )
605     objects.push_back( anObj._retn() );
606
607   return true;
608 }
609
610 //=================================================================================
611 // function : getRadius
612 // purpose  : Get radius     
613 //=================================================================================
614 double OperationGUI_FilletDlg::getRadius() const
615 {
616   int anId = getConstructorId();
617   if      ( anId == 0 ) return Group1->SpinBox_DX->GetValue();
618   else if ( anId == 1 ) return Group2->SpinBox_DX->GetValue();
619   else                  return Group3->SpinBox_DX->GetValue();
620 }
621
622
623
624
625
626
627