Salome HOME
Merge from BR_Dev_For_4_0 branch (from tag mergeto_BR_QT4_Dev_17Jan08)
[modules/geom.git] / src / BasicGUI / BasicGUI_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.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 // File   : BasicGUI_PointDlg.cxx
23 // Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
24 //
25
26 #include "BasicGUI_PointDlg.h"
27
28 #include <SUIT_ResourceMgr.h>
29 #include <SUIT_Session.h>
30 #include <SalomeApp_Application.h>
31 #include <LightApp_SelectionMgr.h>
32
33 #include <GeometryGUI.h>
34 #include <GEOMBase.h>
35
36 #include <DlgRef.h>
37
38 #include <GEOMImpl_Types.hxx>
39
40 #include <QApplication>
41 #include <QLabel>
42
43 #include <gp_Pnt.hxx>
44 #include <TopoDS_Shape.hxx>
45 #include <TopAbs_ShapeEnum.hxx>
46 #include <TopoDS.hxx>
47 #include <BRep_Tool.hxx>
48 #include <TopExp.hxx>
49 #include <TColStd_IndexedMapOfInteger.hxx>
50 #include <TopTools_IndexedMapOfShape.hxx>
51
52 //=================================================================================
53 // class    : BasicGUI_PointDlg()
54 // purpose  : Constructs a BasicGUI_PointDlg which is a child of 'parent', with the 
55 //            name 'name' and widget flags set to 'f'.
56 //            The dialog will by default be modeless, unless you set 'modal' to
57 //            TRUE to construct a modal dialog.
58 //=================================================================================
59 BasicGUI_PointDlg::BasicGUI_PointDlg( GeometryGUI* theGeometryGUI, QWidget* parent,
60                                       bool modal, Qt::WindowFlags fl )
61   : GEOMBase_Skeleton( theGeometryGUI, parent, modal, fl )
62 {
63   QPixmap image0( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_POINT") ) );
64   QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_POINT_EDGE" ) ) );
65   QPixmap image2( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
66   QPixmap image3( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_POINT_REF" ) ) );
67   QPixmap image4( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_POINT_LINES") ) );
68
69   setWindowTitle( tr( "GEOM_POINT_TITLE" ) );
70
71   /***************************************************************/
72   mainFrame()->GroupConstructors->setTitle( tr( "GEOM_POINTS" ) );
73   mainFrame()->RadioButton1->setIcon( image0 );
74   mainFrame()->RadioButton2->setIcon( image3 );
75   mainFrame()->RadioButton3->setIcon( image1 );
76   mainFrame()->RadioButton4->show();
77   mainFrame()->RadioButton4->setIcon( image4 );
78
79   GroupXYZ = new DlgRef_3Spin( centralWidget() );
80   GroupXYZ->GroupBox1->setTitle( tr( "GEOM_COORDINATES" ) );
81   GroupXYZ->TextLabel1->setText( tr( "GEOM_X" ) );
82   GroupXYZ->TextLabel2->setText( tr( "GEOM_Y" ) );
83   GroupXYZ->TextLabel3->setText( tr( "GEOM_Z" ) );
84
85   GroupOnCurve = new DlgRef_1Sel1Spin( centralWidget() );
86   GroupOnCurve->GroupBox1->setTitle( tr( "GEOM_PARAM_POINT" ) );
87   GroupOnCurve->TextLabel1->setText( tr( "GEOM_EDGE" ) );
88   GroupOnCurve->TextLabel2->setText( tr( "GEOM_PARAMETER" ) );
89   GroupOnCurve->PushButton1->setIcon( image2 );
90
91   GroupRefPoint = new DlgRef_1Sel3Spin( centralWidget() );
92   GroupRefPoint->GroupBox1->setTitle( tr( "GEOM_REF_POINT" ) );
93   GroupRefPoint->TextLabel1->setText( tr( "GEOM_POINT" ) );
94   GroupRefPoint->PushButton1->setIcon( image2 );
95   GroupRefPoint->TextLabel2->setText( tr( "GEOM_DX" ) );
96   GroupRefPoint->TextLabel3->setText( tr( "GEOM_DY" ) );
97   GroupRefPoint->TextLabel4->setText( tr( "GEOM_DZ" ) );
98
99   GroupLineIntersection = new DlgRef_2Sel( centralWidget() );
100   GroupLineIntersection->GroupBox1->setTitle( tr( "GEOM_LINE_INTERSECTION" ) );
101   GroupLineIntersection->TextLabel1->setText( tr( "GEOM_LINE1" ) );
102   GroupLineIntersection->TextLabel2->setText( tr( "GEOM_LINE2" ) );
103   GroupLineIntersection->PushButton1->setIcon( image2 );
104   GroupLineIntersection->PushButton2->setIcon( image2 );
105
106   myCoordGrp = new QGroupBox( tr( "GEOM_COORDINATES" ), centralWidget() );
107   QGridLayout* myCoordGrpLayout = new QGridLayout( myCoordGrp );
108   myCoordGrpLayout->addWidget( new QLabel( tr( "GEOM_X" ), myCoordGrp ), 0, 0 );
109   myX = new QLineEdit( myCoordGrp );
110   myCoordGrpLayout->addWidget( myX, 0, 1 );
111   myCoordGrpLayout->addWidget( new QLabel( tr( "GEOM_Y" ), myCoordGrp ), 1, 0 );
112   myY = new QLineEdit( myCoordGrp );
113   myCoordGrpLayout->addWidget( myY, 1, 1 );
114   myCoordGrpLayout->addWidget( new QLabel( tr( "GEOM_Z" ), myCoordGrp ), 2, 0 );
115   myZ = new QLineEdit( myCoordGrp );
116   myCoordGrpLayout->addWidget( myZ, 2, 1 );
117
118   QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
119   layout->setMargin( 0 ); layout->setSpacing( 6 );
120   layout->addWidget( GroupXYZ );
121   layout->addWidget( GroupOnCurve );
122   layout->addWidget( GroupRefPoint );
123   layout->addWidget( GroupLineIntersection );
124   layout->addWidget( myCoordGrp );
125
126   myX->setReadOnly( true );
127   myY->setReadOnly( true );
128   myZ->setReadOnly( true );
129
130   myX->setEnabled( false );
131   myY->setEnabled( false );
132   myZ->setEnabled( false );
133
134   QPalette aPal = myX->palette();
135   aPal.setColor( QPalette::Disabled, QPalette::Text, QColor( 0, 0, 0 ) ) ;
136   myX->setPalette( aPal );
137   myY->setPalette( aPal );
138   myZ->setPalette( aPal );
139
140   //  setHelpFileName( "create_point_page.html" );
141   setHelpFileName( "point.htm" );
142  
143   Init();
144 }
145
146
147 //=================================================================================
148 // function : ~BasicGUI_PointDlg()
149 // purpose  : Destructor
150 //=================================================================================
151 BasicGUI_PointDlg::~BasicGUI_PointDlg()
152 {
153 }
154
155
156 //=================================================================================
157 // function : Init()
158 // purpose  :
159 //=================================================================================
160 void BasicGUI_PointDlg::Init()
161 {
162   GroupOnCurve->LineEdit1->setReadOnly( true );
163   GroupRefPoint->LineEdit1->setReadOnly( true );
164   GroupLineIntersection->LineEdit1->setReadOnly( true );
165   GroupLineIntersection->LineEdit2->setReadOnly( true );
166
167   myEdge = GEOM::GEOM_Object::_nil();
168   myRefPoint = GEOM::GEOM_Object::_nil();
169
170   myEditCurrentArgument = 0;
171
172   /* Get setting of step value from file configuration */
173   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
174   double step = resMgr->doubleValue( "Geometry", "SettingsGeomStep", 100 );
175   
176   /* min, max, step and decimals for spin boxes */
177   initSpinBox( GroupXYZ->SpinBox_DX, COORD_MIN, COORD_MAX, step, 3 ); // VSR:TODO : DBL_DIGITS_DISPLAY
178   initSpinBox( GroupXYZ->SpinBox_DY, COORD_MIN, COORD_MAX, step, 3 ); // VSR:TODO : DBL_DIGITS_DISPLAY
179   initSpinBox( GroupXYZ->SpinBox_DZ, COORD_MIN, COORD_MAX, step, 3 ); // VSR:TODO : DBL_DIGITS_DISPLAY
180   GroupXYZ->SpinBox_DX->setValue( 0.0 );
181   GroupXYZ->SpinBox_DY->setValue( 0.0 );
182   GroupXYZ->SpinBox_DZ->setValue( 0.0 );
183
184   initSpinBox( GroupRefPoint->SpinBox_DX, COORD_MIN, COORD_MAX, step, 3 ); // VSR:TODO : DBL_DIGITS_DISPLAY
185   initSpinBox( GroupRefPoint->SpinBox_DY, COORD_MIN, COORD_MAX, step, 3 ); // VSR:TODO : DBL_DIGITS_DISPLAY
186   initSpinBox( GroupRefPoint->SpinBox_DZ, COORD_MIN, COORD_MAX, step, 3 ); // VSR:TODO : DBL_DIGITS_DISPLAY
187   GroupRefPoint->SpinBox_DX->setValue( 0.0 );
188   GroupRefPoint->SpinBox_DY->setValue( 0.0 );
189   GroupRefPoint->SpinBox_DZ->setValue( 0.0 );
190
191   step = 0.1;
192
193   initSpinBox( GroupOnCurve->SpinBox_DX, 0., 1., step, 3 ); // VSR:TODO : DBL_DIGITS_DISPLAY
194   GroupOnCurve->SpinBox_DX->setValue( 0.5 );
195
196   /* signals and slots connections */
197   connect( myGeomGUI,      SIGNAL( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) );
198   connect( myGeomGUI,      SIGNAL( SignalCloseAllDialogs() ),        this, SLOT( ClickOnCancel() ) );
199
200   connect( buttonOk(),     SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
201   connect( buttonApply(),  SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
202
203   connect( this,           SIGNAL( constructorsClicked( int ) ), this, SLOT( ConstructorsClicked( int ) ) );
204
205   connect( GroupOnCurve->PushButton1, SIGNAL( clicked() ),       this, SLOT( SetEditCurrentArgument() ) );
206   connect( GroupOnCurve->LineEdit1,   SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
207
208   connect( GroupLineIntersection->PushButton1, SIGNAL( clicked() ),       this, SLOT( SetEditCurrentArgument() ) );
209   connect( GroupLineIntersection->PushButton2, SIGNAL( clicked() ),       this, SLOT( SetEditCurrentArgument() ) );
210   connect( GroupLineIntersection->LineEdit1,   SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
211   connect( GroupLineIntersection->LineEdit2,   SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
212
213   connect( GroupOnCurve->SpinBox_DX,  SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
214   connect( GroupXYZ->SpinBox_DX,      SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
215   connect( GroupXYZ->SpinBox_DY,      SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
216   connect( GroupXYZ->SpinBox_DZ,      SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
217   connect( GroupRefPoint->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
218   connect( GroupRefPoint->SpinBox_DY, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
219   connect( GroupRefPoint->SpinBox_DZ, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
220
221   // VSR: TODO ->>
222   connect( myGeomGUI, SIGNAL( SignalDefaultStepValueChanged( double ) ), GroupOnCurve->SpinBox_DX,  SLOT( SetStep( double ) ) );
223   connect( myGeomGUI, SIGNAL( SignalDefaultStepValueChanged( double ) ), GroupXYZ->SpinBox_DX,      SLOT( SetStep( double ) ) );
224   connect( myGeomGUI, SIGNAL( SignalDefaultStepValueChanged( double ) ), GroupXYZ->SpinBox_DY,      SLOT( SetStep( double ) ) );
225   connect( myGeomGUI, SIGNAL( SignalDefaultStepValueChanged( double ) ), GroupXYZ->SpinBox_DZ,      SLOT( SetStep( double ) ) );
226   connect( myGeomGUI, SIGNAL( SignalDefaultStepValueChanged( double ) ), GroupRefPoint->SpinBox_DX, SLOT( SetStep( double ) ) );
227   connect( myGeomGUI, SIGNAL( SignalDefaultStepValueChanged( double ) ), GroupRefPoint->SpinBox_DY, SLOT( SetStep( double ) ) );
228   connect( myGeomGUI, SIGNAL( SignalDefaultStepValueChanged( double ) ), GroupRefPoint->SpinBox_DZ, SLOT( SetStep( double ) ) );
229   // <<-
230
231   connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged() ),
232            this,  SLOT(SelectionIntoArgument() ) );
233
234   
235   initName( tr( "GEOM_VERTEX" ) );
236   
237   ConstructorsClicked( 0 );
238 }
239
240
241 //=================================================================================
242 // function : ConstructorsClicked()
243 // purpose  : Radio button management
244 //=================================================================================
245 void BasicGUI_PointDlg::ConstructorsClicked(int constructorId)
246 {  
247   globalSelection(); // close local contexts, if any
248
249   switch ( constructorId ) {
250   case 0:
251     {
252       localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
253       
254       GroupRefPoint->hide();
255       GroupOnCurve->hide();
256       GroupLineIntersection->hide();
257
258       myCoordGrp->hide();
259
260       GroupXYZ->show();
261       break;
262     }
263   case 1:
264     {
265       myEditCurrentArgument = GroupRefPoint->LineEdit1;
266       myEditCurrentArgument->setText( "" );
267       myRefPoint = GEOM::GEOM_Object::_nil();
268       
269       localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
270       
271       GroupXYZ->hide();
272       GroupOnCurve->hide();
273       GroupLineIntersection->hide();
274       
275       GroupRefPoint->show();
276       
277       myCoordGrp->show();
278       break;
279     }
280   case 2:
281     {
282       myEditCurrentArgument = GroupOnCurve->LineEdit1;
283       myEditCurrentArgument->setText( "" );
284       myEdge = GEOM::GEOM_Object::_nil();
285
286       localSelection( GEOM::GEOM_Object::_nil(), TopAbs_EDGE );
287
288       GroupXYZ->hide();
289       GroupRefPoint->hide();
290       GroupLineIntersection->hide();
291
292       GroupOnCurve->show();
293       
294       myCoordGrp->show();
295       break;
296     }
297   case 3:
298     {
299       myEditCurrentArgument = GroupLineIntersection->LineEdit1;
300       GroupLineIntersection->LineEdit1->setText( "" );
301       GroupLineIntersection->LineEdit2->setText( "" );
302       myLine1 = GEOM::GEOM_Object::_nil();
303       myLine2 = GEOM::GEOM_Object::_nil();
304
305       localSelection( GEOM::GEOM_Object::_nil(), TopAbs_EDGE );
306
307       GroupXYZ->hide();
308       GroupRefPoint->hide();
309       GroupOnCurve->hide();
310
311       myCoordGrp->hide();
312
313       GroupLineIntersection->show();
314       break;
315     }
316   }
317
318   myX->setText( "" );
319   myY->setText( "" );
320   myZ->setText( "" );
321
322   qApp->processEvents();
323   updateGeometry();
324   resize( minimumSize() );
325
326   SelectionIntoArgument();
327 }
328
329
330 //=================================================================================
331 // function : ClickOnOk()
332 // purpose  :
333 //=================================================================================
334 void BasicGUI_PointDlg::ClickOnOk()
335 {
336   if ( onAccept() )
337     ClickOnCancel();
338 }
339
340
341 //=================================================================================
342 // function : ClickOnApply()
343 // purpose  :
344 //=================================================================================
345 bool BasicGUI_PointDlg::ClickOnApply()
346 {
347   if ( !onAccept() )
348     return false;
349   
350   initName();
351   ConstructorsClicked( getConstructorId() );
352   return true;
353 }
354
355
356 //=================================================================================
357 // function : SelectionIntoArgument()
358 // purpose  : Called when selection as changed (for constructors not using local context)
359 //=================================================================================
360 void BasicGUI_PointDlg::SelectionIntoArgument()
361 {
362   const int id = getConstructorId();
363
364   if ( ( id == 1 || id == 2 ) && myEditCurrentArgument != 0 ) {
365     myEditCurrentArgument->setText( "" );
366     myX->setText( "" );
367     myY->setText( "" );
368     myZ->setText( "" );
369     myRefPoint = myEdge = GEOM::GEOM_Object::_nil();
370   }
371
372   if ( IObjectCount() == 1 ) {
373     Standard_Boolean aRes = Standard_False;
374     Handle(SALOME_InteractiveObject) anIO = firstIObject();
375     GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( anIO, aRes );
376     if ( !CORBA::is_nil( aSelectedObject ) && aRes ) {
377       QString aName = GEOMBase::GetName(aSelectedObject);
378
379       TopoDS_Shape aShape;
380       if ( GEOMBase::GetShape( aSelectedObject, aShape, TopAbs_SHAPE ) && !aShape.IsNull() ) {
381         TopAbs_ShapeEnum aNeedType = TopAbs_VERTEX;
382         if ( id == 2 || id == 3 )
383           aNeedType = TopAbs_EDGE;
384
385         LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
386         TColStd_IndexedMapOfInteger aMap;
387         aSelMgr->GetIndexes(firstIObject(), aMap);
388         if ( aMap.Extent() == 1 ) { // Local Selection
389           int anIndex = aMap( 1 );
390           if ( aNeedType == TopAbs_EDGE )
391             aName += QString( ":edge_%1" ).arg( anIndex );
392           else
393             aName += QString( ":vertex_%1" ).arg( anIndex );
394
395           //Find SubShape Object in Father
396           GEOM::GEOM_Object_var aFindedObject = GEOMBase_Helper::findObjectInFather( aSelectedObject, aName );
397           
398           if ( aFindedObject == GEOM::GEOM_Object::_nil() ) { // Object not found in study
399             GEOM::GEOM_IShapesOperations_var aShapesOp = getGeomEngine()->GetIShapesOperations( getStudyId() );
400             aSelectedObject = aShapesOp->GetSubShape( aSelectedObject, anIndex );
401           }
402           else {
403             aSelectedObject = aFindedObject; // get Object from study
404           }
405         }
406         else { // Global Selection
407           if ( aShape.ShapeType() != aNeedType ) {
408             aSelectedObject = GEOM::GEOM_Object::_nil();
409             aName = "";
410             if ( id == 0 ) return;
411           }
412         }
413       }
414
415       if ( id == 0 ) {
416         if ( aShape.IsNull() ) return;
417         gp_Pnt aPnt = BRep_Tool::Pnt( TopoDS::Vertex( aShape ) );
418         GroupXYZ->SpinBox_DX->setValue( aPnt.X() );
419         GroupXYZ->SpinBox_DY->setValue( aPnt.Y() );
420         GroupXYZ->SpinBox_DZ->setValue( aPnt.Z() );
421       }
422       else if ( id == 1 ) {
423         myRefPoint = aSelectedObject;
424         GroupRefPoint->LineEdit1->setText( aName );
425       }
426       else if ( id == 2 ) {
427         myEdge = aSelectedObject;
428         GroupOnCurve->LineEdit1->setText( aName );
429       }
430       else if ( id == 3 ) {
431         if ( myEditCurrentArgument == GroupLineIntersection->LineEdit1 ) {
432           myLine1 = aSelectedObject;
433           myEditCurrentArgument->setText( aName );
434         }
435         else if ( myEditCurrentArgument == GroupLineIntersection->LineEdit2 ) {
436           myLine2 = aSelectedObject;
437           myEditCurrentArgument->setText( aName );
438         }
439       }
440     }
441   }
442   
443   displayPreview();
444 }
445
446
447 //=================================================================================
448 // function : LineEditReturnPressed()
449 // purpose  :
450 //=================================================================================
451 void BasicGUI_PointDlg::LineEditReturnPressed()
452 {
453   QLineEdit* send = (QLineEdit*)sender();
454   if ( send == GroupRefPoint->LineEdit1         || 
455        send == GroupOnCurve->LineEdit1          ||
456        send == GroupLineIntersection->LineEdit1 || 
457        send == GroupLineIntersection->LineEdit2  ) {
458     myEditCurrentArgument = send;
459     GEOMBase_Skeleton::LineEditReturnPressed();
460   }
461 }
462
463
464 //=================================================================================
465 // function : SetEditCurrentArgument()
466 // purpose  :
467 //=================================================================================
468 void BasicGUI_PointDlg::SetEditCurrentArgument()
469 {
470   globalSelection(); // close local contexts, if any
471
472   QPushButton* send = (QPushButton*)sender();
473   globalSelection( GEOM_POINT ); // to break previous local selection
474
475   if ( send == GroupRefPoint->PushButton1 ) {
476     GroupRefPoint->LineEdit1->setFocus();
477     myEditCurrentArgument = GroupRefPoint->LineEdit1;
478     
479     localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
480   }
481   else if ( send == GroupOnCurve->PushButton1 ) {
482     GroupOnCurve->LineEdit1->setFocus();
483     myEditCurrentArgument = GroupOnCurve->LineEdit1;
484     
485     localSelection( GEOM::GEOM_Object::_nil(), TopAbs_EDGE );
486   }
487   else if ( send == GroupLineIntersection->PushButton1 ) {
488     GroupLineIntersection->LineEdit1->setFocus();
489     myEditCurrentArgument = GroupLineIntersection->LineEdit1;
490
491     localSelection( GEOM::GEOM_Object::_nil(), TopAbs_EDGE );
492   }
493   else if ( send == GroupLineIntersection->PushButton2 ) {
494     GroupLineIntersection->LineEdit2->setFocus();
495     myEditCurrentArgument = GroupLineIntersection->LineEdit2;
496
497     localSelection( GEOM::GEOM_Object::_nil(), TopAbs_EDGE );
498   }
499 }
500
501
502 //=================================================================================
503 // function : enterEvent()
504 // purpose  : to reactivate this dialog box when mouse enter onto the window
505 //=================================================================================
506 void BasicGUI_PointDlg::enterEvent( QEvent* )
507 {
508   if ( !mainFrame()->GroupConstructors->isEnabled() )
509     ActivateThisDialog();
510 }
511
512
513 //=================================================================================
514 // function : ActivateThisDialog()
515 // purpose  :
516 //=================================================================================
517 void BasicGUI_PointDlg::ActivateThisDialog( )
518 {
519   GEOMBase_Skeleton::ActivateThisDialog();
520   // myGeomGUI->SetState( 0 );
521   ConstructorsClicked( getConstructorId() );
522 }
523
524
525 //=================================================================================
526 // function : DeactivateActiveDialog()
527 // purpose  : public slot to deactivate if active
528 //=================================================================================
529 void BasicGUI_PointDlg::DeactivateActiveDialog()
530 {
531   // myGeomGUI->SetState( -1 );
532   GEOMBase_Skeleton::DeactivateActiveDialog();
533 }
534
535
536 //=================================================================================
537 // function : ValueChangedInSpinBox()
538 // purpose  :
539 //=================================================================================
540 void BasicGUI_PointDlg::ValueChangedInSpinBox(double newValue)
541 {
542   displayPreview();
543 }
544
545 //=================================================================================
546 // funcion  : getParameter()
547 // purpose  :
548 //=================================================================================
549 double BasicGUI_PointDlg::getParameter() const
550 {
551   return GroupOnCurve->SpinBox_DX->value();
552 }
553
554 //=================================================================================
555 // function : OnPointSelected
556 // purpose  :
557 //=================================================================================
558 void BasicGUI_PointDlg::OnPointSelected( const gp_Pnt& thePnt )
559 {
560   if ( getConstructorId() == 0 ) {
561     GroupXYZ->SpinBox_DX->setValue( thePnt.X() );
562     GroupXYZ->SpinBox_DY->setValue( thePnt.Y() );
563     GroupXYZ->SpinBox_DZ->setValue( thePnt.Z() );
564
565     displayPreview();
566   }
567 }
568
569 //=================================================================================
570 // function : createOperation
571 // purpose  :
572 //=================================================================================
573 GEOM::GEOM_IOperations_ptr BasicGUI_PointDlg::createOperation()
574 {
575   return myGeomGUI->GetGeomGen()->GetIBasicOperations( getStudyId() );
576 }
577
578 //=================================================================================
579 // function : isValid
580 // purpose  :
581 //=================================================================================
582 bool BasicGUI_PointDlg::isValid( QString& /*msg*/ )
583 {
584   const int id = getConstructorId();
585   if ( id == 0 )
586     return true;
587   else if ( id == 1 )
588     return !myRefPoint->_is_nil();
589   else if ( id == 2 )
590     return !myEdge->_is_nil();
591   else if ( id == 3 )
592     return ( !myLine1->_is_nil() && !myLine2->_is_nil() );
593   return false;
594 }
595
596 //=================================================================================
597 // function : execute
598 // purpose  :
599 //=================================================================================
600 bool BasicGUI_PointDlg::execute( ObjectList& objects )
601 {
602   bool res = false;
603
604   GEOM::GEOM_Object_var anObj;
605
606   switch ( getConstructorId() ) {
607   case 0 :
608     {
609       double x = GroupXYZ->SpinBox_DX->value();
610       double y = GroupXYZ->SpinBox_DY->value();
611       double z = GroupXYZ->SpinBox_DZ->value();
612       
613       anObj = GEOM::GEOM_IBasicOperations::_narrow( getOperation() )->MakePointXYZ( x, y, z );
614       res = true;
615       break;
616     }
617   case 1 :
618     {
619       double dx = GroupRefPoint->SpinBox_DX->value();
620       double dy = GroupRefPoint->SpinBox_DY->value();
621       double dz = GroupRefPoint->SpinBox_DZ->value();
622       
623       anObj = GEOM::GEOM_IBasicOperations::_narrow( getOperation() )->
624         MakePointWithReference( myRefPoint, dx, dy, dz );
625       res = true;
626       break;
627     }
628   case 2 :
629     anObj = GEOM::GEOM_IBasicOperations::_narrow( getOperation() )->
630       MakePointOnCurve( myEdge, getParameter() );
631     res = true;
632     break;
633   case 3 :
634     anObj = GEOM::GEOM_IBasicOperations::_narrow( getOperation() )->
635       MakePointOnLinesIntersection( myLine1, myLine2 );
636     res = true;
637     break;
638   }
639   
640   if ( getConstructorId() == 1 || getConstructorId() == 2 ) {
641     TopoDS_Shape aShape;
642     if ( GEOMBase::GetShape( anObj, aShape ) && !aShape.IsNull() && aShape.ShapeType() == TopAbs_VERTEX ) {
643       gp_Pnt aPnt = BRep_Tool::Pnt( TopoDS::Vertex( aShape ) );
644       myX->setText( QString( "%1" ).arg( aPnt.X() ) );
645       myY->setText( QString( "%1" ).arg( aPnt.Y() ) );
646       myZ->setText( QString( "%1" ).arg( aPnt.Z() ) );
647     }
648     else {
649       myX->setText( "" );
650       myY->setText( "" );
651       myZ->setText( "" );
652     }
653   }
654   
655   if ( !anObj->_is_nil() ) {
656     objects.push_back( anObj._retn() );
657   }
658   
659   return res;
660 }
661
662 //=================================================================================
663 // function : addSubshapeToStudy
664 // purpose  : virtual method to add new SubObjects if local selection
665 //=================================================================================
666 void BasicGUI_PointDlg::addSubshapesToStudy()
667 {
668   QMap<QString, GEOM::GEOM_Object_var> objMap;
669
670   switch ( getConstructorId() ) {
671   case 0:
672     break;
673   case 1:
674     objMap[GroupRefPoint->LineEdit1->text()] = myRefPoint;
675     break;
676   case 2:
677     objMap[GroupOnCurve->LineEdit1->text()] = myEdge;
678     break;
679   case 3:
680     objMap[GroupLineIntersection->LineEdit1->text()] = myLine1;
681     objMap[GroupLineIntersection->LineEdit2->text()] = myLine2;
682     break;
683   }
684   addSubshapesToFather( objMap );
685 }