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 <AIS_InteractiveContext.hxx>
36 #include <BRepFilletAPI_MakeChamfer.hxx>
37 #include <BRepTools.hxx>
38 #include <BRep_Tool.hxx>
40 #include <Precision.hxx>
42 #include <Standard_ErrorHandler.hxx>
43 #include <Standard_Failure.hxx>
45 //=================================================================================
46 // class : OperationGUI_ChamferDlg()
47 // purpose : Constructs a OperationGUI_ChamferDlg which is a child of 'parent', with the
48 // name 'name' and widget flags set to 'f'.
49 // The dialog will by default be modeless, unless you set 'modal' to
50 // TRUE to construct a modal dialog.
51 //=================================================================================
52 OperationGUI_ChamferDlg::OperationGUI_ChamferDlg(QWidget* parent, const char* name, OperationGUI* theOperationGUI, SALOME_Selection* Sel, Handle(AIS_InteractiveContext) ic, bool modal, WFlags fl)
53 :GEOMBase_Skeleton(parent, name, Sel, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
55 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_CHAMFER_ALL")));
56 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_CHAMFER_EDGE")));
57 QPixmap image2(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_CHAMFER_FACE")));
58 QPixmap image3(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_SELECT")));
60 setCaption(tr("GEOM_CHAMFER_TITLE"));
62 /***************************************************************/
63 GroupConstructors->setTitle(tr("GEOM_CHAMFER"));
64 RadioButton1->setPixmap(image0);
65 RadioButton2->setPixmap(image1);
66 RadioButton3->setPixmap(image2);
68 Group1 = new DlgRef_1Sel2Spin(this, "Group1");
69 Group1->GroupBox1->setTitle(tr("GEOM_CHAMFER_ALL"));
70 Group1->TextLabel1->setText(tr("GEOM_MAIN_OBJECT"));
71 Group1->TextLabel2->setText(tr("GEOM_D1"));
72 Group1->TextLabel3->setText(tr("GEOM_D2"));
73 Group1->PushButton1->setPixmap(image3);
75 Group2 = new DlgRef_1Sel2Spin(this, "Group2");
76 Group2->GroupBox1->setTitle(tr("GEOM_CHAMFER_EDGES"));
77 Group2->TextLabel1->setText(tr("GEOM_MAIN_OBJECT"));
78 Group2->TextLabel2->setText(tr("GEOM_D1"));
79 Group2->TextLabel3->setText(tr("GEOM_D2"));
80 Group2->PushButton1->setPixmap(image3);
82 Group3 = new DlgRef_1Sel2Spin(this, "Group3");
83 Group3->GroupBox1->setTitle(tr("GEOM_CHAMFER_FACES"));
84 Group3->TextLabel1->setText(tr("GEOM_MAIN_OBJECT"));
85 Group3->TextLabel2->setText(tr("GEOM_D1"));
86 Group3->TextLabel3->setText(tr("GEOM_D2"));
87 Group3->PushButton1->setPixmap(image3);
89 Layout1->addWidget(Group1, 1, 0);
90 Layout1->addWidget(Group2, 1, 0);
91 Layout1->addWidget(Group3, 1, 0);
92 /***************************************************************/
95 myOperationGUI = theOperationGUI;
100 //=================================================================================
101 // function : ~OperationGUI_ChamferDlg()
102 // purpose : Destroys the object and frees any allocated resources
103 //=================================================================================
104 OperationGUI_ChamferDlg::~OperationGUI_ChamferDlg()
106 /* no need to delete child widgets, Qt does it all for us */
110 //=================================================================================
113 //=================================================================================
114 void OperationGUI_ChamferDlg::Init(Handle (AIS_InteractiveContext) ic)
118 myEditCurrentArgument = Group1->LineEdit1;
124 myLocalContextId = -1;
125 myUseLocalContext = false;
127 double SpecificStep = 10.0;
128 /* min, max, step and decimals for spin boxes */
129 Group1->SpinBox_DX->RangeStepAndValidator(0.001, 999.999, SpecificStep, 3);
130 Group2->SpinBox_DX->RangeStepAndValidator(0.001, 999.999, SpecificStep, 3);
131 Group3->SpinBox_DX->RangeStepAndValidator(0.001, 999.999, SpecificStep, 3);
132 Group1->SpinBox_DY->RangeStepAndValidator(0.001, 999.999, SpecificStep, 3);
133 Group2->SpinBox_DY->RangeStepAndValidator(0.001, 999.999, SpecificStep, 3);
134 Group3->SpinBox_DY->RangeStepAndValidator(0.001, 999.999, SpecificStep, 3);
136 Group1->SpinBox_DX->SetValue(myD1);
137 Group2->SpinBox_DX->SetValue(myD1);
138 Group3->SpinBox_DX->SetValue(myD1);
139 Group1->SpinBox_DY->SetValue(myD2);
140 Group2->SpinBox_DY->SetValue(myD2);
141 Group3->SpinBox_DY->SetValue(myD2);
143 /* signals and slots connections */
144 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
145 connect(myGeomGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
146 connect(myGeomGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
148 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
149 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
150 connect(GroupConstructors, SIGNAL(clicked(int)), this, SLOT(ConstructorsClicked(int)));
152 connect(Group1->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
153 connect(Group2->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
154 connect(Group3->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
156 connect(Group1->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
157 connect(Group2->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
158 connect(Group3->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
160 connect(Group1->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
161 connect(Group2->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
162 connect(Group3->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
163 connect(Group1->SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
164 connect(Group2->SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
165 connect(Group3->SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
167 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), Group1->SpinBox_DX, SLOT(SetStep(double)));
168 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), Group2->SpinBox_DX, SLOT(SetStep(double)));
169 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), Group3->SpinBox_DX, SLOT(SetStep(double)));
170 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), Group1->SpinBox_DY, SLOT(SetStep(double)));
171 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), Group2->SpinBox_DY, SLOT(SetStep(double)));
172 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), Group3->SpinBox_DY, SLOT(SetStep(double)));
174 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
176 /* displays Dialog */
186 //=================================================================================
187 // function : ConstructorsClicked()
188 // purpose : Radio button management
189 //=================================================================================
190 void OperationGUI_ChamferDlg::ConstructorsClicked(int constructorId)
192 myConstructorId = constructorId;
193 myGeomBase->EraseSimulationShape();
194 mySimulationTopoDs.Nullify();
195 disconnect(mySelection, 0, this, 0);
200 if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_OCC && myUseLocalContext) {
201 myIC->CloseLocalContext(myLocalContextId);
202 DisplayGUI* myDisplayGUI = new DisplayGUI();
203 myDisplayGUI->OnDisplayAll(true);
204 myUseLocalContext = false;
207 if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() != VIEW_OCC) {
208 myConstructorId = constructorId = 0; //No subshape selection if viewer is not OCC
209 RadioButton1->setChecked(TRUE);
212 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
213 switch (constructorId)
215 case 0: /* Chamfer All */
222 myEditCurrentArgument = Group1->LineEdit1;
223 Group1->LineEdit1->setText("");
226 Group1->SpinBox_DX->SetValue(myD1);
227 Group1->SpinBox_DY->SetValue(myD2);
230 case 1: /* Chamfer edges */
237 myEditCurrentArgument = Group2->LineEdit1;
238 Group2->LineEdit1->setText("");
241 Group2->SpinBox_DX->SetValue(myD1);
242 Group2->SpinBox_DY->SetValue(myD2);
245 case 2: /* Chamfer Faces */
252 myEditCurrentArgument = Group3->LineEdit1;
253 Group3->LineEdit1->setText("");
256 Group3->SpinBox_DX->SetValue(myD1);
257 Group3->SpinBox_DY->SetValue(myD2);
265 //=================================================================================
266 // function : ClickOnOk()
268 //=================================================================================
269 void OperationGUI_ChamferDlg::ClickOnOk()
271 this->ClickOnApply();
272 this->ClickOnCancel();
277 //=================================================================================
278 // function : ClickOnApply()
280 //=================================================================================
281 void OperationGUI_ChamferDlg::ClickOnApply()
283 buttonApply->setFocus();
284 QApplication::setOverrideCursor(Qt::waitCursor);
285 QAD_Application::getDesktop()->putInfo(tr(""));
286 myGeomBase->EraseSimulationShape();
287 mySimulationTopoDs.Nullify();
289 bool testResult = false;
290 switch(myConstructorId)
292 case 0 : /* Chamfer All */
295 testResult = myOperationGUI->OnChamferGetAll(myShape, myD1, myD2, myShapeType, myShapeIOR);
298 case 1 : /* Chamfer Edge */
301 testResult = myOperationGUI->OnChamferGetSelected(myShape, myShapeIOR, myD1, myD2, myShapeType,
302 myLocalContextId, myUseLocalContext);
305 case 2 : /* Chamfer Face */
308 testResult = myOperationGUI->OnChamferGetSelected(myShape, myShapeIOR, myD1, myD2, myShapeType,
309 myLocalContextId, myUseLocalContext);
315 QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_ABORT"));
317 QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_DONE"));
318 /* Reset all arguments and local context to allow user a new selection ...*/
319 this->ResetStateOfDialog();
320 QApplication::restoreOverrideCursor();
325 //=================================================================================
326 // function : ClickOnCancel()
328 //=================================================================================
329 void OperationGUI_ChamferDlg::ClickOnCancel()
331 this->ResetStateOfDialog();
332 GEOMBase_Skeleton::ClickOnCancel();
337 //=================================================================================
338 // function : SelectionIntoArgument()
339 // purpose : Called when selection has changed
340 //=================================================================================
341 void OperationGUI_ChamferDlg::SelectionIntoArgument()
343 myGeomBase->EraseSimulationShape();
344 mySimulationTopoDs.Nullify();
345 myEditCurrentArgument->setText("");
346 this->ResetStateOfDialog();
347 QString aString = ""; /* name of selection */
349 int nbSel = myGeomBase->GetNameOfSelectedIObjects(mySelection, aString);
352 Handle(SALOME_InteractiveObject) IO = mySelection->firstIObject();
353 if(!myGeomBase->GetTopoFromSelection(mySelection, S))
355 if(!IO->hasEntry()) {
356 QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_SHAPE_IN_STUDY"));
360 if(!S.IsNull() && S.ShapeType() <= 2) {
361 if(IO->IsInstance(STANDARD_TYPE(GEOM_InteractiveObject))) {
362 Handle(GEOM_InteractiveObject) GIObject = Handle(GEOM_InteractiveObject)::DownCast(IO);
363 myShapeIOR = GIObject->getIOR(); /* the Geom IOR string of selection */
364 myEditCurrentArgument->setText(aString);
370 SALOMEDS::Study_var aStudy = QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument();
371 SALOMEDS::SObject_var obj = aStudy->FindObjectID(IO->getEntry());
372 SALOMEDS::GenericAttribute_var anAttr;
373 SALOMEDS::AttributeIOR_var anIOR;
374 if(!obj->_is_nil()) {
375 if(obj->FindAttribute(anAttr, "AttributeIOR")) {
376 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
377 myShapeIOR = anIOR->Value();
380 myEditCurrentArgument->setText(aString);
385 if(myConstructorId == 0)
392 if(myOkShape && myShapeType!=-1 && myConstructorId != 0) {
393 /* local context is defined into the method */
394 DisplayGUI* myDisplayGUI = new DisplayGUI();
395 myDisplayGUI->PrepareSubShapeSelection(myShapeType, myLocalContextId);
396 myUseLocalContext = true;
401 //=================================================================================
402 // function : LineEditReturnPressed()
404 //=================================================================================
405 void OperationGUI_ChamferDlg::LineEditReturnPressed()
407 QLineEdit* send = (QLineEdit*)sender();
408 if(send == Group1->LineEdit1)
409 myEditCurrentArgument = Group1->LineEdit1;
410 else if (send == Group2->LineEdit1)
411 myEditCurrentArgument = Group2->LineEdit1;
412 else if (send == Group3->LineEdit1)
413 myEditCurrentArgument = Group3->LineEdit1;
417 GEOMBase_Skeleton::LineEditReturnPressed();
422 //=================================================================================
423 // function : SetEditCurrentArgument()
425 //=================================================================================
426 void OperationGUI_ChamferDlg::SetEditCurrentArgument()
428 QPushButton* send = (QPushButton*)sender();
430 if(send == Group1->PushButton1) {
431 Group1->LineEdit1->setFocus();
432 myEditCurrentArgument = Group1->LineEdit1;
434 else if(send == Group2->PushButton1) {
435 Group2->LineEdit1->setFocus();
436 myEditCurrentArgument = Group2->LineEdit1;
438 else if(send == Group3->PushButton1) {
439 Group3->LineEdit1->setFocus();
440 myEditCurrentArgument = Group3->LineEdit1;
442 this->SelectionIntoArgument();
447 //=================================================================================
448 // function : DeactivateActiveDialog()
450 //=================================================================================
451 void OperationGUI_ChamferDlg::DeactivateActiveDialog()
453 this->ResetStateOfDialog();
454 GEOMBase_Skeleton::DeactivateActiveDialog();
459 //=================================================================================
460 // function : ActivateThisDialog()
462 //=================================================================================
463 void OperationGUI_ChamferDlg::ActivateThisDialog()
465 GEOMBase_Skeleton::ActivateThisDialog();
466 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
467 if(!mySimulationTopoDs.IsNull())
468 myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
473 //=================================================================================
474 // function : enterEvent()
476 //=================================================================================
477 void OperationGUI_ChamferDlg::enterEvent(QEvent* e)
479 if(GroupConstructors->isEnabled())
481 this->ActivateThisDialog();
486 //=================================================================================
487 // function : closeEvent()
489 //=================================================================================
490 void OperationGUI_ChamferDlg::closeEvent(QCloseEvent* e)
492 /* same than click on cancel button */
493 this->ClickOnCancel();
498 //=================================================================================
499 // function : ValueChangedInSpinBox()
501 //=================================================================================
502 void OperationGUI_ChamferDlg::ValueChangedInSpinBox( double newValue )
504 myGeomBase->EraseSimulationShape();
505 mySimulationTopoDs.Nullify();
507 QObject* send = (QObject*)sender();
508 if(send == Group1->SpinBox_DX || send == Group2->SpinBox_DX || send == Group3->SpinBox_DX) { /* D1 */
510 if(myConstructorId == 0)
514 else if(send == Group1->SpinBox_DY || send == Group2->SpinBox_DY || send == Group3->SpinBox_DY) { /* D2 */
516 if(myConstructorId == 0)
524 //=================================================================================
525 // function : ResetStateOfDialog()
527 //=================================================================================
528 void OperationGUI_ChamferDlg::ResetStateOfDialog()
531 myEditCurrentArgument->setText("");
532 QApplication::restoreOverrideCursor();
534 /* Close its local contact if opened */
535 if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_OCC && myUseLocalContext) {
536 myIC->CloseLocalContext(myLocalContextId);
537 myUseLocalContext = false;
538 DisplayGUI* myDisplayGUI = new DisplayGUI();
539 myDisplayGUI->OnDisplayAll(true);
545 //=================================================================================
546 // function : MakePreview()
548 //=================================================================================
549 void OperationGUI_ChamferDlg::MakePreview()
551 QApplication::setOverrideCursor( Qt::waitCursor );
555 BRepFilletAPI_MakeChamfer MC(myShape);
556 switch (myConstructorId)
558 case 0: /* Chamfer All */
560 TopTools_IndexedDataMapOfShapeListOfShape M;
561 TopExp::MapShapesAndAncestors(myShape,TopAbs_EDGE,TopAbs_FACE,M);
562 for (int i = 1;i<=M.Extent();i++)
564 TopoDS_Edge E = TopoDS::Edge(M.FindKey(i));
565 TopoDS_Face F = TopoDS::Face(M.FindFromIndex(i).First());
566 if (!BRepTools::IsReallyClosed(E, F) && !BRep_Tool::Degenerated(E))
567 MC.Add(myD1, myD2,E,F);
572 // case 1: /* Chamfer edges */
573 // case 2: /* Chamfer Faces */
577 mySimulationTopoDs = tds;
578 myGeomBase->DisplaySimulationShape( mySimulationTopoDs ) ;
582 catch(Standard_Failure)
584 QAD_MessageBox::warn1 (QAD_Application::getDesktop(), tr("GEOM_WRN_WARNING"), tr("GEOM_CHAMFER_ABORT").arg(myD1).arg(myD2), tr("GEOM_BUT_OK"));
585 Group1->SpinBox_DX->SetValue(5.0);
586 Group1->SpinBox_DY->SetValue(5.0);
587 myGeomBase->EraseSimulationShape() ;
588 mySimulationTopoDs.Nullify() ;
589 QApplication::restoreOverrideCursor();
591 QApplication::restoreOverrideCursor();