1 // Copyright (C) 2007-2012 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // GEOM GEOMGUI : GUI for Geometry component
24 // File : BasicGUI_PointDlg.cxx
25 // Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
27 #include "BasicGUI_PointDlg.h"
29 #include <SUIT_ResourceMgr.h>
30 #include <SUIT_Session.h>
31 #include <SalomeApp_Application.h>
32 #include <LightApp_SelectionMgr.h>
34 #include <GeometryGUI.h>
39 #include <GEOMImpl_Types.hxx>
41 #include <QApplication>
42 #include <QButtonGroup>
43 #include <QHBoxLayout>
45 #include <QRadioButton>
50 #include <TopoDS_Shape.hxx>
51 #include <TopAbs_ShapeEnum.hxx>
53 #include <BRep_Tool.hxx>
55 #include <TColStd_IndexedMapOfInteger.hxx>
56 #include <TopTools_IndexedMapOfShape.hxx>
60 #define LENGTH_VALUE 2
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
71 enum { SelectEdge, SelectWire };
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),
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")));
95 setWindowTitle(tr("GEOM_POINT_TITLE"));
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);
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);
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"));
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);
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);
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"));
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;
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);
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);
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);
191 myX->setReadOnly(true);
192 myY->setReadOnly(true);
193 myZ->setReadOnly(true);
195 myX->setEnabled(false);
196 myY->setEnabled(false);
197 myZ->setEnabled(false);
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);
205 setHelpFileName("create_point_page.html");
211 //=================================================================================
212 // function : ~BasicGUI_PointDlg()
213 // purpose : Destructor
214 //=================================================================================
215 BasicGUI_PointDlg::~BasicGUI_PointDlg()
220 //=================================================================================
223 //=================================================================================
224 void BasicGUI_PointDlg::Init()
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);
237 myRefPoint.nullify();
240 myNeedType = TopAbs_VERTEX;
242 myEditCurrentArgument = 0;
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);
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);
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);
265 initSpinBox(GroupOnCurve->SpinBox_DX, 0., 1., step, "parametric_precision");
266 GroupOnCurve->SpinBox_DX->setValue(0.5);
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);
273 /* signals and slots connections */
274 connect(myGeomGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
275 connect(myGeomGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
277 connect(buttonOk(), SIGNAL(clicked()), this, SLOT(ClickOnOk()));
278 connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
280 connect(this, SIGNAL(constructorsClicked(int)), this, SLOT(ConstructorsClicked(int)));
282 connect(myParamCoord, SIGNAL(buttonClicked(int)), this, SLOT(ClickParamCoord(int)));
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()));
290 connect(myBtnPopup, SIGNAL(triggered(QAction*)), this, SLOT(onBtnPopup(QAction*)));
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)));
302 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), this, SLOT(SetDoubleSpinBoxStep(double)));
304 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
305 this, SLOT(SelectionIntoArgument()));
307 initName(tr("GEOM_VERTEX"));
309 ConstructorsClicked(0);
312 //=================================================================================
313 // function : SetDoubleSpinBoxStep()
314 // purpose : Double spin box management
315 //=================================================================================
316 void BasicGUI_PointDlg::SetDoubleSpinBoxStep(double step)
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);
328 //=================================================================================
329 // function : ConstructorsClicked()
330 // purpose : Radio button management
331 //=================================================================================
332 void BasicGUI_PointDlg::ConstructorsClicked(int constructorId)
334 switch (constructorId) {
337 globalSelection(); // close local contexts, if any
338 myNeedType = TopAbs_VERTEX;
339 localSelection(GEOM::GEOM_Object::_nil(), myNeedType);
341 GroupRefPoint->hide();
342 GroupOnCurve->hide();
343 GroupLineIntersection->hide();
344 GroupOnSurface->hide();
346 myParamGroup->hide();
352 globalSelection(); // close local contexts, if any
353 myNeedType = TopAbs_VERTEX;
354 localSelection(GEOM::GEOM_Object::_nil(), myNeedType);
356 myEditCurrentArgument = GroupRefPoint->LineEdit1;
357 myEditCurrentArgument->setText("");
358 myRefPoint.nullify();
359 GroupRefPoint->PushButton1->setDown(true);
360 myParamGroup->hide();
362 GroupOnCurve->hide();
363 GroupLineIntersection->hide();
364 GroupOnSurface->hide();
365 GroupRefPoint->show();
369 case GEOM_POINT_EDGE:
371 globalSelection(); // close local contexts, if any
372 myNeedType = TopAbs_EDGE;
373 localSelection(GEOM::GEOM_Object::_nil(), myNeedType);
375 myEditCurrentArgument = GroupOnCurve->LineEdit1;
376 myEditCurrentArgument->setText("");
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();
388 updateParamCoord(false);
391 case GEOM_POINT_INTINT:
393 globalSelection(); // close local contexts, if any
394 myNeedType = TopAbs_EDGE;
395 localSelection(GEOM::GEOM_Object::_nil(), myNeedType);
397 myEditCurrentArgument = GroupLineIntersection->LineEdit1;
398 GroupLineIntersection->LineEdit1->setText("");
399 GroupLineIntersection->LineEdit2->setText("");
400 GroupLineIntersection->LineEdit1->setEnabled(true);
401 GroupLineIntersection->LineEdit2->setEnabled(false);
404 GroupLineIntersection->PushButton1->setDown(true);
405 GroupLineIntersection->PushButton2->setDown(false);
406 myParamGroup->hide();
408 GroupRefPoint->hide();
409 GroupOnCurve->hide();
410 GroupOnSurface->hide();
412 GroupLineIntersection->show();
415 case GEOM_POINT_SURF:
417 globalSelection(); // close local contexts, if any
418 myNeedType = TopAbs_FACE;
419 localSelection(GEOM::GEOM_Object::_nil(), myNeedType);
421 myEditCurrentArgument = GroupOnSurface->LineEdit1;
422 myEditCurrentArgument->setText("");
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();
433 updateParamCoord(false);
442 QTimer::singleShot(50, this, SLOT(updateSize()));
444 SelectionIntoArgument();
447 //=================================================================================
448 // function : ClickOnOk()
450 //=================================================================================
451 void BasicGUI_PointDlg::ClickOnOk()
453 setIsApplyAndClose(true);
458 //=================================================================================
459 // function : ClickOnApply()
461 //=================================================================================
462 bool BasicGUI_PointDlg::ClickOnApply()
468 ConstructorsClicked(getConstructorId());
473 //=================================================================================
474 // function : SelectionIntoArgument()
475 // purpose : Called when selection as changed (for constructors not using local context)
476 //=================================================================================
477 void BasicGUI_PointDlg::SelectionIntoArgument()
480 const int id = getConstructorId();
482 if ((id == GEOM_POINT_REF || id == GEOM_POINT_EDGE || id == GEOM_POINT_SURF)
483 && myEditCurrentArgument != 0)
485 myEditCurrentArgument->setText("");
490 if (myEditCurrentArgument == GroupOnCurve->LineEdit1)
492 else if (myEditCurrentArgument == GroupOnCurve->LineEdit2)
493 myRefPoint.nullify();
495 else if (id == GEOM_POINT_INTINT) {
496 myEditCurrentArgument->setText("");
497 if (myEditCurrentArgument == GroupLineIntersection->LineEdit1)
499 else if (myEditCurrentArgument == GroupLineIntersection->LineEdit2)
503 GEOM::GeomObjPtr aSelectedObject = getSelected(myNeedType);
505 if (aSelectedObject && GEOMBase::GetShape(aSelectedObject.get(), aShape) && !aShape.IsNull()) {
506 QString aName = GEOMBase::GetName(aSelectedObject.get());
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());
514 else if (id == GEOM_POINT_REF) {
515 myRefPoint = aSelectedObject;
516 GroupRefPoint->LineEdit1->setText(aName);
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();
526 else if (myEditCurrentArgument == GroupOnCurve->LineEdit2) {
527 myRefPoint = aSelectedObject;
528 if (myRefPoint && !myEdge) {
529 GroupOnCurve->PushButton1->click();
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);
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);
554 else if (id == GEOM_POINT_SURF) {
555 myFace = aSelectedObject;
556 GroupOnSurface->LineEdit1->setText(aName);
561 displayPreview(true);
565 //=================================================================================
566 // function : SetEditCurrentArgument()
568 //=================================================================================
569 void BasicGUI_PointDlg::SetEditCurrentArgument()
571 QPushButton* send = (QPushButton*)sender();
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);
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);
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);
599 else if (send == GroupOnSurface->PushButton1)
601 GroupOnSurface->LineEdit1->setFocus();
602 myEditCurrentArgument = GroupOnSurface->LineEdit1;
603 globalSelection(); // close local contexts, if any
604 localSelection(GEOM::GEOM_Object::_nil(), TopAbs_FACE);
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);
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);
622 if ((send == GroupLineIntersection->PushButton1 ||
623 send == GroupLineIntersection->PushButton2) && !myBusy)
624 SelectionIntoArgument();
628 //=================================================================================
629 // function : enterEvent()
630 // purpose : to reactivate this dialog box when mouse enter onto the window
631 //=================================================================================
632 void BasicGUI_PointDlg::enterEvent(QEvent*)
634 if (!mainFrame()->GroupConstructors->isEnabled())
635 ActivateThisDialog();
639 //=================================================================================
640 // function : ActivateThisDialog()
642 //=================================================================================
643 void BasicGUI_PointDlg::ActivateThisDialog()
645 GEOMBase_Skeleton::ActivateThisDialog();
647 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
648 this, SLOT(SelectionIntoArgument()));
650 ConstructorsClicked(getConstructorId());
654 //=================================================================================
655 // function : DeactivateActiveDialog()
656 // purpose : public slot to deactivate if active
657 //=================================================================================
658 void BasicGUI_PointDlg::DeactivateActiveDialog()
660 // myGeomGUI->SetState(-1);
661 GEOMBase_Skeleton::DeactivateActiveDialog();
665 //=================================================================================
666 // function : ValueChangedInSpinBox()
668 //=================================================================================
669 void BasicGUI_PointDlg::ValueChangedInSpinBox(double newValue)
671 displayPreview(true);
674 //=================================================================================
675 // function : CheckBoxClicked()
676 // purpose : Check Boxes Management
677 //=================================================================================
678 void BasicGUI_PointDlg::CheckBoxClicked(int State)
680 displayPreview(true);
684 //=================================================================================
685 // funcion : getParameter()
687 //=================================================================================
688 double BasicGUI_PointDlg::getParameter() const
690 return GroupOnCurve->SpinBox_DX->value();
694 //=================================================================================
695 // funcion : getUParameter()
697 //=================================================================================
698 double BasicGUI_PointDlg::getUParameter() const
700 return GroupOnSurface->SpinBox_DX->value();
704 //=================================================================================
705 // funcion : getVParameter()
707 //=================================================================================
708 double BasicGUI_PointDlg::getVParameter() const
710 return GroupOnSurface->SpinBox_DY->value();
714 //=================================================================================
715 // function : OnPointSelected
717 //=================================================================================
718 void BasicGUI_PointDlg::OnPointSelected(const gp_Pnt& thePnt)
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());
725 displayPreview(true);
729 //=================================================================================
730 // function : createOperation
732 //=================================================================================
733 GEOM::GEOM_IOperations_ptr BasicGUI_PointDlg::createOperation()
735 return myGeomGUI->GetGeomGen()->GetIBasicOperations(getStudyId());
738 //=================================================================================
739 // function : isValid
741 //=================================================================================
742 bool BasicGUI_PointDlg::isValid(QString& msg)
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());
752 ok = GroupRefPoint->SpinBox_DX->isValid(msg, !IsPreview()) &&
753 GroupRefPoint->SpinBox_DY->isValid(msg, !IsPreview()) &&
754 GroupRefPoint->SpinBox_DZ->isValid(msg, !IsPreview()) &&
757 case GEOM_POINT_EDGE:
758 if (myParamCoord->checkedId() == PARAM_VALUE || myParamCoord->checkedId() == LENGTH_VALUE)
759 ok = GroupOnCurve->SpinBox_DX->isValid(msg, !IsPreview());
761 ok = GroupXYZ->SpinBox_DX->isValid(msg, !IsPreview()) &&
762 GroupXYZ->SpinBox_DY->isValid(msg, !IsPreview()) &&
763 GroupXYZ->SpinBox_DZ->isValid(msg, !IsPreview());
766 case GEOM_POINT_INTINT:
767 ok = myLine1 && myLine2;
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());
774 ok = GroupXYZ->SpinBox_DX->isValid(msg, !IsPreview()) &&
775 GroupXYZ->SpinBox_DY->isValid(msg, !IsPreview()) &&
776 GroupXYZ->SpinBox_DZ->isValid(msg, !IsPreview());
785 //=================================================================================
786 // function : execute
788 //=================================================================================
789 bool BasicGUI_PointDlg::execute(ObjectList& objects)
793 GEOM::GEOM_Object_var anObj;
794 QStringList aParameters;
796 GEOM::GEOM_IBasicOperations_var anOper = GEOM::GEOM_IBasicOperations::_narrow(getOperation());
798 switch (getConstructorId()) {
799 case GEOM_POINT_XYZ :
801 double x = GroupXYZ->SpinBox_DX->value();
802 double y = GroupXYZ->SpinBox_DY->value();
803 double z = GroupXYZ->SpinBox_DZ->value();
805 aParameters << GroupXYZ->SpinBox_DX->text();
806 aParameters << GroupXYZ->SpinBox_DY->text();
807 aParameters << GroupXYZ->SpinBox_DZ->text();
809 anObj = anOper->MakePointXYZ(x, y, z);
813 case GEOM_POINT_REF :
815 double dx = GroupRefPoint->SpinBox_DX->value();
816 double dy = GroupRefPoint->SpinBox_DY->value();
817 double dz = GroupRefPoint->SpinBox_DZ->value();
819 aParameters << GroupRefPoint->SpinBox_DX->text();
820 aParameters << GroupRefPoint->SpinBox_DY->text();
821 aParameters << GroupRefPoint->SpinBox_DZ->text();
823 anObj = anOper->MakePointWithReference(myRefPoint.get(), dx, dy, dz);
827 case GEOM_POINT_EDGE :
829 if (myParamCoord->checkedId() == PARAM_VALUE) {
830 anObj = anOper->MakePointOnCurve(myEdge.get(), getParameter());
831 aParameters<<GroupOnCurve->SpinBox_DX->text();
833 else if (myParamCoord->checkedId() == LENGTH_VALUE) {
834 anObj = anOper->MakePointOnCurveByLength(myEdge.get(), getParameter(), myRefPoint.get());
835 aParameters<<GroupOnCurve->SpinBox_DX->text();
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();
842 aParameters << GroupXYZ->SpinBox_DX->text();
843 aParameters << GroupXYZ->SpinBox_DY->text();
844 aParameters << GroupXYZ->SpinBox_DZ->text();
846 anObj = anOper->MakePointOnCurveByCoord(myEdge.get(), x, y, z);
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"));
862 case GEOM_POINT_SURF :
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();
869 double x = GroupXYZ->SpinBox_DX->value();
870 double y = GroupXYZ->SpinBox_DY->value();
871 double z = GroupXYZ->SpinBox_DZ->value();
873 aParameters << GroupXYZ->SpinBox_DX->text();
874 aParameters << GroupXYZ->SpinBox_DY->text();
875 aParameters << GroupXYZ->SpinBox_DZ->text();
877 anObj = anOper->MakePointOnSurfaceByCoord(myFace.get(), x, y, z);
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());
892 if (id == GEOM_POINT_REF || id == GEOM_POINT_EDGE || id == GEOM_POINT_SURF) {
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));
910 if (!anObj->_is_nil()) {
911 objects.push_back(anObj._retn());
917 //=================================================================================
918 // function : addSubshapeToStudy
919 // purpose : virtual method to add new SubObjects if local selection
920 //=================================================================================
921 void BasicGUI_PointDlg::addSubshapesToStudy()
923 switch (getConstructorId()) {
925 GEOMBase::PublishSubObject(myRefPoint.get());
927 case GEOM_POINT_EDGE:
928 GEOMBase::PublishSubObject(myEdge.get());
930 case GEOM_POINT_INTINT:
931 GEOMBase::PublishSubObject(myLine1.get());
932 GEOMBase::PublishSubObject(myLine2.get());
934 case GEOM_POINT_SURF:
935 GEOMBase::PublishSubObject(myFace.get());
942 //=================================================================================
943 // function : ClickParamCoord()
945 //=================================================================================
946 void BasicGUI_PointDlg::ClickParamCoord(int id)
948 updateParamCoord(true);
949 displayPreview(true);
952 //=================================================================================
953 // function : updateParamCoord
955 //=================================================================================
956 void BasicGUI_PointDlg::updateParamCoord(bool theIsUpdate)
958 bool isParam = myParamCoord->checkedId() == PARAM_VALUE;
959 bool isLength = myParamCoord->checkedId() == LENGTH_VALUE;
961 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
962 double step = resMgr->doubleValue("Geometry", "SettingsGeomStep", 100);
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);
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"));
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"));
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);
989 GroupXYZ->setShown(!isParam && !isLength);
992 QTimer::singleShot(50, this, SLOT(updateSize()));
995 //=================================================================================
996 // function : onBtnPopup()
998 //=================================================================================
999 void BasicGUI_PointDlg::onBtnPopup(QAction* a)
1001 globalSelection(); // close local contexts, if any
1002 myNeedType = myActions[a] == SelectEdge ? TopAbs_EDGE : TopAbs_WIRE;
1003 localSelection(GEOM::GEOM_Object::_nil(), myNeedType);
1006 //=================================================================================
1007 // function : updateSize
1008 // purpose : adjust dialog size to minimum
1009 //=================================================================================
1010 void BasicGUI_PointDlg::updateSize()
1012 qApp->processEvents();
1014 resize(minimumSizeHint());