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