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_TorusDlg.cxx
25 // Author : Lucien PIGNOLONI
29 #include "PrimitiveGUI_TorusDlg.h"
32 #include <BRepPrimAPI_MakeTorus.hxx>
33 #include <BRepAdaptor_Curve.hxx>
34 #include "QAD_Config.h"
36 #include "utilities.h"
40 //=================================================================================
41 // class : PrimitiveGUI_TorusDlg()
42 // purpose : Constructs a PrimitiveGUI_TorusDlg which is a child of 'parent', with the
43 // name 'name' and widget flags set to 'f'.
44 // The dialog will by default be modeless, unless you set 'modal' to
45 // TRUE to construct a modal dialog.
46 //=================================================================================
47 PrimitiveGUI_TorusDlg::PrimitiveGUI_TorusDlg(QWidget* parent, const char* name, PrimitiveGUI* thePrimitiveGUI, SALOME_Selection* Sel, bool modal, WFlags fl)
48 :GEOMBase_Skeleton(parent, name, Sel, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
50 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_TORUS_PV")));
51 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_TORUS_DXYZ")));
52 QPixmap image2(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_SELECT")));
54 setCaption(tr("GEOM_TORUS_TITLE"));
56 /***************************************************************/
57 GroupConstructors->setTitle(tr("GEOM_TORUS"));
58 RadioButton1->setPixmap(image0);
59 RadioButton2->setPixmap(image1);
60 RadioButton3->close(TRUE);
62 GroupPoints = new DlgRef_2Sel2Spin(this, "GroupPoints");
63 GroupPoints->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
64 GroupPoints->TextLabel1->setText(tr("GEOM_BASE_POINT"));
65 GroupPoints->TextLabel2->setText(tr("GEOM_VECTOR"));
66 GroupPoints->TextLabel3->setText(tr("GEOM_RADIUS_I").arg("1"));
67 GroupPoints->TextLabel4->setText(tr("GEOM_RADIUS_I").arg("2"));
68 GroupPoints->PushButton1->setPixmap(image2);
69 GroupPoints->PushButton2->setPixmap(image2);
71 GroupDimensions = new DlgRef_2Spin(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"));
76 Layout1->addWidget(GroupPoints, 1, 0);
77 Layout1->addWidget(GroupDimensions, 1, 0);
78 /***************************************************************/
81 myPrimitiveGUI = thePrimitiveGUI;
86 //=================================================================================
87 // function : ~PrimitiveGUI_TorusDlg()
88 // purpose : Destroys the object and frees any allocated resources
89 //=================================================================================
90 PrimitiveGUI_TorusDlg::~PrimitiveGUI_TorusDlg()
92 // no need to delete child widgets, Qt does it all for us
96 //=================================================================================
99 //=================================================================================
100 void PrimitiveGUI_TorusDlg::Init()
104 myEditCurrentArgument = GroupPoints->LineEdit1;
108 myOkPoint1 = myOkDir = false;
110 myEdgeFilter = new GEOM_EdgeFilter(StdSelect_Line, myGeom);
111 myVertexFilter = new GEOM_ShapeTypeFilter(TopAbs_VERTEX, myGeom);
112 mySelection->AddFilter(myVertexFilter);
114 /* Get setting of step value from file configuration */
115 QString St = QAD_CONFIG->getSetting("Geometry:SettingsGeomStep");
116 step = St.toDouble();
118 /* min, max, step and decimals for spin boxes & initial values */
119 GroupPoints->SpinBox_DX->RangeStepAndValidator(0.001, 999.999, step, 3);
120 GroupPoints->SpinBox_DY->RangeStepAndValidator(0.001, 999.999, step, 3);
121 GroupDimensions->SpinBox_DX->RangeStepAndValidator(0.001, 999.999, step, 3);
122 GroupDimensions->SpinBox_DY->RangeStepAndValidator(0.001, 999.999, step, 3);
124 GroupPoints->SpinBox_DX->SetValue(myRadius1);
125 GroupPoints->SpinBox_DY->SetValue(myRadius2);
126 GroupDimensions->SpinBox_DX->SetValue(myRadius1);
127 GroupDimensions->SpinBox_DY->SetValue(myRadius2);
129 /* signals and slots connections */
130 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
131 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
132 connect(GroupConstructors, SIGNAL(clicked(int)), this, SLOT(ConstructorsClicked(int)));
134 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
135 connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
137 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
138 connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
140 connect(GroupPoints->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
141 connect(GroupPoints->SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
142 connect(GroupDimensions->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
143 connect(GroupDimensions->SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
145 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_DX, SLOT(SetStep(double)));
146 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_DY, SLOT(SetStep(double)));
147 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DX, SLOT(SetStep(double)));
148 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DY, SLOT(SetStep(double)));
150 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
152 /* displays Dialog */
153 GroupDimensions->hide();
162 //=================================================================================
163 // function : ConstructorsClicked()
164 // purpose : Radio button management
165 //=================================================================================
166 void PrimitiveGUI_TorusDlg::ConstructorsClicked(int constructorId)
168 myConstructorId = constructorId;
169 mySelection->ClearFilters();
170 myGeomBase->EraseSimulationShape();
171 disconnect(mySelection, 0, this, 0);
175 switch(myConstructorId)
179 GroupDimensions->hide();
182 myOkPoint1 = myOkDir = false;
184 myEditCurrentArgument = GroupPoints->LineEdit1;
185 GroupPoints->LineEdit1->setText(tr(""));
186 GroupPoints->LineEdit2->setText(tr(""));
188 GroupPoints->SpinBox_DX->SetValue(myRadius1);
189 GroupPoints->SpinBox_DY->SetValue(myRadius2);
191 /* filter for next selection */
192 mySelection->AddFilter(myVertexFilter);
193 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
200 GroupDimensions->show();
201 myOkPoint1 = myOkDir = true;
203 GroupDimensions->SpinBox_DX->SetValue(myRadius1);
204 GroupDimensions->SpinBox_DY->SetValue(myRadius2);
205 myPoint1.SetCoord(0.0, 0.0, 0.0);
206 myDir.SetCoord(0.0, 0.0, 1.0);
208 MakeTorusSimulationAndDisplay();
216 //=================================================================================
217 // function : ClickOnOk()
219 //=================================================================================
220 void PrimitiveGUI_TorusDlg::ClickOnOk()
222 this->ClickOnApply();
228 //=================================================================================
229 // function : ClickOnApply()
231 //=================================================================================
232 void PrimitiveGUI_TorusDlg::ClickOnApply()
234 buttonApply->setFocus();
235 QAD_Application::getDesktop()->putInfo(tr(""));
236 if (mySimulationTopoDs.IsNull())
238 myGeomBase->EraseSimulationShape();
239 mySimulationTopoDs.Nullify();
241 if(myOkPoint1 && myOkDir)
242 myPrimitiveGUI->MakeTorusAndDisplay(myPoint1, myDir, myRadius1, myRadius2);
247 //=================================================================================
248 // function : SelectionIntoArgument()
249 // purpose : Called when selection as changed or other case
250 //=================================================================================
251 void PrimitiveGUI_TorusDlg::SelectionIntoArgument()
253 myGeomBase->EraseSimulationShape();
254 myEditCurrentArgument->setText("");
255 QString aString = ""; /* name of selection */
257 int nbSel = myGeomBase->GetNameOfSelectedIObjects(mySelection, aString);
259 if(myEditCurrentArgument == GroupPoints->LineEdit1)
261 else if(myEditCurrentArgument == GroupPoints->LineEdit2)
268 if(!myGeomBase->GetTopoFromSelection(mySelection, S))
271 /* gp_Pnt : not used */
272 if(myEditCurrentArgument == GroupPoints->LineEdit1 && myGeomBase->VertexToPoint(S, myPoint1)) {
273 GroupPoints->LineEdit1->setText(aString);
276 else if(myEditCurrentArgument == GroupPoints->LineEdit2) {
277 BRepAdaptor_Curve curv(TopoDS::Edge(S));
278 myDir = curv.Line().Direction();
279 GroupPoints->LineEdit2->setText(aString);
283 if(myOkPoint1 && myOkDir)
284 MakeTorusSimulationAndDisplay();
289 //=================================================================================
290 // function : SetEditCurrentArgument()
292 //=================================================================================
293 void PrimitiveGUI_TorusDlg::SetEditCurrentArgument()
295 if(myConstructorId != 0)
298 QPushButton* send = (QPushButton*)sender();
299 mySelection->ClearFilters();
301 if(send == GroupPoints->PushButton1) {
302 GroupPoints->LineEdit1->setFocus();
303 myEditCurrentArgument = GroupPoints->LineEdit1;
304 mySelection->AddFilter(myVertexFilter);
306 else if(send == GroupPoints->PushButton2) {
307 GroupPoints->LineEdit2->setFocus();
308 myEditCurrentArgument = GroupPoints->LineEdit2;
309 mySelection->AddFilter(myEdgeFilter);
311 this->SelectionIntoArgument();
317 //=================================================================================
318 // function : LineEditReturnPressed()
320 //=================================================================================
321 void PrimitiveGUI_TorusDlg::LineEditReturnPressed()
323 QLineEdit* send = (QLineEdit*)sender();
324 if(send == GroupPoints->LineEdit1)
325 myEditCurrentArgument = GroupPoints->LineEdit1;
326 else if (send == GroupPoints->LineEdit2)
327 myEditCurrentArgument = GroupPoints->LineEdit2;
331 GEOMBase_Skeleton::LineEditReturnPressed();
336 //=================================================================================
337 // function : ActivateThisDialog()
339 //=================================================================================
340 void PrimitiveGUI_TorusDlg::ActivateThisDialog()
342 GEOMBase_Skeleton::ActivateThisDialog();
343 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
344 if(myConstructorId == 1) {
345 GroupPoints->LineEdit1->setFocus();
346 myEditCurrentArgument = GroupPoints->LineEdit1;
347 mySelection->AddFilter(myVertexFilter);
349 if(!mySimulationTopoDs.IsNull())
350 myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
355 //=================================================================================
356 // function : enterEvent()
358 //=================================================================================
359 void PrimitiveGUI_TorusDlg::enterEvent(QEvent* e)
361 if (GroupConstructors->isEnabled())
363 this->ActivateThisDialog();
368 //=================================================================================
369 // function : ValueChangedInSpinBox
371 //=================================================================================
372 void PrimitiveGUI_TorusDlg::ValueChangedInSpinBox(double newValue)
374 myGeomBase->EraseSimulationShape();
375 mySimulationTopoDs.Nullify();
376 QObject* send = (QObject*)sender();
378 if(send == GroupPoints->SpinBox_DX || send == GroupDimensions->SpinBox_DX) {
379 if(newValue > myRadius2)
380 myRadius1 = newValue;
382 GroupPoints->SpinBox_DX->SetValue(myRadius1);
383 GroupDimensions->SpinBox_DX->SetValue(myRadius1);
386 else if(send == GroupPoints->SpinBox_DY || send == GroupDimensions->SpinBox_DY) {
387 if(newValue < myRadius1)
388 myRadius2 = newValue;
390 GroupPoints->SpinBox_DY->SetValue(myRadius2);
391 GroupDimensions->SpinBox_DY->SetValue(myRadius2);
395 if(myOkPoint1 && myOkDir)
396 MakeTorusSimulationAndDisplay();
401 //=================================================================================
402 // function : MakeTorusSimulationAndDisplay()
404 //=================================================================================
405 void PrimitiveGUI_TorusDlg::MakeTorusSimulationAndDisplay()
407 myGeomBase->EraseSimulationShape();
408 mySimulationTopoDs.Nullify();
411 gp_Ax2 anAxis(myPoint1, myDir);
412 mySimulationTopoDs = BRepPrimAPI_MakeTorus(anAxis, myRadius1, myRadius2).Shape();
413 myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
415 catch(Standard_Failure) {
416 MESSAGE("Exception catched in MakeTorusSimulationAndDisplay");