]> SALOME platform Git repositories - modules/geom.git/blob - src/PrimitiveGUI/PrimitiveGUI_ConeDlg.cxx
Salome HOME
f9af4748de9a503a28ec4547259ed1a965c190e2
[modules/geom.git] / src / PrimitiveGUI / PrimitiveGUI_ConeDlg.cxx
1 //  GEOM GEOMGUI : GUI for Geometry component
2 //
3 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
5 // 
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. 
10 // 
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. 
15 // 
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 
19 // 
20 //  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //
24 //  File   : PrimitiveGUI_ConeDlg.cxx
25 //  Author : Lucien PIGNOLONI
26 //  Module : GEOM
27 //  $Header$
28
29 #include "PrimitiveGUI_ConeDlg.h"
30
31 #include <gp_Lin.hxx>
32 #include <BRepPrimAPI_MakeCone.hxx>
33 #include <BRepPrimAPI_MakeCylinder.hxx>
34 #include <BRepAdaptor_Curve.hxx>
35 #include <Precision.hxx>
36 #include "QAD_Config.h"
37
38 #include "utilities.h"
39
40 using namespace std;
41
42 //=================================================================================
43 // class    : PrimitiveGUI_ConeDlg()
44 // purpose  : Constructs a PrimitiveGUI_ConeDlg which is a child of 'parent', with the 
45 //            name 'name' and widget flags set to 'f'.
46 //            The dialog will by default be modeless, unless you set 'modal' to
47 //            TRUE to construct a modal dialog.
48 //=================================================================================
49 PrimitiveGUI_ConeDlg::PrimitiveGUI_ConeDlg(QWidget* parent, const char* name, PrimitiveGUI* thePrimitiveGUI, SALOME_Selection* Sel, bool modal, WFlags fl)
50   :GEOMBase_Skeleton(parent, name, Sel, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
51 {
52   QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_CONE_PV")));
53   QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_CONE_DXYZ")));
54   QPixmap image2(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_SELECT")));
55
56   setCaption(tr("GEOM_CONE_TITLE"));
57
58   /***************************************************************/
59   GroupConstructors->setTitle(tr("GEOM_CONE"));
60   RadioButton1->setPixmap(image0);
61   RadioButton2->setPixmap(image1);
62   RadioButton3->close(TRUE);
63
64   GroupPoints = new DlgRef_2Sel3Spin(this, "GroupPoints");
65   GroupPoints->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
66   GroupPoints->TextLabel1->setText(tr("GEOM_BASE_POINT"));
67   GroupPoints->TextLabel2->setText(tr("GEOM_VECTOR"));
68   GroupPoints->TextLabel3->setText(tr("GEOM_RADIUS_I").arg("1"));
69   GroupPoints->TextLabel4->setText(tr("GEOM_RADIUS_I").arg("2"));
70   GroupPoints->TextLabel5->setText(tr("GEOM_HEIGHT"));
71   GroupPoints->PushButton1->setPixmap(image2);
72   GroupPoints->PushButton2->setPixmap(image2);
73
74   GroupDimensions = new DlgRef_3Spin(this, "GroupDimensions");
75   GroupDimensions->GroupBox1->setTitle(tr("GEOM_BOX_OBJ"));
76   GroupDimensions->TextLabel1->setText(tr("GEOM_RADIUS_I").arg("1"));
77   GroupDimensions->TextLabel2->setText(tr("GEOM_RADIUS_I").arg("2"));
78   GroupDimensions->TextLabel3->setText(tr("GEOM_HEIGHT"));
79
80   Layout1->addWidget(GroupPoints, 1, 0);
81   Layout1->addWidget(GroupDimensions, 1, 0);
82   /***************************************************************/
83
84   /* Initialisations */
85   myPrimitiveGUI = thePrimitiveGUI;
86   Init();
87 }
88
89
90 //=================================================================================
91 // function : ~PrimitiveGUI_ConeDlg()
92 // purpose  : Destroys the object and frees any allocated resources
93 //=================================================================================
94 PrimitiveGUI_ConeDlg::~PrimitiveGUI_ConeDlg()
95 {
96     // no need to delete child widgets, Qt does it all for us
97 }
98
99
100 //=================================================================================
101 // function : Init()
102 // purpose  :
103 //=================================================================================
104 void PrimitiveGUI_ConeDlg::Init()
105 {
106   /* init variables */
107   myConstructorId = 0;
108   myEditCurrentArgument = GroupPoints->LineEdit1;
109
110   myRadius1 = 100.0;
111   myRadius2 = 0.0;
112   myHeight = 300.0;
113
114   myOkRadius1 = myOkRadius2 = myOkHeight = true;
115   myOkPoint1 = myOkDir = false;
116
117   myEdgeFilter = new GEOM_EdgeFilter(StdSelect_Line, myGeom);
118   myVertexFilter = new GEOM_ShapeTypeFilter(TopAbs_VERTEX, myGeom);
119   mySelection->AddFilter(myVertexFilter);
120
121   /* Get setting of step value from file configuration */
122   QString St = QAD_CONFIG->getSetting("Geometry:SettingsGeomStep");
123   step = St.toDouble();
124
125   /* min, max, step and decimals for spin boxes & initial values */
126   GroupPoints->SpinBox_DX->RangeStepAndValidator(0.000, 999.999, step, 3);
127   GroupPoints->SpinBox_DY->RangeStepAndValidator(0.000, 999.999, step, 3);
128   GroupPoints->SpinBox_DZ->RangeStepAndValidator(-999.999, 999.999, step, 3);
129   GroupDimensions->SpinBox_DX->RangeStepAndValidator(0.000, 999.999, step, 3);
130   GroupDimensions->SpinBox_DY->RangeStepAndValidator(0.000, 999.999, step, 3);
131   GroupDimensions->SpinBox_DZ->RangeStepAndValidator(-999.999, 999.999, step, 3);
132
133   GroupPoints->SpinBox_DX->SetValue(myRadius1);
134   GroupPoints->SpinBox_DY->SetValue(myRadius2);
135   GroupPoints->SpinBox_DZ->SetValue(myHeight);
136   GroupDimensions->SpinBox_DX->SetValue(myRadius1);
137   GroupDimensions->SpinBox_DY->SetValue(myRadius2);
138   GroupDimensions->SpinBox_DZ->SetValue(myHeight);
139
140   /* signals and slots connections */
141   connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
142   connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
143   connect(GroupConstructors, SIGNAL(clicked(int)), this, SLOT(ConstructorsClicked(int)));
144
145   connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
146   connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
147
148   connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
149   connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
150
151   connect(GroupPoints->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
152   connect(GroupPoints->SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
153   connect(GroupPoints->SpinBox_DZ, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
154   connect(GroupDimensions->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
155   connect(GroupDimensions->SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
156   connect(GroupDimensions->SpinBox_DZ, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
157
158   connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_DX, SLOT(SetStep(double)));
159   connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_DY, SLOT(SetStep(double)));
160   connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_DZ, SLOT(SetStep(double)));
161   connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DX, SLOT(SetStep(double)));
162   connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DY, SLOT(SetStep(double)));
163   connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DZ, SLOT(SetStep(double)));
164   
165   connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
166
167   /* displays Dialog */
168   GroupDimensions->hide();
169   GroupPoints->show();
170   this->show();
171
172   return ;
173 }
174
175
176 //=================================================================================
177 // function : ConstructorsClicked()
178 // purpose  : Radio button management
179 //=================================================================================
180 void PrimitiveGUI_ConeDlg::ConstructorsClicked(int constructorId)
181 {
182   myConstructorId = constructorId;
183   mySelection->ClearFilters();
184   myGeomBase->EraseSimulationShape();
185   disconnect(mySelection, 0, this, 0);
186   myOkHeight = myOkRadius1 = myOkRadius2 = true;
187   myRadius1 = 100.0;
188   myRadius2 = 0.0;
189   myHeight = 300.0;
190
191   switch(myConstructorId)
192     { 
193     case 0 :
194       {
195         GroupDimensions->hide();
196         resize(0, 0);
197         GroupPoints->show();
198         myOkPoint1 = myOkDir = false;
199
200         myEditCurrentArgument = GroupPoints->LineEdit1;
201         GroupPoints->LineEdit1->setText(tr(""));
202         GroupPoints->LineEdit2->setText(tr(""));
203         
204         GroupPoints->SpinBox_DX->SetValue(myRadius1);
205         GroupPoints->SpinBox_DY->SetValue(myRadius2);
206         GroupPoints->SpinBox_DZ->SetValue(myHeight);
207
208         /* filter for next selection */
209         mySelection->AddFilter(myVertexFilter);
210         connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
211         break;
212       }
213     case 1 :
214       { 
215         GroupPoints->hide();
216         resize( 0, 0 );
217         GroupDimensions->show();
218         myOkPoint1 = myOkDir = true;
219
220         GroupDimensions->SpinBox_DX->SetValue(myRadius1);
221         GroupDimensions->SpinBox_DY->SetValue(myRadius2);
222         GroupDimensions->SpinBox_DZ->SetValue(myHeight);
223
224         myPoint1.SetCoord(0.0, 0.0, 0.0);
225         myDir.SetCoord(0.0, 0.0, 1.0);
226
227         MakeConeSimulationAndDisplay();
228         break;
229       }
230     }
231   return ;
232 }
233
234
235 //=================================================================================
236 // function : ClickOnOk()
237 // purpose  :
238 //=================================================================================
239 void PrimitiveGUI_ConeDlg::ClickOnOk()
240 {
241   this->ClickOnApply();
242   ClickOnCancel();
243   return;
244 }
245
246
247 //=================================================================================
248 // function : ClickOnApply()
249 // purpose  :
250 //=================================================================================
251 void PrimitiveGUI_ConeDlg::ClickOnApply()
252 {
253   buttonApply->setFocus();
254   QAD_Application::getDesktop()->putInfo(tr(""));
255   if (mySimulationTopoDs.IsNull())
256     return;
257   myGeomBase->EraseSimulationShape();
258   mySimulationTopoDs.Nullify();
259  
260   if(myOkPoint1 && myOkDir && myOkRadius1 && myOkRadius2 && myOkHeight) {
261     gp_Dir aDir = myDir;
262     /* allows user to reverse direction of construction with a negative height */
263     if(this->myHeight < -Precision::Confusion())
264       aDir.Reverse();
265     myPrimitiveGUI->MakeConeAndDisplay(myPoint1, aDir, myRadius1, myRadius2, fabs(myHeight)); 
266   }
267   return ;
268 }
269
270
271 //=================================================================================
272 // function : SelectionIntoArgument()
273 // purpose  : Called when selection as changed or other case
274 //=================================================================================
275 void PrimitiveGUI_ConeDlg::SelectionIntoArgument()
276 {
277   myGeomBase->EraseSimulationShape(); 
278   myEditCurrentArgument->setText("");
279   QString aString = ""; /* name of selection */
280
281   int nbSel = myGeomBase->GetNameOfSelectedIObjects(mySelection, aString);
282   if(nbSel != 1) {
283     if(myEditCurrentArgument == GroupPoints->LineEdit1)
284       myOkPoint1 = false;
285     else if (myEditCurrentArgument == GroupPoints->LineEdit2)
286       myOkDir = false;
287     return;
288   }
289
290   /* nbSel == 1 */
291   TopoDS_Shape S;
292   if(!myGeomBase->GetTopoFromSelection(mySelection, S))
293     return;
294
295   /*  gp_Pnt : not used */
296   if (myEditCurrentArgument == GroupPoints->LineEdit1 && myGeomBase->VertexToPoint(S, myPoint1)) {
297     GroupPoints->LineEdit1->setText(aString);
298     myOkPoint1 = true;
299   }    
300   else if (myEditCurrentArgument == GroupPoints->LineEdit2) {
301     BRepAdaptor_Curve curv(TopoDS::Edge(S));
302     myDir = curv.Line().Direction();
303     GroupPoints->LineEdit2->setText(aString);
304     myOkDir = true;
305   }
306
307   if(myOkPoint1 && myOkDir && myOkRadius1 && myOkRadius2 && myOkHeight)
308     MakeConeSimulationAndDisplay();
309   return;
310 }
311
312
313 //=================================================================================
314 // function : SetEditCurrentArgument()
315 // purpose  :
316 //=================================================================================
317 void PrimitiveGUI_ConeDlg::SetEditCurrentArgument()
318 {
319   if(myConstructorId != 0)
320     return;
321
322   QPushButton* send = (QPushButton*)sender();
323   mySelection->ClearFilters();
324
325   if(send == GroupPoints->PushButton1) {
326     GroupPoints->LineEdit1->setFocus();
327     myEditCurrentArgument = GroupPoints->LineEdit1;
328     mySelection->AddFilter(myVertexFilter);
329   }
330   else if(send == GroupPoints->PushButton2) {
331     GroupPoints->LineEdit2->setFocus();
332     myEditCurrentArgument = GroupPoints->LineEdit2;
333     mySelection->AddFilter(myEdgeFilter);
334   }
335   this->SelectionIntoArgument();
336
337   return;
338 }
339
340
341 //=================================================================================
342 // function : LineEditReturnPressed()
343 // purpose  :
344 //=================================================================================
345 void PrimitiveGUI_ConeDlg::LineEditReturnPressed()
346 {
347   QLineEdit* send = (QLineEdit*)sender();
348   if(send == GroupPoints->LineEdit1)
349     myEditCurrentArgument = GroupPoints->LineEdit1;
350   else if (send == GroupPoints->LineEdit2)
351     myEditCurrentArgument = GroupPoints->LineEdit2;
352   else
353     return;
354
355   GEOMBase_Skeleton::LineEditReturnPressed();
356   return;
357 }
358
359
360 //=================================================================================
361 // function : ActivateThisDialog()
362 // purpose  :
363 //=================================================================================
364 void PrimitiveGUI_ConeDlg::ActivateThisDialog()
365 {
366   GEOMBase_Skeleton::ActivateThisDialog();
367   connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
368   if(myConstructorId == 0) {
369     GroupPoints->LineEdit1->setFocus();
370     myEditCurrentArgument = GroupPoints->LineEdit1;
371     mySelection->AddFilter(myVertexFilter);
372   }
373   if(!mySimulationTopoDs.IsNull())
374     myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
375   return;
376 }
377
378
379 //=================================================================================
380 // function : enterEvent()
381 // purpose  :
382 //=================================================================================
383 void PrimitiveGUI_ConeDlg::enterEvent(QEvent* e)
384 {
385   if (GroupConstructors->isEnabled())
386     return;
387   this->ActivateThisDialog();
388   return;
389 }
390
391
392 //=================================================================================
393 // function : ValueChangedInSpinBox()
394 // purpose  :
395 //=================================================================================
396 void PrimitiveGUI_ConeDlg::ValueChangedInSpinBox(double newValue)
397 {
398   myGeomBase->EraseSimulationShape();
399   mySimulationTopoDs.Nullify();
400   QObject* send = (QObject*)sender();
401   
402   if(send == GroupPoints->SpinBox_DX || send == GroupDimensions->SpinBox_DX) {
403     myRadius1 = newValue;
404     myOkRadius1 = true;
405   }
406   else if(send == GroupPoints->SpinBox_DY || send == GroupDimensions->SpinBox_DY) {
407     myRadius2 = newValue;
408     myOkRadius2 = true;
409   }
410   else if(send == GroupPoints->SpinBox_DZ || send == GroupDimensions->SpinBox_DZ) {
411     myHeight = newValue;
412     myOkHeight = true;
413   }
414
415   if (myOkPoint1 && myOkDir && myOkRadius1 && myOkRadius2 && myOkHeight)
416     MakeConeSimulationAndDisplay();
417   return;
418 }
419
420
421 //=================================================================================
422 // function : MakeConeSimulationAndDisplay()
423 // purpose  :
424 //=================================================================================
425 void PrimitiveGUI_ConeDlg::MakeConeSimulationAndDisplay() 
426 {
427   myGeomBase->EraseSimulationShape();
428   mySimulationTopoDs.Nullify();
429   gp_Dir aDir = myDir;
430   
431   try {
432     /* allows user to reverse direction of construction with a negative height */
433     if(this->myHeight < -Precision::Confusion())
434       aDir.Reverse();
435
436     gp_Ax2 anAxis(this->myPoint1, aDir);
437
438     if(fabs(myRadius1 - myRadius2) <= Precision::Confusion())
439       mySimulationTopoDs = BRepPrimAPI_MakeCylinder(anAxis, (myRadius1+myRadius2)/2.0, fabs(myHeight)).Shape();
440     else {
441       if(fabs(myHeight) > Precision::Confusion())
442         mySimulationTopoDs = BRepPrimAPI_MakeCone(anAxis, myRadius1, myRadius2, fabs(myHeight)).Shape();
443     }
444     myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
445   }
446   catch(Standard_Failure) {
447     MESSAGE("Exception catched in MakeConeSimulationAndDisplay");
448   }
449   return;
450 }