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"
37 #include <qcheckbox.h>
39 #include "GEOMImpl_Types.hxx"
41 #include "utilities.h"
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)
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")));
60 setCaption(tr("GEOM_ARC_TITLE"));
62 /***************************************************************/
63 GroupConstructors->setTitle(tr("GEOM_ARC"));
64 RadioButton1->setPixmap(image0);
65 RadioButton2->setPixmap(image1);
66 RadioButton3->close(TRUE);
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"));
74 Group3Pnts->LineEdit1->setReadOnly( true );
75 Group3Pnts->LineEdit2->setReadOnly( true );
76 Group3Pnts->LineEdit3->setReadOnly( true );
78 Group3Pnts->PushButton1->setPixmap(image2);
79 Group3Pnts->PushButton2->setPixmap(image2);
80 Group3Pnts->PushButton3->setPixmap(image2);
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"));
89 Group3Pnts2->LineEdit1->setReadOnly( true );
90 Group3Pnts2->LineEdit2->setReadOnly( true );
91 Group3Pnts2->LineEdit3->setReadOnly( true );
93 Group3Pnts2->PushButton1->setPixmap(image2);
94 Group3Pnts2->PushButton2->setPixmap(image2);
95 Group3Pnts2->PushButton3->setPixmap(image2);
97 Group3Pnts2->CheckButton1->setText(tr("GEOM_REVERSE"));
99 Layout1->addWidget( Group3Pnts, 2, 0 );
100 Layout1->addWidget( Group3Pnts2, 2, 0 );
101 /***************************************************************/
103 setHelpFileName("arc.htm");
109 //=================================================================================
110 // function : ~BasicGUI_ArcDlg()
111 // purpose : Destroys the object and frees any allocated resources
112 //=================================================================================
113 BasicGUI_ArcDlg::~BasicGUI_ArcDlg()
118 //=================================================================================
121 //=================================================================================
122 void BasicGUI_ArcDlg::Init()
125 myEditCurrentArgument = Group3Pnts->LineEdit1;
126 myPoint1 = myPoint2 = myPoint3 = GEOM::GEOM_Object::_nil();
127 Group3Pnts2->CheckButton1->setChecked(FALSE);
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()));
134 connect(GroupConstructors, SIGNAL(clicked(int)), this, SLOT(ConstructorsClicked(int)));
136 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
137 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
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()));
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()));
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()));
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()));
155 connect(Group3Pnts2->CheckButton1, SIGNAL(stateChanged(int)), this, SLOT(ReverseSense(int)));
157 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
158 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
160 initName( tr( "GEOM_ARC" ));
161 ConstructorsClicked( 0 );
165 //=================================================================================
166 // function : ConstructorsClicked()
167 // purpose : Radio button management
168 //=================================================================================
169 void BasicGUI_ArcDlg::ConstructorsClicked (int constructorId)
171 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
173 switch (constructorId)
177 globalSelection( GEOM_POINT );
183 Group3Pnts->LineEdit1->setText(Group3Pnts2->LineEdit1->text());
184 Group3Pnts->LineEdit2->setText(Group3Pnts2->LineEdit2->text());
185 Group3Pnts->LineEdit3->setText(Group3Pnts2->LineEdit3->text());
187 myEditCurrentArgument = Group3Pnts->LineEdit1;
193 globalSelection( GEOM_POINT );
199 Group3Pnts2->LineEdit1->setText(Group3Pnts->LineEdit1->text());
200 Group3Pnts2->LineEdit2->setText(Group3Pnts->LineEdit2->text());
201 Group3Pnts2->LineEdit3->setText(Group3Pnts->LineEdit3->text());
203 myEditCurrentArgument = Group3Pnts2->LineEdit1;
209 myEditCurrentArgument->setFocus();
210 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
211 this, SLOT(SelectionIntoArgument()));
213 if (CORBA::is_nil(myPoint1))
214 SelectionIntoArgument();
220 //=================================================================================
221 // function : ClickOnOk()
223 //=================================================================================
224 void BasicGUI_ArcDlg::ClickOnOk()
226 if ( ClickOnApply() )
230 //=================================================================================
231 // function : ClickOnApply()
233 //=================================================================================
234 bool BasicGUI_ArcDlg::ClickOnApply()
244 //=================================================================================
245 // function : SelectionIntoArgument()
246 // purpose : Called when selection as changed or other case
247 //=================================================================================
248 void BasicGUI_ArcDlg::SelectionIntoArgument()
250 if ((getConstructorId() != 0) && (getConstructorId() != 1))
253 myEditCurrentArgument->setText("");
255 if ( IObjectCount() != 1 )
257 switch (getConstructorId())
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();
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();
279 Standard_Boolean aRes = Standard_False;
280 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( firstIObject(), aRes );
281 if ( !CORBA::is_nil( aSelectedObject ) && aRes )
283 switch (getConstructorId())
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;
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;
308 //=================================================================================
309 // function : LineEditReturnPressed()
311 //=================================================================================
312 void BasicGUI_ArcDlg::LineEditReturnPressed()
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)
318 myEditCurrentArgument = send;
319 GEOMBase_Skeleton::LineEditReturnPressed();
324 //=================================================================================
325 // function : SetEditCurrentArgument()
327 //=================================================================================
328 void BasicGUI_ArcDlg::SetEditCurrentArgument()
330 QPushButton* send = (QPushButton*)sender();
331 switch (getConstructorId())
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;
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;
348 myEditCurrentArgument->setFocus();
349 SelectionIntoArgument();
353 //=================================================================================
354 // function : ActivateThisDialog()
356 //=================================================================================
357 void BasicGUI_ArcDlg::ActivateThisDialog()
359 GEOMBase_Skeleton::ActivateThisDialog();
361 connect(myGeomGUI->getApp()->selectionMgr(),
362 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
364 ConstructorsClicked( getConstructorId() );
368 //=================================================================================
369 // function : enterEvent()
371 //=================================================================================
372 void BasicGUI_ArcDlg::enterEvent(QEvent* e)
374 if (!GroupConstructors->isEnabled())
375 ActivateThisDialog();
379 //=================================================================================
380 // function : createOperation
382 //=================================================================================
383 GEOM::GEOM_IOperations_ptr BasicGUI_ArcDlg::createOperation()
385 return myGeomGUI->GetGeomGen()->GetICurvesOperations( getStudyId() );
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 )
394 return thePnt1->_is_equivalent( thePnt2 );
397 //=================================================================================
398 // function : isValid
400 //=================================================================================
401 bool BasicGUI_ArcDlg::isValid( QString& msg )
403 return !myPoint1->_is_nil() && !myPoint2->_is_nil() && !myPoint3->_is_nil() &&
404 !isEqual( myPoint1, myPoint2 ) && !isEqual( myPoint1, myPoint3 ) && !isEqual( myPoint2, myPoint3 );
407 //=================================================================================
408 // function : execute
410 //=================================================================================
411 bool BasicGUI_ArcDlg::execute( ObjectList& objects )
414 GEOM::GEOM_Object_var anObj;
416 switch (getConstructorId())
420 if ( !CORBA::is_nil(myPoint1) && !CORBA::is_nil(myPoint2) &&!CORBA::is_nil(myPoint3) )
422 anObj = GEOM::GEOM_ICurvesOperations::_narrow(getOperation())->
423 MakeArc(myPoint1, myPoint2, myPoint3);
431 (Group3Pnts2->CheckButton1->isChecked()) ? Sense = true : Sense = false;
432 if ( !CORBA::is_nil(myPoint1) && !CORBA::is_nil(myPoint2) &&!CORBA::is_nil(myPoint3) )
434 anObj = GEOM::GEOM_ICurvesOperations::_narrow(getOperation())->
435 MakeArcCenter(myPoint1, myPoint2, myPoint3, Sense);
441 if ( !anObj->_is_nil() )
442 objects.push_back( anObj._retn() );
447 //=================================================================================
448 // function : ReverseSense()
449 // purpose : Orientation of the arc
450 //=================================================================================
451 void BasicGUI_ArcDlg::ReverseSense(int sense)