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 "QAD_Config.h"
32 #include "QAD_Desktop.h"
34 #include "GEOMImpl_Types.hxx"
36 #include "utilities.h"
40 //=================================================================================
41 // class : PrimitiveGUI_CylinderDlg()
42 // purpose : Constructs a PrimitiveGUI_CylinderDlg which is a child of 'parent', with the
43 // name 'name' and widget flags set to 'f'.
44 // The dialog will by default be modeless, unless you set 'modal' to
45 // TRUE to construct a modal dialog.
46 //=================================================================================
47 PrimitiveGUI_CylinderDlg::PrimitiveGUI_CylinderDlg(QWidget* parent, const char* name, SALOME_Selection* Sel, bool modal, WFlags fl)
48 :GEOMBase_Skeleton(parent, name, Sel, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
50 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_CYLINDER_PV")));
51 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_CYLINDER_DXYZ")));
52 QPixmap image2(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_SELECT")));
54 setCaption(tr("GEOM_CYLINDER_TITLE"));
56 /***************************************************************/
57 GroupConstructors->setTitle(tr("GEOM_CYLINDER"));
58 RadioButton1->setPixmap(image0);
59 RadioButton2->setPixmap(image1);
60 RadioButton3->close(TRUE);
62 GroupPoints = new DlgRef_2Sel2Spin(this, "GroupPoints");
63 GroupPoints->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
64 GroupPoints->TextLabel1->setText(tr("GEOM_BASE_POINT"));
65 GroupPoints->TextLabel2->setText(tr("GEOM_VECTOR"));
66 GroupPoints->TextLabel3->setText(tr("GEOM_RADIUS"));
67 GroupPoints->TextLabel4->setText(tr("GEOM_HEIGHT"));
68 GroupPoints->PushButton1->setPixmap(image2);
69 GroupPoints->PushButton2->setPixmap(image2);
71 GroupDimensions = new DlgRef_2Spin(this, "GroupDimensions");
72 GroupDimensions->GroupBox1->setTitle(tr("GEOM_BOX_OBJ"));
73 GroupDimensions->TextLabel1->setText(tr("GEOM_RADIUS"));
74 GroupDimensions->TextLabel2->setText(tr("GEOM_HEIGHT"));
76 Layout1->addWidget(GroupPoints, 2, 0);
77 Layout1->addWidget(GroupDimensions, 2, 0);
78 /***************************************************************/
84 //=================================================================================
85 // function : ~PrimitiveGUI_CylinderDlg()
86 // purpose : Destroys the object and frees any allocated resources
87 //=================================================================================
88 PrimitiveGUI_CylinderDlg::~PrimitiveGUI_CylinderDlg()
90 // no need to delete child widgets, Qt does it all for us
94 //=================================================================================
97 //=================================================================================
98 void PrimitiveGUI_CylinderDlg::Init()
101 myEditCurrentArgument = GroupPoints->LineEdit1;
102 GroupPoints->LineEdit1->setReadOnly( true );
103 GroupPoints->LineEdit2->setReadOnly( true );
105 myPoint = myDir = GEOM::GEOM_Object::_nil();
107 /* Get setting of step value from file configuration */
108 QString St = QAD_CONFIG->getSetting("Geometry:SettingsGeomStep");
109 double step = St.toDouble();
111 /* min, max, step and decimals for spin boxes & initial values */
112 /* First constructor : radius */
113 GroupPoints->SpinBox_DX->RangeStepAndValidator(0.001, 999.999, step, 3);
114 /* First constructor : algebric height */
115 GroupPoints->SpinBox_DY->RangeStepAndValidator(-999.999, 999.999, step, 3);
116 /* Second constructor : radius */
117 GroupDimensions->SpinBox_DX->RangeStepAndValidator(0.001, 999.999, step, 3);
118 /* Second constructor : algebric height */
119 GroupDimensions->SpinBox_DY->RangeStepAndValidator(-999.999, 999.999, step, 3);
121 GroupPoints->SpinBox_DX->SetValue(100.0);
122 GroupPoints->SpinBox_DY->SetValue(300.0);
123 GroupDimensions->SpinBox_DX->SetValue(100.0);
124 GroupDimensions->SpinBox_DY->SetValue(300.0);
126 /* signals and slots connections */
127 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
128 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
129 connect(GroupConstructors, SIGNAL(clicked(int)), this, SLOT(ConstructorsClicked(int)));
131 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
132 connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
134 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
135 connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
137 connect(GroupPoints->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
138 connect(GroupPoints->SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
139 connect(GroupDimensions->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
140 connect(GroupDimensions->SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
142 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_DX, SLOT(SetStep(double)));
143 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_DY, SLOT(SetStep(double)));
144 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DX, SLOT(SetStep(double)));
145 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DY, SLOT(SetStep(double)));
147 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
149 initName( tr( "GEOM_CYLINDER" ) );
150 ConstructorsClicked(0);
154 //=================================================================================
155 // function : ConstructorsClicked()
156 // purpose : Radio button management
157 //=================================================================================
158 void PrimitiveGUI_CylinderDlg::ConstructorsClicked(int constructorId)
160 disconnect(mySelection, 0, this, 0);
162 switch(constructorId)
166 globalSelection( GEOM_POINT );
168 GroupDimensions->hide();
172 myEditCurrentArgument = GroupPoints->LineEdit1;
173 GroupPoints->LineEdit1->setText(tr(""));
174 GroupPoints->LineEdit2->setText(tr(""));
175 myPoint = myDir = GEOM::GEOM_Object::_nil();
177 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
184 GroupDimensions->show();
193 //=================================================================================
194 // function : ClickOnOk()
196 //=================================================================================
197 void PrimitiveGUI_CylinderDlg::ClickOnOk()
199 if ( ClickOnApply() )
204 //=================================================================================
205 // function : ClickOnApply()
207 //=================================================================================
208 bool PrimitiveGUI_CylinderDlg::ClickOnApply()
214 ConstructorsClicked( getConstructorId() );
219 //=======================================================================
220 // function : ClickOnCancel()
222 //=======================================================================
223 void PrimitiveGUI_CylinderDlg::ClickOnCancel()
225 GEOMBase_Skeleton::ClickOnCancel();
229 //=================================================================================
230 // function : SelectionIntoArgument()
231 // purpose : Called when selection as changed or other case
232 //=================================================================================
233 void PrimitiveGUI_CylinderDlg::SelectionIntoArgument()
235 if ( getConstructorId() != 0 )
238 myEditCurrentArgument->setText("");
240 if(mySelection->IObjectCount() != 1)
242 if(myEditCurrentArgument == GroupPoints->LineEdit1)
243 myPoint = GEOM::GEOM_Object::_nil();
244 else if (myEditCurrentArgument == GroupPoints->LineEdit2)
245 myDir = GEOM::GEOM_Object::_nil();
250 Standard_Boolean testResult = Standard_False;
251 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( mySelection->firstIObject(), testResult );
253 if(!testResult || CORBA::is_nil( aSelectedObject ))
256 if (myEditCurrentArgument == GroupPoints->LineEdit1)
257 myPoint = aSelectedObject;
258 else if (myEditCurrentArgument == GroupPoints->LineEdit2)
259 myDir = aSelectedObject;
261 myEditCurrentArgument->setText( GEOMBase::GetName( aSelectedObject ) );
267 //=================================================================================
268 // function : SetEditCurrentArgument()
270 //=================================================================================
271 void PrimitiveGUI_CylinderDlg::SetEditCurrentArgument()
273 QPushButton* send = (QPushButton*)sender();
275 if(send == GroupPoints->PushButton1) {
276 myEditCurrentArgument = GroupPoints->LineEdit1;
277 globalSelection( GEOM_POINT );
279 else if(send == GroupPoints->PushButton2) {
280 myEditCurrentArgument = GroupPoints->LineEdit2;
281 globalSelection( GEOM_LINE );
284 myEditCurrentArgument->setFocus();
285 SelectionIntoArgument();
289 //=================================================================================
290 // function : LineEditReturnPressed()
292 //=================================================================================
293 void PrimitiveGUI_CylinderDlg::LineEditReturnPressed()
295 QLineEdit* send = (QLineEdit*)sender();
296 if(send == GroupPoints->LineEdit1 ||
297 send == GroupPoints->LineEdit2)
299 myEditCurrentArgument = send;
300 GEOMBase_Skeleton::LineEditReturnPressed();
305 //=================================================================================
306 // function : ActivateThisDialog()
308 //=================================================================================
309 void PrimitiveGUI_CylinderDlg::ActivateThisDialog()
311 GEOMBase_Skeleton::ActivateThisDialog();
312 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
314 ConstructorsClicked( getConstructorId() );
318 //=================================================================================
319 // function : enterEvent()
321 //=================================================================================
322 void PrimitiveGUI_CylinderDlg::enterEvent(QEvent* e)
324 if ( !GroupConstructors->isEnabled() )
325 ActivateThisDialog();
329 //=================================================================================
330 // function : DeactivateActiveDialog()
331 // purpose : public slot to deactivate if active
332 //=================================================================================
333 void PrimitiveGUI_CylinderDlg::DeactivateActiveDialog()
335 GEOMBase_Skeleton::DeactivateActiveDialog();
339 //=================================================================================
340 // function : ValueChangedInSpinBox
342 //=================================================================================
343 void PrimitiveGUI_CylinderDlg::ValueChangedInSpinBox( )
349 //=================================================================================
350 // function : createOperation
352 //=================================================================================
353 GEOM::GEOM_IOperations_ptr PrimitiveGUI_CylinderDlg::createOperation()
355 return getGeomEngine()->GetI3DPrimOperations( getStudyId() );
359 //=================================================================================
360 // function : isValid
362 //=================================================================================
363 bool PrimitiveGUI_CylinderDlg::isValid( QString& msg )
365 return getConstructorId() == 0 ? !(myPoint->_is_nil() || myDir->_is_nil() ) : true;
368 //=================================================================================
369 // function : execute
371 //=================================================================================
372 bool PrimitiveGUI_CylinderDlg::execute( ObjectList& objects )
376 GEOM::GEOM_Object_var anObj;
378 switch ( getConstructorId() )
382 if ( !CORBA::is_nil( myPoint ) && !CORBA::is_nil( myDir )) {
383 anObj = GEOM::GEOM_I3DPrimOperations::_narrow( getOperation() )->MakeCylinderPntVecRH(myPoint, myDir, getRadius(), getHeight());
390 anObj = GEOM::GEOM_I3DPrimOperations::_narrow( getOperation() )->MakeCylinderRH(getRadius(), getHeight());
397 if ( !anObj->_is_nil() )
398 objects.push_back( anObj._retn() );
403 //=================================================================================
404 // function : closeEvent
406 //=================================================================================
407 void PrimitiveGUI_CylinderDlg::closeEvent( QCloseEvent* e )
409 GEOMBase_Skeleton::closeEvent( e );
413 //=================================================================================
414 // function : getRadius()
416 //=================================================================================
417 double PrimitiveGUI_CylinderDlg::getRadius() const
419 int aConstructorId = getConstructorId();
420 if (aConstructorId == 0)
421 return GroupPoints->SpinBox_DX->GetValue();
422 else if (aConstructorId == 1)
423 return GroupDimensions->SpinBox_DX->GetValue();
428 //=================================================================================
429 // function : getHeight()
431 //=================================================================================
432 double PrimitiveGUI_CylinderDlg::getHeight() const
434 int aConstructorId = getConstructorId();
435 if (aConstructorId == 0)
436 return GroupPoints->SpinBox_DY->GetValue();
437 else if (aConstructorId == 1)
438 return GroupDimensions->SpinBox_DY->GetValue();