1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 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.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // SMESH SMESHGUI : GUI for SMESH component
23 // File : SMESHGUI_StandardMeshInfosDlg.cxx
24 // Author : Michael ZORIN
28 #include "SMESHGUI_StandardMeshInfosDlg.h"
31 #include "SMESHGUI_Utils.h"
32 #include "SMESHGUI_MeshUtils.h"
34 #include "SMESH_TypeFilter.hxx"
36 #include "SALOMEDSClient_Study.hxx"
37 #include "SALOMEDSClient_SObject.hxx"
39 #include "SUIT_Desktop.h"
40 #include "SUIT_Session.h"
41 #include "SUIT_OverrideCursor.h"
42 #include "SUIT_MessageBox.h"
44 #include "LightApp_Application.h"
46 #include "LightApp_SelectionMgr.h"
47 #include "SALOME_ListIO.hxx"
49 #include "utilities.h"
52 #include <qgroupbox.h>
55 #include <qlineedit.h>
56 #include <qtextbrowser.h>
58 #include <qpushbutton.h>
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)
69 //=================================================================================
71 * SMESHGUI_StandardMeshInfosDlg::SMESHGUI_StandardMeshInfosDlg
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 ) )
84 setName("SMESHGUI_StandardMeshInfosDlg");
85 setCaption(tr("SMESH_STANDARD_MESHINFO_TITLE" ));
86 setSizeGripEnabled(TRUE);
88 myStartSelection = true;
89 myIsActiveWindow = true;
92 QGridLayout* aDlgLayout = new QGridLayout(this);
93 aDlgLayout->setSpacing(6);
94 aDlgLayout->setMargin(11);
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);
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);
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);
118 myMeshLine = new QLineEdit(myMeshGroup, "myMeshLine");
119 myMeshGroupLayout->addWidget(myMeshLine, 0, 2);
121 aDlgLayout->addWidget(myMeshGroup, 0, 0);
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);
134 // information text browser
135 myInfo = new QTextBrowser(myInfoGroup, "myInfo");
136 myInfoGroupLayout->addWidget(myInfo, 0, 0);
138 aDlgLayout->addWidget(myInfoGroup, 1, 0);
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);
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);
154 myButtonsGroupLayout->addWidget(myOkBtn);
155 myButtonsGroupLayout->addStretch();
156 myButtonsGroupLayout->addWidget(myHelpBtn);
158 aDlgLayout->addWidget(myButtonsGroup, 2, 0);
160 mySMESHGUI->SetActiveDialogBox(this);
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()));
170 // resize and move dialog, then show
171 this->setMinimumSize(270, 428);
174 // init dialog with current selection
175 myMeshFilter = new SMESH_TypeFilter (MESH);
176 mySelectionMgr->installFilter(myMeshFilter);
177 onSelectionChanged();
179 myHelpFileName = "mesh_infos_page.html#standard_mesh_infos_anchor";
182 //=================================================================================
184 * SMESHGUI_StandardMeshInfosDlg::~SMESHGUI_StandardMeshInfosDlg
188 //=================================================================================
189 SMESHGUI_StandardMeshInfosDlg::~SMESHGUI_StandardMeshInfosDlg()
193 //=================================================================================
195 * SMESHGUI_StandardMeshInfosDlg::DumpMeshInfos
197 //=================================================================================
198 void SMESHGUI_StandardMeshInfosDlg::DumpMeshInfos()
200 SUIT_OverrideCursor wc;
203 mySelectionMgr->selectedObjects(aList);
205 int nbSel = aList.Extent();
208 myStartSelection = false;
209 myMeshLine->setText("");
210 SMESH::SMESH_Mesh_var aMesh = SMESH::GetMeshByIO(aList.First());
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();
222 double aNbDimElements = 0;
223 if (aNbVolumes > 0) {
224 aNbDimElements = aNbVolumes;
227 else if(aNbFaces > 0) {
228 aNbDimElements = aNbFaces;
231 else if(aNbEdges > 0) {
232 aNbDimElements = aNbEdges;
235 else if(aNbNodes > 0) {
236 aNbDimElements = aNbNodes;
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));
244 // information about the groups of the mesh
245 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
246 _PTR(SObject) aMeshSO = SMESH::FindSObject(aMesh);
249 bool hasGroup = false;
251 // info about groups on nodes
252 aMeshSO->FindSubObject(SMESH::Tag_NodeGroups, anObj);
254 _PTR(ChildIterator) it = aStudy->NewChildIterator(anObj);
256 anInfo.append(QString("Groups:<br><br>"));
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));
277 anInfo.append(QString("<br>"));
283 // info about groups on edges
285 aMeshSO->FindSubObject(SMESH::Tag_EdgeGroups, anObj);
287 _PTR(ChildIterator) it = aStudy->NewChildIterator(anObj);
288 if (!hasGroup && it->More()) {
289 anInfo.append(QString("Groups:<br><br>"));
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));
310 anInfo.append(QString("<br>"));
316 // info about groups on faces
318 aMeshSO->FindSubObject(SMESH::Tag_FaceGroups , anObj);
320 _PTR(ChildIterator) it = aStudy->NewChildIterator(anObj);
321 if (!hasGroup && it->More()) {
322 anInfo.append(QString("Groups:<br><br>"));
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));
343 anInfo.append(QString("<br>"));
349 // info about groups on volumes
351 aMeshSO->FindSubObject(SMESH::Tag_VolumeGroups, 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));
374 anInfo.append(QString("<br>"));
380 myInfo->setText(anInfo);
386 //=================================================================================
387 // function : SelectionIntoArgument()
388 // purpose : Called when selection has changed
389 //=================================================================================
390 void SMESHGUI_StandardMeshInfosDlg::onSelectionChanged()
392 if (myStartSelection)
396 //=================================================================================
397 // function : closeEvent()
399 //=================================================================================
400 void SMESHGUI_StandardMeshInfosDlg::closeEvent (QCloseEvent* e)
402 mySelectionMgr->clearFilters();
403 mySMESHGUI->ResetState();
404 QDialog::closeEvent(e);
407 //=================================================================================
408 // function : windowActivationChange()
409 // purpose : called when window is activated/deactivated
410 //=================================================================================
411 void SMESHGUI_StandardMeshInfosDlg::windowActivationChange (bool oldActive)
413 QDialog::windowActivationChange(oldActive);
414 if (isActiveWindow() && myIsActiveWindow != isActiveWindow())
415 ActivateThisDialog();
416 myIsActiveWindow = isActiveWindow();
419 //=================================================================================
420 // function : DeactivateActiveDialog()
422 //=================================================================================
423 void SMESHGUI_StandardMeshInfosDlg::DeactivateActiveDialog()
425 disconnect(mySelectionMgr, 0, this, 0);
428 //=================================================================================
429 // function : ActivateThisDialog()
431 //=================================================================================
432 void SMESHGUI_StandardMeshInfosDlg::ActivateThisDialog()
434 /* Emit a signal to deactivate any active dialog */
435 mySMESHGUI->EmitSignalDeactivateDialog();
436 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(onSelectionChanged()));
439 //=================================================================================
440 // function : onStartSelection()
441 // purpose : starts selection
442 //=================================================================================
443 void SMESHGUI_StandardMeshInfosDlg::onStartSelection()
445 myStartSelection = true;
446 mySelectionMgr->installFilter(myMeshFilter);
447 myMeshLine->setText(tr("Select a mesh"));
448 onSelectionChanged();
449 myStartSelection = true;
452 //=================================================================================
453 // function : onHelp()
455 //=================================================================================
456 void SMESHGUI_StandardMeshInfosDlg::onHelp()
458 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
460 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
464 platform = "winapplication";
466 platform = "application";
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"));
475 //=================================================================================
476 // function : keyPressEvent()
478 //=================================================================================
479 void SMESHGUI_StandardMeshInfosDlg::keyPressEvent( QKeyEvent* e )
481 QDialog::keyPressEvent( e );
482 if ( e->isAccepted() )
485 if ( e->key() == Key_F1 )