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