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"
29 #include "DlgRef_2Sel2Spin.h"
30 #include "DlgRef_SpinBox.h"
32 #include "GeometryGUI.h"
35 #include "SUIT_ResourceMgr.h"
36 #include "SUIT_Session.h"
37 #include "SalomeApp_Application.h"
38 #include "LightApp_SelectionMgr.h"
40 #include "GEOMImpl_Types.hxx"
44 //=================================================================================
45 // class : BasicGUI_EllipseDlg()
46 // purpose : Constructs a BasicGUI_EllipseDlg 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_EllipseDlg::BasicGUI_EllipseDlg(GeometryGUI* theGeometryGUI, QWidget* parent,
52 const char* name, bool modal, Qt::WindowFlags fl)
53 :GEOMBase_Skeleton(theGeometryGUI, parent, name, modal, Qt::WindowTitleHint | Qt::WindowSystemMenuHint)
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 setWindowTitle(tr("GEOM_ELLIPSE_TITLE"));
60 /***************************************************************/
61 GroupConstructors->setTitle(tr("GEOM_ELLIPSE"));
62 RadioButton1->setIcon(image0);
63 RadioButton2->setAttribute( Qt::WA_DeleteOnClose );
64 RadioButton2->close();
65 RadioButton3->setAttribute( Qt::WA_DeleteOnClose );
66 RadioButton3->close();
68 GroupPoints = new DlgRef_2Sel2Spin(this, "GroupPoints");
69 GroupPoints->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
70 GroupPoints->TextLabel1->setText(tr("GEOM_CENTER"));
71 GroupPoints->TextLabel2->setText(tr("GEOM_VECTOR"));
72 GroupPoints->TextLabel3->setText(tr("GEOM_RADIUS_MAJOR"));
73 GroupPoints->TextLabel4->setText(tr("GEOM_RADIUS_MINOR"));
74 GroupPoints->PushButton1->setIcon(image1);
75 GroupPoints->PushButton2->setIcon(image1);
77 GroupPoints->LineEdit1->setReadOnly( true );
78 GroupPoints->LineEdit2->setReadOnly( true );
80 gridLayout1->addWidget(GroupPoints, 2, 0);
81 /***************************************************************/
83 setHelpFileName("ellipse.htm");
89 //=================================================================================
90 // function : ~BasicGUI_EllipseDlg()
91 // purpose : Destroys the object and frees any allocated resources
92 //=================================================================================
93 BasicGUI_EllipseDlg::~BasicGUI_EllipseDlg()
98 //=================================================================================
101 //=================================================================================
102 void BasicGUI_EllipseDlg::Init()
105 myEditCurrentArgument = GroupPoints->LineEdit1;
106 globalSelection( GEOM_POINT );
108 myPoint = myDir = GEOM::GEOM_Object::_nil();
110 // myGeomGUI->SetState( 0 );
112 /* Get setting of step value from file configuration */
113 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
114 double step = resMgr->doubleValue( "Geometry", "SettingsGeomStep", 100);
116 double aMajorR( 200. ), aMinorR( 100. );
118 /* min, max, step and decimals for spin boxes & initial values */
119 GroupPoints->SpinBox_DX->RangeStepAndValidator( 0.001, COORD_MAX, step, 3 );
120 GroupPoints->SpinBox_DY->RangeStepAndValidator( 0.001, COORD_MAX, step, 3 );
121 GroupPoints->SpinBox_DX->SetValue( aMajorR );
122 GroupPoints->SpinBox_DY->SetValue( aMinorR );
124 /* signals and slots connections */
125 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
126 connect(myGeomGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
127 connect(myGeomGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
129 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
130 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
132 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
133 connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
135 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
136 connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
138 connect(GroupPoints->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
139 connect(GroupPoints->SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
141 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_DX, SLOT(SetStep(double)));
142 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_DY, SLOT(SetStep(double)));
144 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
145 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
147 initName( tr( "GEOM_ELLIPSE" ).toStdString().c_str() );
151 //=================================================================================
152 // function : ClickOnOk()
154 //=================================================================================
155 void BasicGUI_EllipseDlg::ClickOnOk()
157 if ( ClickOnApply() )
162 //=================================================================================
163 // function : ClickOnApply()
165 //=================================================================================
166 bool BasicGUI_EllipseDlg::ClickOnApply()
174 myPoint = myDir = GEOM::GEOM_Object::_nil();
175 GroupPoints->LineEdit1->setText( "" );
176 GroupPoints->LineEdit2->setText( "" );
177 myEditCurrentArgument = GroupPoints->LineEdit1;
178 globalSelection( GEOM_POINT );
183 //=======================================================================
184 // function : ClickOnCancel()
186 //=======================================================================
187 void BasicGUI_EllipseDlg::ClickOnCancel()
189 GEOMBase_Skeleton::ClickOnCancel();
192 //=================================================================================
193 // function : SelectionIntoArgument()
194 // purpose : Called when selection as changed or other case
195 //=================================================================================
196 void BasicGUI_EllipseDlg::SelectionIntoArgument()
198 myEditCurrentArgument->setText("");
200 if ( IObjectCount() != 1 )
202 if ( myEditCurrentArgument == GroupPoints->LineEdit1 ) myPoint = GEOM::GEOM_Object::_nil();
203 else if ( myEditCurrentArgument == GroupPoints->LineEdit2 ) myDir = GEOM::GEOM_Object::_nil();
207 Standard_Boolean aRes = Standard_False;
208 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( firstIObject(), aRes );
209 if ( !CORBA::is_nil( aSelectedObject ) && aRes )
211 myEditCurrentArgument->setText( GEOMBase::GetName( aSelectedObject ) );
212 if ( myEditCurrentArgument == GroupPoints->LineEdit1 ) myPoint = aSelectedObject;
213 else if ( myEditCurrentArgument == GroupPoints->LineEdit2 ) myDir = aSelectedObject;
220 //=================================================================================
221 // function : SetEditCurrentArgument()
223 //=================================================================================
224 void BasicGUI_EllipseDlg::SetEditCurrentArgument()
226 QPushButton* send = (QPushButton*)sender();
228 if ( send == GroupPoints->PushButton1 ) myEditCurrentArgument = GroupPoints->LineEdit1;
229 else if ( send == GroupPoints->PushButton2 ) myEditCurrentArgument = GroupPoints->LineEdit2;
231 myEditCurrentArgument->setFocus();
232 if ( myEditCurrentArgument == GroupPoints->LineEdit2 )
233 globalSelection( GEOM_LINE );
235 globalSelection( GEOM_POINT );
236 SelectionIntoArgument();
239 //=================================================================================
240 // function : LineEditReturnPressed()
242 //=================================================================================
243 void BasicGUI_EllipseDlg::LineEditReturnPressed()
245 QLineEdit* send = (QLineEdit*)sender();
246 if ( send == GroupPoints->LineEdit1 ||
247 send == GroupPoints->LineEdit2 )
249 myEditCurrentArgument = send;
250 GEOMBase_Skeleton::LineEditReturnPressed();
255 //=================================================================================
256 // function : ActivateThisDialog()
258 //=================================================================================
259 void BasicGUI_EllipseDlg::ActivateThisDialog()
261 GEOMBase_Skeleton::ActivateThisDialog();
262 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
263 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
265 GroupPoints->LineEdit1->setFocus();
266 myEditCurrentArgument = GroupPoints->LineEdit1;
268 GroupPoints->LineEdit1->setText( "" );
269 GroupPoints->LineEdit2->setText( "" );
271 myPoint = myDir = GEOM::GEOM_Object::_nil();
272 globalSelection( GEOM_POINT );
275 //=================================================================================
276 // function : DeactivateActiveDialog()
277 // purpose : public slot to deactivate if active
278 //=================================================================================
279 void BasicGUI_EllipseDlg::DeactivateActiveDialog()
281 // myGeomGUI->SetState( -1 );
282 GEOMBase_Skeleton::DeactivateActiveDialog();
285 //=================================================================================
286 // function : enterEvent()
288 //=================================================================================
289 void BasicGUI_EllipseDlg::enterEvent(QEvent* e)
291 if ( !GroupConstructors->isEnabled() )
292 ActivateThisDialog();
295 //=================================================================================
296 // function : ValueChangedInSpinBox()
298 //=================================================================================
299 void BasicGUI_EllipseDlg::ValueChangedInSpinBox(double newValue)
304 //=================================================================================
305 // function : createOperation
307 //=================================================================================
308 GEOM::GEOM_IOperations_ptr BasicGUI_EllipseDlg::createOperation()
310 return myGeomGUI->GetGeomGen()->GetICurvesOperations( getStudyId() );
313 //=================================================================================
314 // function : isValid
316 //=================================================================================
317 bool BasicGUI_EllipseDlg::isValid( QString& msg )
319 double aMajorR = GroupPoints->SpinBox_DX->GetValue();
320 double aMinorR = GroupPoints->SpinBox_DY->GetValue();
321 if ( aMajorR < aMinorR )
323 msg = tr( "GEOM_ELLIPSE_ERROR_1" );
326 return !myPoint->_is_nil() && !myDir->_is_nil();
329 //=================================================================================
330 // function : execute
332 //=================================================================================
333 bool BasicGUI_EllipseDlg::execute( ObjectList& objects )
335 double aMajorR = GroupPoints->SpinBox_DX->GetValue();
336 double aMinorR = GroupPoints->SpinBox_DY->GetValue();
337 GEOM::GEOM_Object_var anObj = GEOM::GEOM_ICurvesOperations::_narrow( getOperation() )->MakeEllipse( myPoint, myDir, aMajorR, aMinorR );
339 if ( !anObj->_is_nil() )
340 objects.push_back( anObj._retn() );
345 //=================================================================================
346 // function : closeEvent
348 //=================================================================================
349 void BasicGUI_EllipseDlg::closeEvent( QCloseEvent* e )
351 GEOMBase_Skeleton::closeEvent( e );