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