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 "LightApp_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)),
81 setCaption(tr("CAPTION"));
83 QVBoxLayout* aDlgLay = new QVBoxLayout(this, MARGIN, SPACING);
85 QFrame* aMainFrame = createMainFrame (this);
86 QFrame* aBtnFrame = createButtonFrame(this);
88 aDlgLay->addWidget(aMainFrame);
89 aDlgLay->addWidget(aBtnFrame);
91 aDlgLay->setStretchFactor(aMainFrame, 1);
96 //=================================================================================
97 // function : createMainFrame()
98 // purpose : Create frame containing dialog's input fields
99 //=================================================================================
100 QFrame* SMESHGUI_DeleteGroupDlg::createMainFrame (QWidget* theParent)
102 QGroupBox* aMainGrp =
103 new QGroupBox(1, Qt::Horizontal, tr("SELECTED_GROUPS"), theParent);
105 myListBox = new QListBox(aMainGrp);
106 myListBox->setMinimumHeight(100);
107 myListBox->setSelectionMode(QListBox::NoSelection);
108 myListBox->setRowMode(QListBox::FitToWidth);
113 //=================================================================================
114 // function : createButtonFrame()
115 // purpose : Create frame containing buttons
116 //=================================================================================
117 QFrame* SMESHGUI_DeleteGroupDlg::createButtonFrame (QWidget* theParent)
119 QFrame* aFrame = new QFrame(theParent);
120 aFrame->setFrameStyle(QFrame::Box | QFrame::Sunken);
122 myOkBtn = new QPushButton(tr("SMESH_BUT_OK" ), aFrame);
123 myApplyBtn = new QPushButton(tr("SMESH_BUT_APPLY"), aFrame);
124 myCloseBtn = new QPushButton(tr("SMESH_BUT_CLOSE"), aFrame);
126 QSpacerItem* aSpacer = new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum);
128 QHBoxLayout* aLay = new QHBoxLayout(aFrame, MARGIN, SPACING);
130 aLay->addWidget(myOkBtn);
131 aLay->addWidget(myApplyBtn);
132 aLay->addItem(aSpacer);
133 aLay->addWidget(myCloseBtn);
135 // connect signals and slots
136 connect(myOkBtn, SIGNAL(clicked()), SLOT(onOk()));
137 connect(myCloseBtn, SIGNAL(clicked()), SLOT(onClose()));
138 connect(myApplyBtn, SIGNAL(clicked()), SLOT(onApply()));
143 //=================================================================================
144 // name : ~SMESHGUI_DeleteGroupDlg()
145 // Purpose : Destructor
146 //=================================================================================
147 SMESHGUI_DeleteGroupDlg::~SMESHGUI_DeleteGroupDlg()
151 //=================================================================================
153 // purpose : Init dialog fields, connect signals and slots, show dialog
154 //=================================================================================
155 void SMESHGUI_DeleteGroupDlg::Init ()
157 myBlockSelection = false;
158 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
160 // selection and SMESHGUI
161 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), SLOT(onSelectionDone()));
162 connect(mySMESHGUI, SIGNAL(SignalDeactivateActiveDialog()), SLOT(onDeactivate()));
163 connect(mySMESHGUI, SIGNAL(SignalCloseAllDialogs()), SLOT(onClose()));
166 mySMESHGUI->DefineDlgPosition(this, x, y);
170 // set selection mode
171 mySelectionMgr->installFilter(new SMESH_TypeFilter(GROUP));
172 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
173 aViewWindow->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 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
239 aViewWindow->SetSelectionMode(ActorSelection);
240 disconnect(mySelectionMgr, 0, this, 0);
241 disconnect(mySMESHGUI, 0, this, 0);
242 mySMESHGUI->ResetState();
243 mySelectionMgr->clearFilters();
247 //=================================================================================
248 // function : onSelectionDone()
249 // purpose : SLOT called when selection changed
250 //=================================================================================
251 void SMESHGUI_DeleteGroupDlg::onSelectionDone()
253 if (myBlockSelection)
259 SALOME_ListIO aListIO;
260 mySelectionMgr->selectedObjects(aListIO);
261 SALOME_ListIteratorOfListIO anIter (aListIO);
262 for (; anIter.More(); anIter.Next()) {
263 SMESH::SMESH_GroupBase_var aGroup =
264 SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(anIter.Value());
265 if (!aGroup->_is_nil()) {
266 aNames.append(aGroup->GetName());
267 myListGrp.append(aGroup);
272 myListBox->insertStringList(aNames);
275 //=================================================================================
276 // function : onDeactivate()
277 // purpose : SLOT called when dialog must be deativated
278 //=================================================================================
279 void SMESHGUI_DeleteGroupDlg::onDeactivate()
281 mySelectionMgr->clearFilters();
285 //=================================================================================
286 // function : enterEvent()
287 // purpose : Event filter
288 //=================================================================================
289 void SMESHGUI_DeleteGroupDlg::enterEvent (QEvent*)
291 mySMESHGUI->EmitSignalDeactivateDialog();
293 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
294 aViewWindow->SetSelectionMode(ActorSelection);
295 mySelectionMgr->installFilter(new SMESH_TypeFilter (GROUP));
298 //=================================================================================
299 // function : closeEvent()
301 //=================================================================================
302 void SMESHGUI_DeleteGroupDlg::closeEvent (QCloseEvent*)