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"
35 #include <TColStd_IndexedMapOfInteger.hxx>
36 #include <TopTools_IndexedMapOfShape.hxx>
37 #include <TopoDS_Shape.hxx>
38 #include <TopoDS_Edge.hxx>
44 #include "GEOMImpl_Types.hxx"
46 #include "utilities.h"
50 //=================================================================================
51 // class : BasicGUI_EllipseDlg()
52 // purpose : Constructs a BasicGUI_EllipseDlg which is a child of 'parent', with the
53 // name 'name' and widget flags set to 'f'.
54 // The dialog will by default be modeless, unless you set 'modal' to
55 // TRUE to construct a modal dialog.
56 //=================================================================================
57 BasicGUI_EllipseDlg::BasicGUI_EllipseDlg(GeometryGUI* theGeometryGUI, QWidget* parent,
58 const char* name, bool modal, WFlags fl)
59 :GEOMBase_Skeleton(theGeometryGUI, parent, name, modal, WStyle_Customize |
60 WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
62 QPixmap image0(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_ELLIPSE_PV")));
63 QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_SELECT")));
65 setCaption(tr("GEOM_ELLIPSE_TITLE"));
67 /***************************************************************/
68 GroupConstructors->setTitle(tr("GEOM_ELLIPSE"));
69 RadioButton1->setPixmap(image0);
70 RadioButton2->close(TRUE);
71 RadioButton3->close(TRUE);
73 GroupPoints = new DlgRef_2Sel2Spin(this, "GroupPoints");
74 GroupPoints->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
75 GroupPoints->TextLabel1->setText(tr("GEOM_CENTER"));
76 GroupPoints->TextLabel2->setText(tr("GEOM_VECTOR"));
77 GroupPoints->TextLabel3->setText(tr("GEOM_RADIUS_MAJOR"));
78 GroupPoints->TextLabel4->setText(tr("GEOM_RADIUS_MINOR"));
79 GroupPoints->PushButton1->setPixmap(image1);
80 GroupPoints->PushButton2->setPixmap(image1);
82 GroupPoints->LineEdit1->setReadOnly( true );
83 GroupPoints->LineEdit2->setReadOnly( true );
85 Layout1->addWidget(GroupPoints, 2, 0);
86 /***************************************************************/
88 setHelpFileName("ellipse.htm");
94 //=================================================================================
95 // function : ~BasicGUI_EllipseDlg()
96 // purpose : Destroys the object and frees any allocated resources
97 //=================================================================================
98 BasicGUI_EllipseDlg::~BasicGUI_EllipseDlg()
103 //=================================================================================
106 //=================================================================================
107 void BasicGUI_EllipseDlg::Init()
110 myEditCurrentArgument = GroupPoints->LineEdit1;
111 // globalSelection( GEOM_POINT );
112 localSelection(GEOM::GEOM_Object::_nil(), TopAbs_VERTEX); //Select Vertex on All Shapes
114 myPoint = myDir = GEOM::GEOM_Object::_nil();
116 // myGeomGUI->SetState( 0 );
118 /* Get setting of step value from file configuration */
119 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
120 double step = resMgr->doubleValue( "Geometry", "SettingsGeomStep", 100);
122 double aMajorR( 200. ), aMinorR( 100. );
124 /* min, max, step and decimals for spin boxes & initial values */
125 GroupPoints->SpinBox_DX->RangeStepAndValidator( 0.001, COORD_MAX, step, DBL_DIGITS_DISPLAY );
126 GroupPoints->SpinBox_DY->RangeStepAndValidator( 0.001, COORD_MAX, step, DBL_DIGITS_DISPLAY );
127 GroupPoints->SpinBox_DX->SetValue( aMajorR );
128 GroupPoints->SpinBox_DY->SetValue( aMinorR );
130 /* signals and slots connections */
131 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
132 connect(myGeomGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
133 connect(myGeomGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
135 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
136 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
138 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
139 connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
141 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
142 connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
144 connect(GroupPoints->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
145 connect(GroupPoints->SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
147 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_DX, SLOT(SetStep(double)));
148 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_DY, SLOT(SetStep(double)));
150 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
151 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
153 initName( tr( "GEOM_ELLIPSE" ) );
157 //=================================================================================
158 // function : ClickOnOk()
160 //=================================================================================
161 void BasicGUI_EllipseDlg::ClickOnOk()
163 if ( ClickOnApply() )
168 //=================================================================================
169 // function : ClickOnApply()
171 //=================================================================================
172 bool BasicGUI_EllipseDlg::ClickOnApply()
180 myPoint = myDir = GEOM::GEOM_Object::_nil();
181 GroupPoints->LineEdit1->setText( "" );
182 GroupPoints->LineEdit2->setText( "" );
183 myEditCurrentArgument = GroupPoints->LineEdit1;
184 globalSelection( GEOM_POINT );
189 //=======================================================================
190 // function : ClickOnCancel()
192 //=======================================================================
193 void BasicGUI_EllipseDlg::ClickOnCancel()
195 GEOMBase_Skeleton::ClickOnCancel();
198 //=================================================================================
199 // function : SelectionIntoArgument()
200 // purpose : Called when selection as changed or other case
201 //=================================================================================
202 void BasicGUI_EllipseDlg::SelectionIntoArgument()
204 myEditCurrentArgument->setText("");
206 if ( IObjectCount() != 1 )
208 if ( myEditCurrentArgument == GroupPoints->LineEdit1 ) myPoint = GEOM::GEOM_Object::_nil();
209 else if ( myEditCurrentArgument == GroupPoints->LineEdit2 ) myDir = GEOM::GEOM_Object::_nil();
213 Standard_Boolean aRes = Standard_False;
214 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( firstIObject(), aRes );
215 if ( !CORBA::is_nil( aSelectedObject ) && aRes )
217 myEditCurrentArgument->setText( GEOMBase::GetName( aSelectedObject ) );
218 // Get Selected object if selected subshape
220 if ( GEOMBase::GetShape( aSelectedObject, aShape, TopAbs_SHAPE ) && !aShape.IsNull() )
222 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
223 TColStd_IndexedMapOfInteger aMap;
224 aSelMgr->GetIndexes( firstIObject(), aMap );
225 if ( aMap.Extent() == 1 )
227 GEOM::GEOM_IShapesOperations_var aShapesOp =
228 getGeomEngine()->GetIShapesOperations( getStudyId() );
229 int anIndex = aMap( 1 );
230 TopTools_IndexedMapOfShape aShapes;
231 TopExp::MapShapes( aShape, aShapes );
232 aShape = aShapes.FindKey( anIndex );
233 aSelectedObject = aShapesOp->GetSubShape(aSelectedObject, anIndex);
234 aSelMgr->clearSelected();
237 if ( myEditCurrentArgument == GroupPoints->LineEdit1 ) myPoint = aSelectedObject;
238 else if ( myEditCurrentArgument == GroupPoints->LineEdit2 ) myDir = aSelectedObject;
245 //=================================================================================
246 // function : SetEditCurrentArgument()
248 //=================================================================================
249 void BasicGUI_EllipseDlg::SetEditCurrentArgument()
251 QPushButton* send = (QPushButton*)sender();
253 if ( send == GroupPoints->PushButton1 ) myEditCurrentArgument = GroupPoints->LineEdit1;
254 else if ( send == GroupPoints->PushButton2 ) myEditCurrentArgument = GroupPoints->LineEdit2;
256 myEditCurrentArgument->setFocus();
257 if ( myEditCurrentArgument == GroupPoints->LineEdit2 )
258 localSelection(GEOM::GEOM_Object::_nil(), TopAbs_EDGE);
260 localSelection(GEOM::GEOM_Object::_nil(), TopAbs_VERTEX);
261 SelectionIntoArgument();
264 //=================================================================================
265 // function : LineEditReturnPressed()
267 //=================================================================================
268 void BasicGUI_EllipseDlg::LineEditReturnPressed()
270 QLineEdit* send = (QLineEdit*)sender();
271 if ( send == GroupPoints->LineEdit1 ||
272 send == GroupPoints->LineEdit2 )
274 myEditCurrentArgument = send;
275 GEOMBase_Skeleton::LineEditReturnPressed();
280 //=================================================================================
281 // function : ActivateThisDialog()
283 //=================================================================================
284 void BasicGUI_EllipseDlg::ActivateThisDialog()
286 GEOMBase_Skeleton::ActivateThisDialog();
287 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
288 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
290 GroupPoints->LineEdit1->setFocus();
291 myEditCurrentArgument = GroupPoints->LineEdit1;
293 GroupPoints->LineEdit1->setText( "" );
294 GroupPoints->LineEdit2->setText( "" );
296 myPoint = myDir = GEOM::GEOM_Object::_nil();
297 globalSelection( GEOM_POINT );
300 //=================================================================================
301 // function : DeactivateActiveDialog()
302 // purpose : public slot to deactivate if active
303 //=================================================================================
304 void BasicGUI_EllipseDlg::DeactivateActiveDialog()
306 // myGeomGUI->SetState( -1 );
307 GEOMBase_Skeleton::DeactivateActiveDialog();
310 //=================================================================================
311 // function : enterEvent()
313 //=================================================================================
314 void BasicGUI_EllipseDlg::enterEvent(QEvent* e)
316 if ( !GroupConstructors->isEnabled() )
317 ActivateThisDialog();
320 //=================================================================================
321 // function : ValueChangedInSpinBox()
323 //=================================================================================
324 void BasicGUI_EllipseDlg::ValueChangedInSpinBox(double newValue)
329 //=================================================================================
330 // function : createOperation
332 //=================================================================================
333 GEOM::GEOM_IOperations_ptr BasicGUI_EllipseDlg::createOperation()
335 return myGeomGUI->GetGeomGen()->GetICurvesOperations( getStudyId() );
338 //=================================================================================
339 // function : isValid
341 //=================================================================================
342 bool BasicGUI_EllipseDlg::isValid( QString& msg )
344 double aMajorR = GroupPoints->SpinBox_DX->GetValue();
345 double aMinorR = GroupPoints->SpinBox_DY->GetValue();
346 if ( aMajorR < aMinorR )
348 msg = tr( "GEOM_ELLIPSE_ERROR_1" );
351 return !myPoint->_is_nil() && !myDir->_is_nil();
354 //=================================================================================
355 // function : execute
357 //=================================================================================
358 bool BasicGUI_EllipseDlg::execute( ObjectList& objects )
360 double aMajorR = GroupPoints->SpinBox_DX->GetValue();
361 double aMinorR = GroupPoints->SpinBox_DY->GetValue();
362 GEOM::GEOM_Object_var anObj = GEOM::GEOM_ICurvesOperations::_narrow( getOperation() )->MakeEllipse( myPoint, myDir, aMajorR, aMinorR );
364 if ( !anObj->_is_nil() )
365 objects.push_back( anObj._retn() );
370 //=================================================================================
371 // function : closeEvent
373 //=================================================================================
374 void BasicGUI_EllipseDlg::closeEvent( QCloseEvent* e )
376 GEOMBase_Skeleton::closeEvent( e );