Salome HOME
Bug 0020228: [CEA 331] the geompy.RemoveExtraEdges crash with the attached brep shape...
[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 <QLabel>
42
43 #include <gp_Pnt.hxx>
44 #include <TopoDS_Shape.hxx>
45 #include <TopAbs_ShapeEnum.hxx>
46 #include <TopoDS.hxx>
47 #include <BRep_Tool.hxx>
48 #include <TopExp.hxx>
49 #include <TColStd_IndexedMapOfInteger.hxx>
50 #include <TopTools_IndexedMapOfShape.hxx>
51
52 //=================================================================================
53 // class    : BasicGUI_PointDlg()
54 // purpose  : Constructs a BasicGUI_PointDlg which is a child of 'parent', with the 
55 //            name 'name' and widget flags set to 'f'.
56 //            The dialog will by default be modeless, unless you set 'modal' to
57 //            TRUE to construct a modal dialog.
58 //=================================================================================
59 BasicGUI_PointDlg::BasicGUI_PointDlg( GeometryGUI* theGeometryGUI, QWidget* parent,
60                                       bool modal, Qt::WindowFlags fl )
61   : GEOMBase_Skeleton( theGeometryGUI, parent, modal, fl )
62 {
63   QPixmap image0( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_POINT") ) );
64   QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_POINT_EDGE" ) ) );
65   QPixmap image2( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
66   QPixmap image3( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_POINT_REF" ) ) );
67   QPixmap image4( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_POINT_LINES") ) );
68   QPixmap image5( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_POINT_FACE" ) ) );
69
70   setWindowTitle( tr( "GEOM_POINT_TITLE" ) );
71
72   /***************************************************************/
73   mainFrame()->GroupConstructors->setTitle( tr( "GEOM_POINTS" ) );
74   mainFrame()->RadioButton1->setIcon( image0 );
75   mainFrame()->RadioButton2->setIcon( image3 );
76   mainFrame()->RadioButton3->setIcon( image1 );
77   mainFrame()->RadioButton4->show();
78   mainFrame()->RadioButton4->setIcon( image4 );
79   mainFrame()->RadioButton5->show();
80   mainFrame()->RadioButton5->setIcon( image5 );
81
82   GroupXYZ = new DlgRef_3Spin( centralWidget() );
83   GroupXYZ->GroupBox1->setTitle( tr( "GEOM_COORDINATES" ) );
84   GroupXYZ->TextLabel1->setText( tr( "GEOM_X" ) );
85   GroupXYZ->TextLabel2->setText( tr( "GEOM_Y" ) );
86   GroupXYZ->TextLabel3->setText( tr( "GEOM_Z" ) );
87
88   GroupOnCurve = new DlgRef_1Sel1Spin( centralWidget() );
89   GroupOnCurve->GroupBox1->setTitle( tr( "GEOM_PARAM_POINT" ) );
90   GroupOnCurve->TextLabel1->setText( tr( "GEOM_EDGE" ) );
91   GroupOnCurve->TextLabel2->setText( tr( "GEOM_PARAMETER" ) );
92   GroupOnCurve->PushButton1->setIcon( image2 );
93
94   GroupOnSurface = new DlgRef_1Sel2Spin( centralWidget() );
95   GroupOnSurface->GroupBox1->setTitle( tr( "GEOM_PARAM_POINT" ) );
96   GroupOnSurface->TextLabel1->setText( tr( "GEOM_FACE" ) );
97   GroupOnSurface->TextLabel2->setText( tr( "GEOM_UPARAMETER" ) );
98   GroupOnSurface->TextLabel3->setText( tr( "GEOM_VPARAMETER" ) );
99   GroupOnSurface->PushButton1->setIcon( image2 );
100
101   GroupRefPoint = new DlgRef_1Sel3Spin( centralWidget() );
102   GroupRefPoint->GroupBox1->setTitle( tr( "GEOM_REF_POINT" ) );
103   GroupRefPoint->TextLabel1->setText( tr( "GEOM_POINT" ) );
104   GroupRefPoint->PushButton1->setIcon( image2 );
105   GroupRefPoint->TextLabel2->setText( tr( "GEOM_DX" ) );
106   GroupRefPoint->TextLabel3->setText( tr( "GEOM_DY" ) );
107   GroupRefPoint->TextLabel4->setText( tr( "GEOM_DZ" ) );
108
109   GroupLineIntersection = new DlgRef_2Sel( centralWidget() );
110   GroupLineIntersection->GroupBox1->setTitle( tr( "GEOM_LINE_INTERSECTION" ) );
111   GroupLineIntersection->TextLabel1->setText( tr( "GEOM_LINE1" ) );
112   GroupLineIntersection->TextLabel2->setText( tr( "GEOM_LINE2" ) );
113   GroupLineIntersection->PushButton1->setIcon( image2 );
114   GroupLineIntersection->PushButton2->setIcon( image2 );
115   GroupLineIntersection->LineEdit2->setEnabled(false);
116
117   myCoordGrp = new QGroupBox( tr( "GEOM_COORDINATES" ), centralWidget() );
118   QGridLayout* myCoordGrpLayout = new QGridLayout( myCoordGrp );
119   myCoordGrpLayout->addWidget( new QLabel( tr( "GEOM_X" ), myCoordGrp ), 0, 0 );
120   myX = new QLineEdit( myCoordGrp );
121   myCoordGrpLayout->addWidget( myX, 0, 1 );
122   myCoordGrpLayout->addWidget( new QLabel( tr( "GEOM_Y" ), myCoordGrp ), 1, 0 );
123   myY = new QLineEdit( myCoordGrp );
124   myCoordGrpLayout->addWidget( myY, 1, 1 );
125   myCoordGrpLayout->addWidget( new QLabel( tr( "GEOM_Z" ), myCoordGrp ), 2, 0 );
126   myZ = new QLineEdit( myCoordGrp );
127   myCoordGrpLayout->addWidget( myZ, 2, 1 );
128
129   QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
130   layout->setMargin( 0 ); layout->setSpacing( 6 );
131   layout->addWidget( GroupXYZ );
132   layout->addWidget( GroupOnCurve );
133   layout->addWidget( GroupOnSurface );
134   layout->addWidget( GroupRefPoint );
135   layout->addWidget( GroupLineIntersection );
136   layout->addWidget( myCoordGrp );
137
138   myX->setReadOnly( true );
139   myY->setReadOnly( true );
140   myZ->setReadOnly( true );
141
142   myX->setEnabled( false );
143   myY->setEnabled( false );
144   myZ->setEnabled( false );
145
146   QPalette aPal = myX->palette();
147   aPal.setColor( QPalette::Disabled, QPalette::Text, QColor( 0, 0, 0 ) ) ;
148   myX->setPalette( aPal );
149   myY->setPalette( aPal );
150   myZ->setPalette( aPal );
151
152   setHelpFileName( "create_point_page.html" );
153  
154   Init();
155 }
156
157
158 //=================================================================================
159 // function : ~BasicGUI_PointDlg()
160 // purpose  : Destructor
161 //=================================================================================
162 BasicGUI_PointDlg::~BasicGUI_PointDlg()
163 {
164 }
165
166
167 //=================================================================================
168 // function : Init()
169 // purpose  :
170 //=================================================================================
171 void BasicGUI_PointDlg::Init()
172 {
173   GroupOnCurve->LineEdit1->setReadOnly( true );
174   GroupOnSurface->LineEdit1->setReadOnly( true );
175   GroupRefPoint->LineEdit1->setReadOnly( true );
176   GroupLineIntersection->LineEdit1->setReadOnly( true );
177   GroupLineIntersection->LineEdit2->setReadOnly( true );
178   GroupLineIntersection->LineEdit1->setEnabled( true );
179   GroupLineIntersection->LineEdit2->setEnabled( false );
180
181   myEdge = GEOM::GEOM_Object::_nil();
182   myRefPoint = GEOM::GEOM_Object::_nil();
183
184   myEditCurrentArgument = 0;
185
186   /* Get setting of step value from file configuration */
187   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
188   double step = resMgr->doubleValue( "Geometry", "SettingsGeomStep", 100 );
189   
190   /* min, max, step and decimals for spin boxes */
191   initSpinBox( GroupXYZ->SpinBox_DX, COORD_MIN, COORD_MAX, step, 6 ); // VSR: TODO: DBL_DIGITS_DISPLAY
192   initSpinBox( GroupXYZ->SpinBox_DY, COORD_MIN, COORD_MAX, step, 6 ); // VSR: TODO: DBL_DIGITS_DISPLAY
193   initSpinBox( GroupXYZ->SpinBox_DZ, COORD_MIN, COORD_MAX, step, 6 ); // VSR: TODO: DBL_DIGITS_DISPLAY
194   GroupXYZ->SpinBox_DX->setValue( 0.0 );
195   GroupXYZ->SpinBox_DY->setValue( 0.0 );
196   GroupXYZ->SpinBox_DZ->setValue( 0.0 );
197
198   initSpinBox( GroupRefPoint->SpinBox_DX, COORD_MIN, COORD_MAX, step, 6 ); // VSR: TODO: DBL_DIGITS_DISPLAY
199   initSpinBox( GroupRefPoint->SpinBox_DY, COORD_MIN, COORD_MAX, step, 6 ); // VSR: TODO: DBL_DIGITS_DISPLAY
200   initSpinBox( GroupRefPoint->SpinBox_DZ, COORD_MIN, COORD_MAX, step, 6 ); // VSR: TODO: DBL_DIGITS_DISPLAY
201   GroupRefPoint->SpinBox_DX->setValue( 0.0 );
202   GroupRefPoint->SpinBox_DY->setValue( 0.0 );
203   GroupRefPoint->SpinBox_DZ->setValue( 0.0 );
204
205   step = 0.1;
206
207   initSpinBox( GroupOnCurve->SpinBox_DX, 0., 1., step, 6 ); // VSR:TODO : DBL_DIGITS_DISPLAY
208   GroupOnCurve->SpinBox_DX->setValue( 0.5 );
209
210   initSpinBox( GroupOnSurface->SpinBox_DX, 0., 1., step, 6 ); // VSR:TODO : DBL_DIGITS_DISPLAY
211   GroupOnSurface->SpinBox_DX->setValue( 0.5 );
212   initSpinBox( GroupOnSurface->SpinBox_DY, 0., 1., step, 6 ); // VSR:TODO : DBL_DIGITS_DISPLAY
213   GroupOnSurface->SpinBox_DY->setValue( 0.5 );
214
215   /* signals and slots connections */
216   connect( myGeomGUI,      SIGNAL( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) );
217   connect( myGeomGUI,      SIGNAL( SignalCloseAllDialogs() ),        this, SLOT( ClickOnCancel() ) );
218
219   connect( buttonOk(),     SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
220   connect( buttonApply(),  SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
221
222   connect( this,           SIGNAL( constructorsClicked( int ) ), this, SLOT( ConstructorsClicked( int ) ) );
223
224   connect( GroupOnCurve->PushButton1, SIGNAL( clicked() ),       this, SLOT( SetEditCurrentArgument() ) );
225   connect( GroupOnCurve->LineEdit1,   SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
226
227   connect( GroupOnSurface->PushButton1, SIGNAL( clicked() ),       this, SLOT( SetEditCurrentArgument() ) );
228   connect( GroupOnSurface->LineEdit1,   SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
229
230   connect( GroupLineIntersection->PushButton1, SIGNAL( clicked() ),       this, SLOT( SetEditCurrentArgument() ) );
231   connect( GroupLineIntersection->PushButton2, SIGNAL( clicked() ),       this, SLOT( SetEditCurrentArgument() ) );
232   connect( GroupLineIntersection->LineEdit1,   SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
233   connect( GroupLineIntersection->LineEdit2,   SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
234
235   connect( GroupOnCurve->SpinBox_DX,   SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
236   connect( GroupOnSurface->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
237   connect( GroupOnSurface->SpinBox_DY, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
238   connect( GroupXYZ->SpinBox_DX,       SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
239   connect( GroupXYZ->SpinBox_DY,       SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
240   connect( GroupXYZ->SpinBox_DZ,       SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
241   connect( GroupRefPoint->SpinBox_DX,  SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
242   connect( GroupRefPoint->SpinBox_DY,  SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
243   connect( GroupRefPoint->SpinBox_DZ,  SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
244
245   connect( myGeomGUI, SIGNAL( SignalDefaultStepValueChanged( double ) ), this,  SLOT( SetDoubleSpinBoxStep( double ) ) );
246
247   connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged() ),
248            this,  SLOT(SelectionIntoArgument() ) );
249
250   
251   initName( tr( "GEOM_VERTEX" ) );
252   
253   ConstructorsClicked( 0 );
254 }
255
256 //=================================================================================
257 // function : SetDoubleSpinBoxStep()
258 // purpose  : Double spin box management
259 //=================================================================================
260 void BasicGUI_PointDlg::SetDoubleSpinBoxStep( double step )
261 {
262   GroupOnCurve->SpinBox_DX->setSingleStep(step);
263   GroupXYZ->SpinBox_DX->setSingleStep(step);
264   GroupXYZ->SpinBox_DY->setSingleStep(step);
265   GroupXYZ->SpinBox_DZ->setSingleStep(step);
266   GroupRefPoint->SpinBox_DX->setSingleStep(step);
267   GroupRefPoint->SpinBox_DY->setSingleStep(step);
268   GroupRefPoint->SpinBox_DZ->setSingleStep(step);
269   GroupOnSurface->SpinBox_DX->setSingleStep(step);
270   GroupOnSurface->SpinBox_DY->setSingleStep(step);
271 }
272
273
274 //=================================================================================
275 // function : ConstructorsClicked()
276 // purpose  : Radio button management
277 //=================================================================================
278 void BasicGUI_PointDlg::ConstructorsClicked(int constructorId)
279 {  
280   globalSelection(); // close local contexts, if any
281
282   switch ( constructorId ) {
283   case 0:
284     {
285       localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
286       
287       GroupRefPoint->hide();
288       GroupOnCurve->hide();
289       GroupLineIntersection->hide();
290       GroupOnSurface->hide();
291
292       myCoordGrp->hide();
293
294       GroupXYZ->show();
295       break;
296     }
297   case 1:
298     {
299       myEditCurrentArgument = GroupRefPoint->LineEdit1;
300       myEditCurrentArgument->setText( "" );
301       myRefPoint = GEOM::GEOM_Object::_nil();
302       GroupRefPoint->PushButton1->setDown(true);      
303       localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
304       
305       GroupXYZ->hide();
306       GroupOnCurve->hide();
307       GroupLineIntersection->hide();
308       GroupOnSurface->hide();
309       
310       GroupRefPoint->show();
311       
312       myCoordGrp->show();
313       break;
314     }
315   case 2:
316     {
317       myEditCurrentArgument = GroupOnCurve->LineEdit1;
318       myEditCurrentArgument->setText( "" );
319       myEdge = GEOM::GEOM_Object::_nil();
320       GroupOnCurve->PushButton1->setDown(true);
321       localSelection( GEOM::GEOM_Object::_nil(), TopAbs_EDGE );
322
323       GroupXYZ->hide();
324       GroupRefPoint->hide();
325       GroupLineIntersection->hide();
326       GroupOnSurface->hide();
327
328       GroupOnCurve->show();
329       
330       myCoordGrp->show();
331       break;
332     }
333   case 3:
334     {
335       myEditCurrentArgument = GroupLineIntersection->LineEdit1;
336       GroupLineIntersection->LineEdit1->setText( "" );
337       GroupLineIntersection->LineEdit2->setText( "" );
338       GroupLineIntersection->LineEdit1->setEnabled( true );
339       GroupLineIntersection->LineEdit2->setEnabled( false );
340       myLine1 = GEOM::GEOM_Object::_nil();
341       myLine2 = GEOM::GEOM_Object::_nil();
342       GroupLineIntersection->PushButton1->setDown(true);
343       GroupLineIntersection->PushButton2->setDown(false);
344
345       localSelection( GEOM::GEOM_Object::_nil(), TopAbs_EDGE );
346
347       GroupXYZ->hide();
348       GroupRefPoint->hide();
349       GroupOnCurve->hide();
350       GroupOnSurface->hide();
351
352       myCoordGrp->hide();
353
354       GroupLineIntersection->show();
355       break;
356     }
357   case 4:
358     {
359       myEditCurrentArgument = GroupOnSurface->LineEdit1;
360       myEditCurrentArgument->setText( "" );
361       myFace = GEOM::GEOM_Object::_nil();
362       GroupOnSurface->PushButton1->setDown(true);
363       localSelection( GEOM::GEOM_Object::_nil(), TopAbs_FACE );
364
365       GroupXYZ->hide();
366       GroupRefPoint->hide();
367       GroupOnCurve->hide();
368       GroupLineIntersection->hide();
369
370       GroupOnSurface->show();
371
372       myCoordGrp->show();
373       break;
374     }
375   }
376
377   myX->setText( "" );
378   myY->setText( "" );
379   myZ->setText( "" );
380
381   qApp->processEvents();
382   updateGeometry();
383   resize( minimumSizeHint() );
384
385   SelectionIntoArgument();
386 }
387
388
389 //=================================================================================
390 // function : ClickOnOk()
391 // purpose  :
392 //=================================================================================
393 void BasicGUI_PointDlg::ClickOnOk()
394 {
395   if ( onAccept() )
396     ClickOnCancel();
397 }
398
399
400 //=================================================================================
401 // function : ClickOnApply()
402 // purpose  :
403 //=================================================================================
404 bool BasicGUI_PointDlg::ClickOnApply()
405 {
406   if ( !onAccept() )
407     return false;
408   
409   initName();
410   ConstructorsClicked( getConstructorId() );
411   return true;
412 }
413
414
415 //=================================================================================
416 // function : SelectionIntoArgument()
417 // purpose  : Called when selection as changed (for constructors not using local context)
418 //=================================================================================
419 void BasicGUI_PointDlg::SelectionIntoArgument()
420 {
421   const int id = getConstructorId();
422
423   if ( ( id == 1 || id == 2 || id == 4 ) && myEditCurrentArgument != 0 )
424   {
425     myEditCurrentArgument->setText( "" );
426     myX->setText( "" );
427     myY->setText( "" );
428     myZ->setText( "" );
429     myRefPoint = myEdge = myFace = GEOM::GEOM_Object::_nil();
430   }
431
432   LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
433   SALOME_ListIO aSelList;
434   aSelMgr->selectedObjects(aSelList);
435
436   if (aSelList.Extent() == 1) {
437     Standard_Boolean aRes = Standard_False;
438     Handle(SALOME_InteractiveObject) anIO = aSelList.First();
439     GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( anIO, aRes );
440     if ( !CORBA::is_nil( aSelectedObject ) && aRes ) {
441       QString aName = GEOMBase::GetName(aSelectedObject);
442       TopAbs_ShapeEnum aNeedType = TopAbs_VERTEX;
443       TopoDS_Shape aShape;
444       if ( GEOMBase::GetShape( aSelectedObject, aShape, TopAbs_SHAPE ) && !aShape.IsNull() ) {
445         if ( id == 2 || id == 3 )
446           aNeedType = TopAbs_EDGE;
447         else if ( id == 4 )
448           aNeedType = TopAbs_FACE;
449
450         TColStd_IndexedMapOfInteger aMap;
451         aSelMgr->GetIndexes(anIO, aMap);
452         if ( aMap.Extent() == 1 ) { // Local Selection
453           int anIndex = aMap( 1 );
454           if ( aNeedType == TopAbs_EDGE )
455             aName += QString( ":edge_%1" ).arg( anIndex );
456           else
457             aName += QString( ":vertex_%1" ).arg( anIndex );
458
459           //Find SubShape Object in Father
460           GEOM::GEOM_Object_var aFindedObject = GEOMBase_Helper::findObjectInFather(aSelectedObject, aName);
461           
462           if ( aFindedObject == GEOM::GEOM_Object::_nil() ) { // Object not found in study
463             GEOM::GEOM_IShapesOperations_var aShapesOp =
464               getGeomEngine()->GetIShapesOperations(getStudyId());
465             aSelectedObject = aShapesOp->GetSubShape(aSelectedObject, anIndex);
466           }
467           else {
468             aSelectedObject = aFindedObject; // get Object from study
469           }
470           GEOMBase::GetShape( aSelectedObject, aShape, TopAbs_SHAPE );
471         }
472         else { // Global Selection
473           if ( aShape.ShapeType() != aNeedType ) {
474             aSelectedObject = GEOM::GEOM_Object::_nil();
475             aName = "";
476             if ( id == 0 ) return;
477           }
478         }
479       }
480
481       if ( aShape.IsNull() || aShape.ShapeType() != aNeedType)
482         return;
483
484       if ( id == 0 ) {
485         gp_Pnt aPnt = BRep_Tool::Pnt( TopoDS::Vertex( aShape ) );
486         GroupXYZ->SpinBox_DX->setValue( aPnt.X() );
487         GroupXYZ->SpinBox_DY->setValue( aPnt.Y() );
488         GroupXYZ->SpinBox_DZ->setValue( aPnt.Z() );
489       }
490       else if ( id == 1 ) {
491         myRefPoint = aSelectedObject;
492         GroupRefPoint->LineEdit1->setText( aName );
493       }
494       else if ( id == 2 ) {
495         myEdge = aSelectedObject;
496         GroupOnCurve->LineEdit1->setText( aName );
497       }
498       else if ( id == 3 ) {
499         myEditCurrentArgument->setText( aName );
500         globalSelection();
501         localSelection( GEOM::GEOM_Object::_nil(), TopAbs_EDGE );
502         if ( myEditCurrentArgument == GroupLineIntersection->LineEdit1 ) {
503           myLine1 = aSelectedObject;
504           if ( !myLine1->_is_nil() && myLine2->_is_nil() )
505             GroupLineIntersection->PushButton2->click();
506         }
507         else if ( myEditCurrentArgument == GroupLineIntersection->LineEdit2 ) {
508           myLine2 = aSelectedObject;
509           if ( !myLine2->_is_nil() && myLine1->_is_nil() )
510             GroupLineIntersection->PushButton1->click();
511         }
512       }
513       else if ( id == 4 )
514       {
515         myFace = aSelectedObject;
516         GroupOnSurface->LineEdit1->setText( aName );
517       }
518     }
519   }
520   
521   displayPreview();
522 }
523
524
525 //=================================================================================
526 // function : LineEditReturnPressed()
527 // purpose  :
528 //=================================================================================
529 void BasicGUI_PointDlg::LineEditReturnPressed()
530 {
531   QLineEdit* send = (QLineEdit*)sender();
532   if ( send == GroupRefPoint->LineEdit1         || 
533        send == GroupOnCurve->LineEdit1          ||
534        send == GroupLineIntersection->LineEdit1 || 
535        send == GroupLineIntersection->LineEdit2  ) {
536     myEditCurrentArgument = send;
537     GEOMBase_Skeleton::LineEditReturnPressed();
538   }
539 }
540
541
542 //=================================================================================
543 // function : SetEditCurrentArgument()
544 // purpose  :
545 //=================================================================================
546 void BasicGUI_PointDlg::SetEditCurrentArgument()
547 {
548   globalSelection(); // close local contexts, if any
549
550   QPushButton* send = (QPushButton*)sender();
551
552   if ( send == GroupRefPoint->PushButton1 ) {
553     GroupRefPoint->LineEdit1->setFocus();
554     myEditCurrentArgument = GroupRefPoint->LineEdit1;
555     
556     localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
557   }
558   else if ( send == GroupOnCurve->PushButton1 ) {
559     GroupOnCurve->LineEdit1->setFocus();
560     myEditCurrentArgument = GroupOnCurve->LineEdit1;
561     
562     localSelection( GEOM::GEOM_Object::_nil(), TopAbs_EDGE );
563   }
564   else if ( send == GroupOnSurface->PushButton1 )
565   {
566     GroupOnSurface->LineEdit1->setFocus();
567     myEditCurrentArgument = GroupOnSurface->LineEdit1;
568
569     localSelection( GEOM::GEOM_Object::_nil(), TopAbs_FACE );
570   }
571   else if ( send == GroupLineIntersection->PushButton1 ) {
572     GroupLineIntersection->LineEdit1->setFocus();
573     myEditCurrentArgument = GroupLineIntersection->LineEdit1;
574     GroupLineIntersection->PushButton2->setDown( false );
575     GroupLineIntersection->LineEdit1->setEnabled(true);
576     GroupLineIntersection->LineEdit2->setEnabled(false);
577     localSelection( GEOM::GEOM_Object::_nil(), TopAbs_EDGE );
578   }
579   else if ( send == GroupLineIntersection->PushButton2 ) {
580     GroupLineIntersection->LineEdit2->setFocus();
581     myEditCurrentArgument = GroupLineIntersection->LineEdit2;
582     GroupLineIntersection->PushButton1->setDown( false );
583     GroupLineIntersection->LineEdit1->setEnabled(false);
584     GroupLineIntersection->LineEdit2->setEnabled(true);
585     localSelection( GEOM::GEOM_Object::_nil(), TopAbs_EDGE );
586   }
587   send->setDown(true);
588 }
589
590
591 //=================================================================================
592 // function : enterEvent()
593 // purpose  : to reactivate this dialog box when mouse enter onto the window
594 //=================================================================================
595 void BasicGUI_PointDlg::enterEvent( QEvent* )
596 {
597   if ( !mainFrame()->GroupConstructors->isEnabled() )
598     ActivateThisDialog();
599 }
600
601
602 //=================================================================================
603 // function : ActivateThisDialog()
604 // purpose  :
605 //=================================================================================
606 void BasicGUI_PointDlg::ActivateThisDialog( )
607 {
608   GEOMBase_Skeleton::ActivateThisDialog();
609   // myGeomGUI->SetState( 0 );
610   ConstructorsClicked( getConstructorId() );
611 }
612
613
614 //=================================================================================
615 // function : DeactivateActiveDialog()
616 // purpose  : public slot to deactivate if active
617 //=================================================================================
618 void BasicGUI_PointDlg::DeactivateActiveDialog()
619 {
620   // myGeomGUI->SetState( -1 );
621   GEOMBase_Skeleton::DeactivateActiveDialog();
622 }
623
624
625 //=================================================================================
626 // function : ValueChangedInSpinBox()
627 // purpose  :
628 //=================================================================================
629 void BasicGUI_PointDlg::ValueChangedInSpinBox(double newValue)
630 {
631   displayPreview();
632 }
633
634 //=================================================================================
635 // funcion  : getParameter()
636 // purpose  :
637 //=================================================================================
638 double BasicGUI_PointDlg::getParameter() const
639 {
640   return GroupOnCurve->SpinBox_DX->value();
641 }
642
643
644 //=================================================================================
645 // funcion  : getUParameter()
646 // purpose  :
647 //=================================================================================
648 double BasicGUI_PointDlg::getUParameter() const
649 {
650   return GroupOnSurface->SpinBox_DX->value();
651 }
652
653
654 //=================================================================================
655 // funcion  : getVParameter()
656 // purpose  :
657 //=================================================================================
658 double BasicGUI_PointDlg::getVParameter() const
659 {
660   return GroupOnSurface->SpinBox_DY->value();
661 }
662
663
664 //=================================================================================
665 // function : OnPointSelected
666 // purpose  :
667 //=================================================================================
668 void BasicGUI_PointDlg::OnPointSelected( const gp_Pnt& thePnt )
669 {
670   if ( getConstructorId() == 0 ) {
671     GroupXYZ->SpinBox_DX->setValue( thePnt.X() );
672     GroupXYZ->SpinBox_DY->setValue( thePnt.Y() );
673     GroupXYZ->SpinBox_DZ->setValue( thePnt.Z() );
674
675     displayPreview();
676   }
677 }
678
679 //=================================================================================
680 // function : createOperation
681 // purpose  :
682 //=================================================================================
683 GEOM::GEOM_IOperations_ptr BasicGUI_PointDlg::createOperation()
684 {
685   return myGeomGUI->GetGeomGen()->GetIBasicOperations( getStudyId() );
686 }
687
688 //=================================================================================
689 // function : isValid
690 // purpose  :
691 //=================================================================================
692 bool BasicGUI_PointDlg::isValid( QString& msg )
693 {
694   const int id = getConstructorId();
695   if ( id == 0 ) {
696     bool ok = true;
697     ok = GroupXYZ->SpinBox_DX->isValid( msg, !IsPreview() ) && ok;
698     ok = GroupXYZ->SpinBox_DY->isValid( msg, !IsPreview() ) && ok;
699     ok = GroupXYZ->SpinBox_DZ->isValid( msg, !IsPreview() ) && ok;
700     return ok;
701   }
702   else if ( id == 1 ) {
703     bool ok = true;
704     ok = GroupRefPoint->SpinBox_DX->isValid( msg, !IsPreview() ) && ok;
705     ok = GroupRefPoint->SpinBox_DY->isValid( msg, !IsPreview() ) && ok;
706     ok = GroupRefPoint->SpinBox_DZ->isValid( msg, !IsPreview() ) && ok;
707
708     return !myRefPoint->_is_nil() && ok;
709   }
710   else if ( id == 2 ) {
711     bool ok = GroupOnCurve->SpinBox_DX->isValid( msg, !IsPreview() );
712     return !myEdge->_is_nil() && ok;
713   }
714   else if ( id == 3 )
715     return ( !myLine1->_is_nil() && !myLine2->_is_nil() );
716   else if ( id == 4 ) {
717     bool ok = true;
718     ok = GroupOnSurface->SpinBox_DX->isValid( msg, !IsPreview() ) && ok;
719     ok = GroupOnSurface->SpinBox_DY->isValid( msg, !IsPreview() ) && ok;
720     return !myFace->_is_nil() && ok;
721     
722   }
723   return false;
724 }
725
726 //=================================================================================
727 // function : execute
728 // purpose  :
729 //=================================================================================
730 bool BasicGUI_PointDlg::execute( ObjectList& objects )
731 {
732   bool res = false;
733
734   GEOM::GEOM_Object_var anObj;
735   QStringList aParameters;
736
737   switch ( getConstructorId() ) {
738   case 0 :
739     {
740       double x = GroupXYZ->SpinBox_DX->value();
741       double y = GroupXYZ->SpinBox_DY->value();
742       double z = GroupXYZ->SpinBox_DZ->value();
743
744       aParameters << GroupXYZ->SpinBox_DX->text();
745       aParameters << GroupXYZ->SpinBox_DY->text();
746       aParameters << GroupXYZ->SpinBox_DZ->text();
747       
748       anObj = GEOM::GEOM_IBasicOperations::_narrow( getOperation() )->MakePointXYZ( x, y, z );
749       res = true;
750       break;
751     }
752   case 1 :
753     {
754       double dx = GroupRefPoint->SpinBox_DX->value();
755       double dy = GroupRefPoint->SpinBox_DY->value();
756       double dz = GroupRefPoint->SpinBox_DZ->value();
757
758       aParameters << GroupRefPoint->SpinBox_DX->text();
759       aParameters << GroupRefPoint->SpinBox_DY->text();
760       aParameters << GroupRefPoint->SpinBox_DZ->text();
761       
762       anObj = GEOM::GEOM_IBasicOperations::_narrow( getOperation() )->
763         MakePointWithReference( myRefPoint, dx, dy, dz );
764       res = true;
765       break;
766     }
767   case 2 :
768     anObj = GEOM::GEOM_IBasicOperations::_narrow( getOperation() )->
769       MakePointOnCurve( myEdge, getParameter() );
770     aParameters<<GroupOnCurve->SpinBox_DX->text();
771     res = true;
772     break;
773   case 3 :
774     anObj = GEOM::GEOM_IBasicOperations::_narrow( getOperation() )->
775       MakePointOnLinesIntersection( myLine1, myLine2 );
776     res = true;
777     break;
778   case 4 :
779     anObj = GEOM::GEOM_IBasicOperations::_narrow( getOperation() )->
780       MakePointOnSurface( myFace, getUParameter(), getVParameter() );
781     aParameters<<GroupOnSurface->SpinBox_DX->text();
782     aParameters<<GroupOnSurface->SpinBox_DY->text();
783     res = true;
784     break;
785   }
786   
787   if(!anObj->_is_nil() && !IsPreview() && (getConstructorId()==0 || 
788                                            getConstructorId() == 1 ||
789                                            getConstructorId() == 2 ||
790                                            getConstructorId() == 4) ) {
791     anObj->SetParameters(GeometryGUI::JoinObjectParameters(aParameters));
792   }
793   
794
795   if ( getConstructorId() == 1 || getConstructorId() == 2 ||
796        getConstructorId() == 4 ) {
797     TopoDS_Shape aShape;
798     if ( GEOMBase::GetShape( anObj, aShape ) && !aShape.IsNull() &&
799          aShape.ShapeType() == TopAbs_VERTEX ) {
800       gp_Pnt aPnt = BRep_Tool::Pnt( TopoDS::Vertex( aShape ) );
801       myX->setText( QString( "%1" ).arg( aPnt.X() ) );
802       myY->setText( QString( "%1" ).arg( aPnt.Y() ) );
803       myZ->setText( QString( "%1" ).arg( aPnt.Z() ) );
804     }
805     else {
806       myX->setText( "" );
807       myY->setText( "" );
808       myZ->setText( "" );
809     }
810   }
811   
812   if ( !anObj->_is_nil() ) {
813     objects.push_back( anObj._retn() );
814   }
815   
816   return res;
817 }
818
819 //=================================================================================
820 // function : addSubshapeToStudy
821 // purpose  : virtual method to add new SubObjects if local selection
822 //=================================================================================
823 void BasicGUI_PointDlg::addSubshapesToStudy()
824 {
825   QMap<QString, GEOM::GEOM_Object_var> objMap;
826
827   switch ( getConstructorId() ) {
828   case 0:
829     break;
830   case 1:
831     objMap[GroupRefPoint->LineEdit1->text()] = myRefPoint;
832     break;
833   case 2:
834     objMap[GroupOnCurve->LineEdit1->text()] = myEdge;
835     break;
836   case 3:
837     objMap[GroupLineIntersection->LineEdit1->text()] = myLine1;
838     objMap[GroupLineIntersection->LineEdit2->text()] = myLine2;
839     break;
840   case 4:
841     objMap[GroupOnSurface->LineEdit1->text()] = myFace;
842     break;
843   }
844   addSubshapesToFather( objMap );
845 }