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