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