1 // GEOM GEOMGUI : GUI for Geometry component
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : MeasureGUI_InertiaDlg.cxx
25 // Author : Lucien PIGNOLONI
29 #include "MeasureGUI_InertiaDlg.h"
31 #include <BRepGProp.hxx>
32 #include <GProp_GProps.hxx>
33 #include <GProp_PrincipalProps.hxx>
35 //=================================================================================
36 // class : MeasureGUI_InertiaDlg()
37 // purpose : Constructs a MeasureGUI_InertiaDlg which is a child of 'parent', with the
38 // name 'name' and widget flags set to 'f'.
39 // The dialog will by default be modeless, unless you set 'modal' to
40 // TRUE to construct a modal dialog.
41 //=================================================================================
42 MeasureGUI_InertiaDlg::MeasureGUI_InertiaDlg(QWidget* parent, const char* name, SALOME_Selection* Sel, bool modal, WFlags fl)
43 :MeasureGUI_Skeleton(parent, name, Sel, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
45 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_INERTIA")));
46 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_SELECT")));
48 setCaption(tr("GEOM_INERTIA_TITLE"));
50 /***************************************************************/
51 GroupConstructors->setTitle(tr("GEOM_INERTIA_CONSTR"));
52 RadioButton1->setPixmap(image0);
54 GroupC1 = new MeasureGUI_1Sel12LineEdit_QTD(this, "GroupC1");
55 GroupC1->GroupBox1->setTitle(tr("GEOM_MATRIX"));
56 GroupC1->TextLabel1->setText(tr("GEOM_OBJECT"));
57 GroupC1->TextLabel2->setText(tr("GEOM_INERTIA_I").arg("1"));
58 GroupC1->TextLabel3->setText(tr("GEOM_INERTIA_I").arg("2"));
59 GroupC1->TextLabel4->setText(tr("GEOM_INERTIA_I").arg("3"));
60 GroupC1->TextLabel5->setText(tr("GEOM_INERTIA_IXYZ"));
61 GroupC1->LineEdit11->setReadOnly(TRUE);
62 GroupC1->LineEdit12->setReadOnly(TRUE);
63 GroupC1->LineEdit13->setReadOnly(TRUE);
64 GroupC1->LineEdit21->setReadOnly(TRUE);
65 GroupC1->LineEdit22->setReadOnly(TRUE);
66 GroupC1->LineEdit23->setReadOnly(TRUE);
67 GroupC1->LineEdit31->setReadOnly(TRUE);
68 GroupC1->LineEdit32->setReadOnly(TRUE);
69 GroupC1->LineEdit33->setReadOnly(TRUE);
70 GroupC1->LineEdit41->setReadOnly(TRUE);
71 GroupC1->LineEdit42->setReadOnly(TRUE);
72 GroupC1->LineEdit43->setReadOnly(TRUE);
73 GroupC1->PushButton1->setPixmap(image1);
75 Layout1->addWidget(GroupC1, 1, 0);
76 /***************************************************************/
83 //=================================================================================
84 // function : ~MeasureGUI_InertiaDlg()
85 // purpose : Destroys the object and frees any allocated resources
86 //=================================================================================
87 MeasureGUI_InertiaDlg::~MeasureGUI_InertiaDlg()
89 // no need to delete child widgets, Qt does it all for us
93 //=================================================================================
96 //=================================================================================
97 void MeasureGUI_InertiaDlg::Init()
100 myEditCurrentArgument = GroupC1->LineEdit1;
102 /* signals and slots connections */
103 connect(GroupC1->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
104 connect(GroupC1->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
106 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
108 /* displays Dialog */
116 //=================================================================================
117 // function : SelectionIntoArgument()
118 // purpose : Called when selection as changed or other case
119 //=================================================================================
120 void MeasureGUI_InertiaDlg::SelectionIntoArgument()
122 myEditCurrentArgument->setText("");
123 QString aString = "";
125 GroupC1->LineEdit11->setText("");
126 GroupC1->LineEdit12->setText("");
127 GroupC1->LineEdit13->setText("");
128 GroupC1->LineEdit21->setText("");
129 GroupC1->LineEdit22->setText("");
130 GroupC1->LineEdit23->setText("");
131 GroupC1->LineEdit31->setText("");
132 GroupC1->LineEdit32->setText("");
133 GroupC1->LineEdit33->setText("");
134 GroupC1->LineEdit41->setText("");
135 GroupC1->LineEdit42->setText("");
136 GroupC1->LineEdit43->setText("");
138 int nbSel = myGeomBase->GetNameOfSelectedIObjects(mySelection, aString);
144 if(!myGeomBase->GetTopoFromSelection(mySelection, S) || S.IsNull())
147 GroupC1->LineEdit1->setText(aString);
149 this->CalculateAndDisplayInertia(S);
154 //=================================================================================
155 // function : SetEditCurrentArgument()
157 //=================================================================================
158 void MeasureGUI_InertiaDlg::SetEditCurrentArgument()
160 QPushButton* send = (QPushButton*)sender();
162 if(send == GroupC1->PushButton1) {
163 GroupC1->LineEdit1->setFocus();
164 myEditCurrentArgument = GroupC1->LineEdit1;
167 this->SelectionIntoArgument();
172 //=================================================================================
173 // function : LineEditReturnPressed()
175 //=================================================================================
176 void MeasureGUI_InertiaDlg::LineEditReturnPressed()
178 QLineEdit* send = (QLineEdit*)sender();
179 if(send == GroupC1->LineEdit1)
180 myEditCurrentArgument = GroupC1->LineEdit1;
184 MeasureGUI_Skeleton::LineEditReturnPressed();
189 //=================================================================================
190 // function : ActivateThisDialog()
192 //=================================================================================
193 void MeasureGUI_InertiaDlg::ActivateThisDialog()
195 MeasureGUI_Skeleton::ActivateThisDialog();
196 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
201 //=================================================================================
202 // function : enterEvent()
204 //=================================================================================
205 void MeasureGUI_InertiaDlg::enterEvent(QEvent* e)
207 if(GroupConstructors->isEnabled())
209 this->ActivateThisDialog();
214 //=================================================================================
215 // function : CalculateAndDisplayInertia()
217 //=================================================================================
218 void MeasureGUI_InertiaDlg::CalculateAndDisplayInertia(const TopoDS_Shape& S)
220 GroupC1->LineEdit11->setText("");
221 GroupC1->LineEdit12->setText("");
222 GroupC1->LineEdit13->setText("");
223 GroupC1->LineEdit21->setText("");
224 GroupC1->LineEdit22->setText("");
225 GroupC1->LineEdit23->setText("");
226 GroupC1->LineEdit31->setText("");
227 GroupC1->LineEdit32->setText("");
228 GroupC1->LineEdit33->setText("");
229 GroupC1->LineEdit41->setText("");
230 GroupC1->LineEdit42->setText("");
231 GroupC1->LineEdit43->setText("");
240 if(S.ShapeType() == TopAbs_VERTEX || S.ShapeType() == TopAbs_EDGE || S.ShapeType() == TopAbs_WIRE)
241 BRepGProp::LinearProperties(S, System);
242 else if(S.ShapeType() == TopAbs_FACE || S.ShapeType() == TopAbs_SHELL)
243 BRepGProp::SurfaceProperties(S, System);
245 BRepGProp::VolumeProperties(S, System);
247 gp_Mat I = System.MatrixOfInertia() ;
248 GProp_PrincipalProps Pr = System.PrincipalProperties();
249 Standard_Real Ix,Iy,Iz;
250 Pr.Moments(Ix,Iy,Iz);
253 resString = tr("%1").arg(I(1,1), 12, 'f', 6);
254 GroupC1->LineEdit11->setText(resString);
255 resString = tr("%1").arg(I(1,2), 12, 'f', 6);
256 GroupC1->LineEdit12->setText(resString);
257 resString = tr("%1").arg(I(1,3), 12, 'f', 6);
258 GroupC1->LineEdit13->setText(resString);
260 resString = tr("%1").arg(I(2,1), 12, 'f', 6);
261 GroupC1->LineEdit21->setText(resString);
262 resString = tr("%1").arg(I(2,2), 12, 'f', 6);
263 GroupC1->LineEdit22->setText(resString);
264 resString = tr("%1").arg(I(2,3), 12, 'f', 6);
265 GroupC1->LineEdit23->setText(resString);
267 resString = tr("%1").arg(I(3,1), 12, 'f', 6);
268 GroupC1->LineEdit31->setText(resString);
269 resString = tr("%1").arg(I(3,2), 12, 'f', 6);
270 GroupC1->LineEdit32->setText(resString);
271 resString = tr("%1").arg(I(3,3), 12, 'f', 6);
272 GroupC1->LineEdit33->setText(resString);
275 resString = tr("%1").arg(Ix, 12, 'f', 6);
276 GroupC1->LineEdit41->setText(resString);
277 resString = tr("%1").arg(Ix, 12, 'f', 6);
278 GroupC1->LineEdit42->setText(resString);
279 resString = tr("%1").arg(Iz, 12, 'f', 6);
280 GroupC1->LineEdit43->setText(resString);
282 catch(Standard_Failure) {
283 MESSAGE("Catch intercepted in CalculateAndDisplayInertia()");