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_CenterMassDlg.cxx
25 // Author : Lucien PIGNOLONI
30 #include "MeasureGUI_CenterMassDlg.h"
32 #include <BRepBuilderAPI_MakeVertex.hxx>
33 #include <BRepGProp.hxx>
34 #include <GProp_GProps.hxx>
35 #include <GProp_PrincipalProps.hxx>
37 //=================================================================================
38 // class : MeasureGUI_CenterMassDlg()
39 // purpose : Constructs a MeasureGUI_CenterMassDlg which is a child of 'parent', with the
40 // name 'name' and widget flags set to 'f'.
41 // The dialog will by default be modeless, unless you set 'modal' to
42 // TRUE to construct a modal dialog.
43 //=================================================================================
44 MeasureGUI_CenterMassDlg::MeasureGUI_CenterMassDlg(QWidget* parent, const char* name, MeasureGUI* theMeasureGUI, SALOME_Selection* Sel, bool modal, WFlags fl)
45 :GEOMBase_Skeleton(parent, name, Sel, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
47 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_CENTERMASS")));
48 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_SELECT")));
50 setCaption(tr("GEOM_CMASS_TITLE"));
52 /***************************************************************/
53 GroupConstructors->setTitle(tr("GEOM_CMASS"));
54 RadioButton1->setPixmap(image0);
55 RadioButton2->close(TRUE);
56 RadioButton3->close(TRUE);
58 GroupC1 = new MeasureGUI_1Sel3LineEdit_QTD(this, "GroupC1");
59 GroupC1->GroupBox1->setTitle(tr("GEOM_CENTER"));
60 GroupC1->TextLabel1->setText(tr("GEOM_OBJECT"));
61 GroupC1->TextLabel2->setText(tr("GEOM_X"));
62 GroupC1->TextLabel3->setText(tr("GEOM_Y"));
63 GroupC1->TextLabel4->setText(tr("GEOM_Z"));
64 GroupC1->LineEdit2->setReadOnly(TRUE);
65 GroupC1->LineEdit3->setReadOnly(TRUE);
66 GroupC1->LineEdit4->setReadOnly(TRUE);
67 GroupC1->PushButton1->setPixmap(image1);
69 Layout1->addWidget(GroupC1, 1, 0);
70 /***************************************************************/
73 myMeasureGUI = theMeasureGUI;
78 //=================================================================================
79 // function : ~MeasureGUI_CenterMassDlg()
80 // purpose : Destroys the object and frees any allocated resources
81 //=================================================================================
82 MeasureGUI_CenterMassDlg::~MeasureGUI_CenterMassDlg()
84 // no need to delete child widgets, Qt does it all for us
88 //=================================================================================
91 //=================================================================================
92 void MeasureGUI_CenterMassDlg::Init()
95 myEditCurrentArgument = GroupC1->LineEdit1;
97 myOkCenterMass = false;
99 /* signals and slots connections */
100 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
101 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
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 : ClickOnOk()
119 //=================================================================================
120 void MeasureGUI_CenterMassDlg::ClickOnOk()
122 this->ClickOnApply();
128 //=================================================================================
129 // function : ClickOnApply()
131 //=================================================================================
132 void MeasureGUI_CenterMassDlg::ClickOnApply()
134 QAD_Application::getDesktop()->putInfo(tr(""));
135 if (mySimulationTopoDs.IsNull())
137 myGeomBase->EraseSimulationShape();
138 mySimulationTopoDs.Nullify();
141 myMeasureGUI->MakeCDGAndDisplay(myGeomShape);
146 //=================================================================================
147 // function : SelectionIntoArgument()
148 // purpose : Called when selection as changed or other case
149 //=================================================================================
150 void MeasureGUI_CenterMassDlg::SelectionIntoArgument()
152 myGeomBase->EraseSimulationShape();
153 myEditCurrentArgument->setText("");
154 QString aString = "";
156 myOkCenterMass = false;
157 GroupC1->LineEdit2->setText("");
158 GroupC1->LineEdit3->setText("");
159 GroupC1->LineEdit4->setText("");
161 int nbSel = myGeomBase->GetNameOfSelectedIObjects(mySelection, aString);
166 Handle(SALOME_InteractiveObject) IO = mySelection->firstIObject();
167 if(!myGeomBase->GetTopoFromSelection(mySelection, this->myShape))
170 Standard_Boolean testResult;
171 myGeomShape = myGeomBase->ConvertIOinGEOMShape(IO, testResult);
175 myEditCurrentArgument->setText(aString);
177 if(this->CalculateAndDisplayCenterMass())
178 myOkCenterMass = true;
183 //=================================================================================
184 // function : SetEditCurrentArgument()
186 //=================================================================================
187 void MeasureGUI_CenterMassDlg::SetEditCurrentArgument()
189 QPushButton* send = (QPushButton*)sender();
191 if(send == GroupC1->PushButton1) {
192 GroupC1->LineEdit1->setFocus();
193 myEditCurrentArgument = GroupC1->LineEdit1;
196 this->SelectionIntoArgument();
201 //=================================================================================
202 // function : LineEditReturnPressed()
204 //=================================================================================
205 void MeasureGUI_CenterMassDlg::LineEditReturnPressed()
207 QLineEdit* send = (QLineEdit*)sender();
208 if(send == GroupC1->LineEdit1)
209 myEditCurrentArgument = GroupC1->LineEdit1;
213 GEOMBase_Skeleton::LineEditReturnPressed();
218 //=================================================================================
219 // function : ActivateThisDialog()
221 //=================================================================================
222 void MeasureGUI_CenterMassDlg::ActivateThisDialog()
224 GEOMBase_Skeleton::ActivateThisDialog();
225 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
226 if(!mySimulationTopoDs.IsNull())
227 myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
232 //=================================================================================
233 // function : enterEvent()
235 //=================================================================================
236 void MeasureGUI_CenterMassDlg::enterEvent(QEvent* e)
238 if(GroupConstructors->isEnabled())
240 this->ActivateThisDialog();
245 //=================================================================================
246 // function : CalculateAndDisplayCenterMass()
248 //=================================================================================
249 bool MeasureGUI_CenterMassDlg::CalculateAndDisplayCenterMass()
251 myGeomBase->EraseSimulationShape();
252 mySimulationTopoDs.Nullify();
258 if(myShape.ShapeType() == TopAbs_VERTEX)
259 myGeomBase->VertexToPoint(myShape, myCenterMass);
260 else if(myShape.ShapeType() == TopAbs_EDGE || myShape.ShapeType() == TopAbs_WIRE) {
261 BRepGProp::LinearProperties(myShape, System);
262 myCenterMass = System.CentreOfMass();
264 else if(myShape.ShapeType() == TopAbs_FACE || myShape.ShapeType() == TopAbs_SHELL) {
265 BRepGProp::SurfaceProperties(myShape, System);
266 myCenterMass = System.CentreOfMass();
269 BRepGProp::VolumeProperties(myShape, System);
270 myCenterMass = System.CentreOfMass();
273 BRepBuilderAPI_MakeVertex V(myCenterMass);
274 mySimulationTopoDs = V.Shape();
276 resString = tr("%1").arg(myCenterMass.X(), 12, 'f', 6);
277 GroupC1->LineEdit2->setText(resString);
279 resString = tr("%1").arg(myCenterMass.Y(), 12, 'f', 6);
280 GroupC1->LineEdit3->setText(resString);
282 resString = tr("%1").arg(myCenterMass.Z(), 12, 'f', 6);
283 GroupC1->LineEdit4->setText(resString);
286 if(!mySimulationTopoDs.IsNull()) {
287 myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
291 catch(Standard_Failure) {
292 MESSAGE("Catch intercepted in CalculateAndDisplayCenterMass()");