]> SALOME platform Git repositories - modules/geom.git/blob - src/BasicGUI/BasicGUI_ArcDlg.cxx
Salome HOME
*** empty log message ***
[modules/geom.git] / src / BasicGUI / BasicGUI_ArcDlg.cxx
1 // GEOM GEOMGUI : GUI for Geometry component
2 //
3 // Copyright (C) 2003  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 // File   : BasicGUI_ArcDlg.cxx
23 // Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
24 //
25
26 #include "BasicGUI_ArcDlg.h"
27
28 #include <GEOM_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 <GEOMImpl_Types.hxx>
38
39 //=================================================================================
40 // class    : BasicGUI_ArcDlg()
41 // purpose  : Constructs a BasicGUI_ArcDlg which is a child of 'parent', with the
42 //            name 'name' and widget flags set to 'f'.
43 //            The dialog will by default be modeless, unless you set 'modal' to
44 //            TRUE to construct a modal dialog.
45 //=================================================================================
46 BasicGUI_ArcDlg::BasicGUI_ArcDlg( GeometryGUI* theGeometryGUI, QWidget* parent,
47                                   const char* name, bool modal, Qt::WindowFlags fl )
48   : GEOMBase_Skeleton( theGeometryGUI, parent, name, modal, fl )
49 {
50   QPixmap image0( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_ARC" ) ) );
51   QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_ARC_CENTER" ) ) );
52   QPixmap image2( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
53
54   setWindowTitle( tr( "GEOM_ARC_TITLE" ) );
55
56   /***************************************************************/
57   mainFrame()->GroupConstructors->setTitle( tr( "GEOM_ARC" ) );
58   mainFrame()->RadioButton1->setIcon( image0 );
59   mainFrame()->RadioButton2->setIcon( image1 );
60   mainFrame()->RadioButton3->setAttribute( Qt::WA_DeleteOnClose );
61   mainFrame()->RadioButton3->close();
62
63   Group3Pnts = new DlgRef_3Sel( centralWidget() );
64
65   Group3Pnts->GroupBox1->setTitle( tr( "GEOM_POINTS" ) );
66   Group3Pnts->TextLabel1->setText( tr( "GEOM_POINT_I" ).arg( 1 ) );
67   Group3Pnts->TextLabel2->setText( tr( "GEOM_POINT_I" ).arg( 2 ) );
68   Group3Pnts->TextLabel3->setText( tr( "GEOM_POINT_I" ).arg( 3 ) );
69
70   Group3Pnts->LineEdit1->setReadOnly( true );
71   Group3Pnts->LineEdit2->setReadOnly( true );
72   Group3Pnts->LineEdit3->setReadOnly( true );
73
74   Group3Pnts->PushButton1->setIcon(image2);
75   Group3Pnts->PushButton2->setIcon(image2);
76   Group3Pnts->PushButton3->setIcon(image2);
77
78
79   Group3Pnts2 = new DlgRef_3Sel1Check( centralWidget() );
80
81   Group3Pnts2->GroupBox1->setTitle( tr( "GEOM_POINTS" ) );
82   Group3Pnts2->TextLabel1->setText( tr( "GEOM_CENTER_POINT" ) );
83   Group3Pnts2->TextLabel2->setText( tr( "GEOM_POINT_I" ).arg( "Start" ) );
84   Group3Pnts2->TextLabel3->setText( tr( "GEOM_POINT_I" ).arg( "End" ) );
85
86   Group3Pnts2->LineEdit1->setReadOnly( true );
87   Group3Pnts2->LineEdit2->setReadOnly( true );
88   Group3Pnts2->LineEdit3->setReadOnly( true );
89
90   Group3Pnts2->PushButton1->setIcon( image2 );
91   Group3Pnts2->PushButton2->setIcon( image2 );
92   Group3Pnts2->PushButton3->setIcon( image2 );
93   
94   Group3Pnts2->CheckButton1->setText( tr( "GEOM_REVERSE" ) );
95
96   QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
97   layout->setMargin( 0 ); layout->setSpacing( 6 );
98   layout->addWidget( Group3Pnts );
99   layout->addWidget( Group3Pnts2 );
100
101   setHelpFileName( "arc.htm" );
102
103   Init();
104 }
105
106
107 //=================================================================================
108 // function : ~BasicGUI_ArcDlg()
109 // purpose  : Destroys the object and frees any allocated resources
110 //=================================================================================
111 BasicGUI_ArcDlg::~BasicGUI_ArcDlg()
112 {
113 }
114
115
116 //=================================================================================
117 // function : Init()
118 // purpose  :
119 //=================================================================================
120 void BasicGUI_ArcDlg::Init()
121 {
122   /* init variables */
123   // myGeomGUI->SetState( 0 );
124   globalSelection( GEOM_POINT );
125   
126   myConstructorId = -1;
127   myEditCurrentArgument = Group3Pnts->LineEdit1;
128   myEditCurrentArgument->setFocus();
129
130   myPoint1 = myPoint2 = myPoint3 = GEOM::GEOM_Object::_nil();
131   Group3Pnts2->CheckButton1->setChecked( false );
132
133   /* signals and slots connections */
134   connect( myGeomGUI, SIGNAL( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) );
135   connect( myGeomGUI, SIGNAL( SignalCloseAllDialogs() ),        this, SLOT( ClickOnCancel() ) );
136  
137   connect( this,           SIGNAL( constructorsClicked( int ) ), this, SLOT( ConstructorsClicked( int ) ) );
138  
139   connect( buttonCancel(), SIGNAL( clicked() ), this, SLOT( ClickOnCancel() ) );
140   connect( buttonOk(),     SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
141   connect( buttonApply(),  SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
142
143   connect( Group3Pnts->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
144   connect( Group3Pnts->PushButton2, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
145   connect( Group3Pnts->PushButton3, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
146
147   connect( Group3Pnts->LineEdit1, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
148   connect( Group3Pnts->LineEdit2, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
149   connect( Group3Pnts->LineEdit3, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
150   
151   connect( Group3Pnts2->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
152   connect( Group3Pnts2->PushButton2, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
153   connect( Group3Pnts2->PushButton3, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
154
155   connect( Group3Pnts2->LineEdit1, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
156   connect( Group3Pnts2->LineEdit2, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
157   connect( Group3Pnts2->LineEdit3, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
158   
159   connect( Group3Pnts2->CheckButton1, SIGNAL( toggled( bool ) ), this, SLOT( ReverseSense() ) );
160
161   connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
162            SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
163
164   initName( tr( "GEOM_ARC" ) ); 
165   
166
167   ConstructorsClicked( 0 );
168 }
169
170
171 //=================================================================================
172 // function : ClickOnOk()
173 // purpose  :
174 //=================================================================================
175 void BasicGUI_ArcDlg::ClickOnOk()
176 {
177   if ( ClickOnApply() )
178     ClickOnCancel();
179 }
180
181 //=================================================================================
182 // function : ClickOnCancel()
183 // purpose  :
184 //=================================================================================
185 void BasicGUI_ArcDlg::ClickOnCancel()
186 {
187   GEOMBase_Skeleton::ClickOnCancel();
188 }
189
190 //=================================================================================
191 // function : ClickOnApply()
192 // purpose  :
193 //=================================================================================
194 bool BasicGUI_ArcDlg::ClickOnApply()
195 {
196   if ( !onAccept() )
197     return false;
198
199   initName();
200
201   // reset
202   myPoint1 = myPoint2 = myPoint3 = GEOM::GEOM_Object::_nil();
203   Group3Pnts->LineEdit1->setText( "" );
204   Group3Pnts->LineEdit2->setText( "" );
205   Group3Pnts->LineEdit3->setText( "" );
206   Group3Pnts2->LineEdit1->setText( "" );
207   Group3Pnts2->LineEdit2->setText( "" );
208   Group3Pnts2->LineEdit3->setText( "" );
209   if ( getConstructorId() == 0 )  myEditCurrentArgument = Group3Pnts->LineEdit1;
210   if ( getConstructorId() == 1 )  myEditCurrentArgument = Group3Pnts2->LineEdit1;
211
212   ConstructorsClicked( getConstructorId() );
213   return true;
214 }
215
216
217 //=================================================================================
218 // function : SelectionIntoArgument()
219 // purpose  : Called when selection as changed or other case
220 //=================================================================================
221 void BasicGUI_ArcDlg::SelectionIntoArgument()
222 {
223   if ( getConstructorId() != 0 && getConstructorId() != 1 )
224     return;
225   
226   myEditCurrentArgument->setText( "" );
227   if ( IObjectCount() != 1 ) {
228     switch ( getConstructorId() ) {
229     case 0:
230       if      ( myEditCurrentArgument == Group3Pnts->LineEdit1 )   myPoint1 = GEOM::GEOM_Object::_nil();
231       else if ( myEditCurrentArgument == Group3Pnts->LineEdit2 )   myPoint2 = GEOM::GEOM_Object::_nil();
232       else if ( myEditCurrentArgument == Group3Pnts->LineEdit3 )   myPoint3 = GEOM::GEOM_Object::_nil();
233       return;
234       break;
235     case 1:
236       if      ( myEditCurrentArgument == Group3Pnts2->LineEdit1 )   myPoint1 = GEOM::GEOM_Object::_nil();
237       else if ( myEditCurrentArgument == Group3Pnts2->LineEdit2 )   myPoint2 = GEOM::GEOM_Object::_nil();
238       else if ( myEditCurrentArgument == Group3Pnts2->LineEdit3 )   myPoint3 = GEOM::GEOM_Object::_nil();
239       return;
240       break;
241     }
242   }   
243   // nbSel == 1
244   Standard_Boolean aRes = Standard_False;
245   GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( firstIObject(), aRes );
246   if ( !CORBA::is_nil( aSelectedObject ) && aRes ) {
247     switch ( getConstructorId() ) {
248     case 0:
249       myEditCurrentArgument->setText( GEOMBase::GetName( aSelectedObject ) );
250       if      ( myEditCurrentArgument == Group3Pnts->LineEdit1 )   myPoint1 = aSelectedObject;
251       else if ( myEditCurrentArgument == Group3Pnts->LineEdit2 )   myPoint2 = aSelectedObject;
252       else if ( myEditCurrentArgument == Group3Pnts->LineEdit3 )   myPoint3 = aSelectedObject;
253       break;
254     case 1:
255       myEditCurrentArgument->setText( GEOMBase::GetName( aSelectedObject ) );
256       if      ( myEditCurrentArgument == Group3Pnts2->LineEdit1 )   myPoint1 = aSelectedObject;
257       else if ( myEditCurrentArgument == Group3Pnts2->LineEdit2 )   myPoint2 = aSelectedObject;
258       else if ( myEditCurrentArgument == Group3Pnts2->LineEdit3 )   myPoint3 = aSelectedObject;
259       break;
260     }
261   }
262
263   displayPreview();
264 }
265
266
267 //=================================================================================
268 // function : SetEditCurrentArgument()
269 // purpose  :
270 //=================================================================================
271 void BasicGUI_ArcDlg::SetEditCurrentArgument()
272 {
273   QPushButton* send = (QPushButton*)sender();
274   switch ( getConstructorId() ) {
275   case 0:
276     if      ( send == Group3Pnts->PushButton1 )   myEditCurrentArgument = Group3Pnts->LineEdit1;
277     else if ( send == Group3Pnts->PushButton2 )   myEditCurrentArgument = Group3Pnts->LineEdit2;
278     else if ( send == Group3Pnts->PushButton3 )   myEditCurrentArgument = Group3Pnts->LineEdit3;
279     break;
280   case 1:
281     if      ( send == Group3Pnts2->PushButton1 )   myEditCurrentArgument = Group3Pnts2->LineEdit1;
282     else if ( send == Group3Pnts2->PushButton2 )   myEditCurrentArgument = Group3Pnts2->LineEdit2;
283     else if ( send == Group3Pnts2->PushButton3 )   myEditCurrentArgument = Group3Pnts2->LineEdit3;
284     break;
285   }
286   myEditCurrentArgument->setFocus();
287   SelectionIntoArgument();
288 }
289
290
291 //=================================================================================
292 // function : LineEditReturnPressed()
293 // purpose  :
294 //=================================================================================
295 void BasicGUI_ArcDlg::LineEditReturnPressed()
296 {
297   QLineEdit* send = (QLineEdit*)sender();
298   if ( send == Group3Pnts->LineEdit1 || send == Group3Pnts->LineEdit2 || send == Group3Pnts->LineEdit3 ||
299        send == Group3Pnts2->LineEdit1 || send == Group3Pnts2->LineEdit2 || send == Group3Pnts2->LineEdit3 ) {
300     myEditCurrentArgument = send;
301     GEOMBase_Skeleton::LineEditReturnPressed();
302   }
303 }
304
305
306 //=================================================================================
307 // function : ActivateThisDialog()
308 // purpose  :
309 //=================================================================================
310 void BasicGUI_ArcDlg::ActivateThisDialog()
311 {
312   GEOMBase_Skeleton::ActivateThisDialog();
313   connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
314            SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
315
316   // myGeomGUI->SetState( 0 );
317   globalSelection( GEOM_POINT );
318
319   myEditCurrentArgument = Group3Pnts->LineEdit1;
320   myEditCurrentArgument->setFocus();
321
322   Group3Pnts->LineEdit1->setText( "" );
323   Group3Pnts->LineEdit2->setText( "" );
324   Group3Pnts->LineEdit3->setText( "" );
325   myPoint1 = myPoint2 = myPoint3 = GEOM::GEOM_Object::_nil();
326
327   ConstructorsClicked( getConstructorId() );
328   
329 }
330
331 //=================================================================================
332 // function : DeactivateActiveDialog()
333 // purpose  : public slot to deactivate if active
334 //=================================================================================
335 void BasicGUI_ArcDlg::DeactivateActiveDialog()
336 {
337   // myGeomGUI->SetState( -1 );
338   GEOMBase_Skeleton::DeactivateActiveDialog();
339 }
340
341 //=================================================================================
342 // function : enterEvent()
343 // purpose  :
344 //=================================================================================
345 void BasicGUI_ArcDlg::enterEvent( QEvent* )
346 {
347   if ( !mainFrame()->GroupConstructors->isEnabled() )
348     ActivateThisDialog();
349 }
350
351 //=================================================================================
352 // function : createOperation
353 // purpose  :
354 //=================================================================================
355 GEOM::GEOM_IOperations_ptr BasicGUI_ArcDlg::createOperation()
356 {
357   return myGeomGUI->GetGeomGen()->GetICurvesOperations( getStudyId() );
358 }
359
360 //=================================================================================
361 // function : isEqual
362 // purpose  : it may also be needed to check for min distance between gp_Pnt-s...
363 //=================================================================================
364 static bool isEqual( const GEOM::GEOM_Object_var& thePnt1, const GEOM::GEOM_Object_var& thePnt2 )
365 {
366   return thePnt1->_is_equivalent( thePnt2 );
367 }
368
369 //=================================================================================
370 // function : isValid
371 // purpose  :
372 //=================================================================================
373 bool BasicGUI_ArcDlg::isValid( QString& msg )
374 {
375   return !myPoint1->_is_nil() && !myPoint2->_is_nil() && !myPoint3->_is_nil() &&
376     !isEqual( myPoint1, myPoint2 ) && !isEqual( myPoint1, myPoint3 ) && !isEqual( myPoint2, myPoint3 );
377 }
378
379 //=================================================================================
380 // function : execute
381 // purpose  :
382 //=================================================================================
383 bool BasicGUI_ArcDlg::execute( ObjectList& objects )
384 {
385   bool res = false;
386   GEOM::GEOM_Object_var anObj;
387
388   switch ( getConstructorId() ) {
389   case 0:
390     {
391       if ( !CORBA::is_nil( myPoint1 ) && !CORBA::is_nil( myPoint2 ) && !CORBA::is_nil( myPoint3 ) ) {
392         anObj = GEOM::GEOM_ICurvesOperations::_narrow( getOperation() )->MakeArc( myPoint1, myPoint2, myPoint3 );
393         res = true;
394       }
395       break;
396     }
397   case 1:
398     {
399       bool Sense = Group3Pnts2->CheckButton1->isChecked();
400       if ( !CORBA::is_nil( myPoint1 ) && !CORBA::is_nil( myPoint2 ) && !CORBA::is_nil( myPoint3 ) ) {
401         anObj = GEOM::GEOM_ICurvesOperations::_narrow( getOperation() )->MakeArcCenter( myPoint1, myPoint2, myPoint3, Sense );
402         res = true;
403       }
404       break;
405     }
406   }
407   if ( !anObj->_is_nil() ) {
408     objects.push_back( anObj._retn() );
409   }
410   return res;
411 }
412
413 //=================================================================================
414 // function : closeEvent
415 // purpose  :
416 //=================================================================================
417 void BasicGUI_ArcDlg::closeEvent( QCloseEvent* e )
418 {
419   GEOMBase_Skeleton::closeEvent( e );
420 }
421
422 //=================================================================================
423 // function : ConstructorsClicked()
424 // purpose  : Radio button management
425 //=================================================================================
426 void BasicGUI_ArcDlg::ConstructorsClicked( int constructorId )
427 {
428   disconnect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(), 0, this, 0 );
429
430   switch ( constructorId ) {
431   case 0:
432     {
433       Group3Pnts2->hide();
434       Group3Pnts->show();
435
436       connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
437                SIGNAL(currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
438       break;
439     }
440   case 1:
441     {
442       Group3Pnts->hide();
443       Group3Pnts2->show();
444       connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),          
445                SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
446       
447       break;
448     }
449   }
450
451   qApp->processEvents();
452   updateGeometry();
453   resize( minimumSize() );
454
455   displayPreview();
456 }
457
458 //=================================================================================
459 // function : ReverseSense()
460 // purpose  : Orientation of the arc
461 //=================================================================================
462 void BasicGUI_ArcDlg::ReverseSense()
463 {
464   displayPreview();
465 }