1 // Copyright (C) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 // GEOM GEOMGUI : GUI for Geometry component
21 // File : PrimitiveGUI_FaceDlg.cxx
22 // Author : Dmitry Matveitchev, OCN.
24 #include "PrimitiveGUI_FaceDlg.h"
27 #include <GeometryGUI.h>
30 #include <SUIT_ResourceMgr.h>
31 #include <SUIT_Session.h>
32 #include <SalomeApp_Application.h>
33 #include <LightApp_SelectionMgr.h>
35 #include <TopoDS_Shape.hxx>
38 #include <TColStd_IndexedMapOfInteger.hxx>
39 #include <TopTools_IndexedMapOfShape.hxx>
41 #include <GEOMImpl_Types.hxx>
43 //=================================================================================
44 // class : PrimitiveGUI_FaceDlg()
45 // purpose : Constructs a PrimitiveGUI_FaceDlg which is a child of 'parent', with the
46 // name 'name' and widget flags set to 'f'.
47 // The dialog will by default be modeless, unless you set 'modal' to
48 // TRUE to construct a modal dialog.
49 //=================================================================================
50 PrimitiveGUI_FaceDlg::PrimitiveGUI_FaceDlg( GeometryGUI* theGeometryGUI, QWidget* parent,
51 bool modal, Qt::WindowFlags fl )
52 : GEOMBase_Skeleton( theGeometryGUI, parent, modal, fl )
54 QPixmap image0 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_FACE_OBJ_HW")));
55 QPixmap image1 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_SELECT")));
56 QPixmap image2 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_FACE_HW")));
58 setWindowTitle( tr( "GEOM_RECTANGLE_TITLE" ) );
60 /***************************************************************/
61 mainFrame()->GroupConstructors->setTitle( tr( "GEOM_RECTANGLE" ) );
62 mainFrame()->RadioButton1->setIcon( image2 );
63 mainFrame()->RadioButton2->setIcon( image0 );
64 mainFrame()->RadioButton3->setAttribute( Qt::WA_DeleteOnClose );
65 mainFrame()->RadioButton3->close();
67 GroupPlane = new DlgRef_1Sel2Spin( centralWidget() );
68 GroupPlane->GroupBox1->setTitle( tr( "GEOM_ARGUMENTS" ) );
69 GroupPlane->TextLabel1->setText( tr( "GEOM_EDGE" ) );
70 GroupPlane->TextLabel2->setText( tr( "GEOM_HEIGHT" ) );
71 GroupPlane->TextLabel3->setText( tr( "GEOM_WIDTH" ) );
72 GroupPlane->PushButton1->setIcon( image1 );
73 GroupPlane->LineEdit1->setReadOnly( true );
75 GroupType = new DlgRef_3Radio( centralWidget() );
76 GroupType->GroupBox1->setTitle( tr( "GEOM_OBJECT_TYPE" ) );
77 GroupType->RadioButton1->setText( tr( "GEOM_EDGE" ) );
78 GroupType->RadioButton2->setText( tr( "GEOM_FACE" ) );
79 GroupType->RadioButton3->setAttribute( Qt::WA_DeleteOnClose );
80 GroupType->RadioButton3->close();
82 GroupDimensions = new DlgRef_2Spin( centralWidget() );
83 GroupDimensions->GroupBox1->setTitle( tr( "GEOM_BOX_OBJ" ) );
84 GroupDimensions->TextLabel1->setText( tr( "GEOM_HEIGHT" ) );
85 GroupDimensions->TextLabel2->setText( tr( "GEOM_WIDTH" ) );
87 GroupOrientation = new DlgRef_3Radio( centralWidget() );
89 GroupOrientation->GroupBox1->setTitle( tr( "GEOM_ORIENTATION" ) );
90 GroupOrientation->RadioButton1->setText( tr( "GEOM_WPLANE_OXY" ) );
91 GroupOrientation->RadioButton2->setText( tr( "GEOM_WPLANE_OYZ" ) );
92 GroupOrientation->RadioButton3->setText( tr( "GEOM_WPLANE_OZX" ) );
94 QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
95 layout->setMargin( 0 ); layout->setSpacing( 6 );
96 layout->addWidget( GroupType );
97 layout->addWidget( GroupPlane );
98 layout->addWidget( GroupDimensions );
99 layout->addWidget( GroupOrientation );
101 /***************************************************************/
103 setHelpFileName( "create_squareface_page.html" );
109 //=================================================================================
110 // function : ~PrimitiveGUI_FaceDlg()
111 // purpose : Destroys the object and frees any allocated resources
112 //=================================================================================
113 PrimitiveGUI_FaceDlg::~PrimitiveGUI_FaceDlg()
118 //=================================================================================
121 //=================================================================================
122 void PrimitiveGUI_FaceDlg::Init()
125 myEditCurrentArgument = GroupPlane->LineEdit1;
126 GroupType->RadioButton1->setChecked(true);
127 myEdge = GEOM::GEOM_Object::_nil();
128 myFace = GEOM::GEOM_Object::_nil();
129 globalSelection(); // close local contexts, if any
130 // localSelection( GEOM::GEOM_Object::_nil(), TopAbs_EDGE );
132 myOrientationType = 1;
134 /* Get setting of step value from file configuration */
135 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
136 double aStep = resMgr->doubleValue( "Geometry", "SettingsGeomStep", 100 );
138 double aDefaultSize = 100.0;
139 /* min, max, step and decimals for spin boxes */
140 initSpinBox( GroupPlane->SpinBox_DX, 0.00001, COORD_MAX, aStep, "length_precision" );
141 GroupPlane->SpinBox_DX->setValue( aDefaultSize );
142 initSpinBox( GroupPlane->SpinBox_DY, 0.00001, COORD_MAX, aStep, "length_precision" );
143 GroupPlane->SpinBox_DY->setValue( aDefaultSize );
145 initSpinBox( GroupDimensions->SpinBox_DX, 0.00001, COORD_MAX, aStep, "length_precision" );
146 GroupDimensions->SpinBox_DX->setValue( aDefaultSize );
147 initSpinBox( GroupDimensions->SpinBox_DY, 0.00001, COORD_MAX, aStep, "length_precision" );
148 GroupDimensions->SpinBox_DY->setValue( aDefaultSize );
151 /* signals and slots connections */
152 connect( myGeomGUI, SIGNAL( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) );
153 connect( myGeomGUI, SIGNAL( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) );
154 connect( myGeomGUI, SIGNAL( SignalDefaultStepValueChanged( double ) ), this, SLOT( SetDoubleSpinBoxStep( double ) ) );
156 connect( this, SIGNAL( constructorsClicked( int ) ), this, SLOT( ConstructorsClicked( int ) ) );
158 connect( buttonOk(), SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
159 connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
161 connect( GroupPlane->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
162 connect( GroupPlane->LineEdit1, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
163 connect( GroupPlane->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
164 connect( GroupPlane->SpinBox_DY, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
166 connect( GroupDimensions->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
167 connect( GroupDimensions->SpinBox_DY, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
169 connect( GroupOrientation->RadioButton1, SIGNAL( clicked() ), this, SLOT( RadioButtonClicked() ) );
170 connect( GroupOrientation->RadioButton2, SIGNAL( clicked() ), this, SLOT( RadioButtonClicked() ) );
171 connect( GroupOrientation->RadioButton3, SIGNAL( clicked() ), this, SLOT( RadioButtonClicked() ) );
173 connect( GroupType->RadioButton1, SIGNAL( clicked() ), this, SLOT( TypeButtonClicked() ) );
174 connect( GroupType->RadioButton2, SIGNAL( clicked() ), this, SLOT( TypeButtonClicked() ) );
176 connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
177 this, SLOT( SelectionIntoArgument() ) );
179 initName( tr( "GEOM_FACE" ) );
181 ConstructorsClicked( 0 );
184 //=================================================================================
185 // function : SetDoubleSpinBoxStep()
186 // purpose : Double spin box management
187 //=================================================================================
188 void PrimitiveGUI_FaceDlg::SetDoubleSpinBoxStep( double step )
190 GroupPlane->SpinBox_DX->setSingleStep(step);
191 GroupPlane->SpinBox_DY->setSingleStep(step);
192 GroupDimensions->SpinBox_DX->setSingleStep(step);
193 GroupDimensions->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( minimumSizeHint() );
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 )
463 if( getConstructorId() == 0 )
465 ok = GroupDimensions->SpinBox_DX->isValid( msg, !IsPreview() ) && ok;
466 ok = GroupDimensions->SpinBox_DY->isValid( msg, !IsPreview() ) && ok;
468 else if( getConstructorId() == 1 )
470 ok = GroupPlane->SpinBox_DX->isValid( msg, !IsPreview() ) && ok;
471 ok = GroupPlane->SpinBox_DY->isValid( msg, !IsPreview() ) && ok;
474 const int id = getConstructorId();
477 else if ( id == 1 ) {
478 if (GroupType->RadioButton1->isChecked())
479 return !myEdge->_is_nil() && ok;
480 else if (GroupType->RadioButton2->isChecked())
481 return !myFace->_is_nil() && ok;
486 //=================================================================================
487 // function : execute
489 //=================================================================================
490 bool PrimitiveGUI_FaceDlg::execute (ObjectList& objects)
493 QStringList aParameters;
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())
504 aParameters << GroupDimensions->SpinBox_DX->text();
505 aParameters << GroupDimensions->SpinBox_DY->text();
506 anObj->SetParameters(aParameters.join(":").toLatin1().constData());
511 anObj = GroupType->RadioButton1->isChecked() ?
512 anOper->MakeFaceObjHW(myEdge, GroupPlane->SpinBox_DX->value(), GroupPlane->SpinBox_DY->value()) :
513 anOper->MakeFaceObjHW(myFace, GroupPlane->SpinBox_DX->value(), GroupPlane->SpinBox_DY->value());
514 if (!anObj->_is_nil() && !IsPreview())
516 aParameters << GroupPlane->SpinBox_DX->text();
517 aParameters << GroupPlane->SpinBox_DY->text();
518 anObj->SetParameters(aParameters.join(":").toLatin1().constData());
524 if (!anObj->_is_nil())
525 objects.push_back(anObj._retn());
530 //=================================================================================
531 // function : addSubshapeToStudy
532 // purpose : virtual method to add new SubObjects if local selection
533 //=================================================================================
534 void PrimitiveGUI_FaceDlg::addSubshapesToStudy()
536 QMap<QString, GEOM::GEOM_Object_var> objMap;
537 switch ( getConstructorId() ) {
539 if ( GroupType->RadioButton1->isChecked() )
540 objMap[GroupPlane->LineEdit1->text()] = myEdge;
541 if ( GroupType->RadioButton2->isChecked() )
542 objMap[GroupPlane->LineEdit1->text()] = myFace;
545 addSubshapesToFather( objMap );