Salome HOME
corrections for 0020669
[modules/geom.git] / src / BasicGUI / BasicGUI_PointDlg.cxx
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 //  This library is free software; you can redistribute it and/or
7 //  modify it under the terms of the GNU Lesser General Public
8 //  License as published by the Free Software Foundation; either
9 //  version 2.1 of the License.
10 //
11 //  This library is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 //  Lesser General Public License for more details.
15 //
16 //  You should have received a copy of the GNU Lesser General Public
17 //  License along with this library; if not, write to the Free Software
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 //  GEOM GEOMGUI : GUI for Geometry component
23 //  File   : BasicGUI_PointDlg.cxx
24 //  Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
25
26 #include "BasicGUI_PointDlg.h"
27
28 #include <SUIT_ResourceMgr.h>
29 #include <SUIT_Session.h>
30 #include <SalomeApp_Application.h>
31 #include <LightApp_SelectionMgr.h>
32
33 #include <GeometryGUI.h>
34 #include <GEOMBase.h>
35
36 #include <DlgRef.h>
37
38 #include <GEOMImpl_Types.hxx>
39
40 #include <QApplication>
41 #include <QButtonGroup>
42 #include <QHBoxLayout>
43 #include <QLabel>
44 #include <QRadioButton>
45 #include <QMenu>
46
47 #include <gp_Pnt.hxx>
48 #include <TopoDS_Shape.hxx>
49 #include <TopAbs_ShapeEnum.hxx>
50 #include <TopoDS.hxx>
51 #include <BRep_Tool.hxx>
52 #include <TopExp.hxx>
53 #include <TColStd_IndexedMapOfInteger.hxx>
54 #include <TopTools_IndexedMapOfShape.hxx>
55
56 #define PARAM_VALUE 0
57 #define COORD_VALUE 1
58
59 #define GEOM_POINT_XYZ    0
60 #define GEOM_POINT_REF    1
61 #define GEOM_POINT_EDGE   2
62 #define GEOM_POINT_INTINT 3
63 #define GEOM_POINT_SURF   4
64
65 #define SPACING 6
66 #define MARGIN  9
67
68 //=================================================================================
69 // class    : BasicGUI_PointDlg()
70 // purpose  : Constructs a BasicGUI_PointDlg which is a child of 'parent', with the
71 //            name 'name' and widget flags set to 'f'.
72 //            The dialog will by default be modeless, unless you set 'modal' to
73 //            TRUE to construct a modal dialog.
74 //=================================================================================
75 BasicGUI_PointDlg::BasicGUI_PointDlg( GeometryGUI* theGeometryGUI, QWidget* parent,
76                                       bool modal, Qt::WindowFlags fl )
77   : GEOMBase_Skeleton( theGeometryGUI, parent, modal, fl )
78 {
79   QPixmap image0( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_POINT") ) );
80   QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_POINT_EDGE" ) ) );
81   QPixmap image2( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
82   QPixmap image3( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_POINT_REF" ) ) );
83   QPixmap image4( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_POINT_LINES") ) );
84   QPixmap image5( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_POINT_FACE" ) ) );
85   QPixmap image6( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICO_LINE" ) ) );
86   QPixmap image7( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICO_WIRE" ) ) );
87
88   setWindowTitle( tr( "GEOM_POINT_TITLE" ) );
89
90   /***************************************************************/
91   mainFrame()->GroupConstructors->setTitle( tr( "GEOM_POINTS" ) );
92   mainFrame()->RadioButton1->setIcon( image0 );
93   mainFrame()->RadioButton2->setIcon( image3 );
94   mainFrame()->RadioButton3->setIcon( image1 );
95   mainFrame()->RadioButton4->show();
96   mainFrame()->RadioButton4->setIcon( image4 );
97   mainFrame()->RadioButton5->show();
98   mainFrame()->RadioButton5->setIcon( image5 );
99
100   myParamGroup = new QGroupBox( centralWidget() );
101   myParamCoord = new QButtonGroup( myParamGroup );
102   QHBoxLayout* boxLayout = new QHBoxLayout( myParamGroup );
103   boxLayout->setMargin( MARGIN ); boxLayout->setSpacing( SPACING );
104   QRadioButton* btn = new QRadioButton( tr( "GEOM_PARAM_VALUE" ), myParamGroup );
105   myParamCoord->addButton( btn, PARAM_VALUE );
106   boxLayout->addWidget( btn );
107   btn = new QRadioButton( tr( "GEOM_COORD_VALUE" ), myParamGroup );
108   myParamCoord->addButton( btn, COORD_VALUE );
109   boxLayout->addWidget( btn );
110   myParamCoord->setExclusive( true );
111   myParamCoord->button( PARAM_VALUE )->setChecked( true );
112
113   GroupXYZ = new DlgRef_3Spin( centralWidget() );
114   GroupXYZ->GroupBox1->setTitle( tr( "GEOM_COORDINATES" ) );
115   GroupXYZ->TextLabel1->setText( tr( "GEOM_X" ) );
116   GroupXYZ->TextLabel2->setText( tr( "GEOM_Y" ) );
117   GroupXYZ->TextLabel3->setText( tr( "GEOM_Z" ) );
118
119   GroupOnCurve = new DlgRef_1Sel1Spin( centralWidget() );
120   GroupOnCurve->GroupBox1->setTitle( tr( "GEOM_POINT_ON_EDGE" ) );
121   GroupOnCurve->TextLabel1->setText( tr( "GEOM_EDGE" ) );
122   GroupOnCurve->TextLabel2->setText( tr( "GEOM_PARAMETER" ) );
123   GroupOnCurve->PushButton1->setIcon( image2 );
124
125   GroupOnSurface = new DlgRef_1Sel2Spin( centralWidget() );
126   GroupOnSurface->GroupBox1->setTitle( tr( "GEOM_POINT_ON_FACE" ) );
127   GroupOnSurface->TextLabel1->setText( tr( "GEOM_FACE" ) );
128   GroupOnSurface->TextLabel2->setText( tr( "GEOM_UPARAMETER" ) );
129   GroupOnSurface->TextLabel3->setText( tr( "GEOM_VPARAMETER" ) );
130   GroupOnSurface->PushButton1->setIcon( image2 );
131
132   GroupRefPoint = new DlgRef_1Sel3Spin( centralWidget() );
133   GroupRefPoint->GroupBox1->setTitle( tr( "GEOM_REF_POINT" ) );
134   GroupRefPoint->TextLabel1->setText( tr( "GEOM_POINT" ) );
135   GroupRefPoint->PushButton1->setIcon( image2 );
136   GroupRefPoint->TextLabel2->setText( tr( "GEOM_DX" ) );
137   GroupRefPoint->TextLabel3->setText( tr( "GEOM_DY" ) );
138   GroupRefPoint->TextLabel4->setText( tr( "GEOM_DZ" ) );
139
140   /* popup menu for line intersect buttons */
141   myBtnPopup = new QMenu(this);
142   QIcon ico_line = QIcon( image6 );
143   QIcon ico_wire = QIcon( image7 );
144   myActions[myBtnPopup->addAction( ico_line, tr( "GEOM_EDGE" ) )] = 0;
145   myActions[myBtnPopup->addAction( ico_wire, tr( "GEOM_WIRE" ) )] = 1;
146
147   GroupLineIntersection = new DlgRef_2Sel( centralWidget() );
148   GroupLineIntersection->GroupBox1->setTitle( tr( "GEOM_LINE_INTERSECTION" ) );
149   GroupLineIntersection->TextLabel1->setText( tr( "GEOM_LINE1" ) );
150   GroupLineIntersection->TextLabel2->setText( tr( "GEOM_LINE2" ) );
151   GroupLineIntersection->PushButton1->setIcon( image2 );
152   GroupLineIntersection->PushButton1->setMenu( myBtnPopup );
153   GroupLineIntersection->PushButton2->setIcon( image2 );
154   GroupLineIntersection->PushButton2->setMenu( myBtnPopup );
155   GroupLineIntersection->LineEdit2->setEnabled(false);
156
157   myCoordGrp = new QGroupBox( tr( "GEOM_COORDINATES_RES" ), centralWidget() );
158   QGridLayout* myCoordGrpLayout = new QGridLayout( myCoordGrp );
159   myCoordGrpLayout->addWidget( new QLabel( tr( "GEOM_X" ), myCoordGrp ), 0, 0 );
160   myX = new QLineEdit( myCoordGrp );
161   myCoordGrpLayout->addWidget( myX, 0, 1 );
162   myCoordGrpLayout->addWidget( new QLabel( tr( "GEOM_Y" ), myCoordGrp ), 1, 0 );
163   myY = new QLineEdit( myCoordGrp );
164   myCoordGrpLayout->addWidget( myY, 1, 1 );
165   myCoordGrpLayout->addWidget( new QLabel( tr( "GEOM_Z" ), myCoordGrp ), 2, 0 );
166   myZ = new QLineEdit( myCoordGrp );
167   myCoordGrpLayout->addWidget( myZ, 2, 1 );
168
169   QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
170   layout->setMargin( 0 ); layout->setSpacing( 6 );
171   layout->addWidget( myParamGroup );
172   layout->addWidget( GroupXYZ );
173   layout->addWidget( GroupOnCurve );
174   layout->addWidget( GroupOnSurface );
175   layout->addWidget( GroupRefPoint );
176   layout->addWidget( GroupLineIntersection );
177   layout->addWidget( myCoordGrp );
178
179   myX->setReadOnly( true );
180   myY->setReadOnly( true );
181   myZ->setReadOnly( true );
182
183   myX->setEnabled( false );
184   myY->setEnabled( false );
185   myZ->setEnabled( false );
186
187   QPalette aPal = myX->palette();
188   aPal.setColor( QPalette::Disabled, QPalette::Text, QColor( 0, 0, 0 ) );
189   myX->setPalette( aPal );
190   myY->setPalette( aPal );
191   myZ->setPalette( aPal );
192
193   setHelpFileName( "create_point_page.html" );
194
195   Init();
196 }
197
198
199 //=================================================================================
200 // function : ~BasicGUI_PointDlg()
201 // purpose  : Destructor
202 //=================================================================================
203 BasicGUI_PointDlg::~BasicGUI_PointDlg()
204 {
205 }
206
207
208 //=================================================================================
209 // function : Init()
210 // purpose  :
211 //=================================================================================
212 void BasicGUI_PointDlg::Init()
213 {
214   GroupOnCurve->LineEdit1->setReadOnly( true );
215   GroupOnSurface->LineEdit1->setReadOnly( true );
216   GroupRefPoint->LineEdit1->setReadOnly( true );
217   GroupLineIntersection->LineEdit1->setReadOnly( true );
218   GroupLineIntersection->LineEdit2->setReadOnly( true );
219   GroupLineIntersection->LineEdit1->setEnabled( true );
220   GroupLineIntersection->LineEdit2->setEnabled( false );
221
222   myEdge = GEOM::GEOM_Object::_nil();
223   myRefPoint = GEOM::GEOM_Object::_nil();
224   myNeedType = TopAbs_VERTEX;
225
226   myEditCurrentArgument = 0;
227
228   /* Get setting of step value from file configuration */
229   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
230   double step = resMgr->doubleValue( "Geometry", "SettingsGeomStep", 100 );
231
232   /* min, max, step and decimals for spin boxes */
233   initSpinBox( GroupXYZ->SpinBox_DX, COORD_MIN, COORD_MAX, step, 6 ); // VSR: TODO: DBL_DIGITS_DISPLAY
234   initSpinBox( GroupXYZ->SpinBox_DY, COORD_MIN, COORD_MAX, step, 6 ); // VSR: TODO: DBL_DIGITS_DISPLAY
235   initSpinBox( GroupXYZ->SpinBox_DZ, COORD_MIN, COORD_MAX, step, 6 ); // VSR: TODO: DBL_DIGITS_DISPLAY
236   GroupXYZ->SpinBox_DX->setValue( 0.0 );
237   GroupXYZ->SpinBox_DY->setValue( 0.0 );
238   GroupXYZ->SpinBox_DZ->setValue( 0.0 );
239
240   initSpinBox( GroupRefPoint->SpinBox_DX, COORD_MIN, COORD_MAX, step, 6 ); // VSR: TODO: DBL_DIGITS_DISPLAY
241   initSpinBox( GroupRefPoint->SpinBox_DY, COORD_MIN, COORD_MAX, step, 6 ); // VSR: TODO: DBL_DIGITS_DISPLAY
242   initSpinBox( GroupRefPoint->SpinBox_DZ, COORD_MIN, COORD_MAX, step, 6 ); // VSR: TODO: DBL_DIGITS_DISPLAY
243   GroupRefPoint->SpinBox_DX->setValue( 0.0 );
244   GroupRefPoint->SpinBox_DY->setValue( 0.0 );
245   GroupRefPoint->SpinBox_DZ->setValue( 0.0 );
246
247   step = 0.1;
248
249   initSpinBox( GroupOnCurve->SpinBox_DX, 0., 1., step, 6 ); // VSR:TODO : DBL_DIGITS_DISPLAY
250   GroupOnCurve->SpinBox_DX->setValue( 0.5 );
251
252   initSpinBox( GroupOnSurface->SpinBox_DX, 0., 1., step, 6 ); // VSR:TODO : DBL_DIGITS_DISPLAY
253   GroupOnSurface->SpinBox_DX->setValue( 0.5 );
254   initSpinBox( GroupOnSurface->SpinBox_DY, 0., 1., step, 6 ); // VSR:TODO : DBL_DIGITS_DISPLAY
255   GroupOnSurface->SpinBox_DY->setValue( 0.5 );
256
257   /* signals and slots connections */
258   connect( myGeomGUI,      SIGNAL( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) );
259   connect( myGeomGUI,      SIGNAL( SignalCloseAllDialogs() ),        this, SLOT( ClickOnCancel() ) );
260
261   connect( buttonOk(),     SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
262   connect( buttonApply(),  SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
263
264   connect( this,           SIGNAL( constructorsClicked( int ) ), this, SLOT( ConstructorsClicked( int ) ) );
265
266   connect( myParamCoord->button( PARAM_VALUE ), SIGNAL( clicked() ), this, SLOT( ClickParamCoord() ) );
267   connect( myParamCoord->button( COORD_VALUE ), SIGNAL( clicked() ), this, SLOT( ClickParamCoord() ) );
268   connect( GroupOnCurve->PushButton1, SIGNAL( clicked() ),       this, SLOT( SetEditCurrentArgument() ) );
269   connect( GroupOnCurve->LineEdit1,   SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
270
271   connect( GroupOnSurface->PushButton1, SIGNAL( clicked() ),       this, SLOT( SetEditCurrentArgument() ) );
272   connect( GroupOnSurface->LineEdit1,   SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
273
274   connect( myBtnPopup, SIGNAL( triggered( QAction* ) ), SLOT( onBtnPopup( QAction* ) ) );
275   connect( GroupLineIntersection->PushButton1, SIGNAL( pressed() ),       this, SLOT( SetEditCurrentArgument() ) );
276   connect( GroupLineIntersection->PushButton2, SIGNAL( pressed() ),       this, SLOT( SetEditCurrentArgument() ) );
277   connect( GroupLineIntersection->LineEdit1,   SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
278   connect( GroupLineIntersection->LineEdit2,   SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
279
280   connect( GroupOnCurve->SpinBox_DX,   SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
281   connect( GroupOnSurface->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
282   connect( GroupOnSurface->SpinBox_DY, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
283   connect( GroupXYZ->SpinBox_DX,       SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
284   connect( GroupXYZ->SpinBox_DY,       SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
285   connect( GroupXYZ->SpinBox_DZ,       SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
286   connect( GroupRefPoint->SpinBox_DX,  SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
287   connect( GroupRefPoint->SpinBox_DY,  SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
288   connect( GroupRefPoint->SpinBox_DZ,  SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
289
290   connect( myGeomGUI, SIGNAL( SignalDefaultStepValueChanged( double ) ), this,  SLOT( SetDoubleSpinBoxStep( double ) ) );
291
292   connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged() ),
293            this,  SLOT(SelectionIntoArgument() ) );
294
295   initName( tr( "GEOM_VERTEX" ) );
296
297   ConstructorsClicked( 0 );
298 }
299
300 //=================================================================================
301 // function : SetDoubleSpinBoxStep()
302 // purpose  : Double spin box management
303 //=================================================================================
304 void BasicGUI_PointDlg::SetDoubleSpinBoxStep( double step )
305 {
306   GroupOnCurve->SpinBox_DX->setSingleStep(step);
307   GroupXYZ->SpinBox_DX->setSingleStep(step);
308   GroupXYZ->SpinBox_DY->setSingleStep(step);
309   GroupXYZ->SpinBox_DZ->setSingleStep(step);
310   GroupRefPoint->SpinBox_DX->setSingleStep(step);
311   GroupRefPoint->SpinBox_DY->setSingleStep(step);
312   GroupRefPoint->SpinBox_DZ->setSingleStep(step);
313   GroupOnSurface->SpinBox_DX->setSingleStep(step);
314   GroupOnSurface->SpinBox_DY->setSingleStep(step);
315 }
316
317
318 //=================================================================================
319 // function : ConstructorsClicked()
320 // purpose  : Radio button management
321 //=================================================================================
322 void BasicGUI_PointDlg::ConstructorsClicked(int constructorId)
323 {
324   switch ( constructorId ) {
325   case GEOM_POINT_XYZ:
326     {
327       globalSelection(); // close local contexts, if any
328       localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
329
330       GroupRefPoint->hide();
331       GroupOnCurve->hide();
332       GroupLineIntersection->hide();
333       GroupOnSurface->hide();
334       myCoordGrp->hide();
335       myParamGroup->hide();
336       GroupXYZ->show();
337       break;
338     }
339   case GEOM_POINT_REF:
340     {
341       globalSelection(); // close local contexts, if any
342       localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
343
344       myEditCurrentArgument = GroupRefPoint->LineEdit1;
345       myEditCurrentArgument->setText( "" );
346       myRefPoint = GEOM::GEOM_Object::_nil();
347       GroupRefPoint->PushButton1->setDown(true);
348       myParamGroup->hide();
349       GroupXYZ->hide();
350       GroupOnCurve->hide();
351       GroupLineIntersection->hide();
352       GroupOnSurface->hide();
353       GroupRefPoint->show();
354       myCoordGrp->show();
355       break;
356     }
357   case GEOM_POINT_EDGE:
358     {
359       globalSelection(); // close local contexts, if any
360       localSelection( GEOM::GEOM_Object::_nil(), TopAbs_EDGE );
361
362       myEditCurrentArgument = GroupOnCurve->LineEdit1;
363       myEditCurrentArgument->setText( "" );
364       myEdge = GEOM::GEOM_Object::_nil();
365       GroupOnCurve->PushButton1->setDown(true);
366       GroupRefPoint->hide();
367       GroupLineIntersection->hide();
368       GroupOnSurface->hide();
369       myParamGroup->show();
370       GroupOnCurve->show();
371       myCoordGrp->show();
372       updateParamCoord( false );
373       break;
374     }
375   case GEOM_POINT_INTINT:
376     {
377       globalSelection(); // close local contexts, if any
378       localSelection( GEOM::GEOM_Object::_nil(), TopAbs_EDGE );
379       myNeedType = TopAbs_EDGE;
380
381       myEditCurrentArgument = GroupLineIntersection->LineEdit1;
382       GroupLineIntersection->LineEdit1->setText( "" );
383       GroupLineIntersection->LineEdit2->setText( "" );
384       GroupLineIntersection->LineEdit1->setEnabled( true );
385       GroupLineIntersection->LineEdit2->setEnabled( false );
386       myLine1 = GEOM::GEOM_Object::_nil();
387       myLine2 = GEOM::GEOM_Object::_nil();
388       GroupLineIntersection->PushButton1->setDown(true);
389       GroupLineIntersection->PushButton2->setDown(false);
390       myParamGroup->hide();
391       GroupXYZ->hide();
392       GroupRefPoint->hide();
393       GroupOnCurve->hide();
394       GroupOnSurface->hide();
395       myCoordGrp->hide();
396       GroupLineIntersection->show();
397       break;
398     }
399   case GEOM_POINT_SURF:
400     {
401       globalSelection(); // close local contexts, if any
402       localSelection( GEOM::GEOM_Object::_nil(), TopAbs_FACE );
403
404       myEditCurrentArgument = GroupOnSurface->LineEdit1;
405       myEditCurrentArgument->setText( "" );
406       myFace = GEOM::GEOM_Object::_nil();
407       GroupOnSurface->PushButton1->setDown(true);
408       GroupRefPoint->hide();
409       GroupOnCurve->hide();
410       GroupLineIntersection->hide();
411       myParamGroup->show();
412       GroupOnSurface->show();
413       myCoordGrp->show();
414       updateParamCoord( false );
415       break;
416     }
417   }
418
419   myX->setText( "" );
420   myY->setText( "" );
421   myZ->setText( "" );
422
423   qApp->processEvents();
424   updateGeometry();
425   resize( 100, 100 );
426
427   SelectionIntoArgument();
428 }
429
430
431 //=================================================================================
432 // function : ClickOnOk()
433 // purpose  :
434 //=================================================================================
435 void BasicGUI_PointDlg::ClickOnOk()
436 {
437   if ( onAccept() )
438     ClickOnCancel();
439 }
440
441
442 //=================================================================================
443 // function : ClickOnApply()
444 // purpose  :
445 //=================================================================================
446 bool BasicGUI_PointDlg::ClickOnApply()
447 {
448   if ( !onAccept() )
449     return false;
450
451   initName();
452   ConstructorsClicked( getConstructorId() );
453   return true;
454 }
455
456
457 //=================================================================================
458 // function : SelectionIntoArgument()
459 // purpose  : Called when selection as changed (for constructors not using local context)
460 //=================================================================================
461 void BasicGUI_PointDlg::SelectionIntoArgument()
462 {
463   erasePreview();
464   const int id = getConstructorId();
465
466   if ( ( id == GEOM_POINT_REF || id == GEOM_POINT_EDGE || id == GEOM_POINT_SURF ) && myEditCurrentArgument != 0 )
467   {
468     myEditCurrentArgument->setText( "" );
469     myX->setText( "" );
470     myY->setText( "" );
471     myZ->setText( "" );
472     myRefPoint = myEdge = myFace = GEOM::GEOM_Object::_nil();
473   } else if ( id == GEOM_POINT_INTINT ) {
474     myEditCurrentArgument->setText( "" );
475     if ( myEditCurrentArgument == GroupLineIntersection->LineEdit1 )
476       myLine1 = GEOM::GEOM_Object::_nil();
477     else if ( myEditCurrentArgument == GroupLineIntersection->LineEdit2 )
478       myLine2 = GEOM::GEOM_Object::_nil();
479   }
480
481   LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
482   SALOME_ListIO aSelList;
483   aSelMgr->selectedObjects(aSelList);
484
485   if (aSelList.Extent() == 1) {
486     Standard_Boolean aRes = Standard_False;
487     Handle(SALOME_InteractiveObject) anIO = aSelList.First();
488     GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( anIO, aRes );
489     if ( !CORBA::is_nil( aSelectedObject ) && aRes ) {
490       QString aName = GEOMBase::GetName(aSelectedObject);
491       TopoDS_Shape aShape;
492       if ( GEOMBase::GetShape( aSelectedObject, aShape, TopAbs_SHAPE ) && !aShape.IsNull() ) {
493         if ( id == GEOM_POINT_XYZ || id == GEOM_POINT_REF)
494           myNeedType = TopAbs_VERTEX;
495         else if ( id == GEOM_POINT_EDGE )
496           myNeedType = TopAbs_EDGE;
497         else if ( id == GEOM_POINT_SURF )
498           myNeedType = TopAbs_FACE;
499
500         TColStd_IndexedMapOfInteger aMap;
501         aSelMgr->GetIndexes(anIO, aMap);
502         if ( aMap.Extent() == 1 ) { // Local Selection
503           int anIndex = aMap( 1 );
504           if ( myNeedType == TopAbs_FACE )
505             aName += QString( ":face_%1" ).arg( anIndex );
506           else if ( myNeedType == TopAbs_WIRE )
507             aName += QString( ":wire_%1" ).arg( anIndex );
508           else if ( myNeedType == TopAbs_EDGE )
509             aName += QString( ":edge_%1" ).arg( anIndex );
510           else  if ( myNeedType == TopAbs_VERTEX )
511             aName += QString( ":vertex_%1" ).arg( anIndex );
512
513           //Find SubShape Object in Father
514           GEOM::GEOM_Object_var aFindedObject = GEOMBase_Helper::findObjectInFather(aSelectedObject, aName);
515
516           if ( aFindedObject == GEOM::GEOM_Object::_nil() ) { // Object not found in study
517             GEOM::GEOM_IShapesOperations_var aShapesOp =
518               getGeomEngine()->GetIShapesOperations(getStudyId());
519             aSelectedObject = aShapesOp->GetSubShape(aSelectedObject, anIndex);
520           }
521           else {
522             aSelectedObject = aFindedObject; // get Object from study
523           }
524           GEOMBase::GetShape( aSelectedObject, aShape, TopAbs_SHAPE );
525         }
526         else { // Global Selection
527           if ( aShape.ShapeType() != myNeedType ) {
528             aSelectedObject = GEOM::GEOM_Object::_nil();
529             aName = "";
530             if ( id == GEOM_POINT_XYZ ) return;
531           }
532         }
533       }
534
535       if ( aShape.IsNull() || aShape.ShapeType() != myNeedType)
536         return;
537
538       if ( id == GEOM_POINT_XYZ ) {
539         gp_Pnt aPnt = BRep_Tool::Pnt( TopoDS::Vertex( aShape ) );
540         GroupXYZ->SpinBox_DX->setValue( aPnt.X() );
541         GroupXYZ->SpinBox_DY->setValue( aPnt.Y() );
542         GroupXYZ->SpinBox_DZ->setValue( aPnt.Z() );
543       }
544       else if ( id == GEOM_POINT_REF ) {
545         myRefPoint = aSelectedObject;
546         GroupRefPoint->LineEdit1->setText( aName );
547       }
548       else if ( id == GEOM_POINT_EDGE ) {
549         myEdge = aSelectedObject;
550         GroupOnCurve->LineEdit1->setText( aName );
551       }
552       else if ( id == GEOM_POINT_INTINT ) {
553         myEditCurrentArgument->setText( aName );
554         if ( myEditCurrentArgument == GroupLineIntersection->LineEdit1 ) {
555           myLine1 = aSelectedObject;
556           if ( !myLine1->_is_nil() && myLine2->_is_nil() ) {
557             GroupLineIntersection->PushButton2->setMenu( 0 );
558             GroupLineIntersection->PushButton2->click();
559             GroupLineIntersection->PushButton2->setDown(true);
560             GroupLineIntersection->PushButton2->setMenu( myBtnPopup );
561           }
562         }
563         else if ( myEditCurrentArgument == GroupLineIntersection->LineEdit2 ) {
564           myLine2 = aSelectedObject;
565           if ( !myLine2->_is_nil() && myLine1->_is_nil() ) {
566             GroupLineIntersection->PushButton1->setMenu( 0 );
567             GroupLineIntersection->PushButton1->click();
568             GroupLineIntersection->PushButton1->setDown(true);
569             GroupLineIntersection->PushButton1->setMenu( myBtnPopup );
570           }
571         }
572       }
573       else if ( id == GEOM_POINT_SURF )
574       {
575         myFace = aSelectedObject;
576         GroupOnSurface->LineEdit1->setText( aName );
577       }
578     }
579   }
580
581   displayPreview();
582 }
583
584
585 //=================================================================================
586 // function : LineEditReturnPressed()
587 // purpose  :
588 //=================================================================================
589 void BasicGUI_PointDlg::LineEditReturnPressed()
590 {
591   QLineEdit* send = (QLineEdit*)sender();
592   if ( send == GroupRefPoint->LineEdit1         ||
593        send == GroupOnCurve->LineEdit1          ||
594        send == GroupLineIntersection->LineEdit1 ||
595        send == GroupLineIntersection->LineEdit2  ) {
596     myEditCurrentArgument = send;
597     GEOMBase_Skeleton::LineEditReturnPressed();
598   }
599 }
600
601
602 //=================================================================================
603 // function : SetEditCurrentArgument()
604 // purpose  :
605 //=================================================================================
606 void BasicGUI_PointDlg::SetEditCurrentArgument()
607 {
608   QPushButton* send = (QPushButton*)sender();
609
610   if ( send == GroupRefPoint->PushButton1 ) {
611     GroupRefPoint->LineEdit1->setFocus();
612     myEditCurrentArgument = GroupRefPoint->LineEdit1;
613     globalSelection(); // close local contexts, if any
614     localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
615   }
616   else if ( send == GroupOnCurve->PushButton1 ) {
617     GroupOnCurve->LineEdit1->setFocus();
618     myEditCurrentArgument = GroupOnCurve->LineEdit1;
619     globalSelection(); // close local contexts, if any
620     localSelection( GEOM::GEOM_Object::_nil(), TopAbs_EDGE );
621   }
622   else if ( send == GroupOnSurface->PushButton1 )
623   {
624     GroupOnSurface->LineEdit1->setFocus();
625     myEditCurrentArgument = GroupOnSurface->LineEdit1;
626     globalSelection(); // close local contexts, if any
627     localSelection( GEOM::GEOM_Object::_nil(), TopAbs_FACE );
628   }
629   else if ( send == GroupLineIntersection->PushButton1 ) {
630     GroupLineIntersection->LineEdit1->setFocus();
631     myEditCurrentArgument = GroupLineIntersection->LineEdit1;
632     GroupLineIntersection->PushButton2->setDown( false );
633     GroupLineIntersection->LineEdit1->setEnabled(true);
634     GroupLineIntersection->LineEdit2->setEnabled(false);
635   }
636   else if ( send == GroupLineIntersection->PushButton2 ) {
637     GroupLineIntersection->LineEdit2->setFocus();
638     myEditCurrentArgument = GroupLineIntersection->LineEdit2;
639     GroupLineIntersection->PushButton1->setDown( false );
640     GroupLineIntersection->LineEdit1->setEnabled(false);
641     GroupLineIntersection->LineEdit2->setEnabled(true);
642   }
643   send->setDown(true);
644 }
645
646
647 //=================================================================================
648 // function : enterEvent()
649 // purpose  : to reactivate this dialog box when mouse enter onto the window
650 //=================================================================================
651 void BasicGUI_PointDlg::enterEvent( QEvent* )
652 {
653   if ( !mainFrame()->GroupConstructors->isEnabled() )
654     ActivateThisDialog();
655 }
656
657
658 //=================================================================================
659 // function : ActivateThisDialog()
660 // purpose  :
661 //=================================================================================
662 void BasicGUI_PointDlg::ActivateThisDialog( )
663 {
664   GEOMBase_Skeleton::ActivateThisDialog();
665
666   connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
667            this, SLOT( SelectionIntoArgument() ) );
668
669   ConstructorsClicked( getConstructorId() );
670 }
671
672
673 //=================================================================================
674 // function : DeactivateActiveDialog()
675 // purpose  : public slot to deactivate if active
676 //=================================================================================
677 void BasicGUI_PointDlg::DeactivateActiveDialog()
678 {
679   // myGeomGUI->SetState( -1 );
680   GEOMBase_Skeleton::DeactivateActiveDialog();
681 }
682
683
684 //=================================================================================
685 // function : ValueChangedInSpinBox()
686 // purpose  :
687 //=================================================================================
688 void BasicGUI_PointDlg::ValueChangedInSpinBox(double newValue)
689 {
690   displayPreview();
691 }
692
693 //=================================================================================
694 // funcion  : getParameter()
695 // purpose  :
696 //=================================================================================
697 double BasicGUI_PointDlg::getParameter() const
698 {
699   return GroupOnCurve->SpinBox_DX->value();
700 }
701
702
703 //=================================================================================
704 // funcion  : getUParameter()
705 // purpose  :
706 //=================================================================================
707 double BasicGUI_PointDlg::getUParameter() const
708 {
709   return GroupOnSurface->SpinBox_DX->value();
710 }
711
712
713 //=================================================================================
714 // funcion  : getVParameter()
715 // purpose  :
716 //=================================================================================
717 double BasicGUI_PointDlg::getVParameter() const
718 {
719   return GroupOnSurface->SpinBox_DY->value();
720 }
721
722
723 //=================================================================================
724 // function : OnPointSelected
725 // purpose  :
726 //=================================================================================
727 void BasicGUI_PointDlg::OnPointSelected( const gp_Pnt& thePnt )
728 {
729   if ( getConstructorId() == GEOM_POINT_XYZ ) {
730     GroupXYZ->SpinBox_DX->setValue( thePnt.X() );
731     GroupXYZ->SpinBox_DY->setValue( thePnt.Y() );
732     GroupXYZ->SpinBox_DZ->setValue( thePnt.Z() );
733
734     displayPreview();
735   }
736 }
737
738 //=================================================================================
739 // function : createOperation
740 // purpose  :
741 //=================================================================================
742 GEOM::GEOM_IOperations_ptr BasicGUI_PointDlg::createOperation()
743 {
744   return myGeomGUI->GetGeomGen()->GetIBasicOperations( getStudyId() );
745 }
746
747 //=================================================================================
748 // function : isValid
749 // purpose  :
750 //=================================================================================
751 bool BasicGUI_PointDlg::isValid( QString& msg )
752 {
753   const int id = getConstructorId();
754   if ( id == GEOM_POINT_XYZ ) {
755     bool ok = true;
756     ok = GroupXYZ->SpinBox_DX->isValid( msg, !IsPreview() ) && ok;
757     ok = GroupXYZ->SpinBox_DY->isValid( msg, !IsPreview() ) && ok;
758     ok = GroupXYZ->SpinBox_DZ->isValid( msg, !IsPreview() ) && ok;
759     return ok;
760   }
761   else if ( id == GEOM_POINT_REF ) {
762     bool ok = true;
763     ok = GroupRefPoint->SpinBox_DX->isValid( msg, !IsPreview() ) && ok;
764     ok = GroupRefPoint->SpinBox_DY->isValid( msg, !IsPreview() ) && ok;
765     ok = GroupRefPoint->SpinBox_DZ->isValid( msg, !IsPreview() ) && ok;
766
767     return !myRefPoint->_is_nil() && ok;
768   }
769   else if ( id == GEOM_POINT_EDGE ) {
770     bool ok = true;
771     if ( myParamCoord->checkedId() == PARAM_VALUE )
772       ok = GroupOnCurve->SpinBox_DX->isValid( msg, !IsPreview() );
773     else {
774       ok = GroupXYZ->SpinBox_DX->isValid( msg, !IsPreview() ) && ok;
775       ok = GroupXYZ->SpinBox_DY->isValid( msg, !IsPreview() ) && ok;
776       ok = GroupXYZ->SpinBox_DZ->isValid( msg, !IsPreview() ) && ok;
777     }
778     return !myEdge->_is_nil() && ok;
779   }
780   else if ( id == GEOM_POINT_INTINT )
781     return ( !myLine1->_is_nil() && !myLine2->_is_nil() );
782   else if ( id == GEOM_POINT_SURF ) {
783     bool ok = true;
784     if ( myParamCoord->checkedId() == PARAM_VALUE ) {
785       ok = GroupOnSurface->SpinBox_DX->isValid( msg, !IsPreview() ) && ok;
786       ok = GroupOnSurface->SpinBox_DY->isValid( msg, !IsPreview() ) && ok;
787     }
788     else {
789       ok = GroupXYZ->SpinBox_DX->isValid( msg, !IsPreview() ) && ok;
790       ok = GroupXYZ->SpinBox_DY->isValid( msg, !IsPreview() ) && ok;
791       ok = GroupXYZ->SpinBox_DZ->isValid( msg, !IsPreview() ) && ok;
792     }
793     return !myFace->_is_nil() && ok;
794   }
795   return false;
796 }
797
798 //=================================================================================
799 // function : execute
800 // purpose  :
801 //=================================================================================
802 bool BasicGUI_PointDlg::execute( ObjectList& objects )
803 {
804   bool res = false;
805
806   GEOM::GEOM_Object_var anObj;
807   QStringList aParameters;
808
809   GEOM::GEOM_IBasicOperations_var anOper = GEOM::GEOM_IBasicOperations::_narrow( getOperation() );
810
811   switch ( getConstructorId() ) {
812   case GEOM_POINT_XYZ :
813     {
814       double x = GroupXYZ->SpinBox_DX->value();
815       double y = GroupXYZ->SpinBox_DY->value();
816       double z = GroupXYZ->SpinBox_DZ->value();
817
818       aParameters << GroupXYZ->SpinBox_DX->text();
819       aParameters << GroupXYZ->SpinBox_DY->text();
820       aParameters << GroupXYZ->SpinBox_DZ->text();
821
822       anObj = anOper->MakePointXYZ( x, y, z );
823       res = true;
824       break;
825     }
826   case GEOM_POINT_REF :
827     {
828       double dx = GroupRefPoint->SpinBox_DX->value();
829       double dy = GroupRefPoint->SpinBox_DY->value();
830       double dz = GroupRefPoint->SpinBox_DZ->value();
831
832       aParameters << GroupRefPoint->SpinBox_DX->text();
833       aParameters << GroupRefPoint->SpinBox_DY->text();
834       aParameters << GroupRefPoint->SpinBox_DZ->text();
835
836       anObj = anOper->MakePointWithReference( myRefPoint, dx, dy, dz );
837       res = true;
838       break;
839     }
840   case GEOM_POINT_EDGE :
841     {
842       if ( myParamCoord->checkedId() == PARAM_VALUE ) {
843         anObj = anOper->MakePointOnCurve( myEdge, getParameter() );
844         aParameters<<GroupOnCurve->SpinBox_DX->text();
845       } else {
846         double x = GroupXYZ->SpinBox_DX->value();
847         double y = GroupXYZ->SpinBox_DY->value();
848         double z = GroupXYZ->SpinBox_DZ->value();
849
850         aParameters << GroupXYZ->SpinBox_DX->text();
851         aParameters << GroupXYZ->SpinBox_DY->text();
852         aParameters << GroupXYZ->SpinBox_DZ->text();
853
854         anObj = anOper->MakePointOnCurveByCoord( myEdge, x, y, z );
855       }
856       res = true;
857       break;
858     }
859   case GEOM_POINT_INTINT :
860     anObj = anOper->MakePointOnLinesIntersection( myLine1, myLine2 );
861     if ( !anObj->_is_nil() ) {
862       QString aName = getNewObjectName();
863       if ( anObj->GetShapeType() == GEOM::COMPOUND && aName.startsWith("Vertex") )
864         initName( tr( "GEOM_COMPOUND" ) );
865       else if (  anObj->GetShapeType() == GEOM::VERTEX && aName.startsWith("Compound"))
866         initName( tr( "GEOM_VERTEX" ) );
867     }
868     res = true;
869     break;
870   case GEOM_POINT_SURF :
871     {
872       if ( myParamCoord->checkedId() == PARAM_VALUE ) {
873         anObj = anOper->MakePointOnSurface( myFace, getUParameter(), getVParameter() );
874         aParameters<<GroupOnSurface->SpinBox_DX->text();
875         aParameters<<GroupOnSurface->SpinBox_DY->text();
876       } else {
877         double x = GroupXYZ->SpinBox_DX->value();
878         double y = GroupXYZ->SpinBox_DY->value();
879         double z = GroupXYZ->SpinBox_DZ->value();
880
881         aParameters << GroupXYZ->SpinBox_DX->text();
882         aParameters << GroupXYZ->SpinBox_DY->text();
883         aParameters << GroupXYZ->SpinBox_DZ->text();
884
885         anObj = anOper->MakePointOnSurfaceByCoord( myFace, x, y, z );
886       }
887       res = true;
888       break;
889     }
890   }
891
892   const int id = getConstructorId();
893   if(!anObj->_is_nil() && !IsPreview() && (id == GEOM_POINT_XYZ ||
894                                            id == GEOM_POINT_REF ||
895                                            id == GEOM_POINT_EDGE ||
896                                            id == GEOM_POINT_SURF) ) {
897       anObj->SetParameters(aParameters.join(":").toLatin1().constData());
898   }
899
900   if ( id == GEOM_POINT_REF || id == GEOM_POINT_EDGE || id == GEOM_POINT_SURF ) {
901     TopoDS_Shape aShape;
902     if ( GEOMBase::GetShape( anObj, aShape ) && !aShape.IsNull() &&
903          aShape.ShapeType() == TopAbs_VERTEX ) {
904       gp_Pnt aPnt = BRep_Tool::Pnt( TopoDS::Vertex( aShape ) );
905       myX->setText( QString( "%1" ).arg( aPnt.X() ) );
906       myY->setText( QString( "%1" ).arg( aPnt.Y() ) );
907       myZ->setText( QString( "%1" ).arg( aPnt.Z() ) );
908     }
909     else {
910       myX->setText( "" );
911       myY->setText( "" );
912       myZ->setText( "" );
913     }
914   }
915
916   if ( !anObj->_is_nil() ) {
917     objects.push_back( anObj._retn() );
918   }
919
920   return res;
921 }
922
923 //=================================================================================
924 // function : addSubshapeToStudy
925 // purpose  : virtual method to add new SubObjects if local selection
926 //=================================================================================
927 void BasicGUI_PointDlg::addSubshapesToStudy()
928 {
929   QMap<QString, GEOM::GEOM_Object_var> objMap;
930
931   switch ( getConstructorId() ) {
932   case GEOM_POINT_XYZ:
933     break;
934   case GEOM_POINT_REF:
935     objMap[GroupRefPoint->LineEdit1->text()] = myRefPoint;
936     break;
937   case GEOM_POINT_EDGE:
938     objMap[GroupOnCurve->LineEdit1->text()] = myEdge;
939     break;
940   case GEOM_POINT_INTINT:
941     objMap[GroupLineIntersection->LineEdit1->text()] = myLine1;
942     objMap[GroupLineIntersection->LineEdit2->text()] = myLine2;
943     break;
944   case GEOM_POINT_SURF:
945     objMap[GroupOnSurface->LineEdit1->text()] = myFace;
946     break;
947   }
948   addSubshapesToFather( objMap );
949 }
950
951 //=================================================================================
952 // function : ClickParamCoord()
953 // purpose  :
954 //=================================================================================
955 void BasicGUI_PointDlg::ClickParamCoord()
956 {
957   updateParamCoord( true );
958   displayPreview();
959 }
960
961 //=================================================================================
962 // function : updateParamCoord
963 // purpose  :
964 //=================================================================================
965 void BasicGUI_PointDlg::updateParamCoord(bool theIsUpdate)
966 {
967   bool isParam = myParamCoord->checkedId() == PARAM_VALUE;
968   GroupXYZ->setShown( !isParam );
969
970   const int id = getConstructorId();
971   if ( id == GEOM_POINT_EDGE ) {
972     GroupOnCurve->TextLabel2->setShown( isParam );
973     GroupOnCurve->SpinBox_DX->setShown( isParam );
974   }
975   else if ( id == GEOM_POINT_SURF ) {
976     GroupOnSurface->TextLabel2->setShown( isParam );
977     GroupOnSurface->TextLabel3->setShown( isParam );
978     GroupOnSurface->SpinBox_DX->setShown( isParam );
979     GroupOnSurface->SpinBox_DY->setShown( isParam );
980   }
981   if ( theIsUpdate ) {
982     qApp->processEvents();
983     updateGeometry();
984     resize( minimumSizeHint() );
985   }
986 }
987
988 //=================================================================================
989 // function : onBtnPopup()
990 // purpose  :
991 //=================================================================================
992 void BasicGUI_PointDlg::onBtnPopup( QAction* a )
993 {
994   int index = myActions[a];
995   globalSelection(); // close local contexts, if any
996   QString type;
997   if ( index == 0 )
998     myNeedType = TopAbs_EDGE;
999   else 
1000     myNeedType = TopAbs_WIRE;
1001   
1002   localSelection( GEOM::GEOM_Object::_nil(), myNeedType );
1003 }