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 : PrimitiveGUI_SphereDlg.cxx
24 // Author : Lucien PIGNOLONI
28 #include "PrimitiveGUI_SphereDlg.h"
30 #include "SUIT_Desktop.h"
31 #include "SUIT_Session.h"
32 #include "SalomeApp_Application.h"
33 #include "LightApp_SelectionMgr.h"
35 #include <TopoDS_Shape.hxx>
38 #include <TColStd_IndexedMapOfInteger.hxx>
39 #include <TopTools_IndexedMapOfShape.hxx>
43 #include "GEOMImpl_Types.hxx"
45 #include "utilities.h"
49 //=================================================================================
50 // class : PrimitiveGUI_SphereDlg()
51 // purpose : Constructs a PrimitiveGUI_SphereDlg which is a child of 'parent', with the
52 // name 'name' and widget flags set to 'f'.
53 // The dialog will by default be modeless, unless you set 'modal' to
54 // TRUE to construct a modal dialog.
55 //=================================================================================
56 PrimitiveGUI_SphereDlg::PrimitiveGUI_SphereDlg(GeometryGUI* theGeometryGUI, QWidget* parent,
57 const char* name, bool modal, WFlags fl)
58 :GEOMBase_Skeleton(theGeometryGUI, parent, name, modal, WStyle_Customize |
59 WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
61 QPixmap image0(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_SPHERE_P")));
62 QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_SPHERE_DXYZ")));
63 QPixmap image2(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_SELECT")));
65 setCaption(tr("GEOM_SPHERE_TITLE"));
67 /***************************************************************/
68 GroupConstructors->setTitle(tr("GEOM_SPHERE"));
69 RadioButton1->setPixmap(image0);
70 RadioButton2->setPixmap(image1);
71 RadioButton3->close(TRUE);
73 GroupPoints = new DlgRef_1Sel1Spin(this, "GroupPoints");
74 GroupPoints->GroupBox1->setTitle(tr("GEOM_SPHERE_CR"));
75 GroupPoints->TextLabel1->setText(tr("GEOM_CENTER"));
76 GroupPoints->TextLabel2->setText(tr("GEOM_RADIUS"));
77 GroupPoints->PushButton1->setPixmap(image2);
79 GroupDimensions = new DlgRef_1Spin(this, "GroupDimensions");
80 GroupDimensions->GroupBox1->setTitle(tr("GEOM_SPHERE_RO"));
81 GroupDimensions->TextLabel1->setText(tr("GEOM_RADIUS"));
83 Layout1->addWidget(GroupPoints, 2, 0);
84 Layout1->addWidget(GroupDimensions, 2, 0);
85 /***************************************************************/
87 setHelpFileName("create_sphere_page.html");
92 //=================================================================================
93 // function : ~PrimitiveGUI_SphereDlg()
94 // purpose : Destroys the object and frees any allocated resources
95 //=================================================================================
96 PrimitiveGUI_SphereDlg::~PrimitiveGUI_SphereDlg()
98 /* no need to delete child widgets, Qt does it all for us */
101 //=================================================================================
104 //=================================================================================
105 void PrimitiveGUI_SphereDlg::Init()
108 myEditCurrentArgument = GroupPoints->LineEdit1;
109 GroupPoints->LineEdit1->setReadOnly( true );
111 myPoint = GEOM::GEOM_Object::_nil();
113 /* Get setting of step value from file configuration */
114 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
115 double step = resMgr->doubleValue( "Geometry", "SettingsGeomStep", 100);
117 /* min, max, step and decimals for spin boxes */
118 GroupPoints->SpinBox_DX->RangeStepAndValidator(0.001, COORD_MAX, step, DBL_DIGITS_DISPLAY);
119 GroupDimensions->SpinBox_DX->RangeStepAndValidator(0.001, COORD_MAX, step, DBL_DIGITS_DISPLAY);
120 GroupPoints->SpinBox_DX->SetValue(100.0);
121 GroupDimensions->SpinBox_DX->SetValue(100.0);
123 /* signals and slots connections */
124 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
125 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
126 connect(GroupConstructors, SIGNAL(clicked(int)), this, SLOT(ConstructorsClicked(int)));
128 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
129 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
131 connect(GroupDimensions->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
132 connect(GroupPoints->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
134 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)),
135 GroupPoints->SpinBox_DX, SLOT(SetStep(double)));
136 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)),
137 GroupDimensions->SpinBox_DX, SLOT(SetStep(double)));
139 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
140 this, SLOT(SelectionIntoArgument()));
142 initName(tr("GEOM_SPHERE"));
143 ConstructorsClicked(0);
146 //=================================================================================
147 // function : ConstructorsClicked()
148 // purpose : Radio button management
149 //=================================================================================
150 void PrimitiveGUI_SphereDlg::ConstructorsClicked (int constructorId)
152 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
154 switch (constructorId)
158 globalSelection(); // close local contexts, if any
159 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
160 GroupDimensions->hide();
164 myEditCurrentArgument = GroupPoints->LineEdit1;
165 GroupPoints->LineEdit1->setText("");
166 myPoint = GEOM::GEOM_Object::_nil();
168 connect(myGeomGUI->getApp()->selectionMgr(),
169 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
175 globalSelection(); // close local contexts, if any
177 GroupDimensions->show();
185 //=================================================================================
186 // function : ClickOnOk()
188 //=================================================================================
189 void PrimitiveGUI_SphereDlg::ClickOnOk()
191 if ( ClickOnApply() )
195 //=================================================================================
196 // function : ClickOnApply()
198 //=================================================================================
199 bool PrimitiveGUI_SphereDlg::ClickOnApply()
205 ConstructorsClicked( getConstructorId() );
209 //=================================================================================
210 // function : ClickOnCancel()
212 //=================================================================================
213 void PrimitiveGUI_SphereDlg::ClickOnCancel()
215 GEOMBase_Skeleton::ClickOnCancel();
218 //=================================================================================
219 // function : SelectionIntoArgument()
220 // purpose : Called when selection as changed or other case
221 //=================================================================================
222 void PrimitiveGUI_SphereDlg::SelectionIntoArgument()
224 if (getConstructorId() != 0)
227 myEditCurrentArgument->setText("");
229 if (IObjectCount() != 1)
231 myPoint = GEOM::GEOM_Object::_nil();
236 Standard_Boolean testResult = Standard_False;
237 GEOM::GEOM_Object_ptr aSelectedObject = GEOMBase::ConvertIOinGEOMObject(firstIObject(), testResult);
239 if (!testResult || CORBA::is_nil(aSelectedObject))
242 QString aName = GEOMBase::GetName(aSelectedObject);
244 if (GEOMBase::GetShape(aSelectedObject, aShape, TopAbs_SHAPE) && !aShape.IsNull())
246 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
247 TColStd_IndexedMapOfInteger aMap;
248 aSelMgr->GetIndexes(firstIObject(), aMap);
249 if (aMap.Extent() == 1) // Local Selection
251 int anIndex = aMap( 1 );
252 aName.append( ":vertex_" + QString::number( anIndex ) );
254 //Find SubShape Object in Father
255 GEOM::GEOM_Object_var aFindedObject = findObjectInFather(aSelectedObject, aName);
257 if ( aFindedObject == GEOM::GEOM_Object::_nil() ) { // Object not found in study
258 GEOM::GEOM_IShapesOperations_var aShapesOp =
259 getGeomEngine()->GetIShapesOperations( getStudyId() );
260 aSelectedObject = aShapesOp->GetSubShape(aSelectedObject, anIndex);
263 aSelectedObject = aFindedObject; // get Object from study
265 else // Global Selection
267 if (aShape.ShapeType() != TopAbs_VERTEX) {
268 aSelectedObject = GEOM::GEOM_Object::_nil();
274 myEditCurrentArgument->setText(aName);
275 myPoint = aSelectedObject;
280 //=================================================================================
281 // function : LineEditReturnPressed()
283 //=================================================================================
284 void PrimitiveGUI_SphereDlg::LineEditReturnPressed()
286 QLineEdit* send = (QLineEdit*)sender();
287 if(send == GroupPoints->LineEdit1)
289 myEditCurrentArgument = send;
290 GEOMBase_Skeleton::LineEditReturnPressed();
294 //=================================================================================
295 // function : SetEditCurrentArgument()
297 //=================================================================================
298 void PrimitiveGUI_SphereDlg::SetEditCurrentArgument()
300 QPushButton* send = (QPushButton*)sender();
302 if (send == GroupPoints->PushButton1) {
303 GroupPoints->LineEdit1->setFocus();
304 myEditCurrentArgument = GroupPoints->LineEdit1;
305 globalSelection(); // close local contexts, if any
306 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
307 SelectionIntoArgument();
311 //=================================================================================
312 // function : ActivateThisDialog()
314 //=================================================================================
315 void PrimitiveGUI_SphereDlg::ActivateThisDialog()
317 GEOMBase_Skeleton::ActivateThisDialog();
318 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
319 this, SLOT(SelectionIntoArgument()));
321 ConstructorsClicked(getConstructorId());
324 //=================================================================================
325 // function : DeactivateActiveDialog()
326 // purpose : public slot to deactivate if active
327 //=================================================================================
328 void PrimitiveGUI_SphereDlg::DeactivateActiveDialog()
330 GEOMBase_Skeleton::DeactivateActiveDialog();
333 //=================================================================================
334 // function : enterEvent()
336 //=================================================================================
337 void PrimitiveGUI_SphereDlg::enterEvent(QEvent* e)
339 if ( !GroupConstructors->isEnabled() )
340 ActivateThisDialog();
343 //=================================================================================
344 // function : ValueChangedInSpinBox()
346 //=================================================================================
347 void PrimitiveGUI_SphereDlg::ValueChangedInSpinBox()
352 //=================================================================================
353 // function : createOperation
355 //=================================================================================
356 GEOM::GEOM_IOperations_ptr PrimitiveGUI_SphereDlg::createOperation()
358 return getGeomEngine()->GetI3DPrimOperations( getStudyId() );
361 //=================================================================================
362 // function : isValid
364 //=================================================================================
365 bool PrimitiveGUI_SphereDlg::isValid( QString& msg )
367 return getConstructorId() == 0 ? !myPoint->_is_nil() : true;
370 //=================================================================================
371 // function : execute
373 //=================================================================================
374 bool PrimitiveGUI_SphereDlg::execute (ObjectList& objects)
378 GEOM::GEOM_Object_var anObj;
380 switch (getConstructorId())
384 if (!CORBA::is_nil(myPoint)) {
385 anObj = GEOM::GEOM_I3DPrimOperations::_narrow( getOperation() )->
386 MakeSpherePntR(myPoint, getRadius());
393 anObj = GEOM::GEOM_I3DPrimOperations::_narrow( getOperation() )->
394 MakeSphereR(getRadius());
400 if (!anObj->_is_nil())
401 objects.push_back(anObj._retn());
406 //=================================================================================
407 // function : closeEvent
409 //=================================================================================
410 void PrimitiveGUI_SphereDlg::closeEvent( QCloseEvent* e )
412 GEOMBase_Skeleton::closeEvent( e );
415 //=================================================================================
416 // function : getRadius()
418 //=================================================================================
419 double PrimitiveGUI_SphereDlg::getRadius() const
421 int aConstructorId = getConstructorId();
422 if (aConstructorId == 0)
423 return GroupPoints->SpinBox_DX->GetValue();
424 else if (aConstructorId == 1)
425 return GroupDimensions->SpinBox_DX->GetValue();
429 //=================================================================================
430 // function : addSubshapeToStudy
431 // purpose : virtual method to add new SubObjects if local selection
432 //=================================================================================
433 void PrimitiveGUI_SphereDlg::addSubshapesToStudy()
435 QMap<QString, GEOM::GEOM_Object_var> objMap;
437 switch (getConstructorId())
440 objMap[GroupPoints->LineEdit1->text()] = myPoint;
445 addSubshapesToFather( objMap );