Salome HOME
Eliminate useless GetSubShape() lines in the python dump
[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->LineEdit1->setReadOnly( true );
141   GroupLCS->PushButton1->setIcon( image3 );
142   GroupLCS->PushButton1->setDown( true );
143
144   QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
145   layout->setMargin( 0 ); layout->setSpacing( 6 );
146   layout->addWidget( GroupPntDir );
147   layout->addWidget( Group3Pnts );
148   layout->addWidget( GroupFace );
149   layout->addWidget( Group2Vec );
150   layout->addWidget( GroupLCS );
151   /***************************************************************/
152
153   setHelpFileName( "create_plane_page.html" );
154
155   Init();
156 }
157
158
159 //=================================================================================
160 // function : ~BasicGUI_PlaneDlg()
161 // purpose  : Destroys the object and frees any allocated resources
162 //=================================================================================
163 BasicGUI_PlaneDlg::~BasicGUI_PlaneDlg()
164 {
165 }
166
167
168 //=================================================================================
169 // function : Init()
170 // purpose  :
171 //=================================================================================
172 void BasicGUI_PlaneDlg::Init()
173 {
174   /* init variables */
175   myEditCurrentArgument = GroupPntDir->LineEdit1;
176
177   myPoint.nullify();
178   myDir.nullify();
179   myPoint1.nullify();
180   myPoint2.nullify();
181   myPoint3.nullify();
182   myFace.nullify();
183   myLCS.nullify();
184   myVec1.nullify();
185   myVec2.nullify();
186  
187   // myGeomGUI->SetState( 0 );
188   myOriginType = 1;
189
190   /* Get setting of step value from file configuration */
191   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
192   double aStep = resMgr->doubleValue( "Geometry", "SettingsGeomStep", 100 );
193
194   double aTrimSize = 2000.0;
195
196   /* min, max, step and decimals for spin boxes */
197   initSpinBox( GroupPntDir->SpinBox_DX, 0.000001, COORD_MAX, aStep, "length_precision" );
198   GroupPntDir->SpinBox_DX->setValue( aTrimSize );
199   initSpinBox( Group3Pnts->SpinBox_DX, 0.000001, COORD_MAX, aStep, "length_precision" );
200   Group3Pnts->SpinBox_DX->setValue( aTrimSize );
201   initSpinBox( GroupFace->SpinBox_DX, 0.000001, COORD_MAX, aStep, "length_precision" );
202   GroupFace->SpinBox_DX->setValue( aTrimSize );
203   initSpinBox( Group2Vec->SpinBox_DX, 0.000001, COORD_MAX, aStep, "length_precision" );
204   Group2Vec->SpinBox_DX->setValue( aTrimSize );
205   initSpinBox( GroupLCS->SpinBox_DX, 0.000001, COORD_MAX, aStep, "length_precision" );
206   GroupLCS->SpinBox_DX->setValue( aTrimSize );
207
208   /* signals and slots connections */
209   connect( myGeomGUI, SIGNAL( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) );
210   connect( myGeomGUI, SIGNAL( SignalCloseAllDialogs() ),        this, SLOT( ClickOnCancel() ) );
211
212   connect( buttonOk(),     SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
213   connect( buttonApply(),  SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
214
215   connect( this,           SIGNAL( constructorsClicked( int ) ), this, SLOT( ConstructorsClicked( int ) ) );
216
217   connect( GroupPntDir->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
218   connect( GroupPntDir->PushButton2, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
219   connect( Group3Pnts->PushButton1,  SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
220   connect( Group3Pnts->PushButton2,  SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
221   connect( Group3Pnts->PushButton3,  SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
222   connect( GroupFace->PushButton1,   SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
223   connect( Group2Vec->PushButton1,   SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
224   connect( Group2Vec->PushButton2,   SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
225
226   connect( GroupLCS->RadioButton1,   SIGNAL( clicked() ), this, SLOT( GroupClicked() ) );
227   connect( GroupLCS->RadioButton2,   SIGNAL( clicked() ), this, SLOT( GroupClicked() ) );
228   connect( GroupLCS->RadioButton3,   SIGNAL( clicked() ), this, SLOT( GroupClicked() ) );
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.nullify();
266   myDir.nullify();
267   myPoint1.nullify();
268   myPoint2.nullify();
269   myPoint3.nullify();
270   myFace.nullify();
271   myLCS.nullify();
272   myVec1.nullify();
273   myVec2.nullify();
274
275   switch ( constructorId ) {
276   case 0: /* plane from a point and a direction (vector, edge...) */
277     {
278       Group3Pnts->hide();
279       GroupFace->hide();
280       GroupPntDir->show();
281       Group2Vec->hide();
282       GroupLCS->hide();
283       
284       myEditCurrentArgument = GroupPntDir->LineEdit1;
285       GroupPntDir->LineEdit1->setText( "" );
286       GroupPntDir->LineEdit2->setText( "" );
287       GroupPntDir->PushButton1->setDown( true );
288       GroupPntDir->PushButton2->setDown( false );
289       GroupPntDir->LineEdit1->setEnabled( true );
290       GroupPntDir->LineEdit2->setEnabled( false );
291       
292       /* for the first argument */
293       globalSelection(); // close local contexts, if any
294       localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
295       break;
296     }
297   case 1: /* plane from 3 points */
298     {
299       GroupPntDir->hide();
300       GroupFace->hide();
301       Group3Pnts->show();
302       Group2Vec->hide();
303       GroupLCS->hide();
304       
305       myEditCurrentArgument = Group3Pnts->LineEdit1;
306       Group3Pnts->LineEdit1->setText( "" );
307       Group3Pnts->LineEdit2->setText( "" );
308       Group3Pnts->LineEdit3->setText( "" );
309       Group3Pnts->PushButton1->setDown( true );
310       Group3Pnts->PushButton2->setDown( false );
311       Group3Pnts->PushButton3->setDown( false );
312       Group3Pnts->LineEdit1->setEnabled( true );
313       Group3Pnts->LineEdit2->setEnabled( false );
314       Group3Pnts->LineEdit3->setEnabled( false );
315       
316       /* for the first argument */
317       globalSelection(); // close local contexts, if any
318       localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
319       break;
320     }
321   case 2: /* plane from a planar face */
322     {
323       GroupPntDir->hide();
324       Group3Pnts->hide();
325       GroupFace->show();
326       Group2Vec->hide();
327       GroupLCS->hide();
328       
329       myEditCurrentArgument = GroupFace->LineEdit1;
330       GroupFace->LineEdit1->setText( "" );
331       GroupFace->PushButton1->setDown( true );
332       
333       globalSelection(); // close local contexts, if any
334       localSelection( GEOM::GEOM_Object::_nil(), TopAbs_FACE );
335       break;
336     }
337   case 3: /* plane from a 2 Vectors */
338     {
339       GroupPntDir->hide();
340       Group3Pnts->hide();
341       GroupFace->hide();
342       Group2Vec->show();
343       GroupLCS->hide();
344       
345       myEditCurrentArgument = Group2Vec->LineEdit1;
346       Group2Vec->LineEdit1->setText( "" );
347       Group2Vec->PushButton1->setDown( true );
348       
349       globalSelection(); // close local contexts, if any
350       localSelection( GEOM::GEOM_Object::_nil(), TopAbs_EDGE );
351       break;
352     }
353   case 4: /* plane from a LCS */
354     {
355       GroupPntDir->hide();
356       Group3Pnts->hide();
357       GroupFace->hide();
358       Group2Vec->hide();
359       GroupLCS->show();
360       
361       myEditCurrentArgument = GroupLCS->LineEdit1;
362       GroupLCS->LineEdit1->setText( "" );
363       GroupLCS->PushButton1->setDown( true );
364       GroupLCS->RadioButton1->setChecked( true );
365       myOriginType = 1;
366       
367       globalSelection(GEOM_MARKER);
368       break;
369     }
370   }
371   
372   qApp->processEvents();
373   updateGeometry();
374   resize( minimumSizeHint() );
375   SelectionIntoArgument();
376
377   myEditCurrentArgument->setFocus();
378   connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
379            this, SLOT( SelectionIntoArgument() ) );
380   displayPreview();
381 }
382
383
384 //=================================================================================
385 // function : ClickOnOk()
386 // purpose  :
387 //=================================================================================
388 void BasicGUI_PlaneDlg::ClickOnOk()
389 {
390   if ( ClickOnApply() )
391     ClickOnCancel();
392 }
393
394
395 //=================================================================================
396 // function : ClickOnApply()
397 // purpose  :
398 //=================================================================================
399 bool BasicGUI_PlaneDlg::ClickOnApply()
400 {
401   if ( !onAccept() )
402     return false;
403
404   initName();
405   ConstructorsClicked( getConstructorId() );
406   return true;
407 }
408
409 //=================================================================================
410 // function : GroupClicked()
411 // purpose  : OX OY OZ Radio button management
412 //=================================================================================
413 void BasicGUI_PlaneDlg::GroupClicked()
414 {
415   QRadioButton* send = (QRadioButton*)sender();
416
417   if ( send == GroupLCS->RadioButton1 )
418     myOriginType = 1;
419   else if ( send == GroupLCS->RadioButton2 )
420     myOriginType = 2;
421   else if ( send == GroupLCS->RadioButton3 )
422     myOriginType = 3;
423   displayPreview();
424 }
425
426 //=================================================================================
427 // function : SelectionIntoArgument()
428 // purpose  : Called when selection has changed
429 //=================================================================================
430 void BasicGUI_PlaneDlg::SelectionIntoArgument()
431 {
432   myEditCurrentArgument->setText("");
433
434   LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
435   SALOME_ListIO aSelList;
436   aSelMgr->selectedObjects(aSelList);
437
438   if (aSelList.Extent() != 1) {
439     if      ( myEditCurrentArgument == GroupPntDir->LineEdit1 ) myPoint.nullify();
440     else if ( myEditCurrentArgument == GroupPntDir->LineEdit2 ) myDir.nullify();
441     else if ( myEditCurrentArgument == Group3Pnts->LineEdit1 )  myPoint1.nullify();
442     else if ( myEditCurrentArgument == Group3Pnts->LineEdit2 )  myPoint2.nullify();
443     else if ( myEditCurrentArgument == Group3Pnts->LineEdit3 )  myPoint3.nullify();
444     else if ( myEditCurrentArgument == GroupFace->LineEdit1 )   myFace.nullify();
445     else if ( myEditCurrentArgument == Group2Vec->LineEdit1 )   myVec1.nullify();
446     else if ( myEditCurrentArgument == Group2Vec->LineEdit2 )   myVec2.nullify();
447     else if ( myEditCurrentArgument == GroupLCS->LineEdit1 )    myLCS.nullify();
448     displayPreview();
449     return;
450   }
451
452   TopAbs_ShapeEnum aNeedType;
453   if ( myEditCurrentArgument == GroupPntDir->LineEdit2 || myEditCurrentArgument == Group2Vec->LineEdit1 || myEditCurrentArgument == Group2Vec->LineEdit2)
454     aNeedType = TopAbs_EDGE;
455   else if ( myEditCurrentArgument == GroupFace->LineEdit1 )
456     aNeedType = TopAbs_FACE;
457   else if ( myEditCurrentArgument == GroupLCS->LineEdit1 )
458     aNeedType = TopAbs_FACE;
459   else
460     aNeedType = TopAbs_VERTEX;
461   GEOM::GeomObjPtr aSelectedObject = getSelected( aNeedType );
462   TopoDS_Shape aShape;
463   if ( aSelectedObject && GEOMBase::GetShape( aSelectedObject.get(), aShape ) && !aShape.IsNull() ) {
464     QString aName = GEOMBase::GetName( aSelectedObject.get() );
465     myEditCurrentArgument->setText( aName );
466     if ( myEditCurrentArgument == GroupPntDir->LineEdit1 ) {
467       myPoint = aSelectedObject;
468       if ( myPoint && !myDir )
469         GroupPntDir->PushButton2->click();
470     }
471     else if ( myEditCurrentArgument == GroupPntDir->LineEdit2 ) {
472       myDir = aSelectedObject;
473       if ( myDir && !myPoint )
474         GroupPntDir->PushButton1->click();
475     }
476     else if ( myEditCurrentArgument == Group3Pnts->LineEdit1 ) {
477       myPoint1 = aSelectedObject;
478       if ( myPoint1 && !myPoint2 )
479         Group3Pnts->PushButton2->click();
480     }
481     else if ( myEditCurrentArgument == Group3Pnts->LineEdit2 ) {
482       myPoint2 = aSelectedObject;
483       if ( myPoint2 && !myPoint3 )
484         Group3Pnts->PushButton3->click();
485     }
486     else if ( myEditCurrentArgument == Group3Pnts->LineEdit3 ) {
487       myPoint3 = aSelectedObject;
488       if ( myPoint3 && !myPoint1 )
489         Group3Pnts->PushButton1->click();
490     }
491     else if ( myEditCurrentArgument == GroupFace->LineEdit1 )
492       myFace   = aSelectedObject;
493     else if ( myEditCurrentArgument == Group2Vec->LineEdit1 ) {
494       myVec1 = aSelectedObject;
495       if ( myVec1 && !myVec2 )
496         Group2Vec->PushButton2->click();
497     } else if ( myEditCurrentArgument == Group2Vec->LineEdit2 ) {
498       myVec2 = aSelectedObject;
499       if ( myVec2 && !myVec1 )
500         Group2Vec->PushButton1->click();
501     } else if ( myEditCurrentArgument == GroupLCS->LineEdit1 )
502       myLCS = aSelectedObject;
503   }
504
505   displayPreview();
506 }
507
508
509 //=================================================================================
510 // function : SetEditCurrentArgument()
511 // purpose  :
512 //=================================================================================
513 void BasicGUI_PlaneDlg::SetEditCurrentArgument()
514 {
515   QPushButton* send = (QPushButton*)sender();
516   globalSelection( GEOM_POINT );
517
518   if      ( send == GroupPntDir->PushButton1 ) {
519     myEditCurrentArgument = GroupPntDir->LineEdit1;
520     GroupPntDir->PushButton2->setDown( false );
521     GroupPntDir->LineEdit1->setEnabled( true );
522     GroupPntDir->LineEdit2->setEnabled( false );
523   }
524   else if ( send == GroupPntDir->PushButton2 ) {
525     myEditCurrentArgument = GroupPntDir->LineEdit2;
526     GroupPntDir->PushButton1->setDown( false );
527     GroupPntDir->LineEdit1->setEnabled( false );
528     GroupPntDir->LineEdit2->setEnabled( true );
529   }
530   else if ( send == Group3Pnts->PushButton1 ) {
531     myEditCurrentArgument = Group3Pnts->LineEdit1;
532     Group3Pnts->PushButton2->setDown( false );
533     Group3Pnts->PushButton3->setDown( false );
534     Group3Pnts->LineEdit1->setEnabled( true );
535     Group3Pnts->LineEdit2->setEnabled( false );
536     Group3Pnts->LineEdit3->setEnabled( false );
537   }
538   else if ( send == Group3Pnts->PushButton2 ) {
539     myEditCurrentArgument = Group3Pnts->LineEdit2;
540     Group3Pnts->PushButton1->setDown( false );
541     Group3Pnts->PushButton3->setDown( false );
542     Group3Pnts->LineEdit1->setEnabled( false );
543     Group3Pnts->LineEdit2->setEnabled( true );
544     Group3Pnts->LineEdit3->setEnabled( false );
545   }
546   else if ( send == Group3Pnts->PushButton3 ) {
547     myEditCurrentArgument = Group3Pnts->LineEdit3;
548     Group3Pnts->PushButton1->setDown( false );
549     Group3Pnts->PushButton2->setDown( false );
550     Group3Pnts->LineEdit1->setEnabled( false );
551     Group3Pnts->LineEdit2->setEnabled( false );
552     Group3Pnts->LineEdit3->setEnabled( true );
553   }
554   else if ( send == GroupFace->PushButton1 ) {
555     myEditCurrentArgument = GroupFace->LineEdit1;
556     GroupFace->PushButton1->setDown( true );
557   } else if ( send == Group2Vec->PushButton1 ) {
558     myEditCurrentArgument = Group2Vec->LineEdit1;
559     Group2Vec->PushButton2->setDown( false );
560     Group2Vec->LineEdit1->setEnabled( true );
561     Group2Vec->LineEdit2->setEnabled( false );
562   } else if ( send == Group2Vec->PushButton2 ) {
563     myEditCurrentArgument = Group2Vec->LineEdit2;
564     Group2Vec->PushButton1->setDown( false );
565     Group2Vec->LineEdit1->setEnabled( false );
566     Group2Vec->LineEdit2->setEnabled( true );
567   } else if ( send == GroupLCS->PushButton1 ) {
568     myEditCurrentArgument = GroupLCS->LineEdit1;
569     GroupLCS->LineEdit1->setEnabled( true );
570   }
571
572   myEditCurrentArgument->setFocus();
573
574   if ( myEditCurrentArgument == GroupPntDir->LineEdit2 || 
575        myEditCurrentArgument == Group2Vec->LineEdit1   ||
576        myEditCurrentArgument == Group2Vec->LineEdit2 ) {
577     localSelection( GEOM::GEOM_Object::_nil(), TopAbs_EDGE );
578   } else if ( myEditCurrentArgument == GroupFace->LineEdit1 ) {
579     TColStd_MapOfInteger aMap;
580     aMap.Add( GEOM_PLANE );
581     aMap.Add( GEOM_MARKER );
582     globalSelection( aMap );
583   } else if ( myEditCurrentArgument == GroupLCS->LineEdit1 ) {
584     globalSelection( GEOM_MARKER );
585   }
586   else { // 3 Pnts
587     localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
588   }
589
590   //  SelectionIntoArgument();
591   myEditCurrentArgument->setFocus();
592   send->setDown(true);
593   displayPreview();
594 }
595
596
597 //=================================================================================
598 // function : ActivateThisDialog()
599 // purpose  :
600 //=================================================================================
601 void BasicGUI_PlaneDlg::ActivateThisDialog()
602 {
603   GEOMBase_Skeleton::ActivateThisDialog();
604   connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
605            this, SLOT( SelectionIntoArgument() ) );
606
607   ConstructorsClicked( getConstructorId() );
608   SelectionIntoArgument();
609 }
610
611 //=================================================================================
612 // function : DeactivateActiveDialog()
613 // purpose  : public slot to deactivate if active
614 //=================================================================================
615 void BasicGUI_PlaneDlg::DeactivateActiveDialog()
616 {
617   GEOMBase_Skeleton::DeactivateActiveDialog();
618 }
619
620 //=================================================================================
621 // function : enterEvent()
622 // purpose  :
623 //=================================================================================
624 void BasicGUI_PlaneDlg::enterEvent( QEvent* )
625 {
626   if ( !mainFrame()->GroupConstructors->isEnabled() )
627     ActivateThisDialog();
628 }
629
630
631 //=================================================================================
632 // function : ValueChangedInSpinBox()
633 // purpose  :
634 //=================================================================================
635 void BasicGUI_PlaneDlg::ValueChangedInSpinBox( double newValue )
636 {
637   displayPreview();
638 }
639
640 //=================================================================================
641 // function : getSize()
642 // purpose  :
643 //=================================================================================
644 double BasicGUI_PlaneDlg::getSize() const
645 {
646   switch ( getConstructorId() ) {
647   case 0 : return GroupPntDir->SpinBox_DX->value();
648   case 1 : return Group3Pnts->SpinBox_DX->value();
649   case 2 : return GroupFace->SpinBox_DX->value();
650   case 3 : return Group2Vec->SpinBox_DX->value();
651   case 4 : return GroupLCS->SpinBox_DX->value();
652   }
653   return 0.;
654 }
655
656 //=================================================================================
657 // function : getSize()
658 // purpose  :
659 //=================================================================================
660 QString BasicGUI_PlaneDlg::getSizeAsString() const
661 {
662   switch ( getConstructorId() ) {
663   case 0 : return GroupPntDir->SpinBox_DX->text();
664   case 1 : return Group3Pnts->SpinBox_DX->text();
665   case 2 : return GroupFace->SpinBox_DX->text();
666   case 3 : return Group2Vec->SpinBox_DX->text();
667   }
668   return QString();
669 }
670
671 //=================================================================================
672 // function : createOperation
673 // purpose  :
674 //=================================================================================
675 GEOM::GEOM_IOperations_ptr BasicGUI_PlaneDlg::createOperation()
676 {
677   return myGeomGUI->GetGeomGen()->GetIBasicOperations( getStudyId() );
678 }
679
680 //=================================================================================
681 // function : isValid
682 // purpose  :
683 //=================================================================================
684 bool BasicGUI_PlaneDlg::isValid( QString& msg )
685 {
686   bool ok = false;
687   if ( getSize() <= 0 ) {
688     msg = QString( "Please, enter size greater than 0." );
689   }
690   else {
691     switch ( getConstructorId() ) {
692     case 0:
693       ok = GroupPntDir->SpinBox_DX->isValid( msg, !IsPreview() ) && myPoint && myDir;
694       break;
695     case 1:
696       ok = Group3Pnts->SpinBox_DX->isValid( msg, !IsPreview() ) &&
697            myPoint1 && myPoint2 && myPoint3 &&
698            myPoint1 != myPoint2 && myPoint1 != myPoint3 && myPoint2 != myPoint3;
699       break;
700     case 2:
701       ok = GroupFace->SpinBox_DX->isValid( msg, !IsPreview() ) && myFace;
702       break;
703     case 3:
704       ok = Group2Vec->SpinBox_DX->isValid( msg, !IsPreview() ) &&
705            myVec1 && myVec2 && myVec1 != myVec2;
706       break;
707     case 4:
708       ok = GroupLCS->SpinBox_DX->isValid( msg, !IsPreview() );
709       break;
710     default:
711       break;
712     }
713   }
714   return ok;
715 }
716
717 //=================================================================================
718 // function : execute
719 // purpose  :
720 //=================================================================================
721 bool BasicGUI_PlaneDlg::execute( ObjectList& objects )
722 {
723   bool res = false;
724
725   GEOM::GEOM_Object_var anObj;
726
727   GEOM::GEOM_IBasicOperations_var anOper = GEOM::GEOM_IBasicOperations::_narrow( getOperation() );
728
729   switch ( getConstructorId() ) {
730   case 0 :
731     anObj = anOper->MakePlanePntVec( myPoint.get(), myDir.get(), getSize() );
732     res = true;
733     break;
734   case 1 :
735     anObj = anOper->MakePlaneThreePnt( myPoint1.get(), myPoint2.get(), myPoint3.get(), getSize() );
736     res = true;
737     break;
738   case 2 :
739     anObj = anOper->MakePlaneFace( myFace.get(), getSize() );
740     res = true;
741     break;
742   case 3 :
743     anObj = anOper->MakePlane2Vec( myVec1.get(), myVec2.get(), getSize() );
744     res = true;
745     break;
746   case 4 :
747     anObj = anOper->MakePlaneLCS( myLCS.get(), getSize(), myOriginType );
748     res = true;
749     break;
750   }
751   
752   if ( !anObj->_is_nil() ) {
753     if ( !IsPreview() )
754       anObj->SetParameters(getSizeAsString().toLatin1().constData());
755     objects.push_back( anObj._retn() );
756   }
757   return res;
758 }
759 //=================================================================================
760 // function : addSubshapeToStudy
761 // purpose  : virtual method to add new SubObjects if local selection
762 //=================================================================================
763 void BasicGUI_PlaneDlg::addSubshapesToStudy()
764 {
765   switch ( getConstructorId() ) {
766   case 0:
767     GEOMBase::PublishSubObject( myPoint.get() );
768     GEOMBase::PublishSubObject( myDir.get() );
769     break;
770   case 1:
771     GEOMBase::PublishSubObject( myPoint1.get() );
772     GEOMBase::PublishSubObject( myPoint2.get() );
773     GEOMBase::PublishSubObject( myPoint3.get() );
774     break;
775   case 2:
776     GEOMBase::PublishSubObject( myFace.get() );
777     break;
778   case 3:
779     GEOMBase::PublishSubObject( myVec1.get() );
780     GEOMBase::PublishSubObject( myVec2.get() );
781     break;
782   case 4:
783     GEOMBase::PublishSubObject( myLCS.get() );
784     break;
785  default:
786    break;
787   }
788 }