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