feature magic defaults to 1 now
[engrid.git] / src / libengrid / guiselectboundarycodes.cpp
blobbf31d7443a22a82d15852e83e6e838afa6e9e94e
1 //
2 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 // + +
4 // + This file is part of enGrid. +
5 // + +
6 // + Copyright 2008-2013 enGits GmbH +
7 // + +
8 // + enGrid is free software: you can redistribute it and/or modify +
9 // + it under the terms of the GNU General Public License as published by +
10 // + the Free Software Foundation, either version 3 of the License, or +
11 // + (at your option) any later version. +
12 // + +
13 // + enGrid is distributed in the hope that it will be useful, +
14 // + but WITHOUT ANY WARRANTY; without even the implied warranty of +
15 // + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +
16 // + GNU General Public License for more details. +
17 // + +
18 // + You should have received a copy of the GNU General Public License +
19 // + along with enGrid. If not, see <http://www.gnu.org/licenses/>. +
20 // + +
21 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
22 //
23 #include "guiselectboundarycodes.h"
24 #include <vtkIntArray.h>
25 #include <vtkCellData.h>
27 #include "guimainwindow.h"
29 GuiSelectBoundaryCodes::GuiSelectBoundaryCodes()
31 disableAutoSet();
34 void GuiSelectBoundaryCodes::setDisplayBoundaryCodes(const QSet<int> &bcs)
36 m_DisplayBoundaryCodes = bcs;
39 void GuiSelectBoundaryCodes::before()
41 populateBoundaryCodes(m_Ui.listWidget);
42 for (int row = 0; row < m_Ui.listWidget->count(); ++row) {
43 QString txt = m_Ui.listWidget->item(row)->text();
44 QStringList words = txt.split(":");
45 if (words.size() < 1) {
46 EG_BUG;
48 int bc = words[0].toInt();
49 bool checked = m_DisplayBoundaryCodes.contains(bc);
50 if (checked) {
51 m_Ui.listWidget->item(row)->setCheckState(Qt::Checked);
52 } else {
53 m_Ui.listWidget->item(row)->setCheckState(Qt::Unchecked);
57 connect(m_Ui.pushButtonSelect, SIGNAL(clicked()), this, SLOT(selectAll()));
58 connect(m_Ui.pushButtonDeselect, SIGNAL(clicked()), this, SLOT(deselectAll()));
59 connect(m_Ui.pushButton_SaveSelectionAsGrid, SIGNAL(clicked()), this, SLOT(saveSelectionAsGrid()));
62 void GuiSelectBoundaryCodes::operate()
64 getSelectedItems(m_Ui.listWidget, m_DisplayBoundaryCodes);
67 void GuiSelectBoundaryCodes::selectAll()
69 for (int i = 0; i < m_Ui.listWidget->count(); ++i) {
70 m_Ui.listWidget->item(i)->setCheckState(Qt::Checked);
74 void GuiSelectBoundaryCodes::deselectAll()
76 for (int i = 0; i < m_Ui.listWidget->count(); ++i) {
77 m_Ui.listWidget->item(i)->setCheckState(Qt::Unchecked);
81 void GuiSelectBoundaryCodes::saveSelectionAsGrid()
83 getSelectedItems(m_Ui.listWidget, m_DisplayBoundaryCodes);
84 QVector <vtkIdType> selected_cells;
85 getSurfaceCells(m_DisplayBoundaryCodes, selected_cells, m_Grid);
86 writeCells(m_Grid, selected_cells, GuiMainWindow::pointer()->getFilePath() + "selection.vtu" );
89 void GuiSelectBoundaryCodes::getSelectedBoundaryCodes(QSet<int> &bcs)
91 bcs = m_DisplayBoundaryCodes;