1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 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 // GEOM GEOMGUI : GUI for Geometry component
23 // File : PrimitiveGUI_SphereDlg.cxx
24 // Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
26 #include "PrimitiveGUI_SphereDlg.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>
40 #include <TColStd_IndexedMapOfInteger.hxx>
41 #include <TopTools_IndexedMapOfShape.hxx>
43 #include <GEOMImpl_Types.hxx>
45 //=================================================================================
46 // class : PrimitiveGUI_SphereDlg()
47 // purpose : Constructs a PrimitiveGUI_SphereDlg which is a child of 'parent', with the
48 // name 'name' and widget flags set to 'f'.
49 // The dialog will by default be modeless, unless you set 'modal' to
50 // TRUE to construct a modal dialog.
51 //=================================================================================
52 PrimitiveGUI_SphereDlg::PrimitiveGUI_SphereDlg( GeometryGUI* theGeometryGUI, QWidget* parent,
53 bool modal, Qt::WindowFlags fl )
54 :GEOMBase_Skeleton(theGeometryGUI, parent, modal, fl )
56 QPixmap image0( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_SPHERE_P" ) ) );
57 QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_SPHERE_DXYZ" ) ) );
58 QPixmap image2( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
60 setWindowTitle( tr( "GEOM_SPHERE_TITLE" ) );
62 /***************************************************************/
63 mainFrame()->GroupConstructors->setTitle( tr( "GEOM_SPHERE" ) );
64 mainFrame()->RadioButton1->setIcon( image0 );
65 mainFrame()->RadioButton2->setIcon( image1 );
66 mainFrame()->RadioButton3->setAttribute( Qt::WA_DeleteOnClose );
67 mainFrame()->RadioButton3->close();
69 GroupPoints = new DlgRef_1Sel1Spin( centralWidget() );
70 GroupPoints->GroupBox1->setTitle( tr( "GEOM_SPHERE_CR" ) );
71 GroupPoints->TextLabel1->setText( tr( "GEOM_CENTER" ) );
72 GroupPoints->TextLabel2->setText( tr( "GEOM_RADIUS" ) );
73 GroupPoints->PushButton1->setIcon( image2 );
75 GroupDimensions = new DlgRef_1Spin( centralWidget() );
76 GroupDimensions->GroupBox1->setTitle( tr( "GEOM_SPHERE_RO" ) );
77 GroupDimensions->TextLabel1->setText( tr( "GEOM_RADIUS" ) );
79 QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
80 layout->setMargin( 0 ); layout->setSpacing( 6 );
81 layout->addWidget( GroupPoints );
82 layout->addWidget( GroupDimensions );
83 /***************************************************************/
85 setHelpFileName( "create_sphere_page.html" );
91 //=================================================================================
92 // function : ~PrimitiveGUI_SphereDlg()
93 // purpose : Destroys the object and frees any allocated resources
94 //=================================================================================
95 PrimitiveGUI_SphereDlg::~PrimitiveGUI_SphereDlg()
97 /* no need to delete child widgets, Qt does it all for us */
101 //=================================================================================
104 //=================================================================================
105 void PrimitiveGUI_SphereDlg::Init()
108 myEditCurrentArgument = GroupPoints->LineEdit1;
109 GroupPoints->LineEdit1->setReadOnly( true );
111 myPoint = GEOM::GEOM_Object::_nil();
113 /* Get setting of step value from file configuration */
114 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
115 double step = resMgr->doubleValue( "Geometry", "SettingsGeomStep", 100 );
117 /* min, max, step and decimals for spin boxes */
118 initSpinBox( GroupPoints->SpinBox_DX, 0.000001, COORD_MAX, step, 6 ); // VSR: TODO: DBL_DIGITS_DISPLAY
119 initSpinBox( GroupDimensions->SpinBox_DX, 0.000001, COORD_MAX, step, 6 ); // VSR: TODO: DBL_DIGITS_DISPLAY
120 GroupPoints->SpinBox_DX->setValue( 100.0 );
121 GroupDimensions->SpinBox_DX->setValue( 100.0 );
123 /* signals and slots connections */
124 connect( buttonOk(), SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
125 connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
127 connect( this, SIGNAL( constructorsClicked( int ) ), this, SLOT( ConstructorsClicked( int ) ) );
129 connect( GroupPoints->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
130 connect( GroupPoints->LineEdit1, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
132 connect( GroupDimensions->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox() ) );
133 connect( GroupPoints->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox() ) );
135 connect( myGeomGUI, SIGNAL( SignalDefaultStepValueChanged( double ) ), this, SLOT( SetDoubleSpinBoxStep( double ) ) );
137 connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
138 this, SLOT( SelectionIntoArgument() ) );
140 initName( tr( "GEOM_SPHERE" ) );
142 setConstructorId( 1 ); // simplest constructor
143 ConstructorsClicked( 1 );
146 //=================================================================================
147 // function : SetDoubleSpinBoxStep()
148 // purpose : Double spin box management
149 //=================================================================================
150 void PrimitiveGUI_SphereDlg::SetDoubleSpinBoxStep( double step )
152 GroupPoints->SpinBox_DX->setSingleStep(step);
153 GroupDimensions->SpinBox_DX->setSingleStep(step);
156 //=================================================================================
157 // function : ConstructorsClicked()
158 // purpose : Radio button management
159 //=================================================================================
160 void PrimitiveGUI_SphereDlg::ConstructorsClicked( int constructorId )
162 disconnect( myGeomGUI->getApp()->selectionMgr(), 0, this, 0 );
164 switch ( constructorId ) {
167 globalSelection(); // close local contexts, if any
168 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
170 GroupDimensions->hide();
173 myEditCurrentArgument = GroupPoints->LineEdit1;
174 GroupPoints->LineEdit1->setText( "" );
175 myPoint = GEOM::GEOM_Object::_nil();
177 connect( myGeomGUI->getApp()->selectionMgr(),
178 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
183 globalSelection(); // close local contexts, if any
186 GroupDimensions->show();
192 qApp->processEvents();
194 resize( minimumSizeHint() );
200 //=================================================================================
201 // function : ClickOnOk()
203 //=================================================================================
204 void PrimitiveGUI_SphereDlg::ClickOnOk()
206 if ( ClickOnApply() )
211 //=================================================================================
212 // function : ClickOnApply()
214 //=================================================================================
215 bool PrimitiveGUI_SphereDlg::ClickOnApply()
221 ConstructorsClicked( getConstructorId() );
226 //=================================================================================
227 // function : SelectionIntoArgument()
228 // purpose : Called when selection as changed or other case
229 //=================================================================================
230 void PrimitiveGUI_SphereDlg::SelectionIntoArgument()
232 if ( getConstructorId() != 0 )
235 myEditCurrentArgument->setText( "" );
237 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
238 SALOME_ListIO aSelList;
239 aSelMgr->selectedObjects(aSelList);
241 if (aSelList.Extent() != 1) {
242 myPoint = GEOM::GEOM_Object::_nil();
247 Standard_Boolean testResult = Standard_False;
248 GEOM::GEOM_Object_ptr aSelectedObject = GEOMBase::ConvertIOinGEOMObject(aSelList.First(), testResult);
250 if ( !testResult || CORBA::is_nil( aSelectedObject ) )
253 QString aName = GEOMBase::GetName( aSelectedObject );
255 if ( GEOMBase::GetShape( aSelectedObject, aShape, TopAbs_SHAPE) && !aShape.IsNull() ) {
256 TColStd_IndexedMapOfInteger aMap;
257 aSelMgr->GetIndexes(aSelList.First(), aMap);
258 if ( aMap.Extent() == 1 ) { // Local Selection
259 int anIndex = aMap( 1 );
260 aName.append( ":vertex_" + QString::number( anIndex ) );
262 //Find SubShape Object in Father
263 GEOM::GEOM_Object_var aFindedObject = findObjectInFather(aSelectedObject, aName );
265 if ( aFindedObject == GEOM::GEOM_Object::_nil() ) { // Object not found in study
266 GEOM::GEOM_IShapesOperations_var aShapesOp =
267 getGeomEngine()->GetIShapesOperations( getStudyId() );
268 aSelectedObject = aShapesOp->GetSubShape( aSelectedObject, anIndex );
271 aSelectedObject = aFindedObject; // get Object from study
274 else { // Global Selection
275 if (aShape.ShapeType() != TopAbs_VERTEX) {
276 aSelectedObject = GEOM::GEOM_Object::_nil();
282 myEditCurrentArgument->setText( aName );
283 myPoint = aSelectedObject;
288 //=================================================================================
289 // function : LineEditReturnPressed()
291 //=================================================================================
292 void PrimitiveGUI_SphereDlg::LineEditReturnPressed()
294 QLineEdit* send = (QLineEdit*)sender();
295 if ( send == GroupPoints->LineEdit1 ) {
296 myEditCurrentArgument = send;
297 GEOMBase_Skeleton::LineEditReturnPressed();
302 //=================================================================================
303 // function : SetEditCurrentArgument()
305 //=================================================================================
306 void PrimitiveGUI_SphereDlg::SetEditCurrentArgument()
308 QPushButton* send = (QPushButton*)sender();
310 if ( send == GroupPoints->PushButton1 ) {
311 GroupPoints->LineEdit1->setFocus();
312 myEditCurrentArgument = GroupPoints->LineEdit1;
313 globalSelection(); // close local contexts, if any
314 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
315 SelectionIntoArgument();
320 //=================================================================================
321 // function : ActivateThisDialog()
323 //=================================================================================
324 void PrimitiveGUI_SphereDlg::ActivateThisDialog()
326 GEOMBase_Skeleton::ActivateThisDialog();
327 connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
328 this, SLOT( SelectionIntoArgument() ) );
330 ConstructorsClicked( getConstructorId() );
334 //=================================================================================
335 // function : DeactivateActiveDialog()
336 // purpose : public slot to deactivate if active
337 //=================================================================================
338 void PrimitiveGUI_SphereDlg::DeactivateActiveDialog()
340 GEOMBase_Skeleton::DeactivateActiveDialog();
344 //=================================================================================
345 // function : enterEvent()
347 //=================================================================================
348 void PrimitiveGUI_SphereDlg::enterEvent( QEvent* )
350 if ( !mainFrame()->GroupConstructors->isEnabled() )
351 ActivateThisDialog();
355 //=================================================================================
356 // function : ValueChangedInSpinBox()
358 //=================================================================================
359 void PrimitiveGUI_SphereDlg::ValueChangedInSpinBox()
365 //=================================================================================
366 // function : createOperation
368 //=================================================================================
369 GEOM::GEOM_IOperations_ptr PrimitiveGUI_SphereDlg::createOperation()
371 return getGeomEngine()->GetI3DPrimOperations( getStudyId() );
375 //=================================================================================
376 // function : isValid
378 //=================================================================================
379 bool PrimitiveGUI_SphereDlg::isValid( QString& msg )
382 if( getConstructorId() == 0 )
383 ok = GroupPoints->SpinBox_DX->isValid( msg, !IsPreview() ) && ok;
384 else if( getConstructorId() == 1 )
385 ok = GroupDimensions->SpinBox_DX->isValid( msg, !IsPreview() ) && ok;
386 return getConstructorId() == 0 ? !myPoint->_is_nil() && ok : ok;
389 //=================================================================================
390 // function : execute
392 //=================================================================================
393 bool PrimitiveGUI_SphereDlg::execute( ObjectList& objects )
397 GEOM::GEOM_Object_var anObj;
399 GEOM::GEOM_I3DPrimOperations_var anOper = GEOM::GEOM_I3DPrimOperations::_narrow(getOperation());
401 switch ( getConstructorId() ) {
404 if ( !CORBA::is_nil( myPoint ) ) {
405 anObj = anOper->MakeSpherePntR( myPoint, getRadius() );
406 if (!anObj->_is_nil() && !IsPreview())
408 QStringList aParameters;
409 aParameters << GroupPoints->SpinBox_DX->text();
410 anObj->SetParameters(aParameters.join(":").toLatin1().constData());
418 anObj = anOper->MakeSphereR( getRadius() );
419 if (!anObj->_is_nil() && !IsPreview())
421 QStringList aParameters;
422 aParameters << GroupDimensions->SpinBox_DX->text();
423 anObj->SetParameters(aParameters.join(":").toLatin1().constData());
430 if ( !anObj->_is_nil() )
431 objects.push_back( anObj._retn() );
437 //=================================================================================
438 // function : getRadius()
440 //=================================================================================
441 double PrimitiveGUI_SphereDlg::getRadius() const
443 int aConstructorId = getConstructorId();
444 if ( aConstructorId == 0 )
445 return GroupPoints->SpinBox_DX->value();
446 else if ( aConstructorId == 1 )
447 return GroupDimensions->SpinBox_DX->value();
451 //=================================================================================
452 // function : addSubshapeToStudy
453 // purpose : virtual method to add new SubObjects if local selection
454 //=================================================================================
455 void PrimitiveGUI_SphereDlg::addSubshapesToStudy()
457 QMap<QString, GEOM::GEOM_Object_var> objMap;
459 switch ( getConstructorId() ) {
461 objMap[GroupPoints->LineEdit1->text()] = myPoint;
466 addSubshapesToFather( objMap );