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_CircleDlg.cxx
25 // Author : Lucien PIGNOLONI
29 #include "BasicGUI_CircleDlg.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_CircleDlg()
44 // purpose : Constructs a BasicGUI_CircleDlg 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_CircleDlg::BasicGUI_CircleDlg(GeometryGUI* theGeometryGUI, QWidget* parent, const char* name, bool modal, WFlags fl)
50 :GEOMBase_Skeleton(parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu),
51 myGeometryGUI(theGeometryGUI)
53 QPixmap image0(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_CIRCLE_PV")));
54 QPixmap image2(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_CIRCLE_PNTS")));
55 QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_SELECT")));
57 setCaption(tr("GEOM_CIRCLE_TITLE"));
59 /***************************************************************/
60 GroupConstructors->setTitle(tr("GEOM_CIRCLE"));
61 RadioButton1->setPixmap(image0);
62 RadioButton2->setPixmap(image2);
63 RadioButton3->close(TRUE);
65 GroupPntVecR = new DlgRef_2Sel1Spin(this, "GroupPntVecR");
66 GroupPntVecR->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
68 GroupPntVecR->TextLabel1->setText(tr("GEOM_CENTER_POINT"));
69 GroupPntVecR->TextLabel2->setText(tr("GEOM_VECTOR"));
70 GroupPntVecR->TextLabel3->setText(tr("GEOM_RADIUS"));
71 GroupPntVecR->PushButton1->setPixmap(image1);
72 GroupPntVecR->PushButton2->setPixmap(image1);
74 GroupPntVecR->LineEdit1->setReadOnly( true );
75 GroupPntVecR->LineEdit2->setReadOnly( true );
77 Group3Pnts = new DlgRef_3Sel_QTD(this, "Group3Pnts");
78 Group3Pnts->GroupBox1->setTitle(tr("GEOM_3_POINTS"));
79 Group3Pnts->TextLabel1->setText(tr("GEOM_POINT1"));
80 Group3Pnts->TextLabel2->setText(tr("GEOM_POINT2"));
81 Group3Pnts->TextLabel3->setText(tr("GEOM_POINT3"));
82 Group3Pnts->PushButton1->setPixmap(image1);
83 Group3Pnts->PushButton2->setPixmap(image1);
84 Group3Pnts->PushButton3->setPixmap(image1);
86 Group3Pnts->LineEdit1->setReadOnly( true );
87 Group3Pnts->LineEdit2->setReadOnly( true );
88 Group3Pnts->LineEdit3->setReadOnly( true );
90 Layout1->addWidget( GroupPntVecR, 2, 0 );
91 Layout1->addWidget( Group3Pnts, 2, 0 );
92 /***************************************************************/
98 //=================================================================================
99 // function : ~BasicGUI_CircleDlg()
100 // purpose : Destroys the object and frees any allocated resources
101 //=================================================================================
102 BasicGUI_CircleDlg::~BasicGUI_CircleDlg()
107 //=================================================================================
110 //=================================================================================
111 void BasicGUI_CircleDlg::Init()
114 myEditCurrentArgument = GroupPntVecR->LineEdit1;
116 myPoint = myDir = myPoint1 = myPoint2 = myPoint3 = GEOM::GEOM_Object::_nil();
118 // myGeometryGUI->SetState( 0 );
120 /* Get setting of step value from file configuration */
121 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
122 double aStep = resMgr->doubleValue( "Geometry", "SettingsGeomStep", 100);
124 /* min, max, step and decimals for spin boxes & initial values */
125 GroupPntVecR->SpinBox_DX->RangeStepAndValidator(0.001, 999.999, aStep, 3);
126 GroupPntVecR->SpinBox_DX->SetValue( 100 );
128 /* signals and slots connections */
129 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
130 connect(myGeometryGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
131 connect(myGeometryGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
133 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
134 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
135 connect(GroupConstructors, SIGNAL(clicked(int)), this, SLOT(ConstructorsClicked(int)));
137 connect(GroupPntVecR->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
138 connect(GroupPntVecR->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
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(GroupPntVecR->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
144 connect(GroupPntVecR->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
146 connect(GroupPntVecR->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
147 connect(myGeometryGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPntVecR->SpinBox_DX, SLOT(SetStep(double)));
149 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
150 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
152 initName( tr( "GEOM_CIRCLE" ) );
155 ConstructorsClicked( 0 );
158 //=================================================================================
159 // function : ConstructorsClicked()
160 // purpose : Radio button management
161 //=================================================================================
162 void BasicGUI_CircleDlg::ConstructorsClicked( int constructorId )
164 disconnect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), 0, this, 0 );
165 myPoint = myDir = myPoint1 = myPoint2 = myPoint3 = GEOM::GEOM_Object::_nil();
167 switch ( constructorId )
173 GroupPntVecR->show();
175 myEditCurrentArgument = GroupPntVecR->LineEdit1;
176 GroupPntVecR->LineEdit1->setText("");
177 GroupPntVecR->LineEdit2->setText("");
182 GroupPntVecR->hide();
186 myEditCurrentArgument = Group3Pnts->LineEdit1;
187 Group3Pnts->LineEdit1->setText("");
188 Group3Pnts->LineEdit2->setText("");
189 Group3Pnts->LineEdit3->setText("");
194 myEditCurrentArgument->setFocus();
195 globalSelection( GEOM_POINT );
196 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
197 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
200 //=================================================================================
201 // function : ClickOnOk()
203 //=================================================================================
204 void BasicGUI_CircleDlg::ClickOnOk()
206 if ( ClickOnApply() )
210 //=================================================================================
211 // function : ClickOnApply()
213 //=================================================================================
214 bool BasicGUI_CircleDlg::ClickOnApply()
220 ConstructorsClicked( getConstructorId() );
224 //=======================================================================
225 // function : ClickOnCancel()
227 //=======================================================================
228 void BasicGUI_CircleDlg::ClickOnCancel()
230 GEOMBase_Skeleton::ClickOnCancel();
233 //=================================================================================
234 // function : SelectionIntoArgument()
235 // purpose : Called when selection as changed or other case
236 //=================================================================================
237 void BasicGUI_CircleDlg::SelectionIntoArgument()
239 myEditCurrentArgument->setText("");
241 if ( IObjectCount() != 1 )
243 if ( myEditCurrentArgument == GroupPntVecR->LineEdit1 ) myPoint = GEOM::GEOM_Object::_nil();
244 else if ( myEditCurrentArgument == GroupPntVecR->LineEdit2 ) myDir = GEOM::GEOM_Object::_nil();
245 else if ( myEditCurrentArgument == Group3Pnts->LineEdit1 ) myPoint1 = GEOM::GEOM_Object::_nil();
246 else if ( myEditCurrentArgument == Group3Pnts->LineEdit2 ) myPoint2 = GEOM::GEOM_Object::_nil();
247 else if ( myEditCurrentArgument == Group3Pnts->LineEdit3 ) myPoint3 = GEOM::GEOM_Object::_nil();
252 Standard_Boolean aRes = Standard_False;
253 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( firstIObject(), aRes );
254 if ( !CORBA::is_nil( aSelectedObject ) && aRes )
256 myEditCurrentArgument->setText( GEOMBase::GetName( aSelectedObject ) );
257 if ( myEditCurrentArgument == GroupPntVecR->LineEdit1 ) myPoint = aSelectedObject;
258 else if ( myEditCurrentArgument == GroupPntVecR->LineEdit2 ) myDir = aSelectedObject;
259 else if ( myEditCurrentArgument == Group3Pnts->LineEdit1 ) myPoint1 = aSelectedObject;
260 else if ( myEditCurrentArgument == Group3Pnts->LineEdit2 ) myPoint2 = aSelectedObject;
261 else if ( myEditCurrentArgument == Group3Pnts->LineEdit3 ) myPoint3 = aSelectedObject;
268 //=================================================================================
269 // function : SetEditCurrentArgument()
271 //=================================================================================
272 void BasicGUI_CircleDlg::SetEditCurrentArgument()
274 QPushButton* send = (QPushButton*)sender();
276 if ( send == GroupPntVecR->PushButton1 ) myEditCurrentArgument = GroupPntVecR->LineEdit1;
277 else if ( send == GroupPntVecR->PushButton2 ) myEditCurrentArgument = GroupPntVecR->LineEdit2;
278 else if ( send == Group3Pnts->PushButton1 ) myEditCurrentArgument = Group3Pnts->LineEdit1;
279 else if ( send == Group3Pnts->PushButton2 ) myEditCurrentArgument = Group3Pnts->LineEdit2;
280 else if ( send == Group3Pnts->PushButton3 ) myEditCurrentArgument = Group3Pnts->LineEdit3;
282 myEditCurrentArgument->setFocus();
284 if ( myEditCurrentArgument == GroupPntVecR->LineEdit2 )
285 globalSelection( GEOM_LINE );
287 globalSelection( GEOM_POINT );
288 SelectionIntoArgument();
291 //=================================================================================
292 // function : LineEditReturnPressed()
294 //=================================================================================
295 void BasicGUI_CircleDlg::LineEditReturnPressed()
297 QLineEdit* send = (QLineEdit*)sender();
298 if ( send == GroupPntVecR->LineEdit1 ||
299 send == GroupPntVecR->LineEdit2 ||
300 send == Group3Pnts->LineEdit1 ||
301 send == Group3Pnts->LineEdit2 ||
302 send == Group3Pnts->LineEdit3 )
304 myEditCurrentArgument = send;
305 GEOMBase_Skeleton::LineEditReturnPressed();
310 //=================================================================================
311 // function : ActivateThisDialog()
313 //=================================================================================
314 void BasicGUI_CircleDlg::ActivateThisDialog()
316 GEOMBase_Skeleton::ActivateThisDialog();
317 globalSelection( GEOM_POINT );
318 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
319 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
321 // myGeometryGUI->SetState( 0 );
323 ConstructorsClicked( getConstructorId() );
327 //=================================================================================
328 // function : enterEvent()
330 //=================================================================================
331 void BasicGUI_CircleDlg::enterEvent(QEvent* e)
333 if ( !GroupConstructors->isEnabled() )
334 ActivateThisDialog();
337 //=================================================================================
338 // function : DeactivateActiveDialog()
339 // purpose : public slot to deactivate if active
340 //=================================================================================
341 void BasicGUI_CircleDlg::DeactivateActiveDialog()
343 // myGeometryGUI->SetState( -1 );
344 GEOMBase_Skeleton::DeactivateActiveDialog();
347 //=================================================================================
348 // function : ValueChangedInSpinBox()
350 //=================================================================================
351 void BasicGUI_CircleDlg::ValueChangedInSpinBox()
356 //=================================================================================
357 // function : getRadius()
359 //=================================================================================
360 double BasicGUI_CircleDlg::getRadius() const
362 return GroupPntVecR->SpinBox_DX->GetValue();
365 //=================================================================================
366 // function : createOperation
368 //=================================================================================
369 GEOM::GEOM_IOperations_ptr BasicGUI_CircleDlg::createOperation()
371 return myGeometryGUI->GetGeomGen()->GetICurvesOperations( getStudyId() );
374 //=================================================================================
375 // function : isEqual
376 // purpose : it may also be needed to check for min distance between gp_Pnt-s...
377 //=================================================================================
378 static bool isEqual( const GEOM::GEOM_Object_var& thePnt1, const GEOM::GEOM_Object_var& thePnt2 )
380 return thePnt1->_is_equivalent( thePnt2 );
383 //=================================================================================
384 // function : isValid
386 //=================================================================================
387 bool BasicGUI_CircleDlg::isValid( QString& msg )
389 const int id = getConstructorId();
391 return !myPoint->_is_nil() && !myDir->_is_nil() && getRadius() > 0;
393 return !myPoint1->_is_nil() && !myPoint2->_is_nil() && !myPoint3->_is_nil() &&
394 !isEqual( myPoint1, myPoint2 ) && !isEqual( myPoint1, myPoint3 ) && !isEqual( myPoint2, myPoint3 );
398 //=================================================================================
399 // function : execute
401 //=================================================================================
402 bool BasicGUI_CircleDlg::execute( ObjectList& objects )
406 GEOM::GEOM_Object_var anObj;
408 switch ( getConstructorId() )
411 anObj = GEOM::GEOM_ICurvesOperations::_narrow( getOperation() )->MakeCirclePntVecR( myPoint, myDir, getRadius() );
415 anObj = GEOM::GEOM_ICurvesOperations::_narrow( getOperation() )->MakeCircleThreePnt( myPoint1, myPoint2, myPoint3 );
420 if ( !anObj->_is_nil() )
421 objects.push_back( anObj._retn() );
426 //=================================================================================
427 // function : closeEvent
429 //=================================================================================
430 void BasicGUI_CircleDlg::closeEvent( QCloseEvent* e )
432 // myGeometryGUI->SetState( -1 );
433 GEOMBase_Skeleton::closeEvent( e );