1 // GEOM GEOMGUI : GUI for Geometry component
3 // Copyright (C) 2003 OPEN CASCADE
5 // This library is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU Lesser General Public
7 // License as published by the Free Software Foundation; either
8 // version 2.1 of the License.
10 // This library is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // Lesser General Public License for more details.
15 // You should have received a copy of the GNU Lesser General Public
16 // License along with this library; if not, write to the Free Software
17 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // File : BasicGUI_EllipseDlg.cxx
24 // Author : Nicolas REJNERI
28 #include "BasicGUI_EllipseDlg.h"
30 #include "SUIT_Desktop.h"
31 #include "SUIT_Session.h"
32 #include "SalomeApp_Application.h"
33 #include "LightApp_SelectionMgr.h"
37 #include "GEOMImpl_Types.hxx"
39 #include "utilities.h"
43 //=================================================================================
44 // class : BasicGUI_EllipseDlg()
45 // purpose : Constructs a BasicGUI_EllipseDlg which is a child of 'parent', with the
46 // name 'name' and widget flags set to 'f'.
47 // The dialog will by default be modeless, unless you set 'modal' to
48 // TRUE to construct a modal dialog.
49 //=================================================================================
50 BasicGUI_EllipseDlg::BasicGUI_EllipseDlg(GeometryGUI* theGeometryGUI, QWidget* parent,
51 const char* name, bool modal, WFlags fl)
52 :GEOMBase_Skeleton(theGeometryGUI, parent, name, modal, WStyle_Customize |
53 WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
55 QPixmap image0(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_ELLIPSE_PV")));
56 QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_SELECT")));
58 setCaption(tr("GEOM_ELLIPSE_TITLE"));
60 /***************************************************************/
61 GroupConstructors->setTitle(tr("GEOM_ELLIPSE"));
62 RadioButton1->setPixmap(image0);
63 RadioButton2->close(TRUE);
64 RadioButton3->close(TRUE);
66 GroupPoints = new DlgRef_2Sel2Spin(this, "GroupPoints");
67 GroupPoints->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
68 GroupPoints->TextLabel1->setText(tr("GEOM_CENTER"));
69 GroupPoints->TextLabel2->setText(tr("GEOM_VECTOR"));
70 GroupPoints->TextLabel3->setText(tr("GEOM_RADIUS_MAJOR"));
71 GroupPoints->TextLabel4->setText(tr("GEOM_RADIUS_MINOR"));
72 GroupPoints->PushButton1->setPixmap(image1);
73 GroupPoints->PushButton2->setPixmap(image1);
75 GroupPoints->LineEdit1->setReadOnly( true );
76 GroupPoints->LineEdit2->setReadOnly( true );
78 Layout1->addWidget(GroupPoints, 2, 0);
79 /***************************************************************/
81 setHelpFileName("ellipse.htm");
87 //=================================================================================
88 // function : ~BasicGUI_EllipseDlg()
89 // purpose : Destroys the object and frees any allocated resources
90 //=================================================================================
91 BasicGUI_EllipseDlg::~BasicGUI_EllipseDlg()
96 //=================================================================================
99 //=================================================================================
100 void BasicGUI_EllipseDlg::Init()
103 myEditCurrentArgument = GroupPoints->LineEdit1;
104 globalSelection( GEOM_POINT );
106 myPoint = myDir = GEOM::GEOM_Object::_nil();
108 // myGeomGUI->SetState( 0 );
110 /* Get setting of step value from file configuration */
111 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
112 double step = resMgr->doubleValue( "Geometry", "SettingsGeomStep", 100);
114 double aMajorR( 200. ), aMinorR( 100. );
116 /* min, max, step and decimals for spin boxes & initial values */
117 GroupPoints->SpinBox_DX->RangeStepAndValidator( 0.001, COORD_MAX, step, DBL_DIGITS_DISPLAY );
118 GroupPoints->SpinBox_DY->RangeStepAndValidator( 0.001, COORD_MAX, step, DBL_DIGITS_DISPLAY );
119 GroupPoints->SpinBox_DX->SetValue( aMajorR );
120 GroupPoints->SpinBox_DY->SetValue( aMinorR );
122 /* signals and slots connections */
123 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
124 connect(myGeomGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
125 connect(myGeomGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
127 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
128 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
130 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
131 connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
133 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
134 connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
136 connect(GroupPoints->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
137 connect(GroupPoints->SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
139 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_DX, SLOT(SetStep(double)));
140 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_DY, SLOT(SetStep(double)));
142 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
143 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
145 initName( tr( "GEOM_ELLIPSE" ) );
149 //=================================================================================
150 // function : ClickOnOk()
152 //=================================================================================
153 void BasicGUI_EllipseDlg::ClickOnOk()
155 if ( ClickOnApply() )
160 //=================================================================================
161 // function : ClickOnApply()
163 //=================================================================================
164 bool BasicGUI_EllipseDlg::ClickOnApply()
172 myPoint = myDir = GEOM::GEOM_Object::_nil();
173 GroupPoints->LineEdit1->setText( "" );
174 GroupPoints->LineEdit2->setText( "" );
175 myEditCurrentArgument = GroupPoints->LineEdit1;
176 globalSelection( GEOM_POINT );
181 //=======================================================================
182 // function : ClickOnCancel()
184 //=======================================================================
185 void BasicGUI_EllipseDlg::ClickOnCancel()
187 GEOMBase_Skeleton::ClickOnCancel();
190 //=================================================================================
191 // function : SelectionIntoArgument()
192 // purpose : Called when selection as changed or other case
193 //=================================================================================
194 void BasicGUI_EllipseDlg::SelectionIntoArgument()
196 myEditCurrentArgument->setText("");
198 if ( IObjectCount() != 1 )
200 if ( myEditCurrentArgument == GroupPoints->LineEdit1 ) myPoint = GEOM::GEOM_Object::_nil();
201 else if ( myEditCurrentArgument == GroupPoints->LineEdit2 ) myDir = GEOM::GEOM_Object::_nil();
205 Standard_Boolean aRes = Standard_False;
206 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( firstIObject(), aRes );
207 if ( !CORBA::is_nil( aSelectedObject ) && aRes )
209 myEditCurrentArgument->setText( GEOMBase::GetName( aSelectedObject ) );
210 if ( myEditCurrentArgument == GroupPoints->LineEdit1 ) myPoint = aSelectedObject;
211 else if ( myEditCurrentArgument == GroupPoints->LineEdit2 ) myDir = aSelectedObject;
218 //=================================================================================
219 // function : SetEditCurrentArgument()
221 //=================================================================================
222 void BasicGUI_EllipseDlg::SetEditCurrentArgument()
224 QPushButton* send = (QPushButton*)sender();
226 if ( send == GroupPoints->PushButton1 ) myEditCurrentArgument = GroupPoints->LineEdit1;
227 else if ( send == GroupPoints->PushButton2 ) myEditCurrentArgument = GroupPoints->LineEdit2;
229 myEditCurrentArgument->setFocus();
230 if ( myEditCurrentArgument == GroupPoints->LineEdit2 )
231 globalSelection( GEOM_LINE );
233 globalSelection( GEOM_POINT );
234 SelectionIntoArgument();
237 //=================================================================================
238 // function : LineEditReturnPressed()
240 //=================================================================================
241 void BasicGUI_EllipseDlg::LineEditReturnPressed()
243 QLineEdit* send = (QLineEdit*)sender();
244 if ( send == GroupPoints->LineEdit1 ||
245 send == GroupPoints->LineEdit2 )
247 myEditCurrentArgument = send;
248 GEOMBase_Skeleton::LineEditReturnPressed();
253 //=================================================================================
254 // function : ActivateThisDialog()
256 //=================================================================================
257 void BasicGUI_EllipseDlg::ActivateThisDialog()
259 GEOMBase_Skeleton::ActivateThisDialog();
260 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
261 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
263 GroupPoints->LineEdit1->setFocus();
264 myEditCurrentArgument = GroupPoints->LineEdit1;
266 GroupPoints->LineEdit1->setText( "" );
267 GroupPoints->LineEdit2->setText( "" );
269 myPoint = myDir = GEOM::GEOM_Object::_nil();
270 globalSelection( GEOM_POINT );
273 //=================================================================================
274 // function : DeactivateActiveDialog()
275 // purpose : public slot to deactivate if active
276 //=================================================================================
277 void BasicGUI_EllipseDlg::DeactivateActiveDialog()
279 // myGeomGUI->SetState( -1 );
280 GEOMBase_Skeleton::DeactivateActiveDialog();
283 //=================================================================================
284 // function : enterEvent()
286 //=================================================================================
287 void BasicGUI_EllipseDlg::enterEvent(QEvent* e)
289 if ( !GroupConstructors->isEnabled() )
290 ActivateThisDialog();
293 //=================================================================================
294 // function : ValueChangedInSpinBox()
296 //=================================================================================
297 void BasicGUI_EllipseDlg::ValueChangedInSpinBox(double newValue)
302 //=================================================================================
303 // function : createOperation
305 //=================================================================================
306 GEOM::GEOM_IOperations_ptr BasicGUI_EllipseDlg::createOperation()
308 return myGeomGUI->GetGeomGen()->GetICurvesOperations( getStudyId() );
311 //=================================================================================
312 // function : isValid
314 //=================================================================================
315 bool BasicGUI_EllipseDlg::isValid( QString& msg )
317 double aMajorR = GroupPoints->SpinBox_DX->GetValue();
318 double aMinorR = GroupPoints->SpinBox_DY->GetValue();
319 if ( aMajorR < aMinorR )
321 msg = tr( "GEOM_ELLIPSE_ERROR_1" );
324 return !myPoint->_is_nil() && !myDir->_is_nil();
327 //=================================================================================
328 // function : execute
330 //=================================================================================
331 bool BasicGUI_EllipseDlg::execute( ObjectList& objects )
333 double aMajorR = GroupPoints->SpinBox_DX->GetValue();
334 double aMinorR = GroupPoints->SpinBox_DY->GetValue();
335 GEOM::GEOM_Object_var anObj = GEOM::GEOM_ICurvesOperations::_narrow( getOperation() )->MakeEllipse( myPoint, myDir, aMajorR, aMinorR );
337 if ( !anObj->_is_nil() )
338 objects.push_back( anObj._retn() );
343 //=================================================================================
344 // function : closeEvent
346 //=================================================================================
347 void BasicGUI_EllipseDlg::closeEvent( QCloseEvent* e )
349 GEOMBase_Skeleton::closeEvent( e );