]> SALOME platform Git repositories - modules/geom.git/blob - src/PrimitiveGUI/PrimitiveGUI_ConeDlg.cxx
Salome HOME
Patch for bug IPAL9210(3.0.0 "GEOM_usinggeom.py" script execution failed.).
[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 "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_ConeDlg()
46 // purpose  : Constructs a PrimitiveGUI_ConeDlg 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_ConeDlg::PrimitiveGUI_ConeDlg(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_CONE_PV")));
55   QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_CONE_DXYZ")));
56   QPixmap image2(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_SELECT")));
57
58   setCaption(tr("GEOM_CONE_TITLE"));
59
60   /***************************************************************/
61   GroupConstructors->setTitle(tr("GEOM_CONE"));
62   RadioButton1->setPixmap(image0);
63   RadioButton2->setPixmap(image1);
64   RadioButton3->close(TRUE);
65
66   GroupPoints = new DlgRef_2Sel3Spin(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_I").arg("1"));
71   GroupPoints->TextLabel4->setText(tr("GEOM_RADIUS_I").arg("2"));
72   GroupPoints->TextLabel5->setText(tr("GEOM_HEIGHT"));
73   GroupPoints->PushButton1->setPixmap(image2);
74   GroupPoints->PushButton2->setPixmap(image2);
75
76   GroupDimensions = new DlgRef_3Spin(this, "GroupDimensions");
77   GroupDimensions->GroupBox1->setTitle(tr("GEOM_BOX_OBJ"));
78   GroupDimensions->TextLabel1->setText(tr("GEOM_RADIUS_I").arg("1"));
79   GroupDimensions->TextLabel2->setText(tr("GEOM_RADIUS_I").arg("2"));
80   GroupDimensions->TextLabel3->setText(tr("GEOM_HEIGHT"));
81
82   Layout1->addWidget(GroupPoints, 2, 0);
83   Layout1->addWidget(GroupDimensions, 2, 0);
84   /***************************************************************/
85
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   myEditCurrentArgument = GroupPoints->LineEdit1;
108   GroupPoints->LineEdit1->setReadOnly( true );
109   GroupPoints->LineEdit2->setReadOnly( true );
110   
111   myPoint = myDir = GEOM::GEOM_Object::_nil();
112   
113   /* Get setting of step value from file configuration */
114   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
115   double step = resMgr->doubleValue( "Geometry", "SettingsGeomStep", 100);
116   
117   /* min, max, step and decimals for spin boxes & initial values */
118   GroupPoints->SpinBox_DX->RangeStepAndValidator(0.000, 999.999, step, 3);
119   GroupPoints->SpinBox_DY->RangeStepAndValidator(0.000, 999.999, step, 3);
120   GroupPoints->SpinBox_DZ->RangeStepAndValidator(-999.999, 999.999, step, 3);
121   GroupDimensions->SpinBox_DX->RangeStepAndValidator(0.000, 999.999, step, 3);
122   GroupDimensions->SpinBox_DY->RangeStepAndValidator(0.000, 999.999, step, 3);
123   GroupDimensions->SpinBox_DZ->RangeStepAndValidator(-999.999, 999.999, step, 3);
124
125   double aRadius1(100.0), aRadius2(0.0), aHeight(300.0); 
126   GroupPoints->SpinBox_DX->SetValue(aRadius1);
127   GroupPoints->SpinBox_DY->SetValue(aRadius2);
128   GroupPoints->SpinBox_DZ->SetValue(aHeight);
129   GroupDimensions->SpinBox_DX->SetValue(aRadius1);
130   GroupDimensions->SpinBox_DY->SetValue(aRadius2);
131   GroupDimensions->SpinBox_DZ->SetValue(aHeight);
132
133   /* signals and slots connections */
134   connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
135   connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
136   connect(GroupConstructors, SIGNAL(clicked(int)), this, SLOT(ConstructorsClicked(int)));
137
138   connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
139   connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
140
141   connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
142   connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
143
144   connect(GroupPoints->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
145   connect(GroupPoints->SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
146   connect(GroupPoints->SpinBox_DZ, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
147   connect(GroupDimensions->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
148   connect(GroupDimensions->SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
149   connect(GroupDimensions->SpinBox_DZ, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
150
151   connect(myGeometryGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_DX, SLOT(SetStep(double)));
152   connect(myGeometryGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_DY, SLOT(SetStep(double)));
153   connect(myGeometryGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_DZ, SLOT(SetStep(double)));
154   connect(myGeometryGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DX, SLOT(SetStep(double)));
155   connect(myGeometryGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DY, SLOT(SetStep(double)));
156   connect(myGeometryGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DZ, SLOT(SetStep(double)));
157   
158   connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), 
159           SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
160   
161   initName( tr( "GEOM_CONE" ) );
162   ConstructorsClicked(0);
163 }
164
165
166 //=================================================================================
167 // function : ConstructorsClicked()
168 // purpose  : Radio button management
169 //=================================================================================
170 void PrimitiveGUI_ConeDlg::ConstructorsClicked(int constructorId)
171 {
172   disconnect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), 0, this, 0);
173   
174   switch(constructorId)
175     { 
176     case 0 :
177       {
178         globalSelection( GEOM_POINT );
179         GroupDimensions->hide();
180         resize(0, 0);
181         GroupPoints->show();
182         
183         myEditCurrentArgument = GroupPoints->LineEdit1;
184         GroupPoints->LineEdit1->setText(tr(""));
185         GroupPoints->LineEdit2->setText(tr(""));
186         myPoint = myDir = GEOM::GEOM_Object::_nil();
187         
188         connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), 
189                 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
190         break;
191       }
192     case 1 :
193       { 
194         GroupPoints->hide();
195         resize( 0, 0 );
196         GroupDimensions->show();
197
198         break;
199       }
200     }
201   displayPreview();
202 }
203
204
205 //=================================================================================
206 // function : ClickOnOk()
207 // purpose  :
208 //=================================================================================
209 void PrimitiveGUI_ConeDlg::ClickOnOk()
210 {
211   if ( ClickOnApply() )
212     ClickOnCancel();
213 }
214
215
216 //=================================================================================
217 // function : ClickOnApply()
218 // purpose  :
219 //=================================================================================
220 bool PrimitiveGUI_ConeDlg::ClickOnApply()
221 {
222   if ( !onAccept() )
223     return false;
224
225   initName();
226   ConstructorsClicked( getConstructorId() );
227   return true;
228 }
229
230
231 //=======================================================================
232 // function : ClickOnCancel()
233 // purpose  :
234 //=======================================================================
235 void PrimitiveGUI_ConeDlg::ClickOnCancel()
236 {
237   GEOMBase_Skeleton::ClickOnCancel();
238 }
239
240
241 //=================================================================================
242 // function : SelectionIntoArgument()
243 // purpose  : Called when selection as changed or other case
244 //=================================================================================
245 void PrimitiveGUI_ConeDlg::SelectionIntoArgument()
246 {
247   if ( getConstructorId() != 0 )
248     return;
249
250   if(IObjectCount() != 1)
251     {
252       if(myEditCurrentArgument == GroupPoints->LineEdit1)
253         myPoint = GEOM::GEOM_Object::_nil();
254       else if (myEditCurrentArgument == GroupPoints->LineEdit2)
255         myDir = GEOM::GEOM_Object::_nil();
256       return;
257     }
258
259   /* nbSel == 1 */
260   Standard_Boolean testResult = Standard_False;
261   GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( firstIObject(), testResult );
262   
263   if(!testResult || CORBA::is_nil( aSelectedObject ))
264     return;
265
266   if (myEditCurrentArgument == GroupPoints->LineEdit1)
267     myPoint = aSelectedObject;
268   else if (myEditCurrentArgument == GroupPoints->LineEdit2)
269     myDir = aSelectedObject;
270   
271   
272   myEditCurrentArgument->setText( GEOMBase::GetName( aSelectedObject ) );
273   displayPreview();
274 }
275
276
277 //=================================================================================
278 // function : SetEditCurrentArgument()
279 // purpose  :
280 //=================================================================================
281 void PrimitiveGUI_ConeDlg::SetEditCurrentArgument()
282 {
283   QPushButton* send = (QPushButton*)sender();
284   
285   if(send == GroupPoints->PushButton1) {
286     myEditCurrentArgument = GroupPoints->LineEdit1;
287     globalSelection( GEOM_POINT );
288   }
289   else if(send == GroupPoints->PushButton2) {
290     myEditCurrentArgument = GroupPoints->LineEdit2;
291     globalSelection( GEOM_LINE );
292   }
293   
294   myEditCurrentArgument->setFocus();
295   SelectionIntoArgument();
296 }
297
298
299 //=================================================================================
300 // function : LineEditReturnPressed()
301 // purpose  :
302 //=================================================================================
303 void PrimitiveGUI_ConeDlg::LineEditReturnPressed()
304 {
305   QLineEdit* send = (QLineEdit*)sender();
306   if(send == GroupPoints->LineEdit1 ||
307      send == GroupPoints->LineEdit2)
308     {
309       myEditCurrentArgument = send;
310       GEOMBase_Skeleton::LineEditReturnPressed();
311     }
312 }
313
314
315 //=================================================================================
316 // function : ActivateThisDialog()
317 // purpose  :
318 //=================================================================================
319 void PrimitiveGUI_ConeDlg::ActivateThisDialog()
320 {
321   GEOMBase_Skeleton::ActivateThisDialog();
322   connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), 
323           SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
324   
325   ConstructorsClicked( getConstructorId() );
326 }
327
328
329 //=================================================================================
330 // function : DeactivateActiveDialog()
331 // purpose  : public slot to deactivate if active
332 //=================================================================================
333 void PrimitiveGUI_ConeDlg::DeactivateActiveDialog()
334 {
335   GEOMBase_Skeleton::DeactivateActiveDialog();
336 }
337
338
339 //=================================================================================
340 // function : enterEvent()
341 // purpose  :
342 //=================================================================================
343 void PrimitiveGUI_ConeDlg::enterEvent(QEvent* e)
344 {
345   if ( !GroupConstructors->isEnabled() )
346     ActivateThisDialog();
347 }
348
349
350 //=================================================================================
351 // function : ValueChangedInSpinBox()
352 // purpose  :
353 //=================================================================================
354 void PrimitiveGUI_ConeDlg::ValueChangedInSpinBox()
355 {
356   displayPreview();
357 }
358
359
360 //=================================================================================
361 // function : createOperation
362 // purpose  :
363 //=================================================================================
364 GEOM::GEOM_IOperations_ptr  PrimitiveGUI_ConeDlg::createOperation()
365 {
366   return getGeomEngine()->GetI3DPrimOperations( getStudyId() );
367 }
368
369 //=================================================================================
370 // function : isValid
371 // purpose  :
372 //=================================================================================
373 bool  PrimitiveGUI_ConeDlg::isValid( QString& msg )
374 {
375   return getConstructorId() == 0 ? !(myPoint->_is_nil() || myDir->_is_nil()) : true;
376 }
377
378 //=================================================================================
379 // function : execute
380 // purpose  :
381 //=================================================================================
382 bool PrimitiveGUI_ConeDlg::execute( ObjectList& objects )
383 {
384   bool res = false;
385   
386   GEOM::GEOM_Object_var anObj;
387
388   switch ( getConstructorId() ) 
389   {
390   case 0 :
391   {
392     if ( !CORBA::is_nil( myPoint ) && !CORBA::is_nil( myDir ) ){
393       anObj = GEOM::GEOM_I3DPrimOperations::_narrow( getOperation() )->MakeConePntVecR1R2H( myPoint, 
394                                                                                             myDir, 
395                                                                                             getRadius1(),
396                                                                                             getRadius2(),
397                                                                                             getHeight());
398       res = true;
399     }
400     break;
401   }
402   case 1 :
403     {
404       anObj = GEOM::GEOM_I3DPrimOperations::_narrow( getOperation() )->MakeConeR1R2H( getRadius1(),
405                                                                                       getRadius2(),
406                                                                                       getHeight());
407       res = true;
408       break;
409     }
410   }
411
412   if ( !anObj->_is_nil() )
413     objects.push_back( anObj._retn() );
414
415   return res;
416 }
417
418 //=================================================================================
419 // function : closeEvent
420 // purpose  :
421 //=================================================================================
422 void PrimitiveGUI_ConeDlg::closeEvent( QCloseEvent* e )
423 {
424   // myGeomGUI->SetState( -1 );
425   GEOMBase_Skeleton::closeEvent( e );
426 }
427
428
429 //=================================================================================
430 // function : getRadius1()
431 // purpose  :
432 //=================================================================================
433 double PrimitiveGUI_ConeDlg::getRadius1() const
434 {
435   int aConstructorId = getConstructorId();
436   if (aConstructorId == 0)
437     return GroupPoints->SpinBox_DX->GetValue();
438   else if (aConstructorId == 1)
439     return GroupDimensions->SpinBox_DX->GetValue();
440   return 0;
441 }
442
443
444 //=================================================================================
445 // function : getRadius2()
446 // purpose  :
447 //=================================================================================
448 double PrimitiveGUI_ConeDlg::getRadius2() const
449 {
450   int aConstructorId = getConstructorId();
451   if (aConstructorId == 0)
452     return GroupPoints->SpinBox_DY->GetValue();
453   else if (aConstructorId == 1)
454     return GroupDimensions->SpinBox_DY->GetValue();
455   return 0;
456 }
457
458
459 //=================================================================================
460 // function : getRadius2()
461 // purpose  :
462 //=================================================================================
463 double PrimitiveGUI_ConeDlg::getHeight() const
464 {
465   int aConstructorId = getConstructorId();
466   if (aConstructorId == 0)
467     return GroupPoints->SpinBox_DZ->GetValue();
468   else if (aConstructorId == 1)
469     return GroupDimensions->SpinBox_DZ->GetValue();
470   return 0;
471 }