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_Session.h"
42 #include "SUIT_OverrideCursor.h"
44 #include "SalomeApp_SelectionMgr.h"
45 #include "SALOME_ListIO.hxx"
47 #include "utilities.h"
50 #include <qgroupbox.h>
53 #include <qlineedit.h>
54 #include <qtextbrowser.h>
56 #include <qpushbutton.h>
59 #include "SALOMEconfig.h"
60 #include CORBA_SERVER_HEADER(SMESH_Mesh)
61 #include CORBA_SERVER_HEADER(SMESH_Group)
62 #include CORBA_SERVER_HEADER(GEOM_Gen)
67 //=================================================================================
69 * SMESHGUI_StandardMeshInfosDlg::SMESHGUI_StandardMeshInfosDlg
73 //=================================================================================
74 SMESHGUI_StandardMeshInfosDlg::SMESHGUI_StandardMeshInfosDlg (QWidget* parent, const char* name,
75 bool modal, WFlags fl)
76 : QDialog(parent, name, modal, WStyle_Customize | WStyle_NormalBorder |
77 WStyle_Title | WStyle_SysMenu | WDestructiveClose)
80 setName("SMESHGUI_StandardMeshInfosDlg");
81 setCaption(tr("SMESH_STANDARD_MESHINFO_TITLE" ));
82 setSizeGripEnabled(TRUE);
84 myStartSelection = true;
85 myIsActiveWindow = true;
88 QGridLayout* aDlgLayout = new QGridLayout(this);
89 aDlgLayout->setSpacing(6);
90 aDlgLayout->setMargin(11);
93 myMeshGroup = new QGroupBox(this, "myMeshGroup");
94 myMeshGroup->setTitle(tr("SMESH_MESH"));
95 myMeshGroup->setColumnLayout(0, Qt::Vertical);
96 myMeshGroup->layout()->setSpacing(0);
97 myMeshGroup->layout()->setMargin(0);
98 QGridLayout* myMeshGroupLayout = new QGridLayout(myMeshGroup->layout());
99 myMeshGroupLayout->setAlignment(Qt::AlignTop);
100 myMeshGroupLayout->setSpacing(6);
101 myMeshGroupLayout->setMargin(11);
103 // select button, label and line edit with mesh name
104 myNameLab = new QLabel(myMeshGroup, "myNameLab");
105 myNameLab->setText(tr("SMESH_NAME" ));
106 myMeshGroupLayout->addWidget(myNameLab, 0, 0);
108 QPixmap image0(SUIT_Session::session()->resourceMgr()->loadPixmap("SMESH",tr("ICON_SELECT")));
109 mySelectBtn = new QPushButton(myMeshGroup, "mySelectBtn");
110 mySelectBtn->setPixmap(image0);
111 mySelectBtn->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed));
112 myMeshGroupLayout->addWidget(mySelectBtn, 0, 1);
114 myMeshLine = new QLineEdit(myMeshGroup, "myMeshLine");
115 myMeshGroupLayout->addWidget(myMeshLine, 0, 2);
117 aDlgLayout->addWidget(myMeshGroup, 0, 0);
119 // information group box
120 myInfoGroup = new QGroupBox(this, "myInfoGroup");
121 myInfoGroup->setTitle(tr("SMESH_INFORMATION"));
122 myInfoGroup->setColumnLayout(0, Qt::Vertical);
123 myInfoGroup->layout()->setSpacing(0);
124 myInfoGroup->layout()->setMargin(0);
125 QGridLayout* myInfoGroupLayout = new QGridLayout(myInfoGroup->layout());
126 myInfoGroupLayout->setAlignment(Qt::AlignTop);
127 myInfoGroupLayout->setSpacing(6);
128 myInfoGroupLayout->setMargin(11);
130 // information text browser
131 myInfo = new QTextBrowser(myInfoGroup, "myInfo");
132 myInfoGroupLayout->addWidget(myInfo, 0, 0);
134 aDlgLayout->addWidget(myInfoGroup, 1, 0);
137 myButtonsGroup = new QGroupBox(this, "myButtonsGroup");
138 myButtonsGroup->setColumnLayout(0, Qt::Vertical);
139 myButtonsGroup->layout()->setSpacing(0); myButtonsGroup->layout()->setMargin(0);
140 QHBoxLayout* myButtonsGroupLayout = new QHBoxLayout(myButtonsGroup->layout());
141 myButtonsGroupLayout->setAlignment(Qt::AlignTop);
142 myButtonsGroupLayout->setSpacing(6); myButtonsGroupLayout->setMargin(11);
144 // buttons --> OK button
145 myOkBtn = new QPushButton(tr("SMESH_BUT_OK" ), myButtonsGroup, "myOkBtn");
146 myOkBtn->setAutoDefault(TRUE); myOkBtn->setDefault(TRUE);
147 myButtonsGroupLayout->addStretch();
148 myButtonsGroupLayout->addWidget(myOkBtn);
149 myButtonsGroupLayout->addStretch();
151 aDlgLayout->addWidget(myButtonsGroup, 2, 0);
153 mySelectionMgr = SMESHGUI::selectionMgr();
154 SMESHGUI::GetSMESHGUI()->SetActiveDialogBox(this);
157 connect(myOkBtn, SIGNAL(clicked()), this, SLOT(close()));
158 connect(mySelectBtn, SIGNAL(clicked()), this, SLOT(onStartSelection()));
159 connect(SMESHGUI::GetSMESHGUI(), SIGNAL(SignalCloseAllDialogs()), this, SLOT(close()));
160 connect(SMESHGUI::GetSMESHGUI(), SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
161 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(onSelectionChanged()));
163 // resize and move dialog, then show
164 this->setMinimumSize(270, 428);
166 SMESHGUI::GetSMESHGUI()->DefineDlgPosition(this, x, y);
170 // init dialog with current selection
171 myMeshFilter = new SMESH_TypeFilter (MESH);
172 mySelectionMgr->installFilter(myMeshFilter);
173 onSelectionChanged();
176 //=================================================================================
178 * SMESHGUI_StandardMeshInfosDlg::~SMESHGUI_StandardMeshInfosDlg
182 //=================================================================================
183 SMESHGUI_StandardMeshInfosDlg::~SMESHGUI_StandardMeshInfosDlg()
187 //=================================================================================
189 * SMESHGUI_StandardMeshInfosDlg::DumpMeshInfos
191 //=================================================================================
192 void SMESHGUI_StandardMeshInfosDlg::DumpMeshInfos()
194 SUIT_OverrideCursor wc;
197 mySelectionMgr->selectedObjects(aList);
199 int nbSel = aList.Extent();
202 myStartSelection = false;
203 myMeshLine->setText("");
204 SMESH::SMESH_Mesh_var aMesh = SMESH::GetMeshByIO(aList.First());
206 if (!aMesh->_is_nil()) {
207 QString aName, anInfo;
208 SMESH::GetNameOfSelectedIObjects(mySelectionMgr, aName);
209 myMeshLine->setText(aName);
210 int aNbNodes = (int)aMesh->NbNodes();
211 int aNbEdges = (int)aMesh->NbEdges();
212 int aNbFaces = (int)aMesh->NbFaces();
213 int aNbVolumes = (int)aMesh->NbVolumes();
216 double aNbDimElements = 0;
217 if (aNbVolumes > 0) {
218 aNbDimElements = aNbVolumes;
221 else if(aNbFaces > 0) {
222 aNbDimElements = aNbFaces;
225 else if(aNbEdges > 0) {
226 aNbDimElements = aNbEdges;
229 else if(aNbNodes > 0) {
230 aNbDimElements = aNbNodes;
234 // information about the mesh
235 anInfo.append(QString("Nb of element of dimension %1:<b> %2</b><br>").arg(aDimension).arg(aNbDimElements));
236 anInfo.append(QString("Nb of nodes: <b>%1</b><br><br>").arg(aNbNodes));
238 // information about the groups of the mesh
239 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
240 _PTR(SObject) aMeshSO = SMESH::FindSObject(aMesh);
243 bool hasGroup = false;
245 // info about groups on nodes
246 aMeshSO->FindSubObject(Tag_NodeGroups, anObj);
248 _PTR(ChildIterator) it = aStudy->NewChildIterator(anObj);
250 anInfo.append(QString("Groups:<br><br>"));
253 for (; it->More(); it->Next()) {
254 _PTR(SObject) subObj = it->Value();
255 CORBA::Object_var anObject = SMESH::SObjectToObject(subObj);
256 SMESH::SMESH_GroupBase_var aGroup = SMESH::SMESH_GroupBase::_narrow(anObject);
257 if (!aGroup->_is_nil()) {
258 anInfo.append(QString("- <b>%1</b><br>").arg(aGroup->GetName()));
259 anInfo.append(QString("%1<br>").arg("on nodes"));
260 anInfo.append(QString("%1<br>").arg(aGroup->Size()));
261 // check if the group based on geometry
262 SMESH::SMESH_GroupOnGeom_var aGroupOnGeom = SMESH::SMESH_GroupOnGeom::_narrow(aGroup);
263 if (!aGroupOnGeom->_is_nil()) {
264 GEOM::GEOM_Object_var aGroupMainShape = aGroupOnGeom->GetShape();
265 QString aShapeName = "<unknown>";
266 _PTR(SObject) aGeomObj, aRef;
267 if (subObj->FindSubObject(1, aGeomObj) && aGeomObj->ReferencedObject(aRef))
268 aShapeName = aRef->GetName().c_str();
269 anInfo.append(QString("based on <i>%1</i> geometry object<br><br>").arg(aShapeName));
271 anInfo.append(QString("<br>"));
277 // info about groups on edges
279 aMeshSO->FindSubObject(Tag_EdgeGroups, anObj);
281 _PTR(ChildIterator) it = aStudy->NewChildIterator(anObj);
282 if (!hasGroup && it->More()) {
283 anInfo.append(QString("Groups:<br><br>"));
286 for (; it->More(); it->Next()) {
287 _PTR(SObject) subObj = it->Value();
288 CORBA::Object_var anObject = SMESH::SObjectToObject(subObj);
289 SMESH::SMESH_GroupBase_var aGroup = SMESH::SMESH_GroupBase::_narrow(anObject);
290 if (!aGroup->_is_nil()) {
291 anInfo.append(QString("- <b>%1</b><br>").arg(aGroup->GetName()));
292 anInfo.append(QString("%1<br>").arg("on edges"));
293 anInfo.append(QString("%1<br>").arg(aGroup->Size()));
294 // check if the group based on geometry
295 SMESH::SMESH_GroupOnGeom_var aGroupOnGeom = SMESH::SMESH_GroupOnGeom::_narrow(aGroup);
296 if (!aGroupOnGeom->_is_nil()) {
297 GEOM::GEOM_Object_var aGroupMainShape = aGroupOnGeom->GetShape();
298 QString aShapeName = "<unknown>";
299 _PTR(SObject) aGeomObj, aRef;
300 if (subObj->FindSubObject(1, aGeomObj) && aGeomObj->ReferencedObject(aRef))
301 aShapeName = aRef->GetName().c_str();
302 anInfo.append(QString("based on <i>%1</i> geometry object<br><br>").arg(aShapeName));
304 anInfo.append(QString("<br>"));
310 // info about groups on faces
312 aMeshSO->FindSubObject(Tag_FaceGroups , anObj);
314 _PTR(ChildIterator) it = aStudy->NewChildIterator(anObj);
315 if (!hasGroup && it->More()) {
316 anInfo.append(QString("Groups:<br><br>"));
319 for (; it->More(); it->Next()) {
320 _PTR(SObject) subObj = it->Value();
321 CORBA::Object_var anObject = SMESH::SObjectToObject(subObj);
322 SMESH::SMESH_GroupBase_var aGroup = SMESH::SMESH_GroupBase::_narrow(anObject);
323 if (!aGroup->_is_nil()) {
324 anInfo.append(QString("- <b>%1</b><br>").arg(aGroup->GetName()));
325 anInfo.append(QString("%1<br>").arg("on faces"));
326 anInfo.append(QString("%1<br>").arg(aGroup->Size()));
327 // check if the group based on geometry
328 SMESH::SMESH_GroupOnGeom_var aGroupOnGeom = SMESH::SMESH_GroupOnGeom::_narrow(aGroup);
329 if (!aGroupOnGeom->_is_nil()) {
330 GEOM::GEOM_Object_var aGroupMainShape = aGroupOnGeom->GetShape();
331 QString aShapeName = "<unknown>";
332 _PTR(SObject) aGeomObj, aRef;
333 if (subObj->FindSubObject(1, aGeomObj) && aGeomObj->ReferencedObject(aRef))
334 aShapeName = aRef->GetName().c_str();
335 anInfo.append(QString("based on <i>%1</i> geometry object<br><br>").arg(aShapeName));
337 anInfo.append(QString("<br>"));
343 // info about groups on volumes
345 aMeshSO->FindSubObject(Tag_VolumeGroups, anObj);
347 _PTR(ChildIterator) it = aStudy->NewChildIterator(anObj);
348 if (!hasGroup && it->More())
349 anInfo.append(QString("Groups:<br>"));
350 for (; it->More(); it->Next()) {
351 _PTR(SObject) subObj = it->Value();
352 CORBA::Object_var anObject = SMESH::SObjectToObject(subObj);
353 SMESH::SMESH_GroupBase_var aGroup = SMESH::SMESH_GroupBase::_narrow(anObject);
354 if (!aGroup->_is_nil()) {
355 anInfo.append(QString("- <b>%1</b><br>").arg(aGroup->GetName()));
356 anInfo.append(QString("%1<br>").arg("on volumes"));
357 anInfo.append(QString("%1<br>").arg(aGroup->Size()));
358 // check if the group based on geometry
359 SMESH::SMESH_GroupOnGeom_var aGroupOnGeom = SMESH::SMESH_GroupOnGeom::_narrow(aGroup);
360 if (!aGroupOnGeom->_is_nil()) {
361 GEOM::GEOM_Object_var aGroupMainShape = aGroupOnGeom->GetShape();
362 QString aShapeName = "<unknown>";
363 _PTR(SObject) aGeomObj, aRef;
364 if (subObj->FindSubObject(1, aGeomObj) && aGeomObj->ReferencedObject(aRef))
365 aShapeName = aRef->GetName().c_str();
366 anInfo.append(QString("based on <i>%1</i> geometry object<br><br>").arg(aShapeName));
368 anInfo.append(QString("<br>"));
374 myInfo->setText(anInfo);
380 //=================================================================================
381 // function : SelectionIntoArgument()
382 // purpose : Called when selection has changed
383 //=================================================================================
384 void SMESHGUI_StandardMeshInfosDlg::onSelectionChanged()
386 if (myStartSelection)
390 //=================================================================================
391 // function : closeEvent()
393 //=================================================================================
394 void SMESHGUI_StandardMeshInfosDlg::closeEvent (QCloseEvent* e)
396 mySelectionMgr->clearFilters();
397 SMESHGUI::GetSMESHGUI()->ResetState();
398 QDialog::closeEvent(e);
401 //=================================================================================
402 // function : windowActivationChange()
403 // purpose : called when window is activated/deactivated
404 //=================================================================================
405 void SMESHGUI_StandardMeshInfosDlg::windowActivationChange (bool oldActive)
407 QDialog::windowActivationChange(oldActive);
408 if (isActiveWindow() && myIsActiveWindow != isActiveWindow())
409 ActivateThisDialog();
410 myIsActiveWindow = isActiveWindow();
413 //=================================================================================
414 // function : DeactivateActiveDialog()
416 //=================================================================================
417 void SMESHGUI_StandardMeshInfosDlg::DeactivateActiveDialog()
419 disconnect(mySelectionMgr, 0, this, 0);
422 //=================================================================================
423 // function : ActivateThisDialog()
425 //=================================================================================
426 void SMESHGUI_StandardMeshInfosDlg::ActivateThisDialog()
428 /* Emit a signal to deactivate any active dialog */
429 SMESHGUI::GetSMESHGUI()->EmitSignalDeactivateDialog();
430 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(onSelectionChanged()));
433 //=================================================================================
434 // function : onStartSelection()
435 // purpose : starts selection
436 //=================================================================================
437 void SMESHGUI_StandardMeshInfosDlg::onStartSelection()
439 myStartSelection = true;
440 mySelectionMgr->installFilter(myMeshFilter);
441 myMeshLine->setText(tr("Select a mesh"));
442 onSelectionChanged();
443 myStartSelection = true;