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
30 #include "PrimitiveGUI_TorusDlg.h"
33 #include <BRepPrimAPI_MakeTorus.hxx>
34 #include <BRepAdaptor_Curve.hxx>
35 #include "QAD_Config.h"
37 //=================================================================================
38 // class : PrimitiveGUI_TorusDlg()
39 // purpose : Constructs a PrimitiveGUI_TorusDlg which is a child of 'parent', with the
40 // name 'name' and widget flags set to 'f'.
41 // The dialog will by default be modeless, unless you set 'modal' to
42 // TRUE to construct a modal dialog.
43 //=================================================================================
44 PrimitiveGUI_TorusDlg::PrimitiveGUI_TorusDlg(QWidget* parent, const char* name, PrimitiveGUI* thePrimitiveGUI, SALOME_Selection* Sel, bool modal, WFlags fl)
45 :GEOMBase_Skeleton(parent, name, Sel, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
47 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_TORUS_PV")));
48 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_TORUS_DXYZ")));
49 QPixmap image2(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_SELECT")));
51 setCaption(tr("GEOM_TORUS_TITLE"));
53 /***************************************************************/
54 GroupConstructors->setTitle(tr("GEOM_TORUS"));
55 RadioButton1->setPixmap(image0);
56 RadioButton2->setPixmap(image1);
57 RadioButton3->close(TRUE);
59 GroupPoints = new DlgRef_2Sel2Spin(this, "GroupPoints");
60 GroupPoints->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
61 GroupPoints->TextLabel1->setText(tr("GEOM_BASE_POINT"));
62 GroupPoints->TextLabel2->setText(tr("GEOM_VECTOR"));
63 GroupPoints->TextLabel3->setText(tr("GEOM_RADIUS_I").arg("1"));
64 GroupPoints->TextLabel4->setText(tr("GEOM_RADIUS_I").arg("2"));
65 GroupPoints->PushButton1->setPixmap(image2);
66 GroupPoints->PushButton2->setPixmap(image2);
68 GroupDimensions = new DlgRef_2Spin(this, "GroupDimensions");
69 GroupDimensions->GroupBox1->setTitle(tr("GEOM_BOX_OBJ"));
70 GroupDimensions->TextLabel1->setText(tr("GEOM_RADIUS_I").arg("1"));
71 GroupDimensions->TextLabel2->setText(tr("GEOM_RADIUS_I").arg("2"));
73 Layout1->addWidget(GroupPoints, 1, 0);
74 Layout1->addWidget(GroupDimensions, 1, 0);
75 /***************************************************************/
78 myPrimitiveGUI = thePrimitiveGUI;
83 //=================================================================================
84 // function : ~PrimitiveGUI_TorusDlg()
85 // purpose : Destroys the object and frees any allocated resources
86 //=================================================================================
87 PrimitiveGUI_TorusDlg::~PrimitiveGUI_TorusDlg()
89 // no need to delete child widgets, Qt does it all for us
93 //=================================================================================
96 //=================================================================================
97 void PrimitiveGUI_TorusDlg::Init()
101 myEditCurrentArgument = GroupPoints->LineEdit1;
105 myOkRadius1 = myOkRadius2 = true;
106 myOkPoint1 = myOkDir = false;
108 myEdgeFilter = new GEOM_EdgeFilter(StdSelect_Line, myGeom);
109 myVertexFilter = new GEOM_ShapeTypeFilter(TopAbs_VERTEX, myGeom);
110 mySelection->AddFilter(myVertexFilter);
112 /* Get setting of step value from file configuration */
113 QString St = QAD_CONFIG->getSetting("Geometry:SettingsGeomStep");
114 step = St.toDouble();
116 /* min, max, step and decimals for spin boxes & initial values */
117 GroupPoints->SpinBox_DX->RangeStepAndValidator(0.001, 999.999, step, 3);
118 GroupPoints->SpinBox_DY->RangeStepAndValidator(0.001, 999.999, step, 3);
119 GroupDimensions->SpinBox_DX->RangeStepAndValidator(0.001, 999.999, step, 3);
120 GroupDimensions->SpinBox_DY->RangeStepAndValidator(0.001, 999.999, step, 3);
122 GroupPoints->SpinBox_DX->SetValue(myRadius1);
123 GroupPoints->SpinBox_DY->SetValue(myRadius2);
124 GroupDimensions->SpinBox_DX->SetValue(myRadius1);
125 GroupDimensions->SpinBox_DY->SetValue(myRadius2);
127 /* signals and slots connections */
128 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
129 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
130 connect(GroupConstructors, SIGNAL(clicked(int)), this, SLOT(ConstructorsClicked(int)));
132 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
133 connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
135 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
136 connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
138 connect(GroupPoints->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
139 connect(GroupPoints->SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
140 connect(GroupDimensions->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
141 connect(GroupDimensions->SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
143 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_DX, SLOT(SetStep(double)));
144 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_DY, SLOT(SetStep(double)));
145 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DX, SLOT(SetStep(double)));
146 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DY, SLOT(SetStep(double)));
148 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
150 /* displays Dialog */
151 GroupDimensions->hide();
160 //=================================================================================
161 // function : ConstructorsClicked()
162 // purpose : Radio button management
163 //=================================================================================
164 void PrimitiveGUI_TorusDlg::ConstructorsClicked(int constructorId)
166 myConstructorId = constructorId;
167 mySelection->ClearFilters();
168 myGeomBase->EraseSimulationShape();
169 disconnect(mySelection, 0, this, 0);
170 myOkRadius1 = myOkRadius2 = true;
174 switch(myConstructorId)
178 GroupDimensions->hide();
181 myOkPoint1 = myOkDir = false;
183 myEditCurrentArgument = GroupPoints->LineEdit1;
184 GroupPoints->LineEdit1->setText(tr(""));
185 GroupPoints->LineEdit2->setText(tr(""));
187 GroupPoints->SpinBox_DX->SetValue(myRadius1);
188 GroupPoints->SpinBox_DY->SetValue(myRadius2);
190 /* filter for next selection */
191 mySelection->AddFilter(myVertexFilter);
192 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
199 GroupDimensions->show();
200 myOkPoint1 = myOkDir = true;
202 GroupDimensions->SpinBox_DX->SetValue(myRadius1);
203 GroupDimensions->SpinBox_DY->SetValue(myRadius2);
204 myPoint1.SetCoord(0.0, 0.0, 0.0);
205 myDir.SetCoord(0.0, 0.0, 1.0);
207 MakeTorusSimulationAndDisplay();
215 //=================================================================================
216 // function : ClickOnOk()
218 //=================================================================================
219 void PrimitiveGUI_TorusDlg::ClickOnOk()
221 this->ClickOnApply();
227 //=================================================================================
228 // function : ClickOnApply()
230 //=================================================================================
231 void PrimitiveGUI_TorusDlg::ClickOnApply()
233 QAD_Application::getDesktop()->putInfo(tr(""));
234 if (mySimulationTopoDs.IsNull())
236 myGeomBase->EraseSimulationShape();
237 mySimulationTopoDs.Nullify();
239 if(myOkPoint1 && myOkDir && myOkRadius1 && myOkRadius2 )
240 myPrimitiveGUI->MakeTorusAndDisplay(myPoint1, myDir, myRadius1, myRadius2);
245 //=================================================================================
246 // function : SelectionIntoArgument()
247 // purpose : Called when selection as changed or other case
248 //=================================================================================
249 void PrimitiveGUI_TorusDlg::SelectionIntoArgument()
251 myGeomBase->EraseSimulationShape();
252 myEditCurrentArgument->setText("");
253 QString aString = ""; /* name of selection */
255 int nbSel = myGeomBase->GetNameOfSelectedIObjects(mySelection, aString);
257 if(myEditCurrentArgument == GroupPoints->LineEdit1)
259 else if(myEditCurrentArgument == GroupPoints->LineEdit2)
266 if(!myGeomBase->GetTopoFromSelection(mySelection, S))
269 /* gp_Pnt : not used */
270 if(myEditCurrentArgument == GroupPoints->LineEdit1 && myGeomBase->VertexToPoint(S, myPoint1)) {
271 GroupPoints->LineEdit1->setText(aString);
274 else if(myEditCurrentArgument == GroupPoints->LineEdit2) {
275 BRepAdaptor_Curve curv(TopoDS::Edge(S));
276 myDir = curv.Line().Direction();
277 GroupPoints->LineEdit2->setText(aString);
281 if(myOkPoint1 && myOkDir && myOkRadius1 && myOkRadius2)
282 MakeTorusSimulationAndDisplay();
287 //=================================================================================
288 // function : SetEditCurrentArgument()
290 //=================================================================================
291 void PrimitiveGUI_TorusDlg::SetEditCurrentArgument()
293 if(myConstructorId != 0)
296 QPushButton* send = (QPushButton*)sender();
297 mySelection->ClearFilters();
299 if(send == GroupPoints->PushButton1) {
300 GroupPoints->LineEdit1->setFocus();
301 myEditCurrentArgument = GroupPoints->LineEdit1;
302 mySelection->AddFilter(myVertexFilter);
304 else if(send == GroupPoints->PushButton2) {
305 GroupPoints->LineEdit2->setFocus();
306 myEditCurrentArgument = GroupPoints->LineEdit2;
307 mySelection->AddFilter(myEdgeFilter);
309 this->SelectionIntoArgument();
315 //=================================================================================
316 // function : LineEditReturnPressed()
318 //=================================================================================
319 void PrimitiveGUI_TorusDlg::LineEditReturnPressed()
321 QLineEdit* send = (QLineEdit*)sender();
322 if(send == GroupPoints->LineEdit1)
323 myEditCurrentArgument = GroupPoints->LineEdit1;
324 else if (send == GroupPoints->LineEdit2)
325 myEditCurrentArgument = GroupPoints->LineEdit2;
329 GEOMBase_Skeleton::LineEditReturnPressed();
334 //=================================================================================
335 // function : ActivateThisDialog()
337 //=================================================================================
338 void PrimitiveGUI_TorusDlg::ActivateThisDialog()
340 GEOMBase_Skeleton::ActivateThisDialog();
341 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
342 if(myConstructorId == 1) {
343 GroupPoints->LineEdit1->setFocus();
344 myEditCurrentArgument = GroupPoints->LineEdit1;
345 mySelection->AddFilter(myVertexFilter);
347 if(!mySimulationTopoDs.IsNull())
348 myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
353 //=================================================================================
354 // function : enterEvent()
356 //=================================================================================
357 void PrimitiveGUI_TorusDlg::enterEvent(QEvent* e)
359 if (GroupConstructors->isEnabled())
361 this->ActivateThisDialog();
366 //=================================================================================
367 // function : ValueChangedInSpinBox
369 //=================================================================================
370 void PrimitiveGUI_TorusDlg::ValueChangedInSpinBox(double newValue)
372 myGeomBase->EraseSimulationShape();
373 mySimulationTopoDs.Nullify();
374 QObject* send = (QObject*)sender();
376 if(send == GroupPoints->SpinBox_DX || send == GroupDimensions->SpinBox_DX) {
377 myRadius1 = newValue;
380 else if(send == GroupPoints->SpinBox_DY || send == GroupDimensions->SpinBox_DY) {
381 myRadius2 = newValue;
385 if(myOkPoint1 && myOkDir && myOkRadius1 && myOkRadius2)
386 MakeTorusSimulationAndDisplay();
391 //=================================================================================
392 // function : MakeTorusSimulationAndDisplay()
394 //=================================================================================
395 void PrimitiveGUI_TorusDlg::MakeTorusSimulationAndDisplay()
397 myGeomBase->EraseSimulationShape();
398 mySimulationTopoDs.Nullify();
401 gp_Ax2 anAxis(myPoint1, myDir);
402 mySimulationTopoDs = BRepPrimAPI_MakeTorus(anAxis, myRadius1, myRadius2).Shape();
403 myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
405 catch(Standard_Failure) {
406 MESSAGE("Exception catched in MakeTorusSimulationAndDisplay");