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"
29 #include <GEOMImpl_Types.hxx>
31 #include <QApplication>
32 #include <QButtonGroup>
33 #include <QHBoxLayout>
35 #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);
119 QRadioButton* btn = new QRadioButton(tr("By Param"), myParamGroup);
120 myParamCoord->addButton(btn, PARAM_VALUE);
121 boxLayout->addWidget(btn);
122 btn = new QRadioButton(tr("By Length"), myParamGroup);
123 myParamCoord->addButton(btn, LENGTH_VALUE);
124 boxLayout->addWidget(btn);
125 btn = new QRadioButton(tr("By Coords"), myParamGroup);
126 myParamCoord->addButton(btn, COORD_VALUE);
127 boxLayout->addWidget(btn);
128 myParamCoord->setExclusive(true);
129 myParamCoord->button(PARAM_VALUE)->setChecked(true);
131 GroupXYZ = new DlgRef_3Spin(centralWidget());
132 GroupXYZ->GroupBox1->setTitle(tr("GEOM_COORDINATES"));
133 GroupXYZ->TextLabel1->setText(tr("GEOM_X"));
134 GroupXYZ->TextLabel2->setText(tr("GEOM_Y"));
135 GroupXYZ->TextLabel3->setText(tr("GEOM_Z"));
136 coordsInputValue[GEOM_POINT_XYZ] = new QVector3D(0, 0, 0);
137 coordsInputValue[GEOM_POINT_EDGE] = new QVector3D(0, 0, 0);
138 coordsInputValue[GEOM_POINT_SURF] = new QVector3D(0, 0, 0);
140 GroupOnCurve = new DlgRef_2Sel1Spin(centralWidget());
141 GroupOnCurve->GroupBox1->setTitle(tr("GEOM_POINT_ON_EDGE"));
142 GroupOnCurve->TextLabel1->setText(tr("GEOM_EDGE"));
143 GroupOnCurve->TextLabel2->setText(tr("GEOM_START_POINT"));
144 GroupOnCurve->TextLabel3->setText(tr("GEOM_PARAMETER"));
145 paramInputValue[PARAM_VALUE] = 0.5;
146 paramInputValue[LENGTH_VALUE] = 0.5;
148 GroupOnSurface = new DlgRef_1Sel2Spin(centralWidget());
149 GroupOnSurface->GroupBox1->setTitle(tr("GEOM_POINT_ON_FACE"));
150 GroupOnSurface->TextLabel1->setText(tr("GEOM_FACE"));
151 GroupOnSurface->TextLabel2->setText(tr("GEOM_UPARAMETER"));
152 GroupOnSurface->TextLabel3->setText(tr("GEOM_VPARAMETER"));
154 GroupRefPoint = new DlgRef_1Sel3Spin(centralWidget());
155 GroupRefPoint->GroupBox1->setTitle(tr("GEOM_REF_POINT"));
156 GroupRefPoint->TextLabel1->setText(tr("GEOM_POINT"));
157 GroupRefPoint->TextLabel2->setText(tr("GEOM_DX"));
158 GroupRefPoint->TextLabel3->setText(tr("GEOM_DY"));
159 GroupRefPoint->TextLabel4->setText(tr("GEOM_DZ"));
161 /* popup menu for line intersect buttons */
162 QIcon ico_line = QIcon(image6);
163 QIcon ico_wire = QIcon(image7);
165 myBtnPopup = new QMenu(this);
166 action_line1_edge = myBtnPopup->addAction(ico_line, tr("GEOM_EDGE"));
167 action_line1_wire = myBtnPopup->addAction(ico_wire, tr("GEOM_WIRE"));
170 myBtnPopup2 = new QMenu(this);
171 action_line2_edge = myBtnPopup2->addAction(ico_line, tr("GEOM_EDGE"));
172 action_line2_wire = myBtnPopup2->addAction(ico_wire, tr("GEOM_WIRE"));
174 GroupLineIntersection = new DlgRef_2Sel(centralWidget());
175 GroupLineIntersection->GroupBox1->setTitle(tr("GEOM_LINE_INTERSECTION"));
176 GroupLineIntersection->TextLabel1->setText(tr("GEOM_LINE1"));
177 GroupLineIntersection->TextLabel2->setText(tr("GEOM_LINE2"));
178 GroupLineIntersection->PushButton1->setIcon(image2);
179 GroupLineIntersection->PushButton1->setMenu(myBtnPopup);
180 GroupLineIntersection->PushButton2->setIcon(image2);
181 GroupLineIntersection->PushButton2->setMenu(myBtnPopup2);
183 myCoordGrp = new QGroupBox(tr("GEOM_COORDINATES_RES"), centralWidget());
184 QGridLayout* myCoordGrpLayout = new QGridLayout(myCoordGrp);
185 myCoordGrpLayout->addWidget(new QLabel(tr("GEOM_X"), myCoordGrp), 0, 0);
186 myX = new QLineEdit(myCoordGrp);
187 myCoordGrpLayout->addWidget(myX, 0, 1);
188 myCoordGrpLayout->addWidget(new QLabel(tr("GEOM_Y"), myCoordGrp), 1, 0);
189 myY = new QLineEdit(myCoordGrp);
190 myCoordGrpLayout->addWidget(myY, 1, 1);
191 myCoordGrpLayout->addWidget(new QLabel(tr("GEOM_Z"), myCoordGrp), 2, 0);
192 myZ = new QLineEdit(myCoordGrp);
193 myCoordGrpLayout->addWidget(myZ, 2, 1);
195 QVBoxLayout* layout = new QVBoxLayout(centralWidget());
196 layout->setMargin(0); layout->setSpacing(6);
197 layout->addWidget(myParamGroup);
198 layout->addWidget(GroupXYZ);
199 layout->addWidget(GroupOnCurve);
200 layout->addWidget(GroupOnSurface);
201 layout->addWidget(GroupRefPoint);
202 layout->addWidget(GroupLineIntersection);
203 layout->addWidget(myCoordGrp);
205 myX->setReadOnly(true);
206 myY->setReadOnly(true);
207 myZ->setReadOnly(true);
209 myX->setEnabled(false);
210 myY->setEnabled(false);
211 myZ->setEnabled(false);
213 QPalette aPal = myX->palette();
214 aPal.setColor(QPalette::Disabled, QPalette::Text, QColor(0, 0, 0));
215 myX->setPalette(aPal);
216 myY->setPalette(aPal);
217 myZ->setPalette(aPal);
219 _helpFileName = "gui_asso_quad_to_geom.html#associate-to-a-vertex-of-the-geometry";
220 _initWidget( _editMode );
221 mainFrame()->RadioButton1->click();
224 //=================================================================================
225 // function : ~MyBasicGUI_PointDlg()
226 // purpose : Destructor
227 //=================================================================================
228 MyBasicGUI_PointDlg::~MyBasicGUI_PointDlg()
232 void MyBasicGUI_PointDlg::_initInputWidget( HexaBaseDialog::Mode editmode )
234 // *** Init input widgets ***/
235 initSpinBox(GroupXYZ->SpinBox_DX, COORD_MIN, COORD_MAX);
236 initSpinBox(GroupXYZ->SpinBox_DY, COORD_MIN, COORD_MAX);
237 initSpinBox(GroupXYZ->SpinBox_DZ, COORD_MIN, COORD_MAX);
238 GroupXYZ->SpinBox_DX->setValue(0.0);
239 GroupXYZ->SpinBox_DY->setValue(0.0);
240 GroupXYZ->SpinBox_DZ->setValue(0.0);
242 initSpinBox(GroupRefPoint->SpinBox_DX, COORD_MIN, COORD_MAX);
243 initSpinBox(GroupRefPoint->SpinBox_DY, COORD_MIN, COORD_MAX);
244 initSpinBox(GroupRefPoint->SpinBox_DZ, COORD_MIN, COORD_MAX);
245 GroupRefPoint->SpinBox_DX->setValue(0.0);
246 GroupRefPoint->SpinBox_DY->setValue(0.0);
247 GroupRefPoint->SpinBox_DZ->setValue(0.0);
249 initSpinBox(GroupOnCurve->SpinBox_DX, 0., 1.);
250 GroupOnCurve->SpinBox_DX->setValue(paramInputValue[PARAM_VALUE]);
252 initSpinBox(GroupOnSurface->SpinBox_DX, 0., 1.);
253 GroupOnSurface->SpinBox_DX->setValue(0.5);
254 initSpinBox(GroupOnSurface->SpinBox_DY, 0., 1.);
255 GroupOnSurface->SpinBox_DY->setValue(0.5);
257 // * vtk input widget
258 mainFrame()->_vertex_le->setReadOnly(true);
259 mainFrame()->_vertex_le->setProperty( "HexaWidgetType", QVariant::fromValue(HEXABLOCK::GUI::VERTEX_TREE) );
260 mainFrame()->_vertex_le->installEventFilter(this);
262 // * geom input widgets
264 GroupRefPoint->LineEdit1->setReadOnly(true);
265 GroupRefPoint->LineEdit1->setProperty( "HexaWidgetType", QVariant::fromValue(GEOMPOINT_TREE) );
266 GroupRefPoint->LineEdit1->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_VERTEX) );
267 GroupRefPoint->LineEdit1->installEventFilter(this);
271 GroupOnCurve->LineEdit1->setReadOnly(true);
272 GroupOnCurve->LineEdit1->setProperty( "HexaWidgetType", QVariant::fromValue(GEOMEDGE_TREE) );
273 GroupOnCurve->LineEdit1->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_EDGE) );
274 GroupOnCurve->LineEdit1->installEventFilter(this);
277 GroupOnCurve->LineEdit2->setReadOnly(true);
278 GroupOnCurve->LineEdit2->setProperty( "HexaWidgetType", QVariant::fromValue(GEOMPOINT_TREE) );
279 GroupOnCurve->LineEdit2->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_VERTEX) );
280 GroupOnCurve->LineEdit2->installEventFilter(this);
282 // point of 2 lines intersection
284 GroupLineIntersection->LineEdit1->setReadOnly(true);
285 GroupLineIntersection->LineEdit1->setProperty( "HexaWidgetType", QVariant::fromValue(GEOMEDGE_TREE) );
286 GroupLineIntersection->LineEdit1->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_EDGE) );
287 GroupLineIntersection->LineEdit1->installEventFilter(this);
290 GroupLineIntersection->LineEdit2->setReadOnly(true);
291 GroupLineIntersection->LineEdit2->setProperty( "HexaWidgetType", QVariant::fromValue(GEOMEDGE_TREE) );
292 GroupLineIntersection->LineEdit2->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_EDGE) );
293 GroupLineIntersection->LineEdit2->installEventFilter(this);
296 GroupOnSurface->LineEdit1->setReadOnly(true);
297 GroupOnSurface->LineEdit1->setProperty( "HexaWidgetType", QVariant::fromValue(GEOMFACE_TREE) );
298 GroupOnSurface->LineEdit1->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_FACE) );
299 GroupOnSurface->LineEdit1->installEventFilter(this);
302 connect(this, SIGNAL(constructorsClicked(int)), this, SLOT(ConstructorsClicked(int)));
303 connect(myParamCoord, SIGNAL(buttonClicked(int)), this, SLOT(ClickParamCoord(int)));
304 connect(myBtnPopup, SIGNAL(triggered(QAction*)), this, SLOT(onBtnPopup(QAction*)));
305 connect(myBtnPopup2, SIGNAL(triggered(QAction*)), this, SLOT(onBtnPopup(QAction*)));
308 connect(GroupRefPoint->LineEdit1, SIGNAL( textChanged(const QString&) ), this, SLOT(onUpdateResults(const QString&)));
311 connect(GroupOnCurve->LineEdit1, SIGNAL( textChanged(const QString&) ), this, SLOT(onUpdateResults(const QString&)));
312 connect(GroupOnCurve->LineEdit2, SIGNAL( textChanged(const QString&) ), this, SLOT(onUpdateResults(const QString&)));
314 connect(GroupOnCurve->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(onParamValueChanged(double)));
315 connect(GroupOnCurve->SpinBox_DX, SIGNAL(valueChanged(const QString&)), this, SLOT(onUpdateResults(const QString&)));
317 // intersection point
318 connect(GroupLineIntersection->LineEdit1, SIGNAL( textChanged(const QString&) ), this, SLOT(onUpdateResults(const QString&)));
319 connect(GroupLineIntersection->LineEdit2, SIGNAL( textChanged(const QString&) ), this, SLOT(onUpdateResults(const QString&)));
322 connect(GroupOnSurface->SpinBox_DX, SIGNAL(valueChanged(const QString&)), this, SLOT(onUpdateResults(const QString&)));
323 connect(GroupOnSurface->SpinBox_DY, SIGNAL(valueChanged(const QString&)), this, SLOT(onUpdateResults(const QString&)));
324 connect(GroupOnSurface->LineEdit1, SIGNAL( textChanged(const QString&) ), this, SLOT(onUpdateResults(const QString&))); //surface: Face
327 connect(GroupXYZ->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(onXCoordChanged(double)));
328 connect(GroupXYZ->SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(onYCoordChanged(double)));
329 connect(GroupXYZ->SpinBox_DZ, SIGNAL(valueChanged(double)), this, SLOT(onZCoordChanged(double)));
331 connect(GroupXYZ->SpinBox_DX, SIGNAL(valueChanged(const QString&)), this, SLOT(onUpdateResults(const QString&)));
332 connect(GroupXYZ->SpinBox_DY, SIGNAL(valueChanged(const QString&)), this, SLOT(onUpdateResults(const QString&)));
333 connect(GroupXYZ->SpinBox_DZ, SIGNAL(valueChanged(const QString&)), this, SLOT(onUpdateResults(const QString&)));
336 connect(GroupRefPoint->SpinBox_DX, SIGNAL(valueChanged(const QString&)), this, SLOT(onUpdateResults(const QString&)));
337 connect(GroupRefPoint->SpinBox_DY, SIGNAL(valueChanged(const QString&)), this, SLOT(onUpdateResults(const QString&)));
338 connect(GroupRefPoint->SpinBox_DZ, SIGNAL(valueChanged(const QString&)), this, SLOT(onUpdateResults(const QString&)));
341 connect( mainFrame()->RadioButton1, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
342 connect( mainFrame()->RadioButton2, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
343 connect( mainFrame()->RadioButton3, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
344 connect( mainFrame()->RadioButton4, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
345 connect( mainFrame()->RadioButton5, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
347 connect( mainFrame()->RadioButton1, SIGNAL(clicked()), this, SLOT( refreshHighlight()) );
348 connect( mainFrame()->RadioButton2, SIGNAL(clicked()), this, SLOT(refreshHighlight()) );
349 connect( mainFrame()->RadioButton1, SIGNAL(clicked()), this, SLOT( refreshHighlight()) );
350 connect( mainFrame()->RadioButton2, SIGNAL(clicked()), this, SLOT(refreshHighlight()) );
351 connect( mainFrame()->RadioButton1, SIGNAL(clicked()), this, SLOT( refreshHighlight()) );
353 connect( myParamCoord->button(PARAM_VALUE), SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
354 connect( myParamCoord->button(LENGTH_VALUE), SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
355 connect( myParamCoord->button(COORD_VALUE), SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
359 void MyBasicGUI_PointDlg::showEvent ( QShowEvent * event )
361 HexaBaseDialog::showEvent(event);
362 if (getConstructorId() == GEOM_POINT_XYZ)
363 HEXABLOCKGUI::currentOccGView->setSelectionMode(TopAbs_VERTEX);
365 //===============================================================
366 // function : updateHelpFileName()
367 // purpose : update the help file according to the current panel
368 //===============================================================
369 void MyBasicGUI_PointDlg::updateHelpFileName()
371 if ( sender() == mainFrame()->RadioButton1 ){
372 _helpFileName = "gui_asso_quad_to_geom.html#associate-to-a-vertex-of-the-geometry";
373 } else if ( sender() == mainFrame()->RadioButton2 ){
374 _helpFileName = "gui_asso_vertex_to_geom.html#by-a-reference";
375 } else if ( sender() == mainFrame()->RadioButton3 ){
376 _helpFileName = "gui_asso_vertex_to_geom.html#by-an-edge-and-a-parameter";
377 } else if ( sender() == mainFrame()->RadioButton4 ){
378 _helpFileName = "gui_asso_vertex_to_geom.html#by-intersection-of-two-lines-or-wires";
379 } else if ( sender() == mainFrame()->RadioButton5 ){
380 _helpFileName = "gui_asso_vertex_to_geom.html#by-a-face-and-two-parameters";
381 } else if (sender() == myParamCoord->button(PARAM_VALUE)){
382 if (mainFrame()->RadioButton3->isChecked()){
383 _helpFileName = "gui_asso_vertex_to_geom.html#by-an-edge-and-a-parameter";
384 } else if (mainFrame()->RadioButton5->isChecked()){
385 _helpFileName = "gui_asso_vertex_to_geom.html#by-a-face-and-two-parameters";
387 } else if (sender() == myParamCoord->button(LENGTH_VALUE)){
388 _helpFileName = "gui_asso_vertex_to_geom.html#by-an-edge-and-a-length";
389 } else if (sender() == myParamCoord->button(COORD_VALUE)){
390 if (mainFrame()->RadioButton3->isChecked()){
391 _helpFileName = "gui_asso_vertex_to_geom.html#by-an-edge-and-coordinates";
392 } else if (mainFrame()->RadioButton5->isChecked()){
393 _helpFileName = "gui_asso_vertex_to_geom.html#by-a-face-and-coordinates";
398 //=================================================================================
399 // function : SetDoubleSpinBoxStep()
400 // purpose : Double spin box management
401 //=================================================================================
402 void MyBasicGUI_PointDlg::SetDoubleSpinBoxStep(double step)
404 GroupOnCurve->SpinBox_DX->setSingleStep(step);
405 GroupXYZ->SpinBox_DX->setSingleStep(step);
406 GroupXYZ->SpinBox_DY->setSingleStep(step);
407 GroupXYZ->SpinBox_DZ->setSingleStep(step);
408 GroupRefPoint->SpinBox_DX->setSingleStep(step);
409 GroupRefPoint->SpinBox_DY->setSingleStep(step);
410 GroupRefPoint->SpinBox_DZ->setSingleStep(step);
414 //=================================================================================
415 // function : ConstructorsClicked()
416 // purpose : Radio button management
417 //=================================================================================
418 void MyBasicGUI_PointDlg::ConstructorsClicked(int constructorId)
423 switch (constructorId) {
426 HEXABLOCKGUI::currentOccGView->setSelectionMode(TopAbs_VERTEX);
427 GroupRefPoint->hide();
428 GroupOnCurve->hide();
429 GroupLineIntersection->hide();
430 GroupOnSurface->hide();
432 myParamGroup->hide();
438 myParamGroup->hide();
440 GroupOnCurve->hide();
441 GroupLineIntersection->hide();
442 GroupOnSurface->hide();
443 GroupRefPoint->show();
447 case GEOM_POINT_EDGE:
449 GroupRefPoint->hide();
450 GroupLineIntersection->hide();
451 GroupOnSurface->hide();
452 myParamGroup->show();
453 myParamCoord->button(LENGTH_VALUE)->show();
454 myParamCoord->button(PARAM_VALUE)->setChecked(true);
455 GroupOnCurve->show();
457 updateParamCoord(false);
460 case GEOM_POINT_INTINT:
462 myParamGroup->hide();
464 GroupRefPoint->hide();
465 GroupOnCurve->hide();
466 GroupOnSurface->hide();
468 GroupLineIntersection->show();
471 case GEOM_POINT_SURF:
473 GroupRefPoint->hide();
474 GroupOnCurve->hide();
475 GroupLineIntersection->hide();
476 myParamGroup->show();
477 myParamCoord->button(LENGTH_VALUE)->hide();
478 myParamCoord->button(PARAM_VALUE)->setChecked(true);
479 GroupOnSurface->show();
481 updateParamCoord(false);
486 updateInputs(constructorId);
489 //=================================================================================
490 // funcion : getParameter()
492 //=================================================================================
493 double MyBasicGUI_PointDlg::getParameter() const
495 return GroupOnCurve->SpinBox_DX->value();
498 //=================================================================================
499 // funcion : getUParameter()
501 //=================================================================================
502 double MyBasicGUI_PointDlg::getUParameter() const
504 return GroupOnSurface->SpinBox_DX->value();
507 //=================================================================================
508 // funcion : getVParameter()
510 //=================================================================================
511 double MyBasicGUI_PointDlg::getVParameter() const
513 return GroupOnSurface->SpinBox_DY->value();
516 void MyBasicGUI_PointDlg::onParamValueChanged(double newValue)
518 if (getConstructorId() == GEOM_POINT_EDGE)
519 paramInputValue[myParamCoord->checkedId()] = newValue;
522 // ============================================================== onSelectionChanged
524 * Puts elements selected in the model in the corresponding widget (list widget or line edit)
525 * of the current dialog box.
527 void MyBasicGUI_PointDlg::onSelectionChanged( const QItemSelection& sel, const QItemSelection& unsel )
529 QModelIndexList l = sel.indexes();
533 QModelIndex selected = l[0];
534 int selectedType = selected.data(HEXA_TREE_ROLE).toInt();
535 // fill the coordinates of the selected point
536 if ( getConstructorId() == GEOM_POINT_XYZ && selectedType == GEOMPOINT_TREE)
538 DocumentModel::GeomObj* geomObj = getGeomObj(selected);
542 DocumentModel* docModel = getDocumentModel();
543 QString objId = geomObj->shapeName + "," + geomObj->subId;
544 HEXA_NS::SubShape* ssh = docModel->getGeomPtr(objId);
547 TopoDS_Shape shape = ssh->getShape();
548 if (shape.IsNull() || shape.ShapeType() != TopAbs_VERTEX)
550 TopoDS_Vertex vertex = TopoDS::Vertex(shape);
551 gp_Pnt pnt = BRep_Tool::Pnt(vertex);
552 OnPointSelected(pnt);
556 QLineEdit* aLineEdit = NULL;
557 QListWidget* aListWidget = NULL;
559 // * put selection in the current line edit
560 aLineEdit = dynamic_cast<QLineEdit*>(_currentObj);
561 if ( aLineEdit != NULL )
563 _onSelectionChanged( sel, aLineEdit );
567 // * put selection in the current list widget
568 aListWidget = dynamic_cast<QListWidget*>(_currentObj);
570 _onSelectionChanged( sel, aListWidget );
574 bool MyBasicGUI_PointDlg::apply(QModelIndex& result)
576 PatternGeomSelectionModel* pgsm = getPatternGeomSelectionModel();
577 PatternDataSelectionModel* pdsm = getPatternDataSelectionModel();
578 PatternDataModel* pdm = getPatternDataModel();
579 DocumentModel* docModel = getDocumentModel();
581 // get the selected vertex in the vtk view
582 QVariant v = mainFrame()->_vertex_le->property("QModelIndex");
585 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE VERTEX ASSOCIATION" ) );
588 QModelIndex iVertex = pdm->mapToSource( v.value<QModelIndex>() );
590 // get the selected vertex in the geometry (occ view)
591 TopoDS_Vertex geomVertex = computeGeomVertex();
594 if (!iVertex.isValid() || geomVertex.IsNull())
596 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE VERTEX ASSOCIATION" ) );
601 gp_Pnt aPnt = BRep_Tool::Pnt(geomVertex);
602 if (!docModel->setVertexAssociation(iVertex, aPnt.X(), aPnt.Y(), aPnt.Z()))
604 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE VERTEX ASSOCIATION" ) );
608 // * update data in the occ view and the geom tree
609 HEXABLOCKGUI::currentOccGView->addVertexToCloud(geomVertex);
610 docModel->updateGeomTree();
612 // highlight associated items
613 QModelIndex iGeomVertex = docModel->getVertexAssociation(iVertex);
614 QModelIndexList list1, list2;
615 result = v.value<QModelIndex>();
617 list2 << iGeomVertex;
618 pdsm->highlightTreeItems(list1); // data tree
619 pgsm->highlightTreeItems(list2); // geom tree
621 _updateCurrentObject(NULL);
622 HEXABLOCKGUI::currentOccGView->setSelectionMode(TopAbs_VERTEX);
623 HEXABLOCKGUI::currentDocGView->highlight(list1); // vtk view
624 HEXABLOCKGUI::currentOccGView->highlight(list1); // occ view
630 void MyBasicGUI_PointDlg::onXCoordChanged(double newValue)
632 int constructorId = getConstructorId();
633 if (constructorId != GEOM_POINT_XYZ && constructorId != GEOM_POINT_EDGE &&
634 constructorId != GEOM_POINT_SURF)
636 coordsInputValue[constructorId]->setX(newValue);
639 void MyBasicGUI_PointDlg::onYCoordChanged(double newValue)
641 int constructorId = getConstructorId();
642 if (constructorId != GEOM_POINT_XYZ && constructorId != GEOM_POINT_EDGE &&
643 constructorId != GEOM_POINT_SURF)
645 coordsInputValue[constructorId]->setY(newValue);
648 void MyBasicGUI_PointDlg::onZCoordChanged(double newValue)
650 int constructorId = getConstructorId();
651 if (constructorId != GEOM_POINT_XYZ && constructorId != GEOM_POINT_EDGE &&
652 constructorId != GEOM_POINT_SURF)
654 coordsInputValue[constructorId]->setZ(newValue);
658 void MyBasicGUI_PointDlg::onUpdateResults(const QString& data)
660 if (getConstructorId() == GEOM_POINT_XYZ)
663 // * compute the geom vertex
664 TopoDS_Vertex vertex = computeGeomVertex(true);
674 gp_Pnt pnt = BRep_Tool::Pnt(vertex);
675 myX->setText(DlgRef::PrintDoubleValue(pnt.X(), 6));
676 myY->setText(DlgRef::PrintDoubleValue(pnt.Y(), 6));
677 myZ->setText(DlgRef::PrintDoubleValue(pnt.Z(), 6));
680 TopoDS_Vertex MyBasicGUI_PointDlg::computeGeomVertex(bool preview)
682 TopoDS_Vertex vertex;
683 int constructorId = getConstructorId();
685 //display an emply vertex to erase the current preview
686 HEXABLOCKGUI::currentOccGView->displayPreview(vertex);
689 switch (constructorId) {
691 vertex = computeGeomPointXYZ();
694 vertex = computeGeomPointRef();
696 case GEOM_POINT_EDGE:
697 vertex = computeGeomPointEdge();
699 case GEOM_POINT_INTINT:
700 vertex = computeGeomPointInt();
702 case GEOM_POINT_SURF:
703 vertex = computeGeomPointSurf();
709 // * display preview of computed point
711 HEXABLOCKGUI::currentOccGView->displayPreview(vertex);
716 TopoDS_Vertex MyBasicGUI_PointDlg::computeGeomPointXYZ()
718 TopoDS_Vertex vertex;
720 if (getConstructorId() != GEOM_POINT_XYZ)
724 double x = GroupXYZ->SpinBox_DX->value();
725 double y = GroupXYZ->SpinBox_DY->value();
726 double z = GroupXYZ->SpinBox_DZ->value();
728 // - compute the resulting vertex
729 vertex = makePoint(x, y, z);
734 TopoDS_Vertex MyBasicGUI_PointDlg::computeGeomPointRef()
736 TopoDS_Vertex vertex;
738 if (getConstructorId() != GEOM_POINT_REF)
741 // get parameters from widgets
742 double dx = GroupRefPoint->SpinBox_DX->value();
743 double dy = GroupRefPoint->SpinBox_DY->value();
744 double dz = GroupRefPoint->SpinBox_DZ->value();
746 QVariant v = GroupRefPoint->LineEdit1->property("TopoDS_Shape");
749 TopoDS_Shape shape = v.value<TopoDS_Shape>();
751 // compute the resulting point
752 vertex = makePointWithReference(shape, dx, dy, dz);
757 TopoDS_Vertex MyBasicGUI_PointDlg::computeGeomPointEdge()
759 TopoDS_Vertex vertex;
761 if (getConstructorId() != GEOM_POINT_EDGE)
764 // * get inputs values
767 QVariant v1 = GroupOnCurve->LineEdit1->property("TopoDS_Shape");
770 TopoDS_Shape edgeShape = v1.value<TopoDS_Shape>();
772 bool isParam = myParamCoord->checkedId() == PARAM_VALUE;
773 bool isLength = myParamCoord->checkedId() == LENGTH_VALUE;
774 bool isCoord = myParamCoord->checkedId() == COORD_VALUE;
778 double param = GroupOnCurve->SpinBox_DX->value();
780 // - compute the resulting vertex
781 vertex = makePointOnCurve(edgeShape, param);
785 // - the starting point
786 QVariant v2 = GroupOnCurve->LineEdit2->property("TopoDS_Shape");
789 TopoDS_Shape pointShape = v2.value<TopoDS_Shape>();
792 double length = GroupOnCurve->SpinBox_DX->value();
794 // - compute the resulting vertex
795 vertex = makePointOnCurveByLength(edgeShape, pointShape,length);
800 double x = GroupXYZ->SpinBox_DX->value();
801 double y = GroupXYZ->SpinBox_DY->value();
802 double z = GroupXYZ->SpinBox_DZ->value();
804 // - compute the resulting vertex
805 vertex = makePointOnCurveByCoord(edgeShape, x, y, z);
811 TopoDS_Vertex MyBasicGUI_PointDlg::computeGeomPointInt()
813 TopoDS_Vertex vertex;
815 if (getConstructorId() != GEOM_POINT_INTINT)
820 // * get inputs values
823 v = GroupLineIntersection->LineEdit1->property("TopoDS_Shape");
826 TopoDS_Shape line1 = v.value<TopoDS_Shape>();
829 v = GroupLineIntersection->LineEdit2->property("TopoDS_Shape");
832 TopoDS_Shape line2 = v.value<TopoDS_Shape>();
834 // * compute the resulting vertex
835 vertex = makePointOnLinesIntersection(line1, line2);
840 TopoDS_Vertex MyBasicGUI_PointDlg::computeGeomPointSurf()
842 TopoDS_Vertex vertex;
844 if (getConstructorId() != GEOM_POINT_SURF)
847 // * get inputs values
850 QVariant v = GroupOnSurface->LineEdit1->property("TopoDS_Shape");
853 TopoDS_Shape faceShape = v.value<TopoDS_Shape>();
855 bool isParam = myParamCoord->checkedId() == PARAM_VALUE;
856 bool isCoord = myParamCoord->checkedId() == COORD_VALUE;
860 double param_u = GroupOnSurface->SpinBox_DX->value();
861 double param_v = GroupOnSurface->SpinBox_DY->value();
863 // - compute the resulting vertex
864 vertex = makePointOnSurface(faceShape, param_u, param_v);
869 double x = GroupXYZ->SpinBox_DX->value();
870 double y = GroupXYZ->SpinBox_DY->value();
871 double z = GroupXYZ->SpinBox_DZ->value();
873 // - compute the resulting vertex
874 vertex = makePointOnSurfaceByCoord(faceShape, x, y, z);
880 //=================================================================================
881 // function : OnPointSelected
883 //=================================================================================
884 void MyBasicGUI_PointDlg::OnPointSelected(const gp_Pnt& thePnt)
886 if (getConstructorId() == GEOM_POINT_XYZ) {
887 GroupXYZ->SpinBox_DX->setValue(thePnt.X());
888 GroupXYZ->SpinBox_DY->setValue(thePnt.Y());
889 GroupXYZ->SpinBox_DZ->setValue(thePnt.Z());
893 void MyBasicGUI_PointDlg::updateInputs(const int constructorId)
896 QVector3D* coords = NULL;
898 switch (constructorId) {
899 case GEOM_POINT_XYZ :
900 coords = coordsInputValue[GEOM_POINT_XYZ];
904 case GEOM_POINT_EDGE:
905 coords = coordsInputValue[GEOM_POINT_EDGE];
906 updateParamCoord(true);
908 case GEOM_POINT_INTINT:
910 case GEOM_POINT_SURF:
911 coords = coordsInputValue[GEOM_POINT_SURF];
912 updateParamCoord(true);
920 GroupXYZ->SpinBox_DX->setValue(coords->x());
921 GroupXYZ->SpinBox_DY->setValue(coords->y());
922 GroupXYZ->SpinBox_DZ->setValue(coords->z());
925 onUpdateResults(str);
928 //=================================================================================
929 // function : ClickParamCoord()
931 //=================================================================================
932 void MyBasicGUI_PointDlg::ClickParamCoord(int id)
934 updateInputs(getConstructorId());
937 //=================================================================================
938 // function : updateParamCoord
940 //=================================================================================
941 void MyBasicGUI_PointDlg::updateParamCoord(bool theIsUpdate)
943 bool isParam = myParamCoord->checkedId() == PARAM_VALUE;
944 bool isLength = myParamCoord->checkedId() == LENGTH_VALUE;
946 const int id = getConstructorId();
947 if (id == GEOM_POINT_EDGE) {
948 GroupOnCurve->TextLabel2->setVisible(isLength);
949 GroupOnCurve->LineEdit2->setVisible(isLength);
950 GroupOnCurve->TextLabel3->setVisible(isParam || isLength);
951 GroupOnCurve->SpinBox_DX->setVisible(isParam || isLength);
953 GroupOnCurve->TextLabel3->setText(tr("GEOM_PARAMETER"));
954 double value = paramInputValue[PARAM_VALUE];
955 GroupOnCurve->SpinBox_DX->setValue(0.5);
956 initSpinBox(GroupOnCurve->SpinBox_DX, 0., 1.);
957 GroupOnCurve->SpinBox_DX->setValue(value);
960 GroupOnCurve->TextLabel3->setText(tr("GEOM_LENGTH"));
961 double value = paramInputValue[LENGTH_VALUE];
962 GroupOnCurve->SpinBox_DX->setValue(0.5);
963 initSpinBox(GroupOnCurve->SpinBox_DX, COORD_MIN, COORD_MAX);
964 GroupOnCurve->SpinBox_DX->setValue(value);
967 else if (id == GEOM_POINT_SURF) {
968 GroupOnSurface->TextLabel2->setShown(isParam);
969 GroupOnSurface->TextLabel3->setShown(isParam);
970 GroupOnSurface->SpinBox_DX->setShown(isParam);
971 GroupOnSurface->SpinBox_DY->setShown(isParam);
974 GroupXYZ->setShown(!isParam && !isLength);
977 //=================================================================================
978 // function : onBtnPopup()
980 //=================================================================================
981 void MyBasicGUI_PointDlg::onBtnPopup(QAction* a)
983 if (a == action_line1_edge)
985 GroupLineIntersection->LineEdit1->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_EDGE) );
986 GroupLineIntersection->LineEdit1->setFocus();
987 GroupLineIntersection->PushButton2->setDown(false);
989 else if (a == action_line1_wire)
991 GroupLineIntersection->LineEdit1->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_WIRE) );
992 GroupLineIntersection->LineEdit1->setFocus();
993 GroupLineIntersection->PushButton2->setDown(false);
995 else if (a == action_line2_edge)
997 GroupLineIntersection->LineEdit2->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_EDGE) );
998 GroupLineIntersection->LineEdit2->setFocus();
999 GroupLineIntersection->PushButton1->setDown(false);
1001 else if (a == action_line2_wire)
1003 GroupLineIntersection->LineEdit2->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_WIRE) );
1004 GroupLineIntersection->LineEdit2->setFocus();
1005 GroupLineIntersection->PushButton1->setDown(false);
1009 //=================================================================================
1010 // function : updateSize
1011 // purpose : adjust dialog size to minimum
1012 //=================================================================================
1013 void MyBasicGUI_PointDlg::updateSize()
1015 qApp->processEvents();
1017 resize(minimumSizeHint());
1020 void MyBasicGUI_PointDlg::clear()
1022 mainFrame()->_vertex_le->clear();
1023 modelUnregister(mainFrame()->_vertex_le);
1025 GroupRefPoint->LineEdit1->clear();
1026 GroupRefPoint->LineEdit1->setProperty("TopoDS_Shape", QVariant());
1027 GroupRefPoint->LineEdit1->setProperty("QModelIndex", QVariant());
1028 GroupRefPoint->LineEdit1->setProperty("HexaData", QVariant());
1030 GroupOnCurve->LineEdit1->clear();
1031 GroupOnCurve->LineEdit1->setProperty("TopoDS_Shape", QVariant());
1032 GroupOnCurve->LineEdit1->setProperty("QModelIndex", QVariant());
1033 GroupOnCurve->LineEdit1->setProperty("HexaData", QVariant());
1035 GroupOnCurve->LineEdit2->clear();
1036 GroupOnCurve->LineEdit2->setProperty("TopoDS_Shape", QVariant());
1037 GroupOnCurve->LineEdit2->setProperty("QModelIndex", QVariant());
1038 GroupOnCurve->LineEdit2->setProperty("HexaData", QVariant());
1040 GroupLineIntersection->LineEdit1->clear();
1041 GroupLineIntersection->LineEdit1->setProperty("TopoDS_Shape", QVariant());
1042 GroupLineIntersection->LineEdit1->setProperty("QModelIndex", QVariant());
1043 GroupLineIntersection->LineEdit1->setProperty("HexaData", QVariant());
1045 GroupLineIntersection->LineEdit2->clear();
1046 GroupLineIntersection->LineEdit2->setProperty("TopoDS_Shape", QVariant());
1047 GroupLineIntersection->LineEdit2->setProperty("QModelIndex", QVariant());
1048 GroupLineIntersection->LineEdit2->setProperty("HexaData", QVariant());
1050 GroupOnSurface->LineEdit1->clear();
1051 GroupOnSurface->LineEdit1->setProperty("TopoDS_Shape", QVariant());
1052 GroupOnSurface->LineEdit1->setProperty("QModelIndex", QVariant());
1053 GroupOnSurface->LineEdit1->setProperty("HexaData", QVariant());
1055 modelUnregister(this);
1059 void MyBasicGUI_PointDlg::onWindowActivated(SUIT_ViewManager* vm)
1061 QString vmType = vm->getType();
1062 if ( (vmType == SVTK_Viewer::Type()) || (vmType == VTKViewer_Viewer::Type()) ){
1063 mainFrame()->_vertex_le->setFocus();
1064 } else if ( vmType == OCCViewer_Viewer::Type() ){