fixed edge display for volume cells
[engrid-github.git] / src / libengrid / operation.h
blob7646b59249920b77c9a18efab18bb912c7f50994
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
90 QMap<int, int> m_New2OldBc;
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
102 Timer m_Timer; ///< Timer object for periodic output
103 QString m_MenuText; ///< The menu entry (mainly for plugins)
104 bool m_Verbose; ///< General flag to trigger more output
106 protected: // methods
108 void checkGrid();
109 void updateActors();
110 GuiMainWindow* mainWindow();
111 virtual void operate() = 0;
112 void setTypeName(QString name);
115 * Eliminate cells with identical node indices.
116 * @param surf_only if set to false all cells will be checked, otherwise surface cells only.
117 * Careful with eliminating volume cells -- this can be extremely slow.
119 void eliminateDuplicateCells(bool surf_only = true);
121 l2g_t getPartNodes() { return m_Part.getNodes(); }
122 l2g_t getPartCells() const { return m_Part.getCells(); }
123 g2l_t getPartLocalNodes() { return m_Part.getLocalNodes(); }
124 g2l_t getPartLocalCells() { return m_Part.getLocalCells(); }
125 l2l_t getPartN2N() { return m_Part.getN2N(); }
126 l2l_t getPartN2C() { return m_Part.getN2C(); }
127 l2l_t getPartC2C() { return m_Part.getC2C(); }
129 void createFeatureBcs(double feature_angle);
130 void restoreNormalBcs();
132 public: // methods
134 Operation();
135 virtual ~Operation();
136 void del();
138 void setGrid(vtkUnstructuredGrid *ug) { m_Grid = ug; }
139 void setAllCells();
140 void setAllVolumeCells();
141 void setAllSurfaceCells();
142 void setVolume(QString volume_name);
143 template <class T> void setCells(const T &cls);
144 void setMeshPartition(const MeshPartition &part);
146 void setLockGui() { lock_gui = true; }
147 OperationThread& getThread() { return thread; }
148 void enableAutoSet() { autoset = true; }
149 void disableAutoSet() { autoset = false; }
150 void setQuickSave(bool b) { m_quicksave = b; }
151 void setResetOperationCounter(bool b) { m_resetoperationcounter=b; }
152 void setVerboseOn() { m_Verbose = true; }
153 void setVerboseOff() { m_Verbose = false; }
156 * Fill a QListWidget with all available boundary codes from a grid.
157 * @param lw The QListWidget to fill.
158 * @param grid The grid to use.
160 void populateBoundaryCodes(QListWidget *lw);
163 * Fill a QListWidget with all available volumes from a grid.
164 * @param lw The QListWidget to fill.
165 * @param grid The grid to use.
167 void populateVolumes(QListWidget *lw);
169 virtual void operator()();
171 static void collectGarbage();
173 QString getTypeName() { return m_TypeName; }
174 QString getMenuText() { return m_MenuText; }
178 //End of class Operation
180 Q_DECLARE_INTERFACE(Operation, "eu.engits.enGrid.Operation/1.0")
183 template <class T>
184 void Operation::setCells(const T &cls)
186 m_Part.setGrid(m_Grid);
187 m_Part.setCells(cls);
190 #endif