Salome HOME
NRI : First integration.
[modules/geom.git] / src / GEOMGUI / GeometryGUI_PointDlg.cxx
1 using namespace std;
2 //  File      : GeometryGUI_PointDlg.cxx
3 //  Created   :
4 //  Author    : Lucien PIGNOLONI
5 //  Project   : SALOME
6 //  Module    : GeometryGUI
7 //  Copyright : OPEN CASCADE
8 //  $Header$
9
10
11 #include "GeometryGUI_PointDlg.h"
12
13 #include "GeometryGUI.h"
14 #include "QAD_Application.h"
15 #include "QAD_RightFrame.h"
16 #include "QAD_Config.h"
17 #include "QAD_Desktop.h"
18 #include "QAD_Tools.h"
19 #include "OCCViewer_Viewer3d.h"
20 #include "utilities.h"
21
22 #include <BRepBuilderAPI_MakeVertex.hxx>
23 #include <BRep_Tool.hxx>
24 #include <BRepAlgoAPI.hxx>
25 #include <Geom_Curve.hxx>
26
27 #include <qbuttongroup.h>
28 #include <qframe.h>
29 #include <qgroupbox.h>
30 #include <qlabel.h>
31 #include <qlineedit.h>
32 #include <qpushbutton.h>
33 #include <qradiobutton.h>
34 #include <qlayout.h>
35 #include <qvariant.h>
36 #include <qtooltip.h>
37 #include <qwhatsthis.h>
38 #include <qimage.h>
39 #include <qpixmap.h>
40 #include <qvalidator.h>
41 #include <qevent.h>
42
43
44
45 //=================================================================================
46 // class    : GeometryGUI_PointDlg()
47 // purpose  : Constructs a GeometryGUI_PointDlg which is a child of 'parent', with the 
48 //            name 'name' and widget flags set to 'f'.
49 //            The dialog will by default be modeless, unless you set 'modal' to
50 //            TRUE to construct a modal dialog.
51 //=================================================================================
52 GeometryGUI_PointDlg::GeometryGUI_PointDlg( QWidget* parent,
53                                             const char* name,
54                                             SALOME_Selection* Sel,
55                                             const Handle (AIS_InteractiveContext)& ic,
56                                             bool modal,
57                                             WFlags fl )
58     : QDialog( parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
59 {
60
61     QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap( "GeometryGUI",tr("ICON_DLG_POINT")));
62     QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap( "GeometryGUI",tr("ICON_SELECT")));
63     QPixmap image2(QAD_Desktop::getResourceManager()->loadPixmap( "GeometryGUI",tr("ICON_DLG_POINT_EDGE")));
64
65     if ( !name )
66         setName( "GeometryGUI_PointDlg" );
67     resize( 303, 185 ); 
68     setCaption( tr( "GEOM_POINT_TITLE"  ) );
69     setSizeGripEnabled( TRUE );
70     GeometryGUI_PointDlgLayout = new QGridLayout( this ); 
71     GeometryGUI_PointDlgLayout->setSpacing( 6 );
72     GeometryGUI_PointDlgLayout->setMargin( 11 );
73
74     /***************************************************************/
75     GroupButtons = new QGroupBox( this, "GroupButtons" );
76     GroupButtons->setGeometry( QRect( 10, 10, 281, 48 ) ); 
77     GroupButtons->setTitle( tr( ""  ) );
78     GroupButtons->setColumnLayout(0, Qt::Vertical );
79     GroupButtons->layout()->setSpacing( 0 );
80     GroupButtons->layout()->setMargin( 0 );
81     GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
82     GroupButtonsLayout->setAlignment( Qt::AlignTop );
83     GroupButtonsLayout->setSpacing( 6 );
84     GroupButtonsLayout->setMargin( 11 );
85     buttonCancel = new QPushButton( GroupButtons, "buttonCancel" );
86     buttonCancel->setText( tr( "GEOM_BUT_CLOSE"  ) );
87     buttonCancel->setAutoDefault( TRUE );
88     GroupButtonsLayout->addWidget( buttonCancel, 0, 3 );
89     buttonApply = new QPushButton( GroupButtons, "buttonApply" );
90     buttonApply->setText( tr( "GEOM_BUT_APPLY"  ) );
91     buttonApply->setAutoDefault( TRUE );
92     GroupButtonsLayout->addWidget( buttonApply, 0, 1 );
93     QSpacerItem* spacer_9 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
94     GroupButtonsLayout->addItem( spacer_9, 0, 2 );
95     buttonOk = new QPushButton( GroupButtons, "buttonOk" );
96     buttonOk->setText( tr( "GEOM_BUT_OK"  ) );
97     buttonOk->setAutoDefault( TRUE );
98     buttonOk->setDefault( TRUE );
99     GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
100     GeometryGUI_PointDlgLayout->addWidget( GroupButtons, 2, 0 );
101
102     /***************************************************************/
103     GroupConstructors = new QButtonGroup( this, "GroupConstructors" );
104     GroupConstructors->setTitle( tr( "Constructors"  ) );
105     GroupConstructors->setExclusive( TRUE );
106     GroupConstructors->setColumnLayout(0, Qt::Vertical );
107     GroupConstructors->layout()->setSpacing( 0 );
108     GroupConstructors->layout()->setMargin( 0 );
109     GroupConstructorsLayout = new QGridLayout( GroupConstructors->layout() );
110     GroupConstructorsLayout->setAlignment( Qt::AlignTop );
111     GroupConstructorsLayout->setSpacing( 6 );
112     GroupConstructorsLayout->setMargin( 11 );
113
114     Constructor1 = new QRadioButton( GroupConstructors, "Constructor1" );
115     Constructor1->setText( tr( ""  ) );
116     Constructor1->setPixmap( image0 );
117     Constructor1->setChecked( FALSE );
118     Constructor1->setMinimumSize( QSize( 50, 0 ) );
119
120     GroupConstructorsLayout->addWidget( Constructor1, 0, 0 );
121     QSpacerItem* spacer_2 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
122     GroupConstructorsLayout->addItem( spacer_2, 0, 1 );
123
124     Constructor2 = new QRadioButton( GroupConstructors, "Constructor2" );
125     Constructor2->setText( tr( ""  ) );
126     Constructor2->setPixmap( image2 );
127     Constructor2->setChecked( TRUE );
128     Constructor2->setMinimumSize( QSize( 50, 0 ) );
129
130     GroupConstructorsLayout->addWidget( Constructor2, 0, 2 );
131     QSpacerItem* spacer_3 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
132     GroupConstructorsLayout->addItem( spacer_3, 0, 3 );
133
134     GeometryGUI_PointDlgLayout->addWidget( GroupConstructors, 0, 0 );
135
136
137     /***************************************************************/
138     GroupCoordinates = new QGroupBox( this, "GroupCoordinates" );
139     GroupCoordinates->setTitle( tr( "GEOM_COORDINATES"  ) );
140     GroupCoordinates->setColumnLayout(0, Qt::Vertical );
141     GroupCoordinates->layout()->setSpacing( 0 );
142     GroupCoordinates->layout()->setMargin( 0 );
143     GroupCoordinatesLayout = new QGridLayout( GroupCoordinates->layout() );
144     GroupCoordinatesLayout->setAlignment( Qt::AlignTop );
145     GroupCoordinatesLayout->setSpacing( 6 );
146     GroupCoordinatesLayout->setMargin( 11 );
147
148     TextLabel_X = new QLabel( GroupCoordinates, "TextLabel_X" );
149     TextLabel_X->setText( tr( "GEOM_X"  ) );
150     GroupCoordinatesLayout->addWidget( TextLabel_X, 0, 0 );
151     TextLabel_Y = new QLabel( GroupCoordinates, "TextLabel_Y" );
152     TextLabel_Y->setText( tr( "GEOM_Y"  ) );
153     GroupCoordinatesLayout->addWidget( TextLabel_Y, 0, 2 );
154     TextLabel_Z = new QLabel( GroupCoordinates, "TextLabel_Z" );
155     TextLabel_Z->setText( tr( "GEOM_Z"  ) );
156     GroupCoordinatesLayout->addWidget( TextLabel_Z, 0, 4 );
157  
158     /* Spin boxes construction */
159     SpinBox_X = new GeometryGUI_SpinBox( GroupCoordinates, "GeomSpinBox_X" ) ;
160     GroupCoordinatesLayout->addWidget( SpinBox_X, 0, 1 );
161     SpinBox_Y = new GeometryGUI_SpinBox( GroupCoordinates, "GeomSpinBox_Y" ) ;
162     GroupCoordinatesLayout->addWidget( SpinBox_Y, 0, 3 );
163     SpinBox_Z = new GeometryGUI_SpinBox( GroupCoordinates, "GeomSpinBox_Z" ) ;
164     GroupCoordinatesLayout->addWidget( SpinBox_Z, 0, 5 );
165     GeometryGUI_PointDlgLayout->addWidget( GroupCoordinates, 1, 0 );
166
167     /***************************************************************/
168     GroupWithEdge = new QGroupBox( this, "GroupWithEdge" );
169     GroupWithEdge->setTitle( tr( "GEOM_PARAM_POINT" ) );
170     GroupWithEdge->setFrameShape( QGroupBox::Box );
171     GroupWithEdge->setFrameShadow( QGroupBox::Sunken );
172     GroupWithEdge->setColumnLayout(0, Qt::Vertical );
173     GroupWithEdge->layout()->setSpacing( 0 );
174     GroupWithEdge->layout()->setMargin( 0 );
175     GroupWithEdgeLayout = new QGridLayout( GroupWithEdge->layout() );
176     GroupWithEdgeLayout->setAlignment( Qt::AlignTop );
177     GroupWithEdgeLayout->setSpacing( 6 );
178     GroupWithEdgeLayout->setMargin( 11 );
179
180     LineEdit_Edge = new QLineEdit( GroupWithEdge, "LineEdit_Edge" );
181     GroupWithEdgeLayout->addWidget( LineEdit_Edge, 0, 2 );
182
183     SelectButton_Edge = new QPushButton( GroupWithEdge, "SelectButton_Edge" );
184     SelectButton_Edge->setText( tr( ""  ) );
185     SelectButton_Edge->setPixmap( image1 );
186     SelectButton_Edge->setToggleButton( FALSE );
187     GroupWithEdgeLayout->addWidget( SelectButton_Edge, 0, 1 );
188  
189     /* Spin box */
190     SpinBox_Parameter = new GeometryGUI_SpinBox( GroupWithEdge, "SpinBox_Parameter" );
191     GroupWithEdgeLayout->addWidget( SpinBox_Parameter, 1, 2 );
192
193     TextLabel_Edge = new QLabel( GroupWithEdge, "TextLabel_Edge" );
194     TextLabel_Edge->setText( tr( "GEOM_EDGE"  ) );
195     TextLabel_Edge->setMinimumSize( QSize( 50, 0 ) );
196     TextLabel_Edge->setFrameShape( QLabel::NoFrame );
197     TextLabel_Edge->setFrameShadow( QLabel::Plain );
198     GroupWithEdgeLayout->addWidget( TextLabel_Edge, 0, 0 );
199
200     TextLabel_Parameter = new QLabel( GroupWithEdge, "TextLabel_Parameter" );
201     TextLabel_Parameter->setText( tr( "GEOM_PARAMETER"  ) );
202     TextLabel_Parameter->setMinimumSize( QSize( 50, 0 ) );
203     TextLabel_Parameter->setFrameShape( QLabel::NoFrame );
204     TextLabel_Parameter->setFrameShadow( QLabel::Plain );
205     GroupWithEdgeLayout->addWidget( TextLabel_Parameter, 1, 0 );
206
207     GeometryGUI_PointDlgLayout->addWidget( GroupWithEdge, 1, 0 );
208     /***************************************************************/
209
210     /* Initialisation and display */
211     Init(Sel, ic) ;
212  
213     /* Move widget on the botton right corner of main widget */
214     QAD_Tools::alignWidget(this, parent, AlignBottom | AlignRight);
215     /* Display  Dialog */
216     this->show() ; 
217 }
218
219
220 //=======================================================================
221 // function : ~GeometryGUI_PointDlg()
222 // purpose  : Destructor
223 //=======================================================================
224 GeometryGUI_PointDlg::~GeometryGUI_PointDlg()
225 {
226   /* no need to delete child widgets, Qt does it all for us */
227 }
228
229
230 //=================================================================================
231 // function : Init()
232 // purpose  :
233 //=================================================================================
234 void GeometryGUI_PointDlg::Init(SALOME_Selection* Sel, const Handle(AIS_InteractiveContext)& ic)
235 {
236   
237   /* Get setting of step value from file configuration */
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_X->RangeStepAndValidator( -999.999, 999.999, step, 3 ) ;
244   SpinBox_X->SetValue( 0.0 ) ;
245   SpinBox_Y->RangeStepAndValidator( -999.999, 999.999, step, 3 ) ;
246   SpinBox_Y->SetValue( 0.0 ) ;
247   SpinBox_Z->RangeStepAndValidator( -999.999, 999.999, step, 3 ) ;
248   SpinBox_Z->SetValue( 0.0 ) ; 
249
250   /* spin box for parameter on edge */
251   double specificStep = 0.1 ;
252   SpinBox_Parameter->RangeStepAndValidator( -999999.99999, 999999.99999, specificStep, 5 ) ;
253   SpinBox_Parameter->SetValue( 0.50 ) ;
254   myParameter = 0.50 ;
255
256   GroupCoordinates->show();
257   GroupWithEdge->hide() ;
258   myConstructorId = 0 ;
259   Constructor1->setChecked( TRUE );
260
261   /* filter for the second constructor */
262   Engines::Component_var comp = QAD_Application::getDesktop()->getEngine("FactoryServer", "Geometry");
263   myGeom = GEOM::GEOM_Gen::_narrow(comp);
264   myEdgeFilter = new GEOM_ShapeTypeFilter( TopAbs_EDGE, myGeom );
265   
266   bool displayPoint = false ;
267   mySelection = Sel ;
268   myGeomGUI = GeometryGUI::GetGeometryGUI() ;   
269   myGeomGUI->SetActiveDialogBox( (QDialog*)this ) ;
270   myGeomGUI->SetState(POINT_METHOD) ;
271   
272   mySelection = Sel;
273   myOkEdge = false ;
274   
275   /* manages local context selection */
276   myIC = ic ;
277
278   if ( myGeomGUI->GetActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_OCC ) {
279     myLocalContextId = myIC->OpenLocalContext();
280     myGeomGUI->SetDisplayedObjectList();
281     /* sub shapes selection */
282     myLocalContextMode = TopAbs_VERTEX ;
283     myIC->ActivateStandardMode(myLocalContextMode) ;
284     myUseLocalContext = true ;
285   } else {
286     myUseLocalContext = false ;
287   }
288
289   
290   myPoint.SetCoord( 0.0, 0.0, 0.0 ) ;
291   TopoDS_Shape S; 
292   
293   if( myGeomGUI->GetTopoFromSelection(mySelection, S) ) {
294     
295     /* Filter a possibly previous selection and try to put it into coordinates */
296     if( myGeomGUI->VertexToPoint( S,  myPoint) )
297       displayPoint = false ;
298     else
299       displayPoint = true ;
300   }
301   else {
302     displayPoint = true ;
303   }
304   
305   mySimulationTopoDs.Nullify() ;
306   PointIntoCoordinates(myPoint, displayPoint) ;
307   
308   /* signals and slots connections */
309   connect( buttonOk,          SIGNAL( clicked() ),   this, SLOT( ClickOnOk() ) );
310   connect( buttonCancel,      SIGNAL( clicked() ),   this, SLOT( ClickOnCancel() ) );
311   connect( buttonApply,       SIGNAL( clicked() ),   this, SLOT(ClickOnApply() ) );
312   connect( SelectButton_Edge, SIGNAL (clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ;
313
314   connect( GroupConstructors, SIGNAL(clicked(int) ), this, SLOT( ConstructorsClicked(int) ) ) ;
315
316   connect( SpinBox_X, SIGNAL ( valueChanged( double) ), this, SLOT( ValueChangedInSpinBox( double ) ) ) ;
317   connect( SpinBox_Y, SIGNAL ( valueChanged( double) ), this, SLOT( ValueChangedInSpinBox( double ) ) ) ;
318   connect( SpinBox_Z, SIGNAL ( valueChanged( double) ), this, SLOT( ValueChangedInSpinBox( double ) ) ) ;
319
320   connect( SpinBox_Parameter,  SIGNAL ( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) ) ;
321   connect( LineEdit_Edge,      SIGNAL ( returnPressed() ),                   this, SLOT( LineEditReturnPressed() ) ) ;
322   
323   connect( myGeomGUI,   SIGNAL ( SignalDeactivateActiveDialog() ),this, SLOT( DeactivateActiveDialog() ) ) ;
324   connect( myGeomGUI,   SIGNAL ( SignalCloseAllDialogs() ),       this, SLOT( ClickOnCancel() ) ) ;
325   // connect( mySelection, SIGNAL ( currentSelectionChanged() ),     this, SLOT( SelectionIntoArgument() ) ) ; done in constructor clicked !
326
327   /* Move widget on the botton right corner of main widget */
328   int x, y ;
329   myGeomGUI->DefineDlgPosition( this, x, y ) ;
330   this->move( x, y ) ;
331   this->show() ; /* Displays this Dialog */
332 }
333
334
335
336 //=================================================================================
337 // function : ValueChangedInSpinBox()
338 // purpose  :
339 //=================================================================================
340 void GeometryGUI_PointDlg::ValueChangedInSpinBox( double newValue )
341 {
342   GeometryGUI_SpinBox* send = (GeometryGUI_SpinBox*)sender() ;
343   double vx, vy, vz ;
344   if( send == SpinBox_X ) {
345     vx = newValue ;
346     vy = SpinBox_Y->GetValue() ;
347     vz = SpinBox_Z->GetValue() ;
348   } else if ( send == SpinBox_Y ) {
349     vx = SpinBox_X->GetValue() ;
350     vy = newValue ;
351     vz = SpinBox_Z->GetValue() ;
352   } else if (send == SpinBox_Z ) {
353     vx = SpinBox_X->GetValue() ;
354     vy = SpinBox_Y->GetValue() ;
355     vz = newValue ;
356   }  else if (send == SpinBox_Parameter ) {
357     myParameter = newValue ;
358   } else
359     return ;
360   
361   
362   switch (myConstructorId) {
363   case 0: // default constructor 
364     {
365       myPoint.SetCoord(vx, vy, vz) ;
366       myGeomGUI->EraseSimulationShape() ;
367       mySimulationTopoDs = BRepBuilderAPI_MakeVertex (myPoint).Shape() ;
368       myGeomGUI->DisplaySimulationShape( mySimulationTopoDs ) ;
369       break ;
370     }
371   case 1: 
372     {
373       this->SelectionIntoArgument() ;   
374       break ;
375     }
376   }
377
378   return ;
379 }
380
381
382
383 //=======================================================================
384 // funcion  : PointIntoCoordinates()
385 // purpose  : Sets user point coordinates into this dialog Spin boxes
386 //          : and displays it or not according to 'bool displayPoint'
387 //=======================================================================
388 void GeometryGUI_PointDlg::PointIntoCoordinates(gp_Pnt P, bool displayPoint)
389 {
390   switch (myConstructorId) {    
391   case 0 : {
392     SpinBox_X->SetValue( P.X() ) ;
393     SpinBox_Y->SetValue( P.Y() ) ;
394     SpinBox_Z->SetValue( P.Z() ) ;
395     this->myPoint.SetCoord( P.X(), P.Y(), P.Z() ) ;
396     if( displayPoint ) {
397       mySimulationTopoDs = BRepBuilderAPI_MakeVertex(P).Shape() ;
398       myGeomGUI->DisplaySimulationShape(mySimulationTopoDs) ;
399     }
400     break ;
401   }
402   case 1 :
403     {
404       // TODO
405       break ;
406     }
407   }
408   
409   return ;
410 }
411
412 //=================================================================================
413 // function : ConstructorsClicked()
414 // purpose  : Radio button management
415 //=================================================================================
416 void GeometryGUI_PointDlg::ConstructorsClicked(int constructorId)
417 {
418   myGeomGUI->EraseSimulationShape() ;
419   myConstructorId = constructorId ;
420     switch (constructorId)
421     {
422     case 0:
423       {
424         if ( myUseLocalContext == false && myGeomGUI->GetActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_OCC ) {
425           myLocalContextId = myIC->OpenLocalContext();
426           myGeomGUI->SetDisplayedObjectList();
427           /* sub shapes selection */
428           myLocalContextMode = TopAbs_VERTEX ;
429           myIC->ActivateStandardMode(myLocalContextMode) ;
430           myUseLocalContext = true ;
431         }
432         mySelection->ClearFilters() ;
433         GroupCoordinates->show();
434         GroupWithEdge->hide() ;
435         /* Display point simulation */
436         PointIntoCoordinates( this->myPoint, true ) ;
437         disconnect( mySelection, 0, this, 0 );  
438         break;
439       }
440     case 1:
441       {
442         if ( myUseLocalContext == true && myGeomGUI->GetActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_OCC ) {
443           myIC->CloseLocalContext(myLocalContextId) ;
444           myUseLocalContext = false ;
445         }
446         LineEdit_Edge->setText("") ;
447         mySelection->AddFilter( myEdgeFilter );
448         GroupCoordinates->hide();
449         GroupWithEdge->show() ;
450         myOkEdge = false ;
451         connect ( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
452         break;
453       }
454     }
455  return ;
456 }
457
458
459 //=================================================================================
460 // function : LineEditReturnPressed()
461 // purpose  :
462 //=================================================================================
463 void GeometryGUI_PointDlg::LineEditReturnPressed()
464 {
465   QLineEdit* send = (QLineEdit*)sender();
466   if( send == LineEdit_Edge ) {
467     /* User name of object input management                          */
468     /* If successfull the selection is changed and signal emitted... */
469     /* so SelectionIntoArgument() is automatically called.           */
470     const QString objectUserName = send->text() ;
471     QWidget* thisWidget = (QWidget*)this ;
472     if( myGeomGUI->SelectionByNameInDialogs( thisWidget, objectUserName, mySelection ) ) {
473       LineEdit_Edge->setText( objectUserName ) ;
474     }
475   }
476   return ;
477 }
478
479
480
481 //=================================================================================
482 // function : ClickOnOk()
483 // purpose  :
484 //=================================================================================
485 void GeometryGUI_PointDlg::ClickOnOk()
486 {
487   this->ClickOnApply() ;
488   this->ClickOnCancel() ;
489
490   return ;
491 }
492
493 //=======================================================================
494 // function : ClickOnApply()
495 // purpose  :
496 //=======================================================================
497 void GeometryGUI_PointDlg::ClickOnApply()
498 {
499   
500   myGeomGUI->EraseSimulationShape() ;
501   
502   /* Close local context */
503   if ( myGeomGUI->GetActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_OCC ) {
504     myIC->CloseLocalContext(myLocalContextId) ;
505     myUseLocalContext = false ;
506   }
507
508   switch (myConstructorId) {
509     
510     case 0 :
511     {
512       /* Recup args and call method */
513       double x = SpinBox_X->GetValue() ;
514       double y = SpinBox_Y->GetValue() ;
515       double z = SpinBox_Z->GetValue() ;
516       
517       myGeomGUI->MakePointAndDisplay(x,y,z) ;  /* WARNING : no display if a local context is opened */
518       if ( myGeomGUI->GetActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_OCC ) {
519         /* no display if a local context is opened */
520         myLocalContextId = myIC->OpenLocalContext();
521         myGeomGUI->SetDisplayedObjectList();
522         /* sub shapes selection */
523         myLocalContextMode = TopAbs_VERTEX ;
524         myIC->ActivateStandardMode(myLocalContextMode);
525         myUseLocalContext = true ;
526       }
527       break ;
528     }
529   case 1 :
530     {
531       if( myOkEdge == true ) {
532         /* this constructor method has no idl interface : we use same than constructor 0 */
533         myGeomGUI->MakePointAndDisplay( myPoint.X(), myPoint.Y(), myPoint.Z() ) ;
534       }
535       break ;
536     }
537   }
538   
539   return ;
540 }
541
542
543 //=================================================================================
544 // function : SelectionIntoArgument()
545 // purpose  : Called when selection as changed (for constructors not using local context)
546 //=================================================================================
547 void GeometryGUI_PointDlg::SelectionIntoArgument()
548 {
549   myGeomGUI->EraseSimulationShape() ; 
550   LineEdit_Edge->setText("") ;
551   QString aString = "" ; /* future name of selection */
552   int nbSel = myGeomGUI->GetNameOfSelectedIObjects(mySelection, aString) ;
553   if ( nbSel != 1 ) {
554     this->myOkEdge = false ;
555     return ;
556   }
557   
558   // nbSel == 1
559   TopoDS_Shape S; 
560   if( !myGeomGUI->GetTopoFromSelection(mySelection, S) )
561     return ;
562   
563   switch (myConstructorId)
564     {
565     case 0:
566       break ;
567     case 1:
568       {
569         LineEdit_Edge->setText(aString) ;
570         if( S.ShapeType() == TopAbs_EDGE ) {
571           if( CalculateVertexOnCurve( TopoDS::Edge(S), myParameter, mySimulationTopoDs) ) {
572             if ( myGeomGUI->VertexToPoint( mySimulationTopoDs, myPoint ) ) {
573               this->myOkEdge = true ;
574               myGeomGUI->DisplaySimulationShape(mySimulationTopoDs) ;
575             }
576           }
577         }
578         break ; 
579       }
580     }
581   return ;
582 }
583
584
585
586 //=================================================================================
587 // function : SetEditCurrentArgument()
588 // purpose  :
589 //=================================================================================
590 void GeometryGUI_PointDlg::SetEditCurrentArgument()
591 {
592   QPushButton* send = (QPushButton*)sender();
593   switch (myConstructorId)
594     {
595     case 0: // default constructor
596        break;
597     case 1:
598       { 
599         if(send == SelectButton_Edge) {
600           LineEdit_Edge->setFocus() ;
601           SelectionIntoArgument() ;
602         }
603         break;
604       }
605     }
606   return ;
607 }
608
609
610 //=======================================================================
611 // function : UseLocalContext()
612 // purpose  : Return true when this method has opened a local context
613 //          : Used from GeometryGUI
614 //=======================================================================
615 bool GeometryGUI_PointDlg::UseLocalContext()
616 {
617   return this->myUseLocalContext ;
618 }
619
620
621 //=======================================================================
622 // function : closeEvent()
623 // purpose  :
624 //=======================================================================
625 void GeometryGUI_PointDlg::closeEvent(QCloseEvent* e)
626 {
627   this->ClickOnCancel() ; /* same than click on cancel button */
628 }
629
630
631 //=======================================================================
632 // function : ClickOnCancel()
633 // purpose  :
634 //=======================================================================
635 void GeometryGUI_PointDlg::ClickOnCancel()
636 {
637   if ( myConstructorId == 0 && myGeomGUI->GetActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_OCC ) {
638     OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)myGeomGUI->GetActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer();
639     myIC = v3d->getAISContext();
640     if ( myIC->HasOpenedContext() ) {
641       myIC->CloseLocalContext(myLocalContextId) ;
642       myUseLocalContext = false ;
643     }
644   }
645   mySelection->ClearFilters() ;
646   myGeomGUI->SetActiveDialogBox(0) ;
647   myGeomGUI->EraseSimulationShape() ;
648   myGeomGUI->ResetState() ;
649   reject() ;
650   return ;
651 }
652
653
654 //=================================================================================
655 // function : enterEvent()
656 // purpose  : to reactivate this dialog box when mouse enter onto the window
657 //=================================================================================
658 void GeometryGUI_PointDlg::enterEvent( QEvent* e)
659 {
660   if ( GroupConstructors->isEnabled() )
661     return ;
662   ActivateThisDialog() ;
663 }
664
665
666 //=================================================================================
667 // function : DeactivateActiveDialog()
668 // purpose  : public slot to deactivate if active
669 //=================================================================================
670 void GeometryGUI_PointDlg::DeactivateActiveDialog()
671 {
672   if ( GroupConstructors->isEnabled() ) {
673     
674     mySelection->ClearFilters() ;
675     GroupConstructors->setEnabled(false) ;
676     GroupCoordinates->setEnabled(false) ;
677     GroupWithEdge->setEnabled(false) ;
678     GroupButtons->setEnabled(false) ;
679     myGeomGUI->EraseSimulationShape() ;
680     myGeomGUI->ResetState() ;    
681     myGeomGUI->SetActiveDialogBox(0) ;
682     if ( myConstructorId == 0 && myGeomGUI->GetActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_OCC ) {
683       myIC->CloseLocalContext(myLocalContextId) ;
684       myUseLocalContext = false ;
685     }
686   }
687
688   return ;
689 }
690
691
692 //=================================================================================
693 // function : ActivateThisDialog()
694 // purpose  :
695 //=================================================================================
696 void GeometryGUI_PointDlg::ActivateThisDialog( )
697 {
698   
699   if ( !GroupConstructors->isEnabled() ) { /* if not active */
700     
701     myGeomGUI->EmitSignalDeactivateDialog() ;
702     GroupConstructors->setEnabled(true) ;
703     GroupCoordinates->setEnabled(true) ;
704     GroupWithEdge->setEnabled(true) ;
705     GroupButtons->setEnabled(true) ;
706     
707     myGeomGUI->SetState(POINT_METHOD) ;
708     myGeomGUI->SetActiveDialogBox( (QDialog*)this ) ;
709     
710     if ( myConstructorId == 0 ) {
711       
712       mySelection->ClearFilters() ;
713       if( myGeomGUI->GetActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_OCC ) {
714         OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)myGeomGUI->GetActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer();
715         myIC = v3d->getAISContext();
716         myLocalContextId = myIC->OpenLocalContext();
717         myGeomGUI->SetDisplayedObjectList();
718         /* sub shapes selection */
719         myLocalContextMode = TopAbs_VERTEX ;
720         myIC->ActivateStandardMode(myLocalContextMode);
721         myUseLocalContext = true ;
722       }
723     }
724     
725     if ( myConstructorId == 1 )
726       mySelection->AddFilter( myEdgeFilter );
727     
728     if( !mySimulationTopoDs.IsNull() )
729       myGeomGUI->DisplaySimulationShape( mySimulationTopoDs ) ;
730     
731   }
732   return ;
733 }
734
735
736 //=================================================================================
737 // function : CalculateVertexOnCurve()
738 // purpose  : Calculate a Vertex on the curve given by 'anEdge'.
739 //          : The position of resultVertex is given by aParameter.
740 //          : For a linear edge, aParameter=0.0 gives the first vertex of edge
741 //          :                    aParameter=1.0 gives the last vertex of edge
742 //          :                    aParameter=0.5 gives the vertex on the middle of edge
743 //          : It is possible to get vertices out of edge using values > 1.0 or < 0.0
744 //=================================================================================
745 bool GeometryGUI_PointDlg::CalculateVertexOnCurve(const TopoDS_Edge& anEdge, const Standard_Real aParameter, TopoDS_Shape& resultVertex) 
746 {
747   if( anEdge.IsNull() || !BRepAlgoAPI::IsValid(anEdge) )
748     return false ;
749
750   Standard_Real first, last ;
751   Handle(Geom_Curve) curv = BRep_Tool::Curve(anEdge, first, last);
752   if( !curv->IsCN(0) )
753     return false ;
754   
755   Standard_Real param;
756   if( anEdge.Orientation() == TopAbs_FORWARD ) {
757     param = first + (last-first) * aParameter ;
758   }
759   else {
760     param = last + (first-last) * aParameter ;
761   }
762   gp_Pnt paramPoint ;
763   curv->D0( param, paramPoint ) ;
764   resultVertex = BRepBuilderAPI_MakeVertex(paramPoint);
765   return true ;
766 }
767