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"
29 #include "QAD_Desktop.h"
30 #include "QAD_Config.h"
32 #include "GEOMImpl_Types.hxx"
34 #include "utilities.h"
38 //=================================================================================
39 // class : BasicGUI_EllipseDlg()
40 // purpose : Constructs a BasicGUI_EllipseDlg 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_EllipseDlg::BasicGUI_EllipseDlg(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_ELLIPSE_PV")));
49 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_SELECT")));
51 setCaption(tr("GEOM_ELLIPSE_TITLE"));
53 /***************************************************************/
54 GroupConstructors->setTitle(tr("GEOM_ELLIPSE"));
55 RadioButton1->setPixmap(image0);
56 RadioButton2->close(TRUE);
57 RadioButton3->close(TRUE);
59 GroupPoints = new DlgRef_2Sel2Spin(this, "GroupPoints");
60 GroupPoints->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
61 GroupPoints->TextLabel1->setText(tr("GEOM_CENTER"));
62 GroupPoints->TextLabel2->setText(tr("GEOM_VECTOR"));
63 GroupPoints->TextLabel3->setText(tr("GEOM_RADIUS_MAJOR"));
64 GroupPoints->TextLabel4->setText(tr("GEOM_RADIUS_MINOR"));
65 GroupPoints->PushButton1->setPixmap(image1);
66 GroupPoints->PushButton2->setPixmap(image1);
68 GroupPoints->LineEdit1->setReadOnly( true );
69 GroupPoints->LineEdit2->setReadOnly( true );
71 Layout1->addWidget(GroupPoints, 2, 0);
72 /***************************************************************/
78 //=================================================================================
79 // function : ~BasicGUI_EllipseDlg()
80 // purpose : Destroys the object and frees any allocated resources
81 //=================================================================================
82 BasicGUI_EllipseDlg::~BasicGUI_EllipseDlg()
87 //=================================================================================
90 //=================================================================================
91 void BasicGUI_EllipseDlg::Init()
94 myEditCurrentArgument = GroupPoints->LineEdit1;
95 globalSelection( GEOM_POINT );
97 myPoint = myDir = GEOM::GEOM_Object::_nil();
99 myGeomGUI->SetState( 0 );
101 /* Get setting of step value from file configuration */
102 QString St = QAD_CONFIG->getSetting("Geometry:SettingsGeomStep");
103 double step = St.toDouble();
104 double aMajorR( 200. ), aMinorR( 100. );
106 /* min, max, step and decimals for spin boxes & initial values */
107 GroupPoints->SpinBox_DX->RangeStepAndValidator( 0.001, 999.999, step, 3 );
108 GroupPoints->SpinBox_DY->RangeStepAndValidator( 0.001, 999.999, step, 3 );
109 GroupPoints->SpinBox_DX->SetValue( aMajorR );
110 GroupPoints->SpinBox_DY->SetValue( aMinorR );
112 /* signals and slots connections */
113 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
114 connect(myGeomGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
115 connect(myGeomGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
117 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
118 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
120 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
121 connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
123 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
124 connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
126 connect(GroupPoints->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
127 connect(GroupPoints->SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
129 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_DX, SLOT(SetStep(double)));
130 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_DY, SLOT(SetStep(double)));
132 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
134 initName( tr( "GEOM_ELLIPSE" ) );
138 //=================================================================================
139 // function : ClickOnOk()
141 //=================================================================================
142 void BasicGUI_EllipseDlg::ClickOnOk()
144 if ( ClickOnApply() )
149 //=================================================================================
150 // function : ClickOnApply()
152 //=================================================================================
153 bool BasicGUI_EllipseDlg::ClickOnApply()
161 myPoint = myDir = GEOM::GEOM_Object::_nil();
162 GroupPoints->LineEdit1->setText( "" );
163 GroupPoints->LineEdit2->setText( "" );
164 myEditCurrentArgument = GroupPoints->LineEdit1;
165 globalSelection( GEOM_POINT );
170 //=======================================================================
171 // function : ClickOnCancel()
173 //=======================================================================
174 void BasicGUI_EllipseDlg::ClickOnCancel()
176 GEOMBase_Skeleton::ClickOnCancel();
179 //=================================================================================
180 // function : SelectionIntoArgument()
181 // purpose : Called when selection as changed or other case
182 //=================================================================================
183 void BasicGUI_EllipseDlg::SelectionIntoArgument()
185 myEditCurrentArgument->setText("");
187 if ( mySelection->IObjectCount() != 1 )
189 if ( myEditCurrentArgument == GroupPoints->LineEdit1 ) myPoint = GEOM::GEOM_Object::_nil();
190 else if ( myEditCurrentArgument == GroupPoints->LineEdit2 ) myDir = GEOM::GEOM_Object::_nil();
194 Standard_Boolean aRes = Standard_False;
195 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( mySelection->firstIObject(), aRes );
196 if ( !CORBA::is_nil( aSelectedObject ) && aRes )
198 myEditCurrentArgument->setText( GEOMBase::GetName( aSelectedObject ) );
199 if ( myEditCurrentArgument == GroupPoints->LineEdit1 ) myPoint = aSelectedObject;
200 else if ( myEditCurrentArgument == GroupPoints->LineEdit2 ) myDir = aSelectedObject;
207 //=================================================================================
208 // function : SetEditCurrentArgument()
210 //=================================================================================
211 void BasicGUI_EllipseDlg::SetEditCurrentArgument()
213 QPushButton* send = (QPushButton*)sender();
215 if ( send == GroupPoints->PushButton1 ) myEditCurrentArgument = GroupPoints->LineEdit1;
216 else if ( send == GroupPoints->PushButton2 ) myEditCurrentArgument = GroupPoints->LineEdit2;
218 myEditCurrentArgument->setFocus();
219 if ( myEditCurrentArgument == GroupPoints->LineEdit2 )
220 globalSelection( GEOM_LINE );
222 globalSelection( GEOM_POINT );
223 SelectionIntoArgument();
226 //=================================================================================
227 // function : LineEditReturnPressed()
229 //=================================================================================
230 void BasicGUI_EllipseDlg::LineEditReturnPressed()
232 QLineEdit* send = (QLineEdit*)sender();
233 if ( send == GroupPoints->LineEdit1 ||
234 send == GroupPoints->LineEdit2 )
236 myEditCurrentArgument = send;
237 GEOMBase_Skeleton::LineEditReturnPressed();
242 //=================================================================================
243 // function : ActivateThisDialog()
245 //=================================================================================
246 void BasicGUI_EllipseDlg::ActivateThisDialog()
248 GEOMBase_Skeleton::ActivateThisDialog();
249 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
251 GroupPoints->LineEdit1->setFocus();
252 myEditCurrentArgument = GroupPoints->LineEdit1;
254 GroupPoints->LineEdit1->setText( "" );
255 GroupPoints->LineEdit2->setText( "" );
257 myPoint = myDir = GEOM::GEOM_Object::_nil();
258 globalSelection( GEOM_POINT );
261 //=================================================================================
262 // function : DeactivateActiveDialog()
263 // purpose : public slot to deactivate if active
264 //=================================================================================
265 void BasicGUI_EllipseDlg::DeactivateActiveDialog()
267 myGeomGUI->SetState( -1 );
268 GEOMBase_Skeleton::DeactivateActiveDialog();
271 //=================================================================================
272 // function : enterEvent()
274 //=================================================================================
275 void BasicGUI_EllipseDlg::enterEvent(QEvent* e)
277 if ( !GroupConstructors->isEnabled() )
278 ActivateThisDialog();
281 //=================================================================================
282 // function : ValueChangedInSpinBox()
284 //=================================================================================
285 void BasicGUI_EllipseDlg::ValueChangedInSpinBox(double newValue)
290 //=================================================================================
291 // function : createOperation
293 //=================================================================================
294 GEOM::GEOM_IOperations_ptr BasicGUI_EllipseDlg::createOperation()
296 return getGeomEngine()->GetICurvesOperations( getStudyId() );
299 //=================================================================================
300 // function : isValid
302 //=================================================================================
303 bool BasicGUI_EllipseDlg::isValid( QString& msg )
305 double aMajorR = GroupPoints->SpinBox_DX->GetValue();
306 double aMinorR = GroupPoints->SpinBox_DY->GetValue();
307 if ( aMajorR < aMinorR )
309 msg = tr( "GEOM_ELLIPSE_ERROR_1" );
312 return !myPoint->_is_nil() && !myDir->_is_nil();
315 //=================================================================================
316 // function : execute
318 //=================================================================================
319 bool BasicGUI_EllipseDlg::execute( ObjectList& objects )
321 double aMajorR = GroupPoints->SpinBox_DX->GetValue();
322 double aMinorR = GroupPoints->SpinBox_DY->GetValue();
323 GEOM::GEOM_Object_var anObj = GEOM::GEOM_ICurvesOperations::_narrow( getOperation() )->MakeEllipse( myPoint, myDir, aMajorR, aMinorR );
325 if ( !anObj->_is_nil() )
326 objects.push_back( anObj._retn() );
331 //=================================================================================
332 // function : closeEvent
334 //=================================================================================
335 void BasicGUI_EllipseDlg::closeEvent( QCloseEvent* e )
337 myGeomGUI->SetState( -1 );
338 GEOMBase_Skeleton::closeEvent( e );