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.salome-platform.org/ or email : webmaster.salome@opencascade.com
24 // File : SMESHGUI_StandardMeshInfosDlg.cxx
25 // Author : Michael ZORIN
29 #include "SMESHGUI_StandardMeshInfosDlg.h"
32 #include "SMESHGUI_Utils.h"
33 #include "SMESHGUI_MeshUtils.h"
35 #include "SMESH_TypeFilter.hxx"
37 #include "SALOMEDSClient_Study.hxx"
38 #include "SALOMEDSClient_SObject.hxx"
40 #include "SUIT_Desktop.h"
41 #include "SUIT_Session.h"
42 #include "SUIT_OverrideCursor.h"
43 #include "SUIT_MessageBox.h"
45 #include "LightApp_Application.h"
47 #include "LightApp_SelectionMgr.h"
48 #include "SALOME_ListIO.hxx"
50 #include "utilities.h"
53 #include <qgroupbox.h>
56 #include <qlineedit.h>
57 #include <qtextbrowser.h>
59 #include <qpushbutton.h>
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)
70 //=================================================================================
72 * SMESHGUI_StandardMeshInfosDlg::SMESHGUI_StandardMeshInfosDlg
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 ) )
85 setName("SMESHGUI_StandardMeshInfosDlg");
86 setCaption(tr("SMESH_STANDARD_MESHINFO_TITLE" ));
87 setSizeGripEnabled(TRUE);
89 myStartSelection = true;
90 myIsActiveWindow = true;
93 QGridLayout* aDlgLayout = new QGridLayout(this);
94 aDlgLayout->setSpacing(6);
95 aDlgLayout->setMargin(11);
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);
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);
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);
119 myMeshLine = new QLineEdit(myMeshGroup, "myMeshLine");
120 myMeshGroupLayout->addWidget(myMeshLine, 0, 2);
122 aDlgLayout->addWidget(myMeshGroup, 0, 0);
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);
135 // information text browser
136 myInfo = new QTextBrowser(myInfoGroup, "myInfo");
137 myInfoGroupLayout->addWidget(myInfo, 0, 0);
139 aDlgLayout->addWidget(myInfoGroup, 1, 0);
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);
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);
155 myButtonsGroupLayout->addWidget(myOkBtn);
156 myButtonsGroupLayout->addStretch();
157 myButtonsGroupLayout->addWidget(myHelpBtn);
159 aDlgLayout->addWidget(myButtonsGroup, 2, 0);
161 mySMESHGUI->SetActiveDialogBox(this);
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()));
171 // resize and move dialog, then show
172 this->setMinimumSize(270, 428);
175 // init dialog with current selection
176 myMeshFilter = new SMESH_TypeFilter (MESH);
177 mySelectionMgr->installFilter(myMeshFilter);
178 onSelectionChanged();
180 myHelpFileName = "mesh_infos_page.html#standard_mesh_infos_anchor";
183 //=================================================================================
185 * SMESHGUI_StandardMeshInfosDlg::~SMESHGUI_StandardMeshInfosDlg
189 //=================================================================================
190 SMESHGUI_StandardMeshInfosDlg::~SMESHGUI_StandardMeshInfosDlg()
194 //=================================================================================
196 * SMESHGUI_StandardMeshInfosDlg::DumpMeshInfos
198 //=================================================================================
199 void SMESHGUI_StandardMeshInfosDlg::DumpMeshInfos()
201 SUIT_OverrideCursor wc;
204 mySelectionMgr->selectedObjects(aList);
206 int nbSel = aList.Extent();
209 myStartSelection = false;
210 myMeshLine->setText("");
211 SMESH::SMESH_Mesh_var aMesh = SMESH::GetMeshByIO(aList.First());
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();
223 double aNbDimElements = 0;
224 if (aNbVolumes > 0) {
225 aNbDimElements = aNbVolumes;
228 else if(aNbFaces > 0) {
229 aNbDimElements = aNbFaces;
232 else if(aNbEdges > 0) {
233 aNbDimElements = aNbEdges;
236 else if(aNbNodes > 0) {
237 aNbDimElements = aNbNodes;
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));
245 // information about the groups of the mesh
246 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
247 _PTR(SObject) aMeshSO = SMESH::FindSObject(aMesh);
250 bool hasGroup = false;
252 // info about groups on nodes
253 aMeshSO->FindSubObject(SMESH::Tag_NodeGroups, anObj);
255 _PTR(ChildIterator) it = aStudy->NewChildIterator(anObj);
257 anInfo.append(QString("Groups:<br><br>"));
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));
278 anInfo.append(QString("<br>"));
284 // info about groups on edges
286 aMeshSO->FindSubObject(SMESH::Tag_EdgeGroups, anObj);
288 _PTR(ChildIterator) it = aStudy->NewChildIterator(anObj);
289 if (!hasGroup && it->More()) {
290 anInfo.append(QString("Groups:<br><br>"));
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));
311 anInfo.append(QString("<br>"));
317 // info about groups on faces
319 aMeshSO->FindSubObject(SMESH::Tag_FaceGroups , anObj);
321 _PTR(ChildIterator) it = aStudy->NewChildIterator(anObj);
322 if (!hasGroup && it->More()) {
323 anInfo.append(QString("Groups:<br><br>"));
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));
344 anInfo.append(QString("<br>"));
350 // info about groups on volumes
352 aMeshSO->FindSubObject(SMESH::Tag_VolumeGroups, 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));
375 anInfo.append(QString("<br>"));
381 myInfo->setText(anInfo);
387 //=================================================================================
388 // function : SelectionIntoArgument()
389 // purpose : Called when selection has changed
390 //=================================================================================
391 void SMESHGUI_StandardMeshInfosDlg::onSelectionChanged()
393 if (myStartSelection)
397 //=================================================================================
398 // function : closeEvent()
400 //=================================================================================
401 void SMESHGUI_StandardMeshInfosDlg::closeEvent (QCloseEvent* e)
403 mySelectionMgr->clearFilters();
404 mySMESHGUI->ResetState();
405 QDialog::closeEvent(e);
408 //=================================================================================
409 // function : windowActivationChange()
410 // purpose : called when window is activated/deactivated
411 //=================================================================================
412 void SMESHGUI_StandardMeshInfosDlg::windowActivationChange (bool oldActive)
414 QDialog::windowActivationChange(oldActive);
415 if (isActiveWindow() && myIsActiveWindow != isActiveWindow())
416 ActivateThisDialog();
417 myIsActiveWindow = isActiveWindow();
420 //=================================================================================
421 // function : DeactivateActiveDialog()
423 //=================================================================================
424 void SMESHGUI_StandardMeshInfosDlg::DeactivateActiveDialog()
426 disconnect(mySelectionMgr, 0, this, 0);
429 //=================================================================================
430 // function : ActivateThisDialog()
432 //=================================================================================
433 void SMESHGUI_StandardMeshInfosDlg::ActivateThisDialog()
435 /* Emit a signal to deactivate any active dialog */
436 mySMESHGUI->EmitSignalDeactivateDialog();
437 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(onSelectionChanged()));
440 //=================================================================================
441 // function : onStartSelection()
442 // purpose : starts selection
443 //=================================================================================
444 void SMESHGUI_StandardMeshInfosDlg::onStartSelection()
446 myStartSelection = true;
447 mySelectionMgr->installFilter(myMeshFilter);
448 myMeshLine->setText(tr("Select a mesh"));
449 onSelectionChanged();
450 myStartSelection = true;
453 //=================================================================================
454 // function : onHelp()
456 //=================================================================================
457 void SMESHGUI_StandardMeshInfosDlg::onHelp()
459 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
461 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
465 platform = "winapplication";
467 platform = "application";
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"));
476 //=================================================================================
477 // function : keyPressEvent()
479 //=================================================================================
480 void SMESHGUI_StandardMeshInfosDlg::keyPressEvent( QKeyEvent* e )
482 QDialog::keyPressEvent( e );
483 if ( e->isAccepted() )
486 if ( e->key() == Key_F1 )