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);
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 if ( ClickOnApply() )
251 //=================================================================================
252 // function : ClickOnApply()
254 //=================================================================================
255 bool PrimitiveGUI_FaceDlg::ClickOnApply()
262 myEditCurrentArgument->setText( "" );
263 ConstructorsClicked( getConstructorId() );
268 //=================================================================================
269 // function : ConstructorsClicked()
270 // purpose : Radio button management
271 //=================================================================================
272 void PrimitiveGUI_FaceDlg::ConstructorsClicked( int constructorId )
275 switch ( constructorId ) {
278 globalSelection(); // close local contexts, if any
280 GroupDimensions->show();
281 GroupOrientation->show();
283 GroupOrientation->RadioButton1->setChecked( true );
284 myOrientationType = 1;
289 globalSelection(); // close local contexts, if any
290 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_EDGE );
291 myEditCurrentArgument = GroupPlane->LineEdit1;
292 myEditCurrentArgument->setText("");
295 GroupType->RadioButton1->setChecked( true );
297 GroupDimensions->hide();
298 GroupOrientation->hide();
305 qApp->processEvents();
307 resize( minimumSizeHint() );
308 SelectionIntoArgument();
309 //displayPreview(true);
312 //=================================================================================
313 // function : SelectionIntoArgument()
314 // purpose : Called when selection as changed or other case
315 //=================================================================================
316 void PrimitiveGUI_FaceDlg::SelectionIntoArgument()
318 if (getConstructorId() == 0) {
319 displayPreview(true);
323 myEditCurrentArgument->setText( "" );
325 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
326 SALOME_ListIO aSelList;
327 aSelMgr->selectedObjects(aSelList);
329 if ( aSelList.Extent() != 1 ) {
330 if ( myEditCurrentArgument == GroupPlane->LineEdit1 ) myEdge.nullify();
334 TopAbs_ShapeEnum aNeedType = GroupType->RadioButton2->isChecked() ? TopAbs_FACE : TopAbs_EDGE;
335 GEOM::GeomObjPtr aSelectedObject = getSelected( aNeedType );
337 if ( aSelectedObject && GEOMBase::GetShape( aSelectedObject.get(), aShape ) && !aShape.IsNull() ) {
338 QString aName = GEOMBase::GetName( aSelectedObject.get() );
340 myEditCurrentArgument->setText( aName );
342 if ( myEditCurrentArgument == GroupPlane->LineEdit1 && aNeedType == TopAbs_EDGE )
343 myEdge = aSelectedObject;
344 else if ( myEditCurrentArgument == GroupPlane->LineEdit1 && aNeedType == TopAbs_FACE )
345 myFace = aSelectedObject;
348 displayPreview(true);
352 //=================================================================================
353 // function : SetEditCurrentArgument()
355 //=================================================================================
356 void PrimitiveGUI_FaceDlg::SetEditCurrentArgument()
358 QPushButton* send = (QPushButton*)sender();
360 globalSelection(); // close previous local contexts
361 if ( send == GroupPlane->PushButton1 ) {
362 myEditCurrentArgument = GroupPlane->LineEdit1;
363 if (GroupType->RadioButton1->isChecked())
364 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_EDGE );
365 else if (GroupType->RadioButton1->isChecked())
366 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_FACE );
369 myEditCurrentArgument->setFocus();
370 SelectionIntoArgument();
373 //=================================================================================
374 // function : ActivateThisDialog()
376 //=================================================================================
377 void PrimitiveGUI_FaceDlg::ActivateThisDialog()
379 GEOMBase_Skeleton::ActivateThisDialog();
380 connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
381 this, SLOT( SelectionIntoArgument() ) );
383 ConstructorsClicked( getConstructorId() );
386 //=================================================================================
387 // function : DeactivateActiveDialog()
388 // purpose : public slot to deactivate if active
389 //=================================================================================
390 void PrimitiveGUI_FaceDlg::DeactivateActiveDialog()
392 GEOMBase_Skeleton::DeactivateActiveDialog();
395 //=================================================================================
396 // function : enterEvent()
398 //=================================================================================
399 void PrimitiveGUI_FaceDlg::enterEvent( QEvent* )
401 if ( !mainFrame()->GroupConstructors->isEnabled() )
402 ActivateThisDialog();
405 //=================================================================================
406 // function : createOperation
408 //=================================================================================
409 GEOM::GEOM_IOperations_ptr PrimitiveGUI_FaceDlg::createOperation()
411 return myGeomGUI->GetGeomGen()->GetI3DPrimOperations( getStudyId() );
414 //=================================================================================
415 // function : isValid
417 //=================================================================================
418 bool PrimitiveGUI_FaceDlg::isValid( QString& msg )
421 if( getConstructorId() == 0 )
423 ok = GroupDimensions->SpinBox_DX->isValid( msg, !IsPreview() ) &&
424 GroupDimensions->SpinBox_DY->isValid( msg, !IsPreview() );
426 else if( getConstructorId() == 1 )
428 ok = GroupPlane->SpinBox_DX->isValid( msg, !IsPreview() ) &&
429 GroupPlane->SpinBox_DY->isValid( msg, !IsPreview() ) &&
430 ( GroupType->RadioButton1->isChecked() ? myEdge : myFace );
435 //=================================================================================
436 // function : execute
438 //=================================================================================
439 bool PrimitiveGUI_FaceDlg::execute (ObjectList& objects)
442 QStringList aParameters;
443 GEOM::GEOM_Object_var anObj;
445 GEOM::GEOM_I3DPrimOperations_var anOper = GEOM::GEOM_I3DPrimOperations::_narrow(getOperation());
447 switch (getConstructorId()) {
449 anObj = anOper->MakeFaceHW(GroupDimensions->SpinBox_DX->value(),
450 GroupDimensions->SpinBox_DY->value(), myOrientationType);
451 if (!anObj->_is_nil() && !IsPreview())
453 aParameters << GroupDimensions->SpinBox_DX->text();
454 aParameters << GroupDimensions->SpinBox_DY->text();
455 anObj->SetParameters(aParameters.join(":").toLatin1().constData());
460 anObj = GroupType->RadioButton1->isChecked() ?
461 anOper->MakeFaceObjHW(myEdge.get(), GroupPlane->SpinBox_DX->value(), GroupPlane->SpinBox_DY->value()) :
462 anOper->MakeFaceObjHW(myFace.get(), GroupPlane->SpinBox_DX->value(), GroupPlane->SpinBox_DY->value());
463 if (!anObj->_is_nil() && !IsPreview())
465 aParameters << GroupPlane->SpinBox_DX->text();
466 aParameters << GroupPlane->SpinBox_DY->text();
467 anObj->SetParameters(aParameters.join(":").toLatin1().constData());
473 if (!anObj->_is_nil())
474 objects.push_back(anObj._retn());
479 //=================================================================================
480 // function : addSubshapeToStudy
481 // purpose : virtual method to add new SubObjects if local selection
482 //=================================================================================
483 void PrimitiveGUI_FaceDlg::addSubshapesToStudy()
485 if ( getConstructorId() == 1 ) {
486 if ( GroupType->RadioButton1->isChecked() )
487 GEOMBase::PublishSubObject( myEdge.get() );
488 if ( GroupType->RadioButton2->isChecked() )
489 GEOMBase::PublishSubObject( myFace.get() );