1 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License.
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 // File : SMESHGUI_DeleteGroupDlg.cxx
21 // Author : Sergey LITONIN, Open CASCADE S.A.S.
25 #include "SMESHGUI_DeleteGroupDlg.h"
28 #include "SMESHGUI_Utils.h"
29 #include "SMESHGUI_VTKUtils.h"
31 #include <SMESH_TypeFilter.hxx>
33 // SALOME GUI includes
34 #include <SUIT_Desktop.h>
35 #include <SUIT_Session.h>
36 #include <SUIT_MessageBox.h>
37 #include <SUIT_ResourceMgr.h>
39 #include <SalomeApp_Study.h>
40 #include <LightApp_Application.h>
41 #include <LightApp_SelectionMgr.h>
43 #include <SALOME_ListIO.hxx>
44 #include <SALOME_ListIteratorOfListIO.hxx>
46 #include <SVTK_Selection.h>
47 #include <SVTK_ViewWindow.h>
50 #include <QHBoxLayout>
51 #include <QVBoxLayout>
52 #include <QPushButton>
54 #include <QListWidget>
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 mySelectionMgr(SMESH::GetSelectionMgr(theModule)),
79 setWindowTitle(tr("CAPTION"));
81 QVBoxLayout* aDlgLay = new QVBoxLayout(this);
82 aDlgLay->setMargin(MARGIN);
83 aDlgLay->setSpacing(SPACING);
85 QWidget* aMainFrame = createMainFrame (this);
86 QWidget* aBtnFrame = createButtonFrame(this);
88 aDlgLay->addWidget(aMainFrame);
89 aDlgLay->addWidget(aBtnFrame);
91 myHelpFileName = "deleting_groups_page.html";
96 //=================================================================================
97 // function : createMainFrame()
98 // purpose : Create frame containing dialog's input fields
99 //=================================================================================
100 QWidget* SMESHGUI_DeleteGroupDlg::createMainFrame (QWidget* theParent)
102 QGroupBox* aMainGrp =
103 new QGroupBox(tr("SELECTED_GROUPS"), theParent);
104 QVBoxLayout* aLay = new QVBoxLayout(aMainGrp);
105 aLay->setMargin(MARGIN);
106 aLay->setSpacing(SPACING);
108 myListBox = new QListWidget(aMainGrp);
109 myListBox->setMinimumSize(150, 100);
110 myListBox->setSelectionMode(QListWidget::NoSelection);
111 //myListBox->setRowMode(QListBox::FitToWidth);
112 myListBox->setFlow(QListWidget::LeftToRight);
113 myListBox->setWrapping(true);
115 aLay->addWidget(myListBox);
120 //=================================================================================
121 // function : createButtonFrame()
122 // purpose : Create frame containing buttons
123 //=================================================================================
124 QWidget* SMESHGUI_DeleteGroupDlg::createButtonFrame (QWidget* theParent)
126 QGroupBox* aFrame = new QGroupBox(theParent);
128 myOkBtn = new QPushButton(tr("SMESH_BUT_APPLY_AND_CLOSE"), aFrame);
129 myApplyBtn = new QPushButton(tr("SMESH_BUT_APPLY"), aFrame);
130 myCloseBtn = new QPushButton(tr("SMESH_BUT_CLOSE"), aFrame);
131 myHelpBtn = new QPushButton(tr("SMESH_BUT_HELP"), aFrame);
133 QHBoxLayout* aLay = new QHBoxLayout(aFrame);
134 aLay->setMargin(MARGIN);
135 aLay->setSpacing(SPACING);
137 aLay->addWidget(myOkBtn);
138 aLay->addSpacing(10);
139 aLay->addWidget(myApplyBtn);
140 aLay->addSpacing(10);
142 aLay->addWidget(myCloseBtn);
143 aLay->addWidget(myHelpBtn);
145 // connect signals and slots
146 connect(myOkBtn, SIGNAL(clicked()), SLOT(onOk()));
147 connect(myCloseBtn, SIGNAL(clicked()), SLOT(onClose()));
148 connect(myApplyBtn, SIGNAL(clicked()), SLOT(onApply()));
149 connect(myHelpBtn, SIGNAL(clicked()), SLOT(onHelp()));
154 //=================================================================================
155 // name : ~SMESHGUI_DeleteGroupDlg()
156 // Purpose : Destructor
157 //=================================================================================
158 SMESHGUI_DeleteGroupDlg::~SMESHGUI_DeleteGroupDlg()
162 //=================================================================================
164 // purpose : Init dialog fields, connect signals and slots, show dialog
165 //=================================================================================
166 void SMESHGUI_DeleteGroupDlg::Init ()
168 myBlockSelection = false;
169 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
171 // selection and SMESHGUI
172 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), SLOT(onSelectionDone()));
173 connect(mySMESHGUI, SIGNAL(SignalDeactivateActiveDialog()), SLOT(onDeactivate()));
174 connect(mySMESHGUI, SIGNAL(SignalCloseAllDialogs()), SLOT(onClose()));
176 // set selection mode
177 mySelectionMgr->installFilter(new SMESH_TypeFilter(GROUP));
178 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
179 aViewWindow->SetSelectionMode(ActorSelection);
183 //=================================================================================
184 // function : isValid()
185 // purpose : Verify validity of input data
186 //=================================================================================
187 bool SMESHGUI_DeleteGroupDlg::isValid()
189 if (myListBox->count() == 0) {
190 SUIT_MessageBox::information(SMESHGUI::desktop(), tr("SMESH_INSUFFICIENT_DATA"),
191 tr("NO_SELECTED_GROUPS"));
195 return !mySMESHGUI->isActiveStudyLocked();
198 //=================================================================================
199 // function : onApply()
200 // purpose : SLOT called when "Apply" button pressed.
201 //=================================================================================
202 bool SMESHGUI_DeleteGroupDlg::onApply()
207 myBlockSelection = true;
209 QList<SMESH::SMESH_GroupBase_var>::iterator anIter;
210 for (anIter = myListGrp.begin(); anIter != myListGrp.end(); ++anIter) {
211 SMESH::SMESH_Mesh_ptr aMesh = (*anIter)->GetMesh();
212 if (!aMesh->_is_nil())
213 aMesh->RemoveGroupWithContents(*anIter);
218 mySelectionMgr->clearSelected();
220 mySMESHGUI->updateObjBrowser(true);
222 myBlockSelection = false;
226 //=================================================================================
228 // purpose : SLOT called when "Ok" button pressed.
229 //=================================================================================
230 void SMESHGUI_DeleteGroupDlg::onOk()
236 //=================================================================================
237 // function : onClose()
238 // purpose : SLOT called when "Close" button pressed. Close dialog
239 //=================================================================================
240 void SMESHGUI_DeleteGroupDlg::onClose()
242 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
243 aViewWindow->SetSelectionMode(ActorSelection);
244 disconnect(mySelectionMgr, 0, this, 0);
245 disconnect(mySMESHGUI, 0, this, 0);
246 mySMESHGUI->ResetState();
247 mySelectionMgr->clearFilters();
251 //=================================================================================
252 // function : onHelp()
254 //=================================================================================
255 void SMESHGUI_DeleteGroupDlg::onHelp()
257 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
259 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
263 platform = "winapplication";
265 platform = "application";
267 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
268 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
269 arg(app->resourceMgr()->stringValue("ExternalBrowser",
271 arg(myHelpFileName));
275 //=================================================================================
276 // function : onSelectionDone()
277 // purpose : SLOT called when selection changed
278 //=================================================================================
279 void SMESHGUI_DeleteGroupDlg::onSelectionDone()
281 if (myBlockSelection)
287 SALOME_ListIO aListIO;
288 mySelectionMgr->selectedObjects(aListIO);
289 SALOME_ListIteratorOfListIO anIter (aListIO);
290 for ( ; anIter.More(); anIter.Next()) {
291 SMESH::SMESH_GroupBase_var aGroup =
292 SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(anIter.Value());
293 if (!aGroup->_is_nil()) {
294 aNames.append(aGroup->GetName());
295 myListGrp.append(aGroup);
300 myListBox->addItems(aNames);
303 //=================================================================================
304 // function : onDeactivate()
305 // purpose : SLOT called when dialog must be deativated
306 //=================================================================================
307 void SMESHGUI_DeleteGroupDlg::onDeactivate()
309 mySelectionMgr->clearFilters();
313 //=================================================================================
314 // function : enterEvent()
315 // purpose : Event filter
316 //=================================================================================
317 void SMESHGUI_DeleteGroupDlg::enterEvent (QEvent*)
319 mySMESHGUI->EmitSignalDeactivateDialog();
321 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
322 aViewWindow->SetSelectionMode(ActorSelection);
323 mySelectionMgr->installFilter(new SMESH_TypeFilter (GROUP));
326 //=================================================================================
327 // function : closeEvent()
329 //=================================================================================
330 void SMESHGUI_DeleteGroupDlg::closeEvent (QCloseEvent*)
335 //=================================================================================
336 // function : keyPressEvent()
338 //=================================================================================
339 void SMESHGUI_DeleteGroupDlg::keyPressEvent( QKeyEvent* e )
341 QDialog::keyPressEvent( e );
342 if ( e->isAccepted() )
345 if ( e->key() == Qt::Key_F1 ) {