2 // File : SMESHGUI_MeshInfosDlg.cxx
3 // Created : Sat Jun 08 15:31:16 2002
4 // Author : Nicolas BARBEROU
8 // Copyright : EADS CCR 2002
11 #include "SMESHGUI_MeshInfosDlg.h"
14 #include "QAD_Application.h"
15 #include "QAD_Desktop.h"
16 #include "utilities.h"
19 #include <qgroupbox.h>
24 #include <qwhatsthis.h>
28 * Constructs a SMESHGUI_MeshInfosDlg which is a child of 'parent', with the
29 * name 'name' and widget flags set to 'f'
31 * The dialog will by default be modeless, unless you set 'modal' to
32 * TRUE to construct a modal dialog.
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 )
38 setName( "SMESHGUI_MeshInfosDlg" );
39 setCaption( tr( "SMESH_MESHINFO_TITLE" ) );
40 setSizeGripEnabled( TRUE );
42 SMESHGUI_MeshInfosDlgLayout = new QVBoxLayout( this );
43 SMESHGUI_MeshInfosDlgLayout->setSpacing( 6 );
44 SMESHGUI_MeshInfosDlgLayout->setMargin( 11 );
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 );
57 TextLabel11 = new QLabel( GroupBox1, "TextLabel11" );
58 TextLabel11->setMinimumWidth( 100 );
59 TextLabel11->setText( tr( "SMESH_MESHINFO_NODES" ) );
60 GroupBox1Layout->addWidget( TextLabel11, 0, 0 );
62 TextLabel12 = new QLabel( GroupBox1, "TextLabel12" );
63 TextLabel12->setMinimumWidth( 100 );
64 TextLabel12->setText( tr( "SMESH_MESHINFO_EDGES" ) );
65 GroupBox1Layout->addWidget( TextLabel12, 1, 0 );
67 TextLabel13 = new QLabel( GroupBox1, "TextLabel13" );
68 TextLabel13->setMinimumWidth( 100 );
69 GroupBox1Layout->addWidget( TextLabel13, 0, 1 );
71 TextLabel14 = new QLabel( GroupBox1, "TextLabel14" );
72 TextLabel14->setMinimumWidth( 100 );
73 GroupBox1Layout->addWidget( TextLabel14, 1, 1 );
74 SMESHGUI_MeshInfosDlgLayout->addWidget( GroupBox1 );
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 );
87 TextLabel21 = new QLabel( GroupBox2, "TextLabel21" );
88 TextLabel21->setMinimumWidth( 100 );
89 TextLabel21->setText( tr( "SMESH_MESHINFO_TRIANGLES" ) );
90 GroupBox2Layout->addWidget( TextLabel21, 0, 0 );
92 TextLabel22 = new QLabel( GroupBox2, "TextLabel22" );
93 TextLabel22->setMinimumWidth( 100 );
94 TextLabel22->setText( tr( "SMESH_MESHINFO_QUADRANGLES" ) );
95 GroupBox2Layout->addWidget( TextLabel22, 1, 0 );
97 TextLabel23 = new QLabel( GroupBox2, "TextLabel23" );
98 TextLabel23->setMinimumWidth( 100 );
99 GroupBox2Layout->addWidget( TextLabel23, 0, 1 );
101 TextLabel24 = new QLabel( GroupBox2, "TextLabel24" );
102 TextLabel24->setMinimumWidth( 100 );
103 GroupBox2Layout->addWidget( TextLabel24, 1, 1 );
104 SMESHGUI_MeshInfosDlgLayout->addWidget( GroupBox2 );
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 );
117 TextLabel31 = new QLabel( GroupBox3, "TextLabel31" );
118 TextLabel31->setMinimumWidth( 100 );
119 TextLabel31->setText( tr( "SMESH_MESHINFO_TETRAS" ) );
120 GroupBox3Layout->addWidget( TextLabel31, 0, 0 );
122 TextLabel32 = new QLabel( GroupBox3, "TextLabel32" );
123 TextLabel32->setMinimumWidth( 100 );
124 TextLabel32->setText( tr( "SMESH_MESHINFO_HEXAS" ) );
125 GroupBox3Layout->addWidget( TextLabel32, 1, 0 );
127 TextLabel33 = new QLabel( GroupBox3, "TextLabel33" );
128 TextLabel33->setMinimumWidth( 100 );
129 GroupBox3Layout->addWidget( TextLabel33, 0, 1 );
131 TextLabel34 = new QLabel( GroupBox3, "TextLabel34" );
132 TextLabel34->setMinimumWidth( 100 );
133 GroupBox3Layout->addWidget( TextLabel34, 1, 1 );
134 SMESHGUI_MeshInfosDlgLayout->addWidget( GroupBox3 );
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 );
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 /****************************************************************/
160 * Destroys the object and frees any allocated resources
162 SMESHGUI_MeshInfosDlg::~SMESHGUI_MeshInfosDlg()
164 // no need to delete child widgets, Qt does it all for us
167 //=================================================================================
170 //=================================================================================
171 void SMESHGUI_MeshInfosDlg::Init( SALOME_Selection* Sel )
175 mySMESHGUI = SMESHGUI::GetSMESHGUI() ;
176 myStudy = mySMESHGUI->GetActiveStudy()->getStudyDocument();
178 Engines::Component_var comp = QAD_Application::getDesktop()->getEngine("FactoryServer", "SMESH");
179 myCompMesh = SMESH::SMESH_Gen::_narrow(comp);
181 int nbSel = mySelection->IObjectCount();
183 TextLabel13->setText( "0" );
184 TextLabel14->setText( "0" );
185 TextLabel23->setText( "0" );
186 TextLabel24->setText( "0" );
187 TextLabel33->setText( "0" );
188 TextLabel34->setText( "0" );
190 //gets the selected mesh
192 Handle(SALOME_InteractiveObject) IObject = mySelection->firstIObject();
193 Standard_Boolean res;
194 myMesh = mySMESHGUI->ConvertIOinMesh( IObject, res );
199 mySMESHGUI->SetActiveDialogBox( (QDialog*)this ) ;
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() ) ) ;
208 /* Move widget on the botton right corner of main widget */
210 mySMESHGUI->DefineDlgPosition( this, x, y ) ;
212 this->show() ; /* Displays Dialog */
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)
225 long* lKey = (long*)key;
226 *lKey = (a < b) ? a : b;
227 *(++lKey) = (a < b) ? b : a;
230 //=================================================================================
231 // function : DumpMeshInfos()
233 //=================================================================================
234 void SMESHGUI_MeshInfosDlg::DumpMeshInfos()
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();
246 int nbOfTriangles = 0 ;
247 int nbOfQuadrangles = 0 ;
252 QMap<double, char> aMapOfEdges;
254 Standard_Boolean result;
255 SMESH_Actor* MeshActor = mySMESHGUI->FindActor(myMesh, result, true);
258 vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( MeshActor->DataSource );
259 vtkPoints *Pts = ugrid->GetPoints();
260 nbOfNodes = Pts->GetNumberOfPoints();
261 int nbCells = ugrid->GetNumberOfCells();
263 for ( int i = 0; i < nbCells; i++ ) {
264 vtkCell* cellPtr = ugrid->GetCell(i);
265 CellType = cellPtr->GetCellType();
277 for (int edgeNum = 0; edgeNum < 3; edgeNum++) {
278 vtkCell* edgePtr = cellPtr->GetEdge(edgeNum);
280 genEdgeKey(edgePtr->GetPointId(0), edgePtr->GetPointId(1), &anEdgeKey);
281 if (!aMapOfEdges.contains(anEdgeKey)) {
283 aMapOfEdges.insert(anEdgeKey, 0);
288 case 9: //Quadrangles
292 for (int edgeNum = 0; edgeNum < 4; edgeNum++) {
293 vtkCell* edgePtr = cellPtr->GetEdge(edgeNum);
295 genEdgeKey(edgePtr->GetPointId(0), edgePtr->GetPointId(1), &anEdgeKey);
296 if (!aMapOfEdges.contains(anEdgeKey)) {
298 aMapOfEdges.insert(anEdgeKey, 0);
303 case 10: //Tetraedras
307 for (int edgeNum = 0; edgeNum < 6; edgeNum++) {
308 vtkCell* edgePtr = cellPtr->GetEdge(edgeNum);
310 genEdgeKey(edgePtr->GetPointId(0), edgePtr->GetPointId(1), &anEdgeKey);
311 if (!aMapOfEdges.contains(anEdgeKey)) {
313 aMapOfEdges.insert(anEdgeKey, 0);
318 case 12: //Hexahedras
322 for (int edgeNum = 0; edgeNum < 12; edgeNum++) {
323 vtkCell* edgePtr = cellPtr->GetEdge(edgeNum);
325 genEdgeKey(edgePtr->GetPointId(0), edgePtr->GetPointId(1), &anEdgeKey);
326 if (!aMapOfEdges.contains(anEdgeKey)) {
328 aMapOfEdges.insert(anEdgeKey, 0);
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) );
345 //=================================================================================
346 // function : ClickOnOk()
348 //=================================================================================
349 void SMESHGUI_MeshInfosDlg::ClickOnOk()
351 disconnect( mySelection, 0, this, 0 );
352 mySMESHGUI->ResetState() ;
357 //=================================================================================
358 // function : SelectionIntoArgument()
359 // purpose : Called when selection has changed
360 //=================================================================================
361 void SMESHGUI_MeshInfosDlg::SelectionIntoArgument()
363 TextLabel13->setText( "0" );
364 TextLabel14->setText( "0" );
365 TextLabel23->setText( "0" );
366 TextLabel24->setText( "0" );
367 TextLabel33->setText( "0" );
368 TextLabel34->setText( "0" );
370 int nbSel = mySelection->IObjectCount();
372 Handle(SALOME_InteractiveObject) IObject = mySelection->firstIObject();
373 Standard_Boolean res;
374 myMesh = mySMESHGUI->ConvertIOinMesh( IObject, res );
382 //=================================================================================
383 // function : closeEvent()
385 //=================================================================================
386 void SMESHGUI_MeshInfosDlg::closeEvent( QCloseEvent* e )
388 disconnect( mySelection, 0, this, 0 );
389 mySMESHGUI->ResetState() ;
395 //=================================================================================
396 // function : enterEvent()
397 // purpose : when mouse enter onto the QWidget
398 //=================================================================================
399 void SMESHGUI_MeshInfosDlg::enterEvent( QEvent * )
401 ActivateThisDialog() ;
405 //=================================================================================
406 // function : DeactivateActiveDialog()
408 //=================================================================================
409 void SMESHGUI_MeshInfosDlg::DeactivateActiveDialog()
411 disconnect( mySelection, 0, this, 0 );
417 //=================================================================================
418 // function : ActivateThisDialog()
420 //=================================================================================
421 void SMESHGUI_MeshInfosDlg::ActivateThisDialog()
423 /* Emit a signal to deactivate any active dialog */
424 mySMESHGUI->EmitSignalDeactivateDialog() ;