]> SALOME platform Git repositories - modules/geom.git/blob - src/BasicGUI/BasicGUI_CircleDlg.cxx
Salome HOME
NPAL16557 NPAL16558 NPAL16578 NPAL16549 NPAL16561
[modules/geom.git] / src / BasicGUI / BasicGUI_CircleDlg.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 //
23 //
24 //  File   : BasicGUI_CircleDlg.cxx
25 //  Author : Lucien PIGNOLONI
26 //  Module : GEOM
27 //  $Header$
28
29 #include "BasicGUI_CircleDlg.h"
30
31 #include "SUIT_Desktop.h"
32 #include "SUIT_Session.h"
33 #include "SalomeApp_Application.h"
34 #include "LightApp_SelectionMgr.h"
35
36 #include <qlabel.h>
37
38 #include "GEOMImpl_Types.hxx"
39 #include "GEOM_Object.hxx"
40 #include "GEOM_Engine.hxx"
41
42 #include "utilities.h"
43
44 //=================================================================================
45 // class    : BasicGUI_CircleDlg()
46 // purpose  : Constructs a BasicGUI_CircleDlg which is a child of 'parent', with the 
47 //            name 'name' and widget flags set to 'f'.
48 //            The dialog will by default be modeless, unless you set 'modal' to
49 //            TRUE to construct a modal dialog.
50 //=================================================================================
51 BasicGUI_CircleDlg::BasicGUI_CircleDlg(GeometryGUI* theGeometryGUI, QWidget* parent,
52                                        const char* name, bool modal, WFlags fl)
53   :GEOMBase_Skeleton(theGeometryGUI, parent, name, modal, WStyle_Customize |
54                      WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
55 {
56   QPixmap image0(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_CIRCLE_PV")));
57   QPixmap image2(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_CIRCLE_PNTS")));
58   QPixmap image3(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_CIRCLE_C2P")));
59   QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_SELECT")));
60
61   setCaption(tr("GEOM_CIRCLE_TITLE"));
62
63   /***************************************************************/
64   GroupConstructors->setTitle(tr("GEOM_CIRCLE"));
65   RadioButton1->setPixmap(image0);
66   RadioButton2->setPixmap(image2);
67   RadioButton3->setPixmap(image3);
68
69   GroupPntVecR = new DlgRef_2Sel1Spin(this, "GroupPntVecR");
70   GroupPntVecR->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
71   
72   GroupPntVecR->TextLabel1->setText(tr("GEOM_CENTER_POINT"));
73   GroupPntVecR->TextLabel2->setText(tr("GEOM_VECTOR"));
74   GroupPntVecR->TextLabel3->setText(tr("GEOM_RADIUS"));
75   GroupPntVecR->PushButton1->setPixmap(image1);
76   GroupPntVecR->PushButton2->setPixmap(image1);
77
78   GroupPntVecR->LineEdit1->setReadOnly( true );
79   GroupPntVecR->LineEdit2->setReadOnly( true );
80
81   Group3Pnts = new DlgRef_3Sel_QTD(this, "Group3Pnts");
82   Group3Pnts->GroupBox1->setTitle(tr("GEOM_3_POINTS"));
83   Group3Pnts->TextLabel1->setText(tr("GEOM_POINT1"));
84   Group3Pnts->TextLabel2->setText(tr("GEOM_POINT2"));
85   Group3Pnts->TextLabel3->setText(tr("GEOM_POINT3"));
86   Group3Pnts->PushButton1->setPixmap(image1);
87   Group3Pnts->PushButton2->setPixmap(image1);
88   Group3Pnts->PushButton3->setPixmap(image1);
89
90   Group3Pnts->LineEdit1->setReadOnly( true );
91   Group3Pnts->LineEdit2->setReadOnly( true );
92   Group3Pnts->LineEdit3->setReadOnly( true );
93
94   GroupCenter2Pnts = new DlgRef_3Sel_QTD(this, "GroupCenter2Pnts");
95   GroupCenter2Pnts->GroupBox1->setTitle(tr("GEOM_CENTER_2POINTS"));
96   GroupCenter2Pnts->TextLabel1->setText(tr("GEOM_CENTER_POINT"));
97   GroupCenter2Pnts->TextLabel2->setText(tr("GEOM_POINT1"));
98   GroupCenter2Pnts->TextLabel3->setText(tr("GEOM_POINT2"));
99   GroupCenter2Pnts->PushButton1->setPixmap(image1);
100   GroupCenter2Pnts->PushButton2->setPixmap(image1);
101   GroupCenter2Pnts->PushButton3->setPixmap(image1);
102
103   GroupCenter2Pnts->LineEdit1->setReadOnly( true );
104   GroupCenter2Pnts->LineEdit2->setReadOnly( true );
105   GroupCenter2Pnts->LineEdit3->setReadOnly( true );
106
107   Layout1->addWidget( GroupPntVecR, 2, 0 );
108   Layout1->addWidget( Group3Pnts, 2, 0 );
109   Layout1->addWidget( GroupCenter2Pnts, 2, 0 );
110   /***************************************************************/
111
112   setHelpFileName("circle.htm");
113
114   Init();
115 }
116
117
118 //=================================================================================
119 // function : ~BasicGUI_CircleDlg()
120 // purpose  : Destroys the object and frees any allocated resources
121 //=================================================================================
122 BasicGUI_CircleDlg::~BasicGUI_CircleDlg()
123 {
124 }
125
126
127 //=================================================================================
128 // function : Init()
129 // purpose  :
130 //=================================================================================
131 void BasicGUI_CircleDlg::Init()
132 {
133   /* init variables */
134   myEditCurrentArgument = GroupPntVecR->LineEdit1;
135
136   myPoint = myDir = myPoint1 = myPoint2 = myPoint3 = GEOM::GEOM_Object::_nil();
137
138   // myGeomGUI->SetState( 0 );
139
140   /* Get setting of step value from file configuration */
141   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
142   double aStep = resMgr->doubleValue( "Geometry", "SettingsGeomStep", 100);
143
144   /* min, max, step and decimals for spin boxes & initial values */
145   GroupPntVecR->SpinBox_DX->RangeStepAndValidator(0.001, COORD_MAX, aStep, DBL_DIGITS_DISPLAY);
146   GroupPntVecR->SpinBox_DX->SetValue( 100 );
147
148   /* signals and slots connections */
149   connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
150   connect(myGeomGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
151   connect(myGeomGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
152   
153   connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
154   connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
155   connect(GroupConstructors, SIGNAL(clicked(int)), this, SLOT(ConstructorsClicked(int)));
156
157   connect(GroupPntVecR->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
158   connect(GroupPntVecR->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
159   connect(Group3Pnts->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
160   connect(Group3Pnts->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
161   connect(Group3Pnts->PushButton3, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
162
163   connect(GroupCenter2Pnts->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
164   connect(GroupCenter2Pnts->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
165   connect(GroupCenter2Pnts->PushButton3, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
166
167   connect(GroupPntVecR->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
168   connect(GroupPntVecR->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
169
170   connect(GroupPntVecR->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
171   connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPntVecR->SpinBox_DX, SLOT(SetStep(double)));
172   
173   connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
174           SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
175
176   initName( tr( "GEOM_CIRCLE" ) );
177
178   Group3Pnts->hide();
179   GroupCenter2Pnts->hide();
180   ConstructorsClicked( 0 );
181 }
182
183 //=================================================================================
184 // function : ConstructorsClicked()
185 // purpose  : Radio button management
186 //=================================================================================
187 void BasicGUI_CircleDlg::ConstructorsClicked( int constructorId )
188 {
189   disconnect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), 0, this, 0 );
190   myPoint = myDir = myPoint1 = myPoint2 = myPoint3 = GEOM::GEOM_Object::_nil();
191
192   switch ( constructorId )
193   {
194     case 0:
195       {
196         Group3Pnts->hide();
197         GroupCenter2Pnts->hide();
198         resize(0, 0);
199         GroupPntVecR->show();
200         
201         myEditCurrentArgument = GroupPntVecR->LineEdit1;
202         GroupPntVecR->LineEdit1->setText("");
203         GroupPntVecR->LineEdit2->setText("");
204         break;
205       }
206   case 1:
207     {
208       GroupPntVecR->hide();
209       GroupCenter2Pnts->hide();
210       resize( 0, 0 );
211       Group3Pnts->show();
212       
213       myEditCurrentArgument = Group3Pnts->LineEdit1;
214       Group3Pnts->LineEdit1->setText("");
215       Group3Pnts->LineEdit2->setText("");
216       Group3Pnts->LineEdit3->setText("");
217       break;
218       }
219    case 2:
220       {
221         GroupPntVecR->hide();
222         Group3Pnts->hide();             
223         resize( 0, 0 );
224         GroupCenter2Pnts->show();
225
226         myEditCurrentArgument = GroupCenter2Pnts->LineEdit1;
227         GroupCenter2Pnts->LineEdit1->setText("");
228         GroupCenter2Pnts->LineEdit2->setText("");
229         GroupCenter2Pnts->LineEdit3->setText("");
230         break;
231       }
232   }
233   
234   myEditCurrentArgument->setFocus();
235   globalSelection( GEOM_POINT );
236   connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), 
237           SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
238 }
239
240 //=================================================================================
241 // function : ClickOnOk()
242 // purpose  :
243 //=================================================================================
244 void BasicGUI_CircleDlg::ClickOnOk()
245 {
246   if ( ClickOnApply() )
247     ClickOnCancel();
248 }
249
250 //=================================================================================
251 // function : ClickOnApply()
252 // purpose  :
253 //=================================================================================
254 bool BasicGUI_CircleDlg::ClickOnApply()
255 {
256   if ( !onAccept() )
257     return false;
258
259   initName();
260   ConstructorsClicked( getConstructorId() );
261   return true;
262 }
263
264 //=======================================================================
265 // function : ClickOnCancel()
266 // purpose  :
267 //=======================================================================
268 void BasicGUI_CircleDlg::ClickOnCancel()
269 {
270   GEOMBase_Skeleton::ClickOnCancel();
271 }
272
273 //=================================================================================
274 // function : SelectionIntoArgument()
275 // purpose  : Called when selection as changed or other case
276 //=================================================================================
277 void BasicGUI_CircleDlg::SelectionIntoArgument()
278 {
279   myEditCurrentArgument->setText("");
280   
281   if ( IObjectCount() != 1 )  
282   {
283     if      ( myEditCurrentArgument == GroupPntVecR->LineEdit1 ) myPoint  = GEOM::GEOM_Object::_nil();
284     else if ( myEditCurrentArgument == GroupPntVecR->LineEdit2 ) myDir    = GEOM::GEOM_Object::_nil();
285     else if ( myEditCurrentArgument == Group3Pnts->LineEdit1 )   myPoint1 = GEOM::GEOM_Object::_nil();
286     else if ( myEditCurrentArgument == Group3Pnts->LineEdit2 )   myPoint2 = GEOM::GEOM_Object::_nil();
287     else if ( myEditCurrentArgument == Group3Pnts->LineEdit3 )   myPoint3 = GEOM::GEOM_Object::_nil();
288     else if ( myEditCurrentArgument == GroupCenter2Pnts->LineEdit1 ) myPoint4  = GEOM::GEOM_Object::_nil();
289     else if ( myEditCurrentArgument == GroupCenter2Pnts->LineEdit2 ) myPoint5  = GEOM::GEOM_Object::_nil();
290     else if ( myEditCurrentArgument == GroupCenter2Pnts->LineEdit3 ) myPoint6  = GEOM::GEOM_Object::_nil();
291     return;
292   }
293
294   // nbSel == 1
295   Standard_Boolean aRes = Standard_False;
296   GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( firstIObject(), aRes );
297   if ( !CORBA::is_nil( aSelectedObject ) && aRes )
298   { 
299  
300     myEditCurrentArgument->setText( GEOMBase::GetName( aSelectedObject ) );
301     if      ( myEditCurrentArgument == GroupPntVecR->LineEdit1 ) myPoint  = aSelectedObject;
302     else if ( myEditCurrentArgument == GroupPntVecR->LineEdit2 ) myDir    = aSelectedObject;
303     else if ( myEditCurrentArgument == Group3Pnts->LineEdit1 )   myPoint1 = aSelectedObject;
304     else if ( myEditCurrentArgument == Group3Pnts->LineEdit2 )   myPoint2 = aSelectedObject;
305     else if ( myEditCurrentArgument == Group3Pnts->LineEdit3 )   myPoint3 = aSelectedObject;
306     else if ( myEditCurrentArgument == GroupCenter2Pnts->LineEdit1 ) myPoint4 = aSelectedObject;
307     else if ( myEditCurrentArgument == GroupCenter2Pnts->LineEdit2 ) myPoint5 = aSelectedObject;
308     else if ( myEditCurrentArgument == GroupCenter2Pnts->LineEdit3 ) myPoint6 = aSelectedObject;
309   }
310   displayPreview();
311 }
312
313
314 //=================================================================================
315 // function : SetEditCurrentArgument()
316 // purpose  :
317 //=================================================================================
318 void BasicGUI_CircleDlg::SetEditCurrentArgument()
319 {
320   QPushButton* send = (QPushButton*)sender();
321
322   if ( send == GroupPntVecR->PushButton1 )      myEditCurrentArgument = GroupPntVecR->LineEdit1;
323   else if ( send == GroupPntVecR->PushButton2 ) myEditCurrentArgument = GroupPntVecR->LineEdit2;
324   else if ( send == Group3Pnts->PushButton1 )   myEditCurrentArgument = Group3Pnts->LineEdit1;
325   else if ( send == Group3Pnts->PushButton2 )   myEditCurrentArgument = Group3Pnts->LineEdit2;
326   else if ( send == Group3Pnts->PushButton3 )   myEditCurrentArgument = Group3Pnts->LineEdit3;
327   else if ( send == GroupCenter2Pnts->PushButton1 )   myEditCurrentArgument = GroupCenter2Pnts->LineEdit1;
328   else if ( send == GroupCenter2Pnts->PushButton2 )   myEditCurrentArgument = GroupCenter2Pnts->LineEdit2;
329   else if ( send == GroupCenter2Pnts->PushButton3 )   myEditCurrentArgument = GroupCenter2Pnts->LineEdit3;
330   
331   myEditCurrentArgument->setFocus();
332   
333   if ( myEditCurrentArgument == GroupPntVecR->LineEdit2 ) 
334     globalSelection( GEOM_LINE );
335   else
336     globalSelection( GEOM_POINT );
337   SelectionIntoArgument();
338 }
339
340 //=================================================================================
341 // function : LineEditReturnPressed()
342 // purpose  :
343 //=================================================================================
344 void BasicGUI_CircleDlg::LineEditReturnPressed()
345 {
346   QLineEdit* send = (QLineEdit*)sender();
347   if ( send == GroupPntVecR->LineEdit1 ||
348        send == GroupPntVecR->LineEdit2 ||
349        send == Group3Pnts->LineEdit1 ||
350        send == Group3Pnts->LineEdit2 ||
351        send == Group3Pnts->LineEdit3 ||
352        send == GroupCenter2Pnts->LineEdit1 ||
353        send == GroupCenter2Pnts->LineEdit2 ||
354        send == GroupCenter2Pnts->LineEdit3 )
355   {
356     myEditCurrentArgument = send;
357     GEOMBase_Skeleton::LineEditReturnPressed();
358   }
359 }
360
361
362 //=================================================================================
363 // function : ActivateThisDialog()
364 // purpose  :
365 //=================================================================================
366 void BasicGUI_CircleDlg::ActivateThisDialog()
367 {
368   GEOMBase_Skeleton::ActivateThisDialog();
369   globalSelection( GEOM_POINT );
370   connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), 
371           SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
372
373   // myGeomGUI->SetState( 0 );
374
375   ConstructorsClicked( getConstructorId() );
376 }
377
378
379 //=================================================================================
380 // function : enterEvent()
381 // purpose  :
382 //=================================================================================
383 void BasicGUI_CircleDlg::enterEvent(QEvent* e)
384 {
385   if ( !GroupConstructors->isEnabled() )
386     ActivateThisDialog();
387 }
388
389 //=================================================================================
390 // function : DeactivateActiveDialog()
391 // purpose  : public slot to deactivate if active
392 //=================================================================================
393 void BasicGUI_CircleDlg::DeactivateActiveDialog()
394 {
395   // myGeomGUI->SetState( -1 );
396   GEOMBase_Skeleton::DeactivateActiveDialog();
397 }
398
399 //=================================================================================
400 // function : ValueChangedInSpinBox()
401 // purpose  :
402 //=================================================================================
403 void BasicGUI_CircleDlg::ValueChangedInSpinBox()
404 {
405   displayPreview();
406 }
407
408 //=================================================================================
409 // function : getRadius()
410 // purpose  :
411 //=================================================================================
412 double BasicGUI_CircleDlg::getRadius() const
413 {
414   switch ( getConstructorId() )
415     {
416     case 0 :
417       return GroupPntVecR->SpinBox_DX->GetValue();
418     }
419 }
420
421 //=================================================================================
422 // function : createOperation
423 // purpose  :
424 //=================================================================================
425 GEOM::GEOM_IOperations_ptr BasicGUI_CircleDlg::createOperation()
426 {
427   return myGeomGUI->GetGeomGen()->GetICurvesOperations( getStudyId() );
428 }
429
430 //=================================================================================
431 // function : isEqual
432 // purpose  : it may also be needed to check for min distance between gp_Pnt-s...
433 //=================================================================================
434 static bool isEqual( const GEOM::GEOM_Object_var& thePnt1, const GEOM::GEOM_Object_var& thePnt2 )
435 {
436   return thePnt1->_is_equivalent( thePnt2 );
437 }
438
439 //=================================================================================
440 // function : isValid
441 // purpose  :
442 //=================================================================================
443 bool BasicGUI_CircleDlg::isValid( QString& msg )
444 {
445   const int id = getConstructorId();
446   if ( id == 0 )
447     return !myPoint->_is_nil() && !myDir->_is_nil() && getRadius() > 0;
448   else if ( id == 1 )
449     return !myPoint1->_is_nil() && !myPoint2->_is_nil() && !myPoint3->_is_nil() &&
450       !isEqual( myPoint1, myPoint2 ) && !isEqual( myPoint1, myPoint3 ) && !isEqual( myPoint2, myPoint3 );
451   else if ( id == 2 )
452       return !myPoint4->_is_nil() && !myPoint5->_is_nil() && !myPoint6->_is_nil() &&
453       !isEqual( myPoint4, myPoint5 ) && !isEqual( myPoint5, myPoint6 ) && !isEqual( myPoint4, myPoint6 );
454   return false;
455 }
456
457 //=================================================================================
458 // function : execute
459 // purpose  :
460 //=================================================================================
461 bool BasicGUI_CircleDlg::execute( ObjectList& objects )
462 {
463   bool res = false;
464   
465   GEOM::GEOM_Object_var anObj;
466   
467   switch ( getConstructorId() )
468   {
469     cout << "constructior ID = " << getConstructorId() << endl;
470   case 0 :
471     anObj = GEOM::GEOM_ICurvesOperations::_narrow( getOperation() )->MakeCirclePntVecR( myPoint, myDir, getRadius() );
472     res = true;
473     break;
474   case 1 :
475     anObj = GEOM::GEOM_ICurvesOperations::_narrow( getOperation() )->MakeCircleThreePnt( myPoint1, myPoint2, myPoint3 );
476     res = true;
477     break;
478   case 2 :
479     anObj = GEOM::GEOM_ICurvesOperations::_narrow( getOperation() )->MakeCircleCenter2Pnt( myPoint4, myPoint5, myPoint6 );
480     res = true;
481     break;
482   }
483   
484   if ( !anObj->_is_nil() )
485     objects.push_back( anObj._retn() );
486   else cout << "Execute Object is NULL!" << endl;
487   
488   return res;
489 }
490
491 //=================================================================================
492 // function : closeEvent
493 // purpose  :
494 //=================================================================================
495 void BasicGUI_CircleDlg::closeEvent( QCloseEvent* e )
496 {
497   GEOMBase_Skeleton::closeEvent( e );
498 }
499