]> SALOME platform Git repositories - modules/geom.git/blob - src/PrimitiveGUI/PrimitiveGUI_TorusDlg.cxx
Salome HOME
DCQ : Merge with Ecole_Ete_a6.
[modules/geom.git] / src / PrimitiveGUI / PrimitiveGUI_TorusDlg.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_TorusDlg.cxx
25 //  Author : Lucien PIGNOLONI
26 //  Module : GEOM
27 //  $Header$
28
29 #include "PrimitiveGUI_TorusDlg.h"
30
31 #include <gp_Lin.hxx>
32 #include <BRepPrimAPI_MakeTorus.hxx>
33 #include <BRepAdaptor_Curve.hxx>
34 #include "QAD_Config.h"
35
36 #include "utilities.h"
37
38 using namespace std;
39
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)
49 {
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")));
53     
54   setCaption(tr("GEOM_TORUS_TITLE"));
55
56   /***************************************************************/
57   GroupConstructors->setTitle(tr("GEOM_TORUS"));
58   RadioButton1->setPixmap(image0);
59   RadioButton2->setPixmap(image1);
60   RadioButton3->close(TRUE);
61
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);
70
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"));
75
76   Layout1->addWidget(GroupPoints, 1, 0);
77   Layout1->addWidget(GroupDimensions, 1, 0);
78   /***************************************************************/
79
80   /* Initialisations */
81   myPrimitiveGUI = thePrimitiveGUI;
82   Init();
83 }
84
85
86 //=================================================================================
87 // function : ~PrimitiveGUI_TorusDlg()
88 // purpose  : Destroys the object and frees any allocated resources
89 //=================================================================================
90 PrimitiveGUI_TorusDlg::~PrimitiveGUI_TorusDlg()
91 {
92     // no need to delete child widgets, Qt does it all for us
93 }
94
95
96 //=================================================================================
97 // function : Init()
98 // purpose  :
99 //=================================================================================
100 void PrimitiveGUI_TorusDlg::Init()
101 {
102   /* init variables */
103   myConstructorId = 0;
104   myEditCurrentArgument = GroupPoints->LineEdit1;
105
106   myRadius1 = 300.0;
107   myRadius2 = 100.0;
108   myOkPoint1 = myOkDir = false;
109
110   myEdgeFilter = new GEOM_EdgeFilter(StdSelect_Line, myGeom);
111   myVertexFilter = new GEOM_ShapeTypeFilter(TopAbs_VERTEX, myGeom);
112   mySelection->AddFilter(myVertexFilter);
113
114   /* Get setting of step value from file configuration */
115   QString St = QAD_CONFIG->getSetting("Geometry:SettingsGeomStep");
116   step = St.toDouble();
117
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);
123
124   GroupPoints->SpinBox_DX->SetValue(myRadius1);
125   GroupPoints->SpinBox_DY->SetValue(myRadius2);
126   GroupDimensions->SpinBox_DX->SetValue(myRadius1);
127   GroupDimensions->SpinBox_DY->SetValue(myRadius2);
128
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)));
133
134   connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
135   connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
136
137   connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
138   connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
139
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)));
144
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)));
149   
150   connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
151
152   /* displays Dialog */
153   GroupDimensions->hide();
154   GroupPoints->show();
155   this->show();
156
157   return;
158 }
159
160
161
162 //=================================================================================
163 // function : ConstructorsClicked()
164 // purpose  : Radio button management
165 //=================================================================================
166 void PrimitiveGUI_TorusDlg::ConstructorsClicked(int constructorId)
167 {
168   myConstructorId = constructorId;
169   mySelection->ClearFilters();
170   myGeomBase->EraseSimulationShape();
171   disconnect(mySelection, 0, this, 0);
172   myRadius1 = 300.0;
173   myRadius2 = 100.0;
174
175   switch(myConstructorId)
176     { 
177     case 0 :
178       {
179         GroupDimensions->hide();
180         resize(0, 0);
181         GroupPoints->show();
182         myOkPoint1 = myOkDir = false;
183
184         myEditCurrentArgument = GroupPoints->LineEdit1;
185         GroupPoints->LineEdit1->setText(tr(""));
186         GroupPoints->LineEdit2->setText(tr(""));
187         
188         GroupPoints->SpinBox_DX->SetValue(myRadius1);
189         GroupPoints->SpinBox_DY->SetValue(myRadius2);
190
191         /* filter for next selection */
192         mySelection->AddFilter(myVertexFilter);
193         connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
194         break ;
195       }
196     case 1 :
197       {
198         GroupPoints->hide();
199         resize( 0, 0 );
200         GroupDimensions->show();
201         myOkPoint1 = myOkDir = true;
202
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);
207
208         MakeTorusSimulationAndDisplay();
209         break ;
210       }
211     }
212   return ;
213 }
214
215
216 //=================================================================================
217 // function : ClickOnOk()
218 // purpose  :
219 //=================================================================================
220 void PrimitiveGUI_TorusDlg::ClickOnOk()
221 {
222   this->ClickOnApply();
223   ClickOnCancel();
224   return;
225 }
226
227
228 //=================================================================================
229 // function : ClickOnApply()
230 // purpose  :
231 //=================================================================================
232 void PrimitiveGUI_TorusDlg::ClickOnApply()
233 {
234   buttonApply->setFocus();
235   QAD_Application::getDesktop()->putInfo(tr(""));
236   if (mySimulationTopoDs.IsNull())
237     return;
238   myGeomBase->EraseSimulationShape();
239   mySimulationTopoDs.Nullify();
240
241   if(myOkPoint1 && myOkDir)       
242     myPrimitiveGUI->MakeTorusAndDisplay(myPoint1, myDir, myRadius1, myRadius2); 
243   return ;
244 }
245
246
247 //=================================================================================
248 // function : SelectionIntoArgument()
249 // purpose  : Called when selection as changed or other case
250 //=================================================================================
251 void PrimitiveGUI_TorusDlg::SelectionIntoArgument()
252 {
253   myGeomBase->EraseSimulationShape(); 
254   myEditCurrentArgument->setText("");
255   QString aString = ""; /* name of selection */
256   
257   int nbSel = myGeomBase->GetNameOfSelectedIObjects(mySelection, aString);
258   if(nbSel != 1) {
259     if(myEditCurrentArgument == GroupPoints->LineEdit1)
260       myOkPoint1 = false;
261     else if(myEditCurrentArgument == GroupPoints->LineEdit2)
262       myOkDir = false;
263     return;
264   }
265
266   /* nbSel == 1 */
267   TopoDS_Shape S;  
268   if(!myGeomBase->GetTopoFromSelection(mySelection, S))
269     return;  
270  
271   /*  gp_Pnt : not used */
272   if(myEditCurrentArgument == GroupPoints->LineEdit1 && myGeomBase->VertexToPoint(S, myPoint1)) {
273     GroupPoints->LineEdit1->setText(aString);
274     myOkPoint1 = true;
275   }    
276   else if(myEditCurrentArgument == GroupPoints->LineEdit2) {
277     BRepAdaptor_Curve curv(TopoDS::Edge(S));
278     myDir = curv.Line().Direction();
279     GroupPoints->LineEdit2->setText(aString);
280     myOkDir = true;
281   }
282
283   if(myOkPoint1 && myOkDir)
284     MakeTorusSimulationAndDisplay();
285   return;
286 }
287
288
289 //=================================================================================
290 // function : SetEditCurrentArgument()
291 // purpose  :
292 //=================================================================================
293 void PrimitiveGUI_TorusDlg::SetEditCurrentArgument()
294 {
295   if(myConstructorId != 0)
296     return;
297
298   QPushButton* send = (QPushButton*)sender();
299   mySelection->ClearFilters();
300
301   if(send == GroupPoints->PushButton1) {
302     GroupPoints->LineEdit1->setFocus();
303     myEditCurrentArgument = GroupPoints->LineEdit1;
304     mySelection->AddFilter(myVertexFilter);
305   }
306   else if(send == GroupPoints->PushButton2) {
307     GroupPoints->LineEdit2->setFocus();
308     myEditCurrentArgument = GroupPoints->LineEdit2;
309     mySelection->AddFilter(myEdgeFilter);
310   }
311   this->SelectionIntoArgument();
312
313   return;
314 }
315
316
317 //=================================================================================
318 // function : LineEditReturnPressed()
319 // purpose  :
320 //=================================================================================
321 void PrimitiveGUI_TorusDlg::LineEditReturnPressed()
322 {  
323   QLineEdit* send = (QLineEdit*)sender();
324   if(send == GroupPoints->LineEdit1)
325     myEditCurrentArgument = GroupPoints->LineEdit1;
326   else if (send == GroupPoints->LineEdit2)
327     myEditCurrentArgument = GroupPoints->LineEdit2;
328   else
329     return;
330
331   GEOMBase_Skeleton::LineEditReturnPressed();
332   return;
333 }
334
335
336 //=================================================================================
337 // function : ActivateThisDialog()
338 // purpose  :
339 //=================================================================================
340 void PrimitiveGUI_TorusDlg::ActivateThisDialog()
341 {
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);
348   }
349   if(!mySimulationTopoDs.IsNull())
350     myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
351   return;
352 }
353
354
355 //=================================================================================
356 // function : enterEvent()
357 // purpose  :
358 //=================================================================================
359 void PrimitiveGUI_TorusDlg::enterEvent(QEvent* e)
360 {
361   if (GroupConstructors->isEnabled())
362     return;
363   this->ActivateThisDialog();
364   return;
365 }
366
367
368 //=================================================================================
369 // function : ValueChangedInSpinBox
370 // purpose  :
371 //=================================================================================
372 void PrimitiveGUI_TorusDlg::ValueChangedInSpinBox(double newValue)
373 {
374   myGeomBase->EraseSimulationShape();
375   mySimulationTopoDs.Nullify();
376   QObject* send = (QObject*)sender();
377   
378   if(send == GroupPoints->SpinBox_DX || send == GroupDimensions->SpinBox_DX) {
379     if(newValue > myRadius2)
380       myRadius1 = newValue;
381     else {
382       GroupPoints->SpinBox_DX->SetValue(myRadius1);
383       GroupDimensions->SpinBox_DX->SetValue(myRadius1);
384     }
385   }
386   else if(send == GroupPoints->SpinBox_DY || send == GroupDimensions->SpinBox_DY) {
387     if(newValue < myRadius1)
388       myRadius2 = newValue;
389     else {
390       GroupPoints->SpinBox_DY->SetValue(myRadius2);
391       GroupDimensions->SpinBox_DY->SetValue(myRadius2);
392     }
393   }
394   
395   if(myOkPoint1 && myOkDir)
396     MakeTorusSimulationAndDisplay();
397   return;
398 }
399
400
401 //=================================================================================
402 // function : MakeTorusSimulationAndDisplay()
403 // purpose  :
404 //=================================================================================
405 void PrimitiveGUI_TorusDlg::MakeTorusSimulationAndDisplay() 
406 {
407   myGeomBase->EraseSimulationShape();
408   mySimulationTopoDs.Nullify();
409
410   try {
411     gp_Ax2 anAxis(myPoint1, myDir);
412     mySimulationTopoDs = BRepPrimAPI_MakeTorus(anAxis, myRadius1, myRadius2).Shape();
413     myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
414   }
415   catch(Standard_Failure) {
416     MESSAGE("Exception catched in MakeTorusSimulationAndDisplay");
417   }
418   return;
419 }