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