Salome HOME
untabify
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_MeshInfosBox.cxx
1 //  Copyright (C) 2007-2008  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_MeshInfosBox.cxx
23 // Author : Edward AGAPOV, Open CASCADE S.A.S.
24 // SMESH includes
25 //
26 #include "SMESHGUI_MeshInfosBox.h"
27
28 #include "SMDSAbs_ElementType.hxx"
29
30 // Qt includes
31 #include <QFrame>
32 #include <QLabel>
33 #include <QGridLayout>
34
35 #define SPACING 6
36 #define MARGIN  11
37
38 #define COLONIZE(str)   (QString(str).contains(":") > 0 ? QString(str) : QString(str) + " :" )
39
40 static void addSeparator( QWidget* parent )
41 {
42   QGridLayout* l = qobject_cast<QGridLayout*>( parent->layout() );
43   int row  = l->rowCount();
44   int cols = l->columnCount();
45   for ( int i = 0; i < cols; i++ ) {
46     QFrame* hline = new QFrame( parent );
47     hline->setFrameStyle( QFrame::HLine | QFrame::Sunken );
48     l->addWidget( hline, row, i );
49   }
50 }
51
52 enum TCol {
53   COL_ALGO = 0, COL_SHAPE, COL_ERROR, COL_SHAPEID, COL_PUBLISHED, COL_BAD_MESH, NB_COLUMNS
54 };
55
56 // =========================================================================================
57 /*!
58  * \brief Box showing mesh info
59  */
60 // =========================================================================================
61
62 SMESHGUI_MeshInfosBox::SMESHGUI_MeshInfosBox(const bool full, QWidget* theParent)
63 : QGroupBox( tr("SMESH_MESHINFO_TITLE"), theParent ), myFull( full ),
64   myNbNode(0), my0DElem(0), myNbEdge(0), myNbLinEdge(0), myNbQuadEdge(0),
65   myNbTrai(0), myNbLinTrai(0), myNbQuadTrai(0), myNbQuad(0), myNbLinQuad(0),
66   myNbQuadQuad(0), myNbFace(0), myNbLinFace(0), myNbQuadFace(0), myNbPolyg(0),
67   myNbHexa(0), myNbLinHexa(0), myNbQuadHexa(0), myNbTetra(0), myNbLinTetra(0),
68   myNbQuadTetra(0), myNbPyra(0), myNbLinPyra(0), myNbQuadPyra(0), myNbPrism(0),
69   myNbLinPrism(0), myNbQuadPrism(0), myNbVolum(0), myNbLinVolum(0), myNbQuadVolum(0),
70   myNbPolyh(0)
71 {
72   QGridLayout* l = new QGridLayout(this);
73   l->setMargin( MARGIN );
74   l->setSpacing( SPACING );
75
76   QFont italic = font(); italic.setItalic(true);
77   QFont bold   = font(); bold.setBold(true);
78
79   QLabel* lab;
80   int row = 0;
81
82   // title
83   lab = new QLabel( this );
84   lab->setMinimumWidth(100); lab->setFont( italic );
85   l->addWidget( lab, row, 0 );
86   // --
87   lab = new QLabel(tr("SMESH_MESHINFO_ORDER0"), this );
88   lab->setMinimumWidth(100); lab->setFont( italic );
89   l->addWidget( lab, row, 1 );
90   // --
91   lab = new QLabel(tr("SMESH_MESHINFO_ORDER1"), this );
92   lab->setMinimumWidth(100); lab->setFont( italic );
93   l->addWidget( lab, row, 2 );
94   // --
95   lab = new QLabel(tr("SMESH_MESHINFO_ORDER2"), this );
96   lab->setMinimumWidth(100); lab->setFont( italic );
97   l->addWidget( lab, row, 3 );
98
99   if ( myFull )
100   {
101     // nodes
102     row = l->rowCount();         // retrieve current row count
103     // --
104     lab = new QLabel(COLONIZE(tr("SMESH_MESHINFO_NODES")), this );
105     lab->setFont( bold );
106     l->addWidget( lab,           row, 0 );
107     // --
108     myNbNode = new QLabel( this );
109     l->addWidget( myNbNode,      row, 1 );
110
111     addSeparator(this);          // add separator
112
113     // 0D elements
114     row = l->rowCount();         // retrieve current row count
115     // --
116     lab = new QLabel(COLONIZE(tr("SMESH_MESHINFO_0DELEMS")), this );
117     lab->setFont( bold );
118     l->addWidget( lab,           row, 0 );
119     // --
120     my0DElem = new QLabel( this );
121     l->addWidget( my0DElem,      row, 1 );
122
123     addSeparator(this);          // add separator
124
125     // edges
126     row = l->rowCount();         // retrieve current row count
127     // --
128     lab = new QLabel(COLONIZE(tr("SMESH_MESHINFO_EDGES")), this );
129     lab->setFont( bold );
130     l->addWidget( lab,           row, 0 );
131     // --
132     myNbEdge = new QLabel( this );
133     l->addWidget( myNbEdge,      row, 1 );
134     // --
135     myNbLinEdge = new QLabel( this );
136     l->addWidget( myNbLinEdge,   row, 2 );
137     // --
138     myNbQuadEdge = new QLabel( this );
139     l->addWidget( myNbQuadEdge,  row, 3 );
140
141     addSeparator(this);          // add separator
142
143     // faces
144     row = l->rowCount();         // retrieve current row count
145     // --
146     lab = new QLabel(COLONIZE(tr("SMESH_MESHINFO_FACES")), this);
147     lab->setFont( bold );
148     l->addWidget( lab,           row, 0 );
149     // --
150     myNbFace     = new QLabel( this );
151     l->addWidget( myNbFace,      row, 1 );
152     // --
153     myNbLinFace  = new QLabel( this );
154     l->addWidget( myNbLinFace,   row, 2 );
155     // --
156     myNbQuadFace = new QLabel( this );
157     l->addWidget( myNbQuadFace,  row, 3 );
158     // --
159     row++;                       // increment row count
160     // ... triangles
161     lab = new QLabel(COLONIZE(tr("SMESH_MESHINFO_TRIANGLES")), this );
162     l->addWidget( lab,           row, 0 );
163     // --
164     myNbTrai     = new QLabel( this );
165     l->addWidget( myNbTrai,      row, 1 );
166     // --
167     myNbLinTrai  = new QLabel( this );
168     l->addWidget( myNbLinTrai,   row, 2 );
169     // --
170     myNbQuadTrai = new QLabel( this );
171     l->addWidget( myNbQuadTrai,  row, 3 );
172     // --
173     row++;                       // increment row count
174     // ... quadrangles
175     lab = new QLabel(COLONIZE(tr("SMESH_MESHINFO_QUADRANGLES")), this );
176     l->addWidget( lab,           row, 0 );
177     // --
178     myNbQuad     = new QLabel( this );
179     l->addWidget( myNbQuad,      row, 1 );
180     // --
181     myNbLinQuad  = new QLabel( this );
182     l->addWidget( myNbLinQuad,   row, 2 );
183     // --
184     myNbQuadQuad = new QLabel( this );
185     l->addWidget( myNbQuadQuad,  row, 3 );
186     // --
187     row++;                       // increment row count
188     // ... poligones
189     lab = new QLabel(COLONIZE(tr("SMESH_MESHINFO_POLYGONES")), this );
190     l->addWidget( lab,           row, 0 );
191     myNbPolyg    = new QLabel( this );
192     l->addWidget( myNbPolyg,     row, 1 );
193
194     addSeparator(this);          // add separator
195
196     // volumes
197     row = l->rowCount();         // retrieve current row count
198     // --
199     lab = new QLabel(COLONIZE(tr("SMESH_MESHINFO_VOLUMES")), this);
200     lab->setFont( bold );
201     l->addWidget( lab,           row, 0 );
202     // --
203     myNbVolum     = new QLabel( this );
204     l->addWidget( myNbVolum,     row, 1 );
205     // --
206     myNbLinVolum  = new QLabel( this );
207     l->addWidget( myNbLinVolum,  row, 2 );
208     // --
209     myNbQuadVolum = new QLabel( this );
210     l->addWidget( myNbQuadVolum, row, 3 );
211     // --
212     row++;                       // increment row count
213     // ... tetras
214     lab = new QLabel(COLONIZE(tr("SMESH_MESHINFO_TETRAS")), this );
215     l->addWidget( lab,           row, 0 );
216     // --
217     myNbTetra     = new QLabel( this );
218     l->addWidget( myNbTetra,     row, 1 );
219     // --
220     myNbLinTetra  = new QLabel( this );
221     l->addWidget( myNbLinTetra,  row, 2 );
222     // --
223     myNbQuadTetra = new QLabel( this );
224     l->addWidget( myNbQuadTetra, row, 3 );
225     // --
226     row++;                       // increment row count
227     // ... hexas
228     lab = new QLabel(COLONIZE(tr("SMESH_MESHINFO_HEXAS")), this );
229     l->addWidget( lab,           row, 0 );
230     // --
231     myNbHexa      = new QLabel( this );
232     l->addWidget( myNbHexa,      row, 1 );
233     // --
234     myNbLinHexa   = new QLabel( this );
235     l->addWidget( myNbLinHexa,   row, 2 );
236     // --
237     myNbQuadHexa  = new QLabel( this );
238     l->addWidget( myNbQuadHexa,  row, 3 );
239     // --
240     row++;                       // increment row count
241     // ... pyras
242     lab = new QLabel(COLONIZE(tr("SMESH_MESHINFO_PYRAS")), this );
243     l->addWidget( lab,           row, 0 );
244     // --
245     myNbPyra      = new QLabel( this );
246     l->addWidget( myNbPyra,      row, 1 );
247     // --
248     myNbLinPyra   = new QLabel( this );
249     l->addWidget( myNbLinPyra,   row, 2 );
250     // --
251     myNbQuadPyra  = new QLabel( this );
252     l->addWidget( myNbQuadPyra,  row, 3 );
253     // --
254     row++;                       // increment row count
255     // ... prisms
256     lab = new QLabel(COLONIZE(tr("SMESH_MESHINFO_PRISMS")), this );
257     l->addWidget( lab,           row, 0 );
258     // --
259     myNbPrism     = new QLabel( this );
260     l->addWidget( myNbPrism,     row, 1 );
261     // --
262     myNbLinPrism  = new QLabel( this );
263     l->addWidget( myNbLinPrism,  row, 2 );
264     // --
265     myNbQuadPrism = new QLabel( this );
266     l->addWidget( myNbQuadPrism, row, 3 );
267     // --
268     row++;                       // increment row count
269     // ... polyedres
270     lab = new QLabel(COLONIZE(tr("SMESH_MESHINFO_POLYEDRES")), this );
271     l->addWidget( lab,           row, 0 );
272     // --
273     myNbPolyh     = new QLabel( this );
274     l->addWidget( myNbPolyh,     row, 1 );
275   }
276   else
277   {
278     // nodes
279     row = l->rowCount();         // retrieve current row count
280     // --
281     lab = new QLabel(COLONIZE(tr("SMESH_MESHINFO_NODES")), this );
282     l->addWidget( lab,           row, 0 );
283     // --
284     myNbNode      = new QLabel( this );
285     l->addWidget( myNbNode,      row, 1 );
286
287     // 0D elements
288     row = l->rowCount();         // retrieve current row count
289     // --
290     lab = new QLabel(COLONIZE(tr("SMESH_MESHINFO_0DELEMS")), this );
291     l->addWidget( lab,           row, 0 );
292     // --
293     my0DElem = new QLabel( this );
294     l->addWidget( my0DElem,      row, 1 );
295
296     addSeparator(this);          // add separator
297
298     // edges
299     row = l->rowCount();         // retrieve current row count
300     // --
301     lab = new QLabel(COLONIZE(tr("SMESH_MESHINFO_EDGES")), this );
302     l->addWidget( lab,           row, 0 );
303     // --
304     myNbEdge      = new QLabel( this );
305     l->addWidget( myNbEdge,      row, 1 );
306     // --
307     myNbLinEdge   = new QLabel( this );
308     l->addWidget( myNbLinEdge,   row, 2 );
309     // --
310     myNbQuadEdge  = new QLabel( this );
311     l->addWidget( myNbQuadEdge,  row, 3 );
312
313     // faces
314     row = l->rowCount();         // retrieve current row count
315     // --
316     lab = new QLabel(COLONIZE(tr("SMESH_MESHINFO_FACES")), this);
317     l->addWidget( lab,           row, 0 );
318     // --
319     myNbFace      = new QLabel( this );
320     l->addWidget( myNbFace,      row, 1 );
321     // --
322     myNbLinFace   = new QLabel( this );
323     l->addWidget( myNbLinFace,   row, 2 );
324     // --
325     myNbQuadFace  = new QLabel( this );
326     l->addWidget( myNbQuadFace,  row, 3 );
327
328     // volumes
329     row = l->rowCount();         // retrieve current row count
330     // --
331     lab = new QLabel(COLONIZE(tr("SMESH_MESHINFO_VOLUMES")), this);
332     l->addWidget( lab,           row, 0 );
333     // --
334     myNbVolum     = new QLabel( this );
335     l->addWidget( myNbVolum,     row, 1 );
336     // --
337     myNbLinVolum  = new QLabel( this );
338     l->addWidget( myNbLinVolum,  row, 2 );
339     // --
340     myNbQuadVolum = new QLabel( this );
341     l->addWidget( myNbQuadVolum, row, 3 );
342   }
343 }
344
345 // =========================================================================================
346 /*!
347  * \brief Set mesh info
348  */
349 // =========================================================================================
350
351 void SMESHGUI_MeshInfosBox::SetMeshInfo(const SMESH::long_array& theInfo)
352 {
353   // nodes
354   myNbNode     ->setText( QString("%1").arg( theInfo[SMDSEntity_Node] ));
355   
356   //0D elements
357   my0DElem     ->setText( QString("%1").arg( theInfo[SMDSEntity_0D] ));
358
359   // edges
360   myNbEdge     ->setText( QString("%1").arg( theInfo[SMDSEntity_Edge] +
361                                             theInfo[SMDSEntity_Quad_Edge] ));
362   myNbLinEdge  ->setText( QString("%1").arg( theInfo[SMDSEntity_Edge] ));
363   myNbQuadEdge ->setText( QString("%1").arg( theInfo[SMDSEntity_Quad_Edge] ));
364
365   // faces
366   myNbFace     ->setText( QString("%1").arg( theInfo[SMDSEntity_Triangle] +
367                                             theInfo[SMDSEntity_Quad_Triangle] +
368                                             theInfo[SMDSEntity_Quadrangle] +
369                                             theInfo[SMDSEntity_Quad_Quadrangle] +
370                                             theInfo[SMDSEntity_Polygon] ));
371   myNbLinFace  ->setText( QString("%1").arg( theInfo[SMDSEntity_Triangle] +
372                                             theInfo[SMDSEntity_Quadrangle] +
373                                             theInfo[SMDSEntity_Polygon] ));
374   myNbQuadFace ->setText( QString("%1").arg( theInfo[SMDSEntity_Quad_Triangle] +
375                                             theInfo[SMDSEntity_Quad_Quadrangle] ));
376
377   // volumes
378   myNbVolum    ->setText( QString("%1").arg( theInfo[SMDSEntity_Tetra] +
379                                             theInfo[SMDSEntity_Quad_Tetra] +
380                                             theInfo[SMDSEntity_Pyramid] +
381                                             theInfo[SMDSEntity_Quad_Pyramid] +
382                                             theInfo[SMDSEntity_Hexa] +
383                                             theInfo[SMDSEntity_Quad_Hexa] +
384                                             theInfo[SMDSEntity_Penta] +
385                                             theInfo[SMDSEntity_Quad_Penta] +
386                                             theInfo[SMDSEntity_Polyhedra] ));
387   myNbLinVolum ->setText( QString("%1").arg( theInfo[SMDSEntity_Tetra] +
388                                             theInfo[SMDSEntity_Pyramid] +
389                                             theInfo[SMDSEntity_Hexa] +
390                                             theInfo[SMDSEntity_Penta] +
391                                             theInfo[SMDSEntity_Polyhedra] ));
392   myNbQuadVolum->setText( QString("%1").arg( theInfo[SMDSEntity_Quad_Tetra] +
393                                             theInfo[SMDSEntity_Quad_Pyramid] +
394                                             theInfo[SMDSEntity_Quad_Hexa] +
395                                             theInfo[SMDSEntity_Quad_Penta] ));
396
397   if ( myFull )
398   {
399     // triangles
400     myNbTrai     ->setText( QString("%1").arg( theInfo[SMDSEntity_Triangle] +
401                                               theInfo[SMDSEntity_Quad_Triangle] ));
402     myNbLinTrai  ->setText( QString("%1").arg( theInfo[SMDSEntity_Triangle] ));
403     myNbQuadTrai ->setText( QString("%1").arg( theInfo[SMDSEntity_Quad_Triangle] ));
404     // quadrangles
405     myNbQuad     ->setText( QString("%1").arg( theInfo[SMDSEntity_Quadrangle] +
406                                               theInfo[SMDSEntity_Quad_Quadrangle] ));
407     myNbLinQuad  ->setText( QString("%1").arg( theInfo[SMDSEntity_Quadrangle] ));
408     myNbQuadQuad ->setText( QString("%1").arg( theInfo[SMDSEntity_Quad_Quadrangle] ));
409     // poligones
410     myNbPolyg    ->setText( QString("%1").arg( theInfo[SMDSEntity_Polygon] ));
411
412     // tetras
413     myNbTetra    ->setText( QString("%1").arg( theInfo[SMDSEntity_Tetra] +
414                                               theInfo[SMDSEntity_Quad_Tetra] ));
415     myNbLinTetra ->setText( QString("%1").arg( theInfo[SMDSEntity_Tetra] ));
416     myNbQuadTetra->setText( QString("%1").arg( theInfo[SMDSEntity_Quad_Tetra] ));
417     // hexas
418     myNbHexa     ->setText( QString("%1").arg( theInfo[SMDSEntity_Hexa] +
419                                               theInfo[SMDSEntity_Quad_Hexa] ));
420     myNbLinHexa  ->setText( QString("%1").arg( theInfo[SMDSEntity_Hexa] ));
421     myNbQuadHexa ->setText( QString("%1").arg( theInfo[SMDSEntity_Quad_Hexa] ));
422     // pyras
423     myNbPyra     ->setText( QString("%1").arg( theInfo[SMDSEntity_Pyramid] +
424                                             theInfo[SMDSEntity_Quad_Pyramid] ));
425     myNbLinPyra  ->setText( QString("%1").arg( theInfo[SMDSEntity_Pyramid] ));
426     myNbQuadPyra ->setText( QString("%1").arg( theInfo[SMDSEntity_Quad_Pyramid] ));
427     // prisms
428     myNbPrism    ->setText( QString("%1").arg( theInfo[SMDSEntity_Penta] +
429                                               theInfo[SMDSEntity_Quad_Penta] ));
430     myNbLinPrism ->setText( QString("%1").arg( theInfo[SMDSEntity_Penta] ));
431     myNbQuadPrism->setText( QString("%1").arg( theInfo[SMDSEntity_Quad_Penta] ));
432     // polyedres
433     myNbPolyh    ->setText( QString("%1").arg( theInfo[SMDSEntity_Polyhedra] ));
434   }
435 }