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"
36 #include <TopoDS_Shape.hxx>
37 #include <TopoDS_Edge.hxx>
40 #include <TColStd_IndexedMapOfInteger.hxx>
41 #include <TopTools_IndexedMapOfShape.hxx>
45 #include "GEOMImpl_Types.hxx"
47 #include "utilities.h"
51 //=================================================================================
52 // class : PrimitiveGUI_CylinderDlg()
53 // purpose : Constructs a PrimitiveGUI_CylinderDlg which is a child of 'parent', with the
54 // name 'name' and widget flags set to 'f'.
55 // The dialog will by default be modeless, unless you set 'modal' to
56 // TRUE to construct a modal dialog.
57 //=================================================================================
58 PrimitiveGUI_CylinderDlg::PrimitiveGUI_CylinderDlg(GeometryGUI* theGeometryGUI, QWidget* parent,
59 const char* name, bool modal, WFlags fl)
60 :GEOMBase_Skeleton(theGeometryGUI, parent, name, modal, WStyle_Customize |
61 WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
63 QPixmap image0(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_CYLINDER_PV")));
64 QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_CYLINDER_DXYZ")));
65 QPixmap image2(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_SELECT")));
67 setCaption(tr("GEOM_CYLINDER_TITLE"));
69 /***************************************************************/
70 GroupConstructors->setTitle(tr("GEOM_CYLINDER"));
71 RadioButton1->setPixmap(image0);
72 RadioButton2->setPixmap(image1);
73 RadioButton3->close(TRUE);
75 GroupPoints = new DlgRef_2Sel2Spin(this, "GroupPoints");
76 GroupPoints->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
77 GroupPoints->TextLabel1->setText(tr("GEOM_BASE_POINT"));
78 GroupPoints->TextLabel2->setText(tr("GEOM_VECTOR"));
79 GroupPoints->TextLabel3->setText(tr("GEOM_RADIUS"));
80 GroupPoints->TextLabel4->setText(tr("GEOM_HEIGHT"));
81 GroupPoints->PushButton1->setPixmap(image2);
82 GroupPoints->PushButton2->setPixmap(image2);
84 GroupDimensions = new DlgRef_2Spin(this, "GroupDimensions");
85 GroupDimensions->GroupBox1->setTitle(tr("GEOM_BOX_OBJ"));
86 GroupDimensions->TextLabel1->setText(tr("GEOM_RADIUS"));
87 GroupDimensions->TextLabel2->setText(tr("GEOM_HEIGHT"));
89 Layout1->addWidget(GroupPoints, 2, 0);
90 Layout1->addWidget(GroupDimensions, 2, 0);
91 /***************************************************************/
93 setHelpFileName("cylinder.htm");
99 //=================================================================================
100 // function : ~PrimitiveGUI_CylinderDlg()
101 // purpose : Destroys the object and frees any allocated resources
102 //=================================================================================
103 PrimitiveGUI_CylinderDlg::~PrimitiveGUI_CylinderDlg()
105 // no need to delete child widgets, Qt does it all for us
109 //=================================================================================
112 //=================================================================================
113 void PrimitiveGUI_CylinderDlg::Init()
116 myEditCurrentArgument = GroupPoints->LineEdit1;
117 GroupPoints->LineEdit1->setReadOnly( true );
118 GroupPoints->LineEdit2->setReadOnly( true );
120 myPoint = myDir = GEOM::GEOM_Object::_nil();
122 /* Get setting of step value from file configuration */
123 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
124 double step = resMgr->doubleValue( "Geometry", "SettingsGeomStep", 100);
126 /* min, max, step and decimals for spin boxes & initial values */
127 /* First constructor : radius */
128 GroupPoints->SpinBox_DX->RangeStepAndValidator(0.001, COORD_MAX, step, DBL_DIGITS_DISPLAY);
129 /* First constructor : algebric height */
130 GroupPoints->SpinBox_DY->RangeStepAndValidator(COORD_MIN, COORD_MAX, step, DBL_DIGITS_DISPLAY);
131 /* Second constructor : radius */
132 GroupDimensions->SpinBox_DX->RangeStepAndValidator(0.001, COORD_MAX, step, DBL_DIGITS_DISPLAY);
133 /* Second constructor : algebric height */
134 GroupDimensions->SpinBox_DY->RangeStepAndValidator(COORD_MIN, COORD_MAX, step, DBL_DIGITS_DISPLAY);
136 GroupPoints->SpinBox_DX->SetValue(100.0);
137 GroupPoints->SpinBox_DY->SetValue(300.0);
138 GroupDimensions->SpinBox_DX->SetValue(100.0);
139 GroupDimensions->SpinBox_DY->SetValue(300.0);
141 /* signals and slots connections */
142 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
143 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
144 connect(GroupConstructors, SIGNAL(clicked(int)), this, SLOT(ConstructorsClicked(int)));
146 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
147 connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
149 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
150 connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
152 connect(GroupPoints->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
153 connect(GroupPoints->SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
154 connect(GroupDimensions->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
155 connect(GroupDimensions->SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
157 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_DX, SLOT(SetStep(double)));
158 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_DY, SLOT(SetStep(double)));
159 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DX, SLOT(SetStep(double)));
160 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DY, SLOT(SetStep(double)));
162 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
163 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
165 initName( tr( "GEOM_CYLINDER" ) );
166 ConstructorsClicked(0);
170 //=================================================================================
171 // function : ConstructorsClicked()
172 // purpose : Radio button management
173 //=================================================================================
174 void PrimitiveGUI_CylinderDlg::ConstructorsClicked(int constructorId)
176 disconnect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), 0, this, 0);
178 switch(constructorId)
182 // globalSelection( GEOM_POINT );
183 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
185 GroupDimensions->hide();
189 myEditCurrentArgument = GroupPoints->LineEdit1;
190 GroupPoints->LineEdit1->setText(tr(""));
191 GroupPoints->LineEdit2->setText(tr(""));
192 myPoint = myDir = GEOM::GEOM_Object::_nil();
194 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
195 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
202 GroupDimensions->show();
211 //=================================================================================
212 // function : ClickOnOk()
214 //=================================================================================
215 void PrimitiveGUI_CylinderDlg::ClickOnOk()
217 if ( ClickOnApply() )
222 //=================================================================================
223 // function : ClickOnApply()
225 //=================================================================================
226 bool PrimitiveGUI_CylinderDlg::ClickOnApply()
232 ConstructorsClicked( getConstructorId() );
237 //=======================================================================
238 // function : ClickOnCancel()
240 //=======================================================================
241 void PrimitiveGUI_CylinderDlg::ClickOnCancel()
243 GEOMBase_Skeleton::ClickOnCancel();
247 //=================================================================================
248 // function : SelectionIntoArgument()
249 // purpose : Called when selection as changed or other case
250 //=================================================================================
251 void PrimitiveGUI_CylinderDlg::SelectionIntoArgument()
253 if ( getConstructorId() != 0 )
256 myEditCurrentArgument->setText("");
258 if(IObjectCount() != 1)
260 if(myEditCurrentArgument == GroupPoints->LineEdit1)
261 myPoint = GEOM::GEOM_Object::_nil();
262 else if (myEditCurrentArgument == GroupPoints->LineEdit2)
263 myDir = GEOM::GEOM_Object::_nil();
268 Standard_Boolean testResult = Standard_False;
269 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( firstIObject(), testResult );
271 if(!testResult || CORBA::is_nil( aSelectedObject ))
274 QString aName = GEOMBase::GetName( aSelectedObject );
276 if ( GEOMBase::GetShape( aSelectedObject, aShape, TopAbs_SHAPE ) && !aShape.IsNull() )
278 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
279 TColStd_IndexedMapOfInteger aMap;
280 aSelMgr->GetIndexes( firstIObject(), aMap );
281 if ( aMap.Extent() == 1 )
283 GEOM::GEOM_IShapesOperations_var aShapesOp =
284 getGeomEngine()->GetIShapesOperations( getStudyId() );
285 int anIndex = aMap( 1 );
286 if ( myEditCurrentArgument == GroupPoints->LineEdit2 )
287 aName.append( ":edge_" + QString::number( anIndex ) );
289 aName.append( ":vertex_" + QString::number( anIndex ) );
290 aSelectedObject = aShapesOp->GetSubShape(aSelectedObject, anIndex);
291 aSelMgr->clearSelected();
294 myEditCurrentArgument->setText( aName );
296 if (myEditCurrentArgument == GroupPoints->LineEdit1)
297 myPoint = aSelectedObject;
298 else if (myEditCurrentArgument == GroupPoints->LineEdit2)
299 myDir = aSelectedObject;
304 //=================================================================================
305 // function : SetEditCurrentArgument()
307 //=================================================================================
308 void PrimitiveGUI_CylinderDlg::SetEditCurrentArgument()
310 QPushButton* send = (QPushButton*)sender();
312 if(send == GroupPoints->PushButton1) {
313 myEditCurrentArgument = GroupPoints->LineEdit1;
314 globalSelection( GEOM_POINT ); // to break previous local selection
315 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
317 else if(send == GroupPoints->PushButton2) {
318 myEditCurrentArgument = GroupPoints->LineEdit2;
319 globalSelection( GEOM_LINE ); // to break previous local selection
320 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_EDGE );
323 myEditCurrentArgument->setFocus();
324 SelectionIntoArgument();
328 //=================================================================================
329 // function : LineEditReturnPressed()
331 //=================================================================================
332 void PrimitiveGUI_CylinderDlg::LineEditReturnPressed()
334 QLineEdit* send = (QLineEdit*)sender();
335 if(send == GroupPoints->LineEdit1 ||
336 send == GroupPoints->LineEdit2)
338 myEditCurrentArgument = send;
339 GEOMBase_Skeleton::LineEditReturnPressed();
344 //=================================================================================
345 // function : ActivateThisDialog()
347 //=================================================================================
348 void PrimitiveGUI_CylinderDlg::ActivateThisDialog()
350 GEOMBase_Skeleton::ActivateThisDialog();
351 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
352 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
354 ConstructorsClicked( getConstructorId() );
358 //=================================================================================
359 // function : enterEvent()
361 //=================================================================================
362 void PrimitiveGUI_CylinderDlg::enterEvent(QEvent* e)
364 if ( !GroupConstructors->isEnabled() )
365 ActivateThisDialog();
369 //=================================================================================
370 // function : DeactivateActiveDialog()
371 // purpose : public slot to deactivate if active
372 //=================================================================================
373 void PrimitiveGUI_CylinderDlg::DeactivateActiveDialog()
375 GEOMBase_Skeleton::DeactivateActiveDialog();
379 //=================================================================================
380 // function : ValueChangedInSpinBox
382 //=================================================================================
383 void PrimitiveGUI_CylinderDlg::ValueChangedInSpinBox( )
389 //=================================================================================
390 // function : createOperation
392 //=================================================================================
393 GEOM::GEOM_IOperations_ptr PrimitiveGUI_CylinderDlg::createOperation()
395 return getGeomEngine()->GetI3DPrimOperations( getStudyId() );
399 //=================================================================================
400 // function : isValid
402 //=================================================================================
403 bool PrimitiveGUI_CylinderDlg::isValid( QString& msg )
405 return getConstructorId() == 0 ? !(myPoint->_is_nil() || myDir->_is_nil() ) : true;
408 //=================================================================================
409 // function : execute
411 //=================================================================================
412 bool PrimitiveGUI_CylinderDlg::execute( ObjectList& objects )
416 GEOM::GEOM_Object_var anObj;
418 switch ( getConstructorId() )
422 if ( !CORBA::is_nil( myPoint ) && !CORBA::is_nil( myDir )) {
423 anObj = GEOM::GEOM_I3DPrimOperations::_narrow( getOperation() )->MakeCylinderPntVecRH(myPoint, myDir, getRadius(), getHeight());
430 anObj = GEOM::GEOM_I3DPrimOperations::_narrow( getOperation() )->MakeCylinderRH(getRadius(), getHeight());
437 if ( !anObj->_is_nil() )
438 objects.push_back( anObj._retn() );
443 //=================================================================================
444 // function : closeEvent
446 //=================================================================================
447 void PrimitiveGUI_CylinderDlg::closeEvent( QCloseEvent* e )
449 GEOMBase_Skeleton::closeEvent( e );
453 //=================================================================================
454 // function : getRadius()
456 //=================================================================================
457 double PrimitiveGUI_CylinderDlg::getRadius() const
459 int aConstructorId = getConstructorId();
460 if (aConstructorId == 0)
461 return GroupPoints->SpinBox_DX->GetValue();
462 else if (aConstructorId == 1)
463 return GroupDimensions->SpinBox_DX->GetValue();
468 //=================================================================================
469 // function : getHeight()
471 //=================================================================================
472 double PrimitiveGUI_CylinderDlg::getHeight() const
474 int aConstructorId = getConstructorId();
475 if (aConstructorId == 0)
476 return GroupPoints->SpinBox_DY->GetValue();
477 else if (aConstructorId == 1)
478 return GroupDimensions->SpinBox_DY->GetValue();