]> SALOME platform Git repositories - modules/geom.git/blob - src/GEOMGUI/GeometryGUI_BoxDlg.cxx
Salome HOME
sources v1.2
[modules/geom.git] / src / GEOMGUI / GeometryGUI_BoxDlg.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   : GeometryGUI_BoxDlg.cxx
25 //  Author : Lucien PIGNOLONI
26 //  Module : GEOM
27 //  $Header$
28
29 using namespace std;
30 #include "GeometryGUI_BoxDlg.h"
31 #include "GeometryGUI_SpinBox.h"
32
33 #include "GeometryGUI.h"
34 #include "QAD_Application.h"
35 #include "QAD_Desktop.h"
36 #include "QAD_Config.h"
37 #include "utilities.h"
38
39 #include <qbuttongroup.h>
40 #include <qframe.h>
41 #include <qgroupbox.h>
42 #include <qlineedit.h>
43 #include <qpushbutton.h>
44 #include <qradiobutton.h>
45 #include <qlayout.h>
46 #include <qvariant.h>
47 #include <qtooltip.h>
48 #include <qwhatsthis.h>
49 #include <qimage.h>
50 #include <qpixmap.h>
51 #include <qlabel.h>
52 #include <qvalidator.h>
53 #include <qevent.h>
54 #include <qmessagebox.h>
55
56
57
58 //=================================================================================
59 // class    : GeometryGUI_BoxDlg()
60 // purpose  : Constructs a GeometryGUI_BoxDlg which is a child of 'parent', with the 
61 //            name 'name' and widget flags set to 'f'.
62 //            The dialog will by default be modeless, unless you set 'modal' to
63 //            TRUE to construct a modal dialog.
64 //=================================================================================
65 GeometryGUI_BoxDlg::GeometryGUI_BoxDlg( QWidget* parent, const char* name, SALOME_Selection* Sel, bool modal, WFlags fl )
66     : QDialog( parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
67 {
68     QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap( "GeometryGUI",tr("ICON_DLG_BOX_2P")));
69     QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap( "GeometryGUI",tr("ICON_SELECT")));
70     QPixmap image2(QAD_Desktop::getResourceManager()->loadPixmap( "GeometryGUI",tr("ICON_DLG_BOX_DXYZ")));
71
72     if ( !name )
73         setName( "GeometryGUI_BoxDlg" );
74     resize( 335, 220 ); 
75     setCaption( tr( "GEOM_BOX_TITLE"  ) );
76     setSizeGripEnabled( TRUE );
77     GeometryGUI_BoxDlgLayout = new QGridLayout( this ); 
78     GeometryGUI_BoxDlgLayout->setSpacing( 6 );
79     GeometryGUI_BoxDlgLayout->setMargin( 11 );
80     
81     /***************************************************************/
82     GroupConstructors = new QButtonGroup( this, "GroupConstructors" );
83     GroupConstructors->setTitle( tr( "GEOM_BOX"  ) );
84     GroupConstructors->setExclusive( TRUE );
85     GroupConstructors->setColumnLayout(0, Qt::Vertical );
86     GroupConstructors->layout()->setSpacing( 0 );
87     GroupConstructors->layout()->setMargin( 0 );
88     GroupConstructorsLayout = new QGridLayout( GroupConstructors->layout() );
89     GroupConstructorsLayout->setAlignment( Qt::AlignTop );
90     GroupConstructorsLayout->setSpacing( 6 );
91     GroupConstructorsLayout->setMargin( 11 );
92     QSpacerItem* spacer_1 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
93     GroupConstructorsLayout->addItem( spacer_1, 0, 3 );
94     Constructor1 = new QRadioButton( GroupConstructors, "Constructor1" );
95     Constructor1->setText( tr( ""  ) );
96     Constructor1->setPixmap( image0 );
97     Constructor1->setChecked( TRUE );
98     Constructor1->setMinimumSize( QSize( 50, 0 ) );
99     GroupConstructorsLayout->addWidget( Constructor1, 0, 0 );
100     Constructor2 = new QRadioButton( GroupConstructors, "Constructor2" );
101     Constructor2->setText( tr( ""  ) );
102     Constructor2->setPixmap( image2 );
103     Constructor2->setMinimumSize( QSize( 50, 0 ) );
104     GroupConstructorsLayout->addWidget( Constructor2, 0, 2 );
105     QSpacerItem* spacer_2 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
106     GroupConstructorsLayout->addItem( spacer_2, 0, 1 );
107     GeometryGUI_BoxDlgLayout->addWidget( GroupConstructors, 0, 0 );
108
109     /***************************************************************/
110     GroupButtons = new QGroupBox( this, "GroupButtons" );
111     GroupButtons->setGeometry( QRect( 10, 10, 281, 48 ) ); 
112     GroupButtons->setTitle( tr( ""  ) );
113     GroupButtons->setColumnLayout(0, Qt::Vertical );
114     GroupButtons->layout()->setSpacing( 0 );
115     GroupButtons->layout()->setMargin( 0 );
116     GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
117     GroupButtonsLayout->setAlignment( Qt::AlignTop );
118     GroupButtonsLayout->setSpacing( 6 );
119     GroupButtonsLayout->setMargin( 11 );
120     buttonCancel = new QPushButton( GroupButtons, "buttonCancel" );
121     buttonCancel->setText( tr( "GEOM_BUT_CLOSE"  ) );
122     buttonCancel->setAutoDefault( TRUE );
123     GroupButtonsLayout->addWidget( buttonCancel, 0, 3 );
124     buttonApply = new QPushButton( GroupButtons, "buttonApply" );
125     buttonApply->setText( tr( "GEOM_BUT_APPLY"  ) );
126     buttonApply->setAutoDefault( TRUE );
127     GroupButtonsLayout->addWidget( buttonApply, 0, 1 );
128     QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
129     GroupButtonsLayout->addItem( spacer, 0, 2 );
130     buttonOk = new QPushButton( GroupButtons, "buttonOk" );
131     buttonOk->setText( tr( "GEOM_BUT_OK"  ) );
132     buttonOk->setAutoDefault( TRUE );
133     buttonOk->setDefault( TRUE );
134     GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
135     GeometryGUI_BoxDlgLayout->addWidget( GroupButtons, 2, 0 ); 
136
137     /***************************************************************/
138     GroupPoints = new QGroupBox( this, "GroupPoints" );
139     GroupPoints->setGeometry( QRect( 10, 10, 280, 90 ) ); 
140     GroupPoints->setTitle( tr( "GEOM_DIAGONAL_POINTS"  ) );
141     GroupPoints->setFrameShape( QGroupBox::Box );
142     GroupPoints->setFrameShadow( QGroupBox::Sunken );
143     GroupPoints->setColumnLayout(0, Qt::Vertical );
144     GroupPoints->layout()->setSpacing( 0 );
145     GroupPoints->layout()->setMargin( 0 );
146     GroupPointsLayout = new QGridLayout( GroupPoints->layout() );
147     GroupPointsLayout->setAlignment( Qt::AlignTop );
148     GroupPointsLayout->setSpacing( 6 );
149     GroupPointsLayout->setMargin( 11 );
150     SelectButtonPt2 = new QPushButton( GroupPoints, "SelectButtonPt2" );
151     SelectButtonPt2->setText( tr( ""  ) );
152     SelectButtonPt2->setPixmap( image1 );
153     GroupPointsLayout->addWidget( SelectButtonPt2, 1, 1 );
154     LineEditPt1 = new QLineEdit( GroupPoints, "LineEditPt1" );
155     GroupPointsLayout->addWidget( LineEditPt1, 0, 2 );
156     LineEditPt2 = new QLineEdit( GroupPoints, "LineEditPt2" );
157     GroupPointsLayout->addWidget( LineEditPt2, 1, 2 );
158     SelectButtonPt1 = new QPushButton( GroupPoints, "SelectButtonPt1" );
159     SelectButtonPt1->setText( tr( ""  ) );
160     SelectButtonPt1->setPixmap( image1 );
161     SelectButtonPt1->setToggleButton( FALSE );
162     GroupPointsLayout->addWidget( SelectButtonPt1, 0, 1 );
163     TextLabelPt1 = new QLabel( GroupPoints, "TextLabelPt1" );
164     TextLabelPt1->setText( tr( "GEOM_POINT_I"  ).arg("1") );
165     TextLabelPt1->setMinimumSize( QSize( 50, 0 ) );
166     TextLabelPt1->setFrameShape( QLabel::NoFrame );
167     TextLabelPt1->setFrameShadow( QLabel::Plain );
168     GroupPointsLayout->addWidget( TextLabelPt1, 0, 0 );
169     TextLabelPt2 = new QLabel( GroupPoints, "TextLabelPt2" );
170     TextLabelPt2->setText( tr( "GEOM_POINT_I"  ).arg("2") );
171     TextLabelPt2->setMinimumSize( QSize( 50, 0 ) );
172     GroupPointsLayout->addWidget( TextLabelPt2, 1, 0 );
173     GeometryGUI_BoxDlgLayout->addWidget( GroupPoints, 1, 0 );
174
175     /***************************************************************/
176     GroupDimensions = new QGroupBox( this, "GroupDimensions" );
177     GroupDimensions->setGeometry( QRect( 11, 75, 310, 80 ) ); 
178     GroupDimensions->setTitle( tr( "GEOM_BOX_OBJ"  ) );
179     GroupDimensions->setColumnLayout(0, Qt::Vertical );
180     GroupDimensions->setMinimumSize( QSize( 0, 90 ) );
181     GroupDimensions->layout()->setSpacing( 0 );
182     GroupDimensions->layout()->setMargin( 0 );
183     GroupDimensionsLayout = new QGridLayout( GroupDimensions->layout() );
184     GroupDimensionsLayout->setAlignment( Qt::AlignTop );
185     GroupDimensionsLayout->setSpacing( 6 );
186     GroupDimensionsLayout->setMargin( 11 );
187
188     TextLabel_DZ = new QLabel( GroupDimensions, "TextLabel_DZ" );
189     TextLabel_DZ->setText( tr( "GEOM_DZ"  ) );
190     GroupDimensionsLayout->addWidget( TextLabel_DZ, 0, 4 );
191     TextLabel_DY = new QLabel( GroupDimensions, "TextLabel_DY" );
192     TextLabel_DY->setText( tr( "GEOM_DY"  ) );
193     GroupDimensionsLayout->addWidget( TextLabel_DY, 0, 2 );
194     TextLabel_DX = new QLabel( GroupDimensions, "TextLabel_DX" );
195     TextLabel_DX->setText( tr( "GEOM_DX"  ) );
196     GroupDimensionsLayout->addWidget( TextLabel_DX, 0, 0 );
197  
198     /* Spin boxes construction */
199     SpinBox_DX = new GeometryGUI_SpinBox( GroupDimensions, "GeomSpinBox_DX" ) ;
200     GroupDimensionsLayout->addWidget( SpinBox_DX, 0, 1 );
201     SpinBox_DY = new GeometryGUI_SpinBox( GroupDimensions, "GeomSpinBox_DY" ) ;
202     GroupDimensionsLayout->addWidget( SpinBox_DY, 0, 3 );
203     SpinBox_DZ = new GeometryGUI_SpinBox( GroupDimensions, "GeomSpinBox_DZ" ) ;
204     GroupDimensionsLayout->addWidget( SpinBox_DZ, 0, 5 );
205
206     QSpacerItem* spacer1 = new QSpacerItem( 20, 24, QSizePolicy::Minimum, QSizePolicy::Fixed );
207     GroupDimensionsLayout->addItem( spacer1, 1, 3 );
208
209     GeometryGUI_BoxDlgLayout->addWidget( GroupDimensions, 1, 0 );
210
211     /* Initialisations */
212     Init(Sel) ;
213 }
214
215
216 //=================================================================================
217 // function : ~DialogBox_Box()
218 // purpose  : Destroys the object and frees any allocated resources
219 //=================================================================================
220 GeometryGUI_BoxDlg::~GeometryGUI_BoxDlg()
221 {
222   // no need to delete child widgets, Qt does it all for us
223   this->destroy(TRUE, TRUE) ;
224 }
225
226
227 //=================================================================================
228 // function : Init()
229 // purpose  :
230 //=================================================================================
231 void GeometryGUI_BoxDlg::Init(SALOME_Selection *Sel)
232 {
233
234
235   /* Get setting of step value from file configuration */
236   double step ;
237   QString St = QAD_CONFIG->getSetting( "Geometry:SettingsGeomStep" ) ;
238   step = St.toDouble() ;
239
240   /* min, max, step and decimals for spin boxes */
241   SpinBox_DX->RangeStepAndValidator( -999.999, 999.999, step, 3 ) ;
242   SpinBox_DX->SetValue( 200.0 ) ;  
243   SpinBox_DY->RangeStepAndValidator( -999.999, 999.999, step, 3 ) ;
244   SpinBox_DY->SetValue( 200.0 ) ;
245   SpinBox_DZ->RangeStepAndValidator( -999.999, 999.999, step, 3 ) ;
246   SpinBox_DZ->SetValue( 200.0 ) ; 
247
248   GroupPoints->show();
249   GroupDimensions->hide() ;
250   myConstructorId = 0 ;
251   Constructor1->setChecked( TRUE );
252   myEditCurrentArgument = LineEditPt1 ;
253   mySelection = Sel;
254   myGeomGUI = GeometryGUI::GetGeometryGUI() ;
255   myPoint1.SetCoord( 0.0, 0.0, 0.0 );
256   myPoint2.SetCoord( 0.0, 0.0, 0.0 );
257   myOkPoint1 = myOkPoint2 = false ;
258   mySimulationTopoDs.Nullify() ;
259   
260   myGeomGUI->SetActiveDialogBox( (QDialog*)this ) ;
261   
262   // TODO previous selection into argument ?
263   
264   /*  Vertices Filter for all arguments */
265   Engines::Component_var comp = QAD_Application::getDesktop()->getEngine("FactoryServer", "Geometry");
266   myGeom = GEOM::GEOM_Gen::_narrow(comp);
267   myVertexFilter = new GEOM_ShapeTypeFilter( TopAbs_VERTEX, myGeom );
268   mySelection->AddFilter( myVertexFilter ); /* filter for next selection */
269   
270   /* signals and slots connections */
271   connect( buttonOk, SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) ) ;
272   connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( ClickOnCancel() ) ) ;
273   connect( buttonApply, SIGNAL( clicked() ),  this, SLOT( ClickOnApply() ) ) ;
274   connect( GroupConstructors, SIGNAL(clicked(int) ), this, SLOT( ConstructorsClicked(int) ) ) ;
275   connect( SelectButtonPt1, SIGNAL (clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ;
276   connect( SelectButtonPt2, SIGNAL (clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ;
277  
278   connect( SpinBox_DX, SIGNAL ( valueChanged( double) ), this, SLOT( ValueChangedInSpinBox( double) ) ) ;
279   connect( SpinBox_DY, SIGNAL ( valueChanged( double) ), this, SLOT( ValueChangedInSpinBox( double) ) ) ;
280   connect( SpinBox_DZ, SIGNAL ( valueChanged( double) ), this, SLOT( ValueChangedInSpinBox( double) ) ) ;
281
282   connect( LineEditPt1, SIGNAL ( returnPressed() ), this, SLOT( LineEditReturnPressed() ) ) ;
283   connect( LineEditPt2, SIGNAL ( returnPressed() ), this, SLOT( LineEditReturnPressed() ) ) ;
284   
285   connect( myGeomGUI,   SIGNAL ( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) ) ;      
286   connect( mySelection, SIGNAL ( currentSelectionChanged() ),      this, SLOT( SelectionIntoArgument() ) ) ;
287   /* To close dialog if study change */
288   connect( myGeomGUI, SIGNAL ( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) ) ;
289
290   /* Move widget on the botton right corner of main widget */
291   int x, y ;
292   myGeomGUI->DefineDlgPosition( this, x, y ) ;
293   this->move( x, y ) ;
294   
295   this->show() ; /* displays Dialog */
296 }
297
298
299
300 //=================================================================================
301 // function : ConstructorsClicked()
302 // purpose  : Radio button management
303 //=================================================================================
304 void GeometryGUI_BoxDlg::ConstructorsClicked(int constructorId)
305 {
306
307   mySelection->ClearFilters() ;
308   myGeomGUI->EraseSimulationShape() ;
309
310   switch (constructorId)
311     {
312     case 0:
313       {
314         GroupPoints->show();
315         GroupDimensions->hide() ;
316         myConstructorId = constructorId ;
317         myEditCurrentArgument = LineEditPt1 ;
318         Constructor1->setChecked( TRUE );
319         LineEditPt1->setText("") ;
320         LineEditPt2->setText("") ;
321         myOkPoint1 = myOkPoint2 = false ;
322         
323         /* filter for next selection */
324         mySelection->AddFilter( myVertexFilter );
325         connect ( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
326         break;
327       }
328     case 1:
329       {
330         GroupPoints->hide();
331         GroupDimensions->show();
332         myConstructorId = constructorId ;
333         myOkPoint1 = myOkPoint2 = false ;
334
335         disconnect( mySelection, 0, this, 0 );
336         
337         double initValue = 200.0 ;
338         SpinBox_DX->SetValue( initValue ) ;
339         SpinBox_DY->SetValue( initValue ) ;
340         SpinBox_DZ->SetValue( initValue ) ;
341
342         myPoint1.SetCoord( 0.0, 0.0, 0.0 ) ;
343         myPoint2.SetCoord( initValue, initValue,initValue  ) ;
344
345         mySimulationTopoDs = BRepPrimAPI_MakeBox( myPoint1, myPoint2 ).Shape();
346         myGeomGUI->DisplaySimulationShape( mySimulationTopoDs ) ; 
347         break;
348       }
349     }
350  return ;
351 }
352
353 //=================================================================================
354 // function : ClickOnOk()
355 // purpose  :
356 //=================================================================================
357 void GeometryGUI_BoxDlg::ClickOnOk()
358 {
359   this->ClickOnApply() ;
360   this->ClickOnCancel() ;
361   return ;
362 }
363
364 //=================================================================================
365 // function : ClickOnApply()
366 // purpose  :
367 //=================================================================================
368 void GeometryGUI_BoxDlg::ClickOnApply()
369 {
370 //NRI+ : 02/12/2202 - BugID 1065
371 //    if (mySimulationTopoDs.IsNull())
372 //      return;
373   myGeomGUI->EraseSimulationShape() ;
374   mySimulationTopoDs.Nullify() ;
375   myGeomGUI->GetDesktop()->putInfo( tr("") ) ; 
376
377   switch(myConstructorId)
378     { 
379     case 0 :
380       {
381         //NRI+ : 02/12/2202 - BugID 1065        mySelection->ClearFilters() ;
382         if(myOkPoint1 && myOkPoint2) 
383           myGeomGUI->MakeBoxAndDisplay( myPoint1, myPoint2 ) ;
384         break ;
385       }
386     case 1 :
387       {
388         /* Recup args and call method */
389         double vx = SpinBox_DX->GetValue() ;
390         double vy = SpinBox_DY->GetValue() ;
391         double vz = SpinBox_DZ->GetValue() ;
392         myPoint1.SetCoord(0.0, 0.0, 0.0) ;
393         myPoint2.SetCoord(vx, vy, vz) ;
394         myGeomGUI->MakeBoxAndDisplay( myPoint1, myPoint2 ) ;
395         break ;
396       }
397     }
398   return ;
399 }
400
401
402 //=================================================================================
403 // function : ClickOnCancel()
404 // purpose  :
405 //=================================================================================
406 void GeometryGUI_BoxDlg::ClickOnCancel()
407 {
408   mySelection->ClearFilters() ;
409   myGeomGUI->EraseSimulationShape() ;
410   mySimulationTopoDs.Nullify() ;
411   disconnect( mySelection, 0, this, 0 );
412   myGeomGUI->ResetState() ;
413   reject() ;
414   return ;
415 }
416
417
418 //=================================================================================
419 // function : SelectionIntoArgument()
420 // purpose  : Called when selection as changed
421 //=================================================================================
422 void GeometryGUI_BoxDlg::SelectionIntoArgument()
423 {
424   myEditCurrentArgument->setText("") ;
425   myGeomGUI->EraseSimulationShape() ; 
426   mySimulationTopoDs.Nullify() ;
427
428   QString aString = "" ; /* name of selection */
429
430   int nbSel = myGeomGUI->GetNameOfSelectedIObjects(mySelection, aString) ;
431   if ( nbSel != 1 ) {
432     if ( myEditCurrentArgument == LineEditPt1 ) {
433       myOkPoint1 = false ;
434     }
435     else if ( myEditCurrentArgument == LineEditPt2 ) {
436       myOkPoint2 = false ;
437     }
438     return ;
439   }
440
441   // nbSel == 1
442   TopoDS_Shape S; 
443   if( !myGeomGUI->GetTopoFromSelection(mySelection, S) )
444     return ;
445
446   if ( myEditCurrentArgument == LineEditPt1 && myGeomGUI->VertexToPoint(S, myPoint1) ) {
447     myEditCurrentArgument->setText( aString ) ;
448     myOkPoint1 = true ;
449   }
450   else if ( myEditCurrentArgument == LineEditPt2 && myGeomGUI->VertexToPoint(S, myPoint2) ) {
451     myEditCurrentArgument->setText( aString ) ;
452     myOkPoint2 = true ;
453   }
454
455   if( myOkPoint1 && myOkPoint2 && TestBoxDimensions( myPoint1, myPoint2 ) ) {    
456     mySimulationTopoDs = BRepPrimAPI_MakeBox( myPoint1, myPoint2 ).Shape();
457     myGeomGUI->DisplaySimulationShape( mySimulationTopoDs ) ; 
458   }
459   return ;
460 }
461
462
463 //=================================================================================
464 // function : SetEditCurrentArgument()
465 // purpose  :
466 //=================================================================================
467 void GeometryGUI_BoxDlg::SetEditCurrentArgument()
468 {
469   QPushButton* send = (QPushButton*)sender();
470   switch (myConstructorId)
471     {
472     case 0: // default constructor
473       { 
474         if(send == SelectButtonPt1) {
475           LineEditPt1->setFocus() ;
476           myEditCurrentArgument = LineEditPt1;
477         }
478         else if(send == SelectButtonPt2) {
479           LineEditPt2->setFocus() ;
480           myEditCurrentArgument = LineEditPt2;
481         }       
482         mySelection->AddFilter(myVertexFilter) ;
483         SelectionIntoArgument() ;
484         break;
485       }
486     case 1:
487       { 
488         /* nothing to do here */
489         break;
490       }
491     }
492   return ;
493 }
494
495 //=================================================================================
496 // function : ValueChangedInSpinBox()
497 // purpose  :
498 //=================================================================================
499 void GeometryGUI_BoxDlg::ValueChangedInSpinBox( double newValue )
500 {
501   if(myConstructorId != 1)
502     return ;
503   
504   myGeomGUI->EraseSimulationShape() ; 
505   mySimulationTopoDs.Nullify() ;
506
507   QObject* send = (QObject*)sender() ; 
508   double vx, vy, vz ;
509   
510   if( send == SpinBox_DX ) {
511     vx = newValue ;
512     vy = SpinBox_DY->GetValue() ;
513     vz = SpinBox_DZ->GetValue() ;
514   } else if ( send == SpinBox_DY ) {
515     vx = SpinBox_DX->GetValue() ;
516     vy = newValue ;
517     vz = SpinBox_DZ->GetValue() ;
518   } else if (send == SpinBox_DZ ) {
519     vx = SpinBox_DX->GetValue() ;
520     vy = SpinBox_DY->GetValue() ;
521     vz = newValue ;
522   }
523   
524   myPoint1.SetCoord(0.0, 0.0, 0.0) ;
525   myPoint2.SetCoord(vx, vy, vz) ;
526   
527   if ( TestBoxDimensions( myPoint1, myPoint2 ) ) {
528     mySimulationTopoDs = BRepPrimAPI_MakeBox( myPoint1, myPoint2 ).Shape();
529     myGeomGUI->DisplaySimulationShape( mySimulationTopoDs ) ; 
530   }
531   return ;
532 }
533
534
535 //=================================================================================
536 // function : LineEditReturnPressed()
537 // purpose  :
538 //=================================================================================
539 void GeometryGUI_BoxDlg::LineEditReturnPressed()
540 {
541   QLineEdit* send = (QLineEdit*)sender();  
542   if( send == LineEditPt1 )
543     myEditCurrentArgument = LineEditPt1 ;
544   else if ( send == LineEditPt2 )
545     myEditCurrentArgument = LineEditPt2 ; 
546   else
547     return ;
548   
549   /* User name of object input management                          */
550   /* If successfull the selection is changed and signal emitted... */
551   /* so SelectionIntoArgument() is automatically called.           */
552   const QString objectUserName = myEditCurrentArgument->text() ;
553   QWidget* thisWidget = (QWidget*)this ;
554   if( myGeomGUI->SelectionByNameInDialogs( thisWidget, objectUserName, mySelection ) ) {
555     myEditCurrentArgument->setText( objectUserName ) ;
556   }
557   return ;
558 }
559
560
561 //=================================================================================
562 // function : DeactivateActiveDialog()
563 // purpose  :
564 //=================================================================================
565 void GeometryGUI_BoxDlg::DeactivateActiveDialog()
566 {
567   if ( GroupConstructors->isEnabled() ) {
568
569     GroupConstructors->setEnabled(false) ;
570     GroupDimensions->setEnabled(false) ;
571     GroupButtons->setEnabled(false) ;
572     GroupPoints->setEnabled(false) ;
573
574     mySelection->ClearFilters() ;
575     disconnect( mySelection, 0, this, 0 );
576     myGeomGUI->SetActiveDialogBox(0) ;
577     myGeomGUI->EraseSimulationShape() ;
578   }
579   return ;
580 }
581
582
583 //=================================================================================
584 // function : ActivateThisDialog()
585 // purpose  :
586 //=================================================================================
587 void GeometryGUI_BoxDlg::ActivateThisDialog()
588 {
589
590   /* Emit a signal to deactivate the active dialog */
591   myGeomGUI->EmitSignalDeactivateDialog() ; 
592
593   GroupConstructors->setEnabled(true) ;
594   GroupDimensions->setEnabled(true) ;
595   GroupButtons->setEnabled(true) ;
596   GroupPoints->setEnabled(true) ;  
597
598   connect ( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
599   myGeomGUI->SetActiveDialogBox( (QDialog*)this ) ;
600   if( !mySimulationTopoDs.IsNull() )
601     myGeomGUI->DisplaySimulationShape( mySimulationTopoDs ) ;
602   return ;
603 }
604
605
606 //=================================================================================
607 // function : enterEvent [REDEFINED]
608 // purpose  :
609 //=================================================================================
610 void GeometryGUI_BoxDlg::enterEvent(QEvent* e)
611 {
612   if ( GroupConstructors->isEnabled() )
613     return ;
614   ActivateThisDialog() ;
615 }
616
617
618 //=================================================================================
619 // function : closeEvent()
620 // purpose  :
621 //=================================================================================
622 void GeometryGUI_BoxDlg::closeEvent( QCloseEvent* e )
623 {
624   this->ClickOnCancel() ; /* same than click on cancel button */
625 }
626
627
628 //=================================================================================
629 // function : TestBoxDimensions()
630 // purpose  :
631 //=================================================================================
632 bool GeometryGUI_BoxDlg::TestBoxDimensions(gp_Pnt P1,  gp_Pnt P2)
633 {
634   if ( ( fabs( P1.X() - P2.X() ) > Precision::Confusion() ) &&
635        ( fabs( P1.Y() - P2.Y() ) > Precision::Confusion() ) &&
636        ( fabs( P1.Z() - P2.Z() ) > Precision::Confusion() ) )
637     return true ;
638   return false ;
639 }