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()));
167 // set selection mode
168 mySelectionMgr->installFilter(new SMESH_TypeFilter(GROUP));
169 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
170 aViewWindow->SetSelectionMode(ActorSelection);
176 //=================================================================================
177 // function : isValid()
178 // purpose : Verify validity of input data
179 //=================================================================================
180 bool SMESHGUI_DeleteGroupDlg::isValid()
182 if (myListBox->count() == 0) {
183 QMessageBox::information(SMESHGUI::desktop(), tr("SMESH_INSUFFICIENT_DATA"),
184 tr("NO_SELECTED_GROUPS"), QMessageBox::Ok);
188 return !mySMESHGUI->isActiveStudyLocked();
191 //=================================================================================
192 // function : onApply()
193 // purpose : SLOT called when "Apply" button pressed.
194 //=================================================================================
195 bool SMESHGUI_DeleteGroupDlg::onApply()
200 myBlockSelection = true;
202 QValueList<SMESH::SMESH_GroupBase_var>::iterator anIter;
203 for (anIter = myListGrp.begin(); anIter != myListGrp.end(); ++anIter) {
204 SMESH::SMESH_Mesh_ptr aMesh = (*anIter)->GetMesh();
205 if (!aMesh->_is_nil())
206 aMesh->RemoveGroupWithContents(*anIter);
211 mySelectionMgr->clearSelected();
213 mySMESHGUI->updateObjBrowser(true);
215 myBlockSelection = false;
219 //=================================================================================
221 // purpose : SLOT called when "Ok" button pressed.
222 //=================================================================================
223 void SMESHGUI_DeleteGroupDlg::onOk()
229 //=================================================================================
230 // function : onClose()
231 // purpose : SLOT called when "Close" button pressed. Close dialog
232 //=================================================================================
233 void SMESHGUI_DeleteGroupDlg::onClose()
235 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
236 aViewWindow->SetSelectionMode(ActorSelection);
237 disconnect(mySelectionMgr, 0, this, 0);
238 disconnect(mySMESHGUI, 0, this, 0);
239 mySMESHGUI->ResetState();
240 mySelectionMgr->clearFilters();
244 //=================================================================================
245 // function : onSelectionDone()
246 // purpose : SLOT called when selection changed
247 //=================================================================================
248 void SMESHGUI_DeleteGroupDlg::onSelectionDone()
250 if (myBlockSelection)
256 SALOME_ListIO aListIO;
257 mySelectionMgr->selectedObjects(aListIO);
258 SALOME_ListIteratorOfListIO anIter (aListIO);
259 for (; anIter.More(); anIter.Next()) {
260 SMESH::SMESH_GroupBase_var aGroup =
261 SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(anIter.Value());
262 if (!aGroup->_is_nil()) {
263 aNames.append(aGroup->GetName());
264 myListGrp.append(aGroup);
269 myListBox->insertStringList(aNames);
272 //=================================================================================
273 // function : onDeactivate()
274 // purpose : SLOT called when dialog must be deativated
275 //=================================================================================
276 void SMESHGUI_DeleteGroupDlg::onDeactivate()
278 mySelectionMgr->clearFilters();
282 //=================================================================================
283 // function : enterEvent()
284 // purpose : Event filter
285 //=================================================================================
286 void SMESHGUI_DeleteGroupDlg::enterEvent (QEvent*)
288 mySMESHGUI->EmitSignalDeactivateDialog();
290 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
291 aViewWindow->SetSelectionMode(ActorSelection);
292 mySelectionMgr->installFilter(new SMESH_TypeFilter (GROUP));
295 //=================================================================================
296 // function : closeEvent()
298 //=================================================================================
299 void SMESHGUI_DeleteGroupDlg::closeEvent (QCloseEvent*)