]> SALOME platform Git repositories - modules/geom.git/blob - src/MeasureGUI/MeasureGUI_PropertiesDlg.cxx
Salome HOME
DCQ : New Architecture
[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 using namespace std;
30 #include "MeasureGUI_PropertiesDlg.h"
31
32 #include <TopExp_Explorer.hxx>
33 #include <BRepGProp.hxx>
34 #include <GProp_GProps.hxx>
35 #include <GProp_PrincipalProps.hxx>
36
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)
46 {
47   QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_BASICPROPERTIES")));
48   QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_SELECT")));
49
50   setCaption(tr("GEOM_PROPERTIES_TITLE"));
51
52   /***************************************************************/
53   GroupConstructors->setTitle(tr("GEOM_PROPERTIES"));
54   RadioButton1->setPixmap(image0);
55
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);
66
67   Layout1->addWidget(GroupC1, 1, 0);
68   /***************************************************************/
69
70   /* Initialisation */
71   Init();
72 }
73
74
75 //=================================================================================
76 // function : ~MeasureGUI_PropertiesDlg()
77 // purpose  : Destroys the object and frees any allocated resources
78 //=================================================================================
79 MeasureGUI_PropertiesDlg::~MeasureGUI_PropertiesDlg()
80 {
81   // no need to delete child widgets, Qt does it all for us
82 }
83
84
85 //=================================================================================
86 // function : Init()
87 // purpose  :
88 //=================================================================================
89 void MeasureGUI_PropertiesDlg::Init()
90 {
91   /* init variables */
92   myEditCurrentArgument = GroupC1->LineEdit1;
93
94    /* signals and slots connections */
95   connect(GroupC1->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
96   connect(GroupC1->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
97
98   connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
99
100   /* displays Dialog */
101   GroupC1->show();
102   this->show();
103
104   return;
105 }
106
107
108 //=================================================================================
109 // function : SelectionIntoArgument()
110 // purpose  : Called when selection as changed or other case
111 //=================================================================================
112 void MeasureGUI_PropertiesDlg::SelectionIntoArgument()
113 {
114   myGeomBase->EraseSimulationShape();
115   mySimulationTopoDs.Nullify();
116   myEditCurrentArgument->setText("");
117   QString aString = "";
118
119   GroupC1->LineEdit2->setText("");
120   GroupC1->LineEdit3->setText("");
121   GroupC1->LineEdit4->setText("");
122
123   int nbSel = myGeomBase->GetNameOfSelectedIObjects(mySelection, aString);
124   if(nbSel != 1)
125     return;
126
127   /*  nbSel == 1  */
128   TopoDS_Shape S;
129   if(!myGeomBase->GetTopoFromSelection(mySelection, S))
130     return;
131
132   
133   if(S.IsNull() || S.ShapeType() == TopAbs_VERTEX)
134     return;
135  
136   GroupC1->LineEdit1->setText(aString);
137
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);
141
142   this->CalculateAndDisplayProperties(S);
143   return;
144 }
145
146
147 //=================================================================================
148 // function : SetEditCurrentArgument()
149 // purpose  :
150 //=================================================================================
151 void MeasureGUI_PropertiesDlg::SetEditCurrentArgument()
152 {
153   QPushButton* send = (QPushButton*)sender();
154
155   if(send == GroupC1->PushButton1) {
156     GroupC1->LineEdit1->setFocus();
157     myEditCurrentArgument = GroupC1->LineEdit1;
158   }
159
160   this->SelectionIntoArgument();
161   return;
162 }
163
164
165 //=================================================================================
166 // function : LineEditReturnPressed()
167 // purpose  :
168 //=================================================================================
169 void MeasureGUI_PropertiesDlg::LineEditReturnPressed()
170 {
171   QLineEdit* send = (QLineEdit*)sender();
172   if(send == GroupC1->LineEdit1)
173     myEditCurrentArgument = GroupC1->LineEdit1;
174   else
175     return;
176
177   MeasureGUI_Skeleton::LineEditReturnPressed();
178   return;
179 }
180
181
182 //=================================================================================
183 // function : ActivateThisDialog()
184 // purpose  :
185 //=================================================================================
186 void MeasureGUI_PropertiesDlg::ActivateThisDialog()
187 {
188   MeasureGUI_Skeleton::ActivateThisDialog();
189   connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
190   if(!mySimulationTopoDs.IsNull())
191     myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
192   return;
193 }
194
195
196 //=================================================================================
197 // function : enterEvent()
198 // purpose  :
199 //=================================================================================
200 void MeasureGUI_PropertiesDlg::enterEvent(QEvent* e)
201 {
202   if(GroupConstructors->isEnabled())
203     return;
204   this->ActivateThisDialog();
205   return;
206 }
207
208
209 //=================================================================================
210 // function : CalculateAndDisplayProperties()
211 // purpose  :
212 //=================================================================================
213 void MeasureGUI_PropertiesDlg::CalculateAndDisplayProperties(const TopoDS_Shape& S)
214 {
215   GroupC1->LineEdit2->setText("");
216   GroupC1->LineEdit3->setText("");
217   GroupC1->LineEdit4->setText("");
218
219   if(S.IsNull()) 
220     return;
221
222   Standard_Real result;
223   GProp_GProps LProps, SProps;
224   QString resString;
225
226   try {
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);
232     }
233
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);
239     }
240         
241     result = 0.0;
242     if(S.ShapeType() < TopAbs_SHELL) {
243       for(TopExp_Explorer Exp(S,TopAbs_SOLID); Exp.More(); Exp.Next()) { 
244         GProp_GProps VProps;
245         BRepGProp::VolumeProperties(Exp.Current(), VProps);
246         result += VProps.Mass();
247       }
248     }
249     if (!IsEqual(result, 0.0)) {        
250       resString = tr("%1").arg(result, 12, 'f', 6);
251       GroupC1->LineEdit4->setText(resString);
252     }
253   }
254   catch(Standard_Failure) {
255     MESSAGE("Catch intercepted in CalculateAndDisplayProperties()");
256   }
257   return;
258 }