1 // Copyright (C) 2009-2015 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>
40 #include <TopoDS_Shape.hxx>
41 #include <TopAbs_ShapeEnum.hxx>
43 #include <BRep_Tool.hxx>
45 #include <TColStd_IndexedMapOfInteger.hxx>
46 #include <TopTools_IndexedMapOfShape.hxx>
49 #include <VTKViewer_ViewModel.h>
50 #include <SUIT_MessageBox.h>
51 #include <SUIT_OverrideCursor.h>
52 #include <SalomeApp_Tools.h>
53 #include <SalomeApp_Study.h>
55 #include "HEXABLOCKGUI_DocumentModel.hxx"
56 #include "HEXABLOCKGUI_DocumentSelectionModel.hxx"
57 #include "HEXABLOCKGUI_DocumentItem.hxx"
58 #include "HEXABLOCKGUI_SalomeTools.hxx"
59 #include "HEXABLOCKGUI.hxx"
60 #include "HEXABLOCKGUI_VtkDocumentGraphicView.hxx"
64 #define LENGTH_VALUE 2
66 #define GEOM_POINT_XYZ 0
67 #define GEOM_POINT_REF 1
68 #define GEOM_POINT_EDGE 2
69 #define GEOM_POINT_INTINT 3
70 #define GEOM_POINT_SURF 4
75 using namespace HEXABLOCK::GUI;
77 Q_DECLARE_METATYPE(HEXABLOCK::GUI::HexaTreeRole);
78 Q_DECLARE_METATYPE(TopAbs_ShapeEnum);
79 Q_DECLARE_METATYPE(TopoDS_Shape);
81 //=================================================================================
82 // class : MyBasicGUI_PointDlg()
83 // purpose : Constructs a MyBasicGUI_PointDlg which is a child of 'parent', with the
84 // name 'name' and widget flags set to 'f'.
85 // The dialog will by default be modeless, unless you set 'modal' to
86 // TRUE to construct a modal dialog.
87 //=================================================================================
88 MyBasicGUI_PointDlg::MyBasicGUI_PointDlg(QWidget* parent, Qt::WindowFlags fl)
89 : MyGEOMBase_Skeleton(parent, fl),
92 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
93 QPixmap image0 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_POINT")));
94 QPixmap image1 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_POINT_EDGE")));
95 QPixmap image2 (aResMgr->loadPixmap("GEOM", tr("ICON_SELECT")));
96 QPixmap image3 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_POINT_REF")));
97 QPixmap image4 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_POINT_LINES")));
98 QPixmap image5 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_POINT_FACE")));
99 QPixmap image6 (aResMgr->loadPixmap("GEOM", tr("ICO_LINE")));
100 QPixmap image7 (aResMgr->loadPixmap("GEOM", tr("ICO_WIRE")));
102 setWindowTitle( tr("Vertex Association") );
103 // setMinimumWidth(260);
104 // setMinimumHeight(400);
106 mainFrame()->GroupConstructors->setTitle(tr("GEOM_POINTS"));
107 mainFrame()->RadioButton1->setIcon(image0);
108 mainFrame()->RadioButton2->setIcon(image3);
109 mainFrame()->RadioButton3->setIcon(image1);
110 mainFrame()->RadioButton4->show();
111 mainFrame()->RadioButton4->setIcon(image4);
112 mainFrame()->RadioButton5->show();
113 mainFrame()->RadioButton5->setIcon(image5);
115 myParamGroup = new QGroupBox(centralWidget());
116 myParamCoord = new QButtonGroup(myParamGroup);
117 QHBoxLayout* boxLayout = new QHBoxLayout(myParamGroup);
118 boxLayout->setMargin(MARGIN); boxLayout->setSpacing(SPACING);
120 QRadioButton* btn = new QRadioButton(tr("By Param"), myParamGroup);
121 myParamCoord->addButton(btn, PARAM_VALUE);
122 boxLayout->addWidget(btn);
124 btn = new QRadioButton(tr("By Length"), myParamGroup);
125 myParamCoord->addButton(btn, LENGTH_VALUE);
126 boxLayout->addWidget(btn);
128 btn = new QRadioButton(tr("By Coords"), myParamGroup);
129 myParamCoord->addButton(btn, COORD_VALUE);
130 boxLayout->addWidget(btn);
132 myParamCoord->setExclusive(true);
133 myParamCoord->button(PARAM_VALUE)->setChecked(true);
135 GroupXYZ = new MyDlgRef_3Spin(centralWidget());
136 GroupXYZ->GroupBox1->setTitle(tr("GEOM_COORDINATES"));
137 GroupXYZ->TextLabel1->setText(tr("GEOM_X"));
138 GroupXYZ->TextLabel2->setText(tr("GEOM_Y"));
139 GroupXYZ->TextLabel3->setText(tr("GEOM_Z"));
140 coordsInputValue[GEOM_POINT_XYZ] = new QVector3D(0, 0, 0);
141 coordsInputValue[GEOM_POINT_EDGE] = new QVector3D(0, 0, 0);
142 coordsInputValue[GEOM_POINT_SURF] = new QVector3D(0, 0, 0);
144 GroupOnCurve = new MyDlgRef_2Sel1Spin(centralWidget());
145 GroupOnCurve->GroupBox1->setTitle(tr("GEOM_POINT_ON_EDGE"));
146 GroupOnCurve->TextLabel1->setText(tr("GEOM_EDGE"));
147 GroupOnCurve->TextLabel2->setText(tr("GEOM_START_POINT"));
148 GroupOnCurve->TextLabel3->setText(tr("GEOM_PARAMETER"));
149 paramInputValue[PARAM_VALUE] = 0.5;
150 paramInputValue[LENGTH_VALUE] = 0.5;
152 GroupOnSurface = new MyDlgRef_1Sel2Spin(centralWidget());
153 GroupOnSurface->GroupBox1->setTitle(tr("GEOM_POINT_ON_FACE"));
154 GroupOnSurface->TextLabel1->setText(tr("GEOM_FACE"));
155 GroupOnSurface->TextLabel2->setText(tr("GEOM_UPARAMETER"));
156 GroupOnSurface->TextLabel3->setText(tr("GEOM_VPARAMETER"));
158 GroupRefPoint = new MyDlgRef_1Sel3Spin(centralWidget());
159 GroupRefPoint->GroupBox1->setTitle(tr("GEOM_REF_POINT"));
160 GroupRefPoint->TextLabel1->setText(tr("GEOM_POINT"));
161 GroupRefPoint->TextLabel2->setText(tr("GEOM_DX"));
162 GroupRefPoint->TextLabel3->setText(tr("GEOM_DY"));
163 GroupRefPoint->TextLabel4->setText(tr("GEOM_DZ"));
165 /* popup menu for line intersect buttons */
166 QIcon ico_line = QIcon(image6);
167 QIcon ico_wire = QIcon(image7);
169 myBtnPopup = new QMenu(this);
170 action_line1_edge = myBtnPopup->addAction(ico_line, tr("GEOM_EDGE"));
171 action_line1_wire = myBtnPopup->addAction(ico_wire, tr("GEOM_WIRE"));
174 myBtnPopup2 = new QMenu(this);
175 action_line2_edge = myBtnPopup2->addAction(ico_line, tr("GEOM_EDGE"));
176 action_line2_wire = myBtnPopup2->addAction(ico_wire, tr("GEOM_WIRE"));
178 GroupLineIntersection = new MyDlgRef_2Sel(centralWidget());
179 GroupLineIntersection->GroupBox1->setTitle(tr("GEOM_LINE_INTERSECTION"));
180 GroupLineIntersection->TextLabel1->setText(tr("GEOM_LINE1"));
181 GroupLineIntersection->TextLabel2->setText(tr("GEOM_LINE2"));
182 GroupLineIntersection->PushButton1->setIcon(image2);
183 GroupLineIntersection->PushButton1->setMenu(myBtnPopup);
184 GroupLineIntersection->PushButton2->setIcon(image2);
185 GroupLineIntersection->PushButton2->setMenu(myBtnPopup2);
187 myCoordGrp = new QGroupBox(tr("GEOM_COORDINATES_RES"), centralWidget());
188 QGridLayout* myCoordGrpLayout = new QGridLayout(myCoordGrp);
189 myCoordGrpLayout->addWidget(new QLabel(tr("GEOM_X"), myCoordGrp), 0, 0);
190 myX = new QLineEdit(myCoordGrp);
191 myCoordGrpLayout->addWidget(myX, 0, 1);
192 myCoordGrpLayout->addWidget(new QLabel(tr("GEOM_Y"), myCoordGrp), 1, 0);
193 myY = new QLineEdit(myCoordGrp);
194 myCoordGrpLayout->addWidget(myY, 1, 1);
195 myCoordGrpLayout->addWidget(new QLabel(tr("GEOM_Z"), myCoordGrp), 2, 0);
196 myZ = new QLineEdit(myCoordGrp);
197 myCoordGrpLayout->addWidget(myZ, 2, 1);
199 QVBoxLayout* layout = new QVBoxLayout(centralWidget());
200 layout->setMargin(0); layout->setSpacing(6);
201 layout->addWidget(myParamGroup);
202 layout->addWidget(GroupXYZ);
203 layout->addWidget(GroupOnCurve);
204 layout->addWidget(GroupOnSurface);
205 layout->addWidget(GroupRefPoint);
206 layout->addWidget(GroupLineIntersection);
207 layout->addWidget(myCoordGrp);
209 myX->setReadOnly(true);
210 myY->setReadOnly(true);
211 myZ->setReadOnly(true);
213 myX->setEnabled(false);
214 myY->setEnabled(false);
215 myZ->setEnabled(false);
217 QPalette aPal = myX->palette();
218 aPal.setColor(QPalette::Disabled, QPalette::Text, QColor(0, 0, 0));
219 myX->setPalette(aPal);
220 myY->setPalette(aPal);
221 myZ->setPalette(aPal);
223 _helpFileName = "gui_asso_quad_to_geom.html#associate-to-a-vertex-of-the-geometry";
224 _initWidget( _editMode );
225 mainFrame()->RadioButton1->click();
228 //=================================================================================
229 // function : ~MyBasicGUI_PointDlg()
230 // purpose : Destructor
231 //=================================================================================
232 MyBasicGUI_PointDlg::~MyBasicGUI_PointDlg()
236 void MyBasicGUI_PointDlg::_initInputWidget( HexaBaseDialog::Mode editmode )
238 // *** Init input widgets ***/
239 initSpinBox(GroupXYZ->SpinBox_DX, COORD_MIN, COORD_MAX);
240 initSpinBox(GroupXYZ->SpinBox_DY, COORD_MIN, COORD_MAX);
241 initSpinBox(GroupXYZ->SpinBox_DZ, COORD_MIN, COORD_MAX);
242 GroupXYZ->SpinBox_DX->setValue(0.0);
243 GroupXYZ->SpinBox_DY->setValue(0.0);
244 GroupXYZ->SpinBox_DZ->setValue(0.0);
246 initSpinBox(GroupRefPoint->SpinBox_DX, COORD_MIN, COORD_MAX);
247 initSpinBox(GroupRefPoint->SpinBox_DY, COORD_MIN, COORD_MAX);
248 initSpinBox(GroupRefPoint->SpinBox_DZ, COORD_MIN, COORD_MAX);
249 GroupRefPoint->SpinBox_DX->setValue(0.0);
250 GroupRefPoint->SpinBox_DY->setValue(0.0);
251 GroupRefPoint->SpinBox_DZ->setValue(0.0);
253 initSpinBox(GroupOnCurve->SpinBox_DX, 0., 1.);
254 GroupOnCurve->SpinBox_DX->setValue(paramInputValue[PARAM_VALUE]);
256 initSpinBox(GroupOnSurface->SpinBox_DX, 0., 1.);
257 GroupOnSurface->SpinBox_DX->setValue(0.5);
258 initSpinBox(GroupOnSurface->SpinBox_DY, 0., 1.);
259 GroupOnSurface->SpinBox_DY->setValue(0.5);
261 // * vtk input widget
262 mainFrame()->_vertex_le->setReadOnly(true);
263 mainFrame()->_vertex_le->setProperty( "HexaWidgetType", QVariant::fromValue(HEXABLOCK::GUI::VERTEX_TREE) );
264 mainFrame()->_vertex_le->installEventFilter(this);
266 // * geom input widgets
268 GroupRefPoint->LineEdit1->setReadOnly(true);
269 GroupRefPoint->LineEdit1->setProperty( "HexaWidgetType", QVariant::fromValue(GEOMPOINT_TREE) );
270 GroupRefPoint->LineEdit1->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_VERTEX) );
271 GroupRefPoint->LineEdit1->installEventFilter(this);
275 GroupOnCurve->LineEdit1->setReadOnly(true);
276 GroupOnCurve->LineEdit1->setProperty( "HexaWidgetType", QVariant::fromValue(GEOMEDGE_TREE) );
277 GroupOnCurve->LineEdit1->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_EDGE) );
278 GroupOnCurve->LineEdit1->installEventFilter(this);
281 GroupOnCurve->LineEdit2->setReadOnly(true);
282 GroupOnCurve->LineEdit2->setProperty( "HexaWidgetType", QVariant::fromValue(GEOMPOINT_TREE) );
283 GroupOnCurve->LineEdit2->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_VERTEX) );
284 GroupOnCurve->LineEdit2->installEventFilter(this);
286 // point of 2 lines intersection
288 GroupLineIntersection->LineEdit1->setReadOnly(true);
289 GroupLineIntersection->LineEdit1->setProperty( "HexaWidgetType", QVariant::fromValue(GEOMEDGE_TREE) );
290 GroupLineIntersection->LineEdit1->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_EDGE) );
291 GroupLineIntersection->LineEdit1->installEventFilter(this);
294 GroupLineIntersection->LineEdit2->setReadOnly(true);
295 GroupLineIntersection->LineEdit2->setProperty( "HexaWidgetType", QVariant::fromValue(GEOMEDGE_TREE) );
296 GroupLineIntersection->LineEdit2->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_EDGE) );
297 GroupLineIntersection->LineEdit2->installEventFilter(this);
300 GroupOnSurface->LineEdit1->setReadOnly(true);
301 GroupOnSurface->LineEdit1->setProperty( "HexaWidgetType", QVariant::fromValue(GEOMFACE_TREE) );
302 GroupOnSurface->LineEdit1->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_FACE) );
303 GroupOnSurface->LineEdit1->installEventFilter(this);
306 connect(this, SIGNAL(constructorsClicked(int)), this, SLOT(ConstructorsClicked(int)));
307 connect(myParamCoord, SIGNAL(buttonClicked(int)), this, SLOT(ClickParamCoord(int)));
308 connect(myBtnPopup, SIGNAL(triggered(QAction*)), this, SLOT(onBtnPopup(QAction*)));
309 connect(myBtnPopup2, SIGNAL(triggered(QAction*)), this, SLOT(onBtnPopup(QAction*)));
312 connect(GroupRefPoint->LineEdit1, SIGNAL( textChanged(const QString&) ), this, SLOT(onUpdateResults(const QString&)));
315 connect(GroupOnCurve->LineEdit1, SIGNAL( textChanged(const QString&) ), this, SLOT(onUpdateResults(const QString&)));
316 connect(GroupOnCurve->LineEdit2, SIGNAL( textChanged(const QString&) ), this, SLOT(onUpdateResults(const QString&)));
318 connect(GroupOnCurve->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(onParamValueChanged(double)));
319 connect(GroupOnCurve->SpinBox_DX, SIGNAL(valueChanged(const QString&)), this, SLOT(onUpdateResults(const QString&)));
321 // intersection point
322 connect(GroupLineIntersection->LineEdit1, SIGNAL( textChanged(const QString&) ), this, SLOT(onUpdateResults(const QString&)));
323 connect(GroupLineIntersection->LineEdit2, SIGNAL( textChanged(const QString&) ), this, SLOT(onUpdateResults(const QString&)));
326 connect(GroupOnSurface->SpinBox_DX, SIGNAL(valueChanged(const QString&)), this, SLOT(onUpdateResults(const QString&)));
327 connect(GroupOnSurface->SpinBox_DY, SIGNAL(valueChanged(const QString&)), this, SLOT(onUpdateResults(const QString&)));
328 connect(GroupOnSurface->LineEdit1, SIGNAL( textChanged(const QString&) ), this, SLOT(onUpdateResults(const QString&))); //surface: Face
331 connect(GroupXYZ->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(onXCoordChanged(double)));
332 connect(GroupXYZ->SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(onYCoordChanged(double)));
333 connect(GroupXYZ->SpinBox_DZ, SIGNAL(valueChanged(double)), this, SLOT(onZCoordChanged(double)));
335 connect(GroupXYZ->SpinBox_DX, SIGNAL(valueChanged(const QString&)), this, SLOT(onUpdateResults(const QString&)));
336 connect(GroupXYZ->SpinBox_DY, SIGNAL(valueChanged(const QString&)), this, SLOT(onUpdateResults(const QString&)));
337 connect(GroupXYZ->SpinBox_DZ, SIGNAL(valueChanged(const QString&)), this, SLOT(onUpdateResults(const QString&)));
340 connect(GroupRefPoint->SpinBox_DX, SIGNAL(valueChanged(const QString&)), this, SLOT(onUpdateResults(const QString&)));
341 connect(GroupRefPoint->SpinBox_DY, SIGNAL(valueChanged(const QString&)), this, SLOT(onUpdateResults(const QString&)));
342 connect(GroupRefPoint->SpinBox_DZ, SIGNAL(valueChanged(const QString&)), this, SLOT(onUpdateResults(const QString&)));
345 connect( mainFrame()->RadioButton1, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
346 connect( mainFrame()->RadioButton2, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
347 connect( mainFrame()->RadioButton3, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
348 connect( mainFrame()->RadioButton4, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
349 connect( mainFrame()->RadioButton5, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
351 connect( mainFrame()->RadioButton1, SIGNAL(clicked()), this, SLOT( refreshHighlight()) );
352 connect( mainFrame()->RadioButton2, SIGNAL(clicked()), this, SLOT(refreshHighlight()) );
353 connect( mainFrame()->RadioButton1, SIGNAL(clicked()), this, SLOT( refreshHighlight()) );
354 connect( mainFrame()->RadioButton2, SIGNAL(clicked()), this, SLOT(refreshHighlight()) );
355 connect( mainFrame()->RadioButton1, SIGNAL(clicked()), this, SLOT( refreshHighlight()) );
357 connect( myParamCoord->button(PARAM_VALUE), SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
358 connect( myParamCoord->button(LENGTH_VALUE), SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
359 connect( myParamCoord->button(COORD_VALUE), SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
363 void MyBasicGUI_PointDlg::showEvent ( QShowEvent * event )
365 HexaBaseDialog::showEvent(event);
366 if (getConstructorId() == GEOM_POINT_XYZ)
367 HEXABLOCKGUI::currentOccGView->setSelectionMode(TopAbs_VERTEX);
369 //===============================================================
370 // function : updateHelpFileName()
371 // purpose : update the help file according to the current panel
372 //===============================================================
373 void MyBasicGUI_PointDlg::updateHelpFileName()
375 if ( sender() == mainFrame()->RadioButton1 ){
376 _helpFileName = "gui_asso_quad_to_geom.html#associate-to-a-vertex-of-the-geometry";
377 } else if ( sender() == mainFrame()->RadioButton2 ){
378 _helpFileName = "gui_asso_vertex_to_geom.html#by-a-reference";
379 } else if ( sender() == mainFrame()->RadioButton3 ){
380 _helpFileName = "gui_asso_vertex_to_geom.html#by-an-edge-and-a-parameter";
381 } else if ( sender() == mainFrame()->RadioButton4 ){
382 _helpFileName = "gui_asso_vertex_to_geom.html#by-intersection-of-two-lines-or-wires";
383 } else if ( sender() == mainFrame()->RadioButton5 ){
384 _helpFileName = "gui_asso_vertex_to_geom.html#by-a-face-and-two-parameters";
385 } else if (sender() == myParamCoord->button(PARAM_VALUE)){
386 if (mainFrame()->RadioButton3->isChecked()){
387 _helpFileName = "gui_asso_vertex_to_geom.html#by-an-edge-and-a-parameter";
388 } else if (mainFrame()->RadioButton5->isChecked()){
389 _helpFileName = "gui_asso_vertex_to_geom.html#by-a-face-and-two-parameters";
391 } else if (sender() == myParamCoord->button(LENGTH_VALUE)){
392 _helpFileName = "gui_asso_vertex_to_geom.html#by-an-edge-and-a-length";
393 } else if (sender() == myParamCoord->button(COORD_VALUE)){
394 if (mainFrame()->RadioButton3->isChecked()){
395 _helpFileName = "gui_asso_vertex_to_geom.html#by-an-edge-and-coordinates";
396 } else if (mainFrame()->RadioButton5->isChecked()){
397 _helpFileName = "gui_asso_vertex_to_geom.html#by-a-face-and-coordinates";
402 //=================================================================================
403 // function : SetDoubleSpinBoxStep()
404 // purpose : Double spin box management
405 //=================================================================================
406 void MyBasicGUI_PointDlg::SetDoubleSpinBoxStep(double step)
408 GroupOnCurve->SpinBox_DX->setSingleStep(step);
409 GroupXYZ->SpinBox_DX->setSingleStep(step);
410 GroupXYZ->SpinBox_DY->setSingleStep(step);
411 GroupXYZ->SpinBox_DZ->setSingleStep(step);
412 GroupRefPoint->SpinBox_DX->setSingleStep(step);
413 GroupRefPoint->SpinBox_DY->setSingleStep(step);
414 GroupRefPoint->SpinBox_DZ->setSingleStep(step);
418 //=================================================================================
419 // function : ConstructorsClicked()
420 // purpose : Radio button management
421 //=================================================================================
422 void MyBasicGUI_PointDlg::ConstructorsClicked(int constructorId)
427 switch (constructorId) {
430 HEXABLOCKGUI::currentOccGView->setSelectionMode(TopAbs_VERTEX);
431 GroupRefPoint->hide();
432 GroupOnCurve->hide();
433 GroupLineIntersection->hide();
434 GroupOnSurface->hide();
436 myParamGroup->hide();
442 myParamGroup->hide();
444 GroupOnCurve->hide();
445 GroupLineIntersection->hide();
446 GroupOnSurface->hide();
447 GroupRefPoint->show();
451 case GEOM_POINT_EDGE:
453 GroupRefPoint->hide();
454 GroupLineIntersection->hide();
455 GroupOnSurface->hide();
456 myParamGroup->show();
457 myParamCoord->button(LENGTH_VALUE)->show();
458 myParamCoord->button(PARAM_VALUE)->setChecked(true);
459 GroupOnCurve->show();
461 updateParamCoord(false);
464 case GEOM_POINT_INTINT:
466 myParamGroup->hide();
468 GroupRefPoint->hide();
469 GroupOnCurve->hide();
470 GroupOnSurface->hide();
472 GroupLineIntersection->show();
475 case GEOM_POINT_SURF:
477 GroupRefPoint->hide();
478 GroupOnCurve->hide();
479 GroupLineIntersection->hide();
480 myParamGroup->show();
481 myParamCoord->button(LENGTH_VALUE)->hide();
482 myParamCoord->button(PARAM_VALUE)->setChecked(true);
483 GroupOnSurface->show();
485 updateParamCoord(false);
490 updateInputs(constructorId);
493 //=================================================================================
494 // funcion : getParameter()
496 //=================================================================================
497 double MyBasicGUI_PointDlg::getParameter() const
499 return GroupOnCurve->SpinBox_DX->value();
502 //=================================================================================
503 // funcion : getUParameter()
505 //=================================================================================
506 double MyBasicGUI_PointDlg::getUParameter() const
508 return GroupOnSurface->SpinBox_DX->value();
511 //=================================================================================
512 // funcion : getVParameter()
514 //=================================================================================
515 double MyBasicGUI_PointDlg::getVParameter() const
517 return GroupOnSurface->SpinBox_DY->value();
520 void MyBasicGUI_PointDlg::onParamValueChanged(double newValue)
522 if (getConstructorId() == GEOM_POINT_EDGE)
523 paramInputValue[myParamCoord->checkedId()] = newValue;
526 // ============================================================== onSelectionChanged
528 * Puts elements selected in the model in the corresponding widget (list widget or line edit)
529 * of the current dialog box.
531 void MyBasicGUI_PointDlg::onSelectionChanged( const QItemSelection& sel, const QItemSelection& unsel )
533 QModelIndexList l = sel.indexes();
537 QModelIndex selected = l[0];
538 int selectedType = selected.data(HEXA_TREE_ROLE).toInt();
539 // fill the coordinates of the selected point
540 if ( getConstructorId() == GEOM_POINT_XYZ && selectedType == GEOMPOINT_TREE)
542 DocumentModel::GeomObj* geomObj = getGeomObj(selected);
546 DocumentModel* docModel = getDocumentModel();
547 QString objId = geomObj->shapeName + "," + geomObj->subId;
548 HEXA_NS::SubShape* ssh = docModel->getGeomPtr(objId);
551 TopoDS_Shape shape = ssh->getShape();
552 if (shape.IsNull() || shape.ShapeType() != TopAbs_VERTEX)
554 TopoDS_Vertex vertex = TopoDS::Vertex(shape);
555 gp_Pnt pnt = BRep_Tool::Pnt(vertex);
556 OnPointSelected(pnt);
560 QLineEdit* aLineEdit = NULL;
561 QListWidget* aListWidget = NULL;
563 // * put selection in the current line edit
564 aLineEdit = dynamic_cast<QLineEdit*>(_currentObj);
565 if ( aLineEdit != NULL )
567 _onSelectionChanged( sel, aLineEdit );
571 // * put selection in the current list widget
572 aListWidget = dynamic_cast<QListWidget*>(_currentObj);
574 _onSelectionChanged( sel, aListWidget );
578 bool MyBasicGUI_PointDlg::apply(QModelIndex& result)
580 PatternGeomSelectionModel* pgsm = getPatternGeomSelectionModel();
581 PatternDataSelectionModel* pdsm = getPatternDataSelectionModel();
582 PatternDataModel* pdm = getPatternDataModel();
583 DocumentModel* docModel = getDocumentModel();
585 // get the selected vertex in the vtk view
586 QVariant v = mainFrame()->_vertex_le->property("QModelIndex");
589 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE VERTEX ASSOCIATION" ) );
592 QModelIndex iVertex = pdm->mapToSource( v.value<QModelIndex>() );
594 // get the selected vertex in the geometry (occ view)
595 TopoDS_Vertex geomVertex = computeGeomVertex();
598 if (!iVertex.isValid() || geomVertex.IsNull())
600 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE VERTEX ASSOCIATION" ) );
605 gp_Pnt aPnt = BRep_Tool::Pnt(geomVertex);
606 if (!docModel->setVertexAssociation(iVertex, aPnt.X(), aPnt.Y(), aPnt.Z()))
608 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE VERTEX ASSOCIATION" ) );
612 // * update data in the occ view and the geom tree
613 HEXABLOCKGUI::currentOccGView->addVertexToCloud(geomVertex);
614 docModel->updateGeomTree();
616 // highlight associated items
617 QModelIndex iGeomVertex = docModel->getVertexAssociation(iVertex);
618 QModelIndexList list1, list2;
619 result = v.value<QModelIndex>();
621 list2 << iGeomVertex;
622 pdsm->highlightTreeItems(list1); // data tree
623 pgsm->highlightTreeItems(list2); // geom tree
625 _updateCurrentObject(NULL);
626 HEXABLOCKGUI::currentOccGView->setSelectionMode(TopAbs_VERTEX);
627 HEXABLOCKGUI::currentDocGView->highlight(list1); // vtk view
628 HEXABLOCKGUI::currentOccGView->highlight(list1); // occ view
634 void MyBasicGUI_PointDlg::onXCoordChanged(double newValue)
636 int constructorId = getConstructorId();
637 if (constructorId != GEOM_POINT_XYZ && constructorId != GEOM_POINT_EDGE &&
638 constructorId != GEOM_POINT_SURF)
640 coordsInputValue[constructorId]->setX(newValue);
643 void MyBasicGUI_PointDlg::onYCoordChanged(double newValue)
645 int constructorId = getConstructorId();
646 if (constructorId != GEOM_POINT_XYZ && constructorId != GEOM_POINT_EDGE &&
647 constructorId != GEOM_POINT_SURF)
649 coordsInputValue[constructorId]->setY(newValue);
652 void MyBasicGUI_PointDlg::onZCoordChanged(double newValue)
654 int constructorId = getConstructorId();
655 if (constructorId != GEOM_POINT_XYZ && constructorId != GEOM_POINT_EDGE &&
656 constructorId != GEOM_POINT_SURF)
658 coordsInputValue[constructorId]->setZ(newValue);
662 void MyBasicGUI_PointDlg::onUpdateResults(const QString& data)
664 if (getConstructorId() == GEOM_POINT_XYZ)
667 // * compute the geom vertex
668 TopoDS_Vertex vertex = computeGeomVertex(true);
678 gp_Pnt pnt = BRep_Tool::Pnt(vertex);
679 myX->setText(MyDlgRef::PrintDoubleValue(pnt.X(), 6));
680 myY->setText(MyDlgRef::PrintDoubleValue(pnt.Y(), 6));
681 myZ->setText(MyDlgRef::PrintDoubleValue(pnt.Z(), 6));
684 TopoDS_Vertex MyBasicGUI_PointDlg::computeGeomVertex(bool preview)
686 TopoDS_Vertex vertex;
687 int constructorId = getConstructorId();
689 //display an emply vertex to erase the current preview
690 HEXABLOCKGUI::currentOccGView->displayPreview(vertex);
693 switch (constructorId) {
695 vertex = computeGeomPointXYZ();
698 vertex = computeGeomPointRef();
700 case GEOM_POINT_EDGE:
701 vertex = computeGeomPointEdge();
703 case GEOM_POINT_INTINT:
704 vertex = computeGeomPointInt();
706 case GEOM_POINT_SURF:
707 vertex = computeGeomPointSurf();
713 // * display preview of computed point
715 HEXABLOCKGUI::currentOccGView->displayPreview(vertex);
720 TopoDS_Vertex MyBasicGUI_PointDlg::computeGeomPointXYZ()
722 TopoDS_Vertex vertex;
724 if (getConstructorId() != GEOM_POINT_XYZ)
728 double x = GroupXYZ->SpinBox_DX->value();
729 double y = GroupXYZ->SpinBox_DY->value();
730 double z = GroupXYZ->SpinBox_DZ->value();
732 // - compute the resulting vertex
733 vertex = makePoint(x, y, z);
738 TopoDS_Vertex MyBasicGUI_PointDlg::computeGeomPointRef()
740 TopoDS_Vertex vertex;
742 if (getConstructorId() != GEOM_POINT_REF)
745 // get parameters from widgets
746 double dx = GroupRefPoint->SpinBox_DX->value();
747 double dy = GroupRefPoint->SpinBox_DY->value();
748 double dz = GroupRefPoint->SpinBox_DZ->value();
750 QVariant v = GroupRefPoint->LineEdit1->property("TopoDS_Shape");
753 TopoDS_Shape shape = v.value<TopoDS_Shape>();
755 // compute the resulting point
756 vertex = makePointWithReference(shape, dx, dy, dz);
761 TopoDS_Vertex MyBasicGUI_PointDlg::computeGeomPointEdge()
763 TopoDS_Vertex vertex;
765 if (getConstructorId() != GEOM_POINT_EDGE)
768 // * get inputs values
771 QVariant v1 = GroupOnCurve->LineEdit1->property("TopoDS_Shape");
774 TopoDS_Shape edgeShape = v1.value<TopoDS_Shape>();
776 bool isParam = myParamCoord->checkedId() == PARAM_VALUE;
777 bool isLength = myParamCoord->checkedId() == LENGTH_VALUE;
778 bool isCoord = myParamCoord->checkedId() == COORD_VALUE;
782 double param = GroupOnCurve->SpinBox_DX->value();
784 // - compute the resulting vertex
785 vertex = makePointOnCurve(edgeShape, param);
789 // - the starting point
790 QVariant v2 = GroupOnCurve->LineEdit2->property("TopoDS_Shape");
793 TopoDS_Shape pointShape = v2.value<TopoDS_Shape>();
796 double length = GroupOnCurve->SpinBox_DX->value();
798 // - compute the resulting vertex
799 vertex = makePointOnCurveByLength(edgeShape, pointShape,length);
804 double x = GroupXYZ->SpinBox_DX->value();
805 double y = GroupXYZ->SpinBox_DY->value();
806 double z = GroupXYZ->SpinBox_DZ->value();
808 // - compute the resulting vertex
809 vertex = makePointOnCurveByCoord(edgeShape, x, y, z);
815 TopoDS_Vertex MyBasicGUI_PointDlg::computeGeomPointInt()
817 TopoDS_Vertex vertex;
819 if (getConstructorId() != GEOM_POINT_INTINT)
824 // * get inputs values
827 v = GroupLineIntersection->LineEdit1->property("TopoDS_Shape");
830 TopoDS_Shape line1 = v.value<TopoDS_Shape>();
833 v = GroupLineIntersection->LineEdit2->property("TopoDS_Shape");
836 TopoDS_Shape line2 = v.value<TopoDS_Shape>();
838 // * compute the resulting vertex
839 vertex = makePointOnLinesIntersection(line1, line2);
844 TopoDS_Vertex MyBasicGUI_PointDlg::computeGeomPointSurf()
846 TopoDS_Vertex vertex;
848 if (getConstructorId() != GEOM_POINT_SURF)
851 // * get inputs values
854 QVariant v = GroupOnSurface->LineEdit1->property("TopoDS_Shape");
857 TopoDS_Shape faceShape = v.value<TopoDS_Shape>();
859 bool isParam = myParamCoord->checkedId() == PARAM_VALUE;
860 bool isCoord = myParamCoord->checkedId() == COORD_VALUE;
864 double param_u = GroupOnSurface->SpinBox_DX->value();
865 double param_v = GroupOnSurface->SpinBox_DY->value();
867 // - compute the resulting vertex
868 vertex = makePointOnSurface(faceShape, param_u, param_v);
873 double x = GroupXYZ->SpinBox_DX->value();
874 double y = GroupXYZ->SpinBox_DY->value();
875 double z = GroupXYZ->SpinBox_DZ->value();
877 // - compute the resulting vertex
878 vertex = makePointOnSurfaceByCoord(faceShape, x, y, z);
884 //=================================================================================
885 // function : OnPointSelected
887 //=================================================================================
888 void MyBasicGUI_PointDlg::OnPointSelected(const gp_Pnt& thePnt)
890 if (getConstructorId() == GEOM_POINT_XYZ) {
891 GroupXYZ->SpinBox_DX->setValue(thePnt.X());
892 GroupXYZ->SpinBox_DY->setValue(thePnt.Y());
893 GroupXYZ->SpinBox_DZ->setValue(thePnt.Z());
897 void MyBasicGUI_PointDlg::updateInputs(const int constructorId)
900 QVector3D* coords = NULL;
902 switch (constructorId) {
903 case GEOM_POINT_XYZ :
904 coords = coordsInputValue[GEOM_POINT_XYZ];
908 case GEOM_POINT_EDGE:
909 coords = coordsInputValue[GEOM_POINT_EDGE];
910 updateParamCoord(true);
912 case GEOM_POINT_INTINT:
914 case GEOM_POINT_SURF:
915 coords = coordsInputValue[GEOM_POINT_SURF];
916 updateParamCoord(true);
924 GroupXYZ->SpinBox_DX->setValue(coords->x());
925 GroupXYZ->SpinBox_DY->setValue(coords->y());
926 GroupXYZ->SpinBox_DZ->setValue(coords->z());
929 onUpdateResults(str);
932 //=================================================================================
933 // function : ClickParamCoord()
935 //=================================================================================
936 void MyBasicGUI_PointDlg::ClickParamCoord(int id)
938 updateInputs(getConstructorId());
941 //=================================================================================
942 // function : updateParamCoord
944 //=================================================================================
945 void MyBasicGUI_PointDlg::updateParamCoord(bool theIsUpdate)
947 bool isParam = myParamCoord->checkedId() == PARAM_VALUE;
948 bool isLength = myParamCoord->checkedId() == LENGTH_VALUE;
950 const int id = getConstructorId();
951 if (id == GEOM_POINT_EDGE) {
952 GroupOnCurve->TextLabel2->setVisible(isLength);
953 GroupOnCurve->LineEdit2->setVisible(isLength);
954 GroupOnCurve->TextLabel3->setVisible(isParam || isLength);
955 GroupOnCurve->SpinBox_DX->setVisible(isParam || isLength);
957 GroupOnCurve->TextLabel3->setText(tr("GEOM_PARAMETER"));
958 double value = paramInputValue[PARAM_VALUE];
959 GroupOnCurve->SpinBox_DX->setValue(0.5);
960 initSpinBox(GroupOnCurve->SpinBox_DX, 0., 1.);
961 GroupOnCurve->SpinBox_DX->setValue(value);
964 GroupOnCurve->TextLabel3->setText(tr("GEOM_LENGTH"));
965 double value = paramInputValue[LENGTH_VALUE];
966 GroupOnCurve->SpinBox_DX->setValue(0.5);
967 initSpinBox(GroupOnCurve->SpinBox_DX, COORD_MIN, COORD_MAX);
968 GroupOnCurve->SpinBox_DX->setValue(value);
971 else if (id == GEOM_POINT_SURF) {
972 GroupOnSurface->TextLabel2->setVisible(isParam);
973 GroupOnSurface->TextLabel3->setVisible(isParam);
974 GroupOnSurface->SpinBox_DX->setVisible(isParam);
975 GroupOnSurface->SpinBox_DY->setVisible(isParam);
978 GroupXYZ->setVisible(!isParam && !isLength);
981 //=================================================================================
982 // function : onBtnPopup()
984 //=================================================================================
985 void MyBasicGUI_PointDlg::onBtnPopup(QAction* a)
987 if (a == action_line1_edge)
989 GroupLineIntersection->LineEdit1->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_EDGE) );
990 GroupLineIntersection->LineEdit1->setFocus();
991 GroupLineIntersection->PushButton2->setDown(false);
993 else if (a == action_line1_wire)
995 GroupLineIntersection->LineEdit1->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_WIRE) );
996 GroupLineIntersection->LineEdit1->setFocus();
997 GroupLineIntersection->PushButton2->setDown(false);
999 else if (a == action_line2_edge)
1001 GroupLineIntersection->LineEdit2->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_EDGE) );
1002 GroupLineIntersection->LineEdit2->setFocus();
1003 GroupLineIntersection->PushButton1->setDown(false);
1005 else if (a == action_line2_wire)
1007 GroupLineIntersection->LineEdit2->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_WIRE) );
1008 GroupLineIntersection->LineEdit2->setFocus();
1009 GroupLineIntersection->PushButton1->setDown(false);
1013 //=================================================================================
1014 // function : updateSize
1015 // purpose : adjust dialog size to minimum
1016 //=================================================================================
1017 void MyBasicGUI_PointDlg::updateSize()
1019 qApp->processEvents();
1021 resize(minimumSizeHint());
1024 void MyBasicGUI_PointDlg::clear()
1026 mainFrame()->_vertex_le->clear();
1027 modelUnregister(mainFrame()->_vertex_le);
1029 GroupRefPoint->LineEdit1->clear();
1030 GroupRefPoint->LineEdit1->setProperty("TopoDS_Shape", QVariant());
1031 GroupRefPoint->LineEdit1->setProperty("QModelIndex", QVariant());
1032 GroupRefPoint->LineEdit1->setProperty("HexaData", QVariant());
1034 GroupOnCurve->LineEdit1->clear();
1035 GroupOnCurve->LineEdit1->setProperty("TopoDS_Shape", QVariant());
1036 GroupOnCurve->LineEdit1->setProperty("QModelIndex", QVariant());
1037 GroupOnCurve->LineEdit1->setProperty("HexaData", QVariant());
1039 GroupOnCurve->LineEdit2->clear();
1040 GroupOnCurve->LineEdit2->setProperty("TopoDS_Shape", QVariant());
1041 GroupOnCurve->LineEdit2->setProperty("QModelIndex", QVariant());
1042 GroupOnCurve->LineEdit2->setProperty("HexaData", QVariant());
1044 GroupLineIntersection->LineEdit1->clear();
1045 GroupLineIntersection->LineEdit1->setProperty("TopoDS_Shape", QVariant());
1046 GroupLineIntersection->LineEdit1->setProperty("QModelIndex", QVariant());
1047 GroupLineIntersection->LineEdit1->setProperty("HexaData", QVariant());
1049 GroupLineIntersection->LineEdit2->clear();
1050 GroupLineIntersection->LineEdit2->setProperty("TopoDS_Shape", QVariant());
1051 GroupLineIntersection->LineEdit2->setProperty("QModelIndex", QVariant());
1052 GroupLineIntersection->LineEdit2->setProperty("HexaData", QVariant());
1054 GroupOnSurface->LineEdit1->clear();
1055 GroupOnSurface->LineEdit1->setProperty("TopoDS_Shape", QVariant());
1056 GroupOnSurface->LineEdit1->setProperty("QModelIndex", QVariant());
1057 GroupOnSurface->LineEdit1->setProperty("HexaData", QVariant());
1059 modelUnregister(this);
1063 void MyBasicGUI_PointDlg::onWindowActivated(SUIT_ViewManager* vm)
1065 QString vmType = vm->getType();
1066 if ( ((vmType == SVTK_Viewer::Type()) || (vmType == VTKViewer_Viewer::Type())) &&
1067 !mainFrame()->RadioButton4->isChecked() &&
1068 !myParamCoord->button(LENGTH_VALUE)->isChecked() )
1069 mainFrame()->_vertex_le->setFocus();
1070 else if ( vmType == OCCViewer_Viewer::Type() ){
1071 if (mainFrame()->RadioButton1->isChecked())
1072 // Make the field "Vertex of the model" lose the focus
1073 mainFrame()->RadioButton1->click();
1074 else if (mainFrame()->RadioButton2->isChecked())
1075 GroupRefPoint->LineEdit1->setFocus();
1076 else if (mainFrame()->RadioButton3->isChecked() &&
1077 !myParamCoord->button(LENGTH_VALUE)->isChecked())
1078 GroupOnCurve->LineEdit1->setFocus();
1079 else if (mainFrame()->RadioButton5->isChecked())
1080 GroupOnSurface->LineEdit1->setFocus();