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