Back to index

salome-smesh  6.5.0
SMESHGUI_DeleteGroupDlg.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  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 // File   : SMESHGUI_DeleteGroupDlg.cxx
00024 // Author : Sergey LITONIN, Open CASCADE S.A.S.
00025 // SMESH includes
00026 //
00027 #include "SMESHGUI_DeleteGroupDlg.h"
00028 
00029 #include "SMESHGUI.h"
00030 #include "SMESHGUI_Utils.h"
00031 #include "SMESHGUI_VTKUtils.h"
00032 
00033 #include <SMESH_TypeFilter.hxx>
00034 
00035 // SALOME GUI includes
00036 #include <SUIT_Desktop.h>
00037 #include <SUIT_Session.h>
00038 #include <SUIT_MessageBox.h>
00039 #include <SUIT_ResourceMgr.h>
00040 
00041 #include <SalomeApp_Study.h>
00042 #include <LightApp_Application.h>
00043 #include <LightApp_SelectionMgr.h>
00044 
00045 #include <SALOME_ListIO.hxx>
00046 #include <SALOME_ListIteratorOfListIO.hxx>
00047 
00048 #include <SVTK_Selection.h>
00049 #include <SVTK_ViewWindow.h>
00050 
00051 // Qt includes
00052 #include <QHBoxLayout>
00053 #include <QVBoxLayout>
00054 #include <QPushButton>
00055 #include <QGroupBox>
00056 #include <QListWidget>
00057 #include <QKeyEvent>
00058 
00059 // IDL includes
00060 #include <SALOMEconfig.h>
00061 #include CORBA_SERVER_HEADER(SMESH_Mesh)
00062 
00063 #define SPACING 6
00064 #define MARGIN  11
00065 
00071 //=================================================================================
00072 // function : SMESHGUI_DeleteGroupDlg()
00073 // purpose  : Constructor
00074 //=================================================================================
00075 SMESHGUI_DeleteGroupDlg::SMESHGUI_DeleteGroupDlg (SMESHGUI* theModule):
00076   QDialog(SMESH::GetDesktop(theModule)),
00077   mySelectionMgr(SMESH::GetSelectionMgr(theModule)),
00078   mySMESHGUI(theModule)
00079 {
00080   setModal(false);
00081   setWindowTitle(tr("CAPTION"));
00082 
00083   QVBoxLayout* aDlgLay = new QVBoxLayout(this);
00084   aDlgLay->setMargin(MARGIN);
00085   aDlgLay->setSpacing(SPACING);
00086 
00087   QWidget* aMainFrame = createMainFrame  (this);
00088   QWidget* aBtnFrame  = createButtonFrame(this);
00089 
00090   aDlgLay->addWidget(aMainFrame);
00091   aDlgLay->addWidget(aBtnFrame);
00092 
00093   myHelpFileName = "deleting_groups_page.html";
00094 
00095   Init();
00096 }
00097 
00098 //=================================================================================
00099 // function : createMainFrame()
00100 // purpose  : Create frame containing dialog's input fields
00101 //=================================================================================
00102 QWidget* SMESHGUI_DeleteGroupDlg::createMainFrame (QWidget* theParent)
00103 {
00104   QGroupBox* aMainGrp =
00105     new QGroupBox(tr("SELECTED_GROUPS"), theParent);
00106   QVBoxLayout* aLay = new QVBoxLayout(aMainGrp);
00107   aLay->setMargin(MARGIN);
00108   aLay->setSpacing(SPACING);
00109 
00110   myListBox = new QListWidget(aMainGrp);
00111   myListBox->setMinimumSize(150, 100);
00112   myListBox->setSelectionMode(QListWidget::NoSelection);
00113   //myListBox->setRowMode(QListBox::FitToWidth);
00114   myListBox->setFlow(QListWidget::LeftToRight);
00115   myListBox->setWrapping(true);
00116 
00117   aLay->addWidget(myListBox);
00118   
00119   return aMainGrp;
00120 }
00121 
00122 //=================================================================================
00123 // function : createButtonFrame()
00124 // purpose  : Create frame containing buttons
00125 //=================================================================================
00126 QWidget* SMESHGUI_DeleteGroupDlg::createButtonFrame (QWidget* theParent)
00127 {
00128   QGroupBox* aFrame = new QGroupBox(theParent);
00129 
00130   myOkBtn     = new QPushButton(tr("SMESH_BUT_APPLY_AND_CLOSE"), aFrame);
00131   myApplyBtn  = new QPushButton(tr("SMESH_BUT_APPLY"),           aFrame);
00132   myCloseBtn  = new QPushButton(tr("SMESH_BUT_CLOSE"),           aFrame);
00133   myHelpBtn   = new QPushButton(tr("SMESH_BUT_HELP"),            aFrame);
00134 
00135   QHBoxLayout* aLay = new QHBoxLayout(aFrame);
00136   aLay->setMargin(MARGIN);
00137   aLay->setSpacing(SPACING);
00138 
00139   aLay->addWidget(myOkBtn);
00140   aLay->addSpacing(10);
00141   aLay->addWidget(myApplyBtn);
00142   aLay->addSpacing(10);
00143   aLay->addStretch();
00144   aLay->addWidget(myCloseBtn);
00145   aLay->addWidget(myHelpBtn);
00146 
00147   // connect signals and slots
00148   connect(myOkBtn,    SIGNAL(clicked()), SLOT(onOk()));
00149   connect(myCloseBtn, SIGNAL(clicked()), SLOT(onClose()));
00150   connect(myApplyBtn, SIGNAL(clicked()), SLOT(onApply()));
00151   connect(myHelpBtn,  SIGNAL(clicked()), SLOT(onHelp()));
00152 
00153   return aFrame;
00154 }
00155 
00156 //=================================================================================
00157 // name    : ~SMESHGUI_DeleteGroupDlg()
00158 // Purpose : Destructor
00159 //=================================================================================
00160 SMESHGUI_DeleteGroupDlg::~SMESHGUI_DeleteGroupDlg()
00161 {
00162 }
00163 
00164 //=================================================================================
00165 // function : Init()
00166 // purpose  : Init dialog fields, connect signals and slots, show dialog
00167 //=================================================================================
00168 void SMESHGUI_DeleteGroupDlg::Init ()
00169 {
00170   myBlockSelection = false;
00171   mySMESHGUI->SetActiveDialogBox((QDialog*)this);
00172 
00173   // selection and SMESHGUI
00174   connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), SLOT(onSelectionDone()));
00175   connect(mySMESHGUI, SIGNAL(SignalDeactivateActiveDialog()), SLOT(onDeactivate()));
00176   connect(mySMESHGUI, SIGNAL(SignalCloseAllDialogs()), SLOT(onClose()));
00177 
00178   // set selection mode
00179   mySelectionMgr->installFilter(new SMESH_TypeFilter(GROUP));
00180   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
00181     aViewWindow->SetSelectionMode(ActorSelection);
00182   onSelectionDone();
00183 }
00184 
00185 //=================================================================================
00186 // function : isValid()
00187 // purpose  : Verify validity of input data
00188 //=================================================================================
00189 bool SMESHGUI_DeleteGroupDlg::isValid()
00190 {
00191   if (myListBox->count() == 0) {
00192     SUIT_MessageBox::information(SMESHGUI::desktop(), tr("SMESH_INSUFFICIENT_DATA"),
00193                                  tr("NO_SELECTED_GROUPS"));
00194     return false;
00195   }
00196 
00197   return !mySMESHGUI->isActiveStudyLocked();
00198 }
00199 
00200 //=================================================================================
00201 // function : onApply()
00202 // purpose  : SLOT called when "Apply" button pressed.
00203 //=================================================================================
00204 bool SMESHGUI_DeleteGroupDlg::onApply()
00205 {
00206   if (!isValid())
00207     return false;
00208 
00209   myBlockSelection = true;
00210 
00211   QList<SMESH::SMESH_GroupBase_var>::iterator anIter;
00212   for (anIter = myListGrp.begin(); anIter != myListGrp.end(); ++anIter) {
00213     SMESH::SMESH_Mesh_ptr aMesh = (*anIter)->GetMesh();
00214     if (!aMesh->_is_nil())
00215       aMesh->RemoveGroupWithContents(*anIter);
00216   }
00217 
00218   myListBox->clear();
00219   myListGrp.clear();
00220   mySelectionMgr->clearSelected();
00221   SMESH::UpdateView();
00222   SMESHGUI::Modified();
00223   mySMESHGUI->updateObjBrowser(true);
00224 
00225   myBlockSelection = false;
00226   return true;
00227 }
00228 
00229 //=================================================================================
00230 // function : onOk()
00231 // purpose  : SLOT called when "Ok" button pressed.
00232 //=================================================================================
00233 void SMESHGUI_DeleteGroupDlg::onOk()
00234 {
00235   if (onApply())
00236     onClose();
00237 }
00238 
00239 //=================================================================================
00240 // function : onClose()
00241 // purpose  : SLOT called when "Close" button pressed. Close dialog
00242 //=================================================================================
00243 void SMESHGUI_DeleteGroupDlg::onClose()
00244 {
00245   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
00246     aViewWindow->SetSelectionMode(ActorSelection);
00247   disconnect(mySelectionMgr, 0, this, 0);
00248   disconnect(mySMESHGUI, 0, this, 0);
00249   mySMESHGUI->ResetState();
00250   mySelectionMgr->clearFilters();
00251   reject();
00252 }
00253 
00254 //=================================================================================
00255 // function : onHelp()
00256 // purpose  :
00257 //=================================================================================
00258 void SMESHGUI_DeleteGroupDlg::onHelp()
00259 {
00260   LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
00261   if (app) 
00262     app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
00263   else {
00264     QString platform;
00265 #ifdef WIN32
00266     platform = "winapplication";
00267 #else
00268     platform = "application";
00269 #endif
00270     SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
00271                              tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
00272                              arg(app->resourceMgr()->stringValue("ExternalBrowser", 
00273                                                                  platform)).
00274                              arg(myHelpFileName));
00275   }
00276 }
00277 
00278 //=================================================================================
00279 // function : onSelectionDone()
00280 // purpose  : SLOT called when selection changed
00281 //=================================================================================
00282 void SMESHGUI_DeleteGroupDlg::onSelectionDone()
00283 {
00284   if (myBlockSelection)
00285     return;
00286 
00287   myListGrp.clear();
00288   QStringList aNames;
00289 
00290   SALOME_ListIO aListIO;
00291   mySelectionMgr->selectedObjects(aListIO);
00292   SALOME_ListIteratorOfListIO anIter (aListIO);
00293   for ( ; anIter.More(); anIter.Next()) {
00294     SMESH::SMESH_GroupBase_var aGroup =
00295       SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(anIter.Value());
00296     if (!aGroup->_is_nil()) {
00297       aNames.append(aGroup->GetName());
00298       myListGrp.append(aGroup);
00299     }
00300   }
00301 
00302   myListBox->clear();
00303   myListBox->addItems(aNames);
00304 }
00305 
00306 //=================================================================================
00307 // function : onDeactivate()
00308 // purpose  : SLOT called when dialog must be deativated
00309 //=================================================================================
00310 void SMESHGUI_DeleteGroupDlg::onDeactivate()
00311 {
00312   mySelectionMgr->clearFilters();
00313   setEnabled(false);
00314 }
00315 
00316 //=================================================================================
00317 // function : enterEvent()
00318 // purpose  : Event filter
00319 //=================================================================================
00320 void SMESHGUI_DeleteGroupDlg::enterEvent (QEvent*)
00321 {
00322   mySMESHGUI->EmitSignalDeactivateDialog();
00323   setEnabled(true);
00324   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
00325     aViewWindow->SetSelectionMode(ActorSelection);
00326   mySelectionMgr->installFilter(new SMESH_TypeFilter (GROUP));
00327 }
00328 
00329 //=================================================================================
00330 // function : closeEvent()
00331 // purpose  :
00332 //=================================================================================
00333 void SMESHGUI_DeleteGroupDlg::closeEvent (QCloseEvent*)
00334 {
00335   onClose();
00336 }
00337 
00338 //=================================================================================
00339 // function : keyPressEvent()
00340 // purpose  :
00341 //=================================================================================
00342 void SMESHGUI_DeleteGroupDlg::keyPressEvent( QKeyEvent* e )
00343 {
00344   QDialog::keyPressEvent( e );
00345   if ( e->isAccepted() )
00346     return;
00347 
00348   if ( e->key() == Qt::Key_F1 ) {
00349     e->accept();
00350     onHelp();
00351   }
00352 }