1 // Copyright (C) 2007-2015 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, or (at your option) any later version.
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
23 // File : SMESHGUI_DeleteGroupDlg.cxx
24 // Author : Sergey LITONIN, Open CASCADE S.A.S.
27 #include "SMESHGUI_DeleteGroupDlg.h"
30 #include "SMESHGUI_Utils.h"
31 #include "SMESHGUI_VTKUtils.h"
33 #include <SMESH_TypeFilter.hxx>
35 // SALOME GUI includes
36 #include <SUIT_Desktop.h>
37 #include <SUIT_Session.h>
38 #include <SUIT_MessageBox.h>
39 #include <SUIT_ResourceMgr.h>
41 #include <SalomeApp_Study.h>
42 #include <LightApp_Application.h>
43 #include <LightApp_SelectionMgr.h>
45 #include <SALOME_ListIO.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(reject()));
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(reject()));
177 // set selection mode
178 mySelectionMgr->installFilter(new SMESH_TypeFilter(SMESH::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_var aMesh = (*anIter)->GetMesh();
213 if (!aMesh->_is_nil())
214 aMesh->RemoveGroupWithContents(*anIter);
219 mySelectionMgr->clearSelected();
221 /** Erase graphical objects **/
222 SALOME_ListIteratorOfListIO anIterIO (myListGrpIO);
223 for ( ; anIterIO.More(); anIterIO.Next())
224 SMESH::RemoveVisualObjectWithActors( anIterIO.Value()->getEntry(), /*fromAllViews=*/true );
227 SMESHGUI::Modified();
228 mySMESHGUI->updateObjBrowser(true);
230 myBlockSelection = false;
234 //=================================================================================
236 // purpose : SLOT called when "Ok" button pressed.
237 //=================================================================================
238 void SMESHGUI_DeleteGroupDlg::onOk()
244 //=================================================================================
245 // function : reject()
246 // purpose : SLOT called when "Close" button pressed. Close dialog
247 //=================================================================================
248 void SMESHGUI_DeleteGroupDlg::reject()
250 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
251 aViewWindow->SetSelectionMode(ActorSelection);
252 disconnect(mySelectionMgr, 0, this, 0);
253 disconnect(mySMESHGUI, 0, this, 0);
254 mySMESHGUI->ResetState();
255 mySelectionMgr->clearFilters();
259 //=================================================================================
260 // function : onHelp()
262 //=================================================================================
263 void SMESHGUI_DeleteGroupDlg::onHelp()
265 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
267 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
271 platform = "winapplication";
273 platform = "application";
275 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
276 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
277 arg(app->resourceMgr()->stringValue("ExternalBrowser",
279 arg(myHelpFileName));
283 //=================================================================================
284 // function : onSelectionDone()
285 // purpose : SLOT called when selection changed
286 //=================================================================================
287 void SMESHGUI_DeleteGroupDlg::onSelectionDone()
289 if (myBlockSelection)
296 SALOME_ListIO aListIO;
297 mySelectionMgr->selectedObjects(aListIO);
298 SALOME_ListIteratorOfListIO anIter (aListIO);
299 for ( ; anIter.More(); anIter.Next()) {
300 SMESH::SMESH_GroupBase_var aGroup =
301 SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(anIter.Value());
302 if (!aGroup->_is_nil()) {
303 aNames.append(aGroup->GetName());
304 myListGrp.append(aGroup);
305 myListGrpIO.Append( anIter.Value() );
310 myListBox->addItems(aNames);
313 //=================================================================================
314 // function : onDeactivate()
315 // purpose : SLOT called when dialog must be deativated
316 //=================================================================================
317 void SMESHGUI_DeleteGroupDlg::onDeactivate()
319 mySelectionMgr->clearFilters();
323 //=================================================================================
324 // function : enterEvent()
325 // purpose : Event filter
326 //=================================================================================
327 void SMESHGUI_DeleteGroupDlg::enterEvent (QEvent*)
329 mySMESHGUI->EmitSignalDeactivateDialog();
331 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
332 aViewWindow->SetSelectionMode(ActorSelection);
333 mySelectionMgr->installFilter(new SMESH_TypeFilter (SMESH::GROUP));
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 ) {