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
28 #include "MeasureGUI_InertiaDlg.h"
30 #include <BRepGProp.hxx>
31 #include <GProp_GProps.hxx>
32 #include <GProp_PrincipalProps.hxx>
34 #include "utilities.h"
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 MeasureGUI_InertiaDlg::MeasureGUI_InertiaDlg(QWidget* parent, const char* name, SALOME_Selection* Sel, bool modal, WFlags fl)
46 :MeasureGUI_Skeleton(parent, name, Sel, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
48 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_INERTIA")));
49 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_SELECT")));
51 setCaption(tr("GEOM_INERTIA_TITLE"));
53 /***************************************************************/
54 GroupConstructors->setTitle(tr("GEOM_INERTIA_CONSTR"));
55 RadioButton1->setPixmap(image0);
57 GroupC1 = new MeasureGUI_1Sel12LineEdit_QTD(this, "GroupC1");
58 GroupC1->GroupBox1->setTitle(tr("GEOM_MATRIX"));
59 GroupC1->TextLabel1->setText(tr("GEOM_OBJECT"));
60 GroupC1->TextLabel2->setText(tr("GEOM_INERTIA_I").arg("1"));
61 GroupC1->TextLabel3->setText(tr("GEOM_INERTIA_I").arg("2"));
62 GroupC1->TextLabel4->setText(tr("GEOM_INERTIA_I").arg("3"));
63 GroupC1->TextLabel5->setText(tr("GEOM_INERTIA_IXYZ"));
64 GroupC1->LineEdit11->setReadOnly(TRUE);
65 GroupC1->LineEdit12->setReadOnly(TRUE);
66 GroupC1->LineEdit13->setReadOnly(TRUE);
67 GroupC1->LineEdit21->setReadOnly(TRUE);
68 GroupC1->LineEdit22->setReadOnly(TRUE);
69 GroupC1->LineEdit23->setReadOnly(TRUE);
70 GroupC1->LineEdit31->setReadOnly(TRUE);
71 GroupC1->LineEdit32->setReadOnly(TRUE);
72 GroupC1->LineEdit33->setReadOnly(TRUE);
73 GroupC1->LineEdit41->setReadOnly(TRUE);
74 GroupC1->LineEdit42->setReadOnly(TRUE);
75 GroupC1->LineEdit43->setReadOnly(TRUE);
76 GroupC1->PushButton1->setPixmap(image1);
78 Layout1->addWidget(GroupC1, 1, 0);
79 /***************************************************************/
86 //=================================================================================
87 // function : ~MeasureGUI_InertiaDlg()
88 // purpose : Destroys the object and frees any allocated resources
89 //=================================================================================
90 MeasureGUI_InertiaDlg::~MeasureGUI_InertiaDlg()
92 // no need to delete child widgets, Qt does it all for us
96 //=================================================================================
99 //=================================================================================
100 void MeasureGUI_InertiaDlg::Init()
103 myEditCurrentArgument = GroupC1->LineEdit1;
105 /* signals and slots connections */
106 connect(GroupC1->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
107 connect(GroupC1->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
109 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
111 /* displays Dialog */
119 //=================================================================================
120 // function : SelectionIntoArgument()
121 // purpose : Called when selection as changed or other case
122 //=================================================================================
123 void MeasureGUI_InertiaDlg::SelectionIntoArgument()
125 myEditCurrentArgument->setText("");
126 QString aString = "";
128 GroupC1->LineEdit11->setText("");
129 GroupC1->LineEdit12->setText("");
130 GroupC1->LineEdit13->setText("");
131 GroupC1->LineEdit21->setText("");
132 GroupC1->LineEdit22->setText("");
133 GroupC1->LineEdit23->setText("");
134 GroupC1->LineEdit31->setText("");
135 GroupC1->LineEdit32->setText("");
136 GroupC1->LineEdit33->setText("");
137 GroupC1->LineEdit41->setText("");
138 GroupC1->LineEdit42->setText("");
139 GroupC1->LineEdit43->setText("");
141 int nbSel = myGeomBase->GetNameOfSelectedIObjects(mySelection, aString);
147 if(!myGeomBase->GetTopoFromSelection(mySelection, S) || S.IsNull())
150 GroupC1->LineEdit1->setText(aString);
152 this->CalculateAndDisplayInertia(S);
157 //=================================================================================
158 // function : SetEditCurrentArgument()
160 //=================================================================================
161 void MeasureGUI_InertiaDlg::SetEditCurrentArgument()
163 QPushButton* send = (QPushButton*)sender();
165 if(send == GroupC1->PushButton1) {
166 GroupC1->LineEdit1->setFocus();
167 myEditCurrentArgument = GroupC1->LineEdit1;
170 this->SelectionIntoArgument();
175 //=================================================================================
176 // function : LineEditReturnPressed()
178 //=================================================================================
179 void MeasureGUI_InertiaDlg::LineEditReturnPressed()
181 QLineEdit* send = (QLineEdit*)sender();
182 if(send == GroupC1->LineEdit1)
183 myEditCurrentArgument = GroupC1->LineEdit1;
187 MeasureGUI_Skeleton::LineEditReturnPressed();
192 //=================================================================================
193 // function : ActivateThisDialog()
195 //=================================================================================
196 void MeasureGUI_InertiaDlg::ActivateThisDialog()
198 MeasureGUI_Skeleton::ActivateThisDialog();
199 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
204 //=================================================================================
205 // function : enterEvent()
207 //=================================================================================
208 void MeasureGUI_InertiaDlg::enterEvent(QEvent* e)
210 if(GroupConstructors->isEnabled())
212 this->ActivateThisDialog();
217 //=================================================================================
218 // function : CalculateAndDisplayInertia()
220 //=================================================================================
221 void MeasureGUI_InertiaDlg::CalculateAndDisplayInertia(const TopoDS_Shape& S)
223 GroupC1->LineEdit11->setText("");
224 GroupC1->LineEdit12->setText("");
225 GroupC1->LineEdit13->setText("");
226 GroupC1->LineEdit21->setText("");
227 GroupC1->LineEdit22->setText("");
228 GroupC1->LineEdit23->setText("");
229 GroupC1->LineEdit31->setText("");
230 GroupC1->LineEdit32->setText("");
231 GroupC1->LineEdit33->setText("");
232 GroupC1->LineEdit41->setText("");
233 GroupC1->LineEdit42->setText("");
234 GroupC1->LineEdit43->setText("");
243 if(S.ShapeType() == TopAbs_VERTEX || S.ShapeType() == TopAbs_EDGE || S.ShapeType() == TopAbs_WIRE)
244 BRepGProp::LinearProperties(S, System);
245 else if(S.ShapeType() == TopAbs_FACE || S.ShapeType() == TopAbs_SHELL)
246 BRepGProp::SurfaceProperties(S, System);
248 BRepGProp::VolumeProperties(S, System);
250 gp_Mat I = System.MatrixOfInertia() ;
251 GProp_PrincipalProps Pr = System.PrincipalProperties();
252 Standard_Real Ix,Iy,Iz;
253 Pr.Moments(Ix,Iy,Iz);
256 resString = tr("%1").arg(I(1,1), 12, 'f', 6);
257 GroupC1->LineEdit11->setText(resString);
258 resString = tr("%1").arg(I(1,2), 12, 'f', 6);
259 GroupC1->LineEdit12->setText(resString);
260 resString = tr("%1").arg(I(1,3), 12, 'f', 6);
261 GroupC1->LineEdit13->setText(resString);
263 resString = tr("%1").arg(I(2,1), 12, 'f', 6);
264 GroupC1->LineEdit21->setText(resString);
265 resString = tr("%1").arg(I(2,2), 12, 'f', 6);
266 GroupC1->LineEdit22->setText(resString);
267 resString = tr("%1").arg(I(2,3), 12, 'f', 6);
268 GroupC1->LineEdit23->setText(resString);
270 resString = tr("%1").arg(I(3,1), 12, 'f', 6);
271 GroupC1->LineEdit31->setText(resString);
272 resString = tr("%1").arg(I(3,2), 12, 'f', 6);
273 GroupC1->LineEdit32->setText(resString);
274 resString = tr("%1").arg(I(3,3), 12, 'f', 6);
275 GroupC1->LineEdit33->setText(resString);
278 resString = tr("%1").arg(Ix, 12, 'f', 6);
279 GroupC1->LineEdit41->setText(resString);
280 resString = tr("%1").arg(Ix, 12, 'f', 6);
281 GroupC1->LineEdit42->setText(resString);
282 resString = tr("%1").arg(Iz, 12, 'f', 6);
283 GroupC1->LineEdit43->setText(resString);
285 catch(Standard_Failure) {
286 MESSAGE("Catch intercepted in CalculateAndDisplayInertia()");