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
30 #include <qgroupbox.h>
33 #include <qlineedit.h>
34 #include <qtextbrowser.h>
36 #include <qpushbutton.h>
38 #include "QAD_Application.h"
39 #include "QAD_Desktop.h"
40 #include "QAD_WaitCursor.h"
42 #include "SMESHGUI_StandardMeshInfosDlg.h"
43 #include "SMESHGUI_Utils.h"
44 #include "SMESHGUI_MeshUtils.h"
50 #include "SALOMEconfig.h"
51 #include CORBA_SERVER_HEADER(SMESH_Mesh)
52 #include CORBA_SERVER_HEADER(SMESH_Group)
53 #include CORBA_SERVER_HEADER(GEOM_Gen)
55 #include "utilities.h"
60 //=================================================================================
62 * SMESHGUI_StandardMeshInfosDlg::SMESHGUI_StandardMeshInfosDlg
66 //=================================================================================
67 SMESHGUI_StandardMeshInfosDlg::SMESHGUI_StandardMeshInfosDlg( QWidget* parent, const char* name, bool modal, WFlags fl )
68 : QDialog( parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu | WDestructiveClose )
71 setName( "SMESHGUI_StandardMeshInfosDlg" );
72 setCaption( tr( "SMESH_STANDARD_MESHINFO_TITLE" ) );
73 setSizeGripEnabled( TRUE );
75 myStartSelection = true;
76 myIsActiveWindow = true;
79 QGridLayout* aDlgLayout = new QGridLayout( this );
80 aDlgLayout->setSpacing( 6 );
81 aDlgLayout->setMargin( 11 );
84 myMeshGroup = new QGroupBox( this, "myMeshGroup" );
85 myMeshGroup->setTitle( tr( "SMESH_MESH" ) );
86 myMeshGroup->setColumnLayout(0, Qt::Vertical );
87 myMeshGroup->layout()->setSpacing( 0 );
88 myMeshGroup->layout()->setMargin( 0 );
89 QGridLayout* myMeshGroupLayout = new QGridLayout( myMeshGroup->layout() );
90 myMeshGroupLayout->setAlignment( Qt::AlignTop );
91 myMeshGroupLayout->setSpacing( 6 );
92 myMeshGroupLayout->setMargin( 11 );
94 // select button, label and line edit with mesh name
95 myNameLab = new QLabel( myMeshGroup, "myNameLab" );
96 myNameLab->setText( tr( "SMESH_NAME" ) );
97 myMeshGroupLayout->addWidget( myNameLab, 0, 0 );
99 QPixmap image0( QAD_Desktop::getResourceManager()->loadPixmap( "SMESH",tr( "ICON_SELECT" ) ) );
100 mySelectBtn = new QPushButton( myMeshGroup, "mySelectBtn" );
101 mySelectBtn->setPixmap( image0 );
102 mySelectBtn->setSizePolicy( QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ) );
103 myMeshGroupLayout->addWidget( mySelectBtn, 0, 1 );
105 myMeshLine = new QLineEdit( myMeshGroup, "myMeshLine" );
106 myMeshGroupLayout->addWidget( myMeshLine, 0, 2 );
108 aDlgLayout->addWidget( myMeshGroup, 0, 0 );
110 // information group box
111 myInfoGroup = new QGroupBox( this, "myInfoGroup" );
112 myInfoGroup->setTitle( tr( "SMESH_INFORMATION" ) );
113 myInfoGroup->setColumnLayout(0, Qt::Vertical );
114 myInfoGroup->layout()->setSpacing( 0 );
115 myInfoGroup->layout()->setMargin( 0 );
116 QGridLayout* myInfoGroupLayout = new QGridLayout( myInfoGroup->layout() );
117 myInfoGroupLayout->setAlignment( Qt::AlignTop );
118 myInfoGroupLayout->setSpacing( 6 );
119 myInfoGroupLayout->setMargin( 11 );
121 // information text browser
122 myInfo = new QTextBrowser(myInfoGroup, "myInfo");
123 myInfoGroupLayout->addWidget( myInfo, 0, 0 );
125 aDlgLayout->addWidget( myInfoGroup, 1, 0 );
128 myButtonsGroup = new QGroupBox( this, "myButtonsGroup" );
129 myButtonsGroup->setColumnLayout(0, Qt::Vertical );
130 myButtonsGroup->layout()->setSpacing( 0 ); myButtonsGroup->layout()->setMargin( 0 );
131 QHBoxLayout* myButtonsGroupLayout = new QHBoxLayout( myButtonsGroup->layout() );
132 myButtonsGroupLayout->setAlignment( Qt::AlignTop );
133 myButtonsGroupLayout->setSpacing( 6 ); myButtonsGroupLayout->setMargin( 11 );
135 // buttons --> OK button
136 myOkBtn = new QPushButton( tr( "SMESH_BUT_OK" ), myButtonsGroup, "myOkBtn" );
137 myOkBtn->setAutoDefault( TRUE ); myOkBtn->setDefault( TRUE );
138 myButtonsGroupLayout->addStretch();
139 myButtonsGroupLayout->addWidget( myOkBtn );
140 myButtonsGroupLayout->addStretch();
142 aDlgLayout->addWidget( myButtonsGroup, 2, 0 );
144 mySelection = SALOME_Selection::Selection( SMESHGUI::GetSMESHGUI()->GetActiveStudy()->getSelection() );
145 SMESHGUI::GetSMESHGUI()->SetActiveDialogBox( this ) ;
148 connect( myOkBtn, SIGNAL( clicked() ), this, SLOT( close() ) );
149 connect( mySelectBtn, SIGNAL( clicked() ), this, SLOT( onStartSelection() ) );
150 connect( SMESHGUI::GetSMESHGUI(), SIGNAL( SignalCloseAllDialogs() ), this, SLOT( close() ) ) ;
151 connect( SMESHGUI::GetSMESHGUI(), SIGNAL( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) ) ;
152 connect( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( onSelectionChanged() ) );
154 // resize and move dialog, then show
155 this->setMinimumSize(270, 428);
157 SMESHGUI::GetSMESHGUI()->DefineDlgPosition( this, x, y );
161 // init dialog with current selection
162 myMeshFilter = new SMESH_TypeFilter( MESH );
163 mySelection->AddFilter( myMeshFilter );
164 onSelectionChanged();
167 //=================================================================================
169 * SMESHGUI_StandardMeshInfosDlg::~SMESHGUI_StandardMeshInfosDlg
173 //=================================================================================
174 SMESHGUI_StandardMeshInfosDlg::~SMESHGUI_StandardMeshInfosDlg()
178 //=================================================================================
180 * SMESHGUI_StandardMeshInfosDlg::DumpMeshInfos
182 //=================================================================================
183 void SMESHGUI_StandardMeshInfosDlg::DumpMeshInfos()
186 int nbSel = mySelection->IObjectCount();
189 myStartSelection = false;
190 myMeshLine->setText( "" );
191 SMESH::SMESH_Mesh_var aMesh = SMESH::GetMeshByIO( mySelection->firstIObject() );
193 if ( !aMesh->_is_nil() ) {
194 QString aName, anInfo;
195 SMESH::GetNameOfSelectedIObjects(mySelection, aName);
196 myMeshLine->setText( aName );
197 int aNbNodes = (int)aMesh->NbNodes();
198 int aNbEdges = (int)aMesh->NbEdges();
199 int aNbFaces = (int)aMesh->NbFaces();
200 int aNbVolumes = (int)aMesh->NbVolumes();
203 double aNbDimElements = 0;
204 if (aNbVolumes > 0) {
205 aNbDimElements = aNbVolumes;
208 else if(aNbFaces > 0 ) {
209 aNbDimElements = aNbFaces;
212 else if(aNbEdges > 0 ) {
213 aNbDimElements = aNbEdges;
216 else if(aNbNodes > 0 ) {
217 aNbDimElements = aNbNodes;
221 // information about the mesh
222 anInfo.append(QString("Nb of element of dimension %1:<b> %2</b><br>").arg(aDimension).arg(aNbDimElements));
223 anInfo.append(QString("Nb of nodes: <b>%1</b><br><br>").arg(aNbNodes));
225 // information about the groups of the mesh
226 SALOMEDS::Study_var aStudy = SMESH::GetActiveStudyDocument();
227 SALOMEDS::SObject_var aMeshSO = aStudy->FindObjectIOR( aStudy->ConvertObjectToIOR(aMesh) );
228 SALOMEDS::SObject_var anObj;
230 bool hasGroup = false;
232 // info about groups on nodes
233 aMeshSO->FindSubObject(Tag_NodeGroups , anObj);
234 if ( !anObj->_is_nil() )
236 SALOMEDS::ChildIterator_var it = aStudy->NewChildIterator(anObj);
239 anInfo.append(QString("Groups:<br><br>"));
242 for(; it->More(); it->Next()){
243 SALOMEDS::SObject_var subObj = it->Value();
244 SMESH::SMESH_GroupBase_var aGroup = SMESH::SMESH_GroupBase::_narrow( subObj->GetObject() );
245 if ( !aGroup->_is_nil() )
247 anInfo.append(QString("- <b>%1</b><br>").arg(aGroup->GetName()));
248 anInfo.append(QString("%1<br>").arg("on nodes"));
249 anInfo.append(QString("%1<br>").arg(aGroup->Size()));
250 // check if the group based on geometry
251 SMESH::SMESH_GroupOnGeom_var aGroupOnGeom = SMESH::SMESH_GroupOnGeom::_narrow(aGroup);
252 if ( !aGroupOnGeom->_is_nil() )
254 GEOM::GEOM_Object_var aGroupMainShape = aGroupOnGeom->GetShape();
255 QString aShapeName = "<unknown>";
256 SALOMEDS::SObject_var aGeomObj, aRef;
257 if ( subObj->FindSubObject( 1, aGeomObj ) && aGeomObj->ReferencedObject( aRef ))
258 aShapeName = aRef->GetName();
259 anInfo.append(QString("based on <i>%1</i> geometry object<br><br>").arg(aShapeName));
262 anInfo.append(QString("<br>"));
267 // info about groups on edges
268 anObj = SALOMEDS::SObject::_nil();
269 aMeshSO->FindSubObject(Tag_EdgeGroups , anObj);
270 if ( !anObj->_is_nil() )
272 SALOMEDS::ChildIterator_var it = aStudy->NewChildIterator(anObj);
273 if (!hasGroup && it->More())
275 anInfo.append(QString("Groups:<br><br>"));
278 for(; it->More(); it->Next()){
279 SALOMEDS::SObject_var subObj = it->Value();
280 SMESH::SMESH_GroupBase_var aGroup = SMESH::SMESH_GroupBase::_narrow( subObj->GetObject() );
281 if ( !aGroup->_is_nil() )
283 anInfo.append(QString("- <b>%1</b><br>").arg(aGroup->GetName()));
284 anInfo.append(QString("%1<br>").arg("on edges"));
285 anInfo.append(QString("%1<br>").arg(aGroup->Size()));
286 // check if the group based on geometry
287 SMESH::SMESH_GroupOnGeom_var aGroupOnGeom = SMESH::SMESH_GroupOnGeom::_narrow(aGroup);
288 if ( !aGroupOnGeom->_is_nil() )
290 GEOM::GEOM_Object_var aGroupMainShape = aGroupOnGeom->GetShape();
291 QString aShapeName = "<unknown>";
292 SALOMEDS::SObject_var aGeomObj, aRef;
293 if ( subObj->FindSubObject( 1, aGeomObj ) && aGeomObj->ReferencedObject( aRef ))
294 aShapeName = aRef->GetName();
295 anInfo.append(QString("based on <i>%1</i> geometry object<br><br>").arg(aShapeName));
298 anInfo.append(QString("<br>"));
303 // info about groups on faces
304 anObj = SALOMEDS::SObject::_nil();
305 aMeshSO->FindSubObject(Tag_FaceGroups , anObj);
306 if ( !anObj->_is_nil() )
308 SALOMEDS::ChildIterator_var it = aStudy->NewChildIterator(anObj);
309 if (!hasGroup && it->More())
311 anInfo.append(QString("Groups:<br><br>"));
314 for(; it->More(); it->Next()){
315 SALOMEDS::SObject_var subObj = it->Value();
316 SMESH::SMESH_GroupBase_var aGroup = SMESH::SMESH_GroupBase::_narrow( subObj->GetObject() );
317 if ( !aGroup->_is_nil() )
319 anInfo.append(QString("- <b>%1</b><br>").arg(aGroup->GetName()));
320 anInfo.append(QString("%1<br>").arg("on faces"));
321 anInfo.append(QString("%1<br>").arg(aGroup->Size()));
322 // check if the group based on geometry
323 SMESH::SMESH_GroupOnGeom_var aGroupOnGeom = SMESH::SMESH_GroupOnGeom::_narrow(aGroup);
324 if ( !aGroupOnGeom->_is_nil() )
326 GEOM::GEOM_Object_var aGroupMainShape = aGroupOnGeom->GetShape();
327 QString aShapeName = "<unknown>";
328 SALOMEDS::SObject_var aGeomObj, aRef;
329 if ( subObj->FindSubObject( 1, aGeomObj ) && aGeomObj->ReferencedObject( aRef ))
330 aShapeName = aRef->GetName();
331 anInfo.append(QString("based on <i>%1</i> geometry object<br><br>").arg(aShapeName));
334 anInfo.append(QString("<br>"));
339 // info about groups on volumes
340 anObj = SALOMEDS::SObject::_nil();
341 aMeshSO->FindSubObject(Tag_VolumeGroups , anObj);
342 if ( !anObj->_is_nil() )
344 SALOMEDS::ChildIterator_var it = aStudy->NewChildIterator(anObj);
345 if (!hasGroup && it->More())
346 anInfo.append(QString("Groups:<br>"));
347 for(; it->More(); it->Next()){
348 SALOMEDS::SObject_var subObj = it->Value();
349 SMESH::SMESH_GroupBase_var aGroup = SMESH::SMESH_GroupBase::_narrow( subObj->GetObject() );
350 if ( !aGroup->_is_nil() )
352 anInfo.append(QString("- <b>%1</b><br>").arg(aGroup->GetName()));
353 anInfo.append(QString("%1<br>").arg("on volumes"));
354 anInfo.append(QString("%1<br>").arg(aGroup->Size()));
355 // check if the group based on geometry
356 SMESH::SMESH_GroupOnGeom_var aGroupOnGeom = SMESH::SMESH_GroupOnGeom::_narrow(aGroup);
357 if ( !aGroupOnGeom->_is_nil() )
359 GEOM::GEOM_Object_var aGroupMainShape = aGroupOnGeom->GetShape();
360 QString aShapeName = "<unknown>";
361 SALOMEDS::SObject_var aGeomObj, aRef;
362 if ( subObj->FindSubObject( 1, aGeomObj ) && aGeomObj->ReferencedObject( aRef ))
363 aShapeName = aRef->GetName();
364 anInfo.append(QString("based on <i>%1</i> geometry object<br><br>").arg(aShapeName));
367 anInfo.append(QString("<br>"));
372 myInfo->setText(anInfo);
380 //=================================================================================
381 // function : SelectionIntoArgument()
382 // purpose : Called when selection has changed
383 //=================================================================================
384 void SMESHGUI_StandardMeshInfosDlg::onSelectionChanged()
386 if ( myStartSelection )
391 //=================================================================================
392 // function : closeEvent()
394 //=================================================================================
395 void SMESHGUI_StandardMeshInfosDlg::closeEvent( QCloseEvent* e )
397 mySelection->ClearFilters();
398 SMESHGUI::GetSMESHGUI()->ResetState();
399 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();
416 //=================================================================================
417 // function : DeactivateActiveDialog()
419 //=================================================================================
420 void SMESHGUI_StandardMeshInfosDlg::DeactivateActiveDialog()
422 disconnect( mySelection, 0, this, 0 );
426 //=================================================================================
427 // function : ActivateThisDialog()
429 //=================================================================================
430 void SMESHGUI_StandardMeshInfosDlg::ActivateThisDialog()
432 /* Emit a signal to deactivate any active dialog */
433 SMESHGUI::GetSMESHGUI()->EmitSignalDeactivateDialog() ;
434 connect( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( onSelectionChanged() ) );
437 //=================================================================================
438 // function : onStartSelection()
439 // purpose : starts selection
440 //=================================================================================
441 void SMESHGUI_StandardMeshInfosDlg::onStartSelection()
443 myStartSelection = true;
444 mySelection->AddFilter( myMeshFilter ) ;
445 myMeshLine->setText( tr( "Select a mesh" ) );
446 onSelectionChanged();
447 myStartSelection = true;