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_CylinderDlg.cxx
25 // Author : Lucien PIGNOLONI
29 #include "PrimitiveGUI_CylinderDlg.h"
30 #include "DlgRef_2Sel2Spin.h"
31 #include "DlgRef_2Spin.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_CylinderDlg()
48 // purpose : Constructs a PrimitiveGUI_CylinderDlg 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_CylinderDlg::PrimitiveGUI_CylinderDlg(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_CYLINDER_PV")));
58 QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_CYLINDER_DXYZ")));
59 QPixmap image2(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_SELECT")));
61 setWindowTitle(tr("GEOM_CYLINDER_TITLE"));
63 /***************************************************************/
64 GroupConstructors->setTitle(tr("GEOM_CYLINDER"));
65 RadioButton1->setIcon(image0);
66 RadioButton2->setIcon(image1);
67 RadioButton3->setAttribute( Qt::WA_DeleteOnClose );
68 RadioButton3->close();
70 GroupPoints = new DlgRef_2Sel2Spin(this, "GroupPoints");
71 GroupPoints->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
72 GroupPoints->TextLabel1->setText(tr("GEOM_BASE_POINT"));
73 GroupPoints->TextLabel2->setText(tr("GEOM_VECTOR"));
74 GroupPoints->TextLabel3->setText(tr("GEOM_RADIUS"));
75 GroupPoints->TextLabel4->setText(tr("GEOM_HEIGHT"));
76 GroupPoints->PushButton1->setIcon(image2);
77 GroupPoints->PushButton2->setIcon(image2);
79 GroupDimensions = new DlgRef_2Spin(this, "GroupDimensions");
80 GroupDimensions->GroupBox1->setTitle(tr("GEOM_BOX_OBJ"));
81 GroupDimensions->TextLabel1->setText(tr("GEOM_RADIUS"));
82 GroupDimensions->TextLabel2->setText(tr("GEOM_HEIGHT"));
84 gridLayout1->addWidget(GroupPoints, 2, 0);
85 gridLayout1->addWidget(GroupDimensions, 2, 0);
86 /***************************************************************/
88 setHelpFileName("cylinder.htm");
94 //=================================================================================
95 // function : ~PrimitiveGUI_CylinderDlg()
96 // purpose : Destroys the object and frees any allocated resources
97 //=================================================================================
98 PrimitiveGUI_CylinderDlg::~PrimitiveGUI_CylinderDlg()
100 // no need to delete child widgets, Qt does it all for us
104 //=================================================================================
107 //=================================================================================
108 void PrimitiveGUI_CylinderDlg::Init()
111 myEditCurrentArgument = GroupPoints->LineEdit1;
112 GroupPoints->LineEdit1->setReadOnly( true );
113 GroupPoints->LineEdit2->setReadOnly( true );
115 myPoint = myDir = GEOM::GEOM_Object::_nil();
117 /* Get setting of step value from file configuration */
118 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
119 double step = resMgr->doubleValue( "Geometry", "SettingsGeomStep", 100);
121 /* min, max, step and decimals for spin boxes & initial values */
122 /* First constructor : radius */
123 GroupPoints->SpinBox_DX->RangeStepAndValidator(0.001, COORD_MAX, step, 3);
124 /* First constructor : algebric height */
125 GroupPoints->SpinBox_DY->RangeStepAndValidator(COORD_MIN, COORD_MAX, step, 3);
126 /* Second constructor : radius */
127 GroupDimensions->SpinBox_DX->RangeStepAndValidator(0.001, COORD_MAX, step, 3);
128 /* Second constructor : algebric height */
129 GroupDimensions->SpinBox_DY->RangeStepAndValidator(COORD_MIN, COORD_MAX, step, 3);
131 GroupPoints->SpinBox_DX->SetValue(100.0);
132 GroupPoints->SpinBox_DY->SetValue(300.0);
133 GroupDimensions->SpinBox_DX->SetValue(100.0);
134 GroupDimensions->SpinBox_DY->SetValue(300.0);
136 /* signals and slots connections */
137 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
138 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
139 connect(GroupConstructors, SIGNAL(clicked(int)), this, SLOT(ConstructorsClicked(int)));
141 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
142 connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
144 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
145 connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
147 connect(GroupPoints->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
148 connect(GroupPoints->SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
149 connect(GroupDimensions->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
150 connect(GroupDimensions->SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
152 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_DX, SLOT(SetStep(double)));
153 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_DY, SLOT(SetStep(double)));
154 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DX, SLOT(SetStep(double)));
155 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DY, SLOT(SetStep(double)));
157 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
158 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
160 initName( tr( "GEOM_CYLINDER" ).toStdString().c_str() );
161 ConstructorsClicked(0);
165 //=================================================================================
166 // function : ConstructorsClicked()
167 // purpose : Radio button management
168 //=================================================================================
169 void PrimitiveGUI_CylinderDlg::ConstructorsClicked(int constructorId)
171 disconnect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), 0, this, 0);
173 switch(constructorId)
177 globalSelection( GEOM_POINT );
179 GroupDimensions->hide();
183 myEditCurrentArgument = GroupPoints->LineEdit1;
184 GroupPoints->LineEdit1->setText(tr(""));
185 GroupPoints->LineEdit2->setText(tr(""));
186 myPoint = myDir = GEOM::GEOM_Object::_nil();
188 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
189 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
196 GroupDimensions->show();
205 //=================================================================================
206 // function : ClickOnOk()
208 //=================================================================================
209 void PrimitiveGUI_CylinderDlg::ClickOnOk()
211 if ( ClickOnApply() )
216 //=================================================================================
217 // function : ClickOnApply()
219 //=================================================================================
220 bool PrimitiveGUI_CylinderDlg::ClickOnApply()
226 ConstructorsClicked( getConstructorId() );
231 //=======================================================================
232 // function : ClickOnCancel()
234 //=======================================================================
235 void PrimitiveGUI_CylinderDlg::ClickOnCancel()
237 GEOMBase_Skeleton::ClickOnCancel();
241 //=================================================================================
242 // function : SelectionIntoArgument()
243 // purpose : Called when selection as changed or other case
244 //=================================================================================
245 void PrimitiveGUI_CylinderDlg::SelectionIntoArgument()
247 if ( getConstructorId() != 0 )
250 myEditCurrentArgument->setText("");
252 if(IObjectCount() != 1)
254 if(myEditCurrentArgument == GroupPoints->LineEdit1)
255 myPoint = GEOM::GEOM_Object::_nil();
256 else if (myEditCurrentArgument == GroupPoints->LineEdit2)
257 myDir = GEOM::GEOM_Object::_nil();
262 Standard_Boolean testResult = Standard_False;
263 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( firstIObject(), testResult );
265 if(!testResult || CORBA::is_nil( aSelectedObject ))
268 if (myEditCurrentArgument == GroupPoints->LineEdit1)
269 myPoint = aSelectedObject;
270 else if (myEditCurrentArgument == GroupPoints->LineEdit2)
271 myDir = aSelectedObject;
273 myEditCurrentArgument->setText( GEOMBase::GetName( aSelectedObject ) );
279 //=================================================================================
280 // function : SetEditCurrentArgument()
282 //=================================================================================
283 void PrimitiveGUI_CylinderDlg::SetEditCurrentArgument()
285 QPushButton* send = (QPushButton*)sender();
287 if(send == GroupPoints->PushButton1) {
288 myEditCurrentArgument = GroupPoints->LineEdit1;
289 globalSelection( GEOM_POINT );
291 else if(send == GroupPoints->PushButton2) {
292 myEditCurrentArgument = GroupPoints->LineEdit2;
293 globalSelection( GEOM_LINE );
296 myEditCurrentArgument->setFocus();
297 SelectionIntoArgument();
301 //=================================================================================
302 // function : LineEditReturnPressed()
304 //=================================================================================
305 void PrimitiveGUI_CylinderDlg::LineEditReturnPressed()
307 QLineEdit* send = (QLineEdit*)sender();
308 if(send == GroupPoints->LineEdit1 ||
309 send == GroupPoints->LineEdit2)
311 myEditCurrentArgument = send;
312 GEOMBase_Skeleton::LineEditReturnPressed();
317 //=================================================================================
318 // function : ActivateThisDialog()
320 //=================================================================================
321 void PrimitiveGUI_CylinderDlg::ActivateThisDialog()
323 GEOMBase_Skeleton::ActivateThisDialog();
324 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
325 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
327 ConstructorsClicked( getConstructorId() );
331 //=================================================================================
332 // function : enterEvent()
334 //=================================================================================
335 void PrimitiveGUI_CylinderDlg::enterEvent(QEvent* e)
337 if ( !GroupConstructors->isEnabled() )
338 ActivateThisDialog();
342 //=================================================================================
343 // function : DeactivateActiveDialog()
344 // purpose : public slot to deactivate if active
345 //=================================================================================
346 void PrimitiveGUI_CylinderDlg::DeactivateActiveDialog()
348 GEOMBase_Skeleton::DeactivateActiveDialog();
352 //=================================================================================
353 // function : ValueChangedInSpinBox
355 //=================================================================================
356 void PrimitiveGUI_CylinderDlg::ValueChangedInSpinBox( )
362 //=================================================================================
363 // function : createOperation
365 //=================================================================================
366 GEOM::GEOM_IOperations_ptr PrimitiveGUI_CylinderDlg::createOperation()
368 return getGeomEngine()->GetI3DPrimOperations( getStudyId() );
372 //=================================================================================
373 // function : isValid
375 //=================================================================================
376 bool PrimitiveGUI_CylinderDlg::isValid( QString& msg )
378 return getConstructorId() == 0 ? !(myPoint->_is_nil() || myDir->_is_nil() ) : true;
381 //=================================================================================
382 // function : execute
384 //=================================================================================
385 bool PrimitiveGUI_CylinderDlg::execute( ObjectList& objects )
389 GEOM::GEOM_Object_var anObj;
391 switch ( getConstructorId() )
395 if ( !CORBA::is_nil( myPoint ) && !CORBA::is_nil( myDir )) {
396 anObj = GEOM::GEOM_I3DPrimOperations::_narrow( getOperation() )->MakeCylinderPntVecRH(myPoint, myDir, getRadius(), getHeight());
403 anObj = GEOM::GEOM_I3DPrimOperations::_narrow( getOperation() )->MakeCylinderRH(getRadius(), getHeight());
410 if ( !anObj->_is_nil() )
411 objects.push_back( anObj._retn() );
416 //=================================================================================
417 // function : closeEvent
419 //=================================================================================
420 void PrimitiveGUI_CylinderDlg::closeEvent( QCloseEvent* e )
422 GEOMBase_Skeleton::closeEvent( e );
426 //=================================================================================
427 // function : getRadius()
429 //=================================================================================
430 double PrimitiveGUI_CylinderDlg::getRadius() const
432 int aConstructorId = getConstructorId();
433 if (aConstructorId == 0)
434 return GroupPoints->SpinBox_DX->GetValue();
435 else if (aConstructorId == 1)
436 return GroupDimensions->SpinBox_DX->GetValue();
441 //=================================================================================
442 // function : getHeight()
444 //=================================================================================
445 double PrimitiveGUI_CylinderDlg::getHeight() const
447 int aConstructorId = getConstructorId();
448 if (aConstructorId == 0)
449 return GroupPoints->SpinBox_DY->GetValue();
450 else if (aConstructorId == 1)
451 return GroupDimensions->SpinBox_DY->GetValue();