de-activated insert-points for now
[engrid.git] / src / operation.h
bloba6b67477ad643ac1ee06853f9799df771e2499f2
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 bool gui;
82 bool m_quicksave; ///< save grid after operation finished?
83 bool m_resetoperationcounter; ///< reset operation counter after operation finished? (default is false)
84 bool autoset;
85 Error *err;
86 QString volume_name;
87 QString m_TypeName; ///< typename retrieved from typeid(this).name()
88 QTime m_StartTime; ///< start time for run-time information
90 private: // methods
92 void setStartTime() { m_StartTime = QTime::currentTime(); }
93 int elapsedTime() { return m_StartTime.secsTo(QTime::currentTime()); }
95 protected: // attributes
97 vtkUnstructuredGrid *grid; ///< The main grid the operation operates on.
98 MeshPartition m_Part; ///< the partition containing the subset of cells and nodes
100 protected: // methods
102 void checkGrid();
103 void updateActors();
104 GuiMainWindow* mainWindow();
105 virtual void operate() = 0;
106 void setTypeName(QString name);
108 l2g_t getPartNodes() { return m_Part.getNodes(); }
109 l2g_t getPartCells() const { return m_Part.getCells(); }
110 g2l_t getPartLocalNodes() { return m_Part.getLocalNodes(); }
111 g2l_t getPartLocalCells() { return m_Part.getLocalCells(); }
112 l2l_t getPartN2N() { return m_Part.getN2N(); }
113 l2l_t getPartN2C() { return m_Part.getN2C(); }
114 l2l_t getPartC2C() { return m_Part.getC2C(); }
116 public: // methods
118 Operation();
119 virtual ~Operation();
120 void del();
122 void setGrid(vtkUnstructuredGrid *ug) { grid = ug; }
123 void setAllCells();
124 void setAllVolumeCells();
125 void setAllSurfaceCells();
126 void setVolume(QString volume_name);
127 template <class T> void setCells(const T &cls);
128 void setMeshPartition(const MeshPartition &part);
130 void setGui() { gui = true; }
131 OperationThread& getThread() { return thread; }
132 void enableAutoSet() { autoset = true; }
133 void disableAutoSet() { autoset = false; }
134 void setQuickSave(bool b) { m_quicksave = b; }
135 void setResetOperationCounter(bool b) { m_resetoperationcounter=b; }
138 * Fill a QListWidget with all available boundary codes from a grid.
139 * @param lw The QListWidget to fill.
140 * @param grid The grid to use.
142 void populateBoundaryCodes(QListWidget *lw);
145 * Fill a QListWidget with all available volumes from a grid.
146 * @param lw The QListWidget to fill.
147 * @param grid The grid to use.
149 void populateVolumes(QListWidget *lw);
151 virtual void operator()();
153 static void collectGarbage();
155 QString getTypeName() { return m_TypeName; }
159 //End of class Operation
164 template <class T>
165 void Operation::setCells(const T &cls)
167 m_Part.setGrid(grid);
168 m_Part.setCells(cls);
171 #endif