Salome HOME
Update copyright information
[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
64   setWindowTitle( tr( "GEOM_PLANE_TITLE" ) );
65
66   /***************************************************************/
67   mainFrame()->GroupConstructors->setTitle( tr( "GEOM_PLANE" ) );
68   mainFrame()->RadioButton1->setIcon( image0 );
69   mainFrame()->RadioButton2->setIcon( image1 );
70   mainFrame()->RadioButton3->setIcon( image2 );
71
72   GroupPntDir = new DlgRef_2Sel1Spin( centralWidget() );
73   GroupPntDir->GroupBox1->setTitle( tr( "GEOM_PLANE_PV" ) );
74   GroupPntDir->TextLabel1->setText( tr( "GEOM_POINT" ) );
75   GroupPntDir->TextLabel2->setText( tr( "GEOM_VECTOR" ) );
76   GroupPntDir->TextLabel3->setText( tr( "GEOM_PLANE_SIZE" ) );
77   GroupPntDir->PushButton1->setIcon( image3 );
78   GroupPntDir->PushButton2->setIcon( image3 );
79   GroupPntDir->LineEdit1->setReadOnly( true );
80   GroupPntDir->LineEdit2->setReadOnly( true );
81   GroupPntDir->PushButton1->setDown( true );
82   GroupPntDir->LineEdit1->setEnabled( true );
83   GroupPntDir->LineEdit2->setEnabled( false );
84
85   Group3Pnts = new DlgRef_3Sel1Spin( centralWidget() );
86   Group3Pnts->GroupBox1->setTitle( tr( "GEOM_3_POINTS" ) );
87   Group3Pnts->TextLabel1->setText( tr( "GEOM_POINT1" ) );
88   Group3Pnts->TextLabel2->setText( tr( "GEOM_POINT2" ) );
89   Group3Pnts->TextLabel3->setText( tr( "GEOM_POINT3" ) );
90   Group3Pnts->TextLabel4->setText( tr( "GEOM_PLANE_SIZE" ) );
91   Group3Pnts->PushButton1->setIcon( image3 );
92   Group3Pnts->PushButton2->setIcon( image3 );
93   Group3Pnts->PushButton3->setIcon( image3 );
94   Group3Pnts->PushButton1->setDown( true );
95
96   Group3Pnts->LineEdit1->setReadOnly( true );
97   Group3Pnts->LineEdit2->setReadOnly( true );
98   Group3Pnts->LineEdit3->setReadOnly( true );
99   Group3Pnts->LineEdit1->setEnabled( true );
100   Group3Pnts->LineEdit2->setEnabled( false );
101   Group3Pnts->LineEdit3->setEnabled( false );
102
103   GroupFace = new DlgRef_3Radio1Sel1Spin( centralWidget() );
104   GroupFace->RadioButton1->setText(tr("GEOM_FACE"));
105   GroupFace->RadioButton2->setText(tr("GEOM_LCS"));
106   GroupFace->RadioButton3->setAttribute( Qt::WA_DeleteOnClose );
107   GroupFace->RadioButton3->close();
108   GroupFace->GroupBox1->setTitle( tr( "GEOM_FACE_OR_LCS" ) );
109   GroupFace->TextLabel1->setText( tr( "GEOM_SELECTION" ) );
110   GroupFace->TextLabel2->setText( tr( "GEOM_PLANE_SIZE" ) );
111   GroupFace->PushButton1->setIcon( image3 );
112   GroupFace->PushButton1->setDown( true );
113
114   GroupFace->LineEdit1->setReadOnly( true );
115
116   QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
117   layout->setMargin( 0 ); layout->setSpacing( 6 );
118   layout->addWidget( GroupPntDir );
119   layout->addWidget( Group3Pnts );
120   layout->addWidget( GroupFace );
121   /***************************************************************/
122
123   setHelpFileName( "create_plane_page.html" );
124
125   Init();
126 }
127
128
129 //=================================================================================
130 // function : ~BasicGUI_PlaneDlg()
131 // purpose  : Destroys the object and frees any allocated resources
132 //=================================================================================
133 BasicGUI_PlaneDlg::~BasicGUI_PlaneDlg()
134 {
135 }
136
137
138 //=================================================================================
139 // function : Init()
140 // purpose  :
141 //=================================================================================
142 void BasicGUI_PlaneDlg::Init()
143 {
144   /* init variables */
145   myEditCurrentArgument = GroupPntDir->LineEdit1;
146   GroupFace->RadioButton1->setChecked(true);
147
148   myPoint = myDir = myPoint1 = myPoint2 = myPoint3 = myFace = GEOM::GEOM_Object::_nil();
149
150   // myGeomGUI->SetState( 0 );
151
152   /* Get setting of step value from file configuration */
153   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
154   double aStep = resMgr->doubleValue( "Geometry", "SettingsGeomStep", 100 );
155
156   double aTrimSize = 2000.0;
157
158   /* min, max, step and decimals for spin boxes */
159   initSpinBox( GroupPntDir->SpinBox_DX, 0.000001, COORD_MAX, aStep, 6 ); // VSR: TODO: DBL_DIGITS_DISPLAY
160   GroupPntDir->SpinBox_DX->setValue( aTrimSize );
161   initSpinBox( Group3Pnts->SpinBox_DX, 0.000001, COORD_MAX, aStep, 6 ); // VSR: TODO: DBL_DIGITS_DISPLAY
162   Group3Pnts->SpinBox_DX->setValue( aTrimSize );
163   initSpinBox( GroupFace->SpinBox_DX, 0.000001, COORD_MAX, aStep, 6 ); // VSR: TODO: DBL_DIGITS_DISPLAY
164   GroupFace->SpinBox_DX->setValue( aTrimSize );
165
166   /* signals and slots connections */
167   connect( myGeomGUI, SIGNAL( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) );
168   connect( myGeomGUI, SIGNAL( SignalCloseAllDialogs() ),        this, SLOT( ClickOnCancel() ) );
169
170   connect( buttonOk(),     SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
171   connect( buttonApply(),  SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
172
173   connect( this,           SIGNAL( constructorsClicked( int ) ), this, SLOT( ConstructorsClicked( int ) ) );
174
175   connect( GroupPntDir->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
176   connect( GroupPntDir->PushButton2, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
177   connect( Group3Pnts->PushButton1,  SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
178   connect( Group3Pnts->PushButton2,  SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
179   connect( Group3Pnts->PushButton3,  SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
180   connect( GroupFace->PushButton1,   SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
181
182   connect( GroupPntDir->LineEdit1, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
183   connect( GroupPntDir->LineEdit2, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
184   connect( Group3Pnts->LineEdit1,  SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
185   connect( Group3Pnts->LineEdit2,  SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
186   connect( Group3Pnts->LineEdit3,  SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
187   connect( GroupFace->LineEdit1,   SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
188   connect( GroupFace->RadioButton1,SIGNAL( clicked() ), this, SLOT( SelectionTypeClicked() ) );
189   connect( GroupFace->RadioButton2,SIGNAL( clicked() ), this, SLOT( SelectionTypeClicked() ) );
190
191   connect( GroupPntDir->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
192   connect( Group3Pnts->SpinBox_DX,  SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
193   connect( GroupFace->SpinBox_DX,   SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
194
195   connect( myGeomGUI, SIGNAL( SignalDefaultStepValueChanged( double ) ), this, SLOT( SetDoubleSpinBoxStep( double ) ) );
196
197   connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
198
199   initName( tr( "GEOM_PLANE" ) );
200
201   ConstructorsClicked( 0 );
202 }
203
204 //=================================================================================
205 // function : SetDoubleSpinBoxStep()
206 // purpose  : Double spin box management
207 //=================================================================================
208 void BasicGUI_PlaneDlg::SetDoubleSpinBoxStep( double step )
209 {
210   GroupPntDir->SpinBox_DX->setSingleStep(step);
211   Group3Pnts->SpinBox_DX->setSingleStep(step);
212   GroupFace->SpinBox_DX->setSingleStep(step);
213 }
214
215 //=================================================================================
216 // function : SelectionTypeClicked()
217 // purpose  : Selection type radio buttons managment
218 //=================================================================================
219 void BasicGUI_PlaneDlg::SelectionTypeClicked()
220 {
221   myFace   = GEOM::GEOM_Object::_nil();
222   if ( GroupFace->RadioButton1->isChecked()) {
223     globalSelection(); // close local contexts, if any
224     localSelection( GEOM::GEOM_Object::_nil(), TopAbs_FACE );
225   } else if ( GroupFace->RadioButton2->isChecked()) {
226     TColStd_MapOfInteger aMap;
227     aMap.Add( GEOM_PLANE );
228     aMap.Add( GEOM_MARKER );
229     globalSelection( aMap );
230   }
231   displayPreview();
232 }
233
234
235 //=================================================================================
236 // function : ConstructorsClicked()
237 // purpose  : Radio button management
238 //=================================================================================
239 void BasicGUI_PlaneDlg::ConstructorsClicked( int constructorId )
240 {
241   disconnect( myGeomGUI->getApp()->selectionMgr(), 0, this, 0 );
242   myPoint = myDir = myPoint1 = myPoint2 = myPoint3 = myFace = GEOM::GEOM_Object::_nil();
243
244   switch ( constructorId ) {
245   case 0: /* plane from a point and a direction (vector, edge...) */
246     {
247       Group3Pnts->hide();
248       GroupFace->hide();
249       GroupPntDir->show();
250       
251       myEditCurrentArgument = GroupPntDir->LineEdit1;
252       GroupPntDir->LineEdit1->setText( "" );
253       GroupPntDir->LineEdit2->setText( "" );
254       GroupPntDir->PushButton1->setDown( true );
255       GroupPntDir->PushButton2->setDown( false );
256       GroupPntDir->LineEdit1->setEnabled( true );
257       GroupPntDir->LineEdit2->setEnabled( false );
258       
259       /* for the first argument */
260       globalSelection(); // close local contexts, if any
261       localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
262       break;
263     }
264   case 1: /* plane from 3 points */
265     {
266       GroupPntDir->hide();
267       GroupFace->hide();
268       Group3Pnts->show();
269       
270       myEditCurrentArgument = Group3Pnts->LineEdit1;
271       Group3Pnts->LineEdit1->setText( "" );
272       Group3Pnts->LineEdit2->setText( "" );
273       Group3Pnts->LineEdit3->setText( "" );
274       Group3Pnts->PushButton1->setDown( true );
275       Group3Pnts->PushButton2->setDown( false );
276       Group3Pnts->PushButton3->setDown( false );
277       Group3Pnts->LineEdit1->setEnabled( true );
278       Group3Pnts->LineEdit2->setEnabled( false );
279       Group3Pnts->LineEdit3->setEnabled( false );
280       
281       /* for the first argument */
282       globalSelection(); // close local contexts, if any
283       localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
284       break;
285     }
286   case 2: /* plane from a planar face or LSC selection */
287     {
288       GroupPntDir->hide();
289       Group3Pnts->hide();
290       GroupFace->show();
291       
292       myEditCurrentArgument = GroupFace->LineEdit1;
293       GroupFace->LineEdit1->setText( "" );
294       GroupFace->PushButton1->setDown( true );
295       
296       if ( GroupFace->RadioButton1->isChecked()) {
297         globalSelection(); // close local contexts, if any
298         localSelection( GEOM::GEOM_Object::_nil(), TopAbs_FACE );
299       } else if ( GroupFace->RadioButton2->isChecked()) {
300         TColStd_MapOfInteger aMap;
301         aMap.Add( GEOM_PLANE );
302         aMap.Add( GEOM_MARKER );
303         globalSelection( aMap );
304       }
305       break;
306     }
307   }
308   
309   qApp->processEvents();
310   updateGeometry();
311   resize( minimumSize() );
312
313   myEditCurrentArgument->setFocus();
314   connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
315            this, SLOT( SelectionIntoArgument() ) );
316 }
317
318
319 //=================================================================================
320 // function : ClickOnOk()
321 // purpose  :
322 //=================================================================================
323 void BasicGUI_PlaneDlg::ClickOnOk()
324 {
325   if ( ClickOnApply() )
326     ClickOnCancel();
327 }
328
329
330 //=================================================================================
331 // function : ClickOnApply()
332 // purpose  :
333 //=================================================================================
334 bool BasicGUI_PlaneDlg::ClickOnApply()
335 {
336   if ( !onAccept() )
337     return false;
338
339   initName();
340   ConstructorsClicked( getConstructorId() );
341   return true;
342 }
343
344 //=================================================================================
345 // function : SelectionIntoArgument()
346 // purpose  : Called when selection has changed
347 //=================================================================================
348 void BasicGUI_PlaneDlg::SelectionIntoArgument()
349 {
350   myEditCurrentArgument->setText("");
351
352   LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
353   SALOME_ListIO aSelList;
354   aSelMgr->selectedObjects(aSelList);
355
356   if (aSelList.Extent() != 1) {
357     if      ( myEditCurrentArgument == GroupPntDir->LineEdit1 ) myPoint  = GEOM::GEOM_Object::_nil();
358     else if ( myEditCurrentArgument == GroupPntDir->LineEdit2 ) myDir    = GEOM::GEOM_Object::_nil();
359     else if ( myEditCurrentArgument == Group3Pnts->LineEdit1 )  myPoint1 = GEOM::GEOM_Object::_nil();
360     else if ( myEditCurrentArgument == Group3Pnts->LineEdit2 )  myPoint2 = GEOM::GEOM_Object::_nil();
361     else if ( myEditCurrentArgument == Group3Pnts->LineEdit3 )  myPoint3 = GEOM::GEOM_Object::_nil();
362     else if ( myEditCurrentArgument == GroupFace->LineEdit1 )   myFace   = GEOM::GEOM_Object::_nil();
363     return;
364   }
365
366   // nbSel == 1
367   Standard_Boolean aRes = Standard_False;
368   GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject(aSelList.First(), aRes);
369   if ( !CORBA::is_nil( aSelectedObject ) && aRes ) {
370     QString aName = GEOMBase::GetName( aSelectedObject );
371     TopAbs_ShapeEnum aNeedType = TopAbs_VERTEX;
372     if ( myEditCurrentArgument == GroupPntDir->LineEdit2 )
373       aNeedType = TopAbs_EDGE;
374     else if ( myEditCurrentArgument == GroupFace->LineEdit1 )
375       aNeedType = TopAbs_FACE;
376
377     TopoDS_Shape aShape;
378     if ( GEOMBase::GetShape( aSelectedObject, aShape, TopAbs_SHAPE ) && !aShape.IsNull() ) {
379       TColStd_IndexedMapOfInteger aMap;
380       aSelMgr->GetIndexes(aSelList.First(), aMap);
381       if ( aMap.Extent() == 1 ) { // Local Selection
382         int anIndex = aMap( 1 );
383         if ( aNeedType == TopAbs_EDGE )
384           aName += QString( ":edge_%1" ).arg( anIndex );
385         else if (aNeedType == TopAbs_FACE)
386           aName += QString( ":face_%1" ).arg( anIndex );
387         else
388           aName += QString( ":vertex_%1" ).arg( anIndex );
389
390         //Find SubShape Object in Father
391         GEOM::GEOM_Object_var aFindedObject = GEOMBase_Helper::findObjectInFather( aSelectedObject, aName );
392
393         if ( aFindedObject == GEOM::GEOM_Object::_nil() ) { // Object not found in study
394           GEOM::GEOM_IShapesOperations_var aShapesOp = getGeomEngine()->GetIShapesOperations( getStudyId() );
395           aSelectedObject = aShapesOp->GetSubShape( aSelectedObject, anIndex );
396         } 
397         else {
398           aSelectedObject = aFindedObject; // get Object from study
399         }
400       }
401       else { // Global Selection
402         if ( aShape.ShapeType() != aNeedType ) {
403           aSelectedObject = GEOM::GEOM_Object::_nil();
404           aName = "";
405         }
406       }
407     }
408
409     myEditCurrentArgument->setText( aName );
410
411     /*    if (!aSelectedObject->_is_nil()) { // clear selection if something selected
412       globalSelection();
413       if ( myEditCurrentArgument == GroupFace->LineEdit1 ) {
414         TColStd_MapOfInteger aMap;
415         aMap.Add( GEOM_PLANE );
416         aMap.Add( GEOM_MARKER );
417         globalSelection( aMap );
418       }
419       else
420         localSelection( GEOM::GEOM_Object::_nil(), aNeedType );
421         }*/
422
423     if      ( myEditCurrentArgument == GroupPntDir->LineEdit1 ) {
424       myPoint  = aSelectedObject;
425       if ( !myPoint->_is_nil() && myDir->_is_nil() )
426         GroupPntDir->PushButton2->click();
427     }
428     else if ( myEditCurrentArgument == GroupPntDir->LineEdit2 ) {
429       myDir    = aSelectedObject;
430       if ( !myDir->_is_nil() && myPoint->_is_nil() )
431         GroupPntDir->PushButton1->click();
432     }
433     else if ( myEditCurrentArgument == Group3Pnts->LineEdit1 ) {
434       myPoint1 = aSelectedObject;
435       if ( !myPoint1->_is_nil() && myPoint2->_is_nil() )
436         Group3Pnts->PushButton2->click();
437     }
438     else if ( myEditCurrentArgument == Group3Pnts->LineEdit2 ) {
439       myPoint2 = aSelectedObject;
440       if ( !myPoint2->_is_nil() && myPoint3->_is_nil() )
441         Group3Pnts->PushButton3->click();
442     }
443     else if ( myEditCurrentArgument == Group3Pnts->LineEdit3 ) {
444       myPoint3 = aSelectedObject;
445       if ( !myPoint3->_is_nil() && myPoint1->_is_nil() )
446         Group3Pnts->PushButton1->click();
447     }
448     else if ( myEditCurrentArgument == GroupFace->LineEdit1 )
449       myFace   = aSelectedObject;
450   }
451
452   displayPreview();
453 }
454
455
456 //=================================================================================
457 // function : SetEditCurrentArgument()
458 // purpose  :
459 //=================================================================================
460 void BasicGUI_PlaneDlg::SetEditCurrentArgument()
461 {
462   QPushButton* send = (QPushButton*)sender();
463   globalSelection( GEOM_POINT );
464
465   if      ( send == GroupPntDir->PushButton1 ) {
466     myEditCurrentArgument = GroupPntDir->LineEdit1;
467     GroupPntDir->PushButton2->setDown( false );
468     GroupPntDir->LineEdit1->setEnabled( true );
469     GroupPntDir->LineEdit2->setEnabled( false );
470   }
471   else if ( send == GroupPntDir->PushButton2 ) {
472     myEditCurrentArgument = GroupPntDir->LineEdit2;
473     GroupPntDir->PushButton1->setDown( false );
474     GroupPntDir->LineEdit1->setEnabled( false );
475     GroupPntDir->LineEdit2->setEnabled( true );
476   }
477   else if ( send == Group3Pnts->PushButton1 ) {
478     myEditCurrentArgument = Group3Pnts->LineEdit1;
479     Group3Pnts->PushButton2->setDown( false );
480     Group3Pnts->PushButton3->setDown( false );
481     Group3Pnts->LineEdit1->setEnabled( true );
482     Group3Pnts->LineEdit2->setEnabled( false );
483     Group3Pnts->LineEdit3->setEnabled( false );
484   }
485   else if ( send == Group3Pnts->PushButton2 ) {
486     myEditCurrentArgument = Group3Pnts->LineEdit2;
487     Group3Pnts->PushButton1->setDown( false );
488     Group3Pnts->PushButton3->setDown( false );
489     Group3Pnts->LineEdit1->setEnabled( false );
490     Group3Pnts->LineEdit2->setEnabled( true );
491     Group3Pnts->LineEdit3->setEnabled( false );
492   }
493   else if ( send == Group3Pnts->PushButton3 ) {
494     myEditCurrentArgument = Group3Pnts->LineEdit3;
495     Group3Pnts->PushButton1->setDown( false );
496     Group3Pnts->PushButton2->setDown( false );
497     Group3Pnts->LineEdit1->setEnabled( false );
498     Group3Pnts->LineEdit2->setEnabled( false );
499     Group3Pnts->LineEdit3->setEnabled( true );
500   }
501   else if ( send == GroupFace->PushButton1 ) {
502     myEditCurrentArgument = GroupFace->LineEdit1;
503     GroupFace->PushButton1->setDown( true );
504   }
505
506   myEditCurrentArgument->setFocus();
507
508   if ( myEditCurrentArgument == GroupPntDir->LineEdit2 ) {
509     localSelection( GEOM::GEOM_Object::_nil(), TopAbs_EDGE );
510   }
511   else if ( myEditCurrentArgument == GroupFace->LineEdit1 ) {
512     TColStd_MapOfInteger aMap;
513     aMap.Add( GEOM_PLANE );
514     aMap.Add( GEOM_MARKER );
515     globalSelection( aMap );
516   }
517   else { // 3 Pnts
518     localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
519   }
520
521   //  SelectionIntoArgument();
522   myEditCurrentArgument->setFocus();
523   send->setDown(true);
524   displayPreview();
525 }
526
527
528 //=================================================================================
529 // function : LineEditReturnPressed()
530 // purpose  :
531 //=================================================================================
532 void BasicGUI_PlaneDlg::LineEditReturnPressed()
533 {
534   QLineEdit* send = (QLineEdit*)sender();
535   if ( send == GroupPntDir->LineEdit1 ||
536        send == GroupPntDir->LineEdit2 ||
537        send == Group3Pnts->LineEdit1 ||
538        send == Group3Pnts->LineEdit2 ||
539        send == Group3Pnts->LineEdit3 ||
540        send == GroupFace->LineEdit1 ) {
541     myEditCurrentArgument = send;
542     GEOMBase_Skeleton::LineEditReturnPressed();
543   }
544 }
545
546
547 //=================================================================================
548 // function : ActivateThisDialog()
549 // purpose  :
550 //=================================================================================
551 void BasicGUI_PlaneDlg::ActivateThisDialog()
552 {
553   GEOMBase_Skeleton::ActivateThisDialog();
554   connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
555            this, SLOT( SelectionIntoArgument() ) );
556
557   ConstructorsClicked( getConstructorId() );
558 }
559
560 //=================================================================================
561 // function : DeactivateActiveDialog()
562 // purpose  : public slot to deactivate if active
563 //=================================================================================
564 void BasicGUI_PlaneDlg::DeactivateActiveDialog()
565 {
566   GEOMBase_Skeleton::DeactivateActiveDialog();
567 }
568
569 //=================================================================================
570 // function : enterEvent()
571 // purpose  :
572 //=================================================================================
573 void BasicGUI_PlaneDlg::enterEvent( QEvent* )
574 {
575   if ( !mainFrame()->GroupConstructors->isEnabled() )
576     ActivateThisDialog();
577 }
578
579
580 //=================================================================================
581 // function : ValueChangedInSpinBox()
582 // purpose  :
583 //=================================================================================
584 void BasicGUI_PlaneDlg::ValueChangedInSpinBox( double newValue )
585 {
586   displayPreview();
587 }
588
589 //=================================================================================
590 // function : getSize()
591 // purpose  :
592 //=================================================================================
593 double BasicGUI_PlaneDlg::getSize() const
594 {
595   switch ( getConstructorId() ) {
596   case 0 : return GroupPntDir->SpinBox_DX->value();
597   case 1 : return Group3Pnts->SpinBox_DX->value();
598   case 2 : return GroupFace->SpinBox_DX->value();
599   }
600   return 0.;
601 }
602
603 //=================================================================================
604 // function : createOperation
605 // purpose  :
606 //=================================================================================
607 GEOM::GEOM_IOperations_ptr BasicGUI_PlaneDlg::createOperation()
608 {
609   return myGeomGUI->GetGeomGen()->GetIBasicOperations( getStudyId() );
610 }
611
612 //=================================================================================
613 // function : isEqual
614 // purpose  : it may also be needed to check for min distance between gp_Pnt-s...
615 //=================================================================================
616 static bool isEqual( const GEOM::GEOM_Object_var& thePnt1, const GEOM::GEOM_Object_var& thePnt2 )
617 {
618         return thePnt1->_is_equivalent( thePnt2 );
619 }
620
621 //=================================================================================
622 // function : isValid
623 // purpose  :
624 //=================================================================================
625 bool BasicGUI_PlaneDlg::isValid( QString& msg )
626 {
627   const int id = getConstructorId();
628   if ( getSize() <= 0 ) {
629     msg = QString( "Please, enter size greater than 0." );
630     return false;
631   }
632   if ( id == 0 )
633     return !CORBA::is_nil( myPoint ) && !CORBA::is_nil( myDir );
634   else if ( id == 1 )
635     return !CORBA::is_nil( myPoint1  ) && !CORBA::is_nil( myPoint2 ) && !CORBA::is_nil( myPoint3 ) &&
636       !isEqual( myPoint1, myPoint2 ) && !isEqual( myPoint1, myPoint3 ) && !isEqual( myPoint2, myPoint3 );
637   else if ( id == 2 )
638     return !CORBA::is_nil( myFace );
639   return false;
640 }
641
642 //=================================================================================
643 // function : execute
644 // purpose  :
645 //=================================================================================
646 bool BasicGUI_PlaneDlg::execute( ObjectList& objects )
647 {
648   bool res = false;
649
650   GEOM::GEOM_Object_var anObj;
651
652   switch ( getConstructorId() ) {
653   case 0 :
654     anObj = GEOM::GEOM_IBasicOperations::_narrow( getOperation() )->MakePlanePntVec( myPoint, myDir, getSize() );
655     res = true;
656     break;
657   case 1 :
658     anObj = GEOM::GEOM_IBasicOperations::_narrow( getOperation() )->MakePlaneThreePnt( myPoint1, myPoint2, myPoint3, getSize() );
659     res = true;
660     break;
661   case 2 :
662     anObj = GEOM::GEOM_IBasicOperations::_narrow( getOperation() )->MakePlaneFace( myFace, getSize() );
663     res = true;
664     break;
665   }
666
667   if ( !anObj->_is_nil() )
668     objects.push_back( anObj._retn() );
669   
670   return res;
671 }
672 //=================================================================================
673 // function : addSubshapeToStudy
674 // purpose  : virtual method to add new SubObjects if local selection
675 //=================================================================================
676 void BasicGUI_PlaneDlg::addSubshapesToStudy()
677 {
678   QMap<QString, GEOM::GEOM_Object_var> objMap;
679
680   switch ( getConstructorId() ) {
681   case 0:
682     objMap[GroupPntDir->LineEdit1->text()] = myPoint;
683     objMap[GroupPntDir->LineEdit2->text()] = myDir;
684     break;
685   case 1:
686     objMap[Group3Pnts->LineEdit1->text()] = myPoint1;
687     objMap[Group3Pnts->LineEdit2->text()] = myPoint2;
688     objMap[Group3Pnts->LineEdit3->text()] = myPoint3;
689     break;
690   case 2:
691     objMap[GroupFace->LineEdit1->text()] = myFace;
692     break;
693   }
694   addSubshapesToFather( objMap );
695 }