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