Salome HOME
17f653938d46537dcdbbc4f6d0a356c1c95d00a4
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_MeshInfosBox.cxx
1 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 // File   : SMESHGUI_MeshInfosBox.cxx
21 // Author : Edward AGAPOV, Open CASCADE S.A.S.
22 // SMESH includes
23 //
24 #include "SMESHGUI_MeshInfosBox.h"
25
26 #include "SMDSAbs_ElementType.hxx"
27
28 // Qt includes
29 #include <QFrame>
30 #include <QLabel>
31 #include <QGridLayout>
32
33 #define SPACING 6
34 #define MARGIN  11
35
36 #define COLONIZE(str)   (QString(str).contains(":") > 0 ? QString(str) : QString(str) + " :" )
37
38 static void addSeparator( QWidget* parent )
39 {
40   QGridLayout* l = qobject_cast<QGridLayout*>( parent->layout() );
41   int row  = l->rowCount();
42   int cols = l->columnCount();
43   for ( int i = 0; i < cols; i++ ) {
44     QFrame* hline = new QFrame( parent );
45     hline->setFrameStyle( QFrame::HLine | QFrame::Sunken );
46     l->addWidget( hline, row, i );
47   }
48 }
49
50 enum TCol {
51   COL_ALGO = 0, COL_SHAPE, COL_ERROR, COL_SHAPEID, COL_PUBLISHED, COL_BAD_MESH, NB_COLUMNS
52 };
53
54 // =========================================================================================
55 /*!
56  * \brief Box showing mesh info
57  */
58 // =========================================================================================
59
60 SMESHGUI_MeshInfosBox::SMESHGUI_MeshInfosBox(const bool full, QWidget* theParent)
61 : QGroupBox( tr("SMESH_MESHINFO_TITLE"), theParent ), myFull( full ),
62   myNbNode(0),
63   my0DElem(0),
64   myBall(0),
65   myNbEdge(0), myNbLinEdge(0), myNbQuadEdge(0),
66   myNbTrai(0), myNbLinTrai(0), myNbQuadTrai(0),
67   myNbQuad(0), myNbLinQuad(0), myNbQuadQuad(0),
68   myNbFace(0), myNbLinFace(0), myNbQuadFace(0),
69   myNbPolyg(0),
70   myNbHexa(0), myNbLinHexa(0), myNbQuadHexa(0),
71   myNbTetra(0),myNbLinTetra(0),myNbQuadTetra(0),
72   myNbPyra(0), myNbLinPyra(0), myNbQuadPyra(0),
73   myNbPrism(0),myNbLinPrism(0), myNbQuadPrism(0),
74   myNbVolum(0), myNbLinVolum(0), myNbQuadVolum(0),
75   myNbHexaPrism(0),
76   myNbPolyh(0)
77 {
78   QGridLayout* l = new QGridLayout(this);
79   l->setMargin( MARGIN );
80   l->setSpacing( SPACING );
81
82   QFont italic = font(); italic.setItalic(true);
83   QFont bold   = font(); bold.setBold(true);
84
85   QLabel* lab;
86   int row = 0;
87
88   // title
89   lab = new QLabel( this );
90   lab->setMinimumWidth(100); lab->setFont( italic );
91   l->addWidget( lab, row, 0 );
92   // --
93   lab = new QLabel(tr("SMESH_MESHINFO_ORDER0"), this );
94   lab->setMinimumWidth(100); lab->setFont( italic );
95   l->addWidget( lab, row, 1 );
96   // --
97   lab = new QLabel(tr("SMESH_MESHINFO_ORDER1"), this );
98   lab->setMinimumWidth(100); lab->setFont( italic );
99   l->addWidget( lab, row, 2 );
100   // --
101   lab = new QLabel(tr("SMESH_MESHINFO_ORDER2"), this );
102   lab->setMinimumWidth(100); lab->setFont( italic );
103   l->addWidget( lab, row, 3 );
104
105   if ( myFull )
106   {
107     // nodes
108     row = l->rowCount();         // retrieve current row count
109     // --
110     lab = new QLabel(COLONIZE(tr("SMESH_MESHINFO_NODES")), this );
111     lab->setFont( bold );
112     l->addWidget( lab,           row, 0 );
113     // --
114     myNbNode = new QLabel( this );
115     l->addWidget( myNbNode,      row, 1 );
116
117     addSeparator(this);          // add separator
118
119     // 0D elements
120     row = l->rowCount();         // retrieve current row count
121     // --
122     lab = new QLabel(COLONIZE(tr("SMESH_MESHINFO_0DELEMS")), this );
123     lab->setFont( bold );
124     l->addWidget( lab,           row, 0 );
125     // --
126     my0DElem = new QLabel( this );
127     l->addWidget( my0DElem,      row, 1 );
128
129     addSeparator(this);          // add separator
130
131     // balls
132     row = l->rowCount();         // retrieve current row count
133     // --
134     lab = new QLabel(COLONIZE(tr("SMESH_MESHINFO_BALLS")), this );
135     lab->setFont( bold );
136     l->addWidget( lab,           row, 0 );
137     // --
138     myBall = new QLabel( this );
139     l->addWidget( myBall,      row, 1 );
140
141     addSeparator(this);          // add separator
142
143     // edges
144     row = l->rowCount();         // retrieve current row count
145     // --
146     lab = new QLabel(COLONIZE(tr("SMESH_MESHINFO_EDGES")), this );
147     lab->setFont( bold );
148     l->addWidget( lab,           row, 0 );
149     // --
150     myNbEdge = new QLabel( this );
151     l->addWidget( myNbEdge,      row, 1 );
152     // --
153     myNbLinEdge = new QLabel( this );
154     l->addWidget( myNbLinEdge,   row, 2 );
155     // --
156     myNbQuadEdge = new QLabel( this );
157     l->addWidget( myNbQuadEdge,  row, 3 );
158
159     addSeparator(this);          // add separator
160
161     // faces
162     row = l->rowCount();         // retrieve current row count
163     // --
164     lab = new QLabel(COLONIZE(tr("SMESH_MESHINFO_FACES")), this);
165     lab->setFont( bold );
166     l->addWidget( lab,           row, 0 );
167     // --
168     myNbFace     = new QLabel( this );
169     l->addWidget( myNbFace,      row, 1 );
170     // --
171     myNbLinFace  = new QLabel( this );
172     l->addWidget( myNbLinFace,   row, 2 );
173     // --
174     myNbQuadFace = new QLabel( this );
175     l->addWidget( myNbQuadFace,  row, 3 );
176     // --
177     row++;                       // increment row count
178     // ... triangles
179     lab = new QLabel(COLONIZE(tr("SMESH_MESHINFO_TRIANGLES")), this );
180     l->addWidget( lab,           row, 0 );
181     // --
182     myNbTrai     = new QLabel( this );
183     l->addWidget( myNbTrai,      row, 1 );
184     // --
185     myNbLinTrai  = new QLabel( this );
186     l->addWidget( myNbLinTrai,   row, 2 );
187     // --
188     myNbQuadTrai = new QLabel( this );
189     l->addWidget( myNbQuadTrai,  row, 3 );
190     // --
191     row++;                       // increment row count
192     // ... quadrangles
193     lab = new QLabel(COLONIZE(tr("SMESH_MESHINFO_QUADRANGLES")), this );
194     l->addWidget( lab,           row, 0 );
195     // --
196     myNbQuad     = new QLabel( this );
197     l->addWidget( myNbQuad,      row, 1 );
198     // --
199     myNbLinQuad  = new QLabel( this );
200     l->addWidget( myNbLinQuad,   row, 2 );
201     // --
202     myNbQuadQuad = new QLabel( this );
203     l->addWidget( myNbQuadQuad,  row, 3 );
204     // --
205     row++;                       // increment row count
206     // ... poligones
207     lab = new QLabel(COLONIZE(tr("SMESH_MESHINFO_POLYGONES")), this );
208     l->addWidget( lab,           row, 0 );
209     myNbPolyg    = new QLabel( this );
210     l->addWidget( myNbPolyg,     row, 1 );
211
212     addSeparator(this);          // add separator
213
214     // volumes
215     row = l->rowCount();         // retrieve current row count
216     // --
217     lab = new QLabel(COLONIZE(tr("SMESH_MESHINFO_VOLUMES")), this);
218     lab->setFont( bold );
219     l->addWidget( lab,           row, 0 );
220     // --
221     myNbVolum     = new QLabel( this );
222     l->addWidget( myNbVolum,     row, 1 );
223     // --
224     myNbLinVolum  = new QLabel( this );
225     l->addWidget( myNbLinVolum,  row, 2 );
226     // --
227     myNbQuadVolum = new QLabel( this );
228     l->addWidget( myNbQuadVolum, row, 3 );
229     // --
230     row++;                       // increment row count
231     // ... tetras
232     lab = new QLabel(COLONIZE(tr("SMESH_MESHINFO_TETRAS")), this );
233     l->addWidget( lab,           row, 0 );
234     // --
235     myNbTetra     = new QLabel( this );
236     l->addWidget( myNbTetra,     row, 1 );
237     // --
238     myNbLinTetra  = new QLabel( this );
239     l->addWidget( myNbLinTetra,  row, 2 );
240     // --
241     myNbQuadTetra = new QLabel( this );
242     l->addWidget( myNbQuadTetra, row, 3 );
243     // --
244     row++;                       // increment row count
245     // ... hexas
246     lab = new QLabel(COLONIZE(tr("SMESH_MESHINFO_HEXAS")), this );
247     l->addWidget( lab,           row, 0 );
248     // --
249     myNbHexa      = new QLabel( this );
250     l->addWidget( myNbHexa,      row, 1 );
251     // --
252     myNbLinHexa   = new QLabel( this );
253     l->addWidget( myNbLinHexa,   row, 2 );
254     // --
255     myNbQuadHexa  = new QLabel( this );
256     l->addWidget( myNbQuadHexa,  row, 3 );
257     // --
258     row++;                       // increment row count
259     // ... pyras
260     lab = new QLabel(COLONIZE(tr("SMESH_MESHINFO_PYRAS")), this );
261     l->addWidget( lab,           row, 0 );
262     // --
263     myNbPyra      = new QLabel( this );
264     l->addWidget( myNbPyra,      row, 1 );
265     // --
266     myNbLinPyra   = new QLabel( this );
267     l->addWidget( myNbLinPyra,   row, 2 );
268     // --
269     myNbQuadPyra  = new QLabel( this );
270     l->addWidget( myNbQuadPyra,  row, 3 );
271     // --
272     row++;                       // increment row count
273     // ... prisms
274     lab = new QLabel(COLONIZE(tr("SMESH_MESHINFO_PRISMS")), this );
275     l->addWidget( lab,           row, 0 );
276     // --
277     myNbPrism     = new QLabel( this );
278     l->addWidget( myNbPrism,     row, 1 );
279     // --
280     myNbLinPrism  = new QLabel( this );
281     l->addWidget( myNbLinPrism,  row, 2 );
282     // --
283     myNbQuadPrism = new QLabel( this );
284     l->addWidget( myNbQuadPrism, row, 3 );
285     // --
286     row++;                       // increment row count
287     // ... hexa prisms
288     lab = new QLabel(COLONIZE(tr("SMESH_MESHINFO_HEXAPRISM")), this );
289     l->addWidget( lab,           row, 0 );
290     // --
291     myNbHexaPrism     = new QLabel( this );
292     l->addWidget( myNbHexaPrism, row, 1 );
293     // --
294     row++;                       // increment row count
295     // ... polyedres
296     lab = new QLabel(COLONIZE(tr("SMESH_MESHINFO_POLYEDRES")), this );
297     l->addWidget( lab,           row, 0 );
298     // --
299     myNbPolyh     = new QLabel( this );
300     l->addWidget( myNbPolyh,     row, 1 );
301   }
302   else
303   {
304     // nodes
305     row = l->rowCount();         // retrieve current row count
306     // --
307     lab = new QLabel(COLONIZE(tr("SMESH_MESHINFO_NODES")), this );
308     l->addWidget( lab,           row, 0 );
309     // --
310     myNbNode      = new QLabel( this );
311     l->addWidget( myNbNode,      row, 1 );
312
313     // 0D elements
314     row = l->rowCount();         // retrieve current row count
315     // --
316     lab = new QLabel(COLONIZE(tr("SMESH_MESHINFO_0DELEMS")), this );
317     l->addWidget( lab,           row, 0 );
318     // --
319     my0DElem = new QLabel( this );
320     l->addWidget( my0DElem,      row, 1 );
321
322     addSeparator(this);          // add separator
323
324     // edges
325     row = l->rowCount();         // retrieve current row count
326     // --
327     lab = new QLabel(COLONIZE(tr("SMESH_MESHINFO_EDGES")), this );
328     l->addWidget( lab,           row, 0 );
329     // --
330     myNbEdge      = new QLabel( this );
331     l->addWidget( myNbEdge,      row, 1 );
332     // --
333     myNbLinEdge   = new QLabel( this );
334     l->addWidget( myNbLinEdge,   row, 2 );
335     // --
336     myNbQuadEdge  = new QLabel( this );
337     l->addWidget( myNbQuadEdge,  row, 3 );
338
339     // faces
340     row = l->rowCount();         // retrieve current row count
341     // --
342     lab = new QLabel(COLONIZE(tr("SMESH_MESHINFO_FACES")), this);
343     l->addWidget( lab,           row, 0 );
344     // --
345     myNbFace      = new QLabel( this );
346     l->addWidget( myNbFace,      row, 1 );
347     // --
348     myNbLinFace   = new QLabel( this );
349     l->addWidget( myNbLinFace,   row, 2 );
350     // --
351     myNbQuadFace  = new QLabel( this );
352     l->addWidget( myNbQuadFace,  row, 3 );
353
354     // volumes
355     row = l->rowCount();         // retrieve current row count
356     // --
357     lab = new QLabel(COLONIZE(tr("SMESH_MESHINFO_VOLUMES")), this);
358     l->addWidget( lab,           row, 0 );
359     // --
360     myNbVolum     = new QLabel( this );
361     l->addWidget( myNbVolum,     row, 1 );
362     // --
363     myNbLinVolum  = new QLabel( this );
364     l->addWidget( myNbLinVolum,  row, 2 );
365     // --
366     myNbQuadVolum = new QLabel( this );
367     l->addWidget( myNbQuadVolum, row, 3 );
368   }
369 }
370
371 // =========================================================================================
372 /*!
373  * \brief Set mesh info
374  */
375 // =========================================================================================
376
377 void SMESHGUI_MeshInfosBox::SetMeshInfo(const SMESH::long_array& theInfo)
378 {
379   // nodes
380   myNbNode     ->setText( QString("%1").arg( theInfo[SMDSEntity_Node] ));
381
382   //0D elements
383   my0DElem     ->setText( QString("%1").arg( theInfo[SMDSEntity_0D] ));
384
385   //balls
386   myBall       ->setText( QString("%1").arg( theInfo[SMDSEntity_Ball] ));
387
388   // edges
389   myNbEdge     ->setText( QString("%1").arg( theInfo[SMDSEntity_Edge] +
390                                              theInfo[SMDSEntity_Quad_Edge] ));
391   myNbLinEdge  ->setText( QString("%1").arg( theInfo[SMDSEntity_Edge] ));
392   myNbQuadEdge ->setText( QString("%1").arg( theInfo[SMDSEntity_Quad_Edge] ));
393
394   // faces
395   myNbFace     ->setText( QString("%1").arg( theInfo[SMDSEntity_Triangle] +
396                                              theInfo[SMDSEntity_Quad_Triangle] +
397                                              theInfo[SMDSEntity_Quadrangle] +
398                                              theInfo[SMDSEntity_Quad_Quadrangle] +
399                                              theInfo[SMDSEntity_BiQuad_Quadrangle] +
400                                              theInfo[SMDSEntity_Polygon] ));
401   myNbLinFace  ->setText( QString("%1").arg( theInfo[SMDSEntity_Triangle] +
402                                              theInfo[SMDSEntity_Quadrangle] +
403                                              theInfo[SMDSEntity_Polygon] ));
404   myNbQuadFace ->setText( QString("%1").arg( theInfo[SMDSEntity_Quad_Triangle] +
405                                              theInfo[SMDSEntity_Quad_Quadrangle] +
406                                              theInfo[SMDSEntity_BiQuad_Quadrangle] ));
407
408   // volumes
409   myNbVolum    ->setText( QString("%1").arg( theInfo[SMDSEntity_Tetra] +
410                                              theInfo[SMDSEntity_Quad_Tetra] +
411                                              theInfo[SMDSEntity_Pyramid] +
412                                              theInfo[SMDSEntity_Quad_Pyramid] +
413                                              theInfo[SMDSEntity_Hexa] +
414                                              theInfo[SMDSEntity_Quad_Hexa] +
415                                              theInfo[SMDSEntity_TriQuad_Hexa] +
416                                              theInfo[SMDSEntity_Penta] +
417                                              theInfo[SMDSEntity_Quad_Penta] +
418                                              theInfo[SMDSEntity_Hexagonal_Prism] +
419                                              theInfo[SMDSEntity_Polyhedra] ));
420   myNbLinVolum ->setText( QString("%1").arg( theInfo[SMDSEntity_Tetra] +
421                                              theInfo[SMDSEntity_Pyramid] +
422                                              theInfo[SMDSEntity_Hexa] +
423                                              theInfo[SMDSEntity_Penta] +
424                                              theInfo[SMDSEntity_Polyhedra] ));
425   myNbQuadVolum->setText( QString("%1").arg( theInfo[SMDSEntity_Quad_Tetra] +
426                                              theInfo[SMDSEntity_Quad_Pyramid] +
427                                              theInfo[SMDSEntity_Quad_Hexa] +
428                                              theInfo[SMDSEntity_TriQuad_Hexa] +
429                                              theInfo[SMDSEntity_Quad_Penta] ));
430
431   if ( myFull )
432   {
433     // triangles
434     myNbTrai     ->setText( QString("%1").arg( theInfo[SMDSEntity_Triangle] +
435                                                theInfo[SMDSEntity_Quad_Triangle] ));
436     myNbLinTrai  ->setText( QString("%1").arg( theInfo[SMDSEntity_Triangle] ));
437     myNbQuadTrai ->setText( QString("%1").arg( theInfo[SMDSEntity_Quad_Triangle] ));
438     // quadrangles
439     myNbQuad     ->setText( QString("%1").arg( theInfo[SMDSEntity_Quadrangle] +
440                                                theInfo[SMDSEntity_Quad_Quadrangle] +
441                                                theInfo[SMDSEntity_BiQuad_Quadrangle] ));
442     myNbLinQuad  ->setText( QString("%1").arg( theInfo[SMDSEntity_Quadrangle] ));
443     myNbQuadQuad ->setText( QString("%1").arg( theInfo[SMDSEntity_Quad_Quadrangle] +
444                                                theInfo[SMDSEntity_BiQuad_Quadrangle]));
445     // poligones
446     myNbPolyg    ->setText( QString("%1").arg( theInfo[SMDSEntity_Polygon] ));
447
448     // tetras
449     myNbTetra    ->setText( QString("%1").arg( theInfo[SMDSEntity_Tetra] +
450                                                theInfo[SMDSEntity_Quad_Tetra] ));
451     myNbLinTetra ->setText( QString("%1").arg( theInfo[SMDSEntity_Tetra] ));
452     myNbQuadTetra->setText( QString("%1").arg( theInfo[SMDSEntity_Quad_Tetra] ));
453     // hexas
454     myNbHexa     ->setText( QString("%1").arg( theInfo[SMDSEntity_Hexa] +
455                                                theInfo[SMDSEntity_TriQuad_Hexa],
456                                                theInfo[SMDSEntity_Quad_Hexa] ));
457     myNbLinHexa  ->setText( QString("%1").arg( theInfo[SMDSEntity_Hexa] ));
458     myNbQuadHexa ->setText( QString("%1").arg( theInfo[SMDSEntity_Quad_Hexa] +
459                                                theInfo[SMDSEntity_TriQuad_Hexa] ));
460     // pyras
461     myNbPyra     ->setText( QString("%1").arg( theInfo[SMDSEntity_Pyramid] +
462                                                theInfo[SMDSEntity_Quad_Pyramid] ));
463     myNbLinPyra  ->setText( QString("%1").arg( theInfo[SMDSEntity_Pyramid] ));
464     myNbQuadPyra ->setText( QString("%1").arg( theInfo[SMDSEntity_Quad_Pyramid] ));
465     // prisms
466     myNbPrism    ->setText( QString("%1").arg( theInfo[SMDSEntity_Penta] +
467                                                theInfo[SMDSEntity_Quad_Penta] ));
468     myNbLinPrism ->setText( QString("%1").arg( theInfo[SMDSEntity_Penta] ));
469     myNbQuadPrism->setText( QString("%1").arg( theInfo[SMDSEntity_Quad_Penta] ));
470     // octahedra
471     myNbHexaPrism->setText( QString("%1").arg( theInfo[ SMDSEntity_Hexagonal_Prism ]));
472     // polyedres
473     myNbPolyh    ->setText( QString("%1").arg( theInfo[SMDSEntity_Polyhedra] ));
474   }
475 }