1 // SMESH SMESHGUI : GUI for SMESH component
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : SMESHGUI_StandardMeshInfosDlg.cxx
25 // Author : Michael ZORIN
29 #include "SMESHGUI_StandardMeshInfosDlg.h"
32 #include "SMESHGUI_Utils.h"
33 #include "SMESHGUI_MeshUtils.h"
36 #include "SMESH_TypeFilter.hxx"
38 #include "SALOMEDSClient_Study.hxx"
39 #include "SALOMEDSClient_SObject.hxx"
41 #include "SUIT_Desktop.h"
42 #include "SUIT_Session.h"
43 #include "SUIT_OverrideCursor.h"
44 #include "SUIT_MessageBox.h"
46 #include "LightApp_Application.h"
48 #include "LightApp_SelectionMgr.h"
49 #include "SALOME_ListIO.hxx"
51 #include "utilities.h"
54 #include <qgroupbox.h>
57 #include <qlineedit.h>
58 #include <qtextbrowser.h>
60 #include <qpushbutton.h>
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)
71 //=================================================================================
73 * SMESHGUI_StandardMeshInfosDlg::SMESHGUI_StandardMeshInfosDlg
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 ) )
86 setName("SMESHGUI_StandardMeshInfosDlg");
87 setCaption(tr("SMESH_STANDARD_MESHINFO_TITLE" ));
88 setSizeGripEnabled(TRUE);
90 myStartSelection = true;
91 myIsActiveWindow = true;
94 QGridLayout* aDlgLayout = new QGridLayout(this);
95 aDlgLayout->setSpacing(6);
96 aDlgLayout->setMargin(11);
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);
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);
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);
120 myMeshLine = new QLineEdit(myMeshGroup, "myMeshLine");
121 myMeshGroupLayout->addWidget(myMeshLine, 0, 2);
123 aDlgLayout->addWidget(myMeshGroup, 0, 0);
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);
136 // information text browser
137 myInfo = new QTextBrowser(myInfoGroup, "myInfo");
138 myInfoGroupLayout->addWidget(myInfo, 0, 0);
140 aDlgLayout->addWidget(myInfoGroup, 1, 0);
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);
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);
156 myButtonsGroupLayout->addWidget(myOkBtn);
157 myButtonsGroupLayout->addStretch();
158 myButtonsGroupLayout->addWidget(myHelpBtn);
160 aDlgLayout->addWidget(myButtonsGroup, 2, 0);
162 mySMESHGUI->SetActiveDialogBox(this);
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()));
172 // resize and move dialog, then show
173 this->setMinimumSize(270, 428);
176 // init dialog with current selection
177 myMeshFilter = new SMESH_TypeFilter (MESH);
178 mySelectionMgr->installFilter(myMeshFilter);
179 onSelectionChanged();
181 myHelpFileName = "/files/viewing_mesh_info.htm#standard_infos";
184 //=================================================================================
186 * SMESHGUI_StandardMeshInfosDlg::~SMESHGUI_StandardMeshInfosDlg
190 //=================================================================================
191 SMESHGUI_StandardMeshInfosDlg::~SMESHGUI_StandardMeshInfosDlg()
195 //=================================================================================
197 * SMESHGUI_StandardMeshInfosDlg::DumpMeshInfos
199 //=================================================================================
200 void SMESHGUI_StandardMeshInfosDlg::DumpMeshInfos()
202 SUIT_OverrideCursor wc;
205 mySelectionMgr->selectedObjects(aList);
207 int nbSel = aList.Extent();
210 myStartSelection = false;
211 myMeshLine->setText("");
212 SMESH::SMESH_Mesh_var aMesh = SMESH::GetMeshByIO(aList.First());
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();
224 double aNbDimElements = 0;
225 if (aNbVolumes > 0) {
226 aNbDimElements = aNbVolumes;
229 else if(aNbFaces > 0) {
230 aNbDimElements = aNbFaces;
233 else if(aNbEdges > 0) {
234 aNbDimElements = aNbEdges;
237 else if(aNbNodes > 0) {
238 aNbDimElements = aNbNodes;
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));
246 // information about the groups of the mesh
247 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
248 _PTR(SObject) aMeshSO = SMESH::FindSObject(aMesh);
251 bool hasGroup = false;
253 // info about groups on nodes
254 aMeshSO->FindSubObject(Tag_NodeGroups, anObj);
256 _PTR(ChildIterator) it = aStudy->NewChildIterator(anObj);
258 anInfo.append(QString("Groups:<br><br>"));
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));
279 anInfo.append(QString("<br>"));
285 // info about groups on edges
287 aMeshSO->FindSubObject(Tag_EdgeGroups, anObj);
289 _PTR(ChildIterator) it = aStudy->NewChildIterator(anObj);
290 if (!hasGroup && it->More()) {
291 anInfo.append(QString("Groups:<br><br>"));
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));
312 anInfo.append(QString("<br>"));
318 // info about groups on faces
320 aMeshSO->FindSubObject(Tag_FaceGroups , anObj);
322 _PTR(ChildIterator) it = aStudy->NewChildIterator(anObj);
323 if (!hasGroup && it->More()) {
324 anInfo.append(QString("Groups:<br><br>"));
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));
345 anInfo.append(QString("<br>"));
351 // info about groups on volumes
353 aMeshSO->FindSubObject(Tag_VolumeGroups, 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));
376 anInfo.append(QString("<br>"));
382 myInfo->setText(anInfo);
388 //=================================================================================
389 // function : SelectionIntoArgument()
390 // purpose : Called when selection has changed
391 //=================================================================================
392 void SMESHGUI_StandardMeshInfosDlg::onSelectionChanged()
394 if (myStartSelection)
398 //=================================================================================
399 // function : closeEvent()
401 //=================================================================================
402 void SMESHGUI_StandardMeshInfosDlg::closeEvent (QCloseEvent* e)
404 mySelectionMgr->clearFilters();
405 mySMESHGUI->ResetState();
406 QDialog::closeEvent(e);
409 //=================================================================================
410 // function : windowActivationChange()
411 // purpose : called when window is activated/deactivated
412 //=================================================================================
413 void SMESHGUI_StandardMeshInfosDlg::windowActivationChange (bool oldActive)
415 QDialog::windowActivationChange(oldActive);
416 if (isActiveWindow() && myIsActiveWindow != isActiveWindow())
417 ActivateThisDialog();
418 myIsActiveWindow = isActiveWindow();
421 //=================================================================================
422 // function : DeactivateActiveDialog()
424 //=================================================================================
425 void SMESHGUI_StandardMeshInfosDlg::DeactivateActiveDialog()
427 disconnect(mySelectionMgr, 0, this, 0);
430 //=================================================================================
431 // function : ActivateThisDialog()
433 //=================================================================================
434 void SMESHGUI_StandardMeshInfosDlg::ActivateThisDialog()
436 /* Emit a signal to deactivate any active dialog */
437 mySMESHGUI->EmitSignalDeactivateDialog();
438 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(onSelectionChanged()));
441 //=================================================================================
442 // function : onStartSelection()
443 // purpose : starts selection
444 //=================================================================================
445 void SMESHGUI_StandardMeshInfosDlg::onStartSelection()
447 myStartSelection = true;
448 mySelectionMgr->installFilter(myMeshFilter);
449 myMeshLine->setText(tr("Select a mesh"));
450 onSelectionChanged();
451 myStartSelection = true;
454 //=================================================================================
455 // function : onHelp()
457 //=================================================================================
458 void SMESHGUI_StandardMeshInfosDlg::onHelp()
460 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
462 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
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"));