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 <TopoDS_Edge.hxx>
36 #include <AIS_InteractiveContext.hxx>
37 #include <TopExp_Explorer.hxx>
38 #include <BRepFilletAPI_MakeFillet.hxx>
39 #include <Precision.hxx>
41 #include <Standard_ErrorHandler.hxx>
42 #include <Standard_Failure.hxx>
44 //=================================================================================
45 // class : OperationGUI_FilletDlg()
46 // purpose : Constructs a OperationGUI_FilletDlg which is a child of 'parent', with the
47 // name 'name' and widget flags set to 'f'.
48 // The dialog will by default be modeless, unless you set 'modal' to
49 // TRUE to construct a modal dialog.
50 //=================================================================================
51 OperationGUI_FilletDlg::OperationGUI_FilletDlg(QWidget* parent, const char* name, OperationGUI* theOperationGUI, SALOME_Selection* Sel, Handle(AIS_InteractiveContext) ic, bool modal, WFlags fl)
52 :GEOMBase_Skeleton(parent, name, Sel, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
54 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_FILLET_ALL")));
55 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_FILLET_EDGE")));
56 QPixmap image2(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_FILLET_FACE")));
57 QPixmap image3(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_SELECT")));
59 setCaption(tr("GEOM_FILLET_TITLE"));
61 /***************************************************************/
62 GroupConstructors->setTitle(tr("GEOM_FILLET"));
63 RadioButton1->setPixmap(image0);
64 RadioButton2->setPixmap(image1);
65 RadioButton3->setPixmap(image2);
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(image3);
73 Layout1->addWidget(Group1, 1, 0);
74 /***************************************************************/
77 myOperationGUI = theOperationGUI;
82 //=================================================================================
83 // function : ~OperationGUI_FilletDlg()
84 // purpose : Destroys the object and frees any allocated resources
85 //=================================================================================
86 OperationGUI_FilletDlg::~OperationGUI_FilletDlg()
88 /* no need to delete child widgets, Qt does it all for us */
92 //=================================================================================
95 //=================================================================================
96 void OperationGUI_FilletDlg::Init(Handle(AIS_InteractiveContext) ic)
100 myEditCurrentArgument = Group1->LineEdit1;
105 myLocalContextId = -1;
106 myUseLocalContext = false;
108 double SpecificStep = 10.0;
109 /* min, max, step and decimals for spin boxes */
110 Group1->SpinBox_DX->RangeStepAndValidator(0.001, 999.999, SpecificStep, 3);
111 Group1->SpinBox_DX->SetValue(myRadius);
113 /* signals and slots connections */
114 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
115 connect(myGeomGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
116 connect(myGeomGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
118 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
119 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
120 connect(GroupConstructors, SIGNAL(clicked(int)), this, SLOT(ConstructorsClicked(int)));
122 connect(Group1->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
123 connect(Group1->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
125 connect(Group1->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
126 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), Group1->SpinBox_DX, SLOT(SetStep(double)));
128 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
130 /* displays Dialog */
138 //=================================================================================
139 // function : ConstructorsClicked()
140 // purpose : Radio button management
141 //=================================================================================
142 void OperationGUI_FilletDlg::ConstructorsClicked(int constructorId)
144 myConstructorId = constructorId;
145 myGeomBase->EraseSimulationShape();
146 mySimulationTopoDs.Nullify();
147 disconnect(mySelection, 0, this, 0);
151 if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_OCC && myUseLocalContext) {
152 myIC->CloseLocalContext(myLocalContextId);
153 DisplayGUI* myDisplayGUI = new DisplayGUI();
154 myDisplayGUI->OnDisplayAll(true);
155 myUseLocalContext = false;
158 if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() != VIEW_OCC) {
159 myConstructorId = constructorId = 0; //No subshape selection if viewer is not OCC
160 RadioButton1->setChecked(TRUE);
163 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
164 Group1->LineEdit1->setText("");
165 Group1->SpinBox_DX->SetValue(myRadius);
166 switch (constructorId)
168 case 0: /* Fillet All */
170 Group1->GroupBox1->setTitle(tr("GEOM_FILLET_ALL"));
174 case 1: /* Fillet edges */
176 Group1->GroupBox1->setTitle(tr("GEOM_FILLET_EDGES"));
180 case 2: /* Fillet Faces */
182 Group1->GroupBox1->setTitle(tr("GEOM_FILLET_FACES"));
191 //=================================================================================
192 // function : ClickOnOk()
194 //=================================================================================
195 void OperationGUI_FilletDlg::ClickOnOk()
197 this->ClickOnApply();
198 this->ClickOnCancel();
203 //=================================================================================
204 // function : ClickOnApply()
206 //=================================================================================
207 void OperationGUI_FilletDlg::ClickOnApply()
209 buttonApply->setFocus();
210 QApplication::setOverrideCursor(Qt::waitCursor);
211 QAD_Application::getDesktop()->putInfo(tr(""));
212 myGeomBase->EraseSimulationShape();
213 mySimulationTopoDs.Nullify();
215 bool testResult = false;
216 switch(myConstructorId)
218 case 0 : /* Fillet All */
221 testResult = myOperationGUI->OnFilletGetAll(myShape, myRadius, myShapeType, myShapeIOR);
224 case 1 : /* Fillet Edge */
227 testResult = myOperationGUI->OnFilletGetSelected(myShape, myShapeIOR, myRadius, myShapeType, myLocalContextId, myUseLocalContext);
230 case 2 : /* Fillet Face */
233 testResult = myOperationGUI->OnFilletGetSelected(myShape, myShapeIOR, myRadius, myShapeType, myLocalContextId, myUseLocalContext);
239 QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_ABORT"));
241 QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_DONE"));
242 /* Reset all arguments and local context to allow user a new selection ...*/
243 this->ResetStateOfDialog();
244 QApplication::restoreOverrideCursor();
249 //=================================================================================
250 // function : ClickOnCancel()
252 //=================================================================================
253 void OperationGUI_FilletDlg::ClickOnCancel()
255 this->ResetStateOfDialog();
256 GEOMBase_Skeleton::ClickOnCancel();
261 //=================================================================================
262 // function : SelectionIntoArgument()
263 // purpose : Called when selection has changed
264 //=================================================================================
265 void OperationGUI_FilletDlg::SelectionIntoArgument()
267 myGeomBase->EraseSimulationShape();
268 mySimulationTopoDs.Nullify();
269 myEditCurrentArgument->setText("");
270 this->ResetStateOfDialog();
271 QString aString = ""; /* name of selection */
273 int nbSel = myGeomBase->GetNameOfSelectedIObjects(mySelection, aString);
276 Handle(SALOME_InteractiveObject) IO = mySelection->firstIObject();
277 if(!myGeomBase->GetTopoFromSelection(mySelection, S))
279 if(!IO->hasEntry()) {
280 QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_SHAPE_IN_STUDY"));
284 if(!S.IsNull() && S.ShapeType() <= 2) {
285 if(IO->IsInstance(STANDARD_TYPE(GEOM_InteractiveObject))) {
286 Handle(GEOM_InteractiveObject) GIObject = Handle(GEOM_InteractiveObject)::DownCast(IO);
287 myShapeIOR = GIObject->getIOR(); /* the Geom IOR string of selection */
288 myEditCurrentArgument->setText(aString);
294 SALOMEDS::Study_var aStudy = QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument();
295 SALOMEDS::SObject_var obj = aStudy->FindObjectID(IO->getEntry());
296 SALOMEDS::GenericAttribute_var anAttr;
297 SALOMEDS::AttributeIOR_var anIOR;
298 if(!obj->_is_nil()) {
299 if(obj->FindAttribute(anAttr, "AttributeIOR")) {
300 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
301 myShapeIOR = anIOR->Value();
304 myEditCurrentArgument->setText(aString);
309 if(myOkShape && QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_OCC && myConstructorId == 0)
315 if(myOkShape && myShapeType!=-1 && myConstructorId != 0) {
316 /* local context is defined into the method */
317 DisplayGUI* myDisplayGUI = new DisplayGUI();
318 myDisplayGUI->PrepareSubShapeSelection(myShapeType, myLocalContextId);
319 myUseLocalContext = true;
324 //=================================================================================
325 // function : SetEditCurrentArgument()
327 //=================================================================================
328 void OperationGUI_FilletDlg::SetEditCurrentArgument()
330 QPushButton* send = (QPushButton*)sender();
332 if(send == Group1->PushButton1)
333 Group1->LineEdit1->setFocus();
335 this->SelectionIntoArgument();
340 //=================================================================================
341 // function : DeactivateActiveDialog()
343 //=================================================================================
344 void OperationGUI_FilletDlg::DeactivateActiveDialog()
346 this->ResetStateOfDialog();
347 GEOMBase_Skeleton::DeactivateActiveDialog();
352 //=================================================================================
353 // function : ActivateThisDialog()
355 //=================================================================================
356 void OperationGUI_FilletDlg::ActivateThisDialog()
358 GEOMBase_Skeleton::ActivateThisDialog();
359 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
360 if(!mySimulationTopoDs.IsNull())
361 myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
366 //=================================================================================
367 // function : enterEvent()
369 //=================================================================================
370 void OperationGUI_FilletDlg::enterEvent(QEvent* e)
372 if(GroupConstructors->isEnabled())
374 this->ActivateThisDialog();
379 //=================================================================================
380 // function : closeEvent()
382 //=================================================================================
383 void OperationGUI_FilletDlg::closeEvent(QCloseEvent* e)
385 /* same than click on cancel button */
386 this->ClickOnCancel();
391 //=================================================================================
392 // function : ResetStateOfDialog()
394 //=================================================================================
395 void OperationGUI_FilletDlg::ResetStateOfDialog()
398 myEditCurrentArgument->setText("");
399 QApplication::restoreOverrideCursor();
401 /* Close its local contact if opened */
402 if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_OCC && myUseLocalContext) {
403 myIC->CloseLocalContext(myLocalContextId);
404 myUseLocalContext = false;
405 DisplayGUI* myDisplayGUI = new DisplayGUI();
406 myDisplayGUI->OnDisplayAll(true);
412 //=================================================================================
413 // function : ValueChangedInSpinBox()
415 //=================================================================================
416 void OperationGUI_FilletDlg::ValueChangedInSpinBox(double newValue)
418 myGeomBase->EraseSimulationShape();
419 mySimulationTopoDs.Nullify();
423 if(myOkShape && QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_OCC && myConstructorId == 0)
429 //=================================================================================
430 // function : MakePreview()
432 //=================================================================================
433 void OperationGUI_FilletDlg::MakePreview()
435 QApplication::setOverrideCursor(Qt::waitCursor);
439 BRepFilletAPI_MakeFillet fill(myShape);
440 switch(myConstructorId)
442 case 0: /* Fillet All */
444 TopExp_Explorer Exp(myShape, TopAbs_EDGE);
445 for(Exp; Exp.More(); Exp.Next()) {
446 TopoDS_Edge E = TopoDS::Edge(Exp.Current());
450 for(int i = 1; i <= fill.NbContours(); i++) {
452 fill.SetRadius(myRadius,i,i);
454 catch(Standard_Failure) {
455 QApplication::restoreOverrideCursor();
456 QAD_MessageBox::warn1 (QAD_Application::getDesktop(), tr("GEOM_WRN_WARNING"), tr("GEOM_FILLET_ABORT").arg(myRadius), tr("GEOM_BUT_OK"));
457 QApplication::setOverrideCursor(Qt::waitCursor);
458 myGeomBase->EraseSimulationShape();
459 mySimulationTopoDs.Nullify();
460 Group1->SpinBox_DX->SetValue(5.0);
461 QApplication::restoreOverrideCursor();
468 // case 1: /* Fillet edges */
469 // case 2: /* Fillet Faces */
473 mySimulationTopoDs = tds;
474 myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
477 catch(Standard_Failure) {
478 QApplication::restoreOverrideCursor();
479 QAD_MessageBox::warn1 (QAD_Application::getDesktop(), tr("GEOM_WRN_WARNING"), tr("GEOM_FILLET_ABORT").arg(myRadius), tr("GEOM_BUT_OK"));
480 QApplication::setOverrideCursor(Qt::waitCursor);
481 myGeomBase->EraseSimulationShape();
482 mySimulationTopoDs.Nullify();
483 Group1->SpinBox_DX->SetValue(5.0);
486 QApplication::restoreOverrideCursor();