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 // File : SMESHGUI_DeleteGroupDlg.cxx
23 // Author : Sergey LITONIN, Open CASCADE S.A.S.
26 #include "SMESHGUI_DeleteGroupDlg.h"
29 #include "SMESHGUI_Utils.h"
30 #include "SMESHGUI_VTKUtils.h"
32 #include <SMESH_TypeFilter.hxx>
34 // SALOME GUI includes
35 #include <SUIT_Desktop.h>
36 #include <SUIT_Session.h>
37 #include <SUIT_MessageBox.h>
38 #include <SUIT_ResourceMgr.h>
40 #include <SalomeApp_Study.h>
41 #include <LightApp_Application.h>
42 #include <LightApp_SelectionMgr.h>
44 #include <SALOME_ListIO.hxx>
45 #include <SALOME_ListIteratorOfListIO.hxx>
47 #include <SVTK_Selection.h>
48 #include <SVTK_ViewWindow.h>
51 #include <QHBoxLayout>
52 #include <QVBoxLayout>
53 #include <QPushButton>
55 #include <QListWidget>
59 #include <SALOMEconfig.h>
60 #include CORBA_SERVER_HEADER(SMESH_Mesh)
66 * Class : SMESHGUI_DeleteGroupDlg
67 * Description : Delete groups and their contents
70 //=================================================================================
71 // function : SMESHGUI_DeleteGroupDlg()
72 // purpose : Constructor
73 //=================================================================================
74 SMESHGUI_DeleteGroupDlg::SMESHGUI_DeleteGroupDlg (SMESHGUI* theModule):
75 QDialog(SMESH::GetDesktop(theModule)),
76 mySelectionMgr(SMESH::GetSelectionMgr(theModule)),
80 setWindowTitle(tr("CAPTION"));
82 QVBoxLayout* aDlgLay = new QVBoxLayout(this);
83 aDlgLay->setMargin(MARGIN);
84 aDlgLay->setSpacing(SPACING);
86 QWidget* aMainFrame = createMainFrame (this);
87 QWidget* aBtnFrame = createButtonFrame(this);
89 aDlgLay->addWidget(aMainFrame);
90 aDlgLay->addWidget(aBtnFrame);
92 myHelpFileName = "deleting_groups_page.html";
97 //=================================================================================
98 // function : createMainFrame()
99 // purpose : Create frame containing dialog's input fields
100 //=================================================================================
101 QWidget* SMESHGUI_DeleteGroupDlg::createMainFrame (QWidget* theParent)
103 QGroupBox* aMainGrp =
104 new QGroupBox(tr("SELECTED_GROUPS"), theParent);
105 QVBoxLayout* aLay = new QVBoxLayout(aMainGrp);
106 aLay->setMargin(MARGIN);
107 aLay->setSpacing(SPACING);
109 myListBox = new QListWidget(aMainGrp);
110 myListBox->setMinimumSize(150, 100);
111 myListBox->setSelectionMode(QListWidget::NoSelection);
112 //myListBox->setRowMode(QListBox::FitToWidth);
113 myListBox->setFlow(QListWidget::LeftToRight);
114 myListBox->setWrapping(true);
116 aLay->addWidget(myListBox);
121 //=================================================================================
122 // function : createButtonFrame()
123 // purpose : Create frame containing buttons
124 //=================================================================================
125 QWidget* SMESHGUI_DeleteGroupDlg::createButtonFrame (QWidget* theParent)
127 QGroupBox* aFrame = new QGroupBox(theParent);
129 myOkBtn = new QPushButton(tr("SMESH_BUT_APPLY_AND_CLOSE"), aFrame);
130 myApplyBtn = new QPushButton(tr("SMESH_BUT_APPLY"), aFrame);
131 myCloseBtn = new QPushButton(tr("SMESH_BUT_CLOSE"), aFrame);
132 myHelpBtn = new QPushButton(tr("SMESH_BUT_HELP"), aFrame);
134 QHBoxLayout* aLay = new QHBoxLayout(aFrame);
135 aLay->setMargin(MARGIN);
136 aLay->setSpacing(SPACING);
138 aLay->addWidget(myOkBtn);
139 aLay->addSpacing(10);
140 aLay->addWidget(myApplyBtn);
141 aLay->addSpacing(10);
143 aLay->addWidget(myCloseBtn);
144 aLay->addWidget(myHelpBtn);
146 // connect signals and slots
147 connect(myOkBtn, SIGNAL(clicked()), SLOT(onOk()));
148 connect(myCloseBtn, SIGNAL(clicked()), SLOT(onClose()));
149 connect(myApplyBtn, SIGNAL(clicked()), SLOT(onApply()));
150 connect(myHelpBtn, SIGNAL(clicked()), SLOT(onHelp()));
155 //=================================================================================
156 // name : ~SMESHGUI_DeleteGroupDlg()
157 // Purpose : Destructor
158 //=================================================================================
159 SMESHGUI_DeleteGroupDlg::~SMESHGUI_DeleteGroupDlg()
163 //=================================================================================
165 // purpose : Init dialog fields, connect signals and slots, show dialog
166 //=================================================================================
167 void SMESHGUI_DeleteGroupDlg::Init ()
169 myBlockSelection = false;
170 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
172 // selection and SMESHGUI
173 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), SLOT(onSelectionDone()));
174 connect(mySMESHGUI, SIGNAL(SignalDeactivateActiveDialog()), SLOT(onDeactivate()));
175 connect(mySMESHGUI, SIGNAL(SignalCloseAllDialogs()), SLOT(onClose()));
177 // set selection mode
178 mySelectionMgr->installFilter(new SMESH_TypeFilter(GROUP));
179 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
180 aViewWindow->SetSelectionMode(ActorSelection);
184 //=================================================================================
185 // function : isValid()
186 // purpose : Verify validity of input data
187 //=================================================================================
188 bool SMESHGUI_DeleteGroupDlg::isValid()
190 if (myListBox->count() == 0) {
191 SUIT_MessageBox::information(SMESHGUI::desktop(), tr("SMESH_INSUFFICIENT_DATA"),
192 tr("NO_SELECTED_GROUPS"));
196 return !mySMESHGUI->isActiveStudyLocked();
199 //=================================================================================
200 // function : onApply()
201 // purpose : SLOT called when "Apply" button pressed.
202 //=================================================================================
203 bool SMESHGUI_DeleteGroupDlg::onApply()
208 myBlockSelection = true;
210 QList<SMESH::SMESH_GroupBase_var>::iterator anIter;
211 for (anIter = myListGrp.begin(); anIter != myListGrp.end(); ++anIter) {
212 SMESH::SMESH_Mesh_ptr aMesh = (*anIter)->GetMesh();
213 if (!aMesh->_is_nil())
214 aMesh->RemoveGroupWithContents(*anIter);
219 mySelectionMgr->clearSelected();
221 mySMESHGUI->updateObjBrowser(true);
223 myBlockSelection = false;
227 //=================================================================================
229 // purpose : SLOT called when "Ok" button pressed.
230 //=================================================================================
231 void SMESHGUI_DeleteGroupDlg::onOk()
237 //=================================================================================
238 // function : onClose()
239 // purpose : SLOT called when "Close" button pressed. Close dialog
240 //=================================================================================
241 void SMESHGUI_DeleteGroupDlg::onClose()
243 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
244 aViewWindow->SetSelectionMode(ActorSelection);
245 disconnect(mySelectionMgr, 0, this, 0);
246 disconnect(mySMESHGUI, 0, this, 0);
247 mySMESHGUI->ResetState();
248 mySelectionMgr->clearFilters();
252 //=================================================================================
253 // function : onHelp()
255 //=================================================================================
256 void SMESHGUI_DeleteGroupDlg::onHelp()
258 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
260 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
264 platform = "winapplication";
266 platform = "application";
268 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
269 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
270 arg(app->resourceMgr()->stringValue("ExternalBrowser",
272 arg(myHelpFileName));
276 //=================================================================================
277 // function : onSelectionDone()
278 // purpose : SLOT called when selection changed
279 //=================================================================================
280 void SMESHGUI_DeleteGroupDlg::onSelectionDone()
282 if (myBlockSelection)
288 SALOME_ListIO aListIO;
289 mySelectionMgr->selectedObjects(aListIO);
290 SALOME_ListIteratorOfListIO anIter (aListIO);
291 for ( ; anIter.More(); anIter.Next()) {
292 SMESH::SMESH_GroupBase_var aGroup =
293 SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(anIter.Value());
294 if (!aGroup->_is_nil()) {
295 aNames.append(aGroup->GetName());
296 myListGrp.append(aGroup);
301 myListBox->addItems(aNames);
304 //=================================================================================
305 // function : onDeactivate()
306 // purpose : SLOT called when dialog must be deativated
307 //=================================================================================
308 void SMESHGUI_DeleteGroupDlg::onDeactivate()
310 mySelectionMgr->clearFilters();
314 //=================================================================================
315 // function : enterEvent()
316 // purpose : Event filter
317 //=================================================================================
318 void SMESHGUI_DeleteGroupDlg::enterEvent (QEvent*)
320 mySMESHGUI->EmitSignalDeactivateDialog();
322 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
323 aViewWindow->SetSelectionMode(ActorSelection);
324 mySelectionMgr->installFilter(new SMESH_TypeFilter (GROUP));
327 //=================================================================================
328 // function : closeEvent()
330 //=================================================================================
331 void SMESHGUI_DeleteGroupDlg::closeEvent (QCloseEvent*)
336 //=================================================================================
337 // function : keyPressEvent()
339 //=================================================================================
340 void SMESHGUI_DeleteGroupDlg::keyPressEvent( QKeyEvent* e )
342 QDialog::keyPressEvent( e );
343 if ( e->isAccepted() )
346 if ( e->key() == Qt::Key_F1 ) {