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