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