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"
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_CylinderDlg()
46 // purpose : Constructs a PrimitiveGUI_CylinderDlg 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_CylinderDlg::PrimitiveGUI_CylinderDlg(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_CYLINDER_PV")));
57 QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_CYLINDER_DXYZ")));
58 QPixmap image2(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_SELECT")));
60 setCaption(tr("GEOM_CYLINDER_TITLE"));
62 /***************************************************************/
63 GroupConstructors->setTitle(tr("GEOM_CYLINDER"));
64 RadioButton1->setPixmap(image0);
65 RadioButton2->setPixmap(image1);
66 RadioButton3->close(TRUE);
68 GroupPoints = new DlgRef_2Sel2Spin(this, "GroupPoints");
69 GroupPoints->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
70 GroupPoints->TextLabel1->setText(tr("GEOM_BASE_POINT"));
71 GroupPoints->TextLabel2->setText(tr("GEOM_VECTOR"));
72 GroupPoints->TextLabel3->setText(tr("GEOM_RADIUS"));
73 GroupPoints->TextLabel4->setText(tr("GEOM_HEIGHT"));
74 GroupPoints->PushButton1->setPixmap(image2);
75 GroupPoints->PushButton2->setPixmap(image2);
77 GroupDimensions = new DlgRef_2Spin(this, "GroupDimensions");
78 GroupDimensions->GroupBox1->setTitle(tr("GEOM_BOX_OBJ"));
79 GroupDimensions->TextLabel1->setText(tr("GEOM_RADIUS"));
80 GroupDimensions->TextLabel2->setText(tr("GEOM_HEIGHT"));
82 Layout1->addWidget(GroupPoints, 2, 0);
83 Layout1->addWidget(GroupDimensions, 2, 0);
84 /***************************************************************/
86 setHelpFileName("cylinder.htm");
92 //=================================================================================
93 // function : ~PrimitiveGUI_CylinderDlg()
94 // purpose : Destroys the object and frees any allocated resources
95 //=================================================================================
96 PrimitiveGUI_CylinderDlg::~PrimitiveGUI_CylinderDlg()
98 // no need to delete child widgets, Qt does it all for us
102 //=================================================================================
105 //=================================================================================
106 void PrimitiveGUI_CylinderDlg::Init()
109 myEditCurrentArgument = GroupPoints->LineEdit1;
110 GroupPoints->LineEdit1->setReadOnly( true );
111 GroupPoints->LineEdit2->setReadOnly( true );
113 myPoint = myDir = GEOM::GEOM_Object::_nil();
115 /* Get setting of step value from file configuration */
116 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
117 double step = resMgr->doubleValue( "Geometry", "SettingsGeomStep", 100);
119 /* min, max, step and decimals for spin boxes & initial values */
120 /* First constructor : radius */
121 GroupPoints->SpinBox_DX->RangeStepAndValidator(0.001, COORD_MAX, step, 3);
122 /* First constructor : algebric height */
123 GroupPoints->SpinBox_DY->RangeStepAndValidator(COORD_MIN, COORD_MAX, step, 3);
124 /* Second constructor : radius */
125 GroupDimensions->SpinBox_DX->RangeStepAndValidator(0.001, COORD_MAX, step, 3);
126 /* Second constructor : algebric height */
127 GroupDimensions->SpinBox_DY->RangeStepAndValidator(COORD_MIN, COORD_MAX, step, 3);
129 GroupPoints->SpinBox_DX->SetValue(100.0);
130 GroupPoints->SpinBox_DY->SetValue(300.0);
131 GroupDimensions->SpinBox_DX->SetValue(100.0);
132 GroupDimensions->SpinBox_DY->SetValue(300.0);
134 /* signals and slots connections */
135 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
136 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
137 connect(GroupConstructors, SIGNAL(clicked(int)), this, SLOT(ConstructorsClicked(int)));
139 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
140 connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
142 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
143 connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
145 connect(GroupPoints->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
146 connect(GroupPoints->SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
147 connect(GroupDimensions->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
148 connect(GroupDimensions->SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
150 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_DX, SLOT(SetStep(double)));
151 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_DY, SLOT(SetStep(double)));
152 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DX, SLOT(SetStep(double)));
153 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DY, SLOT(SetStep(double)));
155 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
156 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
158 initName( tr( "GEOM_CYLINDER" ) );
159 ConstructorsClicked(0);
163 //=================================================================================
164 // function : ConstructorsClicked()
165 // purpose : Radio button management
166 //=================================================================================
167 void PrimitiveGUI_CylinderDlg::ConstructorsClicked(int constructorId)
169 disconnect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), 0, this, 0);
171 switch(constructorId)
175 globalSelection( GEOM_POINT );
177 GroupDimensions->hide();
181 myEditCurrentArgument = GroupPoints->LineEdit1;
182 GroupPoints->LineEdit1->setText(tr(""));
183 GroupPoints->LineEdit2->setText(tr(""));
184 myPoint = myDir = GEOM::GEOM_Object::_nil();
186 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
187 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
194 GroupDimensions->show();
203 //=================================================================================
204 // function : ClickOnOk()
206 //=================================================================================
207 void PrimitiveGUI_CylinderDlg::ClickOnOk()
209 if ( ClickOnApply() )
214 //=================================================================================
215 // function : ClickOnApply()
217 //=================================================================================
218 bool PrimitiveGUI_CylinderDlg::ClickOnApply()
224 ConstructorsClicked( getConstructorId() );
229 //=======================================================================
230 // function : ClickOnCancel()
232 //=======================================================================
233 void PrimitiveGUI_CylinderDlg::ClickOnCancel()
235 GEOMBase_Skeleton::ClickOnCancel();
239 //=================================================================================
240 // function : SelectionIntoArgument()
241 // purpose : Called when selection as changed or other case
242 //=================================================================================
243 void PrimitiveGUI_CylinderDlg::SelectionIntoArgument()
245 if ( getConstructorId() != 0 )
248 myEditCurrentArgument->setText("");
250 if(IObjectCount() != 1)
252 if(myEditCurrentArgument == GroupPoints->LineEdit1)
253 myPoint = GEOM::GEOM_Object::_nil();
254 else if (myEditCurrentArgument == GroupPoints->LineEdit2)
255 myDir = GEOM::GEOM_Object::_nil();
260 Standard_Boolean testResult = Standard_False;
261 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( firstIObject(), testResult );
263 if(!testResult || CORBA::is_nil( aSelectedObject ))
266 if (myEditCurrentArgument == GroupPoints->LineEdit1)
267 myPoint = aSelectedObject;
268 else if (myEditCurrentArgument == GroupPoints->LineEdit2)
269 myDir = aSelectedObject;
271 myEditCurrentArgument->setText( GEOMBase::GetName( aSelectedObject ) );
277 //=================================================================================
278 // function : SetEditCurrentArgument()
280 //=================================================================================
281 void PrimitiveGUI_CylinderDlg::SetEditCurrentArgument()
283 QPushButton* send = (QPushButton*)sender();
285 if(send == GroupPoints->PushButton1) {
286 myEditCurrentArgument = GroupPoints->LineEdit1;
287 globalSelection( GEOM_POINT );
289 else if(send == GroupPoints->PushButton2) {
290 myEditCurrentArgument = GroupPoints->LineEdit2;
291 globalSelection( GEOM_LINE );
294 myEditCurrentArgument->setFocus();
295 SelectionIntoArgument();
299 //=================================================================================
300 // function : LineEditReturnPressed()
302 //=================================================================================
303 void PrimitiveGUI_CylinderDlg::LineEditReturnPressed()
305 QLineEdit* send = (QLineEdit*)sender();
306 if(send == GroupPoints->LineEdit1 ||
307 send == GroupPoints->LineEdit2)
309 myEditCurrentArgument = send;
310 GEOMBase_Skeleton::LineEditReturnPressed();
315 //=================================================================================
316 // function : ActivateThisDialog()
318 //=================================================================================
319 void PrimitiveGUI_CylinderDlg::ActivateThisDialog()
321 GEOMBase_Skeleton::ActivateThisDialog();
322 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
323 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
325 ConstructorsClicked( getConstructorId() );
329 //=================================================================================
330 // function : enterEvent()
332 //=================================================================================
333 void PrimitiveGUI_CylinderDlg::enterEvent(QEvent* e)
335 if ( !GroupConstructors->isEnabled() )
336 ActivateThisDialog();
340 //=================================================================================
341 // function : DeactivateActiveDialog()
342 // purpose : public slot to deactivate if active
343 //=================================================================================
344 void PrimitiveGUI_CylinderDlg::DeactivateActiveDialog()
346 GEOMBase_Skeleton::DeactivateActiveDialog();
350 //=================================================================================
351 // function : ValueChangedInSpinBox
353 //=================================================================================
354 void PrimitiveGUI_CylinderDlg::ValueChangedInSpinBox( )
360 //=================================================================================
361 // function : createOperation
363 //=================================================================================
364 GEOM::GEOM_IOperations_ptr PrimitiveGUI_CylinderDlg::createOperation()
366 return getGeomEngine()->GetI3DPrimOperations( getStudyId() );
370 //=================================================================================
371 // function : isValid
373 //=================================================================================
374 bool PrimitiveGUI_CylinderDlg::isValid( QString& msg )
376 return getConstructorId() == 0 ? !(myPoint->_is_nil() || myDir->_is_nil() ) : true;
379 //=================================================================================
380 // function : execute
382 //=================================================================================
383 bool PrimitiveGUI_CylinderDlg::execute( ObjectList& objects )
387 GEOM::GEOM_Object_var anObj;
389 switch ( getConstructorId() )
393 if ( !CORBA::is_nil( myPoint ) && !CORBA::is_nil( myDir )) {
394 anObj = GEOM::GEOM_I3DPrimOperations::_narrow( getOperation() )->MakeCylinderPntVecRH(myPoint, myDir, getRadius(), getHeight());
401 anObj = GEOM::GEOM_I3DPrimOperations::_narrow( getOperation() )->MakeCylinderRH(getRadius(), getHeight());
408 if ( !anObj->_is_nil() )
409 objects.push_back( anObj._retn() );
414 //=================================================================================
415 // function : closeEvent
417 //=================================================================================
418 void PrimitiveGUI_CylinderDlg::closeEvent( QCloseEvent* e )
420 GEOMBase_Skeleton::closeEvent( e );
424 //=================================================================================
425 // function : getRadius()
427 //=================================================================================
428 double PrimitiveGUI_CylinderDlg::getRadius() const
430 int aConstructorId = getConstructorId();
431 if (aConstructorId == 0)
432 return GroupPoints->SpinBox_DX->GetValue();
433 else if (aConstructorId == 1)
434 return GroupDimensions->SpinBox_DX->GetValue();
439 //=================================================================================
440 // function : getHeight()
442 //=================================================================================
443 double PrimitiveGUI_CylinderDlg::getHeight() const
445 int aConstructorId = getConstructorId();
446 if (aConstructorId == 0)
447 return GroupPoints->SpinBox_DY->GetValue();
448 else if (aConstructorId == 1)
449 return GroupDimensions->SpinBox_DY->GetValue();