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