1 // GEOM GEOMGUI : GUI for Geometry component
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : OperationGUI_FilletDlg.cxx
25 // Author : Damien COQUERET
30 #include "OperationGUI_FilletDlg.h"
32 #include "DisplayGUI.h"
33 #include "QAD_MessageBox.h"
35 #include <AIS_InteractiveContext.hxx>
36 #include <TopExp_Explorer.hxx>
37 #include <BRepFilletAPI_MakeFillet.hxx>
38 #include <Precision.hxx>
40 #include <Standard_ErrorHandler.hxx>
41 #include <Standard_Failure.hxx>
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)
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")));
58 setCaption(tr("GEOM_FILLET_TITLE"));
60 /***************************************************************/
61 GroupConstructors->setTitle(tr("GEOM_FILLET"));
62 RadioButton1->setPixmap(image0);
63 RadioButton2->setPixmap(image1);
64 RadioButton3->setPixmap(image2);
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);
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);
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);
84 Layout1->addWidget(Group1, 1, 0);
85 Layout1->addWidget(Group2, 1, 0);
86 Layout1->addWidget(Group3, 1, 0);
87 /***************************************************************/
90 myOperationGUI = theOperationGUI;
95 //=================================================================================
96 // function : ~OperationGUI_FilletDlg()
97 // purpose : Destroys the object and frees any allocated resources
98 //=================================================================================
99 OperationGUI_FilletDlg::~OperationGUI_FilletDlg()
101 /* no need to delete child widgets, Qt does it all for us */
105 //=================================================================================
108 //=================================================================================
109 void OperationGUI_FilletDlg::Init(Handle(AIS_InteractiveContext) ic)
113 myEditCurrentArgument = Group1->LineEdit1;
118 myLocalContextId = -1;
119 myUseLocalContext = false;
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);
127 Group1->SpinBox_DX->SetValue(myRadius);
128 Group2->SpinBox_DX->SetValue(myRadius);
129 Group3->SpinBox_DX->SetValue(myRadius);
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()));
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)));
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()));
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()));
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)));
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)));
156 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
158 /* displays Dialog */
168 //=================================================================================
169 // function : ConstructorsClicked()
170 // purpose : Radio button management
171 //=================================================================================
172 void OperationGUI_FilletDlg::ConstructorsClicked(int constructorId)
174 myConstructorId = constructorId;
175 myGeomBase->EraseSimulationShape();
176 mySimulationTopoDs.Nullify();
177 disconnect(mySelection, 0, this, 0);
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;
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);
193 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
194 switch (constructorId)
196 case 0: /* Fillet All */
203 myEditCurrentArgument = Group1->LineEdit1;
204 Group1->LineEdit1->setText("");
207 Group1->SpinBox_DX->SetValue(myRadius);
210 case 1: /* Fillet edges */
217 myEditCurrentArgument = Group2->LineEdit1;
218 Group2->LineEdit1->setText("");
221 Group2->SpinBox_DX->SetValue(myRadius);
224 case 2: /* Fillet Faces */
231 myEditCurrentArgument = Group3->LineEdit1;
232 Group3->LineEdit1->setText("");
235 Group3->SpinBox_DX->SetValue(myRadius);
243 //=================================================================================
244 // function : ClickOnOk()
246 //=================================================================================
247 void OperationGUI_FilletDlg::ClickOnOk()
249 this->ClickOnApply();
250 this->ClickOnCancel();
255 //=================================================================================
256 // function : ClickOnApply()
258 //=================================================================================
259 void OperationGUI_FilletDlg::ClickOnApply()
261 buttonApply->setFocus();
262 QApplication::setOverrideCursor(Qt::waitCursor);
263 QAD_Application::getDesktop()->putInfo(tr(""));
264 myGeomBase->EraseSimulationShape();
265 mySimulationTopoDs.Nullify();
267 bool testResult = false;
268 switch(myConstructorId)
270 case 0 : /* Fillet All */
273 testResult = myOperationGUI->OnFilletGetAll(myShape, myRadius, myShapeType, myShapeIOR);
276 case 1 : /* Fillet Edge */
279 testResult = myOperationGUI->OnFilletGetSelected(myShape, myShapeIOR, myRadius, myShapeType, myLocalContextId, myUseLocalContext);
282 case 2 : /* Fillet Face */
285 testResult = myOperationGUI->OnFilletGetSelected(myShape, myShapeIOR, myRadius, myShapeType, myLocalContextId, myUseLocalContext);
291 QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_ABORT"));
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();
301 //=================================================================================
302 // function : ClickOnCancel()
304 //=================================================================================
305 void OperationGUI_FilletDlg::ClickOnCancel()
307 this->ResetStateOfDialog();
308 GEOMBase_Skeleton::ClickOnCancel();
313 //=================================================================================
314 // function : SelectionIntoArgument()
315 // purpose : Called when selection has changed
316 //=================================================================================
317 void OperationGUI_FilletDlg::SelectionIntoArgument()
319 myGeomBase->EraseSimulationShape();
320 mySimulationTopoDs.Nullify();
321 myEditCurrentArgument->setText("");
322 this->ResetStateOfDialog();
323 QString aString = ""; /* name of selection */
325 int nbSel = myGeomBase->GetNameOfSelectedIObjects(mySelection, aString);
328 Handle(SALOME_InteractiveObject) IO = mySelection->firstIObject();
329 if(!myGeomBase->GetTopoFromSelection(mySelection, S))
331 if(!IO->hasEntry()) {
332 QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_SHAPE_IN_STUDY"));
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);
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();
356 myEditCurrentArgument->setText(aString);
361 if(myConstructorId == 0)
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;
376 //=================================================================================
377 // function : LineEditReturnPressed()
379 //=================================================================================
380 void OperationGUI_FilletDlg::LineEditReturnPressed()
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;
392 GEOMBase_Skeleton::LineEditReturnPressed();
397 //=================================================================================
398 // function : SetEditCurrentArgument()
400 //=================================================================================
401 void OperationGUI_FilletDlg::SetEditCurrentArgument()
403 QPushButton* send = (QPushButton*)sender();
405 if(send == Group1->PushButton1) {
406 Group1->LineEdit1->setFocus();
407 myEditCurrentArgument = Group1->LineEdit1;
409 else if(send == Group2->PushButton1) {
410 Group2->LineEdit1->setFocus();
411 myEditCurrentArgument = Group2->LineEdit1;
413 else if(send == Group3->PushButton1) {
414 Group3->LineEdit1->setFocus();
415 myEditCurrentArgument = Group3->LineEdit1;
417 this->SelectionIntoArgument();
422 //=================================================================================
423 // function : DeactivateActiveDialog()
425 //=================================================================================
426 void OperationGUI_FilletDlg::DeactivateActiveDialog()
428 this->ResetStateOfDialog();
429 GEOMBase_Skeleton::DeactivateActiveDialog();
434 //=================================================================================
435 // function : ActivateThisDialog()
437 //=================================================================================
438 void OperationGUI_FilletDlg::ActivateThisDialog()
440 GEOMBase_Skeleton::ActivateThisDialog();
441 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
442 if(!mySimulationTopoDs.IsNull())
443 myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
448 //=================================================================================
449 // function : enterEvent()
451 //=================================================================================
452 void OperationGUI_FilletDlg::enterEvent(QEvent* e)
454 if(GroupConstructors->isEnabled())
456 this->ActivateThisDialog();
461 //=================================================================================
462 // function : closeEvent()
464 //=================================================================================
465 void OperationGUI_FilletDlg::closeEvent(QCloseEvent* e)
467 /* same than click on cancel button */
468 this->ClickOnCancel();
473 //=================================================================================
474 // function : ResetStateOfDialog()
476 //=================================================================================
477 void OperationGUI_FilletDlg::ResetStateOfDialog()
480 myEditCurrentArgument->setText("");
481 QApplication::restoreOverrideCursor();
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);
494 //=================================================================================
495 // function : ValueChangedInSpinBox()
497 //=================================================================================
498 void OperationGUI_FilletDlg::ValueChangedInSpinBox(double newValue)
500 myGeomBase->EraseSimulationShape();
501 mySimulationTopoDs.Nullify();
505 if(myConstructorId == 0)
511 //=================================================================================
512 // function : MakePreview()
514 //=================================================================================
515 void OperationGUI_FilletDlg::MakePreview()
517 QApplication::setOverrideCursor( Qt::waitCursor );
521 BRepFilletAPI_MakeFillet fill(myShape);
522 switch (myConstructorId)
524 case 0: /* Fillet All */
526 TopExp_Explorer Exp ( myShape, TopAbs_EDGE );
527 for (Exp; Exp.More(); Exp.Next())
529 TopoDS_Edge E =TopoDS::Edge(Exp.Current());
532 for (int i = 1;i<=fill.NbContours();i++) {
535 fill.SetRadius(myRadius,i,i);
537 catch(Standard_Failure)
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();
550 // case 1: /* Fillet edges */
551 // case 2: /* Fillet Faces */
555 mySimulationTopoDs = tds;
556 myGeomBase->DisplaySimulationShape( mySimulationTopoDs ) ;
559 catch(Standard_Failure)
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();
568 QApplication::restoreOverrideCursor();