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_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 "SalomeApp_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, const char* name, bool modal, WFlags fl)
52 :GEOMBase_Skeleton(parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu), myGeometryGUI(theGeometryGUI)
54 QPixmap image0(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_CYLINDER_PV")));
55 QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_CYLINDER_DXYZ")));
56 QPixmap image2(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_SELECT")));
58 setCaption(tr("GEOM_CYLINDER_TITLE"));
60 /***************************************************************/
61 GroupConstructors->setTitle(tr("GEOM_CYLINDER"));
62 RadioButton1->setPixmap(image0);
63 RadioButton2->setPixmap(image1);
64 RadioButton3->close(TRUE);
66 GroupPoints = new DlgRef_2Sel2Spin(this, "GroupPoints");
67 GroupPoints->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
68 GroupPoints->TextLabel1->setText(tr("GEOM_BASE_POINT"));
69 GroupPoints->TextLabel2->setText(tr("GEOM_VECTOR"));
70 GroupPoints->TextLabel3->setText(tr("GEOM_RADIUS"));
71 GroupPoints->TextLabel4->setText(tr("GEOM_HEIGHT"));
72 GroupPoints->PushButton1->setPixmap(image2);
73 GroupPoints->PushButton2->setPixmap(image2);
75 GroupDimensions = new DlgRef_2Spin(this, "GroupDimensions");
76 GroupDimensions->GroupBox1->setTitle(tr("GEOM_BOX_OBJ"));
77 GroupDimensions->TextLabel1->setText(tr("GEOM_RADIUS"));
78 GroupDimensions->TextLabel2->setText(tr("GEOM_HEIGHT"));
80 Layout1->addWidget(GroupPoints, 2, 0);
81 Layout1->addWidget(GroupDimensions, 2, 0);
82 /***************************************************************/
88 //=================================================================================
89 // function : ~PrimitiveGUI_CylinderDlg()
90 // purpose : Destroys the object and frees any allocated resources
91 //=================================================================================
92 PrimitiveGUI_CylinderDlg::~PrimitiveGUI_CylinderDlg()
94 // no need to delete child widgets, Qt does it all for us
98 //=================================================================================
101 //=================================================================================
102 void PrimitiveGUI_CylinderDlg::Init()
105 myEditCurrentArgument = GroupPoints->LineEdit1;
106 GroupPoints->LineEdit1->setReadOnly( true );
107 GroupPoints->LineEdit2->setReadOnly( true );
109 myPoint = myDir = GEOM::GEOM_Object::_nil();
111 /* Get setting of step value from file configuration */
112 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
113 double step = resMgr->doubleValue( "Geometry", "SettingsGeomStep", 100);
115 /* min, max, step and decimals for spin boxes & initial values */
116 /* First constructor : radius */
117 GroupPoints->SpinBox_DX->RangeStepAndValidator(0.001, 999.999, step, 3);
118 /* First constructor : algebric height */
119 GroupPoints->SpinBox_DY->RangeStepAndValidator(-999.999, 999.999, step, 3);
120 /* Second constructor : radius */
121 GroupDimensions->SpinBox_DX->RangeStepAndValidator(0.001, 999.999, step, 3);
122 /* Second constructor : algebric height */
123 GroupDimensions->SpinBox_DY->RangeStepAndValidator(-999.999, 999.999, step, 3);
125 GroupPoints->SpinBox_DX->SetValue(100.0);
126 GroupPoints->SpinBox_DY->SetValue(300.0);
127 GroupDimensions->SpinBox_DX->SetValue(100.0);
128 GroupDimensions->SpinBox_DY->SetValue(300.0);
130 /* signals and slots connections */
131 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
132 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
133 connect(GroupConstructors, SIGNAL(clicked(int)), this, SLOT(ConstructorsClicked(int)));
135 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
136 connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
138 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
139 connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
141 connect(GroupPoints->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
142 connect(GroupPoints->SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
143 connect(GroupDimensions->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
144 connect(GroupDimensions->SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
146 connect(myGeometryGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_DX, SLOT(SetStep(double)));
147 connect(myGeometryGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_DY, SLOT(SetStep(double)));
148 connect(myGeometryGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DX, SLOT(SetStep(double)));
149 connect(myGeometryGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DY, SLOT(SetStep(double)));
151 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
152 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
154 initName( tr( "GEOM_CYLINDER" ) );
155 ConstructorsClicked(0);
159 //=================================================================================
160 // function : ConstructorsClicked()
161 // purpose : Radio button management
162 //=================================================================================
163 void PrimitiveGUI_CylinderDlg::ConstructorsClicked(int constructorId)
165 disconnect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), 0, this, 0);
167 switch(constructorId)
171 globalSelection( GEOM_POINT );
173 GroupDimensions->hide();
177 myEditCurrentArgument = GroupPoints->LineEdit1;
178 GroupPoints->LineEdit1->setText(tr(""));
179 GroupPoints->LineEdit2->setText(tr(""));
180 myPoint = myDir = GEOM::GEOM_Object::_nil();
182 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
183 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
190 GroupDimensions->show();
199 //=================================================================================
200 // function : ClickOnOk()
202 //=================================================================================
203 void PrimitiveGUI_CylinderDlg::ClickOnOk()
205 if ( ClickOnApply() )
210 //=================================================================================
211 // function : ClickOnApply()
213 //=================================================================================
214 bool PrimitiveGUI_CylinderDlg::ClickOnApply()
220 ConstructorsClicked( getConstructorId() );
225 //=======================================================================
226 // function : ClickOnCancel()
228 //=======================================================================
229 void PrimitiveGUI_CylinderDlg::ClickOnCancel()
231 GEOMBase_Skeleton::ClickOnCancel();
235 //=================================================================================
236 // function : SelectionIntoArgument()
237 // purpose : Called when selection as changed or other case
238 //=================================================================================
239 void PrimitiveGUI_CylinderDlg::SelectionIntoArgument()
241 if ( getConstructorId() != 0 )
244 myEditCurrentArgument->setText("");
246 if(IObjectCount() != 1)
248 if(myEditCurrentArgument == GroupPoints->LineEdit1)
249 myPoint = GEOM::GEOM_Object::_nil();
250 else if (myEditCurrentArgument == GroupPoints->LineEdit2)
251 myDir = GEOM::GEOM_Object::_nil();
256 Standard_Boolean testResult = Standard_False;
257 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( firstIObject(), testResult );
259 if(!testResult || CORBA::is_nil( aSelectedObject ))
262 if (myEditCurrentArgument == GroupPoints->LineEdit1)
263 myPoint = aSelectedObject;
264 else if (myEditCurrentArgument == GroupPoints->LineEdit2)
265 myDir = aSelectedObject;
267 myEditCurrentArgument->setText( GEOMBase::GetName( aSelectedObject ) );
273 //=================================================================================
274 // function : SetEditCurrentArgument()
276 //=================================================================================
277 void PrimitiveGUI_CylinderDlg::SetEditCurrentArgument()
279 QPushButton* send = (QPushButton*)sender();
281 if(send == GroupPoints->PushButton1) {
282 myEditCurrentArgument = GroupPoints->LineEdit1;
283 globalSelection( GEOM_POINT );
285 else if(send == GroupPoints->PushButton2) {
286 myEditCurrentArgument = GroupPoints->LineEdit2;
287 globalSelection( GEOM_LINE );
290 myEditCurrentArgument->setFocus();
291 SelectionIntoArgument();
295 //=================================================================================
296 // function : LineEditReturnPressed()
298 //=================================================================================
299 void PrimitiveGUI_CylinderDlg::LineEditReturnPressed()
301 QLineEdit* send = (QLineEdit*)sender();
302 if(send == GroupPoints->LineEdit1 ||
303 send == GroupPoints->LineEdit2)
305 myEditCurrentArgument = send;
306 GEOMBase_Skeleton::LineEditReturnPressed();
311 //=================================================================================
312 // function : ActivateThisDialog()
314 //=================================================================================
315 void PrimitiveGUI_CylinderDlg::ActivateThisDialog()
317 GEOMBase_Skeleton::ActivateThisDialog();
318 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
319 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
321 ConstructorsClicked( getConstructorId() );
325 //=================================================================================
326 // function : enterEvent()
328 //=================================================================================
329 void PrimitiveGUI_CylinderDlg::enterEvent(QEvent* e)
331 if ( !GroupConstructors->isEnabled() )
332 ActivateThisDialog();
336 //=================================================================================
337 // function : DeactivateActiveDialog()
338 // purpose : public slot to deactivate if active
339 //=================================================================================
340 void PrimitiveGUI_CylinderDlg::DeactivateActiveDialog()
342 GEOMBase_Skeleton::DeactivateActiveDialog();
346 //=================================================================================
347 // function : ValueChangedInSpinBox
349 //=================================================================================
350 void PrimitiveGUI_CylinderDlg::ValueChangedInSpinBox( )
356 //=================================================================================
357 // function : createOperation
359 //=================================================================================
360 GEOM::GEOM_IOperations_ptr PrimitiveGUI_CylinderDlg::createOperation()
362 return getGeomEngine()->GetI3DPrimOperations( getStudyId() );
366 //=================================================================================
367 // function : isValid
369 //=================================================================================
370 bool PrimitiveGUI_CylinderDlg::isValid( QString& msg )
372 return getConstructorId() == 0 ? !(myPoint->_is_nil() || myDir->_is_nil() ) : true;
375 //=================================================================================
376 // function : execute
378 //=================================================================================
379 bool PrimitiveGUI_CylinderDlg::execute( ObjectList& objects )
383 GEOM::GEOM_Object_var anObj;
385 switch ( getConstructorId() )
389 if ( !CORBA::is_nil( myPoint ) && !CORBA::is_nil( myDir )) {
390 anObj = GEOM::GEOM_I3DPrimOperations::_narrow( getOperation() )->MakeCylinderPntVecRH(myPoint, myDir, getRadius(), getHeight());
397 anObj = GEOM::GEOM_I3DPrimOperations::_narrow( getOperation() )->MakeCylinderRH(getRadius(), getHeight());
404 if ( !anObj->_is_nil() )
405 objects.push_back( anObj._retn() );
410 //=================================================================================
411 // function : closeEvent
413 //=================================================================================
414 void PrimitiveGUI_CylinderDlg::closeEvent( QCloseEvent* e )
416 GEOMBase_Skeleton::closeEvent( e );
420 //=================================================================================
421 // function : getRadius()
423 //=================================================================================
424 double PrimitiveGUI_CylinderDlg::getRadius() const
426 int aConstructorId = getConstructorId();
427 if (aConstructorId == 0)
428 return GroupPoints->SpinBox_DX->GetValue();
429 else if (aConstructorId == 1)
430 return GroupDimensions->SpinBox_DX->GetValue();
435 //=================================================================================
436 // function : getHeight()
438 //=================================================================================
439 double PrimitiveGUI_CylinderDlg::getHeight() const
441 int aConstructorId = getConstructorId();
442 if (aConstructorId == 0)
443 return GroupPoints->SpinBox_DY->GetValue();
444 else if (aConstructorId == 1)
445 return GroupDimensions->SpinBox_DY->GetValue();