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