Salome HOME
a97e8e41e7f141df63d40e5459e20a2a2a01bd83
[modules/geom.git] / src / BasicGUI / BasicGUI_PointDlg.cxx
1 // Copyright (C) 2007-2023  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_2Sel1Spin2Check(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   GroupOnCurve->TextLabel3->setText(tr("GEOM_PARAMETER"));
136   GroupOnCurve->CheckButton1->setText(tr("GEOM_TAKE_ORIENTATION_INTO_ACCOUNT"));
137   GroupOnCurve->CheckButton2->setAttribute( Qt::WA_DeleteOnClose );
138   GroupOnCurve->CheckButton2->close();
139
140   GroupOnSurface = new DlgRef_1Sel2Spin(centralWidget());
141   GroupOnSurface->GroupBox1->setTitle(tr("GEOM_POINT_ON_FACE"));
142   GroupOnSurface->TextLabel1->setText(tr("GEOM_FACE"));
143   GroupOnSurface->TextLabel2->setText(tr("GEOM_UPARAMETER"));
144   GroupOnSurface->TextLabel3->setText(tr("GEOM_VPARAMETER"));
145   GroupOnSurface->PushButton1->setIcon(image2);
146
147   GroupRefPoint = new DlgRef_1Sel3Spin(centralWidget());
148   GroupRefPoint->GroupBox1->setTitle(tr("GEOM_REF_POINT"));
149   GroupRefPoint->TextLabel1->setText(tr("GEOM_POINT"));
150   GroupRefPoint->PushButton1->setIcon(image2);
151   GroupRefPoint->TextLabel2->setText(tr("GEOM_DX"));
152   GroupRefPoint->TextLabel3->setText(tr("GEOM_DY"));
153   GroupRefPoint->TextLabel4->setText(tr("GEOM_DZ"));
154
155   /* popup menu for line intersect buttons */
156   QIcon ico_line = QIcon(image6);
157   QIcon ico_wire = QIcon(image7);
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->PushButton2->setIcon(image2);
165   GroupLineIntersection->LineEdit2->setEnabled(false);
166
167   myCoordGrp = new QGroupBox(tr("GEOM_COORDINATES_RES"), centralWidget());
168   QGridLayout* myCoordGrpLayout = new QGridLayout(myCoordGrp);
169   myCoordGrpLayout->addWidget(new QLabel(tr("GEOM_X"), myCoordGrp), 0, 0);
170   myX = new QLineEdit(myCoordGrp);
171   myCoordGrpLayout->addWidget(myX, 0, 1);
172   myCoordGrpLayout->addWidget(new QLabel(tr("GEOM_Y"), myCoordGrp), 1, 0);
173   myY = new QLineEdit(myCoordGrp);
174   myCoordGrpLayout->addWidget(myY, 1, 1);
175   myCoordGrpLayout->addWidget(new QLabel(tr("GEOM_Z"), myCoordGrp), 2, 0);
176   myZ = new QLineEdit(myCoordGrp);
177   myCoordGrpLayout->addWidget(myZ, 2, 1);
178
179   QVBoxLayout* layout = new QVBoxLayout(centralWidget());
180   layout->setMargin(0); layout->setSpacing(6);
181   layout->addWidget(myParamGroup);
182   layout->addWidget(GroupXYZ);
183   layout->addWidget(GroupOnCurve);
184   layout->addWidget(GroupOnSurface);
185   layout->addWidget(GroupRefPoint);
186   layout->addWidget(GroupLineIntersection);
187   layout->addWidget(myCoordGrp);
188
189   myX->setReadOnly(true);
190   myY->setReadOnly(true);
191   myZ->setReadOnly(true);
192
193   myX->setEnabled(false);
194   myY->setEnabled(false);
195   myZ->setEnabled(false);
196
197   QPalette aPal = myX->palette();
198   aPal.setColor(QPalette::Disabled, QPalette::Text, QColor(0, 0, 0));
199   myX->setPalette(aPal);
200   myY->setPalette(aPal);
201   myZ->setPalette(aPal);
202
203   setHelpFileName("create_point_page.html");
204
205   Init();
206 }
207
208
209 //=================================================================================
210 // function : ~BasicGUI_PointDlg()
211 // purpose  : Destructor
212 //=================================================================================
213 BasicGUI_PointDlg::~BasicGUI_PointDlg()
214 {
215 }
216
217
218 //=================================================================================
219 // function : Init()
220 // purpose  :
221 //=================================================================================
222 void BasicGUI_PointDlg::Init()
223 {
224   GroupOnCurve->LineEdit1->setReadOnly(true);
225   GroupOnCurve->LineEdit2->setReadOnly(true);
226   GroupOnSurface->LineEdit1->setReadOnly(true);
227   GroupRefPoint->LineEdit1->setReadOnly(true);
228   GroupLineIntersection->LineEdit1->setReadOnly(true);
229   GroupLineIntersection->LineEdit2->setReadOnly(true);
230   GroupLineIntersection->LineEdit1->setEnabled(true);
231   GroupLineIntersection->LineEdit2->setEnabled(false);
232
233   myEdge.nullify();
234   myFace.nullify();
235   myRefPoint.nullify();
236   myLine1.nullify();
237   myLine2.nullify();
238   myNeedType = TopAbs_VERTEX;
239
240   myEditCurrentArgument = 0;
241
242   /* Get setting of step value from file configuration */
243   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
244   double step = resMgr->doubleValue("Geometry", "SettingsGeomStep", 100);
245
246   /* min, max, step and decimals for spin boxes */
247   initSpinBox(GroupXYZ->SpinBox_DX, COORD_MIN, COORD_MAX, step, "length_precision");
248   initSpinBox(GroupXYZ->SpinBox_DY, COORD_MIN, COORD_MAX, step, "length_precision");
249   initSpinBox(GroupXYZ->SpinBox_DZ, COORD_MIN, COORD_MAX, step, "length_precision");
250   GroupXYZ->SpinBox_DX->setValue(0.0);
251   GroupXYZ->SpinBox_DY->setValue(0.0);
252   GroupXYZ->SpinBox_DZ->setValue(0.0);
253
254   initSpinBox(GroupRefPoint->SpinBox_DX, COORD_MIN, COORD_MAX, step, "length_precision");
255   initSpinBox(GroupRefPoint->SpinBox_DY, COORD_MIN, COORD_MAX, step, "length_precision");
256   initSpinBox(GroupRefPoint->SpinBox_DZ, COORD_MIN, COORD_MAX, step, "length_precision");
257   GroupRefPoint->SpinBox_DX->setValue(0.0);
258   GroupRefPoint->SpinBox_DY->setValue(0.0);
259   GroupRefPoint->SpinBox_DZ->setValue(0.0);
260
261   step = 0.1;
262
263   initSpinBox(GroupOnCurve->SpinBox_DX, 0., 1., step, "parametric_precision");
264   GroupOnCurve->SpinBox_DX->setValue(0.5);
265   GroupOnCurve->CheckButton1->setChecked(true);
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->CheckButton1,         SIGNAL(toggled(bool)), this, SLOT(CheckBoxClicked()));
284
285   connect(GroupOnCurve->PushButton1,          SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
286   connect(GroupOnCurve->PushButton2,          SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
287   connect(GroupOnSurface->PushButton1,        SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
288   connect(GroupLineIntersection->PushButton1, SIGNAL(pressed()), this, SLOT(SetEditCurrentArgument()));
289   connect(GroupLineIntersection->PushButton2, SIGNAL(pressed()), this, SLOT(SetEditCurrentArgument()));
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(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(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(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       std::list<int> needTypes;
394       needTypes.push_back( TopAbs_EDGE ), needTypes.push_back( TopAbs_WIRE );
395       localSelection(needTypes );
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(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;
504   if (id == GEOM_POINT_INTINT) {
505     QList<TopAbs_ShapeEnum> needTypes;
506     needTypes << TopAbs_EDGE, needTypes << TopAbs_WIRE;
507     aSelectedObject= getSelected(needTypes);
508   }
509   else 
510     aSelectedObject= getSelected(myNeedType);
511   TopoDS_Shape aShape;
512   if (aSelectedObject && GEOMBase::GetShape(aSelectedObject.get(), aShape) && !aShape.IsNull()) {
513     QString aName = GEOMBase::GetName(aSelectedObject.get());
514     myBusy = true;
515     if (id == GEOM_POINT_XYZ) {
516       gp_Pnt aPnt = BRep_Tool::Pnt(TopoDS::Vertex(aShape));
517       GroupXYZ->SpinBox_DX->setValue(aPnt.X());
518       GroupXYZ->SpinBox_DY->setValue(aPnt.Y());
519       GroupXYZ->SpinBox_DZ->setValue(aPnt.Z());
520     }
521     else if (id == GEOM_POINT_REF) {
522       myRefPoint = aSelectedObject;
523       GroupRefPoint->LineEdit1->setText(aName);
524     }
525     else if (id == GEOM_POINT_EDGE) {
526       myEditCurrentArgument->setText(aName);
527       if (myEditCurrentArgument == GroupOnCurve->LineEdit1) {
528         myEdge = aSelectedObject;
529         if (myEdge && !myRefPoint) {
530           GroupOnCurve->PushButton2->click();
531         }
532       }
533       else if (myEditCurrentArgument == GroupOnCurve->LineEdit2) {
534         myRefPoint = aSelectedObject;
535         if (myRefPoint && !myEdge) {
536           GroupOnCurve->PushButton1->click();
537         }
538       }
539     }
540     else if (id == GEOM_POINT_INTINT) {
541       myEditCurrentArgument->setText(aName);
542       if (myEditCurrentArgument == GroupLineIntersection->LineEdit1) {
543         myLine1 = aSelectedObject;
544         if (myLine1 && !myLine2) {
545           GroupLineIntersection->PushButton2->click();
546         }
547       }
548       else if (myEditCurrentArgument == GroupLineIntersection->LineEdit2) {
549         myLine2 = aSelectedObject;
550         if (myLine2 && !myLine1) {
551           GroupLineIntersection->PushButton1->click();
552         }
553       }
554     }
555     else if (id == GEOM_POINT_SURF) {
556       myFace = aSelectedObject;
557       GroupOnSurface->LineEdit1->setText(aName);
558     }
559     myBusy = false;
560   }
561
562   displayPreview(true);
563 }
564
565
566 //=================================================================================
567 // function : SetEditCurrentArgument()
568 // purpose  :
569 //=================================================================================
570 void BasicGUI_PointDlg::SetEditCurrentArgument()
571 {
572   QPushButton* send = (QPushButton*)sender();
573
574   if (send == GroupRefPoint->PushButton1) {
575     GroupRefPoint->LineEdit1->setFocus();
576     myEditCurrentArgument = GroupRefPoint->LineEdit1;
577     globalSelection(); // close local contexts, if any
578     localSelection(TopAbs_VERTEX);
579   }
580   else if (send == GroupOnCurve->PushButton1) {
581     GroupOnCurve->LineEdit1->setFocus();
582     myEditCurrentArgument = GroupOnCurve->LineEdit1;
583     globalSelection(); // close local contexts, if any
584     myNeedType = TopAbs_EDGE;
585     localSelection(myNeedType);
586     GroupOnCurve->PushButton2->setDown(false);
587     GroupOnCurve->LineEdit1->setEnabled(true);
588     GroupOnCurve->LineEdit2->setEnabled(false);
589   }
590   else if (send == GroupOnCurve->PushButton2) {
591     GroupOnCurve->LineEdit2->setFocus();
592     myEditCurrentArgument = GroupOnCurve->LineEdit2;
593     globalSelection(); // close local contexts, if any
594     myNeedType = TopAbs_VERTEX;
595     localSelection(myNeedType);
596     GroupOnCurve->PushButton1->setDown(false);
597     GroupOnCurve->LineEdit2->setEnabled(true);
598     GroupOnCurve->LineEdit1->setEnabled(false);
599   }
600   else if (send == GroupOnSurface->PushButton1)
601   {
602     GroupOnSurface->LineEdit1->setFocus();
603     myEditCurrentArgument = GroupOnSurface->LineEdit1;
604     globalSelection(); // close local contexts, if any
605     localSelection(TopAbs_FACE);
606   }
607   else if (send == GroupLineIntersection->PushButton1) {
608     GroupLineIntersection->LineEdit1->setFocus();
609     myEditCurrentArgument = GroupLineIntersection->LineEdit1;
610     GroupLineIntersection->PushButton2->setDown(false);
611     GroupLineIntersection->LineEdit1->setEnabled(true);
612     GroupLineIntersection->LineEdit2->setEnabled(false);
613   }
614   else if (send == GroupLineIntersection->PushButton2) {
615     GroupLineIntersection->LineEdit2->setFocus();
616     myEditCurrentArgument = GroupLineIntersection->LineEdit2;
617     GroupLineIntersection->PushButton1->setDown(false);
618     GroupLineIntersection->LineEdit1->setEnabled(false);
619     GroupLineIntersection->LineEdit2->setEnabled(true);
620   }
621   send->setDown(true);
622
623   //  if ((send == GroupLineIntersection->PushButton1 ||
624   //         send == GroupLineIntersection->PushButton2) && !myBusy)
625   //    SelectionIntoArgument();
626 }
627
628
629 //=================================================================================
630 // function : enterEvent()
631 // purpose  : to reactivate this dialog box when mouse enter onto the window
632 //=================================================================================
633 void BasicGUI_PointDlg::enterEvent(QEvent*)
634 {
635   if (!mainFrame()->GroupConstructors->isEnabled())
636     ActivateThisDialog();
637 }
638
639
640 //=================================================================================
641 // function : ActivateThisDialog()
642 // purpose  :
643 //=================================================================================
644 void BasicGUI_PointDlg::ActivateThisDialog()
645 {
646   GEOMBase_Skeleton::ActivateThisDialog();
647
648   connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
649            this, SLOT(SelectionIntoArgument()));
650
651   ConstructorsClicked(getConstructorId());
652 }
653
654
655 //=================================================================================
656 // function : DeactivateActiveDialog()
657 // purpose  : public slot to deactivate if active
658 //=================================================================================
659 void BasicGUI_PointDlg::DeactivateActiveDialog()
660 {
661   // myGeomGUI->SetState(-1);
662   GEOMBase_Skeleton::DeactivateActiveDialog();
663 }
664
665
666 //=================================================================================
667 // function : ValueChangedInSpinBox()
668 // purpose  :
669 //=================================================================================
670 void BasicGUI_PointDlg::ValueChangedInSpinBox(double /*newValue*/)
671 {
672   displayPreview(true);
673 }
674
675 //=================================================================================
676 // function : CheckBoxClicked()
677 // purpose  : Check Boxes Management
678 //=================================================================================
679 void BasicGUI_PointDlg::CheckBoxClicked()
680 {
681   displayPreview(true);
682 }
683
684
685 //=================================================================================
686 // function  : getParameter()
687 // purpose  :
688 //=================================================================================
689 double BasicGUI_PointDlg::getParameter() const
690 {
691   return GroupOnCurve->SpinBox_DX->value();
692 }
693
694
695 //=================================================================================
696 // function  : getUParameter()
697 // purpose  :
698 //=================================================================================
699 double BasicGUI_PointDlg::getUParameter() const
700 {
701   return GroupOnSurface->SpinBox_DX->value();
702 }
703
704
705 //=================================================================================
706 // function  : getVParameter()
707 // purpose  :
708 //=================================================================================
709 double BasicGUI_PointDlg::getVParameter() const
710 {
711   return GroupOnSurface->SpinBox_DY->value();
712 }
713
714
715 //=================================================================================
716 // function : OnPointSelected
717 // purpose  :
718 //=================================================================================
719 void BasicGUI_PointDlg::OnPointSelected(const gp_Pnt& thePnt)
720 {
721   if (getConstructorId() == GEOM_POINT_XYZ) {
722     GroupXYZ->SpinBox_DX->setValue(thePnt.X());
723     GroupXYZ->SpinBox_DY->setValue(thePnt.Y());
724     GroupXYZ->SpinBox_DZ->setValue(thePnt.Z());
725
726     displayPreview(true);
727   }
728 }
729
730 //=================================================================================
731 // function : createOperation
732 // purpose  :
733 //=================================================================================
734 GEOM::GEOM_IOperations_ptr BasicGUI_PointDlg::createOperation()
735 {
736   return myGeomGUI->GetGeomGen()->GetIBasicOperations();
737 }
738
739 //=================================================================================
740 // function : isValid
741 // purpose  :
742 //=================================================================================
743 bool BasicGUI_PointDlg::isValid(QString& msg)
744 {
745   bool ok = false;
746   switch (getConstructorId()) {
747   case GEOM_POINT_XYZ :
748     ok = GroupXYZ->SpinBox_DX->isValid(msg, !IsPreview()) &&
749          GroupXYZ->SpinBox_DY->isValid(msg, !IsPreview()) &&
750          GroupXYZ->SpinBox_DZ->isValid(msg, !IsPreview());
751     break;
752   case GEOM_POINT_REF:
753     ok = GroupRefPoint->SpinBox_DX->isValid(msg, !IsPreview()) &&
754          GroupRefPoint->SpinBox_DY->isValid(msg, !IsPreview()) &&
755          GroupRefPoint->SpinBox_DZ->isValid(msg, !IsPreview()) &&
756          myRefPoint;
757     break;
758   case GEOM_POINT_EDGE:
759     if (myParamCoord->checkedId() == PARAM_VALUE || myParamCoord->checkedId() == LENGTH_VALUE)
760       ok = GroupOnCurve->SpinBox_DX->isValid(msg, !IsPreview());
761     else
762       ok = GroupXYZ->SpinBox_DX->isValid(msg, !IsPreview()) &&
763            GroupXYZ->SpinBox_DY->isValid(msg, !IsPreview()) &&
764            GroupXYZ->SpinBox_DZ->isValid(msg, !IsPreview());
765     ok = myEdge && ok;
766     break;
767   case GEOM_POINT_INTINT:
768     ok = myLine1 && myLine2;
769     break;
770   case GEOM_POINT_SURF:
771     if (myParamCoord->checkedId() == PARAM_VALUE)
772       ok = GroupOnSurface->SpinBox_DX->isValid(msg, !IsPreview()) &&
773            GroupOnSurface->SpinBox_DY->isValid(msg, !IsPreview());
774     else
775       ok = GroupXYZ->SpinBox_DX->isValid(msg, !IsPreview()) &&
776            GroupXYZ->SpinBox_DY->isValid(msg, !IsPreview()) &&
777            GroupXYZ->SpinBox_DZ->isValid(msg, !IsPreview());
778     ok = myFace && ok;
779     break;
780   default:
781     break;
782   }
783   return ok;
784 }
785
786 //=================================================================================
787 // function : execute
788 // purpose  :
789 //=================================================================================
790 bool BasicGUI_PointDlg::execute(ObjectList& objects)
791 {
792   bool res = false;
793
794   GEOM::GEOM_Object_var anObj;
795   QStringList aParameters;
796
797   GEOM::GEOM_IBasicOperations_var anOper = GEOM::GEOM_IBasicOperations::_narrow(getOperation());
798
799   switch (getConstructorId()) {
800   case GEOM_POINT_XYZ :
801     {
802       double x = GroupXYZ->SpinBox_DX->value();
803       double y = GroupXYZ->SpinBox_DY->value();
804       double z = GroupXYZ->SpinBox_DZ->value();
805
806       aParameters << GroupXYZ->SpinBox_DX->text();
807       aParameters << GroupXYZ->SpinBox_DY->text();
808       aParameters << GroupXYZ->SpinBox_DZ->text();
809
810       anObj = anOper->MakePointXYZ(x, y, z);
811       res = true;
812       break;
813     }
814   case GEOM_POINT_REF :
815     {
816       double dx = GroupRefPoint->SpinBox_DX->value();
817       double dy = GroupRefPoint->SpinBox_DY->value();
818       double dz = GroupRefPoint->SpinBox_DZ->value();
819
820       aParameters << GroupRefPoint->SpinBox_DX->text();
821       aParameters << GroupRefPoint->SpinBox_DY->text();
822       aParameters << GroupRefPoint->SpinBox_DZ->text();
823
824       anObj = anOper->MakePointWithReference(myRefPoint.get(), dx, dy, dz);
825       res = true;
826       break;
827     }
828   case GEOM_POINT_EDGE :
829     {
830       if (myParamCoord->checkedId() == PARAM_VALUE) {
831         bool isUseOrientation = GroupOnCurve->CheckButton1->isChecked();
832
833         anObj = anOper->MakePointOnCurve(myEdge.get(), getParameter(), isUseOrientation);
834         aParameters<<GroupOnCurve->SpinBox_DX->text();
835       }
836       else if (myParamCoord->checkedId() == LENGTH_VALUE) {
837         anObj = anOper->MakePointOnCurveByLength(myEdge.get(), getParameter(), myRefPoint.get());
838         aParameters<<GroupOnCurve->SpinBox_DX->text();
839       }
840       else if (myParamCoord->checkedId() == COORD_VALUE) {
841         double x = GroupXYZ->SpinBox_DX->value();
842         double y = GroupXYZ->SpinBox_DY->value();
843         double z = GroupXYZ->SpinBox_DZ->value();
844
845         aParameters << GroupXYZ->SpinBox_DX->text();
846         aParameters << GroupXYZ->SpinBox_DY->text();
847         aParameters << GroupXYZ->SpinBox_DZ->text();
848
849         anObj = anOper->MakePointOnCurveByCoord(myEdge.get(), x, y, z);
850       }
851       res = true;
852       break;
853     }
854   case GEOM_POINT_INTINT :
855     anObj = anOper->MakePointOnLinesIntersection(myLine1.get(), myLine2.get());
856     if (!anObj->_is_nil()) {
857       QString aName = getNewObjectName();
858       if (anObj->GetShapeType() == GEOM::COMPOUND && aName.startsWith("Vertex"))
859         initName(tr("GEOM_COMPOUND"));
860       else if (anObj->GetShapeType() == GEOM::VERTEX && aName.startsWith("Compound"))
861         initName(tr("GEOM_VERTEX"));
862     }
863     res = true;
864     break;
865   case GEOM_POINT_SURF :
866     {
867       if (myParamCoord->checkedId() == PARAM_VALUE) {
868         anObj = anOper->MakePointOnSurface(myFace.get(), getUParameter(), getVParameter());
869         aParameters<<GroupOnSurface->SpinBox_DX->text();
870         aParameters<<GroupOnSurface->SpinBox_DY->text();
871       } else {
872         double x = GroupXYZ->SpinBox_DX->value();
873         double y = GroupXYZ->SpinBox_DY->value();
874         double z = GroupXYZ->SpinBox_DZ->value();
875
876         aParameters << GroupXYZ->SpinBox_DX->text();
877         aParameters << GroupXYZ->SpinBox_DY->text();
878         aParameters << GroupXYZ->SpinBox_DZ->text();
879
880         anObj = anOper->MakePointOnSurfaceByCoord(myFace.get(), x, y, z);
881       }
882       res = true;
883       break;
884     }
885   }
886
887   const int id = getConstructorId();
888   if(!anObj->_is_nil() && !IsPreview() && (id == GEOM_POINT_XYZ ||
889                                            id == GEOM_POINT_REF ||
890                                            id == GEOM_POINT_EDGE ||
891                                            id == GEOM_POINT_SURF)) {
892       anObj->SetParameters(aParameters.join(":").toUtf8().constData());
893   }
894
895   if (id == GEOM_POINT_REF || id == GEOM_POINT_EDGE || id == GEOM_POINT_SURF) {
896     TopoDS_Shape aShape;
897     if (GEOMBase::GetShape(anObj, aShape) && !aShape.IsNull() &&
898          aShape.ShapeType() == TopAbs_VERTEX) {
899       gp_Pnt aPnt = BRep_Tool::Pnt(TopoDS::Vertex(aShape));
900       SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
901       int aPrecision = resMgr->integerValue("Geometry", "length_precision", 6);
902       myX->setText(DlgRef::PrintDoubleValue(aPnt.X(), aPrecision));
903       myY->setText(DlgRef::PrintDoubleValue(aPnt.Y(), aPrecision));
904       myZ->setText(DlgRef::PrintDoubleValue(aPnt.Z(), aPrecision));
905     }
906     else {
907       myX->setText("");
908       myY->setText("");
909       myZ->setText("");
910     }
911   }
912
913   if (!anObj->_is_nil()) {
914     objects.push_back(anObj._retn());
915   }
916
917   return res;
918 }
919
920 //=================================================================================
921 // function : addSubshapeToStudy
922 // purpose  : virtual method to add new SubObjects if local selection
923 //=================================================================================
924 void BasicGUI_PointDlg::addSubshapesToStudy()
925 {
926   switch (getConstructorId()) {
927   case GEOM_POINT_REF:
928     GEOMBase::PublishSubObject(myRefPoint.get());
929     break;
930   case GEOM_POINT_EDGE:
931     GEOMBase::PublishSubObject(myEdge.get());
932     break;
933   case GEOM_POINT_INTINT:
934     GEOMBase::PublishSubObject(myLine1.get());
935     GEOMBase::PublishSubObject(myLine2.get());
936     break;
937   case GEOM_POINT_SURF:
938     GEOMBase::PublishSubObject(myFace.get());
939     break;
940   default:
941     break;
942   }
943 }
944
945 //=================================================================================
946 // function : getSourceObjects
947 // purpose  : virtual method to get source objects
948 //=================================================================================
949 QList<GEOM::GeomObjPtr> BasicGUI_PointDlg::getSourceObjects()
950 {
951   QList<GEOM::GeomObjPtr> res;
952   res << myRefPoint << myEdge << myLine1 << myLine2 << myFace;
953   return res;
954 }
955
956 //=================================================================================
957 // function : ClickParamCoord()
958 // purpose  :
959 //=================================================================================
960 void BasicGUI_PointDlg::ClickParamCoord(int /*id*/)
961 {
962   updateParamCoord(true);
963   displayPreview(true);
964 }
965
966 //=================================================================================
967 // function : updateParamCoord
968 // purpose  :
969 //=================================================================================
970 void BasicGUI_PointDlg::updateParamCoord(bool theIsUpdate)
971 {
972   bool isParam = myParamCoord->checkedId() == PARAM_VALUE;
973   bool isLength = myParamCoord->checkedId() == LENGTH_VALUE;
974
975   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
976   double step = resMgr->doubleValue("Geometry", "SettingsGeomStep", 100);
977
978   const int id = getConstructorId();
979   if (id == GEOM_POINT_EDGE) {
980     GroupOnCurve->TextLabel2->setVisible(isLength);
981     GroupOnCurve->PushButton2->setVisible(isLength);
982     GroupOnCurve->LineEdit2->setVisible(isLength);
983     GroupOnCurve->TextLabel3->setVisible(isParam || isLength);
984     GroupOnCurve->SpinBox_DX->setVisible(isParam || isLength);
985     GroupOnCurve->CheckButton1->setVisible(isParam);
986     if (isParam){
987       initSpinBox(GroupOnCurve->SpinBox_DX, 0., 1., 0.1, "parametric_precision");
988       GroupOnCurve->SpinBox_DX->setValue(0.5);
989       GroupOnCurve->TextLabel3->setText(tr("GEOM_PARAMETER"));
990     }
991     else if (isLength){
992       initSpinBox(GroupOnCurve->SpinBox_DX, COORD_MIN, COORD_MAX, step, "length_precision");
993       GroupOnCurve->SpinBox_DX->setValue(0.0);
994       GroupOnCurve->TextLabel3->setText(tr("GEOM_LENGTH"));
995     }
996   }
997   else if (id == GEOM_POINT_SURF) {
998     GroupOnSurface->TextLabel2->setVisible(isParam);
999     GroupOnSurface->TextLabel3->setVisible(isParam);
1000     GroupOnSurface->SpinBox_DX->setVisible(isParam);
1001     GroupOnSurface->SpinBox_DY->setVisible(isParam);
1002   }
1003
1004   GroupXYZ->setVisible(!isParam && !isLength);
1005
1006   if (theIsUpdate)
1007     QTimer::singleShot(50, this, SLOT(updateSize()));
1008 }
1009
1010 //=================================================================================
1011 // function : updateSize
1012 // purpose  : adjust dialog size to minimum
1013 //=================================================================================
1014 void BasicGUI_PointDlg::updateSize()
1015 {
1016   qApp->processEvents();
1017   updateGeometry();
1018   resize(minimumSizeHint());
1019 }