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
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"
38 #include "GEOMImpl_Types.hxx"
40 #include "utilities.h"
44 //=================================================================================
45 // class : PrimitiveGUI_SphereDlg()
46 // purpose : Constructs a PrimitiveGUI_SphereDlg which is a child of 'parent', with the
47 // name 'name' and widget flags set to 'f'.
48 // The dialog will by default be modeless, unless you set 'modal' to
49 // TRUE to construct a modal dialog.
50 //=================================================================================
51 PrimitiveGUI_SphereDlg::PrimitiveGUI_SphereDlg(GeometryGUI* theGeometryGUI, QWidget* parent,
52 const char* name, bool modal, WFlags fl)
53 :GEOMBase_Skeleton(theGeometryGUI, parent, name, modal, WStyle_Customize |
54 WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
56 QPixmap image0(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_SPHERE_P")));
57 QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_SPHERE_DXYZ")));
58 QPixmap image2(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_SELECT")));
60 setCaption(tr("GEOM_SPHERE_TITLE"));
62 /***************************************************************/
63 GroupConstructors->setTitle(tr("GEOM_SPHERE"));
64 RadioButton1->setPixmap(image0);
65 RadioButton2->setPixmap(image1);
66 RadioButton3->close(TRUE);
68 GroupPoints = new DlgRef_1Sel1Spin(this, "GroupPoints");
69 GroupPoints->GroupBox1->setTitle(tr("GEOM_SPHERE_CR"));
70 GroupPoints->TextLabel1->setText(tr("GEOM_CENTER"));
71 GroupPoints->TextLabel2->setText(tr("GEOM_RADIUS"));
72 GroupPoints->PushButton1->setPixmap(image2);
74 GroupDimensions = new DlgRef_1Spin(this, "GroupDimensions");
75 GroupDimensions->GroupBox1->setTitle(tr("GEOM_SPHERE_RO"));
76 GroupDimensions->TextLabel1->setText(tr("GEOM_RADIUS"));
78 Layout1->addWidget(GroupPoints, 2, 0);
79 Layout1->addWidget(GroupDimensions, 2, 0);
80 /***************************************************************/
82 setHelpFileName("sphere.htm");
88 //=================================================================================
89 // function : ~PrimitiveGUI_SphereDlg()
90 // purpose : Destroys the object and frees any allocated resources
91 //=================================================================================
92 PrimitiveGUI_SphereDlg::~PrimitiveGUI_SphereDlg()
94 /* no need to delete child widgets, Qt does it all for us */
98 //=================================================================================
101 //=================================================================================
102 void PrimitiveGUI_SphereDlg::Init()
105 myEditCurrentArgument = GroupPoints->LineEdit1;
106 GroupPoints->LineEdit1->setReadOnly( true );
108 myPoint = GEOM::GEOM_Object::_nil();
110 /* Get setting of step value from file configuration */
111 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
112 double step = resMgr->doubleValue( "Geometry", "SettingsGeomStep", 100);
114 /* min, max, step and decimals for spin boxes */
115 GroupPoints->SpinBox_DX->RangeStepAndValidator(0.001, 999.999, step, 3);
116 GroupDimensions->SpinBox_DX->RangeStepAndValidator(0.001, 999.999, step, 3);
117 GroupPoints->SpinBox_DX->SetValue(100.0);
118 GroupDimensions->SpinBox_DX->SetValue(100.0);
120 /* signals and slots connections */
121 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
122 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
123 connect(GroupConstructors, SIGNAL(clicked(int)), this, SLOT(ConstructorsClicked(int)));
125 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
126 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
128 connect(GroupDimensions->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
129 connect(GroupPoints->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
131 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_DX, SLOT(SetStep(double)));
132 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DX, SLOT(SetStep(double)));
134 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
135 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
137 initName(tr("GEOM_SPHERE"));
138 ConstructorsClicked(0);
142 //=================================================================================
143 // function : ConstructorsClicked()
144 // purpose : Radio button management
145 //=================================================================================
146 void PrimitiveGUI_SphereDlg::ConstructorsClicked(int constructorId)
148 disconnect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), 0, this, 0);
150 switch (constructorId)
154 globalSelection( GEOM_POINT );
155 GroupDimensions->hide();
159 myEditCurrentArgument = GroupPoints->LineEdit1;
160 GroupPoints->LineEdit1->setText("");
161 myPoint = GEOM::GEOM_Object::_nil();
163 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
164 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
171 GroupDimensions->show();
180 //=================================================================================
181 // function : ClickOnOk()
183 //=================================================================================
184 void PrimitiveGUI_SphereDlg::ClickOnOk()
186 if ( ClickOnApply() )
191 //=================================================================================
192 // function : ClickOnApply()
194 //=================================================================================
195 bool PrimitiveGUI_SphereDlg::ClickOnApply()
201 ConstructorsClicked( getConstructorId() );
207 //=======================================================================
208 // function : ClickOnCancel()
210 //=======================================================================
211 void PrimitiveGUI_SphereDlg::ClickOnCancel()
213 GEOMBase_Skeleton::ClickOnCancel();
217 //=================================================================================
218 // function : SelectionIntoArgument()
219 // purpose : Called when selection as changed or other case
220 //=================================================================================
221 void PrimitiveGUI_SphereDlg::SelectionIntoArgument()
223 if ( getConstructorId() != 0 )
226 myEditCurrentArgument->setText("");
228 if(IObjectCount() != 1)
230 myPoint = GEOM::GEOM_Object::_nil();
235 Standard_Boolean testResult = Standard_False;
236 GEOM::GEOM_Object_ptr aSelectedObject = GEOMBase::ConvertIOinGEOMObject( firstIObject(), testResult );
238 if (!testResult || CORBA::is_nil( aSelectedObject ))
241 myPoint = aSelectedObject;
242 myEditCurrentArgument->setText( GEOMBase::GetName( myPoint ) );
248 //=================================================================================
249 // function : LineEditReturnPressed()
251 //=================================================================================
252 void PrimitiveGUI_SphereDlg::LineEditReturnPressed()
254 QLineEdit* send = (QLineEdit*)sender();
255 if(send == GroupPoints->LineEdit1)
257 myEditCurrentArgument = send;
258 GEOMBase_Skeleton::LineEditReturnPressed();
263 //=================================================================================
264 // function : SetEditCurrentArgument()
266 //=================================================================================
267 void PrimitiveGUI_SphereDlg::SetEditCurrentArgument()
269 QPushButton* send = (QPushButton*)sender();
271 if(send == GroupPoints->PushButton1) {
272 GroupPoints->LineEdit1->setFocus();
273 myEditCurrentArgument = GroupPoints->LineEdit1;
274 globalSelection( GEOM_POINT );
275 SelectionIntoArgument();
280 //=================================================================================
281 // function : ActivateThisDialog()
283 //=================================================================================
284 void PrimitiveGUI_SphereDlg::ActivateThisDialog()
286 GEOMBase_Skeleton::ActivateThisDialog();
287 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
288 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
290 ConstructorsClicked( getConstructorId() );
294 //=================================================================================
295 // function : DeactivateActiveDialog()
296 // purpose : public slot to deactivate if active
297 //=================================================================================
298 void PrimitiveGUI_SphereDlg::DeactivateActiveDialog()
300 GEOMBase_Skeleton::DeactivateActiveDialog();
304 //=================================================================================
305 // function : enterEvent()
307 //=================================================================================
308 void PrimitiveGUI_SphereDlg::enterEvent(QEvent* e)
310 if ( !GroupConstructors->isEnabled() )
311 ActivateThisDialog();
315 //=================================================================================
316 // function : ValueChangedInSpinBox()
318 //=================================================================================
319 void PrimitiveGUI_SphereDlg::ValueChangedInSpinBox()
325 //=================================================================================
326 // function : createOperation
328 //=================================================================================
329 GEOM::GEOM_IOperations_ptr PrimitiveGUI_SphereDlg::createOperation()
331 return getGeomEngine()->GetI3DPrimOperations( getStudyId() );
335 //=================================================================================
336 // function : isValid
338 //=================================================================================
339 bool PrimitiveGUI_SphereDlg::isValid( QString& msg )
341 return getConstructorId() == 0 ? !myPoint->_is_nil() : true;
344 //=================================================================================
345 // function : execute
347 //=================================================================================
348 bool PrimitiveGUI_SphereDlg::execute( ObjectList& objects )
352 GEOM::GEOM_Object_var anObj;
354 switch ( getConstructorId() )
358 if ( !CORBA::is_nil( myPoint ) ) {
359 anObj = GEOM::GEOM_I3DPrimOperations::_narrow( getOperation() )->MakeSpherePntR( myPoint, getRadius() );
366 anObj = GEOM::GEOM_I3DPrimOperations::_narrow( getOperation() )->MakeSphereR( getRadius() );
372 if ( !anObj->_is_nil() )
373 objects.push_back( anObj._retn() );
378 //=================================================================================
379 // function : closeEvent
381 //=================================================================================
382 void PrimitiveGUI_SphereDlg::closeEvent( QCloseEvent* e )
384 //myGeomGUI->SetState( -1 );
385 GEOMBase_Skeleton::closeEvent( e );
390 //=================================================================================
391 // function : getRadius()
393 //=================================================================================
394 double PrimitiveGUI_SphereDlg::getRadius() const
396 int aConstructorId = getConstructorId();
397 if (aConstructorId == 0)
398 return GroupPoints->SpinBox_DX->GetValue();
399 else if (aConstructorId == 1)
400 return GroupDimensions->SpinBox_DX->GetValue();