1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // SMESH SMESHGUI : GUI for SMESH component
23 // File : SMESHGUI_DeleteGroupDlg.cxx
24 // Author : Sergey LITONIN
27 #include "SMESHGUI_DeleteGroupDlg.h"
30 #include "SMESHGUI_Utils.h"
31 #include "SMESHGUI_VTKUtils.h"
33 #include "SMESH_TypeFilter.hxx"
35 #include "SUIT_Desktop.h"
36 #include "SUIT_Session.h"
37 #include "SUIT_MessageBox.h"
39 #include "SalomeApp_Study.h"
40 #include "LightApp_Application.h"
41 #include "LightApp_SelectionMgr.h"
43 #include "SALOME_ListIO.hxx"
44 #include "SALOME_ListIteratorOfListIO.hxx"
46 #include "SVTK_Selection.h"
47 #include "SVTK_ViewWindow.h"
52 #include <qpushbutton.h>
53 #include <qgroupbox.h>
57 #include <qmessagebox.h>
60 #include "SALOMEconfig.h"
61 #include CORBA_SERVER_HEADER(SMESH_Mesh)
67 * Class : SMESHGUI_DeleteGroupDlg
68 * Description : Delete groups and their contents
71 //=================================================================================
72 // function : SMESHGUI_DeleteGroupDlg()
73 // purpose : Constructor
74 //=================================================================================
75 SMESHGUI_DeleteGroupDlg::SMESHGUI_DeleteGroupDlg (SMESHGUI* theModule):
76 QDialog(SMESH::GetDesktop(theModule),
77 "SMESHGUI_DeleteGroupDlg",
79 WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu),
80 mySelectionMgr(SMESH::GetSelectionMgr(theModule)),
83 setCaption(tr("CAPTION"));
85 QVBoxLayout* aDlgLay = new QVBoxLayout(this, MARGIN, SPACING);
87 QFrame* aMainFrame = createMainFrame (this);
88 QFrame* aBtnFrame = createButtonFrame(this);
90 aDlgLay->addWidget(aMainFrame);
91 aDlgLay->addWidget(aBtnFrame);
93 aDlgLay->setStretchFactor(aMainFrame, 1);
95 myHelpFileName = "deleting_groups_page.html";
100 //=================================================================================
101 // function : createMainFrame()
102 // purpose : Create frame containing dialog's input fields
103 //=================================================================================
104 QFrame* SMESHGUI_DeleteGroupDlg::createMainFrame (QWidget* theParent)
106 QGroupBox* aMainGrp =
107 new QGroupBox(1, Qt::Horizontal, tr("SELECTED_GROUPS"), theParent);
109 myListBox = new QListBox(aMainGrp);
110 myListBox->setMinimumHeight(100);
111 myListBox->setSelectionMode(QListBox::NoSelection);
112 myListBox->setRowMode(QListBox::FitToWidth);
117 //=================================================================================
118 // function : createButtonFrame()
119 // purpose : Create frame containing buttons
120 //=================================================================================
121 QFrame* SMESHGUI_DeleteGroupDlg::createButtonFrame (QWidget* theParent)
123 QFrame* aFrame = new QFrame(theParent);
124 aFrame->setFrameStyle(QFrame::Box | QFrame::Sunken);
126 myOkBtn = new QPushButton(tr("SMESH_BUT_APPLY_AND_CLOSE"), aFrame);
127 myApplyBtn = new QPushButton(tr("SMESH_BUT_APPLY"), aFrame);
128 myCloseBtn = new QPushButton(tr("SMESH_BUT_CLOSE"), aFrame);
129 myHelpBtn = new QPushButton(tr("SMESH_BUT_HELP"), aFrame);
131 QSpacerItem* aSpacer = new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum);
133 QHBoxLayout* aLay = new QHBoxLayout(aFrame, MARGIN, SPACING);
135 aLay->addWidget(myOkBtn);
136 aLay->addWidget(myApplyBtn);
137 aLay->addItem(aSpacer);
138 aLay->addWidget(myCloseBtn);
139 aLay->addWidget(myHelpBtn);
141 // connect signals and slots
142 connect(myOkBtn, SIGNAL(clicked()), SLOT(onOk()));
143 connect(myCloseBtn, SIGNAL(clicked()), SLOT(onClose()));
144 connect(myApplyBtn, SIGNAL(clicked()), SLOT(onApply()));
145 connect(myHelpBtn, SIGNAL(clicked()), SLOT(onHelp()));
150 //=================================================================================
151 // name : ~SMESHGUI_DeleteGroupDlg()
152 // Purpose : Destructor
153 //=================================================================================
154 SMESHGUI_DeleteGroupDlg::~SMESHGUI_DeleteGroupDlg()
158 //=================================================================================
160 // purpose : Init dialog fields, connect signals and slots, show dialog
161 //=================================================================================
162 void SMESHGUI_DeleteGroupDlg::Init ()
164 myBlockSelection = false;
165 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
167 // selection and SMESHGUI
168 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), SLOT(onSelectionDone()));
169 connect(mySMESHGUI, SIGNAL(SignalDeactivateActiveDialog()), SLOT(onDeactivate()));
170 connect(mySMESHGUI, SIGNAL(SignalCloseAllDialogs()), SLOT(onClose()));
174 // set selection mode
175 mySelectionMgr->installFilter(new SMESH_TypeFilter(GROUP));
176 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
177 aViewWindow->SetSelectionMode(ActorSelection);
183 //=================================================================================
184 // function : isValid()
185 // purpose : Verify validity of input data
186 //=================================================================================
187 bool SMESHGUI_DeleteGroupDlg::isValid()
189 if (myListBox->count() == 0) {
190 QMessageBox::information(SMESHGUI::desktop(), tr("SMESH_INSUFFICIENT_DATA"),
191 tr("NO_SELECTED_GROUPS"), QMessageBox::Ok);
195 return !mySMESHGUI->isActiveStudyLocked();
198 //=================================================================================
199 // function : onApply()
200 // purpose : SLOT called when "Apply" button pressed.
201 //=================================================================================
202 bool SMESHGUI_DeleteGroupDlg::onApply()
207 myBlockSelection = true;
209 QValueList<SMESH::SMESH_GroupBase_var>::iterator anIter;
210 for (anIter = myListGrp.begin(); anIter != myListGrp.end(); ++anIter) {
211 SMESH::SMESH_Mesh_ptr aMesh = (*anIter)->GetMesh();
212 if (!aMesh->_is_nil())
213 aMesh->RemoveGroupWithContents(*anIter);
218 mySelectionMgr->clearSelected();
220 mySMESHGUI->updateObjBrowser(true);
222 myBlockSelection = false;
226 //=================================================================================
228 // purpose : SLOT called when "Ok" button pressed.
229 //=================================================================================
230 void SMESHGUI_DeleteGroupDlg::onOk()
236 //=================================================================================
237 // function : onClose()
238 // purpose : SLOT called when "Close" button pressed. Close dialog
239 //=================================================================================
240 void SMESHGUI_DeleteGroupDlg::onClose()
242 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
243 aViewWindow->SetSelectionMode(ActorSelection);
244 disconnect(mySelectionMgr, 0, this, 0);
245 disconnect(mySMESHGUI, 0, this, 0);
246 mySMESHGUI->ResetState();
247 mySelectionMgr->clearFilters();
251 //=================================================================================
252 // function : onHelp()
254 //=================================================================================
255 void SMESHGUI_DeleteGroupDlg::onHelp()
257 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
259 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
263 platform = "winapplication";
265 platform = "application";
267 SUIT_MessageBox::warn1(0, QObject::tr("WRN_WARNING"),
268 QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
269 arg(app->resourceMgr()->stringValue("ExternalBrowser", platform)).arg(myHelpFileName),
270 QObject::tr("BUT_OK"));
274 //=================================================================================
275 // function : onSelectionDone()
276 // purpose : SLOT called when selection changed
277 //=================================================================================
278 void SMESHGUI_DeleteGroupDlg::onSelectionDone()
280 if (myBlockSelection)
286 SALOME_ListIO aListIO;
287 mySelectionMgr->selectedObjects(aListIO);
288 SALOME_ListIteratorOfListIO anIter (aListIO);
289 for (; anIter.More(); anIter.Next()) {
290 SMESH::SMESH_GroupBase_var aGroup =
291 SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(anIter.Value());
292 if (!aGroup->_is_nil()) {
293 aNames.append(aGroup->GetName());
294 myListGrp.append(aGroup);
299 myListBox->insertStringList(aNames);
302 //=================================================================================
303 // function : onDeactivate()
304 // purpose : SLOT called when dialog must be deativated
305 //=================================================================================
306 void SMESHGUI_DeleteGroupDlg::onDeactivate()
308 mySelectionMgr->clearFilters();
312 //=================================================================================
313 // function : enterEvent()
314 // purpose : Event filter
315 //=================================================================================
316 void SMESHGUI_DeleteGroupDlg::enterEvent (QEvent*)
318 mySMESHGUI->EmitSignalDeactivateDialog();
320 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
321 aViewWindow->SetSelectionMode(ActorSelection);
322 mySelectionMgr->installFilter(new SMESH_TypeFilter (GROUP));
325 //=================================================================================
326 // function : closeEvent()
328 //=================================================================================
329 void SMESHGUI_DeleteGroupDlg::closeEvent (QCloseEvent*)
334 //=================================================================================
335 // function : keyPressEvent()
337 //=================================================================================
338 void SMESHGUI_DeleteGroupDlg::keyPressEvent( QKeyEvent* e )
340 QDialog::keyPressEvent( e );
341 if ( e->isAccepted() )
344 if ( e->key() == Key_F1 )