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_ChamferDlg.cxx
25 // Author : Damien COQUERET
30 #include "OperationGUI_ChamferDlg.h"
32 #include "DisplayGUI.h"
33 #include "QAD_MessageBox.h"
35 #include <TopoDS_Edge.hxx>
36 #include <TopoDS_Face.hxx>
37 #include <AIS_InteractiveContext.hxx>
38 #include <BRepFilletAPI_MakeChamfer.hxx>
39 #include <BRepTools.hxx>
40 #include <BRep_Tool.hxx>
42 #include <Precision.hxx>
44 #include <Standard_ErrorHandler.hxx>
45 #include <Standard_Failure.hxx>
47 //=================================================================================
48 // class : OperationGUI_ChamferDlg()
49 // purpose : Constructs a OperationGUI_ChamferDlg which is a child of 'parent', with the
50 // name 'name' and widget flags set to 'f'.
51 // The dialog will by default be modeless, unless you set 'modal' to
52 // TRUE to construct a modal dialog.
53 //=================================================================================
54 OperationGUI_ChamferDlg::OperationGUI_ChamferDlg(QWidget* parent, const char* name, OperationGUI* theOperationGUI, SALOME_Selection* Sel, Handle(AIS_InteractiveContext) ic, bool modal, WFlags fl)
55 :GEOMBase_Skeleton(parent, name, Sel, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
57 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_CHAMFER_ALL")));
58 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_CHAMFER_EDGE")));
59 QPixmap image2(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_CHAMFER_FACE")));
60 QPixmap image3(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_SELECT")));
62 setCaption(tr("GEOM_CHAMFER_TITLE"));
64 /***************************************************************/
65 GroupConstructors->setTitle(tr("GEOM_CHAMFER"));
66 RadioButton1->setPixmap(image0);
67 RadioButton2->setPixmap(image1);
68 RadioButton3->setPixmap(image2);
70 Group1 = new DlgRef_1Sel2Spin(this, "Group1");
71 Group1->GroupBox1->setTitle(tr("GEOM_CHAMFER_ALL"));
72 Group1->TextLabel1->setText(tr("GEOM_MAIN_OBJECT"));
73 Group1->TextLabel2->setText(tr("GEOM_D1"));
74 Group1->TextLabel3->setText(tr("GEOM_D2"));
75 Group1->PushButton1->setPixmap(image3);
77 Layout1->addWidget(Group1, 1, 0);
78 /***************************************************************/
81 myOperationGUI = theOperationGUI;
86 //=================================================================================
87 // function : ~OperationGUI_ChamferDlg()
88 // purpose : Destroys the object and frees any allocated resources
89 //=================================================================================
90 OperationGUI_ChamferDlg::~OperationGUI_ChamferDlg()
92 /* no need to delete child widgets, Qt does it all for us */
96 //=================================================================================
99 //=================================================================================
100 void OperationGUI_ChamferDlg::Init(Handle (AIS_InteractiveContext) ic)
104 myEditCurrentArgument = Group1->LineEdit1;
110 myLocalContextId = -1;
111 myUseLocalContext = false;
113 double SpecificStep = 10.0;
114 /* min, max, step and decimals for spin boxes */
115 Group1->SpinBox_DX->RangeStepAndValidator(0.001, 999.999, SpecificStep, 3);
116 Group1->SpinBox_DY->RangeStepAndValidator(0.001, 999.999, SpecificStep, 3);
118 Group1->SpinBox_DX->SetValue(myD1);
119 Group1->SpinBox_DY->SetValue(myD2);
121 /* signals and slots connections */
122 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
123 connect(myGeomGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
124 connect(myGeomGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
126 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
127 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
128 connect(GroupConstructors, SIGNAL(clicked(int)), this, SLOT(ConstructorsClicked(int)));
130 connect(Group1->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
131 connect(Group1->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
133 connect(Group1->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
134 connect(Group1->SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
135 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), Group1->SpinBox_DX, SLOT(SetStep(double)));
136 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), Group1->SpinBox_DY, SLOT(SetStep(double)));
138 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
140 /* displays Dialog */
148 //=================================================================================
149 // function : ConstructorsClicked()
150 // purpose : Radio button management
151 //=================================================================================
152 void OperationGUI_ChamferDlg::ConstructorsClicked(int constructorId)
154 myConstructorId = constructorId;
155 myGeomBase->EraseSimulationShape();
156 mySimulationTopoDs.Nullify();
157 disconnect(mySelection, 0, this, 0);
162 if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_OCC && myUseLocalContext) {
163 myIC->CloseLocalContext(myLocalContextId);
164 DisplayGUI* myDisplayGUI = new DisplayGUI();
165 myDisplayGUI->OnDisplayAll(true);
166 myUseLocalContext = false;
169 if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() != VIEW_OCC) {
170 myConstructorId = constructorId = 0; //No subshape selection if viewer is not OCC
171 RadioButton1->setChecked(TRUE);
174 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
175 Group1->LineEdit1->setText("");
176 Group1->SpinBox_DX->SetValue(myD1);
177 Group1->SpinBox_DY->SetValue(myD2);
178 switch (constructorId)
180 case 0: /* Chamfer All */
182 Group1->GroupBox1->setTitle(tr("GEOM_CHAMFER_ALL"));
186 case 1: /* Chamfer edges */
188 Group1->GroupBox1->setTitle(tr("GEOM_CHAMFER_EDGES"));
192 case 2: /* Chamfer Faces */
194 Group1->GroupBox1->setTitle(tr("GEOM_CHAMFER_FACES"));
203 //=================================================================================
204 // function : ClickOnOk()
206 //=================================================================================
207 void OperationGUI_ChamferDlg::ClickOnOk()
209 this->ClickOnApply();
210 this->ClickOnCancel();
215 //=================================================================================
216 // function : ClickOnApply()
218 //=================================================================================
219 void OperationGUI_ChamferDlg::ClickOnApply()
221 buttonApply->setFocus();
222 QApplication::setOverrideCursor(Qt::waitCursor);
223 QAD_Application::getDesktop()->putInfo(tr(""));
224 myGeomBase->EraseSimulationShape();
225 mySimulationTopoDs.Nullify();
227 bool testResult = false;
228 switch(myConstructorId)
230 case 0 : /* Chamfer All */
233 testResult = myOperationGUI->OnChamferGetAll(myShape, myD1, myD2, myShapeType, myShapeIOR);
236 case 1 : /* Chamfer Edge */
239 testResult = myOperationGUI->OnChamferGetSelected(myShape, myShapeIOR, myD1, myD2, myShapeType,
240 myLocalContextId, myUseLocalContext);
243 case 2 : /* Chamfer Face */
246 testResult = myOperationGUI->OnChamferGetSelected(myShape, myShapeIOR, myD1, myD2, myShapeType,
247 myLocalContextId, myUseLocalContext);
253 QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_ABORT"));
255 QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_DONE"));
256 /* Reset all arguments and local context to allow user a new selection ...*/
257 this->ResetStateOfDialog();
258 QApplication::restoreOverrideCursor();
263 //=================================================================================
264 // function : ClickOnCancel()
266 //=================================================================================
267 void OperationGUI_ChamferDlg::ClickOnCancel()
269 this->ResetStateOfDialog();
270 GEOMBase_Skeleton::ClickOnCancel();
275 //=================================================================================
276 // function : SelectionIntoArgument()
277 // purpose : Called when selection has changed
278 //=================================================================================
279 void OperationGUI_ChamferDlg::SelectionIntoArgument()
281 myGeomBase->EraseSimulationShape();
282 mySimulationTopoDs.Nullify();
283 myEditCurrentArgument->setText("");
284 this->ResetStateOfDialog();
285 QString aString = ""; /* name of selection */
287 int nbSel = myGeomBase->GetNameOfSelectedIObjects(mySelection, aString);
290 Handle(SALOME_InteractiveObject) IO = mySelection->firstIObject();
291 if(!myGeomBase->GetTopoFromSelection(mySelection, S))
293 if(!IO->hasEntry()) {
294 QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_SHAPE_IN_STUDY"));
298 if(!S.IsNull() && S.ShapeType() <= 2) {
299 if(IO->IsInstance(STANDARD_TYPE(GEOM_InteractiveObject))) {
300 Handle(GEOM_InteractiveObject) GIObject = Handle(GEOM_InteractiveObject)::DownCast(IO);
301 myShapeIOR = GIObject->getIOR(); /* the Geom IOR string of selection */
302 myEditCurrentArgument->setText(aString);
308 SALOMEDS::Study_var aStudy = QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument();
309 SALOMEDS::SObject_var obj = aStudy->FindObjectID(IO->getEntry());
310 SALOMEDS::GenericAttribute_var anAttr;
311 SALOMEDS::AttributeIOR_var anIOR;
312 if(!obj->_is_nil()) {
313 if(obj->FindAttribute(anAttr, "AttributeIOR")) {
314 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
315 myShapeIOR = anIOR->Value();
318 myEditCurrentArgument->setText(aString);
323 if(myOkShape && QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_OCC && myConstructorId == 0)
330 if(myOkShape && myShapeType!=-1 && myConstructorId != 0) {
331 /* local context is defined into the method */
332 DisplayGUI* myDisplayGUI = new DisplayGUI();
333 myDisplayGUI->PrepareSubShapeSelection(myShapeType, myLocalContextId);
334 myUseLocalContext = true;
339 //=================================================================================
340 // function : SetEditCurrentArgument()
342 //=================================================================================
343 void OperationGUI_ChamferDlg::SetEditCurrentArgument()
345 QPushButton* send = (QPushButton*)sender();
347 if(send == Group1->PushButton1)
348 Group1->LineEdit1->setFocus();
350 this->SelectionIntoArgument();
355 //=================================================================================
356 // function : DeactivateActiveDialog()
358 //=================================================================================
359 void OperationGUI_ChamferDlg::DeactivateActiveDialog()
361 this->ResetStateOfDialog();
362 GEOMBase_Skeleton::DeactivateActiveDialog();
367 //=================================================================================
368 // function : ActivateThisDialog()
370 //=================================================================================
371 void OperationGUI_ChamferDlg::ActivateThisDialog()
373 GEOMBase_Skeleton::ActivateThisDialog();
374 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
375 if(!mySimulationTopoDs.IsNull())
376 myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
381 //=================================================================================
382 // function : enterEvent()
384 //=================================================================================
385 void OperationGUI_ChamferDlg::enterEvent(QEvent* e)
387 if(GroupConstructors->isEnabled())
389 this->ActivateThisDialog();
394 //=================================================================================
395 // function : closeEvent()
397 //=================================================================================
398 void OperationGUI_ChamferDlg::closeEvent(QCloseEvent* e)
400 /* same than click on cancel button */
401 this->ClickOnCancel();
406 //=================================================================================
407 // function : ValueChangedInSpinBox()
409 //=================================================================================
410 void OperationGUI_ChamferDlg::ValueChangedInSpinBox(double newValue)
412 myGeomBase->EraseSimulationShape();
413 mySimulationTopoDs.Nullify();
415 QObject* send = (QObject*)sender();
416 if(send == Group1->SpinBox_DX) /* D1 */
418 else if(send == Group1->SpinBox_DY) /* D2 */
421 if(myOkShape && QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_OCC && myConstructorId == 0)
428 //=================================================================================
429 // function : ResetStateOfDialog()
431 //=================================================================================
432 void OperationGUI_ChamferDlg::ResetStateOfDialog()
435 myEditCurrentArgument->setText("");
436 QApplication::restoreOverrideCursor();
438 /* Close its local contact if opened */
439 if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_OCC && myUseLocalContext) {
440 myIC->CloseLocalContext(myLocalContextId);
441 myUseLocalContext = false;
442 DisplayGUI* myDisplayGUI = new DisplayGUI();
443 myDisplayGUI->OnDisplayAll(true);
449 //=================================================================================
450 // function : MakePreview()
452 //=================================================================================
453 void OperationGUI_ChamferDlg::MakePreview()
455 QApplication::setOverrideCursor(Qt::waitCursor);
459 BRepFilletAPI_MakeChamfer MC(myShape);
460 switch(myConstructorId)
462 case 0: /* Chamfer All */
464 TopTools_IndexedDataMapOfShapeListOfShape M;
465 TopExp::MapShapesAndAncestors(myShape, TopAbs_EDGE, TopAbs_FACE, M);
466 for(int i = 1; i <= M.Extent(); i++) {
467 TopoDS_Edge E = TopoDS::Edge(M.FindKey(i));
468 TopoDS_Face F = TopoDS::Face(M.FindFromIndex(i).First());
469 if(!BRepTools::IsReallyClosed(E, F) && !BRep_Tool::Degenerated(E))
470 MC.Add(myD1, myD2, E, F);
475 // case 1: /* Chamfer edges */
476 // case 2: /* Chamfer Faces */
480 mySimulationTopoDs = tds;
481 myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
484 catch(Standard_Failure) {
485 QApplication::restoreOverrideCursor();
486 QAD_MessageBox::warn1 (QAD_Application::getDesktop(), tr("GEOM_WRN_WARNING"), tr("GEOM_CHAMFER_ABORT").arg(myD1).arg(myD2), tr("GEOM_BUT_OK"));
487 QApplication::setOverrideCursor(Qt::waitCursor);
488 myGeomBase->EraseSimulationShape();
489 mySimulationTopoDs.Nullify();
490 Group1->SpinBox_DX->SetValue(5.0);
491 Group1->SpinBox_DY->SetValue(5.0);
494 QApplication::restoreOverrideCursor();