Salome HOME
DCQ : Merge with Ecole_Ete_a6.
[modules/geom.git] / src / MeasureGUI / MeasureGUI_PropertiesDlg.cxx
1 //  GEOM GEOMGUI : GUI for Geometry component
2 //
3 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
5 // 
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. 
10 // 
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. 
15 // 
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 
19 // 
20 //  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //
24 //  File   : MeasureGUI_PropertiesDlg.cxx
25 //  Author : Lucien PIGNOLONI
26 //  Module : GEOM
27 //  $Header$
28
29 #include "MeasureGUI_PropertiesDlg.h"
30
31 #include <TopExp_Explorer.hxx>
32 #include <BRepGProp.hxx>
33 #include <GProp_GProps.hxx>
34 #include <GProp_PrincipalProps.hxx>
35
36 #include "utilities.h"
37
38 using namespace std;
39
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)
49 {
50   QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_BASICPROPERTIES")));
51   QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_SELECT")));
52
53   setCaption(tr("GEOM_PROPERTIES_TITLE"));
54
55   /***************************************************************/
56   GroupConstructors->setTitle(tr("GEOM_PROPERTIES"));
57   RadioButton1->setPixmap(image0);
58
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);
69
70   Layout1->addWidget(GroupC1, 1, 0);
71   /***************************************************************/
72
73   /* Initialisation */
74   Init();
75 }
76
77
78 //=================================================================================
79 // function : ~MeasureGUI_PropertiesDlg()
80 // purpose  : Destroys the object and frees any allocated resources
81 //=================================================================================
82 MeasureGUI_PropertiesDlg::~MeasureGUI_PropertiesDlg()
83 {
84   // no need to delete child widgets, Qt does it all for us
85 }
86
87
88 //=================================================================================
89 // function : Init()
90 // purpose  :
91 //=================================================================================
92 void MeasureGUI_PropertiesDlg::Init()
93 {
94   /* init variables */
95   myEditCurrentArgument = GroupC1->LineEdit1;
96
97    /* signals and slots connections */
98   connect(GroupC1->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
99   connect(GroupC1->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
100
101   connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
102
103   /* displays Dialog */
104   GroupC1->show();
105   this->show();
106
107   return;
108 }
109
110
111 //=================================================================================
112 // function : SelectionIntoArgument()
113 // purpose  : Called when selection as changed or other case
114 //=================================================================================
115 void MeasureGUI_PropertiesDlg::SelectionIntoArgument()
116 {
117   myGeomBase->EraseSimulationShape();
118   mySimulationTopoDs.Nullify();
119   myEditCurrentArgument->setText("");
120   QString aString = "";
121
122   GroupC1->LineEdit2->setText("");
123   GroupC1->LineEdit3->setText("");
124   GroupC1->LineEdit4->setText("");
125
126   int nbSel = myGeomBase->GetNameOfSelectedIObjects(mySelection, aString);
127   if(nbSel != 1)
128     return;
129
130   /*  nbSel == 1  */
131   TopoDS_Shape S;
132   if(!myGeomBase->GetTopoFromSelection(mySelection, S))
133     return;
134
135   
136   if(S.IsNull() || S.ShapeType() == TopAbs_VERTEX)
137     return;
138  
139   GroupC1->LineEdit1->setText(aString);
140
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);
144
145   this->CalculateAndDisplayProperties(S);
146   return;
147 }
148
149
150 //=================================================================================
151 // function : SetEditCurrentArgument()
152 // purpose  :
153 //=================================================================================
154 void MeasureGUI_PropertiesDlg::SetEditCurrentArgument()
155 {
156   QPushButton* send = (QPushButton*)sender();
157
158   if(send == GroupC1->PushButton1) {
159     GroupC1->LineEdit1->setFocus();
160     myEditCurrentArgument = GroupC1->LineEdit1;
161   }
162
163   this->SelectionIntoArgument();
164   return;
165 }
166
167
168 //=================================================================================
169 // function : LineEditReturnPressed()
170 // purpose  :
171 //=================================================================================
172 void MeasureGUI_PropertiesDlg::LineEditReturnPressed()
173 {
174   QLineEdit* send = (QLineEdit*)sender();
175   if(send == GroupC1->LineEdit1)
176     myEditCurrentArgument = GroupC1->LineEdit1;
177   else
178     return;
179
180   MeasureGUI_Skeleton::LineEditReturnPressed();
181   return;
182 }
183
184
185 //=================================================================================
186 // function : ActivateThisDialog()
187 // purpose  :
188 //=================================================================================
189 void MeasureGUI_PropertiesDlg::ActivateThisDialog()
190 {
191   MeasureGUI_Skeleton::ActivateThisDialog();
192   connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
193   if(!mySimulationTopoDs.IsNull())
194     myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
195   return;
196 }
197
198
199 //=================================================================================
200 // function : enterEvent()
201 // purpose  :
202 //=================================================================================
203 void MeasureGUI_PropertiesDlg::enterEvent(QEvent* e)
204 {
205   if(GroupConstructors->isEnabled())
206     return;
207   this->ActivateThisDialog();
208   return;
209 }
210
211
212 //=================================================================================
213 // function : CalculateAndDisplayProperties()
214 // purpose  :
215 //=================================================================================
216 void MeasureGUI_PropertiesDlg::CalculateAndDisplayProperties(const TopoDS_Shape& S)
217 {
218   GroupC1->LineEdit2->setText("");
219   GroupC1->LineEdit3->setText("");
220   GroupC1->LineEdit4->setText("");
221
222   if(S.IsNull()) 
223     return;
224
225   Standard_Real result;
226   GProp_GProps LProps, SProps;
227   QString resString;
228
229   try {
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);
235     }
236
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);
242     }
243         
244     result = 0.0;
245     if(S.ShapeType() < TopAbs_SHELL) {
246       for(TopExp_Explorer Exp(S,TopAbs_SOLID); Exp.More(); Exp.Next()) { 
247         GProp_GProps VProps;
248         BRepGProp::VolumeProperties(Exp.Current(), VProps);
249         result += VProps.Mass();
250       }
251     }
252     if (!IsEqual(result, 0.0)) {        
253       resString = tr("%1").arg(result, 12, 'f', 6);
254       GroupC1->LineEdit4->setText(resString);
255     }
256   }
257   catch(Standard_Failure) {
258     MESSAGE("Catch intercepted in CalculateAndDisplayProperties()");
259   }
260   return;
261 }