2 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4 // + This file is part of enGrid. +
6 // + Copyright 2008-2013 enGits GmbH +
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. +
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. +
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/>. +
21 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
29 #include "egvtkobject.h"
30 #include "vertexmeshdensity.h"
31 #include "meshpartition.h"
34 #include <vtkUnstructuredGrid.h>
35 #include <vtkCellType.h>
36 #include <vtkSmartPointer.h>
37 #include <vtkCellLocator.h>
41 #include <QListWidget>
46 #define EG_TYPENAME setTypeName(QString(typeid(*this).name()))
48 class OperationThread
: public QThread
61 void setOperation(Operation
*an_op
) { op
= an_op
; }
66 * This is the base class for all mesh operations.
67 * Operations will typically be triggered by a Qt event; the MainWindow
68 * object will call operator() with the current grid as parameter.
70 class Operation
: public EgVtkObject
73 friend class OperationThread
;
74 OperationThread thread
;
76 private: // static attributes
78 static QSet
<Operation
*> garbage_operations
;
80 private: // attributes
82 /// 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.
85 bool m_quicksave
; ///< save grid after operation finished?
86 bool m_resetoperationcounter
; ///< reset operation counter after operation finished? (default is false)
90 QString m_TypeName
; ///< typename retrieved from typeid(this).name()
91 QTime m_StartTime
; ///< start time for run-time information
95 void setStartTime() { m_StartTime
= QTime::currentTime(); }
96 int elapsedTime() { return m_StartTime
.secsTo(QTime::currentTime()); }
98 protected: // attributes
100 vtkUnstructuredGrid
* m_Grid
; ///< The main grid the operation operates on.
101 vtkUnstructuredGrid
* m_RestGrid
; ///< The remainder grid (not part of the selected volume)
102 MeshPartition m_Part
; ///< the partition containing the subset of cells and nodes
103 Timer m_Timer
; ///< Timer object for periodic output
104 QString m_MenuText
; ///< The menu entry (mainly for plugins)
106 protected: // methods
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(); }
132 virtual ~Operation();
135 void setGrid(vtkUnstructuredGrid
*ug
) { m_Grid
= ug
; }
137 void setAllVolumeCells();
138 void setAllSurfaceCells();
139 void setVolume(QString volume_name
);
140 template <class T
> void setCells(const T
&cls
);
141 void setMeshPartition(const MeshPartition
&part
);
143 void setLockGui() { lock_gui
= true; }
144 OperationThread
& getThread() { return thread
; }
145 void enableAutoSet() { autoset
= true; }
146 void disableAutoSet() { autoset
= false; }
147 void setQuickSave(bool b
) { m_quicksave
= b
; }
148 void setResetOperationCounter(bool b
) { m_resetoperationcounter
=b
; }
151 * Fill a QListWidget with all available boundary codes from a grid.
152 * @param lw The QListWidget to fill.
153 * @param grid The grid to use.
155 void populateBoundaryCodes(QListWidget
*lw
);
158 * Fill a QListWidget with all available volumes from a grid.
159 * @param lw The QListWidget to fill.
160 * @param grid The grid to use.
162 void populateVolumes(QListWidget
*lw
);
164 virtual void operator()();
166 static void collectGarbage();
168 QString
getTypeName() { return m_TypeName
; }
169 QString
getMenuText() { return m_MenuText
; }
173 //End of class Operation
175 Q_DECLARE_INTERFACE(Operation
, "eu.engits.enGrid.Operation/1.0")
179 void Operation::setCells(const T
&cls
)
181 m_Part
.setGrid(m_Grid
);
182 m_Part
.setCells(cls
);