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