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.salome-platform.org/ or email : webmaster.salome@opencascade.com
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"
37 #include "SUIT_Session.h"
38 #include "SUIT_MessageBox.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"
53 #include <qpushbutton.h>
54 #include <qgroupbox.h>
58 #include <qmessagebox.h>
61 #include "SALOMEconfig.h"
62 #include CORBA_SERVER_HEADER(SMESH_Mesh)
68 * Class : SMESHGUI_DeleteGroupDlg
69 * Description : Delete groups and their contents
72 //=================================================================================
73 // function : SMESHGUI_DeleteGroupDlg()
74 // purpose : Constructor
75 //=================================================================================
76 SMESHGUI_DeleteGroupDlg::SMESHGUI_DeleteGroupDlg (SMESHGUI* theModule):
77 QDialog(SMESH::GetDesktop(theModule),
78 "SMESHGUI_DeleteGroupDlg",
80 WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu),
81 mySelectionMgr(SMESH::GetSelectionMgr(theModule)),
84 setCaption(tr("CAPTION"));
86 QVBoxLayout* aDlgLay = new QVBoxLayout(this, MARGIN, SPACING);
88 QFrame* aMainFrame = createMainFrame (this);
89 QFrame* aBtnFrame = createButtonFrame(this);
91 aDlgLay->addWidget(aMainFrame);
92 aDlgLay->addWidget(aBtnFrame);
94 aDlgLay->setStretchFactor(aMainFrame, 1);
96 myHelpFileName = "deleting_groups_page.html";
101 //=================================================================================
102 // function : createMainFrame()
103 // purpose : Create frame containing dialog's input fields
104 //=================================================================================
105 QFrame* SMESHGUI_DeleteGroupDlg::createMainFrame (QWidget* theParent)
107 QGroupBox* aMainGrp =
108 new QGroupBox(1, Qt::Horizontal, tr("SELECTED_GROUPS"), theParent);
110 myListBox = new QListBox(aMainGrp);
111 myListBox->setMinimumHeight(100);
112 myListBox->setSelectionMode(QListBox::NoSelection);
113 myListBox->setRowMode(QListBox::FitToWidth);
118 //=================================================================================
119 // function : createButtonFrame()
120 // purpose : Create frame containing buttons
121 //=================================================================================
122 QFrame* SMESHGUI_DeleteGroupDlg::createButtonFrame (QWidget* theParent)
124 QFrame* aFrame = new QFrame(theParent);
125 aFrame->setFrameStyle(QFrame::Box | QFrame::Sunken);
127 myOkBtn = new QPushButton(tr("SMESH_BUT_OK" ), aFrame);
128 myApplyBtn = new QPushButton(tr("SMESH_BUT_APPLY"), aFrame);
129 myCloseBtn = new QPushButton(tr("SMESH_BUT_CLOSE"), aFrame);
130 myHelpBtn = new QPushButton(tr("SMESH_BUT_HELP"), aFrame);
132 QSpacerItem* aSpacer = new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum);
134 QHBoxLayout* aLay = new QHBoxLayout(aFrame, MARGIN, SPACING);
136 aLay->addWidget(myOkBtn);
137 aLay->addWidget(myApplyBtn);
138 aLay->addItem(aSpacer);
139 aLay->addWidget(myCloseBtn);
140 aLay->addWidget(myHelpBtn);
142 // connect signals and slots
143 connect(myOkBtn, SIGNAL(clicked()), SLOT(onOk()));
144 connect(myCloseBtn, SIGNAL(clicked()), SLOT(onClose()));
145 connect(myApplyBtn, SIGNAL(clicked()), SLOT(onApply()));
146 connect(myHelpBtn, SIGNAL(clicked()), SLOT(onHelp()));
151 //=================================================================================
152 // name : ~SMESHGUI_DeleteGroupDlg()
153 // Purpose : Destructor
154 //=================================================================================
155 SMESHGUI_DeleteGroupDlg::~SMESHGUI_DeleteGroupDlg()
159 //=================================================================================
161 // purpose : Init dialog fields, connect signals and slots, show dialog
162 //=================================================================================
163 void SMESHGUI_DeleteGroupDlg::Init ()
165 myBlockSelection = false;
166 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
168 // selection and SMESHGUI
169 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), SLOT(onSelectionDone()));
170 connect(mySMESHGUI, SIGNAL(SignalDeactivateActiveDialog()), SLOT(onDeactivate()));
171 connect(mySMESHGUI, SIGNAL(SignalCloseAllDialogs()), SLOT(onClose()));
175 // set selection mode
176 mySelectionMgr->installFilter(new SMESH_TypeFilter(GROUP));
177 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
178 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 QMessageBox::information(SMESHGUI::desktop(), tr("SMESH_INSUFFICIENT_DATA"),
192 tr("NO_SELECTED_GROUPS"), QMessageBox::Ok);
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 QValueList<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::warn1(0, QObject::tr("WRN_WARNING"),
269 QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
270 arg(app->resourceMgr()->stringValue("ExternalBrowser", platform)).arg(myHelpFileName),
271 QObject::tr("BUT_OK"));
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->insertStringList(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() == Key_F1 )