Salome HOME
IPAL21643 Point construction dialog appearance is wrong for 1st mode
[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 #include <QTimer>
47
48 #include <gp_Pnt.hxx>
49 #include <TopoDS_Shape.hxx>
50 #include <TopAbs_ShapeEnum.hxx>
51 #include <TopoDS.hxx>
52 #include <BRep_Tool.hxx>
53 #include <TopExp.hxx>
54 #include <TColStd_IndexedMapOfInteger.hxx>
55 #include <TopTools_IndexedMapOfShape.hxx>
56
57 #define PARAM_VALUE 0
58 #define COORD_VALUE 1
59
60 #define GEOM_POINT_XYZ    0
61 #define GEOM_POINT_REF    1
62 #define GEOM_POINT_EDGE   2
63 #define GEOM_POINT_INTINT 3
64 #define GEOM_POINT_SURF   4
65
66 #define SPACING 6
67 #define MARGIN  9
68
69 //=================================================================================
70 // class    : BasicGUI_PointDlg()
71 // purpose  : Constructs a BasicGUI_PointDlg which is a child of 'parent', with the
72 //            name 'name' and widget flags set to 'f'.
73 //            The dialog will by default be modeless, unless you set 'modal' to
74 //            TRUE to construct a modal dialog.
75 //=================================================================================
76 BasicGUI_PointDlg::BasicGUI_PointDlg( GeometryGUI* theGeometryGUI, QWidget* parent,
77                                       bool modal, Qt::WindowFlags fl )
78   : GEOMBase_Skeleton( theGeometryGUI, parent, modal, fl )
79 {
80   QPixmap image0( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_POINT") ) );
81   QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_POINT_EDGE" ) ) );
82   QPixmap image2( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
83   QPixmap image3( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_POINT_REF" ) ) );
84   QPixmap image4( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_POINT_LINES") ) );
85   QPixmap image5( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_POINT_FACE" ) ) );
86   QPixmap image6( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICO_LINE" ) ) );
87   QPixmap image7( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICO_WIRE" ) ) );
88
89   setWindowTitle( tr( "GEOM_POINT_TITLE" ) );
90
91   /***************************************************************/
92   mainFrame()->GroupConstructors->setTitle( tr( "GEOM_POINTS" ) );
93   mainFrame()->RadioButton1->setIcon( image0 );
94   mainFrame()->RadioButton2->setIcon( image3 );
95   mainFrame()->RadioButton3->setIcon( image1 );
96   mainFrame()->RadioButton4->show();
97   mainFrame()->RadioButton4->setIcon( image4 );
98   mainFrame()->RadioButton5->show();
99   mainFrame()->RadioButton5->setIcon( image5 );
100
101   myParamGroup = new QGroupBox( centralWidget() );
102   myParamCoord = new QButtonGroup( myParamGroup );
103   QHBoxLayout* boxLayout = new QHBoxLayout( myParamGroup );
104   boxLayout->setMargin( MARGIN ); boxLayout->setSpacing( SPACING );
105   QRadioButton* btn = new QRadioButton( tr( "GEOM_PARAM_VALUE" ), myParamGroup );
106   myParamCoord->addButton( btn, PARAM_VALUE );
107   boxLayout->addWidget( btn );
108   btn = new QRadioButton( tr( "GEOM_COORD_VALUE" ), myParamGroup );
109   myParamCoord->addButton( btn, COORD_VALUE );
110   boxLayout->addWidget( btn );
111   myParamCoord->setExclusive( true );
112   myParamCoord->button( PARAM_VALUE )->setChecked( true );
113
114   GroupXYZ = new DlgRef_3Spin( centralWidget() );
115   GroupXYZ->GroupBox1->setTitle( tr( "GEOM_COORDINATES" ) );
116   GroupXYZ->TextLabel1->setText( tr( "GEOM_X" ) );
117   GroupXYZ->TextLabel2->setText( tr( "GEOM_Y" ) );
118   GroupXYZ->TextLabel3->setText( tr( "GEOM_Z" ) );
119
120   GroupOnCurve = new DlgRef_1Sel1Spin( centralWidget() );
121   GroupOnCurve->GroupBox1->setTitle( tr( "GEOM_POINT_ON_EDGE" ) );
122   GroupOnCurve->TextLabel1->setText( tr( "GEOM_EDGE" ) );
123   GroupOnCurve->TextLabel2->setText( tr( "GEOM_PARAMETER" ) );
124   GroupOnCurve->PushButton1->setIcon( image2 );
125
126   GroupOnSurface = new DlgRef_1Sel2Spin( centralWidget() );
127   GroupOnSurface->GroupBox1->setTitle( tr( "GEOM_POINT_ON_FACE" ) );
128   GroupOnSurface->TextLabel1->setText( tr( "GEOM_FACE" ) );
129   GroupOnSurface->TextLabel2->setText( tr( "GEOM_UPARAMETER" ) );
130   GroupOnSurface->TextLabel3->setText( tr( "GEOM_VPARAMETER" ) );
131   GroupOnSurface->PushButton1->setIcon( image2 );
132
133   GroupRefPoint = new DlgRef_1Sel3Spin( centralWidget() );
134   GroupRefPoint->GroupBox1->setTitle( tr( "GEOM_REF_POINT" ) );
135   GroupRefPoint->TextLabel1->setText( tr( "GEOM_POINT" ) );
136   GroupRefPoint->PushButton1->setIcon( image2 );
137   GroupRefPoint->TextLabel2->setText( tr( "GEOM_DX" ) );
138   GroupRefPoint->TextLabel3->setText( tr( "GEOM_DY" ) );
139   GroupRefPoint->TextLabel4->setText( tr( "GEOM_DZ" ) );
140
141   /* popup menu for line intersect buttons */
142   myBtnPopup = new QMenu(this);
143   QIcon ico_line = QIcon( image6 );
144   QIcon ico_wire = QIcon( image7 );
145   myActions[myBtnPopup->addAction( ico_line, tr( "GEOM_EDGE" ) )] = 0;
146   myActions[myBtnPopup->addAction( ico_wire, tr( "GEOM_WIRE" ) )] = 1;
147
148   GroupLineIntersection = new DlgRef_2Sel( centralWidget() );
149   GroupLineIntersection->GroupBox1->setTitle( tr( "GEOM_LINE_INTERSECTION" ) );
150   GroupLineIntersection->TextLabel1->setText( tr( "GEOM_LINE1" ) );
151   GroupLineIntersection->TextLabel2->setText( tr( "GEOM_LINE2" ) );
152   GroupLineIntersection->PushButton1->setIcon( image2 );
153   GroupLineIntersection->PushButton1->setMenu( myBtnPopup );
154   GroupLineIntersection->PushButton2->setIcon( image2 );
155   GroupLineIntersection->PushButton2->setMenu( myBtnPopup );
156   GroupLineIntersection->LineEdit2->setEnabled(false);
157
158   myCoordGrp = new QGroupBox( tr( "GEOM_COORDINATES_RES" ), centralWidget() );
159   QGridLayout* myCoordGrpLayout = new QGridLayout( myCoordGrp );
160   myCoordGrpLayout->addWidget( new QLabel( tr( "GEOM_X" ), myCoordGrp ), 0, 0 );
161   myX = new QLineEdit( myCoordGrp );
162   myCoordGrpLayout->addWidget( myX, 0, 1 );
163   myCoordGrpLayout->addWidget( new QLabel( tr( "GEOM_Y" ), myCoordGrp ), 1, 0 );
164   myY = new QLineEdit( myCoordGrp );
165   myCoordGrpLayout->addWidget( myY, 1, 1 );
166   myCoordGrpLayout->addWidget( new QLabel( tr( "GEOM_Z" ), myCoordGrp ), 2, 0 );
167   myZ = new QLineEdit( myCoordGrp );
168   myCoordGrpLayout->addWidget( myZ, 2, 1 );
169
170   QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
171   layout->setMargin( 0 ); layout->setSpacing( 6 );
172   layout->addWidget( myParamGroup );
173   layout->addWidget( GroupXYZ );
174   layout->addWidget( GroupOnCurve );
175   layout->addWidget( GroupOnSurface );
176   layout->addWidget( GroupRefPoint );
177   layout->addWidget( GroupLineIntersection );
178   layout->addWidget( myCoordGrp );
179
180   myX->setReadOnly( true );
181   myY->setReadOnly( true );
182   myZ->setReadOnly( true );
183
184   myX->setEnabled( false );
185   myY->setEnabled( false );
186   myZ->setEnabled( false );
187
188   QPalette aPal = myX->palette();
189   aPal.setColor( QPalette::Disabled, QPalette::Text, QColor( 0, 0, 0 ) );
190   myX->setPalette( aPal );
191   myY->setPalette( aPal );
192   myZ->setPalette( aPal );
193
194   setHelpFileName( "create_point_page.html" );
195
196   Init();
197 }
198
199
200 //=================================================================================
201 // function : ~BasicGUI_PointDlg()
202 // purpose  : Destructor
203 //=================================================================================
204 BasicGUI_PointDlg::~BasicGUI_PointDlg()
205 {
206 }
207
208
209 //=================================================================================
210 // function : Init()
211 // purpose  :
212 //=================================================================================
213 void BasicGUI_PointDlg::Init()
214 {
215   GroupOnCurve->LineEdit1->setReadOnly( true );
216   GroupOnSurface->LineEdit1->setReadOnly( true );
217   GroupRefPoint->LineEdit1->setReadOnly( true );
218   GroupLineIntersection->LineEdit1->setReadOnly( true );
219   GroupLineIntersection->LineEdit2->setReadOnly( true );
220   GroupLineIntersection->LineEdit1->setEnabled( true );
221   GroupLineIntersection->LineEdit2->setEnabled( false );
222
223   myEdge = GEOM::GEOM_Object::_nil();
224   myRefPoint = GEOM::GEOM_Object::_nil();
225   myNeedType = TopAbs_VERTEX;
226
227   myEditCurrentArgument = 0;
228
229   /* Get setting of step value from file configuration */
230   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
231   double step = resMgr->doubleValue( "Geometry", "SettingsGeomStep", 100 );
232
233   /* min, max, step and decimals for spin boxes */
234   initSpinBox( GroupXYZ->SpinBox_DX, COORD_MIN, COORD_MAX, step, 6 ); // VSR: TODO: DBL_DIGITS_DISPLAY
235   initSpinBox( GroupXYZ->SpinBox_DY, COORD_MIN, COORD_MAX, step, 6 ); // VSR: TODO: DBL_DIGITS_DISPLAY
236   initSpinBox( GroupXYZ->SpinBox_DZ, COORD_MIN, COORD_MAX, step, 6 ); // VSR: TODO: DBL_DIGITS_DISPLAY
237   GroupXYZ->SpinBox_DX->setValue( 0.0 );
238   GroupXYZ->SpinBox_DY->setValue( 0.0 );
239   GroupXYZ->SpinBox_DZ->setValue( 0.0 );
240
241   initSpinBox( GroupRefPoint->SpinBox_DX, COORD_MIN, COORD_MAX, step, 6 ); // VSR: TODO: DBL_DIGITS_DISPLAY
242   initSpinBox( GroupRefPoint->SpinBox_DY, COORD_MIN, COORD_MAX, step, 6 ); // VSR: TODO: DBL_DIGITS_DISPLAY
243   initSpinBox( GroupRefPoint->SpinBox_DZ, COORD_MIN, COORD_MAX, step, 6 ); // VSR: TODO: DBL_DIGITS_DISPLAY
244   GroupRefPoint->SpinBox_DX->setValue( 0.0 );
245   GroupRefPoint->SpinBox_DY->setValue( 0.0 );
246   GroupRefPoint->SpinBox_DZ->setValue( 0.0 );
247
248   step = 0.1;
249
250   initSpinBox( GroupOnCurve->SpinBox_DX, 0., 1., step, 6 ); // VSR:TODO : DBL_DIGITS_DISPLAY
251   GroupOnCurve->SpinBox_DX->setValue( 0.5 );
252
253   initSpinBox( GroupOnSurface->SpinBox_DX, 0., 1., step, 6 ); // VSR:TODO : DBL_DIGITS_DISPLAY
254   GroupOnSurface->SpinBox_DX->setValue( 0.5 );
255   initSpinBox( GroupOnSurface->SpinBox_DY, 0., 1., step, 6 ); // VSR:TODO : DBL_DIGITS_DISPLAY
256   GroupOnSurface->SpinBox_DY->setValue( 0.5 );
257
258   /* signals and slots connections */
259   connect( myGeomGUI,      SIGNAL( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) );
260   connect( myGeomGUI,      SIGNAL( SignalCloseAllDialogs() ),        this, SLOT( ClickOnCancel() ) );
261
262   connect( buttonOk(),     SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
263   connect( buttonApply(),  SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
264
265   connect( this,           SIGNAL( constructorsClicked( int ) ), this, SLOT( ConstructorsClicked( int ) ) );
266
267   connect( myParamCoord,   SIGNAL( buttonClicked( int ) ), this, SLOT( ClickParamCoord( int ) ) );
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   QTimer::singleShot(50, this, SLOT(updateSize()));
424
425   SelectionIntoArgument();
426 }
427
428
429 //=================================================================================
430 // function : ClickOnOk()
431 // purpose  :
432 //=================================================================================
433 void BasicGUI_PointDlg::ClickOnOk()
434 {
435   if ( onAccept() )
436     ClickOnCancel();
437 }
438
439
440 //=================================================================================
441 // function : ClickOnApply()
442 // purpose  :
443 //=================================================================================
444 bool BasicGUI_PointDlg::ClickOnApply()
445 {
446   if ( !onAccept() )
447     return false;
448
449   initName();
450   ConstructorsClicked( getConstructorId() );
451   return true;
452 }
453
454
455 //=================================================================================
456 // function : SelectionIntoArgument()
457 // purpose  : Called when selection as changed (for constructors not using local context)
458 //=================================================================================
459 void BasicGUI_PointDlg::SelectionIntoArgument()
460 {
461   erasePreview();
462   const int id = getConstructorId();
463
464   if ( ( id == GEOM_POINT_REF || id == GEOM_POINT_EDGE || id == GEOM_POINT_SURF ) && myEditCurrentArgument != 0 )
465   {
466     myEditCurrentArgument->setText( "" );
467     myX->setText( "" );
468     myY->setText( "" );
469     myZ->setText( "" );
470     myRefPoint = myEdge = myFace = GEOM::GEOM_Object::_nil();
471   } else if ( id == GEOM_POINT_INTINT ) {
472     myEditCurrentArgument->setText( "" );
473     if ( myEditCurrentArgument == GroupLineIntersection->LineEdit1 )
474       myLine1 = GEOM::GEOM_Object::_nil();
475     else if ( myEditCurrentArgument == GroupLineIntersection->LineEdit2 )
476       myLine2 = GEOM::GEOM_Object::_nil();
477   }
478
479   LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
480   SALOME_ListIO aSelList;
481   aSelMgr->selectedObjects(aSelList);
482
483   if (aSelList.Extent() == 1) {
484     Standard_Boolean aRes = Standard_False;
485     Handle(SALOME_InteractiveObject) anIO = aSelList.First();
486     GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( anIO, aRes );
487     if ( !CORBA::is_nil( aSelectedObject ) && aRes ) {
488       QString aName = GEOMBase::GetName(aSelectedObject);
489       TopoDS_Shape aShape;
490       if ( GEOMBase::GetShape( aSelectedObject, aShape, TopAbs_SHAPE ) && !aShape.IsNull() ) {
491         if ( id == GEOM_POINT_XYZ || id == GEOM_POINT_REF)
492           myNeedType = TopAbs_VERTEX;
493         else if ( id == GEOM_POINT_EDGE )
494           myNeedType = TopAbs_EDGE;
495         else if ( id == GEOM_POINT_SURF )
496           myNeedType = TopAbs_FACE;
497
498         TColStd_IndexedMapOfInteger aMap;
499         aSelMgr->GetIndexes(anIO, aMap);
500         if ( aMap.Extent() == 1 ) { // Local Selection
501           int anIndex = aMap( 1 );
502           if ( myNeedType == TopAbs_FACE )
503             aName += QString( ":face_%1" ).arg( anIndex );
504           else if ( myNeedType == TopAbs_WIRE )
505             aName += QString( ":wire_%1" ).arg( anIndex );
506           else if ( myNeedType == TopAbs_EDGE )
507             aName += QString( ":edge_%1" ).arg( anIndex );
508           else  if ( myNeedType == TopAbs_VERTEX )
509             aName += QString( ":vertex_%1" ).arg( anIndex );
510
511           //Find SubShape Object in Father
512           GEOM::GEOM_Object_var aFindedObject = GEOMBase_Helper::findObjectInFather(aSelectedObject, aName);
513
514           if ( aFindedObject == GEOM::GEOM_Object::_nil() ) { // Object not found in study
515             GEOM::GEOM_IShapesOperations_var aShapesOp =
516               getGeomEngine()->GetIShapesOperations(getStudyId());
517             aSelectedObject = aShapesOp->GetSubShape(aSelectedObject, anIndex);
518           }
519           else {
520             aSelectedObject = aFindedObject; // get Object from study
521           }
522           GEOMBase::GetShape( aSelectedObject, aShape, TopAbs_SHAPE );
523         }
524         else { // Global Selection
525           if ( aShape.ShapeType() != myNeedType ) {
526             aSelectedObject = GEOM::GEOM_Object::_nil();
527             aName = "";
528             if ( id == GEOM_POINT_XYZ ) return;
529           }
530         }
531       }
532
533       if ( aShape.IsNull() || aShape.ShapeType() != myNeedType)
534         return;
535
536       if ( id == GEOM_POINT_XYZ ) {
537         gp_Pnt aPnt = BRep_Tool::Pnt( TopoDS::Vertex( aShape ) );
538         GroupXYZ->SpinBox_DX->setValue( aPnt.X() );
539         GroupXYZ->SpinBox_DY->setValue( aPnt.Y() );
540         GroupXYZ->SpinBox_DZ->setValue( aPnt.Z() );
541       }
542       else if ( id == GEOM_POINT_REF ) {
543         myRefPoint = aSelectedObject;
544         GroupRefPoint->LineEdit1->setText( aName );
545       }
546       else if ( id == GEOM_POINT_EDGE ) {
547         myEdge = aSelectedObject;
548         GroupOnCurve->LineEdit1->setText( aName );
549       }
550       else if ( id == GEOM_POINT_INTINT ) {
551         myEditCurrentArgument->setText( aName );
552         if ( myEditCurrentArgument == GroupLineIntersection->LineEdit1 ) {
553           myLine1 = aSelectedObject;
554           if ( !myLine1->_is_nil() && myLine2->_is_nil() ) {
555             GroupLineIntersection->PushButton2->setMenu( 0 );
556             GroupLineIntersection->PushButton2->click();
557             GroupLineIntersection->PushButton2->setDown(true);
558             GroupLineIntersection->PushButton2->setMenu( myBtnPopup );
559           }
560         }
561         else if ( myEditCurrentArgument == GroupLineIntersection->LineEdit2 ) {
562           myLine2 = aSelectedObject;
563           if ( !myLine2->_is_nil() && myLine1->_is_nil() ) {
564             GroupLineIntersection->PushButton1->setMenu( 0 );
565             GroupLineIntersection->PushButton1->click();
566             GroupLineIntersection->PushButton1->setDown(true);
567             GroupLineIntersection->PushButton1->setMenu( myBtnPopup );
568           }
569         }
570       }
571       else if ( id == GEOM_POINT_SURF )
572       {
573         myFace = aSelectedObject;
574         GroupOnSurface->LineEdit1->setText( aName );
575       }
576     }
577   }
578
579   displayPreview();
580 }
581
582
583 //=================================================================================
584 // function : LineEditReturnPressed()
585 // purpose  :
586 //=================================================================================
587 void BasicGUI_PointDlg::LineEditReturnPressed()
588 {
589   QLineEdit* send = (QLineEdit*)sender();
590   if ( send == GroupRefPoint->LineEdit1         ||
591        send == GroupOnCurve->LineEdit1          ||
592        send == GroupLineIntersection->LineEdit1 ||
593        send == GroupLineIntersection->LineEdit2  ) {
594     myEditCurrentArgument = send;
595     GEOMBase_Skeleton::LineEditReturnPressed();
596   }
597 }
598
599
600 //=================================================================================
601 // function : SetEditCurrentArgument()
602 // purpose  :
603 //=================================================================================
604 void BasicGUI_PointDlg::SetEditCurrentArgument()
605 {
606   QPushButton* send = (QPushButton*)sender();
607
608   if ( send == GroupRefPoint->PushButton1 ) {
609     GroupRefPoint->LineEdit1->setFocus();
610     myEditCurrentArgument = GroupRefPoint->LineEdit1;
611     globalSelection(); // close local contexts, if any
612     localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
613   }
614   else if ( send == GroupOnCurve->PushButton1 ) {
615     GroupOnCurve->LineEdit1->setFocus();
616     myEditCurrentArgument = GroupOnCurve->LineEdit1;
617     globalSelection(); // close local contexts, if any
618     localSelection( GEOM::GEOM_Object::_nil(), TopAbs_EDGE );
619   }
620   else if ( send == GroupOnSurface->PushButton1 )
621   {
622     GroupOnSurface->LineEdit1->setFocus();
623     myEditCurrentArgument = GroupOnSurface->LineEdit1;
624     globalSelection(); // close local contexts, if any
625     localSelection( GEOM::GEOM_Object::_nil(), TopAbs_FACE );
626   }
627   else if ( send == GroupLineIntersection->PushButton1 ) {
628     GroupLineIntersection->LineEdit1->setFocus();
629     myEditCurrentArgument = GroupLineIntersection->LineEdit1;
630     GroupLineIntersection->PushButton2->setDown( false );
631     GroupLineIntersection->LineEdit1->setEnabled(true);
632     GroupLineIntersection->LineEdit2->setEnabled(false);
633   }
634   else if ( send == GroupLineIntersection->PushButton2 ) {
635     GroupLineIntersection->LineEdit2->setFocus();
636     myEditCurrentArgument = GroupLineIntersection->LineEdit2;
637     GroupLineIntersection->PushButton1->setDown( false );
638     GroupLineIntersection->LineEdit1->setEnabled(false);
639     GroupLineIntersection->LineEdit2->setEnabled(true);
640   }
641   send->setDown(true);
642 }
643
644
645 //=================================================================================
646 // function : enterEvent()
647 // purpose  : to reactivate this dialog box when mouse enter onto the window
648 //=================================================================================
649 void BasicGUI_PointDlg::enterEvent( QEvent* )
650 {
651   if ( !mainFrame()->GroupConstructors->isEnabled() )
652     ActivateThisDialog();
653 }
654
655
656 //=================================================================================
657 // function : ActivateThisDialog()
658 // purpose  :
659 //=================================================================================
660 void BasicGUI_PointDlg::ActivateThisDialog( )
661 {
662   GEOMBase_Skeleton::ActivateThisDialog();
663
664   connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
665            this, SLOT( SelectionIntoArgument() ) );
666
667   ConstructorsClicked( getConstructorId() );
668 }
669
670
671 //=================================================================================
672 // function : DeactivateActiveDialog()
673 // purpose  : public slot to deactivate if active
674 //=================================================================================
675 void BasicGUI_PointDlg::DeactivateActiveDialog()
676 {
677   // myGeomGUI->SetState( -1 );
678   GEOMBase_Skeleton::DeactivateActiveDialog();
679 }
680
681
682 //=================================================================================
683 // function : ValueChangedInSpinBox()
684 // purpose  :
685 //=================================================================================
686 void BasicGUI_PointDlg::ValueChangedInSpinBox(double newValue)
687 {
688   displayPreview();
689 }
690
691 //=================================================================================
692 // funcion  : getParameter()
693 // purpose  :
694 //=================================================================================
695 double BasicGUI_PointDlg::getParameter() const
696 {
697   return GroupOnCurve->SpinBox_DX->value();
698 }
699
700
701 //=================================================================================
702 // funcion  : getUParameter()
703 // purpose  :
704 //=================================================================================
705 double BasicGUI_PointDlg::getUParameter() const
706 {
707   return GroupOnSurface->SpinBox_DX->value();
708 }
709
710
711 //=================================================================================
712 // funcion  : getVParameter()
713 // purpose  :
714 //=================================================================================
715 double BasicGUI_PointDlg::getVParameter() const
716 {
717   return GroupOnSurface->SpinBox_DY->value();
718 }
719
720
721 //=================================================================================
722 // function : OnPointSelected
723 // purpose  :
724 //=================================================================================
725 void BasicGUI_PointDlg::OnPointSelected( const gp_Pnt& thePnt )
726 {
727   if ( getConstructorId() == GEOM_POINT_XYZ ) {
728     GroupXYZ->SpinBox_DX->setValue( thePnt.X() );
729     GroupXYZ->SpinBox_DY->setValue( thePnt.Y() );
730     GroupXYZ->SpinBox_DZ->setValue( thePnt.Z() );
731
732     displayPreview();
733   }
734 }
735
736 //=================================================================================
737 // function : createOperation
738 // purpose  :
739 //=================================================================================
740 GEOM::GEOM_IOperations_ptr BasicGUI_PointDlg::createOperation()
741 {
742   return myGeomGUI->GetGeomGen()->GetIBasicOperations( getStudyId() );
743 }
744
745 //=================================================================================
746 // function : isValid
747 // purpose  :
748 //=================================================================================
749 bool BasicGUI_PointDlg::isValid( QString& msg )
750 {
751   const int id = getConstructorId();
752   if ( id == GEOM_POINT_XYZ ) {
753     bool ok = true;
754     ok = GroupXYZ->SpinBox_DX->isValid( msg, !IsPreview() ) && ok;
755     ok = GroupXYZ->SpinBox_DY->isValid( msg, !IsPreview() ) && ok;
756     ok = GroupXYZ->SpinBox_DZ->isValid( msg, !IsPreview() ) && ok;
757     return ok;
758   }
759   else if ( id == GEOM_POINT_REF ) {
760     bool ok = true;
761     ok = GroupRefPoint->SpinBox_DX->isValid( msg, !IsPreview() ) && ok;
762     ok = GroupRefPoint->SpinBox_DY->isValid( msg, !IsPreview() ) && ok;
763     ok = GroupRefPoint->SpinBox_DZ->isValid( msg, !IsPreview() ) && ok;
764
765     return !myRefPoint->_is_nil() && ok;
766   }
767   else if ( id == GEOM_POINT_EDGE ) {
768     bool ok = true;
769     if ( myParamCoord->checkedId() == PARAM_VALUE )
770       ok = GroupOnCurve->SpinBox_DX->isValid( msg, !IsPreview() );
771     else {
772       ok = GroupXYZ->SpinBox_DX->isValid( msg, !IsPreview() ) && ok;
773       ok = GroupXYZ->SpinBox_DY->isValid( msg, !IsPreview() ) && ok;
774       ok = GroupXYZ->SpinBox_DZ->isValid( msg, !IsPreview() ) && ok;
775     }
776     return !myEdge->_is_nil() && ok;
777   }
778   else if ( id == GEOM_POINT_INTINT )
779     return ( !myLine1->_is_nil() && !myLine2->_is_nil() );
780   else if ( id == GEOM_POINT_SURF ) {
781     bool ok = true;
782     if ( myParamCoord->checkedId() == PARAM_VALUE ) {
783       ok = GroupOnSurface->SpinBox_DX->isValid( msg, !IsPreview() ) && ok;
784       ok = GroupOnSurface->SpinBox_DY->isValid( msg, !IsPreview() ) && ok;
785     }
786     else {
787       ok = GroupXYZ->SpinBox_DX->isValid( msg, !IsPreview() ) && ok;
788       ok = GroupXYZ->SpinBox_DY->isValid( msg, !IsPreview() ) && ok;
789       ok = GroupXYZ->SpinBox_DZ->isValid( msg, !IsPreview() ) && ok;
790     }
791     return !myFace->_is_nil() && ok;
792   }
793   return false;
794 }
795
796 //=================================================================================
797 // function : execute
798 // purpose  :
799 //=================================================================================
800 bool BasicGUI_PointDlg::execute( ObjectList& objects )
801 {
802   bool res = false;
803
804   GEOM::GEOM_Object_var anObj;
805   QStringList aParameters;
806
807   GEOM::GEOM_IBasicOperations_var anOper = GEOM::GEOM_IBasicOperations::_narrow( getOperation() );
808
809   switch ( getConstructorId() ) {
810   case GEOM_POINT_XYZ :
811     {
812       double x = GroupXYZ->SpinBox_DX->value();
813       double y = GroupXYZ->SpinBox_DY->value();
814       double z = GroupXYZ->SpinBox_DZ->value();
815
816       aParameters << GroupXYZ->SpinBox_DX->text();
817       aParameters << GroupXYZ->SpinBox_DY->text();
818       aParameters << GroupXYZ->SpinBox_DZ->text();
819
820       anObj = anOper->MakePointXYZ( x, y, z );
821       res = true;
822       break;
823     }
824   case GEOM_POINT_REF :
825     {
826       double dx = GroupRefPoint->SpinBox_DX->value();
827       double dy = GroupRefPoint->SpinBox_DY->value();
828       double dz = GroupRefPoint->SpinBox_DZ->value();
829
830       aParameters << GroupRefPoint->SpinBox_DX->text();
831       aParameters << GroupRefPoint->SpinBox_DY->text();
832       aParameters << GroupRefPoint->SpinBox_DZ->text();
833
834       anObj = anOper->MakePointWithReference( myRefPoint, dx, dy, dz );
835       res = true;
836       break;
837     }
838   case GEOM_POINT_EDGE :
839     {
840       if ( myParamCoord->checkedId() == PARAM_VALUE ) {
841         anObj = anOper->MakePointOnCurve( myEdge, getParameter() );
842         aParameters<<GroupOnCurve->SpinBox_DX->text();
843       } else {
844         double x = GroupXYZ->SpinBox_DX->value();
845         double y = GroupXYZ->SpinBox_DY->value();
846         double z = GroupXYZ->SpinBox_DZ->value();
847
848         aParameters << GroupXYZ->SpinBox_DX->text();
849         aParameters << GroupXYZ->SpinBox_DY->text();
850         aParameters << GroupXYZ->SpinBox_DZ->text();
851
852         anObj = anOper->MakePointOnCurveByCoord( myEdge, x, y, z );
853       }
854       res = true;
855       break;
856     }
857   case GEOM_POINT_INTINT :
858     anObj = anOper->MakePointOnLinesIntersection( myLine1, myLine2 );
859     if ( !anObj->_is_nil() ) {
860       QString aName = getNewObjectName();
861       if ( anObj->GetShapeType() == GEOM::COMPOUND && aName.startsWith("Vertex") )
862         initName( tr( "GEOM_COMPOUND" ) );
863       else if (  anObj->GetShapeType() == GEOM::VERTEX && aName.startsWith("Compound"))
864         initName( tr( "GEOM_VERTEX" ) );
865     }
866     res = true;
867     break;
868   case GEOM_POINT_SURF :
869     {
870       if ( myParamCoord->checkedId() == PARAM_VALUE ) {
871         anObj = anOper->MakePointOnSurface( myFace, getUParameter(), getVParameter() );
872         aParameters<<GroupOnSurface->SpinBox_DX->text();
873         aParameters<<GroupOnSurface->SpinBox_DY->text();
874       } else {
875         double x = GroupXYZ->SpinBox_DX->value();
876         double y = GroupXYZ->SpinBox_DY->value();
877         double z = GroupXYZ->SpinBox_DZ->value();
878
879         aParameters << GroupXYZ->SpinBox_DX->text();
880         aParameters << GroupXYZ->SpinBox_DY->text();
881         aParameters << GroupXYZ->SpinBox_DZ->text();
882
883         anObj = anOper->MakePointOnSurfaceByCoord( myFace, x, y, z );
884       }
885       res = true;
886       break;
887     }
888   }
889
890   const int id = getConstructorId();
891   if(!anObj->_is_nil() && !IsPreview() && (id == GEOM_POINT_XYZ ||
892                                            id == GEOM_POINT_REF ||
893                                            id == GEOM_POINT_EDGE ||
894                                            id == GEOM_POINT_SURF) ) {
895       anObj->SetParameters(aParameters.join(":").toLatin1().constData());
896   }
897
898   if ( id == GEOM_POINT_REF || id == GEOM_POINT_EDGE || id == GEOM_POINT_SURF ) {
899     TopoDS_Shape aShape;
900     if ( GEOMBase::GetShape( anObj, aShape ) && !aShape.IsNull() &&
901          aShape.ShapeType() == TopAbs_VERTEX ) {
902       gp_Pnt aPnt = BRep_Tool::Pnt( TopoDS::Vertex( aShape ) );
903       myX->setText( QString( "%1" ).arg( aPnt.X() ) );
904       myY->setText( QString( "%1" ).arg( aPnt.Y() ) );
905       myZ->setText( QString( "%1" ).arg( aPnt.Z() ) );
906     }
907     else {
908       myX->setText( "" );
909       myY->setText( "" );
910       myZ->setText( "" );
911     }
912   }
913
914   if ( !anObj->_is_nil() ) {
915     objects.push_back( anObj._retn() );
916   }
917
918   return res;
919 }
920
921 //=================================================================================
922 // function : addSubshapeToStudy
923 // purpose  : virtual method to add new SubObjects if local selection
924 //=================================================================================
925 void BasicGUI_PointDlg::addSubshapesToStudy()
926 {
927   QMap<QString, GEOM::GEOM_Object_var> objMap;
928
929   switch ( getConstructorId() ) {
930   case GEOM_POINT_XYZ:
931     break;
932   case GEOM_POINT_REF:
933     objMap[GroupRefPoint->LineEdit1->text()] = myRefPoint;
934     break;
935   case GEOM_POINT_EDGE:
936     objMap[GroupOnCurve->LineEdit1->text()] = myEdge;
937     break;
938   case GEOM_POINT_INTINT:
939     objMap[GroupLineIntersection->LineEdit1->text()] = myLine1;
940     objMap[GroupLineIntersection->LineEdit2->text()] = myLine2;
941     break;
942   case GEOM_POINT_SURF:
943     objMap[GroupOnSurface->LineEdit1->text()] = myFace;
944     break;
945   }
946   addSubshapesToFather( objMap );
947 }
948
949 //=================================================================================
950 // function : ClickParamCoord()
951 // purpose  :
952 //=================================================================================
953 void BasicGUI_PointDlg::ClickParamCoord( int id )
954 {
955   updateParamCoord( true );
956   displayPreview();
957 }
958
959 //=================================================================================
960 // function : updateParamCoord
961 // purpose  :
962 //=================================================================================
963 void BasicGUI_PointDlg::updateParamCoord(bool theIsUpdate)
964 {
965   bool isParam = myParamCoord->checkedId() == PARAM_VALUE;
966
967   const int id = getConstructorId();
968   if ( id == GEOM_POINT_EDGE ) {
969     GroupOnCurve->TextLabel2->setShown( isParam );
970     GroupOnCurve->SpinBox_DX->setShown( isParam );
971   }
972   else if ( id == GEOM_POINT_SURF ) {
973     GroupOnSurface->TextLabel2->setShown( isParam );
974     GroupOnSurface->TextLabel3->setShown( isParam );
975     GroupOnSurface->SpinBox_DX->setShown( isParam );
976     GroupOnSurface->SpinBox_DY->setShown( isParam );
977   }
978
979   GroupXYZ->setShown( !isParam );
980
981   if ( theIsUpdate )
982     QTimer::singleShot(50, this, SLOT(updateSize()));
983 }
984
985 //=================================================================================
986 // function : onBtnPopup()
987 // purpose  :
988 //=================================================================================
989 void BasicGUI_PointDlg::onBtnPopup( QAction* a )
990 {
991   int index = myActions[a];
992   globalSelection(); // close local contexts, if any
993   QString type;
994   if ( index == 0 )
995     myNeedType = TopAbs_EDGE;
996   else 
997     myNeedType = TopAbs_WIRE;
998   
999   localSelection( GEOM::GEOM_Object::_nil(), myNeedType );
1000 }
1001
1002 //=================================================================================
1003 // function : updateSize
1004 // purpose  : adjust dialog size to minimum
1005 //=================================================================================
1006 void BasicGUI_PointDlg::updateSize() 
1007 {
1008   qApp->processEvents();
1009   updateGeometry();
1010   resize( minimumSizeHint() );
1011 }