]> SALOME platform Git repositories - modules/geom.git/blob - src/GenerationGUI/GenerationGUI_PrismDlg.cxx
Salome HOME
*** empty log message ***
[modules/geom.git] / src / GenerationGUI / GenerationGUI_PrismDlg.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   : GenerationGUI_PrismDlg.cxx
23 // Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
24 //
25
26 #include "GenerationGUI_PrismDlg.h"
27
28 #include <GEOM_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    : GenerationGUI_PrismDlg()
41 // purpose  : Constructs a GenerationGUI_PrismDlg 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 GenerationGUI_PrismDlg::GenerationGUI_PrismDlg( 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_PRISM" ) ) );
51   QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
52   QPixmap image2( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_PRISM_2P" ) ) );
53
54   setWindowTitle( tr( "GEOM_EXTRUSION_TITLE" ) );
55
56   /***************************************************************/
57   mainFrame()->GroupConstructors->setTitle( tr( "GEOM_EXTRUSION" ) );
58   mainFrame()->RadioButton1->setIcon( image0 );
59   mainFrame()->RadioButton2->setIcon( image2 );
60   mainFrame()->RadioButton3->setAttribute( Qt::WA_DeleteOnClose );
61   mainFrame()->RadioButton3->close();
62
63   GroupPoints = new DlgRef_2Sel1Spin2Check( centralWidget() );
64   GroupPoints->CheckButton1->hide();
65   GroupPoints->GroupBox1->setTitle( tr( "GEOM_EXTRUSION_BSV" ) );
66   GroupPoints->TextLabel1->setText( tr( "GEOM_BASE" ) );
67   GroupPoints->TextLabel2->setText( tr( "GEOM_VECTOR" ) );
68   GroupPoints->TextLabel3->setText( tr( "GEOM_HEIGHT" ) );
69   GroupPoints->PushButton1->setIcon( image1 );
70   GroupPoints->PushButton2->setIcon( image1 );
71   GroupPoints->LineEdit1->setReadOnly( true );
72   GroupPoints->LineEdit2->setReadOnly( true );
73   GroupPoints->CheckButton2->setText( tr( "GEOM_REVERSE" ) );
74
75   GroupPoints2 = new DlgRef_3Sel( centralWidget() );
76
77   GroupPoints2->GroupBox1->setTitle( tr( "GEOM_EXTRUSION_BSV_2P" ) );
78   GroupPoints2->TextLabel1->setText( tr( "GEOM_BASE" ) );
79   GroupPoints2->TextLabel2->setText( tr( "GEOM_POINT_I" ).arg( 1 ) );
80   GroupPoints2->TextLabel3->setText( tr( "GEOM_POINT_I" ).arg( 2 ) );
81   GroupPoints2->PushButton1->setIcon( image1 );
82   GroupPoints2->PushButton2->setIcon( image1 );
83   GroupPoints2->PushButton3->setIcon( image1 );
84
85   QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
86   layout->setMargin( 0 ); layout->setSpacing( 6 );
87   layout->addWidget( GroupPoints );
88   layout->addWidget( GroupPoints2 );
89   /***************************************************************/
90
91   setHelpFileName( "extrusion.htm" );
92
93   /* Initialisations */
94   Init();
95 }
96
97
98 //=================================================================================
99 // function : ~GenerationGUI_PrismDlg()
100 // purpose  : Destroys the object and frees any allocated resources
101 //=================================================================================
102 GenerationGUI_PrismDlg::~GenerationGUI_PrismDlg()
103 {  
104   /* no need to delete child widgets, Qt does it all for us */
105 }
106
107
108 //=================================================================================
109 // function : Init()
110 // purpose  :
111 //=================================================================================
112 void GenerationGUI_PrismDlg::Init()
113 {
114   /* init variables */
115   myEditCurrentArgument = GroupPoints->LineEdit1;
116   GroupPoints->LineEdit1->setReadOnly( true );
117   GroupPoints->LineEdit2->setReadOnly( true );
118
119   GroupPoints2->LineEdit1->setReadOnly( true );
120   GroupPoints2->LineEdit2->setReadOnly( true );
121   GroupPoints2->LineEdit3->setReadOnly( true );
122
123   //myOkBase = myOkVec = false;
124   myOkBase = myOkVec = myOkPnt1 = myOkPnt2 = false;
125   
126   /* Get setting of step value from file configuration */
127   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
128   double step = resMgr->doubleValue( "Geometry", "SettingsGeomStep", 100 );
129
130   /* min, max, step and decimals for spin boxes & initial values */
131   initSpinBox( GroupPoints->SpinBox_DX, COORD_MIN, COORD_MAX, step, 3 );
132   GroupPoints->SpinBox_DX->setValue( 100.0 );
133
134   /* signals and slots connections */
135   connect( buttonOk(),    SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
136   connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
137
138   connect( this,          SIGNAL( constructorsClicked( int ) ), this, SLOT( ConstructorsClicked( int ) ) );
139
140   connect( GroupPoints->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
141   connect( GroupPoints->PushButton2, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
142
143   connect( GroupPoints->LineEdit1, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
144   connect( GroupPoints->LineEdit2, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
145
146   connect( GroupPoints->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox() ) );
147   // VSR: TODO ->>
148   connect( myGeomGUI, SIGNAL( SignalDefaultStepValueChanged( double ) ), GroupPoints->SpinBox_DX, SLOT( SetStep( double ) ) );
149   // <<-
150
151   connect( GroupPoints->CheckButton2, SIGNAL( toggled( bool ) ),      this, SLOT( onReverse() ) );
152
153   connect( GroupPoints2->PushButton1, SIGNAL( clicked() ),       this, SLOT( SetEditCurrentArgument() ) );
154   connect( GroupPoints2->PushButton2, SIGNAL( clicked() ),       this, SLOT( SetEditCurrentArgument() ) );
155   connect( GroupPoints2->PushButton3, SIGNAL( clicked() ),       this, SLOT( SetEditCurrentArgument() ) );
156
157   connect( GroupPoints2->LineEdit1,   SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
158   connect( GroupPoints2->LineEdit2,   SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
159   connect( GroupPoints2->LineEdit3,   SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
160
161
162   connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
163            SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
164
165   initName( tr( "GEOM_EXTRUSION" ) );
166
167   globalSelection( GEOM_ALLSHAPES );
168   ConstructorsClicked( 0 );
169 }
170
171
172 //=================================================================================
173 // function : ConstructorsClicked()
174 // purpose  : Radio button management
175 //=================================================================================
176 void GenerationGUI_PrismDlg::ConstructorsClicked( int constructorId )
177 {
178   disconnect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(), 0, this, 0 );
179   
180   switch ( constructorId ) {
181   case 0:
182     {
183       globalSelection( GEOM_POINT );
184       GroupPoints2->hide();
185       GroupPoints->show();
186       
187       //GroupPoints->LineEdit1->setFocus();
188       //myEditCurrentArgument = GroupPoints->LineEdit1;
189       //displayPreview();
190       
191       myEditCurrentArgument = GroupPoints->LineEdit1;
192       GroupPoints->LineEdit1->setText( "" );
193       GroupPoints->LineEdit2->setText( "" );
194       GroupPoints2->LineEdit1->setText( "" );
195       GroupPoints2->LineEdit2->setText( "" );
196       GroupPoints2->LineEdit3->setText( "" );
197       myPoint1 = myPoint2 = myBase = myVec = GEOM::GEOM_Object::_nil();
198       myOkBase = myOkVec = myOkPnt1 = myOkPnt2 = false;
199       
200       break;
201     }
202   case 1:
203     {
204       GroupPoints->hide();
205       GroupPoints2->show();
206       
207       myEditCurrentArgument = GroupPoints2->LineEdit1;
208       GroupPoints2->LineEdit1->setText( "" );
209       GroupPoints2->LineEdit2->setText( "" );
210       GroupPoints2->LineEdit3->setText( "" );
211       myPoint1 = myPoint2 = myBase = myVec = GEOM::GEOM_Object::_nil();
212       myOkBase = myOkVec = myOkPnt1 = myOkPnt2 = false;
213       GroupPoints->LineEdit1->setText("");
214       GroupPoints->LineEdit2->setText("");
215       
216       break;
217     }
218   }
219
220   qApp->processEvents();
221   updateGeometry();
222   resize( minimumSize() );
223
224   displayPreview();
225 }
226
227
228 //=================================================================================
229 // function : ClickOnOk()
230 // purpose  :
231 //=================================================================================
232 void GenerationGUI_PrismDlg::ClickOnOk()
233 {
234   if ( ClickOnApply() )
235     ClickOnCancel();
236 }
237
238
239 //=================================================================================
240 // function : ClickOnApply()
241 // purpose  :
242 //=================================================================================
243 bool GenerationGUI_PrismDlg::ClickOnApply()
244 {
245   if ( !onAccept() )
246     return false;
247
248   initName();
249   return true;
250 }
251
252
253 //=================================================================================
254 // function : SelectionIntoArgument()
255 // purpose  : Called when selection has changed
256 //=================================================================================
257 void GenerationGUI_PrismDlg::SelectionIntoArgument()
258 {
259   erasePreview();
260   myEditCurrentArgument->setText( "" );
261
262   if ( getConstructorId() == 0 ) {
263
264     if ( IObjectCount() != 1 ) {
265       if ( myEditCurrentArgument == GroupPoints->LineEdit1 )
266         myOkBase = false;
267       else if ( myEditCurrentArgument == GroupPoints->LineEdit2 )
268         myOkVec = false;
269       return;
270     }
271
272     // nbSel == 1
273     Standard_Boolean testResult = Standard_False;
274     GEOM::GEOM_Object_ptr aSelectedObject =
275       GEOMBase::ConvertIOinGEOMObject( firstIObject(), testResult );
276
277     if ( !testResult )
278       return;
279
280     if ( myEditCurrentArgument == GroupPoints->LineEdit1 ) {
281       myBase = aSelectedObject;
282       myOkBase = true;
283     }
284     else if ( myEditCurrentArgument == GroupPoints->LineEdit2 ) {
285       myVec = aSelectedObject;
286       myOkVec = true;
287     }
288     myEditCurrentArgument->setText( GEOMBase::GetName( aSelectedObject ) );
289
290     displayPreview();
291   }
292
293   else { // getConstructorId()==1 - extrusion using 2 points
294
295     if ( IObjectCount() != 1 ) {
296       if ( myEditCurrentArgument == GroupPoints2->LineEdit1 )
297         myOkBase = false;
298       else if ( myEditCurrentArgument == GroupPoints2->LineEdit2 ) {
299         myPoint1 = GEOM::GEOM_Object::_nil();
300         myOkPnt1 = false;
301       }
302       else if ( myEditCurrentArgument == GroupPoints2->LineEdit3 ) {
303         myPoint2 = GEOM::GEOM_Object::_nil();
304         myOkPnt2 = false;
305       }
306       return;
307     }
308
309     // nbSel == 1
310     Standard_Boolean testResult = Standard_False;
311     GEOM::GEOM_Object_var aSelectedObject =
312       GEOMBase::ConvertIOinGEOMObject( firstIObject(), testResult );
313
314     if ( !testResult || CORBA::is_nil( aSelectedObject ) )
315       return;
316
317     if ( myEditCurrentArgument == GroupPoints2->LineEdit1 ) {
318       myBase = aSelectedObject;
319       myOkBase = true;
320     }
321     else if ( myEditCurrentArgument == GroupPoints2->LineEdit2 ) {
322       myPoint1 = aSelectedObject;
323       myOkPnt1 = true;
324     }
325     else if ( myEditCurrentArgument == GroupPoints2->LineEdit3 ) {
326       myPoint2 = aSelectedObject;
327       myOkPnt2 = true;
328     }
329
330     myEditCurrentArgument->setText( GEOMBase::GetName( aSelectedObject ) );
331
332     displayPreview();
333   }
334 }
335
336
337 //=================================================================================
338 // function : SetEditCurrentArgument()
339 // purpose  :
340 //=================================================================================
341 void GenerationGUI_PrismDlg::SetEditCurrentArgument()
342 {
343   QPushButton* send = (QPushButton*)sender();
344   globalSelection( GEOM_ALLSHAPES );
345
346   if ( send == GroupPoints->PushButton1 ) {
347     GroupPoints->LineEdit1->setFocus();
348     myEditCurrentArgument = GroupPoints->LineEdit1;
349   }
350   else if ( send == GroupPoints->PushButton2 ) {
351     GroupPoints->LineEdit2->setFocus();
352     myEditCurrentArgument = GroupPoints->LineEdit2;
353     globalSelection( GEOM_LINE );
354   }
355   else if ( send == GroupPoints2->PushButton1 ) {
356     GroupPoints2->LineEdit1->setFocus();
357     myEditCurrentArgument = GroupPoints2->LineEdit1;
358   }
359   else if ( send == GroupPoints2->PushButton2 ) {
360     GroupPoints2->LineEdit2->setFocus();
361     myEditCurrentArgument = GroupPoints2->LineEdit2;
362     globalSelection( GEOM_POINT );
363   }
364   else if ( send == GroupPoints2->PushButton3 ) {
365     GroupPoints2->LineEdit3->setFocus();
366     myEditCurrentArgument = GroupPoints2->LineEdit3;
367     globalSelection( GEOM_POINT );
368   }
369   SelectionIntoArgument();
370 }
371
372
373 //=================================================================================
374 // function : LineEditReturnPressed()
375 // purpose  :
376 //=================================================================================
377 void GenerationGUI_PrismDlg::LineEditReturnPressed()
378 {
379   QLineEdit* send = (QLineEdit*)sender();
380   if ( send == GroupPoints->LineEdit1 ||
381        send == GroupPoints->LineEdit2 ||
382        send == GroupPoints2->LineEdit1 ||
383        send == GroupPoints2->LineEdit2 ||
384        send == GroupPoints2->LineEdit3 ) {
385     myEditCurrentArgument = send;
386     GEOMBase_Skeleton::LineEditReturnPressed();
387   }
388 }
389
390 //=================================================================================
391 // function : enterEvent()
392 // purpose  : when mouse enter onto the QWidget
393 //=================================================================================
394 void GenerationGUI_PrismDlg::enterEvent( QEvent* )
395 {
396   if ( !mainFrame()->GroupConstructors->isEnabled() )
397     ActivateThisDialog();
398 }
399
400
401 //=================================================================================
402 // function : ActivateThisDialog()
403 // purpose  :
404 //=================================================================================
405 void GenerationGUI_PrismDlg::ActivateThisDialog()
406 {
407   GEOMBase_Skeleton::ActivateThisDialog();
408   globalSelection( GEOM_ALLSHAPES );
409   connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
410            SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
411   //GroupPoints->LineEdit1->setFocus();
412   //myEditCurrentArgument = GroupPoints->LineEdit1;
413   //displayPreview();
414   ConstructorsClicked( getConstructorId() );
415 }
416
417
418 //=================================================================================
419 // function : ValueChangedInSpinBox()
420 // purpose  :
421 //=================================================================================
422 void GenerationGUI_PrismDlg::ValueChangedInSpinBox()
423 {
424   displayPreview();
425 }
426
427
428 //=================================================================================
429 // function : getHeight()
430 // purpose  :
431 //=================================================================================
432 double GenerationGUI_PrismDlg::getHeight() const
433 {
434   return GroupPoints->SpinBox_DX->value();
435 }
436
437 //=================================================================================
438 // function : createOperation
439 // purpose  :
440 //=================================================================================
441 GEOM::GEOM_IOperations_ptr GenerationGUI_PrismDlg::createOperation()
442 {
443   return getGeomEngine()->GetI3DPrimOperations( getStudyId() );
444 }
445
446 //=================================================================================
447 // function : isValid
448 // purpose  :
449 //=================================================================================
450 bool GenerationGUI_PrismDlg::isValid( QString& )
451 {
452   return myOkBase && ( myOkVec || (myOkPnt1 && myOkPnt2) );
453 }
454
455 //=================================================================================
456 // function : execute
457 // purpose  :
458 //=================================================================================
459 bool GenerationGUI_PrismDlg::execute( ObjectList& objects )
460 {
461   GEOM::GEOM_Object_var anObj;
462
463   switch ( getConstructorId() ) {
464   case 0 :
465     anObj = GEOM::GEOM_I3DPrimOperations::_narrow( getOperation() )->
466       MakePrismVecH( myBase, myVec, getHeight() );
467     break;
468   case 1 :
469     anObj = GEOM::GEOM_I3DPrimOperations::_narrow( getOperation() )->
470       MakePrismTwoPnt( myBase, myPoint1, myPoint2 );
471     break;
472   }
473   if ( !anObj->_is_nil() )
474     objects.push_back( anObj._retn() );
475
476   return true;
477 }
478
479
480 //=================================================================================
481 // function :  onReverse()
482 // purpose  :
483 //=================================================================================
484 void GenerationGUI_PrismDlg::onReverse()
485 {
486   double anOldValue = GroupPoints->SpinBox_DX->value();
487   GroupPoints->SpinBox_DX->setValue( -anOldValue );
488 }