1 // Copyright (C) 2009-2013 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "MyBasicGUI_PointDlg.hxx"
22 #include <SUIT_ResourceMgr.h>
23 #include <SUIT_Session.h>
24 #include <SalomeApp_Application.h>
25 #include <LightApp_SelectionMgr.h>
27 #include "MyDlgRef.hxx"
30 #include <QApplication>
31 #include <QButtonGroup>
32 #include <QHBoxLayout>
34 #include <QRadioButton>
39 #include <TopoDS_Shape.hxx>
40 #include <TopAbs_ShapeEnum.hxx>
42 #include <BRep_Tool.hxx>
44 #include <TColStd_IndexedMapOfInteger.hxx>
45 #include <TopTools_IndexedMapOfShape.hxx>
48 #include <VTKViewer_ViewModel.h>
49 #include <SUIT_MessageBox.h>
50 #include <SUIT_OverrideCursor.h>
51 #include <SalomeApp_Tools.h>
52 #include <SalomeApp_Study.h>
54 #include "HEXABLOCKGUI_DocumentModel.hxx"
55 #include "HEXABLOCKGUI_DocumentSelectionModel.hxx"
56 #include "HEXABLOCKGUI_DocumentItem.hxx"
57 #include "HEXABLOCKGUI_SalomeTools.hxx"
58 #include "HEXABLOCKGUI.hxx"
59 #include "HEXABLOCKGUI_VtkDocumentGraphicView.hxx"
63 #define LENGTH_VALUE 2
65 #define GEOM_POINT_XYZ 0
66 #define GEOM_POINT_REF 1
67 #define GEOM_POINT_EDGE 2
68 #define GEOM_POINT_INTINT 3
69 #define GEOM_POINT_SURF 4
74 using namespace HEXABLOCK::GUI;
76 Q_DECLARE_METATYPE(HEXABLOCK::GUI::HexaTreeRole);
77 Q_DECLARE_METATYPE(TopAbs_ShapeEnum);
78 Q_DECLARE_METATYPE(TopoDS_Shape);
80 //=================================================================================
81 // class : MyBasicGUI_PointDlg()
82 // purpose : Constructs a MyBasicGUI_PointDlg which is a child of 'parent', with the
83 // name 'name' and widget flags set to 'f'.
84 // The dialog will by default be modeless, unless you set 'modal' to
85 // TRUE to construct a modal dialog.
86 //=================================================================================
87 MyBasicGUI_PointDlg::MyBasicGUI_PointDlg(QWidget* parent, Qt::WindowFlags fl)
88 : MyGEOMBase_Skeleton(parent, fl),
91 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
92 QPixmap image0 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_POINT")));
93 QPixmap image1 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_POINT_EDGE")));
94 QPixmap image2 (aResMgr->loadPixmap("GEOM", tr("ICON_SELECT")));
95 QPixmap image3 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_POINT_REF")));
96 QPixmap image4 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_POINT_LINES")));
97 QPixmap image5 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_POINT_FACE")));
98 QPixmap image6 (aResMgr->loadPixmap("GEOM", tr("ICO_LINE")));
99 QPixmap image7 (aResMgr->loadPixmap("GEOM", tr("ICO_WIRE")));
101 setWindowTitle( tr("Vertex Association") );
102 // setMinimumWidth(260);
103 // setMinimumHeight(400);
105 mainFrame()->GroupConstructors->setTitle(tr("GEOM_POINTS"));
106 mainFrame()->RadioButton1->setIcon(image0);
107 mainFrame()->RadioButton2->setIcon(image3);
108 mainFrame()->RadioButton3->setIcon(image1);
109 mainFrame()->RadioButton4->show();
110 mainFrame()->RadioButton4->setIcon(image4);
111 mainFrame()->RadioButton5->show();
112 mainFrame()->RadioButton5->setIcon(image5);
114 myParamGroup = new QGroupBox(centralWidget());
115 myParamCoord = new QButtonGroup(myParamGroup);
116 QHBoxLayout* boxLayout = new QHBoxLayout(myParamGroup);
117 boxLayout->setMargin(MARGIN); boxLayout->setSpacing(SPACING);
118 QRadioButton* btn = new QRadioButton(tr("By Param"), myParamGroup);
119 myParamCoord->addButton(btn, PARAM_VALUE);
120 boxLayout->addWidget(btn);
121 btn = new QRadioButton(tr("By Length"), myParamGroup);
122 myParamCoord->addButton(btn, LENGTH_VALUE);
123 boxLayout->addWidget(btn);
124 btn = new QRadioButton(tr("By Coords"), myParamGroup);
125 myParamCoord->addButton(btn, COORD_VALUE);
126 boxLayout->addWidget(btn);
127 myParamCoord->setExclusive(true);
128 myParamCoord->button(PARAM_VALUE)->setChecked(true);
130 GroupXYZ = new MyDlgRef_3Spin(centralWidget());
131 GroupXYZ->GroupBox1->setTitle(tr("GEOM_COORDINATES"));
132 GroupXYZ->TextLabel1->setText(tr("GEOM_X"));
133 GroupXYZ->TextLabel2->setText(tr("GEOM_Y"));
134 GroupXYZ->TextLabel3->setText(tr("GEOM_Z"));
135 coordsInputValue[GEOM_POINT_XYZ] = new QVector3D(0, 0, 0);
136 coordsInputValue[GEOM_POINT_EDGE] = new QVector3D(0, 0, 0);
137 coordsInputValue[GEOM_POINT_SURF] = new QVector3D(0, 0, 0);
139 GroupOnCurve = new MyDlgRef_2Sel1Spin(centralWidget());
140 GroupOnCurve->GroupBox1->setTitle(tr("GEOM_POINT_ON_EDGE"));
141 GroupOnCurve->TextLabel1->setText(tr("GEOM_EDGE"));
142 GroupOnCurve->TextLabel2->setText(tr("GEOM_START_POINT"));
143 GroupOnCurve->TextLabel3->setText(tr("GEOM_PARAMETER"));
144 paramInputValue[PARAM_VALUE] = 0.5;
145 paramInputValue[LENGTH_VALUE] = 0.5;
147 GroupOnSurface = new MyDlgRef_1Sel2Spin(centralWidget());
148 GroupOnSurface->GroupBox1->setTitle(tr("GEOM_POINT_ON_FACE"));
149 GroupOnSurface->TextLabel1->setText(tr("GEOM_FACE"));
150 GroupOnSurface->TextLabel2->setText(tr("GEOM_UPARAMETER"));
151 GroupOnSurface->TextLabel3->setText(tr("GEOM_VPARAMETER"));
153 GroupRefPoint = new MyDlgRef_1Sel3Spin(centralWidget());
154 GroupRefPoint->GroupBox1->setTitle(tr("GEOM_REF_POINT"));
155 GroupRefPoint->TextLabel1->setText(tr("GEOM_POINT"));
156 GroupRefPoint->TextLabel2->setText(tr("GEOM_DX"));
157 GroupRefPoint->TextLabel3->setText(tr("GEOM_DY"));
158 GroupRefPoint->TextLabel4->setText(tr("GEOM_DZ"));
160 /* popup menu for line intersect buttons */
161 QIcon ico_line = QIcon(image6);
162 QIcon ico_wire = QIcon(image7);
164 myBtnPopup = new QMenu(this);
165 action_line1_edge = myBtnPopup->addAction(ico_line, tr("GEOM_EDGE"));
166 action_line1_wire = myBtnPopup->addAction(ico_wire, tr("GEOM_WIRE"));
169 myBtnPopup2 = new QMenu(this);
170 action_line2_edge = myBtnPopup2->addAction(ico_line, tr("GEOM_EDGE"));
171 action_line2_wire = myBtnPopup2->addAction(ico_wire, tr("GEOM_WIRE"));
173 GroupLineIntersection = new MyDlgRef_2Sel(centralWidget());
174 GroupLineIntersection->GroupBox1->setTitle(tr("GEOM_LINE_INTERSECTION"));
175 GroupLineIntersection->TextLabel1->setText(tr("GEOM_LINE1"));
176 GroupLineIntersection->TextLabel2->setText(tr("GEOM_LINE2"));
177 GroupLineIntersection->PushButton1->setIcon(image2);
178 GroupLineIntersection->PushButton1->setMenu(myBtnPopup);
179 GroupLineIntersection->PushButton2->setIcon(image2);
180 GroupLineIntersection->PushButton2->setMenu(myBtnPopup2);
182 myCoordGrp = new QGroupBox(tr("GEOM_COORDINATES_RES"), centralWidget());
183 QGridLayout* myCoordGrpLayout = new QGridLayout(myCoordGrp);
184 myCoordGrpLayout->addWidget(new QLabel(tr("GEOM_X"), myCoordGrp), 0, 0);
185 myX = new QLineEdit(myCoordGrp);
186 myCoordGrpLayout->addWidget(myX, 0, 1);
187 myCoordGrpLayout->addWidget(new QLabel(tr("GEOM_Y"), myCoordGrp), 1, 0);
188 myY = new QLineEdit(myCoordGrp);
189 myCoordGrpLayout->addWidget(myY, 1, 1);
190 myCoordGrpLayout->addWidget(new QLabel(tr("GEOM_Z"), myCoordGrp), 2, 0);
191 myZ = new QLineEdit(myCoordGrp);
192 myCoordGrpLayout->addWidget(myZ, 2, 1);
194 QVBoxLayout* layout = new QVBoxLayout(centralWidget());
195 layout->setMargin(0); layout->setSpacing(6);
196 layout->addWidget(myParamGroup);
197 layout->addWidget(GroupXYZ);
198 layout->addWidget(GroupOnCurve);
199 layout->addWidget(GroupOnSurface);
200 layout->addWidget(GroupRefPoint);
201 layout->addWidget(GroupLineIntersection);
202 layout->addWidget(myCoordGrp);
204 myX->setReadOnly(true);
205 myY->setReadOnly(true);
206 myZ->setReadOnly(true);
208 myX->setEnabled(false);
209 myY->setEnabled(false);
210 myZ->setEnabled(false);
212 QPalette aPal = myX->palette();
213 aPal.setColor(QPalette::Disabled, QPalette::Text, QColor(0, 0, 0));
214 myX->setPalette(aPal);
215 myY->setPalette(aPal);
216 myZ->setPalette(aPal);
218 _helpFileName = "gui_asso_quad_to_geom.html#associate-to-a-vertex-of-the-geometry";
219 _initWidget( _editMode );
220 mainFrame()->RadioButton1->click();
223 //=================================================================================
224 // function : ~MyBasicGUI_PointDlg()
225 // purpose : Destructor
226 //=================================================================================
227 MyBasicGUI_PointDlg::~MyBasicGUI_PointDlg()
231 void MyBasicGUI_PointDlg::_initInputWidget( HexaBaseDialog::Mode editmode )
233 // *** Init input widgets ***/
234 initSpinBox(GroupXYZ->SpinBox_DX, COORD_MIN, COORD_MAX);
235 initSpinBox(GroupXYZ->SpinBox_DY, COORD_MIN, COORD_MAX);
236 initSpinBox(GroupXYZ->SpinBox_DZ, COORD_MIN, COORD_MAX);
237 GroupXYZ->SpinBox_DX->setValue(0.0);
238 GroupXYZ->SpinBox_DY->setValue(0.0);
239 GroupXYZ->SpinBox_DZ->setValue(0.0);
241 initSpinBox(GroupRefPoint->SpinBox_DX, COORD_MIN, COORD_MAX);
242 initSpinBox(GroupRefPoint->SpinBox_DY, COORD_MIN, COORD_MAX);
243 initSpinBox(GroupRefPoint->SpinBox_DZ, COORD_MIN, COORD_MAX);
244 GroupRefPoint->SpinBox_DX->setValue(0.0);
245 GroupRefPoint->SpinBox_DY->setValue(0.0);
246 GroupRefPoint->SpinBox_DZ->setValue(0.0);
248 initSpinBox(GroupOnCurve->SpinBox_DX, 0., 1.);
249 GroupOnCurve->SpinBox_DX->setValue(paramInputValue[PARAM_VALUE]);
251 initSpinBox(GroupOnSurface->SpinBox_DX, 0., 1.);
252 GroupOnSurface->SpinBox_DX->setValue(0.5);
253 initSpinBox(GroupOnSurface->SpinBox_DY, 0., 1.);
254 GroupOnSurface->SpinBox_DY->setValue(0.5);
256 // * vtk input widget
257 mainFrame()->_vertex_le->setReadOnly(true);
258 mainFrame()->_vertex_le->setProperty( "HexaWidgetType", QVariant::fromValue(HEXABLOCK::GUI::VERTEX_TREE) );
259 mainFrame()->_vertex_le->installEventFilter(this);
261 // * geom input widgets
263 GroupRefPoint->LineEdit1->setReadOnly(true);
264 GroupRefPoint->LineEdit1->setProperty( "HexaWidgetType", QVariant::fromValue(GEOMPOINT_TREE) );
265 GroupRefPoint->LineEdit1->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_VERTEX) );
266 GroupRefPoint->LineEdit1->installEventFilter(this);
270 GroupOnCurve->LineEdit1->setReadOnly(true);
271 GroupOnCurve->LineEdit1->setProperty( "HexaWidgetType", QVariant::fromValue(GEOMEDGE_TREE) );
272 GroupOnCurve->LineEdit1->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_EDGE) );
273 GroupOnCurve->LineEdit1->installEventFilter(this);
276 GroupOnCurve->LineEdit2->setReadOnly(true);
277 GroupOnCurve->LineEdit2->setProperty( "HexaWidgetType", QVariant::fromValue(GEOMPOINT_TREE) );
278 GroupOnCurve->LineEdit2->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_VERTEX) );
279 GroupOnCurve->LineEdit2->installEventFilter(this);
281 // point of 2 lines intersection
283 GroupLineIntersection->LineEdit1->setReadOnly(true);
284 GroupLineIntersection->LineEdit1->setProperty( "HexaWidgetType", QVariant::fromValue(GEOMEDGE_TREE) );
285 GroupLineIntersection->LineEdit1->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_EDGE) );
286 GroupLineIntersection->LineEdit1->installEventFilter(this);
289 GroupLineIntersection->LineEdit2->setReadOnly(true);
290 GroupLineIntersection->LineEdit2->setProperty( "HexaWidgetType", QVariant::fromValue(GEOMEDGE_TREE) );
291 GroupLineIntersection->LineEdit2->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_EDGE) );
292 GroupLineIntersection->LineEdit2->installEventFilter(this);
295 GroupOnSurface->LineEdit1->setReadOnly(true);
296 GroupOnSurface->LineEdit1->setProperty( "HexaWidgetType", QVariant::fromValue(GEOMFACE_TREE) );
297 GroupOnSurface->LineEdit1->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_FACE) );
298 GroupOnSurface->LineEdit1->installEventFilter(this);
301 connect(this, SIGNAL(constructorsClicked(int)), this, SLOT(ConstructorsClicked(int)));
302 connect(myParamCoord, SIGNAL(buttonClicked(int)), this, SLOT(ClickParamCoord(int)));
303 connect(myBtnPopup, SIGNAL(triggered(QAction*)), this, SLOT(onBtnPopup(QAction*)));
304 connect(myBtnPopup2, SIGNAL(triggered(QAction*)), this, SLOT(onBtnPopup(QAction*)));
307 connect(GroupRefPoint->LineEdit1, SIGNAL( textChanged(const QString&) ), this, SLOT(onUpdateResults(const QString&)));
310 connect(GroupOnCurve->LineEdit1, SIGNAL( textChanged(const QString&) ), this, SLOT(onUpdateResults(const QString&)));
311 connect(GroupOnCurve->LineEdit2, SIGNAL( textChanged(const QString&) ), this, SLOT(onUpdateResults(const QString&)));
313 connect(GroupOnCurve->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(onParamValueChanged(double)));
314 connect(GroupOnCurve->SpinBox_DX, SIGNAL(valueChanged(const QString&)), this, SLOT(onUpdateResults(const QString&)));
316 // intersection point
317 connect(GroupLineIntersection->LineEdit1, SIGNAL( textChanged(const QString&) ), this, SLOT(onUpdateResults(const QString&)));
318 connect(GroupLineIntersection->LineEdit2, SIGNAL( textChanged(const QString&) ), this, SLOT(onUpdateResults(const QString&)));
321 connect(GroupOnSurface->SpinBox_DX, SIGNAL(valueChanged(const QString&)), this, SLOT(onUpdateResults(const QString&)));
322 connect(GroupOnSurface->SpinBox_DY, SIGNAL(valueChanged(const QString&)), this, SLOT(onUpdateResults(const QString&)));
323 connect(GroupOnSurface->LineEdit1, SIGNAL( textChanged(const QString&) ), this, SLOT(onUpdateResults(const QString&))); //surface: Face
326 connect(GroupXYZ->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(onXCoordChanged(double)));
327 connect(GroupXYZ->SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(onYCoordChanged(double)));
328 connect(GroupXYZ->SpinBox_DZ, SIGNAL(valueChanged(double)), this, SLOT(onZCoordChanged(double)));
330 connect(GroupXYZ->SpinBox_DX, SIGNAL(valueChanged(const QString&)), this, SLOT(onUpdateResults(const QString&)));
331 connect(GroupXYZ->SpinBox_DY, SIGNAL(valueChanged(const QString&)), this, SLOT(onUpdateResults(const QString&)));
332 connect(GroupXYZ->SpinBox_DZ, SIGNAL(valueChanged(const QString&)), this, SLOT(onUpdateResults(const QString&)));
335 connect(GroupRefPoint->SpinBox_DX, SIGNAL(valueChanged(const QString&)), this, SLOT(onUpdateResults(const QString&)));
336 connect(GroupRefPoint->SpinBox_DY, SIGNAL(valueChanged(const QString&)), this, SLOT(onUpdateResults(const QString&)));
337 connect(GroupRefPoint->SpinBox_DZ, SIGNAL(valueChanged(const QString&)), this, SLOT(onUpdateResults(const QString&)));
340 connect( mainFrame()->RadioButton1, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
341 connect( mainFrame()->RadioButton2, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
342 connect( mainFrame()->RadioButton3, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
343 connect( mainFrame()->RadioButton4, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
344 connect( mainFrame()->RadioButton5, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
346 connect( mainFrame()->RadioButton1, SIGNAL(clicked()), this, SLOT( refreshHighlight()) );
347 connect( mainFrame()->RadioButton2, SIGNAL(clicked()), this, SLOT(refreshHighlight()) );
348 connect( mainFrame()->RadioButton1, SIGNAL(clicked()), this, SLOT( refreshHighlight()) );
349 connect( mainFrame()->RadioButton2, SIGNAL(clicked()), this, SLOT(refreshHighlight()) );
350 connect( mainFrame()->RadioButton1, SIGNAL(clicked()), this, SLOT( refreshHighlight()) );
352 connect( myParamCoord->button(PARAM_VALUE), SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
353 connect( myParamCoord->button(LENGTH_VALUE), SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
354 connect( myParamCoord->button(COORD_VALUE), SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
358 void MyBasicGUI_PointDlg::showEvent ( QShowEvent * event )
360 HexaBaseDialog::showEvent(event);
361 if (getConstructorId() == GEOM_POINT_XYZ)
362 HEXABLOCKGUI::currentOccGView->setSelectionMode(TopAbs_VERTEX);
364 //===============================================================
365 // function : updateHelpFileName()
366 // purpose : update the help file according to the current panel
367 //===============================================================
368 void MyBasicGUI_PointDlg::updateHelpFileName()
370 if ( sender() == mainFrame()->RadioButton1 ){
371 _helpFileName = "gui_asso_quad_to_geom.html#associate-to-a-vertex-of-the-geometry";
372 } else if ( sender() == mainFrame()->RadioButton2 ){
373 _helpFileName = "gui_asso_vertex_to_geom.html#by-a-reference";
374 } else if ( sender() == mainFrame()->RadioButton3 ){
375 _helpFileName = "gui_asso_vertex_to_geom.html#by-an-edge-and-a-parameter";
376 } else if ( sender() == mainFrame()->RadioButton4 ){
377 _helpFileName = "gui_asso_vertex_to_geom.html#by-intersection-of-two-lines-or-wires";
378 } else if ( sender() == mainFrame()->RadioButton5 ){
379 _helpFileName = "gui_asso_vertex_to_geom.html#by-a-face-and-two-parameters";
380 } else if (sender() == myParamCoord->button(PARAM_VALUE)){
381 if (mainFrame()->RadioButton3->isChecked()){
382 _helpFileName = "gui_asso_vertex_to_geom.html#by-an-edge-and-a-parameter";
383 } else if (mainFrame()->RadioButton5->isChecked()){
384 _helpFileName = "gui_asso_vertex_to_geom.html#by-a-face-and-two-parameters";
386 } else if (sender() == myParamCoord->button(LENGTH_VALUE)){
387 _helpFileName = "gui_asso_vertex_to_geom.html#by-an-edge-and-a-length";
388 } else if (sender() == myParamCoord->button(COORD_VALUE)){
389 if (mainFrame()->RadioButton3->isChecked()){
390 _helpFileName = "gui_asso_vertex_to_geom.html#by-an-edge-and-coordinates";
391 } else if (mainFrame()->RadioButton5->isChecked()){
392 _helpFileName = "gui_asso_vertex_to_geom.html#by-a-face-and-coordinates";
397 //=================================================================================
398 // function : SetDoubleSpinBoxStep()
399 // purpose : Double spin box management
400 //=================================================================================
401 void MyBasicGUI_PointDlg::SetDoubleSpinBoxStep(double step)
403 GroupOnCurve->SpinBox_DX->setSingleStep(step);
404 GroupXYZ->SpinBox_DX->setSingleStep(step);
405 GroupXYZ->SpinBox_DY->setSingleStep(step);
406 GroupXYZ->SpinBox_DZ->setSingleStep(step);
407 GroupRefPoint->SpinBox_DX->setSingleStep(step);
408 GroupRefPoint->SpinBox_DY->setSingleStep(step);
409 GroupRefPoint->SpinBox_DZ->setSingleStep(step);
413 //=================================================================================
414 // function : ConstructorsClicked()
415 // purpose : Radio button management
416 //=================================================================================
417 void MyBasicGUI_PointDlg::ConstructorsClicked(int constructorId)
422 switch (constructorId) {
425 HEXABLOCKGUI::currentOccGView->setSelectionMode(TopAbs_VERTEX);
426 GroupRefPoint->hide();
427 GroupOnCurve->hide();
428 GroupLineIntersection->hide();
429 GroupOnSurface->hide();
431 myParamGroup->hide();
437 myParamGroup->hide();
439 GroupOnCurve->hide();
440 GroupLineIntersection->hide();
441 GroupOnSurface->hide();
442 GroupRefPoint->show();
446 case GEOM_POINT_EDGE:
448 GroupRefPoint->hide();
449 GroupLineIntersection->hide();
450 GroupOnSurface->hide();
451 myParamGroup->show();
452 myParamCoord->button(LENGTH_VALUE)->show();
453 myParamCoord->button(PARAM_VALUE)->setChecked(true);
454 GroupOnCurve->show();
456 updateParamCoord(false);
459 case GEOM_POINT_INTINT:
461 myParamGroup->hide();
463 GroupRefPoint->hide();
464 GroupOnCurve->hide();
465 GroupOnSurface->hide();
467 GroupLineIntersection->show();
470 case GEOM_POINT_SURF:
472 GroupRefPoint->hide();
473 GroupOnCurve->hide();
474 GroupLineIntersection->hide();
475 myParamGroup->show();
476 myParamCoord->button(LENGTH_VALUE)->hide();
477 myParamCoord->button(PARAM_VALUE)->setChecked(true);
478 GroupOnSurface->show();
480 updateParamCoord(false);
485 updateInputs(constructorId);
488 //=================================================================================
489 // funcion : getParameter()
491 //=================================================================================
492 double MyBasicGUI_PointDlg::getParameter() const
494 return GroupOnCurve->SpinBox_DX->value();
497 //=================================================================================
498 // funcion : getUParameter()
500 //=================================================================================
501 double MyBasicGUI_PointDlg::getUParameter() const
503 return GroupOnSurface->SpinBox_DX->value();
506 //=================================================================================
507 // funcion : getVParameter()
509 //=================================================================================
510 double MyBasicGUI_PointDlg::getVParameter() const
512 return GroupOnSurface->SpinBox_DY->value();
515 void MyBasicGUI_PointDlg::onParamValueChanged(double newValue)
517 if (getConstructorId() == GEOM_POINT_EDGE)
518 paramInputValue[myParamCoord->checkedId()] = newValue;
521 // ============================================================== onSelectionChanged
523 * Puts elements selected in the model in the corresponding widget (list widget or line edit)
524 * of the current dialog box.
526 void MyBasicGUI_PointDlg::onSelectionChanged( const QItemSelection& sel, const QItemSelection& unsel )
528 QModelIndexList l = sel.indexes();
532 QModelIndex selected = l[0];
533 int selectedType = selected.data(HEXA_TREE_ROLE).toInt();
534 // fill the coordinates of the selected point
535 if ( getConstructorId() == GEOM_POINT_XYZ && selectedType == GEOMPOINT_TREE)
537 DocumentModel::GeomObj* geomObj = getGeomObj(selected);
541 DocumentModel* docModel = getDocumentModel();
542 QString objId = geomObj->shapeName + "," + geomObj->subId;
543 HEXA_NS::SubShape* ssh = docModel->getGeomPtr(objId);
546 TopoDS_Shape shape = ssh->getShape();
547 if (shape.IsNull() || shape.ShapeType() != TopAbs_VERTEX)
549 TopoDS_Vertex vertex = TopoDS::Vertex(shape);
550 gp_Pnt pnt = BRep_Tool::Pnt(vertex);
551 OnPointSelected(pnt);
555 QLineEdit* aLineEdit = NULL;
556 QListWidget* aListWidget = NULL;
558 // * put selection in the current line edit
559 aLineEdit = dynamic_cast<QLineEdit*>(_currentObj);
560 if ( aLineEdit != NULL )
562 _onSelectionChanged( sel, aLineEdit );
566 // * put selection in the current list widget
567 aListWidget = dynamic_cast<QListWidget*>(_currentObj);
569 _onSelectionChanged( sel, aListWidget );
573 bool MyBasicGUI_PointDlg::apply(QModelIndex& result)
575 PatternGeomSelectionModel* pgsm = getPatternGeomSelectionModel();
576 PatternDataSelectionModel* pdsm = getPatternDataSelectionModel();
577 PatternDataModel* pdm = getPatternDataModel();
578 DocumentModel* docModel = getDocumentModel();
580 // get the selected vertex in the vtk view
581 QVariant v = mainFrame()->_vertex_le->property("QModelIndex");
584 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE VERTEX ASSOCIATION" ) );
587 QModelIndex iVertex = pdm->mapToSource( v.value<QModelIndex>() );
589 // get the selected vertex in the geometry (occ view)
590 TopoDS_Vertex geomVertex = computeGeomVertex();
593 if (!iVertex.isValid() || geomVertex.IsNull())
595 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE VERTEX ASSOCIATION" ) );
600 gp_Pnt aPnt = BRep_Tool::Pnt(geomVertex);
601 if (!docModel->setVertexAssociation(iVertex, aPnt.X(), aPnt.Y(), aPnt.Z()))
603 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE VERTEX ASSOCIATION" ) );
607 // * update data in the occ view and the geom tree
608 HEXABLOCKGUI::currentOccGView->addVertexToCloud(geomVertex);
609 docModel->updateGeomTree();
611 // highlight associated items
612 QModelIndex iGeomVertex = docModel->getVertexAssociation(iVertex);
613 QModelIndexList list1, list2;
614 result = v.value<QModelIndex>();
616 list2 << iGeomVertex;
617 pdsm->highlightTreeItems(list1); // data tree
618 pgsm->highlightTreeItems(list2); // geom tree
620 _updateCurrentObject(NULL);
621 HEXABLOCKGUI::currentOccGView->setSelectionMode(TopAbs_VERTEX);
622 HEXABLOCKGUI::currentDocGView->highlight(list1); // vtk view
623 HEXABLOCKGUI::currentOccGView->highlight(list1); // occ view
629 void MyBasicGUI_PointDlg::onXCoordChanged(double newValue)
631 int constructorId = getConstructorId();
632 if (constructorId != GEOM_POINT_XYZ && constructorId != GEOM_POINT_EDGE &&
633 constructorId != GEOM_POINT_SURF)
635 coordsInputValue[constructorId]->setX(newValue);
638 void MyBasicGUI_PointDlg::onYCoordChanged(double newValue)
640 int constructorId = getConstructorId();
641 if (constructorId != GEOM_POINT_XYZ && constructorId != GEOM_POINT_EDGE &&
642 constructorId != GEOM_POINT_SURF)
644 coordsInputValue[constructorId]->setY(newValue);
647 void MyBasicGUI_PointDlg::onZCoordChanged(double newValue)
649 int constructorId = getConstructorId();
650 if (constructorId != GEOM_POINT_XYZ && constructorId != GEOM_POINT_EDGE &&
651 constructorId != GEOM_POINT_SURF)
653 coordsInputValue[constructorId]->setZ(newValue);
657 void MyBasicGUI_PointDlg::onUpdateResults(const QString& data)
659 if (getConstructorId() == GEOM_POINT_XYZ)
662 // * compute the geom vertex
663 TopoDS_Vertex vertex = computeGeomVertex(true);
673 gp_Pnt pnt = BRep_Tool::Pnt(vertex);
674 myX->setText(MyDlgRef::PrintDoubleValue(pnt.X(), 6));
675 myY->setText(MyDlgRef::PrintDoubleValue(pnt.Y(), 6));
676 myZ->setText(MyDlgRef::PrintDoubleValue(pnt.Z(), 6));
679 TopoDS_Vertex MyBasicGUI_PointDlg::computeGeomVertex(bool preview)
681 TopoDS_Vertex vertex;
682 int constructorId = getConstructorId();
684 //display an emply vertex to erase the current preview
685 HEXABLOCKGUI::currentOccGView->displayPreview(vertex);
688 switch (constructorId) {
690 vertex = computeGeomPointXYZ();
693 vertex = computeGeomPointRef();
695 case GEOM_POINT_EDGE:
696 vertex = computeGeomPointEdge();
698 case GEOM_POINT_INTINT:
699 vertex = computeGeomPointInt();
701 case GEOM_POINT_SURF:
702 vertex = computeGeomPointSurf();
708 // * display preview of computed point
710 HEXABLOCKGUI::currentOccGView->displayPreview(vertex);
715 TopoDS_Vertex MyBasicGUI_PointDlg::computeGeomPointXYZ()
717 TopoDS_Vertex vertex;
719 if (getConstructorId() != GEOM_POINT_XYZ)
723 double x = GroupXYZ->SpinBox_DX->value();
724 double y = GroupXYZ->SpinBox_DY->value();
725 double z = GroupXYZ->SpinBox_DZ->value();
727 // - compute the resulting vertex
728 vertex = makePoint(x, y, z);
733 TopoDS_Vertex MyBasicGUI_PointDlg::computeGeomPointRef()
735 TopoDS_Vertex vertex;
737 if (getConstructorId() != GEOM_POINT_REF)
740 // get parameters from widgets
741 double dx = GroupRefPoint->SpinBox_DX->value();
742 double dy = GroupRefPoint->SpinBox_DY->value();
743 double dz = GroupRefPoint->SpinBox_DZ->value();
745 QVariant v = GroupRefPoint->LineEdit1->property("TopoDS_Shape");
748 TopoDS_Shape shape = v.value<TopoDS_Shape>();
750 // compute the resulting point
751 vertex = makePointWithReference(shape, dx, dy, dz);
756 TopoDS_Vertex MyBasicGUI_PointDlg::computeGeomPointEdge()
758 TopoDS_Vertex vertex;
760 if (getConstructorId() != GEOM_POINT_EDGE)
763 // * get inputs values
766 QVariant v1 = GroupOnCurve->LineEdit1->property("TopoDS_Shape");
769 TopoDS_Shape edgeShape = v1.value<TopoDS_Shape>();
771 bool isParam = myParamCoord->checkedId() == PARAM_VALUE;
772 bool isLength = myParamCoord->checkedId() == LENGTH_VALUE;
773 bool isCoord = myParamCoord->checkedId() == COORD_VALUE;
777 double param = GroupOnCurve->SpinBox_DX->value();
779 // - compute the resulting vertex
780 vertex = makePointOnCurve(edgeShape, param);
784 // - the starting point
785 QVariant v2 = GroupOnCurve->LineEdit2->property("TopoDS_Shape");
788 TopoDS_Shape pointShape = v2.value<TopoDS_Shape>();
791 double length = GroupOnCurve->SpinBox_DX->value();
793 // - compute the resulting vertex
794 vertex = makePointOnCurveByLength(edgeShape, pointShape,length);
799 double x = GroupXYZ->SpinBox_DX->value();
800 double y = GroupXYZ->SpinBox_DY->value();
801 double z = GroupXYZ->SpinBox_DZ->value();
803 // - compute the resulting vertex
804 vertex = makePointOnCurveByCoord(edgeShape, x, y, z);
810 TopoDS_Vertex MyBasicGUI_PointDlg::computeGeomPointInt()
812 TopoDS_Vertex vertex;
814 if (getConstructorId() != GEOM_POINT_INTINT)
819 // * get inputs values
822 v = GroupLineIntersection->LineEdit1->property("TopoDS_Shape");
825 TopoDS_Shape line1 = v.value<TopoDS_Shape>();
828 v = GroupLineIntersection->LineEdit2->property("TopoDS_Shape");
831 TopoDS_Shape line2 = v.value<TopoDS_Shape>();
833 // * compute the resulting vertex
834 vertex = makePointOnLinesIntersection(line1, line2);
839 TopoDS_Vertex MyBasicGUI_PointDlg::computeGeomPointSurf()
841 TopoDS_Vertex vertex;
843 if (getConstructorId() != GEOM_POINT_SURF)
846 // * get inputs values
849 QVariant v = GroupOnSurface->LineEdit1->property("TopoDS_Shape");
852 TopoDS_Shape faceShape = v.value<TopoDS_Shape>();
854 bool isParam = myParamCoord->checkedId() == PARAM_VALUE;
855 bool isCoord = myParamCoord->checkedId() == COORD_VALUE;
859 double param_u = GroupOnSurface->SpinBox_DX->value();
860 double param_v = GroupOnSurface->SpinBox_DY->value();
862 // - compute the resulting vertex
863 vertex = makePointOnSurface(faceShape, param_u, param_v);
868 double x = GroupXYZ->SpinBox_DX->value();
869 double y = GroupXYZ->SpinBox_DY->value();
870 double z = GroupXYZ->SpinBox_DZ->value();
872 // - compute the resulting vertex
873 vertex = makePointOnSurfaceByCoord(faceShape, x, y, z);
879 //=================================================================================
880 // function : OnPointSelected
882 //=================================================================================
883 void MyBasicGUI_PointDlg::OnPointSelected(const gp_Pnt& thePnt)
885 if (getConstructorId() == GEOM_POINT_XYZ) {
886 GroupXYZ->SpinBox_DX->setValue(thePnt.X());
887 GroupXYZ->SpinBox_DY->setValue(thePnt.Y());
888 GroupXYZ->SpinBox_DZ->setValue(thePnt.Z());
892 void MyBasicGUI_PointDlg::updateInputs(const int constructorId)
895 QVector3D* coords = NULL;
897 switch (constructorId) {
898 case GEOM_POINT_XYZ :
899 coords = coordsInputValue[GEOM_POINT_XYZ];
903 case GEOM_POINT_EDGE:
904 coords = coordsInputValue[GEOM_POINT_EDGE];
905 updateParamCoord(true);
907 case GEOM_POINT_INTINT:
909 case GEOM_POINT_SURF:
910 coords = coordsInputValue[GEOM_POINT_SURF];
911 updateParamCoord(true);
919 GroupXYZ->SpinBox_DX->setValue(coords->x());
920 GroupXYZ->SpinBox_DY->setValue(coords->y());
921 GroupXYZ->SpinBox_DZ->setValue(coords->z());
924 onUpdateResults(str);
927 //=================================================================================
928 // function : ClickParamCoord()
930 //=================================================================================
931 void MyBasicGUI_PointDlg::ClickParamCoord(int id)
933 updateInputs(getConstructorId());
936 //=================================================================================
937 // function : updateParamCoord
939 //=================================================================================
940 void MyBasicGUI_PointDlg::updateParamCoord(bool theIsUpdate)
942 bool isParam = myParamCoord->checkedId() == PARAM_VALUE;
943 bool isLength = myParamCoord->checkedId() == LENGTH_VALUE;
945 const int id = getConstructorId();
946 if (id == GEOM_POINT_EDGE) {
947 GroupOnCurve->TextLabel2->setVisible(isLength);
948 GroupOnCurve->LineEdit2->setVisible(isLength);
949 GroupOnCurve->TextLabel3->setVisible(isParam || isLength);
950 GroupOnCurve->SpinBox_DX->setVisible(isParam || isLength);
952 GroupOnCurve->TextLabel3->setText(tr("GEOM_PARAMETER"));
953 double value = paramInputValue[PARAM_VALUE];
954 GroupOnCurve->SpinBox_DX->setValue(0.5);
955 initSpinBox(GroupOnCurve->SpinBox_DX, 0., 1.);
956 GroupOnCurve->SpinBox_DX->setValue(value);
959 GroupOnCurve->TextLabel3->setText(tr("GEOM_LENGTH"));
960 double value = paramInputValue[LENGTH_VALUE];
961 GroupOnCurve->SpinBox_DX->setValue(0.5);
962 initSpinBox(GroupOnCurve->SpinBox_DX, COORD_MIN, COORD_MAX);
963 GroupOnCurve->SpinBox_DX->setValue(value);
966 else if (id == GEOM_POINT_SURF) {
967 GroupOnSurface->TextLabel2->setShown(isParam);
968 GroupOnSurface->TextLabel3->setShown(isParam);
969 GroupOnSurface->SpinBox_DX->setShown(isParam);
970 GroupOnSurface->SpinBox_DY->setShown(isParam);
973 GroupXYZ->setShown(!isParam && !isLength);
976 //=================================================================================
977 // function : onBtnPopup()
979 //=================================================================================
980 void MyBasicGUI_PointDlg::onBtnPopup(QAction* a)
982 if (a == action_line1_edge)
984 GroupLineIntersection->LineEdit1->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_EDGE) );
985 GroupLineIntersection->LineEdit1->setFocus();
986 GroupLineIntersection->PushButton2->setDown(false);
988 else if (a == action_line1_wire)
990 GroupLineIntersection->LineEdit1->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_WIRE) );
991 GroupLineIntersection->LineEdit1->setFocus();
992 GroupLineIntersection->PushButton2->setDown(false);
994 else if (a == action_line2_edge)
996 GroupLineIntersection->LineEdit2->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_EDGE) );
997 GroupLineIntersection->LineEdit2->setFocus();
998 GroupLineIntersection->PushButton1->setDown(false);
1000 else if (a == action_line2_wire)
1002 GroupLineIntersection->LineEdit2->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_WIRE) );
1003 GroupLineIntersection->LineEdit2->setFocus();
1004 GroupLineIntersection->PushButton1->setDown(false);
1008 //=================================================================================
1009 // function : updateSize
1010 // purpose : adjust dialog size to minimum
1011 //=================================================================================
1012 void MyBasicGUI_PointDlg::updateSize()
1014 qApp->processEvents();
1016 resize(minimumSizeHint());
1019 void MyBasicGUI_PointDlg::clear()
1021 mainFrame()->_vertex_le->clear();
1022 modelUnregister(mainFrame()->_vertex_le);
1024 GroupRefPoint->LineEdit1->clear();
1025 GroupRefPoint->LineEdit1->setProperty("TopoDS_Shape", QVariant());
1026 GroupRefPoint->LineEdit1->setProperty("QModelIndex", QVariant());
1027 GroupRefPoint->LineEdit1->setProperty("HexaData", QVariant());
1029 GroupOnCurve->LineEdit1->clear();
1030 GroupOnCurve->LineEdit1->setProperty("TopoDS_Shape", QVariant());
1031 GroupOnCurve->LineEdit1->setProperty("QModelIndex", QVariant());
1032 GroupOnCurve->LineEdit1->setProperty("HexaData", QVariant());
1034 GroupOnCurve->LineEdit2->clear();
1035 GroupOnCurve->LineEdit2->setProperty("TopoDS_Shape", QVariant());
1036 GroupOnCurve->LineEdit2->setProperty("QModelIndex", QVariant());
1037 GroupOnCurve->LineEdit2->setProperty("HexaData", QVariant());
1039 GroupLineIntersection->LineEdit1->clear();
1040 GroupLineIntersection->LineEdit1->setProperty("TopoDS_Shape", QVariant());
1041 GroupLineIntersection->LineEdit1->setProperty("QModelIndex", QVariant());
1042 GroupLineIntersection->LineEdit1->setProperty("HexaData", QVariant());
1044 GroupLineIntersection->LineEdit2->clear();
1045 GroupLineIntersection->LineEdit2->setProperty("TopoDS_Shape", QVariant());
1046 GroupLineIntersection->LineEdit2->setProperty("QModelIndex", QVariant());
1047 GroupLineIntersection->LineEdit2->setProperty("HexaData", QVariant());
1049 GroupOnSurface->LineEdit1->clear();
1050 GroupOnSurface->LineEdit1->setProperty("TopoDS_Shape", QVariant());
1051 GroupOnSurface->LineEdit1->setProperty("QModelIndex", QVariant());
1052 GroupOnSurface->LineEdit1->setProperty("HexaData", QVariant());
1054 modelUnregister(this);
1058 void MyBasicGUI_PointDlg::onWindowActivated(SUIT_ViewManager* vm)
1060 QString vmType = vm->getType();
1061 if ( (vmType == SVTK_Viewer::Type()) || (vmType == VTKViewer_Viewer::Type()) ){
1062 mainFrame()->_vertex_le->setFocus();
1063 } else if ( vmType == OCCViewer_Viewer::Type() ){