implemented mirror mesh, still not working for vol. cells
[engrid.git] / src / dialogoperation.h
blob42d073ed109bc98bb16b706ed29b3a2dc9ec43ff
1 //
2 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 // + +
4 // + This file is part of enGrid. +
5 // + +
6 // + Copyright 2008,2009 Oliver Gloth +
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 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
23 #ifndef dialogoperation_H
24 #define dialogoperation_H
26 template <class UI, class OP>
27 class DialogOperation;
29 #include "operation.h"
30 // #include "guimainwindow.h"
32 #include <QDialog>
33 #include <QListWidget>
34 #include <QTextStream>
36 #include <vtkUnstructuredGrid.h>
37 #include <vtkIntArray.h>
38 #include <vtkCellData.h>
40 template <class UI, class OP>
41 class DialogOperation : public QDialog,
42 public OP
45 protected: // attributes
47 /** The user interface definition from QtDesigner */
48 UI ui;
50 protected: // methods
52 EgVtkObject::l2g_t getPartNodes() { return this->m_Part.getNodes(); }
53 EgVtkObject::l2g_t getPartCells()const { return this->m_Part.getCells(); }
54 EgVtkObject::g2l_t getPartLocalNodes() { return this->m_Part.getLocalNodes(); }
55 EgVtkObject::g2l_t getPartLocalCells() { return this->m_Part.getLocalCells(); }
56 EgVtkObject::l2l_t getPartN2N() { return this->m_Part.getN2N(); }
57 EgVtkObject::l2l_t getPartN2C() { return this->m_Part.getN2C(); }
58 EgVtkObject::l2l_t getPartC2C() { return this->m_Part.getC2C(); }
60 public: // methods
62 /** Generic constructor to set up the user interface */
63 DialogOperation();
65 /**
66 * Create a checkable QListWidgetItem and add it to a QListWidget.
67 * @param lw the QListWidget to add the item to
68 * @param item the text of the item
69 * @param checked the status of the item checked/unchecked
71 template <class T>
72 void addListItem(QListWidget *lw, T item, bool checked = false);
74 /**
75 * Check if a certain text item is checked within a QListWidget.
76 * @param lw the QListWidget to check
77 * @param item the item to check
78 * @return true if the item is checked and false if not
80 template <class T>
81 bool checkListItem(QListWidget *lw, T item);
83 /**
84 * Get the name of the selected volume.
85 * @param lw the QListWidget for volume selection
86 * @return the name of the selected volume
88 QString getSelectedVolume(QListWidget *lw);
90 /**
91 * Get a set with all seleceted items from a QListWidget.
92 * @param lw The QListWidget.
93 * @param sel On return, this will hold all items.
95 void getSelectedItems(QListWidget *lw, QSet<int> &sel);
97 /**
98 * Get a set with all seleceted items from a QListWidget.
99 * @param lw The QListWidget.
100 * @param sel On return, this will hold all items.
102 void getSelectedItems(QListWidget *lw, QSet<QString> &sel);
104 virtual void before() {}
105 virtual void operator()();
107 //connect(const QObject* a, const char* b, const QObject* c, const char* d) { QObject::connect(a,b,c,d); };
111 template <class UI, class OP>
112 DialogOperation<UI,OP>::DialogOperation()
114 ui.setupUi(this);
117 template <class UI, class OP>
118 template <class T>
119 void DialogOperation<UI,OP>::addListItem(QListWidget *lw, T item, bool checked)
121 QListWidgetItem *lwi = new QListWidgetItem(lw);
122 if (checked) lwi->setCheckState(Qt::Checked);
123 else lwi->setCheckState(Qt::Unchecked);
124 QString text = "";
125 QTextStream ts(&text);
126 ts << item;
127 lwi->setText(text);
128 lwi->setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsEnabled);
131 template <class UI, class OP>
132 template <class T>
133 bool DialogOperation<UI,OP>::checkListItem(QListWidget *lw, T item)
135 QString text = "";
136 QTextStream ts(&text);
137 ts << item;
138 for (int i = 0; i < lw->count(); ++i) {
139 if (lw->item(i)->text() == text) {
140 if (lw->item(i)->checkState() == Qt::Checked) return true;
143 return false;
146 template <class UI, class OP>
147 QString DialogOperation<UI,OP>::getSelectedVolume(QListWidget *lw)
149 QString volume_name;
150 for (int i = 0; i < lw->count(); ++i) {
151 if (lw->item(i)->isSelected()) {
152 volume_name = lw->item(i)->text();
155 return volume_name;
158 template <class UI, class OP>
159 void DialogOperation<UI,OP>::getSelectedItems(QListWidget *lw, QSet<QString> &sel)
161 sel.clear();
162 for (int i = 0; i < lw->count(); ++i) {
163 if (lw->item(i)->checkState() == Qt::Checked) {
164 QString item = lw->item(i)->text();
165 sel.insert(item);
170 template <class UI, class OP>
171 void DialogOperation<UI,OP>::getSelectedItems(QListWidget *lw, QSet<int> &sel)
173 sel.clear();
174 for (int i = 0; i < lw->count(); ++i) {
175 if (lw->item(i)->checkState() == Qt::Checked) {
176 QString item_txt = lw->item(i)->text();
177 QStringList items = item_txt.split(":");
178 int item = items[0].toInt(); ///\todo UiUiUi
179 sel.insert(item);
184 template <class UI, class OP>
185 void DialogOperation<UI,OP>::operator()()
187 bool ok = true;
188 //Prepare the GUI
189 try {
190 OP::checkGrid();
191 before();
192 } catch (Error err) {
193 err.display();
194 ok = false;
196 //Run the GUI
197 if (ok) {
198 if (QDialog::exec()) {
199 //Run the operation
200 try {
201 OP::operator()();
202 } catch (Error err) {
203 err.display();
209 #endif