1 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 // + This file is part of enGrid. +
5 // + Copyright 2008-2014 enGits GmbH +
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. +
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. +
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/>. +
20 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
27 #include "egvtkobject.h"
28 #include "vertexmeshdensity.h"
29 #include "meshpartition.h"
32 #include <vtkUnstructuredGrid.h>
33 #include <vtkCellType.h>
34 #include <vtkSmartPointer.h>
35 #include <vtkCellLocator.h>
39 #include <QListWidget>
44 #define EG_TYPENAME setTypeName(QString(typeid(*this).name()))
46 class OperationThread
: public QThread
59 void setOperation(Operation
*an_op
) { op
= an_op
; }
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.
83 bool m_quicksave
; ///< save grid after operation finished?
84 bool m_resetoperationcounter
; ///< reset operation counter after operation finished? (default is false)
88 QString m_TypeName
; ///< typename retrieved from typeid(this).name()
89 QTime m_StartTime
; ///< start time for run-time information
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
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(); }
130 virtual ~Operation();
133 void setGrid(vtkUnstructuredGrid
*ug
) { m_Grid
= ug
; }
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")
177 void Operation::setCells(const T
&cls
)
179 m_Part
.setGrid(m_Grid
);
180 m_Part
.setCells(cls
);