Salome HOME
Remove OCC_LIBS from LDFLAGS
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_MeshInfosDlg.cxx
1 //  SMESH SMESHGUI : GUI for SMESH component
2 //
3 //  Copyright (C) 2003  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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //
24 //  File   : SMESHGUI_MeshInfosDlg.cxx
25 //  Author : Nicolas BARBEROU
26 //  Module : SMESH
27 //  $Header$
28
29 using namespace std;
30 #include "SMESHGUI_MeshInfosDlg.h"
31
32 #include "SMESHGUI.h"
33 #include "QAD_Application.h"
34 #include "QAD_Desktop.h"
35 #include "utilities.h"
36
37 // QT Includes
38 #include <qgroupbox.h>
39 #include <qlabel.h>
40 #include <qlayout.h>
41 #include <qvariant.h>
42 #include <qtooltip.h>
43 #include <qwhatsthis.h>
44 #include <qmap.h>
45
46 /* 
47  *  Constructs a SMESHGUI_MeshInfosDlg which is a child of 'parent', with the 
48  *  name 'name' and widget flags set to 'f' 
49  *
50  *  The dialog will by default be modeless, unless you set 'modal' to
51  *  TRUE to construct a modal dialog.
52  */
53 SMESHGUI_MeshInfosDlg::SMESHGUI_MeshInfosDlg( QWidget* parent,  const char* name, SALOME_Selection* Sel, bool modal, WFlags fl )
54     : QDialog( parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
55 {
56     if ( !name )
57         setName( "SMESHGUI_MeshInfosDlg" );
58     setCaption( tr( "SMESH_MESHINFO_TITLE"  ) );
59     setSizeGripEnabled( TRUE );
60
61     SMESHGUI_MeshInfosDlgLayout = new QVBoxLayout( this ); 
62     SMESHGUI_MeshInfosDlgLayout->setSpacing( 6 );
63     SMESHGUI_MeshInfosDlgLayout->setMargin( 11 );
64
65     /****************************************************************/
66     GroupBox1 = new QGroupBox( this, "GroupBox1" );
67     GroupBox1->setTitle( tr( "SMESH_MESHINFO_NB1D"  ) );
68     GroupBox1->setColumnLayout(0, Qt::Vertical );
69     GroupBox1->layout()->setSpacing( 0 );
70     GroupBox1->layout()->setMargin( 0 );
71     QGridLayout* GroupBox1Layout = new QGridLayout( GroupBox1->layout() );
72     GroupBox1Layout->setAlignment( Qt::AlignTop );
73     GroupBox1Layout->setSpacing( 6 );
74     GroupBox1Layout->setMargin( 11 );
75
76     TextLabel11 = new QLabel( GroupBox1, "TextLabel11" );
77     TextLabel11->setMinimumWidth( 100 );
78     TextLabel11->setText( tr( "SMESH_MESHINFO_NODES"  ) );
79     GroupBox1Layout->addWidget( TextLabel11, 0, 0 );
80
81     TextLabel12 = new QLabel( GroupBox1, "TextLabel12" );
82     TextLabel12->setMinimumWidth( 100 );
83     TextLabel12->setText( tr( "SMESH_MESHINFO_EDGES"  ) );
84     GroupBox1Layout->addWidget( TextLabel12, 1, 0 );
85
86     TextLabel13 = new QLabel( GroupBox1, "TextLabel13" );
87     TextLabel13->setMinimumWidth( 100 );
88     GroupBox1Layout->addWidget( TextLabel13, 0, 1 );
89
90     TextLabel14 = new QLabel( GroupBox1, "TextLabel14" );
91     TextLabel14->setMinimumWidth( 100 );
92     GroupBox1Layout->addWidget( TextLabel14, 1, 1 );
93     SMESHGUI_MeshInfosDlgLayout->addWidget( GroupBox1 );
94
95     /****************************************************************/
96     GroupBox2 = new QGroupBox( this, "GroupBox2" );
97     GroupBox2->setTitle( tr( "SMESH_MESHINFO_NB2D"  ) );
98     GroupBox2->setColumnLayout(0, Qt::Vertical );
99     GroupBox2->layout()->setSpacing( 0 );
100     GroupBox2->layout()->setMargin( 0 );
101     QGridLayout* GroupBox2Layout = new QGridLayout( GroupBox2->layout() );
102     GroupBox2Layout->setAlignment( Qt::AlignTop );
103     GroupBox2Layout->setSpacing( 6 );
104     GroupBox2Layout->setMargin( 11 );
105
106     TextLabel21 = new QLabel( GroupBox2, "TextLabel21" );
107     TextLabel21->setMinimumWidth( 100 );
108     TextLabel21->setText( tr( "SMESH_MESHINFO_TRIANGLES"  ) );
109     GroupBox2Layout->addWidget( TextLabel21, 0, 0 );
110
111     TextLabel22 = new QLabel( GroupBox2, "TextLabel22" );
112     TextLabel22->setMinimumWidth( 100 );
113     TextLabel22->setText( tr( "SMESH_MESHINFO_QUADRANGLES"  ) );
114     GroupBox2Layout->addWidget( TextLabel22, 1, 0 );
115
116     TextLabel23 = new QLabel( GroupBox2, "TextLabel23" );
117     TextLabel23->setMinimumWidth( 100 );
118     GroupBox2Layout->addWidget( TextLabel23, 0, 1 );
119     
120     TextLabel24 = new QLabel( GroupBox2, "TextLabel24" );
121     TextLabel24->setMinimumWidth( 100 );
122     GroupBox2Layout->addWidget( TextLabel24, 1, 1 );
123     SMESHGUI_MeshInfosDlgLayout->addWidget( GroupBox2 );
124
125     /****************************************************************/
126     GroupBox3 = new QGroupBox( this, "GroupBox3" );
127     GroupBox3->setTitle( tr( "SMESH_MESHINFO_NB3D"  ) );
128     GroupBox3->setColumnLayout(0, Qt::Vertical );
129     GroupBox3->layout()->setSpacing( 0 );
130     GroupBox3->layout()->setMargin( 0 );
131     QGridLayout* GroupBox3Layout = new QGridLayout( GroupBox3->layout() );
132     GroupBox3Layout->setAlignment( Qt::AlignTop );
133     GroupBox3Layout->setSpacing( 6 );
134     GroupBox3Layout->setMargin( 11 );
135
136     TextLabel31 = new QLabel( GroupBox3, "TextLabel31" );
137     TextLabel31->setMinimumWidth( 100 );
138     TextLabel31->setText( tr( "SMESH_MESHINFO_TETRAS"  ) );
139     GroupBox3Layout->addWidget( TextLabel31, 0, 0 );
140
141     TextLabel32 = new QLabel( GroupBox3, "TextLabel32" );
142     TextLabel32->setMinimumWidth( 100 );
143     TextLabel32->setText( tr( "SMESH_MESHINFO_HEXAS"  ) );
144     GroupBox3Layout->addWidget( TextLabel32, 1, 0 );
145
146     TextLabel33 = new QLabel( GroupBox3, "TextLabel33" );
147     TextLabel33->setMinimumWidth( 100 );
148     GroupBox3Layout->addWidget( TextLabel33, 0, 1 );
149
150     TextLabel34 = new QLabel( GroupBox3, "TextLabel34" );
151     TextLabel34->setMinimumWidth( 100 );
152     GroupBox3Layout->addWidget( TextLabel34, 1, 1 );
153     SMESHGUI_MeshInfosDlgLayout->addWidget( GroupBox3 );
154
155     /****************************************************************/
156     QGroupBox* GroupButtons = new QGroupBox( this, "GroupButtons" );
157     GroupButtons->setColumnLayout(0, Qt::Vertical );
158     GroupButtons->layout()->setSpacing( 0 );
159     GroupButtons->layout()->setMargin( 0 );
160     QGridLayout* GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
161     GroupButtonsLayout->setAlignment( Qt::AlignTop );
162     GroupButtonsLayout->setSpacing( 6 );
163     GroupButtonsLayout->setMargin( 11 );
164
165     GroupButtonsLayout->addItem( new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum ), 0, 0 );
166     buttonOk = new QPushButton( GroupButtons, "buttonOk" );
167     buttonOk->setText( tr( "SMESH_BUT_OK"  ) );
168     buttonOk->setAutoDefault( TRUE );
169     buttonOk->setDefault( TRUE );
170     GroupButtonsLayout->addWidget( buttonOk, 0, 1 );
171     GroupButtonsLayout->addItem( new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum ), 0, 2 );
172     SMESHGUI_MeshInfosDlgLayout->addWidget( GroupButtons );
173     /****************************************************************/
174
175     Init( Sel ) ; 
176 }
177
178 /*  
179  *  Destroys the object and frees any allocated resources
180  */
181 SMESHGUI_MeshInfosDlg::~SMESHGUI_MeshInfosDlg()
182 {
183     // no need to delete child widgets, Qt does it all for us
184 }
185
186 //=================================================================================
187 // function : Init()
188 // purpose  :
189 //=================================================================================
190 void SMESHGUI_MeshInfosDlg::Init( SALOME_Selection* Sel )
191 {  
192   mySelection = Sel ;
193
194   mySMESHGUI = SMESHGUI::GetSMESHGUI() ;
195   myStudy = mySMESHGUI->GetActiveStudy()->getStudyDocument();
196
197   Engines::Component_var comp = QAD_Application::getDesktop()->getEngine("FactoryServer", "SMESH");
198   myCompMesh = SMESH::SMESH_Gen::_narrow(comp);
199
200   int nbSel = mySelection->IObjectCount();
201
202   TextLabel13->setText( "0" );
203   TextLabel14->setText( "0" );
204   TextLabel23->setText( "0" );
205   TextLabel24->setText( "0" );
206   TextLabel33->setText( "0" );
207   TextLabel34->setText( "0" );
208
209   //gets the selected mesh
210   if ( nbSel == 1 ) {
211     Handle(SALOME_InteractiveObject) IObject = mySelection->firstIObject();
212     Standard_Boolean res;
213     myMesh = mySMESHGUI->ConvertIOinMesh( IObject, res );
214     if ( res )
215       DumpMeshInfos();
216   }
217
218   mySMESHGUI->SetActiveDialogBox( (QDialog*)this ) ;
219
220   /* signals and slots connections */
221   connect( buttonOk,    SIGNAL( clicked() ),                      this, SLOT( ClickOnOk() ) );
222   connect( mySMESHGUI,  SIGNAL( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) ) ;
223   connect( mySelection, SIGNAL( currentSelectionChanged() ),      this, SLOT( SelectionIntoArgument() ) );
224   /* to close dialog if study change */
225   connect( mySMESHGUI,  SIGNAL ( SignalCloseAllDialogs() ),       this, SLOT( ClickOnOk() ) ) ;
226  
227   /* Move widget on the botton right corner of main widget */
228   int x, y ;
229   mySMESHGUI->DefineDlgPosition( this, x, y ) ;
230   this->move( x, y ) ;
231   this->show() ; /* Displays Dialog */ 
232
233   return ;
234 }
235
236 //=================================================================================
237 // function : genEdgeKey
238 // purpose  : edge counting helper;
239 //            packs two long integers into one 8-byte value (treated as double by the caller);
240 //            the order of arguments is insignificant
241 //=================================================================================
242 void genEdgeKey(long a, long b, void* key)
243 {
244   long* lKey = (long*)key;
245   *lKey     = (a < b) ? a : b;
246   *(++lKey) = (a < b) ? b : a;
247 }
248
249 //=================================================================================
250 // function : DumpMeshInfos()
251 // purpose  :
252 //=================================================================================
253 void SMESHGUI_MeshInfosDlg::DumpMeshInfos()
254 {
255   int nbOfNodes = myMesh->NbNodes();
256   int nbOfEdges = myMesh->NbEdges();
257   int nbOfTriangles = myMesh->NbTriangles();
258   int nbOfQuadrangles = myMesh->NbQuadrangles();
259   int nbOfTetras = myMesh->NbTetras();
260   int nbOfHexas = myMesh->NbHexas();
261
262   /*
263   int nbOfNodes = 0 ;
264   int nbOfEdges = 0 ;
265   int nbOfTriangles = 0 ;
266   int nbOfQuadrangles = 0 ;
267   int nbOfTetras = 0 ;
268   int nbOfHexas = 0 ;
269   int nbCells = 0 ;
270   int CellType = 0 ;
271   QMap<double, char> aMapOfEdges;
272
273   Standard_Boolean result;
274   SMESH_Actor* MeshActor = mySMESHGUI->FindActor(myMesh, result, true);
275
276   if ( result ) {
277     vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( MeshActor->DataSource );
278     vtkPoints *Pts = ugrid->GetPoints();
279     nbOfNodes = Pts->GetNumberOfPoints();
280     int nbCells = ugrid->GetNumberOfCells();
281
282     for ( int i = 0; i < nbCells; i++ ) {
283       vtkCell* cellPtr = ugrid->GetCell(i);
284       CellType = cellPtr->GetCellType();
285       switch (CellType)
286         {
287         case 3: //Edges
288           {
289             nbOfEdges++;
290             break;
291           }
292         case 5: //Triangles
293           {
294             nbOfTriangles++;
295             
296             for (int edgeNum = 0; edgeNum < 3; edgeNum++) {
297               vtkCell* edgePtr = cellPtr->GetEdge(edgeNum);
298               double anEdgeKey;
299               genEdgeKey(edgePtr->GetPointId(0), edgePtr->GetPointId(1), &anEdgeKey);
300               if (!aMapOfEdges.contains(anEdgeKey)) {
301                 nbOfEdges++;
302                 aMapOfEdges.insert(anEdgeKey, 0);
303               }
304             }
305             break;
306           }
307         case 9: //Quadrangles
308           {
309             nbOfQuadrangles++;
310             
311             for (int edgeNum = 0; edgeNum < 4; edgeNum++) {
312               vtkCell* edgePtr = cellPtr->GetEdge(edgeNum);
313               double anEdgeKey;
314               genEdgeKey(edgePtr->GetPointId(0), edgePtr->GetPointId(1), &anEdgeKey);
315               if (!aMapOfEdges.contains(anEdgeKey)) {
316                 nbOfEdges++;
317                 aMapOfEdges.insert(anEdgeKey, 0);
318               }
319             }
320             break;
321           }
322         case 10: //Tetraedras
323           {
324             nbOfTetras++;
325
326             for (int edgeNum = 0; edgeNum < 6; edgeNum++) {
327               vtkCell* edgePtr = cellPtr->GetEdge(edgeNum);
328               double anEdgeKey;
329               genEdgeKey(edgePtr->GetPointId(0), edgePtr->GetPointId(1), &anEdgeKey);
330               if (!aMapOfEdges.contains(anEdgeKey)) {
331                 nbOfEdges++;
332                 aMapOfEdges.insert(anEdgeKey, 0);
333               }
334             }
335             break;
336           }
337         case 12: //Hexahedras
338           {
339             nbOfHexas++;
340
341             for (int edgeNum = 0; edgeNum < 12; edgeNum++) {
342               vtkCell* edgePtr = cellPtr->GetEdge(edgeNum);
343               double anEdgeKey;
344               genEdgeKey(edgePtr->GetPointId(0), edgePtr->GetPointId(1), &anEdgeKey);
345               if (!aMapOfEdges.contains(anEdgeKey)) {
346                 nbOfEdges++;
347                 aMapOfEdges.insert(anEdgeKey, 0);
348               }
349             }
350             break;
351           }
352         }
353     }
354   }
355   */
356   TextLabel13->setText( tr( "%1" ).arg(nbOfNodes) );
357   TextLabel14->setText( tr( "%1" ).arg(nbOfEdges) );
358   TextLabel23->setText( tr( "%1" ).arg(nbOfTriangles) );
359   TextLabel24->setText( tr( "%1" ).arg(nbOfQuadrangles) );
360   TextLabel33->setText( tr( "%1" ).arg(nbOfTetras) );
361   TextLabel34->setText( tr( "%1" ).arg(nbOfHexas) );
362 }
363
364 //=================================================================================
365 // function : ClickOnOk()
366 // purpose  :
367 //=================================================================================
368 void SMESHGUI_MeshInfosDlg::ClickOnOk()
369 {
370   disconnect( mySelection, 0, this, 0 );
371   mySMESHGUI->ResetState() ;
372   reject() ;
373   return ;
374 }
375
376 //=================================================================================
377 // function : SelectionIntoArgument()
378 // purpose  : Called when selection has changed
379 //=================================================================================
380 void SMESHGUI_MeshInfosDlg::SelectionIntoArgument()
381 {
382   TextLabel13->setText( "0" );
383   TextLabel14->setText( "0" );
384   TextLabel23->setText( "0" );
385   TextLabel24->setText( "0" );
386   TextLabel33->setText( "0" );
387   TextLabel34->setText( "0" );
388
389   int nbSel = mySelection->IObjectCount();
390   if ( nbSel == 1 ) {
391     Handle(SALOME_InteractiveObject) IObject = mySelection->firstIObject();
392     Standard_Boolean res;
393     myMesh = mySMESHGUI->ConvertIOinMesh( IObject, res );
394     if ( res ) 
395       DumpMeshInfos();
396   }
397   return ; 
398 }
399
400
401 //=================================================================================
402 // function : closeEvent()
403 // purpose  :
404 //=================================================================================
405 void SMESHGUI_MeshInfosDlg::closeEvent( QCloseEvent* e )
406 {
407   disconnect( mySelection, 0, this, 0 );
408   mySMESHGUI->ResetState() ;
409   reject() ;
410   return ;
411 }
412
413
414 //=================================================================================
415 // function : enterEvent()
416 // purpose  : when mouse enter onto the QWidget
417 //=================================================================================
418 void SMESHGUI_MeshInfosDlg::enterEvent( QEvent *  )
419 {
420   ActivateThisDialog() ;
421 }
422
423
424 //=================================================================================
425 // function : DeactivateActiveDialog()
426 // purpose  :
427 //=================================================================================
428 void SMESHGUI_MeshInfosDlg::DeactivateActiveDialog()
429 {
430   disconnect( mySelection, 0, this, 0 );
431
432   return ;
433 }
434
435
436 //=================================================================================
437 // function : ActivateThisDialog()
438 // purpose  :
439 //=================================================================================
440 void SMESHGUI_MeshInfosDlg::ActivateThisDialog()
441 {
442   /* Emit a signal to deactivate any active dialog */
443   mySMESHGUI->EmitSignalDeactivateDialog() ;
444
445   return ;
446 }
447