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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
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 <BRepBuilderAPI_MakeEdge.hxx>
39 #include <GC_MakeArcOfCircle.hxx>
40 #include <Geom_TrimmedCurve.hxx>
41 #include <Precision.hxx>
43 #include "GEOMImpl_Types.hxx"
45 #include "utilities.h"
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(parent, name, modal, WStyle_Customize |
59 WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu),
60 myGeometryGUI(theGeometryGUI)
62 QPixmap image0(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_ARC")));
63 QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_SELECT")));
65 setCaption(tr("GEOM_ARC_TITLE"));
67 /***************************************************************/
68 GroupConstructors->setTitle(tr("GEOM_ARC"));
69 RadioButton1->setPixmap(image0);
70 RadioButton2->close(TRUE);
71 RadioButton3->close(TRUE);
73 Group3Pnts = new DlgRef_3Sel_QTD(this, "Group3Pnts");
74 Group3Pnts->GroupBox1->setTitle(tr("GEOM_POINTS"));
75 Group3Pnts->TextLabel1->setText(tr("GEOM_POINT_I").arg("1"));
76 Group3Pnts->TextLabel2->setText(tr("GEOM_POINT_I").arg("2"));
77 Group3Pnts->TextLabel3->setText(tr("GEOM_POINT_I").arg("3"));
79 Group3Pnts->LineEdit1->setReadOnly( true );
80 Group3Pnts->LineEdit2->setReadOnly( true );
81 Group3Pnts->LineEdit3->setReadOnly( true );
83 Group3Pnts->PushButton1->setPixmap(image1);
84 Group3Pnts->PushButton2->setPixmap(image1);
85 Group3Pnts->PushButton3->setPixmap(image1);
87 Layout1->addWidget( Group3Pnts, 2, 0 );
93 //=================================================================================
94 // function : ~BasicGUI_ArcDlg()
95 // purpose : Destroys the object and frees any allocated resources
96 //=================================================================================
97 BasicGUI_ArcDlg::~BasicGUI_ArcDlg()
102 //=================================================================================
105 //=================================================================================
106 void BasicGUI_ArcDlg::Init()
109 // myGeometryGUI->SetState( 0 );
110 globalSelection( GEOM_POINT );
112 myEditCurrentArgument = Group3Pnts->LineEdit1;
113 myEditCurrentArgument->setFocus();
115 myPoint1 = myPoint2 = myPoint3 = GEOM::GEOM_Object::_nil();
117 /* signals and slots connections */
118 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
119 connect(myGeometryGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
120 connect(myGeometryGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
122 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
123 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
125 connect(Group3Pnts->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
126 connect(Group3Pnts->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
127 connect(Group3Pnts->PushButton3, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
129 connect(Group3Pnts->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
130 connect(Group3Pnts->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
131 connect(Group3Pnts->LineEdit3, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
133 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
134 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
136 initName( tr( "GEOM_ARC" ) );
140 //=================================================================================
141 // function : ClickOnOk()
143 //=================================================================================
144 void BasicGUI_ArcDlg::ClickOnOk()
146 if ( ClickOnApply() )
150 //=================================================================================
151 // function : ClickOnCancel()
153 //=================================================================================
154 void BasicGUI_ArcDlg::ClickOnCancel()
156 GEOMBase_Skeleton::ClickOnCancel();
159 //=================================================================================
160 // function : ClickOnApply()
162 //=================================================================================
163 bool BasicGUI_ArcDlg::ClickOnApply()
171 myPoint1 = myPoint2 = myPoint3 = GEOM::GEOM_Object::_nil();
172 Group3Pnts->LineEdit1->setText( "" );
173 Group3Pnts->LineEdit2->setText( "" );
174 Group3Pnts->LineEdit3->setText( "" );
175 myEditCurrentArgument = Group3Pnts->LineEdit1;
181 //=================================================================================
182 // function : SelectionIntoArgument()
183 // purpose : Called when selection as changed or other case
184 //=================================================================================
185 void BasicGUI_ArcDlg::SelectionIntoArgument()
187 myEditCurrentArgument->setText("");
189 if ( IObjectCount() != 1 )
191 if ( myEditCurrentArgument == Group3Pnts->LineEdit1 ) myPoint1 = GEOM::GEOM_Object::_nil();
192 else if ( myEditCurrentArgument == Group3Pnts->LineEdit2 ) myPoint2 = GEOM::GEOM_Object::_nil();
193 else if ( myEditCurrentArgument == Group3Pnts->LineEdit3 ) myPoint3 = GEOM::GEOM_Object::_nil();
198 Standard_Boolean aRes = Standard_False;
199 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( firstIObject(), aRes );
200 if ( !CORBA::is_nil( aSelectedObject ) && aRes )
202 myEditCurrentArgument->setText( GEOMBase::GetName( aSelectedObject ) );
203 if ( myEditCurrentArgument == Group3Pnts->LineEdit1 ) myPoint1 = aSelectedObject;
204 else if ( myEditCurrentArgument == Group3Pnts->LineEdit2 ) myPoint2 = aSelectedObject;
205 else if ( myEditCurrentArgument == Group3Pnts->LineEdit3 ) myPoint3 = aSelectedObject;
212 //=================================================================================
213 // function : SetEditCurrentArgument()
215 //=================================================================================
216 void BasicGUI_ArcDlg::SetEditCurrentArgument()
218 QPushButton* send = (QPushButton*)sender();
220 if ( send == Group3Pnts->PushButton1 ) myEditCurrentArgument = Group3Pnts->LineEdit1;
221 else if ( send == Group3Pnts->PushButton2 ) myEditCurrentArgument = Group3Pnts->LineEdit2;
222 else if ( send == Group3Pnts->PushButton3 ) myEditCurrentArgument = Group3Pnts->LineEdit3;
224 myEditCurrentArgument->setFocus();
225 SelectionIntoArgument();
229 //=================================================================================
230 // function : LineEditReturnPressed()
232 //=================================================================================
233 void BasicGUI_ArcDlg::LineEditReturnPressed()
235 QLineEdit* send = (QLineEdit*)sender();
236 if ( send == Group3Pnts->LineEdit1 ||
237 send == Group3Pnts->LineEdit2 ||
238 send == Group3Pnts->LineEdit3 )
240 myEditCurrentArgument = send;
241 GEOMBase_Skeleton::LineEditReturnPressed();
246 //=================================================================================
247 // function : ActivateThisDialog()
249 //=================================================================================
250 void BasicGUI_ArcDlg::ActivateThisDialog()
252 GEOMBase_Skeleton::ActivateThisDialog();
253 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
254 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
256 // myGeometryGUI->SetState( 0 );
257 globalSelection( GEOM_POINT );
259 myEditCurrentArgument = Group3Pnts->LineEdit1;
260 myEditCurrentArgument->setFocus();
262 Group3Pnts->LineEdit1->setText( "" );
263 Group3Pnts->LineEdit2->setText( "" );
264 Group3Pnts->LineEdit3->setText( "" );
265 myPoint1 = myPoint2 = myPoint3 = GEOM::GEOM_Object::_nil();
268 //=================================================================================
269 // function : DeactivateActiveDialog()
270 // purpose : public slot to deactivate if active
271 //=================================================================================
272 void BasicGUI_ArcDlg::DeactivateActiveDialog()
274 // myGeometryGUI->SetState( -1 );
275 GEOMBase_Skeleton::DeactivateActiveDialog();
278 //=================================================================================
279 // function : enterEvent()
281 //=================================================================================
282 void BasicGUI_ArcDlg::enterEvent(QEvent* e)
284 if ( !GroupConstructors->isEnabled() )
285 ActivateThisDialog();
288 //=================================================================================
289 // function : createOperation
291 //=================================================================================
292 GEOM::GEOM_IOperations_ptr BasicGUI_ArcDlg::createOperation()
294 return myGeometryGUI->GetGeomGen()->GetICurvesOperations( getStudyId() );
297 //=================================================================================
298 // function : isEqual
299 // purpose : it may also be needed to check for min distance between gp_Pnt-s...
300 //=================================================================================
301 static bool isEqual( const GEOM::GEOM_Object_var& thePnt1, const GEOM::GEOM_Object_var& thePnt2 )
303 return thePnt1->_is_equivalent( thePnt2 );
306 //=================================================================================
307 // function : isValid
309 //=================================================================================
310 bool BasicGUI_ArcDlg::isValid( QString& msg )
312 return !myPoint1->_is_nil() && !myPoint2->_is_nil() && !myPoint3->_is_nil() &&
313 !isEqual( myPoint1, myPoint2 ) && !isEqual( myPoint1, myPoint3 ) && !isEqual( myPoint2, myPoint3 );
316 //=================================================================================
317 // function : execute
319 //=================================================================================
320 bool BasicGUI_ArcDlg::execute( ObjectList& objects )
322 GEOM::GEOM_Object_var anObj =
323 GEOM::GEOM_ICurvesOperations::_narrow(getOperation())->MakeArc(myPoint1, myPoint2, myPoint3);
324 if ( !anObj->_is_nil() )
325 objects.push_back( anObj._retn() );
329 //=================================================================================
330 // function : closeEvent
332 //=================================================================================
333 void BasicGUI_ArcDlg::closeEvent( QCloseEvent* e )
335 // myGeometryGUI->SetState( -1 );
336 GEOMBase_Skeleton::closeEvent( e );