1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // GEOM GEOMGUI : GUI for Geometry component
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_3Sel2Spin(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("%1 (%2)").arg(tr("GEOM_VECTOR_MAJOR")).arg(tr("GEOM_OPTIONAL")));
78 GroupPoints->TextLabel4->setText(tr("GEOM_RADIUS_MAJOR"));
79 GroupPoints->TextLabel5->setText(tr("GEOM_RADIUS_MINOR"));
80 GroupPoints->PushButton1->setPixmap(image1);
81 GroupPoints->PushButton2->setPixmap(image1);
82 GroupPoints->PushButton3->setPixmap(image1);
84 GroupPoints->LineEdit1->setReadOnly( true );
85 GroupPoints->LineEdit2->setReadOnly( true );
86 GroupPoints->LineEdit3->setReadOnly( true );
88 Layout1->addWidget(GroupPoints, 2, 0);
89 /***************************************************************/
91 setHelpFileName("create_ellipse_page.html");
97 //=================================================================================
98 // function : ~BasicGUI_EllipseDlg()
99 // purpose : Destroys the object and frees any allocated resources
100 //=================================================================================
101 BasicGUI_EllipseDlg::~BasicGUI_EllipseDlg()
106 //=================================================================================
109 //=================================================================================
110 void BasicGUI_EllipseDlg::Init()
113 myEditCurrentArgument = GroupPoints->LineEdit1;
114 globalSelection(); // close local contexts, if any
115 localSelection(GEOM::GEOM_Object::_nil(), TopAbs_VERTEX);
117 myPoint = myDir = myMajor = GEOM::GEOM_Object::_nil();
119 /* Get setting of step value from file configuration */
120 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
121 double step = resMgr->doubleValue( "Geometry", "SettingsGeomStep", 100);
123 double aMajorR( 200. ), aMinorR( 100. );
125 /* min, max, step and decimals for spin boxes & initial values */
126 GroupPoints->SpinBox_DX->RangeStepAndValidator( 0.001, COORD_MAX, step, DBL_DIGITS_DISPLAY );
127 GroupPoints->SpinBox_DY->RangeStepAndValidator( 0.001, COORD_MAX, step, DBL_DIGITS_DISPLAY );
128 GroupPoints->SpinBox_DX->SetValue( aMajorR );
129 GroupPoints->SpinBox_DY->SetValue( aMinorR );
131 /* signals and slots connections */
132 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
133 connect(myGeomGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
134 connect(myGeomGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
136 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
137 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
139 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
140 connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
141 connect(GroupPoints->PushButton3, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
143 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
144 connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
145 connect(GroupPoints->LineEdit3, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
147 connect(GroupPoints->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
148 connect(GroupPoints->SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
150 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)),
151 GroupPoints->SpinBox_DX, SLOT(SetStep(double)));
152 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)),
153 GroupPoints->SpinBox_DY, SLOT(SetStep(double)));
155 connect(myGeomGUI->getApp()->selectionMgr(),
156 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
158 initName( tr( "GEOM_ELLIPSE" ) );
161 //=================================================================================
162 // function : ClickOnOk()
164 //=================================================================================
165 void BasicGUI_EllipseDlg::ClickOnOk()
167 if ( ClickOnApply() )
171 //=================================================================================
172 // function : ClickOnApply()
174 //=================================================================================
175 bool BasicGUI_EllipseDlg::ClickOnApply()
183 myPoint = myDir = myMajor = GEOM::GEOM_Object::_nil();
184 GroupPoints->LineEdit1->setText( "" );
185 GroupPoints->LineEdit2->setText( "" );
186 GroupPoints->LineEdit3->setText( "" );
187 myEditCurrentArgument = GroupPoints->LineEdit1;
188 //globalSelection(GEOM_POINT);
189 globalSelection(); // close local contexts, if any
190 localSelection(GEOM::GEOM_Object::_nil(), TopAbs_VERTEX);
195 //=======================================================================
196 // function : ClickOnCancel()
198 //=======================================================================
199 void BasicGUI_EllipseDlg::ClickOnCancel()
201 GEOMBase_Skeleton::ClickOnCancel();
204 //=================================================================================
205 // function : SelectionIntoArgument()
206 // purpose : Called when selection as changed or other case
207 //=================================================================================
208 void BasicGUI_EllipseDlg::SelectionIntoArgument()
210 myEditCurrentArgument->setText("");
212 if ( IObjectCount() != 1 )
214 if ( myEditCurrentArgument == GroupPoints->LineEdit1 ) myPoint = GEOM::GEOM_Object::_nil();
215 else if ( myEditCurrentArgument == GroupPoints->LineEdit2 ) myDir = GEOM::GEOM_Object::_nil();
216 else if ( myEditCurrentArgument == GroupPoints->LineEdit3 ) myMajor = GEOM::GEOM_Object::_nil();
220 Standard_Boolean aRes = Standard_False;
221 Handle(SALOME_InteractiveObject) anIO = firstIObject();
222 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject(firstIObject(), aRes);
223 if (!CORBA::is_nil(aSelectedObject) && aRes)
225 QString aName = GEOMBase::GetName(aSelectedObject);
227 // Get Selected object if selected subshape
230 if (GEOMBase::GetShape(aSelectedObject, aShape, TopAbs_SHAPE) && !aShape.IsNull())
232 TopAbs_ShapeEnum aNeedType = TopAbs_VERTEX;
233 if (myEditCurrentArgument == GroupPoints->LineEdit2 || myEditCurrentArgument == GroupPoints->LineEdit3)
234 aNeedType = TopAbs_EDGE;
236 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
237 TColStd_IndexedMapOfInteger aMap;
238 aSelMgr->GetIndexes(anIO, aMap);
239 if (aMap.Extent() == 1)
241 int anIndex = aMap(1);
242 if (aNeedType == TopAbs_EDGE)
243 aName += QString(":edge_%1").arg(anIndex);
245 aName += QString(":vertex_%1").arg(anIndex);
247 //Find SubShape Object in Father
248 GEOM::GEOM_Object_var aFindedObject = GEOMBase_Helper::findObjectInFather(aSelectedObject, aName);
250 if ( aFindedObject == GEOM::GEOM_Object::_nil() ) { // Object not found in study
251 GEOM::GEOM_IShapesOperations_var aShapesOp = getGeomEngine()->GetIShapesOperations(getStudyId());
252 aSelectedObject = aShapesOp->GetSubShape(aSelectedObject, anIndex);
254 aSelectedObject = aFindedObject; // get Object from study
257 else // Global Selection
259 if (aShape.ShapeType() != aNeedType) {
260 aSelectedObject = GEOM::GEOM_Object::_nil();
266 myEditCurrentArgument->setText(aName);
268 if ( myEditCurrentArgument == GroupPoints->LineEdit1 ) myPoint = aSelectedObject;
269 else if ( myEditCurrentArgument == GroupPoints->LineEdit2 ) myDir = aSelectedObject;
270 else if ( myEditCurrentArgument == GroupPoints->LineEdit3 ) myMajor = aSelectedObject;
277 //=================================================================================
278 // function : SetEditCurrentArgument()
280 //=================================================================================
281 void BasicGUI_EllipseDlg::SetEditCurrentArgument()
283 QPushButton* send = (QPushButton*)sender();
284 globalSelection( GEOM_POINT );
286 if ( send == GroupPoints->PushButton1 ) myEditCurrentArgument = GroupPoints->LineEdit1;
287 else if ( send == GroupPoints->PushButton2 ) myEditCurrentArgument = GroupPoints->LineEdit2;
288 else if ( send == GroupPoints->PushButton3 ) myEditCurrentArgument = GroupPoints->LineEdit3;
290 myEditCurrentArgument->setFocus();
291 globalSelection(); // close local contexts, if any
292 if ( myEditCurrentArgument == GroupPoints->LineEdit2 || myEditCurrentArgument == GroupPoints->LineEdit3 )
293 localSelection(GEOM::GEOM_Object::_nil(), TopAbs_EDGE);
295 localSelection(GEOM::GEOM_Object::_nil(), TopAbs_VERTEX);
296 SelectionIntoArgument();
299 //=================================================================================
300 // function : LineEditReturnPressed()
302 //=================================================================================
303 void BasicGUI_EllipseDlg::LineEditReturnPressed()
305 QLineEdit* send = (QLineEdit*)sender();
306 if ( send == GroupPoints->LineEdit1 ||
307 send == GroupPoints->LineEdit2 ||
308 send == GroupPoints->LineEdit3 )
310 myEditCurrentArgument = send;
311 GEOMBase_Skeleton::LineEditReturnPressed();
316 //=================================================================================
317 // function : ActivateThisDialog()
319 //=================================================================================
320 void BasicGUI_EllipseDlg::ActivateThisDialog()
322 GEOMBase_Skeleton::ActivateThisDialog();
323 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
324 this, SLOT(SelectionIntoArgument()));
326 GroupPoints->LineEdit1->setFocus();
327 myEditCurrentArgument = GroupPoints->LineEdit1;
329 GroupPoints->LineEdit1->setText( "" );
330 GroupPoints->LineEdit2->setText( "" );
331 GroupPoints->LineEdit3->setText( "" );
333 myPoint = myDir = GEOM::GEOM_Object::_nil();
334 //globalSelection( GEOM_POINT );
335 globalSelection(); // close local contexts, if any
336 localSelection(GEOM::GEOM_Object::_nil(), TopAbs_VERTEX);
339 //=================================================================================
340 // function : DeactivateActiveDialog()
341 // purpose : public slot to deactivate if active
342 //=================================================================================
343 void BasicGUI_EllipseDlg::DeactivateActiveDialog()
345 // myGeomGUI->SetState( -1 );
346 GEOMBase_Skeleton::DeactivateActiveDialog();
349 //=================================================================================
350 // function : enterEvent()
352 //=================================================================================
353 void BasicGUI_EllipseDlg::enterEvent(QEvent* e)
355 if ( !GroupConstructors->isEnabled() )
356 ActivateThisDialog();
359 //=================================================================================
360 // function : ValueChangedInSpinBox()
362 //=================================================================================
363 void BasicGUI_EllipseDlg::ValueChangedInSpinBox(double newValue)
368 //=================================================================================
369 // function : createOperation
371 //=================================================================================
372 GEOM::GEOM_IOperations_ptr BasicGUI_EllipseDlg::createOperation()
374 return myGeomGUI->GetGeomGen()->GetICurvesOperations( getStudyId() );
377 //=================================================================================
378 // function : isValid
380 //=================================================================================
381 bool BasicGUI_EllipseDlg::isValid( QString& msg )
383 double aMajorR = GroupPoints->SpinBox_DX->GetValue();
384 double aMinorR = GroupPoints->SpinBox_DY->GetValue();
385 if ( aMajorR < aMinorR )
387 msg = tr( "GEOM_ELLIPSE_ERROR_1" );
390 return !myPoint->_is_nil() && !myDir->_is_nil();
393 //=================================================================================
394 // function : execute
396 //=================================================================================
397 bool BasicGUI_EllipseDlg::execute( ObjectList& objects )
399 double aMajorR = GroupPoints->SpinBox_DX->GetValue();
400 double aMinorR = GroupPoints->SpinBox_DY->GetValue();
402 GEOM::GEOM_Object_var anObj = myMajor->_is_nil() ?
403 GEOM::GEOM_ICurvesOperations::_narrow( getOperation() )->MakeEllipse ( myPoint, myDir, aMajorR, aMinorR ) :
404 GEOM::GEOM_ICurvesOperations::_narrow( getOperation() )->MakeEllipseVec( myPoint, myDir, aMajorR, aMinorR, myMajor );
406 if ( !anObj->_is_nil() )
407 objects.push_back( anObj._retn() );
412 //=================================================================================
413 // function : closeEvent
415 //=================================================================================
416 void BasicGUI_EllipseDlg::closeEvent( QCloseEvent* e )
418 GEOMBase_Skeleton::closeEvent( e );
421 //=================================================================================
422 // function : addSubshapeToStudy
423 // purpose : virtual method to add new SubObjects if local selection
424 //=================================================================================
425 void BasicGUI_EllipseDlg::addSubshapesToStudy()
427 QMap<QString, GEOM::GEOM_Object_var> objMap;
429 objMap[GroupPoints->LineEdit1->text()] = myPoint;
430 objMap[GroupPoints->LineEdit2->text()] = myDir;
431 if (!CORBA::is_nil(myMajor))
432 objMap[GroupPoints->LineEdit3->text()] = myMajor;
434 addSubshapesToFather( objMap );