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"
30 #include "DlgRef_1Sel1Spin.h"
31 #include "DlgRef_1Spin.h"
32 #include "DlgRef_SpinBox.h"
34 #include "GeometryGUI.h"
37 #include "SUIT_ResourceMgr.h"
38 #include "SUIT_Session.h"
39 #include "SalomeApp_Application.h"
40 #include "LightApp_SelectionMgr.h"
42 #include "GEOMImpl_Types.hxx"
46 //=================================================================================
47 // class : PrimitiveGUI_SphereDlg()
48 // purpose : Constructs a PrimitiveGUI_SphereDlg which is a child of 'parent', with the
49 // name 'name' and widget flags set to 'f'.
50 // The dialog will by default be modeless, unless you set 'modal' to
51 // TRUE to construct a modal dialog.
52 //=================================================================================
53 PrimitiveGUI_SphereDlg::PrimitiveGUI_SphereDlg(GeometryGUI* theGeometryGUI, QWidget* parent,
54 const char* name, bool modal, Qt::WindowFlags fl)
55 :GEOMBase_Skeleton(theGeometryGUI, parent, name, modal, Qt::WindowTitleHint | Qt::WindowSystemMenuHint)
57 QPixmap image0(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_SPHERE_P")));
58 QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_SPHERE_DXYZ")));
59 QPixmap image2(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_SELECT")));
61 setWindowTitle(tr("GEOM_SPHERE_TITLE"));
63 /***************************************************************/
64 GroupConstructors->setTitle(tr("GEOM_SPHERE"));
65 RadioButton1->setIcon(image0);
66 RadioButton2->setIcon(image1);
67 RadioButton3->setAttribute( Qt::WA_DeleteOnClose );
68 RadioButton3->close();
70 GroupPoints = new DlgRef_1Sel1Spin(this, "GroupPoints");
71 GroupPoints->GroupBox1->setTitle(tr("GEOM_SPHERE_CR"));
72 GroupPoints->TextLabel1->setText(tr("GEOM_CENTER"));
73 GroupPoints->TextLabel2->setText(tr("GEOM_RADIUS"));
74 GroupPoints->PushButton1->setIcon(image2);
76 GroupDimensions = new DlgRef_1Spin(this, "GroupDimensions");
77 GroupDimensions->GroupBox1->setTitle(tr("GEOM_SPHERE_RO"));
78 GroupDimensions->TextLabel1->setText(tr("GEOM_RADIUS"));
80 gridLayout1->addWidget(GroupPoints, 2, 0);
81 gridLayout1->addWidget(GroupDimensions, 2, 0);
82 /***************************************************************/
84 setHelpFileName("sphere.htm");
90 //=================================================================================
91 // function : ~PrimitiveGUI_SphereDlg()
92 // purpose : Destroys the object and frees any allocated resources
93 //=================================================================================
94 PrimitiveGUI_SphereDlg::~PrimitiveGUI_SphereDlg()
96 /* no need to delete child widgets, Qt does it all for us */
100 //=================================================================================
103 //=================================================================================
104 void PrimitiveGUI_SphereDlg::Init()
107 myEditCurrentArgument = GroupPoints->LineEdit1;
108 GroupPoints->LineEdit1->setReadOnly( true );
110 myPoint = GEOM::GEOM_Object::_nil();
112 /* Get setting of step value from file configuration */
113 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
114 double step = resMgr->doubleValue( "Geometry", "SettingsGeomStep", 100);
116 /* min, max, step and decimals for spin boxes */
117 GroupPoints->SpinBox_DX->RangeStepAndValidator(0.001, COORD_MAX, step, 3);
118 GroupDimensions->SpinBox_DX->RangeStepAndValidator(0.001, COORD_MAX, step, 3);
119 GroupPoints->SpinBox_DX->SetValue(100.0);
120 GroupDimensions->SpinBox_DX->SetValue(100.0);
122 /* signals and slots connections */
123 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
124 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
125 connect(GroupConstructors, SIGNAL(clicked(int)), this, SLOT(ConstructorsClicked(int)));
127 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
128 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
130 connect(GroupDimensions->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
131 connect(GroupPoints->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
133 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_DX, SLOT(SetStep(double)));
134 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DX, SLOT(SetStep(double)));
136 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
137 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
139 initName(tr("GEOM_SPHERE").toStdString().c_str());
140 ConstructorsClicked(0);
144 //=================================================================================
145 // function : ConstructorsClicked()
146 // purpose : Radio button management
147 //=================================================================================
148 void PrimitiveGUI_SphereDlg::ConstructorsClicked(int constructorId)
150 disconnect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), 0, this, 0);
152 switch (constructorId)
156 globalSelection( GEOM_POINT );
157 GroupDimensions->hide();
161 myEditCurrentArgument = GroupPoints->LineEdit1;
162 GroupPoints->LineEdit1->setText("");
163 myPoint = GEOM::GEOM_Object::_nil();
165 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
166 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
173 GroupDimensions->show();
182 //=================================================================================
183 // function : ClickOnOk()
185 //=================================================================================
186 void PrimitiveGUI_SphereDlg::ClickOnOk()
188 if ( ClickOnApply() )
193 //=================================================================================
194 // function : ClickOnApply()
196 //=================================================================================
197 bool PrimitiveGUI_SphereDlg::ClickOnApply()
203 ConstructorsClicked( getConstructorId() );
209 //=======================================================================
210 // function : ClickOnCancel()
212 //=======================================================================
213 void PrimitiveGUI_SphereDlg::ClickOnCancel()
215 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 myPoint = aSelectedObject;
244 myEditCurrentArgument->setText( GEOMBase::GetName( myPoint ) );
250 //=================================================================================
251 // function : LineEditReturnPressed()
253 //=================================================================================
254 void PrimitiveGUI_SphereDlg::LineEditReturnPressed()
256 QLineEdit* send = (QLineEdit*)sender();
257 if(send == GroupPoints->LineEdit1)
259 myEditCurrentArgument = send;
260 GEOMBase_Skeleton::LineEditReturnPressed();
265 //=================================================================================
266 // function : SetEditCurrentArgument()
268 //=================================================================================
269 void PrimitiveGUI_SphereDlg::SetEditCurrentArgument()
271 QPushButton* send = (QPushButton*)sender();
273 if(send == GroupPoints->PushButton1) {
274 GroupPoints->LineEdit1->setFocus();
275 myEditCurrentArgument = GroupPoints->LineEdit1;
276 globalSelection( GEOM_POINT );
277 SelectionIntoArgument();
282 //=================================================================================
283 // function : ActivateThisDialog()
285 //=================================================================================
286 void PrimitiveGUI_SphereDlg::ActivateThisDialog()
288 GEOMBase_Skeleton::ActivateThisDialog();
289 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
290 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
292 ConstructorsClicked( getConstructorId() );
296 //=================================================================================
297 // function : DeactivateActiveDialog()
298 // purpose : public slot to deactivate if active
299 //=================================================================================
300 void PrimitiveGUI_SphereDlg::DeactivateActiveDialog()
302 GEOMBase_Skeleton::DeactivateActiveDialog();
306 //=================================================================================
307 // function : enterEvent()
309 //=================================================================================
310 void PrimitiveGUI_SphereDlg::enterEvent(QEvent* e)
312 if ( !GroupConstructors->isEnabled() )
313 ActivateThisDialog();
317 //=================================================================================
318 // function : ValueChangedInSpinBox()
320 //=================================================================================
321 void PrimitiveGUI_SphereDlg::ValueChangedInSpinBox()
327 //=================================================================================
328 // function : createOperation
330 //=================================================================================
331 GEOM::GEOM_IOperations_ptr PrimitiveGUI_SphereDlg::createOperation()
333 return getGeomEngine()->GetI3DPrimOperations( getStudyId() );
337 //=================================================================================
338 // function : isValid
340 //=================================================================================
341 bool PrimitiveGUI_SphereDlg::isValid( QString& msg )
343 return getConstructorId() == 0 ? !myPoint->_is_nil() : true;
346 //=================================================================================
347 // function : execute
349 //=================================================================================
350 bool PrimitiveGUI_SphereDlg::execute( ObjectList& objects )
354 GEOM::GEOM_Object_var anObj;
356 switch ( getConstructorId() )
360 if ( !CORBA::is_nil( myPoint ) ) {
361 anObj = GEOM::GEOM_I3DPrimOperations::_narrow( getOperation() )->MakeSpherePntR( myPoint, getRadius() );
368 anObj = GEOM::GEOM_I3DPrimOperations::_narrow( getOperation() )->MakeSphereR( getRadius() );
374 if ( !anObj->_is_nil() )
375 objects.push_back( anObj._retn() );
380 //=================================================================================
381 // function : closeEvent
383 //=================================================================================
384 void PrimitiveGUI_SphereDlg::closeEvent( QCloseEvent* e )
386 //myGeomGUI->SetState( -1 );
387 GEOMBase_Skeleton::closeEvent( e );
392 //=================================================================================
393 // function : getRadius()
395 //=================================================================================
396 double PrimitiveGUI_SphereDlg::getRadius() const
398 int aConstructorId = getConstructorId();
399 if (aConstructorId == 0)
400 return GroupPoints->SpinBox_DX->GetValue();
401 else if (aConstructorId == 1)
402 return GroupDimensions->SpinBox_DX->GetValue();