Version: 6.3.1

src/SMESHGUI/SMESHGUI_StandardMeshInfosDlg.cxx

Go to the documentation of this file.
00001 // Copyright (C) 2007-2011  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 // SMESH SMESHGUI : GUI for SMESH component
00024 // File   : SMESHGUI_StandardMeshInfosDlg.cxx
00025 // Author : Michael ZORIN, Open CASCADE S.A.S.
00026 // SMESH includes
00027 //
00028 #include "SMESHGUI_StandardMeshInfosDlg.h"
00029 
00030 #include "SMESHGUI.h"
00031 #include "SMESHGUI_Utils.h"
00032 #include "SMESHGUI_MeshUtils.h"
00033 
00034 #include <SMESH_TypeFilter.hxx>
00035 
00036 // SALOME KERNEL includes 
00037 #include <SALOMEDSClient_Study.hxx>
00038 #include <SALOMEDSClient_SObject.hxx>
00039 
00040 // SALOME GUI includes
00041 #include <SUIT_Desktop.h>
00042 #include <SUIT_Session.h>
00043 #include <SUIT_OverrideCursor.h>
00044 #include <SUIT_MessageBox.h>
00045 #include <SUIT_ResourceMgr.h>
00046 
00047 #include <LightApp_Application.h>
00048 #include <LightApp_SelectionMgr.h>
00049 
00050 #include <SALOME_ListIO.hxx>
00051 
00052 // Qt includes
00053 #include <QGroupBox>
00054 #include <QLabel>
00055 #include <QVBoxLayout>
00056 #include <QHBoxLayout>
00057 #include <QLineEdit>
00058 #include <QTextBrowser>
00059 #include <QPushButton>
00060 #include <QKeyEvent>
00061 
00062 // IDL includes
00063 #include <SALOMEconfig.h>
00064 #include CORBA_SERVER_HEADER(SMESH_Mesh)
00065 #include CORBA_SERVER_HEADER(SMESH_Group)
00066 
00067 #define SPACING 6
00068 #define MARGIN  11
00069 
00070 //=================================================================================
00076 //=================================================================================
00077 SMESHGUI_StandardMeshInfosDlg::SMESHGUI_StandardMeshInfosDlg( SMESHGUI* theModule )
00078   : QDialog( SMESH::GetDesktop( theModule ) ),
00079     mySMESHGUI( theModule ),
00080     mySelectionMgr( SMESH::GetSelectionMgr( theModule ) )
00081 {
00082   setModal(false);
00083   setAttribute(Qt::WA_DeleteOnClose, true);
00084   setWindowTitle(tr("SMESH_STANDARD_MESHINFO_TITLE"));
00085   setSizeGripEnabled(true);
00086 
00087   myStartSelection = true;
00088   myIsActiveWindow = true;
00089 
00090   // dialog layout
00091   QVBoxLayout* aDlgLayout = new QVBoxLayout(this);
00092   aDlgLayout->setSpacing(SPACING);
00093   aDlgLayout->setMargin(MARGIN);
00094 
00095   // mesh group box
00096   myMeshGroup = new QGroupBox(tr("SMESH_MESH"), this);
00097   QHBoxLayout* myMeshGroupLayout = new QHBoxLayout(myMeshGroup);
00098   myMeshGroupLayout->setSpacing(SPACING);
00099   myMeshGroupLayout->setMargin(MARGIN);
00100 
00101   // select button, label and line edit with mesh name
00102   myNameLab = new QLabel(tr("SMESH_NAME"), myMeshGroup);
00103   myMeshGroupLayout->addWidget(myNameLab);
00104 
00105   QPixmap image0(SUIT_Session::session()->resourceMgr()->loadPixmap("SMESH",tr("ICON_SELECT")));
00106   mySelectBtn = new QPushButton(myMeshGroup);
00107   mySelectBtn->setIcon(image0);
00108   myMeshGroupLayout->addWidget(mySelectBtn);
00109 
00110   myMeshLine = new QLineEdit(myMeshGroup);
00111   myMeshGroupLayout->addWidget(myMeshLine);
00112 
00113   aDlgLayout->addWidget(myMeshGroup);
00114 
00115   // information group box
00116   myInfoGroup  = new QGroupBox(tr("SMESH_INFORMATION"), this);
00117   QVBoxLayout* myInfoGroupLayout = new QVBoxLayout(myInfoGroup);
00118   myInfoGroupLayout->setSpacing(SPACING);
00119   myInfoGroupLayout->setMargin(MARGIN);
00120 
00121   // information text browser
00122   myInfo = new QTextBrowser(myInfoGroup);
00123   myInfo->setMinimumSize(200, 150);
00124   myInfoGroupLayout->addWidget(myInfo);
00125 
00126   aDlgLayout->addWidget(myInfoGroup);
00127 
00128   // buttons group
00129   myButtonsGroup = new QGroupBox(this);
00130   QHBoxLayout* myButtonsGroupLayout = new QHBoxLayout(myButtonsGroup);
00131   myButtonsGroupLayout->setSpacing(SPACING);
00132   myButtonsGroupLayout->setMargin(MARGIN);
00133 
00134   // buttons --> OK and Help buttons
00135   myOkBtn = new QPushButton(tr("SMESH_BUT_OK"), myButtonsGroup);
00136   myOkBtn->setAutoDefault(true); myOkBtn->setDefault(true);
00137   myHelpBtn = new QPushButton(tr("SMESH_BUT_HELP"), myButtonsGroup);
00138   myHelpBtn->setAutoDefault(true);
00139 
00140   myButtonsGroupLayout->addWidget(myOkBtn);
00141   myButtonsGroupLayout->addSpacing(10);
00142   myButtonsGroupLayout->addStretch();
00143   myButtonsGroupLayout->addWidget(myHelpBtn);
00144 
00145   aDlgLayout->addWidget(myButtonsGroup);
00146 
00147   mySMESHGUI->SetActiveDialogBox(this);
00148 
00149   // connect signals
00150   connect( myOkBtn,         SIGNAL(clicked()),                      this, SLOT(close()));
00151   connect( myHelpBtn,       SIGNAL(clicked()),                      this, SLOT(onHelp()));
00152   connect( mySelectBtn,     SIGNAL(clicked()),                      this, SLOT(onStartSelection()));
00153   connect( mySMESHGUI,      SIGNAL(SignalCloseAllDialogs()),        this, SLOT(close()));
00154   connect( mySMESHGUI,      SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
00155   connect( mySelectionMgr,  SIGNAL(currentSelectionChanged()),      this, SLOT(onSelectionChanged()));
00156 
00157   // init dialog with current selection
00158   myMeshFilter = new SMESH_TypeFilter (MESH);
00159   mySelectionMgr->installFilter(myMeshFilter);
00160   onSelectionChanged();
00161 
00162   myHelpFileName = "mesh_infos_page.html#standard_mesh_infos_anchor";
00163 }
00164 
00165 //=================================================================================
00171 //=================================================================================
00172 SMESHGUI_StandardMeshInfosDlg::~SMESHGUI_StandardMeshInfosDlg()
00173 {
00174 }
00175 
00176 //=================================================================================
00180 //=================================================================================
00181 void SMESHGUI_StandardMeshInfosDlg::DumpMeshInfos()
00182 {
00183   SUIT_OverrideCursor wc;
00184 
00185   SALOME_ListIO aList;
00186   mySelectionMgr->selectedObjects(aList);
00187 
00188   int nbSel = aList.Extent();
00189   myInfo->clear();
00190   if (nbSel == 1) {
00191     myStartSelection = false;
00192     myMeshLine->setText("");
00193     SMESH::SMESH_Mesh_var aMesh = SMESH::GetMeshByIO(aList.First());
00194 
00195     if (!aMesh->_is_nil()) {
00196       QString aName, anInfo;
00197       SMESH::GetNameOfSelectedIObjects(mySelectionMgr, aName);
00198       myMeshLine->setText(aName);
00199       int aNbNodes =   (int)aMesh->NbNodes();
00200       int aNbEdges =   (int)aMesh->NbEdges();
00201       int aNbFaces =   (int)aMesh->NbFaces();
00202       int aNbVolumes = (int)aMesh->NbVolumes();
00203 
00204       int aDimension = 0;
00205       double aNbDimElements = 0;
00206       if (aNbVolumes > 0) {
00207         aNbDimElements = aNbVolumes;
00208         aDimension = 3;
00209       }
00210       else if(aNbFaces > 0) {
00211         aNbDimElements = aNbFaces;
00212         aDimension = 2;
00213       }
00214       else if(aNbEdges > 0) {
00215         aNbDimElements = aNbEdges;
00216         aDimension = 1;
00217       }
00218       else if(aNbNodes > 0) {
00219         aNbDimElements = aNbNodes;
00220         aDimension = 0;
00221       }
00222 
00223       // information about the mesh
00224       anInfo.append(QString("Nb of element of dimension %1:<b> %2</b><br>").arg(aDimension).arg(aNbDimElements));
00225       anInfo.append(QString("Nb of nodes: <b>%1</b><br><br>").arg(aNbNodes));
00226 
00227       // information about the groups of the mesh
00228       _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
00229       _PTR(SObject) aMeshSO = SMESH::FindSObject(aMesh);
00230       _PTR(SObject) anObj;
00231 
00232       bool hasGroup = false;
00233 
00234       // info about groups on nodes
00235       aMeshSO->FindSubObject(SMESH::Tag_NodeGroups, anObj);
00236       if (anObj) {
00237         _PTR(ChildIterator) it = aStudy->NewChildIterator(anObj);
00238         if (it->More()) {
00239           anInfo.append(QString("Groups:<br><br>"));
00240           hasGroup = true;
00241         }
00242         for ( ; it->More(); it->Next()) {
00243           _PTR(SObject) subObj = it->Value();
00244           CORBA::Object_var anObject = SMESH::SObjectToObject(subObj);
00245           SMESH::SMESH_GroupBase_var aGroup = SMESH::SMESH_GroupBase::_narrow(anObject);
00246           if (!aGroup->_is_nil()) {
00247             anInfo.append(QString("-   <b>%1</b><br>").arg(aGroup->GetName()));
00248             anInfo.append(QString("%1<br>").arg("on nodes"));
00249             anInfo.append(QString("%1<br>").arg(aGroup->Size()));
00250             // check if the group based on geometry
00251             SMESH::SMESH_GroupOnGeom_var aGroupOnGeom = SMESH::SMESH_GroupOnGeom::_narrow(aGroup);
00252             if (!aGroupOnGeom->_is_nil()) {
00253               GEOM::GEOM_Object_var aGroupMainShape = aGroupOnGeom->GetShape();
00254               QString aShapeName = "<unknown>";
00255               _PTR(SObject) aGeomObj, aRef;
00256               if (subObj->FindSubObject(1, aGeomObj) &&  aGeomObj->ReferencedObject(aRef))
00257                 aShapeName = aRef->GetName().c_str();
00258               anInfo.append(QString("based on <i>%1</i> geometry object<br><br>").arg(aShapeName));
00259             } else {
00260               anInfo.append(QString("<br>"));
00261             }
00262           }
00263         }
00264       }
00265 
00266       // info about groups on edges
00267       anObj.reset();
00268       aMeshSO->FindSubObject(SMESH::Tag_EdgeGroups, anObj);
00269       if (anObj) {
00270         _PTR(ChildIterator) it = aStudy->NewChildIterator(anObj);
00271         if (!hasGroup && it->More()) {
00272           anInfo.append(QString("Groups:<br><br>"));
00273           hasGroup = true;
00274         }
00275         for ( ; it->More(); it->Next()) {
00276           _PTR(SObject) subObj = it->Value();
00277           CORBA::Object_var anObject = SMESH::SObjectToObject(subObj);
00278           SMESH::SMESH_GroupBase_var aGroup = SMESH::SMESH_GroupBase::_narrow(anObject);
00279           if (!aGroup->_is_nil()) {
00280             anInfo.append(QString("-   <b>%1</b><br>").arg(aGroup->GetName()));
00281             anInfo.append(QString("%1<br>").arg("on edges"));
00282             anInfo.append(QString("%1<br>").arg(aGroup->Size()));
00283             // check if the group based on geometry
00284             SMESH::SMESH_GroupOnGeom_var aGroupOnGeom = SMESH::SMESH_GroupOnGeom::_narrow(aGroup);
00285             if (!aGroupOnGeom->_is_nil()) {
00286               GEOM::GEOM_Object_var aGroupMainShape = aGroupOnGeom->GetShape();
00287               QString aShapeName = "<unknown>";
00288               _PTR(SObject) aGeomObj, aRef;
00289               if (subObj->FindSubObject(1, aGeomObj) && aGeomObj->ReferencedObject(aRef))
00290                 aShapeName = aRef->GetName().c_str();
00291               anInfo.append(QString("based on <i>%1</i> geometry object<br><br>").arg(aShapeName));
00292             } else {
00293               anInfo.append(QString("<br>"));
00294             }
00295           }
00296         }
00297       }
00298 
00299       // info about groups on faces
00300       anObj.reset();
00301       aMeshSO->FindSubObject(SMESH::Tag_FaceGroups, anObj);
00302       if (anObj) {
00303         _PTR(ChildIterator) it = aStudy->NewChildIterator(anObj);
00304         if (!hasGroup && it->More()) {
00305           anInfo.append(QString("Groups:<br><br>"));
00306           hasGroup = true;
00307         }
00308         for ( ; it->More(); it->Next()) {
00309           _PTR(SObject) subObj = it->Value();
00310           CORBA::Object_var anObject = SMESH::SObjectToObject(subObj);
00311           SMESH::SMESH_GroupBase_var aGroup = SMESH::SMESH_GroupBase::_narrow(anObject);
00312           if (!aGroup->_is_nil()) {
00313             anInfo.append(QString("-   <b>%1</b><br>").arg(aGroup->GetName()));
00314             anInfo.append(QString("%1<br>").arg("on faces"));
00315             anInfo.append(QString("%1<br>").arg(aGroup->Size()));
00316             // check if the group based on geometry
00317             SMESH::SMESH_GroupOnGeom_var aGroupOnGeom = SMESH::SMESH_GroupOnGeom::_narrow(aGroup);
00318             if (!aGroupOnGeom->_is_nil()) {
00319               GEOM::GEOM_Object_var aGroupMainShape = aGroupOnGeom->GetShape();
00320               QString aShapeName = "<unknown>";
00321               _PTR(SObject) aGeomObj, aRef;
00322               if (subObj->FindSubObject(1, aGeomObj) && aGeomObj->ReferencedObject(aRef))
00323                 aShapeName = aRef->GetName().c_str();
00324               anInfo.append(QString("based on <i>%1</i> geometry object<br><br>").arg(aShapeName));
00325             } else {
00326               anInfo.append(QString("<br>"));
00327             }
00328           }
00329         }
00330       }
00331 
00332       // info about groups on volumes
00333       anObj.reset();
00334       aMeshSO->FindSubObject(SMESH::Tag_VolumeGroups, anObj);
00335       if (anObj) {
00336         _PTR(ChildIterator) it = aStudy->NewChildIterator(anObj);
00337         if (!hasGroup && it->More())
00338           anInfo.append(QString("Groups:<br>"));
00339         for ( ; it->More(); it->Next()) {
00340           _PTR(SObject) subObj = it->Value();
00341           CORBA::Object_var anObject = SMESH::SObjectToObject(subObj);
00342           SMESH::SMESH_GroupBase_var aGroup = SMESH::SMESH_GroupBase::_narrow(anObject);
00343           if (!aGroup->_is_nil()) {
00344             anInfo.append(QString("-   <b>%1</b><br>").arg(aGroup->GetName()));
00345             anInfo.append(QString("%1<br>").arg("on volumes"));
00346             anInfo.append(QString("%1<br>").arg(aGroup->Size()));
00347             // check if the group based on geometry
00348             SMESH::SMESH_GroupOnGeom_var aGroupOnGeom = SMESH::SMESH_GroupOnGeom::_narrow(aGroup);
00349             if (!aGroupOnGeom->_is_nil()) {
00350               GEOM::GEOM_Object_var aGroupMainShape = aGroupOnGeom->GetShape();
00351               QString aShapeName = "<unknown>";
00352               _PTR(SObject) aGeomObj, aRef;
00353               if (subObj->FindSubObject(1, aGeomObj) &&  aGeomObj->ReferencedObject(aRef))
00354                 aShapeName = aRef->GetName().c_str();
00355               anInfo.append(QString("based on <i>%1</i> geometry object<br><br>").arg(aShapeName));
00356             } else {
00357               anInfo.append(QString("<br>"));
00358             }
00359           }
00360         }
00361       }
00362 
00363       myInfo->setText(anInfo);
00364       return;
00365     }
00366   }
00367 }
00368 
00369 //=================================================================================
00370 // function : SelectionIntoArgument()
00371 // purpose  : Called when selection has changed
00372 //=================================================================================
00373 void SMESHGUI_StandardMeshInfosDlg::onSelectionChanged()
00374 {
00375   if (myStartSelection)
00376     DumpMeshInfos();
00377 }
00378 
00379 //=================================================================================
00380 // function : closeEvent()
00381 // purpose  :
00382 //=================================================================================
00383 void SMESHGUI_StandardMeshInfosDlg::closeEvent (QCloseEvent* e)
00384 {
00385   mySelectionMgr->clearFilters();
00386   mySMESHGUI->ResetState();
00387   QDialog::closeEvent(e);
00388 }
00389 
00390 //=================================================================================
00391 // function : windowActivationChange()
00392 // purpose  : called when window is activated/deactivated
00393 //=================================================================================
00394 void SMESHGUI_StandardMeshInfosDlg::windowActivationChange (bool oldActive)
00395 {
00396   QDialog::windowActivationChange(oldActive);
00397   if (isActiveWindow() && myIsActiveWindow != isActiveWindow())
00398     ActivateThisDialog();
00399   myIsActiveWindow = isActiveWindow();
00400 }
00401 
00402 //=================================================================================
00403 // function : DeactivateActiveDialog()
00404 // purpose  :
00405 //=================================================================================
00406 void SMESHGUI_StandardMeshInfosDlg::DeactivateActiveDialog()
00407 {
00408   disconnect(mySelectionMgr, 0, this, 0);
00409 }
00410 
00411 //=================================================================================
00412 // function : ActivateThisDialog()
00413 // purpose  :
00414 //=================================================================================
00415 void SMESHGUI_StandardMeshInfosDlg::ActivateThisDialog()
00416 {
00417   /* Emit a signal to deactivate any active dialog */
00418   mySMESHGUI->EmitSignalDeactivateDialog();
00419   connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(onSelectionChanged()));
00420 }
00421 
00422 //=================================================================================
00423 // function : onStartSelection()
00424 // purpose  : starts selection
00425 //=================================================================================
00426 void SMESHGUI_StandardMeshInfosDlg::onStartSelection()
00427 {
00428   myStartSelection = true;
00429   mySelectionMgr->installFilter(myMeshFilter);
00430   myMeshLine->setText(tr("Select a mesh"));
00431   onSelectionChanged();
00432   myStartSelection = true;
00433 }
00434 
00435 //=================================================================================
00436 // function : onHelp()
00437 // purpose  :
00438 //=================================================================================
00439 void SMESHGUI_StandardMeshInfosDlg::onHelp()
00440 {
00441   LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
00442   if (app)
00443     app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
00444   else {
00445     QString platform;
00446 #ifdef WIN32
00447     platform = "winapplication";
00448 #else
00449     platform = "application";
00450 #endif
00451     SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
00452                              tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
00453                              arg(app->resourceMgr()->stringValue("ExternalBrowser",
00454                                                                  platform)).
00455                              arg(myHelpFileName));
00456   }
00457 }
00458 
00459 //=================================================================================
00460 // function : keyPressEvent()
00461 // purpose  :
00462 //=================================================================================
00463 void SMESHGUI_StandardMeshInfosDlg::keyPressEvent( QKeyEvent* e )
00464 {
00465   QDialog::keyPressEvent( e );
00466   if ( e->isAccepted() )
00467     return;
00468 
00469   if ( e->key() == Qt::Key_F1 ) {
00470     e->accept();
00471     onHelp();
00472   }
00473 }
Copyright © 2007-2011 CEA/DEN, EDF R&D, OPEN CASCADE
Copyright © 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS