Salome HOME
Update copyright
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_MeshInfo.cxx
1 // Copyright (C) 2007-2011  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  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.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 //  File   : SMESHGUI_MeshInfo.cxx
23 //  Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com)
24
25 #include "SMESHGUI_MeshInfo.h"
26
27 #include "SMESH_Actor.h"
28 #include "SMESHGUI.h"
29 #include "SMESHGUI_IdValidator.h"
30 #include "SMESHGUI_Utils.h"
31 #include "SMESHGUI_VTKUtils.h"
32 #include "SMDSAbs_ElementType.hxx"
33 #include "SMDS_Mesh.hxx"
34
35 #include <LightApp_SelectionMgr.h>
36 #include <SUIT_OverrideCursor.h>
37 #include <SUIT_ResourceMgr.h>
38 #include <SVTK_ViewWindow.h>
39
40 #include <SALOMEDSClient_Study.hxx>
41
42 #include <QApplication>
43 #include <QButtonGroup>
44 #include <QGridLayout>
45 #include <QHBoxLayout>
46 #include <QHeaderView>
47 #include <QItemDelegate>
48 #include <QKeyEvent>
49 #include <QLabel>
50 #include <QLineEdit>
51 #include <QPushButton>
52 #include <QRadioButton>
53 #include <QTabWidget>
54 #include <QTextBrowser>
55 #include <QTreeWidget>
56 #include <QVBoxLayout>
57
58 #include "utilities.h"
59
60 #include <SALOMEconfig.h>
61 #include CORBA_SERVER_HEADER(SMESH_Group)
62
63 const int SPACING  = 6;
64 const int MARGIN   = 9;
65 const int MAXITEMS = 10;
66
67 /*!
68   \class SMESHGUI_MeshInfo
69   \brief Base mesh information widget
70   
71   Displays the base information about mesh object: mesh, sub-mesh, group or arbitrary ID source.
72 */
73
74 /*!
75   \brief Constructor.
76   \param parent parent widget
77 */
78 SMESHGUI_MeshInfo::SMESHGUI_MeshInfo( QWidget* parent )
79   : QFrame( parent ), myWidgets( iElementsEnd )
80 {
81   setFrameStyle( StyledPanel | Sunken );
82
83   QGridLayout* l = new QGridLayout( this );
84   l->setMargin( MARGIN );
85   l->setSpacing( SPACING );
86
87   // object
88   QLabel* aNameLab     = new QLabel( tr( "NAME_LAB" ), this );
89   QLabel* aName        = createField();
90   aName->setMinimumWidth( 150 );
91   QLabel* aObjLab      = new QLabel( tr( "OBJECT_LAB" ), this );
92   QLabel* aObj         = createField();
93   aObj->setMinimumWidth( 150 );
94   myWidgets[0] << aNameLab << aName;
95   myWidgets[1] << aObjLab  << aObj;
96
97   // nodes
98   QWidget* aNodesLine  = createLine();
99   QLabel*  aNodesLab   = new QLabel( tr( "NODES_LAB" ), this );
100   QLabel*  aNodes      = createField();
101   myWidgets[2] << aNodesLine;
102   myWidgets[3] << aNodesLab << aNodes;
103
104   // elements
105   QWidget* aElemLine   = createLine();
106   QLabel*  aElemLab    = new QLabel( tr( "ELEMENTS_LAB" ),  this );
107   QLabel*  aElemTotal  = new QLabel( tr( "TOTAL_LAB" ),     this );
108   QLabel*  aElemLin    = new QLabel( tr( "LINEAR_LAB" ),    this );
109   QLabel*  aElemQuad   = new QLabel( tr( "QUADRATIC_LAB" ), this );
110   myWidgets[4] << aElemLine;
111   myWidgets[5] << aElemLab << aElemTotal << aElemLin << aElemQuad;
112
113   // ... 0D elements
114   QWidget* a0DLine     = createLine();
115   QLabel*  a0DLab      = new QLabel( tr( "0D_LAB" ), this );
116   QLabel*  a0DTotal    = createField();
117   myWidgets[6] << a0DLine;
118   myWidgets[7] << a0DLab << a0DTotal;
119
120   // ... 1D elements
121   QWidget* a1DLine     = createLine();
122   QLabel*  a1DLab      = new QLabel( tr( "1D_LAB" ), this );
123   QLabel*  a1DTotal    = createField();
124   QLabel*  a1DLin      = createField();
125   QLabel*  a1DQuad     = createField();
126   myWidgets[8] << a1DLine;
127   myWidgets[9] << a1DLab << a1DTotal << a1DLin << a1DQuad;
128
129   // ... 2D elements
130   QWidget* a2DLine     = createLine();
131   QLabel*  a2DLab      = new QLabel( tr( "2D_LAB" ), this );
132   QLabel*  a2DTotal    = createField();
133   QLabel*  a2DLin      = createField();
134   QLabel*  a2DQuad     = createField();
135   QLabel*  a2DTriLab   = new QLabel( tr( "TRIANGLES_LAB" ), this );
136   QLabel*  a2DTriTotal = createField();
137   QLabel*  a2DTriLin   = createField();
138   QLabel*  a2DTriQuad  = createField();
139   QLabel*  a2DQuaLab   = new QLabel( tr( "QUADRANGLES_LAB" ), this );
140   QLabel*  a2DQuaTotal = createField();
141   QLabel*  a2DQuaLin   = createField();
142   QLabel*  a2DQuaQuad  = createField();
143   QLabel*  a2DPolLab   = new QLabel( tr( "POLYGONS_LAB" ), this );
144   QLabel*  a2DPolTotal = createField();
145   myWidgets[10] << a2DLine;
146   myWidgets[11] << a2DLab    << a2DTotal    << a2DLin    << a2DQuad;
147   myWidgets[12] << a2DTriLab << a2DTriTotal << a2DTriLin << a2DTriQuad;
148   myWidgets[13] << a2DQuaLab << a2DQuaTotal << a2DQuaLin << a2DQuaQuad;
149   myWidgets[14] << a2DPolLab << a2DPolTotal;
150
151   // ... 3D elements
152   QWidget* a3DLine     = createLine();
153   QLabel*  a3DLab      = new QLabel( tr( "3D_LAB" ), this );
154   QLabel*  a3DTotal    = createField();
155   QLabel*  a3DLin      = createField();
156   QLabel*  a3DQuad     = createField();
157   QLabel*  a3DTetLab   = new QLabel( tr( "TETRAHEDRONS_LAB" ), this );
158   QLabel*  a3DTetTotal = createField();
159   QLabel*  a3DTetLin   = createField();
160   QLabel*  a3DTetQuad  = createField();
161   QLabel*  a3DHexLab   = new QLabel( tr( "HEXAHEDONRS_LAB" ), this );
162   QLabel*  a3DHexTotal = createField();
163   QLabel*  a3DHexLin   = createField();
164   QLabel*  a3DHexQuad  = createField();
165   QLabel*  a3DPyrLab   = new QLabel( tr( "PYRAMIDS_LAB" ), this );
166   QLabel*  a3DPyrTotal = createField();
167   QLabel*  a3DPyrLin   = createField();
168   QLabel*  a3DPyrQuad  = createField();
169   QLabel*  a3DPriLab   = new QLabel( tr( "PRISMS_LAB" ), this );
170   QLabel*  a3DPriTotal = createField();
171   QLabel*  a3DPriLin   = createField();
172   QLabel*  a3DPriQuad  = createField();
173   QLabel*  a3DPolLab   = new QLabel( tr( "POLYHEDRONS_LAB" ), this );
174   QLabel*  a3DPolTotal = createField();
175   myWidgets[15] << a3DLine;
176   myWidgets[16] << a3DLab    << a3DTotal    << a3DLin    << a3DQuad;
177   myWidgets[17] << a3DTetLab << a3DTetTotal << a3DTetLin << a3DTetQuad;
178   myWidgets[18] << a3DHexLab << a3DHexTotal << a3DHexLin << a3DHexQuad;
179   myWidgets[19] << a3DPyrLab << a3DPyrTotal << a3DPyrLin << a3DPyrQuad;
180   myWidgets[20] << a3DPriLab << a3DPriTotal << a3DPriLin << a3DPriQuad;
181   myWidgets[21] << a3DPolLab << a3DPolTotal;
182
183   setFontAttributes( aNameLab,   Bold );
184   setFontAttributes( aObjLab,    Bold );
185   setFontAttributes( aNodesLab,  Bold );
186   setFontAttributes( aElemLab,   Bold );
187   setFontAttributes( aElemTotal, Italic );
188   setFontAttributes( aElemLin,   Italic );
189   setFontAttributes( aElemQuad,  Italic );
190   setFontAttributes( a0DLab,     Bold );
191   setFontAttributes( a1DLab,     Bold );
192   setFontAttributes( a2DLab,     Bold );
193   setFontAttributes( a3DLab,     Bold );
194
195   l->addWidget( aNameLab,     0, 0 );
196   l->addWidget( aName,        0, 1, 1, 3 );
197   l->addWidget( aObjLab,      1, 0 );
198   l->addWidget( aObj,         1, 1, 1, 3 );
199   l->addWidget( aNodesLine,   2, 0, 1, 4 );
200   l->addWidget( aNodesLab,    3, 0 );
201   l->addWidget( aNodes,       3, 1 );
202   l->addWidget( aElemLine,    4, 0, 1, 4 );
203   l->addWidget( aElemLab,     5, 0 );
204   l->addWidget( aElemTotal,   5, 1 );
205   l->addWidget( aElemLin,     5, 2 );
206   l->addWidget( aElemQuad,    5, 3 );
207   l->addWidget( a0DLine,      6, 1, 1, 3 );
208   l->addWidget( a0DLab,       7, 0 );
209   l->addWidget( a0DTotal,     7, 1 );
210   l->addWidget( a1DLine,      8, 1, 1, 3 );
211   l->addWidget( a1DLab,       9, 0 );
212   l->addWidget( a1DTotal,     9, 1 );
213   l->addWidget( a1DLin,       9, 2 );
214   l->addWidget( a1DQuad,      9, 3 );
215   l->addWidget( a2DLine,     10, 1, 1, 3 );
216   l->addWidget( a2DLab,      11, 0 );
217   l->addWidget( a2DTotal,    11, 1 );
218   l->addWidget( a2DLin,      11, 2 );
219   l->addWidget( a2DQuad,     11, 3 );
220   l->addWidget( a2DTriLab,   12, 0 );
221   l->addWidget( a2DTriTotal, 12, 1 );
222   l->addWidget( a2DTriLin,   12, 2 );
223   l->addWidget( a2DTriQuad,  12, 3 );
224   l->addWidget( a2DQuaLab,   13, 0 );
225   l->addWidget( a2DQuaTotal, 13, 1 );
226   l->addWidget( a2DQuaLin,   13, 2 );
227   l->addWidget( a2DQuaQuad,  13, 3 );
228   l->addWidget( a2DPolLab,   14, 0 );
229   l->addWidget( a2DPolTotal, 14, 1 );
230   l->addWidget( a3DLine,     15, 1, 1, 3 );
231   l->addWidget( a3DLab,      16, 0 );
232   l->addWidget( a3DTotal,    16, 1 );
233   l->addWidget( a3DLin,      16, 2 );
234   l->addWidget( a3DQuad,     16, 3 );
235   l->addWidget( a3DTetLab,   17, 0 );
236   l->addWidget( a3DTetTotal, 17, 1 );
237   l->addWidget( a3DTetLin,   17, 2 );
238   l->addWidget( a3DTetQuad,  17, 3 );
239   l->addWidget( a3DHexLab,   18, 0 );
240   l->addWidget( a3DHexTotal, 18, 1 );
241   l->addWidget( a3DHexLin,   18, 2 );
242   l->addWidget( a3DHexQuad,  18, 3 );
243   l->addWidget( a3DPyrLab,   19, 0 );
244   l->addWidget( a3DPyrTotal, 19, 1 );
245   l->addWidget( a3DPyrLin,   19, 2 );
246   l->addWidget( a3DPyrQuad,  19, 3 );
247   l->addWidget( a3DPriLab,   20, 0 );
248   l->addWidget( a3DPriTotal, 20, 1 );
249   l->addWidget( a3DPriLin,   20, 2 );
250   l->addWidget( a3DPriQuad,  20, 3 );
251   l->addWidget( a3DPolLab,   21, 0 );
252   l->addWidget( a3DPolTotal, 21, 1 );
253   l->setColumnStretch( 0, 0 );
254   l->setColumnStretch( 1, 5 );
255   l->setColumnStretch( 2, 5 );
256   l->setColumnStretch( 3, 5 );
257   l->setRowStretch( 22, 5 );
258
259   clear();
260 }
261
262 /*!
263   \brief Destructor
264 */
265 SMESHGUI_MeshInfo::~SMESHGUI_MeshInfo()
266 {
267 }
268
269 /*!
270   \brief Show information on the mesh object.
271   \param obj object being processed (mesh, sub-mesh, group, ID source)
272 */
273 void SMESHGUI_MeshInfo::showInfo( SMESH::SMESH_IDSource_ptr obj )
274 {
275   clear();
276   if ( !CORBA::is_nil( obj ) ) {
277     _PTR(SObject) sobj = ObjectToSObject( obj );
278     if ( sobj ) 
279       myWidgets[iName][iSingle]->setProperty( "text", sobj->GetName().c_str() );
280     SMESH::SMESH_Mesh_var      aMesh    = SMESH::SMESH_Mesh::_narrow( obj );
281     SMESH::SMESH_subMesh_var   aSubMesh = SMESH::SMESH_subMesh::_narrow( obj );
282     SMESH::SMESH_GroupBase_var aGroup   = SMESH::SMESH_GroupBase::_narrow( obj );
283     if ( !aMesh->_is_nil() ) {
284       myWidgets[iObject][iSingle]->setProperty( "text", tr( "OBJECT_MESH" ) );
285     }
286     else if ( !aSubMesh->_is_nil() ) {
287       myWidgets[iObject][iSingle]->setProperty( "text", tr( "OBJECT_SUBMESH" ) );
288     }
289     else if ( !aGroup->_is_nil() ) {
290       QString objType;
291       switch( aGroup->GetType() ) {
292       case SMESH::NODE:
293         objType = tr( "OBJECT_GROUP_NODES" );
294         break;
295       case SMESH::EDGE:
296         objType = tr( "OBJECT_GROUP_EDGES" );
297         break;
298       case SMESH::FACE:
299         objType = tr( "OBJECT_GROUP_FACES" );
300         break;
301       case SMESH::VOLUME:
302         objType = tr( "OBJECT_GROUP_VOLUMES" );
303         break;
304       case SMESH::ELEM0D:
305         objType = tr( "OBJECT_GROUP_0DELEMS" );
306         break;
307       default:
308         objType = tr( "OBJECT_GROUP" );
309         break;
310       }
311       myWidgets[iObject][iSingle]->setProperty( "text", objType );
312     }
313     SMESH::long_array_var info = obj->GetMeshInfo();
314     myWidgets[iNodes][iTotal]->setProperty( "text", QString::number( info[SMDSEntity_Node] ) );
315     myWidgets[i0D][iTotal]->setProperty( "text", QString::number( info[SMDSEntity_0D] ) );
316     long nbEdges = info[SMDSEntity_Edge] + info[SMDSEntity_Quad_Edge];
317     myWidgets[i1D][iTotal]->setProperty( "text", QString::number( nbEdges ) );
318     myWidgets[i1D][iLinear]->setProperty( "text", QString::number( info[SMDSEntity_Edge] ) );
319     myWidgets[i1D][iQuadratic]->setProperty( "text", QString::number( info[SMDSEntity_Quad_Edge] ) );
320     long nbTriangles   = info[SMDSEntity_Triangle]   + info[SMDSEntity_Quad_Triangle];
321     long nbQuadrangles = info[SMDSEntity_Quadrangle] + info[SMDSEntity_Quad_Quadrangle];
322     long nb2DLinear    = info[SMDSEntity_Triangle] + info[SMDSEntity_Quadrangle] + info[SMDSEntity_Polygon];
323     long nb2DQuadratic = info[SMDSEntity_Quad_Triangle] + info[SMDSEntity_Quad_Quadrangle];
324     myWidgets[i2D][iTotal]->setProperty( "text", QString::number( nb2DLinear + nb2DQuadratic ) );
325     myWidgets[i2D][iLinear]->setProperty( "text", QString::number( nb2DLinear ) );
326     myWidgets[i2D][iQuadratic]->setProperty( "text", QString::number( nb2DQuadratic ) );
327     myWidgets[i2DTriangles][iTotal]->setProperty( "text", QString::number( nbTriangles ) );
328     myWidgets[i2DTriangles][iLinear]->setProperty( "text", QString::number( info[SMDSEntity_Triangle] ) );
329     myWidgets[i2DTriangles][iQuadratic]->setProperty( "text", QString::number( info[SMDSEntity_Quad_Triangle] ) );
330     myWidgets[i2DQuadrangles][iTotal]->setProperty( "text", QString::number( nbQuadrangles ) );
331     myWidgets[i2DQuadrangles][iLinear]->setProperty( "text", QString::number( info[SMDSEntity_Quadrangle] ) );
332     myWidgets[i2DQuadrangles][iQuadratic]->setProperty( "text", QString::number( info[SMDSEntity_Quad_Quadrangle] ) );
333     myWidgets[i2DPolygons][iTotal]->setProperty( "text", QString::number( info[SMDSEntity_Polygon] ) );
334     long nbTetrahedrons = info[SMDSEntity_Tetra]   + info[SMDSEntity_Quad_Tetra];
335     long nbHexahedrons  = info[SMDSEntity_Hexa]    + info[SMDSEntity_Quad_Hexa];
336     long nbPyramids     = info[SMDSEntity_Pyramid] + info[SMDSEntity_Quad_Pyramid];
337     long nbPrisms       = info[SMDSEntity_Penta]   + info[SMDSEntity_Quad_Penta];
338     long nb3DLinear     = info[SMDSEntity_Tetra] + info[SMDSEntity_Hexa] + info[SMDSEntity_Pyramid] + info[SMDSEntity_Penta] + info[SMDSEntity_Polyhedra];
339     long nb3DQuadratic  = info[SMDSEntity_Quad_Tetra] + info[SMDSEntity_Quad_Hexa] + info[SMDSEntity_Quad_Pyramid] + info[SMDSEntity_Quad_Penta];
340     myWidgets[i3D][iTotal]->setProperty( "text", QString::number( nb3DLinear + nb3DQuadratic ) );
341     myWidgets[i3D][iLinear]->setProperty( "text", QString::number( nb3DLinear ) );
342     myWidgets[i3D][iQuadratic]->setProperty( "text", QString::number( nb3DQuadratic ) );
343     myWidgets[i3DTetrahedrons][iTotal]->setProperty( "text", QString::number( nbTetrahedrons ) );
344     myWidgets[i3DTetrahedrons][iLinear]->setProperty( "text", QString::number( info[SMDSEntity_Tetra] ) );
345     myWidgets[i3DTetrahedrons][iQuadratic]->setProperty( "text", QString::number( info[SMDSEntity_Quad_Tetra] ) );
346     myWidgets[i3DHexahedrons][iTotal]->setProperty( "text", QString::number( nbHexahedrons ) );
347     myWidgets[i3DHexahedrons][iLinear]->setProperty( "text", QString::number( info[SMDSEntity_Hexa] ) );
348     myWidgets[i3DHexahedrons][iQuadratic]->setProperty( "text", QString::number( info[SMDSEntity_Quad_Hexa] ) );
349     myWidgets[i3DPyramids][iTotal]->setProperty( "text", QString::number( nbPyramids ) );
350     myWidgets[i3DPyramids][iLinear]->setProperty( "text", QString::number( info[SMDSEntity_Pyramid] ) );
351     myWidgets[i3DPyramids][iQuadratic]->setProperty( "text", QString::number( info[SMDSEntity_Quad_Pyramid] ) );
352     myWidgets[i3DPrisms][iTotal]->setProperty( "text", QString::number( nbPrisms ) );
353     myWidgets[i3DPrisms][iLinear]->setProperty( "text", QString::number( info[SMDSEntity_Penta] ) );
354     myWidgets[i3DPrisms][iQuadratic]->setProperty( "text", QString::number( info[SMDSEntity_Quad_Penta] ) );
355     myWidgets[i3DPolyhedrons][iTotal]->setProperty( "text", QString::number( info[SMDSEntity_Polyhedra] ) );
356   }
357 }
358
359 /*!
360   \brief Reset the widget to the initial state (nullify all fields).
361 */
362 void SMESHGUI_MeshInfo::clear()
363 {
364   myWidgets[iName][iSingle]->setProperty( "text", QString() );
365   myWidgets[iObject][iSingle]->setProperty( "text", QString() );
366   myWidgets[iNodes][iTotal]->setProperty( "text", QString::number( 0 ) );
367   myWidgets[i0D][iTotal]->setProperty( "text", QString::number( 0 ) );
368   myWidgets[i1D][iTotal]->setProperty( "text", QString::number( 0 ) );
369   myWidgets[i1D][iLinear]->setProperty( "text", QString::number( 0 ) );
370   myWidgets[i1D][iQuadratic]->setProperty( "text", QString::number( 0 ) );
371   myWidgets[i2D][iTotal]->setProperty( "text", QString::number( 0 ) );
372   myWidgets[i2D][iLinear]->setProperty( "text", QString::number( 0 ) );
373   myWidgets[i2D][iQuadratic]->setProperty( "text", QString::number( 0 ) );
374   myWidgets[i2DTriangles][iTotal]->setProperty( "text", QString::number( 0 ) );
375   myWidgets[i2DTriangles][iLinear]->setProperty( "text", QString::number( 0 ) );
376   myWidgets[i2DTriangles][iQuadratic]->setProperty( "text", QString::number( 0 ) );
377   myWidgets[i2DQuadrangles][iTotal]->setProperty( "text", QString::number( 0 ) );
378   myWidgets[i2DQuadrangles][iLinear]->setProperty( "text", QString::number( 0 ) );
379   myWidgets[i2DQuadrangles][iQuadratic]->setProperty( "text", QString::number( 0 ) );
380   myWidgets[i2DPolygons][iTotal]->setProperty( "text", QString::number( 0 ) );
381   myWidgets[i3D][iTotal]->setProperty( "text", QString::number( 0 ) );
382   myWidgets[i3D][iLinear]->setProperty( "text", QString::number( 0 ) );
383   myWidgets[i3D][iQuadratic]->setProperty( "text", QString::number( 0 ) );
384   myWidgets[i3DTetrahedrons][iTotal]->setProperty( "text", QString::number( 0 ) );
385   myWidgets[i3DTetrahedrons][iLinear]->setProperty( "text", QString::number( 0 ) );
386   myWidgets[i3DTetrahedrons][iQuadratic]->setProperty( "text", QString::number( 0 ) );
387   myWidgets[i3DHexahedrons][iTotal]->setProperty( "text", QString::number( 0 ) );
388   myWidgets[i3DHexahedrons][iLinear]->setProperty( "text", QString::number( 0 ) );
389   myWidgets[i3DHexahedrons][iQuadratic]->setProperty( "text", QString::number( 0 ) );
390   myWidgets[i3DPyramids][iTotal]->setProperty( "text", QString::number( 0 ) );
391   myWidgets[i3DPyramids][iLinear]->setProperty( "text", QString::number( 0 ) );
392   myWidgets[i3DPyramids][iQuadratic]->setProperty( "text", QString::number( 0 ) );
393   myWidgets[i3DPrisms][iTotal]->setProperty( "text", QString::number( 0 ) );
394   myWidgets[i3DPrisms][iLinear]->setProperty( "text", QString::number( 0 ) );
395   myWidgets[i3DPrisms][iQuadratic]->setProperty( "text", QString::number( 0 ) );
396   myWidgets[i3DPolyhedrons][iTotal]->setProperty( "text", QString::number( 0 ) );
397 }
398
399 /*!
400   \brief Create info field
401   \return new info field
402 */
403 QLabel* SMESHGUI_MeshInfo::createField()
404 {
405   QLabel* lab = new QLabel( this );
406   lab->setFrameStyle( StyledPanel | Sunken );
407   lab->setAlignment( Qt::AlignCenter );
408   lab->setAutoFillBackground( true );
409   QPalette pal = lab->palette();
410   pal.setColor( QPalette::Window, QApplication::palette().color( QPalette::Active, QPalette::Base ) );
411   lab->setPalette( pal );
412   lab->setMinimumWidth( 70 );
413   return lab;
414 }
415
416 /*!
417   \brief Create horizontal rule.
418   \return new line object
419 */
420 QWidget* SMESHGUI_MeshInfo::createLine()
421 {
422   QFrame* line = new QFrame( this );
423   line->setFrameStyle( HLine | Sunken );
424   return line;
425 }
426
427 /*!
428   \brief Change widget font attributes (bold, italic, ...).
429   \param w widget
430   \param attr font attributes (XORed flags)
431   \param val value to be set to attributes
432 */
433 void SMESHGUI_MeshInfo::setFontAttributes( QWidget* w, int attr, bool val )
434 {
435   if ( w && attr ) {
436     QFont f = w->font();
437     if ( attr & Bold   ) f.setBold( val );
438     if ( attr & Italic ) f.setItalic( val );
439     w->setFont( f );
440   }
441 }
442
443 /*!
444   \brief Show/hide group(s) of fields.
445   \param start beginning of the block
446   \param end end of the block
447   \param on visibility flag
448 */
449 void SMESHGUI_MeshInfo::setFieldsVisible( int start, int end, bool on )
450 {
451   start = qMax( 0, start );
452   end   = qMin( end, (int)iElementsEnd );
453   for ( int i = start; i < end; i++ ) {
454     wlist wl = myWidgets[i];
455     foreach ( QWidget* w, wl ) w->setVisible( on );
456   }
457 }
458
459 /*!
460   \class SMESHGUI_ElemInfo
461   \brief Base class for the mesh element information widget.
462 */
463
464 /*!
465   \brief Constructor
466   \param parent parent widget
467 */
468 SMESHGUI_ElemInfo::SMESHGUI_ElemInfo( QWidget* parent )
469 : QWidget( parent ), myActor( 0 ), myIsElement( -1 )
470 {
471   myFrame = new QWidget( this );
472   myExtra = new QWidget( this );
473   myCurrent = new QLabel( "10/43 items shown", myExtra );
474   myCurrent->setAlignment( Qt::AlignRight | Qt::AlignVCenter );
475   myPrev = new QPushButton( tr( "<<" ), myExtra );
476   myNext = new QPushButton( tr( ">>" ), myExtra );
477   QHBoxLayout* hbl = new QHBoxLayout( myExtra );
478   hbl->setContentsMargins( 0, SPACING, 0, 0 );
479   hbl->setSpacing( SPACING );
480   hbl->addStretch();
481   hbl->addWidget( myCurrent );
482   hbl->addWidget( myPrev );
483   hbl->addWidget( myNext );
484   QVBoxLayout* vbl = new QVBoxLayout( this );
485   vbl->setMargin( 0 );
486   vbl->setSpacing( 0 );
487   vbl->addWidget( myFrame );
488   vbl->addWidget( myExtra );
489   connect( myPrev, SIGNAL( clicked() ), this, SLOT( showPrevious() ) );
490   connect( myNext, SIGNAL( clicked() ), this, SLOT( showNext() ) );
491   clear();
492 }
493
494 /*!
495   \brief Destructor
496 */
497 SMESHGUI_ElemInfo::~SMESHGUI_ElemInfo()
498 {
499 }
500
501 /*!
502   \brief Set mesh data source (actor)
503   \param actor mesh object actor
504 */
505 void SMESHGUI_ElemInfo::setSource( SMESH_Actor* actor )
506 {
507   if ( myActor != actor ) {
508     myActor = actor;
509     myIsElement = -1;
510     clear();
511   }
512 }
513
514 /*!
515   \brief Show mesh element information
516   \param id mesh node / element ID
517   \param isElem show mesh element information if \c true or mesh node information if \c false
518 */
519 void SMESHGUI_ElemInfo::showInfo( long id, bool isElem )
520 {
521   QSet<long> ids;
522   ids << id;
523   showInfo( ids, isElem );
524 }
525
526 /*!
527   \brief Show mesh element information
528   \param ids mesh nodes / elements identifiers
529   \param isElem show mesh element information if \c true or mesh node information if \c false
530 */
531 void SMESHGUI_ElemInfo::showInfo( QSet<long> ids, bool isElem )
532 {
533   QList<long> newIds = ids.toList();
534   qSort( newIds );
535   if ( myIDs == newIds && myIsElement == isElem ) return;
536
537   myIDs = newIds;
538   myIsElement = isElem;
539   myIndex = 0;
540   updateControls();
541   information( myIDs.mid( myIndex*MAXITEMS, MAXITEMS ) );
542 }
543
544 /*!
545   \brief Clear mesh element information widget
546 */
547 void SMESHGUI_ElemInfo::clear()
548 {
549   myIDs.clear();
550   myIndex = 0;
551   clearInternal();
552   updateControls();
553 }
554
555 /*!
556   \brief Get central area widget
557   \return central widget
558 */
559 QWidget* SMESHGUI_ElemInfo::frame() const
560 {
561   return myFrame;
562 }
563
564 /*!
565   \brief Get actor
566   \return actor being used
567 */
568 SMESH_Actor* SMESHGUI_ElemInfo::actor() const
569 {
570   return myActor;
571 }
572
573 /*!
574   \brief Get current info mode.
575   \return \c true if mesh element information is shown or \c false if node information is shown
576 */
577 bool SMESHGUI_ElemInfo::isElements() const
578 {
579   return myIsElement;
580 }
581
582 /*!
583   \fn void SMESHGUI_ElemInfo::information( const QList<long>& ids )
584   \brief Show information on the specified nodes / elements
585
586   This function is to be redefined in sub-classes.
587
588   \param ids nodes / elements identifiers information is to be shown on
589 */
590
591 /*!
592   \brief Internal clean-up (reset widget)
593 */
594 void SMESHGUI_ElemInfo::clearInternal()
595 {
596 }
597
598 /*!
599   \brief Get node connectivity
600   \param node mesh node
601   \return node connectivity map
602 */
603 SMESHGUI_ElemInfo::Connectivity SMESHGUI_ElemInfo::nodeConnectivity( const SMDS_MeshNode* node )
604 {
605   Connectivity elmap;
606   if ( node ) {
607     SMDS_ElemIteratorPtr it = node->GetInverseElementIterator();
608     while ( it && it->more() ) {
609       const SMDS_MeshElement* ne = it->next();
610       elmap[ ne->GetType() ] << ne->GetID();
611     }
612   }
613   return elmap;
614 }
615
616 /*!
617   \brief Format connectivity data to string representation
618   \param connectivity connetivity map
619   \param type element type
620   \return string representation of the connectivity
621 */
622 QString SMESHGUI_ElemInfo::formatConnectivity( Connectivity connectivity, int type )
623 {
624   QStringList str;
625   if ( connectivity.contains( type ) ) {
626     QList<int> elements = connectivity[ type ];
627     qSort( elements );
628     foreach( int id, elements )
629       str << QString::number( id );
630   }
631   return str.join( " " );
632 }
633
634 /*!
635   \brief Calculate gravity center of the mesh element
636   \param element mesh element
637 */
638 SMESHGUI_ElemInfo::XYZ SMESHGUI_ElemInfo::gravityCenter( const SMDS_MeshElement* element )
639 {
640   XYZ xyz;
641   if ( element ) {
642     SMDS_ElemIteratorPtr nodeIt = element->nodesIterator();
643     while ( nodeIt->more() ) {
644       const SMDS_MeshNode* node = static_cast<const SMDS_MeshNode*>( nodeIt->next() );
645       xyz.add( node->X(), node->Y(), node->Z() );
646     }
647     xyz.divide( element->NbNodes() );
648   }
649   return xyz;
650 }
651
652 /*!
653   \brief This slot is called from "Show Previous" button click.
654   Shows information on the previous group of the items.
655 */
656 void SMESHGUI_ElemInfo::showPrevious()
657 {
658   myIndex = qMax( 0, myIndex-1 );
659   updateControls();
660   information( myIDs.mid( myIndex*MAXITEMS, MAXITEMS ) );
661 }
662
663 /*!
664   \brief This slot is called from "Show Next" button click.
665   Shows information on the next group of the items.
666 */
667 void SMESHGUI_ElemInfo::showNext()
668 {
669   myIndex = qMin( myIndex+1, myIDs.count() / MAXITEMS );
670   updateControls();
671   information( myIDs.mid( myIndex*MAXITEMS, MAXITEMS ) );
672 }
673
674 /*!
675   \brief Update widgets state
676 */
677 void SMESHGUI_ElemInfo::updateControls()
678 {
679   myExtra->setVisible( myIDs.count() > MAXITEMS );
680   myCurrent->setText( tr( "X_FROM_Y_ITEMS_SHOWN" ).arg( myIndex*MAXITEMS+1 ).arg(qMin(myIndex*MAXITEMS+MAXITEMS, myIDs.count())).arg( myIDs.count() ) );
681   myPrev->setEnabled( myIndex > 0 );
682   myNext->setEnabled( (myIndex+1)*MAXITEMS < myIDs.count() );
683 }
684
685 /*!
686   \class SMESHGUI_SimpleElemInfo
687   \brief Represents mesh element information in the simple text area.
688 */
689
690 /*!
691   \brief Constructor
692   \param parent parent widget
693 */
694 SMESHGUI_SimpleElemInfo::SMESHGUI_SimpleElemInfo( QWidget* parent )
695 : SMESHGUI_ElemInfo( parent )
696 {
697   myInfo = new QTextBrowser( frame() );
698   QVBoxLayout* l = new QVBoxLayout( frame() );
699   l->setMargin( 0 );
700   l->addWidget( myInfo );
701 }
702
703 /*!
704   \brief Show mesh element information
705   \param ids mesh nodes / elements identifiers
706 */
707 void SMESHGUI_SimpleElemInfo::information( const QList<long>& ids )
708 {
709   clearInternal();
710   
711   if ( actor() ) {
712     int precision = SMESHGUI::resourceMgr()->integerValue( "SMESH", "length_precision", 6 );
713     foreach ( long id, ids ) {
714       if ( !isElements() ) {
715         //
716         // show node info
717         //
718         const SMDS_MeshElement* e = actor()->GetObject()->GetMesh()->FindNode( id );
719         if ( !e ) return;
720         const SMDS_MeshNode* node = static_cast<const SMDS_MeshNode*>( e );
721         
722         // node ID
723         myInfo->append( QString( "<b>%1 #%2</b>" ).arg( tr( "NODE" ) ).arg( id ) );
724         // separator
725         myInfo->append( "" );
726         // coordinates
727         myInfo->append( QString( "<b>%1:</b> (%2, %3, %4)" ).arg( tr( "COORDINATES" ) ).
728                         arg( node->X(), 0, precision > 0 ? 'f' : 'g', qAbs( precision ) ).
729                         arg( node->Y(), 0, precision > 0 ? 'f' : 'g', qAbs( precision ) ).
730                         arg( node->Z(), 0, precision > 0 ? 'f' : 'g', qAbs( precision ) ) );
731         // separator
732         myInfo->append( "" );
733         // connectivity
734         Connectivity connectivity = nodeConnectivity( node );
735         if ( !connectivity.isEmpty() ) {
736           myInfo->append( QString( "<b>%1:</b>" ).arg( tr( "CONNECTIVITY" ) ) );
737           QString con = formatConnectivity( connectivity, SMDSAbs_0DElement );
738           if ( !con.isEmpty() )
739             myInfo->append( QString( "- <b>%1:</b> %2" ).arg( tr( "0D_ELEMENTS" ) ).arg( con ) );
740           con = formatConnectivity( connectivity, SMDSAbs_Edge );
741           if ( !con.isEmpty() )
742             myInfo->append( QString( "- <b>%1:</b> %2" ).arg( tr( "EDGES" ) ).arg( con ) );
743           con = formatConnectivity( connectivity, SMDSAbs_Face );
744           if ( !con.isEmpty() )
745             myInfo->append( QString( "- <b>%1:</b> %2" ).arg( tr( "FACES" ) ).arg( con ) );
746           con = formatConnectivity( connectivity, SMDSAbs_Volume );
747           if ( !con.isEmpty() )
748             myInfo->append( QString( "- <b>%1:</b> %2" ).arg( tr( "VOLUMES" ) ).arg( con ) );
749         }
750         else {
751           myInfo->append( QString( "<b>%1</b>" ).arg( tr( "FREE_NODE" ) ).arg( id ) );
752         }
753       }
754       else {
755         //
756         // show element info
757         // 
758         const SMDS_MeshElement* e = actor()->GetObject()->GetMesh()->FindElement( id );
759         if ( !e ) return;
760         
761         // element ID && type
762         QString stype;
763         switch( e->GetType() ) {
764         case SMDSAbs_0DElement:
765           stype = tr( "0D ELEMENT" ); break;
766         case SMDSAbs_Edge:
767           stype = tr( "EDGE" ); break;
768         case SMDSAbs_Face:
769           stype = tr( "FACE" ); break;
770         case SMDSAbs_Volume:
771           stype = tr( "VOLUME" ); break;
772         default: 
773           break;
774         }
775         if ( stype.isEmpty() ) return;
776         myInfo->append( QString( "<b>%1 #%2</b>" ).arg( stype ).arg( id ) );
777         // separator
778         myInfo->append( "" );
779         // geometry type
780         QString gtype;
781         switch( e->GetEntityType() ) {
782         case SMDSEntity_Triangle:
783         case SMDSEntity_Quad_Triangle:
784           gtype = tr( "TRIANGLE" ); break;
785         case SMDSEntity_Quadrangle:
786         case SMDSEntity_Quad_Quadrangle:
787           gtype = tr( "QUADRANGLE" ); break;
788         case SMDSEntity_Polygon:
789         case SMDSEntity_Quad_Polygon:
790           gtype = tr( "POLYGON" ); break;
791         case SMDSEntity_Tetra:
792         case SMDSEntity_Quad_Tetra:
793           gtype = tr( "TETRAHEDRON" ); break;
794         case SMDSEntity_Pyramid:
795         case SMDSEntity_Quad_Pyramid:
796           gtype = tr( "PYRAMID" ); break;
797         case SMDSEntity_Hexa:
798         case SMDSEntity_Quad_Hexa:
799           gtype = tr( "HEXAHEDRON" ); break;
800         case SMDSEntity_Penta:
801         case SMDSEntity_Quad_Penta:
802           gtype = tr( "PRISM" ); break;
803         case SMDSEntity_Polyhedra:
804         case SMDSEntity_Quad_Polyhedra:
805           gtype = tr( "POLYHEDRON" ); break;
806         default: 
807           break;
808         }
809         if ( !gtype.isEmpty() )
810           myInfo->append( QString( "<b>%1:</b> %2" ).arg( tr( "TYPE" ) ).arg( gtype ) );
811         // quadratic flag and gravity center (any element except 0D)
812         if ( e->GetEntityType() > SMDSEntity_0D && e->GetEntityType() < SMDSEntity_Last ) {
813           // quadratic flag
814           myInfo->append( QString( "<b>%1?</b> %2" ).arg( tr( "QUADRATIC" ) ).arg( e->IsQuadratic() ? tr( "YES" ) : tr( "NO" ) ) );
815           // separator
816           myInfo->append( "" );
817           // gravity center
818           XYZ gc = gravityCenter( e );
819           myInfo->append( QString( "<b>%1:</b> (%2, %3, %4)" ).arg( tr( "GRAVITY_CENTER" ) ).arg( gc.x() ).arg( gc.y() ).arg( gc.z() ) );
820         }
821         // separator
822         myInfo->append( "" );
823         // connectivity
824         SMDS_ElemIteratorPtr nodeIt = e->nodesIterator();
825         for ( int idx = 1; nodeIt->more(); idx++ ) {
826           const SMDS_MeshNode* node = static_cast<const SMDS_MeshNode*>( nodeIt->next() );
827           // node number and ID
828           myInfo->append( QString( "<b>%1 %2/%3</b> - #%4" ).arg( tr( "NODE" ) ).arg( idx ).arg( e->NbNodes() ).arg( node->GetID() ) );
829           // node coordinates
830           myInfo->append( QString( "<b>%1:</b> (%2, %3, %4)" ).arg( tr( "COORDINATES" ) ).
831                           arg( node->X(), 0, precision > 0 ? 'f' : 'g', qAbs( precision ) ).
832                           arg( node->Y(), 0, precision > 0 ? 'f' : 'g', qAbs( precision ) ).
833                           arg( node->Z(), 0, precision > 0 ? 'f' : 'g', qAbs( precision ) ) );
834           // node connectivity
835           Connectivity connectivity = nodeConnectivity( node );
836           if ( !connectivity.isEmpty() ) {
837             myInfo->append( QString( "<b>%1:</b>" ).arg( tr( "CONNECTIVITY" ) ) );
838             QString con = formatConnectivity( connectivity, SMDSAbs_0DElement );
839             if ( !con.isEmpty() )
840               myInfo->append( QString( "- <b>%1:</b> %2" ).arg( tr( "0D_ELEMENTS" ) ).arg( con ) );
841             con = formatConnectivity( connectivity, SMDSAbs_Edge );
842             if ( !con.isEmpty() )
843               myInfo->append( QString( "- <b>%1:</b> %2" ).arg( tr( "EDGES" ) ).arg( con ) );
844             con = formatConnectivity( connectivity, SMDSAbs_Face );
845             if ( !con.isEmpty() )
846               myInfo->append( QString( "- <b>%1:</b> %2" ).arg( tr( "FACES" ) ).arg( con ) );
847             con = formatConnectivity( connectivity, SMDSAbs_Volume );
848             if ( !con.isEmpty() )
849               myInfo->append( QString( "- <b>%1:</b> %2" ).arg( tr( "VOLUMES" ) ).arg( con ) );
850           }
851           else {
852             myInfo->append( QString( "<b>%1</b>" ).arg( tr( "FREE_NODE" ) ).arg( id ) );
853           }
854         }
855       }
856       // separator
857       if ( ids.count() > 1 ) {
858         myInfo->append( "" );
859         myInfo->append( "------" );
860         myInfo->append( "" );
861       }
862     }
863   }
864 }
865
866 /*!
867   \brief Internal clean-up (reset widget)
868 */
869 void SMESHGUI_SimpleElemInfo::clearInternal()
870 {
871   myInfo->clear();
872 }
873
874 /*!
875   \class SMESHGUI_TreeElemInfo::ItemDelegate
876   \brief Item delegate for tree mesh info widget
877   \internal
878 */
879 class SMESHGUI_TreeElemInfo::ItemDelegate : public QItemDelegate
880 {
881 public:
882   ItemDelegate( QObject* );
883   QWidget* createEditor( QWidget*, const QStyleOptionViewItem&, const QModelIndex& ) const;
884 };
885
886 /*!
887   \brief Constructor
888   \internal
889 */
890 SMESHGUI_TreeElemInfo::ItemDelegate::ItemDelegate( QObject* parent ) : QItemDelegate( parent )
891 {
892 }
893
894 /*!
895   \brief Create item editor widget
896   \internal
897 */
898 QWidget* SMESHGUI_TreeElemInfo::ItemDelegate::createEditor( QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index ) const
899 {
900   QWidget* w = index.column() == 0 ? 0: QItemDelegate::createEditor( parent, option, index );
901   if ( qobject_cast<QLineEdit*>( w ) ) qobject_cast<QLineEdit*>( w )->setReadOnly(  true );
902   return w;
903 }
904
905 /*!
906   \class SMESHGUI_TreeElemInfo
907   \brief Represents mesh element information in the tree-like form.
908 */
909
910 /*!
911   \brief Constructor
912   \param parent parent widget
913 */
914 SMESHGUI_TreeElemInfo::SMESHGUI_TreeElemInfo( QWidget* parent )
915 : SMESHGUI_ElemInfo( parent )
916 {
917   myInfo = new QTreeWidget( frame() );
918   myInfo->setColumnCount( 2 );
919   myInfo->setHeaderLabels( QStringList() << tr( "PROPERTY" ) << tr( "VALUE" ) );
920   myInfo->header()->setStretchLastSection( true );
921   myInfo->header()->setResizeMode( 0, QHeaderView::ResizeToContents );
922   myInfo->setItemDelegate( new ItemDelegate( myInfo ) );
923   QVBoxLayout* l = new QVBoxLayout( frame() );
924   l->setMargin( 0 );
925   l->addWidget( myInfo );
926 }
927
928 /*!
929   \brief Show mesh element information
930   \param ids mesh nodes / elements identifiers
931 */
932 void SMESHGUI_TreeElemInfo::information( const QList<long>& ids )
933 {
934   clearInternal();
935
936   if ( actor() ) {
937     int precision = SMESHGUI::resourceMgr()->integerValue( "SMESH", "length_precision", 6 );
938     foreach ( long id, ids ) {
939       if ( !isElements() ) {
940         //
941         // show node info
942         //
943         const SMDS_MeshElement* e = actor()->GetObject()->GetMesh()->FindNode( id );
944         if ( !e ) return;
945         const SMDS_MeshNode* node = static_cast<const SMDS_MeshNode*>( e );
946       
947         // node ID
948         QTreeWidgetItem* nodeItem = createItem( 0, -1 );
949         nodeItem->setText( 0, tr( "NODE" ) );
950         nodeItem->setText( 1, QString( "#%1" ).arg( id ) );
951         nodeItem->setExpanded( true );
952         // coordinates
953         QTreeWidgetItem* coordItem = createItem( nodeItem, 0 );
954         coordItem->setText( 0, tr( "COORDINATES" ) );
955         coordItem->setExpanded( true );
956         QTreeWidgetItem* xItem = createItem( coordItem );
957         xItem->setText( 0, "X" );
958         xItem->setText( 1, QString::number( node->X(), precision > 0 ? 'f' : 'g', qAbs( precision ) ) );
959         QTreeWidgetItem* yItem = createItem( coordItem );
960         yItem->setText( 0, "Y" );
961         yItem->setText( 1, QString::number( node->Y(), precision > 0 ? 'f' : 'g', qAbs( precision ) ) );
962         QTreeWidgetItem* zItem = createItem( coordItem );
963         zItem->setText( 0, "Z" );
964         zItem->setText( 1, QString::number( node->Z(), precision > 0 ? 'f' : 'g', qAbs( precision ) ) );
965         // connectivity
966         QTreeWidgetItem* conItem = createItem( nodeItem, 0 );
967         conItem->setText( 0, tr( "CONNECTIVITY" ) );
968         conItem->setExpanded( true );
969         Connectivity connectivity = nodeConnectivity( node );
970         if ( !connectivity.isEmpty() ) {
971           QString con = formatConnectivity( connectivity, SMDSAbs_0DElement );
972           if ( !con.isEmpty() ) {
973             QTreeWidgetItem* i = createItem( conItem );
974             i->setText( 0, tr( "0D_ELEMENTS" ) );
975             i->setText( 1, con );
976           }
977           con = formatConnectivity( connectivity, SMDSAbs_Edge );
978           if ( !con.isEmpty() ) {
979             QTreeWidgetItem* i = createItem( conItem );
980             i->setText( 0, tr( "EDGES" ) );
981             i->setText( 1, con );
982           }
983           con = formatConnectivity( connectivity, SMDSAbs_Face );
984           if ( !con.isEmpty() ) {
985             QTreeWidgetItem* i = createItem( conItem );
986             i->setText( 0, tr( "FACES" ) );
987             i->setText( 1, con );
988           }
989           con = formatConnectivity( connectivity, SMDSAbs_Volume );
990           if ( !con.isEmpty() ) {
991             QTreeWidgetItem* i = createItem( conItem );
992             i->setText( 0, tr( "VOLUMES" ) );
993             i->setText( 1, con );
994           }
995         }
996         else {
997           conItem->setText( 1, tr( "FREE_NODE" ) );
998         }
999       }
1000       else {
1001         //
1002         // show element info
1003         // 
1004         const SMDS_MeshElement* e = actor()->GetObject()->GetMesh()->FindElement( id );
1005         if ( !e ) return;
1006         
1007         // element ID && type
1008         QString stype;
1009         switch( e->GetType() ) {
1010         case SMDSAbs_0DElement:
1011           stype = tr( "0D ELEMENT" ); break;
1012         case SMDSAbs_Edge:
1013           stype = tr( "EDGE" ); break;
1014         case SMDSAbs_Face:
1015           stype = tr( "FACE" ); break;
1016         case SMDSAbs_Volume:
1017           stype = tr( "VOLUME" ); break;
1018         default: 
1019           break;
1020         }
1021         if ( stype.isEmpty() ) return;
1022         QTreeWidgetItem* elemItem = createItem( 0, -1 );
1023         elemItem->setText( 0, stype );
1024         elemItem->setText( 1, QString( "#%1" ).arg( id ) );
1025         elemItem->setExpanded( true );
1026         // geometry type
1027         QString gtype;
1028         switch( e->GetEntityType() ) {
1029         case SMDSEntity_Triangle:
1030         case SMDSEntity_Quad_Triangle:
1031           gtype = tr( "TRIANGLE" ); break;
1032         case SMDSEntity_Quadrangle:
1033         case SMDSEntity_Quad_Quadrangle:
1034           gtype = tr( "QUADRANGLE" ); break;
1035         case SMDSEntity_Polygon:
1036         case SMDSEntity_Quad_Polygon:
1037           gtype = tr( "POLYGON" ); break;
1038         case SMDSEntity_Tetra:
1039         case SMDSEntity_Quad_Tetra:
1040           gtype = tr( "TETRAHEDRON" ); break;
1041         case SMDSEntity_Pyramid:
1042         case SMDSEntity_Quad_Pyramid:
1043           gtype = tr( "PYRAMID" ); break;
1044         case SMDSEntity_Hexa:
1045         case SMDSEntity_Quad_Hexa:
1046           gtype = tr( "HEXAHEDRON" ); break;
1047         case SMDSEntity_Penta:
1048         case SMDSEntity_Quad_Penta:
1049           gtype = tr( "PRISM" ); break;
1050         case SMDSEntity_Polyhedra:
1051         case SMDSEntity_Quad_Polyhedra:
1052           gtype = tr( "POLYHEDRON" ); break;
1053         default: 
1054           break;
1055         }
1056         if ( !gtype.isEmpty() ) {
1057           QTreeWidgetItem* typeItem = createItem( elemItem, 0 );
1058           typeItem->setText( 0, tr( "TYPE" ) );
1059           typeItem->setText( 1, gtype );
1060         }
1061         // quadratic flag and gravity center (any element except 0D)
1062         if ( e->GetEntityType() > SMDSEntity_0D && e->GetEntityType() < SMDSEntity_Last ) {
1063           // quadratic flag
1064           QTreeWidgetItem* quadItem = createItem( elemItem, 0 );
1065           quadItem->setText( 0, tr( "QUADRATIC" ) );
1066           quadItem->setText( 1, e->IsQuadratic() ? tr( "YES" ) : tr( "NO" ) );
1067           // gravity center
1068           XYZ gc = gravityCenter( e );
1069           QTreeWidgetItem* gcItem = createItem( elemItem, 0 );
1070           gcItem->setText( 0, tr( "GRAVITY_CENTER" ) );
1071           gcItem->setExpanded( true );
1072           QTreeWidgetItem* xItem = createItem( gcItem );
1073           xItem->setText( 0, "X" );
1074           xItem->setText( 1, QString::number( gc.x(), precision > 0 ? 'f' : 'g', qAbs( precision ) ) );
1075           QTreeWidgetItem* yItem = createItem( gcItem );
1076           yItem->setText( 0, "Y" );
1077           yItem->setText( 1, QString::number( gc.y(), precision > 0 ? 'f' : 'g', qAbs( precision ) ) );
1078           QTreeWidgetItem* zItem = createItem( gcItem );
1079           zItem->setText( 0, "Z" );
1080           zItem->setText( 1, QString::number( gc.z(), precision > 0 ? 'f' : 'g', qAbs( precision ) ) );
1081         }
1082         // connectivity
1083         QTreeWidgetItem* conItem = createItem( elemItem, 0 );
1084         conItem->setText( 0, tr( "CONNECTIVITY" ) );
1085         conItem->setExpanded( true );
1086         SMDS_ElemIteratorPtr nodeIt = e->nodesIterator();
1087         for ( int idx = 1; nodeIt->more(); idx++ ) {
1088           const SMDS_MeshNode* node = static_cast<const SMDS_MeshNode*>( nodeIt->next() );
1089           // node number and ID
1090           QTreeWidgetItem* nodeItem = createItem( conItem, 0 );
1091           nodeItem->setText( 0, QString( "%1 %2/%3" ).arg( tr( "NODE" ) ).arg( idx ).arg( e->NbNodes() ) );
1092           nodeItem->setText( 1, QString( "#%1" ).arg( node->GetID() ) );
1093           //nodeItem->setExpanded( true );
1094           // node coordinates
1095           QTreeWidgetItem* coordItem = createItem( nodeItem );
1096           coordItem->setText( 0, tr( "COORDINATES" ) );
1097           coordItem->setExpanded( true );
1098           QTreeWidgetItem* xItem = createItem( coordItem );
1099           xItem->setText( 0, "X" );
1100           xItem->setText( 1, QString::number( node->X(), precision > 0 ? 'f' : 'g', qAbs( precision ) ) );
1101           QTreeWidgetItem* yItem = createItem( coordItem );
1102           yItem->setText( 0, "Y" );
1103           yItem->setText( 1, QString::number( node->Y(), precision > 0 ? 'f' : 'g', qAbs( precision ) ) );
1104           QTreeWidgetItem* zItem = createItem( coordItem );
1105           zItem->setText( 0, "Z" );
1106           zItem->setText( 1, QString::number( node->Z(), precision > 0 ? 'f' : 'g', qAbs( precision ) ) );
1107           // node connectivity
1108           QTreeWidgetItem* nconItem = createItem( nodeItem );
1109           nconItem->setText( 0, tr( "CONNECTIVITY" ) );
1110           nconItem->setExpanded( true );
1111           Connectivity connectivity = nodeConnectivity( node );
1112           if ( !connectivity.isEmpty() ) {
1113             QString con = formatConnectivity( connectivity, SMDSAbs_0DElement );
1114             if ( !con.isEmpty() ) {
1115               QTreeWidgetItem* i = createItem( nconItem );
1116               i->setText( 0, tr( "0D_ELEMENTS" ) );
1117               i->setText( 1, con );
1118             }
1119             con = formatConnectivity( connectivity, SMDSAbs_Edge );
1120             if ( !con.isEmpty() ) {
1121               QTreeWidgetItem* i = createItem( nconItem );
1122               i->setText( 0, tr( "EDGES" ) );
1123               i->setText( 1, con );
1124             }
1125             con = formatConnectivity( connectivity, SMDSAbs_Face );
1126             if ( !con.isEmpty() ) {
1127               QTreeWidgetItem* i = createItem( nconItem );
1128               i->setText( 0, tr( "FACES" ) );
1129               i->setText( 1, con );
1130             }
1131             con = formatConnectivity( connectivity, SMDSAbs_Volume );
1132             if ( !con.isEmpty() ) {
1133               QTreeWidgetItem* i = createItem( nconItem );
1134               i->setText( 0, tr( "VOLUMES" ) );
1135               i->setText( 1, con );
1136             }
1137           }
1138         }
1139       }
1140     }
1141   }
1142 }
1143
1144 /*!
1145   \brief Internal clean-up (reset widget)
1146 */
1147 void SMESHGUI_TreeElemInfo::clearInternal()
1148 {
1149   myInfo->clear();
1150   myInfo->repaint();
1151 }
1152
1153 /*!
1154   \brief Create new tree item.
1155   \param parnt parent tree widget item
1156   \param column item column to be set bold, if it is -1, bold font will be set for all columns
1157   \return new tree widget item
1158 */
1159 QTreeWidgetItem* SMESHGUI_TreeElemInfo::createItem( QTreeWidgetItem* parent, int column )
1160 {
1161   QTreeWidgetItem* item;
1162   if ( parent )
1163     item = new QTreeWidgetItem( parent );
1164   else
1165     item = new QTreeWidgetItem( myInfo );
1166
1167   item->setFlags( item->flags() | Qt::ItemIsEditable );
1168
1169   QFont f = item->font( 0 );
1170   f.setBold( true );
1171   if ( column >= 0 && column < myInfo->columnCount() ) {
1172     item->setFont( column, f );
1173   }
1174   else if ( column == -1 ) {
1175     for ( int i = 0; i < myInfo->columnCount(); i++ )
1176       item->setFont( i, f );
1177   }
1178   return item;
1179 }
1180
1181 /*!
1182   \class SMESHGUI_MeshInfoDlg
1183   \brief Mesh information dialog box
1184 */
1185
1186 /*!
1187   \brief Constructor
1188   \param parent parent widget
1189   \param page specifies the dialog page to be shown at the start-up
1190 */
1191 SMESHGUI_MeshInfoDlg::SMESHGUI_MeshInfoDlg( QWidget* parent, int page )
1192 : QDialog( parent ), myActor( 0 )
1193 {
1194   setModal( false );
1195   setAttribute( Qt::WA_DeleteOnClose, true );
1196   setWindowTitle( tr( "MESH_INFO" ) );
1197   setSizeGripEnabled( true );
1198
1199   myTabWidget = new QTabWidget( this );
1200
1201   // base info 
1202
1203   myBaseInfo = new SMESHGUI_MeshInfo( myTabWidget );
1204   myTabWidget->addTab( myBaseInfo, tr( "BASE_INFO" ) );
1205
1206   // elem info 
1207   
1208   QWidget* w = new QWidget( myTabWidget );
1209
1210   myMode = new QButtonGroup( this );
1211   myMode->addButton( new QRadioButton( tr( "NODE_MODE" ), w ), NodeMode );
1212   myMode->addButton( new QRadioButton( tr( "ELEM_MODE" ), w ), ElemMode );
1213   myMode->button( NodeMode )->setChecked( true );
1214   myID = new QLineEdit( w );
1215   myID->setValidator( new SMESHGUI_IdValidator( this ) );
1216
1217   int mode = SMESHGUI::resourceMgr()->integerValue( "SMESH", "mesh_elem_info", 1 );
1218   mode = qMin( 1, qMax( 0, mode ) );
1219   
1220   if ( mode == 0 ) 
1221     myElemInfo = new SMESHGUI_SimpleElemInfo( w );
1222   else
1223     myElemInfo = new SMESHGUI_TreeElemInfo( w );
1224
1225   QGridLayout* elemLayout = new QGridLayout( w );
1226   elemLayout->setMargin( MARGIN );
1227   elemLayout->setSpacing( SPACING );
1228   elemLayout->addWidget( myMode->button( NodeMode ), 0, 0 );
1229   elemLayout->addWidget( myMode->button( ElemMode ), 0, 1 );
1230   elemLayout->addWidget( myID, 0, 2 );
1231   elemLayout->addWidget( myElemInfo, 1, 0, 1, 3 );
1232   
1233   myTabWidget->addTab( w, tr( "ELEM_INFO" ) );
1234
1235   QPushButton* okBtn = new QPushButton( tr( "SMESH_BUT_OK" ), this );
1236   okBtn->setAutoDefault( true );
1237   okBtn->setDefault( true );
1238   okBtn->setFocus();
1239   QPushButton* helpBtn = new QPushButton( tr( "SMESH_BUT_HELP" ), this );
1240   helpBtn->setAutoDefault( true );
1241
1242   QHBoxLayout* btnLayout = new QHBoxLayout;
1243   btnLayout->setSpacing( SPACING );
1244   btnLayout->setMargin( 0 );
1245
1246   btnLayout->addWidget( okBtn );
1247   btnLayout->addStretch( 10 );
1248   btnLayout->addWidget( helpBtn );
1249
1250   QVBoxLayout* l = new QVBoxLayout ( this );
1251   l->setMargin( MARGIN );
1252   l->setSpacing( SPACING );
1253   l->addWidget( myTabWidget );
1254   l->addStretch();
1255   l->addLayout( btnLayout );
1256
1257   myTabWidget->setCurrentIndex( qMax( (int)BaseInfo, qMin( (int)ElemInfo, page ) ) );
1258
1259   connect( okBtn,       SIGNAL( clicked() ),              this, SLOT( reject() ) );
1260   connect( helpBtn,     SIGNAL( clicked() ),              this, SLOT( help() ) );
1261   connect( myTabWidget, SIGNAL( currentChanged( int  ) ), this, SLOT( updateSelection() ) );
1262   connect( myMode,      SIGNAL( buttonClicked( int  ) ),  this, SLOT( modeChanged() ) );
1263   connect( myID,        SIGNAL( textEdited( QString  ) ), this, SLOT( idChanged() ) );
1264   connect( SMESHGUI::GetSMESHGUI(),  SIGNAL( SignalDeactivateActiveDialog() ), this, SLOT( deactivate() ) );
1265   connect( SMESHGUI::GetSMESHGUI(),  SIGNAL( SignalCloseAllDialogs() ),        this, SLOT( reject() ) );
1266
1267   updateSelection();
1268 }
1269
1270 /*!
1271   \brief Destructor
1272 */
1273 SMESHGUI_MeshInfoDlg::~SMESHGUI_MeshInfoDlg()
1274 {
1275 }
1276
1277 /*!
1278   \brief Show mesh information
1279   \param IO interactive object
1280 */
1281 void SMESHGUI_MeshInfoDlg::showInfo( const Handle(SALOME_InteractiveObject)& IO )
1282 {
1283   SMESH::SMESH_IDSource_var obj = SMESH::IObjectToInterface<SMESH::SMESH_IDSource>( IO );
1284   if ( !CORBA::is_nil( obj ) ) {
1285     myBaseInfo->showInfo( obj );
1286     
1287     myActor = SMESH::FindActorByEntry( IO->getEntry() );
1288     SVTK_Selector* selector = SMESH::GetViewWindow()->GetSelector();
1289     QString ID;
1290     int nb = 0;
1291     if ( myActor && selector ) {
1292       nb = myMode->checkedId() == NodeMode ? 
1293         SMESH::GetNameOfSelectedElements( selector, IO, ID ) :
1294         SMESH::GetNameOfSelectedNodes( selector, IO, ID );
1295     }
1296     myElemInfo->setSource( myActor ) ;
1297     if ( nb > 0 ) {
1298       myID->setText( ID.trimmed() );
1299       QSet<long> ids;
1300       QStringList idTxt = ID.split( " ", QString::SkipEmptyParts );
1301       foreach ( ID, idTxt )
1302         ids << ID.trimmed().toLong();
1303       myElemInfo->showInfo( ids, myMode->checkedId() == ElemMode );
1304     }
1305     else {
1306       myID->clear();
1307       myElemInfo->clear();
1308     }
1309   }
1310 }
1311
1312 /*!
1313   \brief Perform clean-up actions on the dialog box closing.
1314 */
1315 void SMESHGUI_MeshInfoDlg::reject()
1316 {
1317   LightApp_SelectionMgr* selMgr = SMESHGUI::selectionMgr();
1318   selMgr->clearFilters();
1319   SMESH::SetPointRepresentation( false );
1320   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow() )
1321     aViewWindow->SetSelectionMode( ActorSelection );
1322   QDialog::reject();
1323 }
1324
1325 /*!
1326   \brief Process keyboard event
1327   \param e key press event
1328 */
1329 void SMESHGUI_MeshInfoDlg::keyPressEvent( QKeyEvent* e )
1330 {
1331   QDialog::keyPressEvent( e );
1332   if ( !e->isAccepted() && e->key() == Qt::Key_F1 ) {
1333     e->accept();
1334     help();
1335   }
1336 }
1337
1338 /*!
1339   \brief Reactivate dialog box, when mouse pointer goes into it.
1340 */
1341 void SMESHGUI_MeshInfoDlg::enterEvent( QEvent* )
1342 {
1343   activate();
1344 }
1345
1346 /*!
1347   \brief Setup selection mode depending on the current dialog box state.
1348 */
1349 void SMESHGUI_MeshInfoDlg::updateSelection()
1350 {
1351   LightApp_SelectionMgr* selMgr = SMESHGUI::selectionMgr();
1352
1353   disconnect( selMgr, 0, this, 0 );
1354   selMgr->clearFilters();
1355
1356   if ( myTabWidget->currentIndex() == BaseInfo ) {
1357     SMESH::SetPointRepresentation( false );
1358     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow() )
1359       aViewWindow->SetSelectionMode( ActorSelection );
1360   }
1361   else {
1362     if ( myMode->checkedId() == NodeMode ) {
1363       SMESH::SetPointRepresentation( true );
1364       if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow() )
1365         aViewWindow->SetSelectionMode( NodeSelection );
1366     }
1367     else {
1368       SMESH::SetPointRepresentation( false );
1369       if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow() )
1370         aViewWindow->SetSelectionMode( CellSelection );
1371     }
1372   }
1373
1374   QString oldID = myID->text().trimmed();
1375   SMESH_Actor* oldActor = myActor;
1376   myID->clear();
1377   
1378   connect( selMgr, SIGNAL( currentSelectionChanged() ), this, SLOT( updateInfo() ) );
1379   updateInfo();
1380   
1381   if ( oldActor == myActor && myActor && !oldID.isEmpty() ) {
1382     myID->setText( oldID );
1383     idChanged();
1384   }
1385 }
1386
1387 /*!
1388   \brief Show help page
1389 */
1390 void SMESHGUI_MeshInfoDlg::help()
1391 {
1392   SMESH::ShowHelpFile( myTabWidget->currentIndex() == BaseInfo ?
1393                        "mesh_infos_page.html#advanced_mesh_infos_anchor" : 
1394                        "mesh_infos_page.html#mesh_element_info_anchor" );
1395 }
1396
1397 /*!
1398   \brief Show mesh information
1399 */
1400 void SMESHGUI_MeshInfoDlg::updateInfo()
1401 {
1402   SUIT_OverrideCursor wc;
1403
1404   SALOME_ListIO selected;
1405   SMESHGUI::selectionMgr()->selectedObjects( selected );
1406
1407   if ( selected.Extent() == 1 ) {
1408     Handle(SALOME_InteractiveObject) IO = selected.First();
1409     showInfo( IO );
1410   }
1411 //   else {
1412 //     myBaseInfo->clear();
1413 //     myElemInfo->clear();
1414 //   }
1415 }
1416
1417 /*!
1418   \brief Activate dialog box
1419 */
1420 void SMESHGUI_MeshInfoDlg::activate()
1421 {
1422   SMESHGUI::GetSMESHGUI()->EmitSignalDeactivateDialog();
1423   SMESHGUI::GetSMESHGUI()->SetActiveDialogBox( this );
1424   myTabWidget->setEnabled( true );
1425   updateSelection();
1426 }
1427
1428 /*!
1429   \brief Deactivate dialog box
1430 */
1431 void SMESHGUI_MeshInfoDlg::deactivate()
1432 {
1433   myTabWidget->setEnabled( false );
1434   disconnect( SMESHGUI::selectionMgr(), SIGNAL( currentSelectionChanged() ), this, SLOT( updateInfo() ) );
1435 }
1436
1437 /*!
1438   \brief Called when users switches between node / element modes.
1439 */
1440 void SMESHGUI_MeshInfoDlg::modeChanged()
1441 {
1442   myID->clear();
1443   updateSelection();
1444 }
1445
1446 /*!
1447   \brief Caled when users prints mesh element ID in the corresponding field.
1448 */
1449 void SMESHGUI_MeshInfoDlg::idChanged()
1450 {
1451   SVTK_Selector* selector = SMESH::GetViewWindow()->GetSelector();
1452   if ( myActor && selector ) {
1453     Handle(SALOME_InteractiveObject) IO = myActor->getIO();
1454     TColStd_MapOfInteger ID;
1455     QSet<long> ids;
1456     QStringList idTxt = myID->text().split( " ", QString::SkipEmptyParts );
1457     foreach ( QString tid, idTxt ) {
1458       long id = tid.trimmed().toLong();
1459       const SMDS_MeshElement* e = myMode->checkedId() == ElemMode ? 
1460         myActor->GetObject()->GetMesh()->FindElement( id ) :
1461         myActor->GetObject()->GetMesh()->FindNode( id );
1462       if ( e ) {
1463         ID.Add( id );
1464         ids << id;
1465       }
1466     }
1467     selector->AddOrRemoveIndex( IO, ID, false );
1468     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow() )
1469       aViewWindow->highlight( IO, true, true );
1470     myElemInfo->showInfo( ids, myMode->checkedId() == ElemMode );
1471   }
1472 }