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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
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 "SalomeApp_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, const char* name, bool modal, WFlags fl)
51 :GEOMBase_Skeleton(parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu), myGeometryGUI(theGeometryGUI)
53 QPixmap image0(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_ELLIPSE_PV")));
54 QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_SELECT")));
56 setCaption(tr("GEOM_ELLIPSE_TITLE"));
58 /***************************************************************/
59 GroupConstructors->setTitle(tr("GEOM_ELLIPSE"));
60 RadioButton1->setPixmap(image0);
61 RadioButton2->close(TRUE);
62 RadioButton3->close(TRUE);
64 GroupPoints = new DlgRef_2Sel2Spin(this, "GroupPoints");
65 GroupPoints->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
66 GroupPoints->TextLabel1->setText(tr("GEOM_CENTER"));
67 GroupPoints->TextLabel2->setText(tr("GEOM_VECTOR"));
68 GroupPoints->TextLabel3->setText(tr("GEOM_RADIUS_MAJOR"));
69 GroupPoints->TextLabel4->setText(tr("GEOM_RADIUS_MINOR"));
70 GroupPoints->PushButton1->setPixmap(image1);
71 GroupPoints->PushButton2->setPixmap(image1);
73 GroupPoints->LineEdit1->setReadOnly( true );
74 GroupPoints->LineEdit2->setReadOnly( true );
76 Layout1->addWidget(GroupPoints, 2, 0);
77 /***************************************************************/
83 //=================================================================================
84 // function : ~BasicGUI_EllipseDlg()
85 // purpose : Destroys the object and frees any allocated resources
86 //=================================================================================
87 BasicGUI_EllipseDlg::~BasicGUI_EllipseDlg()
92 //=================================================================================
95 //=================================================================================
96 void BasicGUI_EllipseDlg::Init()
99 myEditCurrentArgument = GroupPoints->LineEdit1;
100 globalSelection( GEOM_POINT );
102 myPoint = myDir = GEOM::GEOM_Object::_nil();
104 // myGeometryGUI->SetState( 0 );
106 /* Get setting of step value from file configuration */
107 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
108 double step = resMgr->doubleValue( "Geometry", "SettingsGeomStep", 100);
110 double aMajorR( 200. ), aMinorR( 100. );
112 /* min, max, step and decimals for spin boxes & initial values */
113 GroupPoints->SpinBox_DX->RangeStepAndValidator( 0.001, 999.999, step, 3 );
114 GroupPoints->SpinBox_DY->RangeStepAndValidator( 0.001, 999.999, step, 3 );
115 GroupPoints->SpinBox_DX->SetValue( aMajorR );
116 GroupPoints->SpinBox_DY->SetValue( aMinorR );
118 /* signals and slots connections */
119 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
120 connect(myGeometryGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
121 connect(myGeometryGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
123 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
124 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
126 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
127 connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
129 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
130 connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
132 connect(GroupPoints->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
133 connect(GroupPoints->SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
135 connect(myGeometryGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_DX, SLOT(SetStep(double)));
136 connect(myGeometryGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_DY, SLOT(SetStep(double)));
138 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
139 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
141 initName( tr( "GEOM_ELLIPSE" ) );
145 //=================================================================================
146 // function : ClickOnOk()
148 //=================================================================================
149 void BasicGUI_EllipseDlg::ClickOnOk()
151 if ( ClickOnApply() )
156 //=================================================================================
157 // function : ClickOnApply()
159 //=================================================================================
160 bool BasicGUI_EllipseDlg::ClickOnApply()
168 myPoint = myDir = GEOM::GEOM_Object::_nil();
169 GroupPoints->LineEdit1->setText( "" );
170 GroupPoints->LineEdit2->setText( "" );
171 myEditCurrentArgument = GroupPoints->LineEdit1;
172 globalSelection( GEOM_POINT );
177 //=======================================================================
178 // function : ClickOnCancel()
180 //=======================================================================
181 void BasicGUI_EllipseDlg::ClickOnCancel()
183 GEOMBase_Skeleton::ClickOnCancel();
186 //=================================================================================
187 // function : SelectionIntoArgument()
188 // purpose : Called when selection as changed or other case
189 //=================================================================================
190 void BasicGUI_EllipseDlg::SelectionIntoArgument()
192 myEditCurrentArgument->setText("");
194 if ( IObjectCount() != 1 )
196 if ( myEditCurrentArgument == GroupPoints->LineEdit1 ) myPoint = GEOM::GEOM_Object::_nil();
197 else if ( myEditCurrentArgument == GroupPoints->LineEdit2 ) myDir = GEOM::GEOM_Object::_nil();
201 Standard_Boolean aRes = Standard_False;
202 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( firstIObject(), aRes );
203 if ( !CORBA::is_nil( aSelectedObject ) && aRes )
205 myEditCurrentArgument->setText( GEOMBase::GetName( aSelectedObject ) );
206 if ( myEditCurrentArgument == GroupPoints->LineEdit1 ) myPoint = aSelectedObject;
207 else if ( myEditCurrentArgument == GroupPoints->LineEdit2 ) myDir = aSelectedObject;
214 //=================================================================================
215 // function : SetEditCurrentArgument()
217 //=================================================================================
218 void BasicGUI_EllipseDlg::SetEditCurrentArgument()
220 QPushButton* send = (QPushButton*)sender();
222 if ( send == GroupPoints->PushButton1 ) myEditCurrentArgument = GroupPoints->LineEdit1;
223 else if ( send == GroupPoints->PushButton2 ) myEditCurrentArgument = GroupPoints->LineEdit2;
225 myEditCurrentArgument->setFocus();
226 if ( myEditCurrentArgument == GroupPoints->LineEdit2 )
227 globalSelection( GEOM_LINE );
229 globalSelection( GEOM_POINT );
230 SelectionIntoArgument();
233 //=================================================================================
234 // function : LineEditReturnPressed()
236 //=================================================================================
237 void BasicGUI_EllipseDlg::LineEditReturnPressed()
239 QLineEdit* send = (QLineEdit*)sender();
240 if ( send == GroupPoints->LineEdit1 ||
241 send == GroupPoints->LineEdit2 )
243 myEditCurrentArgument = send;
244 GEOMBase_Skeleton::LineEditReturnPressed();
249 //=================================================================================
250 // function : ActivateThisDialog()
252 //=================================================================================
253 void BasicGUI_EllipseDlg::ActivateThisDialog()
255 GEOMBase_Skeleton::ActivateThisDialog();
256 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
257 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
259 GroupPoints->LineEdit1->setFocus();
260 myEditCurrentArgument = GroupPoints->LineEdit1;
262 GroupPoints->LineEdit1->setText( "" );
263 GroupPoints->LineEdit2->setText( "" );
265 myPoint = myDir = GEOM::GEOM_Object::_nil();
266 globalSelection( GEOM_POINT );
269 //=================================================================================
270 // function : DeactivateActiveDialog()
271 // purpose : public slot to deactivate if active
272 //=================================================================================
273 void BasicGUI_EllipseDlg::DeactivateActiveDialog()
275 // myGeometryGUI->SetState( -1 );
276 GEOMBase_Skeleton::DeactivateActiveDialog();
279 //=================================================================================
280 // function : enterEvent()
282 //=================================================================================
283 void BasicGUI_EllipseDlg::enterEvent(QEvent* e)
285 if ( !GroupConstructors->isEnabled() )
286 ActivateThisDialog();
289 //=================================================================================
290 // function : ValueChangedInSpinBox()
292 //=================================================================================
293 void BasicGUI_EllipseDlg::ValueChangedInSpinBox(double newValue)
298 //=================================================================================
299 // function : createOperation
301 //=================================================================================
302 GEOM::GEOM_IOperations_ptr BasicGUI_EllipseDlg::createOperation()
304 return myGeometryGUI->GetGeomGen()->GetICurvesOperations( getStudyId() );
307 //=================================================================================
308 // function : isValid
310 //=================================================================================
311 bool BasicGUI_EllipseDlg::isValid( QString& msg )
313 double aMajorR = GroupPoints->SpinBox_DX->GetValue();
314 double aMinorR = GroupPoints->SpinBox_DY->GetValue();
315 if ( aMajorR < aMinorR )
317 msg = tr( "GEOM_ELLIPSE_ERROR_1" );
320 return !myPoint->_is_nil() && !myDir->_is_nil();
323 //=================================================================================
324 // function : execute
326 //=================================================================================
327 bool BasicGUI_EllipseDlg::execute( ObjectList& objects )
329 double aMajorR = GroupPoints->SpinBox_DX->GetValue();
330 double aMinorR = GroupPoints->SpinBox_DY->GetValue();
331 GEOM::GEOM_Object_var anObj = GEOM::GEOM_ICurvesOperations::_narrow( getOperation() )->MakeEllipse( myPoint, myDir, aMajorR, aMinorR );
333 if ( !anObj->_is_nil() )
334 objects.push_back( anObj._retn() );
339 //=================================================================================
340 // function : closeEvent
342 //=================================================================================
343 void BasicGUI_EllipseDlg::closeEvent( QCloseEvent* e )
345 // myGeometryGUI->SetState( -1 );
346 GEOMBase_Skeleton::closeEvent( e );