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