]> SALOME platform Git repositories - modules/geom.git/blob - src/MeasureGUI/MeasureGUI_InertiaDlg.cxx
Salome HOME
INT PAL 0052699: Incorrect closing of "Manage dimensions" dialog box (edited)
[modules/geom.git] / src / MeasureGUI / MeasureGUI_InertiaDlg.cxx
1 // Copyright (C) 2007-2015  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, or (at your option) any later version.
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_1->setText( "1:1" );
66   myGrp->TextLabel2_2->setText( "1:2" );
67   myGrp->TextLabel2_3->setText( "1:3" );
68   myGrp->TextLabel3_1->setText( "2:1" );
69   myGrp->TextLabel3_2->setText( "2:2" );
70   myGrp->TextLabel3_3->setText( "2:3" );
71   myGrp->TextLabel4_1->setText( "3:1" );
72   myGrp->TextLabel4_2->setText( "3:2" );
73   myGrp->TextLabel4_3->setText( "3:3" );
74   myGrp->TextLabel5_1->setText( "IX" );
75   myGrp->TextLabel5_2->setText( "IY" );
76   myGrp->TextLabel5_3->setText( "IZ" );
77   myGrp->LineEdit11->setReadOnly( true );
78   myGrp->LineEdit12->setReadOnly( true );
79   myGrp->LineEdit13->setReadOnly( true );
80   myGrp->LineEdit21->setReadOnly( true );
81   myGrp->LineEdit22->setReadOnly( true );
82   myGrp->LineEdit23->setReadOnly( true );
83   myGrp->LineEdit31->setReadOnly( true );
84   myGrp->LineEdit32->setReadOnly( true );
85   myGrp->LineEdit33->setReadOnly( true );
86   myGrp->LineEdit41->setReadOnly( true );
87   myGrp->LineEdit42->setReadOnly( true );
88   myGrp->LineEdit43->setReadOnly( true );
89   myGrp->PushButton1->setIcon( image1 );
90   myGrp->LineEdit1->setReadOnly( true );
91
92   QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
93   layout->setMargin( 0 ); layout->setSpacing( 6 );
94   layout->addWidget( myGrp );
95   
96   /***************************************************************/
97
98   myHelpFileName = "inertia_page.html";
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 : activateSelection()
127 // purpose  :
128 //=================================================================================
129 void MeasureGUI_InertiaDlg::activateSelection()
130 {
131   MeasureGUI_Skeleton::activateSelection();
132   std::list<int> needTypes;
133   needTypes.push_back( TopAbs_VERTEX ), needTypes.push_back( TopAbs_EDGE ), needTypes.push_back( TopAbs_WIRE ), needTypes.push_back( TopAbs_FACE ), needTypes.push_back( TopAbs_SHELL ), needTypes.push_back( TopAbs_SOLID ), needTypes.push_back( TopAbs_COMPOUND );
134   localSelection(GEOM::GEOM_Object::_nil(), needTypes );
135 }
136
137
138 //=================================================================================
139 // function : processObject
140 // purpose  :
141 //=================================================================================
142 void MeasureGUI_InertiaDlg::processObject()
143 {
144   gp_XYZ anIXYZ;
145   gp_Mat aMat;
146
147   if ( !getParameters( aMat, anIXYZ ) ) {
148     mySelEdit->setText( "" );
149     
150     myGrp->LineEdit11->setText( "" );
151     myGrp->LineEdit12->setText( "" );
152     myGrp->LineEdit13->setText( "" );
153     
154     myGrp->LineEdit21->setText( "" );
155     myGrp->LineEdit22->setText( "" );
156     myGrp->LineEdit23->setText( "" );
157     
158     myGrp->LineEdit31->setText( "" );
159     myGrp->LineEdit32->setText( "" );
160     myGrp->LineEdit33->setText( "" );
161
162     myGrp->LineEdit41->setText( "" );
163     myGrp->LineEdit42->setText( "" );
164     myGrp->LineEdit43->setText( "" );
165   }
166   else {
167     myGrp->LineEdit11->setText( DlgRef::PrintDoubleValue( aMat( 1, 1 ), -6 ) );
168     myGrp->LineEdit12->setText( DlgRef::PrintDoubleValue( aMat( 1, 2 ), -6 ) );
169     myGrp->LineEdit13->setText( DlgRef::PrintDoubleValue( aMat( 1, 3 ), -6 ) );
170     
171     myGrp->LineEdit21->setText( DlgRef::PrintDoubleValue( aMat( 2, 1 ), -6 ) );
172     myGrp->LineEdit22->setText( DlgRef::PrintDoubleValue( aMat( 2, 2 ), -6 ) );
173     myGrp->LineEdit23->setText( DlgRef::PrintDoubleValue( aMat( 2, 3 ), -6 ) );
174     
175     myGrp->LineEdit31->setText( DlgRef::PrintDoubleValue( aMat( 3, 1 ), -6 ) );
176     myGrp->LineEdit32->setText( DlgRef::PrintDoubleValue( aMat( 3, 2 ), -6 ) );
177     myGrp->LineEdit33->setText( DlgRef::PrintDoubleValue( aMat( 3, 3 ), -6 ) );
178     
179     myGrp->LineEdit41->setText( DlgRef::PrintDoubleValue( anIXYZ.X(), -6 ) );
180     myGrp->LineEdit42->setText( DlgRef::PrintDoubleValue( anIXYZ.Y(), -6 ) );
181     myGrp->LineEdit43->setText( DlgRef::PrintDoubleValue( anIXYZ.Z(), -6 ) );
182   }
183 }
184
185 //=================================================================================
186 // function : getParameters
187 // purpose  :
188 //=================================================================================
189 bool MeasureGUI_InertiaDlg::getParameters( gp_Mat& I,
190                                            gp_XYZ& theIXYZ )
191 {
192   if ( !myObj )
193     return false;
194   else {
195     GEOM::GEOM_IMeasureOperations_var anOper = GEOM::GEOM_IMeasureOperations::_narrow( getOperation() );
196     try {
197       double x, y, z;
198       anOper->GetInertia( myObj.get(),
199                           I( 1, 1 ), I( 1, 2 ), I( 1, 3 ),
200                           I( 2, 1 ), I( 2, 2 ), I( 2, 3 ),
201                           I( 3, 1 ), I( 3, 2 ), I( 3, 3 ),
202                           x, y, z );
203
204         theIXYZ.SetCoord( x, y, z );
205     }
206     catch ( const SALOME::SALOME_Exception& e ) {
207       SalomeApp_Tools::QtCatchCorbaException( e );
208       return false;
209     }
210
211     return anOper->IsDone();
212   }
213 }
214
215 void MeasureGUI_InertiaDlg::SelectionIntoArgument()
216 {
217   myObj.nullify();
218   QList<TopAbs_ShapeEnum> aTypes;
219   aTypes << TopAbs_VERTEX << TopAbs_EDGE << TopAbs_WIRE << TopAbs_FACE << TopAbs_SHELL << TopAbs_SOLID << TopAbs_COMPSOLID << TopAbs_COMPOUND << TopAbs_SHAPE;
220   myObj = getSelected( aTypes );
221  
222   if (!myObj) {
223     mySelEdit->setText("");
224     processObject();
225     erasePreview();
226     return;
227   }
228
229   mySelEdit->setText(GEOMBase::GetName(myObj.get()));
230   processObject();
231   redisplayPreview();
232 }