Version: 6.3.1

src/SMESHGUI/SMESHGUI_MeshInfosDlg.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_MeshInfosDlg.cxx
00025 // Author : Nicolas BARBEROU
00026 // SMESH includes
00027 //
00028 #include "SMESHGUI_MeshInfosDlg.h"
00029 
00030 #include "SMESHGUI.h"
00031 #include "SMESHGUI_Utils.h"
00032 #include "SMESHGUI_MeshInfosBox.h"
00033 
00034 // SALOME GUI includes
00035 #include <SUIT_Desktop.h>
00036 #include <SUIT_ResourceMgr.h>
00037 #include <SUIT_OverrideCursor.h>
00038 #include <SUIT_Session.h>
00039 #include <SUIT_MessageBox.h>
00040 
00041 #include <LightApp_SelectionMgr.h>
00042 #include <LightApp_Application.h>
00043 #include <SALOME_ListIO.hxx>
00044 
00045 // SALOME KERNEL includes
00046 #include <SALOMEDSClient_Study.hxx>
00047 
00048 // Qt includes
00049 #include <QGroupBox>
00050 #include <QLabel>
00051 #include <QFrame>
00052 #include <QStackedWidget>
00053 #include <QVBoxLayout>
00054 #include <QHBoxLayout>
00055 #include <QGridLayout>
00056 #include <QPushButton>
00057 #include <QKeyEvent>
00058 
00059 // IDL includes
00060 #include <SALOMEconfig.h>
00061 #include CORBA_SERVER_HEADER(SMESH_Mesh)
00062 #include CORBA_SERVER_HEADER(SMESH_Group)
00063 
00064 #define COLONIZE(str)   (QString(str).contains(":") > 0 ? QString(str) : QString(str) + " :" )
00065 #define SPACING 6
00066 #define MARGIN  11
00067 
00068 //=================================================================================
00069 // function : SMESHGUI_MeshInfosDlg()
00070 // purpose  : Constructor
00071 //=================================================================================
00072 SMESHGUI_MeshInfosDlg::SMESHGUI_MeshInfosDlg(SMESHGUI* theModule): 
00073   QDialog(SMESH::GetDesktop(theModule)),
00074   mySelectionMgr(SMESH::GetSelectionMgr(theModule)),
00075   mySMESHGUI(theModule)
00076 {
00077   setModal( false );
00078   setAttribute( Qt::WA_DeleteOnClose, true );
00079   setWindowTitle(tr("SMESH_MESHINFO_TITLE"));
00080   setSizeGripEnabled(true);
00081 
00082   myStartSelection = true;
00083   myIsActiveWindow = true;
00084 
00085   QVBoxLayout* aTopLayout = new QVBoxLayout(this);
00086   aTopLayout->setSpacing(SPACING);  aTopLayout->setMargin(MARGIN);
00087 
00088   // select button & label
00089   QPixmap image0(SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH",tr("ICON_SELECT")));
00090   mySelectBtn = new QPushButton(this);
00091   mySelectBtn->setIcon(image0);
00092   mySelectBtn->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed));
00093 
00094   mySelectLab = new QLabel(this);
00095   mySelectLab->setAlignment(Qt::AlignCenter);
00096   QFont fnt = mySelectLab->font(); fnt.setBold(true);
00097   mySelectLab->setFont(fnt);
00098 
00099   QHBoxLayout* aSelectLayout = new QHBoxLayout;
00100   aSelectLayout->setMargin(0); aSelectLayout->setSpacing(0);
00101   aSelectLayout->addWidget(mySelectBtn);
00102   aSelectLayout->addWidget(mySelectLab);
00103 
00104   // top widget stack
00105   myWGStack = new QStackedWidget(this);
00106 
00107   // no valid selection
00108   QWidget* myBadWidget = new QWidget(myWGStack);
00109   QVBoxLayout* aBadLayout = new QVBoxLayout(myBadWidget);
00110   QLabel* myBadLab = new QLabel(tr("SMESH_BAD_SELECTION"), myBadWidget);
00111   myBadLab->setAlignment(Qt::AlignCenter);
00112   myBadLab->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding));
00113   aBadLayout->addWidget(myBadLab);
00114   myWGStack->addWidget(myBadWidget);
00115 
00116   // mesh
00117   myMeshWidget = new QWidget(myWGStack);
00118   QGridLayout* aMeshLayout = new QGridLayout(myMeshWidget);
00119   aMeshLayout->setSpacing(SPACING);  aMeshLayout->setMargin(0);
00120   myWGStack->addWidget(myMeshWidget);
00121 
00122   // --> name
00123   QLabel* myMeshNameLab = new QLabel(COLONIZE(tr("SMESH_MESHINFO_NAME")), myMeshWidget);
00124   myMeshName    = new QLabel(myMeshWidget);
00125   myMeshName->setMinimumWidth(100);
00126   QFrame* line1 = new QFrame(myMeshWidget);
00127   line1->setFrameStyle(QFrame::HLine | QFrame::Sunken);
00128 
00129   myMeshInfoBox = new SMESHGUI_MeshInfosBox(true, myMeshWidget);
00130 
00131   aMeshLayout->addWidget(myMeshNameLab,      0, 0);
00132   aMeshLayout->addWidget(myMeshName,         0, 1);
00133   aMeshLayout->addWidget(line1,              1, 0, 1, 2);
00134   aMeshLayout->addWidget(myMeshInfoBox,      2, 0, 1, 2);
00135   aMeshLayout->addItem(new QSpacerItem(0, 0, QSizePolicy::Minimum, QSizePolicy::Expanding), 3, 0);
00136 
00137   // buttons
00138   myButtonsGroup = new QGroupBox(this);
00139   QHBoxLayout* myButtonsGroupLayout = new QHBoxLayout(myButtonsGroup);
00140   myButtonsGroupLayout->setSpacing(SPACING); myButtonsGroupLayout->setMargin(MARGIN);
00141 
00142   // buttons --> OK and Help buttons
00143   myOkBtn = new QPushButton(tr("SMESH_BUT_OK" ), myButtonsGroup);
00144   myOkBtn->setAutoDefault(true);
00145   myOkBtn->setDefault(true);
00146   myOkBtn->setFocus();
00147   myHelpBtn = new QPushButton(tr("SMESH_BUT_HELP" ), myButtonsGroup);
00148   myHelpBtn->setAutoDefault(true);
00149 
00150   myButtonsGroupLayout->addWidget(myOkBtn);
00151   myButtonsGroupLayout->addSpacing(10);
00152   myButtonsGroupLayout->addStretch();
00153   myButtonsGroupLayout->addWidget(myHelpBtn);
00154 
00155   aTopLayout->addLayout(aSelectLayout);
00156   aTopLayout->addWidget(myWGStack);
00157   aTopLayout->addWidget(myButtonsGroup);
00158 
00159   mySMESHGUI->SetActiveDialogBox(this);
00160 
00161   // connect signals
00162   connect(myOkBtn,                 SIGNAL(clicked()),                      this, SLOT(close()));
00163   connect( myHelpBtn,              SIGNAL(clicked()),                      this, SLOT(onHelp()));
00164   connect(mySelectBtn,             SIGNAL(clicked()),                      this, SLOT(onStartSelection()));
00165   connect(mySMESHGUI, SIGNAL(SignalCloseAllDialogs()),        this, SLOT(close()));
00166   connect(mySMESHGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
00167   connect(mySelectionMgr,          SIGNAL(currentSelectionChanged()),      this, SLOT(onSelectionChanged()));
00168 
00169   // init dialog with current selection
00170   onSelectionChanged();
00171 
00172   myHelpFileName = "mesh_infos_page.html#advanced_mesh_infos_anchor";
00173 }
00174 
00175 //=================================================================================
00176 // function : ~SMESHGUI_MeshInfosDlg()
00177 // purpose  : Destructor
00178 //=================================================================================
00179 SMESHGUI_MeshInfosDlg::~SMESHGUI_MeshInfosDlg()
00180 {
00181 }
00182 
00183 //=================================================================================
00184 // function : DumpMeshInfos()
00185 // purpose  : 
00186 //=================================================================================
00187 void SMESHGUI_MeshInfosDlg::DumpMeshInfos()
00188 {
00189   SUIT_OverrideCursor wc;
00190 
00191   SALOME_ListIO aList;
00192   mySelectionMgr->selectedObjects(aList);
00193 
00194   int nbSel = aList.Extent();
00195   if (nbSel == 1) {
00196     myStartSelection = false;
00197     mySelectLab->setText("");
00198     Handle(SALOME_InteractiveObject) IObject = aList.First();
00199     _PTR(SObject) aSO = SMESH::GetActiveStudyDocument()->FindObjectID(IObject->getEntry());
00200     if (aSO) {
00201       //CORBA::Object_var anObject = aSO->GetObject();
00202       CORBA::Object_var anObject = SMESH::SObjectToObject(aSO);
00203       if (!CORBA::is_nil(anObject)) {
00204         SMESH::SMESH_IDSource_var anIDSource = SMESH::SMESH_IDSource::_narrow(anObject);
00205         if (!anIDSource->_is_nil()) {
00206           myWGStack->setCurrentWidget(myMeshWidget);
00207           setWindowTitle(tr("SMESH_MESHINFO_TITLE") + " [" + tr("SMESH_OBJECT_MESH") + "]");
00208           myMeshName->setText(aSO->GetName().c_str());
00209 
00210           SMESH::long_array_var aMeshInfo = anIDSource->GetMeshInfo();
00211           myMeshInfoBox->SetMeshInfo( aMeshInfo );
00212 
00213           return;
00214         }
00215       }
00216     }
00217   }
00218   myWGStack->setCurrentIndex(0);
00219   setWindowTitle(tr("SMESH_MESHINFO_TITLE"));
00220 }
00221 
00222 //=================================================================================
00223 // function : SelectionIntoArgument()
00224 // purpose  : Called when selection has changed
00225 //=================================================================================
00226 void SMESHGUI_MeshInfosDlg::onSelectionChanged()
00227 {
00228   if (myStartSelection)
00229     DumpMeshInfos();
00230 }
00231 
00232 //=================================================================================
00233 // function : closeEvent()
00234 // purpose  :
00235 //=================================================================================
00236 void SMESHGUI_MeshInfosDlg::closeEvent(QCloseEvent* e)
00237 {
00238   mySMESHGUI->ResetState();
00239   QDialog::closeEvent(e);
00240 }
00241 
00242 //=================================================================================
00243 // function : windowActivationChange()
00244 // purpose  : called when window is activated/deactivated
00245 //=================================================================================
00246 void SMESHGUI_MeshInfosDlg::windowActivationChange(bool oldActive)
00247 {
00248   QDialog::windowActivationChange(oldActive);
00249   if (isActiveWindow() && myIsActiveWindow != isActiveWindow())
00250     ActivateThisDialog();
00251   myIsActiveWindow = isActiveWindow();
00252 }
00253 
00254 //=================================================================================
00255 // function : DeactivateActiveDialog()
00256 // purpose  :
00257 //=================================================================================
00258 void SMESHGUI_MeshInfosDlg::DeactivateActiveDialog()
00259 {
00260   disconnect(mySelectionMgr, 0, this, 0);
00261 }
00262 
00263 //=================================================================================
00264 // function : ActivateThisDialog()
00265 // purpose  :
00266 //=================================================================================
00267 void SMESHGUI_MeshInfosDlg::ActivateThisDialog()
00268 {
00269   /* Emit a signal to deactivate any active dialog */
00270   mySMESHGUI->EmitSignalDeactivateDialog();
00271   connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(onSelectionChanged()));
00272 }
00273 
00274 //=================================================================================
00275 // function : onStartSelection()
00276 // purpose  : starts selection
00277 //=================================================================================
00278 void SMESHGUI_MeshInfosDlg::onStartSelection()
00279 {
00280   myStartSelection = true;
00281   onSelectionChanged();
00282   myStartSelection = true;
00283   mySelectLab->setText(tr("INF_SELECT_OBJECT"));
00284 }
00285 
00286 //=================================================================================
00287 // function : onHelp()
00288 // purpose  :
00289 //=================================================================================
00290 void SMESHGUI_MeshInfosDlg::onHelp()
00291 {
00292   LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
00293   if (app) 
00294     app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
00295   else {
00296     QString platform;
00297 #ifdef WIN32
00298     platform = "winapplication";
00299 #else
00300     platform = "application";
00301 #endif
00302     SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
00303                              tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
00304                              arg(app->resourceMgr()->stringValue("ExternalBrowser", 
00305                                                                  platform)).
00306                              arg(myHelpFileName));
00307   }
00308 }
00309 
00310 //=================================================================================
00311 // function : keyPressEvent()
00312 // purpose  :
00313 //=================================================================================
00314 void SMESHGUI_MeshInfosDlg::keyPressEvent( QKeyEvent* e )
00315 {
00316   QDialog::keyPressEvent( e );
00317   if ( e->isAccepted() )
00318     return;
00319 
00320   if ( e->key() == Qt::Key_F1 ) {
00321     e->accept();
00322     onHelp();
00323   }
00324 }
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