1 // GEOM GEOMGUI : GUI for Geometry component
3 // Copyright (C) 2003 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : GeometryGUI_PropertiesDlg.cxx
25 // Author : Lucien PIGNOLONI
30 #include "GeometryGUI_PropertiesDlg.h"
32 #include "GeometryGUI.h"
33 #include "QAD_Application.h"
34 #include "QAD_Desktop.h"
35 #include "utilities.h"
37 #include <qbuttongroup.h>
38 #include <qgroupbox.h>
40 #include <qlineedit.h>
41 #include <qpushbutton.h>
42 #include <qradiobutton.h>
46 #include <qwhatsthis.h>
50 #include <TopExp_Explorer.hxx>
53 //=================================================================================
54 // class : GeometryGUI_PropertiesDlg()
55 // purpose : Constructs a GeometryGUI_PropertiesDlg which is a child of 'parent', with the
56 // name 'name' and widget flags set to 'f'.
57 // The dialog will by default be modeless, unless you set 'modal' to
58 // TRUE to construct a modal dialog.
59 //=================================================================================
60 GeometryGUI_PropertiesDlg::GeometryGUI_PropertiesDlg( QWidget* parent, const char* name, SALOME_Selection* Sel, bool modal, WFlags fl )
61 : QDialog( parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
63 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap( "GEOM",tr("ICON_DLG_BASICPROPERTIES")));
64 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap( "GEOM",tr("ICON_SELECT")));
67 setName( "GeometryGUI_PropertiesDlg" );
69 setCaption( tr( "GEOM_PROPERTIES_TITLE" ) );
70 setSizeGripEnabled( TRUE );
71 GeometryGUI_PropertiesDlgLayout = new QGridLayout( this );
72 GeometryGUI_PropertiesDlgLayout->setSpacing( 6 );
73 GeometryGUI_PropertiesDlgLayout->setMargin( 11 );
75 /***************************************************************/
76 GroupConstructors = new QButtonGroup( this, "GroupConstructors" );
77 GroupConstructors->setTitle( tr( "GEOM_PROPERTIES" ) );
78 GroupConstructors->setExclusive( TRUE );
79 GroupConstructors->setColumnLayout(0, Qt::Vertical );
80 GroupConstructors->layout()->setSpacing( 0 );
81 GroupConstructors->layout()->setMargin( 0 );
82 GroupConstructorsLayout = new QGridLayout( GroupConstructors->layout() );
83 GroupConstructorsLayout->setAlignment( Qt::AlignTop );
84 GroupConstructorsLayout->setSpacing( 6 );
85 GroupConstructorsLayout->setMargin( 11 );
86 Constructor1 = new QRadioButton( GroupConstructors, "Constructor1" );
87 Constructor1->setText( tr( "" ) );
88 Constructor1->setPixmap( image0 );
89 Constructor1->setChecked( TRUE );
90 Constructor1->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)0, Constructor1->sizePolicy().hasHeightForWidth() ) );
91 Constructor1->setMinimumSize( QSize( 60, 0 ) );
92 GroupConstructorsLayout->addWidget( Constructor1, 0, 0 );
93 QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
94 GroupConstructorsLayout->addItem( spacer, 0, 1 );
95 GeometryGUI_PropertiesDlgLayout->addWidget( GroupConstructors, 0, 0 );
97 /***************************************************************/
98 GroupConstructor1 = new QGroupBox( this, "GroupConstructor1" );
99 GroupConstructor1->setTitle( tr( "GEOM_PROPERTIES_CONSTR" ) );
100 GroupConstructor1->setColumnLayout(0, Qt::Vertical );
101 GroupConstructor1->layout()->setSpacing( 0 );
102 GroupConstructor1->layout()->setMargin( 0 );
103 GroupConstructor1Layout = new QGridLayout( GroupConstructor1->layout() );
104 GroupConstructor1Layout->setAlignment( Qt::AlignTop );
105 GroupConstructor1Layout->setSpacing( 6 );
106 GroupConstructor1Layout->setMargin( 11 );
107 LineEditC1A1 = new QLineEdit( GroupConstructor1, "LineEditC1A1" );
108 LineEditC1A1->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)0, LineEditC1A1->sizePolicy().hasHeightForWidth() ) );
109 GroupConstructor1Layout->addWidget( LineEditC1A1, 0, 2 );
110 SelectButtonC1A1 = new QPushButton( GroupConstructor1, "SelectButtonC1A1" );
111 SelectButtonC1A1->setText( tr( "" ) );
112 SelectButtonC1A1->setPixmap( image1 );
113 GroupConstructor1Layout->addWidget( SelectButtonC1A1, 0, 1 );
114 TextLabelC1A1 = new QLabel( GroupConstructor1, "TextLabelC1A1" );
115 TextLabelC1A1->setText( tr( "GEOM_OBJECT" ) );
116 TextLabelC1A1->setMinimumSize( QSize( 50, 0 ) );
117 TextLabelC1A1->setFrameShape( QLabel::NoFrame );
118 TextLabelC1A1->setFrameShadow( QLabel::Plain );
119 GroupConstructor1Layout->addWidget( TextLabelC1A1, 0, 0 );
120 TextLabel_Length = new QLabel( GroupConstructor1, "TextLabel_Length" );
121 TextLabel_Length->setText( tr( "GEOM_LENGTH" ) );
122 TextLabel_Length->setMinimumSize( QSize( 50, 0 ) );
123 TextLabel_Length->setFrameShape( QLabel::NoFrame );
124 TextLabel_Length->setFrameShadow( QLabel::Plain );
125 GroupConstructor1Layout->addWidget( TextLabel_Length, 1, 0 );
126 LineEdit_Length = new QLineEdit( GroupConstructor1, "LineEdit_Length" );
127 LineEdit_Length->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)0, LineEdit_Length->sizePolicy().hasHeightForWidth() ) );
128 // LineEdit_Length->setEnabled( FALSE );
129 LineEdit_Length->setReadOnly( TRUE );
130 GroupConstructor1Layout->addWidget( LineEdit_Length, 1, 2 );
131 LineEdit_Surface = new QLineEdit( GroupConstructor1, "LineEdit_Surface" );
132 LineEdit_Surface->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)0, LineEdit_Surface->sizePolicy().hasHeightForWidth() ) );
133 //LineEdit_Surface->setEnabled( FALSE );
134 LineEdit_Surface->setReadOnly( TRUE );
135 GroupConstructor1Layout->addWidget( LineEdit_Surface, 2, 2 );
136 TextLabel_Surface = new QLabel( GroupConstructor1, "TextLabel_Surface" );
137 TextLabel_Surface->setText( tr( "GEOM_PROPERTIES_SURFACE" ) );
138 TextLabel_Surface->setMinimumSize( QSize( 50, 0 ) );
139 TextLabel_Surface->setFrameShape( QLabel::NoFrame );
140 TextLabel_Surface->setFrameShadow( QLabel::Plain );
141 GroupConstructor1Layout->addWidget( TextLabel_Surface, 2, 0 );
142 TextLabel_Volume = new QLabel( GroupConstructor1, "TextLabel_Volume" );
143 TextLabel_Volume->setText( tr( "GEOM_PROPERTIES_VOLUME" ) );
144 TextLabel_Volume->setMinimumSize( QSize( 50, 0 ) );
145 TextLabel_Volume->setFrameShape( QLabel::NoFrame );
146 TextLabel_Volume->setFrameShadow( QLabel::Plain );
147 GroupConstructor1Layout->addWidget( TextLabel_Volume, 3, 0 );
148 LineEdit_Volume = new QLineEdit( GroupConstructor1, "LineEdit_Volume" );
149 LineEdit_Volume->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)0, LineEdit_Volume->sizePolicy().hasHeightForWidth() ) );
150 //LineEdit_Volume->setEnabled( FALSE );
151 LineEdit_Volume->setReadOnly( TRUE );
152 GroupConstructor1Layout->addWidget( LineEdit_Volume, 3, 2 );
153 GeometryGUI_PropertiesDlgLayout->addWidget( GroupConstructor1, 1, 0 );
155 /***************************************************************/
156 GroupButtons = new QGroupBox( this, "GroupButtons" );
157 GroupButtons->setGeometry( QRect( 10, 10, 281, 48 ) );
158 GroupButtons->setTitle( tr( "" ) );
159 GroupButtons->setColumnLayout(0, Qt::Vertical );
160 GroupButtons->layout()->setSpacing( 0 );
161 GroupButtons->layout()->setMargin( 0 );
162 GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
163 GroupButtonsLayout->setAlignment( Qt::AlignTop );
164 GroupButtonsLayout->setSpacing( 6 );
165 GroupButtonsLayout->setMargin( 11 );
166 buttonCancel = new QPushButton( GroupButtons, "buttonCancel" );
167 buttonCancel->setText( tr( "GEOM_BUT_CLOSE" ) );
168 buttonCancel->setAutoDefault( TRUE );
169 GroupButtonsLayout->addWidget( buttonCancel, 0, 1 );
171 QSpacerItem* spacer_8 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
172 GroupButtonsLayout->addItem( spacer_8, 0, 0 );
173 QSpacerItem* spacer_9 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
174 GroupButtonsLayout->addItem( spacer_9, 0, 2 );
176 GeometryGUI_PropertiesDlgLayout->addWidget( GroupButtons, 2, 0 );
177 /***************************************************************/
179 Init(Sel) ; /* Initialisations */
183 //=================================================================================
184 // function : ~GeometryGUI_PropertiesDlg()
185 // purpose : Destroys the object and frees any allocated resources
186 //=================================================================================
187 GeometryGUI_PropertiesDlg::~GeometryGUI_PropertiesDlg()
189 // no need to delete child widgets, Qt does it all for us
193 //=================================================================================
196 //=================================================================================
197 void GeometryGUI_PropertiesDlg::Init( SALOME_Selection* Sel )
199 myConstructorId = 0 ;
200 Constructor1->setChecked( TRUE );
201 myEditCurrentArgument = LineEditC1A1 ;
203 myGeomGUI = GeometryGUI::GetGeometryGUI() ;
204 myGeomGUI->SetActiveDialogBox( (QDialog*)this ) ;
206 // TODO : previous selection into argument ?
208 /* Filter definitions */
209 Engines::Component_var comp = QAD_Application::getDesktop()->getEngine("FactoryServer", "GEOM");
210 myGeom = GEOM::GEOM_Gen::_narrow(comp);
212 /* signals and slots connections */
213 connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( ClickOnCancel() ) ) ;
214 connect( GroupConstructors, SIGNAL(clicked(int) ), SLOT( ConstructorsClicked(int) ) );
215 connect( SelectButtonC1A1, SIGNAL (clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ;
216 connect( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
217 connect( LineEditC1A1, SIGNAL ( returnPressed() ), this, SLOT( LineEditReturnPressed() ) ) ;
219 connect( myGeomGUI, SIGNAL ( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) ) ;
220 /* to close dialog if study change */
221 connect( myGeomGUI, SIGNAL ( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) ) ;
223 /* Move widget on the botton right corner of main widget */
225 myGeomGUI->DefineDlgPosition( this, x, y ) ;
227 this->show() ; /* displays Dialog */
232 //=================================================================================
233 // function : ConstructorsClicked()
234 // purpose : Radio button management
235 //=================================================================================
236 void GeometryGUI_PropertiesDlg::ConstructorsClicked(int constructorId)
243 //=================================================================================
244 // function : ClickOnCancel()
246 //=================================================================================
247 void GeometryGUI_PropertiesDlg::ClickOnCancel()
249 myGeomGUI->EraseSimulationShape() ;
250 disconnect( mySelection, 0, this, 0 );
251 myGeomGUI->EraseSimulationShape() ;
252 myGeomGUI->ResetState() ;
258 //=================================================================================
259 // function : SelectionIntoArgument()
260 // purpose : Called when selection as changed or other case
261 //=================================================================================
262 void GeometryGUI_PropertiesDlg::SelectionIntoArgument()
264 myGeomGUI->EraseSimulationShape() ;
265 mySimulationTopoDs.Nullify() ;
267 LineEdit_Length->setText("") ;
268 LineEdit_Surface->setText("") ;
269 LineEdit_Volume->setText("") ;
270 myEditCurrentArgument->setText("") ;
272 QString aString = ""; /* future the name of selection */
274 int nbSel = myGeomGUI->GetNameOfSelectedIObjects(mySelection, aString) ;
281 if( !myGeomGUI->GetTopoFromSelection(mySelection, S) )
284 if( S.IsNull() || S.ShapeType() == TopAbs_VERTEX ) {
285 myEditCurrentArgument->setText( "" );
289 LineEditC1A1->setText(aString) ;
291 /* Try to display of a cone simulation shape to show direction of a linear edge only in OCC viewer */
292 if( myGeomGUI->CreateArrowForLinearEdge( S, mySimulationTopoDs ) ) {
293 myGeomGUI->DisplaySimulationShape( mySimulationTopoDs ) ;
295 this->CalculateAndDisplayProperties(S) ;
301 //=================================================================================
302 // function : SetEditCurrentArgument()
304 //=================================================================================
305 void GeometryGUI_PropertiesDlg::SetEditCurrentArgument()
307 QPushButton* send = (QPushButton*)sender();
308 switch (myConstructorId)
310 case 0: /* default constructor */
312 if(send == SelectButtonC1A1) {
313 LineEditC1A1->setFocus() ;
314 myEditCurrentArgument = LineEditC1A1;
316 SelectionIntoArgument() ;
325 //=================================================================================
326 // function : LineEditReturnPressed()
328 //=================================================================================
329 void GeometryGUI_PropertiesDlg::LineEditReturnPressed()
331 QLineEdit* send = (QLineEdit*)sender();
332 if( send == LineEditC1A1 )
333 myEditCurrentArgument = LineEditC1A1 ;
337 /* User name of object input management */
338 /* If successfull the selection is changed and signal emitted... */
339 /* so SelectionIntoArgument() is automatically called. */
340 const QString objectUserName = myEditCurrentArgument->text() ;
341 QWidget* thisWidget = (QWidget*)this ;
342 if( myGeomGUI->SelectionByNameInDialogs( thisWidget, objectUserName, mySelection ) ) {
343 myEditCurrentArgument->setText( objectUserName ) ;
349 //=================================================================================
350 // function : DeactivateActiveDialog()
352 //=================================================================================
353 void GeometryGUI_PropertiesDlg::DeactivateActiveDialog()
355 if ( GroupConstructors->isEnabled() ) {
356 disconnect( mySelection, 0, this, 0 );
357 GroupConstructors->setEnabled(false) ;
358 GroupConstructor1->setEnabled(false) ;
359 myGeomGUI->EraseSimulationShape() ;
360 GroupButtons->setEnabled(false) ;
366 //=================================================================================
367 // function : ActivateThisDialog()
369 //=================================================================================
370 void GeometryGUI_PropertiesDlg::ActivateThisDialog()
372 /* Emit a signal to deactivate the active dialog */
373 myGeomGUI->EmitSignalDeactivateDialog() ;
374 GroupConstructors->setEnabled(true) ;
375 GroupConstructor1->setEnabled(true) ;
376 GroupButtons->setEnabled(true) ;
377 connect( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
379 if( !mySimulationTopoDs.IsNull() )
380 myGeomGUI->DisplaySimulationShape( mySimulationTopoDs ) ;
386 //=================================================================================
387 // function : enterEvent()
389 //=================================================================================
390 void GeometryGUI_PropertiesDlg::enterEvent(QEvent* e)
392 if ( GroupConstructors->isEnabled() )
394 ActivateThisDialog() ;
399 //=================================================================================
400 // function : closeEvent()
402 //=================================================================================
403 void GeometryGUI_PropertiesDlg::closeEvent( QCloseEvent* e )
405 /* same than click on cancel button */
406 this->ClickOnCancel() ;
411 //=================================================================================
412 // function : CalculateAndDisplayProperties()
414 //=================================================================================
415 void GeometryGUI_PropertiesDlg::CalculateAndDisplayProperties(const TopoDS_Shape& S)
417 LineEdit_Length->setText("") ;
418 LineEdit_Surface->setText("") ;
419 LineEdit_Volume->setText("") ;
423 Standard_Real result;
430 BRepGProp::LinearProperties(S,LProps);
431 result = LProps.Mass();
432 if (!IsEqual( result, 0.0))
434 resString = tr("%1").arg( result, 12, 'f', 6 ) ;
435 LineEdit_Length->setText(resString) ;
438 BRepGProp::SurfaceProperties(S, SProps);
439 result = SProps.Mass();
440 if (!IsEqual( result, 0.0))
442 resString = tr("%1").arg( result, 12, 'f', 6 ) ;
443 LineEdit_Surface->setText(resString) ;
447 if (S.ShapeType() < TopAbs_SHELL)
449 for( TopExp_Explorer Exp(S,TopAbs_SOLID); Exp.More(); Exp.Next() )
452 BRepGProp::VolumeProperties(Exp.Current(), VProps);
453 result += VProps.Mass();
456 if (!IsEqual( result, 0.0 ))
458 resString = tr("%1").arg( result, 12, 'f', 6 ) ;
459 LineEdit_Volume->setText(resString) ;
462 catch(Standard_Failure)
464 MESSAGE("Catch intercepted in CalculateAndDisplayProperties()" << endl ) ;