]> SALOME platform Git repositories - modules/geom.git/blob - src/GEOMGUI/GeometryGUI_InertiaDlg.cxx
Salome HOME
NRI : First integration.
[modules/geom.git] / src / GEOMGUI / GeometryGUI_InertiaDlg.cxx
1 using namespace std;
2 //  File      : GeometryGUI_InertiaDlg.cxx
3 //  Created   :
4 //  Author    : Lucien PIGNOLONI
5 //  Project   : SALOME
6 //  Module    : GeometryGUI
7 //  Copyright : OPEN CASCADE
8 //  $Headers:
9
10 #include "GeometryGUI_InertiaDlg.h"
11
12 #include "GeometryGUI.h"
13
14 #include <qbuttongroup.h>
15 #include <qgroupbox.h>
16 #include <qlabel.h>
17 #include <qlineedit.h>
18 #include <qpushbutton.h>
19 #include <qradiobutton.h>
20 #include <qlayout.h>
21 #include <qvariant.h>
22 #include <qtooltip.h>
23 #include <qwhatsthis.h>
24 #include <qimage.h>
25 #include <qpixmap.h>
26
27 //=================================================================================
28 // class    : GeometryGUI_InertiaDlg()
29 // purpose  : Constructs a GeometryGUI_InertiaDlg which is a child of 'parent', with the 
30 //            name 'name' and widget flags set to 'f'.
31 //            The dialog will by default be modeless, unless you set 'modal' to
32 //            TRUE to construct a modal dialog.
33 //=================================================================================
34 GeometryGUI_InertiaDlg::GeometryGUI_InertiaDlg( QWidget* parent, const char* name, SALOME_Selection* Sel, bool modal, WFlags fl )
35     : QDialog( parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
36 {
37     QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap( "GeometryGUI",tr("ICON_DLG_INERTIA")));
38     QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap( "GeometryGUI",tr("ICON_SELECT")));
39     
40     if ( !name )
41         setName( "GeometryGUI_InertiaDlg" );
42     resize( 356, 303 ); 
43     setCaption( tr( "GEOM_INERTIA_TITLE"  ) );
44     setSizeGripEnabled( TRUE );
45     GeometryGUI_InertiaDlgLayout = new QGridLayout( this ); 
46     GeometryGUI_InertiaDlgLayout->setSpacing( 6 );
47     GeometryGUI_InertiaDlgLayout->setMargin( 11 );
48
49     /***************************************************************/
50     GroupConstructors = new QButtonGroup( this, "GroupConstructors" );
51     GroupConstructors->setTitle( tr( "GEOM_INERTIA_CONSTR"  ) );
52     GroupConstructors->setExclusive( TRUE );
53     GroupConstructors->setColumnLayout(0, Qt::Vertical );
54     GroupConstructors->layout()->setSpacing( 0 );
55     GroupConstructors->layout()->setMargin( 0 );
56     GroupConstructorsLayout = new QGridLayout( GroupConstructors->layout() );
57     GroupConstructorsLayout->setAlignment( Qt::AlignTop );
58     GroupConstructorsLayout->setSpacing( 6 );
59     GroupConstructorsLayout->setMargin( 11 );
60     QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
61     GroupConstructorsLayout->addItem( spacer, 0, 1 );
62     Constructor1 = new QRadioButton( GroupConstructors, "Constructor1" );
63     Constructor1->setText( tr( ""  ) );
64     Constructor1->setPixmap( image0 );
65     Constructor1->setChecked( TRUE );
66     Constructor1->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)0, Constructor1->sizePolicy().hasHeightForWidth() ) );
67     GroupConstructorsLayout->addWidget( Constructor1, 0, 0 );
68     GeometryGUI_InertiaDlgLayout->addWidget( GroupConstructors, 0, 0 );
69
70     /***************************************************************/
71     GroupC1 = new QGroupBox( this, "GroupC1" );
72     GroupC1->setTitle( tr( "GEOM_OBJECT_RESULT"  ) );
73     GroupC1->setColumnLayout(0, Qt::Vertical );
74     GroupC1->layout()->setSpacing( 0 );
75     GroupC1->layout()->setMargin( 0 );
76     GroupC1Layout = new QGridLayout( GroupC1->layout() );
77     GroupC1Layout->setAlignment( Qt::AlignTop );
78     GroupC1Layout->setSpacing( 6 );
79     GroupC1Layout->setMargin( 11 );
80     TextLabelC1A1 = new QLabel( GroupC1, "TextLabelC1A1" );
81     TextLabelC1A1->setText( tr( "GEOM_OBJECT"  ) );
82     TextLabelC1A1->setMinimumSize( QSize( 50, 0 ) );
83     TextLabelC1A1->setFrameShape( QLabel::NoFrame );
84     TextLabelC1A1->setFrameShadow( QLabel::Plain );
85     GroupC1Layout->addWidget( TextLabelC1A1, 0, 0 );
86     SelectButtonC1A1 = new QPushButton( GroupC1, "SelectButtonC1A1" );
87     SelectButtonC1A1->setText( tr( ""  ) );
88     SelectButtonC1A1->setPixmap( image1 );
89     GroupC1Layout->addWidget( SelectButtonC1A1, 0, 1 );
90     LineEditC1A1 = new QLineEdit( GroupC1, "LineEditC1A1" );
91     LineEditC1A1->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)0, LineEditC1A1->sizePolicy().hasHeightForWidth() ) );
92     LineEditC1A1->setMinimumSize( QSize( 220, 0 ) );
93     GroupC1Layout->addMultiCellWidget( LineEditC1A1, 0, 0, 2, 4 );
94     TextLabel_Matrix = new QLabel( GroupC1, "TextLabel_Matrix" );
95     TextLabel_Matrix->setText( tr( "GEOM_MATRIX"  ) );
96     TextLabel_Matrix->setMinimumSize( QSize( 50, 0 ) );
97     TextLabel_Matrix->setFrameShape( QLabel::NoFrame );
98     TextLabel_Matrix->setFrameShadow( QLabel::Plain );
99     GroupC1Layout->addWidget( TextLabel_Matrix, 1, 0 );
100     TextLabelMatrix_11 = new QLabel( GroupC1, "TextLabelMatrix_11" );
101     TextLabelMatrix_11->setText( tr( "GEOM_INERTIA_I"  ).arg("1") );
102     TextLabelMatrix_11->setMinimumSize( QSize( 0, 0 ) );
103     TextLabelMatrix_11->setFrameShape( QLabel::NoFrame );
104     TextLabelMatrix_11->setFrameShadow( QLabel::Plain );
105     TextLabelMatrix_11->setAlignment( int( QLabel::AlignVCenter | QLabel::AlignRight ) );
106     GroupC1Layout->addWidget( TextLabelMatrix_11, 1, 1 );
107     TextLabelMatrix_21 = new QLabel( GroupC1, "TextLabelMatrix_21" );
108     TextLabelMatrix_21->setText( tr( "GEOM_INERTIA_I"  ).arg("2") );
109     TextLabelMatrix_21->setMinimumSize( QSize( 0, 0 ) );
110     TextLabelMatrix_21->setFrameShape( QLabel::NoFrame );
111     TextLabelMatrix_21->setFrameShadow( QLabel::Plain );
112     TextLabelMatrix_21->setAlignment( int( QLabel::AlignVCenter | QLabel::AlignRight ) );
113     GroupC1Layout->addWidget( TextLabelMatrix_21, 2, 1 );
114     TextLabelMatrix_31 = new QLabel( GroupC1, "TextLabelMatrix_31" );
115     TextLabelMatrix_31->setText( tr( "GEOM_INERTIA_I"  ).arg("3") );
116     TextLabelMatrix_31->setMinimumSize( QSize( 0, 0 ) );
117     TextLabelMatrix_31->setFrameShape( QLabel::NoFrame );
118     TextLabelMatrix_31->setFrameShadow( QLabel::Plain );
119     TextLabelMatrix_31->setAlignment( int( QLabel::AlignVCenter | QLabel::AlignRight ) );
120     GroupC1Layout->addWidget( TextLabelMatrix_31, 3, 1 );
121     LineEdit_L1C1 = new QLineEdit( GroupC1, "LineEdit_L1C1" );
122     LineEdit_L1C1->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)0, LineEdit_L1C1->sizePolicy().hasHeightForWidth() ) );
123     LineEdit_L1C1->setMinimumSize( QSize( 70, 0 ) );
124     //LineEdit_L1C1->setEnabled( FALSE );
125     LineEdit_L1C1->setReadOnly( TRUE );
126     LineEdit_L1C1->setText( tr( ""  ) );
127     GroupC1Layout->addWidget( LineEdit_L1C1, 1, 2 );
128     LineEdit_L1C2 = new QLineEdit( GroupC1, "LineEdit_L1C2" );
129     LineEdit_L1C2->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)0, LineEdit_L1C2->sizePolicy().hasHeightForWidth() ) );
130     LineEdit_L1C2->setMinimumSize( QSize( 70, 0 ) );
131     //LineEdit_L1C2->setEnabled( FALSE );
132     LineEdit_L1C2->setReadOnly( TRUE );
133     GroupC1Layout->addWidget( LineEdit_L1C2, 1, 3 );
134     LineEdit_L1C3 = new QLineEdit( GroupC1, "LineEdit_L1C3" );
135     LineEdit_L1C3->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)0, LineEdit_L1C3->sizePolicy().hasHeightForWidth() ) );
136     LineEdit_L1C3->setMinimumSize( QSize( 70, 0 ) );
137     //LineEdit_L1C3->setEnabled( FALSE );
138     LineEdit_L1C3->setReadOnly( TRUE );
139     GroupC1Layout->addWidget( LineEdit_L1C3, 1, 4 );
140     LineEdit_L2C1 = new QLineEdit( GroupC1, "LineEdit_L2C1" );
141     LineEdit_L2C1->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)0, LineEdit_L2C1->sizePolicy().hasHeightForWidth() ) );
142     LineEdit_L2C1->setMinimumSize( QSize( 70, 0 ) );
143     //LineEdit_L2C1->setEnabled( FALSE );
144     LineEdit_L2C1->setReadOnly( TRUE );
145     GroupC1Layout->addWidget( LineEdit_L2C1, 2, 2 );
146     LineEdit_L2C2 = new QLineEdit( GroupC1, "LineEdit_L2C2" );
147     LineEdit_L2C2->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)0, LineEdit_L2C2->sizePolicy().hasHeightForWidth() ) );
148     LineEdit_L2C2->setMinimumSize( QSize( 70, 0 ) );
149     //LineEdit_L2C2->setEnabled( FALSE );
150     LineEdit_L2C2->setReadOnly( TRUE );
151     GroupC1Layout->addWidget( LineEdit_L2C2, 2, 3 );
152     LineEdit_L2C3 = new QLineEdit( GroupC1, "LineEdit_L2C3" );
153     LineEdit_L2C3->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)0, LineEdit_L2C3->sizePolicy().hasHeightForWidth() ) );
154     LineEdit_L2C3->setMinimumSize( QSize( 70, 0 ) );
155     //LineEdit_L2C3->setEnabled( FALSE );
156     LineEdit_L2C3->setReadOnly( TRUE );
157     GroupC1Layout->addWidget( LineEdit_L2C3, 2, 4 );
158     LineEdit_L3C1 = new QLineEdit( GroupC1, "LineEdit_L3C1" );
159     LineEdit_L3C1->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)0, LineEdit_L3C1->sizePolicy().hasHeightForWidth() ) );
160     LineEdit_L3C1->setMinimumSize( QSize( 70, 0 ) );
161     //LineEdit_L3C1->setEnabled( FALSE );
162     LineEdit_L3C1->setReadOnly( TRUE );
163     GroupC1Layout->addWidget( LineEdit_L3C1, 3, 2 );
164     LineEdit_L3C2 = new QLineEdit( GroupC1, "LineEdit_L3C2" );
165     LineEdit_L3C2->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)0, LineEdit_L3C2->sizePolicy().hasHeightForWidth() ) );
166     LineEdit_L3C2->setMinimumSize( QSize( 70, 0 ) );
167     //LineEdit_L3C2->setEnabled( FALSE );
168     LineEdit_L3C2->setReadOnly( TRUE );
169     GroupC1Layout->addWidget( LineEdit_L3C2, 3, 3 );
170     LineEdit_L3C3 = new QLineEdit( GroupC1, "LineEdit_L3C3" );
171     LineEdit_L3C3->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)0, LineEdit_L3C3->sizePolicy().hasHeightForWidth() ) );
172     LineEdit_L3C3->setMinimumSize( QSize( 70, 0 ) );
173     //LineEdit_L3C3->setEnabled( FALSE );
174     LineEdit_L3C3->setReadOnly( TRUE );
175     GroupC1Layout->addWidget( LineEdit_L3C3, 3, 4 );
176     LineEdit_IX = new QLineEdit( GroupC1, "LineEdit_IX" );
177     LineEdit_IX->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)0, LineEdit_IX->sizePolicy().hasHeightForWidth() ) );
178     LineEdit_IX->setMinimumSize( QSize( 70, 0 ) );
179     //LineEdit_IX->setEnabled( FALSE );
180     LineEdit_IX->setReadOnly( TRUE );
181     GroupC1Layout->addWidget( LineEdit_IX, 4, 2 );
182     LineEdit_IY = new QLineEdit( GroupC1, "LineEdit_IY" );
183     LineEdit_IY->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)0, LineEdit_IY->sizePolicy().hasHeightForWidth() ) );
184     LineEdit_IY->setMinimumSize( QSize( 70, 0 ) );
185     //LineEdit_IY->setEnabled( FALSE );
186     LineEdit_IY->setReadOnly( TRUE );
187     GroupC1Layout->addWidget( LineEdit_IY, 4, 3 );
188     LineEdit_IZ = new QLineEdit( GroupC1, "LineEdit_IZ" );
189     LineEdit_IZ->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)0, LineEdit_IZ->sizePolicy().hasHeightForWidth() ) );
190     LineEdit_IZ->setMinimumSize( QSize( 70, 0 ) );
191     //LineEdit_IZ->setEnabled( FALSE );
192     LineEdit_IZ->setReadOnly( TRUE );
193     GroupC1Layout->addWidget( LineEdit_IZ, 4, 4 );
194     TextLabel_IXIYIZ = new QLabel( GroupC1, "TextLabel_IXIYIZ" );
195     TextLabel_IXIYIZ->setText( tr( "GEOM_INERTIA_IXYZ"  ) );
196     TextLabel_IXIYIZ->setMinimumSize( QSize( 50, 0 ) );
197     TextLabel_IXIYIZ->setFrameShape( QLabel::NoFrame );
198     TextLabel_IXIYIZ->setFrameShadow( QLabel::Plain );
199     TextLabel_IXIYIZ->setAlignment( int( QLabel::AlignVCenter | QLabel::AlignRight ) );
200     GroupC1Layout->addMultiCellWidget( TextLabel_IXIYIZ, 4, 4, 0, 1 );
201     GeometryGUI_InertiaDlgLayout->addWidget( GroupC1, 1, 0 );
202
203     /***************************************************************/
204     GroupButtons = new QGroupBox( this, "GroupButtons" );
205     GroupButtons->setGeometry( QRect( 10, 10, 281, 48 ) ); 
206     GroupButtons->setTitle( tr( ""  ) );
207     GroupButtons->setColumnLayout(0, Qt::Vertical );
208     GroupButtons->layout()->setSpacing( 0 );
209     GroupButtons->layout()->setMargin( 0 );
210     GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
211     GroupButtonsLayout->setAlignment( Qt::AlignTop );
212     GroupButtonsLayout->setSpacing( 6 );
213     GroupButtonsLayout->setMargin( 11 );
214     buttonCancel = new QPushButton( GroupButtons, "buttonCancel" );
215     buttonCancel->setText( tr( "GEOM_BUT_CLOSE"  ) );
216     buttonCancel->setAutoDefault( TRUE );
217     GroupButtonsLayout->addWidget( buttonCancel, 0, 1 );
218
219     QSpacerItem* spacer_8 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
220     GroupButtonsLayout->addItem( spacer_8, 0, 0 );
221     QSpacerItem* spacer_9 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
222     GroupButtonsLayout->addItem( spacer_9, 0, 2 );
223
224     GeometryGUI_InertiaDlgLayout->addWidget( GroupButtons, 2, 0 );
225     /***************************************************************/
226
227     Init(Sel) ; /* Initialisations */
228 }
229
230
231 //=================================================================================
232 // function : ~GeometryGUI_InertiaDlg()
233 // purpose  : Destroys the object and frees any allocated resources
234 //=================================================================================
235 GeometryGUI_InertiaDlg::~GeometryGUI_InertiaDlg()
236 {
237     // no need to delete child widgets, Qt does it all for us
238 }
239
240
241 //=================================================================================
242 // function : Init()
243 // purpose  :
244 //=================================================================================
245 void GeometryGUI_InertiaDlg::Init( SALOME_Selection* Sel )
246 {
247
248   LineEdit_L1C1->setMaxLength( 10 );
249   LineEdit_L1C2->setMaxLength( 10 );
250   LineEdit_L1C3->setMaxLength( 10 );
251   LineEdit_L2C1->setMaxLength( 10 );
252   LineEdit_L2C2->setMaxLength( 10 );
253   LineEdit_L2C3->setMaxLength( 10 );
254   LineEdit_L3C1->setMaxLength( 10 );
255   LineEdit_L3C2->setMaxLength( 10 );
256   LineEdit_L3C3->setMaxLength( 10 );
257
258   LineEdit_IX->setMaxLength( 10 );
259   LineEdit_IY->setMaxLength( 10 );
260   LineEdit_IZ->setMaxLength( 10 );
261
262   myConstructorId = 0 ;
263   Constructor1->setChecked( TRUE );
264   myEditCurrentArgument = LineEditC1A1 ;        
265   mySelection = Sel;
266   myGeomGUI = GeometryGUI::GetGeometryGUI() ;
267   myGeomGUI->SetActiveDialogBox( (QDialog*)this ) ;
268  
269   // TODO : previous selection into argument ?
270
271   /* Filter definitions */
272   Engines::Component_var comp = QAD_Application::getDesktop()->getEngine("FactoryServer", "Geometry");
273   myGeom = GEOM::GEOM_Gen::_narrow(comp);
274
275   /* signals and slots connections */
276   connect( buttonCancel,      SIGNAL( clicked() ),   this, SLOT( ClickOnCancel() ) ) ;
277   connect( GroupConstructors, SIGNAL(clicked(int) ), this, SLOT( ConstructorsClicked(int) ) );
278   connect( SelectButtonC1A1,  SIGNAL (clicked() ),   this, SLOT( SetEditCurrentArgument() ) ) ;
279
280   connect( LineEditC1A1, SIGNAL ( returnPressed() ), this, SLOT( LineEditReturnPressed() ) ) ;
281
282   connect( mySelection,  SIGNAL( currentSelectionChanged() ),     this, SLOT( SelectionIntoArgument() ) );
283   connect( myGeomGUI,    SIGNAL ( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) ) ;
284
285   /* to close dialog if study change */
286   connect( myGeomGUI, SIGNAL ( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) ) ;
287
288   /* Move widget on the botton right corner of main widget */
289   int x, y ;
290   myGeomGUI->DefineDlgPosition( this, x, y ) ;
291   this->move( x, y ) ;
292   this->show() ; /* displays Dialog */
293   return ;
294 }
295
296
297 //=================================================================================
298 // function : ConstructorsClicked()
299 // purpose  : Radio button management
300 //=================================================================================
301 void GeometryGUI_InertiaDlg::ConstructorsClicked(int constructorId)
302 {
303   return ;
304 }
305
306
307
308 //=================================================================================
309 // function : ClickOnCancel()
310 // purpose  :
311 //=================================================================================
312 void GeometryGUI_InertiaDlg::ClickOnCancel()
313 {
314   disconnect( mySelection, 0, this, 0 );
315   myGeomGUI->ResetState() ;
316   reject() ;
317   return ;
318 }
319
320
321 //=================================================================================
322 // function : SelectionIntoArgument()
323 // purpose  : Called when selection as changed or other case
324 //=================================================================================
325 void GeometryGUI_InertiaDlg::SelectionIntoArgument()
326 {
327   LineEdit_L1C1->setText("") ;
328   LineEdit_L1C2->setText("") ;
329   LineEdit_L1C3->setText("") ;
330   LineEdit_L2C1->setText("") ;
331   LineEdit_L2C2->setText("") ;
332   LineEdit_L2C3->setText("") ;
333   LineEdit_L3C1->setText("") ;
334   LineEdit_L3C2->setText("") ;
335   LineEdit_L3C3->setText("") ;
336
337   LineEdit_IX->setText("") ;
338   LineEdit_IY->setText("") ;
339   LineEdit_IZ->setText("") ;
340
341   myEditCurrentArgument->setText("") ;
342   QString aString = ""; /* future the name of selection */
343
344   int nbSel = myGeomGUI->GetNameOfSelectedIObjects(mySelection, aString) ;
345   if ( nbSel != 1 ) {
346     return ;
347   }
348   
349   /*  nbSel == 1  */ 
350   TopoDS_Shape S;
351   if( !myGeomGUI->GetTopoFromSelection(mySelection, S) || S.IsNull() )
352     return ;
353     
354   LineEditC1A1->setText(aString) ;
355   this->CalculateAndDisplayInertia(S) ;  
356   return ;
357 }
358
359
360 //=================================================================================
361 // function : SetEditCurrentArgument()
362 // purpose  :
363 //=================================================================================
364 void GeometryGUI_InertiaDlg::SetEditCurrentArgument()
365 {
366   QPushButton* send = (QPushButton*)sender();
367   switch (myConstructorId)
368     {
369     case 0: /* default constructor */
370       { 
371         if(send == SelectButtonC1A1) {
372           LineEditC1A1->setFocus() ;
373           myEditCurrentArgument = LineEditC1A1;
374         }
375         SelectionIntoArgument() ;
376         break;
377       }
378     }
379   return ;
380 }
381
382
383
384 //=================================================================================
385 // function : LineEditReturnPressed()
386 // purpose  :
387 //=================================================================================
388 void GeometryGUI_InertiaDlg::LineEditReturnPressed()
389 {
390   QLineEdit* send = (QLineEdit*)sender();  
391   if( send == LineEditC1A1 )
392     myEditCurrentArgument = LineEditC1A1 ;
393   else
394     return ;
395   
396   /* User name of object input management                          */
397   /* If successfull the selection is changed and signal emitted... */
398   /* so SelectionIntoArgument() is automatically called.           */
399   const QString objectUserName = myEditCurrentArgument->text() ;
400   QWidget* thisWidget = (QWidget*)this ;
401   if( myGeomGUI->SelectionByNameInDialogs( thisWidget, objectUserName, mySelection ) ) {
402     myEditCurrentArgument->setText( objectUserName ) ;
403   }
404   return ;
405   return ;
406 }
407
408
409 //=================================================================================
410 // function : DeactivateActiveDialog()
411 // purpose  :
412 //=================================================================================
413 void GeometryGUI_InertiaDlg::DeactivateActiveDialog()
414 {
415   if ( GroupConstructors->isEnabled() ) {    
416     disconnect( mySelection, 0, this, 0 );
417     GroupConstructors->setEnabled(false) ;
418     GroupC1->setEnabled(false) ;
419     GroupButtons->setEnabled(false) ;
420   }
421   return ;
422 }
423
424
425 //=================================================================================
426 // function : ActivateThisDialog()
427 // purpose  :
428 //=================================================================================
429 void GeometryGUI_InertiaDlg::ActivateThisDialog()
430 {
431   /* Emit a signal to deactivate the active dialog */
432   myGeomGUI->EmitSignalDeactivateDialog() ;   
433   GroupConstructors->setEnabled(true) ;
434   GroupC1->setEnabled(true) ;
435   GroupButtons->setEnabled(true) ;
436   connect( mySelection, SIGNAL( currentSelectionChanged() ),     this, SLOT( SelectionIntoArgument() ) );
437   return ;
438 }
439
440
441 //=================================================================================
442 // function : enterEvent()
443 // purpose  :
444 //=================================================================================
445 void GeometryGUI_InertiaDlg::enterEvent(QEvent* e)
446 {
447   if ( GroupConstructors->isEnabled() )
448     return ;  
449   ActivateThisDialog() ;
450   return ;
451 }
452
453
454 //=================================================================================
455 // function : closeEvent()
456 // purpose  :
457 //=================================================================================
458 void GeometryGUI_InertiaDlg::closeEvent( QCloseEvent* e )
459 {
460   /* same than click on cancel button */
461   this->ClickOnCancel() ;
462   return ;
463 }
464
465
466 //=================================================================================
467 // function : CalculateAndDisplayInertia()
468 // purpose  :
469 //=================================================================================
470 void GeometryGUI_InertiaDlg::CalculateAndDisplayInertia(const TopoDS_Shape& S)
471 {
472   LineEdit_L1C1->setText("") ;
473   LineEdit_L1C2->setText("") ;
474   LineEdit_L1C3->setText("") ;
475   LineEdit_L2C1->setText("") ;
476   LineEdit_L2C2->setText("") ;
477   LineEdit_L2C3->setText("") ;
478   LineEdit_L3C1->setText("") ;
479   LineEdit_L3C2->setText("") ;
480   LineEdit_L3C3->setText("") ;
481
482   LineEdit_IX->setText("") ;
483   LineEdit_IY->setText("") ;
484   LineEdit_IZ->setText("") ;
485
486
487   if( S.IsNull() ) 
488     return ;
489
490   try {
491
492     QString resString;
493     GProp_GProps System;
494
495     if ( S.ShapeType() == TopAbs_VERTEX || S.ShapeType() == TopAbs_EDGE || S.ShapeType() == TopAbs_WIRE ) {
496       BRepGProp::LinearProperties(S, System);
497     }
498     else if ( S.ShapeType() == TopAbs_FACE || S.ShapeType() == TopAbs_SHELL ) {
499       BRepGProp::SurfaceProperties(S, System);
500     }
501     else {
502       BRepGProp::VolumeProperties(S, System);
503     }
504
505     gp_Mat I = System.MatrixOfInertia() ;
506     GProp_PrincipalProps Pr = System.PrincipalProperties();
507     Standard_Real Ix,Iy,Iz;
508     Pr.Moments(Ix,Iy,Iz);
509     
510     /* matrix 3x3 */
511     resString = tr("%1").arg( I(1,1), 12, 'f', 6 ) ;
512     LineEdit_L1C1->setText(resString) ;
513     resString = tr("%1").arg( I(1,2), 12, 'f', 6 ) ;
514     LineEdit_L1C2->setText(resString) ;
515     resString = tr("%1").arg( I(1,3), 12, 'f', 6 ) ;
516     LineEdit_L1C3->setText(resString) ;
517
518     resString = tr("%1").arg( I(2,1), 12, 'f', 6 ) ;
519     LineEdit_L2C1->setText(resString) ;
520     resString = tr("%1").arg( I(2,2), 12, 'f', 6 ) ;
521     LineEdit_L2C2->setText(resString) ;
522     resString = tr("%1").arg( I(2,3), 12, 'f', 6 ) ;
523     LineEdit_L2C3->setText(resString) ;
524
525     resString = tr("%1").arg( I(3,1), 12, 'f', 6 ) ;
526     LineEdit_L3C1->setText(resString) ;
527     resString = tr("%1").arg( I(3,2), 12, 'f', 6 ) ;
528     LineEdit_L3C2->setText(resString) ;
529     resString = tr("%1").arg( I(3,3), 12, 'f', 6 ) ;
530     LineEdit_L3C3->setText(resString) ;
531
532     /* moments */
533     resString = tr("%1").arg( Ix, 12, 'f', 6 ) ;
534     LineEdit_IX->setText(resString) ;
535     resString = tr("%1").arg( Ix, 12, 'f', 6 ) ;
536     LineEdit_IY->setText(resString) ;
537     resString = tr("%1").arg( Iz, 12, 'f', 6 ) ;
538     LineEdit_IZ->setText(resString) ;
539
540   }
541   catch(Standard_Failure) {
542     MESSAGE("Catch intercepted in CalculateAndDisplayInertia()" << endl ) ;
543   }
544   return ;
545 }
546
547