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);
169 // init dialog with current selection
170 myMeshFilter = new SMESH_TypeFilter (MESH);
171 mySelectionMgr->installFilter(myMeshFilter);
172 onSelectionChanged();
175 //=================================================================================
177 * SMESHGUI_StandardMeshInfosDlg::~SMESHGUI_StandardMeshInfosDlg
181 //=================================================================================
182 SMESHGUI_StandardMeshInfosDlg::~SMESHGUI_StandardMeshInfosDlg()
186 //=================================================================================
188 * SMESHGUI_StandardMeshInfosDlg::DumpMeshInfos
190 //=================================================================================
191 void SMESHGUI_StandardMeshInfosDlg::DumpMeshInfos()
193 SUIT_OverrideCursor wc;
196 mySelectionMgr->selectedObjects(aList);
198 int nbSel = aList.Extent();
201 myStartSelection = false;
202 myMeshLine->setText("");
203 SMESH::SMESH_Mesh_var aMesh = SMESH::GetMeshByIO(aList.First());
205 if (!aMesh->_is_nil()) {
206 QString aName, anInfo;
207 SMESH::GetNameOfSelectedIObjects(mySelectionMgr, aName);
208 myMeshLine->setText(aName);
209 int aNbNodes = (int)aMesh->NbNodes();
210 int aNbEdges = (int)aMesh->NbEdges();
211 int aNbFaces = (int)aMesh->NbFaces();
212 int aNbVolumes = (int)aMesh->NbVolumes();
215 double aNbDimElements = 0;
216 if (aNbVolumes > 0) {
217 aNbDimElements = aNbVolumes;
220 else if(aNbFaces > 0) {
221 aNbDimElements = aNbFaces;
224 else if(aNbEdges > 0) {
225 aNbDimElements = aNbEdges;
228 else if(aNbNodes > 0) {
229 aNbDimElements = aNbNodes;
233 // information about the mesh
234 anInfo.append(QString("Nb of element of dimension %1:<b> %2</b><br>").arg(aDimension).arg(aNbDimElements));
235 anInfo.append(QString("Nb of nodes: <b>%1</b><br><br>").arg(aNbNodes));
237 // information about the groups of the mesh
238 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
239 _PTR(SObject) aMeshSO = SMESH::FindSObject(aMesh);
242 bool hasGroup = false;
244 // info about groups on nodes
245 aMeshSO->FindSubObject(Tag_NodeGroups, anObj);
247 _PTR(ChildIterator) it = aStudy->NewChildIterator(anObj);
249 anInfo.append(QString("Groups:<br><br>"));
252 for (; it->More(); it->Next()) {
253 _PTR(SObject) subObj = it->Value();
254 CORBA::Object_var anObject = SMESH::SObjectToObject(subObj);
255 SMESH::SMESH_GroupBase_var aGroup = SMESH::SMESH_GroupBase::_narrow(anObject);
256 if (!aGroup->_is_nil()) {
257 anInfo.append(QString("- <b>%1</b><br>").arg(aGroup->GetName()));
258 anInfo.append(QString("%1<br>").arg("on nodes"));
259 anInfo.append(QString("%1<br>").arg(aGroup->Size()));
260 // check if the group based on geometry
261 SMESH::SMESH_GroupOnGeom_var aGroupOnGeom = SMESH::SMESH_GroupOnGeom::_narrow(aGroup);
262 if (!aGroupOnGeom->_is_nil()) {
263 GEOM::GEOM_Object_var aGroupMainShape = aGroupOnGeom->GetShape();
264 QString aShapeName = "<unknown>";
265 _PTR(SObject) aGeomObj, aRef;
266 if (subObj->FindSubObject(1, aGeomObj) && aGeomObj->ReferencedObject(aRef))
267 aShapeName = aRef->GetName().c_str();
268 anInfo.append(QString("based on <i>%1</i> geometry object<br><br>").arg(aShapeName));
270 anInfo.append(QString("<br>"));
276 // info about groups on edges
278 aMeshSO->FindSubObject(Tag_EdgeGroups, anObj);
280 _PTR(ChildIterator) it = aStudy->NewChildIterator(anObj);
281 if (!hasGroup && it->More()) {
282 anInfo.append(QString("Groups:<br><br>"));
285 for (; it->More(); it->Next()) {
286 _PTR(SObject) subObj = it->Value();
287 CORBA::Object_var anObject = SMESH::SObjectToObject(subObj);
288 SMESH::SMESH_GroupBase_var aGroup = SMESH::SMESH_GroupBase::_narrow(anObject);
289 if (!aGroup->_is_nil()) {
290 anInfo.append(QString("- <b>%1</b><br>").arg(aGroup->GetName()));
291 anInfo.append(QString("%1<br>").arg("on edges"));
292 anInfo.append(QString("%1<br>").arg(aGroup->Size()));
293 // check if the group based on geometry
294 SMESH::SMESH_GroupOnGeom_var aGroupOnGeom = SMESH::SMESH_GroupOnGeom::_narrow(aGroup);
295 if (!aGroupOnGeom->_is_nil()) {
296 GEOM::GEOM_Object_var aGroupMainShape = aGroupOnGeom->GetShape();
297 QString aShapeName = "<unknown>";
298 _PTR(SObject) aGeomObj, aRef;
299 if (subObj->FindSubObject(1, aGeomObj) && aGeomObj->ReferencedObject(aRef))
300 aShapeName = aRef->GetName().c_str();
301 anInfo.append(QString("based on <i>%1</i> geometry object<br><br>").arg(aShapeName));
303 anInfo.append(QString("<br>"));
309 // info about groups on faces
311 aMeshSO->FindSubObject(Tag_FaceGroups , anObj);
313 _PTR(ChildIterator) it = aStudy->NewChildIterator(anObj);
314 if (!hasGroup && it->More()) {
315 anInfo.append(QString("Groups:<br><br>"));
318 for (; it->More(); it->Next()) {
319 _PTR(SObject) subObj = it->Value();
320 CORBA::Object_var anObject = SMESH::SObjectToObject(subObj);
321 SMESH::SMESH_GroupBase_var aGroup = SMESH::SMESH_GroupBase::_narrow(anObject);
322 if (!aGroup->_is_nil()) {
323 anInfo.append(QString("- <b>%1</b><br>").arg(aGroup->GetName()));
324 anInfo.append(QString("%1<br>").arg("on faces"));
325 anInfo.append(QString("%1<br>").arg(aGroup->Size()));
326 // check if the group based on geometry
327 SMESH::SMESH_GroupOnGeom_var aGroupOnGeom = SMESH::SMESH_GroupOnGeom::_narrow(aGroup);
328 if (!aGroupOnGeom->_is_nil()) {
329 GEOM::GEOM_Object_var aGroupMainShape = aGroupOnGeom->GetShape();
330 QString aShapeName = "<unknown>";
331 _PTR(SObject) aGeomObj, aRef;
332 if (subObj->FindSubObject(1, aGeomObj) && aGeomObj->ReferencedObject(aRef))
333 aShapeName = aRef->GetName().c_str();
334 anInfo.append(QString("based on <i>%1</i> geometry object<br><br>").arg(aShapeName));
336 anInfo.append(QString("<br>"));
342 // info about groups on volumes
344 aMeshSO->FindSubObject(Tag_VolumeGroups, anObj);
346 _PTR(ChildIterator) it = aStudy->NewChildIterator(anObj);
347 if (!hasGroup && it->More())
348 anInfo.append(QString("Groups:<br>"));
349 for (; it->More(); it->Next()) {
350 _PTR(SObject) subObj = it->Value();
351 CORBA::Object_var anObject = SMESH::SObjectToObject(subObj);
352 SMESH::SMESH_GroupBase_var aGroup = SMESH::SMESH_GroupBase::_narrow(anObject);
353 if (!aGroup->_is_nil()) {
354 anInfo.append(QString("- <b>%1</b><br>").arg(aGroup->GetName()));
355 anInfo.append(QString("%1<br>").arg("on volumes"));
356 anInfo.append(QString("%1<br>").arg(aGroup->Size()));
357 // check if the group based on geometry
358 SMESH::SMESH_GroupOnGeom_var aGroupOnGeom = SMESH::SMESH_GroupOnGeom::_narrow(aGroup);
359 if (!aGroupOnGeom->_is_nil()) {
360 GEOM::GEOM_Object_var aGroupMainShape = aGroupOnGeom->GetShape();
361 QString aShapeName = "<unknown>";
362 _PTR(SObject) aGeomObj, aRef;
363 if (subObj->FindSubObject(1, aGeomObj) && aGeomObj->ReferencedObject(aRef))
364 aShapeName = aRef->GetName().c_str();
365 anInfo.append(QString("based on <i>%1</i> geometry object<br><br>").arg(aShapeName));
367 anInfo.append(QString("<br>"));
373 myInfo->setText(anInfo);
379 //=================================================================================
380 // function : SelectionIntoArgument()
381 // purpose : Called when selection has changed
382 //=================================================================================
383 void SMESHGUI_StandardMeshInfosDlg::onSelectionChanged()
385 if (myStartSelection)
389 //=================================================================================
390 // function : closeEvent()
392 //=================================================================================
393 void SMESHGUI_StandardMeshInfosDlg::closeEvent (QCloseEvent* e)
395 mySelectionMgr->clearFilters();
396 mySMESHGUI->ResetState();
397 QDialog::closeEvent(e);
400 //=================================================================================
401 // function : windowActivationChange()
402 // purpose : called when window is activated/deactivated
403 //=================================================================================
404 void SMESHGUI_StandardMeshInfosDlg::windowActivationChange (bool oldActive)
406 QDialog::windowActivationChange(oldActive);
407 if (isActiveWindow() && myIsActiveWindow != isActiveWindow())
408 ActivateThisDialog();
409 myIsActiveWindow = isActiveWindow();
412 //=================================================================================
413 // function : DeactivateActiveDialog()
415 //=================================================================================
416 void SMESHGUI_StandardMeshInfosDlg::DeactivateActiveDialog()
418 disconnect(mySelectionMgr, 0, this, 0);
421 //=================================================================================
422 // function : ActivateThisDialog()
424 //=================================================================================
425 void SMESHGUI_StandardMeshInfosDlg::ActivateThisDialog()
427 /* Emit a signal to deactivate any active dialog */
428 mySMESHGUI->EmitSignalDeactivateDialog();
429 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(onSelectionChanged()));
432 //=================================================================================
433 // function : onStartSelection()
434 // purpose : starts selection
435 //=================================================================================
436 void SMESHGUI_StandardMeshInfosDlg::onStartSelection()
438 myStartSelection = true;
439 mySelectionMgr->installFilter(myMeshFilter);
440 myMeshLine->setText(tr("Select a mesh"));
441 onSelectionChanged();
442 myStartSelection = true;