1 // GEOM GEOMGUI : GUI for Geometry component
3 // Copyright (C) 2003 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
24 // File : PrimitiveGUI_SphereDlg.cxx
25 // Author : Lucien PIGNOLONI
29 #include "PrimitiveGUI_SphereDlg.h"
31 #include "SUIT_Desktop.h"
32 #include "SUIT_Session.h"
33 #include "SalomeApp_Application.h"
34 #include "LightApp_SelectionMgr.h"
36 #include <TopoDS_Shape.hxx>
39 #include <TColStd_IndexedMapOfInteger.hxx>
40 #include <TopTools_IndexedMapOfShape.hxx>
44 #include "GEOMImpl_Types.hxx"
46 #include "utilities.h"
50 //=================================================================================
51 // class : PrimitiveGUI_SphereDlg()
52 // purpose : Constructs a PrimitiveGUI_SphereDlg 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 PrimitiveGUI_SphereDlg::PrimitiveGUI_SphereDlg(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_SPHERE_P")));
63 QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_SPHERE_DXYZ")));
64 QPixmap image2(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_SELECT")));
66 setCaption(tr("GEOM_SPHERE_TITLE"));
68 /***************************************************************/
69 GroupConstructors->setTitle(tr("GEOM_SPHERE"));
70 RadioButton1->setPixmap(image0);
71 RadioButton2->setPixmap(image1);
72 RadioButton3->close(TRUE);
74 GroupPoints = new DlgRef_1Sel1Spin(this, "GroupPoints");
75 GroupPoints->GroupBox1->setTitle(tr("GEOM_SPHERE_CR"));
76 GroupPoints->TextLabel1->setText(tr("GEOM_CENTER"));
77 GroupPoints->TextLabel2->setText(tr("GEOM_RADIUS"));
78 GroupPoints->PushButton1->setPixmap(image2);
80 GroupDimensions = new DlgRef_1Spin(this, "GroupDimensions");
81 GroupDimensions->GroupBox1->setTitle(tr("GEOM_SPHERE_RO"));
82 GroupDimensions->TextLabel1->setText(tr("GEOM_RADIUS"));
84 Layout1->addWidget(GroupPoints, 2, 0);
85 Layout1->addWidget(GroupDimensions, 2, 0);
86 /***************************************************************/
88 setHelpFileName("create_sphere_page.html");
93 //=================================================================================
94 // function : ~PrimitiveGUI_SphereDlg()
95 // purpose : Destroys the object and frees any allocated resources
96 //=================================================================================
97 PrimitiveGUI_SphereDlg::~PrimitiveGUI_SphereDlg()
99 /* no need to delete child widgets, Qt does it all for us */
102 //=================================================================================
105 //=================================================================================
106 void PrimitiveGUI_SphereDlg::Init()
109 myEditCurrentArgument = GroupPoints->LineEdit1;
110 GroupPoints->LineEdit1->setReadOnly( true );
112 myPoint = GEOM::GEOM_Object::_nil();
114 /* Get setting of step value from file configuration */
115 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
116 double step = resMgr->doubleValue( "Geometry", "SettingsGeomStep", 100);
118 /* min, max, step and decimals for spin boxes */
119 GroupPoints->SpinBox_DX->RangeStepAndValidator(0.001, COORD_MAX, step, DBL_DIGITS_DISPLAY);
120 GroupDimensions->SpinBox_DX->RangeStepAndValidator(0.001, COORD_MAX, step, DBL_DIGITS_DISPLAY);
121 GroupPoints->SpinBox_DX->SetValue(100.0);
122 GroupDimensions->SpinBox_DX->SetValue(100.0);
124 /* signals and slots connections */
125 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
126 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
127 connect(GroupConstructors, SIGNAL(clicked(int)), this, SLOT(ConstructorsClicked(int)));
129 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
130 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
132 connect(GroupDimensions->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
133 connect(GroupPoints->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
135 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)),
136 GroupPoints->SpinBox_DX, SLOT(SetStep(double)));
137 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)),
138 GroupDimensions->SpinBox_DX, SLOT(SetStep(double)));
140 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
141 this, SLOT(SelectionIntoArgument()));
143 initName(tr("GEOM_SPHERE"));
144 ConstructorsClicked(0);
147 //=================================================================================
148 // function : ConstructorsClicked()
149 // purpose : Radio button management
150 //=================================================================================
151 void PrimitiveGUI_SphereDlg::ConstructorsClicked (int constructorId)
153 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
155 switch (constructorId)
159 globalSelection(); // close local contexts, if any
160 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
161 GroupDimensions->hide();
165 myEditCurrentArgument = GroupPoints->LineEdit1;
166 GroupPoints->LineEdit1->setText("");
167 myPoint = GEOM::GEOM_Object::_nil();
169 connect(myGeomGUI->getApp()->selectionMgr(),
170 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
176 globalSelection(); // close local contexts, if any
178 GroupDimensions->show();
186 //=================================================================================
187 // function : ClickOnOk()
189 //=================================================================================
190 void PrimitiveGUI_SphereDlg::ClickOnOk()
192 if ( ClickOnApply() )
196 //=================================================================================
197 // function : ClickOnApply()
199 //=================================================================================
200 bool PrimitiveGUI_SphereDlg::ClickOnApply()
206 ConstructorsClicked( getConstructorId() );
210 //=================================================================================
211 // function : ClickOnCancel()
213 //=================================================================================
214 void PrimitiveGUI_SphereDlg::ClickOnCancel()
216 GEOMBase_Skeleton::ClickOnCancel();
219 //=================================================================================
220 // function : SelectionIntoArgument()
221 // purpose : Called when selection as changed or other case
222 //=================================================================================
223 void PrimitiveGUI_SphereDlg::SelectionIntoArgument()
225 if (getConstructorId() != 0)
228 myEditCurrentArgument->setText("");
230 if (IObjectCount() != 1)
232 myPoint = GEOM::GEOM_Object::_nil();
237 Standard_Boolean testResult = Standard_False;
238 GEOM::GEOM_Object_ptr aSelectedObject = GEOMBase::ConvertIOinGEOMObject(firstIObject(), testResult);
240 if (!testResult || CORBA::is_nil(aSelectedObject))
243 QString aName = GEOMBase::GetName(aSelectedObject);
245 if (GEOMBase::GetShape(aSelectedObject, aShape, TopAbs_SHAPE) && !aShape.IsNull())
247 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
248 TColStd_IndexedMapOfInteger aMap;
249 aSelMgr->GetIndexes(firstIObject(), aMap);
250 if (aMap.Extent() == 1) // Local Selection
252 int anIndex = aMap( 1 );
253 aName.append( ":vertex_" + QString::number( anIndex ) );
255 //Find SubShape Object in Father
256 GEOM::GEOM_Object_var aFindedObject = findObjectInFather(aSelectedObject, aName);
258 if ( aFindedObject == GEOM::GEOM_Object::_nil() ) { // Object not found in study
259 GEOM::GEOM_IShapesOperations_var aShapesOp =
260 getGeomEngine()->GetIShapesOperations( getStudyId() );
261 aSelectedObject = aShapesOp->GetSubShape(aSelectedObject, anIndex);
264 aSelectedObject = aFindedObject; // get Object from study
266 else // Global Selection
268 if (aShape.ShapeType() != TopAbs_VERTEX) {
269 aSelectedObject = GEOM::GEOM_Object::_nil();
275 myEditCurrentArgument->setText(aName);
276 myPoint = aSelectedObject;
281 //=================================================================================
282 // function : LineEditReturnPressed()
284 //=================================================================================
285 void PrimitiveGUI_SphereDlg::LineEditReturnPressed()
287 QLineEdit* send = (QLineEdit*)sender();
288 if(send == GroupPoints->LineEdit1)
290 myEditCurrentArgument = send;
291 GEOMBase_Skeleton::LineEditReturnPressed();
295 //=================================================================================
296 // function : SetEditCurrentArgument()
298 //=================================================================================
299 void PrimitiveGUI_SphereDlg::SetEditCurrentArgument()
301 QPushButton* send = (QPushButton*)sender();
303 if (send == GroupPoints->PushButton1) {
304 GroupPoints->LineEdit1->setFocus();
305 myEditCurrentArgument = GroupPoints->LineEdit1;
306 globalSelection(); // close local contexts, if any
307 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
308 SelectionIntoArgument();
312 //=================================================================================
313 // function : ActivateThisDialog()
315 //=================================================================================
316 void PrimitiveGUI_SphereDlg::ActivateThisDialog()
318 GEOMBase_Skeleton::ActivateThisDialog();
319 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
320 this, SLOT(SelectionIntoArgument()));
322 ConstructorsClicked(getConstructorId());
325 //=================================================================================
326 // function : DeactivateActiveDialog()
327 // purpose : public slot to deactivate if active
328 //=================================================================================
329 void PrimitiveGUI_SphereDlg::DeactivateActiveDialog()
331 GEOMBase_Skeleton::DeactivateActiveDialog();
334 //=================================================================================
335 // function : enterEvent()
337 //=================================================================================
338 void PrimitiveGUI_SphereDlg::enterEvent(QEvent* e)
340 if ( !GroupConstructors->isEnabled() )
341 ActivateThisDialog();
344 //=================================================================================
345 // function : ValueChangedInSpinBox()
347 //=================================================================================
348 void PrimitiveGUI_SphereDlg::ValueChangedInSpinBox()
353 //=================================================================================
354 // function : createOperation
356 //=================================================================================
357 GEOM::GEOM_IOperations_ptr PrimitiveGUI_SphereDlg::createOperation()
359 return getGeomEngine()->GetI3DPrimOperations( getStudyId() );
362 //=================================================================================
363 // function : isValid
365 //=================================================================================
366 bool PrimitiveGUI_SphereDlg::isValid( QString& msg )
368 return getConstructorId() == 0 ? !myPoint->_is_nil() : true;
371 //=================================================================================
372 // function : execute
374 //=================================================================================
375 bool PrimitiveGUI_SphereDlg::execute (ObjectList& objects)
379 GEOM::GEOM_Object_var anObj;
381 switch (getConstructorId())
385 if (!CORBA::is_nil(myPoint)) {
386 anObj = GEOM::GEOM_I3DPrimOperations::_narrow( getOperation() )->
387 MakeSpherePntR(myPoint, getRadius());
394 anObj = GEOM::GEOM_I3DPrimOperations::_narrow( getOperation() )->
395 MakeSphereR(getRadius());
401 if (!anObj->_is_nil())
402 objects.push_back(anObj._retn());
407 //=================================================================================
408 // function : closeEvent
410 //=================================================================================
411 void PrimitiveGUI_SphereDlg::closeEvent( QCloseEvent* e )
413 GEOMBase_Skeleton::closeEvent( e );
416 //=================================================================================
417 // function : getRadius()
419 //=================================================================================
420 double PrimitiveGUI_SphereDlg::getRadius() const
422 int aConstructorId = getConstructorId();
423 if (aConstructorId == 0)
424 return GroupPoints->SpinBox_DX->GetValue();
425 else if (aConstructorId == 1)
426 return GroupDimensions->SpinBox_DX->GetValue();
430 //=================================================================================
431 // function : addSubshapeToStudy
432 // purpose : virtual method to add new SubObjects if local selection
433 //=================================================================================
434 void PrimitiveGUI_SphereDlg::addSubshapesToStudy()
436 QMap<QString, GEOM::GEOM_Object_var> objMap;
438 switch (getConstructorId())
441 objMap[GroupPoints->LineEdit1->text()] = myPoint;
446 addSubshapesToFather( objMap );