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
30 #include "PrimitiveGUI_ConeDlg.h"
33 #include <BRepPrimAPI_MakeCone.hxx>
34 #include <BRepPrimAPI_MakeCylinder.hxx>
35 #include <BRepAdaptor_Curve.hxx>
36 #include <Precision.hxx>
37 #include "QAD_Config.h"
39 //=================================================================================
40 // class : PrimitiveGUI_ConeDlg()
41 // purpose : Constructs a PrimitiveGUI_ConeDlg 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 PrimitiveGUI_ConeDlg::PrimitiveGUI_ConeDlg(QWidget* parent, const char* name, PrimitiveGUI* thePrimitiveGUI, SALOME_Selection* Sel, 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_CONE_PV")));
50 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_CONE_DXYZ")));
51 QPixmap image2(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_SELECT")));
53 setCaption(tr("GEOM_CONE_TITLE"));
55 /***************************************************************/
56 GroupConstructors->setTitle(tr("GEOM_CONE"));
57 RadioButton1->setPixmap(image0);
58 RadioButton2->setPixmap(image1);
59 RadioButton3->close(TRUE);
61 GroupPoints = new DlgRef_2Sel3Spin(this, "GroupPoints");
62 GroupPoints->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
63 GroupPoints->TextLabel1->setText(tr("GEOM_BASE_POINT"));
64 GroupPoints->TextLabel2->setText(tr("GEOM_VECTOR"));
65 GroupPoints->TextLabel3->setText(tr("GEOM_RADIUS_I").arg("1"));
66 GroupPoints->TextLabel4->setText(tr("GEOM_RADIUS_I").arg("2"));
67 GroupPoints->TextLabel5->setText(tr("GEOM_HEIGHT"));
68 GroupPoints->PushButton1->setPixmap(image2);
69 GroupPoints->PushButton2->setPixmap(image2);
71 GroupDimensions = new DlgRef_3Spin(this, "GroupDimensions");
72 GroupDimensions->GroupBox1->setTitle(tr("GEOM_BOX_OBJ"));
73 GroupDimensions->TextLabel1->setText(tr("GEOM_RADIUS_I").arg("1"));
74 GroupDimensions->TextLabel2->setText(tr("GEOM_RADIUS_I").arg("2"));
75 GroupDimensions->TextLabel3->setText(tr("GEOM_HEIGHT"));
77 Layout1->addWidget(GroupPoints, 1, 0);
78 Layout1->addWidget(GroupDimensions, 1, 0);
79 /***************************************************************/
82 myPrimitiveGUI = thePrimitiveGUI;
87 //=================================================================================
88 // function : ~PrimitiveGUI_ConeDlg()
89 // purpose : Destroys the object and frees any allocated resources
90 //=================================================================================
91 PrimitiveGUI_ConeDlg::~PrimitiveGUI_ConeDlg()
93 // no need to delete child widgets, Qt does it all for us
97 //=================================================================================
100 //=================================================================================
101 void PrimitiveGUI_ConeDlg::Init()
105 myEditCurrentArgument = GroupPoints->LineEdit1;
111 myOkRadius1 = myOkRadius2 = myOkHeight = true;
112 myOkPoint1 = myOkDir = false;
114 myEdgeFilter = new GEOM_EdgeFilter(StdSelect_Line, myGeom);
115 myVertexFilter = new GEOM_ShapeTypeFilter(TopAbs_VERTEX, myGeom);
116 mySelection->AddFilter(myVertexFilter);
118 /* Get setting of step value from file configuration */
119 QString St = QAD_CONFIG->getSetting("Geometry:SettingsGeomStep");
120 step = St.toDouble();
122 /* min, max, step and decimals for spin boxes & initial values */
123 GroupPoints->SpinBox_DX->RangeStepAndValidator(0.001, 999.999, step, 3);
124 GroupPoints->SpinBox_DY->RangeStepAndValidator(0.001, 999.999, step, 3);
125 GroupPoints->SpinBox_DZ->RangeStepAndValidator(-999.999, 999.999, step, 3);
126 GroupDimensions->SpinBox_DX->RangeStepAndValidator(0.001, 999.999, step, 3);
127 GroupDimensions->SpinBox_DY->RangeStepAndValidator(0.001, 999.999, step, 3);
128 GroupDimensions->SpinBox_DZ->RangeStepAndValidator(-999.999, 999.999, step, 3);
130 GroupPoints->SpinBox_DX->SetValue(myRadius1);
131 GroupPoints->SpinBox_DY->SetValue(myRadius2);
132 GroupPoints->SpinBox_DZ->SetValue(myHeight);
133 GroupDimensions->SpinBox_DX->SetValue(myRadius1);
134 GroupDimensions->SpinBox_DY->SetValue(myRadius2);
135 GroupDimensions->SpinBox_DZ->SetValue(myHeight);
137 /* signals and slots connections */
138 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
139 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
140 connect(GroupConstructors, SIGNAL(clicked(int)), this, SLOT(ConstructorsClicked(int)));
142 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
143 connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
145 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
146 connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
148 connect(GroupPoints->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
149 connect(GroupPoints->SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
150 connect(GroupPoints->SpinBox_DZ, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
151 connect(GroupDimensions->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
152 connect(GroupDimensions->SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
153 connect(GroupDimensions->SpinBox_DZ, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
155 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_DX, SLOT(SetStep(double)));
156 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_DY, SLOT(SetStep(double)));
157 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_DZ, SLOT(SetStep(double)));
158 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DX, SLOT(SetStep(double)));
159 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DY, SLOT(SetStep(double)));
160 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DZ, SLOT(SetStep(double)));
162 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
164 /* displays Dialog */
165 GroupDimensions->hide();
173 //=================================================================================
174 // function : ConstructorsClicked()
175 // purpose : Radio button management
176 //=================================================================================
177 void PrimitiveGUI_ConeDlg::ConstructorsClicked(int constructorId)
179 myConstructorId = constructorId;
180 mySelection->ClearFilters();
181 myGeomBase->EraseSimulationShape();
182 disconnect(mySelection, 0, this, 0);
183 myOkHeight = myOkRadius1 = myOkRadius2 = true;
188 switch(myConstructorId)
192 GroupDimensions->hide();
195 myOkPoint1 = myOkDir = false;
197 myEditCurrentArgument = GroupPoints->LineEdit1;
198 GroupPoints->LineEdit1->setText(tr(""));
199 GroupPoints->LineEdit2->setText(tr(""));
201 GroupPoints->SpinBox_DX->SetValue(myRadius1);
202 GroupPoints->SpinBox_DY->SetValue(myRadius2);
203 GroupPoints->SpinBox_DZ->SetValue(myHeight);
205 /* filter for next selection */
206 mySelection->AddFilter(myVertexFilter);
207 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
214 GroupDimensions->show();
215 myOkPoint1 = myOkDir = true;
217 GroupDimensions->SpinBox_DX->SetValue(myRadius1);
218 GroupDimensions->SpinBox_DY->SetValue(myRadius2);
219 GroupDimensions->SpinBox_DZ->SetValue(myHeight);
221 myPoint1.SetCoord(0.0, 0.0, 0.0);
222 myDir.SetCoord(0.0, 0.0, 1.0);
224 MakeConeSimulationAndDisplay();
232 //=================================================================================
233 // function : ClickOnOk()
235 //=================================================================================
236 void PrimitiveGUI_ConeDlg::ClickOnOk()
238 this->ClickOnApply();
244 //=================================================================================
245 // function : ClickOnApply()
247 //=================================================================================
248 void PrimitiveGUI_ConeDlg::ClickOnApply()
250 QAD_Application::getDesktop()->putInfo(tr(""));
251 if (mySimulationTopoDs.IsNull())
253 myGeomBase->EraseSimulationShape();
254 mySimulationTopoDs.Nullify();
256 if(myOkPoint1 && myOkDir && myOkRadius1 && myOkRadius2 && myOkHeight) {
258 /* allows user to reverse direction of construction with a negative height */
259 if(this->myHeight < -Precision::Confusion())
261 myPrimitiveGUI->MakeConeAndDisplay(myPoint1, aDir, myRadius1, myRadius2, fabs(myHeight));
267 //=================================================================================
268 // function : SelectionIntoArgument()
269 // purpose : Called when selection as changed or other case
270 //=================================================================================
271 void PrimitiveGUI_ConeDlg::SelectionIntoArgument()
273 myGeomBase->EraseSimulationShape();
274 myEditCurrentArgument->setText("");
275 QString aString = ""; /* name of selection */
277 int nbSel = myGeomBase->GetNameOfSelectedIObjects(mySelection, aString);
279 if(myEditCurrentArgument == GroupPoints->LineEdit1)
281 else if (myEditCurrentArgument == GroupPoints->LineEdit2)
288 if(!myGeomBase->GetTopoFromSelection(mySelection, S))
291 /* gp_Pnt : not used */
292 if (myEditCurrentArgument == GroupPoints->LineEdit1 && myGeomBase->VertexToPoint(S, myPoint1)) {
293 GroupPoints->LineEdit1->setText(aString);
296 else if (myEditCurrentArgument == GroupPoints->LineEdit2) {
297 BRepAdaptor_Curve curv(TopoDS::Edge(S));
298 myDir = curv.Line().Direction();
299 GroupPoints->LineEdit2->setText(aString);
303 if(myOkPoint1 && myOkDir && myOkRadius1 && myOkRadius2 && myOkHeight)
304 MakeConeSimulationAndDisplay();
309 //=================================================================================
310 // function : SetEditCurrentArgument()
312 //=================================================================================
313 void PrimitiveGUI_ConeDlg::SetEditCurrentArgument()
315 if(myConstructorId != 0)
318 QPushButton* send = (QPushButton*)sender();
319 mySelection->ClearFilters();
321 if(send == GroupPoints->PushButton1) {
322 GroupPoints->LineEdit1->setFocus();
323 myEditCurrentArgument = GroupPoints->LineEdit1;
324 mySelection->AddFilter(myVertexFilter);
326 else if(send == GroupPoints->PushButton2) {
327 GroupPoints->LineEdit2->setFocus();
328 myEditCurrentArgument = GroupPoints->LineEdit2;
329 mySelection->AddFilter(myEdgeFilter);
331 this->SelectionIntoArgument();
337 //=================================================================================
338 // function : LineEditReturnPressed()
340 //=================================================================================
341 void PrimitiveGUI_ConeDlg::LineEditReturnPressed()
343 QLineEdit* send = (QLineEdit*)sender();
344 if(send == GroupPoints->LineEdit1)
345 myEditCurrentArgument = GroupPoints->LineEdit1;
346 else if (send == GroupPoints->LineEdit2)
347 myEditCurrentArgument = GroupPoints->LineEdit2;
351 GEOMBase_Skeleton::LineEditReturnPressed();
356 //=================================================================================
357 // function : ActivateThisDialog()
359 //=================================================================================
360 void PrimitiveGUI_ConeDlg::ActivateThisDialog()
362 GEOMBase_Skeleton::ActivateThisDialog();
363 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
364 if(myConstructorId == 0) {
365 GroupPoints->LineEdit1->setFocus();
366 myEditCurrentArgument = GroupPoints->LineEdit1;
367 mySelection->AddFilter(myVertexFilter);
369 if(!mySimulationTopoDs.IsNull())
370 myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
375 //=================================================================================
376 // function : enterEvent()
378 //=================================================================================
379 void PrimitiveGUI_ConeDlg::enterEvent(QEvent* e)
381 if (GroupConstructors->isEnabled())
383 this->ActivateThisDialog();
388 //=================================================================================
389 // function : ValueChangedInSpinBox()
391 //=================================================================================
392 void PrimitiveGUI_ConeDlg::ValueChangedInSpinBox(double newValue)
394 myGeomBase->EraseSimulationShape();
395 mySimulationTopoDs.Nullify();
396 QObject* send = (QObject*)sender();
398 if(send == GroupPoints->SpinBox_DX || send == GroupDimensions->SpinBox_DX) {
399 myRadius1 = newValue;
402 else if(send == GroupPoints->SpinBox_DY || send == GroupDimensions->SpinBox_DY) {
403 myRadius2 = newValue;
406 else if(send == GroupPoints->SpinBox_DZ || send == GroupDimensions->SpinBox_DZ) {
411 if (myOkPoint1 && myOkDir && myOkRadius1 && myOkRadius2 && myOkHeight)
412 MakeConeSimulationAndDisplay();
417 //=================================================================================
418 // function : MakeConeSimulationAndDisplay()
420 //=================================================================================
421 void PrimitiveGUI_ConeDlg::MakeConeSimulationAndDisplay()
423 myGeomBase->EraseSimulationShape();
424 mySimulationTopoDs.Nullify();
428 /* allows user to reverse direction of construction with a negative height */
429 if(this->myHeight < -Precision::Confusion())
432 gp_Ax2 anAxis(this->myPoint1, aDir);
434 if(fabs(myRadius1 - myRadius2) <= Precision::Confusion())
435 mySimulationTopoDs = BRepPrimAPI_MakeCylinder(anAxis, (myRadius1+myRadius2)/2.0, fabs(myHeight)).Shape();
437 if(fabs(myHeight) > Precision::Confusion())
438 mySimulationTopoDs = BRepPrimAPI_MakeCone(anAxis, myRadius1, myRadius2, fabs(myHeight)).Shape();
440 myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
442 catch(Standard_Failure) {
443 MESSAGE("Exception catched in MakeConeSimulationAndDisplay");