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_FaceDlg.cxx
24 // 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_OBJ_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( image2 );
65 mainFrame()->RadioButton2->setIcon( image0 );
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 GroupType = new DlgRef_3Radio( centralWidget() );
78 GroupType->GroupBox1->setTitle( tr( "GEOM_OBJECT_TYPE" ) );
79 GroupType->RadioButton1->setText( tr( "GEOM_EDGE" ) );
80 GroupType->RadioButton2->setText( tr( "GEOM_FACE" ) );
81 GroupType->RadioButton3->setAttribute( Qt::WA_DeleteOnClose );
82 GroupType->RadioButton3->close();
84 GroupDimensions = new DlgRef_2Spin( centralWidget() );
85 GroupDimensions->GroupBox1->setTitle( tr( "GEOM_BOX_OBJ" ) );
86 GroupDimensions->TextLabel1->setText( tr( "GEOM_HEIGHT" ) );
87 GroupDimensions->TextLabel2->setText( tr( "GEOM_WIDTH" ) );
89 GroupOrientation = new DlgRef_3Radio( centralWidget() );
91 GroupOrientation->GroupBox1->setTitle( tr( "GEOM_ORIENTATION" ) );
92 GroupOrientation->RadioButton1->setText( tr( "GEOM_WPLANE_OXY" ) );
93 GroupOrientation->RadioButton2->setText( tr( "GEOM_WPLANE_OYZ" ) );
94 GroupOrientation->RadioButton3->setText( tr( "GEOM_WPLANE_OZX" ) );
96 QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
97 layout->setMargin( 0 ); layout->setSpacing( 6 );
98 layout->addWidget( GroupType );
99 layout->addWidget( GroupPlane );
100 layout->addWidget( GroupDimensions );
101 layout->addWidget( GroupOrientation );
103 /***************************************************************/
105 setHelpFileName( "create_squareface_page.html" );
111 //=================================================================================
112 // function : ~PrimitiveGUI_FaceDlg()
113 // purpose : Destroys the object and frees any allocated resources
114 //=================================================================================
115 PrimitiveGUI_FaceDlg::~PrimitiveGUI_FaceDlg()
120 //=================================================================================
123 //=================================================================================
124 void PrimitiveGUI_FaceDlg::Init()
127 myEditCurrentArgument = GroupPlane->LineEdit1;
128 GroupType->RadioButton1->setChecked(true);
129 myEdge = GEOM::GEOM_Object::_nil();
130 myFace = GEOM::GEOM_Object::_nil();
131 globalSelection(); // close local contexts, if any
132 // localSelection( GEOM::GEOM_Object::_nil(), TopAbs_EDGE );
134 myOrientationType = 1;
136 /* Get setting of step value from file configuration */
137 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
138 double aStep = resMgr->doubleValue( "Geometry", "SettingsGeomStep", 100 );
140 double aDefaultSize = 100.0;
141 /* min, max, step and decimals for spin boxes */
142 initSpinBox( GroupPlane->SpinBox_DX, 0.00001, COORD_MAX, aStep, 6 ); // VSR: TODO: DBL_DIGITS_DISPLAY
143 GroupPlane->SpinBox_DX->setValue( aDefaultSize );
144 initSpinBox( GroupPlane->SpinBox_DY, 0.000001, COORD_MAX, aStep, 6 ); // VSR: TODO: DBL_DIGITS_DISPLAY
145 GroupPlane->SpinBox_DY->setValue( aDefaultSize );
147 initSpinBox( GroupDimensions->SpinBox_DX, 0.000001, COORD_MAX, aStep, 6 ); // VSR: TODO: DBL_DIGITS_DISPLAY
148 GroupDimensions->SpinBox_DX->setValue( aDefaultSize );
149 initSpinBox( GroupDimensions->SpinBox_DY, 0.000001, COORD_MAX, aStep, 6 ); // VSR: TODO: DBL_DIGITS_DISPLAY
150 GroupDimensions->SpinBox_DY->setValue( aDefaultSize );
153 /* signals and slots connections */
154 connect( myGeomGUI, SIGNAL( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) );
155 connect( myGeomGUI, SIGNAL( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) );
156 connect( myGeomGUI, SIGNAL( SignalDefaultStepValueChanged( double ) ), this, SLOT( SetDoubleSpinBoxStep( double ) ) );
158 connect( this, SIGNAL( constructorsClicked( int ) ), this, SLOT( ConstructorsClicked( int ) ) );
160 connect( buttonOk(), SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
161 connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
163 connect( GroupPlane->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
164 connect( GroupPlane->LineEdit1, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
165 connect( GroupPlane->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
166 connect( GroupPlane->SpinBox_DY, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
168 connect( GroupDimensions->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
169 connect( GroupDimensions->SpinBox_DY, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
171 connect( GroupOrientation->RadioButton1, SIGNAL( clicked() ), this, SLOT( RadioButtonClicked() ) );
172 connect( GroupOrientation->RadioButton2, SIGNAL( clicked() ), this, SLOT( RadioButtonClicked() ) );
173 connect( GroupOrientation->RadioButton3, SIGNAL( clicked() ), this, SLOT( RadioButtonClicked() ) );
175 connect( GroupType->RadioButton1, SIGNAL( clicked() ), this, SLOT( TypeButtonClicked() ) );
176 connect( GroupType->RadioButton2, SIGNAL( clicked() ), this, SLOT( TypeButtonClicked() ) );
178 connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
179 this, SLOT( SelectionIntoArgument() ) );
181 initName( tr( "GEOM_FACE" ) );
183 ConstructorsClicked( 0 );
186 //=================================================================================
187 // function : SetDoubleSpinBoxStep()
188 // purpose : Double spin box management
189 //=================================================================================
190 void PrimitiveGUI_FaceDlg::SetDoubleSpinBoxStep( double step )
192 GroupPlane->SpinBox_DX->setSingleStep(step);
193 GroupPlane->SpinBox_DY->setSingleStep(step);
196 //=================================================================================
197 // function : ValueChangedInSpinBox()
199 //=================================================================================
200 void PrimitiveGUI_FaceDlg::ValueChangedInSpinBox( double newValue )
205 //=================================================================================
206 // function : RadioBittonClicked()
207 // purpose : Radio button management
208 //=================================================================================
209 void PrimitiveGUI_FaceDlg::RadioButtonClicked()
211 if ( GroupOrientation->RadioButton1->isChecked() )
212 myOrientationType = 1;
213 else if ( GroupOrientation->RadioButton2->isChecked() )
214 myOrientationType = 2;
215 else if ( GroupOrientation->RadioButton3->isChecked() )
216 myOrientationType = 3;
220 //=================================================================================
221 // function : TypeBittonClicked()
222 // purpose : Radio button management
223 //=================================================================================
224 void PrimitiveGUI_FaceDlg::TypeButtonClicked()
226 if ( GroupType->RadioButton1->isChecked() ) {
227 globalSelection(); // close local contexts, if any
228 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_EDGE );
229 GroupPlane->TextLabel1->setText( tr( "GEOM_EDGE" ) );
231 else if ( GroupType->RadioButton2->isChecked() ) {
232 globalSelection(); // close local contexts, if any
233 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_FACE );
234 GroupPlane->TextLabel1->setText( tr( "GEOM_FACE" ) );
238 //=================================================================================
239 // function : ClickOnOk()
241 //=================================================================================
242 void PrimitiveGUI_FaceDlg::ClickOnOk()
244 if ( ClickOnApply() )
248 //=================================================================================
249 // function : ClickOnApply()
251 //=================================================================================
252 bool PrimitiveGUI_FaceDlg::ClickOnApply()
259 myEditCurrentArgument->setText( "" );
260 ConstructorsClicked( getConstructorId() );
265 //=================================================================================
266 // function : ConstructorsClicked()
267 // purpose : Radio button management
268 //=================================================================================
269 void PrimitiveGUI_FaceDlg::ConstructorsClicked( int constructorId )
272 switch ( constructorId ) {
275 globalSelection(); // close local contexts, if any
277 GroupDimensions->show();
278 GroupOrientation->show();
280 GroupOrientation->RadioButton1->setChecked( true );
281 myOrientationType = 1;
286 globalSelection(); // close local contexts, if any
287 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_EDGE );
288 myEditCurrentArgument = GroupPlane->LineEdit1;
289 myEditCurrentArgument->setText("");
290 myEdge = GEOM::GEOM_Object::_nil();
291 myFace = GEOM::GEOM_Object::_nil();
292 GroupType->RadioButton1->setChecked( true );
294 GroupDimensions->hide();
295 GroupOrientation->hide();
302 qApp->processEvents();
304 resize( minimumSize() );
305 SelectionIntoArgument();
309 //=================================================================================
310 // function : SelectionIntoArgument()
311 // purpose : Called when selection as changed or other case
312 //=================================================================================
313 void PrimitiveGUI_FaceDlg::SelectionIntoArgument()
315 if (getConstructorId() == 0) {
320 myEditCurrentArgument->setText( "" );
322 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
323 SALOME_ListIO aSelList;
324 aSelMgr->selectedObjects(aSelList);
326 if ( aSelList.Extent() != 1 ) {
327 if ( myEditCurrentArgument == GroupPlane->LineEdit1 ) myEdge = GEOM::GEOM_Object::_nil();
332 Standard_Boolean aRes = Standard_False;
333 TopAbs_ShapeEnum aNeedType = TopAbs_EDGE;
334 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( aSelList.First(), aRes );
335 if ( !CORBA::is_nil( aSelectedObject ) && aRes ) {
336 QString aName = GEOMBase::GetName( aSelectedObject );
339 if ( GEOMBase::GetShape( aSelectedObject, aShape, TopAbs_SHAPE ) && !aShape.IsNull() ) {
340 if (GroupType->RadioButton2->isChecked())
341 aNeedType = TopAbs_FACE;
343 TColStd_IndexedMapOfInteger aMap;
344 aSelMgr->GetIndexes( aSelList.First(), aMap );
345 if ( aMap.Extent() == 1 ) { // Local Selection
346 int anIndex = aMap( 1 );
347 if ( aNeedType == TopAbs_EDGE )
348 aName += QString( ":edge_%1" ).arg( anIndex );
350 aName += QString( ":face_%1" ).arg( anIndex );
352 //Find SubShape Object in Father
353 GEOM::GEOM_Object_var aFindedObject = GEOMBase_Helper::findObjectInFather( aSelectedObject, aName );
355 if ( aFindedObject == GEOM::GEOM_Object::_nil() ) { // Object not found in study
356 GEOM::GEOM_IShapesOperations_var aShapesOp = getGeomEngine()->GetIShapesOperations( getStudyId() );
357 aSelectedObject = aShapesOp->GetSubShape( aSelectedObject, anIndex );
360 aSelectedObject = aFindedObject; // get Object from study
362 else { // Global Selection
363 if ( aShape.ShapeType() != aNeedType ) {
364 aSelectedObject = GEOM::GEOM_Object::_nil();
370 myEditCurrentArgument->setText( aName );
371 if ( myEditCurrentArgument == GroupPlane->LineEdit1 && aNeedType == TopAbs_EDGE )
372 myEdge = aSelectedObject;
373 else if ( myEditCurrentArgument == GroupPlane->LineEdit1 && aNeedType == TopAbs_FACE )
374 myFace = aSelectedObject;
380 //=================================================================================
381 // function : SetEditCurrentArgument()
383 //=================================================================================
384 void PrimitiveGUI_FaceDlg::SetEditCurrentArgument()
386 QPushButton* send = (QPushButton*)sender();
388 globalSelection(); // close previous local contexts
389 if ( send == GroupPlane->PushButton1 ) {
390 myEditCurrentArgument = GroupPlane->LineEdit1;
391 if (GroupType->RadioButton1->isChecked())
392 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_EDGE );
393 else if (GroupType->RadioButton1->isChecked())
394 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_FACE );
397 myEditCurrentArgument->setFocus();
398 SelectionIntoArgument();
402 //=================================================================================
403 // function : LineEditReturnPressed()
405 //=================================================================================
406 void PrimitiveGUI_FaceDlg::LineEditReturnPressed()
408 QLineEdit* send = (QLineEdit*)sender();
409 if ( send == GroupPlane->LineEdit1 ) myEditCurrentArgument = GroupPlane->LineEdit1;
411 GEOMBase_Skeleton::LineEditReturnPressed();
415 //=================================================================================
416 // function : ActivateThisDialog()
418 //=================================================================================
419 void PrimitiveGUI_FaceDlg::ActivateThisDialog()
421 GEOMBase_Skeleton::ActivateThisDialog();
422 connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
423 this, SLOT( SelectionIntoArgument() ) );
425 ConstructorsClicked( getConstructorId() );
428 //=================================================================================
429 // function : DeactivateActiveDialog()
430 // purpose : public slot to deactivate if active
431 //=================================================================================
432 void PrimitiveGUI_FaceDlg::DeactivateActiveDialog()
434 GEOMBase_Skeleton::DeactivateActiveDialog();
437 //=================================================================================
438 // function : enterEvent()
440 //=================================================================================
441 void PrimitiveGUI_FaceDlg::enterEvent( QEvent* )
443 if ( !mainFrame()->GroupConstructors->isEnabled() )
444 ActivateThisDialog();
447 //=================================================================================
448 // function : createOperation
450 //=================================================================================
451 GEOM::GEOM_IOperations_ptr PrimitiveGUI_FaceDlg::createOperation()
453 return myGeomGUI->GetGeomGen()->GetI3DPrimOperations( getStudyId() );
456 //=================================================================================
457 // function : isValid
459 //=================================================================================
460 bool PrimitiveGUI_FaceDlg::isValid( QString& msg )
462 const int id = getConstructorId();
465 else if ( id == 1 ) {
466 if (GroupType->RadioButton1->isChecked())
467 return !myEdge->_is_nil();
468 else if (GroupType->RadioButton2->isChecked())
469 return !myFace->_is_nil();
474 //=================================================================================
475 // function : execute
477 //=================================================================================
478 bool PrimitiveGUI_FaceDlg::execute (ObjectList& objects)
481 GEOM::GEOM_Object_var anObj;
482 switch (getConstructorId()) {
484 anObj = GEOM::GEOM_I3DPrimOperations::_narrow(getOperation())->
485 MakeFaceHW(GroupDimensions->SpinBox_DX->value(),
486 GroupDimensions->SpinBox_DY->value(), myOrientationType);
490 if (GroupType->RadioButton1->isChecked())
491 anObj = GEOM::GEOM_I3DPrimOperations::_narrow(getOperation())->
492 MakeFaceObjHW(myEdge, GroupPlane->SpinBox_DX->value(), GroupPlane->SpinBox_DY->value());
493 else if (GroupType->RadioButton2->isChecked())
494 anObj = GEOM::GEOM_I3DPrimOperations::_narrow(getOperation())->
495 MakeFaceObjHW(myFace, GroupPlane->SpinBox_DX->value(), GroupPlane->SpinBox_DY->value());
500 if (!anObj->_is_nil())
501 objects.push_back(anObj._retn());
506 //=================================================================================
507 // function : addSubshapeToStudy
508 // purpose : virtual method to add new SubObjects if local selection
509 //=================================================================================
510 void PrimitiveGUI_FaceDlg::addSubshapesToStudy()
512 QMap<QString, GEOM::GEOM_Object_var> objMap;
513 switch ( getConstructorId() ) {
515 if ( GroupType->RadioButton1->isChecked() )
516 objMap[GroupPlane->LineEdit1->text()] = myEdge;
517 if ( GroupType->RadioButton2->isChecked() )
518 objMap[GroupPlane->LineEdit1->text()] = myFace;
521 addSubshapesToFather( objMap );