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
22 // File : SMESHGUI_StandardMeshInfosDlg.cxx
23 // Author : Michael ZORIN, Open CASCADE S.A.S.
27 #include "SMESHGUI_StandardMeshInfosDlg.h"
30 #include "SMESHGUI_Utils.h"
31 #include "SMESHGUI_MeshUtils.h"
33 #include <SMESH_TypeFilter.hxx>
35 // SALOME KERNEL includes
36 #include <SALOMEDSClient_Study.hxx>
37 #include <SALOMEDSClient_SObject.hxx>
39 // SALOME GUI includes
40 #include <SUIT_Desktop.h>
41 #include <SUIT_Session.h>
42 #include <SUIT_OverrideCursor.h>
43 #include <SUIT_MessageBox.h>
44 #include <SUIT_ResourceMgr.h>
46 #include <LightApp_Application.h>
47 #include <LightApp_SelectionMgr.h>
49 #include <SALOME_ListIO.hxx>
54 #include <QVBoxLayout>
55 #include <QHBoxLayout>
57 #include <QTextBrowser>
58 #include <QPushButton>
62 #include <SALOMEconfig.h>
63 #include CORBA_SERVER_HEADER(SMESH_Mesh)
64 #include CORBA_SERVER_HEADER(SMESH_Group)
69 //=================================================================================
71 * SMESHGUI_StandardMeshInfosDlg::SMESHGUI_StandardMeshInfosDlg
75 //=================================================================================
76 SMESHGUI_StandardMeshInfosDlg::SMESHGUI_StandardMeshInfosDlg( SMESHGUI* theModule )
77 : QDialog( SMESH::GetDesktop( theModule ) ),
78 mySMESHGUI( theModule ),
79 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) )
82 setAttribute(Qt::WA_DeleteOnClose, true);
83 setWindowTitle(tr("SMESH_STANDARD_MESHINFO_TITLE"));
84 setSizeGripEnabled(true);
86 myStartSelection = true;
87 myIsActiveWindow = true;
90 QVBoxLayout* aDlgLayout = new QVBoxLayout(this);
91 aDlgLayout->setSpacing(SPACING);
92 aDlgLayout->setMargin(MARGIN);
95 myMeshGroup = new QGroupBox(tr("SMESH_MESH"), this);
96 QHBoxLayout* myMeshGroupLayout = new QHBoxLayout(myMeshGroup);
97 myMeshGroupLayout->setSpacing(SPACING);
98 myMeshGroupLayout->setMargin(MARGIN);
100 // select button, label and line edit with mesh name
101 myNameLab = new QLabel(tr("SMESH_NAME"), myMeshGroup);
102 myMeshGroupLayout->addWidget(myNameLab);
104 QPixmap image0(SUIT_Session::session()->resourceMgr()->loadPixmap("SMESH",tr("ICON_SELECT")));
105 mySelectBtn = new QPushButton(myMeshGroup);
106 mySelectBtn->setIcon(image0);
107 myMeshGroupLayout->addWidget(mySelectBtn);
109 myMeshLine = new QLineEdit(myMeshGroup);
110 myMeshGroupLayout->addWidget(myMeshLine);
112 aDlgLayout->addWidget(myMeshGroup);
114 // information group box
115 myInfoGroup = new QGroupBox(tr("SMESH_INFORMATION"), this);
116 QVBoxLayout* myInfoGroupLayout = new QVBoxLayout(myInfoGroup);
117 myInfoGroupLayout->setSpacing(SPACING);
118 myInfoGroupLayout->setMargin(MARGIN);
120 // information text browser
121 myInfo = new QTextBrowser(myInfoGroup);
122 myInfo->setMinimumSize(200, 150);
123 myInfoGroupLayout->addWidget(myInfo);
125 aDlgLayout->addWidget(myInfoGroup);
128 myButtonsGroup = new QGroupBox(this);
129 QHBoxLayout* myButtonsGroupLayout = new QHBoxLayout(myButtonsGroup);
130 myButtonsGroupLayout->setSpacing(SPACING);
131 myButtonsGroupLayout->setMargin(MARGIN);
133 // buttons --> OK and Help buttons
134 myOkBtn = new QPushButton(tr("SMESH_BUT_OK"), myButtonsGroup);
135 myOkBtn->setAutoDefault(true); myOkBtn->setDefault(true);
136 myHelpBtn = new QPushButton(tr("SMESH_BUT_HELP"), myButtonsGroup);
137 myHelpBtn->setAutoDefault(true);
139 myButtonsGroupLayout->addWidget(myOkBtn);
140 myButtonsGroupLayout->addSpacing(10);
141 myButtonsGroupLayout->addStretch();
142 myButtonsGroupLayout->addWidget(myHelpBtn);
144 aDlgLayout->addWidget(myButtonsGroup);
146 mySMESHGUI->SetActiveDialogBox(this);
149 connect( myOkBtn, SIGNAL(clicked()), this, SLOT(close()));
150 connect( myHelpBtn, SIGNAL(clicked()), this, SLOT(onHelp()));
151 connect( mySelectBtn, SIGNAL(clicked()), this, SLOT(onStartSelection()));
152 connect( mySMESHGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(close()));
153 connect( mySMESHGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
154 connect( mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(onSelectionChanged()));
156 // init dialog with current selection
157 myMeshFilter = new SMESH_TypeFilter (MESH);
158 mySelectionMgr->installFilter(myMeshFilter);
159 onSelectionChanged();
161 myHelpFileName = "mesh_infos_page.html#standard_mesh_infos_anchor";
164 //=================================================================================
166 * SMESHGUI_StandardMeshInfosDlg::~SMESHGUI_StandardMeshInfosDlg
170 //=================================================================================
171 SMESHGUI_StandardMeshInfosDlg::~SMESHGUI_StandardMeshInfosDlg()
175 //=================================================================================
177 * SMESHGUI_StandardMeshInfosDlg::DumpMeshInfos
179 //=================================================================================
180 void SMESHGUI_StandardMeshInfosDlg::DumpMeshInfos()
182 SUIT_OverrideCursor wc;
185 mySelectionMgr->selectedObjects(aList);
187 int nbSel = aList.Extent();
190 myStartSelection = false;
191 myMeshLine->setText("");
192 SMESH::SMESH_Mesh_var aMesh = SMESH::GetMeshByIO(aList.First());
194 if (!aMesh->_is_nil()) {
195 QString aName, anInfo;
196 SMESH::GetNameOfSelectedIObjects(mySelectionMgr, aName);
197 myMeshLine->setText(aName);
198 int aNbNodes = (int)aMesh->NbNodes();
199 int aNbEdges = (int)aMesh->NbEdges();
200 int aNbFaces = (int)aMesh->NbFaces();
201 int aNbVolumes = (int)aMesh->NbVolumes();
204 double aNbDimElements = 0;
205 if (aNbVolumes > 0) {
206 aNbDimElements = aNbVolumes;
209 else if(aNbFaces > 0) {
210 aNbDimElements = aNbFaces;
213 else if(aNbEdges > 0) {
214 aNbDimElements = aNbEdges;
217 else if(aNbNodes > 0) {
218 aNbDimElements = aNbNodes;
222 // information about the mesh
223 anInfo.append(QString("Nb of element of dimension %1:<b> %2</b><br>").arg(aDimension).arg(aNbDimElements));
224 anInfo.append(QString("Nb of nodes: <b>%1</b><br><br>").arg(aNbNodes));
226 // information about the groups of the mesh
227 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
228 _PTR(SObject) aMeshSO = SMESH::FindSObject(aMesh);
231 bool hasGroup = false;
233 // info about groups on nodes
234 aMeshSO->FindSubObject(SMESH::Tag_NodeGroups, anObj);
236 _PTR(ChildIterator) it = aStudy->NewChildIterator(anObj);
238 anInfo.append(QString("Groups:<br><br>"));
241 for ( ; it->More(); it->Next()) {
242 _PTR(SObject) subObj = it->Value();
243 CORBA::Object_var anObject = SMESH::SObjectToObject(subObj);
244 SMESH::SMESH_GroupBase_var aGroup = SMESH::SMESH_GroupBase::_narrow(anObject);
245 if (!aGroup->_is_nil()) {
246 anInfo.append(QString("- <b>%1</b><br>").arg(aGroup->GetName()));
247 anInfo.append(QString("%1<br>").arg("on nodes"));
248 anInfo.append(QString("%1<br>").arg(aGroup->Size()));
249 // check if the group based on geometry
250 SMESH::SMESH_GroupOnGeom_var aGroupOnGeom = SMESH::SMESH_GroupOnGeom::_narrow(aGroup);
251 if (!aGroupOnGeom->_is_nil()) {
252 GEOM::GEOM_Object_var aGroupMainShape = aGroupOnGeom->GetShape();
253 QString aShapeName = "<unknown>";
254 _PTR(SObject) aGeomObj, aRef;
255 if (subObj->FindSubObject(1, aGeomObj) && aGeomObj->ReferencedObject(aRef))
256 aShapeName = aRef->GetName().c_str();
257 anInfo.append(QString("based on <i>%1</i> geometry object<br><br>").arg(aShapeName));
259 anInfo.append(QString("<br>"));
265 // info about groups on edges
267 aMeshSO->FindSubObject(SMESH::Tag_EdgeGroups, anObj);
269 _PTR(ChildIterator) it = aStudy->NewChildIterator(anObj);
270 if (!hasGroup && it->More()) {
271 anInfo.append(QString("Groups:<br><br>"));
274 for ( ; it->More(); it->Next()) {
275 _PTR(SObject) subObj = it->Value();
276 CORBA::Object_var anObject = SMESH::SObjectToObject(subObj);
277 SMESH::SMESH_GroupBase_var aGroup = SMESH::SMESH_GroupBase::_narrow(anObject);
278 if (!aGroup->_is_nil()) {
279 anInfo.append(QString("- <b>%1</b><br>").arg(aGroup->GetName()));
280 anInfo.append(QString("%1<br>").arg("on edges"));
281 anInfo.append(QString("%1<br>").arg(aGroup->Size()));
282 // check if the group based on geometry
283 SMESH::SMESH_GroupOnGeom_var aGroupOnGeom = SMESH::SMESH_GroupOnGeom::_narrow(aGroup);
284 if (!aGroupOnGeom->_is_nil()) {
285 GEOM::GEOM_Object_var aGroupMainShape = aGroupOnGeom->GetShape();
286 QString aShapeName = "<unknown>";
287 _PTR(SObject) aGeomObj, aRef;
288 if (subObj->FindSubObject(1, aGeomObj) && aGeomObj->ReferencedObject(aRef))
289 aShapeName = aRef->GetName().c_str();
290 anInfo.append(QString("based on <i>%1</i> geometry object<br><br>").arg(aShapeName));
292 anInfo.append(QString("<br>"));
298 // info about groups on faces
300 aMeshSO->FindSubObject(SMESH::Tag_FaceGroups, anObj);
302 _PTR(ChildIterator) it = aStudy->NewChildIterator(anObj);
303 if (!hasGroup && it->More()) {
304 anInfo.append(QString("Groups:<br><br>"));
307 for ( ; it->More(); it->Next()) {
308 _PTR(SObject) subObj = it->Value();
309 CORBA::Object_var anObject = SMESH::SObjectToObject(subObj);
310 SMESH::SMESH_GroupBase_var aGroup = SMESH::SMESH_GroupBase::_narrow(anObject);
311 if (!aGroup->_is_nil()) {
312 anInfo.append(QString("- <b>%1</b><br>").arg(aGroup->GetName()));
313 anInfo.append(QString("%1<br>").arg("on faces"));
314 anInfo.append(QString("%1<br>").arg(aGroup->Size()));
315 // check if the group based on geometry
316 SMESH::SMESH_GroupOnGeom_var aGroupOnGeom = SMESH::SMESH_GroupOnGeom::_narrow(aGroup);
317 if (!aGroupOnGeom->_is_nil()) {
318 GEOM::GEOM_Object_var aGroupMainShape = aGroupOnGeom->GetShape();
319 QString aShapeName = "<unknown>";
320 _PTR(SObject) aGeomObj, aRef;
321 if (subObj->FindSubObject(1, aGeomObj) && aGeomObj->ReferencedObject(aRef))
322 aShapeName = aRef->GetName().c_str();
323 anInfo.append(QString("based on <i>%1</i> geometry object<br><br>").arg(aShapeName));
325 anInfo.append(QString("<br>"));
331 // info about groups on volumes
333 aMeshSO->FindSubObject(SMESH::Tag_VolumeGroups, anObj);
335 _PTR(ChildIterator) it = aStudy->NewChildIterator(anObj);
336 if (!hasGroup && it->More())
337 anInfo.append(QString("Groups:<br>"));
338 for ( ; it->More(); it->Next()) {
339 _PTR(SObject) subObj = it->Value();
340 CORBA::Object_var anObject = SMESH::SObjectToObject(subObj);
341 SMESH::SMESH_GroupBase_var aGroup = SMESH::SMESH_GroupBase::_narrow(anObject);
342 if (!aGroup->_is_nil()) {
343 anInfo.append(QString("- <b>%1</b><br>").arg(aGroup->GetName()));
344 anInfo.append(QString("%1<br>").arg("on volumes"));
345 anInfo.append(QString("%1<br>").arg(aGroup->Size()));
346 // check if the group based on geometry
347 SMESH::SMESH_GroupOnGeom_var aGroupOnGeom = SMESH::SMESH_GroupOnGeom::_narrow(aGroup);
348 if (!aGroupOnGeom->_is_nil()) {
349 GEOM::GEOM_Object_var aGroupMainShape = aGroupOnGeom->GetShape();
350 QString aShapeName = "<unknown>";
351 _PTR(SObject) aGeomObj, aRef;
352 if (subObj->FindSubObject(1, aGeomObj) && aGeomObj->ReferencedObject(aRef))
353 aShapeName = aRef->GetName().c_str();
354 anInfo.append(QString("based on <i>%1</i> geometry object<br><br>").arg(aShapeName));
356 anInfo.append(QString("<br>"));
362 myInfo->setText(anInfo);
368 //=================================================================================
369 // function : SelectionIntoArgument()
370 // purpose : Called when selection has changed
371 //=================================================================================
372 void SMESHGUI_StandardMeshInfosDlg::onSelectionChanged()
374 if (myStartSelection)
378 //=================================================================================
379 // function : closeEvent()
381 //=================================================================================
382 void SMESHGUI_StandardMeshInfosDlg::closeEvent (QCloseEvent* e)
384 mySelectionMgr->clearFilters();
385 mySMESHGUI->ResetState();
386 QDialog::closeEvent(e);
389 //=================================================================================
390 // function : windowActivationChange()
391 // purpose : called when window is activated/deactivated
392 //=================================================================================
393 void SMESHGUI_StandardMeshInfosDlg::windowActivationChange (bool oldActive)
395 QDialog::windowActivationChange(oldActive);
396 if (isActiveWindow() && myIsActiveWindow != isActiveWindow())
397 ActivateThisDialog();
398 myIsActiveWindow = isActiveWindow();
401 //=================================================================================
402 // function : DeactivateActiveDialog()
404 //=================================================================================
405 void SMESHGUI_StandardMeshInfosDlg::DeactivateActiveDialog()
407 disconnect(mySelectionMgr, 0, this, 0);
410 //=================================================================================
411 // function : ActivateThisDialog()
413 //=================================================================================
414 void SMESHGUI_StandardMeshInfosDlg::ActivateThisDialog()
416 /* Emit a signal to deactivate any active dialog */
417 mySMESHGUI->EmitSignalDeactivateDialog();
418 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(onSelectionChanged()));
421 //=================================================================================
422 // function : onStartSelection()
423 // purpose : starts selection
424 //=================================================================================
425 void SMESHGUI_StandardMeshInfosDlg::onStartSelection()
427 myStartSelection = true;
428 mySelectionMgr->installFilter(myMeshFilter);
429 myMeshLine->setText(tr("Select a mesh"));
430 onSelectionChanged();
431 myStartSelection = true;
434 //=================================================================================
435 // function : onHelp()
437 //=================================================================================
438 void SMESHGUI_StandardMeshInfosDlg::onHelp()
440 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
442 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
446 platform = "winapplication";
448 platform = "application";
450 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
451 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
452 arg(app->resourceMgr()->stringValue("ExternalBrowser",
454 arg(myHelpFileName));
458 //=================================================================================
459 // function : keyPressEvent()
461 //=================================================================================
462 void SMESHGUI_StandardMeshInfosDlg::keyPressEvent( QKeyEvent* e )
464 QDialog::keyPressEvent( e );
465 if ( e->isAccepted() )
468 if ( e->key() == Qt::Key_F1 ) {