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