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