Salome HOME
Fix pb with point on edges intersection.
[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   connect( myParamCoord->button( PARAM_VALUE ), SIGNAL( clicked() ), this, SLOT( ClickParamCoord() ) );
252   connect( myParamCoord->button( COORD_VALUE ), SIGNAL( clicked() ), this, SLOT( ClickParamCoord() ) );
253   connect( GroupOnCurve->PushButton1, SIGNAL( clicked() ),       this, SLOT( SetEditCurrentArgument() ) );
254   connect( GroupOnCurve->LineEdit1,   SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
255
256   connect( GroupOnSurface->PushButton1, SIGNAL( clicked() ),       this, SLOT( SetEditCurrentArgument() ) );
257   connect( GroupOnSurface->LineEdit1,   SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
258
259   connect( GroupLineIntersection->PushButton1, SIGNAL( clicked() ),       this, SLOT( SetEditCurrentArgument() ) );
260   connect( GroupLineIntersection->PushButton2, SIGNAL( clicked() ),       this, SLOT( SetEditCurrentArgument() ) );
261   connect( GroupLineIntersection->LineEdit1,   SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
262   connect( GroupLineIntersection->LineEdit2,   SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
263
264   connect( GroupOnCurve->SpinBox_DX,   SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
265   connect( GroupOnSurface->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
266   connect( GroupOnSurface->SpinBox_DY, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
267   connect( GroupXYZ->SpinBox_DX,       SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
268   connect( GroupXYZ->SpinBox_DY,       SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
269   connect( GroupXYZ->SpinBox_DZ,       SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
270   connect( GroupRefPoint->SpinBox_DX,  SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
271   connect( GroupRefPoint->SpinBox_DY,  SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
272   connect( GroupRefPoint->SpinBox_DZ,  SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
273
274   connect( myGeomGUI, SIGNAL( SignalDefaultStepValueChanged( double ) ), this,  SLOT( SetDoubleSpinBoxStep( double ) ) );
275
276   connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged() ),
277            this,  SLOT(SelectionIntoArgument() ) );
278
279   initName( tr( "GEOM_VERTEX" ) );
280
281   ConstructorsClicked( 0 );
282 }
283
284 //=================================================================================
285 // function : SetDoubleSpinBoxStep()
286 // purpose  : Double spin box management
287 //=================================================================================
288 void BasicGUI_PointDlg::SetDoubleSpinBoxStep( double step )
289 {
290   GroupOnCurve->SpinBox_DX->setSingleStep(step);
291   GroupXYZ->SpinBox_DX->setSingleStep(step);
292   GroupXYZ->SpinBox_DY->setSingleStep(step);
293   GroupXYZ->SpinBox_DZ->setSingleStep(step);
294   GroupRefPoint->SpinBox_DX->setSingleStep(step);
295   GroupRefPoint->SpinBox_DY->setSingleStep(step);
296   GroupRefPoint->SpinBox_DZ->setSingleStep(step);
297   GroupOnSurface->SpinBox_DX->setSingleStep(step);
298   GroupOnSurface->SpinBox_DY->setSingleStep(step);
299 }
300
301
302 //=================================================================================
303 // function : ConstructorsClicked()
304 // purpose  : Radio button management
305 //=================================================================================
306 void BasicGUI_PointDlg::ConstructorsClicked(int constructorId)
307 {
308   globalSelection(); // close local contexts, if any
309
310   switch ( constructorId ) {
311   case GEOM_POINT_XYZ:
312     {
313       localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
314
315       GroupRefPoint->hide();
316       GroupOnCurve->hide();
317       GroupLineIntersection->hide();
318       GroupOnSurface->hide();
319
320       myCoordGrp->hide();
321
322       myParamCoord->button( PARAM_VALUE )->hide();
323       myParamCoord->button( COORD_VALUE )->hide();
324       GroupXYZ->show();
325       break;
326     }
327   case GEOM_POINT_REF:
328     {
329       myEditCurrentArgument = GroupRefPoint->LineEdit1;
330       myEditCurrentArgument->setText( "" );
331       myRefPoint = GEOM::GEOM_Object::_nil();
332       GroupRefPoint->PushButton1->setDown(true);
333       localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
334
335       myParamCoord->button( PARAM_VALUE )->hide();
336       myParamCoord->button( COORD_VALUE )->hide();
337       GroupXYZ->hide();
338       GroupOnCurve->hide();
339       GroupLineIntersection->hide();
340       GroupOnSurface->hide();
341
342       GroupRefPoint->show();
343
344       myCoordGrp->show();
345       break;
346     }
347   case GEOM_POINT_EDGE:
348     {
349       myEditCurrentArgument = GroupOnCurve->LineEdit1;
350       myEditCurrentArgument->setText( "" );
351       myEdge = GEOM::GEOM_Object::_nil();
352       GroupOnCurve->PushButton1->setDown(true);
353       localSelection( GEOM::GEOM_Object::_nil(), TopAbs_EDGE );
354
355       GroupRefPoint->hide();
356       GroupLineIntersection->hide();
357       GroupOnSurface->hide();
358
359       myParamCoord->button( PARAM_VALUE )->show();
360       myParamCoord->button( COORD_VALUE )->show();
361       GroupOnCurve->show();
362       myCoordGrp->show();
363
364       updateParamCoord( false );
365       break;
366     }
367   case GEOM_POINT_INTINT:
368     {
369       myEditCurrentArgument = GroupLineIntersection->LineEdit1;
370       GroupLineIntersection->LineEdit1->setText( "" );
371       GroupLineIntersection->LineEdit2->setText( "" );
372       GroupLineIntersection->LineEdit1->setEnabled( true );
373       GroupLineIntersection->LineEdit2->setEnabled( false );
374       myLine1 = GEOM::GEOM_Object::_nil();
375       myLine2 = GEOM::GEOM_Object::_nil();
376       GroupLineIntersection->PushButton1->setDown(true);
377       GroupLineIntersection->PushButton2->setDown(false);
378
379       localSelection( GEOM::GEOM_Object::_nil(), TopAbs_EDGE );
380
381       myParamCoord->button( PARAM_VALUE )->hide();
382       myParamCoord->button( COORD_VALUE )->hide();
383       GroupXYZ->hide();
384       GroupRefPoint->hide();
385       GroupOnCurve->hide();
386       GroupOnSurface->hide();
387
388       myCoordGrp->hide();
389
390       GroupLineIntersection->show();
391       break;
392     }
393   case GEOM_POINT_SURF:
394     {
395       myEditCurrentArgument = GroupOnSurface->LineEdit1;
396       myEditCurrentArgument->setText( "" );
397       myFace = GEOM::GEOM_Object::_nil();
398       GroupOnSurface->PushButton1->setDown(true);
399       localSelection( GEOM::GEOM_Object::_nil(), TopAbs_FACE );
400
401       GroupRefPoint->hide();
402       GroupOnCurve->hide();
403       GroupLineIntersection->hide();
404
405       myParamCoord->button( PARAM_VALUE )->show();
406       myParamCoord->button( COORD_VALUE )->show();
407       GroupOnSurface->show();
408       myCoordGrp->show();
409
410       updateParamCoord( false );
411       break;
412     }
413   }
414
415   myX->setText( "" );
416   myY->setText( "" );
417   myZ->setText( "" );
418
419   qApp->processEvents();
420   updateGeometry();
421   resize( minimumSizeHint() );
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   const int id = getConstructorId();
460
461   if ( ( id == GEOM_POINT_REF || id == GEOM_POINT_EDGE || id == GEOM_POINT_SURF ) && myEditCurrentArgument != 0 )
462   {
463     myEditCurrentArgument->setText( "" );
464     myX->setText( "" );
465     myY->setText( "" );
466     myZ->setText( "" );
467     myRefPoint = myEdge = myFace = GEOM::GEOM_Object::_nil();
468   }
469
470   LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
471   SALOME_ListIO aSelList;
472   aSelMgr->selectedObjects(aSelList);
473
474   if (aSelList.Extent() == 1) {
475     Standard_Boolean aRes = Standard_False;
476     Handle(SALOME_InteractiveObject) anIO = aSelList.First();
477     GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( anIO, aRes );
478     if ( !CORBA::is_nil( aSelectedObject ) && aRes ) {
479       QString aName = GEOMBase::GetName(aSelectedObject);
480       TopAbs_ShapeEnum aNeedType = TopAbs_VERTEX;
481       TopoDS_Shape aShape;
482       if ( GEOMBase::GetShape( aSelectedObject, aShape, TopAbs_SHAPE ) && !aShape.IsNull() ) {
483         if ( id == GEOM_POINT_EDGE || id == GEOM_POINT_INTINT )
484           aNeedType = TopAbs_EDGE;
485         else if ( id == GEOM_POINT_SURF )
486           aNeedType = TopAbs_FACE;
487
488         TColStd_IndexedMapOfInteger aMap;
489         aSelMgr->GetIndexes(anIO, aMap);
490         if ( aMap.Extent() == 1 ) { // Local Selection
491           int anIndex = aMap( 1 );
492           if ( aNeedType == TopAbs_EDGE )
493             aName += QString( ":edge_%1" ).arg( anIndex );
494           else
495             aName += QString( ":vertex_%1" ).arg( anIndex );
496
497           //Find SubShape Object in Father
498           GEOM::GEOM_Object_var aFindedObject = GEOMBase_Helper::findObjectInFather(aSelectedObject, aName);
499
500           if ( aFindedObject == GEOM::GEOM_Object::_nil() ) { // Object not found in study
501             GEOM::GEOM_IShapesOperations_var aShapesOp =
502               getGeomEngine()->GetIShapesOperations(getStudyId());
503             aSelectedObject = aShapesOp->GetSubShape(aSelectedObject, anIndex);
504           }
505           else {
506             aSelectedObject = aFindedObject; // get Object from study
507           }
508           GEOMBase::GetShape( aSelectedObject, aShape, TopAbs_SHAPE );
509         }
510         else { // Global Selection
511           if ( aShape.ShapeType() != aNeedType ) {
512             aSelectedObject = GEOM::GEOM_Object::_nil();
513             aName = "";
514             if ( id == GEOM_POINT_XYZ ) return;
515           }
516         }
517       }
518
519       if ( aShape.IsNull() || aShape.ShapeType() != aNeedType)
520         return;
521
522       if ( id == GEOM_POINT_XYZ ) {
523         gp_Pnt aPnt = BRep_Tool::Pnt( TopoDS::Vertex( aShape ) );
524         GroupXYZ->SpinBox_DX->setValue( aPnt.X() );
525         GroupXYZ->SpinBox_DY->setValue( aPnt.Y() );
526         GroupXYZ->SpinBox_DZ->setValue( aPnt.Z() );
527       }
528       else if ( id == GEOM_POINT_REF ) {
529         myRefPoint = aSelectedObject;
530         GroupRefPoint->LineEdit1->setText( aName );
531       }
532       else if ( id == GEOM_POINT_EDGE ) {
533         myEdge = aSelectedObject;
534         GroupOnCurve->LineEdit1->setText( aName );
535       }
536       else if ( id == GEOM_POINT_INTINT ) {
537         myEditCurrentArgument->setText( aName );
538         globalSelection();
539         localSelection( GEOM::GEOM_Object::_nil(), TopAbs_EDGE );
540         if ( myEditCurrentArgument == GroupLineIntersection->LineEdit1 ) {
541           myLine1 = aSelectedObject;
542           if ( !myLine1->_is_nil() && myLine2->_is_nil() )
543             GroupLineIntersection->PushButton2->click();
544         }
545         else if ( myEditCurrentArgument == GroupLineIntersection->LineEdit2 ) {
546           myLine2 = aSelectedObject;
547           if ( !myLine2->_is_nil() && myLine1->_is_nil() )
548             GroupLineIntersection->PushButton1->click();
549         }
550       }
551       else if ( id == GEOM_POINT_SURF )
552       {
553         myFace = aSelectedObject;
554         GroupOnSurface->LineEdit1->setText( aName );
555       }
556     }
557   }
558
559   displayPreview();
560 }
561
562
563 //=================================================================================
564 // function : LineEditReturnPressed()
565 // purpose  :
566 //=================================================================================
567 void BasicGUI_PointDlg::LineEditReturnPressed()
568 {
569   QLineEdit* send = (QLineEdit*)sender();
570   if ( send == GroupRefPoint->LineEdit1         ||
571        send == GroupOnCurve->LineEdit1          ||
572        send == GroupLineIntersection->LineEdit1 ||
573        send == GroupLineIntersection->LineEdit2  ) {
574     myEditCurrentArgument = send;
575     GEOMBase_Skeleton::LineEditReturnPressed();
576   }
577 }
578
579
580 //=================================================================================
581 // function : SetEditCurrentArgument()
582 // purpose  :
583 //=================================================================================
584 void BasicGUI_PointDlg::SetEditCurrentArgument()
585 {
586   globalSelection(); // close local contexts, if any
587
588   QPushButton* send = (QPushButton*)sender();
589
590   if ( send == GroupRefPoint->PushButton1 ) {
591     GroupRefPoint->LineEdit1->setFocus();
592     myEditCurrentArgument = GroupRefPoint->LineEdit1;
593
594     localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
595   }
596   else if ( send == GroupOnCurve->PushButton1 ) {
597     GroupOnCurve->LineEdit1->setFocus();
598     myEditCurrentArgument = GroupOnCurve->LineEdit1;
599
600     localSelection( GEOM::GEOM_Object::_nil(), TopAbs_EDGE );
601   }
602   else if ( send == GroupOnSurface->PushButton1 )
603   {
604     GroupOnSurface->LineEdit1->setFocus();
605     myEditCurrentArgument = GroupOnSurface->LineEdit1;
606
607     localSelection( GEOM::GEOM_Object::_nil(), TopAbs_FACE );
608   }
609   else if ( send == GroupLineIntersection->PushButton1 ) {
610     GroupLineIntersection->LineEdit1->setFocus();
611     myEditCurrentArgument = GroupLineIntersection->LineEdit1;
612     GroupLineIntersection->PushButton2->setDown( false );
613     GroupLineIntersection->LineEdit1->setEnabled(true);
614     GroupLineIntersection->LineEdit2->setEnabled(false);
615     localSelection( GEOM::GEOM_Object::_nil(), TopAbs_EDGE );
616   }
617   else if ( send == GroupLineIntersection->PushButton2 ) {
618     GroupLineIntersection->LineEdit2->setFocus();
619     myEditCurrentArgument = GroupLineIntersection->LineEdit2;
620     GroupLineIntersection->PushButton1->setDown( false );
621     GroupLineIntersection->LineEdit1->setEnabled(false);
622     GroupLineIntersection->LineEdit2->setEnabled(true);
623     localSelection( GEOM::GEOM_Object::_nil(), TopAbs_EDGE );
624   }
625   send->setDown(true);
626 }
627
628
629 //=================================================================================
630 // function : enterEvent()
631 // purpose  : to reactivate this dialog box when mouse enter onto the window
632 //=================================================================================
633 void BasicGUI_PointDlg::enterEvent( QEvent* )
634 {
635   if ( !mainFrame()->GroupConstructors->isEnabled() )
636     ActivateThisDialog();
637 }
638
639
640 //=================================================================================
641 // function : ActivateThisDialog()
642 // purpose  :
643 //=================================================================================
644 void BasicGUI_PointDlg::ActivateThisDialog( )
645 {
646   GEOMBase_Skeleton::ActivateThisDialog();
647
648   connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
649            this, SLOT( SelectionIntoArgument() ) );
650
651   ConstructorsClicked( getConstructorId() );
652 }
653
654
655 //=================================================================================
656 // function : DeactivateActiveDialog()
657 // purpose  : public slot to deactivate if active
658 //=================================================================================
659 void BasicGUI_PointDlg::DeactivateActiveDialog()
660 {
661   // myGeomGUI->SetState( -1 );
662   GEOMBase_Skeleton::DeactivateActiveDialog();
663 }
664
665
666 //=================================================================================
667 // function : ValueChangedInSpinBox()
668 // purpose  :
669 //=================================================================================
670 void BasicGUI_PointDlg::ValueChangedInSpinBox(double newValue)
671 {
672   displayPreview();
673 }
674
675 //=================================================================================
676 // funcion  : getParameter()
677 // purpose  :
678 //=================================================================================
679 double BasicGUI_PointDlg::getParameter() const
680 {
681   return GroupOnCurve->SpinBox_DX->value();
682 }
683
684
685 //=================================================================================
686 // funcion  : getUParameter()
687 // purpose  :
688 //=================================================================================
689 double BasicGUI_PointDlg::getUParameter() const
690 {
691   return GroupOnSurface->SpinBox_DX->value();
692 }
693
694
695 //=================================================================================
696 // funcion  : getVParameter()
697 // purpose  :
698 //=================================================================================
699 double BasicGUI_PointDlg::getVParameter() const
700 {
701   return GroupOnSurface->SpinBox_DY->value();
702 }
703
704
705 //=================================================================================
706 // function : OnPointSelected
707 // purpose  :
708 //=================================================================================
709 void BasicGUI_PointDlg::OnPointSelected( const gp_Pnt& thePnt )
710 {
711   if ( getConstructorId() == GEOM_POINT_XYZ ) {
712     GroupXYZ->SpinBox_DX->setValue( thePnt.X() );
713     GroupXYZ->SpinBox_DY->setValue( thePnt.Y() );
714     GroupXYZ->SpinBox_DZ->setValue( thePnt.Z() );
715
716     displayPreview();
717   }
718 }
719
720 //=================================================================================
721 // function : createOperation
722 // purpose  :
723 //=================================================================================
724 GEOM::GEOM_IOperations_ptr BasicGUI_PointDlg::createOperation()
725 {
726   return myGeomGUI->GetGeomGen()->GetIBasicOperations( getStudyId() );
727 }
728
729 //=================================================================================
730 // function : isValid
731 // purpose  :
732 //=================================================================================
733 bool BasicGUI_PointDlg::isValid( QString& msg )
734 {
735   const int id = getConstructorId();
736   if ( id == GEOM_POINT_XYZ ) {
737     bool ok = true;
738     ok = GroupXYZ->SpinBox_DX->isValid( msg, !IsPreview() ) && ok;
739     ok = GroupXYZ->SpinBox_DY->isValid( msg, !IsPreview() ) && ok;
740     ok = GroupXYZ->SpinBox_DZ->isValid( msg, !IsPreview() ) && ok;
741     return ok;
742   }
743   else if ( id == GEOM_POINT_REF ) {
744     bool ok = true;
745     ok = GroupRefPoint->SpinBox_DX->isValid( msg, !IsPreview() ) && ok;
746     ok = GroupRefPoint->SpinBox_DY->isValid( msg, !IsPreview() ) && ok;
747     ok = GroupRefPoint->SpinBox_DZ->isValid( msg, !IsPreview() ) && ok;
748
749     return !myRefPoint->_is_nil() && ok;
750   }
751   else if ( id == GEOM_POINT_EDGE ) {
752     bool ok = true;
753     if ( myParamCoord->checkedId() == PARAM_VALUE )
754       ok = GroupOnCurve->SpinBox_DX->isValid( msg, !IsPreview() );
755     else {
756       ok = GroupXYZ->SpinBox_DX->isValid( msg, !IsPreview() ) && ok;
757       ok = GroupXYZ->SpinBox_DY->isValid( msg, !IsPreview() ) && ok;
758       ok = GroupXYZ->SpinBox_DZ->isValid( msg, !IsPreview() ) && ok;
759     }
760     return !myEdge->_is_nil() && ok;
761   }
762   else if ( id == GEOM_POINT_INTINT )
763     return ( !myLine1->_is_nil() && !myLine2->_is_nil() );
764   else if ( id == GEOM_POINT_SURF ) {
765     bool ok = true;
766     if ( myParamCoord->checkedId() == PARAM_VALUE ) {
767       ok = GroupOnSurface->SpinBox_DX->isValid( msg, !IsPreview() ) && ok;
768       ok = GroupOnSurface->SpinBox_DY->isValid( msg, !IsPreview() ) && ok;
769     }
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 !myFace->_is_nil() && ok;
776   }
777   return false;
778 }
779
780 //=================================================================================
781 // function : execute
782 // purpose  :
783 //=================================================================================
784 bool BasicGUI_PointDlg::execute( ObjectList& objects )
785 {
786   bool res = false;
787
788   GEOM::GEOM_Object_var anObj;
789   QStringList aParameters;
790
791   GEOM::GEOM_IBasicOperations_var anOper = GEOM::GEOM_IBasicOperations::_narrow( getOperation() );
792
793   switch ( getConstructorId() ) {
794   case GEOM_POINT_XYZ :
795     {
796       double x = GroupXYZ->SpinBox_DX->value();
797       double y = GroupXYZ->SpinBox_DY->value();
798       double z = GroupXYZ->SpinBox_DZ->value();
799
800       aParameters << GroupXYZ->SpinBox_DX->text();
801       aParameters << GroupXYZ->SpinBox_DY->text();
802       aParameters << GroupXYZ->SpinBox_DZ->text();
803
804       anObj = anOper->MakePointXYZ( x, y, z );
805       res = true;
806       break;
807     }
808   case GEOM_POINT_REF :
809     {
810       double dx = GroupRefPoint->SpinBox_DX->value();
811       double dy = GroupRefPoint->SpinBox_DY->value();
812       double dz = GroupRefPoint->SpinBox_DZ->value();
813
814       aParameters << GroupRefPoint->SpinBox_DX->text();
815       aParameters << GroupRefPoint->SpinBox_DY->text();
816       aParameters << GroupRefPoint->SpinBox_DZ->text();
817
818       anObj = anOper->MakePointWithReference( myRefPoint, dx, dy, dz );
819       res = true;
820       break;
821     }
822   case GEOM_POINT_EDGE :
823     {
824       if ( myParamCoord->checkedId() == PARAM_VALUE ) {
825         anObj = anOper->MakePointOnCurve( myEdge, getParameter() );
826         aParameters<<GroupOnCurve->SpinBox_DX->text();
827       } else {
828         double x = GroupXYZ->SpinBox_DX->value();
829         double y = GroupXYZ->SpinBox_DY->value();
830         double z = GroupXYZ->SpinBox_DZ->value();
831
832         aParameters << GroupXYZ->SpinBox_DX->text();
833         aParameters << GroupXYZ->SpinBox_DY->text();
834         aParameters << GroupXYZ->SpinBox_DZ->text();
835
836         anObj = anOper->MakePointOnCurveByCoord( myEdge, x, y, z );
837       }
838       res = true;
839       break;
840     }
841   case GEOM_POINT_INTINT :
842     anObj = anOper->MakePointOnLinesIntersection( myLine1, myLine2 );
843     res = true;
844     break;
845   case GEOM_POINT_SURF :
846     {
847       if ( myParamCoord->checkedId() == PARAM_VALUE ) {
848         anObj = anOper->MakePointOnSurface( myFace, getUParameter(), getVParameter() );
849         aParameters<<GroupOnSurface->SpinBox_DX->text();
850         aParameters<<GroupOnSurface->SpinBox_DY->text();
851       } else {
852         double x = GroupXYZ->SpinBox_DX->value();
853         double y = GroupXYZ->SpinBox_DY->value();
854         double z = GroupXYZ->SpinBox_DZ->value();
855
856         aParameters << GroupXYZ->SpinBox_DX->text();
857         aParameters << GroupXYZ->SpinBox_DY->text();
858         aParameters << GroupXYZ->SpinBox_DZ->text();
859
860         anObj = anOper->MakePointOnSurfaceByCoord( myFace, x, y, z );
861       }
862       res = true;
863       break;
864     }
865   }
866
867   const int id = getConstructorId();
868   if(!anObj->_is_nil() && !IsPreview() && (id == GEOM_POINT_XYZ ||
869                                            id == GEOM_POINT_REF ||
870                                            id == GEOM_POINT_EDGE ||
871                                            id == GEOM_POINT_SURF) ) {
872       anObj->SetParameters(aParameters.join(":").toLatin1().constData());
873   }
874
875   if ( id == GEOM_POINT_REF || id == GEOM_POINT_EDGE || id == GEOM_POINT_SURF ) {
876     TopoDS_Shape aShape;
877     if ( GEOMBase::GetShape( anObj, aShape ) && !aShape.IsNull() &&
878          aShape.ShapeType() == TopAbs_VERTEX ) {
879       gp_Pnt aPnt = BRep_Tool::Pnt( TopoDS::Vertex( aShape ) );
880       myX->setText( QString( "%1" ).arg( aPnt.X() ) );
881       myY->setText( QString( "%1" ).arg( aPnt.Y() ) );
882       myZ->setText( QString( "%1" ).arg( aPnt.Z() ) );
883     }
884     else {
885       myX->setText( "" );
886       myY->setText( "" );
887       myZ->setText( "" );
888     }
889   }
890
891   if ( !anObj->_is_nil() ) {
892     objects.push_back( anObj._retn() );
893   }
894
895   return res;
896 }
897
898 //=================================================================================
899 // function : addSubshapeToStudy
900 // purpose  : virtual method to add new SubObjects if local selection
901 //=================================================================================
902 void BasicGUI_PointDlg::addSubshapesToStudy()
903 {
904   QMap<QString, GEOM::GEOM_Object_var> objMap;
905
906   switch ( getConstructorId() ) {
907   case GEOM_POINT_XYZ:
908     break;
909   case GEOM_POINT_REF:
910     objMap[GroupRefPoint->LineEdit1->text()] = myRefPoint;
911     break;
912   case GEOM_POINT_EDGE:
913     objMap[GroupOnCurve->LineEdit1->text()] = myEdge;
914     break;
915   case GEOM_POINT_INTINT:
916     objMap[GroupLineIntersection->LineEdit1->text()] = myLine1;
917     objMap[GroupLineIntersection->LineEdit2->text()] = myLine2;
918     break;
919   case GEOM_POINT_SURF:
920     objMap[GroupOnSurface->LineEdit1->text()] = myFace;
921     break;
922   }
923   addSubshapesToFather( objMap );
924 }
925
926 //=================================================================================
927 // function : ClickParamCoord()
928 // purpose  :
929 //=================================================================================
930 void BasicGUI_PointDlg::ClickParamCoord()
931 {
932   updateParamCoord( true );
933   displayPreview();
934 }
935
936 //=================================================================================
937 // function : updateParamCoord
938 // purpose  :
939 //=================================================================================
940 void BasicGUI_PointDlg::updateParamCoord(bool theIsUpdate)
941 {
942   bool isParam = myParamCoord->checkedId() == PARAM_VALUE;
943   GroupXYZ->setShown( !isParam );
944
945   const int id = getConstructorId();
946   if ( id == GEOM_POINT_EDGE ) {
947     GroupOnCurve->TextLabel2->setShown( isParam );
948     GroupOnCurve->SpinBox_DX->setShown( isParam );
949   }
950   else if ( id == GEOM_POINT_SURF ) {
951     GroupOnSurface->TextLabel2->setShown( isParam );
952     GroupOnSurface->TextLabel3->setShown( isParam );
953     GroupOnSurface->SpinBox_DX->setShown( isParam );
954     GroupOnSurface->SpinBox_DY->setShown( isParam );
955   }
956   if ( theIsUpdate ) {
957     qApp->processEvents();
958     updateGeometry();
959     resize( minimumSizeHint() );
960   }
961 }