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