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