Salome HOME
Update comments for ExportMED / ExportToMED methods
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_StandardMeshInfosDlg.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_StandardMeshInfosDlg.cxx
25 //  Author : Michael ZORIN
26 //  Module : SMESH
27 //  $Header$
28
29 // QT Includes
30 #include <qgroupbox.h>
31 #include <qlabel.h>
32 #include <qlayout.h>
33 #include <qlineedit.h>
34 #include <qtextbrowser.h>
35 #include <qmap.h>
36 #include <qpushbutton.h>
37
38 #include "QAD_Application.h"
39 #include "QAD_Desktop.h"
40 #include "QAD_WaitCursor.h"
41
42 #include "SMESHGUI_StandardMeshInfosDlg.h"
43 #include "SMESHGUI_Utils.h"
44 #include "SMESHGUI_MeshUtils.h"
45 #include "SMESHGUI.h"
46
47 #include "SMESH.hxx"
48
49 // IDL Headers
50 #include "SALOMEconfig.h"
51 #include CORBA_SERVER_HEADER(SMESH_Mesh)
52 #include CORBA_SERVER_HEADER(SMESH_Group)
53 #include CORBA_SERVER_HEADER(GEOM_Gen)
54
55 #include "utilities.h"
56
57 using namespace std;
58
59
60 //=================================================================================
61 /*!
62  *  SMESHGUI_StandardMeshInfosDlg::SMESHGUI_StandardMeshInfosDlg
63  * 
64  *  Constructor
65  */
66 //=================================================================================
67 SMESHGUI_StandardMeshInfosDlg::SMESHGUI_StandardMeshInfosDlg( QWidget* parent,  const char* name, bool modal, WFlags fl )
68      : QDialog( parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu | WDestructiveClose )
69 {
70   if ( !name )
71       setName( "SMESHGUI_StandardMeshInfosDlg" );
72   setCaption( tr( "SMESH_STANDARD_MESHINFO_TITLE"  ) );
73   setSizeGripEnabled( TRUE );
74
75   myStartSelection = true;
76   myIsActiveWindow = true;
77
78   // dialog layout
79   QGridLayout* aDlgLayout = new QGridLayout( this ); 
80   aDlgLayout->setSpacing( 6 );
81   aDlgLayout->setMargin( 11 );
82   
83   // mesh group box
84   myMeshGroup = new QGroupBox( this, "myMeshGroup" );
85   myMeshGroup->setTitle( tr( "SMESH_MESH" ) );
86   myMeshGroup->setColumnLayout(0, Qt::Vertical );
87   myMeshGroup->layout()->setSpacing( 0 );
88   myMeshGroup->layout()->setMargin( 0 );
89   QGridLayout* myMeshGroupLayout = new QGridLayout( myMeshGroup->layout() );
90   myMeshGroupLayout->setAlignment( Qt::AlignTop );
91   myMeshGroupLayout->setSpacing( 6 );
92   myMeshGroupLayout->setMargin( 11 );
93   
94   // select button, label and line edit with mesh name
95   myNameLab = new QLabel( myMeshGroup, "myNameLab" );
96   myNameLab->setText( tr( "SMESH_NAME"  ) );
97   myMeshGroupLayout->addWidget( myNameLab, 0, 0 );
98
99   QPixmap image0( QAD_Desktop::getResourceManager()->loadPixmap( "SMESH",tr( "ICON_SELECT" ) ) );
100   mySelectBtn = new QPushButton( myMeshGroup, "mySelectBtn" );
101   mySelectBtn->setPixmap( image0 );
102   mySelectBtn->setSizePolicy( QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ) );
103   myMeshGroupLayout->addWidget( mySelectBtn, 0, 1 );
104   
105   myMeshLine = new QLineEdit( myMeshGroup, "myMeshLine" );
106   myMeshGroupLayout->addWidget( myMeshLine, 0, 2 );
107   
108   aDlgLayout->addWidget( myMeshGroup, 0, 0 );
109
110   // information group box
111   myInfoGroup  = new QGroupBox( this, "myInfoGroup" );
112   myInfoGroup->setTitle( tr( "SMESH_INFORMATION" ) );
113   myInfoGroup->setColumnLayout(0, Qt::Vertical );
114   myInfoGroup->layout()->setSpacing( 0 );
115   myInfoGroup->layout()->setMargin( 0 );
116   QGridLayout* myInfoGroupLayout = new QGridLayout( myInfoGroup->layout() );
117   myInfoGroupLayout->setAlignment( Qt::AlignTop );
118   myInfoGroupLayout->setSpacing( 6 );
119   myInfoGroupLayout->setMargin( 11 );
120   
121   // information text browser
122   myInfo = new QTextBrowser(myInfoGroup, "myInfo");
123   myInfoGroupLayout->addWidget( myInfo, 0, 0 );
124
125   aDlgLayout->addWidget( myInfoGroup, 1, 0 );
126
127   // buttons group
128   myButtonsGroup = new QGroupBox( this, "myButtonsGroup" );
129   myButtonsGroup->setColumnLayout(0, Qt::Vertical );
130   myButtonsGroup->layout()->setSpacing( 0 );  myButtonsGroup->layout()->setMargin( 0 );
131   QHBoxLayout* myButtonsGroupLayout = new QHBoxLayout( myButtonsGroup->layout() );
132   myButtonsGroupLayout->setAlignment( Qt::AlignTop );
133   myButtonsGroupLayout->setSpacing( 6 ); myButtonsGroupLayout->setMargin( 11 );
134   
135   // buttons --> OK button
136   myOkBtn = new QPushButton( tr( "SMESH_BUT_OK"  ), myButtonsGroup, "myOkBtn" );
137   myOkBtn->setAutoDefault( TRUE ); myOkBtn->setDefault( TRUE );
138   myButtonsGroupLayout->addStretch();
139   myButtonsGroupLayout->addWidget( myOkBtn );
140   myButtonsGroupLayout->addStretch();
141   
142   aDlgLayout->addWidget( myButtonsGroup, 2, 0 );
143   
144   mySelection = SALOME_Selection::Selection( SMESHGUI::GetSMESHGUI()->GetActiveStudy()->getSelection() );
145   SMESHGUI::GetSMESHGUI()->SetActiveDialogBox( this ) ;
146
147   // connect signals
148   connect( myOkBtn,                  SIGNAL( clicked() ),                      this, SLOT( close() ) );
149   connect( mySelectBtn,              SIGNAL( clicked() ),                      this, SLOT( onStartSelection() ) );
150   connect( SMESHGUI::GetSMESHGUI(),  SIGNAL( SignalCloseAllDialogs() ),        this, SLOT( close() ) ) ;
151   connect( SMESHGUI::GetSMESHGUI(),  SIGNAL( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) ) ;
152   connect( mySelection,              SIGNAL( currentSelectionChanged() ),      this, SLOT( onSelectionChanged() ) );
153
154   // resize and move dialog, then show
155   this->setMinimumSize(270, 428);
156   int x, y;
157   SMESHGUI::GetSMESHGUI()->DefineDlgPosition( this, x, y );
158   this->move( x, y );
159   this->show();
160   
161   // init dialog with current selection
162   myMeshFilter = new SMESH_TypeFilter( MESH );
163   mySelection->AddFilter( myMeshFilter );
164   onSelectionChanged();
165 }
166
167 //=================================================================================
168 /*!
169  *  SMESHGUI_StandardMeshInfosDlg::~SMESHGUI_StandardMeshInfosDlg
170  * 
171  *  Destructor
172  */
173 //=================================================================================
174 SMESHGUI_StandardMeshInfosDlg::~SMESHGUI_StandardMeshInfosDlg()
175 {
176 }
177
178 //=================================================================================
179 /*!
180  *  SMESHGUI_StandardMeshInfosDlg::DumpMeshInfos
181  */
182 //=================================================================================
183 void SMESHGUI_StandardMeshInfosDlg::DumpMeshInfos()
184 {
185   QAD_WaitCursor wc;
186   int nbSel = mySelection->IObjectCount();
187   myInfo->clear();
188   if ( nbSel == 1 ) {
189     myStartSelection = false;
190     myMeshLine->setText( "" );
191     SMESH::SMESH_Mesh_var aMesh = SMESH::GetMeshByIO( mySelection->firstIObject() );
192     
193     if ( !aMesh->_is_nil() ) {
194       QString aName, anInfo;
195       SMESH::GetNameOfSelectedIObjects(mySelection, aName);
196       myMeshLine->setText( aName );
197       int aNbNodes =   (int)aMesh->NbNodes();
198       int aNbEdges =   (int)aMesh->NbEdges();
199       int aNbFaces =   (int)aMesh->NbFaces();
200       int aNbVolumes = (int)aMesh->NbVolumes();
201       
202       int aDimension = 0;
203       double aNbDimElements = 0;
204       if (aNbVolumes > 0) {
205         aNbDimElements = aNbVolumes;
206         aDimension = 3;
207       }
208       else if(aNbFaces > 0 ) {
209         aNbDimElements = aNbFaces;
210         aDimension = 2;
211       }
212       else if(aNbEdges > 0 ) {
213         aNbDimElements = aNbEdges;
214         aDimension = 1;
215       }
216       else if(aNbNodes > 0 ) {
217         aNbDimElements = aNbNodes;
218         aDimension = 0;
219       }
220       
221       // information about the mesh
222       anInfo.append(QString("Nb of element of dimension %1:<b> %2</b><br>").arg(aDimension).arg(aNbDimElements));
223       anInfo.append(QString("Nb of nodes: <b>%1</b><br><br>").arg(aNbNodes));
224
225       // information about the groups of the mesh
226       SALOMEDS::Study_var aStudy = SMESH::GetActiveStudyDocument();
227       SALOMEDS::SObject_var aMeshSO = aStudy->FindObjectIOR( aStudy->ConvertObjectToIOR(aMesh) ); 
228       SALOMEDS::SObject_var anObj;
229       
230       bool hasGroup = false;
231
232       // info about groups on nodes
233       aMeshSO->FindSubObject(Tag_NodeGroups , anObj);
234       if ( !anObj->_is_nil() )
235         {
236           SALOMEDS::ChildIterator_var it = aStudy->NewChildIterator(anObj);
237           if (it->More())
238             {
239               anInfo.append(QString("Groups:<br><br>"));
240               hasGroup = true;
241             }
242           for(; it->More(); it->Next()){
243             SALOMEDS::SObject_var subObj = it->Value();
244             SMESH::SMESH_GroupBase_var aGroup = SMESH::SMESH_GroupBase::_narrow( subObj->GetObject() );
245             if ( !aGroup->_is_nil() )
246               {
247                 anInfo.append(QString("-   <b>%1</b><br>").arg(aGroup->GetName()));
248                 anInfo.append(QString("%1<br>").arg("on nodes"));
249                 anInfo.append(QString("%1<br>").arg(aGroup->Size()));
250                 // check if the group based on geometry
251                 SMESH::SMESH_GroupOnGeom_var aGroupOnGeom = SMESH::SMESH_GroupOnGeom::_narrow(aGroup);
252                 if ( !aGroupOnGeom->_is_nil() )
253                   {
254                     GEOM::GEOM_Object_var aGroupMainShape = aGroupOnGeom->GetShape();
255                     QString aShapeName = "<unknown>";
256                     SALOMEDS::SObject_var aGeomObj, aRef;
257                     if ( subObj->FindSubObject( 1, aGeomObj ) &&  aGeomObj->ReferencedObject( aRef ))
258                       aShapeName = aRef->GetName();
259                     anInfo.append(QString("based on <i>%1</i> geometry object<br><br>").arg(aShapeName));
260                   }
261                 else
262                   anInfo.append(QString("<br>"));
263               }
264           }
265         }  
266       
267       // info about groups on edges
268       anObj = SALOMEDS::SObject::_nil();
269       aMeshSO->FindSubObject(Tag_EdgeGroups , anObj);
270       if ( !anObj->_is_nil() )
271         {
272           SALOMEDS::ChildIterator_var it = aStudy->NewChildIterator(anObj);
273           if (!hasGroup && it->More())
274             {
275               anInfo.append(QString("Groups:<br><br>"));
276               hasGroup = true;
277             }
278           for(; it->More(); it->Next()){
279             SALOMEDS::SObject_var subObj = it->Value();
280             SMESH::SMESH_GroupBase_var aGroup = SMESH::SMESH_GroupBase::_narrow( subObj->GetObject() );
281             if ( !aGroup->_is_nil() )
282               {
283                 anInfo.append(QString("-   <b>%1</b><br>").arg(aGroup->GetName()));
284                 anInfo.append(QString("%1<br>").arg("on edges"));
285                 anInfo.append(QString("%1<br>").arg(aGroup->Size()));
286                 // check if the group based on geometry
287                 SMESH::SMESH_GroupOnGeom_var aGroupOnGeom = SMESH::SMESH_GroupOnGeom::_narrow(aGroup);
288                 if ( !aGroupOnGeom->_is_nil() )
289                   {
290                     GEOM::GEOM_Object_var aGroupMainShape = aGroupOnGeom->GetShape();
291                     QString aShapeName = "<unknown>";
292                     SALOMEDS::SObject_var aGeomObj, aRef;
293                     if ( subObj->FindSubObject( 1, aGeomObj ) &&  aGeomObj->ReferencedObject( aRef ))
294                       aShapeName = aRef->GetName();
295                     anInfo.append(QString("based on <i>%1</i> geometry object<br><br>").arg(aShapeName));
296                   }
297                 else
298                   anInfo.append(QString("<br>"));
299               }
300           }
301         }
302       
303       // info about groups on faces
304       anObj = SALOMEDS::SObject::_nil();
305       aMeshSO->FindSubObject(Tag_FaceGroups , anObj);
306       if ( !anObj->_is_nil() )
307         {
308           SALOMEDS::ChildIterator_var it = aStudy->NewChildIterator(anObj);
309           if (!hasGroup && it->More())
310             {
311               anInfo.append(QString("Groups:<br><br>"));
312               hasGroup = true;
313             }
314           for(; it->More(); it->Next()){
315             SALOMEDS::SObject_var subObj = it->Value();
316             SMESH::SMESH_GroupBase_var aGroup = SMESH::SMESH_GroupBase::_narrow( subObj->GetObject() );
317             if ( !aGroup->_is_nil() )
318               {
319                 anInfo.append(QString("-   <b>%1</b><br>").arg(aGroup->GetName()));
320                 anInfo.append(QString("%1<br>").arg("on faces"));
321                 anInfo.append(QString("%1<br>").arg(aGroup->Size()));
322                 // check if the group based on geometry
323                 SMESH::SMESH_GroupOnGeom_var aGroupOnGeom = SMESH::SMESH_GroupOnGeom::_narrow(aGroup);
324                 if ( !aGroupOnGeom->_is_nil() )
325                   {
326                     GEOM::GEOM_Object_var aGroupMainShape = aGroupOnGeom->GetShape();
327                     QString aShapeName = "<unknown>";
328                     SALOMEDS::SObject_var aGeomObj, aRef;
329                     if ( subObj->FindSubObject( 1, aGeomObj ) &&  aGeomObj->ReferencedObject( aRef ))
330                       aShapeName = aRef->GetName();
331                     anInfo.append(QString("based on <i>%1</i> geometry object<br><br>").arg(aShapeName));
332                   }
333                 else
334                   anInfo.append(QString("<br>"));
335               }
336           }
337         }
338       
339       // info about groups on volumes
340       anObj = SALOMEDS::SObject::_nil();
341       aMeshSO->FindSubObject(Tag_VolumeGroups , anObj);
342       if ( !anObj->_is_nil() )
343         {
344           SALOMEDS::ChildIterator_var it = aStudy->NewChildIterator(anObj);
345           if (!hasGroup && it->More())
346             anInfo.append(QString("Groups:<br>"));
347           for(; it->More(); it->Next()){
348             SALOMEDS::SObject_var subObj = it->Value();
349             SMESH::SMESH_GroupBase_var aGroup = SMESH::SMESH_GroupBase::_narrow( subObj->GetObject() );
350             if ( !aGroup->_is_nil() )
351               {
352                 anInfo.append(QString("-   <b>%1</b><br>").arg(aGroup->GetName()));
353                 anInfo.append(QString("%1<br>").arg("on volumes"));
354                 anInfo.append(QString("%1<br>").arg(aGroup->Size()));
355                 // check if the group based on geometry
356                 SMESH::SMESH_GroupOnGeom_var aGroupOnGeom = SMESH::SMESH_GroupOnGeom::_narrow(aGroup);
357                 if ( !aGroupOnGeom->_is_nil() )
358                   {
359                     GEOM::GEOM_Object_var aGroupMainShape = aGroupOnGeom->GetShape();
360                     QString aShapeName = "<unknown>";
361                     SALOMEDS::SObject_var aGeomObj, aRef;
362                     if ( subObj->FindSubObject( 1, aGeomObj ) &&  aGeomObj->ReferencedObject( aRef ))
363                       aShapeName = aRef->GetName();
364                     anInfo.append(QString("based on <i>%1</i> geometry object<br><br>").arg(aShapeName));
365                   }
366                 else
367                   anInfo.append(QString("<br>"));
368               }
369           }
370         }
371       
372       myInfo->setText(anInfo);
373       return;
374     }
375   }
376   
377   return;
378 }
379
380 //=================================================================================
381 // function : SelectionIntoArgument()
382 // purpose  : Called when selection has changed
383 //=================================================================================
384 void SMESHGUI_StandardMeshInfosDlg::onSelectionChanged()
385 {
386   if ( myStartSelection )
387     DumpMeshInfos();
388 }
389
390
391 //=================================================================================
392 // function : closeEvent()
393 // purpose  :
394 //=================================================================================
395 void SMESHGUI_StandardMeshInfosDlg::closeEvent( QCloseEvent* e )
396 {
397   mySelection->ClearFilters();
398   SMESHGUI::GetSMESHGUI()->ResetState();
399   QDialog::closeEvent( e );
400 }
401
402
403 //=================================================================================
404 // function : windowActivationChange()
405 // purpose  : called when window is activated/deactivated
406 //=================================================================================
407 void SMESHGUI_StandardMeshInfosDlg::windowActivationChange( bool oldActive )
408 {
409   QDialog::windowActivationChange( oldActive );
410   if ( isActiveWindow() && myIsActiveWindow != isActiveWindow() )
411     ActivateThisDialog() ;
412   myIsActiveWindow = isActiveWindow();
413 }
414
415
416 //=================================================================================
417 // function : DeactivateActiveDialog()
418 // purpose  :
419 //=================================================================================
420 void SMESHGUI_StandardMeshInfosDlg::DeactivateActiveDialog()
421 {
422   disconnect( mySelection, 0, this, 0 );
423 }
424
425
426 //=================================================================================
427 // function : ActivateThisDialog()
428 // purpose  :
429 //=================================================================================
430 void SMESHGUI_StandardMeshInfosDlg::ActivateThisDialog()
431 {
432   /* Emit a signal to deactivate any active dialog */
433   SMESHGUI::GetSMESHGUI()->EmitSignalDeactivateDialog() ;
434   connect( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( onSelectionChanged() ) );
435 }
436
437 //=================================================================================
438 // function : onStartSelection()
439 // purpose  : starts selection
440 //=================================================================================
441 void SMESHGUI_StandardMeshInfosDlg::onStartSelection()
442 {
443   myStartSelection = true;
444   mySelection->AddFilter( myMeshFilter ) ;
445   myMeshLine->setText( tr( "Select a mesh" ) );
446   onSelectionChanged();
447   myStartSelection = true;
448 }