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_PropertiesDlg.cxx
25 // Author : Lucien PIGNOLONI
29 #include "MeasureGUI_PropertiesDlg.h"
31 #include <TopExp_Explorer.hxx>
32 #include <BRepGProp.hxx>
33 #include <GProp_GProps.hxx>
34 #include <GProp_PrincipalProps.hxx>
36 #include "utilities.h"
40 //=================================================================================
41 // class : MeasureGUI_PropertiesDlg()
42 // purpose : Constructs a MeasureGUI_PropertiesDlg 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_PropertiesDlg::MeasureGUI_PropertiesDlg(QWidget* parent, const char* name, SALOME_Selection* Sel, bool modal, WFlags fl)
48 :MeasureGUI_Skeleton(parent, name, Sel, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
50 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_BASICPROPERTIES")));
51 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_SELECT")));
53 setCaption(tr("GEOM_PROPERTIES_TITLE"));
55 /***************************************************************/
56 GroupConstructors->setTitle(tr("GEOM_PROPERTIES"));
57 RadioButton1->setPixmap(image0);
59 GroupC1 = new MeasureGUI_1Sel3LineEdit_QTD(this, "GroupC1");
60 GroupC1->GroupBox1->setTitle(tr("GEOM_PROPERTIES_CONSTR"));
61 GroupC1->TextLabel1->setText(tr("GEOM_OBJECT"));
62 GroupC1->TextLabel2->setText(tr("GEOM_LENGTH"));
63 GroupC1->TextLabel3->setText(tr("GEOM_PROPERTIES_SURFACE"));
64 GroupC1->TextLabel4->setText(tr("GEOM_PROPERTIES_VOLUME"));
65 GroupC1->LineEdit2->setReadOnly(TRUE);
66 GroupC1->LineEdit3->setReadOnly(TRUE);
67 GroupC1->LineEdit4->setReadOnly(TRUE);
68 GroupC1->PushButton1->setPixmap(image1);
70 Layout1->addWidget(GroupC1, 1, 0);
71 /***************************************************************/
78 //=================================================================================
79 // function : ~MeasureGUI_PropertiesDlg()
80 // purpose : Destroys the object and frees any allocated resources
81 //=================================================================================
82 MeasureGUI_PropertiesDlg::~MeasureGUI_PropertiesDlg()
84 // no need to delete child widgets, Qt does it all for us
88 //=================================================================================
91 //=================================================================================
92 void MeasureGUI_PropertiesDlg::Init()
95 myEditCurrentArgument = GroupC1->LineEdit1;
97 /* signals and slots connections */
98 connect(GroupC1->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
99 connect(GroupC1->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
101 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
103 /* displays Dialog */
111 //=================================================================================
112 // function : SelectionIntoArgument()
113 // purpose : Called when selection as changed or other case
114 //=================================================================================
115 void MeasureGUI_PropertiesDlg::SelectionIntoArgument()
117 myGeomBase->EraseSimulationShape();
118 mySimulationTopoDs.Nullify();
119 myEditCurrentArgument->setText("");
120 QString aString = "";
122 GroupC1->LineEdit2->setText("");
123 GroupC1->LineEdit3->setText("");
124 GroupC1->LineEdit4->setText("");
126 int nbSel = myGeomBase->GetNameOfSelectedIObjects(mySelection, aString);
132 if(!myGeomBase->GetTopoFromSelection(mySelection, S))
136 if(S.IsNull() || S.ShapeType() == TopAbs_VERTEX)
139 GroupC1->LineEdit1->setText(aString);
141 /* Try to display of a cone simulation shape to show direction of a linear edge only in OCC viewer */
142 if(myGeomBase->CreateArrowForLinearEdge(S, mySimulationTopoDs))
143 myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
145 this->CalculateAndDisplayProperties(S);
150 //=================================================================================
151 // function : SetEditCurrentArgument()
153 //=================================================================================
154 void MeasureGUI_PropertiesDlg::SetEditCurrentArgument()
156 QPushButton* send = (QPushButton*)sender();
158 if(send == GroupC1->PushButton1) {
159 GroupC1->LineEdit1->setFocus();
160 myEditCurrentArgument = GroupC1->LineEdit1;
163 this->SelectionIntoArgument();
168 //=================================================================================
169 // function : LineEditReturnPressed()
171 //=================================================================================
172 void MeasureGUI_PropertiesDlg::LineEditReturnPressed()
174 QLineEdit* send = (QLineEdit*)sender();
175 if(send == GroupC1->LineEdit1)
176 myEditCurrentArgument = GroupC1->LineEdit1;
180 MeasureGUI_Skeleton::LineEditReturnPressed();
185 //=================================================================================
186 // function : ActivateThisDialog()
188 //=================================================================================
189 void MeasureGUI_PropertiesDlg::ActivateThisDialog()
191 MeasureGUI_Skeleton::ActivateThisDialog();
192 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
193 if(!mySimulationTopoDs.IsNull())
194 myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
199 //=================================================================================
200 // function : enterEvent()
202 //=================================================================================
203 void MeasureGUI_PropertiesDlg::enterEvent(QEvent* e)
205 if(GroupConstructors->isEnabled())
207 this->ActivateThisDialog();
212 //=================================================================================
213 // function : CalculateAndDisplayProperties()
215 //=================================================================================
216 void MeasureGUI_PropertiesDlg::CalculateAndDisplayProperties(const TopoDS_Shape& S)
218 GroupC1->LineEdit2->setText("");
219 GroupC1->LineEdit3->setText("");
220 GroupC1->LineEdit4->setText("");
225 Standard_Real result;
226 GProp_GProps LProps, SProps;
230 BRepGProp::LinearProperties(S,LProps);
231 result = LProps.Mass();
232 if(!IsEqual(result, 0.0)) {
233 resString = tr("%1").arg(result, 12, 'f', 6);
234 GroupC1->LineEdit2->setText(resString);
237 BRepGProp::SurfaceProperties(S, SProps);
238 result = SProps.Mass();
239 if(!IsEqual(result, 0.0)) {
240 resString = tr("%1").arg(result, 12, 'f', 6);
241 GroupC1->LineEdit3->setText(resString);
245 if(S.ShapeType() < TopAbs_SHELL) {
246 for(TopExp_Explorer Exp(S,TopAbs_SOLID); Exp.More(); Exp.Next()) {
248 BRepGProp::VolumeProperties(Exp.Current(), VProps);
249 result += VProps.Mass();
252 if (!IsEqual(result, 0.0)) {
253 resString = tr("%1").arg(result, 12, 'f', 6);
254 GroupC1->LineEdit4->setText(resString);
257 catch(Standard_Failure) {
258 MESSAGE("Catch intercepted in CalculateAndDisplayProperties()");