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_CylinderDlg.cxx
25 // Author : Lucien PIGNOLONI
29 #include "PrimitiveGUI_CylinderDlg.h"
32 #include <BRepPrimAPI_MakeCylinder.hxx>
33 #include <BRepAdaptor_Curve.hxx>
34 #include <Precision.hxx>
35 #include "QAD_Config.h"
37 #include "utilities.h"
41 //=================================================================================
42 // class : PrimitiveGUI_CylinderDlg()
43 // purpose : Constructs a PrimitiveGUI_CylinderDlg which is a child of 'parent', with the
44 // name 'name' and widget flags set to 'f'.
45 // The dialog will by default be modeless, unless you set 'modal' to
46 // TRUE to construct a modal dialog.
47 //=================================================================================
48 PrimitiveGUI_CylinderDlg::PrimitiveGUI_CylinderDlg(QWidget* parent, const char* name, PrimitiveGUI* thePrimitiveGUI, SALOME_Selection* Sel, bool modal, WFlags fl)
49 :GEOMBase_Skeleton(parent, name, Sel, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
51 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_CYLINDER_PV")));
52 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_CYLINDER_DXYZ")));
53 QPixmap image2(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_SELECT")));
55 setCaption(tr("GEOM_CYLINDER_TITLE"));
57 /***************************************************************/
58 GroupConstructors->setTitle(tr("GEOM_CYLINDER"));
59 RadioButton1->setPixmap(image0);
60 RadioButton2->setPixmap(image1);
61 RadioButton3->close(TRUE);
63 GroupPoints = new DlgRef_2Sel2Spin(this, "GroupPoints");
64 GroupPoints->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
65 GroupPoints->TextLabel1->setText(tr("GEOM_BASE_POINT"));
66 GroupPoints->TextLabel2->setText(tr("GEOM_VECTOR"));
67 GroupPoints->TextLabel3->setText(tr("GEOM_RADIUS"));
68 GroupPoints->TextLabel4->setText(tr("GEOM_HEIGHT"));
69 GroupPoints->PushButton1->setPixmap(image2);
70 GroupPoints->PushButton2->setPixmap(image2);
72 GroupDimensions = new DlgRef_2Spin(this, "GroupDimensions");
73 GroupDimensions->GroupBox1->setTitle(tr("GEOM_BOX_OBJ"));
74 GroupDimensions->TextLabel1->setText(tr("GEOM_RADIUS"));
75 GroupDimensions->TextLabel2->setText(tr("GEOM_HEIGHT"));
77 Layout1->addWidget(GroupPoints, 1, 0);
78 Layout1->addWidget(GroupDimensions, 1, 0);
79 /***************************************************************/
82 myPrimitiveGUI = thePrimitiveGUI;
87 //=================================================================================
88 // function : ~PrimitiveGUI_CylinderDlg()
89 // purpose : Destroys the object and frees any allocated resources
90 //=================================================================================
91 PrimitiveGUI_CylinderDlg::~PrimitiveGUI_CylinderDlg()
93 // no need to delete child widgets, Qt does it all for us
97 //=================================================================================
100 //=================================================================================
101 void PrimitiveGUI_CylinderDlg::Init()
105 myEditCurrentArgument = GroupPoints->LineEdit1;
109 myOkRadius = myOkHeight = true;
110 myOkPoint1 = myOkDir = false;
112 myEdgeFilter = new GEOM_EdgeFilter(StdSelect_Line, myGeom);
113 myVertexFilter = new GEOM_ShapeTypeFilter(TopAbs_VERTEX, myGeom);
114 mySelection->AddFilter(myVertexFilter);
116 /* Get setting of step value from file configuration */
117 QString St = QAD_CONFIG->getSetting("Geometry:SettingsGeomStep");
118 step = St.toDouble();
120 /* min, max, step and decimals for spin boxes & initial values */
121 /* First constructor : radius */
122 GroupPoints->SpinBox_DX->RangeStepAndValidator(0.001, 999.999, step, 3);
123 /* First constructor : algebric height */
124 GroupPoints->SpinBox_DY->RangeStepAndValidator(-999.999, 999.999, step, 3);
125 /* Second constructor : radius */
126 GroupDimensions->SpinBox_DX->RangeStepAndValidator(0.001, 999.999, step, 3);
127 /* Second constructor : algebric height */
128 GroupDimensions->SpinBox_DY->RangeStepAndValidator(-999.999, 999.999, step, 3);
130 GroupPoints->SpinBox_DX->SetValue(myRadius);
131 GroupPoints->SpinBox_DY->SetValue(myHeight);
132 GroupDimensions->SpinBox_DX->SetValue(myRadius);
133 GroupDimensions->SpinBox_DY->SetValue(myHeight);
135 /* signals and slots connections */
136 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
137 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
138 connect(GroupConstructors, SIGNAL(clicked(int)), this, SLOT(ConstructorsClicked(int)));
140 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
141 connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
143 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
144 connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
146 connect(GroupPoints->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
147 connect(GroupPoints->SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
148 connect(GroupDimensions->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
149 connect(GroupDimensions->SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
151 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_DX, SLOT(SetStep(double)));
152 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_DY, SLOT(SetStep(double)));
153 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DX, SLOT(SetStep(double)));
154 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DY, SLOT(SetStep(double)));
156 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
158 /* displays Dialog */
159 GroupDimensions->hide();
167 //=================================================================================
168 // function : ConstructorsClicked()
169 // purpose : Radio button management
170 //=================================================================================
171 void PrimitiveGUI_CylinderDlg::ConstructorsClicked(int constructorId)
173 myConstructorId = constructorId;
174 mySelection->ClearFilters();
175 myGeomBase->EraseSimulationShape();
176 disconnect(mySelection, 0, this, 0);
177 myOkHeight = myOkRadius = true;
181 switch(myConstructorId)
185 GroupDimensions->hide();
188 myOkPoint1 = myOkDir = false;
190 myEditCurrentArgument = GroupPoints->LineEdit1;
191 GroupPoints->LineEdit1->setText(tr(""));
192 GroupPoints->LineEdit2->setText(tr(""));
194 GroupPoints->SpinBox_DX->SetValue(myRadius);
195 GroupPoints->SpinBox_DY->SetValue(myHeight);
197 /* filter for next selection */
198 mySelection->AddFilter(myVertexFilter);
199 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
206 GroupDimensions->show();
207 myOkPoint1 = myOkDir = true;
209 GroupDimensions->SpinBox_DX->SetValue(myRadius);
210 GroupDimensions->SpinBox_DY->SetValue(myHeight);
211 myPoint1.SetCoord(0.0, 0.0, 0.0);
212 myDir.SetCoord(0.0, 0.0, 1.0);
214 MakeCylinderSimulationAndDisplay();
222 //=================================================================================
223 // function : ClickOnOk()
225 //=================================================================================
226 void PrimitiveGUI_CylinderDlg::ClickOnOk()
228 this->ClickOnApply();
234 //=================================================================================
235 // function : ClickOnApply()
237 //=================================================================================
238 void PrimitiveGUI_CylinderDlg::ClickOnApply()
240 buttonApply->setFocus();
241 QAD_Application::getDesktop()->putInfo(tr(""));
242 if (mySimulationTopoDs.IsNull())
244 myGeomBase->EraseSimulationShape();
245 mySimulationTopoDs.Nullify();
247 if(myOkPoint1 && myOkDir && myOkRadius && myOkHeight) {
249 /* allows user to reverse direction of construction with a negative height */
250 if(this->myHeight < -Precision::Confusion())
252 myPrimitiveGUI->MakeCylinderAndDisplay(myPoint1, aDir, myRadius, fabs(myHeight));
258 //=================================================================================
259 // function : SelectionIntoArgument()
260 // purpose : Called when selection as changed or other case
261 //=================================================================================
262 void PrimitiveGUI_CylinderDlg::SelectionIntoArgument()
264 myGeomBase->EraseSimulationShape();
265 myEditCurrentArgument->setText("");
266 QString aString = ""; /* name of selection */
268 int nbSel = myGeomBase->GetNameOfSelectedIObjects(mySelection, aString);
270 if(myEditCurrentArgument == GroupPoints->LineEdit1)
272 else if (myEditCurrentArgument == GroupPoints->LineEdit2)
279 if(!myGeomBase->GetTopoFromSelection(mySelection, S))
282 /* gp_Pnt : not used */
283 if (myEditCurrentArgument == GroupPoints->LineEdit1 && myGeomBase->VertexToPoint(S, myPoint1)) {
284 GroupPoints->LineEdit1->setText(aString);
287 else if (myEditCurrentArgument == GroupPoints->LineEdit2) {
288 BRepAdaptor_Curve curv(TopoDS::Edge(S));
289 myDir = curv.Line().Direction();
290 GroupPoints->LineEdit2->setText(aString);
294 if(myOkPoint1 && myOkDir && myOkRadius && myOkHeight)
295 MakeCylinderSimulationAndDisplay();
300 //=================================================================================
301 // function : SetEditCurrentArgument()
303 //=================================================================================
304 void PrimitiveGUI_CylinderDlg::SetEditCurrentArgument()
306 if(myConstructorId != 0)
309 QPushButton* send = (QPushButton*)sender();
310 mySelection->ClearFilters();
312 if(send == GroupPoints->PushButton1) {
313 GroupPoints->LineEdit1->setFocus();
314 myEditCurrentArgument = GroupPoints->LineEdit1;
315 mySelection->AddFilter(myVertexFilter);
317 else if(send == GroupPoints->PushButton2) {
318 GroupPoints->LineEdit2->setFocus();
319 myEditCurrentArgument = GroupPoints->LineEdit2;
320 mySelection->AddFilter(myEdgeFilter);
322 this->SelectionIntoArgument();
328 //=================================================================================
329 // function : LineEditReturnPressed()
331 //=================================================================================
332 void PrimitiveGUI_CylinderDlg::LineEditReturnPressed()
334 QLineEdit* send = (QLineEdit*)sender();
335 if(send == GroupPoints->LineEdit1)
336 myEditCurrentArgument = GroupPoints->LineEdit1;
337 else if (send == GroupPoints->LineEdit2)
338 myEditCurrentArgument = GroupPoints->LineEdit2;
342 GEOMBase_Skeleton::LineEditReturnPressed();
347 //=================================================================================
348 // function : ActivateThisDialog()
350 //=================================================================================
351 void PrimitiveGUI_CylinderDlg::ActivateThisDialog()
353 GEOMBase_Skeleton::ActivateThisDialog();
354 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
355 if(myConstructorId == 0) {
356 GroupPoints->LineEdit1->setFocus();
357 myEditCurrentArgument = GroupPoints->LineEdit1;
358 mySelection->AddFilter(myVertexFilter);
360 if(!mySimulationTopoDs.IsNull())
361 myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
366 //=================================================================================
367 // function : enterEvent()
369 //=================================================================================
370 void PrimitiveGUI_CylinderDlg::enterEvent(QEvent* e)
372 if (GroupConstructors->isEnabled())
374 this->ActivateThisDialog();
379 //=================================================================================
380 // function : ValueChangedInSpinBox
382 //=================================================================================
383 void PrimitiveGUI_CylinderDlg::ValueChangedInSpinBox( double newValue )
385 myGeomBase->EraseSimulationShape();
386 mySimulationTopoDs.Nullify();
387 QObject* send = (QObject*)sender();
390 if(send == GroupPoints->SpinBox_DX || send == GroupDimensions->SpinBox_DX) {
393 } /* algebric height */
394 else if(send == GroupPoints->SpinBox_DY || send == GroupDimensions->SpinBox_DY) {
399 if (myOkPoint1 && myOkDir && myOkRadius && myOkHeight)
400 MakeCylinderSimulationAndDisplay();
405 //=================================================================================
406 // function : MakeCylinderSimulationAndDisplay()
408 //=================================================================================
409 void PrimitiveGUI_CylinderDlg::MakeCylinderSimulationAndDisplay()
411 myGeomBase->EraseSimulationShape();
412 mySimulationTopoDs.Nullify();
413 gp_Dir aDir = this->myDir;
416 /* allows user to reverse direction of construction with a negative height */
417 if(this->myHeight < -Precision::Confusion())
420 gp_Ax2 anAxis(this->myPoint1, aDir);
422 mySimulationTopoDs = BRepPrimAPI_MakeCylinder(anAxis, this->myRadius, fabs(myHeight)).Shape();
423 myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
425 catch(Standard_Failure) {
426 MESSAGE("Exception catched in MakeCylinderSimulationAndDisplay");