2 // File : GeometryGUI_PropertiesDlg.cxx
4 // Author : Lucien PIGNOLONI
6 // Module : GeometryGUI
7 // Copyright : OPEN CASCADE
10 #include "GeometryGUI_PropertiesDlg.h"
12 #include "GeometryGUI.h"
13 #include "QAD_Application.h"
14 #include "QAD_Desktop.h"
15 #include "utilities.h"
17 #include <qbuttongroup.h>
18 #include <qgroupbox.h>
20 #include <qlineedit.h>
21 #include <qpushbutton.h>
22 #include <qradiobutton.h>
26 #include <qwhatsthis.h>
30 #include <TopExp_Explorer.hxx>
33 //=================================================================================
34 // class : GeometryGUI_PropertiesDlg()
35 // purpose : Constructs a GeometryGUI_PropertiesDlg which is a child of 'parent', with the
36 // name 'name' and widget flags set to 'f'.
37 // The dialog will by default be modeless, unless you set 'modal' to
38 // TRUE to construct a modal dialog.
39 //=================================================================================
40 GeometryGUI_PropertiesDlg::GeometryGUI_PropertiesDlg( QWidget* parent, const char* name, SALOME_Selection* Sel, bool modal, WFlags fl )
41 : QDialog( parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
43 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap( "GeometryGUI",tr("ICON_DLG_BASICPROPERTIES")));
44 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap( "GeometryGUI",tr("ICON_SELECT")));
47 setName( "GeometryGUI_PropertiesDlg" );
49 setCaption( tr( "GEOM_PROPERTIES_TITLE" ) );
50 setSizeGripEnabled( TRUE );
51 GeometryGUI_PropertiesDlgLayout = new QGridLayout( this );
52 GeometryGUI_PropertiesDlgLayout->setSpacing( 6 );
53 GeometryGUI_PropertiesDlgLayout->setMargin( 11 );
55 /***************************************************************/
56 GroupConstructors = new QButtonGroup( this, "GroupConstructors" );
57 GroupConstructors->setTitle( tr( "GEOM_PROPERTIES" ) );
58 GroupConstructors->setExclusive( TRUE );
59 GroupConstructors->setColumnLayout(0, Qt::Vertical );
60 GroupConstructors->layout()->setSpacing( 0 );
61 GroupConstructors->layout()->setMargin( 0 );
62 GroupConstructorsLayout = new QGridLayout( GroupConstructors->layout() );
63 GroupConstructorsLayout->setAlignment( Qt::AlignTop );
64 GroupConstructorsLayout->setSpacing( 6 );
65 GroupConstructorsLayout->setMargin( 11 );
66 Constructor1 = new QRadioButton( GroupConstructors, "Constructor1" );
67 Constructor1->setText( tr( "" ) );
68 Constructor1->setPixmap( image0 );
69 Constructor1->setChecked( TRUE );
70 Constructor1->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)0, Constructor1->sizePolicy().hasHeightForWidth() ) );
71 Constructor1->setMinimumSize( QSize( 60, 0 ) );
72 GroupConstructorsLayout->addWidget( Constructor1, 0, 0 );
73 QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
74 GroupConstructorsLayout->addItem( spacer, 0, 1 );
75 GeometryGUI_PropertiesDlgLayout->addWidget( GroupConstructors, 0, 0 );
77 /***************************************************************/
78 GroupConstructor1 = new QGroupBox( this, "GroupConstructor1" );
79 GroupConstructor1->setTitle( tr( "GEOM_PROPERTIES_CONSTR" ) );
80 GroupConstructor1->setColumnLayout(0, Qt::Vertical );
81 GroupConstructor1->layout()->setSpacing( 0 );
82 GroupConstructor1->layout()->setMargin( 0 );
83 GroupConstructor1Layout = new QGridLayout( GroupConstructor1->layout() );
84 GroupConstructor1Layout->setAlignment( Qt::AlignTop );
85 GroupConstructor1Layout->setSpacing( 6 );
86 GroupConstructor1Layout->setMargin( 11 );
87 LineEditC1A1 = new QLineEdit( GroupConstructor1, "LineEditC1A1" );
88 LineEditC1A1->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)0, LineEditC1A1->sizePolicy().hasHeightForWidth() ) );
89 GroupConstructor1Layout->addWidget( LineEditC1A1, 0, 2 );
90 SelectButtonC1A1 = new QPushButton( GroupConstructor1, "SelectButtonC1A1" );
91 SelectButtonC1A1->setText( tr( "" ) );
92 SelectButtonC1A1->setPixmap( image1 );
93 GroupConstructor1Layout->addWidget( SelectButtonC1A1, 0, 1 );
94 TextLabelC1A1 = new QLabel( GroupConstructor1, "TextLabelC1A1" );
95 TextLabelC1A1->setText( tr( "GEOM_OBJECT" ) );
96 TextLabelC1A1->setMinimumSize( QSize( 50, 0 ) );
97 TextLabelC1A1->setFrameShape( QLabel::NoFrame );
98 TextLabelC1A1->setFrameShadow( QLabel::Plain );
99 GroupConstructor1Layout->addWidget( TextLabelC1A1, 0, 0 );
100 TextLabel_Length = new QLabel( GroupConstructor1, "TextLabel_Length" );
101 TextLabel_Length->setText( tr( "GEOM_LENGTH" ) );
102 TextLabel_Length->setMinimumSize( QSize( 50, 0 ) );
103 TextLabel_Length->setFrameShape( QLabel::NoFrame );
104 TextLabel_Length->setFrameShadow( QLabel::Plain );
105 GroupConstructor1Layout->addWidget( TextLabel_Length, 1, 0 );
106 LineEdit_Length = new QLineEdit( GroupConstructor1, "LineEdit_Length" );
107 LineEdit_Length->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)0, LineEdit_Length->sizePolicy().hasHeightForWidth() ) );
108 // LineEdit_Length->setEnabled( FALSE );
109 LineEdit_Length->setReadOnly( TRUE );
110 GroupConstructor1Layout->addWidget( LineEdit_Length, 1, 2 );
111 LineEdit_Surface = new QLineEdit( GroupConstructor1, "LineEdit_Surface" );
112 LineEdit_Surface->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)0, LineEdit_Surface->sizePolicy().hasHeightForWidth() ) );
113 //LineEdit_Surface->setEnabled( FALSE );
114 LineEdit_Surface->setReadOnly( TRUE );
115 GroupConstructor1Layout->addWidget( LineEdit_Surface, 2, 2 );
116 TextLabel_Surface = new QLabel( GroupConstructor1, "TextLabel_Surface" );
117 TextLabel_Surface->setText( tr( "GEOM_PROPERTIES_SURFACE" ) );
118 TextLabel_Surface->setMinimumSize( QSize( 50, 0 ) );
119 TextLabel_Surface->setFrameShape( QLabel::NoFrame );
120 TextLabel_Surface->setFrameShadow( QLabel::Plain );
121 GroupConstructor1Layout->addWidget( TextLabel_Surface, 2, 0 );
122 TextLabel_Volume = new QLabel( GroupConstructor1, "TextLabel_Volume" );
123 TextLabel_Volume->setText( tr( "GEOM_PROPERTIES_VOLUME" ) );
124 TextLabel_Volume->setMinimumSize( QSize( 50, 0 ) );
125 TextLabel_Volume->setFrameShape( QLabel::NoFrame );
126 TextLabel_Volume->setFrameShadow( QLabel::Plain );
127 GroupConstructor1Layout->addWidget( TextLabel_Volume, 3, 0 );
128 LineEdit_Volume = new QLineEdit( GroupConstructor1, "LineEdit_Volume" );
129 LineEdit_Volume->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)0, LineEdit_Volume->sizePolicy().hasHeightForWidth() ) );
130 //LineEdit_Volume->setEnabled( FALSE );
131 LineEdit_Volume->setReadOnly( TRUE );
132 GroupConstructor1Layout->addWidget( LineEdit_Volume, 3, 2 );
133 GeometryGUI_PropertiesDlgLayout->addWidget( GroupConstructor1, 1, 0 );
135 /***************************************************************/
136 GroupButtons = new QGroupBox( this, "GroupButtons" );
137 GroupButtons->setGeometry( QRect( 10, 10, 281, 48 ) );
138 GroupButtons->setTitle( tr( "" ) );
139 GroupButtons->setColumnLayout(0, Qt::Vertical );
140 GroupButtons->layout()->setSpacing( 0 );
141 GroupButtons->layout()->setMargin( 0 );
142 GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
143 GroupButtonsLayout->setAlignment( Qt::AlignTop );
144 GroupButtonsLayout->setSpacing( 6 );
145 GroupButtonsLayout->setMargin( 11 );
146 buttonCancel = new QPushButton( GroupButtons, "buttonCancel" );
147 buttonCancel->setText( tr( "GEOM_BUT_CLOSE" ) );
148 buttonCancel->setAutoDefault( TRUE );
149 GroupButtonsLayout->addWidget( buttonCancel, 0, 1 );
151 QSpacerItem* spacer_8 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
152 GroupButtonsLayout->addItem( spacer_8, 0, 0 );
153 QSpacerItem* spacer_9 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
154 GroupButtonsLayout->addItem( spacer_9, 0, 2 );
156 GeometryGUI_PropertiesDlgLayout->addWidget( GroupButtons, 2, 0 );
157 /***************************************************************/
159 Init(Sel) ; /* Initialisations */
163 //=================================================================================
164 // function : ~GeometryGUI_PropertiesDlg()
165 // purpose : Destroys the object and frees any allocated resources
166 //=================================================================================
167 GeometryGUI_PropertiesDlg::~GeometryGUI_PropertiesDlg()
169 // no need to delete child widgets, Qt does it all for us
173 //=================================================================================
176 //=================================================================================
177 void GeometryGUI_PropertiesDlg::Init( SALOME_Selection* Sel )
179 myConstructorId = 0 ;
180 Constructor1->setChecked( TRUE );
181 myEditCurrentArgument = LineEditC1A1 ;
183 myGeomGUI = GeometryGUI::GetGeometryGUI() ;
184 myGeomGUI->SetActiveDialogBox( (QDialog*)this ) ;
186 // TODO : previous selection into argument ?
188 /* Filter definitions */
189 Engines::Component_var comp = QAD_Application::getDesktop()->getEngine("FactoryServer", "Geometry");
190 myGeom = GEOM::GEOM_Gen::_narrow(comp);
192 /* signals and slots connections */
193 connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( ClickOnCancel() ) ) ;
194 connect( GroupConstructors, SIGNAL(clicked(int) ), SLOT( ConstructorsClicked(int) ) );
195 connect( SelectButtonC1A1, SIGNAL (clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ;
196 connect( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
197 connect( LineEditC1A1, SIGNAL ( returnPressed() ), this, SLOT( LineEditReturnPressed() ) ) ;
199 connect( myGeomGUI, SIGNAL ( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) ) ;
200 /* to close dialog if study change */
201 connect( myGeomGUI, SIGNAL ( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) ) ;
203 /* Move widget on the botton right corner of main widget */
205 myGeomGUI->DefineDlgPosition( this, x, y ) ;
207 this->show() ; /* displays Dialog */
212 //=================================================================================
213 // function : ConstructorsClicked()
214 // purpose : Radio button management
215 //=================================================================================
216 void GeometryGUI_PropertiesDlg::ConstructorsClicked(int constructorId)
223 //=================================================================================
224 // function : ClickOnCancel()
226 //=================================================================================
227 void GeometryGUI_PropertiesDlg::ClickOnCancel()
229 myGeomGUI->EraseSimulationShape() ;
230 disconnect( mySelection, 0, this, 0 );
231 myGeomGUI->EraseSimulationShape() ;
232 myGeomGUI->ResetState() ;
238 //=================================================================================
239 // function : SelectionIntoArgument()
240 // purpose : Called when selection as changed or other case
241 //=================================================================================
242 void GeometryGUI_PropertiesDlg::SelectionIntoArgument()
244 myGeomGUI->EraseSimulationShape() ;
245 mySimulationTopoDs.Nullify() ;
247 LineEdit_Length->setText("") ;
248 LineEdit_Surface->setText("") ;
249 LineEdit_Volume->setText("") ;
250 myEditCurrentArgument->setText("") ;
252 QString aString = ""; /* future the name of selection */
254 int nbSel = myGeomGUI->GetNameOfSelectedIObjects(mySelection, aString) ;
261 if( !myGeomGUI->GetTopoFromSelection(mySelection, S) )
264 if( S.IsNull() || S.ShapeType() == TopAbs_VERTEX ) {
265 myEditCurrentArgument->setText( "" );
269 LineEditC1A1->setText(aString) ;
271 /* Try to display of a cone simulation shape to show direction of a linear edge only in OCC viewer */
272 if( myGeomGUI->CreateArrowForLinearEdge( S, mySimulationTopoDs ) ) {
273 myGeomGUI->DisplaySimulationShape( mySimulationTopoDs ) ;
275 this->CalculateAndDisplayProperties(S) ;
281 //=================================================================================
282 // function : SetEditCurrentArgument()
284 //=================================================================================
285 void GeometryGUI_PropertiesDlg::SetEditCurrentArgument()
287 QPushButton* send = (QPushButton*)sender();
288 switch (myConstructorId)
290 case 0: /* default constructor */
292 if(send == SelectButtonC1A1) {
293 LineEditC1A1->setFocus() ;
294 myEditCurrentArgument = LineEditC1A1;
296 SelectionIntoArgument() ;
305 //=================================================================================
306 // function : LineEditReturnPressed()
308 //=================================================================================
309 void GeometryGUI_PropertiesDlg::LineEditReturnPressed()
311 QLineEdit* send = (QLineEdit*)sender();
312 if( send == LineEditC1A1 )
313 myEditCurrentArgument = LineEditC1A1 ;
317 /* User name of object input management */
318 /* If successfull the selection is changed and signal emitted... */
319 /* so SelectionIntoArgument() is automatically called. */
320 const QString objectUserName = myEditCurrentArgument->text() ;
321 QWidget* thisWidget = (QWidget*)this ;
322 if( myGeomGUI->SelectionByNameInDialogs( thisWidget, objectUserName, mySelection ) ) {
323 myEditCurrentArgument->setText( objectUserName ) ;
329 //=================================================================================
330 // function : DeactivateActiveDialog()
332 //=================================================================================
333 void GeometryGUI_PropertiesDlg::DeactivateActiveDialog()
335 if ( GroupConstructors->isEnabled() ) {
336 disconnect( mySelection, 0, this, 0 );
337 GroupConstructors->setEnabled(false) ;
338 GroupConstructor1->setEnabled(false) ;
339 myGeomGUI->EraseSimulationShape() ;
340 GroupButtons->setEnabled(false) ;
346 //=================================================================================
347 // function : ActivateThisDialog()
349 //=================================================================================
350 void GeometryGUI_PropertiesDlg::ActivateThisDialog()
352 /* Emit a signal to deactivate the active dialog */
353 myGeomGUI->EmitSignalDeactivateDialog() ;
354 GroupConstructors->setEnabled(true) ;
355 GroupConstructor1->setEnabled(true) ;
356 GroupButtons->setEnabled(true) ;
357 connect( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
359 if( !mySimulationTopoDs.IsNull() )
360 myGeomGUI->DisplaySimulationShape( mySimulationTopoDs ) ;
366 //=================================================================================
367 // function : enterEvent()
369 //=================================================================================
370 void GeometryGUI_PropertiesDlg::enterEvent(QEvent* e)
372 if ( GroupConstructors->isEnabled() )
374 ActivateThisDialog() ;
379 //=================================================================================
380 // function : closeEvent()
382 //=================================================================================
383 void GeometryGUI_PropertiesDlg::closeEvent( QCloseEvent* e )
385 /* same than click on cancel button */
386 this->ClickOnCancel() ;
391 //=================================================================================
392 // function : CalculateAndDisplayProperties()
394 //=================================================================================
395 void GeometryGUI_PropertiesDlg::CalculateAndDisplayProperties(const TopoDS_Shape& S)
397 LineEdit_Length->setText("") ;
398 LineEdit_Surface->setText("") ;
399 LineEdit_Volume->setText("") ;
403 Standard_Real result;
410 BRepGProp::LinearProperties(S,LProps);
411 result = LProps.Mass();
412 if (!IsEqual( result, 0.0))
414 resString = tr("%1").arg( result, 12, 'f', 6 ) ;
415 LineEdit_Length->setText(resString) ;
418 BRepGProp::SurfaceProperties(S, SProps);
419 result = SProps.Mass();
420 if (!IsEqual( result, 0.0))
422 resString = tr("%1").arg( result, 12, 'f', 6 ) ;
423 LineEdit_Surface->setText(resString) ;
427 if (S.ShapeType() < TopAbs_SHELL)
429 for( TopExp_Explorer Exp(S,TopAbs_SOLID); Exp.More(); Exp.Next() )
432 BRepGProp::VolumeProperties(Exp.Current(), VProps);
433 result += VProps.Mass();
436 if (!IsEqual( result, 0.0 ))
438 resString = tr("%1").arg( result, 12, 'f', 6 ) ;
439 LineEdit_Volume->setText(resString) ;
442 catch(Standard_Failure)
444 MESSAGE("Catch intercepted in CalculateAndDisplayProperties()" << endl ) ;