Salome HOME
Bug 0020043: EDF 865 GEOM: Object is non valid after translation. Fix object after...
[modules/geom.git] / src / MeasureGUI / MeasureGUI_InertiaDlg.cxx
1 //  GEOM GEOMGUI : GUI for Geometry component
2 //
3 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
5 // 
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. 
10 // 
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. 
15 // 
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 
19 // 
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 //
23 //
24 //  File   : MeasureGUI_InertiaDlg.cxx
25 //  Author : Lucien PIGNOLONI
26 //  Module : GEOM
27
28 #include "MeasureGUI_InertiaDlg.h"
29 #include "MeasureGUI_1Sel12LineEdit_QTD.h"
30
31 #include "GEOMBase.h"
32
33 #include <BRepGProp.hxx>
34 #include <GProp_GProps.hxx>
35 #include <GProp_PrincipalProps.hxx>
36 #include <gp_XYZ.hxx>
37 #include <TopoDS_Shape.hxx>
38
39 #include "utilities.h"
40 #include "SUIT_Session.h"
41 #include "SalomeApp_Tools.h"
42
43 #include <qlineedit.h>
44 #include <qlabel.h>
45 #include <qlayout.h>
46 #include <qpushbutton.h>
47 #include <qradiobutton.h>
48 #include <qbuttongroup.h>
49
50 //=================================================================================
51 // class    : MeasureGUI_InertiaDlg()
52 // purpose  : Constructs a MeasureGUI_InertiaDlg which is a child of 'parent', with the
53 //            name 'name' and widget flags set to 'f'.
54 //            The dialog will by default be modeless, unless you set 'modal' to
55 //            TRUE to construct a modal dialog.
56 //=================================================================================
57
58 MeasureGUI_InertiaDlg::MeasureGUI_InertiaDlg( GeometryGUI* GUI, QWidget* parent )
59 : MeasureGUI_Skeleton( GUI, parent, "MeasureGUI_InertiaDlg" )
60 {
61   QPixmap image0( SUIT_Session::session()->resourceMgr()->loadPixmap(
62     "GEOM",tr( "ICON_DLG_INERTIA" ) ) );
63   QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap(
64     "GEOM",tr( "ICON_SELECT" ) ) );
65
66   setCaption( tr( "GEOM_INERTIA_TITLE" ) );
67
68   /***************************************************************/
69   
70   GroupConstructors->setTitle( tr( "GEOM_INERTIA_CONSTR" ) );
71   RadioButton1->setPixmap( image0 );
72
73   myGrp = new MeasureGUI_1Sel12LineEdit_QTD( this, "myGrp" );
74   myGrp->GroupBox1->setTitle( tr( "GEOM_MATRIX" ) );
75   myGrp->TextLabel1->setText( tr( "GEOM_OBJECT" ) );
76   myGrp->TextLabel2->setText( tr( "GEOM_INERTIA_I" ).arg( "1" ) );
77   myGrp->TextLabel3->setText( tr( "GEOM_INERTIA_I" ).arg( "2" ) );
78   myGrp->TextLabel4->setText( tr( "GEOM_INERTIA_I" ).arg( "3" ) );
79   myGrp->TextLabel5->setText( tr( "GEOM_INERTIA_IXYZ" ) );
80   myGrp->LineEdit11->setReadOnly( TRUE );
81   myGrp->LineEdit12->setReadOnly( TRUE );
82   myGrp->LineEdit13->setReadOnly( TRUE );
83   myGrp->LineEdit21->setReadOnly( TRUE );
84   myGrp->LineEdit22->setReadOnly( TRUE );
85   myGrp->LineEdit23->setReadOnly( TRUE );
86   myGrp->LineEdit31->setReadOnly( TRUE );
87   myGrp->LineEdit32->setReadOnly( TRUE );
88   myGrp->LineEdit33->setReadOnly( TRUE );
89   myGrp->LineEdit41->setReadOnly( TRUE );
90   myGrp->LineEdit42->setReadOnly( TRUE );
91   myGrp->LineEdit43->setReadOnly( TRUE );
92   myGrp->PushButton1->setPixmap( image1 );
93   myGrp->LineEdit1->setReadOnly( true );
94
95   Layout1->addWidget( myGrp, 1, 0 );
96   
97   /***************************************************************/
98
99   myHelpFileName = "using_measurement_tools_page.html#inertia_anchor";
100
101   /* Initialisation */
102   Init();
103 }
104
105
106 //=================================================================================
107 // function : ~MeasureGUI_InertiaDlg()
108 // purpose  : Destroys the object and frees any allocated resources
109 //=================================================================================
110 MeasureGUI_InertiaDlg::~MeasureGUI_InertiaDlg()
111 {
112 }
113
114
115 //=================================================================================
116 // function : Init()
117 // purpose  :
118 //=================================================================================
119 void MeasureGUI_InertiaDlg::Init()
120 {
121   mySelBtn = myGrp->PushButton1;
122   mySelEdit = myGrp->LineEdit1;
123   MeasureGUI_Skeleton::Init();
124 }
125
126 //=================================================================================
127 // function : processObject
128 // purpose  :
129 //=================================================================================
130 void MeasureGUI_InertiaDlg::processObject()
131 {
132   gp_XYZ anIXYZ;
133   gp_Mat aMat;
134
135   if ( !getParameters( aMat, anIXYZ ) )
136   {
137     mySelEdit->setText( "" );
138     
139     myGrp->LineEdit11->setText( "" );
140     myGrp->LineEdit12->setText( "" );
141     myGrp->LineEdit13->setText( "" );
142     
143     myGrp->LineEdit21->setText( "" );
144     myGrp->LineEdit22->setText( "" );
145     myGrp->LineEdit23->setText( "" );
146     
147     myGrp->LineEdit31->setText( "" );
148     myGrp->LineEdit32->setText( "" );
149     myGrp->LineEdit33->setText( "" );
150
151     myGrp->LineEdit41->setText( "" );
152     myGrp->LineEdit42->setText( "" );
153     myGrp->LineEdit43->setText( "" );
154   }
155   else
156   {
157     myGrp->LineEdit11->setText( QString( "%1" ).arg( aMat( 1, 1 ), 12, 'e', 4 ) );
158     myGrp->LineEdit12->setText( QString( "%1" ).arg( aMat( 1, 2 ), 12, 'e', 4 ) );
159     myGrp->LineEdit13->setText( QString( "%1" ).arg( aMat( 1, 3 ), 12, 'e', 4 ) );
160     
161     myGrp->LineEdit21->setText( QString( "%1" ).arg( aMat( 2, 1 ), 12, 'e', 4 ) );
162     myGrp->LineEdit22->setText( QString( "%1" ).arg( aMat( 2, 2 ), 12, 'e', 4 ) );
163     myGrp->LineEdit23->setText( QString( "%1" ).arg( aMat( 2, 3 ), 12, 'e', 4 ) );
164     
165     myGrp->LineEdit31->setText( QString( "%1" ).arg( aMat( 3, 1 ), 12, 'e', 4 ) );
166     myGrp->LineEdit32->setText( QString( "%1" ).arg( aMat( 3, 2 ), 12, 'e', 4 ) );
167     myGrp->LineEdit33->setText( QString( "%1" ).arg( aMat( 3, 3 ), 12, 'e', 4 ) );
168     
169     myGrp->LineEdit41->setText( QString( "%1" ).arg( anIXYZ.X(), 12, 'e', 4 ) );
170     myGrp->LineEdit42->setText( QString( "%1" ).arg( anIXYZ.Y(), 12, 'e', 4 ) );
171     myGrp->LineEdit43->setText( QString( "%1" ).arg( anIXYZ.Z(), 12, 'e', 4 ) );
172   }
173 }
174
175 //=================================================================================
176 // function : getParameters
177 // purpose  :
178 //=================================================================================
179 bool MeasureGUI_InertiaDlg::getParameters( gp_Mat& I,
180                                            gp_XYZ& theIXYZ )
181 {
182   if ( myObj->_is_nil() )
183     return false;
184   else
185   {
186     try
187     {
188       double x, y, z;
189       GEOM::GEOM_IMeasureOperations::_narrow( getOperation() )->GetInertia( myObj,
190         I( 1, 1 ), I( 1, 2 ), I( 1, 3 ),
191         I( 2, 1 ), I( 2, 2 ), I( 2, 3 ),
192         I( 3, 1 ), I( 3, 2 ), I( 3, 3 ),
193         x, y, z );
194
195         theIXYZ.SetCoord( x, y, z );
196     }
197     catch( const SALOME::SALOME_Exception& e )
198     {
199       SalomeApp_Tools::QtCatchCorbaException( e );
200       return false;
201     }
202
203     return getOperation()->IsDone();
204   }
205 }