1 // SMESH SMESHGUI : GUI for SMESH component
3 // Copyright (C) 2003 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : SMESHGUI_DeleteGroupDlg.cxx
25 // Author : Sergey LITONIN
28 #include "SMESHGUI_DeleteGroupDlg.h"
31 #include "SMESHGUI_Utils.h"
32 #include "SMESHGUI_VTKUtils.h"
34 #include "SMESH_TypeFilter.hxx"
36 #include "SUIT_Desktop.h"
38 #include "SalomeApp_Study.h"
39 #include "SalomeApp_SelectionMgr.h"
41 #include "SVTK_Selection.h"
42 #include "SALOME_ListIO.hxx"
43 #include "SALOME_ListIteratorOfListIO.hxx"
48 #include <qpushbutton.h>
49 #include <qgroupbox.h>
53 #include <qmessagebox.h>
56 #include "SALOMEconfig.h"
57 #include CORBA_SERVER_HEADER(SMESH_Mesh)
63 * Class : SMESHGUI_DeleteGroupDlg
64 * Description : Delete groups and their contents
67 //=================================================================================
68 // function : SMESHGUI_DeleteGroupDlg()
69 // purpose : Constructor
70 //=================================================================================
71 SMESHGUI_DeleteGroupDlg::SMESHGUI_DeleteGroupDlg (QWidget* theParent,
72 SalomeApp_SelectionMgr* theSelection)
73 : QDialog(theParent, "SMESHGUI_DeleteGroupDlg", false,
74 WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
76 setCaption(tr("CAPTION"));
78 QVBoxLayout* aDlgLay = new QVBoxLayout(this, MARGIN, SPACING);
80 QFrame* aMainFrame = createMainFrame (this);
81 QFrame* aBtnFrame = createButtonFrame(this);
83 aDlgLay->addWidget(aMainFrame);
84 aDlgLay->addWidget(aBtnFrame);
86 aDlgLay->setStretchFactor(aMainFrame, 1);
91 //=================================================================================
92 // function : createMainFrame()
93 // purpose : Create frame containing dialog's input fields
94 //=================================================================================
95 QFrame* SMESHGUI_DeleteGroupDlg::createMainFrame (QWidget* theParent)
98 new QGroupBox(1, Qt::Horizontal, tr("SELECTED_GROUPS"), theParent);
100 myListBox = new QListBox(aMainGrp);
101 myListBox->setMinimumHeight(100);
102 myListBox->setSelectionMode(QListBox::NoSelection);
103 myListBox->setRowMode(QListBox::FitToWidth);
108 //=================================================================================
109 // function : createButtonFrame()
110 // purpose : Create frame containing buttons
111 //=================================================================================
112 QFrame* SMESHGUI_DeleteGroupDlg::createButtonFrame (QWidget* theParent)
114 QFrame* aFrame = new QFrame(theParent);
115 aFrame->setFrameStyle(QFrame::Box | QFrame::Sunken);
117 myOkBtn = new QPushButton(tr("SMESH_BUT_OK" ), aFrame);
118 myApplyBtn = new QPushButton(tr("SMESH_BUT_APPLY"), aFrame);
119 myCloseBtn = new QPushButton(tr("SMESH_BUT_CLOSE"), aFrame);
121 QSpacerItem* aSpacer = new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum);
123 QHBoxLayout* aLay = new QHBoxLayout(aFrame, MARGIN, SPACING);
125 aLay->addWidget(myOkBtn);
126 aLay->addWidget(myApplyBtn);
127 aLay->addItem(aSpacer);
128 aLay->addWidget(myCloseBtn);
130 // connect signals and slots
131 connect(myOkBtn, SIGNAL(clicked()), SLOT(onOk()));
132 connect(myCloseBtn, SIGNAL(clicked()), SLOT(onClose()));
133 connect(myApplyBtn, SIGNAL(clicked()), SLOT(onApply()));
138 //=================================================================================
139 // name : ~SMESHGUI_DeleteGroupDlg()
140 // Purpose : Destructor
141 //=================================================================================
142 SMESHGUI_DeleteGroupDlg::~SMESHGUI_DeleteGroupDlg()
146 //=================================================================================
148 // purpose : Init dialog fields, connect signals and slots, show dialog
149 //=================================================================================
150 void SMESHGUI_DeleteGroupDlg::Init (SalomeApp_SelectionMgr* theSelection)
152 myBlockSelection = false;
153 mySelectionMgr = theSelection;
154 SMESHGUI* aSMESHGUI = SMESHGUI::GetSMESHGUI();
155 aSMESHGUI->SetActiveDialogBox((QDialog*)this);
157 // selection and SMESHGUI
158 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), SLOT(onSelectionDone()));
159 connect(aSMESHGUI, SIGNAL(SignalDeactivateActiveDialog()), SLOT(onDeactivate()));
160 connect(aSMESHGUI, SIGNAL(SignalCloseAllDialogs()), SLOT(onClose()));
163 aSMESHGUI->DefineDlgPosition(this, x, y);
167 // set selection mode
169 mySelectionMgr->setSelectionModes(ActorSelection, true);
171 mySelectionMgr->setSelectionModes(ActorSelection);
173 mySelectionMgr->installFilter(new SMESH_TypeFilter(GROUP));
179 //=================================================================================
180 // function : isValid()
181 // purpose : Verify validity of input data
182 //=================================================================================
183 bool SMESHGUI_DeleteGroupDlg::isValid()
185 if (myListBox->count() == 0) {
186 QMessageBox::information(SMESHGUI::desktop(), tr("SMESH_INSUFFICIENT_DATA"),
187 tr("NO_SELECTED_GROUPS"), QMessageBox::Ok);
191 return !SMESHGUI::GetSMESHGUI()->isActiveStudyLocked();
194 //=================================================================================
195 // function : onApply()
196 // purpose : SLOT called when "Apply" button pressed.
197 //=================================================================================
198 bool SMESHGUI_DeleteGroupDlg::onApply()
203 myBlockSelection = true;
205 QValueList<SMESH::SMESH_GroupBase_var>::iterator anIter;
206 for (anIter = myListGrp.begin(); anIter != myListGrp.end(); ++anIter) {
207 SMESH::SMESH_Mesh_ptr aMesh = (*anIter)->GetMesh();
208 if (!aMesh->_is_nil())
209 aMesh->RemoveGroupWithContents(*anIter);
214 mySelectionMgr->clearSelected();
216 SMESHGUI::GetSMESHGUI()->updateObjBrowser(true);
218 myBlockSelection = false;
222 //=================================================================================
224 // purpose : SLOT called when "Ok" button pressed.
225 //=================================================================================
226 void SMESHGUI_DeleteGroupDlg::onOk()
232 //=================================================================================
233 // function : onClose()
234 // purpose : SLOT called when "Close" button pressed. Close dialog
235 //=================================================================================
236 void SMESHGUI_DeleteGroupDlg::onClose()
238 mySelectionMgr->setSelectionModes(ActorSelection);
239 disconnect(mySelectionMgr, 0, this, 0);
240 disconnect(SMESHGUI::GetSMESHGUI(), 0, this, 0);
241 SMESHGUI::GetSMESHGUI()->ResetState();
242 mySelectionMgr->clearFilters();
246 //=================================================================================
247 // function : onSelectionDone()
248 // purpose : SLOT called when selection changed
249 //=================================================================================
250 void SMESHGUI_DeleteGroupDlg::onSelectionDone()
252 if (myBlockSelection)
258 SALOME_ListIO aListIO;
259 mySelectionMgr->selectedObjects(aListIO);
260 SALOME_ListIteratorOfListIO anIter (aListIO);
261 for (; anIter.More(); anIter.Next()) {
262 SMESH::SMESH_GroupBase_var aGroup =
263 SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(anIter.Value());
264 if (!aGroup->_is_nil()) {
265 aNames.append(aGroup->GetName());
266 myListGrp.append(aGroup);
271 myListBox->insertStringList(aNames);
274 //=================================================================================
275 // function : onDeactivate()
276 // purpose : SLOT called when dialog must be deativated
277 //=================================================================================
278 void SMESHGUI_DeleteGroupDlg::onDeactivate()
280 mySelectionMgr->clearFilters();
284 //=================================================================================
285 // function : enterEvent()
286 // purpose : Event filter
287 //=================================================================================
288 void SMESHGUI_DeleteGroupDlg::enterEvent (QEvent*)
290 SMESHGUI::GetSMESHGUI()->EmitSignalDeactivateDialog();
293 mySelectionMgr->setSelectionModes(ActorSelection, true);
295 mySelectionMgr->setSelectionModes(ActorSelection);
297 mySelectionMgr->installFilter(new SMESH_TypeFilter (GROUP));
300 //=================================================================================
301 // function : closeEvent()
303 //=================================================================================
304 void SMESHGUI_DeleteGroupDlg::closeEvent (QCloseEvent*)