implemented mirror mesh, still not working for vol. cells
[engrid.git] / src / operation.h
blob1da4c139819591dd1781c3a85549a11210817d11
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 operation_H
24 #define operation_H
26 class Operation;
27 class GuiMainWindow;
29 #include "egvtkobject.h"
30 #include "vertexmeshdensity.h"
31 #include "meshpartition.h"
33 #include <vtkUnstructuredGrid.h>
34 #include <vtkCellType.h>
35 #include <vtkSmartPointer.h>
36 #include <vtkCellLocator.h>
38 #include <QThread>
39 #include <QMutex>
40 #include <QListWidget>
41 #include <QTime>
43 #include <typeinfo>
45 #define EG_TYPENAME setTypeName(QString(typeid(*this).name()))
47 class OperationThread : public QThread
50 private:
52 Operation *op;
54 protected:
56 virtual void run();
58 public:
60 void setOperation(Operation *an_op) { op = an_op; }
64 /**
65 * This is the base class for all mesh operations.
66 * Operations will typically be triggered by a Qt event; the MainWindow
67 * object will call operator() with the current grid as parameter.
69 class Operation : public EgVtkObject
72 friend class OperationThread;
73 OperationThread thread;
75 private: // static attributes
77 static QSet<Operation*> garbage_operations;
79 private: // attributes
81 /// 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.
82 bool lock_gui;
84 bool m_quicksave; ///< save grid after operation finished?
85 bool m_resetoperationcounter; ///< reset operation counter after operation finished? (default is false)
86 bool autoset;
87 Error *err;
88 QString volume_name;
89 QString m_TypeName; ///< typename retrieved from typeid(this).name()
90 QTime m_StartTime; ///< start time for run-time information
92 private: // methods
94 void setStartTime() { m_StartTime = QTime::currentTime(); }
95 int elapsedTime() { return m_StartTime.secsTo(QTime::currentTime()); }
97 protected: // attributes
99 vtkUnstructuredGrid* m_Grid; ///< The main grid the operation operates on.
100 vtkUnstructuredGrid* m_RestGrid; ///< The remainder grid (not part of the selected volume)
101 MeshPartition m_Part; ///< the partition containing the subset of cells and nodes
103 protected: // methods
105 void checkGrid();
106 void updateActors();
107 GuiMainWindow* mainWindow();
108 virtual void operate() = 0;
109 void setTypeName(QString name);
112 * Eliminate cells with identical node indices.
113 * @param surf_only if set to false all cells will be checked, otherwise surface cells only.
114 * Careful with eliminating volume cells -- this can be extremely slow.
116 void eliminateDuplicateCells(bool surf_only = true);
118 l2g_t getPartNodes() { return m_Part.getNodes(); }
119 l2g_t getPartCells() const { return m_Part.getCells(); }
120 g2l_t getPartLocalNodes() { return m_Part.getLocalNodes(); }
121 g2l_t getPartLocalCells() { return m_Part.getLocalCells(); }
122 l2l_t getPartN2N() { return m_Part.getN2N(); }
123 l2l_t getPartN2C() { return m_Part.getN2C(); }
124 l2l_t getPartC2C() { return m_Part.getC2C(); }
126 public: // methods
128 Operation();
129 virtual ~Operation();
130 void del();
132 void setGrid(vtkUnstructuredGrid *ug) { m_Grid = ug; }
133 void setAllCells();
134 void setAllVolumeCells();
135 void setAllSurfaceCells();
136 void setVolume(QString volume_name);
137 template <class T> void setCells(const T &cls);
138 void setMeshPartition(const MeshPartition &part);
140 void setLockGui() { lock_gui = true; }
141 OperationThread& getThread() { return thread; }
142 void enableAutoSet() { autoset = true; }
143 void disableAutoSet() { autoset = false; }
144 void setQuickSave(bool b) { m_quicksave = b; }
145 void setResetOperationCounter(bool b) { m_resetoperationcounter=b; }
148 * Fill a QListWidget with all available boundary codes from a grid.
149 * @param lw The QListWidget to fill.
150 * @param grid The grid to use.
152 void populateBoundaryCodes(QListWidget *lw);
155 * Fill a QListWidget with all available volumes from a grid.
156 * @param lw The QListWidget to fill.
157 * @param grid The grid to use.
159 void populateVolumes(QListWidget *lw);
161 virtual void operator()();
163 static void collectGarbage();
165 QString getTypeName() { return m_TypeName; }
169 //End of class Operation
174 template <class T>
175 void Operation::setCells(const T &cls)
177 m_Part.setGrid(m_Grid);
178 m_Part.setCells(cls);
181 #endif