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("sphere.htm");
94 //=================================================================================
95 // function : ~PrimitiveGUI_SphereDlg()
96 // purpose : Destroys the object and frees any allocated resources
97 //=================================================================================
98 PrimitiveGUI_SphereDlg::~PrimitiveGUI_SphereDlg()
100 /* no need to delete child widgets, Qt does it all for us */
104 //=================================================================================
107 //=================================================================================
108 void PrimitiveGUI_SphereDlg::Init()
111 myEditCurrentArgument = GroupPoints->LineEdit1;
112 GroupPoints->LineEdit1->setReadOnly( true );
114 myPoint = 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 /* min, max, step and decimals for spin boxes */
121 GroupPoints->SpinBox_DX->RangeStepAndValidator(0.001, COORD_MAX, step, DBL_DIGITS_DISPLAY);
122 GroupDimensions->SpinBox_DX->RangeStepAndValidator(0.001, COORD_MAX, step, DBL_DIGITS_DISPLAY);
123 GroupPoints->SpinBox_DX->SetValue(100.0);
124 GroupDimensions->SpinBox_DX->SetValue(100.0);
126 /* signals and slots connections */
127 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
128 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
129 connect(GroupConstructors, SIGNAL(clicked(int)), this, SLOT(ConstructorsClicked(int)));
131 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
132 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
134 connect(GroupDimensions->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
135 connect(GroupPoints->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
137 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_DX, SLOT(SetStep(double)));
138 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DX, SLOT(SetStep(double)));
140 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
141 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
143 initName(tr("GEOM_SPHERE"));
144 ConstructorsClicked(0);
148 //=================================================================================
149 // function : ConstructorsClicked()
150 // purpose : Radio button management
151 //=================================================================================
152 void PrimitiveGUI_SphereDlg::ConstructorsClicked(int constructorId)
154 disconnect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), 0, this, 0);
156 switch (constructorId)
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(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
170 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
177 GroupDimensions->show();
186 //=================================================================================
187 // function : ClickOnOk()
189 //=================================================================================
190 void PrimitiveGUI_SphereDlg::ClickOnOk()
192 if ( ClickOnApply() )
197 //=================================================================================
198 // function : ClickOnApply()
200 //=================================================================================
201 bool PrimitiveGUI_SphereDlg::ClickOnApply()
207 ConstructorsClicked( getConstructorId() );
213 //=======================================================================
214 // function : ClickOnCancel()
216 //=======================================================================
217 void PrimitiveGUI_SphereDlg::ClickOnCancel()
219 GEOMBase_Skeleton::ClickOnCancel();
223 //=================================================================================
224 // function : SelectionIntoArgument()
225 // purpose : Called when selection as changed or other case
226 //=================================================================================
227 void PrimitiveGUI_SphereDlg::SelectionIntoArgument()
229 if ( getConstructorId() != 0 )
232 myEditCurrentArgument->setText("");
234 if(IObjectCount() != 1)
236 myPoint = GEOM::GEOM_Object::_nil();
241 Standard_Boolean testResult = Standard_False;
242 GEOM::GEOM_Object_ptr aSelectedObject = GEOMBase::ConvertIOinGEOMObject( firstIObject(), testResult );
244 if (!testResult || CORBA::is_nil( aSelectedObject ))
247 myEditCurrentArgument->setText( GEOMBase::GetName( aSelectedObject ) );
249 if ( GEOMBase::GetShape( aSelectedObject, aShape, TopAbs_SHAPE ) && !aShape.IsNull() )
251 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
252 TColStd_IndexedMapOfInteger aMap;
253 aSelMgr->GetIndexes( firstIObject(), aMap );
254 if ( aMap.Extent() == 1 )
256 GEOM::GEOM_IShapesOperations_var aShapesOp =
257 getGeomEngine()->GetIShapesOperations( getStudyId() );
258 int anIndex = aMap( 1 );
259 TopTools_IndexedMapOfShape aShapes;
260 TopExp::MapShapes( aShape, aShapes );
261 aShape = aShapes.FindKey( anIndex );
262 aSelectedObject = aShapesOp->GetSubShape(aSelectedObject, anIndex);
263 aSelMgr->clearSelected();
266 myPoint = aSelectedObject;
272 //=================================================================================
273 // function : LineEditReturnPressed()
275 //=================================================================================
276 void PrimitiveGUI_SphereDlg::LineEditReturnPressed()
278 QLineEdit* send = (QLineEdit*)sender();
279 if(send == GroupPoints->LineEdit1)
281 myEditCurrentArgument = send;
282 GEOMBase_Skeleton::LineEditReturnPressed();
287 //=================================================================================
288 // function : SetEditCurrentArgument()
290 //=================================================================================
291 void PrimitiveGUI_SphereDlg::SetEditCurrentArgument()
293 QPushButton* send = (QPushButton*)sender();
295 if(send == GroupPoints->PushButton1) {
296 GroupPoints->LineEdit1->setFocus();
297 myEditCurrentArgument = GroupPoints->LineEdit1;
298 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
299 SelectionIntoArgument();
304 //=================================================================================
305 // function : ActivateThisDialog()
307 //=================================================================================
308 void PrimitiveGUI_SphereDlg::ActivateThisDialog()
310 GEOMBase_Skeleton::ActivateThisDialog();
311 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
312 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
314 ConstructorsClicked( getConstructorId() );
318 //=================================================================================
319 // function : DeactivateActiveDialog()
320 // purpose : public slot to deactivate if active
321 //=================================================================================
322 void PrimitiveGUI_SphereDlg::DeactivateActiveDialog()
324 GEOMBase_Skeleton::DeactivateActiveDialog();
328 //=================================================================================
329 // function : enterEvent()
331 //=================================================================================
332 void PrimitiveGUI_SphereDlg::enterEvent(QEvent* e)
334 if ( !GroupConstructors->isEnabled() )
335 ActivateThisDialog();
339 //=================================================================================
340 // function : ValueChangedInSpinBox()
342 //=================================================================================
343 void PrimitiveGUI_SphereDlg::ValueChangedInSpinBox()
349 //=================================================================================
350 // function : createOperation
352 //=================================================================================
353 GEOM::GEOM_IOperations_ptr PrimitiveGUI_SphereDlg::createOperation()
355 return getGeomEngine()->GetI3DPrimOperations( getStudyId() );
359 //=================================================================================
360 // function : isValid
362 //=================================================================================
363 bool PrimitiveGUI_SphereDlg::isValid( QString& msg )
365 return getConstructorId() == 0 ? !myPoint->_is_nil() : true;
368 //=================================================================================
369 // function : execute
371 //=================================================================================
372 bool PrimitiveGUI_SphereDlg::execute( ObjectList& objects )
376 GEOM::GEOM_Object_var anObj;
378 switch ( getConstructorId() )
382 if ( !CORBA::is_nil( myPoint ) ) {
383 anObj = GEOM::GEOM_I3DPrimOperations::_narrow( getOperation() )->MakeSpherePntR( myPoint, getRadius() );
390 anObj = GEOM::GEOM_I3DPrimOperations::_narrow( getOperation() )->MakeSphereR( getRadius() );
396 if ( !anObj->_is_nil() )
397 objects.push_back( anObj._retn() );
402 //=================================================================================
403 // function : closeEvent
405 //=================================================================================
406 void PrimitiveGUI_SphereDlg::closeEvent( QCloseEvent* e )
408 //myGeomGUI->SetState( -1 );
409 GEOMBase_Skeleton::closeEvent( e );
414 //=================================================================================
415 // function : getRadius()
417 //=================================================================================
418 double PrimitiveGUI_SphereDlg::getRadius() const
420 int aConstructorId = getConstructorId();
421 if (aConstructorId == 0)
422 return GroupPoints->SpinBox_DX->GetValue();
423 else if (aConstructorId == 1)
424 return GroupDimensions->SpinBox_DX->GetValue();