Salome HOME
7326a37e2a4578b78f7429f3cd3efeaefc9a2d3c
[modules/geom.git] / src / BasicGUI / BasicGUI_ArcDlg.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_ArcDlg.cxx
24 // Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
25 //
26 #include "BasicGUI_ArcDlg.h"
27
28 #include <DlgRef.h>
29 #include <GeometryGUI.h>
30 #include <GEOMBase.h>
31
32 #include <SUIT_ResourceMgr.h>
33 #include <SUIT_Session.h>
34 #include <SalomeApp_Application.h>
35 #include <LightApp_SelectionMgr.h>
36
37 #include <TColStd_IndexedMapOfInteger.hxx>
38 #include <TopTools_IndexedMapOfShape.hxx>
39 #include <TopoDS_Shape.hxx>
40 #include <TopoDS_Edge.hxx>
41 #include <TopoDS.hxx>
42 #include <TopExp.hxx>
43
44 #include <GEOMImpl_Types.hxx>
45
46 //=================================================================================
47 // class    : BasicGUI_ArcDlg()
48 // purpose  : Constructs a BasicGUI_ArcDlg 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_ArcDlg::BasicGUI_ArcDlg( GeometryGUI* theGeometryGUI, QWidget* parent,
54                                   bool modal, Qt::WindowFlags fl )
55   : GEOMBase_Skeleton( theGeometryGUI, parent, modal, fl )
56 {
57   SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
58   QPixmap image0( aResMgr->loadPixmap( "GEOM", tr( "ICON_DLG_ARC" ) ) );
59   QPixmap image1( aResMgr->loadPixmap( "GEOM", tr( "ICON_DLG_ARC_CENTER" ) ) );
60   QPixmap image2( aResMgr->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
61   QPixmap image3( aResMgr->loadPixmap( "GEOM", tr( "ICON_DLG_ARC_OF_ELLIPSE" ) ) );
62
63   setWindowTitle( tr( "GEOM_ARC_TITLE" ) );
64
65   /***************************************************************/
66   mainFrame()->GroupConstructors->setTitle( tr( "GEOM_ARC" ) );
67   mainFrame()->RadioButton1->setIcon( image0 );
68   mainFrame()->RadioButton2->setIcon( image1 );
69   mainFrame()->RadioButton3->setIcon( image3 );
70
71   Group3Pnts = new DlgRef_3Sel( centralWidget() );
72
73   Group3Pnts->GroupBox1->setTitle( tr( "GEOM_POINTS" ) );
74   Group3Pnts->TextLabel1->setText( tr( "GEOM_POINT_I" ).arg( 1 ) );
75   Group3Pnts->TextLabel2->setText( tr( "GEOM_POINT_I" ).arg( 2 ) );
76   Group3Pnts->TextLabel3->setText( tr( "GEOM_POINT_I" ).arg( 3 ) );
77
78   Group3Pnts->LineEdit1->setReadOnly( true );
79   Group3Pnts->LineEdit2->setReadOnly( true );
80   Group3Pnts->LineEdit3->setReadOnly( true );
81
82   Group3Pnts->LineEdit1->setEnabled(true);
83   Group3Pnts->LineEdit2->setEnabled(false);
84   Group3Pnts->LineEdit3->setEnabled(false);
85
86   Group3Pnts->PushButton1->setIcon(image2);
87   Group3Pnts->PushButton2->setIcon(image2);
88   Group3Pnts->PushButton3->setIcon(image2);
89
90
91   Group3Pnts2 = new DlgRef_3Sel1Check( centralWidget() );
92
93   Group3Pnts2->GroupBox1->setTitle( tr( "GEOM_POINTS" ) );
94   Group3Pnts2->TextLabel1->setText( tr( "GEOM_CENTER_POINT" ) );
95   Group3Pnts2->TextLabel2->setText( tr( "GEOM_POINT_I" ).arg( "Start" ) );
96   Group3Pnts2->TextLabel3->setText( tr( "GEOM_POINT_I" ).arg( "End" ) );
97
98   Group3Pnts2->LineEdit1->setReadOnly( true );
99   Group3Pnts2->LineEdit2->setReadOnly( true );
100   Group3Pnts2->LineEdit3->setReadOnly( true );
101
102   Group3Pnts2->LineEdit1->setEnabled(true);
103   Group3Pnts2->LineEdit2->setEnabled(false);
104   Group3Pnts2->LineEdit3->setEnabled(false);
105
106   Group3Pnts2->PushButton1->setIcon( image2 );
107   Group3Pnts2->PushButton2->setIcon( image2 );
108   Group3Pnts2->PushButton3->setIcon( image2 );
109   
110   Group3Pnts2->CheckButton1->setText( tr( "GEOM_REVERSE" ) );
111
112   Group3Pnts3 = new DlgRef_3Sel( centralWidget() );
113
114   Group3Pnts3->GroupBox1->setTitle( tr( "GEOM_POINTS" ) );
115   Group3Pnts3->TextLabel1->setText( tr( "GEOM_CENTER_POINT" ) );
116   Group3Pnts3->TextLabel2->setText( tr( "GEOM_POINT_I" ).arg( 1 ) );
117   Group3Pnts3->TextLabel3->setText( tr( "GEOM_POINT_I" ).arg( 2 ) );
118
119   Group3Pnts3->LineEdit1->setReadOnly( true );
120   Group3Pnts3->LineEdit2->setReadOnly( true );
121   Group3Pnts3->LineEdit3->setReadOnly( true );
122
123   Group3Pnts3->LineEdit1->setEnabled(true);
124   Group3Pnts3->LineEdit2->setEnabled(false);
125   Group3Pnts3->LineEdit3->setEnabled(false);
126
127   Group3Pnts3->PushButton1->setIcon(image2);
128   Group3Pnts3->PushButton2->setIcon(image2);
129   Group3Pnts3->PushButton3->setIcon(image2);
130
131   QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
132   layout->setMargin( 0 ); layout->setSpacing( 6 );
133   layout->addWidget( Group3Pnts );
134   layout->addWidget( Group3Pnts2 );
135   layout->addWidget( Group3Pnts3 );
136
137   setHelpFileName( "create_arc_page.html" );
138
139   Init();
140 }
141
142
143 //=================================================================================
144 // function : ~BasicGUI_ArcDlg()
145 // purpose  : Destroys the object and frees any allocated resources
146 //=================================================================================
147 BasicGUI_ArcDlg::~BasicGUI_ArcDlg()
148 {
149 }
150
151
152 //=================================================================================
153 // function : Init()
154 // purpose  :
155 //=================================================================================
156 void BasicGUI_ArcDlg::Init()
157 {
158   /* init variables */
159   myEditCurrentArgument = Group3Pnts->LineEdit1;
160
161   myPoint1 = myPoint2 = myPoint3 = GEOM::GEOM_Object::_nil();
162   Group3Pnts2->CheckButton1->setChecked( false );
163   Group3Pnts->PushButton1->setDown(true);
164
165   /* signals and slots connections */
166   connect( myGeomGUI, SIGNAL( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) );
167   connect( myGeomGUI, SIGNAL( SignalCloseAllDialogs() ),        this, SLOT( ClickOnCancel() ) );
168  
169   connect( this,           SIGNAL( constructorsClicked( int ) ), this, SLOT( ConstructorsClicked( int ) ) );
170  
171   connect( buttonOk(),     SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
172   connect( buttonApply(),  SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
173
174   connect( Group3Pnts->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
175   connect( Group3Pnts->PushButton2, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
176   connect( Group3Pnts->PushButton3, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
177
178   connect( Group3Pnts->LineEdit1, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
179   connect( Group3Pnts->LineEdit2, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
180   connect( Group3Pnts->LineEdit3, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
181   
182   connect( Group3Pnts2->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
183   connect( Group3Pnts2->PushButton2, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
184   connect( Group3Pnts2->PushButton3, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
185
186   connect( Group3Pnts2->LineEdit1, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
187   connect( Group3Pnts2->LineEdit2, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
188   connect( Group3Pnts2->LineEdit3, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
189
190   connect( Group3Pnts2->CheckButton1, SIGNAL( toggled( bool ) ), this, SLOT( ReverseSense() ) );
191
192   connect( Group3Pnts3->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
193   connect( Group3Pnts3->PushButton2, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
194   connect( Group3Pnts3->PushButton3, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
195
196   connect( Group3Pnts3->LineEdit1, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
197   connect( Group3Pnts3->LineEdit2, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
198   connect( Group3Pnts3->LineEdit3, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
199
200   connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
201            this, SLOT( SelectionIntoArgument() ) );
202
203   initName( tr( "GEOM_ARC" ) ); 
204   
205
206   ConstructorsClicked( 0 );
207 }
208
209
210 //=================================================================================
211 // function : ClickOnOk()
212 // purpose  :
213 //=================================================================================
214 void BasicGUI_ArcDlg::ClickOnOk()
215 {
216   if ( ClickOnApply() )
217     ClickOnCancel();
218 }
219
220 //=================================================================================
221 // function : ClickOnApply()
222 // purpose  :
223 //=================================================================================
224 bool BasicGUI_ArcDlg::ClickOnApply()
225 {
226   if ( !onAccept() )
227     return false;
228
229   initName();
230   ConstructorsClicked( getConstructorId() );
231
232   return true;
233 }
234
235
236 //=================================================================================
237 // function : SelectionIntoArgument()
238 // purpose  : Called when selection as changed or other case
239 //=================================================================================
240 void BasicGUI_ArcDlg::SelectionIntoArgument()
241 {
242   myEditCurrentArgument->setText( "" );
243
244   LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
245   SALOME_ListIO aSelList;
246   aSelMgr->selectedObjects(aSelList);
247
248   if (aSelList.Extent() != 1) {
249     switch (getConstructorId()) {
250     case 0:
251       if      ( myEditCurrentArgument == Group3Pnts->LineEdit1 )   myPoint1 = GEOM::GEOM_Object::_nil();
252       else if ( myEditCurrentArgument == Group3Pnts->LineEdit2 )   myPoint2 = GEOM::GEOM_Object::_nil();
253       else if ( myEditCurrentArgument == Group3Pnts->LineEdit3 )   myPoint3 = GEOM::GEOM_Object::_nil();
254       return;
255       break;
256     case 1:
257       if      ( myEditCurrentArgument == Group3Pnts2->LineEdit1 )   myPoint1 = GEOM::GEOM_Object::_nil();
258       else if ( myEditCurrentArgument == Group3Pnts2->LineEdit2 )   myPoint2 = GEOM::GEOM_Object::_nil();
259       else if ( myEditCurrentArgument == Group3Pnts2->LineEdit3 )   myPoint3 = GEOM::GEOM_Object::_nil();
260       return;
261       break;
262     case 2:
263       if      ( myEditCurrentArgument == Group3Pnts3->LineEdit1 )   myPoint1 = GEOM::GEOM_Object::_nil();
264       else if ( myEditCurrentArgument == Group3Pnts3->LineEdit2 )   myPoint2 = GEOM::GEOM_Object::_nil();
265       else if ( myEditCurrentArgument == Group3Pnts3->LineEdit3 )   myPoint3 = GEOM::GEOM_Object::_nil();
266       return;
267       break;
268     }
269   }   
270   // nbSel == 1
271   Standard_Boolean aRes = Standard_False;
272   GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject(aSelList.First(), aRes);
273   if ( !CORBA::is_nil( aSelectedObject ) && aRes ) {
274     QString aName = GEOMBase::GetName(aSelectedObject);
275
276     // Get Selected object if selected subshape
277     TopoDS_Shape aShape;
278     if (GEOMBase::GetShape(aSelectedObject, aShape, TopAbs_SHAPE) && !aShape.IsNull())
279     {
280       TColStd_IndexedMapOfInteger aMap;
281       aSelMgr->GetIndexes(aSelList.First(), aMap);
282       if (aMap.Extent() == 1) // Local Selection
283       {
284         int anIndex = aMap(1);
285         aName += QString(":vertex_%1").arg(anIndex);
286
287         //Find SubShape Object in Father
288         GEOM::GEOM_Object_var aFindedObject = GEOMBase_Helper::findObjectInFather(aSelectedObject, aName);
289
290         if ( aFindedObject == GEOM::GEOM_Object::_nil() ) { // Object not found in study
291           GEOM::GEOM_IShapesOperations_var aShapesOp = getGeomEngine()->GetIShapesOperations(getStudyId());
292           aSelectedObject = aShapesOp->GetSubShape(aSelectedObject, anIndex);
293         }
294         else
295           aSelectedObject = aFindedObject; // get Object from study
296       }
297       else // Global Selection
298       {
299         if (aShape.ShapeType() != TopAbs_VERTEX) {
300           aSelectedObject = GEOM::GEOM_Object::_nil();
301           aName = "";
302         }
303       }
304     }
305
306     myEditCurrentArgument->setText(aName);
307
308     if (!aSelectedObject->_is_nil()) { // clear selection if something selected
309       globalSelection();
310       localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );      
311     }
312
313     switch ( getConstructorId() ) {
314     case 0:
315       if      ( myEditCurrentArgument == Group3Pnts->LineEdit1 ) {
316         myPoint1 = aSelectedObject;
317         if ( !myPoint1->_is_nil() && myPoint2->_is_nil() )
318           Group3Pnts->PushButton2->click();
319       }
320       else if ( myEditCurrentArgument == Group3Pnts->LineEdit2 ) {
321         myPoint2 = aSelectedObject;
322         if ( !myPoint2->_is_nil() && myPoint3->_is_nil() )
323           Group3Pnts->PushButton3->click();
324       }
325       else if ( myEditCurrentArgument == Group3Pnts->LineEdit3 ) {
326         myPoint3 = aSelectedObject;
327         if ( !myPoint3->_is_nil() && myPoint1->_is_nil() )
328           Group3Pnts->PushButton1->click();
329       }
330       break;
331     case 1:
332       if ( myEditCurrentArgument == Group3Pnts2->LineEdit1 ) {
333         myPoint1 = aSelectedObject;
334         if ( !myPoint1->_is_nil() && myPoint2->_is_nil() )
335           Group3Pnts2->PushButton2->click();
336       }
337       else if ( myEditCurrentArgument == Group3Pnts2->LineEdit2 ) {
338         myPoint2 = aSelectedObject;
339         if ( !myPoint2->_is_nil() && myPoint3->_is_nil() )
340           Group3Pnts2->PushButton3->click();
341       }
342       else if ( myEditCurrentArgument == Group3Pnts2->LineEdit3 ) {
343         myPoint3 = aSelectedObject;
344         if ( !myPoint3->_is_nil() && myPoint1->_is_nil() )
345           Group3Pnts2->PushButton1->click();
346       }
347       break;
348     case 2:
349       if ( myEditCurrentArgument == Group3Pnts3->LineEdit1 ) {
350         myPoint1 = aSelectedObject;
351         if ( !myPoint1->_is_nil() && myPoint2->_is_nil() )
352           Group3Pnts3->PushButton2->click();
353       }
354       else if ( myEditCurrentArgument == Group3Pnts3->LineEdit2 ) {
355         myPoint2 = aSelectedObject;
356         if ( !myPoint2->_is_nil() && myPoint3->_is_nil() )
357           Group3Pnts3->PushButton3->click();
358       }
359       else if ( myEditCurrentArgument == Group3Pnts3->LineEdit3 ) {
360         myPoint3 = aSelectedObject;
361         if ( !myPoint3->_is_nil() && myPoint1->_is_nil() )
362           Group3Pnts3->PushButton1->click();
363       }
364       break;
365     }
366   }
367
368   displayPreview();
369 }
370
371
372 //=================================================================================
373 // function : SetEditCurrentArgument()
374 // purpose  :
375 //=================================================================================
376 void BasicGUI_ArcDlg::SetEditCurrentArgument()
377 {
378   globalSelection(); // close local selection to clear it
379   localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
380
381   QPushButton* send = (QPushButton*)sender();
382   switch ( getConstructorId() ) {
383   case 0:
384     if      ( send == Group3Pnts->PushButton1 ) {
385       myEditCurrentArgument = Group3Pnts->LineEdit1;
386       Group3Pnts->PushButton2->setDown(false);
387       Group3Pnts->PushButton3->setDown(false);
388       Group3Pnts->LineEdit1->setEnabled(true);
389       Group3Pnts->LineEdit2->setEnabled(false);
390       Group3Pnts->LineEdit3->setEnabled(false);
391     }
392     else if ( send == Group3Pnts->PushButton2 ) {
393       myEditCurrentArgument = Group3Pnts->LineEdit2;
394       Group3Pnts->PushButton1->setDown(false);
395       Group3Pnts->PushButton3->setDown(false);
396       Group3Pnts->LineEdit1->setEnabled(false);
397       Group3Pnts->LineEdit2->setEnabled(true);
398       Group3Pnts->LineEdit3->setEnabled(false);
399     }
400     else if ( send == Group3Pnts->PushButton3 ) {
401       myEditCurrentArgument = Group3Pnts->LineEdit3;
402       Group3Pnts->PushButton1->setDown(false);
403       Group3Pnts->PushButton2->setDown(false);
404       Group3Pnts->LineEdit1->setEnabled(false);
405       Group3Pnts->LineEdit2->setEnabled(false);
406       Group3Pnts->LineEdit3->setEnabled(true);
407     }
408     break;
409   case 1:
410     if      ( send == Group3Pnts2->PushButton1 ) {
411       myEditCurrentArgument = Group3Pnts2->LineEdit1;
412       Group3Pnts2->PushButton2->setDown(false);
413       Group3Pnts2->PushButton3->setDown(false);
414       Group3Pnts2->LineEdit1->setEnabled(true);
415       Group3Pnts2->LineEdit2->setEnabled(false);
416       Group3Pnts2->LineEdit3->setEnabled(false);
417     }
418     else if ( send == Group3Pnts2->PushButton2 ) {
419       myEditCurrentArgument = Group3Pnts2->LineEdit2;
420       Group3Pnts2->PushButton1->setDown(false);
421       Group3Pnts2->PushButton3->setDown(false);
422       Group3Pnts2->LineEdit1->setEnabled(false);
423       Group3Pnts2->LineEdit2->setEnabled(true);
424       Group3Pnts2->LineEdit3->setEnabled(false);
425     }
426     else if ( send == Group3Pnts2->PushButton3 ) {
427       myEditCurrentArgument = Group3Pnts2->LineEdit3;
428       Group3Pnts2->PushButton1->setDown(false);
429       Group3Pnts2->PushButton2->setDown(false);
430       Group3Pnts2->LineEdit1->setEnabled(false);
431       Group3Pnts2->LineEdit2->setEnabled(false);
432       Group3Pnts2->LineEdit3->setEnabled(true);
433     }
434     break;
435   case 2:
436     if ( send == Group3Pnts3->PushButton1 ) {
437       myEditCurrentArgument = Group3Pnts3->LineEdit1;
438       Group3Pnts3->PushButton2->setDown(false);
439       Group3Pnts3->PushButton3->setDown(false);
440       Group3Pnts3->LineEdit1->setEnabled(true);
441       Group3Pnts3->LineEdit2->setEnabled(false);
442       Group3Pnts3->LineEdit3->setEnabled(false);
443     }
444     else if ( send == Group3Pnts3->PushButton2 ) {
445       myEditCurrentArgument = Group3Pnts3->LineEdit2;
446       Group3Pnts3->PushButton1->setDown(false);
447       Group3Pnts3->PushButton3->setDown(false);
448       Group3Pnts3->LineEdit1->setEnabled(false);
449       Group3Pnts3->LineEdit2->setEnabled(true);
450       Group3Pnts3->LineEdit3->setEnabled(false);
451     }
452     else if ( send == Group3Pnts3->PushButton3 ) {
453       myEditCurrentArgument = Group3Pnts3->LineEdit3;
454       Group3Pnts3->PushButton1->setDown(false);
455       Group3Pnts3->PushButton2->setDown(false);
456       Group3Pnts3->LineEdit1->setEnabled(false);
457       Group3Pnts3->LineEdit2->setEnabled(false);
458       Group3Pnts3->LineEdit3->setEnabled(true);
459     }
460     break;
461   }
462   myEditCurrentArgument->setFocus();
463   //  SelectionIntoArgument();
464   send->setDown(true);
465   displayPreview();
466 }
467
468
469 //=================================================================================
470 // function : LineEditReturnPressed()
471 // purpose  :
472 //=================================================================================
473 void BasicGUI_ArcDlg::LineEditReturnPressed()
474 {
475   QLineEdit* send = (QLineEdit*)sender();
476   if ( send == Group3Pnts->LineEdit1 || send == Group3Pnts->LineEdit2 || send == Group3Pnts->LineEdit3 ||
477        send == Group3Pnts2->LineEdit1 || send == Group3Pnts2->LineEdit2 || send == Group3Pnts2->LineEdit3 ||
478        send == Group3Pnts3->LineEdit1 || send == Group3Pnts3->LineEdit2 || send == Group3Pnts3->LineEdit3 ) {
479     myEditCurrentArgument = send;
480     GEOMBase_Skeleton::LineEditReturnPressed();
481   }
482 }
483
484
485 //=================================================================================
486 // function : ActivateThisDialog()
487 // purpose  :
488 //=================================================================================
489 void BasicGUI_ArcDlg::ActivateThisDialog()
490 {
491   GEOMBase_Skeleton::ActivateThisDialog();
492
493   connect( myGeomGUI->getApp()->selectionMgr(),
494            SIGNAL( currentSelectionChanged() ),
495            this,
496            SLOT(SelectionIntoArgument() ) );
497
498   ConstructorsClicked( getConstructorId() );
499 }
500
501 //=================================================================================
502 // function : enterEvent()
503 // purpose  :
504 //=================================================================================
505 void BasicGUI_ArcDlg::enterEvent( QEvent* )
506 {
507   if ( !mainFrame()->GroupConstructors->isEnabled() )
508     ActivateThisDialog();
509 }
510
511 //=================================================================================
512 // function : createOperation
513 // purpose  :
514 //=================================================================================
515 GEOM::GEOM_IOperations_ptr BasicGUI_ArcDlg::createOperation()
516 {
517   return myGeomGUI->GetGeomGen()->GetICurvesOperations( getStudyId() );
518 }
519
520 //=================================================================================
521 // function : isEqual
522 // purpose  : it may also be needed to check for min distance between gp_Pnt-s...
523 //=================================================================================
524 static bool isEqual( const GEOM::GEOM_Object_var& thePnt1, const GEOM::GEOM_Object_var& thePnt2 )
525 {
526   return thePnt1->_is_equivalent( thePnt2 );
527 }
528
529 //=================================================================================
530 // function : isValid
531 // purpose  :
532 //=================================================================================
533 bool BasicGUI_ArcDlg::isValid( QString& msg )
534 {
535   switch (getConstructorId()) {
536   case 0:
537     {
538       if (Group3Pnts->LineEdit1->text().trimmed().isEmpty() ||
539           Group3Pnts->LineEdit2->text().trimmed().isEmpty() ||
540           Group3Pnts->LineEdit3->text().trimmed().isEmpty())
541         return false;
542       break;
543     }
544   case 1:
545     {
546       if (Group3Pnts2->LineEdit1->text().trimmed().isEmpty() ||
547           Group3Pnts2->LineEdit2->text().trimmed().isEmpty() ||
548           Group3Pnts2->LineEdit3->text().trimmed().isEmpty())
549         return false;
550       break;
551     }
552   case 2:
553     {
554       if (Group3Pnts3->LineEdit1->text().trimmed().isEmpty() ||
555           Group3Pnts3->LineEdit2->text().trimmed().isEmpty() ||
556           Group3Pnts3->LineEdit3->text().trimmed().isEmpty())
557         return false;
558       break;
559     }
560   }
561   return !myPoint1->_is_nil() && !myPoint2->_is_nil() && !myPoint3->_is_nil() &&
562     !isEqual( myPoint1, myPoint2 ) && !isEqual( myPoint1, myPoint3 ) && !isEqual( myPoint2, myPoint3 );
563 }
564
565 //=================================================================================
566 // function : execute
567 // purpose  :
568 //=================================================================================
569 bool BasicGUI_ArcDlg::execute( ObjectList& objects )
570 {
571   bool res = false;
572   GEOM::GEOM_Object_var anObj;
573
574   switch ( getConstructorId() ) {
575   case 0:
576     {
577       if ( !CORBA::is_nil( myPoint1 ) && !CORBA::is_nil( myPoint2 ) && !CORBA::is_nil( myPoint3 ) ) {
578         anObj = GEOM::GEOM_ICurvesOperations::_narrow( getOperation() )->MakeArc( myPoint1, myPoint2, myPoint3 );
579         res = true;
580       }
581       break;
582     }
583   case 1:
584     {
585       bool Sense = Group3Pnts2->CheckButton1->isChecked();
586       if ( !CORBA::is_nil( myPoint1 ) && !CORBA::is_nil( myPoint2 ) && !CORBA::is_nil( myPoint3 ) ) {
587         anObj = GEOM::GEOM_ICurvesOperations::_narrow( getOperation() )->MakeArcCenter( myPoint1, myPoint2, myPoint3, Sense );
588         res = true;
589       }
590       break;
591     }
592   case 2:
593     {
594       if ( !CORBA::is_nil( myPoint1 ) && !CORBA::is_nil( myPoint2 ) && !CORBA::is_nil( myPoint3 ) ) {
595         anObj = GEOM::GEOM_ICurvesOperations::_narrow( getOperation() )->MakeArcOfEllipse( myPoint1, myPoint2, myPoint3 );
596         res = true;
597       }
598       break;
599     }
600   }
601   if ( !anObj->_is_nil() ) {
602     objects.push_back( anObj._retn() );
603   }
604   return res;
605 }
606
607 //=================================================================================
608 // function : ConstructorsClicked()
609 // purpose  : Radio button management
610 //=================================================================================
611 void BasicGUI_ArcDlg::ConstructorsClicked( int constructorId )
612 {
613   disconnect( myGeomGUI->getApp()->selectionMgr(), 0, this, 0 );
614
615   switch ( constructorId ) {
616   case 0:
617     {
618       globalSelection(); // close local contexts, if any
619       localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX ); //Select Vertex on All Shapes
620
621       Group3Pnts->show();
622       Group3Pnts2->hide();
623       Group3Pnts3->hide();
624       Group3Pnts->PushButton1->setDown(true);
625       Group3Pnts->PushButton2->setDown(false);
626       Group3Pnts->PushButton3->setDown(false);
627       Group3Pnts->LineEdit1->setText( "" );
628       Group3Pnts->LineEdit2->setText( "" );
629       Group3Pnts->LineEdit3->setText( "" );
630       Group3Pnts->LineEdit1->setEnabled(true);
631       Group3Pnts->LineEdit2->setEnabled(false);
632       Group3Pnts->LineEdit3->setEnabled(false);
633       myPoint1 = myPoint2 = myPoint3 = GEOM::GEOM_Object::_nil();
634
635       myEditCurrentArgument = Group3Pnts->LineEdit1;
636       break;
637     }
638   case 1:
639     {
640       globalSelection(); // close local contexts, if any
641       localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX ); //Select Vertex on All Shapes
642
643       Group3Pnts->hide();
644       Group3Pnts2->show();
645       Group3Pnts3->hide();
646       Group3Pnts2->PushButton1->setDown(true);
647       Group3Pnts2->PushButton2->setDown(false);
648       Group3Pnts2->PushButton3->setDown(false);
649       Group3Pnts2->LineEdit1->setText( "" );
650       Group3Pnts2->LineEdit2->setText( "" );
651       Group3Pnts2->LineEdit3->setText( "" );
652       Group3Pnts2->LineEdit1->setEnabled(true);
653       Group3Pnts2->LineEdit2->setEnabled(false);
654       Group3Pnts2->LineEdit3->setEnabled(false);
655       myPoint1 = myPoint2 = myPoint3 = GEOM::GEOM_Object::_nil();
656       
657       myEditCurrentArgument = Group3Pnts2->LineEdit1;
658       break;
659     }
660   case 2:
661     {
662       globalSelection(); // close local contexts, if any
663       localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX ); //Select Vertex on All Shapes
664
665       Group3Pnts->hide();
666       Group3Pnts2->hide();
667       Group3Pnts3->show();
668       Group3Pnts3->PushButton1->setDown(true);
669       Group3Pnts3->PushButton2->setDown(false);
670       Group3Pnts3->PushButton3->setDown(false);
671       Group3Pnts3->LineEdit1->setText( "" );
672       Group3Pnts3->LineEdit2->setText( "" );
673       Group3Pnts3->LineEdit3->setText( "" );
674       Group3Pnts3->LineEdit1->setEnabled(true);
675       Group3Pnts3->LineEdit2->setEnabled(false);
676       Group3Pnts3->LineEdit3->setEnabled(false);
677       myPoint1 = myPoint2 = myPoint3 = GEOM::GEOM_Object::_nil();
678
679       myEditCurrentArgument = Group3Pnts3->LineEdit1;
680       break;
681     }
682   }
683
684   qApp->processEvents();
685   updateGeometry();
686   resize( minimumSizeHint() );
687
688   myEditCurrentArgument->setFocus();
689   connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
690            this, SLOT( SelectionIntoArgument() ) );
691
692   if ( CORBA::is_nil( myPoint1 ) )
693     SelectionIntoArgument();
694
695   displayPreview();
696 }
697
698 //=================================================================================
699 // function : ReverseSense()
700 // purpose  : Orientation of the arc
701 //=================================================================================
702 void BasicGUI_ArcDlg::ReverseSense()
703 {
704   displayPreview();
705 }
706
707 //=================================================================================
708 // function : addSubshapeToStudy
709 // purpose  : virtual method to add new SubObjects if local selection
710 //=================================================================================
711 void BasicGUI_ArcDlg::addSubshapesToStudy()
712 {
713   QMap<QString, GEOM::GEOM_Object_var> objMap;
714
715   switch ( getConstructorId() ) {
716   case 0:
717     objMap[Group3Pnts->LineEdit1->text()] = myPoint1;
718     objMap[Group3Pnts->LineEdit2->text()] = myPoint2;
719     objMap[Group3Pnts->LineEdit3->text()] = myPoint3;
720     break;
721   case 1:
722     objMap[Group3Pnts2->LineEdit1->text()] = myPoint1;
723     objMap[Group3Pnts2->LineEdit2->text()] = myPoint2;
724     objMap[Group3Pnts2->LineEdit3->text()] = myPoint3;
725     break;
726   case 2:
727     objMap[Group3Pnts3->LineEdit1->text()] = myPoint1;
728     objMap[Group3Pnts3->LineEdit2->text()] = myPoint2;
729     objMap[Group3Pnts3->LineEdit3->text()] = myPoint3;
730     break;
731   }
732   addSubshapesToFather( objMap );
733 }