Salome HOME
Preparation of intermediate revision
[modules/geom.git] / src / BasicGUI / BasicGUI_PointDlg.cxx
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  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 // GEOM GEOMGUI : GUI for Geometry component
23 // File   : BasicGUI_PointDlg.cxx
24 // Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
25 //
26 #include "BasicGUI_PointDlg.h"
27
28 #include <SUIT_ResourceMgr.h>
29 #include <SUIT_Session.h>
30 #include <SalomeApp_Application.h>
31 #include <SalomeApp_Notebook.h>
32 #include <LightApp_SelectionMgr.h>
33
34 #include <GeometryGUI.h>
35 #include <GEOMBase.h>
36
37 #include <DlgRef.h>
38
39 #include <GEOMImpl_Types.hxx>
40
41 #include <QApplication>
42 #include <QButtonGroup>
43 #include <QHBoxLayout>
44 #include <QLabel>
45 #include <QRadioButton>
46
47 #include <gp_Pnt.hxx>
48 #include <TopoDS_Shape.hxx>
49 #include <TopAbs_ShapeEnum.hxx>
50 #include <TopoDS.hxx>
51 #include <BRep_Tool.hxx>
52 #include <TopExp.hxx>
53 #include <TColStd_IndexedMapOfInteger.hxx>
54 #include <TopTools_IndexedMapOfShape.hxx>
55
56 #define PARAM_VALUE 0
57 #define COORD_VALUE 1
58
59 #define GEOM_POINT_XYZ    0
60 #define GEOM_POINT_REF    1
61 #define GEOM_POINT_EDGE   2
62 #define GEOM_POINT_INTINT 3
63 #define GEOM_POINT_SURF   4
64
65
66 //=================================================================================
67 // class    : BasicGUI_PointDlg()
68 // purpose  : Constructs a BasicGUI_PointDlg which is a child of 'parent', with the 
69 //            name 'name' and widget flags set to 'f'.
70 //            The dialog will by default be modeless, unless you set 'modal' to
71 //            TRUE to construct a modal dialog.
72 //=================================================================================
73 BasicGUI_PointDlg::BasicGUI_PointDlg( GeometryGUI* theGeometryGUI, QWidget* parent,
74                                       bool modal, Qt::WindowFlags fl )
75   : GEOMBase_Skeleton( theGeometryGUI, parent, modal, fl )
76 {
77   QPixmap image0( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_POINT") ) );
78   QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_POINT_EDGE" ) ) );
79   QPixmap image2( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
80   QPixmap image3( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_POINT_REF" ) ) );
81   QPixmap image4( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_POINT_LINES") ) );
82   QPixmap image5( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_POINT_FACE" ) ) );
83
84   setWindowTitle( tr( "GEOM_POINT_TITLE" ) );
85
86   /***************************************************************/
87   mainFrame()->GroupConstructors->setTitle( tr( "GEOM_POINTS" ) );
88   mainFrame()->RadioButton1->setIcon( image0 );
89   mainFrame()->RadioButton2->setIcon( image3 );
90   mainFrame()->RadioButton3->setIcon( image1 );
91   mainFrame()->RadioButton4->show();
92   mainFrame()->RadioButton4->setIcon( image4 );
93   mainFrame()->RadioButton5->show();
94   mainFrame()->RadioButton5->setIcon( image5 );
95
96   QGroupBox* paramGrp = new QGroupBox( centralWidget() );
97   myParamCoord = new QButtonGroup( paramGrp );
98   QHBoxLayout* boxLayout = new QHBoxLayout( paramGrp );
99   boxLayout->setMargin( 0 ); boxLayout->setSpacing( 6 );
100   QRadioButton* btn = new QRadioButton( tr( "GEOM_PARAM_VALUE" ), paramGrp );
101   myParamCoord->addButton( btn, PARAM_VALUE );
102   boxLayout->addWidget( btn );
103   btn = new QRadioButton( tr( "GEOM_COORD_VALUE" ), paramGrp );
104   myParamCoord->addButton( btn, COORD_VALUE );
105   boxLayout->addWidget( btn );
106   myParamCoord->setExclusive( true );
107   myParamCoord->button( PARAM_VALUE )->setChecked( true );
108
109   GroupXYZ = new DlgRef_3Spin( centralWidget() );
110   GroupXYZ->GroupBox1->setTitle( tr( "GEOM_COORDINATES" ) );
111   GroupXYZ->TextLabel1->setText( tr( "GEOM_X" ) );
112   GroupXYZ->TextLabel2->setText( tr( "GEOM_Y" ) );
113   GroupXYZ->TextLabel3->setText( tr( "GEOM_Z" ) );
114
115   GroupOnCurve = new DlgRef_1Sel1Spin( centralWidget() );
116   GroupOnCurve->GroupBox1->setTitle( tr( "GEOM_POINT_ON_EDGE" ) );
117   GroupOnCurve->TextLabel1->setText( tr( "GEOM_EDGE" ) );
118   GroupOnCurve->TextLabel2->setText( tr( "GEOM_PARAMETER" ) );
119   GroupOnCurve->PushButton1->setIcon( image2 );
120
121   GroupOnSurface = new DlgRef_1Sel2Spin( centralWidget() );
122   GroupOnSurface->GroupBox1->setTitle( tr( "GEOM_POINT_ON_FACE" ) );
123   GroupOnSurface->TextLabel1->setText( tr( "GEOM_FACE" ) );
124   GroupOnSurface->TextLabel2->setText( tr( "GEOM_UPARAMETER" ) );
125   GroupOnSurface->TextLabel3->setText( tr( "GEOM_VPARAMETER" ) );
126   GroupOnSurface->PushButton1->setIcon( image2 );
127
128   GroupRefPoint = new DlgRef_1Sel3Spin( centralWidget() );
129   GroupRefPoint->GroupBox1->setTitle( tr( "GEOM_REF_POINT" ) );
130   GroupRefPoint->TextLabel1->setText( tr( "GEOM_POINT" ) );
131   GroupRefPoint->PushButton1->setIcon( image2 );
132   GroupRefPoint->TextLabel2->setText( tr( "GEOM_DX" ) );
133   GroupRefPoint->TextLabel3->setText( tr( "GEOM_DY" ) );
134   GroupRefPoint->TextLabel4->setText( tr( "GEOM_DZ" ) );
135
136   GroupLineIntersection = new DlgRef_2Sel( centralWidget() );
137   GroupLineIntersection->GroupBox1->setTitle( tr( "GEOM_LINE_INTERSECTION" ) );
138   GroupLineIntersection->TextLabel1->setText( tr( "GEOM_LINE1" ) );
139   GroupLineIntersection->TextLabel2->setText( tr( "GEOM_LINE2" ) );
140   GroupLineIntersection->PushButton1->setIcon( image2 );
141   GroupLineIntersection->PushButton2->setIcon( image2 );
142   GroupLineIntersection->LineEdit2->setEnabled(false);
143
144   myCoordGrp = new QGroupBox( tr( "GEOM_COORDINATES_RES" ), centralWidget() );
145   QGridLayout* myCoordGrpLayout = new QGridLayout( myCoordGrp );
146   myCoordGrpLayout->addWidget( new QLabel( tr( "GEOM_X" ), myCoordGrp ), 0, 0 );
147   myX = new QLineEdit( myCoordGrp );
148   myCoordGrpLayout->addWidget( myX, 0, 1 );
149   myCoordGrpLayout->addWidget( new QLabel( tr( "GEOM_Y" ), myCoordGrp ), 1, 0 );
150   myY = new QLineEdit( myCoordGrp );
151   myCoordGrpLayout->addWidget( myY, 1, 1 );
152   myCoordGrpLayout->addWidget( new QLabel( tr( "GEOM_Z" ), myCoordGrp ), 2, 0 );
153   myZ = new QLineEdit( myCoordGrp );
154   myCoordGrpLayout->addWidget( myZ, 2, 1 );
155
156   QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
157   layout->setMargin( 0 ); layout->setSpacing( 6 );
158   layout->addWidget( paramGrp );
159   layout->addWidget( GroupXYZ );
160   layout->addWidget( GroupOnCurve );
161   layout->addWidget( GroupOnSurface );
162   layout->addWidget( GroupRefPoint );
163   layout->addWidget( GroupLineIntersection );
164   layout->addWidget( myCoordGrp );
165
166   myX->setReadOnly( true );
167   myY->setReadOnly( true );
168   myZ->setReadOnly( true );
169
170   myX->setEnabled( false );
171   myY->setEnabled( false );
172   myZ->setEnabled( false );
173
174   QPalette aPal = myX->palette();
175   aPal.setColor( QPalette::Disabled, QPalette::Text, QColor( 0, 0, 0 ) ) ;
176   myX->setPalette( aPal );
177   myY->setPalette( aPal );
178   myZ->setPalette( aPal );
179
180   setHelpFileName( "create_point_page.html" );
181  
182   Init();
183 }
184
185
186 //=================================================================================
187 // function : ~BasicGUI_PointDlg()
188 // purpose  : Destructor
189 //=================================================================================
190 BasicGUI_PointDlg::~BasicGUI_PointDlg()
191 {
192 }
193
194
195 //=================================================================================
196 // function : Init()
197 // purpose  :
198 //=================================================================================
199 void BasicGUI_PointDlg::Init()
200 {
201   GroupOnCurve->LineEdit1->setReadOnly( true );
202   GroupOnSurface->LineEdit1->setReadOnly( true );
203   GroupRefPoint->LineEdit1->setReadOnly( true );
204   GroupLineIntersection->LineEdit1->setReadOnly( true );
205   GroupLineIntersection->LineEdit2->setReadOnly( true );
206   GroupLineIntersection->LineEdit1->setEnabled( true );
207   GroupLineIntersection->LineEdit2->setEnabled( false );
208
209   myEdge = GEOM::GEOM_Object::_nil();
210   myRefPoint = GEOM::GEOM_Object::_nil();
211
212   myEditCurrentArgument = 0;
213
214   /* Get setting of step value from file configuration */
215   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
216   double step = resMgr->doubleValue( "Geometry", "SettingsGeomStep", 100 );
217   
218   /* min, max, step and decimals for spin boxes */
219   initSpinBox( GroupXYZ->SpinBox_DX, COORD_MIN, COORD_MAX, step, 6 ); // VSR: TODO: DBL_DIGITS_DISPLAY
220   initSpinBox( GroupXYZ->SpinBox_DY, COORD_MIN, COORD_MAX, step, 6 ); // VSR: TODO: DBL_DIGITS_DISPLAY
221   initSpinBox( GroupXYZ->SpinBox_DZ, COORD_MIN, COORD_MAX, step, 6 ); // VSR: TODO: DBL_DIGITS_DISPLAY
222   GroupXYZ->SpinBox_DX->setValue( 0.0 );
223   GroupXYZ->SpinBox_DY->setValue( 0.0 );
224   GroupXYZ->SpinBox_DZ->setValue( 0.0 );
225
226   initSpinBox( GroupRefPoint->SpinBox_DX, COORD_MIN, COORD_MAX, step, 6 ); // VSR: TODO: DBL_DIGITS_DISPLAY
227   initSpinBox( GroupRefPoint->SpinBox_DY, COORD_MIN, COORD_MAX, step, 6 ); // VSR: TODO: DBL_DIGITS_DISPLAY
228   initSpinBox( GroupRefPoint->SpinBox_DZ, COORD_MIN, COORD_MAX, step, 6 ); // VSR: TODO: DBL_DIGITS_DISPLAY
229   GroupRefPoint->SpinBox_DX->setValue( 0.0 );
230   GroupRefPoint->SpinBox_DY->setValue( 0.0 );
231   GroupRefPoint->SpinBox_DZ->setValue( 0.0 );
232
233   step = 0.1;
234
235   initSpinBox( GroupOnCurve->SpinBox_DX, 0., 1., step, 6 ); // VSR:TODO : DBL_DIGITS_DISPLAY
236   GroupOnCurve->SpinBox_DX->setValue( 0.5 );
237
238   initSpinBox( GroupOnSurface->SpinBox_DX, 0., 1., step, 6 ); // VSR:TODO : DBL_DIGITS_DISPLAY
239   GroupOnSurface->SpinBox_DX->setValue( 0.5 );
240   initSpinBox( GroupOnSurface->SpinBox_DY, 0., 1., step, 6 ); // VSR:TODO : DBL_DIGITS_DISPLAY
241   GroupOnSurface->SpinBox_DY->setValue( 0.5 );
242
243   /* signals and slots connections */
244   connect( myGeomGUI,      SIGNAL( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) );
245   connect( myGeomGUI,      SIGNAL( SignalCloseAllDialogs() ),        this, SLOT( ClickOnCancel() ) );
246
247   connect( buttonOk(),     SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
248   connect( buttonApply(),  SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
249
250   connect( this,           SIGNAL( constructorsClicked( int ) ), this, SLOT( ConstructorsClicked( int ) ) );
251
252
253   connect( myParamCoord->button( PARAM_VALUE ), SIGNAL( clicked() ), this, SLOT( ClickParamCoord() ) );
254   connect( myParamCoord->button( COORD_VALUE ), SIGNAL( clicked() ), this, SLOT( ClickParamCoord() ) );
255   connect( GroupOnCurve->PushButton1, SIGNAL( clicked() ),       this, SLOT( SetEditCurrentArgument() ) );
256   connect( GroupOnCurve->LineEdit1,   SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
257
258   connect( GroupOnSurface->PushButton1, SIGNAL( clicked() ),       this, SLOT( SetEditCurrentArgument() ) );
259   connect( GroupOnSurface->LineEdit1,   SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
260
261   connect( GroupLineIntersection->PushButton1, SIGNAL( clicked() ),       this, SLOT( SetEditCurrentArgument() ) );
262   connect( GroupLineIntersection->PushButton2, SIGNAL( clicked() ),       this, SLOT( SetEditCurrentArgument() ) );
263   connect( GroupLineIntersection->LineEdit1,   SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
264   connect( GroupLineIntersection->LineEdit2,   SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
265
266   connect( GroupOnCurve->SpinBox_DX,   SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
267   connect( GroupOnSurface->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
268   connect( GroupOnSurface->SpinBox_DY, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
269   connect( GroupXYZ->SpinBox_DX,       SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
270   connect( GroupXYZ->SpinBox_DY,       SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
271   connect( GroupXYZ->SpinBox_DZ,       SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
272   connect( GroupRefPoint->SpinBox_DX,  SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
273   connect( GroupRefPoint->SpinBox_DY,  SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
274   connect( GroupRefPoint->SpinBox_DZ,  SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
275
276   connect( myGeomGUI, SIGNAL( SignalDefaultStepValueChanged( double ) ), this,  SLOT( SetDoubleSpinBoxStep( double ) ) );
277
278   connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged() ),
279            this,  SLOT(SelectionIntoArgument() ) );
280
281   
282   initName( tr( "GEOM_VERTEX" ) );
283   
284   ConstructorsClicked( 0 );
285 }
286
287 //=================================================================================
288 // function : SetDoubleSpinBoxStep()
289 // purpose  : Double spin box management
290 //=================================================================================
291 void BasicGUI_PointDlg::SetDoubleSpinBoxStep( double step )
292 {
293   GroupOnCurve->SpinBox_DX->setSingleStep(step);
294   GroupXYZ->SpinBox_DX->setSingleStep(step);
295   GroupXYZ->SpinBox_DY->setSingleStep(step);
296   GroupXYZ->SpinBox_DZ->setSingleStep(step);
297   GroupRefPoint->SpinBox_DX->setSingleStep(step);
298   GroupRefPoint->SpinBox_DY->setSingleStep(step);
299   GroupRefPoint->SpinBox_DZ->setSingleStep(step);
300   GroupOnSurface->SpinBox_DX->setSingleStep(step);
301   GroupOnSurface->SpinBox_DY->setSingleStep(step);
302 }
303
304
305 //=================================================================================
306 // function : ConstructorsClicked()
307 // purpose  : Radio button management
308 //=================================================================================
309 void BasicGUI_PointDlg::ConstructorsClicked(int constructorId)
310 {  
311   globalSelection(); // close local contexts, if any
312
313   switch ( constructorId ) {
314   case GEOM_POINT_XYZ:
315     {
316       localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
317       
318       GroupRefPoint->hide();
319       GroupOnCurve->hide();
320       GroupLineIntersection->hide();
321       GroupOnSurface->hide();
322
323       myCoordGrp->hide();
324
325       myParamCoord->button( PARAM_VALUE )->hide();
326       myParamCoord->button( COORD_VALUE )->hide();
327       GroupXYZ->show();
328       break;
329     }
330   case GEOM_POINT_REF:
331     {
332       myEditCurrentArgument = GroupRefPoint->LineEdit1;
333       myEditCurrentArgument->setText( "" );
334       myRefPoint = GEOM::GEOM_Object::_nil();
335       GroupRefPoint->PushButton1->setDown(true);      
336       localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
337       
338       myParamCoord->button( PARAM_VALUE )->hide();
339       myParamCoord->button( COORD_VALUE )->hide();
340       GroupXYZ->hide();
341       GroupOnCurve->hide();
342       GroupLineIntersection->hide();
343       GroupOnSurface->hide();
344       
345       GroupRefPoint->show();
346       
347       myCoordGrp->show();
348       break;
349     }
350   case GEOM_POINT_EDGE:
351     {
352       myEditCurrentArgument = GroupOnCurve->LineEdit1;
353       myEditCurrentArgument->setText( "" );
354       myEdge = GEOM::GEOM_Object::_nil();
355       GroupOnCurve->PushButton1->setDown(true);
356       localSelection( GEOM::GEOM_Object::_nil(), TopAbs_EDGE );
357
358       GroupRefPoint->hide();
359       GroupLineIntersection->hide();
360       GroupOnSurface->hide();
361
362       myParamCoord->button( PARAM_VALUE )->show();
363       myParamCoord->button( COORD_VALUE )->show();
364       GroupOnCurve->show();
365       myCoordGrp->show();
366
367       updateParamCoord( false );
368       break;
369     }
370   case GEOM_POINT_INTINT:
371     {
372       myEditCurrentArgument = GroupLineIntersection->LineEdit1;
373       GroupLineIntersection->LineEdit1->setText( "" );
374       GroupLineIntersection->LineEdit2->setText( "" );
375       GroupLineIntersection->LineEdit1->setEnabled( true );
376       GroupLineIntersection->LineEdit2->setEnabled( false );
377       myLine1 = GEOM::GEOM_Object::_nil();
378       myLine2 = GEOM::GEOM_Object::_nil();
379       GroupLineIntersection->PushButton1->setDown(true);
380       GroupLineIntersection->PushButton2->setDown(false);
381
382       localSelection( GEOM::GEOM_Object::_nil(), TopAbs_EDGE );
383
384       myParamCoord->button( PARAM_VALUE )->hide();
385       myParamCoord->button( COORD_VALUE )->hide();
386       GroupXYZ->hide();
387       GroupRefPoint->hide();
388       GroupOnCurve->hide();
389       GroupOnSurface->hide();
390
391       myCoordGrp->hide();
392
393       GroupLineIntersection->show();
394       break;
395     }
396   case GEOM_POINT_SURF:
397     {
398       myEditCurrentArgument = GroupOnSurface->LineEdit1;
399       myEditCurrentArgument->setText( "" );
400       myFace = GEOM::GEOM_Object::_nil();
401       GroupOnSurface->PushButton1->setDown(true);
402       localSelection( GEOM::GEOM_Object::_nil(), TopAbs_FACE );
403
404       GroupRefPoint->hide();
405       GroupOnCurve->hide();
406       GroupLineIntersection->hide();
407
408       myParamCoord->button( PARAM_VALUE )->show();
409       myParamCoord->button( COORD_VALUE )->show();
410       GroupOnSurface->show();
411       myCoordGrp->show();
412
413       updateParamCoord( false );
414       break;
415     }
416   }
417
418   myX->setText( "" );
419   myY->setText( "" );
420   myZ->setText( "" );
421
422   qApp->processEvents();
423   updateGeometry();
424   resize( minimumSizeHint() );
425
426   SelectionIntoArgument();
427 }
428
429
430 //=================================================================================
431 // function : ClickOnOk()
432 // purpose  :
433 //=================================================================================
434 void BasicGUI_PointDlg::ClickOnOk()
435 {
436   if ( onAccept() )
437     ClickOnCancel();
438 }
439
440
441 //=================================================================================
442 // function : ClickOnApply()
443 // purpose  :
444 //=================================================================================
445 bool BasicGUI_PointDlg::ClickOnApply()
446 {
447   if ( !onAccept() )
448     return false;
449   
450   initName();
451   ConstructorsClicked( getConstructorId() );
452   return true;
453 }
454
455
456 //=================================================================================
457 // function : SelectionIntoArgument()
458 // purpose  : Called when selection as changed (for constructors not using local context)
459 //=================================================================================
460 void BasicGUI_PointDlg::SelectionIntoArgument()
461 {
462   const int id = getConstructorId();
463
464   if ( ( id == GEOM_POINT_REF || id == GEOM_POINT_EDGE || id == GEOM_POINT_SURF ) && myEditCurrentArgument != 0 )
465   {
466     myEditCurrentArgument->setText( "" );
467     myX->setText( "" );
468     myY->setText( "" );
469     myZ->setText( "" );
470     myRefPoint = myEdge = myFace = GEOM::GEOM_Object::_nil();
471   }
472
473   LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
474   SALOME_ListIO aSelList;
475   aSelMgr->selectedObjects(aSelList);
476
477   if (aSelList.Extent() == 1) {
478     Standard_Boolean aRes = Standard_False;
479     Handle(SALOME_InteractiveObject) anIO = aSelList.First();
480     GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( anIO, aRes );
481     if ( !CORBA::is_nil( aSelectedObject ) && aRes ) {
482       QString aName = GEOMBase::GetName(aSelectedObject);
483       TopAbs_ShapeEnum aNeedType = TopAbs_VERTEX;
484       TopoDS_Shape aShape;
485       if ( GEOMBase::GetShape( aSelectedObject, aShape, TopAbs_SHAPE ) && !aShape.IsNull() ) {
486         if ( id == GEOM_POINT_EDGE || id == GEOM_POINT_INTINT )
487           aNeedType = TopAbs_EDGE;
488         else if ( id == GEOM_POINT_SURF )
489           aNeedType = TopAbs_FACE;
490
491         TColStd_IndexedMapOfInteger aMap;
492         aSelMgr->GetIndexes(anIO, aMap);
493         if ( aMap.Extent() == 1 ) { // Local Selection
494           int anIndex = aMap( 1 );
495           if ( aNeedType == TopAbs_EDGE )
496             aName += QString( ":edge_%1" ).arg( anIndex );
497           else
498             aName += QString( ":vertex_%1" ).arg( anIndex );
499
500           //Find SubShape Object in Father
501           GEOM::GEOM_Object_var aFindedObject = GEOMBase_Helper::findObjectInFather(aSelectedObject, aName);
502           
503           if ( aFindedObject == GEOM::GEOM_Object::_nil() ) { // Object not found in study
504             GEOM::GEOM_IShapesOperations_var aShapesOp =
505               getGeomEngine()->GetIShapesOperations(getStudyId());
506             aSelectedObject = aShapesOp->GetSubShape(aSelectedObject, anIndex);
507           }
508           else {
509             aSelectedObject = aFindedObject; // get Object from study
510           }
511           GEOMBase::GetShape( aSelectedObject, aShape, TopAbs_SHAPE );
512         }
513         else { // Global Selection
514           if ( aShape.ShapeType() != aNeedType ) {
515             aSelectedObject = GEOM::GEOM_Object::_nil();
516             aName = "";
517             if ( id == GEOM_POINT_XYZ ) return;
518           }
519         }
520       }
521
522       if ( aShape.IsNull() || aShape.ShapeType() != aNeedType)
523         return;
524
525       if ( id == GEOM_POINT_XYZ ) {
526         gp_Pnt aPnt = BRep_Tool::Pnt( TopoDS::Vertex( aShape ) );
527         GroupXYZ->SpinBox_DX->setValue( aPnt.X() );
528         GroupXYZ->SpinBox_DY->setValue( aPnt.Y() );
529         GroupXYZ->SpinBox_DZ->setValue( aPnt.Z() );
530       }
531       else if ( id == GEOM_POINT_REF ) {
532         myRefPoint = aSelectedObject;
533         GroupRefPoint->LineEdit1->setText( aName );
534       }
535       else if ( id == GEOM_POINT_EDGE ) {
536         myEdge = aSelectedObject;
537         GroupOnCurve->LineEdit1->setText( aName );
538       }
539       else if ( id == GEOM_POINT_INTINT ) {
540         myEditCurrentArgument->setText( aName );
541         globalSelection();
542         localSelection( GEOM::GEOM_Object::_nil(), TopAbs_EDGE );
543         if ( myEditCurrentArgument == GroupLineIntersection->LineEdit1 ) {
544           myLine1 = aSelectedObject;
545           if ( !myLine1->_is_nil() && myLine2->_is_nil() )
546             GroupLineIntersection->PushButton2->click();
547         }
548         else if ( myEditCurrentArgument == GroupLineIntersection->LineEdit2 ) {
549           myLine2 = aSelectedObject;
550           if ( !myLine2->_is_nil() && myLine1->_is_nil() )
551             GroupLineIntersection->PushButton1->click();
552         }
553       }
554       else if ( id == GEOM_POINT_SURF )
555       {
556         myFace = aSelectedObject;
557         GroupOnSurface->LineEdit1->setText( aName );
558       }
559     }
560   }
561   
562   displayPreview();
563 }
564
565
566 //=================================================================================
567 // function : LineEditReturnPressed()
568 // purpose  :
569 //=================================================================================
570 void BasicGUI_PointDlg::LineEditReturnPressed()
571 {
572   QLineEdit* send = (QLineEdit*)sender();
573   if ( send == GroupRefPoint->LineEdit1         || 
574        send == GroupOnCurve->LineEdit1          ||
575        send == GroupLineIntersection->LineEdit1 || 
576        send == GroupLineIntersection->LineEdit2  ) {
577     myEditCurrentArgument = send;
578     GEOMBase_Skeleton::LineEditReturnPressed();
579   }
580 }
581
582
583 //=================================================================================
584 // function : SetEditCurrentArgument()
585 // purpose  :
586 //=================================================================================
587 void BasicGUI_PointDlg::SetEditCurrentArgument()
588 {
589   globalSelection(); // close local contexts, if any
590
591   QPushButton* send = (QPushButton*)sender();
592
593   if ( send == GroupRefPoint->PushButton1 ) {
594     GroupRefPoint->LineEdit1->setFocus();
595     myEditCurrentArgument = GroupRefPoint->LineEdit1;
596     
597     localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
598   }
599   else if ( send == GroupOnCurve->PushButton1 ) {
600     GroupOnCurve->LineEdit1->setFocus();
601     myEditCurrentArgument = GroupOnCurve->LineEdit1;
602     
603     localSelection( GEOM::GEOM_Object::_nil(), TopAbs_EDGE );
604   }
605   else if ( send == GroupOnSurface->PushButton1 )
606   {
607     GroupOnSurface->LineEdit1->setFocus();
608     myEditCurrentArgument = GroupOnSurface->LineEdit1;
609
610     localSelection( GEOM::GEOM_Object::_nil(), TopAbs_FACE );
611   }
612   else if ( send == GroupLineIntersection->PushButton1 ) {
613     GroupLineIntersection->LineEdit1->setFocus();
614     myEditCurrentArgument = GroupLineIntersection->LineEdit1;
615     GroupLineIntersection->PushButton2->setDown( false );
616     GroupLineIntersection->LineEdit1->setEnabled(true);
617     GroupLineIntersection->LineEdit2->setEnabled(false);
618     localSelection( GEOM::GEOM_Object::_nil(), TopAbs_EDGE );
619   }
620   else if ( send == GroupLineIntersection->PushButton2 ) {
621     GroupLineIntersection->LineEdit2->setFocus();
622     myEditCurrentArgument = GroupLineIntersection->LineEdit2;
623     GroupLineIntersection->PushButton1->setDown( false );
624     GroupLineIntersection->LineEdit1->setEnabled(false);
625     GroupLineIntersection->LineEdit2->setEnabled(true);
626     localSelection( GEOM::GEOM_Object::_nil(), TopAbs_EDGE );
627   }
628   send->setDown(true);
629 }
630
631
632 //=================================================================================
633 // function : enterEvent()
634 // purpose  : to reactivate this dialog box when mouse enter onto the window
635 //=================================================================================
636 void BasicGUI_PointDlg::enterEvent( QEvent* )
637 {
638   if ( !mainFrame()->GroupConstructors->isEnabled() )
639     ActivateThisDialog();
640 }
641
642
643 //=================================================================================
644 // function : ActivateThisDialog()
645 // purpose  :
646 //=================================================================================
647 void BasicGUI_PointDlg::ActivateThisDialog( )
648 {
649   GEOMBase_Skeleton::ActivateThisDialog();
650
651   connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
652            this, SLOT( SelectionIntoArgument() ) );
653
654   ConstructorsClicked( getConstructorId() );
655 }
656
657
658 //=================================================================================
659 // function : DeactivateActiveDialog()
660 // purpose  : public slot to deactivate if active
661 //=================================================================================
662 void BasicGUI_PointDlg::DeactivateActiveDialog()
663 {
664   // myGeomGUI->SetState( -1 );
665   GEOMBase_Skeleton::DeactivateActiveDialog();
666 }
667
668
669 //=================================================================================
670 // function : ValueChangedInSpinBox()
671 // purpose  :
672 //=================================================================================
673 void BasicGUI_PointDlg::ValueChangedInSpinBox(double newValue)
674 {
675   displayPreview();
676 }
677
678 //=================================================================================
679 // funcion  : getParameter()
680 // purpose  :
681 //=================================================================================
682 double BasicGUI_PointDlg::getParameter() const
683 {
684   return GroupOnCurve->SpinBox_DX->value();
685 }
686
687
688 //=================================================================================
689 // funcion  : getUParameter()
690 // purpose  :
691 //=================================================================================
692 double BasicGUI_PointDlg::getUParameter() const
693 {
694   return GroupOnSurface->SpinBox_DX->value();
695 }
696
697
698 //=================================================================================
699 // funcion  : getVParameter()
700 // purpose  :
701 //=================================================================================
702 double BasicGUI_PointDlg::getVParameter() const
703 {
704   return GroupOnSurface->SpinBox_DY->value();
705 }
706
707
708 //=================================================================================
709 // function : OnPointSelected
710 // purpose  :
711 //=================================================================================
712 void BasicGUI_PointDlg::OnPointSelected( const gp_Pnt& thePnt )
713 {
714   if ( getConstructorId() == GEOM_POINT_XYZ ) {
715     GroupXYZ->SpinBox_DX->setValue( thePnt.X() );
716     GroupXYZ->SpinBox_DY->setValue( thePnt.Y() );
717     GroupXYZ->SpinBox_DZ->setValue( thePnt.Z() );
718
719     displayPreview();
720   }
721 }
722
723 //=================================================================================
724 // function : createOperation
725 // purpose  :
726 //=================================================================================
727 GEOM::GEOM_IOperations_ptr BasicGUI_PointDlg::createOperation()
728 {
729   return myGeomGUI->GetGeomGen()->GetIBasicOperations( getStudyId() );
730 }
731
732 //=================================================================================
733 // function : isValid
734 // purpose  :
735 //=================================================================================
736 bool BasicGUI_PointDlg::isValid( QString& msg )
737 {
738   const int id = getConstructorId();
739   if ( id == GEOM_POINT_XYZ ) {
740     bool ok = true;
741     ok = GroupXYZ->SpinBox_DX->isValid( msg, !IsPreview() ) && ok;
742     ok = GroupXYZ->SpinBox_DY->isValid( msg, !IsPreview() ) && ok;
743     ok = GroupXYZ->SpinBox_DZ->isValid( msg, !IsPreview() ) && ok;
744     return ok;
745   }
746   else if ( id == GEOM_POINT_REF ) {
747     bool ok = true;
748     ok = GroupRefPoint->SpinBox_DX->isValid( msg, !IsPreview() ) && ok;
749     ok = GroupRefPoint->SpinBox_DY->isValid( msg, !IsPreview() ) && ok;
750     ok = GroupRefPoint->SpinBox_DZ->isValid( msg, !IsPreview() ) && ok;
751
752     return !myRefPoint->_is_nil() && ok;
753   }
754   else if ( id == GEOM_POINT_EDGE ) {
755     bool ok = true;
756     if ( myParamCoord->checkedId() == PARAM_VALUE )
757       ok = GroupOnCurve->SpinBox_DX->isValid( msg, !IsPreview() );
758     else {
759       ok = GroupXYZ->SpinBox_DX->isValid( msg, !IsPreview() ) && ok;
760       ok = GroupXYZ->SpinBox_DY->isValid( msg, !IsPreview() ) && ok;
761       ok = GroupXYZ->SpinBox_DZ->isValid( msg, !IsPreview() ) && ok;
762     }
763     return !myEdge->_is_nil() && ok;
764   }
765   else if ( id == GEOM_POINT_INTINT )
766     return ( !myLine1->_is_nil() && !myLine2->_is_nil() );
767   else if ( id == GEOM_POINT_SURF ) {
768     bool ok = true;
769     if ( myParamCoord->checkedId() == PARAM_VALUE ) {
770       ok = GroupOnSurface->SpinBox_DX->isValid( msg, !IsPreview() ) && ok;
771       ok = GroupOnSurface->SpinBox_DY->isValid( msg, !IsPreview() ) && ok;
772     }
773     else {
774       ok = GroupXYZ->SpinBox_DX->isValid( msg, !IsPreview() ) && ok;
775       ok = GroupXYZ->SpinBox_DY->isValid( msg, !IsPreview() ) && ok;
776       ok = GroupXYZ->SpinBox_DZ->isValid( msg, !IsPreview() ) && ok;
777     }
778     return !myFace->_is_nil() && ok;
779     
780   }
781   return false;
782 }
783
784 //=================================================================================
785 // function : execute
786 // purpose  :
787 //=================================================================================
788 bool BasicGUI_PointDlg::execute( ObjectList& objects )
789 {
790   bool res = false;
791
792   GEOM::GEOM_Object_var anObj;
793   QStringList aParameters;
794
795   GEOM::GEOM_IBasicOperations_var anOper = GEOM::GEOM_IBasicOperations::_narrow( getOperation() );
796
797   switch ( getConstructorId() ) {
798   case GEOM_POINT_XYZ :
799     {
800       double x = GroupXYZ->SpinBox_DX->value();
801       double y = GroupXYZ->SpinBox_DY->value();
802       double z = GroupXYZ->SpinBox_DZ->value();
803
804       aParameters << GroupXYZ->SpinBox_DX->text();
805       aParameters << GroupXYZ->SpinBox_DY->text();
806       aParameters << GroupXYZ->SpinBox_DZ->text();
807       
808       anObj = anOper->MakePointXYZ( x, y, z );
809       res = true;
810       break;
811     }
812   case GEOM_POINT_REF :
813     {
814       double dx = GroupRefPoint->SpinBox_DX->value();
815       double dy = GroupRefPoint->SpinBox_DY->value();
816       double dz = GroupRefPoint->SpinBox_DZ->value();
817
818       aParameters << GroupRefPoint->SpinBox_DX->text();
819       aParameters << GroupRefPoint->SpinBox_DY->text();
820       aParameters << GroupRefPoint->SpinBox_DZ->text();
821       
822       anObj = anOper->MakePointWithReference( myRefPoint, dx, dy, dz );
823       res = true;
824       break;
825     }
826   case GEOM_POINT_EDGE :
827     {
828       if ( myParamCoord->checkedId() == PARAM_VALUE ) {
829         anObj = anOper->MakePointOnCurve( myEdge, getParameter() );
830         aParameters<<GroupOnCurve->SpinBox_DX->text();
831       } else {
832         double x = GroupXYZ->SpinBox_DX->value();
833         double y = GroupXYZ->SpinBox_DY->value();
834         double z = GroupXYZ->SpinBox_DZ->value();
835         
836         aParameters << GroupXYZ->SpinBox_DX->text();
837         aParameters << GroupXYZ->SpinBox_DY->text();
838         aParameters << GroupXYZ->SpinBox_DZ->text();
839         
840         anObj = anOper->MakePointOnCurveByCoord( myEdge, x, y, z );
841       }
842       res = true;
843       break;
844     }
845   case GEOM_POINT_INTINT :
846     anOper->MakePointOnLinesIntersection( myLine1, myLine2 );
847     res = true;
848     break;
849   case GEOM_POINT_SURF :
850     {
851       if ( myParamCoord->checkedId() == PARAM_VALUE ) {
852         anObj = anOper->MakePointOnSurface( myFace, getUParameter(), getVParameter() );
853         aParameters<<GroupOnSurface->SpinBox_DX->text();
854         aParameters<<GroupOnSurface->SpinBox_DY->text();
855       } else {
856         double x = GroupXYZ->SpinBox_DX->value();
857         double y = GroupXYZ->SpinBox_DY->value();
858         double z = GroupXYZ->SpinBox_DZ->value();
859         
860         aParameters << GroupXYZ->SpinBox_DX->text();
861         aParameters << GroupXYZ->SpinBox_DY->text();
862         aParameters << GroupXYZ->SpinBox_DZ->text();
863         
864         anObj = anOper->MakePointOnSurfaceByCoord( myFace, x, y, z );
865       }
866       res = true;
867       break;
868     }
869   }
870   
871   const int id = getConstructorId();
872   if(!anObj->_is_nil() && !IsPreview() && (id == GEOM_POINT_XYZ || 
873                                            id == GEOM_POINT_REF ||
874                                            id == GEOM_POINT_EDGE ||
875                                            id == GEOM_POINT_SURF) ) {
876     myNoteBook->setParameters(anObj, aParameters);
877   }
878   
879
880   if ( id == GEOM_POINT_REF || id == GEOM_POINT_EDGE || id == GEOM_POINT_SURF ) {
881     TopoDS_Shape aShape;
882     if ( GEOMBase::GetShape( anObj, aShape ) && !aShape.IsNull() &&
883          aShape.ShapeType() == TopAbs_VERTEX ) {
884       gp_Pnt aPnt = BRep_Tool::Pnt( TopoDS::Vertex( aShape ) );
885       myX->setText( QString( "%1" ).arg( aPnt.X() ) );
886       myY->setText( QString( "%1" ).arg( aPnt.Y() ) );
887       myZ->setText( QString( "%1" ).arg( aPnt.Z() ) );
888     }
889     else {
890       myX->setText( "" );
891       myY->setText( "" );
892       myZ->setText( "" );
893     }
894   }
895   
896   if ( !anObj->_is_nil() ) {
897     objects.push_back( anObj._retn() );
898   }
899   
900   return res;
901 }
902
903 //=================================================================================
904 // function : addSubshapeToStudy
905 // purpose  : virtual method to add new SubObjects if local selection
906 //=================================================================================
907 void BasicGUI_PointDlg::addSubshapesToStudy()
908 {
909   QMap<QString, GEOM::GEOM_Object_var> objMap;
910
911   switch ( getConstructorId() ) {
912   case GEOM_POINT_XYZ:
913     break;
914   case GEOM_POINT_REF:
915     objMap[GroupRefPoint->LineEdit1->text()] = myRefPoint;
916     break;
917   case GEOM_POINT_EDGE:
918     objMap[GroupOnCurve->LineEdit1->text()] = myEdge;
919     break;
920   case GEOM_POINT_INTINT:
921     objMap[GroupLineIntersection->LineEdit1->text()] = myLine1;
922     objMap[GroupLineIntersection->LineEdit2->text()] = myLine2;
923     break;
924   case GEOM_POINT_SURF:
925     objMap[GroupOnSurface->LineEdit1->text()] = myFace;
926     break;
927   }
928   addSubshapesToFather( objMap );
929 }
930
931 //=================================================================================
932 // function : ClickParamCoord()
933 // purpose  :
934 //=================================================================================
935 void BasicGUI_PointDlg::ClickParamCoord()
936 {
937   updateParamCoord( true );
938   displayPreview();
939 }
940
941 //=================================================================================
942 // function : updateParamCoord
943 // purpose  :
944 //=================================================================================
945 void BasicGUI_PointDlg::updateParamCoord(bool theIsUpdate)
946 {
947   bool isParam = myParamCoord->checkedId() == PARAM_VALUE;
948   GroupXYZ->setShown( !isParam );
949   
950   const int id = getConstructorId();
951   if ( id == GEOM_POINT_EDGE ) {
952     GroupOnCurve->TextLabel2->setShown( isParam );
953     GroupOnCurve->SpinBox_DX->setShown( isParam );
954   }
955   else if ( id == GEOM_POINT_SURF ) {
956     GroupOnSurface->TextLabel2->setShown( isParam );
957     GroupOnSurface->TextLabel3->setShown( isParam );
958     GroupOnSurface->SpinBox_DX->setShown( isParam );
959     GroupOnSurface->SpinBox_DY->setShown( isParam );
960   }
961   if ( theIsUpdate ) {
962     qApp->processEvents();
963     updateGeometry();
964     resize( minimumSizeHint() );
965   }
966 }