Salome HOME
fcb55f8e277e71da82591e02e1add40dc4a8bcdc
[modules/geom.git] / src / BasicGUI / BasicGUI_CircleDlg.cxx
1 // Copyright (C) 2007-2023  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, or (at your option) any later version.
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_CircleDlg.cxx
25 // Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
26 //
27 #include "BasicGUI_CircleDlg.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 #include "utilities.h"
39
40 #include <TopTools_IndexedMapOfShape.hxx>
41 #include <TopoDS_Shape.hxx>
42 #include <TopoDS_Edge.hxx>
43 #include <TopoDS.hxx>
44 #include <TopExp.hxx>
45
46 //=================================================================================
47 // class    : BasicGUI_CircleDlg()
48 // purpose  : Constructs a BasicGUI_CircleDlg which is a child of 'parent', with the 
49 //            name 'name' and widget flags set to 'f'.
50 //            The dialog will by default be modeless, unless you set 'modal' to
51 //            TRUE to construct a modal dialog.
52 //=================================================================================
53 BasicGUI_CircleDlg::BasicGUI_CircleDlg( GeometryGUI* theGeometryGUI, QWidget* parent,
54                                         bool modal, Qt::WindowFlags fl )
55   : GEOMBase_Skeleton( theGeometryGUI, parent, modal, fl )
56 {
57   QPixmap image0( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_CIRCLE_PV" ) ) );
58   QPixmap image2( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_CIRCLE_PNTS" ) ) );
59   QPixmap image3( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_CIRCLE_C2P" ) ) );
60   QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
61
62   setWindowTitle( tr( "GEOM_CIRCLE_TITLE" ) );
63
64   /***************************************************************/
65   mainFrame()->GroupConstructors->setTitle( tr( "GEOM_CIRCLE" ) );
66   mainFrame()->RadioButton1->setIcon( image0 );
67   mainFrame()->RadioButton2->setIcon( image2 );
68   mainFrame()->RadioButton3->setIcon( image3 );
69
70   GroupPntVecR = new DlgRef_2Sel1Spin( centralWidget() );
71   GroupPntVecR->GroupBox1->setTitle( tr( "GEOM_ARGUMENTS" ) );
72   
73   GroupPntVecR->TextLabel1->setText( tr( "GEOM_CENTER_POINT" ) + " " + tr( "GEOM_CENTER_DEFAULT" )  );
74   GroupPntVecR->TextLabel2->setText( tr( "GEOM_VECTOR" ) + " " + tr( "GEOM_AXIS_DEFAULT" ) );
75   GroupPntVecR->TextLabel3->setText( tr( "GEOM_RADIUS" ) );
76   GroupPntVecR->PushButton1->setIcon( image1 );
77   GroupPntVecR->PushButton2->setIcon( image1 );
78   GroupPntVecR->PushButton1->setDown( true );
79
80   GroupPntVecR->LineEdit1->setReadOnly( true );
81   GroupPntVecR->LineEdit2->setReadOnly( true );
82
83   GroupPntVecR->LineEdit1->setEnabled( true );
84   GroupPntVecR->LineEdit2->setEnabled( false );
85
86   Group3Pnts = new DlgRef_3Sel( centralWidget() );
87
88   Group3Pnts->GroupBox1->setTitle( tr( "GEOM_3_POINTS" ) );
89   Group3Pnts->TextLabel1->setText( tr( "GEOM_POINT1" ) );
90   Group3Pnts->TextLabel2->setText( tr( "GEOM_POINT2" ) );
91   Group3Pnts->TextLabel3->setText( tr( "GEOM_POINT3" ) );
92   Group3Pnts->PushButton1->setIcon( image1 );
93   Group3Pnts->PushButton2->setIcon( image1 );
94   Group3Pnts->PushButton3->setIcon( image1 );
95   Group3Pnts->PushButton1->setDown( true );
96
97   Group3Pnts->LineEdit1->setReadOnly( true );
98   Group3Pnts->LineEdit2->setReadOnly( true );
99   Group3Pnts->LineEdit3->setReadOnly( true );
100   Group3Pnts->LineEdit1->setEnabled( true );
101   Group3Pnts->LineEdit2->setEnabled( false );
102   Group3Pnts->LineEdit3->setEnabled( false );
103
104   GroupCenter2Pnts = new DlgRef_3Sel( centralWidget() );
105   GroupCenter2Pnts->GroupBox1->setTitle( tr( "GEOM_CENTER_2POINTS" ) );
106   GroupCenter2Pnts->TextLabel1->setText( tr( "GEOM_CENTER_POINT" ) );
107   GroupCenter2Pnts->TextLabel2->setText( tr( "GEOM_POINT1" ) );
108   GroupCenter2Pnts->TextLabel3->setText( tr( "GEOM_POINT2" ) );
109   GroupCenter2Pnts->PushButton1->setIcon( image1 );
110   GroupCenter2Pnts->PushButton2->setIcon( image1 );
111   GroupCenter2Pnts->PushButton3->setIcon( image1 );
112   GroupCenter2Pnts->PushButton1->setDown( true );
113
114   GroupCenter2Pnts->LineEdit1->setReadOnly( true );
115   GroupCenter2Pnts->LineEdit2->setReadOnly( true );
116   GroupCenter2Pnts->LineEdit3->setReadOnly( true );
117
118   GroupCenter2Pnts->LineEdit1->setEnabled( true );
119   GroupCenter2Pnts->LineEdit2->setEnabled( false );
120   GroupCenter2Pnts->LineEdit3->setEnabled( false );
121
122   QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
123   layout->setMargin( 0 ); layout->setSpacing( 6 );
124   layout->addWidget( GroupPntVecR );
125   layout->addWidget( Group3Pnts );
126   layout->addWidget( GroupCenter2Pnts );
127   /***************************************************************/
128
129   setHelpFileName( "create_circle_page.html" );
130
131   Init();
132 }
133
134
135 //=================================================================================
136 // function : ~BasicGUI_CircleDlg()
137 // purpose  : Destroys the object and frees any allocated resources
138 //=================================================================================
139 BasicGUI_CircleDlg::~BasicGUI_CircleDlg()
140 {
141 }
142
143
144 //=================================================================================
145 // function : Init()
146 // purpose  :
147 //=================================================================================
148 void BasicGUI_CircleDlg::Init()
149 {
150   /* init variables */
151   myEditCurrentArgument = GroupPntVecR->LineEdit1;
152
153   myPoint.nullify();
154   myDir.nullify();
155   myPoint1.nullify();
156   myPoint2.nullify();
157   myPoint3.nullify();
158   myPoint4.nullify();
159   myPoint5.nullify();
160   myPoint6.nullify();
161
162   /* Get setting of step value from file configuration */
163   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
164   double aStep = resMgr->doubleValue( "Geometry", "SettingsGeomStep", 100 );
165
166   /* min, max, step and decimals for spin boxes & initial values */
167   initSpinBox( GroupPntVecR->SpinBox_DX, 0.000001, COORD_MAX, aStep, "length_precision" );
168   GroupPntVecR->SpinBox_DX->setValue( 100 );
169
170   /* signals and slots connections */
171   connect( myGeomGUI, SIGNAL( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) );
172   connect( myGeomGUI, SIGNAL( SignalCloseAllDialogs() ),        this, SLOT( ClickOnCancel() ) );
173   
174   connect( buttonOk(),     SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
175   connect( buttonApply(),  SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
176
177   connect( this,           SIGNAL( constructorsClicked( int ) ), this, SLOT( ConstructorsClicked( int ) ) );
178
179   connect( GroupPntVecR->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
180   connect( GroupPntVecR->PushButton2, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
181   connect( Group3Pnts->PushButton1,   SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
182   connect( Group3Pnts->PushButton2,   SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
183   connect( Group3Pnts->PushButton3,   SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
184
185   connect( GroupCenter2Pnts->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
186   connect( GroupCenter2Pnts->PushButton2, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
187   connect( GroupCenter2Pnts->PushButton3, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
188
189   connect( GroupPntVecR->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT(ValueChangedInSpinBox() ) );
190   connect( myGeomGUI, SIGNAL( SignalDefaultStepValueChanged( double ) ), this, SLOT( SetDoubleSpinBoxStep( double ) ) );
191
192   connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
193            this, SLOT( SelectionIntoArgument() ) );
194
195   initName( tr( "GEOM_CIRCLE" ) );
196
197   ConstructorsClicked( 0 );
198 }
199
200 //=================================================================================
201 // function : SetDoubleSpinBoxStep()
202 // purpose  : Double spin box management
203 //=================================================================================
204 void BasicGUI_CircleDlg::SetDoubleSpinBoxStep( double step )
205 {
206   GroupPntVecR->SpinBox_DX->setSingleStep(step);
207 }
208
209 //=================================================================================
210 // function : ConstructorsClicked()
211 // purpose  : Radio button management
212 //=================================================================================
213 void BasicGUI_CircleDlg::ConstructorsClicked( int constructorId )
214 {
215   disconnect( myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
216
217   myPoint.nullify();
218   myDir.nullify();
219   myPoint1.nullify();
220   myPoint2.nullify();
221   myPoint3.nullify();
222   myPoint4.nullify();
223   myPoint5.nullify();
224   myPoint6.nullify();
225
226   switch ( constructorId ) {
227   case 0:
228     {
229       Group3Pnts->hide();
230       GroupCenter2Pnts->hide();
231       GroupPntVecR->show();
232       
233       myEditCurrentArgument = GroupPntVecR->LineEdit1;
234       GroupPntVecR->LineEdit1->setText( "" );
235       GroupPntVecR->LineEdit2->setText( "" );
236       GroupPntVecR->PushButton1->setDown( true );
237       GroupPntVecR->PushButton2->setDown( false );
238       GroupPntVecR->LineEdit1->setEnabled( true );
239       GroupPntVecR->LineEdit2->setEnabled( false );
240       break;
241     }
242   case 1:
243     {
244       GroupPntVecR->hide();
245       GroupCenter2Pnts->hide();
246       Group3Pnts->show();
247       
248       myEditCurrentArgument = Group3Pnts->LineEdit1;
249       Group3Pnts->LineEdit1->setText( "" );
250       Group3Pnts->LineEdit2->setText( "" );
251       Group3Pnts->LineEdit3->setText( "" );
252       Group3Pnts->PushButton1->setDown( true );
253       Group3Pnts->PushButton2->setDown( false );
254       Group3Pnts->PushButton3->setDown( false );
255       Group3Pnts->LineEdit1->setEnabled( true );
256       Group3Pnts->LineEdit2->setEnabled( false );
257       Group3Pnts->LineEdit3->setEnabled( false );
258       break;
259     }
260   case 2:
261     {
262       GroupPntVecR->hide();
263       Group3Pnts->hide();               
264       GroupCenter2Pnts->show();
265       
266       myEditCurrentArgument = GroupCenter2Pnts->LineEdit1;
267       GroupCenter2Pnts->LineEdit1->setText( "" );
268       GroupCenter2Pnts->LineEdit2->setText( "" );
269       GroupCenter2Pnts->LineEdit3->setText( "" );
270       GroupCenter2Pnts->PushButton1->setDown( true );
271       GroupCenter2Pnts->PushButton2->setDown( false );
272       GroupCenter2Pnts->PushButton3->setDown( false );
273       GroupCenter2Pnts->LineEdit1->setEnabled( true );
274       GroupCenter2Pnts->LineEdit2->setEnabled( false );
275       GroupCenter2Pnts->LineEdit3->setEnabled( false );
276       break;
277     }
278   }
279   
280   qApp->processEvents();
281   updateGeometry();
282   resize( minimumSizeHint() );
283
284   myEditCurrentArgument->setFocus();
285   globalSelection(); // close local contexts, if any
286   localSelection( TopAbs_VERTEX );
287
288   connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged() ),
289            this, SLOT( SelectionIntoArgument() ) );
290
291   SelectionIntoArgument();
292 }
293
294 //=================================================================================
295 // function : ClickOnOk()
296 // purpose  :
297 //=================================================================================
298 void BasicGUI_CircleDlg::ClickOnOk()
299 {
300   setIsApplyAndClose( true );
301   if ( ClickOnApply() )
302     ClickOnCancel();
303 }
304
305 //=================================================================================
306 // function : ClickOnApply()
307 // purpose  :
308 //=================================================================================
309 bool BasicGUI_CircleDlg::ClickOnApply()
310 {
311   if ( !onAccept() )
312     return false;
313
314   initName();
315   ConstructorsClicked( getConstructorId() );
316   return true;
317 }
318
319 //=================================================================================
320 // function : SelectionIntoArgument()
321 // purpose  : Called when selection as changed or other case
322 //=================================================================================
323 void BasicGUI_CircleDlg::SelectionIntoArgument()
324 {
325   myEditCurrentArgument->setText( "" );
326   
327   LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
328   SALOME_ListIO aList;
329   aSelMgr->selectedObjects( aList );
330
331   if ( aList.Extent() != 1 ) {
332     if      ( myEditCurrentArgument == GroupPntVecR->LineEdit1 )     myPoint.nullify();
333     else if ( myEditCurrentArgument == GroupPntVecR->LineEdit2 )     myDir.nullify();
334     else if ( myEditCurrentArgument == Group3Pnts->LineEdit1 )       myPoint1.nullify();
335     else if ( myEditCurrentArgument == Group3Pnts->LineEdit2 )       myPoint2.nullify();
336     else if ( myEditCurrentArgument == Group3Pnts->LineEdit3 )       myPoint3.nullify();
337     else if ( myEditCurrentArgument == GroupCenter2Pnts->LineEdit1 ) myPoint4.nullify();
338     else if ( myEditCurrentArgument == GroupCenter2Pnts->LineEdit2 ) myPoint5.nullify();
339     else if ( myEditCurrentArgument == GroupCenter2Pnts->LineEdit3 ) myPoint6.nullify();
340     return;
341   }
342
343   TopAbs_ShapeEnum aNeedType = ( myEditCurrentArgument == GroupPntVecR->LineEdit2 ) ?
344     TopAbs_EDGE : TopAbs_VERTEX;
345   GEOM::GeomObjPtr aSelectedObject = getSelected( aNeedType );
346   TopoDS_Shape aShape;
347   if ( aSelectedObject && GEOMBase::GetShape( aSelectedObject.get(), aShape ) && !aShape.IsNull() ) {
348     QString aName = GEOMBase::GetName( aSelectedObject.get() );
349     
350     myEditCurrentArgument->setText( aName );
351
352     if      ( myEditCurrentArgument == GroupPntVecR->LineEdit1 ) {
353       myPoint  = aSelectedObject;
354       if ( myPoint && !myDir )
355         GroupPntVecR->PushButton2->click();
356     }
357     else if ( myEditCurrentArgument == GroupPntVecR->LineEdit2 ) {
358       myDir    = aSelectedObject;
359       if ( myDir && !myPoint )
360         GroupPntVecR->PushButton1->click();
361     }
362     else if ( myEditCurrentArgument == Group3Pnts->LineEdit1 ) {
363       myPoint1 = aSelectedObject;
364       if ( myPoint1 && !myPoint2 )
365         Group3Pnts->PushButton2->click();
366     }
367     else if ( myEditCurrentArgument == Group3Pnts->LineEdit2 ) {
368       myPoint2 = aSelectedObject;
369       if ( myPoint2 && !myPoint3 )
370         Group3Pnts->PushButton3->click();
371     }
372     else if ( myEditCurrentArgument == Group3Pnts->LineEdit3 ) {
373       myPoint3 = aSelectedObject;
374       if ( myPoint3 && !myPoint1 )
375         Group3Pnts->PushButton1->click();
376     }
377     else if ( myEditCurrentArgument == GroupCenter2Pnts->LineEdit1 ) {
378       myPoint4 = aSelectedObject;
379       if ( myPoint4 && !myPoint5 )
380         GroupCenter2Pnts->PushButton2->click();
381     }
382     else if ( myEditCurrentArgument == GroupCenter2Pnts->LineEdit2 ) {
383       myPoint5 = aSelectedObject;
384       if ( myPoint5 && !myPoint6 )
385         GroupCenter2Pnts->PushButton3->click();
386     }
387     else if ( myEditCurrentArgument == GroupCenter2Pnts->LineEdit3 ) {
388       myPoint6 = aSelectedObject;
389       if ( myPoint6 && !myPoint4 )
390         GroupCenter2Pnts->PushButton1->click();
391     }
392   }
393
394   displayPreview(true);
395 }
396
397
398 //=================================================================================
399 // function : SetEditCurrentArgument()
400 // purpose  :
401 //=================================================================================
402 void BasicGUI_CircleDlg::SetEditCurrentArgument()
403 {
404   QPushButton* send = (QPushButton*)sender();
405
406   if ( send == GroupPntVecR->PushButton1 ) {
407     myEditCurrentArgument = GroupPntVecR->LineEdit1;
408     GroupPntVecR->PushButton2->setDown(false);
409     GroupPntVecR->LineEdit1->setEnabled( true );
410     GroupPntVecR->LineEdit2->setEnabled( false );
411   }
412   else if ( send == GroupPntVecR->PushButton2 ) {
413     myEditCurrentArgument = GroupPntVecR->LineEdit2;
414     GroupPntVecR->PushButton1->setDown(false);
415     GroupPntVecR->LineEdit1->setEnabled( false );
416     GroupPntVecR->LineEdit2->setEnabled( true );
417   }
418   else if ( send == Group3Pnts->PushButton1 ) {
419     myEditCurrentArgument = Group3Pnts->LineEdit1;
420     Group3Pnts->PushButton2->setDown( false );
421     Group3Pnts->PushButton3->setDown( false );
422     Group3Pnts->LineEdit1->setEnabled( true );
423     Group3Pnts->LineEdit2->setEnabled( false );
424     Group3Pnts->LineEdit3->setEnabled( false );
425   }
426   else if ( send == Group3Pnts->PushButton2 )  {
427     myEditCurrentArgument = Group3Pnts->LineEdit2;
428     Group3Pnts->PushButton1->setDown( false );
429     Group3Pnts->PushButton3->setDown( false );
430     Group3Pnts->LineEdit1->setEnabled( false );
431     Group3Pnts->LineEdit2->setEnabled( true );
432     Group3Pnts->LineEdit3->setEnabled( false );
433   }
434   else if ( send == Group3Pnts->PushButton3 ) {
435     myEditCurrentArgument = Group3Pnts->LineEdit3;
436     Group3Pnts->PushButton1->setDown( false );
437     Group3Pnts->PushButton2->setDown( false );
438     Group3Pnts->LineEdit1->setEnabled( false );
439     Group3Pnts->LineEdit2->setEnabled( false );
440     Group3Pnts->LineEdit3->setEnabled( true );
441   }
442   else if ( send == GroupCenter2Pnts->PushButton1 ) {
443     myEditCurrentArgument = GroupCenter2Pnts->LineEdit1;
444     GroupCenter2Pnts->PushButton2->setDown( false );
445     GroupCenter2Pnts->PushButton3->setDown( false );
446     GroupCenter2Pnts->LineEdit1->setEnabled( true );
447     GroupCenter2Pnts->LineEdit2->setEnabled( false );
448     GroupCenter2Pnts->LineEdit3->setEnabled( false );
449   }
450   else if ( send == GroupCenter2Pnts->PushButton2 ) {
451     myEditCurrentArgument = GroupCenter2Pnts->LineEdit2;
452     GroupCenter2Pnts->PushButton1->setDown( false );
453     GroupCenter2Pnts->PushButton3->setDown( false );
454     GroupCenter2Pnts->LineEdit1->setEnabled( false );
455     GroupCenter2Pnts->LineEdit2->setEnabled( true );
456     GroupCenter2Pnts->LineEdit3->setEnabled( false );
457     
458   }
459   else if ( send == GroupCenter2Pnts->PushButton3 ) {
460     myEditCurrentArgument = GroupCenter2Pnts->LineEdit3;
461     GroupCenter2Pnts->PushButton1->setDown( false );
462     GroupCenter2Pnts->PushButton2->setDown( false );
463     GroupCenter2Pnts->LineEdit1->setEnabled( false );
464     GroupCenter2Pnts->LineEdit2->setEnabled( false );
465     GroupCenter2Pnts->LineEdit3->setEnabled( true );
466   }
467
468   
469   myEditCurrentArgument->setFocus();
470
471   TopAbs_ShapeEnum aNeedType = ( myEditCurrentArgument == GroupPntVecR->LineEdit2 ) ?
472     TopAbs_EDGE : TopAbs_VERTEX;
473   globalSelection(); // close local contexts, if any
474   localSelection( aNeedType );
475
476   myEditCurrentArgument->setFocus();
477   //  SelectionIntoArgument();
478   send->setDown(true);
479   displayPreview(true);
480 }
481
482
483 //=================================================================================
484 // function : ActivateThisDialog()
485 // purpose  :
486 //=================================================================================
487 void BasicGUI_CircleDlg::ActivateThisDialog()
488 {
489   GEOMBase_Skeleton::ActivateThisDialog();
490
491   connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
492            this, SLOT( SelectionIntoArgument() ) );
493
494   ConstructorsClicked( getConstructorId() );
495 }
496
497
498 //=================================================================================
499 // function : enterEvent()
500 // purpose  :
501 //=================================================================================
502 void BasicGUI_CircleDlg::enterEvent( QEvent* )
503 {
504   if ( !mainFrame()->GroupConstructors->isEnabled() )
505     ActivateThisDialog();
506 }
507
508 //=================================================================================
509 // function : DeactivateActiveDialog()
510 // purpose  : public slot to deactivate if active
511 //=================================================================================
512 void BasicGUI_CircleDlg::DeactivateActiveDialog()
513 {
514   GEOMBase_Skeleton::DeactivateActiveDialog();
515 }
516
517 //=================================================================================
518 // function : ValueChangedInSpinBox()
519 // purpose  :
520 //=================================================================================
521 void BasicGUI_CircleDlg::ValueChangedInSpinBox()
522 {
523   displayPreview(true);
524 }
525
526 //=================================================================================
527 // function : getRadius()
528 // purpose  :
529 //=================================================================================
530 double BasicGUI_CircleDlg::getRadius() const
531 {
532   double r = 0.;
533   switch ( getConstructorId() ) {
534   case 0:
535     r = GroupPntVecR->SpinBox_DX->value(); break;
536   }
537   return r;
538 }
539
540 //=================================================================================
541 // function : createOperation
542 // purpose  :
543 //=================================================================================
544 GEOM::GEOM_IOperations_ptr BasicGUI_CircleDlg::createOperation()
545 {
546   return myGeomGUI->GetGeomGen()->GetICurvesOperations();
547 }
548
549 //=================================================================================
550 // function : isValid
551 // purpose  :
552 //=================================================================================
553 bool BasicGUI_CircleDlg::isValid( QString& msg )
554 {
555   bool ok = false;
556   switch( getConstructorId() ) {
557   case 0:
558     // nil point means origin of global CS
559     // nil vector means Z axis
560     ok = GroupPntVecR->SpinBox_DX->isValid(msg, !IsPreview()) && getRadius() > 0;
561     break;
562   case 1:
563     ok = myPoint1 && myPoint2 && myPoint3 && myPoint1 != myPoint2 && 
564          myPoint1 != myPoint3 && myPoint2 != myPoint3;
565     break;
566   case 2:
567     ok = myPoint4 && myPoint5 && myPoint6 && myPoint4 != myPoint5 && 
568          myPoint5 != myPoint6 && myPoint4 != myPoint6;
569     break;
570   default:
571     break;
572   }
573   return ok;
574 }
575
576 //=================================================================================
577 // function : execute
578 // purpose  :
579 //=================================================================================
580 bool BasicGUI_CircleDlg::execute( ObjectList& objects )
581 {
582   bool res = false;
583   
584   GEOM::GEOM_Object_var anObj;
585   
586   GEOM::GEOM_ICurvesOperations_var anOper = GEOM::GEOM_ICurvesOperations::_narrow( getOperation() );
587
588   switch ( getConstructorId() ) {
589   case 0 :
590     {
591       QStringList aParameters;
592       aParameters << GroupPntVecR->SpinBox_DX->text();
593       anObj = anOper->MakeCirclePntVecR( myPoint.get(), myDir.get(), getRadius() );
594       if ( !anObj->_is_nil() && !IsPreview() )
595         anObj->SetParameters(aParameters.join(":").toUtf8().constData());
596       res = true;
597       break;
598     }
599   case 1 :
600     anObj = anOper->MakeCircleThreePnt( myPoint1.get(), myPoint2.get(), myPoint3.get() );
601     res = true;
602     break;
603   case 2:
604     anObj = anOper->MakeCircleCenter2Pnt( myPoint4.get(), myPoint5.get(), myPoint6.get() );
605     res = true;
606     break;
607   }
608   
609   if ( !anObj->_is_nil() )
610     objects.push_back( anObj._retn() );
611   else {
612     MESSAGE( "Execute Object is NULL!" );
613   }
614   
615   return res;
616 }
617
618 //=================================================================================
619 // function : addSubshapeToStudy
620 // purpose  : virtual method to add new SubObjects if local selection
621 //=================================================================================
622 void BasicGUI_CircleDlg::addSubshapesToStudy()
623 {
624   switch ( getConstructorId() ) {
625   case 0:
626     GEOMBase::PublishSubObject( myPoint.get() );
627     GEOMBase::PublishSubObject( myDir.get() );
628     break;
629   case 1:
630     GEOMBase::PublishSubObject( myPoint1.get() );
631     GEOMBase::PublishSubObject( myPoint2.get() );
632     GEOMBase::PublishSubObject( myPoint3.get() );
633     break;
634   case 2:
635     GEOMBase::PublishSubObject( myPoint4.get() );
636     GEOMBase::PublishSubObject( myPoint5.get() );
637     GEOMBase::PublishSubObject( myPoint6.get() );
638     break;
639  default:
640    break;
641   }
642 }
643
644 //=================================================================================
645 // function : getSourceObjects
646 // purpose  : virtual method to get source objects
647 //=================================================================================
648 QList<GEOM::GeomObjPtr> BasicGUI_CircleDlg::getSourceObjects()
649 {
650   QList<GEOM::GeomObjPtr> res;
651   res << myPoint << myDir << myPoint1 << myPoint2 << myPoint3
652       << myPoint4 << myPoint5 << myPoint6;
653   return res;
654 }