1 // Copyright (C) 2009-2012 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 <GeometryGUI.h>
30 #include "MyDlgRef.hxx"
32 #include <GEOMImpl_Types.hxx>
34 #include <QApplication>
35 #include <QButtonGroup>
36 #include <QHBoxLayout>
38 #include <QRadioButton>
43 #include <TopoDS_Shape.hxx>
44 #include <TopAbs_ShapeEnum.hxx>
46 #include <BRep_Tool.hxx>
48 #include <TColStd_IndexedMapOfInteger.hxx>
49 #include <TopTools_IndexedMapOfShape.hxx>
52 #include <VTKViewer_ViewModel.h>
53 #include <SUIT_MessageBox.h>
54 #include <SUIT_OverrideCursor.h>
55 #include <SalomeApp_Tools.h>
56 #include <SalomeApp_Study.h>
58 #include "HEXABLOCKGUI_DocumentModel.hxx"
59 #include "HEXABLOCKGUI_DocumentSelectionModel.hxx"
60 #include "HEXABLOCKGUI_DocumentItem.hxx"
61 #include "HEXABLOCKGUI_SalomeTools.hxx"
62 #include "HEXABLOCKGUI.hxx"
63 #include "HEXABLOCKGUI_VtkDocumentGraphicView.hxx"
67 #define LENGTH_VALUE 2
69 #define GEOM_POINT_XYZ 0
70 #define GEOM_POINT_REF 1
71 #define GEOM_POINT_EDGE 2
72 #define GEOM_POINT_INTINT 3
73 #define GEOM_POINT_SURF 4
78 using namespace HEXABLOCK::GUI;
80 Q_DECLARE_METATYPE(QModelIndex);
81 Q_DECLARE_METATYPE(HEXABLOCK::GUI::HexaTreeRole);
83 enum { SelectEdge, SelectWire };
85 //=================================================================================
86 // class : MyBasicGUI_PointDlg()
87 // purpose : Constructs a MyBasicGUI_PointDlg which is a child of 'parent', with the
88 // name 'name' and widget flags set to 'f'.
89 // The dialog will by default be modeless, unless you set 'modal' to
90 // TRUE to construct a modal dialog.
91 //=================================================================================
92 MyBasicGUI_PointDlg::MyBasicGUI_PointDlg(GeometryGUI* theGeometryGUI, QWidget* parent,
93 bool modal, Qt::WindowFlags fl)
94 : MyGEOMBase_Skeleton(theGeometryGUI, parent, modal, fl),
97 _patternDataSelectionModel(0),
99 _selectionMutex(false)
101 QWidget* w = centralWidget();
102 QString objectName = w->objectName();
103 QString className = w->metaObject()->className();
105 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
106 QPixmap image0 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_POINT")));
107 QPixmap image1 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_POINT_EDGE")));
108 QPixmap image2 (aResMgr->loadPixmap("GEOM", tr("ICON_SELECT")));
109 QPixmap image3 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_POINT_REF")));
110 QPixmap image4 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_POINT_LINES")));
111 QPixmap image5 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_POINT_FACE")));
112 QPixmap image6 (aResMgr->loadPixmap("GEOM", tr("ICO_LINE")));
113 QPixmap image7 (aResMgr->loadPixmap("GEOM", tr("ICO_WIRE")));
115 // setWindowTitle(tr("GEOM_POINT_TITLE"));
116 setWindowTitle( tr("Vertex Association") );
117 setMinimumWidth(260);
122 mainFrame()->GroupConstructors->setTitle(tr("GEOM_POINTS"));
123 mainFrame()->RadioButton1->setIcon(image0);
124 mainFrame()->RadioButton2->setIcon(image3);
125 mainFrame()->RadioButton3->setIcon(image1);
126 mainFrame()->RadioButton4->show();
127 mainFrame()->RadioButton4->setIcon(image4);
128 mainFrame()->RadioButton5->show();
129 mainFrame()->RadioButton5->setIcon(image5);
131 myParamGroup = new QGroupBox(centralWidget());
132 myParamCoord = new QButtonGroup(myParamGroup);
133 QHBoxLayout* boxLayout = new QHBoxLayout(myParamGroup);
134 boxLayout->setMargin(MARGIN); boxLayout->setSpacing(SPACING);
135 QRadioButton* btn = new QRadioButton(tr("GEOM_PARAM_VALUE"), myParamGroup);
136 myParamCoord->addButton(btn, PARAM_VALUE);
137 boxLayout->addWidget(btn);
138 btn = new QRadioButton(tr("GEOM_LENGTH_VALUE"), myParamGroup);
139 myParamCoord->addButton(btn, LENGTH_VALUE);
140 boxLayout->addWidget(btn);
141 btn = new QRadioButton(tr("GEOM_COORD_VALUE"), myParamGroup);
142 myParamCoord->addButton(btn, COORD_VALUE);
143 boxLayout->addWidget(btn);
144 myParamCoord->setExclusive(true);
145 myParamCoord->button(PARAM_VALUE)->setChecked(true);
147 GroupXYZ = new DlgRef_3Spin(centralWidget());
148 GroupXYZ->GroupBox1->setTitle(tr("GEOM_COORDINATES"));
149 GroupXYZ->TextLabel1->setText(tr("GEOM_X"));
150 GroupXYZ->TextLabel2->setText(tr("GEOM_Y"));
151 GroupXYZ->TextLabel3->setText(tr("GEOM_Z"));
153 GroupOnCurve = new DlgRef_2Sel1Spin(centralWidget());
154 GroupOnCurve->GroupBox1->setTitle(tr("GEOM_POINT_ON_EDGE"));
155 GroupOnCurve->TextLabel1->setText(tr("GEOM_EDGE"));
156 GroupOnCurve->TextLabel2->setText(tr("GEOM_START_POINT"));
157 GroupOnCurve->TextLabel3->setText(tr("GEOM_PARAMETER"));
158 GroupOnCurve->PushButton1->setIcon(image2);
159 GroupOnCurve->PushButton2->setIcon(image2);
161 GroupOnSurface = new DlgRef_1Sel2Spin(centralWidget());
162 GroupOnSurface->GroupBox1->setTitle(tr("GEOM_POINT_ON_FACE"));
163 GroupOnSurface->TextLabel1->setText(tr("GEOM_FACE"));
164 GroupOnSurface->TextLabel2->setText(tr("GEOM_UPARAMETER"));
165 GroupOnSurface->TextLabel3->setText(tr("GEOM_VPARAMETER"));
166 GroupOnSurface->PushButton1->setIcon(image2);
168 GroupRefPoint = new DlgRef_1Sel3Spin(centralWidget());
169 GroupRefPoint->GroupBox1->setTitle(tr("GEOM_REF_POINT"));
170 GroupRefPoint->TextLabel1->setText(tr("GEOM_POINT"));
171 GroupRefPoint->PushButton1->setIcon(image2);
172 GroupRefPoint->TextLabel2->setText(tr("GEOM_DX"));
173 GroupRefPoint->TextLabel3->setText(tr("GEOM_DY"));
174 GroupRefPoint->TextLabel4->setText(tr("GEOM_DZ"));
176 /* popup menu for line intersect buttons */
177 myBtnPopup = new QMenu(this);
178 QIcon ico_line = QIcon(image6);
179 QIcon ico_wire = QIcon(image7);
180 myActions[myBtnPopup->addAction(ico_line, tr("GEOM_EDGE"))] = SelectEdge;
181 myActions[myBtnPopup->addAction(ico_wire, tr("GEOM_WIRE"))] = SelectWire;
183 GroupLineIntersection = new DlgRef_2Sel(centralWidget());
184 GroupLineIntersection->GroupBox1->setTitle(tr("GEOM_LINE_INTERSECTION"));
185 GroupLineIntersection->TextLabel1->setText(tr("GEOM_LINE1"));
186 GroupLineIntersection->TextLabel2->setText(tr("GEOM_LINE2"));
187 GroupLineIntersection->PushButton1->setIcon(image2);
188 GroupLineIntersection->PushButton1->setMenu(myBtnPopup);
189 GroupLineIntersection->PushButton2->setIcon(image2);
190 GroupLineIntersection->PushButton2->setMenu(myBtnPopup);
191 GroupLineIntersection->LineEdit2->setEnabled(false);
193 myCoordGrp = new QGroupBox(tr("GEOM_COORDINATES_RES"), centralWidget());
194 QGridLayout* myCoordGrpLayout = new QGridLayout(myCoordGrp);
195 myCoordGrpLayout->addWidget(new QLabel(tr("GEOM_X"), myCoordGrp), 0, 0);
196 myX = new QLineEdit(myCoordGrp);
197 myCoordGrpLayout->addWidget(myX, 0, 1);
198 myCoordGrpLayout->addWidget(new QLabel(tr("GEOM_Y"), myCoordGrp), 1, 0);
199 myY = new QLineEdit(myCoordGrp);
200 myCoordGrpLayout->addWidget(myY, 1, 1);
201 myCoordGrpLayout->addWidget(new QLabel(tr("GEOM_Z"), myCoordGrp), 2, 0);
202 myZ = new QLineEdit(myCoordGrp);
203 myCoordGrpLayout->addWidget(myZ, 2, 1);
205 QVBoxLayout* layout = new QVBoxLayout(centralWidget());
206 layout->setMargin(0); layout->setSpacing(6);
207 layout->addWidget(myParamGroup);
208 layout->addWidget(GroupXYZ);
209 layout->addWidget(GroupOnCurve);
210 layout->addWidget(GroupOnSurface);
211 layout->addWidget(GroupRefPoint);
212 layout->addWidget(GroupLineIntersection);
213 layout->addWidget(myCoordGrp);
216 myX->setReadOnly(true);
217 myY->setReadOnly(true);
218 myZ->setReadOnly(true);
220 myX->setEnabled(false);
221 myY->setEnabled(false);
222 myZ->setEnabled(false);
224 QPalette aPal = myX->palette();
225 aPal.setColor(QPalette::Disabled, QPalette::Text, QColor(0, 0, 0));
226 myX->setPalette(aPal);
227 myY->setPalette(aPal);
228 myZ->setPalette(aPal);
230 setHelpFileName("gui_asso_quad_to_geom.html#associate-to-a-vertex-of-the-geometry");/*"create_point_page.html"*/
236 // _initViewManager();
241 //=================================================================================
242 // function : ~MyBasicGUI_PointDlg()
243 // purpose : Destructor
244 //=================================================================================
245 MyBasicGUI_PointDlg::~MyBasicGUI_PointDlg()
249 //=================================================================================
252 //=================================================================================
253 void MyBasicGUI_PointDlg::Init()
255 GroupOnCurve->LineEdit1->setReadOnly(true);
256 GroupOnCurve->LineEdit2->setReadOnly(true);
257 GroupOnSurface->LineEdit1->setReadOnly(true);
258 GroupRefPoint->LineEdit1->setReadOnly(true);
259 GroupLineIntersection->LineEdit1->setReadOnly(true);
260 GroupLineIntersection->LineEdit2->setReadOnly(true);
261 GroupLineIntersection->LineEdit1->setEnabled(true);
262 GroupLineIntersection->LineEdit2->setEnabled(false);
266 myRefPoint.nullify();
269 myNeedType = TopAbs_VERTEX;
271 myEditCurrentArgument = 0;
273 /* Get setting of step value from file configuration */
274 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
275 double step = resMgr->doubleValue("Geometry", "SettingsGeomStep", 100);
277 /* min, max, step and decimals for spin boxes */
278 initSpinBox(GroupXYZ->SpinBox_DX, COORD_MIN, COORD_MAX, step, "length_precision");
279 initSpinBox(GroupXYZ->SpinBox_DY, COORD_MIN, COORD_MAX, step, "length_precision");
280 initSpinBox(GroupXYZ->SpinBox_DZ, COORD_MIN, COORD_MAX, step, "length_precision");
281 GroupXYZ->SpinBox_DX->setValue(0.0);
282 GroupXYZ->SpinBox_DY->setValue(0.0);
283 GroupXYZ->SpinBox_DZ->setValue(0.0);
285 initSpinBox(GroupRefPoint->SpinBox_DX, COORD_MIN, COORD_MAX, step, "length_precision");
286 initSpinBox(GroupRefPoint->SpinBox_DY, COORD_MIN, COORD_MAX, step, "length_precision");
287 initSpinBox(GroupRefPoint->SpinBox_DZ, COORD_MIN, COORD_MAX, step, "length_precision");
288 GroupRefPoint->SpinBox_DX->setValue(0.0);
289 GroupRefPoint->SpinBox_DY->setValue(0.0);
290 GroupRefPoint->SpinBox_DZ->setValue(0.0);
294 initSpinBox(GroupOnCurve->SpinBox_DX, 0., 1., step, "parametric_precision");
295 GroupOnCurve->SpinBox_DX->setValue(0.5);
297 initSpinBox(GroupOnSurface->SpinBox_DX, 0., 1., step, "parametric_precision");
298 GroupOnSurface->SpinBox_DX->setValue(0.5);
299 initSpinBox(GroupOnSurface->SpinBox_DY, 0., 1., step, "parametric_precision");
300 GroupOnSurface->SpinBox_DY->setValue(0.5);
302 /* signals and slots connections */
304 connect(myGeomGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
305 connect(myGeomGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(close()));
307 //connect(buttonOk(), SIGNAL(clicked()), this, SLOT(ClickOnOk()));
308 connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
309 connect(buttonHelp(), SIGNAL(clicked()), this, SLOT(onHelpRequested()) );
310 // connect( closeButton, SIGNAL(clicked()), this, SLOT(close()) );
312 connect(this, SIGNAL(constructorsClicked(int)), this, SLOT(ConstructorsClicked(int)));
314 connect(myParamCoord, SIGNAL(buttonClicked(int)), this, SLOT(ClickParamCoord(int)));
316 connect(GroupOnCurve->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
317 connect(GroupOnCurve->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
318 connect(GroupOnSurface->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
319 connect(GroupLineIntersection->PushButton1, SIGNAL(pressed()), this, SLOT(SetEditCurrentArgument()));
320 connect(GroupLineIntersection->PushButton2, SIGNAL(pressed()), this, SLOT(SetEditCurrentArgument()));
322 connect(myBtnPopup, SIGNAL(triggered(QAction*)), this, SLOT(onBtnPopup(QAction*)));
324 connect(GroupOnCurve->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
325 connect(GroupOnSurface->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
326 connect(GroupOnSurface->SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
327 connect(GroupXYZ->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
328 connect(GroupXYZ->SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
329 connect(GroupXYZ->SpinBox_DZ, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
330 connect(GroupRefPoint->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
331 connect(GroupRefPoint->SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
332 connect(GroupRefPoint->SpinBox_DZ, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
334 connect( mainFrame()->RadioButton1, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
335 connect( mainFrame()->RadioButton2, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
336 connect( mainFrame()->RadioButton3, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
337 connect( mainFrame()->RadioButton4, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
338 connect( mainFrame()->RadioButton5, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
339 connect( myParamCoord->button(PARAM_VALUE), SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
340 connect( myParamCoord->button(LENGTH_VALUE), SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
341 connect( myParamCoord->button(COORD_VALUE), SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
344 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), this, SLOT(SetDoubleSpinBoxStep(double)));
346 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
347 this, SLOT(SelectionIntoArgument()));
350 initName(tr("GEOM_VERTEX"));
352 ConstructorsClicked(0);
355 //=================================================================================
356 // function : onHelpRequested()
357 // purpose : show help in web browser
358 //=================================================================================
359 void MyBasicGUI_PointDlg::onHelpRequested()
361 LightApp_Application* app = (LightApp_Application*)( SUIT_Session::session()->activeApplication() );
363 // app->onHelpContextModule( myGeometryGUI ? app->moduleName( myGeometryGUI->moduleName() ) : QString( "" ), _helpFileName );
364 app->onHelpContextModule( "HEXABLOCK", myHelpFileName );
369 platform = "winapplication";
371 platform = "application";
374 SUIT_MessageBox::warning( 0, QObject::tr( "WRN_WARNING" ),
375 QObject::tr( "EXTERNAL_BROWSER_CANNOT_SHOW_PAGE" ).
376 arg( app->resourceMgr()->stringValue( "ExternalBrowser", platform ) ).arg( myHelpFileName ),
377 QObject::tr( "BUT_OK" ) );
381 //===============================================================
382 // function : updateHelpFileName()
383 // purpose : update the help file according to the current panel
384 //===============================================================
385 void MyBasicGUI_PointDlg::updateHelpFileName()
387 if ( sender() == mainFrame()->RadioButton1 ){
388 setHelpFileName("gui_asso_quad_to_geom.html#associate-to-a-vertex-of-the-geometry");
389 } else if ( sender() == mainFrame()->RadioButton2 ){
390 setHelpFileName("gui_asso_vertex_to_geom.html#by-a-reference");
391 } else if ( sender() == mainFrame()->RadioButton3 ){
392 setHelpFileName("gui_asso_vertex_to_geom.html#by-an-edge-and-a-parameter");
393 } else if ( sender() == mainFrame()->RadioButton4 ){
394 setHelpFileName("gui_asso_vertex_to_geom.html#by-intersection-of-two-lines-or-wires");
395 } else if ( sender() == mainFrame()->RadioButton5 ){
396 setHelpFileName("gui_asso_vertex_to_geom.html#by-a-face-and-two-parameters");
397 } else if (sender() == myParamCoord->button(PARAM_VALUE)){
398 if (mainFrame()->RadioButton3->isChecked()){
399 setHelpFileName("gui_asso_vertex_to_geom.html#by-an-edge-and-a-parameter");
400 } else if (mainFrame()->RadioButton5->isChecked()){
401 setHelpFileName("gui_asso_vertex_to_geom.html#by-a-face-and-two-parameters");
403 } else if (sender() == myParamCoord->button(LENGTH_VALUE)){
404 setHelpFileName("gui_asso_vertex_to_geom.html#by-an-edge-and-a-length");
405 } else if (sender() == myParamCoord->button(COORD_VALUE)){
406 if (mainFrame()->RadioButton3->isChecked()){
407 setHelpFileName("gui_asso_vertex_to_geom.html#by-an-edge-and-coordinates");
408 } else if (mainFrame()->RadioButton5->isChecked()){
409 setHelpFileName("gui_asso_vertex_to_geom.html#by-a-face-and-coordinates");
414 //=================================================================================
415 // function : SetDoubleSpinBoxStep()
416 // purpose : Double spin box management
417 //=================================================================================
418 void MyBasicGUI_PointDlg::SetDoubleSpinBoxStep(double step)
420 GroupOnCurve->SpinBox_DX->setSingleStep(step);
421 GroupXYZ->SpinBox_DX->setSingleStep(step);
422 GroupXYZ->SpinBox_DY->setSingleStep(step);
423 GroupXYZ->SpinBox_DZ->setSingleStep(step);
424 GroupRefPoint->SpinBox_DX->setSingleStep(step);
425 GroupRefPoint->SpinBox_DY->setSingleStep(step);
426 GroupRefPoint->SpinBox_DZ->setSingleStep(step);
430 //=================================================================================
431 // function : ConstructorsClicked()
432 // purpose : Radio button management
433 //=================================================================================
434 void MyBasicGUI_PointDlg::ConstructorsClicked(int constructorId)
436 // HEXABLOCKGUI::currentOccView->raise();
437 // HEXABLOCKGUI::currentOccView->setFocus();
438 switch (constructorId) {
441 globalSelection(HEXABLOCKGUI::currentOccGView->getViewWindow()); // close local contexts, if any
442 myNeedType = TopAbs_VERTEX;
443 localSelection(HEXABLOCKGUI::currentOccGView->getViewWindow(), myNeedType);
445 GroupRefPoint->hide();
446 GroupOnCurve->hide();
447 GroupLineIntersection->hide();
448 GroupOnSurface->hide();
450 myParamGroup->hide();
456 globalSelection(HEXABLOCKGUI::currentOccGView->getViewWindow()); // close local contexts, if any
457 myNeedType = TopAbs_VERTEX;
458 localSelection(HEXABLOCKGUI::currentOccGView->getViewWindow(), myNeedType);
460 myEditCurrentArgument = GroupRefPoint->LineEdit1;
461 //myEditCurrentArgument->setText("");
462 //myRefPoint.nullify();
463 GroupRefPoint->PushButton1->setDown(true);
464 myParamGroup->hide();
466 GroupOnCurve->hide();
467 GroupLineIntersection->hide();
468 GroupOnSurface->hide();
469 GroupRefPoint->show();
473 case GEOM_POINT_EDGE:
475 globalSelection(HEXABLOCKGUI::currentOccGView->getViewWindow()); // close local contexts, if any
476 myNeedType = TopAbs_EDGE;
477 localSelection(HEXABLOCKGUI::currentOccGView->getViewWindow(), myNeedType);
479 myEditCurrentArgument = GroupOnCurve->LineEdit1;
480 // myEditCurrentArgument->setText("");
482 // myRefPoint.nullify();
483 GroupOnCurve->PushButton1->setDown(true);
484 GroupRefPoint->hide();
485 GroupLineIntersection->hide();
486 GroupOnSurface->hide();
487 myParamGroup->show();
488 myParamCoord->button(LENGTH_VALUE)->show();
489 myParamCoord->button(PARAM_VALUE)->setChecked(true);
490 GroupOnCurve->show();
492 updateParamCoord(false);
495 case GEOM_POINT_INTINT:
497 globalSelection(HEXABLOCKGUI::currentOccGView->getViewWindow()); // close local contexts, if any
498 myNeedType = TopAbs_EDGE;
499 localSelection(HEXABLOCKGUI::currentOccGView->getViewWindow(), myNeedType);
501 myEditCurrentArgument = GroupLineIntersection->LineEdit1;
502 // GroupLineIntersection->LineEdit1->setText("");
503 // GroupLineIntersection->LineEdit2->setText("");
504 GroupLineIntersection->LineEdit1->setEnabled(true);
505 GroupLineIntersection->LineEdit2->setEnabled(false);
506 // myLine1.nullify();
507 // myLine2.nullify();
508 GroupLineIntersection->PushButton1->setDown(true);
509 GroupLineIntersection->PushButton2->setDown(false);
510 myParamGroup->hide();
512 GroupRefPoint->hide();
513 GroupOnCurve->hide();
514 GroupOnSurface->hide();
516 GroupLineIntersection->show();
519 case GEOM_POINT_SURF:
521 globalSelection(HEXABLOCKGUI::currentOccGView->getViewWindow()); // close local contexts, if any
522 myNeedType = TopAbs_FACE;
523 localSelection(HEXABLOCKGUI::currentOccGView->getViewWindow(), myNeedType);
525 myEditCurrentArgument = GroupOnSurface->LineEdit1;
526 //myEditCurrentArgument->setText("");
528 GroupOnSurface->PushButton1->setDown(true);
529 GroupRefPoint->hide();
530 GroupOnCurve->hide();
531 GroupLineIntersection->hide();
532 myParamGroup->show();
533 myParamCoord->button(LENGTH_VALUE)->hide();
534 myParamCoord->button(PARAM_VALUE)->setChecked(true);
535 GroupOnSurface->show();
537 updateParamCoord(false);
546 QTimer::singleShot(50, this, SLOT(updateSize()));
548 SelectionIntoArgument();
551 //=================================================================================
552 // function : ClickOnOk()
554 //=================================================================================
555 void MyBasicGUI_PointDlg::ClickOnOk()
557 setIsApplyAndClose(true);
562 //=================================================================================
563 // function : ClickOnApply()
565 //=================================================================================
566 bool MyBasicGUI_PointDlg::ClickOnApply()
572 // ConstructorsClicked(getConstructorId());
574 //Set selection mode to the last selected mode
575 globalSelection(HEXABLOCKGUI::currentOccGView->getViewWindow()); // close local contexts, if any
576 localSelection(HEXABLOCKGUI::currentOccGView->getViewWindow(), myNeedType);
582 //=================================================================================
583 // function : SelectionIntoArgument()
584 // purpose : Called when selection as changed (for constructors not using local context)
585 //=================================================================================
586 void MyBasicGUI_PointDlg::SelectionIntoArgument()
588 GEOM::GeomObjPtr aSelectedObject = getSelected(myNeedType);
590 if (!aSelectedObject || !GEOMBase::GetShape(aSelectedObject.get(), aShape) || aShape.IsNull())
594 const int id = getConstructorId();
596 if ((id == GEOM_POINT_REF || id == GEOM_POINT_EDGE || id == GEOM_POINT_SURF)
597 && myEditCurrentArgument != 0)
599 myEditCurrentArgument->setText("");
604 if (myEditCurrentArgument == GroupOnCurve->LineEdit1)
606 else if (myEditCurrentArgument == GroupOnCurve->LineEdit2)
607 myRefPoint.nullify();
609 else if (id == GEOM_POINT_INTINT) {
610 myEditCurrentArgument->setText("");
611 if (myEditCurrentArgument == GroupLineIntersection->LineEdit1)
613 else if (myEditCurrentArgument == GroupLineIntersection->LineEdit2)
617 QString aName = GEOMBase::GetName(aSelectedObject.get());
619 if (id == GEOM_POINT_XYZ) {
620 gp_Pnt aPnt = BRep_Tool::Pnt(TopoDS::Vertex(aShape));
621 GroupXYZ->SpinBox_DX->setValue(aPnt.X());
622 GroupXYZ->SpinBox_DY->setValue(aPnt.Y());
623 GroupXYZ->SpinBox_DZ->setValue(aPnt.Z());
625 else if (id == GEOM_POINT_REF) {
626 myRefPoint = aSelectedObject;
627 GroupRefPoint->LineEdit1->setText(aName);
629 else if (id == GEOM_POINT_EDGE) {
630 myEditCurrentArgument->setText(aName);
631 if (myEditCurrentArgument == GroupOnCurve->LineEdit1) {
632 myEdge = aSelectedObject;
633 if (myEdge && !myRefPoint) {
634 GroupOnCurve->PushButton2->click();
637 else if (myEditCurrentArgument == GroupOnCurve->LineEdit2) {
638 myRefPoint = aSelectedObject;
639 if (myRefPoint && !myEdge) {
640 GroupOnCurve->PushButton1->click();
644 else if (id == GEOM_POINT_INTINT) {
645 myEditCurrentArgument->setText(aName);
646 if (myEditCurrentArgument == GroupLineIntersection->LineEdit1) {
647 myLine1 = aSelectedObject;
649 GroupLineIntersection->PushButton2->setMenu(0);
650 GroupLineIntersection->PushButton2->click();
651 GroupLineIntersection->PushButton2->setDown(true);
652 GroupLineIntersection->PushButton2->setMenu(myBtnPopup);
655 else if (myEditCurrentArgument == GroupLineIntersection->LineEdit2) {
656 myLine2 = aSelectedObject;
658 GroupLineIntersection->PushButton1->setMenu(0);
659 GroupLineIntersection->PushButton1->click();
660 GroupLineIntersection->PushButton1->setDown(true);
661 GroupLineIntersection->PushButton1->setMenu(myBtnPopup);
665 else if (id == GEOM_POINT_SURF) {
666 myFace = aSelectedObject;
667 GroupOnSurface->LineEdit1->setText(aName);
672 displayPreview(true);
676 //=================================================================================
677 // function : SetEditCurrentArgument()
679 //=================================================================================
680 void MyBasicGUI_PointDlg::SetEditCurrentArgument()
682 QPushButton* send = (QPushButton*)sender();
684 if (send == GroupRefPoint->PushButton1) {
685 GroupRefPoint->LineEdit1->setFocus();
686 myEditCurrentArgument = GroupRefPoint->LineEdit1;
687 globalSelection(HEXABLOCKGUI::currentOccGView->getViewWindow()); // close local contexts, if any
688 localSelection(HEXABLOCKGUI::currentOccGView->getViewWindow(), TopAbs_VERTEX);
690 else if (send == GroupOnCurve->PushButton1) {
691 GroupOnCurve->LineEdit1->setFocus();
692 myEditCurrentArgument = GroupOnCurve->LineEdit1;
693 globalSelection(HEXABLOCKGUI::currentOccGView->getViewWindow()); // close local contexts, if any
694 myNeedType = TopAbs_EDGE;
695 localSelection(HEXABLOCKGUI::currentOccGView->getViewWindow(), myNeedType);
696 GroupOnCurve->PushButton2->setDown(false);
697 GroupOnCurve->LineEdit1->setEnabled(true);
698 GroupOnCurve->LineEdit2->setEnabled(false);
700 else if (send == GroupOnCurve->PushButton2) {
701 GroupOnCurve->LineEdit2->setFocus();
702 myEditCurrentArgument = GroupOnCurve->LineEdit2;
703 globalSelection(HEXABLOCKGUI::currentOccGView->getViewWindow()); // close local contexts, if any
704 myNeedType = TopAbs_VERTEX;
705 localSelection(HEXABLOCKGUI::currentOccGView->getViewWindow(), myNeedType);
706 GroupOnCurve->PushButton1->setDown(false);
707 GroupOnCurve->LineEdit2->setEnabled(true);
708 GroupOnCurve->LineEdit1->setEnabled(false);
710 else if (send == GroupOnSurface->PushButton1)
712 GroupOnSurface->LineEdit1->setFocus();
713 myEditCurrentArgument = GroupOnSurface->LineEdit1;
714 globalSelection(HEXABLOCKGUI::currentOccGView->getViewWindow()); // close local contexts, if any
715 localSelection(HEXABLOCKGUI::currentOccGView->getViewWindow(), TopAbs_FACE);
717 else if (send == GroupLineIntersection->PushButton1) {
718 GroupLineIntersection->LineEdit1->setFocus();
719 myEditCurrentArgument = GroupLineIntersection->LineEdit1;
720 GroupLineIntersection->PushButton2->setDown(false);
721 GroupLineIntersection->LineEdit1->setEnabled(true);
722 GroupLineIntersection->LineEdit2->setEnabled(false);
724 else if (send == GroupLineIntersection->PushButton2) {
725 GroupLineIntersection->LineEdit2->setFocus();
726 myEditCurrentArgument = GroupLineIntersection->LineEdit2;
727 GroupLineIntersection->PushButton1->setDown(false);
728 GroupLineIntersection->LineEdit1->setEnabled(false);
729 GroupLineIntersection->LineEdit2->setEnabled(true);
733 if ((send == GroupLineIntersection->PushButton1 ||
734 send == GroupLineIntersection->PushButton2) && !myBusy)
735 SelectionIntoArgument();
739 //=================================================================================
740 // function : enterEvent()
741 // purpose : to reactivate this dialog box when mouse enter onto the window
742 //=================================================================================
743 void MyBasicGUI_PointDlg::enterEvent(QEvent*)
745 if (!mainFrame()->GroupConstructors->isEnabled())
746 ActivateThisDialog();
750 //=================================================================================
751 // function : ActivateThisDialog()
753 //=================================================================================
754 void MyBasicGUI_PointDlg::ActivateThisDialog()
756 MyGEOMBase_Skeleton::ActivateThisDialog();
759 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
760 this, SLOT(SelectionIntoArgument()));
762 ConstructorsClicked(getConstructorId());
766 //=================================================================================
767 // function : DeactivateActiveDialog()
768 // purpose : public slot to deactivate if active
769 //=================================================================================
770 void MyBasicGUI_PointDlg::DeactivateActiveDialog()
772 // myGeomGUI->SetState(-1);
773 MyGEOMBase_Skeleton::DeactivateActiveDialog();
777 //=================================================================================
778 // function : ValueChangedInSpinBox()
780 //=================================================================================
781 void MyBasicGUI_PointDlg::ValueChangedInSpinBox(double newValue)
783 displayPreview(true);
786 //=================================================================================
787 // function : CheckBoxClicked()
788 // purpose : Check Boxes Management
789 //=================================================================================
790 void MyBasicGUI_PointDlg::CheckBoxClicked(int State)
792 displayPreview(true);
796 //=================================================================================
797 // funcion : getParameter()
799 //=================================================================================
800 double MyBasicGUI_PointDlg::getParameter() const
802 return GroupOnCurve->SpinBox_DX->value();
806 //=================================================================================
807 // funcion : getUParameter()
809 //=================================================================================
810 double MyBasicGUI_PointDlg::getUParameter() const
812 return GroupOnSurface->SpinBox_DX->value();
816 //=================================================================================
817 // funcion : getVParameter()
819 //=================================================================================
820 double MyBasicGUI_PointDlg::getVParameter() const
822 return GroupOnSurface->SpinBox_DY->value();
826 //=================================================================================
827 // function : OnPointSelected
829 //=================================================================================
830 void MyBasicGUI_PointDlg::OnPointSelected(const gp_Pnt& thePnt)
832 if (getConstructorId() == GEOM_POINT_XYZ) {
833 GroupXYZ->SpinBox_DX->setValue(thePnt.X());
834 GroupXYZ->SpinBox_DY->setValue(thePnt.Y());
835 GroupXYZ->SpinBox_DZ->setValue(thePnt.Z());
837 displayPreview(true);
841 //=================================================================================
842 // function : createOperation
844 //=================================================================================
845 GEOM::GEOM_IOperations_ptr MyBasicGUI_PointDlg::createOperation()
847 return myGeomGUI->GetGeomGen()->GetIBasicOperations(getStudyId());
850 //=================================================================================
851 // function : isValid
853 //=================================================================================
854 bool MyBasicGUI_PointDlg::isValid(QString& msg)
857 switch (getConstructorId()) {
858 case GEOM_POINT_XYZ :
859 ok = GroupXYZ->SpinBox_DX->isValid(msg, !IsPreview()) &&
860 GroupXYZ->SpinBox_DY->isValid(msg, !IsPreview()) &&
861 GroupXYZ->SpinBox_DZ->isValid(msg, !IsPreview());
864 ok = GroupRefPoint->SpinBox_DX->isValid(msg, !IsPreview()) &&
865 GroupRefPoint->SpinBox_DY->isValid(msg, !IsPreview()) &&
866 GroupRefPoint->SpinBox_DZ->isValid(msg, !IsPreview()) &&
869 case GEOM_POINT_EDGE:
870 if (myParamCoord->checkedId() == PARAM_VALUE || myParamCoord->checkedId() == LENGTH_VALUE)
871 ok = GroupOnCurve->SpinBox_DX->isValid(msg, !IsPreview());
873 ok = GroupXYZ->SpinBox_DX->isValid(msg, !IsPreview()) &&
874 GroupXYZ->SpinBox_DY->isValid(msg, !IsPreview()) &&
875 GroupXYZ->SpinBox_DZ->isValid(msg, !IsPreview());
878 case GEOM_POINT_INTINT:
879 ok = myLine1 && myLine2;
881 case GEOM_POINT_SURF:
882 if (myParamCoord->checkedId() == PARAM_VALUE)
883 ok = GroupOnSurface->SpinBox_DX->isValid(msg, !IsPreview()) &&
884 GroupOnSurface->SpinBox_DY->isValid(msg, !IsPreview());
886 ok = GroupXYZ->SpinBox_DX->isValid(msg, !IsPreview()) &&
887 GroupXYZ->SpinBox_DY->isValid(msg, !IsPreview()) &&
888 GroupXYZ->SpinBox_DZ->isValid(msg, !IsPreview());
897 //=================================================================================
898 // function : execute
900 //=================================================================================
901 bool MyBasicGUI_PointDlg::execute(ObjectList& objects)
905 GEOM::GEOM_Object_var anObj;
906 QStringList aParameters;
908 GEOM::GEOM_IBasicOperations_var anOper = GEOM::GEOM_IBasicOperations::_narrow(getOperation());
910 switch (getConstructorId()) {
911 case GEOM_POINT_XYZ :
913 double x = GroupXYZ->SpinBox_DX->value();
914 double y = GroupXYZ->SpinBox_DY->value();
915 double z = GroupXYZ->SpinBox_DZ->value();
917 aParameters << GroupXYZ->SpinBox_DX->text();
918 aParameters << GroupXYZ->SpinBox_DY->text();
919 aParameters << GroupXYZ->SpinBox_DZ->text();
921 anObj = anOper->MakePointXYZ(x, y, z);
925 case GEOM_POINT_REF :
927 double dx = GroupRefPoint->SpinBox_DX->value();
928 double dy = GroupRefPoint->SpinBox_DY->value();
929 double dz = GroupRefPoint->SpinBox_DZ->value();
931 aParameters << GroupRefPoint->SpinBox_DX->text();
932 aParameters << GroupRefPoint->SpinBox_DY->text();
933 aParameters << GroupRefPoint->SpinBox_DZ->text();
935 anObj = anOper->MakePointWithReference(myRefPoint.get(), dx, dy, dz);
939 case GEOM_POINT_EDGE :
941 if (myParamCoord->checkedId() == PARAM_VALUE) {
942 anObj = anOper->MakePointOnCurve(myEdge.get(), getParameter());
943 aParameters<<GroupOnCurve->SpinBox_DX->text();
945 else if (myParamCoord->checkedId() == LENGTH_VALUE) {
946 anObj = anOper->MakePointOnCurveByLength(myEdge.get(), getParameter(), myRefPoint.get());
947 aParameters<<GroupOnCurve->SpinBox_DX->text();
949 else if (myParamCoord->checkedId() == COORD_VALUE) {
950 double x = GroupXYZ->SpinBox_DX->value();
951 double y = GroupXYZ->SpinBox_DY->value();
952 double z = GroupXYZ->SpinBox_DZ->value();
954 aParameters << GroupXYZ->SpinBox_DX->text();
955 aParameters << GroupXYZ->SpinBox_DY->text();
956 aParameters << GroupXYZ->SpinBox_DZ->text();
958 anObj = anOper->MakePointOnCurveByCoord(myEdge.get(), x, y, z);
963 case GEOM_POINT_INTINT :
964 anObj = anOper->MakePointOnLinesIntersection(myLine1.get(), myLine2.get());
965 if (!anObj->_is_nil()) {
966 QString aName = getNewObjectName();
967 if (anObj->GetShapeType() == GEOM::COMPOUND && aName.startsWith("Vertex"))
968 initName(tr("GEOM_COMPOUND"));
969 else if (anObj->GetShapeType() == GEOM::VERTEX && aName.startsWith("Compound"))
970 initName(tr("GEOM_VERTEX"));
974 case GEOM_POINT_SURF :
976 if (myParamCoord->checkedId() == PARAM_VALUE) {
977 anObj = anOper->MakePointOnSurface(myFace.get(), getUParameter(), getVParameter());
978 aParameters<<GroupOnSurface->SpinBox_DX->text();
979 aParameters<<GroupOnSurface->SpinBox_DY->text();
981 double x = GroupXYZ->SpinBox_DX->value();
982 double y = GroupXYZ->SpinBox_DY->value();
983 double z = GroupXYZ->SpinBox_DZ->value();
985 aParameters << GroupXYZ->SpinBox_DX->text();
986 aParameters << GroupXYZ->SpinBox_DY->text();
987 aParameters << GroupXYZ->SpinBox_DZ->text();
989 anObj = anOper->MakePointOnSurfaceByCoord(myFace.get(), x, y, z);
996 const int id = getConstructorId();
997 if(!anObj->_is_nil() && !IsPreview() && (id == GEOM_POINT_XYZ ||
998 id == GEOM_POINT_REF ||
999 id == GEOM_POINT_EDGE ||
1000 id == GEOM_POINT_SURF)) {
1001 anObj->SetParameters(aParameters.join(":").toLatin1().constData());
1004 if (id == GEOM_POINT_REF || id == GEOM_POINT_EDGE || id == GEOM_POINT_SURF) {
1005 TopoDS_Shape aShape;
1006 if (GEOMBase::GetShape(anObj, aShape) && !aShape.IsNull() &&
1007 aShape.ShapeType() == TopAbs_VERTEX) {
1008 gp_Pnt aPnt = BRep_Tool::Pnt(TopoDS::Vertex(aShape));
1009 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1010 int aPrecision = resMgr->integerValue("Geometry", "length_precision", 6);
1011 myX->setText(DlgRef::PrintDoubleValue(aPnt.X(), aPrecision));
1012 myY->setText(DlgRef::PrintDoubleValue(aPnt.Y(), aPrecision));
1013 myZ->setText(DlgRef::PrintDoubleValue(aPnt.Z(), aPrecision));
1022 if (!anObj->_is_nil()) {
1023 objects.push_back(anObj._retn());
1029 //=================================================================================
1030 // function : addSubshapeToStudy
1031 // purpose : virtual method to add new SubObjects if local selection
1032 //=================================================================================
1033 void MyBasicGUI_PointDlg::addSubshapesToStudy()
1035 switch (getConstructorId()) {
1036 case GEOM_POINT_REF:
1037 GEOMBase::PublishSubObject(myRefPoint.get());
1039 case GEOM_POINT_EDGE:
1040 GEOMBase::PublishSubObject(myEdge.get());
1042 case GEOM_POINT_INTINT:
1043 GEOMBase::PublishSubObject(myLine1.get());
1044 GEOMBase::PublishSubObject(myLine2.get());
1046 case GEOM_POINT_SURF:
1047 GEOMBase::PublishSubObject(myFace.get());
1054 //=================================================================================
1055 // function : ClickParamCoord()
1057 //=================================================================================
1058 void MyBasicGUI_PointDlg::ClickParamCoord(int id)
1060 updateParamCoord(true);
1061 displayPreview(true);
1064 //=================================================================================
1065 // function : updateParamCoord
1067 //=================================================================================
1068 void MyBasicGUI_PointDlg::updateParamCoord(bool theIsUpdate)
1070 bool isParam = myParamCoord->checkedId() == PARAM_VALUE;
1071 bool isLength = myParamCoord->checkedId() == LENGTH_VALUE;
1073 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1074 double step = resMgr->doubleValue("Geometry", "SettingsGeomStep", 100);
1076 const int id = getConstructorId();
1077 if (id == GEOM_POINT_EDGE) {
1078 GroupOnCurve->TextLabel2->setVisible(isLength);
1079 GroupOnCurve->PushButton2->setVisible(isLength);
1080 GroupOnCurve->LineEdit2->setVisible(isLength);
1081 GroupOnCurve->TextLabel3->setVisible(isParam || isLength);
1082 GroupOnCurve->SpinBox_DX->setVisible(isParam || isLength);
1084 initSpinBox(GroupOnCurve->SpinBox_DX, 0., 1., 0.1, "parametric_precision");
1085 // GroupOnCurve->SpinBox_DX->setValue(0.5);
1086 GroupOnCurve->TextLabel3->setText(tr("GEOM_PARAMETER"));
1089 initSpinBox(GroupOnCurve->SpinBox_DX, COORD_MIN, COORD_MAX, step, "length_precision");
1090 // GroupOnCurve->SpinBox_DX->setValue(0);
1091 GroupOnCurve->TextLabel3->setText(tr("GEOM_LENGTH"));
1094 else if (id == GEOM_POINT_SURF) {
1095 GroupOnSurface->TextLabel2->setShown(isParam);
1096 GroupOnSurface->TextLabel3->setShown(isParam);
1097 GroupOnSurface->SpinBox_DX->setShown(isParam);
1098 GroupOnSurface->SpinBox_DY->setShown(isParam);
1101 GroupXYZ->setShown(!isParam && !isLength);
1104 QTimer::singleShot(50, this, SLOT(updateSize()));
1107 //=================================================================================
1108 // function : onBtnPopup()
1110 //=================================================================================
1111 void MyBasicGUI_PointDlg::onBtnPopup(QAction* a)
1113 globalSelection(HEXABLOCKGUI::currentOccGView->getViewWindow()); // close local contexts, if any
1114 myNeedType = myActions[a] == SelectEdge ? TopAbs_EDGE : TopAbs_WIRE;
1115 localSelection(HEXABLOCKGUI::currentOccGView->getViewWindow(), myNeedType);
1118 //=================================================================================
1119 // function : updateSize
1120 // purpose : adjust dialog size to minimum
1121 //=================================================================================
1122 void MyBasicGUI_PointDlg::updateSize()
1124 qApp->processEvents();
1126 resize(minimumSizeHint());
1139 void MyBasicGUI_PointDlg::setDocumentModel( HEXABLOCK::GUI::DocumentModel* m)
1144 void MyBasicGUI_PointDlg::setPatternDataSelectionModel( HEXABLOCK::GUI::PatternDataSelectionModel* s)
1146 _patternDataSelectionModel = s;
1149 void MyBasicGUI_PointDlg::_initInputWidget()
1152 // QVBoxLayout* mainLayout = new QVBoxLayout( centralWidget() );
1153 // setLayout( mainLayout );
1154 // QHBoxLayout* up = new QHBoxLayout( centralWidget() );
1155 // QVBoxLayout* down = new QVBoxLayout( centralWidget() );
1157 // QGroupBox *GroupBoxName = new QGroupBox(centralWidget());
1158 // GroupBoxName->setObjectName(QString::fromUtf8("GroupBoxName"));
1159 // GroupBoxName->setTitle("Vertex");
1160 // QHBoxLayout *hboxLayout1 = new QHBoxLayout(GroupBoxName);
1161 // hboxLayout1->setSpacing(6);
1162 // hboxLayout1->setContentsMargins(9, 9, 9, 9);
1163 // hboxLayout1->setObjectName(QString::fromUtf8("hboxLayout1"));
1164 // QLabel *NameLabel = new QLabel(GroupBoxName);
1165 // NameLabel->setObjectName(QString::fromUtf8("NameLabel"));
1166 // NameLabel->setWordWrap(false);
1167 // NameLabel->setText( "Name : " );
1168 // hboxLayout1->addWidget( NameLabel );
1169 // mainFrame()->_vertex_le = new QLineEdit( GroupBoxName );
1170 // mainFrame()->_vertex_le->setObjectName(QString::fromUtf8("mainFrame()->_vertex_le"));
1171 // hboxLayout1->addWidget(mainFrame()->_vertex_le);
1173 // layout()->addWidget( GroupBoxName );
1178 QValidator *validator = new QRegExpValidator(rx, this);
1180 // setProperty( "HexaWidgetType", QVariant::fromValue(HEXABLOCK::GUI::VERTEX_TREE) );
1181 // installEventFilter(this);
1183 mainFrame()->_vertex_le->setProperty( "HexaWidgetType", QVariant::fromValue(HEXABLOCK::GUI::VERTEX_TREE) );
1184 mainFrame()->_vertex_le->installEventFilter(this);
1185 mainFrame()->_vertex_le->setValidator( validator );
1188 void MyBasicGUI_PointDlg::clear()
1191 mainFrame()->_vertex_le->clear();
1192 mainFrame()->_vertex_le->setProperty("QModelIndex", QVariant());
1195 void MyBasicGUI_PointDlg::_initViewManager()
1197 // SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
1198 // _mgr = dynamic_cast<LightApp_SelectionMgr*>( anApp->selectionMgr() );
1199 // _vtkVm = anApp->getViewManager( SVTK_Viewer::Type(), false );
1200 // _occVm = anApp->getViewManager( OCCViewer_Viewer::Type(), false );
1201 // SUIT_ViewManager* activeVm = anApp->activeViewManager();
1202 // onWindowActivated ( activeVm );
1206 // bool MyBasicGUI_PointDlg::_onSelectionChanged( const QItemSelection& sel, QLineEdit* le )
1208 // QModelIndexList l = sel.indexes();
1209 // if ( l.count() == 0 ) return false;
1211 // //type from selection (first)
1212 // QModelIndex selected = l[0];
1213 // int selType = selected.data(HEXABLOCK::GUI::HEXA_TREE_ROLE).toInt();
1216 // QVariant v = le->property("HexaWidgetType");
1217 // if ( !v.isValid() ) return false;
1218 // HexaWidgetType wType = v.value<HexaWidgetType>();
1220 // // check selection compatibility between selection and widget
1221 // if ( selType != wType ){
1222 // SUIT_MessageBox::information( 0,
1224 // tr("Bad selection type: please select a %1").arg( _strHexaWidgetType[wType]) );
1228 // //fill the lineEdit if selection is OK
1229 // le->setText( selected.data().toString() );// name
1230 // le->setProperty("QModelIndex", QVariant::fromValue(selected) );
1236 void MyBasicGUI_PointDlg::onSelectionChanged( const QItemSelection& sel, const QItemSelection& unsel )
1238 QString className = metaObject()->className();
1239 // QItemSelectionModel* selector = dynamic_cast<QItemSelectionModel*>(sender());
1241 if (_patternDataSelectionModel)
1242 _patternDataSelectionModel->highlightEltsWithAssocs(sel.indexes());
1244 if ( _selectionMutex ) return;
1245 if ( _currentObj != mainFrame()->_vertex_le ) return;
1249 QModelIndexList l = sel.indexes();
1250 if ( l.count() != 0 ){
1251 //type from selection (first)
1252 QModelIndex selected = l[0];
1253 int selType = selected.data(HEXABLOCK::GUI::HEXA_TREE_ROLE).toInt();
1254 // check selection compatibility between selection and widget
1255 if ( selType == HEXABLOCK::GUI::VERTEX_TREE ){
1256 mainFrame()->_vertex_le->setText( selected.data().toString() );// name
1257 mainFrame()->_vertex_le->setProperty("QModelIndex", QVariant::fromValue(selected) );
1260 _patternDataSelectionModel->clearSelection();
1261 SUIT_MessageBox::information( 0,
1263 tr("Bad selection type: please select a %1").arg( "VERTEX" ) );
1269 void MyBasicGUI_PointDlg::onWindowActivated(SUIT_ViewManager* vm)
1271 // SUIT_ViewWindow* v = vm->getActiveView();
1272 QString vmType = vm->getType();
1273 if ( (vmType == SVTK_Viewer::Type()) || (vmType == VTKViewer_Viewer::Type()) ){
1274 mainFrame()->_vertex_le->setFocus();
1275 } else if ( vmType == OCCViewer_Viewer::Type() ){
1276 // lines_lw->setFocus();
1277 // ConstructorsClicked(0);
1278 ConstructorsClicked( getConstructorId() );
1282 // ============================================================== _isLineOrListWidget
1284 * Return true is the widget is a line or a list
1287 bool MyBasicGUI_PointDlg::_isLineOrListWidget(QObject *widget)
1289 if (widget == NULL) return false;
1291 QLineEdit *lineEdit = dynamic_cast<QLineEdit*>(widget);
1292 QListWidget *listWidget = dynamic_cast<QListWidget*>(widget);
1293 return (lineEdit != NULL) || (listWidget != NULL);
1295 }//_isLineOrListWidget
1299 // ============================================================== _highlightWidget
1301 * Highlight the given widget with the given color.
1303 void MyBasicGUI_PointDlg::_highlightWidget(QObject *obj, Qt::GlobalColor clr)
1305 if (!_isLineOrListWidget(obj)) return;
1307 QWidget *widget = dynamic_cast<QWidget*>(obj); //sure it's not NULL (_isLineOrListWidget(obj))
1308 QPalette palette1 = widget->palette();
1309 palette1.setColor(widget->backgroundRole(), clr);
1310 widget->setPalette(palette1);
1315 bool MyBasicGUI_PointDlg::eventFilter(QObject *obj, QEvent *event)
1318 // if (event->type() == QEvent::FocusOut)
1319 // _highlightWidget(obj, Qt::white);
1322 if ( (event->type() != QEvent::FocusIn)
1323 or (obj != mainFrame()->_vertex_le) ){
1324 return MyGEOMBase_Skeleton::eventFilter(obj, event);
1326 // _highlightWidget(obj, Qt::yellow);
1329 QModelIndex vxIndex;
1332 // HEXABLOCKGUI::currentVtkView->raise();
1333 HEXABLOCKGUI::currentDocGView->setVertexSelection();
1335 vxVariant = mainFrame()->_vertex_le->property("QModelIndex");
1336 if ( !vxVariant.isValid() ) {
1337 return MyGEOMBase_Skeleton::eventFilter(obj, event);
1339 vxIndex = vxVariant.value<QModelIndex>();
1340 _selectionMutex = true;
1341 _patternDataSelectionModel->select( vxIndex, QItemSelectionModel::Clear );
1342 _patternDataSelectionModel->select( vxIndex, QItemSelectionModel::Select );
1343 _selectionMutex = false;
1348 void MyBasicGUI_PointDlg::hideEvent ( QHideEvent * event )
1350 disconnect( _patternDataSelectionModel, SIGNAL( selectionChanged ( const QItemSelection &, const QItemSelection &) ),
1351 this, SLOT( onSelectionChanged(const QItemSelection &, const QItemSelection &) ) );
1353 //Disconnection salome selection signals
1354 if (HEXABLOCKGUI::selectionMgr() != NULL)
1355 disconnect( HEXABLOCKGUI::selectionMgr() , SIGNAL(currentSelectionChanged()),
1356 this, SLOT(onCurrentSelectionChanged()) );
1358 //Disconnect vtk window activation signals
1359 if (HEXABLOCKGUI::currentDocGView->getViewWindow() != NULL)
1360 disconnect( HEXABLOCKGUI::currentDocGView->getViewWindow()->getViewManager(),
1361 SIGNAL( activated(SUIT_ViewManager*) ),
1362 this, SLOT( onWindowActivated(SUIT_ViewManager*) ) );
1364 //Disconnect occ window activation signals
1365 if (HEXABLOCKGUI::currentOccGView->getViewWindow() != NULL)
1366 disconnect( HEXABLOCKGUI::currentOccGView->getViewWindow()->getViewManager(),
1367 SIGNAL( activated(SUIT_ViewManager*) ),
1368 this, SLOT( onWindowActivated(SUIT_ViewManager*) ) );
1370 _documentModel->allowEdition();
1371 DeactivateActiveDialog();
1372 MyGEOMBase_Skeleton::hideEvent( event );
1375 void MyBasicGUI_PointDlg::showEvent( QShowEvent * event )
1377 _documentModel->disallowEdition();
1378 // _patternDataSelectionModel->clearSelection();
1379 connect( _patternDataSelectionModel, SIGNAL( selectionChanged ( const QItemSelection &, const QItemSelection &) ),
1380 this, SLOT( onSelectionChanged(const QItemSelection &, const QItemSelection &) ) );
1382 //Connect to salome selection signals
1383 if (HEXABLOCKGUI::selectionMgr() != NULL)
1385 connect( HEXABLOCKGUI::selectionMgr(), SIGNAL(currentSelectionChanged()),
1386 this, SLOT(onCurrentSelectionChanged()), Qt::UniqueConnection );
1389 //Connect to vtk window activation signals
1390 if (HEXABLOCKGUI::currentDocGView->getViewWindow() != NULL)
1392 connect( HEXABLOCKGUI::currentDocGView->getViewWindow()->getViewManager(), SIGNAL( activated(SUIT_ViewManager*) ),
1393 this, SLOT( onWindowActivated(SUIT_ViewManager*) ), Qt::UniqueConnection );
1396 //connect to occ window activation signals
1397 if (HEXABLOCKGUI::currentOccGView->getViewWindow() != NULL)
1399 connect( HEXABLOCKGUI::currentOccGView->getViewWindow()->getViewManager(),
1400 SIGNAL( activated(SUIT_ViewManager*) ),
1401 this, SLOT( onWindowActivated(SUIT_ViewManager*) ), Qt::UniqueConnection );
1404 // connect( _mgr, SIGNAL(currentSelectionChanged()), this, SLOT(onCurrentSelectionChanged()) );
1405 // connect( _vtkVm, SIGNAL( activated(SUIT_ViewManager*) ), this, SLOT( onWindowActivated(SUIT_ViewManager*) ) );
1406 // connect( _occVm, SIGNAL( activated(SUIT_ViewManager*) ), this, SLOT( onWindowActivated(SUIT_ViewManager*) ) );
1409 SalomeApp_Application* app = (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() );
1411 if ( !myGeomGUI && app )
1412 myGeomGUI = dynamic_cast<GeometryGUI*>( app->module( "Geometry" ) );
1415 ActivateThisDialog();
1416 MyGEOMBase_Skeleton::showEvent ( event );
1422 bool MyBasicGUI_PointDlg::onAccept( const bool publish, const bool useTransaction )
1425 GEOM::GEOM_Object_ptr newVertex;
1426 QString newVertexEntry;
1427 QString newVertexName;
1428 QString newVertexBrep;
1433 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
1434 if ( !appStudy ) return false;
1435 _PTR(Study) aStudy = appStudy->studyDS();
1437 bool aLocked = (_PTR(AttributeStudyProperties) (aStudy->GetProperties()))->IsLocked();
1439 SUIT_MessageBox::warning ( (QWidget*)SUIT_Session::session()->activeApplication()->desktop(),
1440 QObject::tr("WRN_WARNING"),
1441 QObject::tr("WRN_STUDY_LOCKED"),
1442 QObject::tr("BUT_OK") );
1447 if ( !isValid( msg ) ) {
1452 erasePreview( false );
1454 bool result = false;
1457 if ( ( !publish && !useTransaction ) || openCommand() ) {
1458 SUIT_OverrideCursor wc;
1459 SUIT_Session::session()->activeApplication()->putInfo( "" );
1461 if ( !execute( objects ) || !getOperation()->IsDone() ) {
1467 addSubshapesToStudy(); // add Subshapes if local selection
1468 const int nbObjs = objects.size();
1469 QStringList anEntryList;
1471 for ( ObjectList::iterator it = objects.begin(); it != objects.end(); ++it ) {
1472 GEOM::GEOM_Object_var obj=*it;
1474 QString aName = getNewObjectName();
1476 if (aName.isEmpty())
1477 aName = getPrefix(obj);
1479 // Try to find a unique name
1480 aName = GEOMBase::GetDefaultName(aName, extractPrefix());
1482 // Don't check name uniqueness in case of numerous objects
1483 aName = aName + "_" + QString::number(aNumber++);
1486 // PAL6521: use a prefix, if some dialog box doesn't reimplement getNewObjectName()
1487 if ( aName.isEmpty() )
1488 aName = GEOMBase::GetDefaultName( getPrefix( obj ) );
1490 anEntryList << addInStudy( obj, aName.toLatin1().constData() );
1493 newVertexEntry = anEntryList[0];
1494 TopoDS_Shape aShape;
1495 GEOMBase::GetShape( newVertex, aShape );
1496 if ( !aShape.IsNull() ){
1497 newVertexName = GEOMBase::GetName( newVertex );
1498 newVertexBrep = HEXABLOCK::GUI::shape2string( aShape ).c_str();
1499 aPnt = BRep_Tool::Pnt(TopoDS::Vertex(aShape));
1503 display( obj, false );
1504 #ifdef WITHGENERICOBJ
1505 // obj has been published in study. Its refcount has been incremented.
1506 // It is safe to decrement its refcount
1507 // so that it will be destroyed when the entry in study will be removed
1512 // asv : fix of PAL6454. If publish==false, then the original shape
1513 // was modified, and need to be re-cached in GEOM_Client before redisplay
1514 // clearShapeBuffer( obj );
1515 // withChildren=true, updateView=false
1516 redisplay( obj, true, false );
1523 if( SUIT_Application* anApp = SUIT_Session::session()->activeApplication() ) {
1524 if( LightApp_Application* aLightApp = dynamic_cast<LightApp_Application*>( anApp ) ){
1525 aLightApp->browseObjects( anEntryList, isApplyAndClose(), isOptimizedBrowsing() );
1527 anApp->putInfo( QObject::tr("GEOM_PRP_DONE") );
1536 catch( const SALOME::SALOME_Exception& e ) {
1537 SalomeApp_Tools::QtCatchCorbaException( e );
1544 SUIT_OverrideCursor wc;
1545 if ( !_documentModel ) return false;
1546 if ( !_patternDataSelectionModel ) return false;
1547 const HEXABLOCK::GUI::PatternDataModel* patternDataModel = dynamic_cast<const HEXABLOCK::GUI::PatternDataModel*>( _patternDataSelectionModel->model() );
1548 if ( !patternDataModel ) return false;
1551 QVariant v = mainFrame()->_vertex_le->property("QModelIndex");
1552 if ( !v.isValid() ) return false;
1553 QModelIndex iVertex = patternDataModel->mapToSource( v.value<QModelIndex>() );
1555 if ( iVertex.isValid() ){
1556 HEXABLOCK::GUI::DocumentModel::GeomObj aPoint;
1557 aPoint.shapeName = newVertexName;
1558 aPoint.subid = QString::number(-1);
1559 aPoint.brep = newVertexBrep;
1560 _documentModel->setGeomObjName(newVertexEntry, newVertexName);
1561 _documentModel->setGeomObjEntry(newVertexName, newVertexEntry);
1562 // _documentModel->addAssociation( iVertex, aPoint );
1563 _documentModel->setVertexAssociation(iVertex, aPnt.X(), aPnt.Y(), aPnt.Z());
1564 // to select/highlight result
1565 // _patternDataSelectionModel->clearSelection();
1566 // mainFrame()->_vertex_le->setFocus();
1568 // globalSelection(HEXABLOCKGUI::currentOccGView->getViewWindow());
1569 // localSelection(HEXABLOCKGUI::currentOccGView->getViewWindow(), TopAbs_VERTEX);
1570 _patternDataSelectionModel->select( patternDataModel->mapFromSource(iVertex), QItemSelectionModel::Clear );
1571 _patternDataSelectionModel->select( patternDataModel->mapFromSource(iVertex), QItemSelectionModel::Select );
1575 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE VERTEX ASSOCIATION" ) );