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