smesh/src/SMESHGUI/SMESHGUI_MeshInfosDlg.cxx

325 lines
12 KiB
C++
Raw Normal View History

2011-06-06 14:15:39 +06:00
// Copyright (C) 2007-2011 CEA/DEN, EDF R&D, OPEN CASCADE
2003-07-10 19:18:22 +06:00
//
2011-06-06 14:15:39 +06:00
// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
//
2011-06-06 14:15:39 +06:00
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License.
//
2011-06-06 14:15:39 +06:00
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
2011-06-06 14:15:39 +06:00
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
2011-06-06 14:15:39 +06:00
// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
2003-07-10 19:18:22 +06:00
//
2010-05-14 21:32:37 +06:00
2009-02-17 10:27:49 +05:00
// SMESH SMESHGUI : GUI for SMESH component
// File : SMESHGUI_MeshInfosDlg.cxx
// Author : Nicolas BARBEROU
// SMESH includes
2003-07-10 19:18:22 +06:00
//
#include "SMESHGUI_MeshInfosDlg.h"
#include "SMESHGUI.h"
#include "SMESHGUI_Utils.h"
#include "SMESHGUI_MeshInfosBox.h"
2009-02-17 10:27:49 +05:00
// SALOME GUI includes
#include <SUIT_Desktop.h>
#include <SUIT_ResourceMgr.h>
#include <SUIT_OverrideCursor.h>
#include <SUIT_Session.h>
#include <SUIT_MessageBox.h>
#include <LightApp_SelectionMgr.h>
#include <LightApp_Application.h>
#include <SALOME_ListIO.hxx>
// SALOME KERNEL includes
#include <SALOMEDSClient_Study.hxx>
// Qt includes
#include <QGroupBox>
#include <QLabel>
#include <QFrame>
#include <QStackedWidget>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QGridLayout>
#include <QPushButton>
#include <QKeyEvent>
// IDL includes
#include <SALOMEconfig.h>
2004-12-01 15:48:31 +05:00
#include CORBA_SERVER_HEADER(SMESH_Mesh)
#include CORBA_SERVER_HEADER(SMESH_Group)
#define COLONIZE(str) (QString(str).contains(":") > 0 ? QString(str) : QString(str) + " :" )
2009-02-17 10:27:49 +05:00
#define SPACING 6
#define MARGIN 11
2003-05-19 20:07:00 +06:00
//=================================================================================
// function : SMESHGUI_MeshInfosDlg()
// purpose : Constructor
2003-05-19 20:07:00 +06:00
//=================================================================================
2009-02-17 10:27:49 +05:00
SMESHGUI_MeshInfosDlg::SMESHGUI_MeshInfosDlg(SMESHGUI* theModule):
QDialog(SMESH::GetDesktop(theModule)),
mySelectionMgr(SMESH::GetSelectionMgr(theModule)),
mySMESHGUI(theModule)
2004-06-18 14:34:31 +06:00
{
2009-02-17 10:27:49 +05:00
setModal( false );
setAttribute( Qt::WA_DeleteOnClose, true );
setWindowTitle(tr("SMESH_MESHINFO_TITLE"));
setSizeGripEnabled(true);
2004-06-18 14:34:31 +06:00
myStartSelection = true;
myIsActiveWindow = true;
QVBoxLayout* aTopLayout = new QVBoxLayout(this);
2009-02-17 10:27:49 +05:00
aTopLayout->setSpacing(SPACING); aTopLayout->setMargin(MARGIN);
2004-06-18 14:34:31 +06:00
// select button & label
2005-06-08 16:45:19 +06:00
QPixmap image0(SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH",tr("ICON_SELECT")));
2009-02-17 10:27:49 +05:00
mySelectBtn = new QPushButton(this);
mySelectBtn->setIcon(image0);
mySelectBtn->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed));
2004-06-18 14:34:31 +06:00
2009-02-17 10:27:49 +05:00
mySelectLab = new QLabel(this);
mySelectLab->setAlignment(Qt::AlignCenter);
QFont fnt = mySelectLab->font(); fnt.setBold(true);
mySelectLab->setFont(fnt);
2004-06-18 14:34:31 +06:00
QHBoxLayout* aSelectLayout = new QHBoxLayout;
aSelectLayout->setMargin(0); aSelectLayout->setSpacing(0);
aSelectLayout->addWidget(mySelectBtn);
aSelectLayout->addWidget(mySelectLab);
2004-06-18 14:34:31 +06:00
// top widget stack
2009-02-17 10:27:49 +05:00
myWGStack = new QStackedWidget(this);
2004-06-18 14:34:31 +06:00
// no valid selection
QWidget* myBadWidget = new QWidget(myWGStack);
QVBoxLayout* aBadLayout = new QVBoxLayout(myBadWidget);
2009-02-17 10:27:49 +05:00
QLabel* myBadLab = new QLabel(tr("SMESH_BAD_SELECTION"), myBadWidget);
myBadLab->setAlignment(Qt::AlignCenter);
myBadLab->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding));
aBadLayout->addWidget(myBadLab);
2009-02-17 10:27:49 +05:00
myWGStack->addWidget(myBadWidget);
2004-06-18 14:34:31 +06:00
// mesh
myMeshWidget = new QWidget(myWGStack);
QGridLayout* aMeshLayout = new QGridLayout(myMeshWidget);
2009-02-17 10:27:49 +05:00
aMeshLayout->setSpacing(SPACING); aMeshLayout->setMargin(0);
myWGStack->addWidget(myMeshWidget);
2004-06-18 14:34:31 +06:00
// --> name
2009-02-17 10:27:49 +05:00
QLabel* myMeshNameLab = new QLabel(COLONIZE(tr("SMESH_MESHINFO_NAME")), myMeshWidget);
myMeshName = new QLabel(myMeshWidget);
myMeshName->setMinimumWidth(100);
QFrame* line1 = new QFrame(myMeshWidget);
line1->setFrameStyle(QFrame::HLine | QFrame::Sunken);
myMeshInfoBox = new SMESHGUI_MeshInfosBox(true, myMeshWidget);
2009-02-17 10:27:49 +05:00
aMeshLayout->addWidget(myMeshNameLab, 0, 0);
aMeshLayout->addWidget(myMeshName, 0, 1);
aMeshLayout->addWidget(line1, 1, 0, 1, 2);
aMeshLayout->addWidget(myMeshInfoBox, 2, 0, 1, 2);
aMeshLayout->addItem(new QSpacerItem(0, 0, QSizePolicy::Minimum, QSizePolicy::Expanding), 3, 0);
2004-06-18 14:34:31 +06:00
// buttons
2009-02-17 10:27:49 +05:00
myButtonsGroup = new QGroupBox(this);
QHBoxLayout* myButtonsGroupLayout = new QHBoxLayout(myButtonsGroup);
myButtonsGroupLayout->setSpacing(SPACING); myButtonsGroupLayout->setMargin(MARGIN);
// buttons --> OK and Help buttons
2009-02-17 10:27:49 +05:00
myOkBtn = new QPushButton(tr("SMESH_BUT_OK" ), myButtonsGroup);
2010-11-25 17:44:43 +05:00
myOkBtn->setAutoDefault(true);
myOkBtn->setDefault(true);
myOkBtn->setFocus();
2009-02-17 10:27:49 +05:00
myHelpBtn = new QPushButton(tr("SMESH_BUT_HELP" ), myButtonsGroup);
myHelpBtn->setAutoDefault(true);
myButtonsGroupLayout->addWidget(myOkBtn);
2009-02-17 10:27:49 +05:00
myButtonsGroupLayout->addSpacing(10);
2004-06-18 14:34:31 +06:00
myButtonsGroupLayout->addStretch();
myButtonsGroupLayout->addWidget(myHelpBtn);
2004-06-18 14:34:31 +06:00
aTopLayout->addLayout(aSelectLayout);
aTopLayout->addWidget(myWGStack);
aTopLayout->addWidget(myButtonsGroup);
mySMESHGUI->SetActiveDialogBox(this);
2004-06-18 14:34:31 +06:00
// connect signals
connect(myOkBtn, SIGNAL(clicked()), this, SLOT(close()));
connect( myHelpBtn, SIGNAL(clicked()), this, SLOT(onHelp()));
connect(mySelectBtn, SIGNAL(clicked()), this, SLOT(onStartSelection()));
connect(mySMESHGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(close()));
connect(mySMESHGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(onSelectionChanged()));
2004-06-18 14:34:31 +06:00
// init dialog with current selection
onSelectionChanged();
myHelpFileName = "mesh_infos_page.html#advanced_mesh_infos_anchor";
2003-05-19 20:07:00 +06:00
}
//=================================================================================
// function : ~SMESHGUI_MeshInfosDlg()
// purpose : Destructor
2003-05-19 20:07:00 +06:00
//=================================================================================
2004-06-18 14:34:31 +06:00
SMESHGUI_MeshInfosDlg::~SMESHGUI_MeshInfosDlg()
2003-05-19 20:07:00 +06:00
{
}
//=================================================================================
// function : DumpMeshInfos()
// purpose :
2003-05-19 20:07:00 +06:00
//=================================================================================
void SMESHGUI_MeshInfosDlg::DumpMeshInfos()
{
SUIT_OverrideCursor wc;
SALOME_ListIO aList;
mySelectionMgr->selectedObjects(aList);
int nbSel = aList.Extent();
if (nbSel == 1) {
2004-06-18 14:34:31 +06:00
myStartSelection = false;
mySelectLab->setText("");
Handle(SALOME_InteractiveObject) IObject = aList.First();
_PTR(SObject) aSO = SMESH::GetActiveStudyDocument()->FindObjectID(IObject->getEntry());
if (aSO) {
//CORBA::Object_var anObject = aSO->GetObject();
CORBA::Object_var anObject = SMESH::SObjectToObject(aSO);
if (!CORBA::is_nil(anObject)) {
2009-10-01 12:28:20 +06:00
SMESH::SMESH_IDSource_var anIDSource = SMESH::SMESH_IDSource::_narrow(anObject);
if (!anIDSource->_is_nil()) {
myWGStack->setCurrentWidget(myMeshWidget);
setWindowTitle(tr("SMESH_MESHINFO_TITLE") + " [" + tr("SMESH_OBJECT_MESH") + "]");
myMeshName->setText(aSO->GetName().c_str());
2009-10-01 12:28:20 +06:00
SMESH::long_array_var aMeshInfo = anIDSource->GetMeshInfo();
myMeshInfoBox->SetMeshInfo( aMeshInfo );
2009-10-01 12:28:20 +06:00
return;
}
2004-06-18 14:34:31 +06:00
}
2003-05-19 20:07:00 +06:00
}
}
2009-02-17 10:27:49 +05:00
myWGStack->setCurrentIndex(0);
setWindowTitle(tr("SMESH_MESHINFO_TITLE"));
2003-05-19 20:07:00 +06:00
}
//=================================================================================
// function : SelectionIntoArgument()
// purpose : Called when selection has changed
//=================================================================================
2004-06-18 14:34:31 +06:00
void SMESHGUI_MeshInfosDlg::onSelectionChanged()
2003-05-19 20:07:00 +06:00
{
if (myStartSelection)
2004-06-18 14:34:31 +06:00
DumpMeshInfos();
2003-05-19 20:07:00 +06:00
}
//=================================================================================
// function : closeEvent()
// purpose :
//=================================================================================
2009-02-17 10:27:49 +05:00
void SMESHGUI_MeshInfosDlg::closeEvent(QCloseEvent* e)
2003-05-19 20:07:00 +06:00
{
mySMESHGUI->ResetState();
QDialog::closeEvent(e);
2003-05-19 20:07:00 +06:00
}
//=================================================================================
2004-06-18 14:34:31 +06:00
// function : windowActivationChange()
// purpose : called when window is activated/deactivated
2003-05-19 20:07:00 +06:00
//=================================================================================
2009-02-17 10:27:49 +05:00
void SMESHGUI_MeshInfosDlg::windowActivationChange(bool oldActive)
2003-05-19 20:07:00 +06:00
{
QDialog::windowActivationChange(oldActive);
if (isActiveWindow() && myIsActiveWindow != isActiveWindow())
ActivateThisDialog();
2004-06-18 14:34:31 +06:00
myIsActiveWindow = isActiveWindow();
2003-05-19 20:07:00 +06:00
}
//=================================================================================
// function : DeactivateActiveDialog()
// purpose :
//=================================================================================
void SMESHGUI_MeshInfosDlg::DeactivateActiveDialog()
{
disconnect(mySelectionMgr, 0, this, 0);
2003-05-19 20:07:00 +06:00
}
//=================================================================================
// function : ActivateThisDialog()
// purpose :
//=================================================================================
void SMESHGUI_MeshInfosDlg::ActivateThisDialog()
{
/* Emit a signal to deactivate any active dialog */
mySMESHGUI->EmitSignalDeactivateDialog();
connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(onSelectionChanged()));
2003-05-19 20:07:00 +06:00
}
2004-06-18 14:34:31 +06:00
//=================================================================================
// function : onStartSelection()
// purpose : starts selection
//=================================================================================
void SMESHGUI_MeshInfosDlg::onStartSelection()
{
myStartSelection = true;
onSelectionChanged();
myStartSelection = true;
mySelectLab->setText(tr("INF_SELECT_OBJECT"));
2004-06-18 14:34:31 +06:00
}
//=================================================================================
// function : onHelp()
// purpose :
//=================================================================================
void SMESHGUI_MeshInfosDlg::onHelp()
{
LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
if (app)
app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
else {
2009-02-17 10:27:49 +05:00
QString platform;
#ifdef WIN32
2009-02-17 10:27:49 +05:00
platform = "winapplication";
#else
2009-02-17 10:27:49 +05:00
platform = "application";
#endif
2009-02-17 10:27:49 +05:00
SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
2009-10-01 12:28:20 +06:00
tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
arg(app->resourceMgr()->stringValue("ExternalBrowser",
platform)).
arg(myHelpFileName));
}
}
//=================================================================================
// function : keyPressEvent()
// purpose :
//=================================================================================
void SMESHGUI_MeshInfosDlg::keyPressEvent( QKeyEvent* e )
{
QDialog::keyPressEvent( e );
if ( e->isAccepted() )
return;
2009-02-17 10:27:49 +05:00
if ( e->key() == Qt::Key_F1 ) {
e->accept();
onHelp();
}
}