Salome HOME
Correct make file for shared modules script
[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
25 //  Module : GEOM
26 //  $Header$
27 //
28 #include "BasicGUI_PointDlg.h"
29
30 #include "SUIT_Session.h"
31 #include "SalomeApp_Application.h"
32 #include "LightApp_SelectionMgr.h"
33
34 #include "GEOMImpl_Types.hxx"
35
36 #include <qlabel.h>
37
38 #include "utilities.h"
39
40 #include <gp_Pnt.hxx>
41 #include <TopoDS_Shape.hxx>
42 #include <TopoDS_Vertex.hxx>
43 #include <TopAbs_ShapeEnum.hxx>
44 #include <TopoDS.hxx>
45 #include <BRep_Tool.hxx>
46 #include <TopExp.hxx>
47 #include <TColStd_IndexedMapOfInteger.hxx>
48 #include <TopTools_IndexedMapOfShape.hxx>
49
50 #include <qapplication.h>
51
52 using namespace std;
53
54 //=================================================================================
55 // class    : BasicGUI_PointDlg()
56 // purpose  : Constructs a BasicGUI_PointDlg which is a child of 'parent', with the
57 //            name 'name' and widget flags set to 'f'.
58 //            The dialog will by default be modeless, unless you set 'modal' to
59 //            TRUE to construct a modal dialog.
60 //=================================================================================
61 BasicGUI_PointDlg::BasicGUI_PointDlg(GeometryGUI* theGeometryGUI, QWidget* parent,
62                                      const char* name, bool modal, WFlags fl)
63   :GEOMBase_Skeleton(theGeometryGUI, parent, name, modal, fl )
64 {
65   QPixmap image0(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_POINT")));
66   QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_POINT_EDGE")));
67   QPixmap image2(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_SELECT")));
68   QPixmap image3(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_POINT_REF")));
69   QPixmap image4(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_POINT_LINES")));
70   QPixmap image5(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_POINT_FACE")));
71
72   setCaption(tr("GEOM_POINT_TITLE"));
73
74   QGroupBox* aFrame = new QGroupBox( 1, Qt::Horizontal, this );
75   aFrame->setInsideMargin( 0 );
76   aFrame->setFrameStyle( QFrame::NoFrame );
77
78   /***************************************************************/
79   GroupConstructors->setTitle(tr("GEOM_POINTS"));
80   RadioButton1->setPixmap(image0);
81   RadioButton2->setPixmap(image3);
82   RadioButton3->setPixmap(image1);
83   RadioButton4->show();
84   RadioButton4->setPixmap(image4);
85   RadioButton5->show();
86   RadioButton5->setPixmap(image5);
87
88   GroupXYZ = new DlgRef_3Spin( aFrame, "GroupXYZ" );
89   GroupXYZ->GroupBox1->setTitle(tr("GEOM_COORDINATES"));
90   GroupXYZ->TextLabel1->setText(tr("GEOM_X"));
91   GroupXYZ->TextLabel2->setText(tr("GEOM_Y"));
92   GroupXYZ->TextLabel3->setText(tr("GEOM_Z"));
93
94   GroupOnCurve = new DlgRef_1Sel1Spin( aFrame, "GroupOnCurve" );
95   GroupOnCurve->GroupBox1->setTitle(tr("GEOM_PARAM_POINT"));
96   GroupOnCurve->TextLabel1->setText(tr("GEOM_EDGE"));
97   GroupOnCurve->TextLabel2->setText(tr("GEOM_PARAMETER"));
98   GroupOnCurve->PushButton1->setPixmap(image2);
99
100   GroupOnSurface = new DlgRef_1Sel2Spin( aFrame, "GroupOnSurface" );
101   GroupOnSurface->GroupBox1->setTitle(tr("GEOM_PARAM_POINT"));
102   GroupOnSurface->TextLabel1->setText(tr("GEOM_FACE"));
103   GroupOnSurface->TextLabel2->setText(tr("GEOM_UPARAMETER"));
104   GroupOnSurface->TextLabel3->setText(tr("GEOM_VPARAMETER"));
105   GroupOnSurface->PushButton1->setPixmap(image2);
106
107   GroupRefPoint = new DlgRef_1Sel3Spin( aFrame, "GoupRefPoint" );
108   GroupRefPoint->GroupBox1->setTitle(tr("GEOM_REF_POINT"));
109   GroupRefPoint->TextLabel1->setText(tr("GEOM_POINT"));
110   GroupRefPoint->PushButton1->setPixmap(image2);
111   GroupRefPoint->TextLabel2->setText(tr("GEOM_DX"));
112   GroupRefPoint->TextLabel3->setText(tr("GEOM_DY"));
113   GroupRefPoint->TextLabel4->setText(tr("GEOM_DZ"));
114
115   GroupLineIntersection = new DlgRef_2Sel_QTD (aFrame, "GroupLineIntersection");
116   GroupLineIntersection->GroupBox1->setTitle(tr("GEOM_LINE_INTERSECTION"));
117   GroupLineIntersection->TextLabel1->setText(tr("GEOM_LINE1"));
118   GroupLineIntersection->PushButton1->setPixmap(image2);
119   GroupLineIntersection->TextLabel2->setText(tr("GEOM_LINE2"));
120   GroupLineIntersection->PushButton2->setPixmap(image2);
121
122   Layout1->addWidget( aFrame, 2, 0 );
123   /***************************************************************/
124
125   myCoordGrp = new QGroupBox( 2, Qt::Horizontal, tr( "GEOM_COORDINATES" ), aFrame );
126   new QLabel( tr( "GEOM_X" ), myCoordGrp );
127   myX = new QLineEdit( myCoordGrp );
128   new QLabel( tr( "GEOM_Y" ), myCoordGrp );
129   myY = new QLineEdit( myCoordGrp );
130   new QLabel( tr( "GEOM_Z" ), myCoordGrp );
131   myZ = new QLineEdit( myCoordGrp );
132
133   myX->setReadOnly( true );
134   myY->setReadOnly( true );
135   myZ->setReadOnly( true );
136
137   myX->setEnabled( false );
138   myY->setEnabled( false );
139   myZ->setEnabled( false );
140
141   QPalette aPal = myX->palette();
142   aPal.setColor( QPalette::Disabled, QColorGroup::Text, QColor( 0, 0, 0 ) ) ;
143   myX->setPalette( aPal );
144   myY->setPalette( aPal );
145   myZ->setPalette( aPal );
146
147   setHelpFileName("create_point_page.html");
148
149   Init();
150 }
151
152 //=================================================================================
153 // function : ~BasicGUI_PointDlg()
154 // purpose  : Destructor
155 //=================================================================================
156 BasicGUI_PointDlg::~BasicGUI_PointDlg()
157 {
158 }
159
160 //=================================================================================
161 // function : Init()
162 // purpose  :
163 //=================================================================================
164 void BasicGUI_PointDlg::Init()
165 {
166   GroupOnCurve->LineEdit1->setReadOnly( true );
167   GroupOnSurface->LineEdit1->setReadOnly( true );
168   GroupRefPoint->LineEdit1->setReadOnly( true );
169   GroupLineIntersection->LineEdit1->setReadOnly( true );
170   GroupLineIntersection->LineEdit2->setReadOnly( true );
171
172   myEdge = GEOM::GEOM_Object::_nil();
173   myRefPoint = GEOM::GEOM_Object::_nil();
174
175   myEditCurrentArgument = 0;
176
177   /* Get setting of step value from file configuration */
178   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
179   double step = resMgr->doubleValue( "Geometry", "SettingsGeomStep", 100);
180
181   /* min, max, step and decimals for spin boxes */
182   GroupXYZ->SpinBox_DX->RangeStepAndValidator(COORD_MIN, COORD_MAX, step, DBL_DIGITS_DISPLAY);
183   GroupXYZ->SpinBox_DY->RangeStepAndValidator(COORD_MIN, COORD_MAX, step, DBL_DIGITS_DISPLAY);
184   GroupXYZ->SpinBox_DZ->RangeStepAndValidator(COORD_MIN, COORD_MAX, step, DBL_DIGITS_DISPLAY);
185   GroupXYZ->SpinBox_DX->SetValue(0.0);
186   GroupXYZ->SpinBox_DY->SetValue(0.0);
187   GroupXYZ->SpinBox_DZ->SetValue(0.0);
188
189   GroupRefPoint->SpinBox_DX->RangeStepAndValidator(COORD_MIN, COORD_MAX, step, DBL_DIGITS_DISPLAY);
190   GroupRefPoint->SpinBox_DY->RangeStepAndValidator(COORD_MIN, COORD_MAX, step, DBL_DIGITS_DISPLAY);
191   GroupRefPoint->SpinBox_DZ->RangeStepAndValidator(COORD_MIN, COORD_MAX, step, DBL_DIGITS_DISPLAY);
192   GroupRefPoint->SpinBox_DX->SetValue(0.0);
193   GroupRefPoint->SpinBox_DY->SetValue(0.0);
194   GroupRefPoint->SpinBox_DZ->SetValue(0.0);
195
196   step = 0.1;
197   GroupOnCurve->SpinBox_DX->RangeStepAndValidator(0., 1., step, DBL_DIGITS_DISPLAY);
198   GroupOnCurve->SpinBox_DX->SetValue( 0.5 );
199
200   GroupOnSurface->SpinBox_DX->RangeStepAndValidator(0., 1., step, DBL_DIGITS_DISPLAY);
201   GroupOnSurface->SpinBox_DX->SetValue( 0.5 );
202   GroupOnSurface->SpinBox_DY->RangeStepAndValidator(0., 1., step, DBL_DIGITS_DISPLAY);
203   GroupOnSurface->SpinBox_DY->SetValue( 0.5 );
204
205   /* signals and slots connections */
206   connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
207   connect(myGeomGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
208   connect(myGeomGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
209
210   connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
211   connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
212   connect(GroupConstructors, SIGNAL(clicked(int)), this, SLOT(ConstructorsClicked(int)));
213
214   connect(GroupOnCurve->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
215   connect(GroupOnCurve->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
216   connect(GroupOnSurface->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
217   connect(GroupOnSurface->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
218   connect(GroupLineIntersection->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
219   connect(GroupLineIntersection->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
220   connect(GroupLineIntersection->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
221   connect(GroupLineIntersection->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
222
223   connect(GroupOnCurve->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
224   connect(GroupOnSurface->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
225   connect(GroupOnSurface->SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
226   connect(GroupXYZ->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
227   connect(GroupXYZ->SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
228   connect(GroupXYZ->SpinBox_DZ, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
229   connect(GroupRefPoint->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
230   connect(GroupRefPoint->SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
231   connect(GroupRefPoint->SpinBox_DZ, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
232
233   connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)),
234           GroupOnCurve->SpinBox_DX, SLOT(SetStep(double)));
235   connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)),
236           GroupOnSurface->SpinBox_DX, SLOT(SetStep(double)));
237   connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)),
238           GroupOnSurface->SpinBox_DY, SLOT(SetStep(double)));
239   connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)),
240           GroupXYZ->SpinBox_DX, SLOT(SetStep(double)));
241   connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)),
242           GroupXYZ->SpinBox_DY, SLOT(SetStep(double)));
243   connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)),
244           GroupXYZ->SpinBox_DZ, SLOT(SetStep(double)));
245   connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)),
246           GroupRefPoint->SpinBox_DX, SLOT(SetStep(double)));
247   connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)),
248           GroupRefPoint->SpinBox_DY, SLOT(SetStep(double)));
249   connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)),
250           GroupRefPoint->SpinBox_DZ, SLOT(SetStep(double)));
251
252   connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
253           this, SLOT(SelectionIntoArgument()));
254
255   initName( tr("GEOM_VERTEX") );
256
257   ConstructorsClicked( 0 );
258 }
259
260 //=================================================================================
261 // function : ConstructorsClicked()
262 // purpose  : Radio button management
263 //=================================================================================
264 void BasicGUI_PointDlg::ConstructorsClicked (int constructorId)
265 {
266   globalSelection(); // close local contexts, if any
267
268   switch (constructorId)
269   {
270   case 0:
271     {
272       localSelection(GEOM::GEOM_Object::_nil(), TopAbs_VERTEX);
273
274       GroupRefPoint->hide();
275       GroupOnCurve->hide();
276       GroupLineIntersection->hide();
277       GroupXYZ->show();
278       GroupOnSurface->hide();
279       myCoordGrp->hide();
280       break;
281     }
282   case 1:
283     {
284       myEditCurrentArgument = GroupRefPoint->LineEdit1;
285       myEditCurrentArgument->setText("");
286       myRefPoint = GEOM::GEOM_Object::_nil();
287
288       localSelection(GEOM::GEOM_Object::_nil(), TopAbs_VERTEX);
289
290       GroupXYZ->hide();
291       GroupOnCurve->hide();
292       GroupRefPoint->show();
293       GroupLineIntersection->hide();
294       GroupOnSurface->hide();
295       myCoordGrp->show();
296       break;
297     }
298   case 2:
299     {
300       myEditCurrentArgument = GroupOnCurve->LineEdit1;
301       myEditCurrentArgument->setText("");
302       myEdge = GEOM::GEOM_Object::_nil();
303
304       localSelection(GEOM::GEOM_Object::_nil(), TopAbs_EDGE);
305
306       GroupXYZ->hide();
307       GroupRefPoint->hide();
308       GroupOnCurve->show();
309       GroupLineIntersection->hide();
310       GroupOnSurface->hide();
311       myCoordGrp->show();
312       break;
313     }
314   case 3:
315     {
316       myEditCurrentArgument = GroupLineIntersection->LineEdit1;
317       GroupLineIntersection->LineEdit1->setText("");
318       GroupLineIntersection->LineEdit2->setText("");
319       myLine1 = GEOM::GEOM_Object::_nil();
320       myLine2 = GEOM::GEOM_Object::_nil();
321
322       localSelection(GEOM::GEOM_Object::_nil(), TopAbs_EDGE);
323
324       GroupXYZ->hide();
325       GroupRefPoint->hide();
326       GroupOnCurve->hide();
327       GroupLineIntersection->show();
328       GroupOnSurface->hide();
329       myCoordGrp->hide();
330       break;
331     }
332   case 4:
333     {
334       myEditCurrentArgument = GroupOnSurface->LineEdit1;
335       myEditCurrentArgument->setText("");
336       myFace = GEOM::GEOM_Object::_nil();
337
338       localSelection(GEOM::GEOM_Object::_nil(), TopAbs_FACE);
339
340       GroupXYZ->hide();
341       GroupRefPoint->hide();
342       GroupOnCurve->hide();
343       GroupLineIntersection->hide();
344       GroupOnSurface->show();
345       myCoordGrp->show();
346       break;
347     }
348   }
349
350   myX->setText( "" );
351   myY->setText( "" );
352   myZ->setText( "" );
353
354   qApp->processEvents();
355   updateGeometry();
356   resize( minimumSize() );
357
358   SelectionIntoArgument();
359 }
360
361 //=================================================================================
362 // function : ClickOnOk()
363 // purpose  :
364 //=================================================================================
365 void BasicGUI_PointDlg::ClickOnOk()
366 {
367   if (onAccept())
368     ClickOnCancel();
369 }
370
371 //=================================================================================
372 // function : ClickOnApply()
373 // purpose  :
374 //=================================================================================
375 bool BasicGUI_PointDlg::ClickOnApply()
376 {
377   if (!onAccept())
378     return false;
379
380   initName();
381   ConstructorsClicked(getConstructorId());
382   return true;
383 }
384
385 //=================================================================================
386 // function : ClickOnCancel()
387 // purpose  :
388 //=================================================================================
389 void BasicGUI_PointDlg::ClickOnCancel()
390 {
391   GEOMBase_Skeleton::ClickOnCancel();
392 }
393
394 //=================================================================================
395 // function : SelectionIntoArgument()
396 // purpose  : Called when selection as changed (for constructors not using local context)
397 //=================================================================================
398 void BasicGUI_PointDlg::SelectionIntoArgument()
399 {
400   const int id = getConstructorId();
401
402   if ((id == 1 || id == 2 || id == 4 ) && myEditCurrentArgument != 0)
403   {
404     myEditCurrentArgument->setText("");
405     myX->setText( "" );
406     myY->setText( "" );
407     myZ->setText( "" );
408     myRefPoint = myEdge = myFace = GEOM::GEOM_Object::_nil();
409   }
410
411   if (IObjectCount() == 1)
412   {
413     Standard_Boolean aRes = Standard_False;
414     Handle(SALOME_InteractiveObject) anIO = firstIObject();
415     GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject(anIO, aRes);
416     if (!CORBA::is_nil(aSelectedObject) && aRes)
417     {
418       QString aName = GEOMBase::GetName(aSelectedObject);
419       TopAbs_ShapeEnum aNeedType = TopAbs_VERTEX;
420       TopoDS_Shape aShape;
421       if (GEOMBase::GetShape(aSelectedObject, aShape, TopAbs_SHAPE) && !aShape.IsNull())
422       {
423         if (id == 2 || id == 3)
424           aNeedType = TopAbs_EDGE;
425         if(id == 4)
426           aNeedType = TopAbs_FACE;
427
428         LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
429         TColStd_IndexedMapOfInteger aMap;
430         aSelMgr->GetIndexes(firstIObject(), aMap);
431         if (aMap.Extent() == 1) // Local Selection
432         {
433           int anIndex = aMap(1);
434           if (aNeedType == TopAbs_EDGE)
435             aName += QString(":edge_%1").arg(anIndex);
436           else
437             aName += QString(":vertex_%1").arg(anIndex);
438
439           //Find SubShape Object in Father
440           GEOM::GEOM_Object_var aFindedObject = GEOMBase_Helper::findObjectInFather(aSelectedObject, aName);
441           
442           if ( aFindedObject == GEOM::GEOM_Object::_nil() ) { // Object not found in study
443             GEOM::GEOM_IShapesOperations_var aShapesOp = getGeomEngine()->GetIShapesOperations(getStudyId());
444             aSelectedObject = aShapesOp->GetSubShape(aSelectedObject, anIndex);
445           }
446           else
447             aSelectedObject = aFindedObject; // get Object from study
448           GEOMBase::GetShape(aSelectedObject, aShape, TopAbs_SHAPE);
449         }
450         else // Global Selection
451         {
452           if (aShape.ShapeType() != aNeedType) {
453             aSelectedObject = GEOM::GEOM_Object::_nil();
454             aName = "";
455             if (id == 0) return;
456           }
457         }
458       }
459
460       if (id == 0)
461       {
462         if (aShape.IsNull() || aShape.ShapeType() != aNeedType)
463           return;
464         gp_Pnt aPnt = BRep_Tool::Pnt( TopoDS::Vertex( aShape ) );
465         GroupXYZ->SpinBox_DX->SetValue( aPnt.X() );
466         GroupXYZ->SpinBox_DY->SetValue( aPnt.Y() );
467         GroupXYZ->SpinBox_DZ->SetValue( aPnt.Z() );
468       }
469       else if (id == 1)
470       {
471         myRefPoint = aSelectedObject;
472         GroupRefPoint->LineEdit1->setText(aName);
473       }
474       else if (id == 2)
475       {
476         myEdge = aSelectedObject;
477         GroupOnCurve->LineEdit1->setText(aName);
478       }
479       else if (id == 3)
480       {
481         if (myEditCurrentArgument == GroupLineIntersection->LineEdit1) {
482           myLine1 = aSelectedObject;
483           myEditCurrentArgument->setText(aName);
484         }
485         else if (myEditCurrentArgument == GroupLineIntersection->LineEdit2) {
486           myLine2 = aSelectedObject;
487           myEditCurrentArgument->setText(aName);
488         }
489       }
490       else if (id == 4)
491       {
492         myFace = aSelectedObject;
493         GroupOnSurface->LineEdit1->setText(aName);
494       }
495     }
496   }
497
498   displayPreview();
499 }
500
501 //=================================================================================
502 // function : LineEditReturnPressed()
503 // purpose  :
504 //=================================================================================
505 void BasicGUI_PointDlg::LineEditReturnPressed()
506 {
507   QLineEdit* send = (QLineEdit*)sender();
508   if ( send == GroupRefPoint->LineEdit1 || send == GroupOnCurve->LineEdit1 ||
509        send == GroupLineIntersection->LineEdit1 || send == GroupLineIntersection->LineEdit2  )
510   {
511     myEditCurrentArgument = send;
512     GEOMBase_Skeleton::LineEditReturnPressed();
513   }
514 }
515
516 //=================================================================================
517 // function : SetEditCurrentArgument()
518 // purpose  :
519 //=================================================================================
520 void BasicGUI_PointDlg::SetEditCurrentArgument()
521 {
522   globalSelection(); // close local contexts, if any
523
524   QPushButton* send = (QPushButton*)sender();
525   globalSelection( GEOM_POINT); // to break previous local selection
526
527   if ( send == GroupRefPoint->PushButton1 )
528   {
529     GroupRefPoint->LineEdit1->setFocus();
530     myEditCurrentArgument = GroupRefPoint->LineEdit1;
531
532     localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
533   }
534   else if ( send == GroupOnCurve->PushButton1 )
535   {
536     GroupOnCurve->LineEdit1->setFocus();
537     myEditCurrentArgument = GroupOnCurve->LineEdit1;
538
539     localSelection( GEOM::GEOM_Object::_nil(), TopAbs_EDGE );
540   }
541   else if ( send == GroupOnSurface->PushButton1 )
542   {
543     GroupOnSurface->LineEdit1->setFocus();
544     myEditCurrentArgument = GroupOnSurface->LineEdit1;
545
546     localSelection( GEOM::GEOM_Object::_nil(), TopAbs_FACE );
547   }
548   else if ( send == GroupLineIntersection->PushButton1 )
549   {
550     GroupLineIntersection->LineEdit1->setFocus();
551     myEditCurrentArgument = GroupLineIntersection->LineEdit1;
552
553     localSelection( GEOM::GEOM_Object::_nil(), TopAbs_EDGE );
554   }
555   else if ( send == GroupLineIntersection->PushButton2 )
556   {
557     GroupLineIntersection->LineEdit2->setFocus();
558     myEditCurrentArgument = GroupLineIntersection->LineEdit2;
559
560     localSelection( GEOM::GEOM_Object::_nil(), TopAbs_EDGE );
561   }
562 }
563
564 //=================================================================================
565 // function : enterEvent()
566 // purpose  : to reactivate this dialog box when mouse enter onto the window
567 //=================================================================================
568 void BasicGUI_PointDlg::enterEvent(QEvent* e)
569 {
570   if ( !GroupConstructors->isEnabled() )
571     ActivateThisDialog();
572 }
573
574 //=================================================================================
575 // function : ActivateThisDialog()
576 // purpose  :
577 //=================================================================================
578 void BasicGUI_PointDlg::ActivateThisDialog( )
579 {
580   GEOMBase_Skeleton::ActivateThisDialog();
581   // myGeomGUI->SetState( 0 );
582   ConstructorsClicked( getConstructorId() );
583 }
584
585 //=================================================================================
586 // function : DeactivateActiveDialog()
587 // purpose  : public slot to deactivate if active
588 //=================================================================================
589 void BasicGUI_PointDlg::DeactivateActiveDialog()
590 {
591   // myGeomGUI->SetState( -1 );
592   GEOMBase_Skeleton::DeactivateActiveDialog();
593 }
594
595 //=================================================================================
596 // function : ValueChangedInSpinBox()
597 // purpose  :
598 //=================================================================================
599 void BasicGUI_PointDlg::ValueChangedInSpinBox(double newValue)
600 {
601   displayPreview();
602 }
603
604 //=================================================================================
605 // funcion  : getParameter()
606 // purpose  :
607 //=================================================================================
608 double BasicGUI_PointDlg::getParameter() const
609 {
610   return GroupOnCurve->SpinBox_DX->GetValue();
611 }
612
613
614 //=================================================================================
615 // funcion  : getUParameter()
616 // purpose  :
617 //=================================================================================
618 double BasicGUI_PointDlg::getUParameter() const
619 {
620   return GroupOnSurface->SpinBox_DX->GetValue();
621 }
622
623
624 //=================================================================================
625 // funcion  : getVParameter()
626 // purpose  :
627 //=================================================================================
628 double BasicGUI_PointDlg::getVParameter() const
629 {
630   return GroupOnSurface->SpinBox_DY->GetValue();
631 }
632
633
634 //=================================================================================
635 // function : OnPointSelected
636 // purpose  :
637 //=================================================================================
638 void BasicGUI_PointDlg::OnPointSelected( const gp_Pnt& thePnt )
639 {
640   if ( getConstructorId() == 0 )
641   {
642     GroupXYZ->SpinBox_DX->SetValue( thePnt.X() );
643     GroupXYZ->SpinBox_DY->SetValue( thePnt.Y() );
644     GroupXYZ->SpinBox_DZ->SetValue( thePnt.Z() );
645
646     displayPreview();
647   }
648 }
649
650 //=================================================================================
651 // function : createOperation
652 // purpose  :
653 //=================================================================================
654 GEOM::GEOM_IOperations_ptr BasicGUI_PointDlg::createOperation()
655 {
656   return myGeomGUI->GetGeomGen()->GetIBasicOperations( getStudyId() );
657 }
658
659 //=================================================================================
660 // function : isValid
661 // purpose  :
662 //=================================================================================
663 bool BasicGUI_PointDlg::isValid( QString& msg )
664 {
665   const int id = getConstructorId();
666   if ( id == 0 )
667     return true;
668   else if ( id == 1 )
669     return !myRefPoint->_is_nil();
670   else if ( id == 2 )
671     return !myEdge->_is_nil();
672   else if ( id == 3)
673     return ( !myLine1->_is_nil() && !myLine2->_is_nil() );
674   else if ( id == 4 )
675     return !myFace->_is_nil();
676   return false;
677 }
678
679 //=================================================================================
680 // function : execute
681 // purpose  :
682 //=================================================================================
683 bool BasicGUI_PointDlg::execute( ObjectList& objects )
684 {
685   bool res = false;
686
687   GEOM::GEOM_Object_var anObj;
688
689   switch ( getConstructorId() )
690   {
691   case 0 :
692   {
693     double x = GroupXYZ->SpinBox_DX->GetValue();
694     double y = GroupXYZ->SpinBox_DY->GetValue();
695     double z = GroupXYZ->SpinBox_DZ->GetValue();
696
697     anObj = GEOM::GEOM_IBasicOperations::_narrow( getOperation() )->MakePointXYZ( x,y,z );
698     res = true;
699     break;
700   }
701   case 1 :
702   {
703     double dx = GroupRefPoint->SpinBox_DX->GetValue();
704     double dy = GroupRefPoint->SpinBox_DY->GetValue();
705     double dz = GroupRefPoint->SpinBox_DZ->GetValue();
706
707     anObj = GEOM::GEOM_IBasicOperations::_narrow( getOperation() )->
708       MakePointWithReference( myRefPoint, dx, dy, dz );
709     res = true;
710     break;
711   }
712   case 2 :
713     anObj = GEOM::GEOM_IBasicOperations::_narrow( getOperation() )->
714       MakePointOnCurve( myEdge, getParameter() );
715     res = true;
716     break;
717   case 3 :
718     anObj = GEOM::GEOM_IBasicOperations::_narrow( getOperation() )->
719       MakePointOnLinesIntersection( myLine1, myLine2 );
720       res = true;
721       break;
722   case 4 :
723     anObj = GEOM::GEOM_IBasicOperations::_narrow( getOperation() )->
724       MakePointOnSurface( myFace, getUParameter(), getVParameter() );
725     res = true;
726     break;
727   }
728
729   if ( getConstructorId() == 1 || getConstructorId() == 2 ||
730        getConstructorId() == 4 ) {
731     TopoDS_Shape aShape;
732     if ( GEOMBase::GetShape( anObj, aShape ) && !aShape.IsNull() &&
733          aShape.ShapeType() == TopAbs_VERTEX ) {
734       gp_Pnt aPnt = BRep_Tool::Pnt( TopoDS::Vertex( aShape ) );
735       myX->setText( QString( "%1" ).arg( aPnt.X() ) );
736       myY->setText( QString( "%1" ).arg( aPnt.Y() ) );
737       myZ->setText( QString( "%1" ).arg( aPnt.Z() ) );
738     }
739     else {
740       myX->setText( "" );
741       myY->setText( "" );
742       myZ->setText( "" );
743     }
744   }
745
746   if ( !anObj->_is_nil() )
747   {
748     //printf( "--> a valid point is created\n" );
749     objects.push_back( anObj._retn() );
750   }
751
752   return res;
753 }
754
755 //=================================================================================
756 // function : closeEvent
757 // purpose  :
758 //=================================================================================
759 void BasicGUI_PointDlg::closeEvent( QCloseEvent* e )
760 {
761   GEOMBase_Skeleton::closeEvent( e );
762 }
763
764 //=================================================================================
765 // function : addSubshapeToStudy
766 // purpose  : virtual method to add new SubObjects if local selection
767 //=================================================================================
768 void BasicGUI_PointDlg::addSubshapesToStudy()
769 {
770   QMap<QString, GEOM::GEOM_Object_var> objMap;
771
772   switch (getConstructorId())
773   {
774   case 0:
775     break;
776   case 1:
777     objMap[GroupRefPoint->LineEdit1->text()] = myRefPoint;
778     break;
779   case 2:
780     objMap[GroupOnCurve->LineEdit1->text()] = myEdge;
781     break;
782   case 3:
783     objMap[GroupLineIntersection->LineEdit1->text()] = myLine1;
784     objMap[GroupLineIntersection->LineEdit2->text()] = myLine2;
785     break;
786   case 4:
787     objMap[GroupOnSurface->LineEdit1->text()] = myFace;
788     break;
789   }
790  addSubshapesToFather( objMap );
791 }