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
30 #include "MeasureGUI_PropertiesDlg.h"
32 #include <TopExp_Explorer.hxx>
33 #include <BRepGProp.hxx>
34 #include <GProp_GProps.hxx>
35 #include <GProp_PrincipalProps.hxx>
37 //=================================================================================
38 // class : MeasureGUI_PropertiesDlg()
39 // purpose : Constructs a MeasureGUI_PropertiesDlg 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_PropertiesDlg::MeasureGUI_PropertiesDlg(QWidget* parent, const char* name, SALOME_Selection* Sel, bool modal, WFlags fl)
45 :MeasureGUI_Skeleton(parent, name, Sel, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
47 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_BASICPROPERTIES")));
48 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_SELECT")));
50 setCaption(tr("GEOM_PROPERTIES_TITLE"));
52 /***************************************************************/
53 GroupConstructors->setTitle(tr("GEOM_PROPERTIES"));
54 RadioButton1->setPixmap(image0);
56 GroupC1 = new MeasureGUI_1Sel3LineEdit_QTD(this, "GroupC1");
57 GroupC1->GroupBox1->setTitle(tr("GEOM_PROPERTIES_CONSTR"));
58 GroupC1->TextLabel1->setText(tr("GEOM_OBJECT"));
59 GroupC1->TextLabel2->setText(tr("GEOM_LENGTH"));
60 GroupC1->TextLabel3->setText(tr("GEOM_PROPERTIES_SURFACE"));
61 GroupC1->TextLabel4->setText(tr("GEOM_PROPERTIES_VOLUME"));
62 GroupC1->LineEdit2->setReadOnly(TRUE);
63 GroupC1->LineEdit3->setReadOnly(TRUE);
64 GroupC1->LineEdit4->setReadOnly(TRUE);
65 GroupC1->PushButton1->setPixmap(image1);
67 Layout1->addWidget(GroupC1, 1, 0);
68 /***************************************************************/
75 //=================================================================================
76 // function : ~MeasureGUI_PropertiesDlg()
77 // purpose : Destroys the object and frees any allocated resources
78 //=================================================================================
79 MeasureGUI_PropertiesDlg::~MeasureGUI_PropertiesDlg()
81 // no need to delete child widgets, Qt does it all for us
85 //=================================================================================
88 //=================================================================================
89 void MeasureGUI_PropertiesDlg::Init()
92 myEditCurrentArgument = GroupC1->LineEdit1;
94 /* signals and slots connections */
95 connect(GroupC1->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
96 connect(GroupC1->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
98 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
100 /* displays Dialog */
108 //=================================================================================
109 // function : SelectionIntoArgument()
110 // purpose : Called when selection as changed or other case
111 //=================================================================================
112 void MeasureGUI_PropertiesDlg::SelectionIntoArgument()
114 myGeomBase->EraseSimulationShape();
115 mySimulationTopoDs.Nullify();
116 myEditCurrentArgument->setText("");
117 QString aString = "";
119 GroupC1->LineEdit2->setText("");
120 GroupC1->LineEdit3->setText("");
121 GroupC1->LineEdit4->setText("");
123 int nbSel = myGeomBase->GetNameOfSelectedIObjects(mySelection, aString);
129 if(!myGeomBase->GetTopoFromSelection(mySelection, S))
133 if(S.IsNull() || S.ShapeType() == TopAbs_VERTEX)
136 GroupC1->LineEdit1->setText(aString);
138 /* Try to display of a cone simulation shape to show direction of a linear edge only in OCC viewer */
139 if(myGeomBase->CreateArrowForLinearEdge(S, mySimulationTopoDs))
140 myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
142 this->CalculateAndDisplayProperties(S);
147 //=================================================================================
148 // function : SetEditCurrentArgument()
150 //=================================================================================
151 void MeasureGUI_PropertiesDlg::SetEditCurrentArgument()
153 QPushButton* send = (QPushButton*)sender();
155 if(send == GroupC1->PushButton1) {
156 GroupC1->LineEdit1->setFocus();
157 myEditCurrentArgument = GroupC1->LineEdit1;
160 this->SelectionIntoArgument();
165 //=================================================================================
166 // function : LineEditReturnPressed()
168 //=================================================================================
169 void MeasureGUI_PropertiesDlg::LineEditReturnPressed()
171 QLineEdit* send = (QLineEdit*)sender();
172 if(send == GroupC1->LineEdit1)
173 myEditCurrentArgument = GroupC1->LineEdit1;
177 MeasureGUI_Skeleton::LineEditReturnPressed();
182 //=================================================================================
183 // function : ActivateThisDialog()
185 //=================================================================================
186 void MeasureGUI_PropertiesDlg::ActivateThisDialog()
188 MeasureGUI_Skeleton::ActivateThisDialog();
189 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
190 if(!mySimulationTopoDs.IsNull())
191 myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
196 //=================================================================================
197 // function : enterEvent()
199 //=================================================================================
200 void MeasureGUI_PropertiesDlg::enterEvent(QEvent* e)
202 if(GroupConstructors->isEnabled())
204 this->ActivateThisDialog();
209 //=================================================================================
210 // function : CalculateAndDisplayProperties()
212 //=================================================================================
213 void MeasureGUI_PropertiesDlg::CalculateAndDisplayProperties(const TopoDS_Shape& S)
215 GroupC1->LineEdit2->setText("");
216 GroupC1->LineEdit3->setText("");
217 GroupC1->LineEdit4->setText("");
222 Standard_Real result;
223 GProp_GProps LProps, SProps;
227 BRepGProp::LinearProperties(S,LProps);
228 result = LProps.Mass();
229 if(!IsEqual(result, 0.0)) {
230 resString = tr("%1").arg(result, 12, 'f', 6);
231 GroupC1->LineEdit2->setText(resString);
234 BRepGProp::SurfaceProperties(S, SProps);
235 result = SProps.Mass();
236 if(!IsEqual(result, 0.0)) {
237 resString = tr("%1").arg(result, 12, 'f', 6);
238 GroupC1->LineEdit3->setText(resString);
242 if(S.ShapeType() < TopAbs_SHELL) {
243 for(TopExp_Explorer Exp(S,TopAbs_SOLID); Exp.More(); Exp.Next()) {
245 BRepGProp::VolumeProperties(Exp.Current(), VProps);
246 result += VProps.Mass();
249 if (!IsEqual(result, 0.0)) {
250 resString = tr("%1").arg(result, 12, 'f', 6);
251 GroupC1->LineEdit4->setText(resString);
254 catch(Standard_Failure) {
255 MESSAGE("Catch intercepted in CalculateAndDisplayProperties()");