1 // SMESH SMESHGUI : GUI for SMESH component
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : SMESHGUI_MeshInfosDlg.cxx
25 // Author : Nicolas BARBEROU
30 #include "SMESHGUI_MeshInfosDlg.h"
33 #include "QAD_Application.h"
34 #include "QAD_Desktop.h"
35 #include "utilities.h"
38 #include <qgroupbox.h>
43 #include <qwhatsthis.h>
47 * Constructs a SMESHGUI_MeshInfosDlg which is a child of 'parent', with the
48 * name 'name' and widget flags set to 'f'
50 * The dialog will by default be modeless, unless you set 'modal' to
51 * TRUE to construct a modal dialog.
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 )
57 setName( "SMESHGUI_MeshInfosDlg" );
58 setCaption( tr( "SMESH_MESHINFO_TITLE" ) );
59 setSizeGripEnabled( TRUE );
61 SMESHGUI_MeshInfosDlgLayout = new QVBoxLayout( this );
62 SMESHGUI_MeshInfosDlgLayout->setSpacing( 6 );
63 SMESHGUI_MeshInfosDlgLayout->setMargin( 11 );
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 );
76 TextLabel11 = new QLabel( GroupBox1, "TextLabel11" );
77 TextLabel11->setMinimumWidth( 100 );
78 TextLabel11->setText( tr( "SMESH_MESHINFO_NODES" ) );
79 GroupBox1Layout->addWidget( TextLabel11, 0, 0 );
81 TextLabel12 = new QLabel( GroupBox1, "TextLabel12" );
82 TextLabel12->setMinimumWidth( 100 );
83 TextLabel12->setText( tr( "SMESH_MESHINFO_EDGES" ) );
84 GroupBox1Layout->addWidget( TextLabel12, 1, 0 );
86 TextLabel13 = new QLabel( GroupBox1, "TextLabel13" );
87 TextLabel13->setMinimumWidth( 100 );
88 GroupBox1Layout->addWidget( TextLabel13, 0, 1 );
90 TextLabel14 = new QLabel( GroupBox1, "TextLabel14" );
91 TextLabel14->setMinimumWidth( 100 );
92 GroupBox1Layout->addWidget( TextLabel14, 1, 1 );
93 SMESHGUI_MeshInfosDlgLayout->addWidget( GroupBox1 );
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 );
106 TextLabel21 = new QLabel( GroupBox2, "TextLabel21" );
107 TextLabel21->setMinimumWidth( 100 );
108 TextLabel21->setText( tr( "SMESH_MESHINFO_TRIANGLES" ) );
109 GroupBox2Layout->addWidget( TextLabel21, 0, 0 );
111 TextLabel22 = new QLabel( GroupBox2, "TextLabel22" );
112 TextLabel22->setMinimumWidth( 100 );
113 TextLabel22->setText( tr( "SMESH_MESHINFO_QUADRANGLES" ) );
114 GroupBox2Layout->addWidget( TextLabel22, 1, 0 );
116 TextLabel23 = new QLabel( GroupBox2, "TextLabel23" );
117 TextLabel23->setMinimumWidth( 100 );
118 GroupBox2Layout->addWidget( TextLabel23, 0, 1 );
120 TextLabel24 = new QLabel( GroupBox2, "TextLabel24" );
121 TextLabel24->setMinimumWidth( 100 );
122 GroupBox2Layout->addWidget( TextLabel24, 1, 1 );
123 SMESHGUI_MeshInfosDlgLayout->addWidget( GroupBox2 );
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 );
136 TextLabel31 = new QLabel( GroupBox3, "TextLabel31" );
137 TextLabel31->setMinimumWidth( 100 );
138 TextLabel31->setText( tr( "SMESH_MESHINFO_TETRAS" ) );
139 GroupBox3Layout->addWidget( TextLabel31, 0, 0 );
141 TextLabel32 = new QLabel( GroupBox3, "TextLabel32" );
142 TextLabel32->setMinimumWidth( 100 );
143 TextLabel32->setText( tr( "SMESH_MESHINFO_HEXAS" ) );
144 GroupBox3Layout->addWidget( TextLabel32, 1, 0 );
146 TextLabel33 = new QLabel( GroupBox3, "TextLabel33" );
147 TextLabel33->setMinimumWidth( 100 );
148 GroupBox3Layout->addWidget( TextLabel33, 0, 1 );
150 TextLabel34 = new QLabel( GroupBox3, "TextLabel34" );
151 TextLabel34->setMinimumWidth( 100 );
152 GroupBox3Layout->addWidget( TextLabel34, 1, 1 );
153 SMESHGUI_MeshInfosDlgLayout->addWidget( GroupBox3 );
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 );
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 /****************************************************************/
179 * Destroys the object and frees any allocated resources
181 SMESHGUI_MeshInfosDlg::~SMESHGUI_MeshInfosDlg()
183 // no need to delete child widgets, Qt does it all for us
186 //=================================================================================
189 //=================================================================================
190 void SMESHGUI_MeshInfosDlg::Init( SALOME_Selection* Sel )
194 mySMESHGUI = SMESHGUI::GetSMESHGUI() ;
195 myStudy = mySMESHGUI->GetActiveStudy()->getStudyDocument();
197 Engines::Component_var comp = QAD_Application::getDesktop()->getEngine("FactoryServer", "SMESH");
198 myCompMesh = SMESH::SMESH_Gen::_narrow(comp);
200 int nbSel = mySelection->IObjectCount();
202 TextLabel13->setText( "0" );
203 TextLabel14->setText( "0" );
204 TextLabel23->setText( "0" );
205 TextLabel24->setText( "0" );
206 TextLabel33->setText( "0" );
207 TextLabel34->setText( "0" );
209 //gets the selected mesh
211 Handle(SALOME_InteractiveObject) IObject = mySelection->firstIObject();
212 Standard_Boolean res;
213 myMesh = mySMESHGUI->ConvertIOinMesh( IObject, res );
218 mySMESHGUI->SetActiveDialogBox( (QDialog*)this ) ;
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() ) ) ;
227 /* Move widget on the botton right corner of main widget */
229 mySMESHGUI->DefineDlgPosition( this, x, y ) ;
231 this->show() ; /* Displays Dialog */
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)
244 long* lKey = (long*)key;
245 *lKey = (a < b) ? a : b;
246 *(++lKey) = (a < b) ? b : a;
249 //=================================================================================
250 // function : DumpMeshInfos()
252 //=================================================================================
253 void SMESHGUI_MeshInfosDlg::DumpMeshInfos()
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();
265 int nbOfTriangles = 0 ;
266 int nbOfQuadrangles = 0 ;
271 QMap<double, char> aMapOfEdges;
273 Standard_Boolean result;
274 SMESH_Actor* MeshActor = mySMESHGUI->FindActor(myMesh, result, true);
277 vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( MeshActor->DataSource );
278 vtkPoints *Pts = ugrid->GetPoints();
279 nbOfNodes = Pts->GetNumberOfPoints();
280 int nbCells = ugrid->GetNumberOfCells();
282 for ( int i = 0; i < nbCells; i++ ) {
283 vtkCell* cellPtr = ugrid->GetCell(i);
284 CellType = cellPtr->GetCellType();
296 for (int edgeNum = 0; edgeNum < 3; edgeNum++) {
297 vtkCell* edgePtr = cellPtr->GetEdge(edgeNum);
299 genEdgeKey(edgePtr->GetPointId(0), edgePtr->GetPointId(1), &anEdgeKey);
300 if (!aMapOfEdges.contains(anEdgeKey)) {
302 aMapOfEdges.insert(anEdgeKey, 0);
307 case 9: //Quadrangles
311 for (int edgeNum = 0; edgeNum < 4; edgeNum++) {
312 vtkCell* edgePtr = cellPtr->GetEdge(edgeNum);
314 genEdgeKey(edgePtr->GetPointId(0), edgePtr->GetPointId(1), &anEdgeKey);
315 if (!aMapOfEdges.contains(anEdgeKey)) {
317 aMapOfEdges.insert(anEdgeKey, 0);
322 case 10: //Tetraedras
326 for (int edgeNum = 0; edgeNum < 6; edgeNum++) {
327 vtkCell* edgePtr = cellPtr->GetEdge(edgeNum);
329 genEdgeKey(edgePtr->GetPointId(0), edgePtr->GetPointId(1), &anEdgeKey);
330 if (!aMapOfEdges.contains(anEdgeKey)) {
332 aMapOfEdges.insert(anEdgeKey, 0);
337 case 12: //Hexahedras
341 for (int edgeNum = 0; edgeNum < 12; edgeNum++) {
342 vtkCell* edgePtr = cellPtr->GetEdge(edgeNum);
344 genEdgeKey(edgePtr->GetPointId(0), edgePtr->GetPointId(1), &anEdgeKey);
345 if (!aMapOfEdges.contains(anEdgeKey)) {
347 aMapOfEdges.insert(anEdgeKey, 0);
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) );
364 //=================================================================================
365 // function : ClickOnOk()
367 //=================================================================================
368 void SMESHGUI_MeshInfosDlg::ClickOnOk()
370 disconnect( mySelection, 0, this, 0 );
371 mySMESHGUI->ResetState() ;
376 //=================================================================================
377 // function : SelectionIntoArgument()
378 // purpose : Called when selection has changed
379 //=================================================================================
380 void SMESHGUI_MeshInfosDlg::SelectionIntoArgument()
382 TextLabel13->setText( "0" );
383 TextLabel14->setText( "0" );
384 TextLabel23->setText( "0" );
385 TextLabel24->setText( "0" );
386 TextLabel33->setText( "0" );
387 TextLabel34->setText( "0" );
389 int nbSel = mySelection->IObjectCount();
391 Handle(SALOME_InteractiveObject) IObject = mySelection->firstIObject();
392 Standard_Boolean res;
393 myMesh = mySMESHGUI->ConvertIOinMesh( IObject, res );
401 //=================================================================================
402 // function : closeEvent()
404 //=================================================================================
405 void SMESHGUI_MeshInfosDlg::closeEvent( QCloseEvent* e )
407 disconnect( mySelection, 0, this, 0 );
408 mySMESHGUI->ResetState() ;
414 //=================================================================================
415 // function : enterEvent()
416 // purpose : when mouse enter onto the QWidget
417 //=================================================================================
418 void SMESHGUI_MeshInfosDlg::enterEvent( QEvent * )
420 ActivateThisDialog() ;
424 //=================================================================================
425 // function : DeactivateActiveDialog()
427 //=================================================================================
428 void SMESHGUI_MeshInfosDlg::DeactivateActiveDialog()
430 disconnect( mySelection, 0, this, 0 );
436 //=================================================================================
437 // function : ActivateThisDialog()
439 //=================================================================================
440 void SMESHGUI_MeshInfosDlg::ActivateThisDialog()
442 /* Emit a signal to deactivate any active dialog */
443 mySMESHGUI->EmitSignalDeactivateDialog() ;