Salome HOME
Merge from V5_1_main branch 24/11/2010
[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   SelectionIntoArgument();
368
369   myEditCurrentArgument->setFocus();
370   connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
371            this, SLOT( SelectionIntoArgument() ) );
372   displayPreview();
373 }
374
375
376 //=================================================================================
377 // function : ClickOnOk()
378 // purpose  :
379 //=================================================================================
380 void BasicGUI_PlaneDlg::ClickOnOk()
381 {
382   if ( ClickOnApply() )
383     ClickOnCancel();
384 }
385
386
387 //=================================================================================
388 // function : ClickOnApply()
389 // purpose  :
390 //=================================================================================
391 bool BasicGUI_PlaneDlg::ClickOnApply()
392 {
393   if ( !onAccept() )
394     return false;
395
396   initName();
397   ConstructorsClicked( getConstructorId() );
398   return true;
399 }
400
401 //=================================================================================
402 // function : GroupClicked()
403 // purpose  : OX OY OZ Radio button management
404 //=================================================================================
405 void BasicGUI_PlaneDlg::GroupClicked()
406 {
407   QRadioButton* send = (QRadioButton*)sender();
408
409   if ( send == GroupLCS->RadioButton1 )
410     myOriginType = 1;
411   else if ( send == GroupLCS->RadioButton2 )
412     myOriginType = 2;
413   else if ( send == GroupLCS->RadioButton3 )
414     myOriginType = 3;
415   displayPreview();
416 }
417
418 //=================================================================================
419 // function : SelectionIntoArgument()
420 // purpose  : Called when selection has changed
421 //=================================================================================
422 void BasicGUI_PlaneDlg::SelectionIntoArgument()
423 {
424   myEditCurrentArgument->setText("");
425
426   LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
427   SALOME_ListIO aSelList;
428   aSelMgr->selectedObjects(aSelList);
429
430   if (aSelList.Extent() != 1) {
431     if      ( myEditCurrentArgument == GroupPntDir->LineEdit1 ) myPoint  = GEOM::GEOM_Object::_nil();
432     else if ( myEditCurrentArgument == GroupPntDir->LineEdit2 ) myDir    = GEOM::GEOM_Object::_nil();
433     else if ( myEditCurrentArgument == Group3Pnts->LineEdit1 )  myPoint1 = GEOM::GEOM_Object::_nil();
434     else if ( myEditCurrentArgument == Group3Pnts->LineEdit2 )  myPoint2 = GEOM::GEOM_Object::_nil();
435     else if ( myEditCurrentArgument == Group3Pnts->LineEdit3 )  myPoint3 = GEOM::GEOM_Object::_nil();
436     else if ( myEditCurrentArgument == GroupFace->LineEdit1 )   myFace   = GEOM::GEOM_Object::_nil();
437     else if ( myEditCurrentArgument == Group2Vec->LineEdit1 )   myVec1   = GEOM::GEOM_Object::_nil();
438     else if ( myEditCurrentArgument == Group2Vec->LineEdit2 )   myVec2   = GEOM::GEOM_Object::_nil();
439     else if ( myEditCurrentArgument == GroupLCS->LineEdit1 )    myLCS   = GEOM::GEOM_Object::_nil();
440     displayPreview();
441     return;
442   }
443
444   // nbSel == 1
445   Standard_Boolean aRes = Standard_False;
446   GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject(aSelList.First(), aRes);
447   if ( !CORBA::is_nil( aSelectedObject ) && aRes ) {
448     QString aName = GEOMBase::GetName( aSelectedObject );
449     TopAbs_ShapeEnum aNeedType = TopAbs_VERTEX;
450     if ( myEditCurrentArgument == GroupPntDir->LineEdit2 || myEditCurrentArgument == Group2Vec->LineEdit1 || myEditCurrentArgument == Group2Vec->LineEdit2)
451       aNeedType = TopAbs_EDGE;
452     else if ( myEditCurrentArgument == GroupFace->LineEdit1 )
453       aNeedType = TopAbs_FACE;
454     else if ( myEditCurrentArgument == GroupLCS->LineEdit1 )
455       aNeedType = TopAbs_FACE;
456
457     TopoDS_Shape aShape;
458     if ( GEOMBase::GetShape( aSelectedObject, aShape, TopAbs_SHAPE ) && !aShape.IsNull() ) {
459       TColStd_IndexedMapOfInteger aMap;
460       aSelMgr->GetIndexes(aSelList.First(), aMap);
461       if ( aMap.Extent() == 1 ) { // Local Selection
462         int anIndex = aMap( 1 );
463         if ( aNeedType == TopAbs_EDGE )
464           aName += QString( ":edge_%1" ).arg( anIndex );
465         else if (aNeedType == TopAbs_FACE)
466           aName += QString( ":face_%1" ).arg( anIndex );
467         else
468           aName += QString( ":vertex_%1" ).arg( anIndex );
469
470         //Find SubShape Object in Father
471         GEOM::GEOM_Object_var aFindedObject = GEOMBase_Helper::findObjectInFather( aSelectedObject, aName );
472
473         if ( aFindedObject->_is_nil() ) { // Object not found in study
474           GEOM::GEOM_IShapesOperations_var aShapesOp = getGeomEngine()->GetIShapesOperations( getStudyId() );
475           aSelectedObject = aShapesOp->GetSubShape( aSelectedObject, anIndex );
476         } 
477         else {
478           aSelectedObject = aFindedObject; // get Object from study
479         }
480       }
481       else { // Global Selection
482         if ( aShape.ShapeType() != aNeedType ) {
483           aSelectedObject = GEOM::GEOM_Object::_nil();
484           aName = "";
485         }
486       }
487     }
488
489     myEditCurrentArgument->setText( aName );
490
491     /*    if (!aSelectedObject->_is_nil()) { // clear selection if something selected
492       globalSelection();
493       if ( myEditCurrentArgument == GroupFace->LineEdit1 ) {
494         TColStd_MapOfInteger aMap;
495         aMap.Add( GEOM_PLANE );
496         aMap.Add( GEOM_MARKER );
497         globalSelection( aMap );
498       }
499       else
500         localSelection( GEOM::GEOM_Object::_nil(), aNeedType );
501         }*/
502
503     if      ( myEditCurrentArgument == GroupPntDir->LineEdit1 ) {
504       myPoint  = aSelectedObject;
505       if ( !myPoint->_is_nil() && myDir->_is_nil() )
506         GroupPntDir->PushButton2->click();
507     }
508     else if ( myEditCurrentArgument == GroupPntDir->LineEdit2 ) {
509       myDir    = aSelectedObject;
510       if ( !myDir->_is_nil() && myPoint->_is_nil() )
511         GroupPntDir->PushButton1->click();
512     }
513     else if ( myEditCurrentArgument == Group3Pnts->LineEdit1 ) {
514       myPoint1 = aSelectedObject;
515       if ( !myPoint1->_is_nil() && myPoint2->_is_nil() )
516         Group3Pnts->PushButton2->click();
517     }
518     else if ( myEditCurrentArgument == Group3Pnts->LineEdit2 ) {
519       myPoint2 = aSelectedObject;
520       if ( !myPoint2->_is_nil() && myPoint3->_is_nil() )
521         Group3Pnts->PushButton3->click();
522     }
523     else if ( myEditCurrentArgument == Group3Pnts->LineEdit3 ) {
524       myPoint3 = aSelectedObject;
525       if ( !myPoint3->_is_nil() && myPoint1->_is_nil() )
526         Group3Pnts->PushButton1->click();
527     }
528     else if ( myEditCurrentArgument == GroupFace->LineEdit1 )
529       myFace   = aSelectedObject;
530     else if ( myEditCurrentArgument == Group2Vec->LineEdit1 ) {
531       myVec1 = aSelectedObject;
532       if ( !myVec1->_is_nil() && myVec2->_is_nil() )
533         Group2Vec->PushButton2->click();
534     } else if ( myEditCurrentArgument == Group2Vec->LineEdit2 ) {
535       myVec2 = aSelectedObject;
536       if ( !myVec2->_is_nil() && myVec1->_is_nil() )
537         Group2Vec->PushButton1->click();
538     } else if ( myEditCurrentArgument == GroupLCS->LineEdit1 )
539       myLCS = aSelectedObject;
540
541   }
542
543   displayPreview();
544 }
545
546
547 //=================================================================================
548 // function : SetEditCurrentArgument()
549 // purpose  :
550 //=================================================================================
551 void BasicGUI_PlaneDlg::SetEditCurrentArgument()
552 {
553   QPushButton* send = (QPushButton*)sender();
554   globalSelection( GEOM_POINT );
555
556   if      ( send == GroupPntDir->PushButton1 ) {
557     myEditCurrentArgument = GroupPntDir->LineEdit1;
558     GroupPntDir->PushButton2->setDown( false );
559     GroupPntDir->LineEdit1->setEnabled( true );
560     GroupPntDir->LineEdit2->setEnabled( false );
561   }
562   else if ( send == GroupPntDir->PushButton2 ) {
563     myEditCurrentArgument = GroupPntDir->LineEdit2;
564     GroupPntDir->PushButton1->setDown( false );
565     GroupPntDir->LineEdit1->setEnabled( false );
566     GroupPntDir->LineEdit2->setEnabled( true );
567   }
568   else if ( send == Group3Pnts->PushButton1 ) {
569     myEditCurrentArgument = Group3Pnts->LineEdit1;
570     Group3Pnts->PushButton2->setDown( false );
571     Group3Pnts->PushButton3->setDown( false );
572     Group3Pnts->LineEdit1->setEnabled( true );
573     Group3Pnts->LineEdit2->setEnabled( false );
574     Group3Pnts->LineEdit3->setEnabled( false );
575   }
576   else if ( send == Group3Pnts->PushButton2 ) {
577     myEditCurrentArgument = Group3Pnts->LineEdit2;
578     Group3Pnts->PushButton1->setDown( false );
579     Group3Pnts->PushButton3->setDown( false );
580     Group3Pnts->LineEdit1->setEnabled( false );
581     Group3Pnts->LineEdit2->setEnabled( true );
582     Group3Pnts->LineEdit3->setEnabled( false );
583   }
584   else if ( send == Group3Pnts->PushButton3 ) {
585     myEditCurrentArgument = Group3Pnts->LineEdit3;
586     Group3Pnts->PushButton1->setDown( false );
587     Group3Pnts->PushButton2->setDown( false );
588     Group3Pnts->LineEdit1->setEnabled( false );
589     Group3Pnts->LineEdit2->setEnabled( false );
590     Group3Pnts->LineEdit3->setEnabled( true );
591   }
592   else if ( send == GroupFace->PushButton1 ) {
593     myEditCurrentArgument = GroupFace->LineEdit1;
594     GroupFace->PushButton1->setDown( true );
595   } else if ( send == Group2Vec->PushButton1 ) {
596     myEditCurrentArgument = Group2Vec->LineEdit1;
597     Group2Vec->PushButton2->setDown( false );
598     Group2Vec->LineEdit1->setEnabled( true );
599     Group2Vec->LineEdit2->setEnabled( false );
600   } else if ( send == Group2Vec->PushButton2 ) {
601     myEditCurrentArgument = Group2Vec->LineEdit2;
602     Group2Vec->PushButton1->setDown( false );
603     Group2Vec->LineEdit1->setEnabled( false );
604     Group2Vec->LineEdit2->setEnabled( true );
605   } else if ( send == GroupLCS->PushButton1 ) {
606     myEditCurrentArgument = GroupLCS->LineEdit1;
607     GroupLCS->LineEdit1->setEnabled( true );
608   }
609
610   myEditCurrentArgument->setFocus();
611
612   if ( myEditCurrentArgument == GroupPntDir->LineEdit2 || 
613        myEditCurrentArgument == Group2Vec->LineEdit1   ||
614        myEditCurrentArgument == Group2Vec->LineEdit2 ) {
615     localSelection( GEOM::GEOM_Object::_nil(), TopAbs_EDGE );
616   } else if ( myEditCurrentArgument == GroupFace->LineEdit1 ) {
617     TColStd_MapOfInteger aMap;
618     aMap.Add( GEOM_PLANE );
619     aMap.Add( GEOM_MARKER );
620     globalSelection( aMap );
621   } else if ( myEditCurrentArgument == GroupLCS->LineEdit1 ) {
622     globalSelection( GEOM_MARKER );
623   }
624   else { // 3 Pnts
625     localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
626   }
627
628   //  SelectionIntoArgument();
629   myEditCurrentArgument->setFocus();
630   send->setDown(true);
631   displayPreview();
632 }
633
634
635 //=================================================================================
636 // function : LineEditReturnPressed()
637 // purpose  :
638 //=================================================================================
639 void BasicGUI_PlaneDlg::LineEditReturnPressed()
640 {
641   QLineEdit* send = (QLineEdit*)sender();
642   if ( send == GroupPntDir->LineEdit1 ||
643        send == GroupPntDir->LineEdit2 ||
644        send == Group3Pnts->LineEdit1 ||
645        send == Group3Pnts->LineEdit2 ||
646        send == Group3Pnts->LineEdit3 ||
647        send == GroupFace->LineEdit1  ||
648        send == Group2Vec->LineEdit1  ||
649        send == Group2Vec->LineEdit2  ||
650        send == GroupLCS->LineEdit1  ) {
651     myEditCurrentArgument = send;
652     GEOMBase_Skeleton::LineEditReturnPressed();
653   }
654 }
655
656
657 //=================================================================================
658 // function : ActivateThisDialog()
659 // purpose  :
660 //=================================================================================
661 void BasicGUI_PlaneDlg::ActivateThisDialog()
662 {
663   GEOMBase_Skeleton::ActivateThisDialog();
664   connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
665            this, SLOT( SelectionIntoArgument() ) );
666
667   ConstructorsClicked( getConstructorId() );
668   SelectionIntoArgument();
669 }
670
671 //=================================================================================
672 // function : DeactivateActiveDialog()
673 // purpose  : public slot to deactivate if active
674 //=================================================================================
675 void BasicGUI_PlaneDlg::DeactivateActiveDialog()
676 {
677   GEOMBase_Skeleton::DeactivateActiveDialog();
678 }
679
680 //=================================================================================
681 // function : enterEvent()
682 // purpose  :
683 //=================================================================================
684 void BasicGUI_PlaneDlg::enterEvent( QEvent* )
685 {
686   if ( !mainFrame()->GroupConstructors->isEnabled() )
687     ActivateThisDialog();
688 }
689
690
691 //=================================================================================
692 // function : ValueChangedInSpinBox()
693 // purpose  :
694 //=================================================================================
695 void BasicGUI_PlaneDlg::ValueChangedInSpinBox( double newValue )
696 {
697   displayPreview();
698 }
699
700 //=================================================================================
701 // function : getSize()
702 // purpose  :
703 //=================================================================================
704 double BasicGUI_PlaneDlg::getSize() const
705 {
706   switch ( getConstructorId() ) {
707   case 0 : return GroupPntDir->SpinBox_DX->value();
708   case 1 : return Group3Pnts->SpinBox_DX->value();
709   case 2 : return GroupFace->SpinBox_DX->value();
710   case 3 : return Group2Vec->SpinBox_DX->value();
711   case 4 : return GroupLCS->SpinBox_DX->value();
712   }
713   return 0.;
714 }
715
716 //=================================================================================
717 // function : getSize()
718 // purpose  :
719 //=================================================================================
720 QString BasicGUI_PlaneDlg::getSizeAsString() const
721 {
722   switch ( getConstructorId() ) {
723   case 0 : return GroupPntDir->SpinBox_DX->text();
724   case 1 : return Group3Pnts->SpinBox_DX->text();
725   case 2 : return GroupFace->SpinBox_DX->text();
726   case 3 : return Group2Vec->SpinBox_DX->text();
727   }
728   return QString();
729 }
730
731 //=================================================================================
732 // function : createOperation
733 // purpose  :
734 //=================================================================================
735 GEOM::GEOM_IOperations_ptr BasicGUI_PlaneDlg::createOperation()
736 {
737   return myGeomGUI->GetGeomGen()->GetIBasicOperations( getStudyId() );
738 }
739
740 //=================================================================================
741 // function : isEqual
742 // purpose  : it may also be needed to check for min distance between gp_Pnt-s...
743 //=================================================================================
744 static bool isEqual( const GEOM::GEOM_Object_var& thePnt1, const GEOM::GEOM_Object_var& thePnt2 )
745 {
746         return thePnt1->_is_equivalent( thePnt2 );
747 }
748
749 //=================================================================================
750 // function : isValid
751 // purpose  :
752 //=================================================================================
753 bool BasicGUI_PlaneDlg::isValid( QString& msg )
754 {
755   const int id = getConstructorId();
756   if ( getSize() <= 0 ) {
757     msg = QString( "Please, enter size greater than 0." );
758     return false;
759   }
760
761   if ( id == 0 ) { 
762     bool ok = GroupPntDir->SpinBox_DX->isValid( msg, !IsPreview() );
763     return !CORBA::is_nil( myPoint ) && !CORBA::is_nil( myDir ) && ok;
764   }
765   else if ( id == 1 ) {
766     bool ok = Group3Pnts->SpinBox_DX->isValid( msg, !IsPreview() );
767     return !CORBA::is_nil( myPoint1  ) && !CORBA::is_nil( myPoint2 ) && !CORBA::is_nil( myPoint3 ) &&
768       !isEqual( myPoint1, myPoint2 ) && !isEqual( myPoint1, myPoint3 ) && !isEqual( myPoint2, myPoint3 ) && ok;
769   }
770   else if ( id == 2 ) {
771     bool ok = GroupFace->SpinBox_DX->isValid( msg, !IsPreview() );
772     return !CORBA::is_nil( myFace ) && ok;
773   }   else if ( id == 3 ) {
774     bool ok = Group2Vec->SpinBox_DX->isValid( msg, !IsPreview() );
775     return !CORBA::is_nil( myVec1  ) && !CORBA::is_nil( myVec2 ) && !isEqual( myVec1, myVec2 ) && ok;
776   } else if ( id == 4 ) {
777     bool ok = GroupLCS->SpinBox_DX->isValid( msg, !IsPreview() );
778     return ok;
779   }
780   return false;
781 }
782
783 //=================================================================================
784 // function : execute
785 // purpose  :
786 //=================================================================================
787 bool BasicGUI_PlaneDlg::execute( ObjectList& objects )
788 {
789   bool res = false;
790
791   GEOM::GEOM_Object_var anObj;
792
793   GEOM::GEOM_IBasicOperations_var anOper = GEOM::GEOM_IBasicOperations::_narrow( getOperation() );
794
795   switch ( getConstructorId() ) {
796   case 0 :
797     anObj = anOper->MakePlanePntVec( myPoint, myDir, getSize() );
798     res = true;
799     break;
800   case 1 :
801     anObj = anOper->MakePlaneThreePnt( myPoint1, myPoint2, myPoint3, getSize() );
802     res = true;
803     break;
804   case 2 :
805     anObj = anOper->MakePlaneFace( myFace, getSize() );
806     res = true;
807     break;
808   case 3 :
809     anObj = anOper->MakePlane2Vec( myVec1, myVec2, getSize() );
810     res = true;
811     break;
812   case 4 :
813     anObj = anOper->MakePlaneLCS( myLCS, getSize(), myOriginType );
814     res = true;
815     break;
816   }
817   
818   if ( !anObj->_is_nil() ) {
819     if ( !IsPreview() )
820       anObj->SetParameters(getSizeAsString().toLatin1().constData());
821     objects.push_back( anObj._retn() );
822   }
823   return res;
824 }
825 //=================================================================================
826 // function : addSubshapeToStudy
827 // purpose  : virtual method to add new SubObjects if local selection
828 //=================================================================================
829 void BasicGUI_PlaneDlg::addSubshapesToStudy()
830 {
831   QMap<QString, GEOM::GEOM_Object_var> objMap;
832
833   switch ( getConstructorId() ) {
834   case 0:
835     objMap[GroupPntDir->LineEdit1->text()] = myPoint;
836     objMap[GroupPntDir->LineEdit2->text()] = myDir;
837     break;
838   case 1:
839     objMap[Group3Pnts->LineEdit1->text()] = myPoint1;
840     objMap[Group3Pnts->LineEdit2->text()] = myPoint2;
841     objMap[Group3Pnts->LineEdit3->text()] = myPoint3;
842     break;
843   case 2:
844     objMap[GroupFace->LineEdit1->text()] = myFace;
845     break;
846   case 3:
847     objMap[Group2Vec->LineEdit1->text()] = myVec1;
848     objMap[Group2Vec->LineEdit2->text()] = myVec2;
849     break;
850   }
851   addSubshapesToFather( objMap );
852 }