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