]> SALOME platform Git repositories - modules/geom.git/blob - src/PrimitiveGUI/PrimitiveGUI_CylinderDlg.cxx
Salome HOME
Modified a method createAndDisplayGO
[modules/geom.git] / src / PrimitiveGUI / PrimitiveGUI_CylinderDlg.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_CylinderDlg.cxx
25 //  Author : Lucien PIGNOLONI
26 //  Module : GEOM
27 //  $Header$
28
29 #include "PrimitiveGUI_CylinderDlg.h"
30
31 #include "SUIT_Desktop.h"
32 #include "SUIT_Session.h"
33 #include "SalomeApp_Application.h"
34 #include "SalomeApp_SelectionMgr.h"
35
36 #include <qlabel.h>
37
38 #include "GEOMImpl_Types.hxx"
39
40 #include "utilities.h"
41
42 using namespace std;
43
44 //=================================================================================
45 // class    : PrimitiveGUI_CylinderDlg()
46 // purpose  : Constructs a PrimitiveGUI_CylinderDlg which is a child of 'parent', with the 
47 //            name 'name' and widget flags set to 'f'.
48 //            The dialog will by default be modeless, unless you set 'modal' to
49 //            TRUE to construct a modal dialog.
50 //=================================================================================
51 PrimitiveGUI_CylinderDlg::PrimitiveGUI_CylinderDlg(GeometryGUI* theGeometryGUI, QWidget* parent, const char* name, bool modal, WFlags fl)
52   :GEOMBase_Skeleton(parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu), myGeometryGUI(theGeometryGUI)
53 {
54   QPixmap image0(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_CYLINDER_PV")));
55   QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_CYLINDER_DXYZ")));
56   QPixmap image2(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_SELECT")));
57
58   setCaption(tr("GEOM_CYLINDER_TITLE"));
59
60   /***************************************************************/
61   GroupConstructors->setTitle(tr("GEOM_CYLINDER"));
62   RadioButton1->setPixmap(image0);
63   RadioButton2->setPixmap(image1);
64   RadioButton3->close(TRUE);
65
66   GroupPoints = new DlgRef_2Sel2Spin(this, "GroupPoints");
67   GroupPoints->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
68   GroupPoints->TextLabel1->setText(tr("GEOM_BASE_POINT"));
69   GroupPoints->TextLabel2->setText(tr("GEOM_VECTOR"));
70   GroupPoints->TextLabel3->setText(tr("GEOM_RADIUS"));
71   GroupPoints->TextLabel4->setText(tr("GEOM_HEIGHT"));
72   GroupPoints->PushButton1->setPixmap(image2);
73   GroupPoints->PushButton2->setPixmap(image2);
74
75   GroupDimensions = new DlgRef_2Spin(this, "GroupDimensions");
76   GroupDimensions->GroupBox1->setTitle(tr("GEOM_BOX_OBJ"));
77   GroupDimensions->TextLabel1->setText(tr("GEOM_RADIUS"));
78   GroupDimensions->TextLabel2->setText(tr("GEOM_HEIGHT"));
79
80   Layout1->addWidget(GroupPoints, 2, 0);
81   Layout1->addWidget(GroupDimensions, 2, 0);
82   /***************************************************************/
83
84   Init();
85 }
86
87
88 //=================================================================================
89 // function : ~PrimitiveGUI_CylinderDlg()
90 // purpose  : Destroys the object and frees any allocated resources
91 //=================================================================================
92 PrimitiveGUI_CylinderDlg::~PrimitiveGUI_CylinderDlg()
93 {
94     // no need to delete child widgets, Qt does it all for us
95 }
96
97
98 //=================================================================================
99 // function : Init()
100 // purpose  :
101 //=================================================================================
102 void PrimitiveGUI_CylinderDlg::Init()
103 {
104   /* init variables */
105   myEditCurrentArgument = GroupPoints->LineEdit1;
106   GroupPoints->LineEdit1->setReadOnly( true );
107   GroupPoints->LineEdit2->setReadOnly( true );
108
109   myPoint = myDir = GEOM::GEOM_Object::_nil();
110   
111   /* Get setting of step value from file configuration */
112   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
113   double step = resMgr->doubleValue( "Geometry", "SettingsGeomStep", 100);
114
115   /* min, max, step and decimals for spin boxes & initial values */
116   /* First constructor : radius */
117   GroupPoints->SpinBox_DX->RangeStepAndValidator(0.001, 999.999, step, 3);
118   /* First constructor : algebric height */
119   GroupPoints->SpinBox_DY->RangeStepAndValidator(-999.999, 999.999, step, 3);
120   /* Second constructor : radius */
121   GroupDimensions->SpinBox_DX->RangeStepAndValidator(0.001, 999.999, step, 3);
122   /* Second constructor : algebric height */
123   GroupDimensions->SpinBox_DY->RangeStepAndValidator(-999.999, 999.999, step, 3);
124
125   GroupPoints->SpinBox_DX->SetValue(100.0);
126   GroupPoints->SpinBox_DY->SetValue(300.0);
127   GroupDimensions->SpinBox_DX->SetValue(100.0);  
128   GroupDimensions->SpinBox_DY->SetValue(300.0);  
129
130   /* signals and slots connections */
131   connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
132   connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
133   connect(GroupConstructors, SIGNAL(clicked(int)), this, SLOT(ConstructorsClicked(int)));
134
135   connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
136   connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
137
138   connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
139   connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
140
141   connect(GroupPoints->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
142   connect(GroupPoints->SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
143   connect(GroupDimensions->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
144   connect(GroupDimensions->SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
145
146   connect(myGeometryGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_DX, SLOT(SetStep(double)));
147   connect(myGeometryGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_DY, SLOT(SetStep(double)));
148   connect(myGeometryGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DX, SLOT(SetStep(double)));
149   connect(myGeometryGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DY, SLOT(SetStep(double)));
150   
151   connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), 
152           SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
153   
154   initName( tr( "GEOM_CYLINDER" ) );
155   ConstructorsClicked(0);
156 }
157
158
159 //=================================================================================
160 // function : ConstructorsClicked()
161 // purpose  : Radio button management
162 //=================================================================================
163 void PrimitiveGUI_CylinderDlg::ConstructorsClicked(int constructorId)
164 {
165   disconnect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), 0, this, 0);
166     
167   switch(constructorId)
168     { 
169     case 0 :
170       {
171         globalSelection( GEOM_POINT );
172
173         GroupDimensions->hide();
174         resize(0, 0);
175         GroupPoints->show();
176         
177         myEditCurrentArgument = GroupPoints->LineEdit1;
178         GroupPoints->LineEdit1->setText(tr(""));
179         GroupPoints->LineEdit2->setText(tr(""));
180         myPoint = myDir = GEOM::GEOM_Object::_nil();
181
182         connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), 
183                 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
184         break;
185       }
186     case 1 :
187       { 
188         GroupPoints->hide();
189         resize( 0, 0 );
190         GroupDimensions->show();
191         
192         break;
193       }
194     }
195   displayPreview();
196 }
197
198
199 //=================================================================================
200 // function : ClickOnOk()
201 // purpose  :
202 //=================================================================================
203 void PrimitiveGUI_CylinderDlg::ClickOnOk()
204 {
205   if ( ClickOnApply() )
206     ClickOnCancel();
207 }
208
209
210 //=================================================================================
211 // function : ClickOnApply()
212 // purpose  :
213 //=================================================================================
214 bool PrimitiveGUI_CylinderDlg::ClickOnApply()
215 {
216   if ( !onAccept() )
217     return false;
218
219   initName();
220   ConstructorsClicked( getConstructorId() );
221   return true;
222 }
223
224
225 //=======================================================================
226 // function : ClickOnCancel()
227 // purpose  :
228 //=======================================================================
229 void PrimitiveGUI_CylinderDlg::ClickOnCancel()
230 {
231   GEOMBase_Skeleton::ClickOnCancel();
232 }
233
234
235 //=================================================================================
236 // function : SelectionIntoArgument()
237 // purpose  : Called when selection as changed or other case
238 //=================================================================================
239 void PrimitiveGUI_CylinderDlg::SelectionIntoArgument()
240 {
241   if ( getConstructorId() != 0 )
242     return;
243
244   myEditCurrentArgument->setText("");
245   
246   if(IObjectCount() != 1) 
247     {
248       if(myEditCurrentArgument == GroupPoints->LineEdit1)
249         myPoint = GEOM::GEOM_Object::_nil();
250       else if (myEditCurrentArgument == GroupPoints->LineEdit2)
251         myDir = GEOM::GEOM_Object::_nil();
252       return;
253     }
254   
255   /* nbSel == 1 */
256   Standard_Boolean testResult = Standard_False;
257   GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( firstIObject(), testResult );
258     
259   if(!testResult || CORBA::is_nil( aSelectedObject ))
260     return;
261   
262   if (myEditCurrentArgument == GroupPoints->LineEdit1)
263     myPoint = aSelectedObject;
264   else if (myEditCurrentArgument == GroupPoints->LineEdit2)
265     myDir = aSelectedObject;
266     
267   myEditCurrentArgument->setText( GEOMBase::GetName( aSelectedObject ) );
268  
269   displayPreview();
270 }
271
272
273 //=================================================================================
274 // function : SetEditCurrentArgument()
275 // purpose  :
276 //=================================================================================
277 void PrimitiveGUI_CylinderDlg::SetEditCurrentArgument()
278 {
279   QPushButton* send = (QPushButton*)sender();
280   
281   if(send == GroupPoints->PushButton1) {
282     myEditCurrentArgument = GroupPoints->LineEdit1;
283     globalSelection( GEOM_POINT );
284   }
285   else if(send == GroupPoints->PushButton2) {
286     myEditCurrentArgument = GroupPoints->LineEdit2;
287     globalSelection( GEOM_LINE );
288   }
289   
290   myEditCurrentArgument->setFocus();
291   SelectionIntoArgument();
292 }
293
294
295 //=================================================================================
296 // function : LineEditReturnPressed()
297 // purpose  :
298 //=================================================================================
299 void PrimitiveGUI_CylinderDlg::LineEditReturnPressed()
300 {  
301   QLineEdit* send = (QLineEdit*)sender();
302   if(send == GroupPoints->LineEdit1 ||
303      send == GroupPoints->LineEdit2)
304     {
305       myEditCurrentArgument = send;
306       GEOMBase_Skeleton::LineEditReturnPressed();
307     }
308 }
309
310
311 //=================================================================================
312 // function : ActivateThisDialog()
313 // purpose  :
314 //=================================================================================
315 void PrimitiveGUI_CylinderDlg::ActivateThisDialog()
316 {
317   GEOMBase_Skeleton::ActivateThisDialog();
318   connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), 
319           SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
320   
321   ConstructorsClicked( getConstructorId() );
322 }
323
324
325 //=================================================================================
326 // function : enterEvent()
327 // purpose  :
328 //=================================================================================
329 void PrimitiveGUI_CylinderDlg::enterEvent(QEvent* e)
330 {
331   if ( !GroupConstructors->isEnabled() )
332     ActivateThisDialog();
333 }
334
335
336 //=================================================================================
337 // function : DeactivateActiveDialog()
338 // purpose  : public slot to deactivate if active
339 //=================================================================================
340 void PrimitiveGUI_CylinderDlg::DeactivateActiveDialog()
341 {
342   GEOMBase_Skeleton::DeactivateActiveDialog();
343 }
344
345
346 //=================================================================================
347 // function : ValueChangedInSpinBox
348 // purpose  :
349 //=================================================================================
350 void PrimitiveGUI_CylinderDlg::ValueChangedInSpinBox( )
351 {  
352   displayPreview();
353 }
354
355
356 //=================================================================================
357 // function : createOperation
358 // purpose  :
359 //=================================================================================
360 GEOM::GEOM_IOperations_ptr PrimitiveGUI_CylinderDlg::createOperation()
361 {
362   return getGeomEngine()->GetI3DPrimOperations( getStudyId() );
363 }
364
365
366 //=================================================================================
367 // function : isValid
368 // purpose  :
369 //=================================================================================
370 bool PrimitiveGUI_CylinderDlg::isValid( QString& msg )
371 {
372   return getConstructorId() == 0 ? !(myPoint->_is_nil() || myDir->_is_nil() ) : true;
373 }
374
375 //=================================================================================
376 // function : execute
377 // purpose  :
378 //=================================================================================
379 bool  PrimitiveGUI_CylinderDlg::execute( ObjectList& objects )
380 {
381   bool res = false;
382   
383   GEOM::GEOM_Object_var anObj;
384   
385   switch ( getConstructorId() ) 
386     {
387     case 0 :
388       {
389         if ( !CORBA::is_nil( myPoint ) && !CORBA::is_nil( myDir )) {
390           anObj = GEOM::GEOM_I3DPrimOperations::_narrow( getOperation() )->MakeCylinderPntVecRH(myPoint, myDir, getRadius(), getHeight());
391           res = true;
392         }
393         break;
394       }
395     case 1 :
396       {
397         anObj = GEOM::GEOM_I3DPrimOperations::_narrow( getOperation() )->MakeCylinderRH(getRadius(), getHeight());
398         res = true;
399
400         break;
401       }
402     }
403   
404   if ( !anObj->_is_nil() )
405     objects.push_back( anObj._retn() );
406   
407   return res;
408 }
409
410 //=================================================================================
411 // function : closeEvent
412 // purpose  :
413 //=================================================================================
414 void  PrimitiveGUI_CylinderDlg::closeEvent( QCloseEvent* e )
415 {
416   GEOMBase_Skeleton::closeEvent( e );
417 }
418
419
420 //=================================================================================
421 // function : getRadius()
422 // purpose  :
423 //=================================================================================
424 double PrimitiveGUI_CylinderDlg::getRadius() const
425 {
426   int aConstructorId = getConstructorId();
427   if (aConstructorId == 0)
428     return GroupPoints->SpinBox_DX->GetValue();
429   else if (aConstructorId == 1)
430     return GroupDimensions->SpinBox_DX->GetValue();
431   return 0;
432 }
433
434
435 //=================================================================================
436 // function : getHeight()
437 // purpose  :
438 //=================================================================================
439 double PrimitiveGUI_CylinderDlg::getHeight() const
440 {
441   int aConstructorId = getConstructorId();
442   if (aConstructorId == 0)
443     return GroupPoints->SpinBox_DY->GetValue();
444   else if (aConstructorId == 1)
445     return GroupDimensions->SpinBox_DY->GetValue();
446   return 0;
447 }