]> SALOME platform Git repositories - modules/hexablock.git/blob - src/HEXABLOCKGUI/MyBasicGUI_PointDlg.cxx
Salome HOME
Merge from V6_main_20120808 08Aug12
[modules/hexablock.git] / src / HEXABLOCKGUI / MyBasicGUI_PointDlg.cxx
1 // Copyright (C) 2009-2012  CEA/DEN, EDF R&D
2 //
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.
7 //
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #include "MyBasicGUI_PointDlg.hxx"
21
22 #include <SUIT_ResourceMgr.h>
23 #include <SUIT_Session.h>
24 #include <SalomeApp_Application.h>
25 #include <LightApp_SelectionMgr.h>
26
27 #include <GeometryGUI.h>
28 #include <GEOMBase.h>
29
30 #include "MyDlgRef.hxx"
31
32 #include <GEOMImpl_Types.hxx>
33
34 #include <QApplication>
35 #include <QButtonGroup>
36 #include <QHBoxLayout>
37 #include <QLabel>
38 #include <QRadioButton>
39 #include <QMenu>
40 #include <QTimer>
41
42 #include <gp_Pnt.hxx>
43 #include <TopoDS_Shape.hxx>
44 #include <TopAbs_ShapeEnum.hxx>
45 #include <TopoDS.hxx>
46 #include <BRep_Tool.hxx>
47 #include <TopExp.hxx>
48 #include <TColStd_IndexedMapOfInteger.hxx>
49 #include <TopTools_IndexedMapOfShape.hxx>
50
51
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>
57
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
64 #define PARAM_VALUE 0
65 #define COORD_VALUE 1
66 #define LENGTH_VALUE 2
67
68 #define GEOM_POINT_XYZ    0
69 #define GEOM_POINT_REF    1
70 #define GEOM_POINT_EDGE   2
71 #define GEOM_POINT_INTINT 3
72 #define GEOM_POINT_SURF   4
73
74 #define SPACING 6
75 #define MARGIN  9
76
77 using namespace HEXABLOCK::GUI;
78
79 Q_DECLARE_METATYPE(QModelIndex);
80 Q_DECLARE_METATYPE(HEXABLOCK::GUI::HexaTreeRole);
81
82 enum { SelectEdge, SelectWire };
83
84 //=================================================================================
85 // class    : MyBasicGUI_PointDlg()
86 // purpose  : Constructs a MyBasicGUI_PointDlg which is a child of 'parent', with the
87 //            name 'name' and widget flags set to 'f'.
88 //            The dialog will by default be modeless, unless you set 'modal' to
89 //            TRUE to construct a modal dialog.
90 //=================================================================================
91 MyBasicGUI_PointDlg::MyBasicGUI_PointDlg(GeometryGUI* theGeometryGUI, QWidget* parent,
92                                       bool modal, Qt::WindowFlags fl)
93   : MyGEOMBase_Skeleton(theGeometryGUI, parent, modal, fl),
94     myBusy (false),
95     _documentModel(0),
96     _patternDataSelectionModel(0),
97     _mgr(0),
98     _vtkVm(0),
99     _occVm(0),
100     _currentObj(0),
101     _selectionMutex(false)
102 {
103   QWidget* w = centralWidget();
104   QString objectName = w->objectName();
105   QString className = w->metaObject()->className();
106   MESSAGE("*  centralWidget() " << w );
107   MESSAGE("*  centralWidget()->objectName() is "<< objectName.toStdString() ); //toStdString()
108   MESSAGE("*  centralWidget()->metaObject()->className() is "<< className.toStdString() );
109 ;
110   SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
111   QPixmap image0 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_POINT")));
112   QPixmap image1 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_POINT_EDGE")));
113   QPixmap image2 (aResMgr->loadPixmap("GEOM", tr("ICON_SELECT")));
114   QPixmap image3 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_POINT_REF")));
115   QPixmap image4 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_POINT_LINES")));
116   QPixmap image5 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_POINT_FACE")));
117   QPixmap image6 (aResMgr->loadPixmap("GEOM", tr("ICO_LINE")));
118   QPixmap image7 (aResMgr->loadPixmap("GEOM", tr("ICO_WIRE")));
119
120 //   setWindowTitle(tr("GEOM_POINT_TITLE"));
121   setWindowTitle( tr("Vertex Association") );
122   setMinimumWidth(260);
123
124
125
126
127   mainFrame()->GroupConstructors->setTitle(tr("GEOM_POINTS"));
128   mainFrame()->RadioButton1->setIcon(image0);
129   mainFrame()->RadioButton2->setIcon(image3);
130   mainFrame()->RadioButton3->setIcon(image1);
131   mainFrame()->RadioButton4->show();
132   mainFrame()->RadioButton4->setIcon(image4);
133   mainFrame()->RadioButton5->show();
134   mainFrame()->RadioButton5->setIcon(image5);
135
136   myParamGroup = new QGroupBox(centralWidget());
137   myParamCoord = new QButtonGroup(myParamGroup);
138   QHBoxLayout* boxLayout = new QHBoxLayout(myParamGroup);
139   boxLayout->setMargin(MARGIN); boxLayout->setSpacing(SPACING);
140   QRadioButton* btn = new QRadioButton(tr("GEOM_PARAM_VALUE"), myParamGroup);
141   myParamCoord->addButton(btn, PARAM_VALUE);
142   boxLayout->addWidget(btn);
143   btn = new QRadioButton(tr("GEOM_LENGTH_VALUE"), myParamGroup);
144   myParamCoord->addButton(btn, LENGTH_VALUE);
145   boxLayout->addWidget(btn);
146   btn = new QRadioButton(tr("GEOM_COORD_VALUE"), myParamGroup);
147   myParamCoord->addButton(btn, COORD_VALUE);
148   boxLayout->addWidget(btn);
149   myParamCoord->setExclusive(true);
150   myParamCoord->button(PARAM_VALUE)->setChecked(true);
151
152   GroupXYZ = new DlgRef_3Spin(centralWidget());
153   GroupXYZ->GroupBox1->setTitle(tr("GEOM_COORDINATES"));
154   GroupXYZ->TextLabel1->setText(tr("GEOM_X"));
155   GroupXYZ->TextLabel2->setText(tr("GEOM_Y"));
156   GroupXYZ->TextLabel3->setText(tr("GEOM_Z"));
157
158   GroupOnCurve = new DlgRef_2Sel1Spin(centralWidget());
159   GroupOnCurve->GroupBox1->setTitle(tr("GEOM_POINT_ON_EDGE"));
160   GroupOnCurve->TextLabel1->setText(tr("GEOM_EDGE"));
161   GroupOnCurve->TextLabel2->setText(tr("GEOM_START_POINT"));
162   GroupOnCurve->TextLabel3->setText(tr("GEOM_PARAMETER"));
163   GroupOnCurve->PushButton1->setIcon(image2);
164   GroupOnCurve->PushButton2->setIcon(image2);
165
166   GroupOnSurface = new DlgRef_1Sel2Spin(centralWidget());
167   GroupOnSurface->GroupBox1->setTitle(tr("GEOM_POINT_ON_FACE"));
168   GroupOnSurface->TextLabel1->setText(tr("GEOM_FACE"));
169   GroupOnSurface->TextLabel2->setText(tr("GEOM_UPARAMETER"));
170   GroupOnSurface->TextLabel3->setText(tr("GEOM_VPARAMETER"));
171   GroupOnSurface->PushButton1->setIcon(image2);
172
173   GroupRefPoint = new DlgRef_1Sel3Spin(centralWidget());
174   GroupRefPoint->GroupBox1->setTitle(tr("GEOM_REF_POINT"));
175   GroupRefPoint->TextLabel1->setText(tr("GEOM_POINT"));
176   GroupRefPoint->PushButton1->setIcon(image2);
177   GroupRefPoint->TextLabel2->setText(tr("GEOM_DX"));
178   GroupRefPoint->TextLabel3->setText(tr("GEOM_DY"));
179   GroupRefPoint->TextLabel4->setText(tr("GEOM_DZ"));
180
181   /* popup menu for line intersect buttons */
182   myBtnPopup = new QMenu(this);
183   QIcon ico_line = QIcon(image6);
184   QIcon ico_wire = QIcon(image7);
185   myActions[myBtnPopup->addAction(ico_line, tr("GEOM_EDGE"))] = SelectEdge;
186   myActions[myBtnPopup->addAction(ico_wire, tr("GEOM_WIRE"))] = SelectWire;
187
188   GroupLineIntersection = new DlgRef_2Sel(centralWidget());
189   GroupLineIntersection->GroupBox1->setTitle(tr("GEOM_LINE_INTERSECTION"));
190   GroupLineIntersection->TextLabel1->setText(tr("GEOM_LINE1"));
191   GroupLineIntersection->TextLabel2->setText(tr("GEOM_LINE2"));
192   GroupLineIntersection->PushButton1->setIcon(image2);
193   GroupLineIntersection->PushButton1->setMenu(myBtnPopup);
194   GroupLineIntersection->PushButton2->setIcon(image2);
195   GroupLineIntersection->PushButton2->setMenu(myBtnPopup);
196   GroupLineIntersection->LineEdit2->setEnabled(false);
197
198   myCoordGrp = new QGroupBox(tr("GEOM_COORDINATES_RES"), centralWidget());
199   QGridLayout* myCoordGrpLayout = new QGridLayout(myCoordGrp);
200   myCoordGrpLayout->addWidget(new QLabel(tr("GEOM_X"), myCoordGrp), 0, 0);
201   myX = new QLineEdit(myCoordGrp);
202   myCoordGrpLayout->addWidget(myX, 0, 1);
203   myCoordGrpLayout->addWidget(new QLabel(tr("GEOM_Y"), myCoordGrp), 1, 0);
204   myY = new QLineEdit(myCoordGrp);
205   myCoordGrpLayout->addWidget(myY, 1, 1);
206   myCoordGrpLayout->addWidget(new QLabel(tr("GEOM_Z"), myCoordGrp), 2, 0);
207   myZ = new QLineEdit(myCoordGrp);
208   myCoordGrpLayout->addWidget(myZ, 2, 1);
209
210   QVBoxLayout* layout = new QVBoxLayout(centralWidget());
211   layout->setMargin(0); layout->setSpacing(6);
212   layout->addWidget(myParamGroup);
213   layout->addWidget(GroupXYZ);
214   layout->addWidget(GroupOnCurve);
215   layout->addWidget(GroupOnSurface);
216   layout->addWidget(GroupRefPoint);
217   layout->addWidget(GroupLineIntersection);
218   layout->addWidget(myCoordGrp);
219
220
221   myX->setReadOnly(true);
222   myY->setReadOnly(true);
223   myZ->setReadOnly(true);
224
225   myX->setEnabled(false);
226   myY->setEnabled(false);
227   myZ->setEnabled(false);
228
229   QPalette aPal = myX->palette();
230   aPal.setColor(QPalette::Disabled, QPalette::Text, QColor(0, 0, 0));
231   myX->setPalette(aPal);
232   myY->setPalette(aPal);
233   myZ->setPalette(aPal);
234
235   setHelpFileName("gui_asso_quad_to_geom.html#associate-to-a-vertex-of-the-geometry");/*"create_point_page.html"*/
236
237   Init();
238
239   /* HEXABLOCK */
240   _initInputWidget();
241   _initViewManager();
242   /* HEXABLOCK */
243 }
244
245
246 //=================================================================================
247 // function : ~MyBasicGUI_PointDlg()
248 // purpose  : Destructor
249 //=================================================================================
250 MyBasicGUI_PointDlg::~MyBasicGUI_PointDlg()
251 {
252 }
253
254
255
256
257
258 //=================================================================================
259 // function : Init()
260 // purpose  :
261 //=================================================================================
262 void MyBasicGUI_PointDlg::Init()
263 {
264   MESSAGE("MyBasicGUI_PointDlg::Init() ");
265
266   GroupOnCurve->LineEdit1->setReadOnly(true);
267   GroupOnCurve->LineEdit2->setReadOnly(true);
268   GroupOnSurface->LineEdit1->setReadOnly(true);
269   GroupRefPoint->LineEdit1->setReadOnly(true);
270   GroupLineIntersection->LineEdit1->setReadOnly(true);
271   GroupLineIntersection->LineEdit2->setReadOnly(true);
272   GroupLineIntersection->LineEdit1->setEnabled(true);
273   GroupLineIntersection->LineEdit2->setEnabled(false);
274
275   myEdge.nullify();
276   myFace.nullify();
277   myRefPoint.nullify();
278   myLine1.nullify();
279   myLine2.nullify();
280   myNeedType = TopAbs_VERTEX;
281
282   myEditCurrentArgument = 0;
283
284   /* Get setting of step value from file configuration */
285   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
286   double step = resMgr->doubleValue("Geometry", "SettingsGeomStep", 100);
287
288   /* min, max, step and decimals for spin boxes */
289   initSpinBox(GroupXYZ->SpinBox_DX, COORD_MIN, COORD_MAX, step, "length_precision");
290   initSpinBox(GroupXYZ->SpinBox_DY, COORD_MIN, COORD_MAX, step, "length_precision");
291   initSpinBox(GroupXYZ->SpinBox_DZ, COORD_MIN, COORD_MAX, step, "length_precision");
292   GroupXYZ->SpinBox_DX->setValue(0.0);
293   GroupXYZ->SpinBox_DY->setValue(0.0);
294   GroupXYZ->SpinBox_DZ->setValue(0.0);
295
296   initSpinBox(GroupRefPoint->SpinBox_DX, COORD_MIN, COORD_MAX, step, "length_precision");
297   initSpinBox(GroupRefPoint->SpinBox_DY, COORD_MIN, COORD_MAX, step, "length_precision");
298   initSpinBox(GroupRefPoint->SpinBox_DZ, COORD_MIN, COORD_MAX, step, "length_precision");
299   GroupRefPoint->SpinBox_DX->setValue(0.0);
300   GroupRefPoint->SpinBox_DY->setValue(0.0);
301   GroupRefPoint->SpinBox_DZ->setValue(0.0);
302
303   step = 0.1;
304
305   initSpinBox(GroupOnCurve->SpinBox_DX, 0., 1., step, "parametric_precision");
306   GroupOnCurve->SpinBox_DX->setValue(0.5);
307
308   initSpinBox(GroupOnSurface->SpinBox_DX, 0., 1., step, "parametric_precision");
309   GroupOnSurface->SpinBox_DX->setValue(0.5);
310   initSpinBox(GroupOnSurface->SpinBox_DY, 0., 1., step, "parametric_precision");
311   GroupOnSurface->SpinBox_DY->setValue(0.5);
312
313   MESSAGE("MyBasicGUI_PointDlg::Init() : myGeomGUI " << myGeomGUI);
314   /* signals and slots connections */
315   if ( myGeomGUI ){
316     connect(myGeomGUI,      SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
317     connect(myGeomGUI,      SIGNAL(SignalCloseAllDialogs()),        this, SLOT(ClickOnCancel()));
318   }
319   //connect(buttonOk(),     SIGNAL(clicked()), this, SLOT(ClickOnOk()));
320   connect(buttonApply(),  SIGNAL(clicked()), this, SLOT(ClickOnApply()));
321
322   connect(this,           SIGNAL(constructorsClicked(int)), this, SLOT(ConstructorsClicked(int)));
323
324   connect(myParamCoord,   SIGNAL(buttonClicked(int)), this, SLOT(ClickParamCoord(int)));
325
326   connect(GroupOnCurve->PushButton1,          SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
327   connect(GroupOnCurve->PushButton2,          SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
328   connect(GroupOnSurface->PushButton1,        SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
329   connect(GroupLineIntersection->PushButton1, SIGNAL(pressed()), this, SLOT(SetEditCurrentArgument()));
330   connect(GroupLineIntersection->PushButton2, SIGNAL(pressed()), this, SLOT(SetEditCurrentArgument()));
331
332   connect(myBtnPopup, SIGNAL(triggered(QAction*)), this, SLOT(onBtnPopup(QAction*)));
333
334   connect(GroupOnCurve->SpinBox_DX,   SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
335   connect(GroupOnSurface->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
336   connect(GroupOnSurface->SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
337   connect(GroupXYZ->SpinBox_DX,       SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
338   connect(GroupXYZ->SpinBox_DY,       SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
339   connect(GroupXYZ->SpinBox_DZ,       SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
340   connect(GroupRefPoint->SpinBox_DX,  SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
341   connect(GroupRefPoint->SpinBox_DY,  SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
342   connect(GroupRefPoint->SpinBox_DZ,  SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
343
344   if ( myGeomGUI ){
345     connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), this,  SLOT(SetDoubleSpinBoxStep(double)));
346
347     connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
348             this,  SLOT(SelectionIntoArgument()));
349   }
350
351   initName(tr("GEOM_VERTEX"));
352
353   ConstructorsClicked(0);
354 }
355
356 //=================================================================================
357 // function : SetDoubleSpinBoxStep()
358 // purpose  : Double spin box management
359 //=================================================================================
360 void MyBasicGUI_PointDlg::SetDoubleSpinBoxStep(double step)
361 {
362   GroupOnCurve->SpinBox_DX->setSingleStep(step);
363   GroupXYZ->SpinBox_DX->setSingleStep(step);
364   GroupXYZ->SpinBox_DY->setSingleStep(step);
365   GroupXYZ->SpinBox_DZ->setSingleStep(step);
366   GroupRefPoint->SpinBox_DX->setSingleStep(step);
367   GroupRefPoint->SpinBox_DY->setSingleStep(step);
368   GroupRefPoint->SpinBox_DZ->setSingleStep(step);
369 }
370
371
372 //=================================================================================
373 // function : ConstructorsClicked()
374 // purpose  : Radio button management
375 //=================================================================================
376 void MyBasicGUI_PointDlg::ConstructorsClicked(int constructorId)
377 {
378 //   HEXABLOCKGUI::currentOccView->raise();
379 //   HEXABLOCKGUI::currentOccView->setFocus();
380   MESSAGE("MyBasicGUI_PointDlg::ConstructorsClicked("<< constructorId << ")");
381   switch (constructorId) {
382   case GEOM_POINT_XYZ:
383     {
384       globalSelection(); // close local contexts, if any
385       myNeedType = TopAbs_VERTEX;
386       localSelection(GEOM::GEOM_Object::_nil(), myNeedType);
387
388       GroupRefPoint->hide();
389       GroupOnCurve->hide();
390       GroupLineIntersection->hide();
391       GroupOnSurface->hide();
392       myCoordGrp->hide();
393       myParamGroup->hide();
394       GroupXYZ->show();
395       break;
396     }
397   case GEOM_POINT_REF:
398     {
399       globalSelection(); // close local contexts, if any
400       myNeedType = TopAbs_VERTEX;
401       localSelection(GEOM::GEOM_Object::_nil(), myNeedType);
402
403       myEditCurrentArgument = GroupRefPoint->LineEdit1;
404       //myEditCurrentArgument->setText("");
405       //myRefPoint.nullify();
406       GroupRefPoint->PushButton1->setDown(true);
407       myParamGroup->hide();
408       GroupXYZ->hide();
409       GroupOnCurve->hide();
410       GroupLineIntersection->hide();
411       GroupOnSurface->hide();
412       GroupRefPoint->show();
413       myCoordGrp->show();
414       break;
415     }
416   case GEOM_POINT_EDGE:
417     {
418       globalSelection(); // close local contexts, if any
419       myNeedType = TopAbs_EDGE;
420       localSelection(GEOM::GEOM_Object::_nil(), myNeedType);
421
422       myEditCurrentArgument = GroupOnCurve->LineEdit1;
423 //      myEditCurrentArgument->setText("");
424 //      myEdge.nullify();
425 //      myRefPoint.nullify();
426       GroupOnCurve->PushButton1->setDown(true);
427       GroupRefPoint->hide();
428       GroupLineIntersection->hide();
429       GroupOnSurface->hide();
430       myParamGroup->show();
431       myParamCoord->button(LENGTH_VALUE)->show();
432       myParamCoord->button(PARAM_VALUE)->setChecked(true);
433       GroupOnCurve->show();
434       myCoordGrp->show();
435       updateParamCoord(false);
436       break;
437     }
438   case GEOM_POINT_INTINT:
439     {
440       globalSelection(); // close local contexts, if any
441       myNeedType = TopAbs_EDGE;
442       localSelection(GEOM::GEOM_Object::_nil(), myNeedType);
443
444       myEditCurrentArgument = GroupLineIntersection->LineEdit1;
445 //      GroupLineIntersection->LineEdit1->setText("");
446 //      GroupLineIntersection->LineEdit2->setText("");
447       GroupLineIntersection->LineEdit1->setEnabled(true);
448       GroupLineIntersection->LineEdit2->setEnabled(false);
449 //      myLine1.nullify();
450 //      myLine2.nullify();
451       GroupLineIntersection->PushButton1->setDown(true);
452       GroupLineIntersection->PushButton2->setDown(false);
453       myParamGroup->hide();
454       GroupXYZ->hide();
455       GroupRefPoint->hide();
456       GroupOnCurve->hide();
457       GroupOnSurface->hide();
458       myCoordGrp->hide();
459       GroupLineIntersection->show();
460       break;
461     }
462   case GEOM_POINT_SURF:
463     {
464       globalSelection(); // close local contexts, if any
465       myNeedType = TopAbs_FACE;
466       localSelection(GEOM::GEOM_Object::_nil(), myNeedType);
467
468       myEditCurrentArgument = GroupOnSurface->LineEdit1;
469       //myEditCurrentArgument->setText("");
470       //myFace.nullify();
471       GroupOnSurface->PushButton1->setDown(true);
472       GroupRefPoint->hide();
473       GroupOnCurve->hide();
474       GroupLineIntersection->hide();
475       myParamGroup->show();
476       myParamCoord->button(LENGTH_VALUE)->hide();
477       myParamCoord->button(PARAM_VALUE)->setChecked(true);
478       GroupOnSurface->show();
479       myCoordGrp->show();
480       updateParamCoord(false);
481       break;
482     }
483   }
484
485 //  myX->setText("");
486 //  myY->setText("");
487 //  myZ->setText("");
488
489   QTimer::singleShot(50, this, SLOT(updateSize()));
490
491   SelectionIntoArgument();
492 }
493
494 //=================================================================================
495 // function : ClickOnOk()
496 // purpose  :
497 //=================================================================================
498 void MyBasicGUI_PointDlg::ClickOnOk()
499 {
500   setIsApplyAndClose(true);
501   if (onAccept())
502     ClickOnCancel();
503 }
504
505 //=================================================================================
506 // function : ClickOnApply()
507 // purpose  :
508 //=================================================================================
509 bool MyBasicGUI_PointDlg::ClickOnApply()
510 {
511   if (!onAccept())
512     return false;
513
514   initName();
515   ConstructorsClicked(getConstructorId());
516
517   return true;
518 }
519
520
521 //=================================================================================
522 // function : SelectionIntoArgument()
523 // purpose  : Called when selection as changed (for constructors not using local context)
524 //=================================================================================
525 void MyBasicGUI_PointDlg::SelectionIntoArgument()
526 {
527         MESSAGE("MyBasicGUI_PointDlg::SelectionIntoArgument() myGeomGUI : "<< myGeomGUI);
528
529         GEOM::GeomObjPtr aSelectedObject = getSelected(myNeedType);
530         TopoDS_Shape aShape;
531         if (!aSelectedObject || !GEOMBase::GetShape(aSelectedObject.get(), aShape) || aShape.IsNull())
532                 return;
533
534         erasePreview();
535         const int id = getConstructorId();
536
537         if ((id == GEOM_POINT_REF || id == GEOM_POINT_EDGE || id == GEOM_POINT_SURF)
538                         && myEditCurrentArgument != 0)
539         {
540                 myEditCurrentArgument->setText("");
541                 myX->setText("");
542                 myY->setText("");
543                 myZ->setText("");
544                 myFace.nullify();
545                 if (myEditCurrentArgument == GroupOnCurve->LineEdit1)
546                         myEdge.nullify();
547                 else if (myEditCurrentArgument == GroupOnCurve->LineEdit2)
548                         myRefPoint.nullify();
549         }
550         else if (id == GEOM_POINT_INTINT) {
551                 myEditCurrentArgument->setText("");
552                 if (myEditCurrentArgument == GroupLineIntersection->LineEdit1)
553                         myLine1.nullify();
554                 else if (myEditCurrentArgument == GroupLineIntersection->LineEdit2)
555                         myLine2.nullify();
556         }
557
558         QString aName = GEOMBase::GetName(aSelectedObject.get());
559         myBusy = true;
560         if (id == GEOM_POINT_XYZ) {
561                 gp_Pnt aPnt = BRep_Tool::Pnt(TopoDS::Vertex(aShape));
562                 GroupXYZ->SpinBox_DX->setValue(aPnt.X());
563                 GroupXYZ->SpinBox_DY->setValue(aPnt.Y());
564                 GroupXYZ->SpinBox_DZ->setValue(aPnt.Z());
565         }
566         else if (id == GEOM_POINT_REF) {
567                 myRefPoint = aSelectedObject;
568                 GroupRefPoint->LineEdit1->setText(aName);
569         }
570         else if (id == GEOM_POINT_EDGE) {
571                 myEditCurrentArgument->setText(aName);
572                 if (myEditCurrentArgument == GroupOnCurve->LineEdit1) {
573                         myEdge = aSelectedObject;
574                         if (myEdge && !myRefPoint) {
575                                 GroupOnCurve->PushButton2->click();
576                         }
577                 }
578                 else if (myEditCurrentArgument == GroupOnCurve->LineEdit2) {
579                         myRefPoint = aSelectedObject;
580                         if (myRefPoint && !myEdge) {
581                                 GroupOnCurve->PushButton1->click();
582                         }
583                 }
584         }
585         else if (id == GEOM_POINT_INTINT) {
586                 myEditCurrentArgument->setText(aName);
587                 if (myEditCurrentArgument == GroupLineIntersection->LineEdit1) {
588                         myLine1 = aSelectedObject;
589                         if (!myLine2) {
590                                 GroupLineIntersection->PushButton2->setMenu(0);
591                                 GroupLineIntersection->PushButton2->click();
592                                 GroupLineIntersection->PushButton2->setDown(true);
593                                 GroupLineIntersection->PushButton2->setMenu(myBtnPopup);
594                         }
595                 }
596                 else if (myEditCurrentArgument == GroupLineIntersection->LineEdit2) {
597                         myLine2 = aSelectedObject;
598                         if (!myLine1) {
599                                 GroupLineIntersection->PushButton1->setMenu(0);
600                                 GroupLineIntersection->PushButton1->click();
601                                 GroupLineIntersection->PushButton1->setDown(true);
602                                 GroupLineIntersection->PushButton1->setMenu(myBtnPopup);
603                         }
604                 }
605         }
606         else if (id == GEOM_POINT_SURF) {
607                 myFace = aSelectedObject;
608                 GroupOnSurface->LineEdit1->setText(aName);
609         }
610         myBusy = false;
611
612
613         displayPreview(true);
614 }
615
616
617 //=================================================================================
618 // function : SetEditCurrentArgument()
619 // purpose  :
620 //=================================================================================
621 void MyBasicGUI_PointDlg::SetEditCurrentArgument()
622 {
623   QPushButton* send = (QPushButton*)sender();
624
625   if (send == GroupRefPoint->PushButton1) {
626     GroupRefPoint->LineEdit1->setFocus();
627     myEditCurrentArgument = GroupRefPoint->LineEdit1;
628     globalSelection(); // close local contexts, if any
629     localSelection(GEOM::GEOM_Object::_nil(), TopAbs_VERTEX);
630   }
631   else if (send == GroupOnCurve->PushButton1) {
632     GroupOnCurve->LineEdit1->setFocus();
633     myEditCurrentArgument = GroupOnCurve->LineEdit1;
634     globalSelection(); // close local contexts, if any
635     myNeedType = TopAbs_EDGE;
636     localSelection(GEOM::GEOM_Object::_nil(), myNeedType);
637     GroupOnCurve->PushButton2->setDown(false);
638     GroupOnCurve->LineEdit1->setEnabled(true);
639     GroupOnCurve->LineEdit2->setEnabled(false);
640   }
641   else if (send == GroupOnCurve->PushButton2) {
642     GroupOnCurve->LineEdit2->setFocus();
643     myEditCurrentArgument = GroupOnCurve->LineEdit2;
644     globalSelection(); // close local contexts, if any
645     myNeedType = TopAbs_VERTEX;
646     localSelection(GEOM::GEOM_Object::_nil(), myNeedType);
647     GroupOnCurve->PushButton1->setDown(false);
648     GroupOnCurve->LineEdit2->setEnabled(true);
649     GroupOnCurve->LineEdit1->setEnabled(false);
650   }
651   else if (send == GroupOnSurface->PushButton1)
652   {
653     GroupOnSurface->LineEdit1->setFocus();
654     myEditCurrentArgument = GroupOnSurface->LineEdit1;
655     globalSelection(); // close local contexts, if any
656     localSelection(GEOM::GEOM_Object::_nil(), TopAbs_FACE);
657   }
658   else if (send == GroupLineIntersection->PushButton1) {
659     GroupLineIntersection->LineEdit1->setFocus();
660     myEditCurrentArgument = GroupLineIntersection->LineEdit1;
661     GroupLineIntersection->PushButton2->setDown(false);
662     GroupLineIntersection->LineEdit1->setEnabled(true);
663     GroupLineIntersection->LineEdit2->setEnabled(false);
664   }
665   else if (send == GroupLineIntersection->PushButton2) {
666     GroupLineIntersection->LineEdit2->setFocus();
667     myEditCurrentArgument = GroupLineIntersection->LineEdit2;
668     GroupLineIntersection->PushButton1->setDown(false);
669     GroupLineIntersection->LineEdit1->setEnabled(false);
670     GroupLineIntersection->LineEdit2->setEnabled(true);
671   }
672   send->setDown(true);
673
674   if ((send == GroupLineIntersection->PushButton1 ||
675          send == GroupLineIntersection->PushButton2) && !myBusy)
676     SelectionIntoArgument();
677 }
678
679
680 //=================================================================================
681 // function : enterEvent()
682 // purpose  : to reactivate this dialog box when mouse enter onto the window
683 //=================================================================================
684 void MyBasicGUI_PointDlg::enterEvent(QEvent*)
685 {
686   MESSAGE( "MyBasicGUI_PointDlg::enterEvent() ");
687   if (!mainFrame()->GroupConstructors->isEnabled())
688     ActivateThisDialog();
689 }
690
691
692 //=================================================================================
693 // function : ActivateThisDialog()
694 // purpose  :
695 //=================================================================================
696 void MyBasicGUI_PointDlg::ActivateThisDialog()
697 {
698   MESSAGE( "MyBasicGUI_PointDlg::ActivateThisDialog() ");
699   MyGEOMBase_Skeleton::ActivateThisDialog();
700
701   if ( myGeomGUI ){
702     connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
703             this, SLOT(SelectionIntoArgument()));
704   }
705   ConstructorsClicked(getConstructorId());
706 }
707
708
709 //=================================================================================
710 // function : DeactivateActiveDialog()
711 // purpose  : public slot to deactivate if active
712 //=================================================================================
713 void MyBasicGUI_PointDlg::DeactivateActiveDialog()
714 {
715   MESSAGE( "MyBasicGUI_PointDlg::DeactivateActiveDialog() ");
716   // myGeomGUI->SetState(-1);
717   MyGEOMBase_Skeleton::DeactivateActiveDialog();
718 }
719
720
721 //=================================================================================
722 // function : ValueChangedInSpinBox()
723 // purpose  :
724 //=================================================================================
725 void MyBasicGUI_PointDlg::ValueChangedInSpinBox(double newValue)
726 {
727   displayPreview(true);
728 }
729
730 //=================================================================================
731 // function : CheckBoxClicked()
732 // purpose  : Check Boxes Management
733 //=================================================================================
734 void MyBasicGUI_PointDlg::CheckBoxClicked(int  State)
735 {
736   displayPreview(true);
737 }
738
739
740 //=================================================================================
741 // funcion  : getParameter()
742 // purpose  :
743 //=================================================================================
744 double MyBasicGUI_PointDlg::getParameter() const
745 {
746   return GroupOnCurve->SpinBox_DX->value();
747 }
748
749
750 //=================================================================================
751 // funcion  : getUParameter()
752 // purpose  :
753 //=================================================================================
754 double MyBasicGUI_PointDlg::getUParameter() const
755 {
756   return GroupOnSurface->SpinBox_DX->value();
757 }
758
759
760 //=================================================================================
761 // funcion  : getVParameter()
762 // purpose  :
763 //=================================================================================
764 double MyBasicGUI_PointDlg::getVParameter() const
765 {
766   return GroupOnSurface->SpinBox_DY->value();
767 }
768
769
770 //=================================================================================
771 // function : OnPointSelected
772 // purpose  :
773 //=================================================================================
774 void MyBasicGUI_PointDlg::OnPointSelected(const gp_Pnt& thePnt)
775 {
776   if (getConstructorId() == GEOM_POINT_XYZ) {
777     GroupXYZ->SpinBox_DX->setValue(thePnt.X());
778     GroupXYZ->SpinBox_DY->setValue(thePnt.Y());
779     GroupXYZ->SpinBox_DZ->setValue(thePnt.Z());
780
781     displayPreview(true);
782   }
783 }
784
785 //=================================================================================
786 // function : createOperation
787 // purpose  :
788 //=================================================================================
789 GEOM::GEOM_IOperations_ptr MyBasicGUI_PointDlg::createOperation()
790 {
791   return myGeomGUI->GetGeomGen()->GetIBasicOperations(getStudyId());
792 }
793
794 //=================================================================================
795 // function : isValid
796 // purpose  :
797 //=================================================================================
798 bool MyBasicGUI_PointDlg::isValid(QString& msg)
799 {
800   bool ok = false;
801   switch (getConstructorId()) {
802   case GEOM_POINT_XYZ :
803     ok = GroupXYZ->SpinBox_DX->isValid(msg, !IsPreview()) &&
804          GroupXYZ->SpinBox_DY->isValid(msg, !IsPreview()) &&
805          GroupXYZ->SpinBox_DZ->isValid(msg, !IsPreview());
806     break;
807   case GEOM_POINT_REF:
808     ok = GroupRefPoint->SpinBox_DX->isValid(msg, !IsPreview()) &&
809          GroupRefPoint->SpinBox_DY->isValid(msg, !IsPreview()) &&
810          GroupRefPoint->SpinBox_DZ->isValid(msg, !IsPreview()) &&
811          myRefPoint;
812     break;
813   case GEOM_POINT_EDGE:
814     if (myParamCoord->checkedId() == PARAM_VALUE || myParamCoord->checkedId() == LENGTH_VALUE)
815       ok = GroupOnCurve->SpinBox_DX->isValid(msg, !IsPreview());
816     else
817       ok = GroupXYZ->SpinBox_DX->isValid(msg, !IsPreview()) &&
818            GroupXYZ->SpinBox_DY->isValid(msg, !IsPreview()) &&
819            GroupXYZ->SpinBox_DZ->isValid(msg, !IsPreview());
820     ok = myEdge && ok;
821     break;
822   case GEOM_POINT_INTINT:
823     ok = myLine1 && myLine2;
824     break;
825   case GEOM_POINT_SURF:
826     if (myParamCoord->checkedId() == PARAM_VALUE)
827       ok = GroupOnSurface->SpinBox_DX->isValid(msg, !IsPreview()) &&
828            GroupOnSurface->SpinBox_DY->isValid(msg, !IsPreview());
829     else
830       ok = GroupXYZ->SpinBox_DX->isValid(msg, !IsPreview()) &&
831            GroupXYZ->SpinBox_DY->isValid(msg, !IsPreview()) &&
832            GroupXYZ->SpinBox_DZ->isValid(msg, !IsPreview());
833     ok = myFace && ok;
834     break;
835   default:
836     break;
837   }
838   return ok;
839 }
840
841 //=================================================================================
842 // function : execute
843 // purpose  :
844 //=================================================================================
845 bool MyBasicGUI_PointDlg::execute(ObjectList& objects)
846 {
847   bool res = false;
848
849   GEOM::GEOM_Object_var anObj;
850   QStringList aParameters;
851
852   GEOM::GEOM_IBasicOperations_var anOper = GEOM::GEOM_IBasicOperations::_narrow(getOperation());
853
854   switch (getConstructorId()) {
855   case GEOM_POINT_XYZ :
856     {
857       double x = GroupXYZ->SpinBox_DX->value();
858       double y = GroupXYZ->SpinBox_DY->value();
859       double z = GroupXYZ->SpinBox_DZ->value();
860
861       aParameters << GroupXYZ->SpinBox_DX->text();
862       aParameters << GroupXYZ->SpinBox_DY->text();
863       aParameters << GroupXYZ->SpinBox_DZ->text();
864
865       anObj = anOper->MakePointXYZ(x, y, z);
866       res = true;
867       break;
868     }
869   case GEOM_POINT_REF :
870     {
871       double dx = GroupRefPoint->SpinBox_DX->value();
872       double dy = GroupRefPoint->SpinBox_DY->value();
873       double dz = GroupRefPoint->SpinBox_DZ->value();
874
875       aParameters << GroupRefPoint->SpinBox_DX->text();
876       aParameters << GroupRefPoint->SpinBox_DY->text();
877       aParameters << GroupRefPoint->SpinBox_DZ->text();
878
879       anObj = anOper->MakePointWithReference(myRefPoint.get(), dx, dy, dz);
880       res = true;
881       break;
882     }
883   case GEOM_POINT_EDGE :
884     {
885       if (myParamCoord->checkedId() == PARAM_VALUE) {
886         anObj = anOper->MakePointOnCurve(myEdge.get(), getParameter());
887         aParameters<<GroupOnCurve->SpinBox_DX->text();
888       }
889       else if (myParamCoord->checkedId() == LENGTH_VALUE) {
890         anObj = anOper->MakePointOnCurveByLength(myEdge.get(), getParameter(), myRefPoint.get());
891         aParameters<<GroupOnCurve->SpinBox_DX->text();
892       }
893       else if (myParamCoord->checkedId() == COORD_VALUE) {
894         double x = GroupXYZ->SpinBox_DX->value();
895         double y = GroupXYZ->SpinBox_DY->value();
896         double z = GroupXYZ->SpinBox_DZ->value();
897
898         aParameters << GroupXYZ->SpinBox_DX->text();
899         aParameters << GroupXYZ->SpinBox_DY->text();
900         aParameters << GroupXYZ->SpinBox_DZ->text();
901
902         anObj = anOper->MakePointOnCurveByCoord(myEdge.get(), x, y, z);
903       }
904       res = true;
905       break;
906     }
907   case GEOM_POINT_INTINT :
908     anObj = anOper->MakePointOnLinesIntersection(myLine1.get(), myLine2.get());
909     if (!anObj->_is_nil()) {
910       QString aName = getNewObjectName();
911       if (anObj->GetShapeType() == GEOM::COMPOUND && aName.startsWith("Vertex"))
912         initName(tr("GEOM_COMPOUND"));
913       else if (anObj->GetShapeType() == GEOM::VERTEX && aName.startsWith("Compound"))
914         initName(tr("GEOM_VERTEX"));
915     }
916     res = true;
917     break;
918   case GEOM_POINT_SURF :
919     {
920       if (myParamCoord->checkedId() == PARAM_VALUE) {
921         anObj = anOper->MakePointOnSurface(myFace.get(), getUParameter(), getVParameter());
922         aParameters<<GroupOnSurface->SpinBox_DX->text();
923         aParameters<<GroupOnSurface->SpinBox_DY->text();
924       } else {
925         double x = GroupXYZ->SpinBox_DX->value();
926         double y = GroupXYZ->SpinBox_DY->value();
927         double z = GroupXYZ->SpinBox_DZ->value();
928
929         aParameters << GroupXYZ->SpinBox_DX->text();
930         aParameters << GroupXYZ->SpinBox_DY->text();
931         aParameters << GroupXYZ->SpinBox_DZ->text();
932
933         anObj = anOper->MakePointOnSurfaceByCoord(myFace.get(), x, y, z);
934       }
935       res = true;
936       break;
937     }
938   }
939
940   const int id = getConstructorId();
941   if(!anObj->_is_nil() && !IsPreview() && (id == GEOM_POINT_XYZ ||
942                                            id == GEOM_POINT_REF ||
943                                            id == GEOM_POINT_EDGE ||
944                                            id == GEOM_POINT_SURF)) {
945       anObj->SetParameters(aParameters.join(":").toLatin1().constData());
946   }
947
948   if (id == GEOM_POINT_REF || id == GEOM_POINT_EDGE || id == GEOM_POINT_SURF) {
949     TopoDS_Shape aShape;
950     if (GEOMBase::GetShape(anObj, aShape) && !aShape.IsNull() &&
951          aShape.ShapeType() == TopAbs_VERTEX) {
952       gp_Pnt aPnt = BRep_Tool::Pnt(TopoDS::Vertex(aShape));
953       SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
954       int aPrecision = resMgr->integerValue("Geometry", "length_precision", 6);
955       myX->setText(DlgRef::PrintDoubleValue(aPnt.X(), aPrecision));
956       myY->setText(DlgRef::PrintDoubleValue(aPnt.Y(), aPrecision));
957       myZ->setText(DlgRef::PrintDoubleValue(aPnt.Z(), aPrecision));
958     }
959     else {
960       myX->setText("");
961       myY->setText("");
962       myZ->setText("");
963     }
964   }
965
966   if (!anObj->_is_nil()) {
967     objects.push_back(anObj._retn());
968   }
969
970   return res;
971 }
972
973 //=================================================================================
974 // function : addSubshapeToStudy
975 // purpose  : virtual method to add new SubObjects if local selection
976 //=================================================================================
977 void MyBasicGUI_PointDlg::addSubshapesToStudy()
978 {
979   switch (getConstructorId()) {
980   case GEOM_POINT_REF:
981     GEOMBase::PublishSubObject(myRefPoint.get());
982     break;
983   case GEOM_POINT_EDGE:
984     GEOMBase::PublishSubObject(myEdge.get());
985     break;
986   case GEOM_POINT_INTINT:
987     GEOMBase::PublishSubObject(myLine1.get());
988     GEOMBase::PublishSubObject(myLine2.get());
989     break;
990   case GEOM_POINT_SURF:
991     GEOMBase::PublishSubObject(myFace.get());
992     break;
993   default:
994     break;
995   }
996 }
997
998 //=================================================================================
999 // function : ClickParamCoord()
1000 // purpose  :
1001 //=================================================================================
1002 void MyBasicGUI_PointDlg::ClickParamCoord(int id)
1003 {
1004   updateParamCoord(true);
1005   displayPreview(true);
1006 }
1007
1008 //=================================================================================
1009 // function : updateParamCoord
1010 // purpose  :
1011 //=================================================================================
1012 void MyBasicGUI_PointDlg::updateParamCoord(bool theIsUpdate)
1013 {
1014   bool isParam = myParamCoord->checkedId() == PARAM_VALUE;
1015   bool isLength = myParamCoord->checkedId() == LENGTH_VALUE;
1016
1017   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1018   double step = resMgr->doubleValue("Geometry", "SettingsGeomStep", 100);
1019
1020   const int id = getConstructorId();
1021   if (id == GEOM_POINT_EDGE) {
1022     GroupOnCurve->TextLabel2->setVisible(isLength);
1023     GroupOnCurve->PushButton2->setVisible(isLength);
1024     GroupOnCurve->LineEdit2->setVisible(isLength);
1025     GroupOnCurve->TextLabel3->setVisible(isParam || isLength);
1026     GroupOnCurve->SpinBox_DX->setVisible(isParam || isLength);
1027     if (isParam){
1028       initSpinBox(GroupOnCurve->SpinBox_DX, 0., 1., 0.1, "parametric_precision");
1029       GroupOnCurve->SpinBox_DX->setValue(0.5);
1030       GroupOnCurve->TextLabel3->setText(tr("GEOM_PARAMETER"));
1031     }
1032     else if (isLength){
1033       initSpinBox(GroupOnCurve->SpinBox_DX, COORD_MIN, COORD_MAX, step, "length_precision");
1034       GroupOnCurve->SpinBox_DX->setValue(0.0);
1035       GroupOnCurve->TextLabel3->setText(tr("GEOM_LENGTH"));
1036     }
1037   }
1038   else if (id == GEOM_POINT_SURF) {
1039     GroupOnSurface->TextLabel2->setShown(isParam);
1040     GroupOnSurface->TextLabel3->setShown(isParam);
1041     GroupOnSurface->SpinBox_DX->setShown(isParam);
1042     GroupOnSurface->SpinBox_DY->setShown(isParam);
1043   }
1044
1045   GroupXYZ->setShown(!isParam && !isLength);
1046
1047   if (theIsUpdate)
1048     QTimer::singleShot(50, this, SLOT(updateSize()));
1049 }
1050
1051 //=================================================================================
1052 // function : onBtnPopup()
1053 // purpose  :
1054 //=================================================================================
1055 void MyBasicGUI_PointDlg::onBtnPopup(QAction* a)
1056 {
1057   globalSelection(); // close local contexts, if any
1058   myNeedType = myActions[a] == SelectEdge ? TopAbs_EDGE : TopAbs_WIRE;
1059   localSelection(GEOM::GEOM_Object::_nil(), myNeedType);
1060 }
1061
1062 //=================================================================================
1063 // function : updateSize
1064 // purpose  : adjust dialog size to minimum
1065 //=================================================================================
1066 void MyBasicGUI_PointDlg::updateSize()
1067 {
1068   qApp->processEvents();
1069   updateGeometry();
1070   resize(minimumSizeHint());
1071 }
1072
1073
1074
1075
1076
1077 /*
1078       HEXABLOCK
1079 */
1080
1081
1082
1083 void MyBasicGUI_PointDlg::setDocumentModel( HEXABLOCK::GUI::DocumentModel* m)
1084 {
1085   _documentModel = m;
1086 }
1087
1088 void MyBasicGUI_PointDlg::setPatternDataSelectionModel( HEXABLOCK::GUI::PatternDataSelectionModel* s)
1089 {
1090   _patternDataSelectionModel = s;
1091 }
1092
1093 void MyBasicGUI_PointDlg::_initInputWidget()
1094 {
1095
1096 //   QVBoxLayout* mainLayout = new QVBoxLayout( centralWidget() );
1097 //   setLayout( mainLayout );
1098 //   QHBoxLayout* up   = new QHBoxLayout( centralWidget() );
1099 //   QVBoxLayout* down = new QVBoxLayout( centralWidget() );
1100
1101 //   QGroupBox *GroupBoxName = new QGroupBox(centralWidget());
1102 //   GroupBoxName->setObjectName(QString::fromUtf8("GroupBoxName"));
1103 //   GroupBoxName->setTitle("Vertex");
1104 //   QHBoxLayout *hboxLayout1 = new QHBoxLayout(GroupBoxName);
1105 //   hboxLayout1->setSpacing(6);
1106 //   hboxLayout1->setContentsMargins(9, 9, 9, 9);
1107 //   hboxLayout1->setObjectName(QString::fromUtf8("hboxLayout1"));
1108 //   QLabel *NameLabel = new QLabel(GroupBoxName);
1109 //   NameLabel->setObjectName(QString::fromUtf8("NameLabel"));
1110 //   NameLabel->setWordWrap(false);
1111 //   NameLabel->setText( "Name : " );
1112 //   hboxLayout1->addWidget( NameLabel );
1113 //   mainFrame()->_vertex_le = new QLineEdit( GroupBoxName );
1114 //   mainFrame()->_vertex_le->setObjectName(QString::fromUtf8("mainFrame()->_vertex_le"));
1115 //   hboxLayout1->addWidget(mainFrame()->_vertex_le);
1116 //
1117 //   layout()->addWidget( GroupBoxName );
1118
1119
1120
1121   QRegExp rx("");
1122   QValidator *validator = new QRegExpValidator(rx, this);
1123
1124 //   setProperty( "HexaWidgetType",  QVariant::fromValue(HEXABLOCK::GUI::VERTEX_TREE) );
1125 //   installEventFilter(this);
1126
1127   mainFrame()->_vertex_le->setProperty( "HexaWidgetType",  QVariant::fromValue(HEXABLOCK::GUI::VERTEX_TREE) );
1128   mainFrame()->_vertex_le->installEventFilter(this);
1129   mainFrame()->_vertex_le->setValidator( validator );
1130 }
1131
1132 void MyBasicGUI_PointDlg::_initViewManager()
1133 {
1134   SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
1135   _mgr   = dynamic_cast<LightApp_SelectionMgr*>( anApp->selectionMgr() );
1136   _vtkVm = anApp->getViewManager( SVTK_Viewer::Type(),      true );
1137   _occVm = anApp->getViewManager( OCCViewer_Viewer::Type(), true );
1138   SUIT_ViewManager* activeVm = anApp->activeViewManager();
1139   onWindowActivated ( activeVm );
1140 }
1141
1142
1143 // bool MyBasicGUI_PointDlg::_onSelectionChanged( const QItemSelection& sel, QLineEdit*  le )
1144 // {
1145 //   MESSAGE("HexaBaseDialog::_onSelectionChanged(const QItemSelection& sel, QLineEdit*  le)");
1146 //   MESSAGE("*  le is "<< le->objectName().toStdString() );
1147 //   QModelIndexList l = sel.indexes();
1148 //   if ( l.count() == 0 ) return false;
1149 //
1150 //   //type from selection (first)
1151 //   QModelIndex selected = l[0];
1152 //   int selType = selected.data(HEXABLOCK::GUI::HEXA_TREE_ROLE).toInt();
1153 //
1154 //   //type of widget
1155 //   QVariant v = le->property("HexaWidgetType");
1156 //   if ( !v.isValid() ) return false;
1157 //   HexaWidgetType wType = v.value<HexaWidgetType>();
1158 //
1159 //   // check selection compatibility between selection and widget
1160 //   if ( selType != wType ){
1161 //     MESSAGE("*  bad selection : " << selType << " is not  " << wType );
1162 //     SUIT_MessageBox::information( 0,
1163 //       tr("HEXA_INFO"),
1164 //       tr("Bad selection type: please select a %1").arg( _strHexaWidgetType[wType]) );
1165 //     return false;
1166 //   }
1167 //
1168 //   //fill the lineEdit if selection is OK
1169 //   le->setText( selected.data().toString() );// name
1170 //   le->setProperty("QModelIndex",  QVariant::fromValue(selected) );
1171 //   MESSAGE("}");
1172 //   return true;
1173 // }
1174
1175
1176
1177 void MyBasicGUI_PointDlg::onSelectionChanged( const QItemSelection& sel, const QItemSelection& unsel )
1178 {
1179   MESSAGE( "HexaBaseDialog::onSelectionChanged(){" );
1180   QString className = metaObject()->className();
1181   MESSAGE( "*  I am                          : " << className.toStdString() );
1182   MESSAGE( "*  sender is                     : " << sender() );
1183   QItemSelectionModel* selector = dynamic_cast<QItemSelectionModel*>(sender());
1184   MESSAGE( "*  selector           : " << selector);
1185
1186   foreach( const QModelIndex& isel, sel.indexes() ){
1187     MESSAGE("*  selected : " << isel.data().toString().toStdString());
1188   }
1189   foreach( const QModelIndex& iunsel, unsel.indexes() ){
1190     MESSAGE("*  unselected : " << iunsel.data().toString().toStdString());
1191   }
1192   if ( _selectionMutex ) return;
1193   if ( _currentObj != mainFrame()->_vertex_le ) return;
1194
1195   bool selOk = false;
1196
1197   QModelIndexList l = sel.indexes();
1198   if ( l.count() != 0 ){
1199     //type from selection (first)
1200     QModelIndex selected = l[0];
1201     int selType = selected.data(HEXABLOCK::GUI::HEXA_TREE_ROLE).toInt();
1202     // check selection compatibility between selection and widget
1203     if ( selType == HEXABLOCK::GUI::VERTEX_TREE ){
1204       mainFrame()->_vertex_le->setText( selected.data().toString() );// name
1205       mainFrame()->_vertex_le->setProperty("QModelIndex",  QVariant::fromValue(selected) );
1206       selOk = true;
1207     } else {
1208       _patternDataSelectionModel->clearSelection();
1209       MESSAGE("*  bad selection : " << selType << " is not  " << HEXABLOCK::GUI::VERTEX_TREE );
1210       SUIT_MessageBox::information( 0,
1211         tr("HEXA_INFO"),
1212         tr("Bad selection type: please select a %1").arg( "VERTEX" ) );
1213     }
1214   }
1215   MESSAGE("}");
1216 }
1217
1218
1219 void MyBasicGUI_PointDlg::onWindowActivated(SUIT_ViewManager* vm)
1220 {
1221   MESSAGE( "getConstructorId()"<< getConstructorId() );
1222   SUIT_ViewWindow* v = vm->getActiveView();
1223   QString vmType = vm->getType();
1224   if ( (vmType == SVTK_Viewer::Type()) || (vmType == VTKViewer_Viewer::Type()) ){
1225     mainFrame()->_vertex_le->setFocus();
1226   } else if ( vmType == OCCViewer_Viewer::Type() ){
1227 //     lines_lw->setFocus();
1228 //     ConstructorsClicked(0);
1229     MESSAGE( "getConstructorId()"<< getConstructorId() );
1230     ConstructorsClicked( getConstructorId() );
1231   }
1232 }
1233
1234
1235
1236 bool MyBasicGUI_PointDlg::eventFilter(QObject *obj, QEvent *event)
1237 {
1238
1239   if ( (event->type() != QEvent::FocusIn)
1240     or (obj != mainFrame()->_vertex_le) ){
1241     return MyGEOMBase_Skeleton::eventFilter(obj, event);
1242   }
1243
1244   MESSAGE("MyBasicGUI_PointDlg::eventFilter{");
1245
1246   QVariant       vxVariant;
1247   QModelIndex    vxIndex;
1248
1249   _currentObj = obj;
1250 //   HEXABLOCKGUI::currentVtkView->raise();
1251   _patternDataSelectionModel->setVertexSelection();
1252
1253   vxVariant = mainFrame()->_vertex_le->property("QModelIndex");
1254   if ( !vxVariant.isValid() ) {
1255           return MyGEOMBase_Skeleton::eventFilter(obj, event);
1256   }
1257   vxIndex = vxVariant.value<QModelIndex>();
1258   _selectionMutex = true;
1259   MESSAGE("*  selecting the element         : " << vxIndex.data().toString().toStdString());
1260   MESSAGE("*  _patternDataSelectionModel    : " << _patternDataSelectionModel );
1261   _patternDataSelectionModel->select( vxIndex, QItemSelectionModel::Clear );
1262   _patternDataSelectionModel->select( vxIndex, QItemSelectionModel::Select );
1263   _selectionMutex = false;
1264   MESSAGE("}");
1265   return false;
1266 }
1267
1268
1269 void MyBasicGUI_PointDlg::hideEvent ( QHideEvent * event )
1270 {
1271   MESSAGE("MyBasicGUI_PointDlg::hideEvent(){");
1272   disconnect( _patternDataSelectionModel, SIGNAL( selectionChanged ( const QItemSelection &, const QItemSelection &) ),
1273                 this,                     SLOT( onSelectionChanged(const QItemSelection &, const QItemSelection &) ) );
1274   disconnect(  HEXABLOCKGUI::selectionMgr() , SIGNAL(currentSelectionChanged()), this, SLOT(onCurrentSelectionChanged()) );
1275   disconnect( _vtkVm, SIGNAL( activated(SUIT_ViewManager*) ), this, SLOT( onWindowActivated(SUIT_ViewManager*) ) );
1276   disconnect( _occVm, SIGNAL( activated(SUIT_ViewManager*) ), this, SLOT( onWindowActivated(SUIT_ViewManager*) ) );
1277   _documentModel->allowEdition();
1278   DeactivateActiveDialog();
1279   MyGEOMBase_Skeleton::hideEvent( event );
1280   MESSAGE("}");
1281 }
1282
1283 void MyBasicGUI_PointDlg::showEvent( QShowEvent * event )
1284 {
1285   MESSAGE("MyBasicGUI_PointDlg::showEvent(){");
1286   _documentModel->disallowEdition();
1287   //     _patternDataSelectionModel->clearSelection();
1288   connect( _patternDataSelectionModel, SIGNAL( selectionChanged ( const QItemSelection &, const QItemSelection &) ),
1289               this,                    SLOT( onSelectionChanged(const QItemSelection &, const QItemSelection &) ) );
1290   connect( _mgr, SIGNAL(currentSelectionChanged()), this, SLOT(onCurrentSelectionChanged()) );
1291   connect( _vtkVm, SIGNAL( activated(SUIT_ViewManager*) ), this, SLOT( onWindowActivated(SUIT_ViewManager*) ) );
1292   connect( _occVm, SIGNAL( activated(SUIT_ViewManager*) ), this, SLOT( onWindowActivated(SUIT_ViewManager*) ) );
1293
1294
1295   SalomeApp_Application* app = (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() );
1296
1297   MESSAGE( "XXXXXXXXXXX   myGeomGUI  => " << myGeomGUI );
1298   if ( !myGeomGUI && app )
1299     myGeomGUI = dynamic_cast<GeometryGUI*>( app->module( "Geometry" ) );
1300
1301   MESSAGE( "YYYYYYYYYYYYY myGeomGUI  => " << myGeomGUI );
1302
1303   ActivateThisDialog();
1304   MyGEOMBase_Skeleton::showEvent ( event );
1305   MESSAGE("}");
1306 }
1307
1308
1309
1310
1311 bool MyBasicGUI_PointDlg::onAccept( const bool publish, const bool useTransaction )
1312 {
1313   MESSAGE("MyBasicGUI_PointDlg::onAccept()");
1314
1315   GEOM::GEOM_Object_ptr newVertex;
1316   QString               newVertexEntry;
1317   QString               newVertexName;
1318   QString               newVertexBrep;
1319
1320
1321
1322   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
1323   if ( !appStudy ) return false;
1324   _PTR(Study) aStudy = appStudy->studyDS();
1325
1326   bool aLocked = (_PTR(AttributeStudyProperties) (aStudy->GetProperties()))->IsLocked();
1327   if ( aLocked ) {
1328     MESSAGE("GEOMBase_Helper::onAccept - ActiveStudy is locked");
1329     SUIT_MessageBox::warning ( (QWidget*)SUIT_Session::session()->activeApplication()->desktop(),
1330                                QObject::tr("WRN_WARNING"),
1331                                QObject::tr("WRN_STUDY_LOCKED"),
1332                                QObject::tr("BUT_OK") );
1333     return false;
1334   }
1335
1336   QString msg;
1337   if ( !isValid( msg ) ) {
1338     showError( msg );
1339     return false;
1340   }
1341
1342   erasePreview( false );
1343
1344   bool result = false;
1345
1346   try {
1347     if ( ( !publish && !useTransaction ) || openCommand() ) {
1348       SUIT_OverrideCursor wc;
1349       SUIT_Session::session()->activeApplication()->putInfo( "" );
1350       ObjectList objects;
1351       if ( !execute( objects ) || !getOperation()->IsDone() ) {
1352         wc.suspend();
1353         abortCommand();
1354         showError();
1355       }
1356       else {
1357         addSubshapesToStudy(); // add Subshapes if local selection
1358         const int nbObjs = objects.size();
1359         QStringList anEntryList;
1360         int aNumber = 1;
1361         for ( ObjectList::iterator it = objects.begin(); it != objects.end(); ++it ) {
1362           GEOM::GEOM_Object_var obj=*it;
1363           if ( publish ) {
1364             QString aName = getNewObjectName();
1365             if ( nbObjs > 1 ) {
1366               if (aName.isEmpty())
1367                 aName = getPrefix(obj);
1368               if (nbObjs <= 30) {
1369                 // Try to find a unique name
1370                 aName = GEOMBase::GetDefaultName(aName, extractPrefix());
1371               } else {
1372                 // Don't check name uniqueness in case of numerous objects
1373                 aName = aName + "_" + QString::number(aNumber++);
1374               }
1375             } else {
1376               // PAL6521: use a prefix, if some dialog box doesn't reimplement getNewObjectName()
1377               if ( aName.isEmpty() )
1378                 aName = GEOMBase::GetDefaultName( getPrefix( obj ) );
1379             }
1380             anEntryList << addInStudy( obj, aName.toLatin1().constData() );
1381
1382             newVertex      = obj;
1383             newVertexEntry = anEntryList[0];
1384             TopoDS_Shape aShape;
1385             GEOMBase::GetShape( newVertex, aShape );
1386             if ( !aShape.IsNull() ){
1387               MESSAGE("!aShape.IsNull()");
1388               newVertexName = GEOMBase::GetName( newVertex );
1389               MESSAGE("newVertexName "<< newVertexName.toStdString());
1390               newVertexBrep = HEXABLOCK::GUI::shape2string( aShape ).c_str();
1391             }
1392
1393             // updateView=false
1394             display( obj, false );
1395 #ifdef WITHGENERICOBJ
1396             // obj has been published in study. Its refcount has been incremented.
1397             // It is safe to decrement its refcount
1398             // so that it will be destroyed when the entry in study will be removed
1399             obj->UnRegister();
1400 #endif
1401           }
1402           else {
1403             // asv : fix of PAL6454. If publish==false, then the original shape
1404             // was modified, and need to be re-cached in GEOM_Client before redisplay
1405 //             clearShapeBuffer( obj );
1406             // withChildren=true, updateView=false
1407             redisplay( obj, true, false );
1408           }
1409         }
1410
1411         if ( nbObjs ) {
1412           commitCommand();
1413           updateObjBrowser();
1414           if( SUIT_Application* anApp = SUIT_Session::session()->activeApplication() ) {
1415             if( LightApp_Application* aLightApp = dynamic_cast<LightApp_Application*>( anApp ) ){
1416               aLightApp->browseObjects( anEntryList, isApplyAndClose(), isOptimizedBrowsing() );
1417             }
1418             anApp->putInfo( QObject::tr("GEOM_PRP_DONE") );
1419           }
1420           result = true;
1421         }
1422         else
1423           abortCommand();
1424       }
1425     }
1426   }
1427   catch( const SALOME::SALOME_Exception& e ) {
1428     SalomeApp_Tools::QtCatchCorbaException( e );
1429     abortCommand();
1430   }
1431
1432   updateViewer();
1433
1434   if (result){
1435     SUIT_OverrideCursor wc;
1436     if ( !_documentModel )             return false;
1437     if ( !_patternDataSelectionModel ) return false;
1438     const HEXABLOCK::GUI::PatternDataModel* patternDataModel = dynamic_cast<const HEXABLOCK::GUI::PatternDataModel*>( _patternDataSelectionModel->model() );
1439     if ( !patternDataModel ) return false;
1440     _currentObj = NULL;
1441
1442     QVariant v = mainFrame()->_vertex_le->property("QModelIndex");
1443     if ( !v.isValid() ) return false;
1444     QModelIndex iVertex = patternDataModel->mapToSource( v.value<QModelIndex>() );
1445
1446     if ( iVertex.isValid() ){
1447       HEXABLOCK::GUI::DocumentModel::GeomObj aPoint;
1448       aPoint.name  = newVertexName;
1449       aPoint.entry = newVertexEntry;
1450       aPoint.brep  = newVertexBrep;
1451       MESSAGE(" aPoint.name"  <<  aPoint.name.toStdString() );
1452       MESSAGE(" aPoint.entry" <<  aPoint.entry.toStdString() );
1453       MESSAGE(" aPoint.brep"  <<  aPoint.brep.toStdString() );
1454       _documentModel->addAssociation( iVertex, aPoint );
1455       // to select/highlight result
1456 //       _patternDataSelectionModel->clearSelection();
1457 //       mainFrame()->_vertex_le->setFocus();
1458
1459 //       globalSelection();
1460 //       localSelection(GEOM::GEOM_Object::_nil(), TopAbs_VERTEX);
1461       _patternDataSelectionModel->select( patternDataModel->mapFromSource(iVertex), QItemSelectionModel::Clear );
1462       _patternDataSelectionModel->select( patternDataModel->mapFromSource(iVertex), QItemSelectionModel::Select );
1463       _currentObj = NULL;
1464       result = true;
1465     } else  {
1466       SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE VERTEX ASSOCIATION" ) );
1467       return false;
1468     }
1469   }
1470
1471
1472   return result;
1473 }
1474