1 // Copyright (C) 2009-2014 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, or (at your option) any later version.
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);
119 QRadioButton* btn = new QRadioButton(tr("By Param"), myParamGroup);
120 myParamCoord->addButton(btn, PARAM_VALUE);
121 boxLayout->addWidget(btn);
123 btn = new QRadioButton(tr("By Length"), myParamGroup);
124 myParamCoord->addButton(btn, LENGTH_VALUE);
125 boxLayout->addWidget(btn);
127 btn = new QRadioButton(tr("By Coords"), myParamGroup);
128 myParamCoord->addButton(btn, COORD_VALUE);
129 boxLayout->addWidget(btn);
131 myParamCoord->setExclusive(true);
132 myParamCoord->button(PARAM_VALUE)->setChecked(true);
134 GroupXYZ = new MyDlgRef_3Spin(centralWidget());
135 GroupXYZ->GroupBox1->setTitle(tr("GEOM_COORDINATES"));
136 GroupXYZ->TextLabel1->setText(tr("GEOM_X"));
137 GroupXYZ->TextLabel2->setText(tr("GEOM_Y"));
138 GroupXYZ->TextLabel3->setText(tr("GEOM_Z"));
139 coordsInputValue[GEOM_POINT_XYZ] = new QVector3D(0, 0, 0);
140 coordsInputValue[GEOM_POINT_EDGE] = new QVector3D(0, 0, 0);
141 coordsInputValue[GEOM_POINT_SURF] = new QVector3D(0, 0, 0);
143 GroupOnCurve = new MyDlgRef_2Sel1Spin(centralWidget());
144 GroupOnCurve->GroupBox1->setTitle(tr("GEOM_POINT_ON_EDGE"));
145 GroupOnCurve->TextLabel1->setText(tr("GEOM_EDGE"));
146 GroupOnCurve->TextLabel2->setText(tr("GEOM_START_POINT"));
147 GroupOnCurve->TextLabel3->setText(tr("GEOM_PARAMETER"));
148 paramInputValue[PARAM_VALUE] = 0.5;
149 paramInputValue[LENGTH_VALUE] = 0.5;
151 GroupOnSurface = new MyDlgRef_1Sel2Spin(centralWidget());
152 GroupOnSurface->GroupBox1->setTitle(tr("GEOM_POINT_ON_FACE"));
153 GroupOnSurface->TextLabel1->setText(tr("GEOM_FACE"));
154 GroupOnSurface->TextLabel2->setText(tr("GEOM_UPARAMETER"));
155 GroupOnSurface->TextLabel3->setText(tr("GEOM_VPARAMETER"));
157 GroupRefPoint = new MyDlgRef_1Sel3Spin(centralWidget());
158 GroupRefPoint->GroupBox1->setTitle(tr("GEOM_REF_POINT"));
159 GroupRefPoint->TextLabel1->setText(tr("GEOM_POINT"));
160 GroupRefPoint->TextLabel2->setText(tr("GEOM_DX"));
161 GroupRefPoint->TextLabel3->setText(tr("GEOM_DY"));
162 GroupRefPoint->TextLabel4->setText(tr("GEOM_DZ"));
164 /* popup menu for line intersect buttons */
165 QIcon ico_line = QIcon(image6);
166 QIcon ico_wire = QIcon(image7);
168 myBtnPopup = new QMenu(this);
169 action_line1_edge = myBtnPopup->addAction(ico_line, tr("GEOM_EDGE"));
170 action_line1_wire = myBtnPopup->addAction(ico_wire, tr("GEOM_WIRE"));
173 myBtnPopup2 = new QMenu(this);
174 action_line2_edge = myBtnPopup2->addAction(ico_line, tr("GEOM_EDGE"));
175 action_line2_wire = myBtnPopup2->addAction(ico_wire, tr("GEOM_WIRE"));
177 GroupLineIntersection = new MyDlgRef_2Sel(centralWidget());
178 GroupLineIntersection->GroupBox1->setTitle(tr("GEOM_LINE_INTERSECTION"));
179 GroupLineIntersection->TextLabel1->setText(tr("GEOM_LINE1"));
180 GroupLineIntersection->TextLabel2->setText(tr("GEOM_LINE2"));
181 GroupLineIntersection->PushButton1->setIcon(image2);
182 GroupLineIntersection->PushButton1->setMenu(myBtnPopup);
183 GroupLineIntersection->PushButton2->setIcon(image2);
184 GroupLineIntersection->PushButton2->setMenu(myBtnPopup2);
186 myCoordGrp = new QGroupBox(tr("GEOM_COORDINATES_RES"), centralWidget());
187 QGridLayout* myCoordGrpLayout = new QGridLayout(myCoordGrp);
188 myCoordGrpLayout->addWidget(new QLabel(tr("GEOM_X"), myCoordGrp), 0, 0);
189 myX = new QLineEdit(myCoordGrp);
190 myCoordGrpLayout->addWidget(myX, 0, 1);
191 myCoordGrpLayout->addWidget(new QLabel(tr("GEOM_Y"), myCoordGrp), 1, 0);
192 myY = new QLineEdit(myCoordGrp);
193 myCoordGrpLayout->addWidget(myY, 1, 1);
194 myCoordGrpLayout->addWidget(new QLabel(tr("GEOM_Z"), myCoordGrp), 2, 0);
195 myZ = new QLineEdit(myCoordGrp);
196 myCoordGrpLayout->addWidget(myZ, 2, 1);
198 QVBoxLayout* layout = new QVBoxLayout(centralWidget());
199 layout->setMargin(0); layout->setSpacing(6);
200 layout->addWidget(myParamGroup);
201 layout->addWidget(GroupXYZ);
202 layout->addWidget(GroupOnCurve);
203 layout->addWidget(GroupOnSurface);
204 layout->addWidget(GroupRefPoint);
205 layout->addWidget(GroupLineIntersection);
206 layout->addWidget(myCoordGrp);
208 myX->setReadOnly(true);
209 myY->setReadOnly(true);
210 myZ->setReadOnly(true);
212 myX->setEnabled(false);
213 myY->setEnabled(false);
214 myZ->setEnabled(false);
216 QPalette aPal = myX->palette();
217 aPal.setColor(QPalette::Disabled, QPalette::Text, QColor(0, 0, 0));
218 myX->setPalette(aPal);
219 myY->setPalette(aPal);
220 myZ->setPalette(aPal);
222 _helpFileName = "gui_asso_quad_to_geom.html#associate-to-a-vertex-of-the-geometry";
223 _initWidget( _editMode );
224 mainFrame()->RadioButton1->click();
227 //=================================================================================
228 // function : ~MyBasicGUI_PointDlg()
229 // purpose : Destructor
230 //=================================================================================
231 MyBasicGUI_PointDlg::~MyBasicGUI_PointDlg()
235 void MyBasicGUI_PointDlg::_initInputWidget( HexaBaseDialog::Mode editmode )
237 // *** Init input widgets ***/
238 initSpinBox(GroupXYZ->SpinBox_DX, COORD_MIN, COORD_MAX);
239 initSpinBox(GroupXYZ->SpinBox_DY, COORD_MIN, COORD_MAX);
240 initSpinBox(GroupXYZ->SpinBox_DZ, COORD_MIN, COORD_MAX);
241 GroupXYZ->SpinBox_DX->setValue(0.0);
242 GroupXYZ->SpinBox_DY->setValue(0.0);
243 GroupXYZ->SpinBox_DZ->setValue(0.0);
245 initSpinBox(GroupRefPoint->SpinBox_DX, COORD_MIN, COORD_MAX);
246 initSpinBox(GroupRefPoint->SpinBox_DY, COORD_MIN, COORD_MAX);
247 initSpinBox(GroupRefPoint->SpinBox_DZ, COORD_MIN, COORD_MAX);
248 GroupRefPoint->SpinBox_DX->setValue(0.0);
249 GroupRefPoint->SpinBox_DY->setValue(0.0);
250 GroupRefPoint->SpinBox_DZ->setValue(0.0);
252 initSpinBox(GroupOnCurve->SpinBox_DX, 0., 1.);
253 GroupOnCurve->SpinBox_DX->setValue(paramInputValue[PARAM_VALUE]);
255 initSpinBox(GroupOnSurface->SpinBox_DX, 0., 1.);
256 GroupOnSurface->SpinBox_DX->setValue(0.5);
257 initSpinBox(GroupOnSurface->SpinBox_DY, 0., 1.);
258 GroupOnSurface->SpinBox_DY->setValue(0.5);
260 // * vtk input widget
261 mainFrame()->_vertex_le->setReadOnly(true);
262 mainFrame()->_vertex_le->setProperty( "HexaWidgetType", QVariant::fromValue(HEXABLOCK::GUI::VERTEX_TREE) );
263 mainFrame()->_vertex_le->installEventFilter(this);
265 // * geom input widgets
267 GroupRefPoint->LineEdit1->setReadOnly(true);
268 GroupRefPoint->LineEdit1->setProperty( "HexaWidgetType", QVariant::fromValue(GEOMPOINT_TREE) );
269 GroupRefPoint->LineEdit1->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_VERTEX) );
270 GroupRefPoint->LineEdit1->installEventFilter(this);
274 GroupOnCurve->LineEdit1->setReadOnly(true);
275 GroupOnCurve->LineEdit1->setProperty( "HexaWidgetType", QVariant::fromValue(GEOMEDGE_TREE) );
276 GroupOnCurve->LineEdit1->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_EDGE) );
277 GroupOnCurve->LineEdit1->installEventFilter(this);
280 GroupOnCurve->LineEdit2->setReadOnly(true);
281 GroupOnCurve->LineEdit2->setProperty( "HexaWidgetType", QVariant::fromValue(GEOMPOINT_TREE) );
282 GroupOnCurve->LineEdit2->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_VERTEX) );
283 GroupOnCurve->LineEdit2->installEventFilter(this);
285 // point of 2 lines intersection
287 GroupLineIntersection->LineEdit1->setReadOnly(true);
288 GroupLineIntersection->LineEdit1->setProperty( "HexaWidgetType", QVariant::fromValue(GEOMEDGE_TREE) );
289 GroupLineIntersection->LineEdit1->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_EDGE) );
290 GroupLineIntersection->LineEdit1->installEventFilter(this);
293 GroupLineIntersection->LineEdit2->setReadOnly(true);
294 GroupLineIntersection->LineEdit2->setProperty( "HexaWidgetType", QVariant::fromValue(GEOMEDGE_TREE) );
295 GroupLineIntersection->LineEdit2->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_EDGE) );
296 GroupLineIntersection->LineEdit2->installEventFilter(this);
299 GroupOnSurface->LineEdit1->setReadOnly(true);
300 GroupOnSurface->LineEdit1->setProperty( "HexaWidgetType", QVariant::fromValue(GEOMFACE_TREE) );
301 GroupOnSurface->LineEdit1->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_FACE) );
302 GroupOnSurface->LineEdit1->installEventFilter(this);
305 connect(this, SIGNAL(constructorsClicked(int)), this, SLOT(ConstructorsClicked(int)));
306 connect(myParamCoord, SIGNAL(buttonClicked(int)), this, SLOT(ClickParamCoord(int)));
307 connect(myBtnPopup, SIGNAL(triggered(QAction*)), this, SLOT(onBtnPopup(QAction*)));
308 connect(myBtnPopup2, SIGNAL(triggered(QAction*)), this, SLOT(onBtnPopup(QAction*)));
311 connect(GroupRefPoint->LineEdit1, SIGNAL( textChanged(const QString&) ), this, SLOT(onUpdateResults(const QString&)));
314 connect(GroupOnCurve->LineEdit1, SIGNAL( textChanged(const QString&) ), this, SLOT(onUpdateResults(const QString&)));
315 connect(GroupOnCurve->LineEdit2, SIGNAL( textChanged(const QString&) ), this, SLOT(onUpdateResults(const QString&)));
317 connect(GroupOnCurve->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(onParamValueChanged(double)));
318 connect(GroupOnCurve->SpinBox_DX, SIGNAL(valueChanged(const QString&)), this, SLOT(onUpdateResults(const QString&)));
320 // intersection point
321 connect(GroupLineIntersection->LineEdit1, SIGNAL( textChanged(const QString&) ), this, SLOT(onUpdateResults(const QString&)));
322 connect(GroupLineIntersection->LineEdit2, SIGNAL( textChanged(const QString&) ), this, SLOT(onUpdateResults(const QString&)));
325 connect(GroupOnSurface->SpinBox_DX, SIGNAL(valueChanged(const QString&)), this, SLOT(onUpdateResults(const QString&)));
326 connect(GroupOnSurface->SpinBox_DY, SIGNAL(valueChanged(const QString&)), this, SLOT(onUpdateResults(const QString&)));
327 connect(GroupOnSurface->LineEdit1, SIGNAL( textChanged(const QString&) ), this, SLOT(onUpdateResults(const QString&))); //surface: Face
330 connect(GroupXYZ->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(onXCoordChanged(double)));
331 connect(GroupXYZ->SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(onYCoordChanged(double)));
332 connect(GroupXYZ->SpinBox_DZ, SIGNAL(valueChanged(double)), this, SLOT(onZCoordChanged(double)));
334 connect(GroupXYZ->SpinBox_DX, SIGNAL(valueChanged(const QString&)), this, SLOT(onUpdateResults(const QString&)));
335 connect(GroupXYZ->SpinBox_DY, SIGNAL(valueChanged(const QString&)), this, SLOT(onUpdateResults(const QString&)));
336 connect(GroupXYZ->SpinBox_DZ, SIGNAL(valueChanged(const QString&)), this, SLOT(onUpdateResults(const QString&)));
339 connect(GroupRefPoint->SpinBox_DX, SIGNAL(valueChanged(const QString&)), this, SLOT(onUpdateResults(const QString&)));
340 connect(GroupRefPoint->SpinBox_DY, SIGNAL(valueChanged(const QString&)), this, SLOT(onUpdateResults(const QString&)));
341 connect(GroupRefPoint->SpinBox_DZ, SIGNAL(valueChanged(const QString&)), this, SLOT(onUpdateResults(const QString&)));
344 connect( mainFrame()->RadioButton1, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
345 connect( mainFrame()->RadioButton2, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
346 connect( mainFrame()->RadioButton3, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
347 connect( mainFrame()->RadioButton4, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
348 connect( mainFrame()->RadioButton5, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
350 connect( mainFrame()->RadioButton1, SIGNAL(clicked()), this, SLOT( refreshHighlight()) );
351 connect( mainFrame()->RadioButton2, SIGNAL(clicked()), this, SLOT(refreshHighlight()) );
352 connect( mainFrame()->RadioButton1, SIGNAL(clicked()), this, SLOT( refreshHighlight()) );
353 connect( mainFrame()->RadioButton2, SIGNAL(clicked()), this, SLOT(refreshHighlight()) );
354 connect( mainFrame()->RadioButton1, SIGNAL(clicked()), this, SLOT( refreshHighlight()) );
356 connect( myParamCoord->button(PARAM_VALUE), SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
357 connect( myParamCoord->button(LENGTH_VALUE), SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
358 connect( myParamCoord->button(COORD_VALUE), SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
362 void MyBasicGUI_PointDlg::showEvent ( QShowEvent * event )
364 HexaBaseDialog::showEvent(event);
365 if (getConstructorId() == GEOM_POINT_XYZ)
366 HEXABLOCKGUI::currentOccGView->setSelectionMode(TopAbs_VERTEX);
368 //===============================================================
369 // function : updateHelpFileName()
370 // purpose : update the help file according to the current panel
371 //===============================================================
372 void MyBasicGUI_PointDlg::updateHelpFileName()
374 if ( sender() == mainFrame()->RadioButton1 ){
375 _helpFileName = "gui_asso_quad_to_geom.html#associate-to-a-vertex-of-the-geometry";
376 } else if ( sender() == mainFrame()->RadioButton2 ){
377 _helpFileName = "gui_asso_vertex_to_geom.html#by-a-reference";
378 } else if ( sender() == mainFrame()->RadioButton3 ){
379 _helpFileName = "gui_asso_vertex_to_geom.html#by-an-edge-and-a-parameter";
380 } else if ( sender() == mainFrame()->RadioButton4 ){
381 _helpFileName = "gui_asso_vertex_to_geom.html#by-intersection-of-two-lines-or-wires";
382 } else if ( sender() == mainFrame()->RadioButton5 ){
383 _helpFileName = "gui_asso_vertex_to_geom.html#by-a-face-and-two-parameters";
384 } else if (sender() == myParamCoord->button(PARAM_VALUE)){
385 if (mainFrame()->RadioButton3->isChecked()){
386 _helpFileName = "gui_asso_vertex_to_geom.html#by-an-edge-and-a-parameter";
387 } else if (mainFrame()->RadioButton5->isChecked()){
388 _helpFileName = "gui_asso_vertex_to_geom.html#by-a-face-and-two-parameters";
390 } else if (sender() == myParamCoord->button(LENGTH_VALUE)){
391 _helpFileName = "gui_asso_vertex_to_geom.html#by-an-edge-and-a-length";
392 } else if (sender() == myParamCoord->button(COORD_VALUE)){
393 if (mainFrame()->RadioButton3->isChecked()){
394 _helpFileName = "gui_asso_vertex_to_geom.html#by-an-edge-and-coordinates";
395 } else if (mainFrame()->RadioButton5->isChecked()){
396 _helpFileName = "gui_asso_vertex_to_geom.html#by-a-face-and-coordinates";
401 //=================================================================================
402 // function : SetDoubleSpinBoxStep()
403 // purpose : Double spin box management
404 //=================================================================================
405 void MyBasicGUI_PointDlg::SetDoubleSpinBoxStep(double step)
407 GroupOnCurve->SpinBox_DX->setSingleStep(step);
408 GroupXYZ->SpinBox_DX->setSingleStep(step);
409 GroupXYZ->SpinBox_DY->setSingleStep(step);
410 GroupXYZ->SpinBox_DZ->setSingleStep(step);
411 GroupRefPoint->SpinBox_DX->setSingleStep(step);
412 GroupRefPoint->SpinBox_DY->setSingleStep(step);
413 GroupRefPoint->SpinBox_DZ->setSingleStep(step);
417 //=================================================================================
418 // function : ConstructorsClicked()
419 // purpose : Radio button management
420 //=================================================================================
421 void MyBasicGUI_PointDlg::ConstructorsClicked(int constructorId)
426 switch (constructorId) {
429 HEXABLOCKGUI::currentOccGView->setSelectionMode(TopAbs_VERTEX);
430 GroupRefPoint->hide();
431 GroupOnCurve->hide();
432 GroupLineIntersection->hide();
433 GroupOnSurface->hide();
435 myParamGroup->hide();
441 myParamGroup->hide();
443 GroupOnCurve->hide();
444 GroupLineIntersection->hide();
445 GroupOnSurface->hide();
446 GroupRefPoint->show();
450 case GEOM_POINT_EDGE:
452 GroupRefPoint->hide();
453 GroupLineIntersection->hide();
454 GroupOnSurface->hide();
455 myParamGroup->show();
456 myParamCoord->button(LENGTH_VALUE)->show();
457 myParamCoord->button(PARAM_VALUE)->setChecked(true);
458 GroupOnCurve->show();
460 updateParamCoord(false);
463 case GEOM_POINT_INTINT:
465 myParamGroup->hide();
467 GroupRefPoint->hide();
468 GroupOnCurve->hide();
469 GroupOnSurface->hide();
471 GroupLineIntersection->show();
474 case GEOM_POINT_SURF:
476 GroupRefPoint->hide();
477 GroupOnCurve->hide();
478 GroupLineIntersection->hide();
479 myParamGroup->show();
480 myParamCoord->button(LENGTH_VALUE)->hide();
481 myParamCoord->button(PARAM_VALUE)->setChecked(true);
482 GroupOnSurface->show();
484 updateParamCoord(false);
489 updateInputs(constructorId);
492 //=================================================================================
493 // funcion : getParameter()
495 //=================================================================================
496 double MyBasicGUI_PointDlg::getParameter() const
498 return GroupOnCurve->SpinBox_DX->value();
501 //=================================================================================
502 // funcion : getUParameter()
504 //=================================================================================
505 double MyBasicGUI_PointDlg::getUParameter() const
507 return GroupOnSurface->SpinBox_DX->value();
510 //=================================================================================
511 // funcion : getVParameter()
513 //=================================================================================
514 double MyBasicGUI_PointDlg::getVParameter() const
516 return GroupOnSurface->SpinBox_DY->value();
519 void MyBasicGUI_PointDlg::onParamValueChanged(double newValue)
521 if (getConstructorId() == GEOM_POINT_EDGE)
522 paramInputValue[myParamCoord->checkedId()] = newValue;
525 // ============================================================== onSelectionChanged
527 * Puts elements selected in the model in the corresponding widget (list widget or line edit)
528 * of the current dialog box.
530 void MyBasicGUI_PointDlg::onSelectionChanged( const QItemSelection& sel, const QItemSelection& unsel )
532 QModelIndexList l = sel.indexes();
536 QModelIndex selected = l[0];
537 int selectedType = selected.data(HEXA_TREE_ROLE).toInt();
538 // fill the coordinates of the selected point
539 if ( getConstructorId() == GEOM_POINT_XYZ && selectedType == GEOMPOINT_TREE)
541 DocumentModel::GeomObj* geomObj = getGeomObj(selected);
545 DocumentModel* docModel = getDocumentModel();
546 QString objId = geomObj->shapeName + "," + geomObj->subId;
547 HEXA_NS::SubShape* ssh = docModel->getGeomPtr(objId);
550 TopoDS_Shape shape = ssh->getShape();
551 if (shape.IsNull() || shape.ShapeType() != TopAbs_VERTEX)
553 TopoDS_Vertex vertex = TopoDS::Vertex(shape);
554 gp_Pnt pnt = BRep_Tool::Pnt(vertex);
555 OnPointSelected(pnt);
559 QLineEdit* aLineEdit = NULL;
560 QListWidget* aListWidget = NULL;
562 // * put selection in the current line edit
563 aLineEdit = dynamic_cast<QLineEdit*>(_currentObj);
564 if ( aLineEdit != NULL )
566 _onSelectionChanged( sel, aLineEdit );
570 // * put selection in the current list widget
571 aListWidget = dynamic_cast<QListWidget*>(_currentObj);
573 _onSelectionChanged( sel, aListWidget );
577 bool MyBasicGUI_PointDlg::apply(QModelIndex& result)
579 PatternGeomSelectionModel* pgsm = getPatternGeomSelectionModel();
580 PatternDataSelectionModel* pdsm = getPatternDataSelectionModel();
581 PatternDataModel* pdm = getPatternDataModel();
582 DocumentModel* docModel = getDocumentModel();
584 // get the selected vertex in the vtk view
585 QVariant v = mainFrame()->_vertex_le->property("QModelIndex");
588 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE VERTEX ASSOCIATION" ) );
591 QModelIndex iVertex = pdm->mapToSource( v.value<QModelIndex>() );
593 // get the selected vertex in the geometry (occ view)
594 TopoDS_Vertex geomVertex = computeGeomVertex();
597 if (!iVertex.isValid() || geomVertex.IsNull())
599 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE VERTEX ASSOCIATION" ) );
604 gp_Pnt aPnt = BRep_Tool::Pnt(geomVertex);
605 if (!docModel->setVertexAssociation(iVertex, aPnt.X(), aPnt.Y(), aPnt.Z()))
607 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE VERTEX ASSOCIATION" ) );
611 // * update data in the occ view and the geom tree
612 HEXABLOCKGUI::currentOccGView->addVertexToCloud(geomVertex);
613 docModel->updateGeomTree();
615 // highlight associated items
616 QModelIndex iGeomVertex = docModel->getVertexAssociation(iVertex);
617 QModelIndexList list1, list2;
618 result = v.value<QModelIndex>();
620 list2 << iGeomVertex;
621 pdsm->highlightTreeItems(list1); // data tree
622 pgsm->highlightTreeItems(list2); // geom tree
624 _updateCurrentObject(NULL);
625 HEXABLOCKGUI::currentOccGView->setSelectionMode(TopAbs_VERTEX);
626 HEXABLOCKGUI::currentDocGView->highlight(list1); // vtk view
627 HEXABLOCKGUI::currentOccGView->highlight(list1); // occ view
633 void MyBasicGUI_PointDlg::onXCoordChanged(double newValue)
635 int constructorId = getConstructorId();
636 if (constructorId != GEOM_POINT_XYZ && constructorId != GEOM_POINT_EDGE &&
637 constructorId != GEOM_POINT_SURF)
639 coordsInputValue[constructorId]->setX(newValue);
642 void MyBasicGUI_PointDlg::onYCoordChanged(double newValue)
644 int constructorId = getConstructorId();
645 if (constructorId != GEOM_POINT_XYZ && constructorId != GEOM_POINT_EDGE &&
646 constructorId != GEOM_POINT_SURF)
648 coordsInputValue[constructorId]->setY(newValue);
651 void MyBasicGUI_PointDlg::onZCoordChanged(double newValue)
653 int constructorId = getConstructorId();
654 if (constructorId != GEOM_POINT_XYZ && constructorId != GEOM_POINT_EDGE &&
655 constructorId != GEOM_POINT_SURF)
657 coordsInputValue[constructorId]->setZ(newValue);
661 void MyBasicGUI_PointDlg::onUpdateResults(const QString& data)
663 if (getConstructorId() == GEOM_POINT_XYZ)
666 // * compute the geom vertex
667 TopoDS_Vertex vertex = computeGeomVertex(true);
677 gp_Pnt pnt = BRep_Tool::Pnt(vertex);
678 myX->setText(MyDlgRef::PrintDoubleValue(pnt.X(), 6));
679 myY->setText(MyDlgRef::PrintDoubleValue(pnt.Y(), 6));
680 myZ->setText(MyDlgRef::PrintDoubleValue(pnt.Z(), 6));
683 TopoDS_Vertex MyBasicGUI_PointDlg::computeGeomVertex(bool preview)
685 TopoDS_Vertex vertex;
686 int constructorId = getConstructorId();
688 //display an emply vertex to erase the current preview
689 HEXABLOCKGUI::currentOccGView->displayPreview(vertex);
692 switch (constructorId) {
694 vertex = computeGeomPointXYZ();
697 vertex = computeGeomPointRef();
699 case GEOM_POINT_EDGE:
700 vertex = computeGeomPointEdge();
702 case GEOM_POINT_INTINT:
703 vertex = computeGeomPointInt();
705 case GEOM_POINT_SURF:
706 vertex = computeGeomPointSurf();
712 // * display preview of computed point
714 HEXABLOCKGUI::currentOccGView->displayPreview(vertex);
719 TopoDS_Vertex MyBasicGUI_PointDlg::computeGeomPointXYZ()
721 TopoDS_Vertex vertex;
723 if (getConstructorId() != GEOM_POINT_XYZ)
727 double x = GroupXYZ->SpinBox_DX->value();
728 double y = GroupXYZ->SpinBox_DY->value();
729 double z = GroupXYZ->SpinBox_DZ->value();
731 // - compute the resulting vertex
732 vertex = makePoint(x, y, z);
737 TopoDS_Vertex MyBasicGUI_PointDlg::computeGeomPointRef()
739 TopoDS_Vertex vertex;
741 if (getConstructorId() != GEOM_POINT_REF)
744 // get parameters from widgets
745 double dx = GroupRefPoint->SpinBox_DX->value();
746 double dy = GroupRefPoint->SpinBox_DY->value();
747 double dz = GroupRefPoint->SpinBox_DZ->value();
749 QVariant v = GroupRefPoint->LineEdit1->property("TopoDS_Shape");
752 TopoDS_Shape shape = v.value<TopoDS_Shape>();
754 // compute the resulting point
755 vertex = makePointWithReference(shape, dx, dy, dz);
760 TopoDS_Vertex MyBasicGUI_PointDlg::computeGeomPointEdge()
762 TopoDS_Vertex vertex;
764 if (getConstructorId() != GEOM_POINT_EDGE)
767 // * get inputs values
770 QVariant v1 = GroupOnCurve->LineEdit1->property("TopoDS_Shape");
773 TopoDS_Shape edgeShape = v1.value<TopoDS_Shape>();
775 bool isParam = myParamCoord->checkedId() == PARAM_VALUE;
776 bool isLength = myParamCoord->checkedId() == LENGTH_VALUE;
777 bool isCoord = myParamCoord->checkedId() == COORD_VALUE;
781 double param = GroupOnCurve->SpinBox_DX->value();
783 // - compute the resulting vertex
784 vertex = makePointOnCurve(edgeShape, param);
788 // - the starting point
789 QVariant v2 = GroupOnCurve->LineEdit2->property("TopoDS_Shape");
792 TopoDS_Shape pointShape = v2.value<TopoDS_Shape>();
795 double length = GroupOnCurve->SpinBox_DX->value();
797 // - compute the resulting vertex
798 vertex = makePointOnCurveByLength(edgeShape, pointShape,length);
803 double x = GroupXYZ->SpinBox_DX->value();
804 double y = GroupXYZ->SpinBox_DY->value();
805 double z = GroupXYZ->SpinBox_DZ->value();
807 // - compute the resulting vertex
808 vertex = makePointOnCurveByCoord(edgeShape, x, y, z);
814 TopoDS_Vertex MyBasicGUI_PointDlg::computeGeomPointInt()
816 TopoDS_Vertex vertex;
818 if (getConstructorId() != GEOM_POINT_INTINT)
823 // * get inputs values
826 v = GroupLineIntersection->LineEdit1->property("TopoDS_Shape");
829 TopoDS_Shape line1 = v.value<TopoDS_Shape>();
832 v = GroupLineIntersection->LineEdit2->property("TopoDS_Shape");
835 TopoDS_Shape line2 = v.value<TopoDS_Shape>();
837 // * compute the resulting vertex
838 vertex = makePointOnLinesIntersection(line1, line2);
843 TopoDS_Vertex MyBasicGUI_PointDlg::computeGeomPointSurf()
845 TopoDS_Vertex vertex;
847 if (getConstructorId() != GEOM_POINT_SURF)
850 // * get inputs values
853 QVariant v = GroupOnSurface->LineEdit1->property("TopoDS_Shape");
856 TopoDS_Shape faceShape = v.value<TopoDS_Shape>();
858 bool isParam = myParamCoord->checkedId() == PARAM_VALUE;
859 bool isCoord = myParamCoord->checkedId() == COORD_VALUE;
863 double param_u = GroupOnSurface->SpinBox_DX->value();
864 double param_v = GroupOnSurface->SpinBox_DY->value();
866 // - compute the resulting vertex
867 vertex = makePointOnSurface(faceShape, param_u, param_v);
872 double x = GroupXYZ->SpinBox_DX->value();
873 double y = GroupXYZ->SpinBox_DY->value();
874 double z = GroupXYZ->SpinBox_DZ->value();
876 // - compute the resulting vertex
877 vertex = makePointOnSurfaceByCoord(faceShape, x, y, z);
883 //=================================================================================
884 // function : OnPointSelected
886 //=================================================================================
887 void MyBasicGUI_PointDlg::OnPointSelected(const gp_Pnt& thePnt)
889 if (getConstructorId() == GEOM_POINT_XYZ) {
890 GroupXYZ->SpinBox_DX->setValue(thePnt.X());
891 GroupXYZ->SpinBox_DY->setValue(thePnt.Y());
892 GroupXYZ->SpinBox_DZ->setValue(thePnt.Z());
896 void MyBasicGUI_PointDlg::updateInputs(const int constructorId)
899 QVector3D* coords = NULL;
901 switch (constructorId) {
902 case GEOM_POINT_XYZ :
903 coords = coordsInputValue[GEOM_POINT_XYZ];
907 case GEOM_POINT_EDGE:
908 coords = coordsInputValue[GEOM_POINT_EDGE];
909 updateParamCoord(true);
911 case GEOM_POINT_INTINT:
913 case GEOM_POINT_SURF:
914 coords = coordsInputValue[GEOM_POINT_SURF];
915 updateParamCoord(true);
923 GroupXYZ->SpinBox_DX->setValue(coords->x());
924 GroupXYZ->SpinBox_DY->setValue(coords->y());
925 GroupXYZ->SpinBox_DZ->setValue(coords->z());
928 onUpdateResults(str);
931 //=================================================================================
932 // function : ClickParamCoord()
934 //=================================================================================
935 void MyBasicGUI_PointDlg::ClickParamCoord(int id)
937 updateInputs(getConstructorId());
940 //=================================================================================
941 // function : updateParamCoord
943 //=================================================================================
944 void MyBasicGUI_PointDlg::updateParamCoord(bool theIsUpdate)
946 bool isParam = myParamCoord->checkedId() == PARAM_VALUE;
947 bool isLength = myParamCoord->checkedId() == LENGTH_VALUE;
949 const int id = getConstructorId();
950 if (id == GEOM_POINT_EDGE) {
951 GroupOnCurve->TextLabel2->setVisible(isLength);
952 GroupOnCurve->LineEdit2->setVisible(isLength);
953 GroupOnCurve->TextLabel3->setVisible(isParam || isLength);
954 GroupOnCurve->SpinBox_DX->setVisible(isParam || isLength);
956 GroupOnCurve->TextLabel3->setText(tr("GEOM_PARAMETER"));
957 double value = paramInputValue[PARAM_VALUE];
958 GroupOnCurve->SpinBox_DX->setValue(0.5);
959 initSpinBox(GroupOnCurve->SpinBox_DX, 0., 1.);
960 GroupOnCurve->SpinBox_DX->setValue(value);
963 GroupOnCurve->TextLabel3->setText(tr("GEOM_LENGTH"));
964 double value = paramInputValue[LENGTH_VALUE];
965 GroupOnCurve->SpinBox_DX->setValue(0.5);
966 initSpinBox(GroupOnCurve->SpinBox_DX, COORD_MIN, COORD_MAX);
967 GroupOnCurve->SpinBox_DX->setValue(value);
970 else if (id == GEOM_POINT_SURF) {
971 GroupOnSurface->TextLabel2->setShown(isParam);
972 GroupOnSurface->TextLabel3->setShown(isParam);
973 GroupOnSurface->SpinBox_DX->setShown(isParam);
974 GroupOnSurface->SpinBox_DY->setShown(isParam);
977 GroupXYZ->setShown(!isParam && !isLength);
980 //=================================================================================
981 // function : onBtnPopup()
983 //=================================================================================
984 void MyBasicGUI_PointDlg::onBtnPopup(QAction* a)
986 if (a == action_line1_edge)
988 GroupLineIntersection->LineEdit1->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_EDGE) );
989 GroupLineIntersection->LineEdit1->setFocus();
990 GroupLineIntersection->PushButton2->setDown(false);
992 else if (a == action_line1_wire)
994 GroupLineIntersection->LineEdit1->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_WIRE) );
995 GroupLineIntersection->LineEdit1->setFocus();
996 GroupLineIntersection->PushButton2->setDown(false);
998 else if (a == action_line2_edge)
1000 GroupLineIntersection->LineEdit2->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_EDGE) );
1001 GroupLineIntersection->LineEdit2->setFocus();
1002 GroupLineIntersection->PushButton1->setDown(false);
1004 else if (a == action_line2_wire)
1006 GroupLineIntersection->LineEdit2->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_WIRE) );
1007 GroupLineIntersection->LineEdit2->setFocus();
1008 GroupLineIntersection->PushButton1->setDown(false);
1012 //=================================================================================
1013 // function : updateSize
1014 // purpose : adjust dialog size to minimum
1015 //=================================================================================
1016 void MyBasicGUI_PointDlg::updateSize()
1018 qApp->processEvents();
1020 resize(minimumSizeHint());
1023 void MyBasicGUI_PointDlg::clear()
1025 mainFrame()->_vertex_le->clear();
1026 modelUnregister(mainFrame()->_vertex_le);
1028 GroupRefPoint->LineEdit1->clear();
1029 GroupRefPoint->LineEdit1->setProperty("TopoDS_Shape", QVariant());
1030 GroupRefPoint->LineEdit1->setProperty("QModelIndex", QVariant());
1031 GroupRefPoint->LineEdit1->setProperty("HexaData", QVariant());
1033 GroupOnCurve->LineEdit1->clear();
1034 GroupOnCurve->LineEdit1->setProperty("TopoDS_Shape", QVariant());
1035 GroupOnCurve->LineEdit1->setProperty("QModelIndex", QVariant());
1036 GroupOnCurve->LineEdit1->setProperty("HexaData", QVariant());
1038 GroupOnCurve->LineEdit2->clear();
1039 GroupOnCurve->LineEdit2->setProperty("TopoDS_Shape", QVariant());
1040 GroupOnCurve->LineEdit2->setProperty("QModelIndex", QVariant());
1041 GroupOnCurve->LineEdit2->setProperty("HexaData", QVariant());
1043 GroupLineIntersection->LineEdit1->clear();
1044 GroupLineIntersection->LineEdit1->setProperty("TopoDS_Shape", QVariant());
1045 GroupLineIntersection->LineEdit1->setProperty("QModelIndex", QVariant());
1046 GroupLineIntersection->LineEdit1->setProperty("HexaData", QVariant());
1048 GroupLineIntersection->LineEdit2->clear();
1049 GroupLineIntersection->LineEdit2->setProperty("TopoDS_Shape", QVariant());
1050 GroupLineIntersection->LineEdit2->setProperty("QModelIndex", QVariant());
1051 GroupLineIntersection->LineEdit2->setProperty("HexaData", QVariant());
1053 GroupOnSurface->LineEdit1->clear();
1054 GroupOnSurface->LineEdit1->setProperty("TopoDS_Shape", QVariant());
1055 GroupOnSurface->LineEdit1->setProperty("QModelIndex", QVariant());
1056 GroupOnSurface->LineEdit1->setProperty("HexaData", QVariant());
1058 modelUnregister(this);
1062 void MyBasicGUI_PointDlg::onWindowActivated(SUIT_ViewManager* vm)
1064 QString vmType = vm->getType();
1065 if ( ((vmType == SVTK_Viewer::Type()) || (vmType == VTKViewer_Viewer::Type())) &&
1066 !mainFrame()->RadioButton4->isChecked() &&
1067 !myParamCoord->button(LENGTH_VALUE)->isChecked() )
1068 mainFrame()->_vertex_le->setFocus();
1069 else if ( vmType == OCCViewer_Viewer::Type() ){
1070 if (mainFrame()->RadioButton1->isChecked())
1071 // Make the field "Vertex of the model" lose the focus
1072 mainFrame()->RadioButton1->click();
1073 else if (mainFrame()->RadioButton2->isChecked())
1074 GroupRefPoint->LineEdit1->setFocus();
1075 else if (mainFrame()->RadioButton3->isChecked() &&
1076 !myParamCoord->button(LENGTH_VALUE)->isChecked())
1077 GroupOnCurve->LineEdit1->setFocus();
1078 else if (mainFrame()->RadioButton5->isChecked())
1079 GroupOnSurface->LineEdit1->setFocus();