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