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 "QAD_Desktop.h"
32 #include "QAD_Config.h"
34 #include "GEOMImpl_Types.hxx"
36 #include "utilities.h"
38 //=================================================================================
39 // class : BasicGUI_CircleDlg()
40 // purpose : Constructs a BasicGUI_CircleDlg which is a child of 'parent', with the
41 // name 'name' and widget flags set to 'f'.
42 // The dialog will by default be modeless, unless you set 'modal' to
43 // TRUE to construct a modal dialog.
44 //=================================================================================
45 BasicGUI_CircleDlg::BasicGUI_CircleDlg(QWidget* parent, const char* name, SALOME_Selection* Sel, bool modal, WFlags fl)
46 :GEOMBase_Skeleton(parent, name, Sel, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
48 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_CIRCLE_PV")));
49 QPixmap image2(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_CIRCLE_PNTS")));
50 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_SELECT")));
52 setCaption(tr("GEOM_CIRCLE_TITLE"));
54 /***************************************************************/
55 GroupConstructors->setTitle(tr("GEOM_CIRCLE"));
56 RadioButton1->setPixmap(image0);
57 RadioButton2->setPixmap(image2);
58 RadioButton3->close(TRUE);
60 GroupPntVecR = new DlgRef_2Sel1Spin(this, "GroupPntVecR");
61 GroupPntVecR->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
63 GroupPntVecR->TextLabel1->setText(tr("GEOM_CENTER_POINT"));
64 GroupPntVecR->TextLabel2->setText(tr("GEOM_VECTOR"));
65 GroupPntVecR->TextLabel3->setText(tr("GEOM_RADIUS"));
66 GroupPntVecR->PushButton1->setPixmap(image1);
67 GroupPntVecR->PushButton2->setPixmap(image1);
69 GroupPntVecR->LineEdit1->setReadOnly( true );
70 GroupPntVecR->LineEdit2->setReadOnly( true );
72 Group3Pnts = new DlgRef_3Sel_QTD(this, "Group3Pnts");
73 Group3Pnts->GroupBox1->setTitle(tr("GEOM_3_POINTS"));
74 Group3Pnts->TextLabel1->setText(tr("GEOM_POINT1"));
75 Group3Pnts->TextLabel2->setText(tr("GEOM_POINT2"));
76 Group3Pnts->TextLabel3->setText(tr("GEOM_POINT3"));
77 Group3Pnts->PushButton1->setPixmap(image1);
78 Group3Pnts->PushButton2->setPixmap(image1);
79 Group3Pnts->PushButton3->setPixmap(image1);
81 Group3Pnts->LineEdit1->setReadOnly( true );
82 Group3Pnts->LineEdit2->setReadOnly( true );
83 Group3Pnts->LineEdit3->setReadOnly( true );
85 Layout1->addWidget( GroupPntVecR, 2, 0 );
86 Layout1->addWidget( Group3Pnts, 2, 0 );
87 /***************************************************************/
93 //=================================================================================
94 // function : ~BasicGUI_CircleDlg()
95 // purpose : Destroys the object and frees any allocated resources
96 //=================================================================================
97 BasicGUI_CircleDlg::~BasicGUI_CircleDlg()
102 //=================================================================================
105 //=================================================================================
106 void BasicGUI_CircleDlg::Init()
109 myEditCurrentArgument = GroupPntVecR->LineEdit1;
111 myPoint = myDir = myPoint1 = myPoint2 = myPoint3 = GEOM::GEOM_Object::_nil();
113 myGeomGUI->SetState( 0 );
115 /* Get setting of step value from file configuration */
116 QString St = QAD_CONFIG->getSetting("Geometry:SettingsGeomStep");
117 double aStep = St.toDouble();
119 /* min, max, step and decimals for spin boxes & initial values */
120 GroupPntVecR->SpinBox_DX->RangeStepAndValidator(0.001, 999.999, aStep, 3);
121 GroupPntVecR->SpinBox_DX->SetValue( 100 );
123 /* signals and slots connections */
124 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
125 connect(myGeomGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
126 connect(myGeomGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
128 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
129 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
130 connect(GroupConstructors, SIGNAL(clicked(int)), this, SLOT(ConstructorsClicked(int)));
132 connect(GroupPntVecR->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
133 connect(GroupPntVecR->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
134 connect(Group3Pnts->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
135 connect(Group3Pnts->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
136 connect(Group3Pnts->PushButton3, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
138 connect(GroupPntVecR->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
139 connect(GroupPntVecR->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
141 connect(GroupPntVecR->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
142 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPntVecR->SpinBox_DX, SLOT(SetStep(double)));
144 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
146 initName( tr( "GEOM_CIRCLE" ) );
149 ConstructorsClicked( 0 );
152 //=================================================================================
153 // function : ConstructorsClicked()
154 // purpose : Radio button management
155 //=================================================================================
156 void BasicGUI_CircleDlg::ConstructorsClicked( int constructorId )
158 disconnect( mySelection, 0, this, 0 );
159 myPoint = myDir = myPoint1 = myPoint2 = myPoint3 = GEOM::GEOM_Object::_nil();
161 switch ( constructorId )
167 GroupPntVecR->show();
169 myEditCurrentArgument = GroupPntVecR->LineEdit1;
170 GroupPntVecR->LineEdit1->setText("");
171 GroupPntVecR->LineEdit2->setText("");
176 GroupPntVecR->hide();
180 myEditCurrentArgument = Group3Pnts->LineEdit1;
181 Group3Pnts->LineEdit1->setText("");
182 Group3Pnts->LineEdit2->setText("");
183 Group3Pnts->LineEdit3->setText("");
188 myEditCurrentArgument->setFocus();
189 globalSelection( GEOM_POINT );
190 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
193 //=================================================================================
194 // function : ClickOnOk()
196 //=================================================================================
197 void BasicGUI_CircleDlg::ClickOnOk()
199 if ( ClickOnApply() )
203 //=================================================================================
204 // function : ClickOnApply()
206 //=================================================================================
207 bool BasicGUI_CircleDlg::ClickOnApply()
213 ConstructorsClicked( getConstructorId() );
217 //=======================================================================
218 // function : ClickOnCancel()
220 //=======================================================================
221 void BasicGUI_CircleDlg::ClickOnCancel()
223 GEOMBase_Skeleton::ClickOnCancel();
226 //=================================================================================
227 // function : SelectionIntoArgument()
228 // purpose : Called when selection as changed or other case
229 //=================================================================================
230 void BasicGUI_CircleDlg::SelectionIntoArgument()
232 myEditCurrentArgument->setText("");
234 if ( mySelection->IObjectCount() != 1 )
236 if ( myEditCurrentArgument == GroupPntVecR->LineEdit1 ) myPoint = GEOM::GEOM_Object::_nil();
237 else if ( myEditCurrentArgument == GroupPntVecR->LineEdit2 ) myDir = GEOM::GEOM_Object::_nil();
238 else if ( myEditCurrentArgument == Group3Pnts->LineEdit1 ) myPoint1 = GEOM::GEOM_Object::_nil();
239 else if ( myEditCurrentArgument == Group3Pnts->LineEdit2 ) myPoint2 = GEOM::GEOM_Object::_nil();
240 else if ( myEditCurrentArgument == Group3Pnts->LineEdit3 ) myPoint3 = GEOM::GEOM_Object::_nil();
245 Standard_Boolean aRes = Standard_False;
246 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( mySelection->firstIObject(), aRes );
247 if ( !CORBA::is_nil( aSelectedObject ) && aRes )
249 myEditCurrentArgument->setText( GEOMBase::GetName( aSelectedObject ) );
250 if ( myEditCurrentArgument == GroupPntVecR->LineEdit1 ) myPoint = aSelectedObject;
251 else if ( myEditCurrentArgument == GroupPntVecR->LineEdit2 ) myDir = aSelectedObject;
252 else if ( myEditCurrentArgument == Group3Pnts->LineEdit1 ) myPoint1 = aSelectedObject;
253 else if ( myEditCurrentArgument == Group3Pnts->LineEdit2 ) myPoint2 = aSelectedObject;
254 else if ( myEditCurrentArgument == Group3Pnts->LineEdit3 ) myPoint3 = aSelectedObject;
261 //=================================================================================
262 // function : SetEditCurrentArgument()
264 //=================================================================================
265 void BasicGUI_CircleDlg::SetEditCurrentArgument()
267 QPushButton* send = (QPushButton*)sender();
269 if ( send == GroupPntVecR->PushButton1 ) myEditCurrentArgument = GroupPntVecR->LineEdit1;
270 else if ( send == GroupPntVecR->PushButton2 ) myEditCurrentArgument = GroupPntVecR->LineEdit2;
271 else if ( send == Group3Pnts->PushButton1 ) myEditCurrentArgument = Group3Pnts->LineEdit1;
272 else if ( send == Group3Pnts->PushButton2 ) myEditCurrentArgument = Group3Pnts->LineEdit2;
273 else if ( send == Group3Pnts->PushButton3 ) myEditCurrentArgument = Group3Pnts->LineEdit3;
275 myEditCurrentArgument->setFocus();
277 if ( myEditCurrentArgument == GroupPntVecR->LineEdit2 )
278 globalSelection( GEOM_LINE );
280 globalSelection( GEOM_POINT );
281 SelectionIntoArgument();
284 //=================================================================================
285 // function : LineEditReturnPressed()
287 //=================================================================================
288 void BasicGUI_CircleDlg::LineEditReturnPressed()
290 QLineEdit* send = (QLineEdit*)sender();
291 if ( send == GroupPntVecR->LineEdit1 ||
292 send == GroupPntVecR->LineEdit2 ||
293 send == Group3Pnts->LineEdit1 ||
294 send == Group3Pnts->LineEdit2 ||
295 send == Group3Pnts->LineEdit3 )
297 myEditCurrentArgument = send;
298 GEOMBase_Skeleton::LineEditReturnPressed();
303 //=================================================================================
304 // function : ActivateThisDialog()
306 //=================================================================================
307 void BasicGUI_CircleDlg::ActivateThisDialog()
309 GEOMBase_Skeleton::ActivateThisDialog();
310 globalSelection( GEOM_POINT );
311 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
313 myGeomGUI->SetState( 0 );
315 ConstructorsClicked( getConstructorId() );
319 //=================================================================================
320 // function : enterEvent()
322 //=================================================================================
323 void BasicGUI_CircleDlg::enterEvent(QEvent* e)
325 if ( !GroupConstructors->isEnabled() )
326 ActivateThisDialog();
329 //=================================================================================
330 // function : DeactivateActiveDialog()
331 // purpose : public slot to deactivate if active
332 //=================================================================================
333 void BasicGUI_CircleDlg::DeactivateActiveDialog()
335 myGeomGUI->SetState( -1 );
336 GEOMBase_Skeleton::DeactivateActiveDialog();
339 //=================================================================================
340 // function : ValueChangedInSpinBox()
342 //=================================================================================
343 void BasicGUI_CircleDlg::ValueChangedInSpinBox()
348 //=================================================================================
349 // function : getRadius()
351 //=================================================================================
352 double BasicGUI_CircleDlg::getRadius() const
354 return GroupPntVecR->SpinBox_DX->GetValue();
357 //=================================================================================
358 // function : createOperation
360 //=================================================================================
361 GEOM::GEOM_IOperations_ptr BasicGUI_CircleDlg::createOperation()
363 return getGeomEngine()->GetICurvesOperations( getStudyId() );
366 //=================================================================================
367 // function : isEqual
368 // purpose : it may also be needed to check for min distance between gp_Pnt-s...
369 //=================================================================================
370 static bool isEqual( const GEOM::GEOM_Object_var& thePnt1, const GEOM::GEOM_Object_var& thePnt2 )
372 return thePnt1->_is_equivalent( thePnt2 );
375 //=================================================================================
376 // function : isValid
378 //=================================================================================
379 bool BasicGUI_CircleDlg::isValid( QString& msg )
381 const int id = getConstructorId();
383 return !myPoint->_is_nil() && !myDir->_is_nil() && getRadius() > 0;
385 return !myPoint1->_is_nil() && !myPoint2->_is_nil() && !myPoint3->_is_nil() &&
386 !isEqual( myPoint1, myPoint2 ) && !isEqual( myPoint1, myPoint3 ) && !isEqual( myPoint2, myPoint3 );
390 //=================================================================================
391 // function : execute
393 //=================================================================================
394 bool BasicGUI_CircleDlg::execute( ObjectList& objects )
398 GEOM::GEOM_Object_var anObj;
400 switch ( getConstructorId() )
403 anObj = GEOM::GEOM_ICurvesOperations::_narrow( getOperation() )->MakeCirclePntVecR( myPoint, myDir, getRadius() );
407 anObj = GEOM::GEOM_ICurvesOperations::_narrow( getOperation() )->MakeCircleThreePnt( myPoint1, myPoint2, myPoint3 );
412 if ( !anObj->_is_nil() )
413 objects.push_back( anObj._retn() );
418 //=================================================================================
419 // function : closeEvent
421 //=================================================================================
422 void BasicGUI_CircleDlg::closeEvent( QCloseEvent* e )
424 myGeomGUI->SetState( -1 );
425 GEOMBase_Skeleton::closeEvent( e );