smesh/src/SMESHGUI/SMESHGUI_DeleteGroupDlg.cxx

352 lines
11 KiB
C++
Raw Normal View History

2013-04-01 19:05:47 +06:00
// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE
2004-12-01 15:48:31 +05:00
//
2012-08-09 16:03:55 +06:00
// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
//
2012-08-09 16:03:55 +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.
//
2012-08-09 16:03:55 +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.
//
2012-08-09 16:03:55 +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
//
2012-08-09 16:03:55 +06:00
// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
2004-12-01 15:48:31 +05:00
//
2012-08-09 16:03:55 +06:00
2009-02-17 10:27:49 +05:00
// File : SMESHGUI_DeleteGroupDlg.cxx
// Author : Sergey LITONIN, Open CASCADE S.A.S.
// SMESH includes
2004-12-01 15:48:31 +05:00
//
#include "SMESHGUI_DeleteGroupDlg.h"
#include "SMESHGUI.h"
#include "SMESHGUI_Utils.h"
#include "SMESHGUI_VTKUtils.h"
2009-02-17 10:27:49 +05:00
#include <SMESH_TypeFilter.hxx>
2009-02-17 10:27:49 +05:00
// SALOME GUI includes
#include <SUIT_Desktop.h>
#include <SUIT_Session.h>
#include <SUIT_MessageBox.h>
#include <SUIT_ResourceMgr.h>
2009-02-17 10:27:49 +05:00
#include <SalomeApp_Study.h>
#include <LightApp_Application.h>
#include <LightApp_SelectionMgr.h>
2009-02-17 10:27:49 +05:00
#include <SALOME_ListIO.hxx>
#include <SALOME_ListIteratorOfListIO.hxx>
2004-12-01 15:48:31 +05:00
2009-02-17 10:27:49 +05:00
#include <SVTK_Selection.h>
#include <SVTK_ViewWindow.h>
2005-06-08 12:18:53 +06:00
2009-02-17 10:27:49 +05:00
// Qt includes
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QPushButton>
#include <QGroupBox>
#include <QListWidget>
#include <QKeyEvent>
2004-12-01 15:48:31 +05:00
2009-02-17 10:27:49 +05:00
// IDL includes
#include <SALOMEconfig.h>
2004-12-01 15:48:31 +05:00
#include CORBA_SERVER_HEADER(SMESH_Mesh)
2009-02-17 10:27:49 +05:00
#define SPACING 6
#define MARGIN 11
2004-12-01 15:48:31 +05:00
/*!
* Class : SMESHGUI_DeleteGroupDlg
* Description : Delete groups and their contents
*/
//=================================================================================
// function : SMESHGUI_DeleteGroupDlg()
// purpose : Constructor
//=================================================================================
2005-06-08 12:18:53 +06:00
SMESHGUI_DeleteGroupDlg::SMESHGUI_DeleteGroupDlg (SMESHGUI* theModule):
2009-02-17 10:27:49 +05:00
QDialog(SMESH::GetDesktop(theModule)),
2005-06-08 12:18:53 +06:00
mySelectionMgr(SMESH::GetSelectionMgr(theModule)),
mySMESHGUI(theModule)
2004-12-01 15:48:31 +05:00
{
2009-02-17 10:27:49 +05:00
setModal(false);
setWindowTitle(tr("CAPTION"));
2004-12-01 15:48:31 +05:00
2009-02-17 10:27:49 +05:00
QVBoxLayout* aDlgLay = new QVBoxLayout(this);
aDlgLay->setMargin(MARGIN);
aDlgLay->setSpacing(SPACING);
2004-12-01 15:48:31 +05:00
2009-02-17 10:27:49 +05:00
QWidget* aMainFrame = createMainFrame (this);
QWidget* aBtnFrame = createButtonFrame(this);
2004-12-01 15:48:31 +05:00
aDlgLay->addWidget(aMainFrame);
aDlgLay->addWidget(aBtnFrame);
2004-12-01 15:48:31 +05:00
myHelpFileName = "deleting_groups_page.html";
2005-06-08 12:18:53 +06:00
Init();
2004-12-01 15:48:31 +05:00
}
//=================================================================================
// function : createMainFrame()
// purpose : Create frame containing dialog's input fields
//=================================================================================
2009-02-17 10:27:49 +05:00
QWidget* SMESHGUI_DeleteGroupDlg::createMainFrame (QWidget* theParent)
2004-12-01 15:48:31 +05:00
{
QGroupBox* aMainGrp =
2009-02-17 10:27:49 +05:00
new QGroupBox(tr("SELECTED_GROUPS"), theParent);
QVBoxLayout* aLay = new QVBoxLayout(aMainGrp);
aLay->setMargin(MARGIN);
aLay->setSpacing(SPACING);
myListBox = new QListWidget(aMainGrp);
myListBox->setMinimumSize(150, 100);
myListBox->setSelectionMode(QListWidget::NoSelection);
//myListBox->setRowMode(QListBox::FitToWidth);
myListBox->setFlow(QListWidget::LeftToRight);
myListBox->setWrapping(true);
aLay->addWidget(myListBox);
2004-12-01 15:48:31 +05:00
return aMainGrp;
}
//=================================================================================
// function : createButtonFrame()
// purpose : Create frame containing buttons
//=================================================================================
2009-02-17 10:27:49 +05:00
QWidget* SMESHGUI_DeleteGroupDlg::createButtonFrame (QWidget* theParent)
2004-12-01 15:48:31 +05:00
{
2009-02-17 10:27:49 +05:00
QGroupBox* aFrame = new QGroupBox(theParent);
2004-12-01 15:48:31 +05:00
2009-02-17 10:27:49 +05:00
myOkBtn = new QPushButton(tr("SMESH_BUT_APPLY_AND_CLOSE"), aFrame);
myApplyBtn = new QPushButton(tr("SMESH_BUT_APPLY"), aFrame);
myCloseBtn = new QPushButton(tr("SMESH_BUT_CLOSE"), aFrame);
myHelpBtn = new QPushButton(tr("SMESH_BUT_HELP"), aFrame);
2004-12-01 15:48:31 +05:00
2009-02-17 10:27:49 +05:00
QHBoxLayout* aLay = new QHBoxLayout(aFrame);
aLay->setMargin(MARGIN);
aLay->setSpacing(SPACING);
aLay->addWidget(myOkBtn);
2009-02-17 10:27:49 +05:00
aLay->addSpacing(10);
aLay->addWidget(myApplyBtn);
2009-02-17 10:27:49 +05:00
aLay->addSpacing(10);
aLay->addStretch();
aLay->addWidget(myCloseBtn);
aLay->addWidget(myHelpBtn);
2004-12-01 15:48:31 +05:00
// connect signals and slots
connect(myOkBtn, SIGNAL(clicked()), SLOT(onOk()));
2013-02-28 21:07:35 +06:00
connect(myCloseBtn, SIGNAL(clicked()), SLOT(reject()));
connect(myApplyBtn, SIGNAL(clicked()), SLOT(onApply()));
connect(myHelpBtn, SIGNAL(clicked()), SLOT(onHelp()));
2004-12-01 15:48:31 +05:00
return aFrame;
}
//=================================================================================
// name : ~SMESHGUI_DeleteGroupDlg()
2004-12-01 15:48:31 +05:00
// Purpose : Destructor
//=================================================================================
2004-12-01 15:48:31 +05:00
SMESHGUI_DeleteGroupDlg::~SMESHGUI_DeleteGroupDlg()
{
}
//=================================================================================
// function : Init()
// purpose : Init dialog fields, connect signals and slots, show dialog
//=================================================================================
2005-06-08 12:18:53 +06:00
void SMESHGUI_DeleteGroupDlg::Init ()
2004-12-01 15:48:31 +05:00
{
myBlockSelection = false;
2005-06-08 12:18:53 +06:00
mySMESHGUI->SetActiveDialogBox((QDialog*)this);
2004-12-01 15:48:31 +05:00
// selection and SMESHGUI
connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), SLOT(onSelectionDone()));
2005-06-08 12:18:53 +06:00
connect(mySMESHGUI, SIGNAL(SignalDeactivateActiveDialog()), SLOT(onDeactivate()));
2013-02-28 21:07:35 +06:00
connect(mySMESHGUI, SIGNAL(SignalCloseAllDialogs()), SLOT(reject()));
2004-12-01 15:48:31 +05:00
// set selection mode
2012-12-13 17:41:29 +06:00
mySelectionMgr->installFilter(new SMESH_TypeFilter(SMESH::GROUP));
if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
aViewWindow->SetSelectionMode(ActorSelection);
2004-12-01 15:48:31 +05:00
onSelectionDone();
}
//=================================================================================
// function : isValid()
// purpose : Verify validity of input data
//=================================================================================
2004-12-01 15:48:31 +05:00
bool SMESHGUI_DeleteGroupDlg::isValid()
{
if (myListBox->count() == 0) {
2009-02-17 10:27:49 +05:00
SUIT_MessageBox::information(SMESHGUI::desktop(), tr("SMESH_INSUFFICIENT_DATA"),
2012-08-09 16:03:55 +06:00
tr("NO_SELECTED_GROUPS"));
2004-12-01 15:48:31 +05:00
return false;
}
2005-06-08 12:18:53 +06:00
return !mySMESHGUI->isActiveStudyLocked();
2004-12-01 15:48:31 +05:00
}
//=================================================================================
// function : onApply()
// purpose : SLOT called when "Apply" button pressed.
//=================================================================================
2004-12-01 15:48:31 +05:00
bool SMESHGUI_DeleteGroupDlg::onApply()
{
if (!isValid())
2004-12-01 15:48:31 +05:00
return false;
myBlockSelection = true;
2009-02-17 10:27:49 +05:00
QList<SMESH::SMESH_GroupBase_var>::iterator anIter;
for (anIter = myListGrp.begin(); anIter != myListGrp.end(); ++anIter) {
2012-12-13 17:41:29 +06:00
SMESH::SMESH_Mesh_var aMesh = (*anIter)->GetMesh();
if (!aMesh->_is_nil())
aMesh->RemoveGroupWithContents(*anIter);
2004-12-01 15:48:31 +05:00
}
myListBox->clear();
myListGrp.clear();
mySelectionMgr->clearSelected();
2012-12-13 17:41:29 +06:00
/** Erase graphical objects **/
SALOME_ListIteratorOfListIO anIterIO (myListGrpIO);
for ( ; anIterIO.More(); anIterIO.Next())
SMESH::RemoveVisualObjectWithActors( anIterIO.Value()->getEntry(), /*fromAllViews=*/true );
2004-12-01 15:48:31 +05:00
SMESH::UpdateView();
2012-08-09 16:03:55 +06:00
SMESHGUI::Modified();
2005-06-08 12:18:53 +06:00
mySMESHGUI->updateObjBrowser(true);
2004-12-01 15:48:31 +05:00
myBlockSelection = false;
return true;
2004-12-01 15:48:31 +05:00
}
//=================================================================================
// function : onOk()
// purpose : SLOT called when "Ok" button pressed.
//=================================================================================
2004-12-01 15:48:31 +05:00
void SMESHGUI_DeleteGroupDlg::onOk()
{
if (onApply())
2013-02-28 21:07:35 +06:00
reject();
2004-12-01 15:48:31 +05:00
}
//=================================================================================
2013-02-28 21:07:35 +06:00
// function : reject()
// purpose : SLOT called when "Close" button pressed. Close dialog
//=================================================================================
2013-02-28 21:07:35 +06:00
void SMESHGUI_DeleteGroupDlg::reject()
2004-12-01 15:48:31 +05:00
{
if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
aViewWindow->SetSelectionMode(ActorSelection);
disconnect(mySelectionMgr, 0, this, 0);
2005-06-08 12:18:53 +06:00
disconnect(mySMESHGUI, 0, this, 0);
mySMESHGUI->ResetState();
mySelectionMgr->clearFilters();
2013-02-28 21:07:35 +06:00
QDialog::reject();
2004-12-01 15:48:31 +05:00
}
//=================================================================================
// function : onHelp()
// purpose :
//=================================================================================
void SMESHGUI_DeleteGroupDlg::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"),
2012-08-09 16:03:55 +06:00
tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
arg(app->resourceMgr()->stringValue("ExternalBrowser",
platform)).
arg(myHelpFileName));
}
}
//=================================================================================
// function : onSelectionDone()
// purpose : SLOT called when selection changed
//=================================================================================
2004-12-01 15:48:31 +05:00
void SMESHGUI_DeleteGroupDlg::onSelectionDone()
{
if (myBlockSelection)
2004-12-01 15:48:31 +05:00
return;
2004-12-01 15:48:31 +05:00
myListGrp.clear();
2012-12-13 17:41:29 +06:00
myListGrpIO.Clear();
2004-12-01 15:48:31 +05:00
QStringList aNames;
SALOME_ListIO aListIO;
mySelectionMgr->selectedObjects(aListIO);
SALOME_ListIteratorOfListIO anIter (aListIO);
2009-02-17 10:27:49 +05:00
for ( ; anIter.More(); anIter.Next()) {
SMESH::SMESH_GroupBase_var aGroup =
SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(anIter.Value());
if (!aGroup->_is_nil()) {
aNames.append(aGroup->GetName());
myListGrp.append(aGroup);
2012-12-13 17:41:29 +06:00
myListGrpIO.Append( anIter.Value() );
2004-12-01 15:48:31 +05:00
}
}
2004-12-01 15:48:31 +05:00
myListBox->clear();
2009-02-17 10:27:49 +05:00
myListBox->addItems(aNames);
2004-12-01 15:48:31 +05:00
}
//=================================================================================
// function : onDeactivate()
// purpose : SLOT called when dialog must be deativated
//=================================================================================
2004-12-01 15:48:31 +05:00
void SMESHGUI_DeleteGroupDlg::onDeactivate()
{
mySelectionMgr->clearFilters();
setEnabled(false);
2004-12-01 15:48:31 +05:00
}
//=================================================================================
// function : enterEvent()
// purpose : Event filter
//=================================================================================
void SMESHGUI_DeleteGroupDlg::enterEvent (QEvent*)
2004-12-01 15:48:31 +05:00
{
2005-06-08 12:18:53 +06:00
mySMESHGUI->EmitSignalDeactivateDialog();
setEnabled(true);
if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
aViewWindow->SetSelectionMode(ActorSelection);
2012-12-13 17:41:29 +06:00
mySelectionMgr->installFilter(new SMESH_TypeFilter (SMESH::GROUP));
2004-12-01 15:48:31 +05:00
}
//=================================================================================
// function : keyPressEvent()
// purpose :
//=================================================================================
void SMESHGUI_DeleteGroupDlg::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();
}
}