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"
34 #include <AIS_InteractiveContext.hxx>
35 #include <TopExp_Explorer.hxx>
36 #include <BRepFilletAPI_MakeFillet.hxx>
37 #include <Precision.hxx>
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, const char* name, OperationGUI* theOperationGUI, SALOME_Selection* Sel, Handle(AIS_InteractiveContext) ic, bool modal, WFlags fl)
47 :GEOMBase_Skeleton(parent, name, Sel, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
49 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_FILLET_ALL")));
50 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_FILLET_EDGE")));
51 QPixmap image2(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_FILLET_FACE")));
52 QPixmap image3(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_SELECT")));
54 setCaption(tr("GEOM_FILLET_TITLE"));
56 /***************************************************************/
57 GroupConstructors->setTitle(tr("GEOM_FILLET"));
58 RadioButton1->setPixmap(image0);
59 RadioButton2->setPixmap(image1);
60 RadioButton3->setPixmap(image2);
62 Group1 = new DlgRef_1Sel1Spin(this, "Group1");
63 Group1->GroupBox1->setTitle(tr("GEOM_FILLET_ALL"));
64 Group1->TextLabel1->setText(tr("GEOM_MAIN_OBJECT"));
65 Group1->TextLabel2->setText(tr("GEOM_RADIUS"));
66 Group1->PushButton1->setPixmap(image3);
68 Group2 = new DlgRef_1Sel1Spin(this, "Group2");
69 Group2->GroupBox1->setTitle(tr("GEOM_FILLET_EDGES"));
70 Group2->TextLabel1->setText(tr("GEOM_MAIN_OBJECT"));
71 Group2->TextLabel2->setText(tr("GEOM_RADIUS"));
72 Group2->PushButton1->setPixmap(image3);
74 Group3 = new DlgRef_1Sel1Spin(this, "Group3");
75 Group3->GroupBox1->setTitle(tr("GEOM_FILLET_FACES"));
76 Group3->TextLabel1->setText(tr("GEOM_MAIN_OBJECT"));
77 Group3->TextLabel2->setText(tr("GEOM_RADIUS"));
78 Group3->PushButton1->setPixmap(image3);
80 Layout1->addWidget(Group1, 1, 0);
81 Layout1->addWidget(Group2, 1, 0);
82 Layout1->addWidget(Group3, 1, 0);
83 /***************************************************************/
86 myOperationGUI = theOperationGUI;
91 //=================================================================================
92 // function : ~OperationGUI_FilletDlg()
93 // purpose : Destroys the object and frees any allocated resources
94 //=================================================================================
95 OperationGUI_FilletDlg::~OperationGUI_FilletDlg()
97 /* no need to delete child widgets, Qt does it all for us */
101 //=================================================================================
104 //=================================================================================
105 void OperationGUI_FilletDlg::Init(Handle(AIS_InteractiveContext) ic)
109 myEditCurrentArgument = Group1->LineEdit1;
114 myLocalContextId = -1;
115 myUseLocalContext = false;
117 double SpecificStep = 10.0;
118 /* min, max, step and decimals for spin boxes */
119 Group1->SpinBox_DX->RangeStepAndValidator(0.001, 999.999, SpecificStep, 3);
120 Group2->SpinBox_DX->RangeStepAndValidator(0.001, 999.999, SpecificStep, 3);
121 Group3->SpinBox_DX->RangeStepAndValidator(0.001, 999.999, SpecificStep, 3);
123 Group1->SpinBox_DX->SetValue(myRadius);
124 Group2->SpinBox_DX->SetValue(myRadius);
125 Group3->SpinBox_DX->SetValue(myRadius);
127 /* signals and slots connections */
128 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
129 connect(myGeomGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
130 connect(myGeomGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
132 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
133 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
134 connect(GroupConstructors, SIGNAL(clicked(int)), this, SLOT(ConstructorsClicked(int)));
136 connect(Group1->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
137 connect(Group2->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
138 connect(Group3->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
140 connect(Group1->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
141 connect(Group2->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
142 connect(Group3->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
144 connect(Group1->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
145 connect(Group2->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
146 connect(Group3->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
148 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), Group1->SpinBox_DX, SLOT(SetStep(double)));
149 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), Group2->SpinBox_DX, SLOT(SetStep(double)));
150 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), Group3->SpinBox_DX, SLOT(SetStep(double)));
152 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
154 /* displays Dialog */
164 //=================================================================================
165 // function : ConstructorsClicked()
166 // purpose : Radio button management
167 //=================================================================================
168 void OperationGUI_FilletDlg::ConstructorsClicked(int constructorId)
170 myConstructorId = constructorId;
171 myGeomBase->EraseSimulationShape();
172 mySimulationTopoDs.Nullify();
173 disconnect(mySelection, 0, this, 0);
177 if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_OCC && myUseLocalContext) {
178 myIC->CloseLocalContext(myLocalContextId);
179 DisplayGUI* myDisplayGUI = new DisplayGUI();
180 myDisplayGUI->OnDisplayAll(true);
181 myUseLocalContext = false;
184 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
185 switch (constructorId)
187 case 0: /* Fillet All */
194 myEditCurrentArgument = Group1->LineEdit1;
195 Group1->LineEdit1->setText("");
198 Group1->SpinBox_DX->SetValue(myRadius);
201 case 1: /* Fillet edges */
208 myEditCurrentArgument = Group2->LineEdit1;
209 Group2->LineEdit1->setText("");
212 Group2->SpinBox_DX->SetValue(myRadius);
215 case 2: /* Fillet Faces */
222 myEditCurrentArgument = Group3->LineEdit1;
223 Group3->LineEdit1->setText("");
226 Group3->SpinBox_DX->SetValue(myRadius);
234 //=================================================================================
235 // function : ClickOnOk()
237 //=================================================================================
238 void OperationGUI_FilletDlg::ClickOnOk()
240 this->ClickOnApply();
241 this->ClickOnCancel();
246 //=================================================================================
247 // function : ClickOnApply()
249 //=================================================================================
250 void OperationGUI_FilletDlg::ClickOnApply()
252 QApplication::setOverrideCursor(Qt::waitCursor);
253 QAD_Application::getDesktop()->putInfo(tr(""));
254 myGeomBase->EraseSimulationShape();
255 mySimulationTopoDs.Nullify();
257 bool testResult = false;
258 switch(myConstructorId)
260 case 0 : /* Fillet All */
263 testResult = myOperationGUI->OnFilletGetAll(myShape, myRadius, myShapeType, myShapeIOR);
266 case 1 : /* Fillet Edge */
269 testResult = myOperationGUI->OnFilletGetSelected(myShape, myShapeIOR, myRadius, myShapeType, myLocalContextId, myUseLocalContext);
272 case 2 : /* Fillet Face */
275 testResult = myOperationGUI->OnFilletGetSelected(myShape, myShapeIOR, myRadius, myShapeType, myLocalContextId, myUseLocalContext);
281 QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_ABORT"));
283 QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_DONE"));
284 /* Reset all arguments and local context to allow user a new selection ...*/
285 this->ResetStateOfDialog();
286 QApplication::restoreOverrideCursor();
291 //=================================================================================
292 // function : ClickOnCancel()
294 //=================================================================================
295 void OperationGUI_FilletDlg::ClickOnCancel()
297 this->ResetStateOfDialog();
298 GEOMBase_Skeleton::ClickOnCancel();
303 //=================================================================================
304 // function : SelectionIntoArgument()
305 // purpose : Called when selection has changed
306 //=================================================================================
307 void OperationGUI_FilletDlg::SelectionIntoArgument()
309 myGeomBase->EraseSimulationShape();
310 mySimulationTopoDs.Nullify();
311 myEditCurrentArgument->setText("");
312 this->ResetStateOfDialog();
313 QString aString = ""; /* name of selection */
315 int nbSel = myGeomBase->GetNameOfSelectedIObjects(mySelection, aString);
318 Handle(SALOME_InteractiveObject) IO = mySelection->firstIObject();
319 if(!myGeomBase->GetTopoFromSelection(mySelection, S))
321 if(!IO->hasEntry()) {
322 QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_SHAPE_IN_STUDY"));
326 if(!S.IsNull() && S.ShapeType() <= 2) {
327 if(IO->IsInstance(STANDARD_TYPE(GEOM_InteractiveObject))) {
328 Handle(GEOM_InteractiveObject) GIObject = Handle(GEOM_InteractiveObject)::DownCast(IO);
329 myShapeIOR = GIObject->getIOR(); /* the Geom IOR string of selection */
330 myEditCurrentArgument->setText(aString);
336 SALOMEDS::Study_var aStudy = QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument();
337 SALOMEDS::SObject_var obj = aStudy->FindObjectID(IO->getEntry());
338 SALOMEDS::GenericAttribute_var anAttr;
339 SALOMEDS::AttributeIOR_var anIOR;
340 if(!obj->_is_nil()) {
341 if(obj->FindAttribute(anAttr, "AttributeIOR")) {
342 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
343 myShapeIOR = anIOR->Value();
346 myEditCurrentArgument->setText(aString);
351 if(myConstructorId == 0)
357 if(myOkShape && myShapeType!=-1 && myConstructorId != 0) {
358 /* local context is defined into the method */
359 DisplayGUI* myDisplayGUI = new DisplayGUI();
360 myDisplayGUI->PrepareSubShapeSelection(myShapeType, myLocalContextId);
361 myUseLocalContext = true;
366 //=================================================================================
367 // function : LineEditReturnPressed()
369 //=================================================================================
370 void OperationGUI_FilletDlg::LineEditReturnPressed()
372 QLineEdit* send = (QLineEdit*)sender();
373 if(send == Group1->LineEdit1)
374 myEditCurrentArgument = Group1->LineEdit1;
375 else if (send == Group2->LineEdit1)
376 myEditCurrentArgument = Group2->LineEdit1;
377 else if (send == Group3->LineEdit1)
378 myEditCurrentArgument = Group3->LineEdit1;
382 GEOMBase_Skeleton::LineEditReturnPressed();
387 //=================================================================================
388 // function : SetEditCurrentArgument()
390 //=================================================================================
391 void OperationGUI_FilletDlg::SetEditCurrentArgument()
393 QPushButton* send = (QPushButton*)sender();
395 if(send == Group1->PushButton1) {
396 Group1->LineEdit1->setFocus();
397 myEditCurrentArgument = Group1->LineEdit1;
399 else if(send == Group2->PushButton1) {
400 Group2->LineEdit1->setFocus();
401 myEditCurrentArgument = Group2->LineEdit1;
403 else if(send == Group3->PushButton1) {
404 Group3->LineEdit1->setFocus();
405 myEditCurrentArgument = Group3->LineEdit1;
407 this->SelectionIntoArgument();
412 //=================================================================================
413 // function : DeactivateActiveDialog()
415 //=================================================================================
416 void OperationGUI_FilletDlg::DeactivateActiveDialog()
418 this->ResetStateOfDialog();
419 GEOMBase_Skeleton::DeactivateActiveDialog();
424 //=================================================================================
425 // function : ActivateThisDialog()
427 //=================================================================================
428 void OperationGUI_FilletDlg::ActivateThisDialog()
430 GEOMBase_Skeleton::ActivateThisDialog();
431 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
432 if(!mySimulationTopoDs.IsNull())
433 myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
438 //=================================================================================
439 // function : enterEvent()
441 //=================================================================================
442 void OperationGUI_FilletDlg::enterEvent(QEvent* e)
444 if(GroupConstructors->isEnabled())
446 this->ActivateThisDialog();
451 //=================================================================================
452 // function : closeEvent()
454 //=================================================================================
455 void OperationGUI_FilletDlg::closeEvent(QCloseEvent* e)
457 /* same than click on cancel button */
458 this->ClickOnCancel();
463 //=================================================================================
464 // function : ResetStateOfDialog()
466 //=================================================================================
467 void OperationGUI_FilletDlg::ResetStateOfDialog()
470 myEditCurrentArgument->setText("");
471 QApplication::restoreOverrideCursor();
473 /* Close its local contact if opened */
474 if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_OCC && myUseLocalContext) {
475 myIC->CloseLocalContext(myLocalContextId);
476 myUseLocalContext = false;
477 DisplayGUI* myDisplayGUI = new DisplayGUI();
478 myDisplayGUI->OnDisplayAll(true);
484 //=================================================================================
485 // function : ValueChangedInSpinBox()
487 //=================================================================================
488 void OperationGUI_FilletDlg::ValueChangedInSpinBox(double newValue)
490 myGeomBase->EraseSimulationShape();
491 mySimulationTopoDs.Nullify();
495 if(myConstructorId == 0)
501 //=================================================================================
502 // function : MakePreview()
504 //=================================================================================
505 void OperationGUI_FilletDlg::MakePreview()
507 QApplication::setOverrideCursor(Qt::waitCursor);
510 QApplication::restoreOverrideCursor();
514 GEOM::GEOM_Shape::ListOfSubShapeID_var ListOfID = new GEOM::GEOM_Shape::ListOfSubShapeID;
517 SALOMEDS::Study_var aStudy = QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument();
518 SALOMEDS::SObject_var theObj = aStudy->FindObjectIOR(myShapeIOR);
519 if(theObj->_is_nil()) {
520 QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_SHAPE_IN_STUDY"));
521 QApplication::restoreOverrideCursor();
526 if(myRadius <= Precision::Confusion()) {
527 QApplication::restoreOverrideCursor();
531 GEOM::GEOM_Shape_var aShape = myGeom->GetIORFromString(myShapeIOR);
532 GEOM::GEOM_Shape_var result = myGeom->MakeFillet(aShape, myRadius, myShapeType, ListOfID);
533 if(result->_is_nil()) {
534 QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_ABORT"));
535 QApplication::restoreOverrideCursor();
538 TopoDS_Shape S = myGeomGUI->GetShapeReader().GetShape(myGeom, result);
540 mySimulationTopoDs = S;
541 myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
543 catch(Standard_Failure) {
544 MESSAGE("Exception catched in MakePreview");
545 QApplication::restoreOverrideCursor();
548 QApplication::restoreOverrideCursor();