]> SALOME platform Git repositories - modules/geom.git/blob - src/BasicGUI/BasicGUI_ArcDlg.cxx
Salome HOME
Correct make file for shared modules script
[modules/geom.git] / src / BasicGUI / BasicGUI_ArcDlg.cxx
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  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 //  GEOM GEOMGUI : GUI for Geometry component
23 //  File   : BasicGUI_ArcDlg.cxx
24 //  Author : Lucien PIGNOLONI
25 //  Module : GEOM
26 //  $Header$
27 //
28 #include "BasicGUI_ArcDlg.h"
29
30 #include "SUIT_Desktop.h"
31 #include "SUIT_Session.h"
32 #include "SalomeApp_Application.h"
33 #include "LightApp_SelectionMgr.h"
34
35 #include <TColStd_IndexedMapOfInteger.hxx>
36 #include <TopTools_IndexedMapOfShape.hxx>
37 #include <TopoDS_Shape.hxx>
38 #include <TopoDS_Edge.hxx>
39 #include <TopoDS.hxx>
40 #include <TopExp.hxx>
41
42 #include <qlabel.h>
43 #include <qcheckbox.h>
44
45 #include "GEOMImpl_Types.hxx"
46
47 #include "utilities.h"
48
49 //=================================================================================
50 // class    : BasicGUI_ArcDlg()
51 // purpose  : Constructs a BasicGUI_ArcDlg which is a child of 'parent', with the
52 //            name 'name' and widget flags set to 'f'.
53 //            The dialog will by default be modeless, unless you set 'modal' to
54 //            TRUE to construct a modal dialog.
55 //=================================================================================
56 BasicGUI_ArcDlg::BasicGUI_ArcDlg(GeometryGUI* theGeometryGUI, QWidget* parent,
57                                  const char* name, bool modal, WFlags fl)
58   : GEOMBase_Skeleton(theGeometryGUI, parent, name, modal, WStyle_Customize |
59                       WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
60 {
61   SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
62   QPixmap image0(aResMgr->loadPixmap("GEOM",tr("ICON_DLG_ARC")));
63   QPixmap image1(aResMgr->loadPixmap("GEOM",tr("ICON_DLG_ARC_CENTER")));
64   QPixmap image2(aResMgr->loadPixmap("GEOM",tr("ICON_SELECT")));
65
66   setCaption(tr("GEOM_ARC_TITLE"));
67
68   /***************************************************************/
69   GroupConstructors->setTitle(tr("GEOM_ARC"));
70   RadioButton1->setPixmap(image0);
71   RadioButton2->setPixmap(image1);
72   RadioButton3->close(TRUE);
73
74   Group3Pnts = new DlgRef_3Sel_QTD(this, "Group3Pnts");
75   Group3Pnts->GroupBox1->setTitle(tr("GEOM_POINTS"));
76   Group3Pnts->TextLabel1->setText(tr("GEOM_POINT_I").arg("1"));
77   Group3Pnts->TextLabel2->setText(tr("GEOM_POINT_I").arg("2"));
78   Group3Pnts->TextLabel3->setText(tr("GEOM_POINT_I").arg("3"));
79
80   Group3Pnts->LineEdit1->setReadOnly( true );
81   Group3Pnts->LineEdit2->setReadOnly( true );
82   Group3Pnts->LineEdit3->setReadOnly( true );
83
84   Group3Pnts->PushButton1->setPixmap(image2);
85   Group3Pnts->PushButton2->setPixmap(image2);
86   Group3Pnts->PushButton3->setPixmap(image2);
87
88
89   Group3Pnts2 = new DlgRef_3Sel1Check_QTD(this, "Group3Pnts2");
90   Group3Pnts2->GroupBox1->setTitle(tr("GEOM_POINTS"));
91   Group3Pnts2->TextLabel1->setText(tr("GEOM_CENTER_POINT"));
92   Group3Pnts2->TextLabel2->setText(tr("GEOM_POINT_I").arg("Start"));
93   Group3Pnts2->TextLabel3->setText(tr("GEOM_POINT_I").arg("End"));
94
95   Group3Pnts2->LineEdit1->setReadOnly( true );
96   Group3Pnts2->LineEdit2->setReadOnly( true );
97   Group3Pnts2->LineEdit3->setReadOnly( true );
98
99   Group3Pnts2->PushButton1->setPixmap(image2);
100   Group3Pnts2->PushButton2->setPixmap(image2);
101   Group3Pnts2->PushButton3->setPixmap(image2);
102
103   Group3Pnts2->CheckButton1->setText(tr("GEOM_REVERSE"));
104
105   Layout1->addWidget( Group3Pnts, 2, 0 );
106   Layout1->addWidget( Group3Pnts2, 2, 0 );
107   /***************************************************************/
108
109   setHelpFileName("create_arc_page.html");
110
111   Init();
112 }
113
114
115 //=================================================================================
116 // function : ~BasicGUI_ArcDlg()
117 // purpose  : Destroys the object and frees any allocated resources
118 //=================================================================================
119 BasicGUI_ArcDlg::~BasicGUI_ArcDlg()
120 {
121 }
122
123
124 //=================================================================================
125 // function : Init()
126 // purpose  :
127 //=================================================================================
128 void BasicGUI_ArcDlg::Init()
129 {
130   /* init variables */
131   myEditCurrentArgument = Group3Pnts->LineEdit1;
132   myPoint1 = myPoint2 = myPoint3 = GEOM::GEOM_Object::_nil();
133   Group3Pnts2->CheckButton1->setChecked(FALSE);
134
135   /* signals and slots connections */
136   connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
137   connect(myGeomGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
138   connect(myGeomGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
139
140   connect(GroupConstructors, SIGNAL(clicked(int)), this, SLOT(ConstructorsClicked(int)));
141
142   connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
143   connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
144
145   connect(Group3Pnts->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
146   connect(Group3Pnts->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
147   connect(Group3Pnts->PushButton3, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
148
149   connect(Group3Pnts->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
150   connect(Group3Pnts->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
151   connect(Group3Pnts->LineEdit3, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
152
153   connect(Group3Pnts2->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
154   connect(Group3Pnts2->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
155   connect(Group3Pnts2->PushButton3, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
156
157   connect(Group3Pnts2->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
158   connect(Group3Pnts2->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
159   connect(Group3Pnts2->LineEdit3, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
160
161   connect(Group3Pnts2->CheckButton1, SIGNAL(stateChanged(int)), this, SLOT(ReverseSense(int)));
162
163   connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
164           this, SLOT(SelectionIntoArgument()));
165
166   initName( tr( "GEOM_ARC" ));
167   ConstructorsClicked( 0 );
168 }
169
170
171 //=================================================================================
172 // function : ConstructorsClicked()
173 // purpose  : Radio button management
174 //=================================================================================
175 void BasicGUI_ArcDlg::ConstructorsClicked (int constructorId)
176 {
177   disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
178
179   switch (constructorId)
180   {
181   case 0:
182     {
183       globalSelection(); // close local contexts, if any
184       localSelection(GEOM::GEOM_Object::_nil(), TopAbs_VERTEX); //Select Vertex on All Shapes
185
186       Group3Pnts->show();
187       resize(0, 0);
188       Group3Pnts2->hide();
189
190       Group3Pnts->LineEdit1->setText(Group3Pnts2->LineEdit1->text());
191       Group3Pnts->LineEdit2->setText(Group3Pnts2->LineEdit2->text());
192       Group3Pnts->LineEdit3->setText(Group3Pnts2->LineEdit3->text());
193
194       myEditCurrentArgument = Group3Pnts->LineEdit1;
195
196       break;
197     }
198   case 1:
199     {
200       globalSelection(); // close local contexts, if any
201       localSelection(GEOM::GEOM_Object::_nil(), TopAbs_VERTEX); //Select Vertex on All Shapes
202
203       Group3Pnts->hide();
204       resize(0, 0);
205       Group3Pnts2->show();
206
207       Group3Pnts2->LineEdit1->setText(Group3Pnts->LineEdit1->text());
208       Group3Pnts2->LineEdit2->setText(Group3Pnts->LineEdit2->text());
209       Group3Pnts2->LineEdit3->setText(Group3Pnts->LineEdit3->text());
210
211       myEditCurrentArgument = Group3Pnts2->LineEdit1;
212
213       break;
214     }
215   }
216
217   myEditCurrentArgument->setFocus();
218   connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
219           this, SLOT(SelectionIntoArgument()));
220
221   if (CORBA::is_nil(myPoint1))
222     SelectionIntoArgument();
223
224   displayPreview();
225 }
226
227
228 //=================================================================================
229 // function : ClickOnOk()
230 // purpose  :
231 //=================================================================================
232 void BasicGUI_ArcDlg::ClickOnOk()
233 {
234   if ( ClickOnApply() )
235     ClickOnCancel();
236 }
237
238 //=================================================================================
239 // function : ClickOnApply()
240 // purpose  :
241 //=================================================================================
242 bool BasicGUI_ArcDlg::ClickOnApply()
243 {
244   if ( !onAccept() )
245     return false;
246
247   initName();
248   return true;
249 }
250
251 //=================================================================================
252 // function : SelectionIntoArgument()
253 // purpose  : Called when selection as changed or other case
254 //=================================================================================
255 void BasicGUI_ArcDlg::SelectionIntoArgument()
256 {
257   if ((getConstructorId() != 0) && (getConstructorId() != 1))
258     return;
259
260   myEditCurrentArgument->setText("");
261
262   if (IObjectCount() != 1)
263   {
264     switch (getConstructorId())
265     {
266     case 0:
267       {
268         if      ( myEditCurrentArgument == Group3Pnts->LineEdit1 )   myPoint1 = GEOM::GEOM_Object::_nil();
269         else if ( myEditCurrentArgument == Group3Pnts->LineEdit2 )   myPoint2 = GEOM::GEOM_Object::_nil();
270         else if ( myEditCurrentArgument == Group3Pnts->LineEdit3 )   myPoint3 = GEOM::GEOM_Object::_nil();
271         return;
272         break;
273       }
274     case 1:
275       {
276         if      ( myEditCurrentArgument == Group3Pnts2->LineEdit1 )   myPoint1 = GEOM::GEOM_Object::_nil();
277         else if ( myEditCurrentArgument == Group3Pnts2->LineEdit2 )   myPoint2 = GEOM::GEOM_Object::_nil();
278         else if ( myEditCurrentArgument == Group3Pnts2->LineEdit3 )   myPoint3 = GEOM::GEOM_Object::_nil();
279         return;
280         break;
281       }
282     }
283   }
284
285   // nbSel == 1
286   Standard_Boolean aRes = Standard_False;
287   GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject(firstIObject(), aRes);
288   if (!CORBA::is_nil(aSelectedObject) && aRes)
289   {
290     QString aName = GEOMBase::GetName(aSelectedObject);
291
292     // Get Selected object if selected subshape
293     TopoDS_Shape aShape;
294     if (GEOMBase::GetShape(aSelectedObject, aShape, TopAbs_SHAPE) && !aShape.IsNull())
295     {
296       LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
297       TColStd_IndexedMapOfInteger aMap;
298       aSelMgr->GetIndexes(firstIObject(), aMap);
299       if (aMap.Extent() == 1) // Local Selection
300       {
301         int anIndex = aMap(1);
302         aName += QString(":vertex_%1").arg(anIndex);
303
304         //Find SubShape Object in Father
305         GEOM::GEOM_Object_var aFindedObject = GEOMBase_Helper::findObjectInFather(aSelectedObject, aName);
306
307         if ( aFindedObject == GEOM::GEOM_Object::_nil() ) { // Object not found in study
308           GEOM::GEOM_IShapesOperations_var aShapesOp = getGeomEngine()->GetIShapesOperations(getStudyId());
309           aSelectedObject = aShapesOp->GetSubShape(aSelectedObject, anIndex);
310         }
311         else
312           aSelectedObject = aFindedObject; // get Object from study
313       }
314       else // Global Selection
315       {
316         if (aShape.ShapeType() != TopAbs_VERTEX) {
317           aSelectedObject = GEOM::GEOM_Object::_nil();
318           aName = "";
319         }
320       }
321     }
322
323     myEditCurrentArgument->setText(aName);
324
325     switch (getConstructorId())
326     {
327       case 0:
328       {
329         if      ( myEditCurrentArgument == Group3Pnts->LineEdit1 )   myPoint1 = aSelectedObject;
330         else if ( myEditCurrentArgument == Group3Pnts->LineEdit2 )   myPoint2 = aSelectedObject;
331         else if ( myEditCurrentArgument == Group3Pnts->LineEdit3 )   myPoint3 = aSelectedObject;
332         break;
333       }
334       case 1:
335       {
336         if      ( myEditCurrentArgument == Group3Pnts2->LineEdit1 )   myPoint1 = aSelectedObject;
337         else if ( myEditCurrentArgument == Group3Pnts2->LineEdit2 )   myPoint2 = aSelectedObject;
338         else if ( myEditCurrentArgument == Group3Pnts2->LineEdit3 )   myPoint3 = aSelectedObject;
339         break;
340       }
341     }
342   }
343
344   displayPreview();
345 }
346
347 //=================================================================================
348 // function : LineEditReturnPressed()
349 // purpose  :
350 //=================================================================================
351 void BasicGUI_ArcDlg::LineEditReturnPressed()
352 {
353   QLineEdit* send = (QLineEdit*)sender();
354   if (send == Group3Pnts->LineEdit1  || send == Group3Pnts->LineEdit2  || send == Group3Pnts->LineEdit3 ||
355       send == Group3Pnts2->LineEdit1 || send == Group3Pnts2->LineEdit2 || send == Group3Pnts2->LineEdit3)
356   {
357     myEditCurrentArgument = send;
358     GEOMBase_Skeleton::LineEditReturnPressed();
359   }
360 }
361
362
363 //=================================================================================
364 // function : SetEditCurrentArgument()
365 // purpose  :
366 //=================================================================================
367 void BasicGUI_ArcDlg::SetEditCurrentArgument()
368 {
369   QPushButton* send = (QPushButton*)sender();
370   switch (getConstructorId())
371   {
372     case 0:
373     {
374       if      ( send == Group3Pnts->PushButton1 )   myEditCurrentArgument = Group3Pnts->LineEdit1;
375       else if ( send == Group3Pnts->PushButton2 )   myEditCurrentArgument = Group3Pnts->LineEdit2;
376       else if ( send == Group3Pnts->PushButton3 )   myEditCurrentArgument = Group3Pnts->LineEdit3;
377       break;
378     }
379     case 1:
380     {
381       if      ( send == Group3Pnts2->PushButton1 )   myEditCurrentArgument = Group3Pnts2->LineEdit1;
382       else if ( send == Group3Pnts2->PushButton2 )   myEditCurrentArgument = Group3Pnts2->LineEdit2;
383       else if ( send == Group3Pnts2->PushButton3 )   myEditCurrentArgument = Group3Pnts2->LineEdit3;
384       break;
385     }
386   }
387   myEditCurrentArgument->setFocus();
388   SelectionIntoArgument();
389 }
390
391
392 //=================================================================================
393 // function : ActivateThisDialog()
394 // purpose  :
395 //=================================================================================
396 void BasicGUI_ArcDlg::ActivateThisDialog()
397 {
398   GEOMBase_Skeleton::ActivateThisDialog();
399
400   connect(myGeomGUI->getApp()->selectionMgr(),
401           SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
402
403   ConstructorsClicked( getConstructorId() );
404 }
405
406
407 //=================================================================================
408 // function : enterEvent()
409 // purpose  :
410 //=================================================================================
411 void BasicGUI_ArcDlg::enterEvent(QEvent* e)
412 {
413   if (!GroupConstructors->isEnabled())
414     ActivateThisDialog();
415 }
416
417
418 //=================================================================================
419 // function : createOperation
420 // purpose  :
421 //=================================================================================
422 GEOM::GEOM_IOperations_ptr BasicGUI_ArcDlg::createOperation()
423 {
424   return myGeomGUI->GetGeomGen()->GetICurvesOperations( getStudyId() );
425 }
426
427 //=================================================================================
428 // function : isEqual
429 // purpose  : it may also be needed to check for min distance between gp_Pnt-s...
430 //=================================================================================
431 static bool isEqual( const GEOM::GEOM_Object_var& thePnt1, const GEOM::GEOM_Object_var& thePnt2 )
432 {
433   return thePnt1->_is_equivalent( thePnt2 );
434 }
435
436 //=================================================================================
437 // function : isValid
438 // purpose  :
439 //=================================================================================
440 bool BasicGUI_ArcDlg::isValid( QString& msg )
441 {
442   switch (getConstructorId()) {
443   case 0:
444     {
445       if (Group3Pnts->LineEdit1->text() == "" ||
446           Group3Pnts->LineEdit2->text() == "" ||
447           Group3Pnts->LineEdit3->text() == "")
448         return false;
449       break;
450     }
451   case 1:
452     {
453       if (Group3Pnts2->LineEdit1->text() == "" ||
454           Group3Pnts2->LineEdit2->text() == "" ||
455           Group3Pnts2->LineEdit3->text() == "")
456         return false;
457       break;
458     }
459   }
460   return !myPoint1->_is_nil() && !myPoint2->_is_nil() && !myPoint3->_is_nil() &&
461     !isEqual( myPoint1, myPoint2 ) && !isEqual( myPoint1, myPoint3 ) && !isEqual( myPoint2, myPoint3 );
462 }
463
464 //=================================================================================
465 // function : execute
466 // purpose  :
467 //=================================================================================
468 bool BasicGUI_ArcDlg::execute( ObjectList& objects )
469 {
470   bool res = false;
471   GEOM::GEOM_Object_var anObj;
472
473   switch (getConstructorId())
474   {
475   case 0:
476     {
477       if ( !CORBA::is_nil(myPoint1) && !CORBA::is_nil(myPoint2) &&!CORBA::is_nil(myPoint3) )
478       {
479         anObj = GEOM::GEOM_ICurvesOperations::_narrow(getOperation())->
480           MakeArc(myPoint1, myPoint2, myPoint3);
481         res = true;
482       }
483       break;
484     }
485   case 1:
486     {
487       bool Sense;
488       (Group3Pnts2->CheckButton1->isChecked()) ? Sense = true : Sense = false;
489       if ( !CORBA::is_nil(myPoint1) && !CORBA::is_nil(myPoint2) &&!CORBA::is_nil(myPoint3) )
490       {
491         anObj = GEOM::GEOM_ICurvesOperations::_narrow(getOperation())->
492           MakeArcCenter(myPoint1, myPoint2, myPoint3, Sense);
493         res = true;
494       }
495       break;
496     }
497   }
498   if ( !anObj->_is_nil() )
499     objects.push_back( anObj._retn() );
500
501   return res;
502 }
503
504 //=================================================================================
505 // function : ReverseSense()
506 // purpose  : Orientation of the arc
507 //=================================================================================
508 void BasicGUI_ArcDlg::ReverseSense(int sense)
509 {
510   displayPreview();
511 }
512
513 //=================================================================================
514 // function : addSubshapeToStudy
515 // purpose  : virtual method to add new SubObjects if local selection
516 //=================================================================================
517 void BasicGUI_ArcDlg::addSubshapesToStudy()
518 {
519   QMap<QString, GEOM::GEOM_Object_var> objMap;
520
521 switch (getConstructorId())
522   {
523   case 0:
524     objMap[Group3Pnts->LineEdit1->text()] = myPoint1;
525     objMap[Group3Pnts->LineEdit2->text()] = myPoint2;
526     objMap[Group3Pnts->LineEdit3->text()] = myPoint3;
527     break;
528   case 1:
529     objMap[Group3Pnts2->LineEdit1->text()] = myPoint1;
530     objMap[Group3Pnts2->LineEdit2->text()] = myPoint2;
531     objMap[Group3Pnts2->LineEdit3->text()] = myPoint3;
532     break;
533   }
534  addSubshapesToFather( objMap );
535 }