Salome HOME
0020105: EDF 862 SMESH : Creation of the skin elements (2D) of a 3D Mesh
[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 {
65   QGridLayout* l = new QGridLayout(this);
66   l->setMargin( MARGIN );
67   l->setSpacing( SPACING );
68
69   QFont italic = font(); italic.setItalic(true);
70   QFont bold   = font(); bold.setBold(true);
71
72   QLabel* lab;
73   int row = 0;
74
75   // title
76   lab = new QLabel( this );
77   lab->setMinimumWidth(100); lab->setFont( italic );
78   l->addWidget( lab, row, 0 );
79   // --
80   lab = new QLabel(tr("SMESH_MESHINFO_ORDER0"), this );
81   lab->setMinimumWidth(100); lab->setFont( italic );
82   l->addWidget( lab, row, 1 );
83   // --
84   lab = new QLabel(tr("SMESH_MESHINFO_ORDER1"), this );
85   lab->setMinimumWidth(100); lab->setFont( italic );
86   l->addWidget( lab, row, 2 );
87   // --
88   lab = new QLabel(tr("SMESH_MESHINFO_ORDER2"), this );
89   lab->setMinimumWidth(100); lab->setFont( italic );
90   l->addWidget( lab, row, 3 );
91
92   if ( myFull )
93   {
94     // nodes
95     row = l->rowCount();         // retrieve current row count
96     // --
97     lab = new QLabel(COLONIZE(tr("SMESH_MESHINFO_NODES")), this );
98     lab->setFont( bold );
99     l->addWidget( lab,           row, 0 );
100     // --
101     myNbNode = new QLabel( this );
102     l->addWidget( myNbNode,      row, 1 );
103
104     addSeparator(this);          // add separator
105
106     // 0D elements
107     row = l->rowCount();         // retrieve current row count
108     // --
109     lab = new QLabel(COLONIZE(tr("SMESH_MESHINFO_0DELEMS")), this );
110     lab->setFont( bold );
111     l->addWidget( lab,           row, 0 );
112     // --
113     my0DElem = new QLabel( this );
114     l->addWidget( my0DElem,      row, 1 );
115
116     addSeparator(this);          // add separator
117
118     // edges
119     row = l->rowCount();         // retrieve current row count
120     // --
121     lab = new QLabel(COLONIZE(tr("SMESH_MESHINFO_EDGES")), this );
122     lab->setFont( bold );
123     l->addWidget( lab,           row, 0 );
124     // --
125     myNbEdge = new QLabel( this );
126     l->addWidget( myNbEdge,      row, 1 );
127     // --
128     myNbLinEdge = new QLabel( this );
129     l->addWidget( myNbLinEdge,   row, 2 );
130     // --
131     myNbQuadEdge = new QLabel( this );
132     l->addWidget( myNbQuadEdge,  row, 3 );
133
134     addSeparator(this);          // add separator
135
136     // faces
137     row = l->rowCount();         // retrieve current row count
138     // --
139     lab = new QLabel(COLONIZE(tr("SMESH_MESHINFO_FACES")), this);
140     lab->setFont( bold );
141     l->addWidget( lab,           row, 0 );
142     // --
143     myNbFace     = new QLabel( this );
144     l->addWidget( myNbFace,      row, 1 );
145     // --
146     myNbLinFace  = new QLabel( this );
147     l->addWidget( myNbLinFace,   row, 2 );
148     // --
149     myNbQuadFace = new QLabel( this );
150     l->addWidget( myNbQuadFace,  row, 3 );
151     // --
152     row++;                       // increment row count
153     // ... triangles
154     lab = new QLabel(COLONIZE(tr("SMESH_MESHINFO_TRIANGLES")), this );
155     l->addWidget( lab,           row, 0 );
156     // --
157     myNbTrai     = new QLabel( this );
158     l->addWidget( myNbTrai,      row, 1 );
159     // --
160     myNbLinTrai  = new QLabel( this );
161     l->addWidget( myNbLinTrai,   row, 2 );
162     // --
163     myNbQuadTrai = new QLabel( this );
164     l->addWidget( myNbQuadTrai,  row, 3 );
165     // --
166     row++;                       // increment row count
167     // ... quadrangles
168     lab = new QLabel(COLONIZE(tr("SMESH_MESHINFO_QUADRANGLES")), this );
169     l->addWidget( lab,           row, 0 );
170     // --
171     myNbQuad     = new QLabel( this );
172     l->addWidget( myNbQuad,      row, 1 );
173     // --
174     myNbLinQuad  = new QLabel( this );
175     l->addWidget( myNbLinQuad,   row, 2 );
176     // --
177     myNbQuadQuad = new QLabel( this );
178     l->addWidget( myNbQuadQuad,  row, 3 );
179     // --
180     row++;                       // increment row count
181     // ... poligones
182     lab = new QLabel(COLONIZE(tr("SMESH_MESHINFO_POLYGONES")), this );
183     l->addWidget( lab,           row, 0 );
184     myNbPolyg    = new QLabel( this );
185     l->addWidget( myNbPolyg,     row, 1 );
186
187     addSeparator(this);          // add separator
188
189     // volumes
190     row = l->rowCount();         // retrieve current row count
191     // --
192     lab = new QLabel(COLONIZE(tr("SMESH_MESHINFO_VOLUMES")), this);
193     lab->setFont( bold );
194     l->addWidget( lab,           row, 0 );
195     // --
196     myNbVolum     = new QLabel( this );
197     l->addWidget( myNbVolum,     row, 1 );
198     // --
199     myNbLinVolum  = new QLabel( this );
200     l->addWidget( myNbLinVolum,  row, 2 );
201     // --
202     myNbQuadVolum = new QLabel( this );
203     l->addWidget( myNbQuadVolum, row, 3 );
204     // --
205     row++;                       // increment row count
206     // ... tetras
207     lab = new QLabel(COLONIZE(tr("SMESH_MESHINFO_TETRAS")), this );
208     l->addWidget( lab,           row, 0 );
209     // --
210     myNbTetra     = new QLabel( this );
211     l->addWidget( myNbTetra,     row, 1 );
212     // --
213     myNbLinTetra  = new QLabel( this );
214     l->addWidget( myNbLinTetra,  row, 2 );
215     // --
216     myNbQuadTetra = new QLabel( this );
217     l->addWidget( myNbQuadTetra, row, 3 );
218     // --
219     row++;                       // increment row count
220     // ... hexas
221     lab = new QLabel(COLONIZE(tr("SMESH_MESHINFO_HEXAS")), this );
222     l->addWidget( lab,           row, 0 );
223     // --
224     myNbHexa      = new QLabel( this );
225     l->addWidget( myNbHexa,      row, 1 );
226     // --
227     myNbLinHexa   = new QLabel( this );
228     l->addWidget( myNbLinHexa,   row, 2 );
229     // --
230     myNbQuadHexa  = new QLabel( this );
231     l->addWidget( myNbQuadHexa,  row, 3 );
232     // --
233     row++;                       // increment row count
234     // ... pyras
235     lab = new QLabel(COLONIZE(tr("SMESH_MESHINFO_PYRAS")), this );
236     l->addWidget( lab,           row, 0 );
237     // --
238     myNbPyra      = new QLabel( this );
239     l->addWidget( myNbPyra,      row, 1 );
240     // --
241     myNbLinPyra   = new QLabel( this );
242     l->addWidget( myNbLinPyra,   row, 2 );
243     // --
244     myNbQuadPyra  = new QLabel( this );
245     l->addWidget( myNbQuadPyra,  row, 3 );
246     // --
247     row++;                       // increment row count
248     // ... prisms
249     lab = new QLabel(COLONIZE(tr("SMESH_MESHINFO_PRISMS")), this );
250     l->addWidget( lab,           row, 0 );
251     // --
252     myNbPrism     = new QLabel( this );
253     l->addWidget( myNbPrism,     row, 1 );
254     // --
255     myNbLinPrism  = new QLabel( this );
256     l->addWidget( myNbLinPrism,  row, 2 );
257     // --
258     myNbQuadPrism = new QLabel( this );
259     l->addWidget( myNbQuadPrism, row, 3 );
260     // --
261     row++;                       // increment row count
262     // ... polyedres
263     lab = new QLabel(COLONIZE(tr("SMESH_MESHINFO_POLYEDRES")), this );
264     l->addWidget( lab,           row, 0 );
265     // --
266     myNbPolyh     = new QLabel( this );
267     l->addWidget( myNbPolyh,     row, 1 );
268   }
269   else
270   {
271     // nodes
272     row = l->rowCount();         // retrieve current row count
273     // --
274     lab = new QLabel(COLONIZE(tr("SMESH_MESHINFO_NODES")), this );
275     l->addWidget( lab,           row, 0 );
276     // --
277     myNbNode      = new QLabel( this );
278     l->addWidget( myNbNode,      row, 1 );
279
280     // edges
281     row = l->rowCount();         // retrieve current row count
282     // --
283     lab = new QLabel(COLONIZE(tr("SMESH_MESHINFO_EDGES")), this );
284     l->addWidget( lab,           row, 0 );
285     // --
286     myNbEdge      = new QLabel( this );
287     l->addWidget( myNbEdge,      row, 1 );
288     // --
289     myNbLinEdge   = new QLabel( this );
290     l->addWidget( myNbLinEdge,   row, 2 );
291     // --
292     myNbQuadEdge  = new QLabel( this );
293     l->addWidget( myNbQuadEdge,  row, 3 );
294
295     // faces
296     row = l->rowCount();         // retrieve current row count
297     // --
298     lab = new QLabel(COLONIZE(tr("SMESH_MESHINFO_FACES")), this);
299     l->addWidget( lab,           row, 0 );
300     // --
301     myNbFace      = new QLabel( this );
302     l->addWidget( myNbFace,      row, 1 );
303     // --
304     myNbLinFace   = new QLabel( this );
305     l->addWidget( myNbLinFace,   row, 2 );
306     // --
307     myNbQuadFace  = new QLabel( this );
308     l->addWidget( myNbQuadFace,  row, 3 );
309
310     // volumes
311     row = l->rowCount();         // retrieve current row count
312     // --
313     lab = new QLabel(COLONIZE(tr("SMESH_MESHINFO_VOLUMES")), this);
314     l->addWidget( lab,           row, 0 );
315     // --
316     myNbVolum     = new QLabel( this );
317     l->addWidget( myNbVolum,     row, 1 );
318     // --
319     myNbLinVolum  = new QLabel( this );
320     l->addWidget( myNbLinVolum,  row, 2 );
321     // --
322     myNbQuadVolum = new QLabel( this );
323     l->addWidget( myNbQuadVolum, row, 3 );
324   }
325 }
326
327 // =========================================================================================
328 /*!
329  * \brief Set mesh info
330  */
331 // =========================================================================================
332
333 void SMESHGUI_MeshInfosBox::SetMeshInfo(const SMESH::long_array& theInfo)
334 {
335   // nodes
336   myNbNode     ->setText( QString("%1").arg( theInfo[SMDSEntity_Node] ));
337   
338   //0D elements
339   my0DElem     ->setText( QString("%1").arg( theInfo[SMDSEntity_0D] ));
340
341   // edges
342   myNbEdge     ->setText( QString("%1").arg( theInfo[SMDSEntity_Edge] +
343                                             theInfo[SMDSEntity_Quad_Edge] ));
344   myNbLinEdge  ->setText( QString("%1").arg( theInfo[SMDSEntity_Edge] ));
345   myNbQuadEdge ->setText( QString("%1").arg( theInfo[SMDSEntity_Quad_Edge] ));
346
347   // faces
348   myNbFace     ->setText( QString("%1").arg( theInfo[SMDSEntity_Triangle] +
349                                             theInfo[SMDSEntity_Quad_Triangle] +
350                                             theInfo[SMDSEntity_Quadrangle] +
351                                             theInfo[SMDSEntity_Quad_Quadrangle] +
352                                             theInfo[SMDSEntity_Polygon] ));
353   myNbLinFace  ->setText( QString("%1").arg( theInfo[SMDSEntity_Triangle] +
354                                             theInfo[SMDSEntity_Quadrangle] +
355                                             theInfo[SMDSEntity_Polygon] ));
356   myNbQuadFace ->setText( QString("%1").arg( theInfo[SMDSEntity_Quad_Triangle] +
357                                             theInfo[SMDSEntity_Quad_Quadrangle] ));
358
359   // volumes
360   myNbVolum    ->setText( QString("%1").arg( theInfo[SMDSEntity_Tetra] +
361                                             theInfo[SMDSEntity_Quad_Tetra] +
362                                             theInfo[SMDSEntity_Pyramid] +
363                                             theInfo[SMDSEntity_Quad_Pyramid] +
364                                             theInfo[SMDSEntity_Hexa] +
365                                             theInfo[SMDSEntity_Quad_Hexa] +
366                                             theInfo[SMDSEntity_Penta] +
367                                             theInfo[SMDSEntity_Quad_Penta] +
368                                             theInfo[SMDSEntity_Polyhedra] ));
369   myNbLinVolum ->setText( QString("%1").arg( theInfo[SMDSEntity_Tetra] +
370                                             theInfo[SMDSEntity_Pyramid] +
371                                             theInfo[SMDSEntity_Hexa] +
372                                             theInfo[SMDSEntity_Penta] +
373                                             theInfo[SMDSEntity_Polyhedra] ));
374   myNbQuadVolum->setText( QString("%1").arg( theInfo[SMDSEntity_Quad_Tetra] +
375                                             theInfo[SMDSEntity_Quad_Pyramid] +
376                                             theInfo[SMDSEntity_Quad_Hexa] +
377                                             theInfo[SMDSEntity_Quad_Penta] ));
378
379   if ( myFull )
380   {
381     // triangles
382     myNbTrai     ->setText( QString("%1").arg( theInfo[SMDSEntity_Triangle] +
383                                               theInfo[SMDSEntity_Quad_Triangle] ));
384     myNbLinTrai  ->setText( QString("%1").arg( theInfo[SMDSEntity_Triangle] ));
385     myNbQuadTrai ->setText( QString("%1").arg( theInfo[SMDSEntity_Quad_Triangle] ));
386     // quadrangles
387     myNbQuad     ->setText( QString("%1").arg( theInfo[SMDSEntity_Quadrangle] +
388                                               theInfo[SMDSEntity_Quad_Quadrangle] ));
389     myNbLinQuad  ->setText( QString("%1").arg( theInfo[SMDSEntity_Quadrangle] ));
390     myNbQuadQuad ->setText( QString("%1").arg( theInfo[SMDSEntity_Quad_Quadrangle] ));
391     // poligones
392     myNbPolyg    ->setText( QString("%1").arg( theInfo[SMDSEntity_Polygon] ));
393
394     // tetras
395     myNbTetra    ->setText( QString("%1").arg( theInfo[SMDSEntity_Tetra] +
396                                               theInfo[SMDSEntity_Quad_Tetra] ));
397     myNbLinTetra ->setText( QString("%1").arg( theInfo[SMDSEntity_Tetra] ));
398     myNbQuadTetra->setText( QString("%1").arg( theInfo[SMDSEntity_Quad_Tetra] ));
399     // hexas
400     myNbHexa     ->setText( QString("%1").arg( theInfo[SMDSEntity_Hexa] +
401                                               theInfo[SMDSEntity_Quad_Hexa] ));
402     myNbLinHexa  ->setText( QString("%1").arg( theInfo[SMDSEntity_Hexa] ));
403     myNbQuadHexa ->setText( QString("%1").arg( theInfo[SMDSEntity_Quad_Hexa] ));
404     // pyras
405     myNbPyra     ->setText( QString("%1").arg( theInfo[SMDSEntity_Pyramid] +
406                                             theInfo[SMDSEntity_Quad_Pyramid] ));
407     myNbLinPyra  ->setText( QString("%1").arg( theInfo[SMDSEntity_Pyramid] ));
408     myNbQuadPyra ->setText( QString("%1").arg( theInfo[SMDSEntity_Quad_Pyramid] ));
409     // prisms
410     myNbPrism    ->setText( QString("%1").arg( theInfo[SMDSEntity_Penta] +
411                                               theInfo[SMDSEntity_Quad_Penta] ));
412     myNbLinPrism ->setText( QString("%1").arg( theInfo[SMDSEntity_Penta] ));
413     myNbQuadPrism->setText( QString("%1").arg( theInfo[SMDSEntity_Quad_Penta] ));
414     // polyedres
415     myNbPolyh    ->setText( QString("%1").arg( theInfo[SMDSEntity_Polyhedra] ));
416   }
417 }