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_VEC_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_ARGUMENTS" ) );
71 GroupPlane->TextLabel1->setText( tr( "GEOM_EDGE" ) );
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 GroupOrientation = new DlgRef_3Check( centralWidget() );
84 GroupOrientation->GroupBox1->setTitle( tr( "GEOM_ORIENTATION" ) );
85 GroupOrientation->RadioButton1->setText( tr( "GEOM_WPLANE_OXY" ) );
86 GroupOrientation->RadioButton2->setText( tr( "GEOM_WPLANE_OYZ" ) );
87 GroupOrientation->RadioButton3->setText( tr( "GEOM_WPLANE_OZX" ) );
89 QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
90 layout->setMargin( 0 ); layout->setSpacing( 6 );
91 layout->addWidget( GroupPlane );
92 layout->addWidget( GroupDimensions );
93 layout->addWidget( GroupOrientation );
95 /***************************************************************/
97 setHelpFileName( "create_face_page.html" );
103 //=================================================================================
104 // function : ~PrimitiveGUI_FaceDlg()
105 // purpose : Destroys the object and frees any allocated resources
106 //=================================================================================
107 PrimitiveGUI_FaceDlg::~PrimitiveGUI_FaceDlg()
112 //=================================================================================
115 //=================================================================================
116 void PrimitiveGUI_FaceDlg::Init()
119 myEditCurrentArgument = GroupPlane->LineEdit1;
120 myEdge = GEOM::GEOM_Object::_nil();
121 globalSelection(); // close local contexts, if any
122 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_EDGE );
124 myOrientationType = 1;
126 /* Get setting of step value from file configuration */
127 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
128 double aStep = resMgr->doubleValue( "Geometry", "SettingsGeomStep", 100 );
130 double aDefaultSize = 100.0;
131 /* min, max, step and decimals for spin boxes */
132 initSpinBox( GroupPlane->SpinBox_DX, 0.001, COORD_MAX, aStep, 3 ); // VSR:TODO : DBL_DIGITS_DISPLAY
133 GroupPlane->SpinBox_DX->setValue( aDefaultSize );
134 initSpinBox( GroupPlane->SpinBox_DY, 0.001, COORD_MAX, aStep, 3 ); // VSR:TODO : DBL_DIGITS_DISPLAY
135 GroupPlane->SpinBox_DY->setValue( aDefaultSize );
137 initSpinBox( GroupDimensions->SpinBox_DX, 0.001, COORD_MAX, aStep, 3 ); // VSR:TODO : DBL_DIGITS_DISPLAY
138 GroupDimensions->SpinBox_DX->setValue( aDefaultSize );
139 initSpinBox( GroupDimensions->SpinBox_DY, 0.001, COORD_MAX, aStep, 3 ); // VSR:TODO : DBL_DIGITS_DISPLAY
140 GroupDimensions->SpinBox_DY->setValue( aDefaultSize );
143 /* signals and slots connections */
144 connect( myGeomGUI, SIGNAL( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) );
145 connect( myGeomGUI, SIGNAL( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) );
146 connect( myGeomGUI, SIGNAL( SignalDefaultStepValueChanged( double ) ), this, SLOT( SetDoubleSpinBoxStep( double ) ) );
148 connect( this, SIGNAL( constructorsClicked( int ) ), this, SLOT( ConstructorsClicked( int ) ) );
150 connect( buttonOk(), SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
151 connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
153 connect( GroupPlane->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
154 connect( GroupPlane->LineEdit1, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
155 connect( GroupPlane->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
156 connect( GroupPlane->SpinBox_DY, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
158 connect( GroupDimensions->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
159 connect( GroupDimensions->SpinBox_DY, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
161 connect( GroupOrientation->RadioButton1, SIGNAL( clicked() ), this, SLOT( RadioButtonClicked() ) );
162 connect( GroupOrientation->RadioButton2, SIGNAL( clicked() ), this, SLOT( RadioButtonClicked() ) );
163 connect( GroupOrientation->RadioButton3, SIGNAL( clicked() ), this, SLOT( RadioButtonClicked() ) );
165 connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
166 this, SLOT( SelectionIntoArgument() ) );
168 initName( tr( "GEOM_FACE" ) );
170 ConstructorsClicked( 0 );
173 //=================================================================================
174 // function : SetDoubleSpinBoxStep()
175 // purpose : Double spin box management
176 //=================================================================================
177 void PrimitiveGUI_FaceDlg::SetDoubleSpinBoxStep( double step )
179 GroupPlane->SpinBox_DX->setSingleStep(step);
180 GroupPlane->SpinBox_DY->setSingleStep(step);
183 //=================================================================================
184 // function : ValueChangedInSpinBox()
186 //=================================================================================
187 void PrimitiveGUI_FaceDlg::ValueChangedInSpinBox( double newValue )
192 //=================================================================================
193 // function : RadioBittonClicked()
194 // purpose : Radio button management
195 //=================================================================================
196 void PrimitiveGUI_FaceDlg::RadioButtonClicked()
198 if ( GroupOrientation->RadioButton1->isChecked() )
199 myOrientationType = 1;
200 else if ( GroupOrientation->RadioButton2->isChecked() )
201 myOrientationType = 2;
202 else if ( GroupOrientation->RadioButton3->isChecked() )
203 myOrientationType = 3;
207 //=================================================================================
208 // function : ClickOnOk()
210 //=================================================================================
211 void PrimitiveGUI_FaceDlg::ClickOnOk()
213 if ( ClickOnApply() )
217 //=================================================================================
218 // function : ClickOnApply()
220 //=================================================================================
221 bool PrimitiveGUI_FaceDlg::ClickOnApply()
228 myEditCurrentArgument->setText( "" );
229 ConstructorsClicked( getConstructorId() );
234 //=================================================================================
235 // function : ConstructorsClicked()
236 // purpose : Radio button management
237 //=================================================================================
238 void PrimitiveGUI_FaceDlg::ConstructorsClicked( int constructorId )
240 switch ( constructorId ) {
243 globalSelection(); // close local contexts, if any
244 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_EDGE );
246 myEditCurrentArgument = GroupPlane->LineEdit1;
247 myEditCurrentArgument->setText("");
248 myEdge = GEOM::GEOM_Object::_nil();
249 GroupDimensions->hide();
250 GroupOrientation->hide();
256 globalSelection(); // close local contexts, if any
258 GroupDimensions->show();
259 GroupOrientation->show();
260 GroupOrientation->RadioButton1->setChecked( true );
261 myOrientationType = 1;
266 qApp->processEvents();
268 resize( minimumSize() );
269 SelectionIntoArgument();
273 //=================================================================================
274 // function : SelectionIntoArgument()
275 // purpose : Called when selection as changed or other case
276 //=================================================================================
277 void PrimitiveGUI_FaceDlg::SelectionIntoArgument()
279 if (getConstructorId() != 0) {
284 myEditCurrentArgument->setText( "" );
286 if ( IObjectCount() != 1 ) {
287 if ( myEditCurrentArgument == GroupPlane->LineEdit1 ) myEdge = GEOM::GEOM_Object::_nil();
292 Standard_Boolean aRes = Standard_False;
293 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( firstIObject(), aRes );
294 if ( !CORBA::is_nil( aSelectedObject ) && aRes ) {
295 QString aName = GEOMBase::GetName( aSelectedObject );
298 if ( GEOMBase::GetShape( aSelectedObject, aShape, TopAbs_SHAPE ) && !aShape.IsNull() ) {
299 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
300 TColStd_IndexedMapOfInteger aMap;
301 aSelMgr->GetIndexes( firstIObject(), aMap );
302 if ( aMap.Extent() == 1 ) { // Local Selection
303 int anIndex = aMap( 1 );
304 aName += QString( ":edge_%1" ).arg( anIndex );
306 //Find SubShape Object in Father
307 GEOM::GEOM_Object_var aFindedObject = GEOMBase_Helper::findObjectInFather( aSelectedObject, aName );
309 if ( aFindedObject == GEOM::GEOM_Object::_nil() ) { // Object not found in study
310 GEOM::GEOM_IShapesOperations_var aShapesOp = getGeomEngine()->GetIShapesOperations( getStudyId() );
311 aSelectedObject = aShapesOp->GetSubShape( aSelectedObject, anIndex );
314 aSelectedObject = aFindedObject; // get Object from study
316 else { // Global Selection
317 if ( aShape.ShapeType() != TopAbs_EDGE ) {
318 aSelectedObject = GEOM::GEOM_Object::_nil();
324 myEditCurrentArgument->setText( aName );
325 if ( myEditCurrentArgument == GroupPlane->LineEdit1 ) myEdge = aSelectedObject;
331 //=================================================================================
332 // function : SetEditCurrentArgument()
334 //=================================================================================
335 void PrimitiveGUI_FaceDlg::SetEditCurrentArgument()
337 QPushButton* send = (QPushButton*)sender();
339 globalSelection(); // close previous local contexts
340 if ( send == GroupPlane->PushButton1 ) {
341 myEditCurrentArgument = GroupPlane->LineEdit1;
342 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_EDGE );
345 myEditCurrentArgument->setFocus();
346 SelectionIntoArgument();
350 //=================================================================================
351 // function : LineEditReturnPressed()
353 //=================================================================================
354 void PrimitiveGUI_FaceDlg::LineEditReturnPressed()
356 QLineEdit* send = (QLineEdit*)sender();
357 if ( send == GroupPlane->LineEdit1 ) myEditCurrentArgument = GroupPlane->LineEdit1;
359 GEOMBase_Skeleton::LineEditReturnPressed();
363 //=================================================================================
364 // function : ActivateThisDialog()
366 //=================================================================================
367 void PrimitiveGUI_FaceDlg::ActivateThisDialog()
369 GEOMBase_Skeleton::ActivateThisDialog();
370 connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
371 this, SLOT( SelectionIntoArgument() ) );
373 ConstructorsClicked( getConstructorId() );
376 //=================================================================================
377 // function : DeactivateActiveDialog()
378 // purpose : public slot to deactivate if active
379 //=================================================================================
380 void PrimitiveGUI_FaceDlg::DeactivateActiveDialog()
382 GEOMBase_Skeleton::DeactivateActiveDialog();
385 //=================================================================================
386 // function : enterEvent()
388 //=================================================================================
389 void PrimitiveGUI_FaceDlg::enterEvent( QEvent* )
391 if ( !mainFrame()->GroupConstructors->isEnabled() )
392 ActivateThisDialog();
395 //=================================================================================
396 // function : createOperation
398 //=================================================================================
399 GEOM::GEOM_IOperations_ptr PrimitiveGUI_FaceDlg::createOperation()
401 return myGeomGUI->GetGeomGen()->GetI3DPrimOperations( getStudyId() );
404 //=================================================================================
405 // function : isValid
407 //=================================================================================
408 bool PrimitiveGUI_FaceDlg::isValid( QString& msg )
410 const int id = getConstructorId();
412 return !myEdge->_is_nil();
418 //=================================================================================
419 // function : execute
421 //=================================================================================
422 bool PrimitiveGUI_FaceDlg::execute( ObjectList& objects )
425 GEOM::GEOM_Object_var anObj;
426 switch ( getConstructorId() ) {
428 anObj = GEOM::GEOM_I3DPrimOperations::_narrow( getOperation() )->MakeFaceVecHW( myEdge, GroupPlane->SpinBox_DX->value(), GroupPlane->SpinBox_DY->value() );
432 anObj = GEOM::GEOM_I3DPrimOperations::_narrow( getOperation() )->MakeFaceHW( GroupDimensions->SpinBox_DX->value(), GroupDimensions->SpinBox_DY->value(), myOrientationType );
437 if ( !anObj->_is_nil() )
438 objects.push_back( anObj._retn() );
443 //=================================================================================
444 // function : addSubshapeToStudy
445 // purpose : virtual method to add new SubObjects if local selection
446 //=================================================================================
447 void PrimitiveGUI_FaceDlg::addSubshapesToStudy()
449 QMap<QString, GEOM::GEOM_Object_var> objMap;
450 switch ( getConstructorId() ) {
452 objMap[GroupPlane->LineEdit1->text()] = myEdge;
455 addSubshapesToFather( objMap );