]> SALOME platform Git repositories - modules/geom.git/blob - src/OperationGUI/OperationGUI_FilletDlg.cxx
Salome HOME
SALOME PAL V1_4_1
[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 using namespace std;
30 #include "OperationGUI_FilletDlg.h"
31
32 #include "DisplayGUI.h"
33 #include "QAD_MessageBox.h"
34
35 #include <AIS_InteractiveContext.hxx>
36 #include <TopExp_Explorer.hxx>
37 #include <BRepFilletAPI_MakeFillet.hxx>
38 #include <Precision.hxx>
39
40 #include <Standard_ErrorHandler.hxx> 
41 #include <Standard_Failure.hxx>
42
43 //=================================================================================
44 // class    : OperationGUI_FilletDlg()
45 // purpose  : Constructs a OperationGUI_FilletDlg 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 OperationGUI_FilletDlg::OperationGUI_FilletDlg(QWidget* parent, const char* name, OperationGUI* theOperationGUI, SALOME_Selection* Sel, Handle(AIS_InteractiveContext) ic, bool modal, WFlags fl)
51   :GEOMBase_Skeleton(parent, name, Sel, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
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   QPixmap image3(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_SELECT")));
57
58   setCaption(tr("GEOM_FILLET_TITLE"));
59
60   /***************************************************************/
61   GroupConstructors->setTitle(tr("GEOM_FILLET"));
62   RadioButton1->setPixmap(image0);
63   RadioButton2->setPixmap(image1);
64   RadioButton3->setPixmap(image2);
65
66   Group1 = new DlgRef_1Sel1Spin(this, "Group1");
67   Group1->GroupBox1->setTitle(tr("GEOM_FILLET_ALL"));
68   Group1->TextLabel1->setText(tr("GEOM_MAIN_OBJECT"));
69   Group1->TextLabel2->setText(tr("GEOM_RADIUS"));
70   Group1->PushButton1->setPixmap(image3);
71
72   Group2 = new DlgRef_1Sel1Spin(this, "Group2");
73   Group2->GroupBox1->setTitle(tr("GEOM_FILLET_EDGES"));
74   Group2->TextLabel1->setText(tr("GEOM_MAIN_OBJECT"));
75   Group2->TextLabel2->setText(tr("GEOM_RADIUS"));
76   Group2->PushButton1->setPixmap(image3);
77
78   Group3 = new DlgRef_1Sel1Spin(this, "Group3");
79   Group3->GroupBox1->setTitle(tr("GEOM_FILLET_FACES"));
80   Group3->TextLabel1->setText(tr("GEOM_MAIN_OBJECT"));
81   Group3->TextLabel2->setText(tr("GEOM_RADIUS"));
82   Group3->PushButton1->setPixmap(image3);
83
84   Layout1->addWidget(Group1, 1, 0);
85   Layout1->addWidget(Group2, 1, 0);
86   Layout1->addWidget(Group3, 1, 0);
87   /***************************************************************/
88
89   /* Initialisations */
90   myOperationGUI = theOperationGUI;
91   Init(ic);
92 }
93
94
95 //=================================================================================
96 // function : ~OperationGUI_FilletDlg()
97 // purpose  : Destroys the object and frees any allocated resources
98 //=================================================================================
99 OperationGUI_FilletDlg::~OperationGUI_FilletDlg()
100 {  
101   /* no need to delete child widgets, Qt does it all for us */
102 }
103
104
105 //=================================================================================
106 // function : Init()
107 // purpose  :
108 //=================================================================================
109 void OperationGUI_FilletDlg::Init(Handle(AIS_InteractiveContext) ic)
110 {
111   /* init variables */
112   myConstructorId = 0;
113   myEditCurrentArgument = Group1->LineEdit1;
114
115   myRadius = 5.0;
116   myOkShape = false;
117   myIC = ic;
118   myLocalContextId = -1;
119   myUseLocalContext = false;
120
121   double SpecificStep = 10.0;
122   /* min, max, step and decimals for spin boxes */
123   Group1->SpinBox_DX->RangeStepAndValidator(0.001, 999.999, SpecificStep, 3);
124   Group2->SpinBox_DX->RangeStepAndValidator(0.001, 999.999, SpecificStep, 3);
125   Group3->SpinBox_DX->RangeStepAndValidator(0.001, 999.999, SpecificStep, 3);
126
127   Group1->SpinBox_DX->SetValue(myRadius);
128   Group2->SpinBox_DX->SetValue(myRadius);
129   Group3->SpinBox_DX->SetValue(myRadius);
130
131   /* signals and slots connections */
132   connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
133   connect(myGeomGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
134   connect(myGeomGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
135
136   connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
137   connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
138   connect(GroupConstructors, SIGNAL(clicked(int)), this, SLOT(ConstructorsClicked(int)));
139
140   connect(Group1->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
141   connect(Group2->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
142   connect(Group3->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
143
144   connect(Group1->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
145   connect(Group2->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
146   connect(Group3->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
147
148   connect(Group1->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
149   connect(Group2->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
150   connect(Group3->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
151   
152   connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), Group1->SpinBox_DX, SLOT(SetStep(double)));
153   connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), Group2->SpinBox_DX, SLOT(SetStep(double)));
154   connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), Group3->SpinBox_DX, SLOT(SetStep(double)));
155
156   connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
157
158   /* displays Dialog */
159   Group2->hide();
160   Group3->hide();
161   Group1->show();
162   this->show();
163
164   return;
165 }
166
167
168 //=================================================================================
169 // function : ConstructorsClicked()
170 // purpose  : Radio button management
171 //=================================================================================
172 void OperationGUI_FilletDlg::ConstructorsClicked(int constructorId)
173 {
174   myConstructorId = constructorId;
175   myGeomBase->EraseSimulationShape();
176   mySimulationTopoDs.Nullify();
177   disconnect(mySelection, 0, this, 0);
178   myOkShape = false;
179   myRadius = 5.0;
180
181   if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_OCC && myUseLocalContext) {
182     myIC->CloseLocalContext(myLocalContextId);
183     DisplayGUI* myDisplayGUI = new DisplayGUI();
184     myDisplayGUI->OnDisplayAll(true);
185     myUseLocalContext = false;
186   }
187
188   if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() != VIEW_OCC) {
189     myConstructorId = constructorId = 0; //No subshape selection if viewer is not OCC
190     RadioButton1->setChecked(TRUE);
191   }
192   
193   connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
194   switch (constructorId)
195     {
196     case 0: /* Fillet All */
197       {
198         Group2->hide();
199         Group3->hide();
200         resize(0, 0);
201         Group1->show();
202
203         myEditCurrentArgument = Group1->LineEdit1;
204         Group1->LineEdit1->setText("");
205         myShapeType = -1;
206
207         Group1->SpinBox_DX->SetValue(myRadius);
208         break;
209       }
210     case 1: /* Fillet edges */
211       {
212         Group1->hide();
213         Group3->hide();
214         resize(0, 0);
215         Group2->show();
216
217         myEditCurrentArgument = Group2->LineEdit1;
218         Group2->LineEdit1->setText("");
219         myShapeType = 6;
220
221         Group2->SpinBox_DX->SetValue(myRadius);
222         break;
223       }
224     case 2: /* Fillet Faces */
225       {
226         Group1->hide();
227         Group2->hide();
228         resize(0, 0);
229         Group3->show();
230
231         myEditCurrentArgument = Group3->LineEdit1;
232         Group3->LineEdit1->setText("");
233         myShapeType = 4;
234
235         Group3->SpinBox_DX->SetValue(myRadius);
236         break;
237       }
238     }
239   return;
240 }
241
242
243 //=================================================================================
244 // function : ClickOnOk()
245 // purpose  :
246 //=================================================================================
247 void OperationGUI_FilletDlg::ClickOnOk()
248 {
249   this->ClickOnApply();
250   this->ClickOnCancel();
251   return;
252 }
253
254
255 //=================================================================================
256 // function : ClickOnApply()
257 // purpose  :
258 //=================================================================================
259 void OperationGUI_FilletDlg::ClickOnApply()
260 {
261   buttonApply->setFocus();
262   QApplication::setOverrideCursor(Qt::waitCursor);
263   QAD_Application::getDesktop()->putInfo(tr(""));
264   myGeomBase->EraseSimulationShape();
265   mySimulationTopoDs.Nullify();
266
267   bool testResult = false;
268   switch(myConstructorId)
269     { 
270     case 0 : /* Fillet All */
271       { 
272         if(myOkShape)
273           testResult = myOperationGUI->OnFilletGetAll(myShape, myRadius, myShapeType, myShapeIOR);
274         break;
275       }
276     case 1 : /* Fillet Edge */
277       { 
278         if(myOkShape)
279           testResult = myOperationGUI->OnFilletGetSelected(myShape, myShapeIOR, myRadius, myShapeType, myLocalContextId, myUseLocalContext);
280         break;
281       }
282     case 2 : /* Fillet Face */
283       {
284         if(myOkShape)
285           testResult = myOperationGUI->OnFilletGetSelected(myShape, myShapeIOR, myRadius, myShapeType, myLocalContextId, myUseLocalContext);       
286         break;
287       }
288     }
289
290   if(!testResult) 
291     QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_ABORT"));
292   else
293     QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_DONE"));
294   /* Reset all arguments and local context to allow user a new selection ...*/
295   this->ResetStateOfDialog();
296   QApplication::restoreOverrideCursor();
297   return;
298 }
299
300
301 //=================================================================================
302 // function : ClickOnCancel()
303 // purpose  :
304 //=================================================================================
305 void OperationGUI_FilletDlg::ClickOnCancel()
306 {
307   this->ResetStateOfDialog();
308   GEOMBase_Skeleton::ClickOnCancel();
309   return;
310 }
311
312
313 //=================================================================================
314 // function : SelectionIntoArgument()
315 // purpose  : Called when selection has changed
316 //=================================================================================
317 void OperationGUI_FilletDlg::SelectionIntoArgument()
318 {
319   myGeomBase->EraseSimulationShape();
320   mySimulationTopoDs.Nullify();
321   myEditCurrentArgument->setText("");
322   this->ResetStateOfDialog();
323   QString aString = ""; /* name of selection */
324
325   int nbSel = myGeomBase->GetNameOfSelectedIObjects(mySelection, aString);
326   if (nbSel == 1) {
327     TopoDS_Shape S;
328     Handle(SALOME_InteractiveObject) IO = mySelection->firstIObject();
329     if(!myGeomBase->GetTopoFromSelection(mySelection, S))
330       return;
331     if(!IO->hasEntry()) {
332       QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_SHAPE_IN_STUDY"));
333       return;
334     }
335         
336     if(!S.IsNull() &&  S.ShapeType() <= 2) {
337       if(IO->IsInstance(STANDARD_TYPE(GEOM_InteractiveObject))) {
338         Handle(GEOM_InteractiveObject) GIObject = Handle(GEOM_InteractiveObject)::DownCast(IO);
339         myShapeIOR = GIObject->getIOR(); /* the Geom IOR string of selection */
340         myEditCurrentArgument->setText(aString);
341         myShape = S;
342         myOkShape = true;
343       }
344       
345       if(IO->hasEntry()) {
346         SALOMEDS::Study_var aStudy = QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument();
347         SALOMEDS::SObject_var obj = aStudy->FindObjectID(IO->getEntry());
348         SALOMEDS::GenericAttribute_var anAttr;
349         SALOMEDS::AttributeIOR_var anIOR;
350         if(!obj->_is_nil()) {
351           if(obj->FindAttribute(anAttr, "AttributeIOR")) {
352             anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
353             myShapeIOR = anIOR->Value();
354             myOkShape = true;
355             myShape = S;
356             myEditCurrentArgument->setText(aString);
357           }
358         }
359       }
360     }
361     if(myConstructorId == 0)
362       this->MakePreview();
363   }
364   else 
365     return;
366   
367   if(myOkShape && myShapeType!=-1 && myConstructorId != 0) {
368     /* local context is defined into the method */
369     DisplayGUI* myDisplayGUI = new DisplayGUI();
370     myDisplayGUI->PrepareSubShapeSelection(myShapeType, myLocalContextId);  
371     myUseLocalContext = true;
372   }
373 }
374
375
376 //=================================================================================
377 // function : LineEditReturnPressed()
378 // purpose  :
379 //=================================================================================
380 void OperationGUI_FilletDlg::LineEditReturnPressed()
381 {
382   QLineEdit* send = (QLineEdit*)sender();
383   if(send == Group1->LineEdit1)
384     myEditCurrentArgument = Group1->LineEdit1;
385   else if (send == Group2->LineEdit1)
386     myEditCurrentArgument = Group2->LineEdit1;
387   else if (send == Group3->LineEdit1)
388     myEditCurrentArgument = Group3->LineEdit1;
389   else
390     return;
391
392   GEOMBase_Skeleton::LineEditReturnPressed();
393   return;
394 }
395
396
397 //=================================================================================
398 // function : SetEditCurrentArgument()
399 // purpose  :
400 //=================================================================================
401 void OperationGUI_FilletDlg::SetEditCurrentArgument()
402 {
403   QPushButton* send = (QPushButton*)sender();  
404
405   if(send == Group1->PushButton1) {
406     Group1->LineEdit1->setFocus();
407     myEditCurrentArgument = Group1->LineEdit1;
408   }
409   else if(send == Group2->PushButton1) {
410     Group2->LineEdit1->setFocus();
411     myEditCurrentArgument = Group2->LineEdit1;
412   }
413   else if(send == Group3->PushButton1) {
414     Group3->LineEdit1->setFocus();
415     myEditCurrentArgument = Group3->LineEdit1;
416   }
417   this->SelectionIntoArgument();
418   return;
419 }
420
421
422 //=================================================================================
423 // function : DeactivateActiveDialog()
424 // purpose  :
425 //=================================================================================
426 void OperationGUI_FilletDlg::DeactivateActiveDialog()
427 {
428   this->ResetStateOfDialog();
429   GEOMBase_Skeleton::DeactivateActiveDialog();
430   return;
431 }
432
433
434 //=================================================================================
435 // function : ActivateThisDialog()
436 // purpose  :
437 //=================================================================================
438 void OperationGUI_FilletDlg::ActivateThisDialog()
439 {
440   GEOMBase_Skeleton::ActivateThisDialog();
441   connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
442   if(!mySimulationTopoDs.IsNull())
443     myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
444   return;
445 }
446
447
448 //=================================================================================
449 // function : enterEvent()
450 // purpose  :
451 //=================================================================================
452 void OperationGUI_FilletDlg::enterEvent(QEvent* e)
453 {
454   if(GroupConstructors->isEnabled())
455     return;
456   this->ActivateThisDialog();
457   return;
458 }
459
460
461 //=================================================================================
462 // function : closeEvent()
463 // purpose  :
464 //=================================================================================
465 void OperationGUI_FilletDlg::closeEvent(QCloseEvent* e)
466
467   /* same than click on cancel button */
468   this->ClickOnCancel();
469   return;
470 }
471
472
473 //=================================================================================
474 // function : ResetStateOfDialog()
475 // purpose  :
476 //=================================================================================
477 void OperationGUI_FilletDlg::ResetStateOfDialog()
478 {
479   myOkShape = false;
480   myEditCurrentArgument->setText("");
481   QApplication::restoreOverrideCursor();
482
483   /* Close its local contact if opened */
484   if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_OCC && myUseLocalContext) {
485     myIC->CloseLocalContext(myLocalContextId);
486     myUseLocalContext = false;
487     DisplayGUI* myDisplayGUI = new DisplayGUI();
488     myDisplayGUI->OnDisplayAll(true);
489   }
490   return;
491 }
492
493
494 //=================================================================================
495 // function : ValueChangedInSpinBox()
496 // purpose  :
497 //=================================================================================
498 void OperationGUI_FilletDlg::ValueChangedInSpinBox(double newValue)
499 {
500   myGeomBase->EraseSimulationShape(); 
501   mySimulationTopoDs.Nullify();
502
503   myRadius = newValue;
504
505   if(myConstructorId == 0)
506     this->MakePreview();
507   return;
508 }
509
510
511 //=================================================================================
512 // function : MakePreview()
513 // purpose  :
514 //=================================================================================
515 void OperationGUI_FilletDlg::MakePreview()
516 {
517   QApplication::setOverrideCursor( Qt::waitCursor );
518   TopoDS_Shape tds ;
519   try
520     {
521       BRepFilletAPI_MakeFillet fill(myShape);
522       switch (myConstructorId)
523         {
524         case 0: /* Fillet All */
525           {
526             TopExp_Explorer Exp ( myShape, TopAbs_EDGE );
527             for (Exp; Exp.More(); Exp.Next()) 
528               {
529                 TopoDS_Edge E =TopoDS::Edge(Exp.Current());
530                 fill.Add(E);
531               }
532             for (int i = 1;i<=fill.NbContours();i++) {
533               try
534                 {
535                   fill.SetRadius(myRadius,i,i);
536                 }  
537               catch(Standard_Failure)
538                 {
539                   QAD_MessageBox::warn1 (QAD_Application::getDesktop(), tr("GEOM_WRN_WARNING"), tr("GEOM_FILLET_ABORT").arg(myRadius), tr("GEOM_BUT_OK"));
540                   Group1->SpinBox_DX->SetValue(5.0);
541                   myGeomBase->EraseSimulationShape() ; 
542                   mySimulationTopoDs.Nullify() ;
543                   QApplication::restoreOverrideCursor();
544                   return;
545                 }
546             }
547             tds = fill.Shape();
548             break;
549           }
550           //    case 1: /* Fillet edges */
551           //    case 2: /* Fillet Faces */
552         }
553       if (!tds.IsNull()) 
554         {
555           mySimulationTopoDs = tds;
556           myGeomBase->DisplaySimulationShape( mySimulationTopoDs ) ; 
557         }
558     }  
559   catch(Standard_Failure)
560     {
561       QAD_MessageBox::warn1 (QAD_Application::getDesktop(), tr("GEOM_WRN_WARNING"), tr("GEOM_FILLET_ABORT").arg(myRadius), tr("GEOM_BUT_OK"));
562       Group1->SpinBox_DX->SetValue(5.0);
563       myGeomBase->EraseSimulationShape() ; 
564       mySimulationTopoDs.Nullify() ;
565       QApplication::restoreOverrideCursor();
566      
567     }
568   QApplication::restoreOverrideCursor();
569 }