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"
38 #include "GEOMImpl_Types.hxx"
40 #include "utilities.h"
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)
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")));
59 setCaption(tr("GEOM_ARC_TITLE"));
61 /***************************************************************/
62 GroupConstructors->setTitle(tr("GEOM_ARC"));
63 RadioButton1->setPixmap(image0);
64 RadioButton2->setPixmap(image1);
65 RadioButton3->close(TRUE);
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"));
73 Group3Pnts->LineEdit1->setReadOnly( true );
74 Group3Pnts->LineEdit2->setReadOnly( true );
75 Group3Pnts->LineEdit3->setReadOnly( true );
77 Group3Pnts->PushButton1->setPixmap(image2);
78 Group3Pnts->PushButton2->setPixmap(image2);
79 Group3Pnts->PushButton3->setPixmap(image2);
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"));
88 Group3Pnts2->LineEdit1->setReadOnly( true );
89 Group3Pnts2->LineEdit2->setReadOnly( true );
90 Group3Pnts2->LineEdit3->setReadOnly( true );
92 Group3Pnts2->PushButton1->setPixmap(image2);
93 Group3Pnts2->PushButton2->setPixmap(image2);
94 Group3Pnts2->PushButton3->setPixmap(image2);
96 Group3Pnts2->radioButton4->setText(tr("GEOM_REVERSE"));
98 Layout1->addWidget( Group3Pnts, 2, 0 );
99 Layout1->addWidget( Group3Pnts2, 2, 0 );
100 /***************************************************************/
102 setHelpFileName("arc.htm");
108 //=================================================================================
109 // function : ~BasicGUI_ArcDlg()
110 // purpose : Destroys the object and frees any allocated resources
111 //=================================================================================
112 BasicGUI_ArcDlg::~BasicGUI_ArcDlg()
117 //=================================================================================
120 //=================================================================================
121 void BasicGUI_ArcDlg::Init()
124 myEditCurrentArgument = Group3Pnts->LineEdit1;
125 myPoint1 = myPoint2 = myPoint3 = GEOM::GEOM_Object::_nil();
126 Group3Pnts2->radioButton4->setChecked(FALSE);
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()));
133 connect(GroupConstructors, SIGNAL(clicked(int)), this, SLOT(ConstructorsClicked(int)));
135 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
136 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
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()));
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()));
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()));
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()));
154 connect(Group3Pnts2->radioButton4, SIGNAL(stateChanged(int)), this, SLOT(ReverseSense(int)));
156 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
157 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
159 initName( tr( "GEOM_ARC" ));
160 ConstructorsClicked( 0 );
164 //=================================================================================
165 // function : ConstructorsClicked()
166 // purpose : Radio button management
167 //=================================================================================
168 void BasicGUI_ArcDlg::ConstructorsClicked (int constructorId)
170 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
172 switch (constructorId)
176 globalSelection( GEOM_POINT );
182 Group3Pnts->LineEdit1->setText(Group3Pnts2->LineEdit1->text());
183 Group3Pnts->LineEdit2->setText(Group3Pnts2->LineEdit2->text());
184 Group3Pnts->LineEdit3->setText(Group3Pnts2->LineEdit3->text());
186 myEditCurrentArgument = Group3Pnts->LineEdit1;
192 globalSelection( GEOM_POINT );
198 Group3Pnts2->LineEdit1->setText(Group3Pnts->LineEdit1->text());
199 Group3Pnts2->LineEdit2->setText(Group3Pnts->LineEdit2->text());
200 Group3Pnts2->LineEdit3->setText(Group3Pnts->LineEdit3->text());
202 myEditCurrentArgument = Group3Pnts2->LineEdit1;
208 myEditCurrentArgument->setFocus();
209 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
210 this, SLOT(SelectionIntoArgument()));
212 if (CORBA::is_nil(myPoint1))
213 SelectionIntoArgument();
219 //=================================================================================
220 // function : ClickOnOk()
222 //=================================================================================
223 void BasicGUI_ArcDlg::ClickOnOk()
225 if ( ClickOnApply() )
229 //=================================================================================
230 // function : ClickOnApply()
232 //=================================================================================
233 bool BasicGUI_ArcDlg::ClickOnApply()
243 //=================================================================================
244 // function : SelectionIntoArgument()
245 // purpose : Called when selection as changed or other case
246 //=================================================================================
247 void BasicGUI_ArcDlg::SelectionIntoArgument()
249 if ((getConstructorId() != 0) && (getConstructorId() != 1))
252 myEditCurrentArgument->setText("");
254 if ( IObjectCount() != 1 )
256 switch (getConstructorId())
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();
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();
278 Standard_Boolean aRes = Standard_False;
279 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( firstIObject(), aRes );
280 if ( !CORBA::is_nil( aSelectedObject ) && aRes )
282 switch (getConstructorId())
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;
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;
307 //=================================================================================
308 // function : LineEditReturnPressed()
310 //=================================================================================
311 void BasicGUI_ArcDlg::LineEditReturnPressed()
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)
317 myEditCurrentArgument = send;
318 GEOMBase_Skeleton::LineEditReturnPressed();
323 //=================================================================================
324 // function : SetEditCurrentArgument()
326 //=================================================================================
327 void BasicGUI_ArcDlg::SetEditCurrentArgument()
329 QPushButton* send = (QPushButton*)sender();
330 switch (getConstructorId())
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;
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;
347 myEditCurrentArgument->setFocus();
348 SelectionIntoArgument();
352 //=================================================================================
353 // function : ActivateThisDialog()
355 //=================================================================================
356 void BasicGUI_ArcDlg::ActivateThisDialog()
358 GEOMBase_Skeleton::ActivateThisDialog();
360 connect(myGeomGUI->getApp()->selectionMgr(),
361 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
363 ConstructorsClicked( getConstructorId() );
367 //=================================================================================
368 // function : enterEvent()
370 //=================================================================================
371 void BasicGUI_ArcDlg::enterEvent(QEvent* e)
373 if (!GroupConstructors->isEnabled())
374 ActivateThisDialog();
378 //=================================================================================
379 // function : createOperation
381 //=================================================================================
382 GEOM::GEOM_IOperations_ptr BasicGUI_ArcDlg::createOperation()
384 return myGeomGUI->GetGeomGen()->GetICurvesOperations( getStudyId() );
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 )
393 return thePnt1->_is_equivalent( thePnt2 );
396 //=================================================================================
397 // function : isValid
399 //=================================================================================
400 bool BasicGUI_ArcDlg::isValid( QString& msg )
402 return !myPoint1->_is_nil() && !myPoint2->_is_nil() && !myPoint3->_is_nil() &&
403 !isEqual( myPoint1, myPoint2 ) && !isEqual( myPoint1, myPoint3 ) && !isEqual( myPoint2, myPoint3 );
406 //=================================================================================
407 // function : execute
409 //=================================================================================
410 bool BasicGUI_ArcDlg::execute( ObjectList& objects )
413 GEOM::GEOM_Object_var anObj;
415 switch (getConstructorId())
419 if ( !CORBA::is_nil(myPoint1) && !CORBA::is_nil(myPoint2) &&!CORBA::is_nil(myPoint3) )
421 anObj = GEOM::GEOM_ICurvesOperations::_narrow(getOperation())->
422 MakeArc(myPoint1, myPoint2, myPoint3);
430 (Group3Pnts2->radioButton4->isChecked()) ? Sense = true : Sense = false;
431 if ( !CORBA::is_nil(myPoint1) && !CORBA::is_nil(myPoint2) &&!CORBA::is_nil(myPoint3) )
433 anObj = GEOM::GEOM_ICurvesOperations::_narrow(getOperation())->
434 MakeArcCenter(myPoint1, myPoint2, myPoint3, Sense);
440 if ( !anObj->_is_nil() )
441 objects.push_back( anObj._retn() );
446 //=================================================================================
447 // function : ReverseSense()
448 // purpose : Orientation of the arc
449 //=================================================================================
450 void BasicGUI_ArcDlg::ReverseSense(int sense)