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