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