]> 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                                   bool modal, Qt::WindowFlags fl )
48   : GEOMBase_Skeleton( theGeometryGUI, parent, "BasicGUI_ArcDlg", 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( buttonOk(),     SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
140   connect( buttonApply(),  SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
141
142   connect( Group3Pnts->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
143   connect( Group3Pnts->PushButton2, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
144   connect( Group3Pnts->PushButton3, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
145
146   connect( Group3Pnts->LineEdit1, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
147   connect( Group3Pnts->LineEdit2, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
148   connect( Group3Pnts->LineEdit3, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
149   
150   connect( Group3Pnts2->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
151   connect( Group3Pnts2->PushButton2, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
152   connect( Group3Pnts2->PushButton3, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
153
154   connect( Group3Pnts2->LineEdit1, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
155   connect( Group3Pnts2->LineEdit2, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
156   connect( Group3Pnts2->LineEdit3, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
157   
158   connect( Group3Pnts2->CheckButton1, SIGNAL( toggled( bool ) ), this, SLOT( ReverseSense() ) );
159
160   connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
161            SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
162
163   initName( tr( "GEOM_ARC" ) ); 
164   
165
166   ConstructorsClicked( 0 );
167 }
168
169
170 //=================================================================================
171 // function : ClickOnOk()
172 // purpose  :
173 //=================================================================================
174 void BasicGUI_ArcDlg::ClickOnOk()
175 {
176   if ( ClickOnApply() )
177     ClickOnCancel();
178 }
179
180 //=================================================================================
181 // function : ClickOnApply()
182 // purpose  :
183 //=================================================================================
184 bool BasicGUI_ArcDlg::ClickOnApply()
185 {
186   if ( !onAccept() )
187     return false;
188
189   initName();
190
191   // reset
192   myPoint1 = myPoint2 = myPoint3 = GEOM::GEOM_Object::_nil();
193   Group3Pnts->LineEdit1->setText( "" );
194   Group3Pnts->LineEdit2->setText( "" );
195   Group3Pnts->LineEdit3->setText( "" );
196   Group3Pnts2->LineEdit1->setText( "" );
197   Group3Pnts2->LineEdit2->setText( "" );
198   Group3Pnts2->LineEdit3->setText( "" );
199   if ( getConstructorId() == 0 )  myEditCurrentArgument = Group3Pnts->LineEdit1;
200   if ( getConstructorId() == 1 )  myEditCurrentArgument = Group3Pnts2->LineEdit1;
201
202   ConstructorsClicked( getConstructorId() );
203   return true;
204 }
205
206
207 //=================================================================================
208 // function : SelectionIntoArgument()
209 // purpose  : Called when selection as changed or other case
210 //=================================================================================
211 void BasicGUI_ArcDlg::SelectionIntoArgument()
212 {
213   if ( getConstructorId() != 0 && getConstructorId() != 1 )
214     return;
215   
216   myEditCurrentArgument->setText( "" );
217   if ( IObjectCount() != 1 ) {
218     switch ( getConstructorId() ) {
219     case 0:
220       if      ( myEditCurrentArgument == Group3Pnts->LineEdit1 )   myPoint1 = GEOM::GEOM_Object::_nil();
221       else if ( myEditCurrentArgument == Group3Pnts->LineEdit2 )   myPoint2 = GEOM::GEOM_Object::_nil();
222       else if ( myEditCurrentArgument == Group3Pnts->LineEdit3 )   myPoint3 = GEOM::GEOM_Object::_nil();
223       return;
224       break;
225     case 1:
226       if      ( myEditCurrentArgument == Group3Pnts2->LineEdit1 )   myPoint1 = GEOM::GEOM_Object::_nil();
227       else if ( myEditCurrentArgument == Group3Pnts2->LineEdit2 )   myPoint2 = GEOM::GEOM_Object::_nil();
228       else if ( myEditCurrentArgument == Group3Pnts2->LineEdit3 )   myPoint3 = GEOM::GEOM_Object::_nil();
229       return;
230       break;
231     }
232   }   
233   // nbSel == 1
234   Standard_Boolean aRes = Standard_False;
235   GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( firstIObject(), aRes );
236   if ( !CORBA::is_nil( aSelectedObject ) && aRes ) {
237     switch ( getConstructorId() ) {
238     case 0:
239       myEditCurrentArgument->setText( GEOMBase::GetName( aSelectedObject ) );
240       if      ( myEditCurrentArgument == Group3Pnts->LineEdit1 )   myPoint1 = aSelectedObject;
241       else if ( myEditCurrentArgument == Group3Pnts->LineEdit2 )   myPoint2 = aSelectedObject;
242       else if ( myEditCurrentArgument == Group3Pnts->LineEdit3 )   myPoint3 = aSelectedObject;
243       break;
244     case 1:
245       myEditCurrentArgument->setText( GEOMBase::GetName( aSelectedObject ) );
246       if      ( myEditCurrentArgument == Group3Pnts2->LineEdit1 )   myPoint1 = aSelectedObject;
247       else if ( myEditCurrentArgument == Group3Pnts2->LineEdit2 )   myPoint2 = aSelectedObject;
248       else if ( myEditCurrentArgument == Group3Pnts2->LineEdit3 )   myPoint3 = aSelectedObject;
249       break;
250     }
251   }
252
253   displayPreview();
254 }
255
256
257 //=================================================================================
258 // function : SetEditCurrentArgument()
259 // purpose  :
260 //=================================================================================
261 void BasicGUI_ArcDlg::SetEditCurrentArgument()
262 {
263   QPushButton* send = (QPushButton*)sender();
264   switch ( getConstructorId() ) {
265   case 0:
266     if      ( send == Group3Pnts->PushButton1 )   myEditCurrentArgument = Group3Pnts->LineEdit1;
267     else if ( send == Group3Pnts->PushButton2 )   myEditCurrentArgument = Group3Pnts->LineEdit2;
268     else if ( send == Group3Pnts->PushButton3 )   myEditCurrentArgument = Group3Pnts->LineEdit3;
269     break;
270   case 1:
271     if      ( send == Group3Pnts2->PushButton1 )   myEditCurrentArgument = Group3Pnts2->LineEdit1;
272     else if ( send == Group3Pnts2->PushButton2 )   myEditCurrentArgument = Group3Pnts2->LineEdit2;
273     else if ( send == Group3Pnts2->PushButton3 )   myEditCurrentArgument = Group3Pnts2->LineEdit3;
274     break;
275   }
276   myEditCurrentArgument->setFocus();
277   SelectionIntoArgument();
278 }
279
280
281 //=================================================================================
282 // function : LineEditReturnPressed()
283 // purpose  :
284 //=================================================================================
285 void BasicGUI_ArcDlg::LineEditReturnPressed()
286 {
287   QLineEdit* send = (QLineEdit*)sender();
288   if ( send == Group3Pnts->LineEdit1 || send == Group3Pnts->LineEdit2 || send == Group3Pnts->LineEdit3 ||
289        send == Group3Pnts2->LineEdit1 || send == Group3Pnts2->LineEdit2 || send == Group3Pnts2->LineEdit3 ) {
290     myEditCurrentArgument = send;
291     GEOMBase_Skeleton::LineEditReturnPressed();
292   }
293 }
294
295
296 //=================================================================================
297 // function : ActivateThisDialog()
298 // purpose  :
299 //=================================================================================
300 void BasicGUI_ArcDlg::ActivateThisDialog()
301 {
302   GEOMBase_Skeleton::ActivateThisDialog();
303   connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
304            SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
305
306   // myGeomGUI->SetState( 0 );
307   globalSelection( GEOM_POINT );
308
309   myEditCurrentArgument = Group3Pnts->LineEdit1;
310   myEditCurrentArgument->setFocus();
311
312   Group3Pnts->LineEdit1->setText( "" );
313   Group3Pnts->LineEdit2->setText( "" );
314   Group3Pnts->LineEdit3->setText( "" );
315   myPoint1 = myPoint2 = myPoint3 = GEOM::GEOM_Object::_nil();
316
317   ConstructorsClicked( getConstructorId() );
318   
319 }
320
321 //=================================================================================
322 // function : DeactivateActiveDialog()
323 // purpose  : public slot to deactivate if active
324 //=================================================================================
325 void BasicGUI_ArcDlg::DeactivateActiveDialog()
326 {
327   // myGeomGUI->SetState( -1 );
328   GEOMBase_Skeleton::DeactivateActiveDialog();
329 }
330
331 //=================================================================================
332 // function : enterEvent()
333 // purpose  :
334 //=================================================================================
335 void BasicGUI_ArcDlg::enterEvent( QEvent* )
336 {
337   if ( !mainFrame()->GroupConstructors->isEnabled() )
338     ActivateThisDialog();
339 }
340
341 //=================================================================================
342 // function : createOperation
343 // purpose  :
344 //=================================================================================
345 GEOM::GEOM_IOperations_ptr BasicGUI_ArcDlg::createOperation()
346 {
347   return myGeomGUI->GetGeomGen()->GetICurvesOperations( getStudyId() );
348 }
349
350 //=================================================================================
351 // function : isEqual
352 // purpose  : it may also be needed to check for min distance between gp_Pnt-s...
353 //=================================================================================
354 static bool isEqual( const GEOM::GEOM_Object_var& thePnt1, const GEOM::GEOM_Object_var& thePnt2 )
355 {
356   return thePnt1->_is_equivalent( thePnt2 );
357 }
358
359 //=================================================================================
360 // function : isValid
361 // purpose  :
362 //=================================================================================
363 bool BasicGUI_ArcDlg::isValid( QString& msg )
364 {
365   return !myPoint1->_is_nil() && !myPoint2->_is_nil() && !myPoint3->_is_nil() &&
366     !isEqual( myPoint1, myPoint2 ) && !isEqual( myPoint1, myPoint3 ) && !isEqual( myPoint2, myPoint3 );
367 }
368
369 //=================================================================================
370 // function : execute
371 // purpose  :
372 //=================================================================================
373 bool BasicGUI_ArcDlg::execute( ObjectList& objects )
374 {
375   bool res = false;
376   GEOM::GEOM_Object_var anObj;
377
378   switch ( getConstructorId() ) {
379   case 0:
380     {
381       if ( !CORBA::is_nil( myPoint1 ) && !CORBA::is_nil( myPoint2 ) && !CORBA::is_nil( myPoint3 ) ) {
382         anObj = GEOM::GEOM_ICurvesOperations::_narrow( getOperation() )->MakeArc( myPoint1, myPoint2, myPoint3 );
383         res = true;
384       }
385       break;
386     }
387   case 1:
388     {
389       bool Sense = Group3Pnts2->CheckButton1->isChecked();
390       if ( !CORBA::is_nil( myPoint1 ) && !CORBA::is_nil( myPoint2 ) && !CORBA::is_nil( myPoint3 ) ) {
391         anObj = GEOM::GEOM_ICurvesOperations::_narrow( getOperation() )->MakeArcCenter( myPoint1, myPoint2, myPoint3, Sense );
392         res = true;
393       }
394       break;
395     }
396   }
397   if ( !anObj->_is_nil() ) {
398     objects.push_back( anObj._retn() );
399   }
400   return res;
401 }
402
403 //=================================================================================
404 // function : closeEvent
405 // purpose  :
406 //=================================================================================
407 void BasicGUI_ArcDlg::closeEvent( QCloseEvent* e )
408 {
409   GEOMBase_Skeleton::closeEvent( e );
410 }
411
412 //=================================================================================
413 // function : ConstructorsClicked()
414 // purpose  : Radio button management
415 //=================================================================================
416 void BasicGUI_ArcDlg::ConstructorsClicked( int constructorId )
417 {
418   disconnect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(), 0, this, 0 );
419
420   switch ( constructorId ) {
421   case 0:
422     {
423       Group3Pnts2->hide();
424       Group3Pnts->show();
425
426       connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
427                SIGNAL(currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
428       break;
429     }
430   case 1:
431     {
432       Group3Pnts->hide();
433       Group3Pnts2->show();
434       connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),          
435                SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
436       
437       break;
438     }
439   }
440
441   qApp->processEvents();
442   updateGeometry();
443   resize( minimumSize() );
444
445   displayPreview();
446 }
447
448 //=================================================================================
449 // function : ReverseSense()
450 // purpose  : Orientation of the arc
451 //=================================================================================
452 void BasicGUI_ArcDlg::ReverseSense()
453 {
454   displayPreview();
455 }