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