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 "SALOME_ListIO.hxx"
42 #include "SALOME_ListIteratorOfListIO.hxx"
44 #include "SVTK_Selection.h"
45 #include "SVTK_ViewWindow.h"
50 #include <qpushbutton.h>
51 #include <qgroupbox.h>
55 #include <qmessagebox.h>
58 #include "SALOMEconfig.h"
59 #include CORBA_SERVER_HEADER(SMESH_Mesh)
65 * Class : SMESHGUI_DeleteGroupDlg
66 * Description : Delete groups and their contents
69 //=================================================================================
70 // function : SMESHGUI_DeleteGroupDlg()
71 // purpose : Constructor
72 //=================================================================================
73 SMESHGUI_DeleteGroupDlg::SMESHGUI_DeleteGroupDlg (SMESHGUI* theModule):
74 QDialog(SMESH::GetDesktop(theModule),
75 "SMESHGUI_DeleteGroupDlg",
77 WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu),
78 mySelectionMgr(SMESH::GetSelectionMgr(theModule)),
79 myViewWindow(SMESH::GetViewWindow(mySMESHGUI)),
82 setCaption(tr("CAPTION"));
84 QVBoxLayout* aDlgLay = new QVBoxLayout(this, MARGIN, SPACING);
86 QFrame* aMainFrame = createMainFrame (this);
87 QFrame* aBtnFrame = createButtonFrame(this);
89 aDlgLay->addWidget(aMainFrame);
90 aDlgLay->addWidget(aBtnFrame);
92 aDlgLay->setStretchFactor(aMainFrame, 1);
97 //=================================================================================
98 // function : createMainFrame()
99 // purpose : Create frame containing dialog's input fields
100 //=================================================================================
101 QFrame* SMESHGUI_DeleteGroupDlg::createMainFrame (QWidget* theParent)
103 QGroupBox* aMainGrp =
104 new QGroupBox(1, Qt::Horizontal, tr("SELECTED_GROUPS"), theParent);
106 myListBox = new QListBox(aMainGrp);
107 myListBox->setMinimumHeight(100);
108 myListBox->setSelectionMode(QListBox::NoSelection);
109 myListBox->setRowMode(QListBox::FitToWidth);
114 //=================================================================================
115 // function : createButtonFrame()
116 // purpose : Create frame containing buttons
117 //=================================================================================
118 QFrame* SMESHGUI_DeleteGroupDlg::createButtonFrame (QWidget* theParent)
120 QFrame* aFrame = new QFrame(theParent);
121 aFrame->setFrameStyle(QFrame::Box | QFrame::Sunken);
123 myOkBtn = new QPushButton(tr("SMESH_BUT_OK" ), aFrame);
124 myApplyBtn = new QPushButton(tr("SMESH_BUT_APPLY"), aFrame);
125 myCloseBtn = new QPushButton(tr("SMESH_BUT_CLOSE"), aFrame);
127 QSpacerItem* aSpacer = new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum);
129 QHBoxLayout* aLay = new QHBoxLayout(aFrame, MARGIN, SPACING);
131 aLay->addWidget(myOkBtn);
132 aLay->addWidget(myApplyBtn);
133 aLay->addItem(aSpacer);
134 aLay->addWidget(myCloseBtn);
136 // connect signals and slots
137 connect(myOkBtn, SIGNAL(clicked()), SLOT(onOk()));
138 connect(myCloseBtn, SIGNAL(clicked()), SLOT(onClose()));
139 connect(myApplyBtn, SIGNAL(clicked()), SLOT(onApply()));
144 //=================================================================================
145 // name : ~SMESHGUI_DeleteGroupDlg()
146 // Purpose : Destructor
147 //=================================================================================
148 SMESHGUI_DeleteGroupDlg::~SMESHGUI_DeleteGroupDlg()
152 //=================================================================================
154 // purpose : Init dialog fields, connect signals and slots, show dialog
155 //=================================================================================
156 void SMESHGUI_DeleteGroupDlg::Init ()
158 myBlockSelection = false;
159 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
161 // selection and SMESHGUI
162 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), SLOT(onSelectionDone()));
163 connect(mySMESHGUI, SIGNAL(SignalDeactivateActiveDialog()), SLOT(onDeactivate()));
164 connect(mySMESHGUI, SIGNAL(SignalCloseAllDialogs()), SLOT(onClose()));
167 mySMESHGUI->DefineDlgPosition(this, x, y);
171 // set selection mode
172 mySelectionMgr->installFilter(new SMESH_TypeFilter(GROUP));
173 myViewWindow->SetSelectionMode(ActorSelection);
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 !mySMESHGUI->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 mySMESHGUI->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 myViewWindow->SetSelectionMode(ActorSelection);
239 disconnect(mySelectionMgr, 0, this, 0);
240 disconnect(mySMESHGUI, 0, this, 0);
241 mySMESHGUI->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 mySMESHGUI->EmitSignalDeactivateDialog();
292 myViewWindow->SetSelectionMode(ActorSelection);
293 mySelectionMgr->installFilter(new SMESH_TypeFilter (GROUP));
296 //=================================================================================
297 // function : closeEvent()
299 //=================================================================================
300 void SMESHGUI_DeleteGroupDlg::closeEvent (QCloseEvent*)