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_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,
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 QPixmap image0(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_CIRCLE_PV")));
55 QPixmap image2(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_CIRCLE_PNTS")));
56 QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_SELECT")));
58 setCaption(tr("GEOM_CIRCLE_TITLE"));
60 /***************************************************************/
61 GroupConstructors->setTitle(tr("GEOM_CIRCLE"));
62 RadioButton1->setPixmap(image0);
63 RadioButton2->setPixmap(image2);
64 RadioButton3->close(TRUE);
66 GroupPntVecR = new DlgRef_2Sel1Spin(this, "GroupPntVecR");
67 GroupPntVecR->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
69 GroupPntVecR->TextLabel1->setText(tr("GEOM_CENTER_POINT"));
70 GroupPntVecR->TextLabel2->setText(tr("GEOM_VECTOR"));
71 GroupPntVecR->TextLabel3->setText(tr("GEOM_RADIUS"));
72 GroupPntVecR->PushButton1->setPixmap(image1);
73 GroupPntVecR->PushButton2->setPixmap(image1);
75 GroupPntVecR->LineEdit1->setReadOnly( true );
76 GroupPntVecR->LineEdit2->setReadOnly( true );
78 Group3Pnts = new DlgRef_3Sel_QTD(this, "Group3Pnts");
79 Group3Pnts->GroupBox1->setTitle(tr("GEOM_3_POINTS"));
80 Group3Pnts->TextLabel1->setText(tr("GEOM_POINT1"));
81 Group3Pnts->TextLabel2->setText(tr("GEOM_POINT2"));
82 Group3Pnts->TextLabel3->setText(tr("GEOM_POINT3"));
83 Group3Pnts->PushButton1->setPixmap(image1);
84 Group3Pnts->PushButton2->setPixmap(image1);
85 Group3Pnts->PushButton3->setPixmap(image1);
87 Group3Pnts->LineEdit1->setReadOnly( true );
88 Group3Pnts->LineEdit2->setReadOnly( true );
89 Group3Pnts->LineEdit3->setReadOnly( true );
91 Layout1->addWidget( GroupPntVecR, 2, 0 );
92 Layout1->addWidget( Group3Pnts, 2, 0 );
93 /***************************************************************/
95 setHelpFileName("circle.htm");
101 //=================================================================================
102 // function : ~BasicGUI_CircleDlg()
103 // purpose : Destroys the object and frees any allocated resources
104 //=================================================================================
105 BasicGUI_CircleDlg::~BasicGUI_CircleDlg()
110 //=================================================================================
113 //=================================================================================
114 void BasicGUI_CircleDlg::Init()
117 myEditCurrentArgument = GroupPntVecR->LineEdit1;
119 myPoint = myDir = myPoint1 = myPoint2 = myPoint3 = GEOM::GEOM_Object::_nil();
121 // myGeomGUI->SetState( 0 );
123 /* Get setting of step value from file configuration */
124 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
125 double aStep = resMgr->doubleValue( "Geometry", "SettingsGeomStep", 100);
127 /* min, max, step and decimals for spin boxes & initial values */
128 GroupPntVecR->SpinBox_DX->RangeStepAndValidator(0.001, COORD_MAX, aStep, DBL_DIGITS_DISPLAY);
129 GroupPntVecR->SpinBox_DX->SetValue( 100 );
131 /* signals and slots connections */
132 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
133 connect(myGeomGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
134 connect(myGeomGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
136 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
137 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
138 connect(GroupConstructors, SIGNAL(clicked(int)), this, SLOT(ConstructorsClicked(int)));
140 connect(GroupPntVecR->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
141 connect(GroupPntVecR->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
142 connect(Group3Pnts->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
143 connect(Group3Pnts->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
144 connect(Group3Pnts->PushButton3, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
146 connect(GroupPntVecR->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
147 connect(GroupPntVecR->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
149 connect(GroupPntVecR->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
150 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPntVecR->SpinBox_DX, SLOT(SetStep(double)));
152 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
153 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
155 initName( tr( "GEOM_CIRCLE" ) );
158 ConstructorsClicked( 0 );
161 //=================================================================================
162 // function : ConstructorsClicked()
163 // purpose : Radio button management
164 //=================================================================================
165 void BasicGUI_CircleDlg::ConstructorsClicked( int constructorId )
167 disconnect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), 0, this, 0 );
168 myPoint = myDir = myPoint1 = myPoint2 = myPoint3 = GEOM::GEOM_Object::_nil();
170 switch ( constructorId )
176 GroupPntVecR->show();
178 myEditCurrentArgument = GroupPntVecR->LineEdit1;
179 GroupPntVecR->LineEdit1->setText("");
180 GroupPntVecR->LineEdit2->setText("");
185 GroupPntVecR->hide();
189 myEditCurrentArgument = Group3Pnts->LineEdit1;
190 Group3Pnts->LineEdit1->setText("");
191 Group3Pnts->LineEdit2->setText("");
192 Group3Pnts->LineEdit3->setText("");
197 myEditCurrentArgument->setFocus();
198 globalSelection( GEOM_POINT );
199 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
200 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
203 //=================================================================================
204 // function : ClickOnOk()
206 //=================================================================================
207 void BasicGUI_CircleDlg::ClickOnOk()
209 if ( ClickOnApply() )
213 //=================================================================================
214 // function : ClickOnApply()
216 //=================================================================================
217 bool BasicGUI_CircleDlg::ClickOnApply()
223 ConstructorsClicked( getConstructorId() );
227 //=======================================================================
228 // function : ClickOnCancel()
230 //=======================================================================
231 void BasicGUI_CircleDlg::ClickOnCancel()
233 GEOMBase_Skeleton::ClickOnCancel();
236 //=================================================================================
237 // function : SelectionIntoArgument()
238 // purpose : Called when selection as changed or other case
239 //=================================================================================
240 void BasicGUI_CircleDlg::SelectionIntoArgument()
242 myEditCurrentArgument->setText("");
244 if ( IObjectCount() != 1 )
246 if ( myEditCurrentArgument == GroupPntVecR->LineEdit1 ) myPoint = GEOM::GEOM_Object::_nil();
247 else if ( myEditCurrentArgument == GroupPntVecR->LineEdit2 ) myDir = GEOM::GEOM_Object::_nil();
248 else if ( myEditCurrentArgument == Group3Pnts->LineEdit1 ) myPoint1 = GEOM::GEOM_Object::_nil();
249 else if ( myEditCurrentArgument == Group3Pnts->LineEdit2 ) myPoint2 = GEOM::GEOM_Object::_nil();
250 else if ( myEditCurrentArgument == Group3Pnts->LineEdit3 ) myPoint3 = GEOM::GEOM_Object::_nil();
255 Standard_Boolean aRes = Standard_False;
256 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( firstIObject(), aRes );
257 if ( !CORBA::is_nil( aSelectedObject ) && aRes )
259 myEditCurrentArgument->setText( GEOMBase::GetName( aSelectedObject ) );
260 if ( myEditCurrentArgument == GroupPntVecR->LineEdit1 ) myPoint = aSelectedObject;
261 else if ( myEditCurrentArgument == GroupPntVecR->LineEdit2 ) myDir = aSelectedObject;
262 else if ( myEditCurrentArgument == Group3Pnts->LineEdit1 ) myPoint1 = aSelectedObject;
263 else if ( myEditCurrentArgument == Group3Pnts->LineEdit2 ) myPoint2 = aSelectedObject;
264 else if ( myEditCurrentArgument == Group3Pnts->LineEdit3 ) myPoint3 = aSelectedObject;
271 //=================================================================================
272 // function : SetEditCurrentArgument()
274 //=================================================================================
275 void BasicGUI_CircleDlg::SetEditCurrentArgument()
277 QPushButton* send = (QPushButton*)sender();
279 if ( send == GroupPntVecR->PushButton1 ) myEditCurrentArgument = GroupPntVecR->LineEdit1;
280 else if ( send == GroupPntVecR->PushButton2 ) myEditCurrentArgument = GroupPntVecR->LineEdit2;
281 else if ( send == Group3Pnts->PushButton1 ) myEditCurrentArgument = Group3Pnts->LineEdit1;
282 else if ( send == Group3Pnts->PushButton2 ) myEditCurrentArgument = Group3Pnts->LineEdit2;
283 else if ( send == Group3Pnts->PushButton3 ) myEditCurrentArgument = Group3Pnts->LineEdit3;
285 myEditCurrentArgument->setFocus();
287 if ( myEditCurrentArgument == GroupPntVecR->LineEdit2 )
288 globalSelection( GEOM_LINE );
290 globalSelection( GEOM_POINT );
291 SelectionIntoArgument();
294 //=================================================================================
295 // function : LineEditReturnPressed()
297 //=================================================================================
298 void BasicGUI_CircleDlg::LineEditReturnPressed()
300 QLineEdit* send = (QLineEdit*)sender();
301 if ( send == GroupPntVecR->LineEdit1 ||
302 send == GroupPntVecR->LineEdit2 ||
303 send == Group3Pnts->LineEdit1 ||
304 send == Group3Pnts->LineEdit2 ||
305 send == Group3Pnts->LineEdit3 )
307 myEditCurrentArgument = send;
308 GEOMBase_Skeleton::LineEditReturnPressed();
313 //=================================================================================
314 // function : ActivateThisDialog()
316 //=================================================================================
317 void BasicGUI_CircleDlg::ActivateThisDialog()
319 GEOMBase_Skeleton::ActivateThisDialog();
320 globalSelection( GEOM_POINT );
321 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
322 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
324 // myGeomGUI->SetState( 0 );
326 ConstructorsClicked( getConstructorId() );
330 //=================================================================================
331 // function : enterEvent()
333 //=================================================================================
334 void BasicGUI_CircleDlg::enterEvent(QEvent* e)
336 if ( !GroupConstructors->isEnabled() )
337 ActivateThisDialog();
340 //=================================================================================
341 // function : DeactivateActiveDialog()
342 // purpose : public slot to deactivate if active
343 //=================================================================================
344 void BasicGUI_CircleDlg::DeactivateActiveDialog()
346 // myGeomGUI->SetState( -1 );
347 GEOMBase_Skeleton::DeactivateActiveDialog();
350 //=================================================================================
351 // function : ValueChangedInSpinBox()
353 //=================================================================================
354 void BasicGUI_CircleDlg::ValueChangedInSpinBox()
359 //=================================================================================
360 // function : getRadius()
362 //=================================================================================
363 double BasicGUI_CircleDlg::getRadius() const
365 return GroupPntVecR->SpinBox_DX->GetValue();
368 //=================================================================================
369 // function : createOperation
371 //=================================================================================
372 GEOM::GEOM_IOperations_ptr BasicGUI_CircleDlg::createOperation()
374 return myGeomGUI->GetGeomGen()->GetICurvesOperations( getStudyId() );
377 //=================================================================================
378 // function : isEqual
379 // purpose : it may also be needed to check for min distance between gp_Pnt-s...
380 //=================================================================================
381 static bool isEqual( const GEOM::GEOM_Object_var& thePnt1, const GEOM::GEOM_Object_var& thePnt2 )
383 return thePnt1->_is_equivalent( thePnt2 );
386 //=================================================================================
387 // function : isValid
389 //=================================================================================
390 bool BasicGUI_CircleDlg::isValid( QString& msg )
392 const int id = getConstructorId();
394 return !myPoint->_is_nil() && !myDir->_is_nil() && getRadius() > 0;
396 return !myPoint1->_is_nil() && !myPoint2->_is_nil() && !myPoint3->_is_nil() &&
397 !isEqual( myPoint1, myPoint2 ) && !isEqual( myPoint1, myPoint3 ) && !isEqual( myPoint2, myPoint3 );
401 //=================================================================================
402 // function : execute
404 //=================================================================================
405 bool BasicGUI_CircleDlg::execute( ObjectList& objects )
409 GEOM::GEOM_Object_var anObj;
411 switch ( getConstructorId() )
414 anObj = GEOM::GEOM_ICurvesOperations::_narrow( getOperation() )->MakeCirclePntVecR( myPoint, myDir, getRadius() );
418 anObj = GEOM::GEOM_ICurvesOperations::_narrow( getOperation() )->MakeCircleThreePnt( myPoint1, myPoint2, myPoint3 );
423 if ( !anObj->_is_nil() )
424 objects.push_back( anObj._retn() );
429 //=================================================================================
430 // function : closeEvent
432 //=================================================================================
433 void BasicGUI_CircleDlg::closeEvent( QCloseEvent* e )
435 GEOMBase_Skeleton::closeEvent( e );