implemented method to access individual variables from an XML section
[engrid-github.git] / src / libengrid / operation.h
blob2ba9eb8af850e2edfbe39602e5662dc6878ac102
1 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 // + +
3 // + This file is part of enGrid. +
4 // + +
5 // + Copyright 2008-2014 enGits GmbH +
6 // + +
7 // + enGrid is free software: you can redistribute it and/or modify +
8 // + it under the terms of the GNU General Public License as published by +
9 // + the Free Software Foundation, either version 3 of the License, or +
10 // + (at your option) any later version. +
11 // + +
12 // + enGrid is distributed in the hope that it will be useful, +
13 // + but WITHOUT ANY WARRANTY; without even the implied warranty of +
14 // + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +
15 // + GNU General Public License for more details. +
16 // + +
17 // + You should have received a copy of the GNU General Public License +
18 // + along with enGrid. If not, see <http://www.gnu.org/licenses/>. +
19 // + +
20 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
21 #ifndef operation_H
22 #define operation_H
24 class Operation;
25 class GuiMainWindow;
27 #include "egvtkobject.h"
28 #include "vertexmeshdensity.h"
29 #include "meshpartition.h"
30 #include "timer.h"
32 #include <vtkUnstructuredGrid.h>
33 #include <vtkCellType.h>
34 #include <vtkSmartPointer.h>
35 #include <vtkCellLocator.h>
37 #include <QThread>
38 #include <QMutex>
39 #include <QListWidget>
40 #include <QTime>
42 #include <typeinfo>
44 #define EG_TYPENAME setTypeName(QString(typeid(*this).name()))
46 class OperationThread : public QThread
49 private:
51 Operation *op;
53 protected:
55 virtual void run();
57 public:
59 void setOperation(Operation *an_op) { op = an_op; }
63 /**
64 * This is the base class for all mesh operations.
65 * Operations will typically be triggered by a Qt event; the MainWindow
66 * object will call operator() with the current grid as parameter.
68 class Operation : public EgVtkObject
71 friend class OperationThread;
72 OperationThread thread;
74 private: // static attributes
76 static QSet<Operation*> garbage_operations;
78 private: // attributes
80 /// If true, attempts to lock the mutex when Operation::operator()() is called. If the lock was obtained, all other "lock_gui operations" will not work until the current "lock_gui opration" is done.
81 bool lock_gui;
83 bool m_quicksave; ///< save grid after operation finished?
84 bool m_resetoperationcounter; ///< reset operation counter after operation finished? (default is false)
85 bool autoset;
86 Error *err;
87 QString volume_name;
88 QString m_TypeName; ///< typename retrieved from typeid(this).name()
89 QTime m_StartTime; ///< start time for run-time information
91 private: // methods
93 void setStartTime() { m_StartTime = QTime::currentTime(); }
94 int elapsedTime() { return m_StartTime.secsTo(QTime::currentTime()); }
96 protected: // attributes
98 vtkUnstructuredGrid* m_Grid; ///< The main grid the operation operates on.
99 vtkUnstructuredGrid* m_RestGrid; ///< The remainder grid (not part of the selected volume)
100 MeshPartition m_Part; ///< the partition containing the subset of cells and nodes
101 Timer m_Timer; ///< Timer object for periodic output
102 QString m_MenuText; ///< The menu entry (mainly for plugins)
104 protected: // methods
106 void checkGrid();
107 void updateActors();
108 GuiMainWindow* mainWindow();
109 virtual void operate() = 0;
110 void setTypeName(QString name);
113 * Eliminate cells with identical node indices.
114 * @param surf_only if set to false all cells will be checked, otherwise surface cells only.
115 * Careful with eliminating volume cells -- this can be extremely slow.
117 void eliminateDuplicateCells(bool surf_only = true);
119 l2g_t getPartNodes() { return m_Part.getNodes(); }
120 l2g_t getPartCells() const { return m_Part.getCells(); }
121 g2l_t getPartLocalNodes() { return m_Part.getLocalNodes(); }
122 g2l_t getPartLocalCells() { return m_Part.getLocalCells(); }
123 l2l_t getPartN2N() { return m_Part.getN2N(); }
124 l2l_t getPartN2C() { return m_Part.getN2C(); }
125 l2l_t getPartC2C() { return m_Part.getC2C(); }
127 public: // methods
129 Operation();
130 virtual ~Operation();
131 void del();
133 void setGrid(vtkUnstructuredGrid *ug) { m_Grid = ug; }
134 void setAllCells();
135 void setAllVolumeCells();
136 void setAllSurfaceCells();
137 void setVolume(QString volume_name);
138 template <class T> void setCells(const T &cls);
139 void setMeshPartition(const MeshPartition &part);
141 void setLockGui() { lock_gui = true; }
142 OperationThread& getThread() { return thread; }
143 void enableAutoSet() { autoset = true; }
144 void disableAutoSet() { autoset = false; }
145 void setQuickSave(bool b) { m_quicksave = b; }
146 void setResetOperationCounter(bool b) { m_resetoperationcounter=b; }
149 * Fill a QListWidget with all available boundary codes from a grid.
150 * @param lw The QListWidget to fill.
151 * @param grid The grid to use.
153 void populateBoundaryCodes(QListWidget *lw);
156 * Fill a QListWidget with all available volumes from a grid.
157 * @param lw The QListWidget to fill.
158 * @param grid The grid to use.
160 void populateVolumes(QListWidget *lw);
162 virtual void operator()();
164 static void collectGarbage();
166 QString getTypeName() { return m_TypeName; }
167 QString getMenuText() { return m_MenuText; }
171 //End of class Operation
173 Q_DECLARE_INTERFACE(Operation, "eu.engits.enGrid.Operation/1.0")
176 template <class T>
177 void Operation::setCells(const T &cls)
179 m_Part.setGrid(m_Grid);
180 m_Part.setCells(cls);
183 #endif