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