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