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