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