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("create_ellipse_page.html");
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(); // close local contexts, if any
112 localSelection(GEOM::GEOM_Object::_nil(), TopAbs_VERTEX);
114 myPoint = myDir = GEOM::GEOM_Object::_nil();
116 /* Get setting of step value from file configuration */
117 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
118 double step = resMgr->doubleValue( "Geometry", "SettingsGeomStep", 100);
120 double aMajorR( 200. ), aMinorR( 100. );
122 /* min, max, step and decimals for spin boxes & initial values */
123 GroupPoints->SpinBox_DX->RangeStepAndValidator( 0.001, COORD_MAX, step, DBL_DIGITS_DISPLAY );
124 GroupPoints->SpinBox_DY->RangeStepAndValidator( 0.001, COORD_MAX, step, DBL_DIGITS_DISPLAY );
125 GroupPoints->SpinBox_DX->SetValue( aMajorR );
126 GroupPoints->SpinBox_DY->SetValue( aMinorR );
128 /* signals and slots connections */
129 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
130 connect(myGeomGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
131 connect(myGeomGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
133 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
134 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
136 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
137 connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
139 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
140 connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
142 connect(GroupPoints->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
143 connect(GroupPoints->SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
145 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)),
146 GroupPoints->SpinBox_DX, SLOT(SetStep(double)));
147 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)),
148 GroupPoints->SpinBox_DY, SLOT(SetStep(double)));
150 connect(myGeomGUI->getApp()->selectionMgr(),
151 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
153 initName( tr( "GEOM_ELLIPSE" ) );
156 //=================================================================================
157 // function : ClickOnOk()
159 //=================================================================================
160 void BasicGUI_EllipseDlg::ClickOnOk()
162 if ( ClickOnApply() )
166 //=================================================================================
167 // function : ClickOnApply()
169 //=================================================================================
170 bool BasicGUI_EllipseDlg::ClickOnApply()
178 myPoint = myDir = GEOM::GEOM_Object::_nil();
179 GroupPoints->LineEdit1->setText( "" );
180 GroupPoints->LineEdit2->setText( "" );
181 myEditCurrentArgument = GroupPoints->LineEdit1;
182 //globalSelection(GEOM_POINT);
183 globalSelection(); // close local contexts, if any
184 localSelection(GEOM::GEOM_Object::_nil(), TopAbs_VERTEX);
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 Handle(SALOME_InteractiveObject) anIO = firstIObject();
215 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject(firstIObject(), aRes);
216 if (!CORBA::is_nil(aSelectedObject) && aRes)
218 QString aName = GEOMBase::GetName(aSelectedObject);
220 // Get Selected object if selected subshape
223 if (GEOMBase::GetShape(aSelectedObject, aShape, TopAbs_SHAPE) && !aShape.IsNull())
225 TopAbs_ShapeEnum aNeedType = TopAbs_VERTEX;
226 if (myEditCurrentArgument == GroupPoints->LineEdit2)
227 aNeedType = TopAbs_EDGE;
229 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
230 TColStd_IndexedMapOfInteger aMap;
231 aSelMgr->GetIndexes(anIO, aMap);
232 if (aMap.Extent() == 1)
234 int anIndex = aMap(1);
235 if (aNeedType == TopAbs_EDGE)
236 aName += QString(":edge_%1").arg(anIndex);
238 aName += QString(":vertex_%1").arg(anIndex);
240 //Find SubShape Object in Father
241 GEOM::GEOM_Object_var aFindedObject = GEOMBase_Helper::findObjectInFather(aSelectedObject, aName);
243 if ( aFindedObject == GEOM::GEOM_Object::_nil() ) { // Object not found in study
244 GEOM::GEOM_IShapesOperations_var aShapesOp = getGeomEngine()->GetIShapesOperations(getStudyId());
245 aSelectedObject = aShapesOp->GetSubShape(aSelectedObject, anIndex);
247 aSelectedObject = aFindedObject; // get Object from study
250 else // Global Selection
252 if (aShape.ShapeType() != aNeedType) {
253 aSelectedObject = GEOM::GEOM_Object::_nil();
259 myEditCurrentArgument->setText(aName);
261 if ( myEditCurrentArgument == GroupPoints->LineEdit1 ) myPoint = aSelectedObject;
262 else if ( myEditCurrentArgument == GroupPoints->LineEdit2 ) myDir = aSelectedObject;
269 //=================================================================================
270 // function : SetEditCurrentArgument()
272 //=================================================================================
273 void BasicGUI_EllipseDlg::SetEditCurrentArgument()
275 QPushButton* send = (QPushButton*)sender();
276 globalSelection( GEOM_POINT );
278 if ( send == GroupPoints->PushButton1 ) myEditCurrentArgument = GroupPoints->LineEdit1;
279 else if ( send == GroupPoints->PushButton2 ) myEditCurrentArgument = GroupPoints->LineEdit2;
281 myEditCurrentArgument->setFocus();
282 globalSelection(); // close local contexts, if any
283 if ( myEditCurrentArgument == GroupPoints->LineEdit2 )
284 localSelection(GEOM::GEOM_Object::_nil(), TopAbs_EDGE);
286 localSelection(GEOM::GEOM_Object::_nil(), TopAbs_VERTEX);
287 SelectionIntoArgument();
290 //=================================================================================
291 // function : LineEditReturnPressed()
293 //=================================================================================
294 void BasicGUI_EllipseDlg::LineEditReturnPressed()
296 QLineEdit* send = (QLineEdit*)sender();
297 if ( send == GroupPoints->LineEdit1 ||
298 send == GroupPoints->LineEdit2 )
300 myEditCurrentArgument = send;
301 GEOMBase_Skeleton::LineEditReturnPressed();
306 //=================================================================================
307 // function : ActivateThisDialog()
309 //=================================================================================
310 void BasicGUI_EllipseDlg::ActivateThisDialog()
312 GEOMBase_Skeleton::ActivateThisDialog();
313 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
314 this, SLOT(SelectionIntoArgument()));
316 GroupPoints->LineEdit1->setFocus();
317 myEditCurrentArgument = GroupPoints->LineEdit1;
319 GroupPoints->LineEdit1->setText( "" );
320 GroupPoints->LineEdit2->setText( "" );
322 myPoint = myDir = GEOM::GEOM_Object::_nil();
323 //globalSelection( GEOM_POINT );
324 globalSelection(); // close local contexts, if any
325 localSelection(GEOM::GEOM_Object::_nil(), TopAbs_VERTEX);
328 //=================================================================================
329 // function : DeactivateActiveDialog()
330 // purpose : public slot to deactivate if active
331 //=================================================================================
332 void BasicGUI_EllipseDlg::DeactivateActiveDialog()
334 // myGeomGUI->SetState( -1 );
335 GEOMBase_Skeleton::DeactivateActiveDialog();
338 //=================================================================================
339 // function : enterEvent()
341 //=================================================================================
342 void BasicGUI_EllipseDlg::enterEvent(QEvent* e)
344 if ( !GroupConstructors->isEnabled() )
345 ActivateThisDialog();
348 //=================================================================================
349 // function : ValueChangedInSpinBox()
351 //=================================================================================
352 void BasicGUI_EllipseDlg::ValueChangedInSpinBox(double newValue)
357 //=================================================================================
358 // function : createOperation
360 //=================================================================================
361 GEOM::GEOM_IOperations_ptr BasicGUI_EllipseDlg::createOperation()
363 return myGeomGUI->GetGeomGen()->GetICurvesOperations( getStudyId() );
366 //=================================================================================
367 // function : isValid
369 //=================================================================================
370 bool BasicGUI_EllipseDlg::isValid( QString& msg )
372 double aMajorR = GroupPoints->SpinBox_DX->GetValue();
373 double aMinorR = GroupPoints->SpinBox_DY->GetValue();
374 if ( aMajorR < aMinorR )
376 msg = tr( "GEOM_ELLIPSE_ERROR_1" );
379 return !myPoint->_is_nil() && !myDir->_is_nil();
382 //=================================================================================
383 // function : execute
385 //=================================================================================
386 bool BasicGUI_EllipseDlg::execute( ObjectList& objects )
388 double aMajorR = GroupPoints->SpinBox_DX->GetValue();
389 double aMinorR = GroupPoints->SpinBox_DY->GetValue();
390 GEOM::GEOM_Object_var anObj = GEOM::GEOM_ICurvesOperations::_narrow( getOperation() )->MakeEllipse( myPoint, myDir, aMajorR, aMinorR );
392 if ( !anObj->_is_nil() )
393 objects.push_back( anObj._retn() );
398 //=================================================================================
399 // function : closeEvent
401 //=================================================================================
402 void BasicGUI_EllipseDlg::closeEvent( QCloseEvent* e )
404 GEOMBase_Skeleton::closeEvent( e );
407 //=================================================================================
408 // function : addSubshapeToStudy
409 // purpose : virtual method to add new SubObjects if local selection
410 //=================================================================================
411 void BasicGUI_EllipseDlg::addSubshapesToStudy()
413 QMap<QString, GEOM::GEOM_Object_var> objMap;
415 objMap[GroupPoints->LineEdit1->text()] = myPoint;
416 objMap[GroupPoints->LineEdit2->text()] = myDir;
418 addSubshapesToFather( objMap );