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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : PrimitiveGUI_SphereDlg.cxx
25 // Author : Lucien PIGNOLONI
30 #include "PrimitiveGUI_SphereDlg.h"
32 #include "SUIT_Desktop.h"
33 #include "SUIT_Session.h"
34 #include "SalomeApp_Application.h"
35 #include "SalomeApp_SelectionMgr.h"
39 #include "GEOMImpl_Types.hxx"
41 #include "utilities.h"
45 //=================================================================================
46 // class : PrimitiveGUI_SphereDlg()
47 // purpose : Constructs a PrimitiveGUI_SphereDlg which is a child of 'parent', with the
48 // name 'name' and widget flags set to 'f'.
49 // The dialog will by default be modeless, unless you set 'modal' to
50 // TRUE to construct a modal dialog.
51 //=================================================================================
52 PrimitiveGUI_SphereDlg::PrimitiveGUI_SphereDlg(GeometryGUI* theGeometryGUI, QWidget* parent, const char* name, bool modal, WFlags fl)
53 :GEOMBase_Skeleton(parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu), myGeometryGUI(theGeometryGUI)
55 QPixmap image0(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_SPHERE_P")));
56 QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_SPHERE_DXYZ")));
57 QPixmap image2(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_SELECT")));
59 setCaption(tr("GEOM_SPHERE_TITLE"));
61 /***************************************************************/
62 GroupConstructors->setTitle(tr("GEOM_SPHERE"));
63 RadioButton1->setPixmap(image0);
64 RadioButton2->setPixmap(image1);
65 RadioButton3->close(TRUE);
67 GroupPoints = new DlgRef_1Sel1Spin(this, "GroupPoints");
68 GroupPoints->GroupBox1->setTitle(tr("GEOM_SPHERE_CR"));
69 GroupPoints->TextLabel1->setText(tr("GEOM_CENTER"));
70 GroupPoints->TextLabel2->setText(tr("GEOM_RADIUS"));
71 GroupPoints->PushButton1->setPixmap(image2);
73 GroupDimensions = new DlgRef_1Spin(this, "GroupDimensions");
74 GroupDimensions->GroupBox1->setTitle(tr("GEOM_SPHERE_RO"));
75 GroupDimensions->TextLabel1->setText(tr("GEOM_RADIUS"));
77 Layout1->addWidget(GroupPoints, 2, 0);
78 Layout1->addWidget(GroupDimensions, 2, 0);
79 /***************************************************************/
85 //=================================================================================
86 // function : ~PrimitiveGUI_SphereDlg()
87 // purpose : Destroys the object and frees any allocated resources
88 //=================================================================================
89 PrimitiveGUI_SphereDlg::~PrimitiveGUI_SphereDlg()
91 /* no need to delete child widgets, Qt does it all for us */
95 //=================================================================================
98 //=================================================================================
99 void PrimitiveGUI_SphereDlg::Init()
102 myEditCurrentArgument = GroupPoints->LineEdit1;
103 GroupPoints->LineEdit1->setReadOnly( true );
105 myPoint = GEOM::GEOM_Object::_nil();
107 /* Get setting of step value from file configuration */
108 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
109 double step = resMgr->doubleValue( "Geometry", "SettingsGeomStep", 100);
111 /* min, max, step and decimals for spin boxes */
112 GroupPoints->SpinBox_DX->RangeStepAndValidator(0.001, 999.999, step, 3);
113 GroupDimensions->SpinBox_DX->RangeStepAndValidator(0.001, 999.999, step, 3);
114 GroupPoints->SpinBox_DX->SetValue(100.0);
115 GroupDimensions->SpinBox_DX->SetValue(100.0);
117 /* signals and slots connections */
118 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
119 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
120 connect(GroupConstructors, SIGNAL(clicked(int)), this, SLOT(ConstructorsClicked(int)));
122 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
123 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
125 connect(GroupDimensions->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
126 connect(GroupPoints->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
128 connect(myGeometryGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_DX, SLOT(SetStep(double)));
129 connect(myGeometryGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DX, SLOT(SetStep(double)));
131 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
132 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
134 initName(tr("GEOM_SPHERE"));
135 ConstructorsClicked(0);
139 //=================================================================================
140 // function : ConstructorsClicked()
141 // purpose : Radio button management
142 //=================================================================================
143 void PrimitiveGUI_SphereDlg::ConstructorsClicked(int constructorId)
145 disconnect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), 0, this, 0);
147 switch (constructorId)
151 globalSelection( GEOM_POINT );
152 GroupDimensions->hide();
156 myEditCurrentArgument = GroupPoints->LineEdit1;
157 GroupPoints->LineEdit1->setText("");
158 myPoint = GEOM::GEOM_Object::_nil();
160 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
161 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
168 GroupDimensions->show();
177 //=================================================================================
178 // function : ClickOnOk()
180 //=================================================================================
181 void PrimitiveGUI_SphereDlg::ClickOnOk()
183 if ( ClickOnApply() )
188 //=================================================================================
189 // function : ClickOnApply()
191 //=================================================================================
192 bool PrimitiveGUI_SphereDlg::ClickOnApply()
198 ConstructorsClicked( getConstructorId() );
204 //=======================================================================
205 // function : ClickOnCancel()
207 //=======================================================================
208 void PrimitiveGUI_SphereDlg::ClickOnCancel()
210 GEOMBase_Skeleton::ClickOnCancel();
214 //=================================================================================
215 // function : SelectionIntoArgument()
216 // purpose : Called when selection as changed or other case
217 //=================================================================================
218 void PrimitiveGUI_SphereDlg::SelectionIntoArgument()
220 if ( getConstructorId() != 0 )
223 myEditCurrentArgument->setText("");
225 if(IObjectCount() != 1)
227 myPoint = GEOM::GEOM_Object::_nil();
232 Standard_Boolean testResult = Standard_False;
233 GEOM::GEOM_Object_ptr aSelectedObject = GEOMBase::ConvertIOinGEOMObject( firstIObject(), testResult );
235 if (!testResult || CORBA::is_nil( aSelectedObject ))
238 myPoint = aSelectedObject;
239 myEditCurrentArgument->setText( GEOMBase::GetName( myPoint ) );
245 //=================================================================================
246 // function : LineEditReturnPressed()
248 //=================================================================================
249 void PrimitiveGUI_SphereDlg::LineEditReturnPressed()
251 QLineEdit* send = (QLineEdit*)sender();
252 if(send == GroupPoints->LineEdit1)
254 myEditCurrentArgument = send;
255 GEOMBase_Skeleton::LineEditReturnPressed();
260 //=================================================================================
261 // function : SetEditCurrentArgument()
263 //=================================================================================
264 void PrimitiveGUI_SphereDlg::SetEditCurrentArgument()
266 QPushButton* send = (QPushButton*)sender();
268 if(send == GroupPoints->PushButton1) {
269 GroupPoints->LineEdit1->setFocus();
270 myEditCurrentArgument = GroupPoints->LineEdit1;
271 globalSelection( GEOM_POINT );
272 SelectionIntoArgument();
277 //=================================================================================
278 // function : ActivateThisDialog()
280 //=================================================================================
281 void PrimitiveGUI_SphereDlg::ActivateThisDialog()
283 GEOMBase_Skeleton::ActivateThisDialog();
284 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
285 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
287 ConstructorsClicked( getConstructorId() );
291 //=================================================================================
292 // function : DeactivateActiveDialog()
293 // purpose : public slot to deactivate if active
294 //=================================================================================
295 void PrimitiveGUI_SphereDlg::DeactivateActiveDialog()
297 GEOMBase_Skeleton::DeactivateActiveDialog();
301 //=================================================================================
302 // function : enterEvent()
304 //=================================================================================
305 void PrimitiveGUI_SphereDlg::enterEvent(QEvent* e)
307 if ( !GroupConstructors->isEnabled() )
308 ActivateThisDialog();
312 //=================================================================================
313 // function : ValueChangedInSpinBox()
315 //=================================================================================
316 void PrimitiveGUI_SphereDlg::ValueChangedInSpinBox()
322 //=================================================================================
323 // function : createOperation
325 //=================================================================================
326 GEOM::GEOM_IOperations_ptr PrimitiveGUI_SphereDlg::createOperation()
328 return getGeomEngine()->GetI3DPrimOperations( getStudyId() );
332 //=================================================================================
333 // function : isValid
335 //=================================================================================
336 bool PrimitiveGUI_SphereDlg::isValid( QString& msg )
338 return getConstructorId() == 0 ? !myPoint->_is_nil() : true;
341 //=================================================================================
342 // function : execute
344 //=================================================================================
345 bool PrimitiveGUI_SphereDlg::execute( ObjectList& objects )
349 GEOM::GEOM_Object_var anObj;
351 switch ( getConstructorId() )
355 if ( !CORBA::is_nil( myPoint ) ) {
356 anObj = GEOM::GEOM_I3DPrimOperations::_narrow( getOperation() )->MakeSpherePntR( myPoint, getRadius() );
363 anObj = GEOM::GEOM_I3DPrimOperations::_narrow( getOperation() )->MakeSphereR( getRadius() );
369 if ( !anObj->_is_nil() )
370 objects.push_back( anObj._retn() );
375 //=================================================================================
376 // function : closeEvent
378 //=================================================================================
379 void PrimitiveGUI_SphereDlg::closeEvent( QCloseEvent* e )
381 //myGeomGUI->SetState( -1 );
382 GEOMBase_Skeleton::closeEvent( e );
387 //=================================================================================
388 // function : getRadius()
390 //=================================================================================
391 double PrimitiveGUI_SphereDlg::getRadius() const
393 int aConstructorId = getConstructorId();
394 if (aConstructorId == 0)
395 return GroupPoints->SpinBox_DX->GetValue();
396 else if (aConstructorId == 1)
397 return GroupDimensions->SpinBox_DX->GetValue();