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
22 // File : PrimitiveGUI_TorusDlg.cxx
23 // Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
26 #include "PrimitiveGUI_TorusDlg.h"
29 #include <GeometryGUI.h>
32 #include <SUIT_ResourceMgr.h>
33 #include <SUIT_Session.h>
34 #include <SalomeApp_Application.h>
35 #include <LightApp_SelectionMgr.h>
37 #include <TopoDS_Shape.hxx>
38 #include <TopoDS_Edge.hxx>
41 #include <TColStd_IndexedMapOfInteger.hxx>
42 #include <TopTools_IndexedMapOfShape.hxx>
44 #include <GEOMImpl_Types.hxx>
46 //=================================================================================
47 // class : PrimitiveGUI_TorusDlg()
48 // purpose : Constructs a PrimitiveGUI_TorusDlg 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_TorusDlg::PrimitiveGUI_TorusDlg( GeometryGUI* theGeometryGUI, QWidget* parent,
54 bool modal, Qt::WindowFlags fl )
55 : GEOMBase_Skeleton( theGeometryGUI, parent, modal, fl )
57 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
58 QPixmap image0( aResMgr->loadPixmap( "GEOM", tr( "ICON_DLG_TORUS_PV" ) ) );
59 QPixmap image1( aResMgr->loadPixmap( "GEOM", tr( "ICON_DLG_TORUS_DXYZ" ) ) );
60 QPixmap image2( aResMgr->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
62 setWindowTitle( tr( "GEOM_TORUS_TITLE" ) );
64 /***************************************************************/
65 mainFrame()->GroupConstructors->setTitle( tr( "GEOM_TORUS" ) );
66 mainFrame()->RadioButton1->setIcon( image0 );
67 mainFrame()->RadioButton2->setIcon( image1 );
68 mainFrame()->RadioButton3->setAttribute( Qt::WA_DeleteOnClose );
69 mainFrame()->RadioButton3->close();
71 GroupPoints = new DlgRef_2Sel2Spin( centralWidget() );
72 GroupPoints->GroupBox1->setTitle( tr( "GEOM_ARGUMENTS" ) );
73 GroupPoints->TextLabel1->setText( tr( "GEOM_BASE_POINT" ) );
74 GroupPoints->TextLabel2->setText( tr( "GEOM_VECTOR" ) );
75 GroupPoints->TextLabel3->setText( tr( "GEOM_RADIUS_I" ).arg( 1 ) );
76 GroupPoints->TextLabel4->setText( tr( "GEOM_RADIUS_I" ).arg( 2 ) );
77 GroupPoints->PushButton1->setIcon( image2 );
78 GroupPoints->PushButton2->setIcon( image2 );
80 GroupDimensions = new DlgRef_2Spin( centralWidget() );
81 GroupDimensions->GroupBox1->setTitle( tr( "GEOM_BOX_OBJ" ) );
82 GroupDimensions->TextLabel1->setText( tr( "GEOM_RADIUS_I" ).arg( 1 ) );
83 GroupDimensions->TextLabel2->setText( tr( "GEOM_RADIUS_I" ).arg( 2 ) );
85 QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
86 layout->setMargin( 0 ); layout->setSpacing( 6 );
87 layout->addWidget( GroupPoints );
88 layout->addWidget( GroupDimensions );
89 /***************************************************************/
91 setHelpFileName( "create_torus_page.html" );
97 //=================================================================================
98 // function : ~PrimitiveGUI_TorusDlg()
99 // purpose : Destroys the object and frees any allocated resources
100 //=================================================================================
101 PrimitiveGUI_TorusDlg::~PrimitiveGUI_TorusDlg()
103 // no need to delete child widgets, Qt does it all for us
107 //=================================================================================
110 //=================================================================================
111 void PrimitiveGUI_TorusDlg::Init()
114 myEditCurrentArgument = GroupPoints->LineEdit1;
115 GroupPoints->LineEdit1->setReadOnly( true );
116 GroupPoints->LineEdit2->setReadOnly( true );
118 myPoint = myDir = GEOM::GEOM_Object::_nil();
120 /* Get setting of step value from file configuration */
121 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
122 double step = resMgr->doubleValue( "Geometry", "SettingsGeomStep", 100 );
124 /* min, max, step and decimals for spin boxes & initial values */
125 initSpinBox( GroupPoints->SpinBox_DX, 0.001, COORD_MAX, step, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
126 initSpinBox( GroupPoints->SpinBox_DY, 0.001, COORD_MAX, step, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
127 initSpinBox( GroupDimensions->SpinBox_DX, 0.001, COORD_MAX, step, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
128 initSpinBox( GroupDimensions->SpinBox_DY, 0.001, COORD_MAX, step, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
130 GroupPoints->SpinBox_DX->setValue( 300.0 );
131 GroupPoints->SpinBox_DY->setValue( 100.0 );
132 GroupDimensions->SpinBox_DX->setValue( 300.0 );
133 GroupDimensions->SpinBox_DY->setValue( 100.0 );
135 /* signals and slots connections */
136 connect( buttonOk(), SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
137 connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
139 connect( this, SIGNAL( constructorsClicked( 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 ) ), this, SLOT( SetDoubleSpinBoxStep( double ) ) );
154 connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
155 this, SLOT( SelectionIntoArgument() ) );
157 initName( tr( "GEOM_TORUS" ) );
159 setConstructorId( 1 ); // simplest constructor
160 ConstructorsClicked( 1 );
163 //=================================================================================
164 // function : SetDoubleSpinBoxStep()
165 // purpose : Double spin box management
166 //=================================================================================
167 void PrimitiveGUI_TorusDlg::SetDoubleSpinBoxStep( double step )
169 GroupPoints->SpinBox_DX->setSingleStep(step);
170 GroupPoints->SpinBox_DY->setSingleStep(step);
171 GroupDimensions->SpinBox_DX->setSingleStep(step);
172 GroupDimensions->SpinBox_DY->setSingleStep(step);
176 //=================================================================================
177 // function : ConstructorsClicked()
178 // purpose : Radio button management
179 //=================================================================================
180 void PrimitiveGUI_TorusDlg::ConstructorsClicked( int constructorId )
182 disconnect( myGeomGUI->getApp()->selectionMgr(), 0, this, 0 );
184 switch( constructorId ) {
187 globalSelection(); // close local contexts, if any
188 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
190 GroupDimensions->hide();
193 myEditCurrentArgument = GroupPoints->LineEdit1;
194 GroupPoints->LineEdit1->setText( "" );
195 GroupPoints->LineEdit2->setText( "" );
196 myPoint = myDir = GEOM::GEOM_Object::_nil();
198 connect( myGeomGUI->getApp()->selectionMgr(),
199 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
200 SelectionIntoArgument();
206 GroupDimensions->show();
207 globalSelection(); // close local contexts, if any
213 qApp->processEvents();
215 resize( minimumSize() );
221 //=================================================================================
222 // function : ClickOnOk()
224 //=================================================================================
225 void PrimitiveGUI_TorusDlg::ClickOnOk()
227 if ( ClickOnApply() )
232 //=================================================================================
233 // function : ClickOnApply()
235 //=================================================================================
236 bool PrimitiveGUI_TorusDlg::ClickOnApply()
247 //=================================================================================
248 // function : SelectionIntoArgument()
249 // purpose : Called when selection as changed or other case
250 //=================================================================================
251 void PrimitiveGUI_TorusDlg::SelectionIntoArgument()
253 if ( getConstructorId() != 0 )
256 myEditCurrentArgument->setText( "" );
258 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
259 SALOME_ListIO aSelList;
260 aSelMgr->selectedObjects(aSelList);
262 if ( aSelList.Extent() != 1 ) {
263 if ( myEditCurrentArgument == GroupPoints->LineEdit1 )
264 myPoint = GEOM::GEOM_Object::_nil();
265 else if ( myEditCurrentArgument == GroupPoints->LineEdit2 )
266 myDir = GEOM::GEOM_Object::_nil();
271 Standard_Boolean testResult = Standard_False;
272 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( aSelList.First(), testResult );
274 if ( !testResult || CORBA::is_nil( aSelectedObject ) )
278 QString aName = GEOMBase::GetName(aSelectedObject);
280 if ( GEOMBase::GetShape( aSelectedObject, aShape, TopAbs_SHAPE ) && !aShape.IsNull() ) {
281 TopAbs_ShapeEnum aNeedType = TopAbs_VERTEX;
282 if ( myEditCurrentArgument == GroupPoints->LineEdit2 )
283 aNeedType = TopAbs_EDGE;
285 TColStd_IndexedMapOfInteger aMap;
286 aSelMgr->GetIndexes( aSelList.First(), aMap );
287 if ( aMap.Extent() == 1 ) { // Local Selection
288 int anIndex = aMap( 1 );
289 if ( aNeedType == TopAbs_EDGE )
290 aName.append( ":edge_" + QString::number( anIndex ) );
292 aName.append( ":vertex_" + QString::number( anIndex ) );
294 //Find SubShape Object in Father
295 GEOM::GEOM_Object_var aFindedObject = GEOMBase_Helper::findObjectInFather( aSelectedObject, aName );
297 if ( aFindedObject == GEOM::GEOM_Object::_nil() ) { // Object not found in study
298 GEOM::GEOM_IShapesOperations_var aShapesOp =
299 getGeomEngine()->GetIShapesOperations( getStudyId() );
300 aSelectedObject = aShapesOp->GetSubShape( aSelectedObject, anIndex );
303 aSelectedObject = aFindedObject; // get Object from study
305 else { // Global Selection
306 if ( aShape.ShapeType() != aNeedType ) {
307 aSelectedObject = GEOM::GEOM_Object::_nil();
313 myEditCurrentArgument->setText(aName);
315 if ( myEditCurrentArgument == GroupPoints->LineEdit1 )
316 myPoint = aSelectedObject;
317 else if ( myEditCurrentArgument == GroupPoints->LineEdit2 )
318 myDir = aSelectedObject;
324 //=================================================================================
325 // function : SetEditCurrentArgument()
327 //=================================================================================
328 void PrimitiveGUI_TorusDlg::SetEditCurrentArgument()
330 QPushButton* send = (QPushButton*)sender();
331 globalSelection( GEOM_POINT ); // to break previous local selection
333 if ( send == GroupPoints->PushButton1 ) {
334 myEditCurrentArgument = GroupPoints->LineEdit1;
335 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
337 else if ( send == GroupPoints->PushButton2 ) {
338 myEditCurrentArgument = GroupPoints->LineEdit2;
339 GEOM::GEOM_Object_var anObj;
340 localSelection( anObj, TopAbs_EDGE );
343 myEditCurrentArgument->setFocus();
344 SelectionIntoArgument();
348 //=================================================================================
349 // function : LineEditReturnPressed()
351 //=================================================================================
352 void PrimitiveGUI_TorusDlg::LineEditReturnPressed()
354 QLineEdit* send = (QLineEdit*)sender();
355 if ( send == GroupPoints->LineEdit1 ||
356 send == GroupPoints->LineEdit2 ) {
357 myEditCurrentArgument = send;
358 GEOMBase_Skeleton::LineEditReturnPressed();
363 //=================================================================================
364 // function : ActivateThisDialog()
366 //=================================================================================
367 void PrimitiveGUI_TorusDlg::ActivateThisDialog()
369 GEOMBase_Skeleton::ActivateThisDialog();
370 connect( myGeomGUI->getApp()->selectionMgr(),
371 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
373 ConstructorsClicked( getConstructorId() );
377 //=================================================================================
378 // function : enterEvent()
380 //=================================================================================
381 void PrimitiveGUI_TorusDlg::enterEvent( QEvent* )
383 if ( !mainFrame()->GroupConstructors->isEnabled() )
384 ActivateThisDialog();
388 //=================================================================================
389 // function : ValueChangedInSpinBox
391 //=================================================================================
392 void PrimitiveGUI_TorusDlg::ValueChangedInSpinBox()
398 //=================================================================================
399 // function : createOperation
401 //=================================================================================
402 GEOM::GEOM_IOperations_ptr PrimitiveGUI_TorusDlg::createOperation()
404 return getGeomEngine()->GetI3DPrimOperations( getStudyId() );
408 //=================================================================================
409 // function : isValid
411 //=================================================================================
412 bool PrimitiveGUI_TorusDlg::isValid( QString& msg )
414 return getConstructorId() == 0 ? !(myPoint->_is_nil() || myDir->_is_nil()) : true;
418 //=================================================================================
419 // function : execute
421 //=================================================================================
422 bool PrimitiveGUI_TorusDlg::execute( ObjectList& objects )
426 GEOM::GEOM_Object_var anObj;
428 switch ( getConstructorId() ) {
430 if (!CORBA::is_nil( myPoint ) && !CORBA::is_nil( myDir )){
431 anObj = GEOM::GEOM_I3DPrimOperations::_narrow( getOperation() )->MakeTorusPntVecRR( myPoint, myDir, getRadius1(), getRadius2() );
436 anObj = GEOM::GEOM_I3DPrimOperations::_narrow( getOperation() )->MakeTorusRR( getRadius1(), getRadius2() );
441 if ( !anObj->_is_nil() )
442 objects.push_back( anObj._retn() );
448 //=================================================================================
449 // function : getRadius1()
451 //=================================================================================
452 double PrimitiveGUI_TorusDlg::getRadius1() const
454 int aConstructorId = getConstructorId();
455 if ( aConstructorId == 0 )
456 return GroupPoints->SpinBox_DX->value();
457 else if ( aConstructorId == 1 )
458 return GroupDimensions->SpinBox_DX->value();
463 //=================================================================================
464 // function : getRadius2()
466 //=================================================================================
467 double PrimitiveGUI_TorusDlg::getRadius2() const
469 int aConstructorId = getConstructorId();
470 if ( aConstructorId == 0 )
471 return GroupPoints->SpinBox_DY->value();
472 else if ( aConstructorId == 1 )
473 return GroupDimensions->SpinBox_DY->value();
477 //=================================================================================
478 // function : addSubshapeToStudy
479 // purpose : virtual method to add new SubObjects if local selection
480 //=================================================================================
481 void PrimitiveGUI_TorusDlg::addSubshapesToStudy()
483 QMap<QString, GEOM::GEOM_Object_var> objMap;
485 switch ( getConstructorId() ) {
487 objMap[GroupPoints->LineEdit1->text()] = myPoint;
488 objMap[GroupPoints->LineEdit2->text()] = myDir;
493 addSubshapesToFather( objMap );