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"
45 #include "LightApp_SelectionMgr.h"
46 #include "SALOME_ListIO.hxx"
48 #include "utilities.h"
51 #include <qgroupbox.h>
54 #include <qlineedit.h>
55 #include <qtextbrowser.h>
57 #include <qpushbutton.h>
60 #include "SALOMEconfig.h"
61 #include CORBA_SERVER_HEADER(SMESH_Mesh)
62 #include CORBA_SERVER_HEADER(SMESH_Group)
63 #include CORBA_SERVER_HEADER(GEOM_Gen)
68 //=================================================================================
70 * SMESHGUI_StandardMeshInfosDlg::SMESHGUI_StandardMeshInfosDlg
74 //=================================================================================
75 SMESHGUI_StandardMeshInfosDlg::SMESHGUI_StandardMeshInfosDlg( SMESHGUI* theModule, const char* name,
76 bool modal, WFlags fl)
77 : QDialog( SMESH::GetDesktop( theModule ), name, modal, WStyle_Customize | WStyle_NormalBorder |
78 WStyle_Title | WStyle_SysMenu | WDestructiveClose),
79 mySMESHGUI( theModule ),
80 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) )
83 setName("SMESHGUI_StandardMeshInfosDlg");
84 setCaption(tr("SMESH_STANDARD_MESHINFO_TITLE" ));
85 setSizeGripEnabled(TRUE);
87 myStartSelection = true;
88 myIsActiveWindow = true;
91 QGridLayout* aDlgLayout = new QGridLayout(this);
92 aDlgLayout->setSpacing(6);
93 aDlgLayout->setMargin(11);
96 myMeshGroup = new QGroupBox(this, "myMeshGroup");
97 myMeshGroup->setTitle(tr("SMESH_MESH"));
98 myMeshGroup->setColumnLayout(0, Qt::Vertical);
99 myMeshGroup->layout()->setSpacing(0);
100 myMeshGroup->layout()->setMargin(0);
101 QGridLayout* myMeshGroupLayout = new QGridLayout(myMeshGroup->layout());
102 myMeshGroupLayout->setAlignment(Qt::AlignTop);
103 myMeshGroupLayout->setSpacing(6);
104 myMeshGroupLayout->setMargin(11);
106 // select button, label and line edit with mesh name
107 myNameLab = new QLabel(myMeshGroup, "myNameLab");
108 myNameLab->setText(tr("SMESH_NAME" ));
109 myMeshGroupLayout->addWidget(myNameLab, 0, 0);
111 QPixmap image0(SUIT_Session::session()->resourceMgr()->loadPixmap("SMESH",tr("ICON_SELECT")));
112 mySelectBtn = new QPushButton(myMeshGroup, "mySelectBtn");
113 mySelectBtn->setPixmap(image0);
114 mySelectBtn->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed));
115 myMeshGroupLayout->addWidget(mySelectBtn, 0, 1);
117 myMeshLine = new QLineEdit(myMeshGroup, "myMeshLine");
118 myMeshGroupLayout->addWidget(myMeshLine, 0, 2);
120 aDlgLayout->addWidget(myMeshGroup, 0, 0);
122 // information group box
123 myInfoGroup = new QGroupBox(this, "myInfoGroup");
124 myInfoGroup->setTitle(tr("SMESH_INFORMATION"));
125 myInfoGroup->setColumnLayout(0, Qt::Vertical);
126 myInfoGroup->layout()->setSpacing(0);
127 myInfoGroup->layout()->setMargin(0);
128 QGridLayout* myInfoGroupLayout = new QGridLayout(myInfoGroup->layout());
129 myInfoGroupLayout->setAlignment(Qt::AlignTop);
130 myInfoGroupLayout->setSpacing(6);
131 myInfoGroupLayout->setMargin(11);
133 // information text browser
134 myInfo = new QTextBrowser(myInfoGroup, "myInfo");
135 myInfoGroupLayout->addWidget(myInfo, 0, 0);
137 aDlgLayout->addWidget(myInfoGroup, 1, 0);
140 myButtonsGroup = new QGroupBox(this, "myButtonsGroup");
141 myButtonsGroup->setColumnLayout(0, Qt::Vertical);
142 myButtonsGroup->layout()->setSpacing(0); myButtonsGroup->layout()->setMargin(0);
143 QHBoxLayout* myButtonsGroupLayout = new QHBoxLayout(myButtonsGroup->layout());
144 myButtonsGroupLayout->setAlignment(Qt::AlignTop);
145 myButtonsGroupLayout->setSpacing(6); myButtonsGroupLayout->setMargin(11);
147 // buttons --> OK button
148 myOkBtn = new QPushButton(tr("SMESH_BUT_OK" ), myButtonsGroup, "myOkBtn");
149 myOkBtn->setAutoDefault(TRUE); myOkBtn->setDefault(TRUE);
150 myButtonsGroupLayout->addStretch();
151 myButtonsGroupLayout->addWidget(myOkBtn);
152 myButtonsGroupLayout->addStretch();
154 aDlgLayout->addWidget(myButtonsGroup, 2, 0);
156 mySMESHGUI->SetActiveDialogBox(this);
159 connect( myOkBtn, SIGNAL(clicked()), this, SLOT(close()));
160 connect( mySelectBtn, SIGNAL(clicked()), this, SLOT(onStartSelection()));
161 connect( mySMESHGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(close()));
162 connect( mySMESHGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
163 connect( mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(onSelectionChanged()));
165 // resize and move dialog, then show
166 this->setMinimumSize(270, 428);
168 mySMESHGUI->DefineDlgPosition(this, x, y);
172 // init dialog with current selection
173 myMeshFilter = new SMESH_TypeFilter (MESH);
174 mySelectionMgr->installFilter(myMeshFilter);
175 onSelectionChanged();
178 //=================================================================================
180 * SMESHGUI_StandardMeshInfosDlg::~SMESHGUI_StandardMeshInfosDlg
184 //=================================================================================
185 SMESHGUI_StandardMeshInfosDlg::~SMESHGUI_StandardMeshInfosDlg()
189 //=================================================================================
191 * SMESHGUI_StandardMeshInfosDlg::DumpMeshInfos
193 //=================================================================================
194 void SMESHGUI_StandardMeshInfosDlg::DumpMeshInfos()
196 SUIT_OverrideCursor wc;
199 mySelectionMgr->selectedObjects(aList);
201 int nbSel = aList.Extent();
204 myStartSelection = false;
205 myMeshLine->setText("");
206 SMESH::SMESH_Mesh_var aMesh = SMESH::GetMeshByIO(aList.First());
208 if (!aMesh->_is_nil()) {
209 QString aName, anInfo;
210 SMESH::GetNameOfSelectedIObjects(mySelectionMgr, aName);
211 myMeshLine->setText(aName);
212 int aNbNodes = (int)aMesh->NbNodes();
213 int aNbEdges = (int)aMesh->NbEdges();
214 int aNbFaces = (int)aMesh->NbFaces();
215 int aNbVolumes = (int)aMesh->NbVolumes();
218 double aNbDimElements = 0;
219 if (aNbVolumes > 0) {
220 aNbDimElements = aNbVolumes;
223 else if(aNbFaces > 0) {
224 aNbDimElements = aNbFaces;
227 else if(aNbEdges > 0) {
228 aNbDimElements = aNbEdges;
231 else if(aNbNodes > 0) {
232 aNbDimElements = aNbNodes;
236 // information about the mesh
237 anInfo.append(QString("Nb of element of dimension %1:<b> %2</b><br>").arg(aDimension).arg(aNbDimElements));
238 anInfo.append(QString("Nb of nodes: <b>%1</b><br><br>").arg(aNbNodes));
240 // information about the groups of the mesh
241 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
242 _PTR(SObject) aMeshSO = SMESH::FindSObject(aMesh);
245 bool hasGroup = false;
247 // info about groups on nodes
248 aMeshSO->FindSubObject(Tag_NodeGroups, anObj);
250 _PTR(ChildIterator) it = aStudy->NewChildIterator(anObj);
252 anInfo.append(QString("Groups:<br><br>"));
255 for (; it->More(); it->Next()) {
256 _PTR(SObject) subObj = it->Value();
257 CORBA::Object_var anObject = SMESH::SObjectToObject(subObj);
258 SMESH::SMESH_GroupBase_var aGroup = SMESH::SMESH_GroupBase::_narrow(anObject);
259 if (!aGroup->_is_nil()) {
260 anInfo.append(QString("- <b>%1</b><br>").arg(aGroup->GetName()));
261 anInfo.append(QString("%1<br>").arg("on nodes"));
262 anInfo.append(QString("%1<br>").arg(aGroup->Size()));
263 // check if the group based on geometry
264 SMESH::SMESH_GroupOnGeom_var aGroupOnGeom = SMESH::SMESH_GroupOnGeom::_narrow(aGroup);
265 if (!aGroupOnGeom->_is_nil()) {
266 GEOM::GEOM_Object_var aGroupMainShape = aGroupOnGeom->GetShape();
267 QString aShapeName = "<unknown>";
268 _PTR(SObject) aGeomObj, aRef;
269 if (subObj->FindSubObject(1, aGeomObj) && aGeomObj->ReferencedObject(aRef))
270 aShapeName = aRef->GetName().c_str();
271 anInfo.append(QString("based on <i>%1</i> geometry object<br><br>").arg(aShapeName));
273 anInfo.append(QString("<br>"));
279 // info about groups on edges
281 aMeshSO->FindSubObject(Tag_EdgeGroups, anObj);
283 _PTR(ChildIterator) it = aStudy->NewChildIterator(anObj);
284 if (!hasGroup && it->More()) {
285 anInfo.append(QString("Groups:<br><br>"));
288 for (; it->More(); it->Next()) {
289 _PTR(SObject) subObj = it->Value();
290 CORBA::Object_var anObject = SMESH::SObjectToObject(subObj);
291 SMESH::SMESH_GroupBase_var aGroup = SMESH::SMESH_GroupBase::_narrow(anObject);
292 if (!aGroup->_is_nil()) {
293 anInfo.append(QString("- <b>%1</b><br>").arg(aGroup->GetName()));
294 anInfo.append(QString("%1<br>").arg("on edges"));
295 anInfo.append(QString("%1<br>").arg(aGroup->Size()));
296 // check if the group based on geometry
297 SMESH::SMESH_GroupOnGeom_var aGroupOnGeom = SMESH::SMESH_GroupOnGeom::_narrow(aGroup);
298 if (!aGroupOnGeom->_is_nil()) {
299 GEOM::GEOM_Object_var aGroupMainShape = aGroupOnGeom->GetShape();
300 QString aShapeName = "<unknown>";
301 _PTR(SObject) aGeomObj, aRef;
302 if (subObj->FindSubObject(1, aGeomObj) && aGeomObj->ReferencedObject(aRef))
303 aShapeName = aRef->GetName().c_str();
304 anInfo.append(QString("based on <i>%1</i> geometry object<br><br>").arg(aShapeName));
306 anInfo.append(QString("<br>"));
312 // info about groups on faces
314 aMeshSO->FindSubObject(Tag_FaceGroups , anObj);
316 _PTR(ChildIterator) it = aStudy->NewChildIterator(anObj);
317 if (!hasGroup && it->More()) {
318 anInfo.append(QString("Groups:<br><br>"));
321 for (; it->More(); it->Next()) {
322 _PTR(SObject) subObj = it->Value();
323 CORBA::Object_var anObject = SMESH::SObjectToObject(subObj);
324 SMESH::SMESH_GroupBase_var aGroup = SMESH::SMESH_GroupBase::_narrow(anObject);
325 if (!aGroup->_is_nil()) {
326 anInfo.append(QString("- <b>%1</b><br>").arg(aGroup->GetName()));
327 anInfo.append(QString("%1<br>").arg("on faces"));
328 anInfo.append(QString("%1<br>").arg(aGroup->Size()));
329 // check if the group based on geometry
330 SMESH::SMESH_GroupOnGeom_var aGroupOnGeom = SMESH::SMESH_GroupOnGeom::_narrow(aGroup);
331 if (!aGroupOnGeom->_is_nil()) {
332 GEOM::GEOM_Object_var aGroupMainShape = aGroupOnGeom->GetShape();
333 QString aShapeName = "<unknown>";
334 _PTR(SObject) aGeomObj, aRef;
335 if (subObj->FindSubObject(1, aGeomObj) && aGeomObj->ReferencedObject(aRef))
336 aShapeName = aRef->GetName().c_str();
337 anInfo.append(QString("based on <i>%1</i> geometry object<br><br>").arg(aShapeName));
339 anInfo.append(QString("<br>"));
345 // info about groups on volumes
347 aMeshSO->FindSubObject(Tag_VolumeGroups, anObj);
349 _PTR(ChildIterator) it = aStudy->NewChildIterator(anObj);
350 if (!hasGroup && it->More())
351 anInfo.append(QString("Groups:<br>"));
352 for (; it->More(); it->Next()) {
353 _PTR(SObject) subObj = it->Value();
354 CORBA::Object_var anObject = SMESH::SObjectToObject(subObj);
355 SMESH::SMESH_GroupBase_var aGroup = SMESH::SMESH_GroupBase::_narrow(anObject);
356 if (!aGroup->_is_nil()) {
357 anInfo.append(QString("- <b>%1</b><br>").arg(aGroup->GetName()));
358 anInfo.append(QString("%1<br>").arg("on volumes"));
359 anInfo.append(QString("%1<br>").arg(aGroup->Size()));
360 // check if the group based on geometry
361 SMESH::SMESH_GroupOnGeom_var aGroupOnGeom = SMESH::SMESH_GroupOnGeom::_narrow(aGroup);
362 if (!aGroupOnGeom->_is_nil()) {
363 GEOM::GEOM_Object_var aGroupMainShape = aGroupOnGeom->GetShape();
364 QString aShapeName = "<unknown>";
365 _PTR(SObject) aGeomObj, aRef;
366 if (subObj->FindSubObject(1, aGeomObj) && aGeomObj->ReferencedObject(aRef))
367 aShapeName = aRef->GetName().c_str();
368 anInfo.append(QString("based on <i>%1</i> geometry object<br><br>").arg(aShapeName));
370 anInfo.append(QString("<br>"));
376 myInfo->setText(anInfo);
382 //=================================================================================
383 // function : SelectionIntoArgument()
384 // purpose : Called when selection has changed
385 //=================================================================================
386 void SMESHGUI_StandardMeshInfosDlg::onSelectionChanged()
388 if (myStartSelection)
392 //=================================================================================
393 // function : closeEvent()
395 //=================================================================================
396 void SMESHGUI_StandardMeshInfosDlg::closeEvent (QCloseEvent* e)
398 mySelectionMgr->clearFilters();
399 mySMESHGUI->ResetState();
400 QDialog::closeEvent(e);
403 //=================================================================================
404 // function : windowActivationChange()
405 // purpose : called when window is activated/deactivated
406 //=================================================================================
407 void SMESHGUI_StandardMeshInfosDlg::windowActivationChange (bool oldActive)
409 QDialog::windowActivationChange(oldActive);
410 if (isActiveWindow() && myIsActiveWindow != isActiveWindow())
411 ActivateThisDialog();
412 myIsActiveWindow = isActiveWindow();
415 //=================================================================================
416 // function : DeactivateActiveDialog()
418 //=================================================================================
419 void SMESHGUI_StandardMeshInfosDlg::DeactivateActiveDialog()
421 disconnect(mySelectionMgr, 0, this, 0);
424 //=================================================================================
425 // function : ActivateThisDialog()
427 //=================================================================================
428 void SMESHGUI_StandardMeshInfosDlg::ActivateThisDialog()
430 /* Emit a signal to deactivate any active dialog */
431 mySMESHGUI->EmitSignalDeactivateDialog();
432 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(onSelectionChanged()));
435 //=================================================================================
436 // function : onStartSelection()
437 // purpose : starts selection
438 //=================================================================================
439 void SMESHGUI_StandardMeshInfosDlg::onStartSelection()
441 myStartSelection = true;
442 mySelectionMgr->installFilter(myMeshFilter);
443 myMeshLine->setText(tr("Select a mesh"));
444 onSelectionChanged();
445 myStartSelection = true;