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_FaceDlg.cxx
23 // Author : Dmitry Matveitchev, OCN.
26 #include "PrimitiveGUI_FaceDlg.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_FaceDlg()
47 // purpose : Constructs a PrimitiveGUI_FaceDlg 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_FaceDlg::PrimitiveGUI_FaceDlg( 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_FACE_PLANE_HW" ) ) );
57 QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
58 QPixmap image2( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_FACE_HW" ) ) );
60 setWindowTitle( tr( "GEOM_FACE_TITLE" ) );
62 /***************************************************************/
63 mainFrame()->GroupConstructors->setTitle( tr( "GEOM_FACE" ) );
64 mainFrame()->RadioButton1->setIcon( image0 );
65 mainFrame()->RadioButton2->setIcon( image2 );
66 mainFrame()->RadioButton3->setAttribute( Qt::WA_DeleteOnClose );
67 mainFrame()->RadioButton3->close();
69 GroupPlane = new DlgRef_1Sel2Spin( centralWidget() );
70 GroupPlane->GroupBox1->setTitle( tr( "GEOM_FACES" ) );
71 GroupPlane->TextLabel1->setText( tr( "GEOM_FACE" ) );
72 GroupPlane->TextLabel2->setText( tr( "GEOM_HEIGHT" ) );
73 GroupPlane->TextLabel3->setText( tr( "GEOM_WIDTH" ) );
74 GroupPlane->PushButton1->setIcon( image1 );
75 GroupPlane->LineEdit1->setReadOnly( true );
77 GroupDimensions = new DlgRef_2Spin( centralWidget() );
78 GroupDimensions->GroupBox1->setTitle( tr( "GEOM_BOX_OBJ" ) );
79 GroupDimensions->TextLabel1->setText( tr( "GEOM_HEIGHT" ) );
80 GroupDimensions->TextLabel2->setText( tr( "GEOM_WIDTH" ) );
82 QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
83 layout->setMargin( 0 ); layout->setSpacing( 6 );
84 layout->addWidget( GroupPlane );
85 layout->addWidget( GroupDimensions );
87 /***************************************************************/
89 setHelpFileName( "create_face_page.html" );
95 //=================================================================================
96 // function : ~PrimitiveGUI_FaceDlg()
97 // purpose : Destroys the object and frees any allocated resources
98 //=================================================================================
99 PrimitiveGUI_FaceDlg::~PrimitiveGUI_FaceDlg()
104 //=================================================================================
107 //=================================================================================
108 void PrimitiveGUI_FaceDlg::Init()
111 myEditCurrentArgument = GroupPlane->LineEdit1;
112 myFace = GEOM::GEOM_Object::_nil();
113 globalSelection(); // close local contexts, if any
114 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_FACE );
116 /* Get setting of step value from file configuration */
117 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
118 double aStep = resMgr->doubleValue( "Geometry", "SettingsGeomStep", 100 );
120 double aDefaultSize = 100.0;
121 /* min, max, step and decimals for spin boxes */
122 initSpinBox( GroupPlane->SpinBox_DX, 0.001, COORD_MAX, aStep, 3 ); // VSR:TODO : DBL_DIGITS_DISPLAY
123 GroupPlane->SpinBox_DX->setValue( aDefaultSize );
124 initSpinBox( GroupPlane->SpinBox_DY, 0.001, COORD_MAX, aStep, 3 ); // VSR:TODO : DBL_DIGITS_DISPLAY
125 GroupPlane->SpinBox_DY->setValue( aDefaultSize );
127 initSpinBox( GroupDimensions->SpinBox_DX, 0.001, COORD_MAX, aStep, 3 ); // VSR:TODO : DBL_DIGITS_DISPLAY
128 GroupDimensions->SpinBox_DX->setValue( aDefaultSize );
129 initSpinBox( GroupDimensions->SpinBox_DY, 0.001, COORD_MAX, aStep, 3 ); // VSR:TODO : DBL_DIGITS_DISPLAY
130 GroupDimensions->SpinBox_DY->setValue( aDefaultSize );
133 /* signals and slots connections */
134 connect( myGeomGUI, SIGNAL( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) );
135 connect( myGeomGUI, SIGNAL( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) );
136 connect( myGeomGUI, SIGNAL( SignalDefaultStepValueChanged( double ) ), this, SLOT( SetDoubleSpinBoxStep( double ) ) );
138 connect( this, SIGNAL( constructorsClicked( int ) ), this, SLOT( ConstructorsClicked( int ) ) );
140 connect( buttonOk(), SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
141 connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
143 connect( GroupPlane->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
144 connect( GroupPlane->LineEdit1, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
145 connect( GroupPlane->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
146 connect( GroupPlane->SpinBox_DY, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
148 connect( GroupDimensions->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
149 connect( GroupDimensions->SpinBox_DY, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
151 connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
152 this, SLOT( SelectionIntoArgument() ) );
154 initName( tr( "GEOM_FACE" ) );
156 ConstructorsClicked( 0 );
159 //=================================================================================
160 // function : SetDoubleSpinBoxStep()
161 // purpose : Double spin box management
162 //=================================================================================
163 void PrimitiveGUI_FaceDlg::SetDoubleSpinBoxStep( double step )
165 GroupPlane->SpinBox_DX->setSingleStep(step);
166 GroupPlane->SpinBox_DY->setSingleStep(step);
169 //=================================================================================
170 // function : ValueChangedInSpinBox()
172 //=================================================================================
173 void PrimitiveGUI_FaceDlg::ValueChangedInSpinBox( double newValue )
178 //=================================================================================
179 // function : ClickOnOk()
181 //=================================================================================
182 void PrimitiveGUI_FaceDlg::ClickOnOk()
184 if ( ClickOnApply() )
188 //=================================================================================
189 // function : ClickOnApply()
191 //=================================================================================
192 bool PrimitiveGUI_FaceDlg::ClickOnApply()
199 myEditCurrentArgument->setText( "" );
200 ConstructorsClicked( getConstructorId() );
205 //=================================================================================
206 // function : ConstructorsClicked()
207 // purpose : Radio button management
208 //=================================================================================
209 void PrimitiveGUI_FaceDlg::ConstructorsClicked( int constructorId )
211 switch ( constructorId ) {
214 globalSelection(); // close local contexts, if any
215 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_FACE );
217 myEditCurrentArgument = GroupPlane->LineEdit1;
218 myEditCurrentArgument->setText("");
219 myFace = GEOM::GEOM_Object::_nil();
220 GroupDimensions->hide();
226 globalSelection(); // close local contexts, if any
228 GroupDimensions->show();
233 qApp->processEvents();
235 resize( minimumSize() );
236 SelectionIntoArgument();
239 //=================================================================================
240 // function : SelectionIntoArgument()
241 // purpose : Called when selection as changed or other case
242 //=================================================================================
243 void PrimitiveGUI_FaceDlg::SelectionIntoArgument()
245 if (getConstructorId() != 0) {
250 myEditCurrentArgument->setText( "" );
252 if ( IObjectCount() != 1 ) {
253 if ( myEditCurrentArgument == GroupPlane->LineEdit1 ) myFace = GEOM::GEOM_Object::_nil();
258 Standard_Boolean aRes = Standard_False;
259 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( firstIObject(), aRes );
260 if ( !CORBA::is_nil( aSelectedObject ) && aRes ) {
261 QString aName = GEOMBase::GetName( aSelectedObject );
264 if ( GEOMBase::GetShape( aSelectedObject, aShape, TopAbs_SHAPE ) && !aShape.IsNull() ) {
265 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
266 TColStd_IndexedMapOfInteger aMap;
267 aSelMgr->GetIndexes( firstIObject(), aMap );
268 if ( aMap.Extent() == 1 ) { // Local Selection
269 int anIndex = aMap( 1 );
270 aName += QString( ":face_%1" ).arg( anIndex );
272 //Find SubShape Object in Father
273 GEOM::GEOM_Object_var aFindedObject = GEOMBase_Helper::findObjectInFather( aSelectedObject, aName );
275 if ( aFindedObject == GEOM::GEOM_Object::_nil() ) { // Object not found in study
276 GEOM::GEOM_IShapesOperations_var aShapesOp = getGeomEngine()->GetIShapesOperations( getStudyId() );
277 aSelectedObject = aShapesOp->GetSubShape( aSelectedObject, anIndex );
280 aSelectedObject = aFindedObject; // get Object from study
282 else { // Global Selection
283 if ( aShape.ShapeType() != TopAbs_FACE ) {
284 aSelectedObject = GEOM::GEOM_Object::_nil();
290 myEditCurrentArgument->setText( aName );
291 if ( myEditCurrentArgument == GroupPlane->LineEdit1 ) myFace = aSelectedObject;
297 //=================================================================================
298 // function : SetEditCurrentArgument()
300 //=================================================================================
301 void PrimitiveGUI_FaceDlg::SetEditCurrentArgument()
303 QPushButton* send = (QPushButton*)sender();
305 globalSelection(); // close previous local contexts
306 if ( send == GroupPlane->PushButton1 ) {
307 myEditCurrentArgument = GroupPlane->LineEdit1;
308 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_FACE );
311 myEditCurrentArgument->setFocus();
312 SelectionIntoArgument();
316 //=================================================================================
317 // function : LineEditReturnPressed()
319 //=================================================================================
320 void PrimitiveGUI_FaceDlg::LineEditReturnPressed()
322 QLineEdit* send = (QLineEdit*)sender();
323 if ( send == GroupPlane->LineEdit1 ) myEditCurrentArgument = GroupPlane->LineEdit1;
325 GEOMBase_Skeleton::LineEditReturnPressed();
329 //=================================================================================
330 // function : ActivateThisDialog()
332 //=================================================================================
333 void PrimitiveGUI_FaceDlg::ActivateThisDialog()
335 GEOMBase_Skeleton::ActivateThisDialog();
336 connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
337 this, SLOT( SelectionIntoArgument() ) );
339 ConstructorsClicked( getConstructorId() );
342 //=================================================================================
343 // function : DeactivateActiveDialog()
344 // purpose : public slot to deactivate if active
345 //=================================================================================
346 void PrimitiveGUI_FaceDlg::DeactivateActiveDialog()
348 GEOMBase_Skeleton::DeactivateActiveDialog();
351 //=================================================================================
352 // function : enterEvent()
354 //=================================================================================
355 void PrimitiveGUI_FaceDlg::enterEvent( QEvent* )
357 if ( !mainFrame()->GroupConstructors->isEnabled() )
358 ActivateThisDialog();
361 //=================================================================================
362 // function : createOperation
364 //=================================================================================
365 GEOM::GEOM_IOperations_ptr PrimitiveGUI_FaceDlg::createOperation()
367 return myGeomGUI->GetGeomGen()->GetI3DPrimOperations( getStudyId() );
370 //=================================================================================
371 // function : isValid
373 //=================================================================================
374 bool PrimitiveGUI_FaceDlg::isValid( QString& msg )
376 const int id = getConstructorId();
378 return !myFace->_is_nil();
384 //=================================================================================
385 // function : execute
387 //=================================================================================
388 bool PrimitiveGUI_FaceDlg::execute( ObjectList& objects )
391 GEOM::GEOM_Object_var anObj;
392 switch ( getConstructorId() ) {
394 anObj = GEOM::GEOM_I3DPrimOperations::_narrow( getOperation() )->MakeFacePlaneHW( myFace, GroupPlane->SpinBox_DX->value(), GroupPlane->SpinBox_DY->value() );
398 anObj = GEOM::GEOM_I3DPrimOperations::_narrow( getOperation() )->MakeFaceHW( GroupDimensions->SpinBox_DX->value(), GroupDimensions->SpinBox_DY->value() );
403 if ( !anObj->_is_nil() )
404 objects.push_back( anObj._retn() );
409 //=================================================================================
410 // function : addSubshapeToStudy
411 // purpose : virtual method to add new SubObjects if local selection
412 //=================================================================================
413 void PrimitiveGUI_FaceDlg::addSubshapesToStudy()
415 QMap<QString, GEOM::GEOM_Object_var> objMap;
416 switch ( getConstructorId() ) {
418 objMap[GroupPlane->LineEdit1->text()] = myFace;
421 addSubshapesToFather( objMap );