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
29 #include "MeasureGUI_CenterMassDlg.h"
31 #include <BRepBuilderAPI_MakeVertex.hxx>
32 #include <BRepGProp.hxx>
33 #include <GProp_GProps.hxx>
34 #include <GProp_PrincipalProps.hxx>
36 #include "utilities.h"
40 //=================================================================================
41 // class : MeasureGUI_CenterMassDlg()
42 // purpose : Constructs a MeasureGUI_CenterMassDlg which is a child of 'parent', with the
43 // name 'name' and widget flags set to 'f'.
44 // The dialog will by default be modeless, unless you set 'modal' to
45 // TRUE to construct a modal dialog.
46 //=================================================================================
47 MeasureGUI_CenterMassDlg::MeasureGUI_CenterMassDlg(QWidget* parent, const char* name, MeasureGUI* theMeasureGUI, SALOME_Selection* Sel, bool modal, WFlags fl)
48 :GEOMBase_Skeleton(parent, name, Sel, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
50 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_CENTERMASS")));
51 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_SELECT")));
53 setCaption(tr("GEOM_CMASS_TITLE"));
55 /***************************************************************/
56 GroupConstructors->setTitle(tr("GEOM_CMASS"));
57 RadioButton1->setPixmap(image0);
58 RadioButton2->close(TRUE);
59 RadioButton3->close(TRUE);
61 GroupC1 = new MeasureGUI_1Sel3LineEdit_QTD(this, "GroupC1");
62 GroupC1->GroupBox1->setTitle(tr("GEOM_CENTER"));
63 GroupC1->TextLabel1->setText(tr("GEOM_OBJECT"));
64 GroupC1->TextLabel2->setText(tr("GEOM_X"));
65 GroupC1->TextLabel3->setText(tr("GEOM_Y"));
66 GroupC1->TextLabel4->setText(tr("GEOM_Z"));
67 GroupC1->LineEdit2->setReadOnly(TRUE);
68 GroupC1->LineEdit3->setReadOnly(TRUE);
69 GroupC1->LineEdit4->setReadOnly(TRUE);
70 GroupC1->PushButton1->setPixmap(image1);
72 Layout1->addWidget(GroupC1, 1, 0);
73 /***************************************************************/
76 myMeasureGUI = theMeasureGUI;
81 //=================================================================================
82 // function : ~MeasureGUI_CenterMassDlg()
83 // purpose : Destroys the object and frees any allocated resources
84 //=================================================================================
85 MeasureGUI_CenterMassDlg::~MeasureGUI_CenterMassDlg()
87 // no need to delete child widgets, Qt does it all for us
91 //=================================================================================
94 //=================================================================================
95 void MeasureGUI_CenterMassDlg::Init()
98 myEditCurrentArgument = GroupC1->LineEdit1;
100 myOkCenterMass = false;
102 /* signals and slots connections */
103 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
104 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
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 : ClickOnOk()
122 //=================================================================================
123 void MeasureGUI_CenterMassDlg::ClickOnOk()
125 this->ClickOnApply();
131 //=================================================================================
132 // function : ClickOnApply()
134 //=================================================================================
135 void MeasureGUI_CenterMassDlg::ClickOnApply()
137 QAD_Application::getDesktop()->putInfo(tr(""));
138 if (mySimulationTopoDs.IsNull())
140 myGeomBase->EraseSimulationShape();
141 mySimulationTopoDs.Nullify();
144 myMeasureGUI->MakeCDGAndDisplay(myGeomShape);
149 //=================================================================================
150 // function : SelectionIntoArgument()
151 // purpose : Called when selection as changed or other case
152 //=================================================================================
153 void MeasureGUI_CenterMassDlg::SelectionIntoArgument()
155 myGeomBase->EraseSimulationShape();
156 myEditCurrentArgument->setText("");
157 QString aString = "";
159 myOkCenterMass = false;
160 GroupC1->LineEdit2->setText("");
161 GroupC1->LineEdit3->setText("");
162 GroupC1->LineEdit4->setText("");
164 int nbSel = myGeomBase->GetNameOfSelectedIObjects(mySelection, aString);
169 Handle(SALOME_InteractiveObject) IO = mySelection->firstIObject();
170 if(!myGeomBase->GetTopoFromSelection(mySelection, this->myShape))
173 Standard_Boolean testResult;
174 myGeomShape = myGeomBase->ConvertIOinGEOMShape(IO, testResult);
178 myEditCurrentArgument->setText(aString);
180 if(this->CalculateAndDisplayCenterMass())
181 myOkCenterMass = true;
186 //=================================================================================
187 // function : SetEditCurrentArgument()
189 //=================================================================================
190 void MeasureGUI_CenterMassDlg::SetEditCurrentArgument()
192 QPushButton* send = (QPushButton*)sender();
194 if(send == GroupC1->PushButton1) {
195 GroupC1->LineEdit1->setFocus();
196 myEditCurrentArgument = GroupC1->LineEdit1;
199 this->SelectionIntoArgument();
204 //=================================================================================
205 // function : LineEditReturnPressed()
207 //=================================================================================
208 void MeasureGUI_CenterMassDlg::LineEditReturnPressed()
210 QLineEdit* send = (QLineEdit*)sender();
211 if(send == GroupC1->LineEdit1)
212 myEditCurrentArgument = GroupC1->LineEdit1;
216 GEOMBase_Skeleton::LineEditReturnPressed();
221 //=================================================================================
222 // function : ActivateThisDialog()
224 //=================================================================================
225 void MeasureGUI_CenterMassDlg::ActivateThisDialog()
227 GEOMBase_Skeleton::ActivateThisDialog();
228 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
229 if(!mySimulationTopoDs.IsNull())
230 myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
235 //=================================================================================
236 // function : enterEvent()
238 //=================================================================================
239 void MeasureGUI_CenterMassDlg::enterEvent(QEvent* e)
241 if(GroupConstructors->isEnabled())
243 this->ActivateThisDialog();
248 //=================================================================================
249 // function : CalculateAndDisplayCenterMass()
251 //=================================================================================
252 bool MeasureGUI_CenterMassDlg::CalculateAndDisplayCenterMass()
254 myGeomBase->EraseSimulationShape();
255 mySimulationTopoDs.Nullify();
261 if(myShape.ShapeType() == TopAbs_VERTEX)
262 myGeomBase->VertexToPoint(myShape, myCenterMass);
263 else if(myShape.ShapeType() == TopAbs_EDGE || myShape.ShapeType() == TopAbs_WIRE) {
264 BRepGProp::LinearProperties(myShape, System);
265 myCenterMass = System.CentreOfMass();
267 else if(myShape.ShapeType() == TopAbs_FACE || myShape.ShapeType() == TopAbs_SHELL) {
268 BRepGProp::SurfaceProperties(myShape, System);
269 myCenterMass = System.CentreOfMass();
272 BRepGProp::VolumeProperties(myShape, System);
273 myCenterMass = System.CentreOfMass();
276 BRepBuilderAPI_MakeVertex V(myCenterMass);
277 mySimulationTopoDs = V.Shape();
279 resString = tr("%1").arg(myCenterMass.X(), 12, 'f', 6);
280 GroupC1->LineEdit2->setText(resString);
282 resString = tr("%1").arg(myCenterMass.Y(), 12, 'f', 6);
283 GroupC1->LineEdit3->setText(resString);
285 resString = tr("%1").arg(myCenterMass.Z(), 12, 'f', 6);
286 GroupC1->LineEdit4->setText(resString);
289 if(!mySimulationTopoDs.IsNull()) {
290 myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
294 catch(Standard_Failure) {
295 MESSAGE("Catch intercepted in CalculateAndDisplayCenterMass()");