Salome HOME
3c18582039c4cf5f87acce48ebf07e94aa21a660
[modules/geom.git] / src / BasicGUI / BasicGUI_CircleDlg.cxx
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 //  This library is free software; you can redistribute it and/or
7 //  modify it under the terms of the GNU Lesser General Public
8 //  License as published by the Free Software Foundation; either
9 //  version 2.1 of the License.
10 //
11 //  This library is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 //  Lesser General Public License for more details.
15 //
16 //  You should have received a copy of the GNU Lesser General Public
17 //  License along with this library; if not, write to the Free Software
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 // GEOM GEOMGUI : GUI for Geometry component
23 // File   : BasicGUI_CircleDlg.cxx
24 // Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
25 //
26 #include "BasicGUI_CircleDlg.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_IndexedMapOfInteger.hxx>
39 #include <TopTools_IndexedMapOfShape.hxx>
40 #include <TopoDS_Shape.hxx>
41 #include <TopoDS_Edge.hxx>
42 #include <TopoDS.hxx>
43 #include <TopExp.hxx>
44
45 //=================================================================================
46 // class    : BasicGUI_CircleDlg()
47 // purpose  : Constructs a BasicGUI_CircleDlg which is a child of 'parent', with the 
48 //            name 'name' and widget flags set to 'f'.
49 //            The dialog will by default be modeless, unless you set 'modal' to
50 //            TRUE to construct a modal dialog.
51 //=================================================================================
52 BasicGUI_CircleDlg::BasicGUI_CircleDlg( GeometryGUI* theGeometryGUI, QWidget* parent,
53                                         bool modal, Qt::WindowFlags fl )
54   : GEOMBase_Skeleton( theGeometryGUI, parent, modal, fl )
55 {
56   QPixmap image0( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_CIRCLE_PV" ) ) );
57   QPixmap image2( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_CIRCLE_PNTS" ) ) );
58   QPixmap image3( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_CIRCLE_C2P" ) ) );
59   QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
60
61   setWindowTitle( tr( "GEOM_CIRCLE_TITLE" ) );
62
63   /***************************************************************/
64   mainFrame()->GroupConstructors->setTitle( tr( "GEOM_CIRCLE" ) );
65   mainFrame()->RadioButton1->setIcon( image0 );
66   mainFrame()->RadioButton2->setIcon( image2 );
67   mainFrame()->RadioButton3->setIcon( image3 );
68
69   GroupPntVecR = new DlgRef_2Sel1Spin( centralWidget() );
70   GroupPntVecR->GroupBox1->setTitle( tr( "GEOM_ARGUMENTS" ) );
71   
72   GroupPntVecR->TextLabel1->setText( tr( "GEOM_CENTER_POINT" ) + " (Origin by default)" );
73   GroupPntVecR->TextLabel2->setText( tr( "GEOM_VECTOR" ) + " (Z axis by default)" );
74   GroupPntVecR->TextLabel3->setText( tr( "GEOM_RADIUS" ) );
75   GroupPntVecR->PushButton1->setIcon( image1 );
76   GroupPntVecR->PushButton2->setIcon( image1 );
77   GroupPntVecR->PushButton1->setDown( true );
78
79   GroupPntVecR->LineEdit1->setReadOnly( true );
80   GroupPntVecR->LineEdit2->setReadOnly( true );
81
82   GroupPntVecR->LineEdit1->setEnabled( true );
83   GroupPntVecR->LineEdit2->setEnabled( false );
84
85   Group3Pnts = new DlgRef_3Sel( centralWidget() );
86
87   Group3Pnts->GroupBox1->setTitle( tr( "GEOM_3_POINTS" ) );
88   Group3Pnts->TextLabel1->setText( tr( "GEOM_POINT1" ) );
89   Group3Pnts->TextLabel2->setText( tr( "GEOM_POINT2" ) );
90   Group3Pnts->TextLabel3->setText( tr( "GEOM_POINT3" ) );
91   Group3Pnts->PushButton1->setIcon( image1 );
92   Group3Pnts->PushButton2->setIcon( image1 );
93   Group3Pnts->PushButton3->setIcon( image1 );
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   GroupCenter2Pnts = new DlgRef_3Sel( centralWidget() );
104   GroupCenter2Pnts->GroupBox1->setTitle( tr( "GEOM_CENTER_2POINTS" ) );
105   GroupCenter2Pnts->TextLabel1->setText( tr( "GEOM_CENTER_POINT" ) );
106   GroupCenter2Pnts->TextLabel2->setText( tr( "GEOM_POINT1" ) );
107   GroupCenter2Pnts->TextLabel3->setText( tr( "GEOM_POINT2" ) );
108   GroupCenter2Pnts->PushButton1->setIcon( image1 );
109   GroupCenter2Pnts->PushButton2->setIcon( image1 );
110   GroupCenter2Pnts->PushButton3->setIcon( image1 );
111   GroupCenter2Pnts->PushButton1->setDown( true );
112
113   GroupCenter2Pnts->LineEdit1->setReadOnly( true );
114   GroupCenter2Pnts->LineEdit2->setReadOnly( true );
115   GroupCenter2Pnts->LineEdit3->setReadOnly( true );
116
117   GroupCenter2Pnts->LineEdit1->setEnabled( true );
118   GroupCenter2Pnts->LineEdit2->setEnabled( false );
119   GroupCenter2Pnts->LineEdit3->setEnabled( false );
120
121   QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
122   layout->setMargin( 0 ); layout->setSpacing( 6 );
123   layout->addWidget( GroupPntVecR );
124   layout->addWidget( Group3Pnts );
125   layout->addWidget( GroupCenter2Pnts );
126   /***************************************************************/
127
128   setHelpFileName( "create_circle_page.html" );
129
130   Init();
131 }
132
133
134 //=================================================================================
135 // function : ~BasicGUI_CircleDlg()
136 // purpose  : Destroys the object and frees any allocated resources
137 //=================================================================================
138 BasicGUI_CircleDlg::~BasicGUI_CircleDlg()
139 {
140 }
141
142
143 //=================================================================================
144 // function : Init()
145 // purpose  :
146 //=================================================================================
147 void BasicGUI_CircleDlg::Init()
148 {
149   /* init variables */
150   myEditCurrentArgument = GroupPntVecR->LineEdit1;
151
152   myPoint = myDir = myPoint1 = myPoint2 = myPoint3 = GEOM::GEOM_Object::_nil();
153
154   // myGeomGUI->SetState( 0 );
155
156   /* Get setting of step value from file configuration */
157   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
158   double aStep = resMgr->doubleValue( "Geometry", "SettingsGeomStep", 100 );
159
160   /* min, max, step and decimals for spin boxes & initial values */
161   initSpinBox( GroupPntVecR->SpinBox_DX, 0.000001, COORD_MAX, aStep, 6 ); // VSR: TODO: DBL_DIGITS_DISPLAY
162   GroupPntVecR->SpinBox_DX->setValue( 100 );
163
164   /* signals and slots connections */
165   connect( myGeomGUI, SIGNAL( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) );
166   connect( myGeomGUI, SIGNAL( SignalCloseAllDialogs() ),        this, SLOT( ClickOnCancel() ) );
167   
168   connect( buttonOk(),     SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
169   connect( buttonApply(),  SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
170
171   connect( this,           SIGNAL( constructorsClicked( int ) ), this, SLOT( ConstructorsClicked( int ) ) );
172
173   connect( GroupPntVecR->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
174   connect( GroupPntVecR->PushButton2, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
175   connect( Group3Pnts->PushButton1,   SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
176   connect( Group3Pnts->PushButton2,   SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
177   connect( Group3Pnts->PushButton3,   SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
178
179   connect( GroupCenter2Pnts->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
180   connect( GroupCenter2Pnts->PushButton2, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
181   connect( GroupCenter2Pnts->PushButton3, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
182
183   connect( GroupPntVecR->LineEdit1, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
184   connect( GroupPntVecR->LineEdit2, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
185
186   connect( GroupPntVecR->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT(ValueChangedInSpinBox() ) );
187   connect( myGeomGUI, SIGNAL( SignalDefaultStepValueChanged( double ) ), this, SLOT( SetDoubleSpinBoxStep( double ) ) );
188
189   connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
190            this, SLOT( SelectionIntoArgument() ) );
191
192   initName( tr( "GEOM_CIRCLE" ) );
193
194   ConstructorsClicked( 0 );
195 }
196
197 //=================================================================================
198 // function : SetDoubleSpinBoxStep()
199 // purpose  : Double spin box management
200 //=================================================================================
201 void BasicGUI_CircleDlg::SetDoubleSpinBoxStep( double step )
202 {
203   GroupPntVecR->SpinBox_DX->setSingleStep(step);
204 }
205
206 //=================================================================================
207 // function : ConstructorsClicked()
208 // purpose  : Radio button management
209 //=================================================================================
210 void BasicGUI_CircleDlg::ConstructorsClicked( int constructorId )
211 {
212   disconnect( myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
213
214   myPoint = myDir = myPoint1 = myPoint2 = myPoint3 = GEOM::GEOM_Object::_nil();
215
216   switch ( constructorId ) {
217   case 0:
218     {
219       Group3Pnts->hide();
220       GroupCenter2Pnts->hide();
221       GroupPntVecR->show();
222       
223       myEditCurrentArgument = GroupPntVecR->LineEdit1;
224       GroupPntVecR->LineEdit1->setText( "" );
225       GroupPntVecR->LineEdit2->setText( "" );
226       GroupPntVecR->PushButton1->setDown( true );
227       GroupPntVecR->PushButton2->setDown( false );
228       GroupPntVecR->LineEdit1->setEnabled( true );
229       GroupPntVecR->LineEdit2->setEnabled( false );
230       break;
231     }
232   case 1:
233     {
234       GroupPntVecR->hide();
235       GroupCenter2Pnts->hide();
236       Group3Pnts->show();
237       
238       myEditCurrentArgument = Group3Pnts->LineEdit1;
239       Group3Pnts->LineEdit1->setText( "" );
240       Group3Pnts->LineEdit2->setText( "" );
241       Group3Pnts->LineEdit3->setText( "" );
242       Group3Pnts->PushButton1->setDown( true );
243       Group3Pnts->PushButton2->setDown( false );
244       Group3Pnts->PushButton3->setDown( false );
245       Group3Pnts->LineEdit1->setEnabled( true );
246       Group3Pnts->LineEdit2->setEnabled( false );
247       Group3Pnts->LineEdit3->setEnabled( false );
248       break;
249     }
250   case 2:
251     {
252       GroupPntVecR->hide();
253       Group3Pnts->hide();               
254       GroupCenter2Pnts->show();
255       
256       myEditCurrentArgument = GroupCenter2Pnts->LineEdit1;
257       GroupCenter2Pnts->LineEdit1->setText( "" );
258       GroupCenter2Pnts->LineEdit2->setText( "" );
259       GroupCenter2Pnts->LineEdit3->setText( "" );
260       GroupCenter2Pnts->PushButton1->setDown( true );
261       GroupCenter2Pnts->PushButton2->setDown( false );
262       GroupCenter2Pnts->PushButton3->setDown( false );
263       GroupCenter2Pnts->LineEdit1->setEnabled( true );
264       GroupCenter2Pnts->LineEdit2->setEnabled( false );
265       GroupCenter2Pnts->LineEdit3->setEnabled( false );
266       break;
267     }
268   }
269   
270   qApp->processEvents();
271   updateGeometry();
272   resize( minimumSizeHint() );
273
274   myEditCurrentArgument->setFocus();
275   globalSelection(); // close local contexts, if any
276   localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
277
278   connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged() ),
279            this, SLOT( SelectionIntoArgument() ) );
280
281   displayPreview();
282 }
283
284 //=================================================================================
285 // function : ClickOnOk()
286 // purpose  :
287 //=================================================================================
288 void BasicGUI_CircleDlg::ClickOnOk()
289 {
290   if ( ClickOnApply() )
291     ClickOnCancel();
292 }
293
294 //=================================================================================
295 // function : ClickOnApply()
296 // purpose  :
297 //=================================================================================
298 bool BasicGUI_CircleDlg::ClickOnApply()
299 {
300   if ( !onAccept() )
301     return false;
302
303   initName();
304   ConstructorsClicked( getConstructorId() );
305   return true;
306 }
307
308 //=================================================================================
309 // function : SelectionIntoArgument()
310 // purpose  : Called when selection as changed or other case
311 //=================================================================================
312 void BasicGUI_CircleDlg::SelectionIntoArgument()
313 {
314   myEditCurrentArgument->setText( "" );
315   
316   LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
317   SALOME_ListIO aList;
318   aSelMgr->selectedObjects( aList );
319
320   if ( aList.Extent() != 1 ) {
321     if      ( myEditCurrentArgument == GroupPntVecR->LineEdit1 )     myPoint  = GEOM::GEOM_Object::_nil();
322     else if ( myEditCurrentArgument == GroupPntVecR->LineEdit2 )     myDir    = GEOM::GEOM_Object::_nil();
323     else if ( myEditCurrentArgument == Group3Pnts->LineEdit1 )       myPoint1 = GEOM::GEOM_Object::_nil();
324     else if ( myEditCurrentArgument == Group3Pnts->LineEdit2 )       myPoint2 = GEOM::GEOM_Object::_nil();
325     else if ( myEditCurrentArgument == Group3Pnts->LineEdit3 )       myPoint3 = GEOM::GEOM_Object::_nil();
326     else if ( myEditCurrentArgument == GroupCenter2Pnts->LineEdit1 ) myPoint4 = GEOM::GEOM_Object::_nil();
327     else if ( myEditCurrentArgument == GroupCenter2Pnts->LineEdit2 ) myPoint5 = GEOM::GEOM_Object::_nil();
328     else if ( myEditCurrentArgument == GroupCenter2Pnts->LineEdit3 ) myPoint6 = GEOM::GEOM_Object::_nil();
329     return;
330   }
331
332   // nbSel == 1
333   Handle(SALOME_InteractiveObject) anIO = aList.First();
334
335   Standard_Boolean aRes = Standard_False;
336   GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject(anIO, aRes);
337   if ( !CORBA::is_nil( aSelectedObject ) && aRes ) {
338     QString aName = GEOMBase::GetName( aSelectedObject );
339
340     TopAbs_ShapeEnum aNeedType = TopAbs_VERTEX;
341     if ( myEditCurrentArgument == GroupPntVecR->LineEdit2 )
342       aNeedType = TopAbs_EDGE;
343
344     // If selected Vertex or Edge on the some Shape Get selection Subshape
345     TopoDS_Shape aShape;
346     if ( GEOMBase::GetShape( aSelectedObject, aShape, TopAbs_SHAPE ) && !aShape.IsNull() ) {
347       TColStd_IndexedMapOfInteger aMap;
348       aSelMgr->GetIndexes(anIO, aMap);
349       if ( aMap.Extent() == 1 ) { // Local Selection
350         int anIndex = aMap(1);
351         if ( aNeedType == TopAbs_EDGE )
352           aName += QString( ":edge_%1" ).arg( anIndex );
353         else
354           aName += QString( ":vertex_%1" ).arg( anIndex );
355
356         //Find SubShape Object in Father
357         GEOM::GEOM_Object_var aFindedObject = GEOMBase_Helper::findObjectInFather( aSelectedObject, aName );
358
359         if ( aFindedObject == GEOM::GEOM_Object::_nil() ) { // Object not found in study
360           GEOM::GEOM_IShapesOperations_var aShapesOp = getGeomEngine()->GetIShapesOperations( getStudyId() );
361           aSelectedObject = aShapesOp->GetSubShape( aSelectedObject, anIndex );
362         }
363         else {
364           aSelectedObject = aFindedObject; // get Object from study
365         }
366       }
367       else { // Global Selection
368         if ( aShape.ShapeType() != aNeedType ) {
369           aSelectedObject = GEOM::GEOM_Object::_nil();
370           aName = "";
371         }
372       }
373     }
374     
375     myEditCurrentArgument->setText( aName );
376
377     if (!aSelectedObject->_is_nil()) { // clear selection if something selected
378       globalSelection();
379       localSelection( GEOM::GEOM_Object::_nil(), aNeedType );
380     }
381
382     if      ( myEditCurrentArgument == GroupPntVecR->LineEdit1 ) {
383       myPoint  = aSelectedObject;
384       if ( !myPoint->_is_nil() && myDir->_is_nil() )
385         GroupPntVecR->PushButton2->click();
386     }
387     else if ( myEditCurrentArgument == GroupPntVecR->LineEdit2 ) {
388       myDir    = aSelectedObject;
389       if ( !myDir->_is_nil() && myPoint->_is_nil() )
390         GroupPntVecR->PushButton1->click();
391     }
392     else if ( myEditCurrentArgument == Group3Pnts->LineEdit1 ) {
393       myPoint1 = aSelectedObject;
394       if ( !myPoint1->_is_nil() && myPoint2->_is_nil() )
395         Group3Pnts->PushButton2->click();
396     }
397     else if ( myEditCurrentArgument == Group3Pnts->LineEdit2 ) {
398       myPoint2 = aSelectedObject;
399       if ( !myPoint2->_is_nil() && myPoint3->_is_nil() )
400         Group3Pnts->PushButton3->click();
401     }
402     else if ( myEditCurrentArgument == Group3Pnts->LineEdit3 ) {
403       myPoint3 = aSelectedObject;
404       if ( !myPoint3->_is_nil() && myPoint1->_is_nil() )
405         Group3Pnts->PushButton1->click();
406     }
407     else if ( myEditCurrentArgument == GroupCenter2Pnts->LineEdit1 ) {
408       myPoint4 = aSelectedObject;
409       if ( !myPoint4->_is_nil() && myPoint5->_is_nil() )
410         GroupCenter2Pnts->PushButton2->click();
411     }
412     else if ( myEditCurrentArgument == GroupCenter2Pnts->LineEdit2 ) {
413       myPoint5 = aSelectedObject;
414       if ( !myPoint5->_is_nil() && myPoint6->_is_nil() )
415         GroupCenter2Pnts->PushButton3->click();
416     }
417     else if ( myEditCurrentArgument == GroupCenter2Pnts->LineEdit3 ) {
418       myPoint6 = aSelectedObject;
419       if ( !myPoint6->_is_nil() && myPoint4->_is_nil() )
420         GroupCenter2Pnts->PushButton1->click();
421     }
422   }
423
424   displayPreview();
425 }
426
427
428 //=================================================================================
429 // function : SetEditCurrentArgument()
430 // purpose  :
431 //=================================================================================
432 void BasicGUI_CircleDlg::SetEditCurrentArgument()
433 {
434   QPushButton* send = (QPushButton*)sender();
435
436   if ( send == GroupPntVecR->PushButton1 ) {
437     myEditCurrentArgument = GroupPntVecR->LineEdit1;
438     GroupPntVecR->PushButton2->setDown(false);
439     GroupPntVecR->LineEdit1->setEnabled( true );
440     GroupPntVecR->LineEdit2->setEnabled( false );
441   }
442   else if ( send == GroupPntVecR->PushButton2 ) {
443     myEditCurrentArgument = GroupPntVecR->LineEdit2;
444     GroupPntVecR->PushButton1->setDown(false);
445     GroupPntVecR->LineEdit1->setEnabled( false );
446     GroupPntVecR->LineEdit2->setEnabled( true );
447   }
448   else if ( send == Group3Pnts->PushButton1 ) {
449     myEditCurrentArgument = Group3Pnts->LineEdit1;
450     Group3Pnts->PushButton2->setDown( false );
451     Group3Pnts->PushButton3->setDown( false );
452     Group3Pnts->LineEdit1->setEnabled( true );
453     Group3Pnts->LineEdit2->setEnabled( false );
454     Group3Pnts->LineEdit3->setEnabled( false );
455   }
456   else if ( send == Group3Pnts->PushButton2 )  {
457     myEditCurrentArgument = Group3Pnts->LineEdit2;
458     Group3Pnts->PushButton1->setDown( false );
459     Group3Pnts->PushButton3->setDown( false );
460     Group3Pnts->LineEdit1->setEnabled( false );
461     Group3Pnts->LineEdit2->setEnabled( true );
462     Group3Pnts->LineEdit3->setEnabled( false );
463   }
464   else if ( send == Group3Pnts->PushButton3 ) {
465     myEditCurrentArgument = Group3Pnts->LineEdit3;
466     Group3Pnts->PushButton1->setDown( false );
467     Group3Pnts->PushButton2->setDown( false );
468     Group3Pnts->LineEdit1->setEnabled( false );
469     Group3Pnts->LineEdit2->setEnabled( false );
470     Group3Pnts->LineEdit3->setEnabled( true );
471   }
472   else if ( send == GroupCenter2Pnts->PushButton1 ) {
473     myEditCurrentArgument = GroupCenter2Pnts->LineEdit1;
474     GroupCenter2Pnts->PushButton2->setDown( false );
475     GroupCenter2Pnts->PushButton3->setDown( false );
476     GroupCenter2Pnts->LineEdit1->setEnabled( true );
477     GroupCenter2Pnts->LineEdit2->setEnabled( false );
478     GroupCenter2Pnts->LineEdit3->setEnabled( false );
479   }
480   else if ( send == GroupCenter2Pnts->PushButton2 ) {
481     myEditCurrentArgument = GroupCenter2Pnts->LineEdit2;
482     GroupCenter2Pnts->PushButton1->setDown( false );
483     GroupCenter2Pnts->PushButton3->setDown( false );
484     GroupCenter2Pnts->LineEdit1->setEnabled( false );
485     GroupCenter2Pnts->LineEdit2->setEnabled( true );
486     GroupCenter2Pnts->LineEdit3->setEnabled( false );
487     
488   }
489   else if ( send == GroupCenter2Pnts->PushButton3 ) {
490     myEditCurrentArgument = GroupCenter2Pnts->LineEdit3;
491     GroupCenter2Pnts->PushButton1->setDown( false );
492     GroupCenter2Pnts->PushButton2->setDown( false );
493     GroupCenter2Pnts->LineEdit1->setEnabled( false );
494     GroupCenter2Pnts->LineEdit2->setEnabled( false );
495     GroupCenter2Pnts->LineEdit3->setEnabled( true );
496   }
497
498   
499   myEditCurrentArgument->setFocus();
500
501   if ( myEditCurrentArgument == GroupPntVecR->LineEdit2 ) {
502     globalSelection(); // close local contexts, if any
503     localSelection( GEOM::GEOM_Object::_nil(), TopAbs_EDGE );
504   }
505   else {
506     globalSelection(); // close local contexts, if any
507     localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
508   }
509
510   myEditCurrentArgument->setFocus();
511   //  SelectionIntoArgument();
512   send->setDown(true);
513   displayPreview();
514 }
515
516 //=================================================================================
517 // function : LineEditReturnPressed()
518 // purpose  :
519 //=================================================================================
520 void BasicGUI_CircleDlg::LineEditReturnPressed()
521 {
522   QLineEdit* send = (QLineEdit*)sender();
523   if ( send == GroupPntVecR->LineEdit1 ||
524        send == GroupPntVecR->LineEdit2 ||
525        send == Group3Pnts->LineEdit1 ||
526        send == Group3Pnts->LineEdit2 ||
527        send == Group3Pnts->LineEdit3 ||
528        send == GroupCenter2Pnts->LineEdit1 ||
529        send == GroupCenter2Pnts->LineEdit2 ||
530        send == GroupCenter2Pnts->LineEdit3 ) {
531     myEditCurrentArgument = send;
532     GEOMBase_Skeleton::LineEditReturnPressed();
533   }
534 }
535
536
537 //=================================================================================
538 // function : ActivateThisDialog()
539 // purpose  :
540 //=================================================================================
541 void BasicGUI_CircleDlg::ActivateThisDialog()
542 {
543   GEOMBase_Skeleton::ActivateThisDialog();
544
545   connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
546            this, SLOT( SelectionIntoArgument() ) );
547
548   ConstructorsClicked( getConstructorId() );
549 }
550
551
552 //=================================================================================
553 // function : enterEvent()
554 // purpose  :
555 //=================================================================================
556 void BasicGUI_CircleDlg::enterEvent( QEvent* )
557 {
558   if ( !mainFrame()->GroupConstructors->isEnabled() )
559     ActivateThisDialog();
560 }
561
562 //=================================================================================
563 // function : DeactivateActiveDialog()
564 // purpose  : public slot to deactivate if active
565 //=================================================================================
566 void BasicGUI_CircleDlg::DeactivateActiveDialog()
567 {
568   // myGeomGUI->SetState( -1 );
569   GEOMBase_Skeleton::DeactivateActiveDialog();
570 }
571
572 //=================================================================================
573 // function : ValueChangedInSpinBox()
574 // purpose  :
575 //=================================================================================
576 void BasicGUI_CircleDlg::ValueChangedInSpinBox()
577 {
578   displayPreview();
579 }
580
581 //=================================================================================
582 // function : getRadius()
583 // purpose  :
584 //=================================================================================
585 double BasicGUI_CircleDlg::getRadius() const
586 {
587   double r = 0.;
588   switch ( getConstructorId() ) {
589   case 0:
590     r = GroupPntVecR->SpinBox_DX->value(); break;
591   }
592   return r;
593 }
594
595 //=================================================================================
596 // function : createOperation
597 // purpose  :
598 //=================================================================================
599 GEOM::GEOM_IOperations_ptr BasicGUI_CircleDlg::createOperation()
600 {
601   return myGeomGUI->GetGeomGen()->GetICurvesOperations( getStudyId() );
602 }
603
604 //=================================================================================
605 // function : isEqual
606 // purpose  : it may also be needed to check for min distance between gp_Pnt-s...
607 //=================================================================================
608 static bool isEqual( const GEOM::GEOM_Object_var& thePnt1, const GEOM::GEOM_Object_var& thePnt2 )
609 {
610   return thePnt1->_is_equivalent( thePnt2 );
611 }
612
613 //=================================================================================
614 // function : isValid
615 // purpose  :
616 //=================================================================================
617 bool BasicGUI_CircleDlg::isValid( QString& msg )
618 {
619   const int id = getConstructorId();
620   if ( id == 0 ) {
621     //return !myPoint->_is_nil() && !myDir->_is_nil() && getRadius() > 0;
622     //nil point means origin of global CS
623     //nil vector means Z axis
624     bool ok = GroupPntVecR->SpinBox_DX->isValid(msg, !IsPreview());
625     return getRadius() > 0 && ok;
626   }
627   else if ( id == 1 )
628     return !myPoint1->_is_nil() && !myPoint2->_is_nil() && !myPoint3->_is_nil() &&
629       !isEqual( myPoint1, myPoint2 ) && !isEqual( myPoint1, myPoint3 ) && !isEqual( myPoint2, myPoint3 );
630   else if ( id == 2 )
631     return !myPoint4->_is_nil() && !myPoint5->_is_nil() && !myPoint6->_is_nil() &&
632       !isEqual( myPoint4, myPoint5 ) && !isEqual( myPoint5, myPoint6 ) && !isEqual( myPoint4, myPoint6 );
633   return false;
634 }
635
636 //=================================================================================
637 // function : execute
638 // purpose  :
639 //=================================================================================
640 bool BasicGUI_CircleDlg::execute( ObjectList& objects )
641 {
642   bool res = false;
643   
644   GEOM::GEOM_Object_var anObj;
645   
646   switch ( getConstructorId() ) {
647   case 0 :
648     {
649       QStringList aParameters;
650       aParameters << GroupPntVecR->SpinBox_DX->text();
651       anObj = GEOM::GEOM_ICurvesOperations::_narrow( getOperation() )->MakeCirclePntVecR( myPoint, myDir, getRadius() );
652       if ( !anObj->_is_nil() && !IsPreview() )
653         anObj->SetParameters(GeometryGUI::JoinObjectParameters(aParameters));
654       res = true;
655       break;
656     }
657   case 1 :
658     anObj = GEOM::GEOM_ICurvesOperations::_narrow( getOperation() )->MakeCircleThreePnt( myPoint1, myPoint2, myPoint3 );
659     res = true;
660     break;
661   case 2:
662     anObj = GEOM::GEOM_ICurvesOperations::_narrow( getOperation() )->MakeCircleCenter2Pnt( myPoint4, myPoint5, myPoint6 );
663     res = true;
664     break;
665   }
666   
667   if ( !anObj->_is_nil() )
668     objects.push_back( anObj._retn() );
669   else {
670     MESSAGE( "Execute Object is NULL!" );
671   }
672   
673   return res;
674 }
675
676 //=================================================================================
677 // function : addSubshapeToStudy
678 // purpose  : virtual method to add new SubObjects if local selection
679 //=================================================================================
680 void BasicGUI_CircleDlg::addSubshapesToStudy()
681 {
682   QMap<QString, GEOM::GEOM_Object_var> objMap;
683
684   switch ( getConstructorId() ) {
685   case 0:
686     if (!CORBA::is_nil(myPoint))
687       objMap[GroupPntVecR->LineEdit1->text()] = myPoint;
688     if (!CORBA::is_nil(myDir))
689       objMap[GroupPntVecR->LineEdit2->text()] = myDir;
690     break;
691   case 1:
692     objMap[Group3Pnts->LineEdit1->text()] = myPoint1;
693     objMap[Group3Pnts->LineEdit2->text()] = myPoint2;
694     objMap[Group3Pnts->LineEdit3->text()] = myPoint3;
695     break;
696   case 2:
697     objMap[GroupCenter2Pnts->LineEdit1->text()] = myPoint4;
698     objMap[GroupCenter2Pnts->LineEdit2->text()] = myPoint5;
699     objMap[GroupCenter2Pnts->LineEdit3->text()] = myPoint6;
700     break;
701   }
702   addSubshapesToFather( objMap );
703 }