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
30 #include "PrimitiveGUI_CylinderDlg.h"
33 #include <BRepPrimAPI_MakeCylinder.hxx>
34 #include <BRepAdaptor_Curve.hxx>
35 #include <Precision.hxx>
36 #include "QAD_Config.h"
38 //=================================================================================
39 // class : PrimitiveGUI_CylinderDlg()
40 // purpose : Constructs a PrimitiveGUI_CylinderDlg which is a child of 'parent', with the
41 // name 'name' and widget flags set to 'f'.
42 // The dialog will by default be modeless, unless you set 'modal' to
43 // TRUE to construct a modal dialog.
44 //=================================================================================
45 PrimitiveGUI_CylinderDlg::PrimitiveGUI_CylinderDlg(QWidget* parent, const char* name, PrimitiveGUI* thePrimitiveGUI, SALOME_Selection* Sel, bool modal, WFlags fl)
46 :GEOMBase_Skeleton(parent, name, Sel, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
48 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_CYLINDER_PV")));
49 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_CYLINDER_DXYZ")));
50 QPixmap image2(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_SELECT")));
52 setCaption(tr("GEOM_CYLINDER_TITLE"));
54 /***************************************************************/
55 GroupConstructors->setTitle(tr("GEOM_CYLINDER"));
56 RadioButton1->setPixmap(image0);
57 RadioButton2->setPixmap(image1);
58 RadioButton3->close(TRUE);
60 GroupPoints = new DlgRef_2Sel2Spin(this, "GroupPoints");
61 GroupPoints->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
62 GroupPoints->TextLabel1->setText(tr("GEOM_BASE_POINT"));
63 GroupPoints->TextLabel2->setText(tr("GEOM_VECTOR"));
64 GroupPoints->TextLabel3->setText(tr("GEOM_RADIUS"));
65 GroupPoints->TextLabel4->setText(tr("GEOM_HEIGHT"));
66 GroupPoints->PushButton1->setPixmap(image2);
67 GroupPoints->PushButton2->setPixmap(image2);
69 GroupDimensions = new DlgRef_2Spin(this, "GroupDimensions");
70 GroupDimensions->GroupBox1->setTitle(tr("GEOM_BOX_OBJ"));
71 GroupDimensions->TextLabel1->setText(tr("GEOM_RADIUS"));
72 GroupDimensions->TextLabel2->setText(tr("GEOM_HEIGHT"));
74 Layout1->addWidget(GroupPoints, 1, 0);
75 Layout1->addWidget(GroupDimensions, 1, 0);
76 /***************************************************************/
79 myPrimitiveGUI = thePrimitiveGUI;
84 //=================================================================================
85 // function : ~PrimitiveGUI_CylinderDlg()
86 // purpose : Destroys the object and frees any allocated resources
87 //=================================================================================
88 PrimitiveGUI_CylinderDlg::~PrimitiveGUI_CylinderDlg()
90 // no need to delete child widgets, Qt does it all for us
94 //=================================================================================
97 //=================================================================================
98 void PrimitiveGUI_CylinderDlg::Init()
102 myEditCurrentArgument = GroupPoints->LineEdit1;
106 myOkRadius = myOkHeight = true;
107 myOkPoint1 = myOkDir = false;
109 myEdgeFilter = new GEOM_EdgeFilter(StdSelect_Line, myGeom);
110 myVertexFilter = new GEOM_ShapeTypeFilter(TopAbs_VERTEX, myGeom);
111 mySelection->AddFilter(myVertexFilter);
113 /* Get setting of step value from file configuration */
114 QString St = QAD_CONFIG->getSetting("Geometry:SettingsGeomStep");
115 step = St.toDouble();
117 /* min, max, step and decimals for spin boxes & initial values */
118 /* First constructor : radius */
119 GroupPoints->SpinBox_DX->RangeStepAndValidator(0.001, 999.999, step, 3);
120 /* First constructor : algebric height */
121 GroupPoints->SpinBox_DY->RangeStepAndValidator(-999.999, 999.999, step, 3);
122 /* Second constructor : radius */
123 GroupDimensions->SpinBox_DX->RangeStepAndValidator(0.001, 999.999, step, 3);
124 /* Second constructor : algebric height */
125 GroupDimensions->SpinBox_DY->RangeStepAndValidator(-999.999, 999.999, step, 3);
127 GroupPoints->SpinBox_DX->SetValue(myRadius);
128 GroupPoints->SpinBox_DY->SetValue(myHeight);
129 GroupDimensions->SpinBox_DX->SetValue(myRadius);
130 GroupDimensions->SpinBox_DY->SetValue(myHeight);
132 /* signals and slots connections */
133 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
134 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
135 connect(GroupConstructors, SIGNAL(clicked(int)), this, SLOT(ConstructorsClicked(int)));
137 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
138 connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
140 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
141 connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
143 connect(GroupPoints->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
144 connect(GroupPoints->SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
145 connect(GroupDimensions->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
146 connect(GroupDimensions->SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
148 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_DX, SLOT(SetStep(double)));
149 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_DY, SLOT(SetStep(double)));
150 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DX, SLOT(SetStep(double)));
151 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DY, SLOT(SetStep(double)));
153 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
155 /* displays Dialog */
156 GroupDimensions->hide();
164 //=================================================================================
165 // function : ConstructorsClicked()
166 // purpose : Radio button management
167 //=================================================================================
168 void PrimitiveGUI_CylinderDlg::ConstructorsClicked(int constructorId)
170 myConstructorId = constructorId;
171 mySelection->ClearFilters();
172 myGeomBase->EraseSimulationShape();
173 disconnect(mySelection, 0, this, 0);
174 myOkHeight = myOkRadius = true;
178 switch(myConstructorId)
182 GroupDimensions->hide();
185 myOkPoint1 = myOkDir = false;
187 myEditCurrentArgument = GroupPoints->LineEdit1;
188 GroupPoints->LineEdit1->setText(tr(""));
189 GroupPoints->LineEdit2->setText(tr(""));
191 GroupPoints->SpinBox_DX->SetValue(myRadius);
192 GroupPoints->SpinBox_DY->SetValue(myHeight);
194 /* filter for next selection */
195 mySelection->AddFilter(myVertexFilter);
196 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
203 GroupDimensions->show();
204 myOkPoint1 = myOkDir = true;
206 GroupDimensions->SpinBox_DX->SetValue(myRadius);
207 GroupDimensions->SpinBox_DY->SetValue(myHeight);
208 myPoint1.SetCoord(0.0, 0.0, 0.0);
209 myDir.SetCoord(0.0, 0.0, 1.0);
211 MakeCylinderSimulationAndDisplay();
219 //=================================================================================
220 // function : ClickOnOk()
222 //=================================================================================
223 void PrimitiveGUI_CylinderDlg::ClickOnOk()
225 this->ClickOnApply();
231 //=================================================================================
232 // function : ClickOnApply()
234 //=================================================================================
235 void PrimitiveGUI_CylinderDlg::ClickOnApply()
237 QAD_Application::getDesktop()->putInfo(tr(""));
238 if (mySimulationTopoDs.IsNull())
240 myGeomBase->EraseSimulationShape();
241 mySimulationTopoDs.Nullify();
243 if(myOkPoint1 && myOkDir && myOkRadius && myOkHeight) {
245 /* allows user to reverse direction of construction with a negative height */
246 if(this->myHeight < -Precision::Confusion())
248 myPrimitiveGUI->MakeCylinderAndDisplay(myPoint1, aDir, myRadius, fabs(myHeight));
254 //=================================================================================
255 // function : SelectionIntoArgument()
256 // purpose : Called when selection as changed or other case
257 //=================================================================================
258 void PrimitiveGUI_CylinderDlg::SelectionIntoArgument()
260 myGeomBase->EraseSimulationShape();
261 myEditCurrentArgument->setText("");
262 QString aString = ""; /* name of selection */
264 int nbSel = myGeomBase->GetNameOfSelectedIObjects(mySelection, aString);
266 if(myEditCurrentArgument == GroupPoints->LineEdit1)
268 else if (myEditCurrentArgument == GroupPoints->LineEdit2)
275 if(!myGeomBase->GetTopoFromSelection(mySelection, S))
278 /* gp_Pnt : not used */
279 if (myEditCurrentArgument == GroupPoints->LineEdit1 && myGeomBase->VertexToPoint(S, myPoint1)) {
280 GroupPoints->LineEdit1->setText(aString);
283 else if (myEditCurrentArgument == GroupPoints->LineEdit2) {
284 BRepAdaptor_Curve curv(TopoDS::Edge(S));
285 myDir = curv.Line().Direction();
286 GroupPoints->LineEdit2->setText(aString);
290 if(myOkPoint1 && myOkDir && myOkRadius && myOkHeight)
291 MakeCylinderSimulationAndDisplay();
296 //=================================================================================
297 // function : SetEditCurrentArgument()
299 //=================================================================================
300 void PrimitiveGUI_CylinderDlg::SetEditCurrentArgument()
302 if(myConstructorId != 0)
305 QPushButton* send = (QPushButton*)sender();
306 mySelection->ClearFilters();
308 if(send == GroupPoints->PushButton1) {
309 GroupPoints->LineEdit1->setFocus();
310 myEditCurrentArgument = GroupPoints->LineEdit1;
311 mySelection->AddFilter(myVertexFilter);
313 else if(send == GroupPoints->PushButton2) {
314 GroupPoints->LineEdit2->setFocus();
315 myEditCurrentArgument = GroupPoints->LineEdit2;
316 mySelection->AddFilter(myEdgeFilter);
318 this->SelectionIntoArgument();
324 //=================================================================================
325 // function : LineEditReturnPressed()
327 //=================================================================================
328 void PrimitiveGUI_CylinderDlg::LineEditReturnPressed()
330 QLineEdit* send = (QLineEdit*)sender();
331 if(send == GroupPoints->LineEdit1)
332 myEditCurrentArgument = GroupPoints->LineEdit1;
333 else if (send == GroupPoints->LineEdit2)
334 myEditCurrentArgument = GroupPoints->LineEdit2;
338 GEOMBase_Skeleton::LineEditReturnPressed();
343 //=================================================================================
344 // function : ActivateThisDialog()
346 //=================================================================================
347 void PrimitiveGUI_CylinderDlg::ActivateThisDialog()
349 GEOMBase_Skeleton::ActivateThisDialog();
350 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
351 if(myConstructorId == 0) {
352 GroupPoints->LineEdit1->setFocus();
353 myEditCurrentArgument = GroupPoints->LineEdit1;
354 mySelection->AddFilter(myVertexFilter);
356 if(!mySimulationTopoDs.IsNull())
357 myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
362 //=================================================================================
363 // function : enterEvent()
365 //=================================================================================
366 void PrimitiveGUI_CylinderDlg::enterEvent(QEvent* e)
368 if (GroupConstructors->isEnabled())
370 this->ActivateThisDialog();
375 //=================================================================================
376 // function : ValueChangedInSpinBox
378 //=================================================================================
379 void PrimitiveGUI_CylinderDlg::ValueChangedInSpinBox( double newValue )
381 myGeomBase->EraseSimulationShape();
382 mySimulationTopoDs.Nullify();
383 QObject* send = (QObject*)sender();
386 if(send == GroupPoints->SpinBox_DX || send == GroupDimensions->SpinBox_DX) {
389 } /* algebric height */
390 else if(send == GroupPoints->SpinBox_DY || send == GroupDimensions->SpinBox_DY) {
395 if (myOkPoint1 && myOkDir && myOkRadius && myOkHeight)
396 MakeCylinderSimulationAndDisplay();
401 //=================================================================================
402 // function : MakeCylinderSimulationAndDisplay()
404 //=================================================================================
405 void PrimitiveGUI_CylinderDlg::MakeCylinderSimulationAndDisplay()
407 myGeomBase->EraseSimulationShape();
408 mySimulationTopoDs.Nullify();
409 gp_Dir aDir = this->myDir;
412 /* allows user to reverse direction of construction with a negative height */
413 if(this->myHeight < -Precision::Confusion())
416 gp_Ax2 anAxis(this->myPoint1, aDir);
418 mySimulationTopoDs = BRepPrimAPI_MakeCylinder(anAxis, this->myRadius, fabs(myHeight)).Shape();
419 myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
421 catch(Standard_Failure) {
422 MESSAGE("Exception catched in MakeCylinderSimulationAndDisplay");