1 // GEOM GEOMGUI : GUI for Geometry component
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
24 // File : BasicGUI_ArcDlg.cxx
25 // Author : Lucien PIGNOLONI
29 #include "BasicGUI_ArcDlg.h"
31 #include "SUIT_Desktop.h"
32 #include "SUIT_Session.h"
33 #include "SalomeApp_Application.h"
34 #include "LightApp_SelectionMgr.h"
36 #include <TColStd_IndexedMapOfInteger.hxx>
37 #include <TopTools_IndexedMapOfShape.hxx>
38 #include <TopoDS_Shape.hxx>
39 #include <TopoDS_Edge.hxx>
44 #include <qcheckbox.h>
46 #include "GEOMImpl_Types.hxx"
48 #include "utilities.h"
50 //=================================================================================
51 // class : BasicGUI_ArcDlg()
52 // purpose : Constructs a BasicGUI_ArcDlg which is a child of 'parent', with the
53 // name 'name' and widget flags set to 'f'.
54 // The dialog will by default be modeless, unless you set 'modal' to
55 // TRUE to construct a modal dialog.
56 //=================================================================================
57 BasicGUI_ArcDlg::BasicGUI_ArcDlg(GeometryGUI* theGeometryGUI, QWidget* parent,
58 const char* name, bool modal, WFlags fl)
59 : GEOMBase_Skeleton(theGeometryGUI, parent, name, modal, WStyle_Customize |
60 WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
62 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
63 QPixmap image0(aResMgr->loadPixmap("GEOM",tr("ICON_DLG_ARC")));
64 QPixmap image1(aResMgr->loadPixmap("GEOM",tr("ICON_DLG_ARC_CENTER")));
65 QPixmap image2(aResMgr->loadPixmap("GEOM",tr("ICON_SELECT")));
67 setCaption(tr("GEOM_ARC_TITLE"));
69 /***************************************************************/
70 GroupConstructors->setTitle(tr("GEOM_ARC"));
71 RadioButton1->setPixmap(image0);
72 RadioButton2->setPixmap(image1);
73 RadioButton3->close(TRUE);
75 Group3Pnts = new DlgRef_3Sel_QTD(this, "Group3Pnts");
76 Group3Pnts->GroupBox1->setTitle(tr("GEOM_POINTS"));
77 Group3Pnts->TextLabel1->setText(tr("GEOM_POINT_I").arg("1"));
78 Group3Pnts->TextLabel2->setText(tr("GEOM_POINT_I").arg("2"));
79 Group3Pnts->TextLabel3->setText(tr("GEOM_POINT_I").arg("3"));
81 Group3Pnts->LineEdit1->setReadOnly( true );
82 Group3Pnts->LineEdit2->setReadOnly( true );
83 Group3Pnts->LineEdit3->setReadOnly( true );
85 Group3Pnts->PushButton1->setPixmap(image2);
86 Group3Pnts->PushButton2->setPixmap(image2);
87 Group3Pnts->PushButton3->setPixmap(image2);
90 Group3Pnts2 = new DlgRef_3Sel1Check_QTD(this, "Group3Pnts2");
91 Group3Pnts2->GroupBox1->setTitle(tr("GEOM_POINTS"));
92 Group3Pnts2->TextLabel1->setText(tr("GEOM_CENTER_POINT"));
93 Group3Pnts2->TextLabel2->setText(tr("GEOM_POINT_I").arg("Start"));
94 Group3Pnts2->TextLabel3->setText(tr("GEOM_POINT_I").arg("End"));
96 Group3Pnts2->LineEdit1->setReadOnly( true );
97 Group3Pnts2->LineEdit2->setReadOnly( true );
98 Group3Pnts2->LineEdit3->setReadOnly( true );
100 Group3Pnts2->PushButton1->setPixmap(image2);
101 Group3Pnts2->PushButton2->setPixmap(image2);
102 Group3Pnts2->PushButton3->setPixmap(image2);
104 Group3Pnts2->CheckButton1->setText(tr("GEOM_REVERSE"));
106 Layout1->addWidget( Group3Pnts, 2, 0 );
107 Layout1->addWidget( Group3Pnts2, 2, 0 );
108 /***************************************************************/
110 setHelpFileName("arc.htm");
116 //=================================================================================
117 // function : ~BasicGUI_ArcDlg()
118 // purpose : Destroys the object and frees any allocated resources
119 //=================================================================================
120 BasicGUI_ArcDlg::~BasicGUI_ArcDlg()
125 //=================================================================================
128 //=================================================================================
129 void BasicGUI_ArcDlg::Init()
132 myEditCurrentArgument = Group3Pnts->LineEdit1;
133 myPoint1 = myPoint2 = myPoint3 = GEOM::GEOM_Object::_nil();
134 Group3Pnts2->CheckButton1->setChecked(FALSE);
136 /* signals and slots connections */
137 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
138 connect(myGeomGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
139 connect(myGeomGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
141 connect(GroupConstructors, SIGNAL(clicked(int)), this, SLOT(ConstructorsClicked(int)));
143 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
144 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
146 connect(Group3Pnts->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
147 connect(Group3Pnts->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
148 connect(Group3Pnts->PushButton3, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
150 connect(Group3Pnts->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
151 connect(Group3Pnts->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
152 connect(Group3Pnts->LineEdit3, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
154 connect(Group3Pnts2->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
155 connect(Group3Pnts2->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
156 connect(Group3Pnts2->PushButton3, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
158 connect(Group3Pnts2->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
159 connect(Group3Pnts2->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
160 connect(Group3Pnts2->LineEdit3, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
162 connect(Group3Pnts2->CheckButton1, SIGNAL(stateChanged(int)), this, SLOT(ReverseSense(int)));
164 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
165 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
167 initName( tr( "GEOM_ARC" ));
168 ConstructorsClicked( 0 );
172 //=================================================================================
173 // function : ConstructorsClicked()
174 // purpose : Radio button management
175 //=================================================================================
176 void BasicGUI_ArcDlg::ConstructorsClicked (int constructorId)
178 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
180 switch (constructorId)
184 localSelection(GEOM::GEOM_Object::_nil(), TopAbs_VERTEX); //Select Vertex on All Shapes
190 Group3Pnts->LineEdit1->setText(Group3Pnts2->LineEdit1->text());
191 Group3Pnts->LineEdit2->setText(Group3Pnts2->LineEdit2->text());
192 Group3Pnts->LineEdit3->setText(Group3Pnts2->LineEdit3->text());
194 myEditCurrentArgument = Group3Pnts->LineEdit1;
200 localSelection(GEOM::GEOM_Object::_nil(), TopAbs_VERTEX); //Select Vertex on All Shapes
206 Group3Pnts2->LineEdit1->setText(Group3Pnts->LineEdit1->text());
207 Group3Pnts2->LineEdit2->setText(Group3Pnts->LineEdit2->text());
208 Group3Pnts2->LineEdit3->setText(Group3Pnts->LineEdit3->text());
210 myEditCurrentArgument = Group3Pnts2->LineEdit1;
216 myEditCurrentArgument->setFocus();
217 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
218 this, SLOT(SelectionIntoArgument()));
220 if (CORBA::is_nil(myPoint1))
221 SelectionIntoArgument();
227 //=================================================================================
228 // function : ClickOnOk()
230 //=================================================================================
231 void BasicGUI_ArcDlg::ClickOnOk()
233 if ( ClickOnApply() )
237 //=================================================================================
238 // function : ClickOnApply()
240 //=================================================================================
241 bool BasicGUI_ArcDlg::ClickOnApply()
251 //=================================================================================
252 // function : SelectionIntoArgument()
253 // purpose : Called when selection as changed or other case
254 //=================================================================================
255 void BasicGUI_ArcDlg::SelectionIntoArgument()
257 if ((getConstructorId() != 0) && (getConstructorId() != 1))
260 myEditCurrentArgument->setText("");
262 if ( IObjectCount() != 1 )
264 switch (getConstructorId())
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();
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();
286 Standard_Boolean aRes = Standard_False;
287 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( firstIObject(), aRes );
288 if ( !CORBA::is_nil( aSelectedObject ) && aRes )
290 myEditCurrentArgument->setText( GEOMBase::GetName( aSelectedObject ) );
291 // Get Selected object if selected subshape
293 if ( GEOMBase::GetShape( aSelectedObject, aShape, TopAbs_SHAPE ) && !aShape.IsNull() )
295 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
296 TColStd_IndexedMapOfInteger aMap;
297 aSelMgr->GetIndexes( firstIObject(), aMap );
298 if ( aMap.Extent() == 1 )
300 GEOM::GEOM_IShapesOperations_var aShapesOp =
301 getGeomEngine()->GetIShapesOperations( getStudyId() );
302 int anIndex = aMap( 1 );
303 TopTools_IndexedMapOfShape aShapes;
304 TopExp::MapShapes( aShape, aShapes );
305 aShape = aShapes.FindKey( anIndex );
306 aSelectedObject = aShapesOp->GetSubShape(aSelectedObject, anIndex);
307 aSelMgr->clearSelected();
310 switch (getConstructorId())
314 if ( myEditCurrentArgument == Group3Pnts->LineEdit1 ) myPoint1 = aSelectedObject;
315 else if ( myEditCurrentArgument == Group3Pnts->LineEdit2 ) myPoint2 = aSelectedObject;
316 else if ( myEditCurrentArgument == Group3Pnts->LineEdit3 ) myPoint3 = aSelectedObject;
321 if ( myEditCurrentArgument == Group3Pnts2->LineEdit1 ) myPoint1 = aSelectedObject;
322 else if ( myEditCurrentArgument == Group3Pnts2->LineEdit2 ) myPoint2 = aSelectedObject;
323 else if ( myEditCurrentArgument == Group3Pnts2->LineEdit3 ) myPoint3 = aSelectedObject;
333 //=================================================================================
334 // function : LineEditReturnPressed()
336 //=================================================================================
337 void BasicGUI_ArcDlg::LineEditReturnPressed()
339 QLineEdit* send = (QLineEdit*)sender();
340 if (send == Group3Pnts->LineEdit1 || send == Group3Pnts->LineEdit2 || send == Group3Pnts->LineEdit3 ||
341 send == Group3Pnts2->LineEdit1 || send == Group3Pnts2->LineEdit2 || send == Group3Pnts2->LineEdit3)
343 myEditCurrentArgument = send;
344 GEOMBase_Skeleton::LineEditReturnPressed();
349 //=================================================================================
350 // function : SetEditCurrentArgument()
352 //=================================================================================
353 void BasicGUI_ArcDlg::SetEditCurrentArgument()
355 QPushButton* send = (QPushButton*)sender();
356 switch (getConstructorId())
360 if ( send == Group3Pnts->PushButton1 ) myEditCurrentArgument = Group3Pnts->LineEdit1;
361 else if ( send == Group3Pnts->PushButton2 ) myEditCurrentArgument = Group3Pnts->LineEdit2;
362 else if ( send == Group3Pnts->PushButton3 ) myEditCurrentArgument = Group3Pnts->LineEdit3;
367 if ( send == Group3Pnts2->PushButton1 ) myEditCurrentArgument = Group3Pnts2->LineEdit1;
368 else if ( send == Group3Pnts2->PushButton2 ) myEditCurrentArgument = Group3Pnts2->LineEdit2;
369 else if ( send == Group3Pnts2->PushButton3 ) myEditCurrentArgument = Group3Pnts2->LineEdit3;
373 myEditCurrentArgument->setFocus();
374 SelectionIntoArgument();
378 //=================================================================================
379 // function : ActivateThisDialog()
381 //=================================================================================
382 void BasicGUI_ArcDlg::ActivateThisDialog()
384 GEOMBase_Skeleton::ActivateThisDialog();
386 connect(myGeomGUI->getApp()->selectionMgr(),
387 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
389 ConstructorsClicked( getConstructorId() );
393 //=================================================================================
394 // function : enterEvent()
396 //=================================================================================
397 void BasicGUI_ArcDlg::enterEvent(QEvent* e)
399 if (!GroupConstructors->isEnabled())
400 ActivateThisDialog();
404 //=================================================================================
405 // function : createOperation
407 //=================================================================================
408 GEOM::GEOM_IOperations_ptr BasicGUI_ArcDlg::createOperation()
410 return myGeomGUI->GetGeomGen()->GetICurvesOperations( getStudyId() );
413 //=================================================================================
414 // function : isEqual
415 // purpose : it may also be needed to check for min distance between gp_Pnt-s...
416 //=================================================================================
417 static bool isEqual( const GEOM::GEOM_Object_var& thePnt1, const GEOM::GEOM_Object_var& thePnt2 )
419 return thePnt1->_is_equivalent( thePnt2 );
422 //=================================================================================
423 // function : isValid
425 //=================================================================================
426 bool BasicGUI_ArcDlg::isValid( QString& msg )
428 return !myPoint1->_is_nil() && !myPoint2->_is_nil() && !myPoint3->_is_nil() &&
429 !isEqual( myPoint1, myPoint2 ) && !isEqual( myPoint1, myPoint3 ) && !isEqual( myPoint2, myPoint3 );
432 //=================================================================================
433 // function : execute
435 //=================================================================================
436 bool BasicGUI_ArcDlg::execute( ObjectList& objects )
439 GEOM::GEOM_Object_var anObj;
441 switch (getConstructorId())
445 if ( !CORBA::is_nil(myPoint1) && !CORBA::is_nil(myPoint2) &&!CORBA::is_nil(myPoint3) )
447 anObj = GEOM::GEOM_ICurvesOperations::_narrow(getOperation())->
448 MakeArc(myPoint1, myPoint2, myPoint3);
456 (Group3Pnts2->CheckButton1->isChecked()) ? Sense = true : Sense = false;
457 if ( !CORBA::is_nil(myPoint1) && !CORBA::is_nil(myPoint2) &&!CORBA::is_nil(myPoint3) )
459 anObj = GEOM::GEOM_ICurvesOperations::_narrow(getOperation())->
460 MakeArcCenter(myPoint1, myPoint2, myPoint3, Sense);
466 if ( !anObj->_is_nil() )
467 objects.push_back( anObj._retn() );
472 //=================================================================================
473 // function : ReverseSense()
474 // purpose : Orientation of the arc
475 //=================================================================================
476 void BasicGUI_ArcDlg::ReverseSense(int sense)