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 "QAD_Config.h"
33 #include "QAD_Desktop.h"
35 #include "GEOMImpl_Types.hxx"
37 #include "utilities.h"
41 //=================================================================================
42 // class : PrimitiveGUI_SphereDlg()
43 // purpose : Constructs a PrimitiveGUI_SphereDlg which is a child of 'parent', with the
44 // name 'name' and widget flags set to 'f'.
45 // The dialog will by default be modeless, unless you set 'modal' to
46 // TRUE to construct a modal dialog.
47 //=================================================================================
48 PrimitiveGUI_SphereDlg::PrimitiveGUI_SphereDlg(QWidget* parent, const char* name, SALOME_Selection* Sel, bool modal, WFlags fl)
49 :GEOMBase_Skeleton(parent, name, Sel, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
51 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_SPHERE_P")));
52 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_SPHERE_DXYZ")));
53 QPixmap image2(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_SELECT")));
55 setCaption(tr("GEOM_SPHERE_TITLE"));
57 /***************************************************************/
58 GroupConstructors->setTitle(tr("GEOM_SPHERE"));
59 RadioButton1->setPixmap(image0);
60 RadioButton2->setPixmap(image1);
61 RadioButton3->close(TRUE);
63 GroupPoints = new DlgRef_1Sel1Spin(this, "GroupPoints");
64 GroupPoints->GroupBox1->setTitle(tr("GEOM_SPHERE_CR"));
65 GroupPoints->TextLabel1->setText(tr("GEOM_CENTER"));
66 GroupPoints->TextLabel2->setText(tr("GEOM_RADIUS"));
67 GroupPoints->PushButton1->setPixmap(image2);
69 GroupDimensions = new DlgRef_1Spin(this, "GroupDimensions");
70 GroupDimensions->GroupBox1->setTitle(tr("GEOM_SPHERE_RO"));
71 GroupDimensions->TextLabel1->setText(tr("GEOM_RADIUS"));
73 Layout1->addWidget(GroupPoints, 2, 0);
74 Layout1->addWidget(GroupDimensions, 2, 0);
75 /***************************************************************/
81 //=================================================================================
82 // function : ~PrimitiveGUI_SphereDlg()
83 // purpose : Destroys the object and frees any allocated resources
84 //=================================================================================
85 PrimitiveGUI_SphereDlg::~PrimitiveGUI_SphereDlg()
87 /* no need to delete child widgets, Qt does it all for us */
91 //=================================================================================
94 //=================================================================================
95 void PrimitiveGUI_SphereDlg::Init()
98 myEditCurrentArgument = GroupPoints->LineEdit1;
99 GroupPoints->LineEdit1->setReadOnly( true );
101 myPoint = GEOM::GEOM_Object::_nil();
103 /* Get setting of step value from file configuration */
104 QString St = QAD_CONFIG->getSetting("Geometry:SettingsGeomStep");
105 double step = St.toDouble();
107 /* min, max, step and decimals for spin boxes */
108 GroupPoints->SpinBox_DX->RangeStepAndValidator(0.001, 999.999, step, 3);
109 GroupDimensions->SpinBox_DX->RangeStepAndValidator(0.001, 999.999, step, 3);
110 GroupPoints->SpinBox_DX->SetValue(100.0);
111 GroupDimensions->SpinBox_DX->SetValue(100.0);
113 /* signals and slots connections */
114 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
115 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
116 connect(GroupConstructors, SIGNAL(clicked(int)), this, SLOT(ConstructorsClicked(int)));
118 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
119 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
121 connect(GroupDimensions->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
122 connect(GroupPoints->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
124 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_DX, SLOT(SetStep(double)));
125 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DX, SLOT(SetStep(double)));
127 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
129 initName(tr("GEOM_SPHERE"));
130 ConstructorsClicked(0);
134 //=================================================================================
135 // function : ConstructorsClicked()
136 // purpose : Radio button management
137 //=================================================================================
138 void PrimitiveGUI_SphereDlg::ConstructorsClicked(int constructorId)
140 disconnect(mySelection, 0, this, 0);
142 switch (constructorId)
146 globalSelection( GEOM_POINT );
147 GroupDimensions->hide();
151 myEditCurrentArgument = GroupPoints->LineEdit1;
152 GroupPoints->LineEdit1->setText("");
153 myPoint = GEOM::GEOM_Object::_nil();
155 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
162 GroupDimensions->show();
171 //=================================================================================
172 // function : ClickOnOk()
174 //=================================================================================
175 void PrimitiveGUI_SphereDlg::ClickOnOk()
177 if ( ClickOnApply() )
182 //=================================================================================
183 // function : ClickOnApply()
185 //=================================================================================
186 bool PrimitiveGUI_SphereDlg::ClickOnApply()
192 ConstructorsClicked( getConstructorId() );
198 //=======================================================================
199 // function : ClickOnCancel()
201 //=======================================================================
202 void PrimitiveGUI_SphereDlg::ClickOnCancel()
204 GEOMBase_Skeleton::ClickOnCancel();
208 //=================================================================================
209 // function : SelectionIntoArgument()
210 // purpose : Called when selection as changed or other case
211 //=================================================================================
212 void PrimitiveGUI_SphereDlg::SelectionIntoArgument()
214 if ( getConstructorId() != 0 )
217 myEditCurrentArgument->setText("");
219 if(mySelection->IObjectCount() != 1)
221 myPoint = GEOM::GEOM_Object::_nil();
226 Standard_Boolean testResult = Standard_False;
227 GEOM::GEOM_Object_ptr aSelectedObject = GEOMBase::ConvertIOinGEOMObject( mySelection->firstIObject(), testResult );
229 if (!testResult || CORBA::is_nil( aSelectedObject ))
232 myPoint = aSelectedObject;
233 myEditCurrentArgument->setText( GEOMBase::GetName( myPoint ) );
239 //=================================================================================
240 // function : LineEditReturnPressed()
242 //=================================================================================
243 void PrimitiveGUI_SphereDlg::LineEditReturnPressed()
245 QLineEdit* send = (QLineEdit*)sender();
246 if(send == GroupPoints->LineEdit1)
248 myEditCurrentArgument = send;
249 GEOMBase_Skeleton::LineEditReturnPressed();
254 //=================================================================================
255 // function : SetEditCurrentArgument()
257 //=================================================================================
258 void PrimitiveGUI_SphereDlg::SetEditCurrentArgument()
260 QPushButton* send = (QPushButton*)sender();
262 if(send == GroupPoints->PushButton1) {
263 GroupPoints->LineEdit1->setFocus();
264 myEditCurrentArgument = GroupPoints->LineEdit1;
265 globalSelection( GEOM_POINT );
266 SelectionIntoArgument();
271 //=================================================================================
272 // function : ActivateThisDialog()
274 //=================================================================================
275 void PrimitiveGUI_SphereDlg::ActivateThisDialog()
277 GEOMBase_Skeleton::ActivateThisDialog();
278 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
280 ConstructorsClicked( getConstructorId() );
284 //=================================================================================
285 // function : DeactivateActiveDialog()
286 // purpose : public slot to deactivate if active
287 //=================================================================================
288 void PrimitiveGUI_SphereDlg::DeactivateActiveDialog()
290 GEOMBase_Skeleton::DeactivateActiveDialog();
294 //=================================================================================
295 // function : enterEvent()
297 //=================================================================================
298 void PrimitiveGUI_SphereDlg::enterEvent(QEvent* e)
300 if ( !GroupConstructors->isEnabled() )
301 ActivateThisDialog();
305 //=================================================================================
306 // function : ValueChangedInSpinBox()
308 //=================================================================================
309 void PrimitiveGUI_SphereDlg::ValueChangedInSpinBox()
315 //=================================================================================
316 // function : createOperation
318 //=================================================================================
319 GEOM::GEOM_IOperations_ptr PrimitiveGUI_SphereDlg::createOperation()
321 return getGeomEngine()->GetI3DPrimOperations( getStudyId() );
325 //=================================================================================
326 // function : isValid
328 //=================================================================================
329 bool PrimitiveGUI_SphereDlg::isValid( QString& msg )
331 return getConstructorId() == 0 ? !myPoint->_is_nil() : true;
334 //=================================================================================
335 // function : execute
337 //=================================================================================
338 bool PrimitiveGUI_SphereDlg::execute( ObjectList& objects )
342 GEOM::GEOM_Object_var anObj;
344 switch ( getConstructorId() )
348 if ( !CORBA::is_nil( myPoint ) ) {
349 anObj = GEOM::GEOM_I3DPrimOperations::_narrow( getOperation() )->MakeSpherePntR( myPoint, getRadius() );
356 anObj = GEOM::GEOM_I3DPrimOperations::_narrow( getOperation() )->MakeSphereR( getRadius() );
362 if ( !anObj->_is_nil() )
363 objects.push_back( anObj._retn() );
368 //=================================================================================
369 // function : closeEvent
371 //=================================================================================
372 void PrimitiveGUI_SphereDlg::closeEvent( QCloseEvent* e )
374 myGeomGUI->SetState( -1 );
375 GEOMBase_Skeleton::closeEvent( e );
380 //=================================================================================
381 // function : getRadius()
383 //=================================================================================
384 double PrimitiveGUI_SphereDlg::getRadius() const
386 int aConstructorId = getConstructorId();
387 if (aConstructorId == 0)
388 return GroupPoints->SpinBox_DX->GetValue();
389 else if (aConstructorId == 1)
390 return GroupDimensions->SpinBox_DX->GetValue();