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 : PrimitiveGUI_ConeDlg.cxx
25 // Author : Lucien PIGNOLONI
29 #include "PrimitiveGUI_ConeDlg.h"
32 #include <BRepPrimAPI_MakeCone.hxx>
33 #include <BRepPrimAPI_MakeCylinder.hxx>
34 #include <BRepAdaptor_Curve.hxx>
35 #include <Precision.hxx>
36 #include "QAD_Config.h"
38 #include "utilities.h"
42 //=================================================================================
43 // class : PrimitiveGUI_ConeDlg()
44 // purpose : Constructs a PrimitiveGUI_ConeDlg which is a child of 'parent', with the
45 // name 'name' and widget flags set to 'f'.
46 // The dialog will by default be modeless, unless you set 'modal' to
47 // TRUE to construct a modal dialog.
48 //=================================================================================
49 PrimitiveGUI_ConeDlg::PrimitiveGUI_ConeDlg(QWidget* parent, const char* name, PrimitiveGUI* thePrimitiveGUI, SALOME_Selection* Sel, bool modal, WFlags fl)
50 :GEOMBase_Skeleton(parent, name, Sel, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
52 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_CONE_PV")));
53 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_CONE_DXYZ")));
54 QPixmap image2(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_SELECT")));
56 setCaption(tr("GEOM_CONE_TITLE"));
58 /***************************************************************/
59 GroupConstructors->setTitle(tr("GEOM_CONE"));
60 RadioButton1->setPixmap(image0);
61 RadioButton2->setPixmap(image1);
62 RadioButton3->close(TRUE);
64 GroupPoints = new DlgRef_2Sel3Spin(this, "GroupPoints");
65 GroupPoints->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
66 GroupPoints->TextLabel1->setText(tr("GEOM_BASE_POINT"));
67 GroupPoints->TextLabel2->setText(tr("GEOM_VECTOR"));
68 GroupPoints->TextLabel3->setText(tr("GEOM_RADIUS_I").arg("1"));
69 GroupPoints->TextLabel4->setText(tr("GEOM_RADIUS_I").arg("2"));
70 GroupPoints->TextLabel5->setText(tr("GEOM_HEIGHT"));
71 GroupPoints->PushButton1->setPixmap(image2);
72 GroupPoints->PushButton2->setPixmap(image2);
74 GroupDimensions = new DlgRef_3Spin(this, "GroupDimensions");
75 GroupDimensions->GroupBox1->setTitle(tr("GEOM_BOX_OBJ"));
76 GroupDimensions->TextLabel1->setText(tr("GEOM_RADIUS_I").arg("1"));
77 GroupDimensions->TextLabel2->setText(tr("GEOM_RADIUS_I").arg("2"));
78 GroupDimensions->TextLabel3->setText(tr("GEOM_HEIGHT"));
80 Layout1->addWidget(GroupPoints, 1, 0);
81 Layout1->addWidget(GroupDimensions, 1, 0);
82 /***************************************************************/
85 myPrimitiveGUI = thePrimitiveGUI;
90 //=================================================================================
91 // function : ~PrimitiveGUI_ConeDlg()
92 // purpose : Destroys the object and frees any allocated resources
93 //=================================================================================
94 PrimitiveGUI_ConeDlg::~PrimitiveGUI_ConeDlg()
96 // no need to delete child widgets, Qt does it all for us
100 //=================================================================================
103 //=================================================================================
104 void PrimitiveGUI_ConeDlg::Init()
108 myEditCurrentArgument = GroupPoints->LineEdit1;
114 myOkRadius1 = myOkRadius2 = myOkHeight = true;
115 myOkPoint1 = myOkDir = false;
117 myEdgeFilter = new GEOM_EdgeFilter(StdSelect_Line, myGeom);
118 myVertexFilter = new GEOM_ShapeTypeFilter(TopAbs_VERTEX, myGeom);
119 mySelection->AddFilter(myVertexFilter);
121 /* Get setting of step value from file configuration */
122 QString St = QAD_CONFIG->getSetting("Geometry:SettingsGeomStep");
123 step = St.toDouble();
125 /* min, max, step and decimals for spin boxes & initial values */
126 GroupPoints->SpinBox_DX->RangeStepAndValidator(0.000, 999.999, step, 3);
127 GroupPoints->SpinBox_DY->RangeStepAndValidator(0.000, 999.999, step, 3);
128 GroupPoints->SpinBox_DZ->RangeStepAndValidator(-999.999, 999.999, step, 3);
129 GroupDimensions->SpinBox_DX->RangeStepAndValidator(0.000, 999.999, step, 3);
130 GroupDimensions->SpinBox_DY->RangeStepAndValidator(0.000, 999.999, step, 3);
131 GroupDimensions->SpinBox_DZ->RangeStepAndValidator(-999.999, 999.999, step, 3);
133 GroupPoints->SpinBox_DX->SetValue(myRadius1);
134 GroupPoints->SpinBox_DY->SetValue(myRadius2);
135 GroupPoints->SpinBox_DZ->SetValue(myHeight);
136 GroupDimensions->SpinBox_DX->SetValue(myRadius1);
137 GroupDimensions->SpinBox_DY->SetValue(myRadius2);
138 GroupDimensions->SpinBox_DZ->SetValue(myHeight);
140 /* signals and slots connections */
141 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
142 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
143 connect(GroupConstructors, SIGNAL(clicked(int)), this, SLOT(ConstructorsClicked(int)));
145 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
146 connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
148 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
149 connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
151 connect(GroupPoints->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
152 connect(GroupPoints->SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
153 connect(GroupPoints->SpinBox_DZ, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
154 connect(GroupDimensions->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
155 connect(GroupDimensions->SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
156 connect(GroupDimensions->SpinBox_DZ, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
158 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_DX, SLOT(SetStep(double)));
159 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_DY, SLOT(SetStep(double)));
160 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_DZ, SLOT(SetStep(double)));
161 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DX, SLOT(SetStep(double)));
162 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DY, SLOT(SetStep(double)));
163 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DZ, SLOT(SetStep(double)));
165 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
167 /* displays Dialog */
168 GroupDimensions->hide();
176 //=================================================================================
177 // function : ConstructorsClicked()
178 // purpose : Radio button management
179 //=================================================================================
180 void PrimitiveGUI_ConeDlg::ConstructorsClicked(int constructorId)
182 myConstructorId = constructorId;
183 mySelection->ClearFilters();
184 myGeomBase->EraseSimulationShape();
185 disconnect(mySelection, 0, this, 0);
186 myOkHeight = myOkRadius1 = myOkRadius2 = true;
191 switch(myConstructorId)
195 GroupDimensions->hide();
198 myOkPoint1 = myOkDir = false;
200 myEditCurrentArgument = GroupPoints->LineEdit1;
201 GroupPoints->LineEdit1->setText(tr(""));
202 GroupPoints->LineEdit2->setText(tr(""));
204 GroupPoints->SpinBox_DX->SetValue(myRadius1);
205 GroupPoints->SpinBox_DY->SetValue(myRadius2);
206 GroupPoints->SpinBox_DZ->SetValue(myHeight);
208 /* filter for next selection */
209 mySelection->AddFilter(myVertexFilter);
210 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
217 GroupDimensions->show();
218 myOkPoint1 = myOkDir = true;
220 GroupDimensions->SpinBox_DX->SetValue(myRadius1);
221 GroupDimensions->SpinBox_DY->SetValue(myRadius2);
222 GroupDimensions->SpinBox_DZ->SetValue(myHeight);
224 myPoint1.SetCoord(0.0, 0.0, 0.0);
225 myDir.SetCoord(0.0, 0.0, 1.0);
227 MakeConeSimulationAndDisplay();
235 //=================================================================================
236 // function : ClickOnOk()
238 //=================================================================================
239 void PrimitiveGUI_ConeDlg::ClickOnOk()
241 this->ClickOnApply();
247 //=================================================================================
248 // function : ClickOnApply()
250 //=================================================================================
251 void PrimitiveGUI_ConeDlg::ClickOnApply()
253 buttonApply->setFocus();
254 QAD_Application::getDesktop()->putInfo(tr(""));
255 if (mySimulationTopoDs.IsNull())
257 myGeomBase->EraseSimulationShape();
258 mySimulationTopoDs.Nullify();
260 if(myOkPoint1 && myOkDir && myOkRadius1 && myOkRadius2 && myOkHeight) {
262 /* allows user to reverse direction of construction with a negative height */
263 if(this->myHeight < -Precision::Confusion())
265 myPrimitiveGUI->MakeConeAndDisplay(myPoint1, aDir, myRadius1, myRadius2, fabs(myHeight));
271 //=================================================================================
272 // function : SelectionIntoArgument()
273 // purpose : Called when selection as changed or other case
274 //=================================================================================
275 void PrimitiveGUI_ConeDlg::SelectionIntoArgument()
277 myGeomBase->EraseSimulationShape();
278 myEditCurrentArgument->setText("");
279 QString aString = ""; /* name of selection */
281 int nbSel = myGeomBase->GetNameOfSelectedIObjects(mySelection, aString);
283 if(myEditCurrentArgument == GroupPoints->LineEdit1)
285 else if (myEditCurrentArgument == GroupPoints->LineEdit2)
292 if(!myGeomBase->GetTopoFromSelection(mySelection, S))
295 /* gp_Pnt : not used */
296 if (myEditCurrentArgument == GroupPoints->LineEdit1 && myGeomBase->VertexToPoint(S, myPoint1)) {
297 GroupPoints->LineEdit1->setText(aString);
300 else if (myEditCurrentArgument == GroupPoints->LineEdit2) {
301 BRepAdaptor_Curve curv(TopoDS::Edge(S));
302 myDir = curv.Line().Direction();
303 GroupPoints->LineEdit2->setText(aString);
307 if(myOkPoint1 && myOkDir && myOkRadius1 && myOkRadius2 && myOkHeight)
308 MakeConeSimulationAndDisplay();
313 //=================================================================================
314 // function : SetEditCurrentArgument()
316 //=================================================================================
317 void PrimitiveGUI_ConeDlg::SetEditCurrentArgument()
319 if(myConstructorId != 0)
322 QPushButton* send = (QPushButton*)sender();
323 mySelection->ClearFilters();
325 if(send == GroupPoints->PushButton1) {
326 GroupPoints->LineEdit1->setFocus();
327 myEditCurrentArgument = GroupPoints->LineEdit1;
328 mySelection->AddFilter(myVertexFilter);
330 else if(send == GroupPoints->PushButton2) {
331 GroupPoints->LineEdit2->setFocus();
332 myEditCurrentArgument = GroupPoints->LineEdit2;
333 mySelection->AddFilter(myEdgeFilter);
335 this->SelectionIntoArgument();
341 //=================================================================================
342 // function : LineEditReturnPressed()
344 //=================================================================================
345 void PrimitiveGUI_ConeDlg::LineEditReturnPressed()
347 QLineEdit* send = (QLineEdit*)sender();
348 if(send == GroupPoints->LineEdit1)
349 myEditCurrentArgument = GroupPoints->LineEdit1;
350 else if (send == GroupPoints->LineEdit2)
351 myEditCurrentArgument = GroupPoints->LineEdit2;
355 GEOMBase_Skeleton::LineEditReturnPressed();
360 //=================================================================================
361 // function : ActivateThisDialog()
363 //=================================================================================
364 void PrimitiveGUI_ConeDlg::ActivateThisDialog()
366 GEOMBase_Skeleton::ActivateThisDialog();
367 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
368 if(myConstructorId == 0) {
369 GroupPoints->LineEdit1->setFocus();
370 myEditCurrentArgument = GroupPoints->LineEdit1;
371 mySelection->AddFilter(myVertexFilter);
373 if(!mySimulationTopoDs.IsNull())
374 myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
379 //=================================================================================
380 // function : enterEvent()
382 //=================================================================================
383 void PrimitiveGUI_ConeDlg::enterEvent(QEvent* e)
385 if (GroupConstructors->isEnabled())
387 this->ActivateThisDialog();
392 //=================================================================================
393 // function : ValueChangedInSpinBox()
395 //=================================================================================
396 void PrimitiveGUI_ConeDlg::ValueChangedInSpinBox(double newValue)
398 myGeomBase->EraseSimulationShape();
399 mySimulationTopoDs.Nullify();
400 QObject* send = (QObject*)sender();
402 if(send == GroupPoints->SpinBox_DX || send == GroupDimensions->SpinBox_DX) {
403 myRadius1 = newValue;
406 else if(send == GroupPoints->SpinBox_DY || send == GroupDimensions->SpinBox_DY) {
407 myRadius2 = newValue;
410 else if(send == GroupPoints->SpinBox_DZ || send == GroupDimensions->SpinBox_DZ) {
415 if (myOkPoint1 && myOkDir && myOkRadius1 && myOkRadius2 && myOkHeight)
416 MakeConeSimulationAndDisplay();
421 //=================================================================================
422 // function : MakeConeSimulationAndDisplay()
424 //=================================================================================
425 void PrimitiveGUI_ConeDlg::MakeConeSimulationAndDisplay()
427 myGeomBase->EraseSimulationShape();
428 mySimulationTopoDs.Nullify();
432 /* allows user to reverse direction of construction with a negative height */
433 if(this->myHeight < -Precision::Confusion())
436 gp_Ax2 anAxis(this->myPoint1, aDir);
438 if(fabs(myRadius1 - myRadius2) <= Precision::Confusion())
439 mySimulationTopoDs = BRepPrimAPI_MakeCylinder(anAxis, (myRadius1+myRadius2)/2.0, fabs(myHeight)).Shape();
441 if(fabs(myHeight) > Precision::Confusion())
442 mySimulationTopoDs = BRepPrimAPI_MakeCone(anAxis, myRadius1, myRadius2, fabs(myHeight)).Shape();
444 myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
446 catch(Standard_Failure) {
447 MESSAGE("Exception catched in MakeConeSimulationAndDisplay");