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"
39 #include "GEOM_Object.hxx"
40 #include "GEOM_Engine.hxx"
42 #include "utilities.h"
44 //=================================================================================
45 // class : BasicGUI_CircleDlg()
46 // purpose : Constructs a BasicGUI_CircleDlg which is a child of 'parent', with the
47 // name 'name' and widget flags set to 'f'.
48 // The dialog will by default be modeless, unless you set 'modal' to
49 // TRUE to construct a modal dialog.
50 //=================================================================================
51 BasicGUI_CircleDlg::BasicGUI_CircleDlg(GeometryGUI* theGeometryGUI, QWidget* parent,
52 const char* name, bool modal, WFlags fl)
53 :GEOMBase_Skeleton(theGeometryGUI, parent, name, modal, WStyle_Customize |
54 WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
56 QPixmap image0(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_CIRCLE_PV")));
57 QPixmap image2(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_CIRCLE_PNTS")));
58 QPixmap image3(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_CIRCLE_C2P")));
59 QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_SELECT")));
61 setCaption(tr("GEOM_CIRCLE_TITLE"));
63 /***************************************************************/
64 GroupConstructors->setTitle(tr("GEOM_CIRCLE"));
65 RadioButton1->setPixmap(image0);
66 RadioButton2->setPixmap(image2);
67 RadioButton3->setPixmap(image3);
69 GroupPntVecR = new DlgRef_2Sel1Spin(this, "GroupPntVecR");
70 GroupPntVecR->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
72 GroupPntVecR->TextLabel1->setText(tr("GEOM_CENTER_POINT"));
73 GroupPntVecR->TextLabel2->setText(tr("GEOM_VECTOR"));
74 GroupPntVecR->TextLabel3->setText(tr("GEOM_RADIUS"));
75 GroupPntVecR->PushButton1->setPixmap(image1);
76 GroupPntVecR->PushButton2->setPixmap(image1);
78 GroupPntVecR->LineEdit1->setReadOnly( true );
79 GroupPntVecR->LineEdit2->setReadOnly( true );
81 Group3Pnts = new DlgRef_3Sel_QTD(this, "Group3Pnts");
82 Group3Pnts->GroupBox1->setTitle(tr("GEOM_3_POINTS"));
83 Group3Pnts->TextLabel1->setText(tr("GEOM_POINT1"));
84 Group3Pnts->TextLabel2->setText(tr("GEOM_POINT2"));
85 Group3Pnts->TextLabel3->setText(tr("GEOM_POINT3"));
86 Group3Pnts->PushButton1->setPixmap(image1);
87 Group3Pnts->PushButton2->setPixmap(image1);
88 Group3Pnts->PushButton3->setPixmap(image1);
90 Group3Pnts->LineEdit1->setReadOnly( true );
91 Group3Pnts->LineEdit2->setReadOnly( true );
92 Group3Pnts->LineEdit3->setReadOnly( true );
94 GroupCenter2Pnts = new DlgRef_3Sel_QTD(this, "GroupCenter2Pnts");
95 GroupCenter2Pnts->GroupBox1->setTitle(tr("GEOM_CENTER_2POINTS"));
96 GroupCenter2Pnts->TextLabel1->setText(tr("GEOM_CENTER_POINT"));
97 GroupCenter2Pnts->TextLabel2->setText(tr("GEOM_POINT1"));
98 GroupCenter2Pnts->TextLabel3->setText(tr("GEOM_POINT2"));
99 GroupCenter2Pnts->PushButton1->setPixmap(image1);
100 GroupCenter2Pnts->PushButton2->setPixmap(image1);
101 GroupCenter2Pnts->PushButton3->setPixmap(image1);
103 GroupCenter2Pnts->LineEdit1->setReadOnly( true );
104 GroupCenter2Pnts->LineEdit2->setReadOnly( true );
105 GroupCenter2Pnts->LineEdit3->setReadOnly( true );
107 Layout1->addWidget( GroupPntVecR, 2, 0 );
108 Layout1->addWidget( Group3Pnts, 2, 0 );
109 Layout1->addWidget( GroupCenter2Pnts, 2, 0 );
110 /***************************************************************/
112 setHelpFileName("circle.htm");
118 //=================================================================================
119 // function : ~BasicGUI_CircleDlg()
120 // purpose : Destroys the object and frees any allocated resources
121 //=================================================================================
122 BasicGUI_CircleDlg::~BasicGUI_CircleDlg()
127 //=================================================================================
130 //=================================================================================
131 void BasicGUI_CircleDlg::Init()
134 myEditCurrentArgument = GroupPntVecR->LineEdit1;
136 myPoint = myDir = myPoint1 = myPoint2 = myPoint3 = GEOM::GEOM_Object::_nil();
138 // myGeomGUI->SetState( 0 );
140 /* Get setting of step value from file configuration */
141 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
142 double aStep = resMgr->doubleValue( "Geometry", "SettingsGeomStep", 100);
144 /* min, max, step and decimals for spin boxes & initial values */
145 GroupPntVecR->SpinBox_DX->RangeStepAndValidator(0.001, COORD_MAX, aStep, DBL_DIGITS_DISPLAY);
146 GroupPntVecR->SpinBox_DX->SetValue( 100 );
148 /* signals and slots connections */
149 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
150 connect(myGeomGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
151 connect(myGeomGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
153 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
154 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
155 connect(GroupConstructors, SIGNAL(clicked(int)), this, SLOT(ConstructorsClicked(int)));
157 connect(GroupPntVecR->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
158 connect(GroupPntVecR->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
159 connect(Group3Pnts->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
160 connect(Group3Pnts->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
161 connect(Group3Pnts->PushButton3, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
163 connect(GroupCenter2Pnts->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
164 connect(GroupCenter2Pnts->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
165 connect(GroupCenter2Pnts->PushButton3, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
167 connect(GroupPntVecR->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
168 connect(GroupPntVecR->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
170 connect(GroupPntVecR->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
171 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPntVecR->SpinBox_DX, SLOT(SetStep(double)));
173 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
174 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
176 initName( tr( "GEOM_CIRCLE" ) );
179 GroupCenter2Pnts->hide();
180 ConstructorsClicked( 0 );
183 //=================================================================================
184 // function : ConstructorsClicked()
185 // purpose : Radio button management
186 //=================================================================================
187 void BasicGUI_CircleDlg::ConstructorsClicked( int constructorId )
189 disconnect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), 0, this, 0 );
190 myPoint = myDir = myPoint1 = myPoint2 = myPoint3 = GEOM::GEOM_Object::_nil();
192 switch ( constructorId )
197 GroupCenter2Pnts->hide();
199 GroupPntVecR->show();
201 myEditCurrentArgument = GroupPntVecR->LineEdit1;
202 GroupPntVecR->LineEdit1->setText("");
203 GroupPntVecR->LineEdit2->setText("");
208 GroupPntVecR->hide();
209 GroupCenter2Pnts->hide();
213 myEditCurrentArgument = Group3Pnts->LineEdit1;
214 Group3Pnts->LineEdit1->setText("");
215 Group3Pnts->LineEdit2->setText("");
216 Group3Pnts->LineEdit3->setText("");
221 GroupPntVecR->hide();
224 GroupCenter2Pnts->show();
226 myEditCurrentArgument = GroupCenter2Pnts->LineEdit1;
227 GroupCenter2Pnts->LineEdit1->setText("");
228 GroupCenter2Pnts->LineEdit2->setText("");
229 GroupCenter2Pnts->LineEdit3->setText("");
234 myEditCurrentArgument->setFocus();
235 globalSelection( GEOM_POINT );
236 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
237 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
240 //=================================================================================
241 // function : ClickOnOk()
243 //=================================================================================
244 void BasicGUI_CircleDlg::ClickOnOk()
246 if ( ClickOnApply() )
250 //=================================================================================
251 // function : ClickOnApply()
253 //=================================================================================
254 bool BasicGUI_CircleDlg::ClickOnApply()
260 ConstructorsClicked( getConstructorId() );
264 //=======================================================================
265 // function : ClickOnCancel()
267 //=======================================================================
268 void BasicGUI_CircleDlg::ClickOnCancel()
270 GEOMBase_Skeleton::ClickOnCancel();
273 //=================================================================================
274 // function : SelectionIntoArgument()
275 // purpose : Called when selection as changed or other case
276 //=================================================================================
277 void BasicGUI_CircleDlg::SelectionIntoArgument()
279 myEditCurrentArgument->setText("");
281 if ( IObjectCount() != 1 )
283 if ( myEditCurrentArgument == GroupPntVecR->LineEdit1 ) myPoint = GEOM::GEOM_Object::_nil();
284 else if ( myEditCurrentArgument == GroupPntVecR->LineEdit2 ) myDir = GEOM::GEOM_Object::_nil();
285 else if ( myEditCurrentArgument == Group3Pnts->LineEdit1 ) myPoint1 = GEOM::GEOM_Object::_nil();
286 else if ( myEditCurrentArgument == Group3Pnts->LineEdit2 ) myPoint2 = GEOM::GEOM_Object::_nil();
287 else if ( myEditCurrentArgument == Group3Pnts->LineEdit3 ) myPoint3 = GEOM::GEOM_Object::_nil();
288 else if ( myEditCurrentArgument == GroupCenter2Pnts->LineEdit1 ) myPoint4 = GEOM::GEOM_Object::_nil();
289 else if ( myEditCurrentArgument == GroupCenter2Pnts->LineEdit2 ) myPoint5 = GEOM::GEOM_Object::_nil();
290 else if ( myEditCurrentArgument == GroupCenter2Pnts->LineEdit3 ) myPoint6 = GEOM::GEOM_Object::_nil();
295 Standard_Boolean aRes = Standard_False;
296 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( firstIObject(), aRes );
297 if ( !CORBA::is_nil( aSelectedObject ) && aRes )
300 myEditCurrentArgument->setText( GEOMBase::GetName( aSelectedObject ) );
301 if ( myEditCurrentArgument == GroupPntVecR->LineEdit1 ) myPoint = aSelectedObject;
302 else if ( myEditCurrentArgument == GroupPntVecR->LineEdit2 ) myDir = aSelectedObject;
303 else if ( myEditCurrentArgument == Group3Pnts->LineEdit1 ) myPoint1 = aSelectedObject;
304 else if ( myEditCurrentArgument == Group3Pnts->LineEdit2 ) myPoint2 = aSelectedObject;
305 else if ( myEditCurrentArgument == Group3Pnts->LineEdit3 ) myPoint3 = aSelectedObject;
306 else if ( myEditCurrentArgument == GroupCenter2Pnts->LineEdit1 ) myPoint4 = aSelectedObject;
307 else if ( myEditCurrentArgument == GroupCenter2Pnts->LineEdit2 ) myPoint5 = aSelectedObject;
308 else if ( myEditCurrentArgument == GroupCenter2Pnts->LineEdit3 ) myPoint6 = aSelectedObject;
314 //=================================================================================
315 // function : SetEditCurrentArgument()
317 //=================================================================================
318 void BasicGUI_CircleDlg::SetEditCurrentArgument()
320 QPushButton* send = (QPushButton*)sender();
322 if ( send == GroupPntVecR->PushButton1 ) myEditCurrentArgument = GroupPntVecR->LineEdit1;
323 else if ( send == GroupPntVecR->PushButton2 ) myEditCurrentArgument = GroupPntVecR->LineEdit2;
324 else if ( send == Group3Pnts->PushButton1 ) myEditCurrentArgument = Group3Pnts->LineEdit1;
325 else if ( send == Group3Pnts->PushButton2 ) myEditCurrentArgument = Group3Pnts->LineEdit2;
326 else if ( send == Group3Pnts->PushButton3 ) myEditCurrentArgument = Group3Pnts->LineEdit3;
327 else if ( send == GroupCenter2Pnts->PushButton1 ) myEditCurrentArgument = GroupCenter2Pnts->LineEdit1;
328 else if ( send == GroupCenter2Pnts->PushButton2 ) myEditCurrentArgument = GroupCenter2Pnts->LineEdit2;
329 else if ( send == GroupCenter2Pnts->PushButton3 ) myEditCurrentArgument = GroupCenter2Pnts->LineEdit3;
331 myEditCurrentArgument->setFocus();
333 if ( myEditCurrentArgument == GroupPntVecR->LineEdit2 )
334 globalSelection( GEOM_LINE );
336 globalSelection( GEOM_POINT );
337 SelectionIntoArgument();
340 //=================================================================================
341 // function : LineEditReturnPressed()
343 //=================================================================================
344 void BasicGUI_CircleDlg::LineEditReturnPressed()
346 QLineEdit* send = (QLineEdit*)sender();
347 if ( send == GroupPntVecR->LineEdit1 ||
348 send == GroupPntVecR->LineEdit2 ||
349 send == Group3Pnts->LineEdit1 ||
350 send == Group3Pnts->LineEdit2 ||
351 send == Group3Pnts->LineEdit3 ||
352 send == GroupCenter2Pnts->LineEdit1 ||
353 send == GroupCenter2Pnts->LineEdit2 ||
354 send == GroupCenter2Pnts->LineEdit3 )
356 myEditCurrentArgument = send;
357 GEOMBase_Skeleton::LineEditReturnPressed();
362 //=================================================================================
363 // function : ActivateThisDialog()
365 //=================================================================================
366 void BasicGUI_CircleDlg::ActivateThisDialog()
368 GEOMBase_Skeleton::ActivateThisDialog();
369 globalSelection( GEOM_POINT );
370 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
371 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
373 // myGeomGUI->SetState( 0 );
375 ConstructorsClicked( getConstructorId() );
379 //=================================================================================
380 // function : enterEvent()
382 //=================================================================================
383 void BasicGUI_CircleDlg::enterEvent(QEvent* e)
385 if ( !GroupConstructors->isEnabled() )
386 ActivateThisDialog();
389 //=================================================================================
390 // function : DeactivateActiveDialog()
391 // purpose : public slot to deactivate if active
392 //=================================================================================
393 void BasicGUI_CircleDlg::DeactivateActiveDialog()
395 // myGeomGUI->SetState( -1 );
396 GEOMBase_Skeleton::DeactivateActiveDialog();
399 //=================================================================================
400 // function : ValueChangedInSpinBox()
402 //=================================================================================
403 void BasicGUI_CircleDlg::ValueChangedInSpinBox()
408 //=================================================================================
409 // function : getRadius()
411 //=================================================================================
412 double BasicGUI_CircleDlg::getRadius() const
414 switch ( getConstructorId() )
417 return GroupPntVecR->SpinBox_DX->GetValue();
421 //=================================================================================
422 // function : createOperation
424 //=================================================================================
425 GEOM::GEOM_IOperations_ptr BasicGUI_CircleDlg::createOperation()
427 return myGeomGUI->GetGeomGen()->GetICurvesOperations( getStudyId() );
430 //=================================================================================
431 // function : isEqual
432 // purpose : it may also be needed to check for min distance between gp_Pnt-s...
433 //=================================================================================
434 static bool isEqual( const GEOM::GEOM_Object_var& thePnt1, const GEOM::GEOM_Object_var& thePnt2 )
436 return thePnt1->_is_equivalent( thePnt2 );
439 //=================================================================================
440 // function : isValid
442 //=================================================================================
443 bool BasicGUI_CircleDlg::isValid( QString& msg )
445 const int id = getConstructorId();
447 return !myPoint->_is_nil() && !myDir->_is_nil() && getRadius() > 0;
449 return !myPoint1->_is_nil() && !myPoint2->_is_nil() && !myPoint3->_is_nil() &&
450 !isEqual( myPoint1, myPoint2 ) && !isEqual( myPoint1, myPoint3 ) && !isEqual( myPoint2, myPoint3 );
452 return !myPoint4->_is_nil() && !myPoint5->_is_nil() && !myPoint6->_is_nil() &&
453 !isEqual( myPoint4, myPoint5 ) && !isEqual( myPoint5, myPoint6 ) && !isEqual( myPoint4, myPoint6 );
457 //=================================================================================
458 // function : execute
460 //=================================================================================
461 bool BasicGUI_CircleDlg::execute( ObjectList& objects )
465 GEOM::GEOM_Object_var anObj;
467 switch ( getConstructorId() )
469 cout << "constructior ID = " << getConstructorId() << endl;
471 anObj = GEOM::GEOM_ICurvesOperations::_narrow( getOperation() )->MakeCirclePntVecR( myPoint, myDir, getRadius() );
475 anObj = GEOM::GEOM_ICurvesOperations::_narrow( getOperation() )->MakeCircleThreePnt( myPoint1, myPoint2, myPoint3 );
479 anObj = GEOM::GEOM_ICurvesOperations::_narrow( getOperation() )->MakeCircleCenter2Pnt( myPoint4, myPoint5, myPoint6 );
484 if ( !anObj->_is_nil() )
485 objects.push_back( anObj._retn() );
486 else cout << "Execute Object is NULL!" << endl;
491 //=================================================================================
492 // function : closeEvent
494 //=================================================================================
495 void BasicGUI_CircleDlg::closeEvent( QCloseEvent* e )
497 GEOMBase_Skeleton::closeEvent( e );