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