1 // Copyright (C) 2007-2011 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);
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->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
163 connect( GroupPlane->SpinBox_DY, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
165 connect( GroupDimensions->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
166 connect( GroupDimensions->SpinBox_DY, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
168 connect( GroupOrientation->RadioButton1, SIGNAL( clicked() ), this, SLOT( RadioButtonClicked() ) );
169 connect( GroupOrientation->RadioButton2, SIGNAL( clicked() ), this, SLOT( RadioButtonClicked() ) );
170 connect( GroupOrientation->RadioButton3, SIGNAL( clicked() ), this, SLOT( RadioButtonClicked() ) );
172 connect( GroupType->RadioButton1, SIGNAL( clicked() ), this, SLOT( TypeButtonClicked() ) );
173 connect( GroupType->RadioButton2, SIGNAL( clicked() ), this, SLOT( TypeButtonClicked() ) );
175 connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
176 this, SLOT( SelectionIntoArgument() ) );
178 initName( tr( "GEOM_FACE" ) );
180 ConstructorsClicked( 0 );
183 //=================================================================================
184 // function : SetDoubleSpinBoxStep()
185 // purpose : Double spin box management
186 //=================================================================================
187 void PrimitiveGUI_FaceDlg::SetDoubleSpinBoxStep( double step )
189 GroupPlane->SpinBox_DX->setSingleStep(step);
190 GroupPlane->SpinBox_DY->setSingleStep(step);
191 GroupDimensions->SpinBox_DX->setSingleStep(step);
192 GroupDimensions->SpinBox_DY->setSingleStep(step);
195 //=================================================================================
196 // function : ValueChangedInSpinBox()
198 //=================================================================================
199 void PrimitiveGUI_FaceDlg::ValueChangedInSpinBox( double newValue )
201 displayPreview(true);
204 //=================================================================================
205 // function : RadioBittonClicked()
206 // purpose : Radio button management
207 //=================================================================================
208 void PrimitiveGUI_FaceDlg::RadioButtonClicked()
210 if ( GroupOrientation->RadioButton1->isChecked() )
211 myOrientationType = 1;
212 else if ( GroupOrientation->RadioButton2->isChecked() )
213 myOrientationType = 2;
214 else if ( GroupOrientation->RadioButton3->isChecked() )
215 myOrientationType = 3;
216 displayPreview(true);
219 //=================================================================================
220 // function : TypeBittonClicked()
221 // purpose : Radio button management
222 //=================================================================================
223 void PrimitiveGUI_FaceDlg::TypeButtonClicked()
225 if ( GroupType->RadioButton1->isChecked() ) {
226 globalSelection(); // close local contexts, if any
227 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_EDGE );
228 GroupPlane->TextLabel1->setText( tr( "GEOM_EDGE" ) );
230 else if ( GroupType->RadioButton2->isChecked() ) {
231 globalSelection(); // close local contexts, if any
232 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_FACE );
233 GroupPlane->TextLabel1->setText( tr( "GEOM_FACE" ) );
235 myEditCurrentArgument = GroupPlane->LineEdit1;
236 myEditCurrentArgument->setText( "" );
241 //=================================================================================
242 // function : ClickOnOk()
244 //=================================================================================
245 void PrimitiveGUI_FaceDlg::ClickOnOk()
247 setIsApplyAndClose( true );
248 if ( ClickOnApply() )
252 //=================================================================================
253 // function : ClickOnApply()
255 //=================================================================================
256 bool PrimitiveGUI_FaceDlg::ClickOnApply()
263 myEditCurrentArgument->setText( "" );
264 ConstructorsClicked( getConstructorId() );
269 //=================================================================================
270 // function : ConstructorsClicked()
271 // purpose : Radio button management
272 //=================================================================================
273 void PrimitiveGUI_FaceDlg::ConstructorsClicked( int constructorId )
276 switch ( constructorId ) {
279 globalSelection(); // close local contexts, if any
281 GroupDimensions->show();
282 GroupOrientation->show();
284 GroupOrientation->RadioButton1->setChecked( true );
285 myOrientationType = 1;
290 globalSelection(); // close local contexts, if any
291 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_EDGE );
292 myEditCurrentArgument = GroupPlane->LineEdit1;
293 myEditCurrentArgument->setText("");
296 GroupType->RadioButton1->setChecked( true );
298 GroupDimensions->hide();
299 GroupOrientation->hide();
306 qApp->processEvents();
308 resize( minimumSizeHint() );
309 SelectionIntoArgument();
310 //displayPreview(true);
313 //=================================================================================
314 // function : SelectionIntoArgument()
315 // purpose : Called when selection as changed or other case
316 //=================================================================================
317 void PrimitiveGUI_FaceDlg::SelectionIntoArgument()
319 if (getConstructorId() == 0) {
320 displayPreview(true);
324 myEditCurrentArgument->setText( "" );
326 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
327 SALOME_ListIO aSelList;
328 aSelMgr->selectedObjects(aSelList);
330 if ( aSelList.Extent() != 1 ) {
331 if ( myEditCurrentArgument == GroupPlane->LineEdit1 ) myEdge.nullify();
335 TopAbs_ShapeEnum aNeedType = GroupType->RadioButton2->isChecked() ? TopAbs_FACE : TopAbs_EDGE;
336 GEOM::GeomObjPtr aSelectedObject = getSelected( aNeedType );
338 if ( aSelectedObject && GEOMBase::GetShape( aSelectedObject.get(), aShape ) && !aShape.IsNull() ) {
339 QString aName = GEOMBase::GetName( aSelectedObject.get() );
341 myEditCurrentArgument->setText( aName );
343 if ( myEditCurrentArgument == GroupPlane->LineEdit1 && aNeedType == TopAbs_EDGE )
344 myEdge = aSelectedObject;
345 else if ( myEditCurrentArgument == GroupPlane->LineEdit1 && aNeedType == TopAbs_FACE )
346 myFace = aSelectedObject;
349 displayPreview(true);
353 //=================================================================================
354 // function : SetEditCurrentArgument()
356 //=================================================================================
357 void PrimitiveGUI_FaceDlg::SetEditCurrentArgument()
359 QPushButton* send = (QPushButton*)sender();
361 globalSelection(); // close previous local contexts
362 if ( send == GroupPlane->PushButton1 ) {
363 myEditCurrentArgument = GroupPlane->LineEdit1;
364 if (GroupType->RadioButton1->isChecked())
365 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_EDGE );
366 else if (GroupType->RadioButton1->isChecked())
367 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_FACE );
370 myEditCurrentArgument->setFocus();
371 SelectionIntoArgument();
374 //=================================================================================
375 // function : ActivateThisDialog()
377 //=================================================================================
378 void PrimitiveGUI_FaceDlg::ActivateThisDialog()
380 GEOMBase_Skeleton::ActivateThisDialog();
381 connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
382 this, SLOT( SelectionIntoArgument() ) );
384 ConstructorsClicked( getConstructorId() );
387 //=================================================================================
388 // function : DeactivateActiveDialog()
389 // purpose : public slot to deactivate if active
390 //=================================================================================
391 void PrimitiveGUI_FaceDlg::DeactivateActiveDialog()
393 GEOMBase_Skeleton::DeactivateActiveDialog();
396 //=================================================================================
397 // function : enterEvent()
399 //=================================================================================
400 void PrimitiveGUI_FaceDlg::enterEvent( QEvent* )
402 if ( !mainFrame()->GroupConstructors->isEnabled() )
403 ActivateThisDialog();
406 //=================================================================================
407 // function : createOperation
409 //=================================================================================
410 GEOM::GEOM_IOperations_ptr PrimitiveGUI_FaceDlg::createOperation()
412 return myGeomGUI->GetGeomGen()->GetI3DPrimOperations( getStudyId() );
415 //=================================================================================
416 // function : isValid
418 //=================================================================================
419 bool PrimitiveGUI_FaceDlg::isValid( QString& msg )
422 if( getConstructorId() == 0 )
424 ok = GroupDimensions->SpinBox_DX->isValid( msg, !IsPreview() ) &&
425 GroupDimensions->SpinBox_DY->isValid( msg, !IsPreview() );
427 else if( getConstructorId() == 1 )
429 ok = GroupPlane->SpinBox_DX->isValid( msg, !IsPreview() ) &&
430 GroupPlane->SpinBox_DY->isValid( msg, !IsPreview() ) &&
431 ( GroupType->RadioButton1->isChecked() ? myEdge : myFace );
436 //=================================================================================
437 // function : execute
439 //=================================================================================
440 bool PrimitiveGUI_FaceDlg::execute (ObjectList& objects)
443 QStringList aParameters;
444 GEOM::GEOM_Object_var anObj;
446 GEOM::GEOM_I3DPrimOperations_var anOper = GEOM::GEOM_I3DPrimOperations::_narrow(getOperation());
448 switch (getConstructorId()) {
450 anObj = anOper->MakeFaceHW(GroupDimensions->SpinBox_DX->value(),
451 GroupDimensions->SpinBox_DY->value(), myOrientationType);
452 if (!anObj->_is_nil() && !IsPreview())
454 aParameters << GroupDimensions->SpinBox_DX->text();
455 aParameters << GroupDimensions->SpinBox_DY->text();
456 anObj->SetParameters(aParameters.join(":").toLatin1().constData());
461 anObj = GroupType->RadioButton1->isChecked() ?
462 anOper->MakeFaceObjHW(myEdge.get(), GroupPlane->SpinBox_DX->value(), GroupPlane->SpinBox_DY->value()) :
463 anOper->MakeFaceObjHW(myFace.get(), GroupPlane->SpinBox_DX->value(), GroupPlane->SpinBox_DY->value());
464 if (!anObj->_is_nil() && !IsPreview())
466 aParameters << GroupPlane->SpinBox_DX->text();
467 aParameters << GroupPlane->SpinBox_DY->text();
468 anObj->SetParameters(aParameters.join(":").toLatin1().constData());
474 if (!anObj->_is_nil())
475 objects.push_back(anObj._retn());
480 //=================================================================================
481 // function : addSubshapeToStudy
482 // purpose : virtual method to add new SubObjects if local selection
483 //=================================================================================
484 void PrimitiveGUI_FaceDlg::addSubshapesToStudy()
486 if ( getConstructorId() == 1 ) {
487 if ( GroupType->RadioButton1->isChecked() )
488 GEOMBase::PublishSubObject( myEdge.get() );
489 if ( GroupType->RadioButton2->isChecked() )
490 GEOMBase::PublishSubObject( myFace.get() );