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 <SalomeApp_Notebook.h>
36 #include <LightApp_SelectionMgr.h>
38 #include <TopoDS_Shape.hxx>
41 #include <TColStd_IndexedMapOfInteger.hxx>
42 #include <TopTools_IndexedMapOfShape.hxx>
44 #include <GEOMImpl_Types.hxx>
46 //=================================================================================
47 // class : PrimitiveGUI_FaceDlg()
48 // purpose : Constructs a PrimitiveGUI_FaceDlg 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_FaceDlg::PrimitiveGUI_FaceDlg( GeometryGUI* theGeometryGUI, QWidget* parent,
54 bool modal, Qt::WindowFlags fl )
55 : GEOMBase_Skeleton( theGeometryGUI, parent, modal, fl )
57 QPixmap image0 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_FACE_OBJ_HW")));
58 QPixmap image1 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_SELECT")));
59 QPixmap image2 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_FACE_HW")));
61 setWindowTitle( tr( "GEOM_FACE_TITLE" ) );
63 /***************************************************************/
64 mainFrame()->GroupConstructors->setTitle( tr( "GEOM_FACE" ) );
65 mainFrame()->RadioButton1->setIcon( image2 );
66 mainFrame()->RadioButton2->setIcon( image0 );
67 mainFrame()->RadioButton3->setAttribute( Qt::WA_DeleteOnClose );
68 mainFrame()->RadioButton3->close();
70 GroupPlane = new DlgRef_1Sel2Spin( centralWidget() );
71 GroupPlane->GroupBox1->setTitle( tr( "GEOM_ARGUMENTS" ) );
72 GroupPlane->TextLabel1->setText( tr( "GEOM_EDGE" ) );
73 GroupPlane->TextLabel2->setText( tr( "GEOM_HEIGHT" ) );
74 GroupPlane->TextLabel3->setText( tr( "GEOM_WIDTH" ) );
75 GroupPlane->PushButton1->setIcon( image1 );
76 GroupPlane->LineEdit1->setReadOnly( true );
78 GroupType = new DlgRef_3Radio( centralWidget() );
79 GroupType->GroupBox1->setTitle( tr( "GEOM_OBJECT_TYPE" ) );
80 GroupType->RadioButton1->setText( tr( "GEOM_EDGE" ) );
81 GroupType->RadioButton2->setText( tr( "GEOM_FACE" ) );
82 GroupType->RadioButton3->setAttribute( Qt::WA_DeleteOnClose );
83 GroupType->RadioButton3->close();
85 GroupDimensions = new DlgRef_2Spin( centralWidget() );
86 GroupDimensions->GroupBox1->setTitle( tr( "GEOM_BOX_OBJ" ) );
87 GroupDimensions->TextLabel1->setText( tr( "GEOM_HEIGHT" ) );
88 GroupDimensions->TextLabel2->setText( tr( "GEOM_WIDTH" ) );
90 GroupOrientation = new DlgRef_3Radio( centralWidget() );
92 GroupOrientation->GroupBox1->setTitle( tr( "GEOM_ORIENTATION" ) );
93 GroupOrientation->RadioButton1->setText( tr( "GEOM_WPLANE_OXY" ) );
94 GroupOrientation->RadioButton2->setText( tr( "GEOM_WPLANE_OYZ" ) );
95 GroupOrientation->RadioButton3->setText( tr( "GEOM_WPLANE_OZX" ) );
97 QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
98 layout->setMargin( 0 ); layout->setSpacing( 6 );
99 layout->addWidget( GroupType );
100 layout->addWidget( GroupPlane );
101 layout->addWidget( GroupDimensions );
102 layout->addWidget( GroupOrientation );
104 /***************************************************************/
106 setHelpFileName( "create_squareface_page.html" );
112 //=================================================================================
113 // function : ~PrimitiveGUI_FaceDlg()
114 // purpose : Destroys the object and frees any allocated resources
115 //=================================================================================
116 PrimitiveGUI_FaceDlg::~PrimitiveGUI_FaceDlg()
121 //=================================================================================
124 //=================================================================================
125 void PrimitiveGUI_FaceDlg::Init()
128 myEditCurrentArgument = GroupPlane->LineEdit1;
129 GroupType->RadioButton1->setChecked(true);
130 myEdge = GEOM::GEOM_Object::_nil();
131 myFace = GEOM::GEOM_Object::_nil();
132 globalSelection(); // close local contexts, if any
133 // localSelection( GEOM::GEOM_Object::_nil(), TopAbs_EDGE );
135 myOrientationType = 1;
137 /* Get setting of step value from file configuration */
138 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
139 double aStep = resMgr->doubleValue( "Geometry", "SettingsGeomStep", 100 );
141 double aDefaultSize = 100.0;
142 /* min, max, step and decimals for spin boxes */
143 initSpinBox( GroupPlane->SpinBox_DX, 0.00001, COORD_MAX, aStep, 5 ); // VSR: TODO: DBL_DIGITS_DISPLAY
144 GroupPlane->SpinBox_DX->setValue( aDefaultSize );
145 initSpinBox( GroupPlane->SpinBox_DY, 0.00001, COORD_MAX, aStep, 5 ); // VSR: TODO: DBL_DIGITS_DISPLAY
146 GroupPlane->SpinBox_DY->setValue( aDefaultSize );
148 initSpinBox( GroupDimensions->SpinBox_DX, 0.00001, COORD_MAX, aStep, 5 ); // VSR: TODO: DBL_DIGITS_DISPLAY
149 GroupDimensions->SpinBox_DX->setValue( aDefaultSize );
150 initSpinBox( GroupDimensions->SpinBox_DY, 0.00001, COORD_MAX, aStep, 5 ); // VSR: TODO: DBL_DIGITS_DISPLAY
151 GroupDimensions->SpinBox_DY->setValue( aDefaultSize );
154 /* signals and slots connections */
155 connect( myGeomGUI, SIGNAL( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) );
156 connect( myGeomGUI, SIGNAL( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) );
157 connect( myGeomGUI, SIGNAL( SignalDefaultStepValueChanged( double ) ), this, SLOT( SetDoubleSpinBoxStep( double ) ) );
159 connect( this, SIGNAL( constructorsClicked( int ) ), this, SLOT( ConstructorsClicked( int ) ) );
161 connect( buttonOk(), SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
162 connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
164 connect( GroupPlane->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
165 connect( GroupPlane->LineEdit1, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
166 connect( GroupPlane->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
167 connect( GroupPlane->SpinBox_DY, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
169 connect( GroupDimensions->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
170 connect( GroupDimensions->SpinBox_DY, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
172 connect( GroupOrientation->RadioButton1, SIGNAL( clicked() ), this, SLOT( RadioButtonClicked() ) );
173 connect( GroupOrientation->RadioButton2, SIGNAL( clicked() ), this, SLOT( RadioButtonClicked() ) );
174 connect( GroupOrientation->RadioButton3, SIGNAL( clicked() ), this, SLOT( RadioButtonClicked() ) );
176 connect( GroupType->RadioButton1, SIGNAL( clicked() ), this, SLOT( TypeButtonClicked() ) );
177 connect( GroupType->RadioButton2, SIGNAL( clicked() ), this, SLOT( TypeButtonClicked() ) );
179 connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
180 this, SLOT( SelectionIntoArgument() ) );
182 initName( tr( "GEOM_FACE" ) );
184 ConstructorsClicked( 0 );
187 //=================================================================================
188 // function : SetDoubleSpinBoxStep()
189 // purpose : Double spin box management
190 //=================================================================================
191 void PrimitiveGUI_FaceDlg::SetDoubleSpinBoxStep( double step )
193 GroupPlane->SpinBox_DX->setSingleStep(step);
194 GroupPlane->SpinBox_DY->setSingleStep(step);
197 //=================================================================================
198 // function : ValueChangedInSpinBox()
200 //=================================================================================
201 void PrimitiveGUI_FaceDlg::ValueChangedInSpinBox( double newValue )
206 //=================================================================================
207 // function : RadioBittonClicked()
208 // purpose : Radio button management
209 //=================================================================================
210 void PrimitiveGUI_FaceDlg::RadioButtonClicked()
212 if ( GroupOrientation->RadioButton1->isChecked() )
213 myOrientationType = 1;
214 else if ( GroupOrientation->RadioButton2->isChecked() )
215 myOrientationType = 2;
216 else if ( GroupOrientation->RadioButton3->isChecked() )
217 myOrientationType = 3;
221 //=================================================================================
222 // function : TypeBittonClicked()
223 // purpose : Radio button management
224 //=================================================================================
225 void PrimitiveGUI_FaceDlg::TypeButtonClicked()
227 if ( GroupType->RadioButton1->isChecked() ) {
228 globalSelection(); // close local contexts, if any
229 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_EDGE );
230 GroupPlane->TextLabel1->setText( tr( "GEOM_EDGE" ) );
232 else if ( GroupType->RadioButton2->isChecked() ) {
233 globalSelection(); // close local contexts, if any
234 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_FACE );
235 GroupPlane->TextLabel1->setText( tr( "GEOM_FACE" ) );
239 //=================================================================================
240 // function : ClickOnOk()
242 //=================================================================================
243 void PrimitiveGUI_FaceDlg::ClickOnOk()
245 if ( ClickOnApply() )
249 //=================================================================================
250 // function : ClickOnApply()
252 //=================================================================================
253 bool PrimitiveGUI_FaceDlg::ClickOnApply()
260 myEditCurrentArgument->setText( "" );
261 ConstructorsClicked( getConstructorId() );
266 //=================================================================================
267 // function : ConstructorsClicked()
268 // purpose : Radio button management
269 //=================================================================================
270 void PrimitiveGUI_FaceDlg::ConstructorsClicked( int constructorId )
273 switch ( constructorId ) {
276 globalSelection(); // close local contexts, if any
278 GroupDimensions->show();
279 GroupOrientation->show();
281 GroupOrientation->RadioButton1->setChecked( true );
282 myOrientationType = 1;
287 globalSelection(); // close local contexts, if any
288 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_EDGE );
289 myEditCurrentArgument = GroupPlane->LineEdit1;
290 myEditCurrentArgument->setText("");
291 myEdge = GEOM::GEOM_Object::_nil();
292 myFace = GEOM::GEOM_Object::_nil();
293 GroupType->RadioButton1->setChecked( true );
295 GroupDimensions->hide();
296 GroupOrientation->hide();
303 qApp->processEvents();
305 resize( minimumSizeHint() );
306 SelectionIntoArgument();
310 //=================================================================================
311 // function : SelectionIntoArgument()
312 // purpose : Called when selection as changed or other case
313 //=================================================================================
314 void PrimitiveGUI_FaceDlg::SelectionIntoArgument()
316 if (getConstructorId() == 0) {
321 myEditCurrentArgument->setText( "" );
323 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
324 SALOME_ListIO aSelList;
325 aSelMgr->selectedObjects(aSelList);
327 if ( aSelList.Extent() != 1 ) {
328 if ( myEditCurrentArgument == GroupPlane->LineEdit1 ) myEdge = GEOM::GEOM_Object::_nil();
333 Standard_Boolean aRes = Standard_False;
334 TopAbs_ShapeEnum aNeedType = TopAbs_EDGE;
335 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( aSelList.First(), aRes );
336 if ( !CORBA::is_nil( aSelectedObject ) && aRes ) {
337 QString aName = GEOMBase::GetName( aSelectedObject );
340 if ( GEOMBase::GetShape( aSelectedObject, aShape, TopAbs_SHAPE ) && !aShape.IsNull() ) {
341 if (GroupType->RadioButton2->isChecked())
342 aNeedType = TopAbs_FACE;
344 TColStd_IndexedMapOfInteger aMap;
345 aSelMgr->GetIndexes( aSelList.First(), aMap );
346 if ( aMap.Extent() == 1 ) { // Local Selection
347 int anIndex = aMap( 1 );
348 if ( aNeedType == TopAbs_EDGE )
349 aName += QString( ":edge_%1" ).arg( anIndex );
351 aName += QString( ":face_%1" ).arg( anIndex );
353 //Find SubShape Object in Father
354 GEOM::GEOM_Object_var aFindedObject = GEOMBase_Helper::findObjectInFather( aSelectedObject, aName );
356 if ( aFindedObject == GEOM::GEOM_Object::_nil() ) { // Object not found in study
357 GEOM::GEOM_IShapesOperations_var aShapesOp = getGeomEngine()->GetIShapesOperations( getStudyId() );
358 aSelectedObject = aShapesOp->GetSubShape( aSelectedObject, anIndex );
361 aSelectedObject = aFindedObject; // get Object from study
363 else { // Global Selection
364 if ( aShape.ShapeType() != aNeedType ) {
365 aSelectedObject = GEOM::GEOM_Object::_nil();
371 myEditCurrentArgument->setText( aName );
372 if ( myEditCurrentArgument == GroupPlane->LineEdit1 && aNeedType == TopAbs_EDGE )
373 myEdge = aSelectedObject;
374 else if ( myEditCurrentArgument == GroupPlane->LineEdit1 && aNeedType == TopAbs_FACE )
375 myFace = aSelectedObject;
381 //=================================================================================
382 // function : SetEditCurrentArgument()
384 //=================================================================================
385 void PrimitiveGUI_FaceDlg::SetEditCurrentArgument()
387 QPushButton* send = (QPushButton*)sender();
389 globalSelection(); // close previous local contexts
390 if ( send == GroupPlane->PushButton1 ) {
391 myEditCurrentArgument = GroupPlane->LineEdit1;
392 if (GroupType->RadioButton1->isChecked())
393 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_EDGE );
394 else if (GroupType->RadioButton1->isChecked())
395 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_FACE );
398 myEditCurrentArgument->setFocus();
399 SelectionIntoArgument();
403 //=================================================================================
404 // function : LineEditReturnPressed()
406 //=================================================================================
407 void PrimitiveGUI_FaceDlg::LineEditReturnPressed()
409 QLineEdit* send = (QLineEdit*)sender();
410 if ( send == GroupPlane->LineEdit1 ) myEditCurrentArgument = GroupPlane->LineEdit1;
412 GEOMBase_Skeleton::LineEditReturnPressed();
416 //=================================================================================
417 // function : ActivateThisDialog()
419 //=================================================================================
420 void PrimitiveGUI_FaceDlg::ActivateThisDialog()
422 GEOMBase_Skeleton::ActivateThisDialog();
423 connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
424 this, SLOT( SelectionIntoArgument() ) );
426 ConstructorsClicked( getConstructorId() );
429 //=================================================================================
430 // function : DeactivateActiveDialog()
431 // purpose : public slot to deactivate if active
432 //=================================================================================
433 void PrimitiveGUI_FaceDlg::DeactivateActiveDialog()
435 GEOMBase_Skeleton::DeactivateActiveDialog();
438 //=================================================================================
439 // function : enterEvent()
441 //=================================================================================
442 void PrimitiveGUI_FaceDlg::enterEvent( QEvent* )
444 if ( !mainFrame()->GroupConstructors->isEnabled() )
445 ActivateThisDialog();
448 //=================================================================================
449 // function : createOperation
451 //=================================================================================
452 GEOM::GEOM_IOperations_ptr PrimitiveGUI_FaceDlg::createOperation()
454 return myGeomGUI->GetGeomGen()->GetI3DPrimOperations( getStudyId() );
457 //=================================================================================
458 // function : isValid
460 //=================================================================================
461 bool PrimitiveGUI_FaceDlg::isValid( QString& msg, QStringList& absentParams )
464 if( getConstructorId() == 0 )
466 ok = GroupDimensions->SpinBox_DX->isValid( msg, absentParams, !IsPreview() ) && ok;
467 ok = GroupDimensions->SpinBox_DY->isValid( msg, absentParams, !IsPreview() ) && ok;
469 else if( getConstructorId() == 1 )
471 ok = GroupPlane->SpinBox_DX->isValid( msg, absentParams, !IsPreview() ) && ok;
472 ok = GroupPlane->SpinBox_DY->isValid( msg, absentParams, !IsPreview() ) && ok;
475 const int id = getConstructorId();
478 else if ( id == 1 ) {
479 if (GroupType->RadioButton1->isChecked())
480 return !myEdge->_is_nil() && ok;
481 else if (GroupType->RadioButton2->isChecked())
482 return !myFace->_is_nil() && ok;
487 //=================================================================================
488 // function : execute
490 //=================================================================================
491 bool PrimitiveGUI_FaceDlg::execute (ObjectList& objects)
494 GEOM::GEOM_Object_var anObj;
496 GEOM::GEOM_I3DPrimOperations_var anOper = GEOM::GEOM_I3DPrimOperations::_narrow(getOperation());
498 switch (getConstructorId()) {
500 anObj = anOper->MakeFaceHW(GroupDimensions->SpinBox_DX->value(),
501 GroupDimensions->SpinBox_DY->value(), myOrientationType);
502 if (!anObj->_is_nil() && !IsPreview())
503 myNoteBook->setParameters(anObj, 2, GroupDimensions->SpinBox_DX, GroupDimensions->SpinBox_DY);
507 anObj = GroupType->RadioButton1->isChecked() ?
508 anOper->MakeFaceObjHW(myEdge, GroupPlane->SpinBox_DX->value(), GroupPlane->SpinBox_DY->value()) :
509 anOper->MakeFaceObjHW(myFace, GroupPlane->SpinBox_DX->value(), GroupPlane->SpinBox_DY->value());
510 if (!anObj->_is_nil() && !IsPreview())
511 myNoteBook->setParameters(anObj, 2, GroupPlane->SpinBox_DX, GroupPlane->SpinBox_DY);
516 if (!anObj->_is_nil())
517 objects.push_back(anObj._retn());
522 //=================================================================================
523 // function : addSubshapeToStudy
524 // purpose : virtual method to add new SubObjects if local selection
525 //=================================================================================
526 void PrimitiveGUI_FaceDlg::addSubshapesToStudy()
528 QMap<QString, GEOM::GEOM_Object_var> objMap;
529 switch ( getConstructorId() ) {
531 if ( GroupType->RadioButton1->isChecked() )
532 objMap[GroupPlane->LineEdit1->text()] = myEdge;
533 if ( GroupType->RadioButton2->isChecked() )
534 objMap[GroupPlane->LineEdit1->text()] = myFace;
537 addSubshapesToFather( objMap );