de-activated insert-points for now
[engrid.git] / src / operation.cpp
blob18e5e854eed3ca64c8c8b7c5be3c99af0978f919
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 #include "operation.h"
25 #include "guimainwindow.h"
26 #include "egvtkobject.h"
28 #include <vtkTriangleFilter.h>
29 #include <vtkInformation.h>
30 #include <vtkInformationVector.h>
31 #include <vtkObjectFactory.h>
32 #include <vtkPointData.h>
33 #include <vtkPolyData.h>
34 #include <vtkPolygon.h>
35 #include <vtkStreamingDemandDrivenPipeline.h>
36 #include <vtkCellArray.h>
37 #include <vtkCellData.h>
38 #include <vtkCellLocator.h>
39 #include <vtkFloatArray.h>
40 #include <vtkMath.h>
41 #include <vtkCharArray.h>
43 #include <QApplication>
44 #include <QTime>
46 #include "geometrytools.h"
47 using namespace GeometryTools;
49 QSet<Operation*> Operation::garbage_operations;
51 QVector<vtkIdType> m_static_DummyCells;
52 QVector<int> m_static_DummyRCells;
53 QVector<vtkIdType> m_static_DummyNodes;
54 QVector<int> m_static_DummyRNodes;
55 QVector<QVector<int> > m_static_DummyN2N;
56 QVector<QVector<int> > m_static_DummyN2C;
57 QVector<QVector<int> > m_static_DummyC2C;
61 void Operation::collectGarbage()
63 QSet<Operation*> delete_operations;
65 foreach (Operation *op, garbage_operations)
67 if (!op->getThread().isRunning()) {
68 delete_operations.insert(op);
69 cout << "deleting Operation " << op << endl;
70 delete op;
74 foreach (Operation *op, delete_operations)
76 garbage_operations.remove(op);
80 Operation::Operation()
82 grid = NULL;
83 gui = false;
84 m_quicksave = false;
85 m_resetoperationcounter = false;
86 err = NULL;
87 autoset = true;
88 m_TypeName = "undefined";
91 Operation::~Operation()
93 if (err) {
94 err->display();
95 delete err;
99 void Operation::del()
101 garbage_operations.insert(this);
104 void OperationThread::run()
106 try {
107 GuiMainWindow::lock();
108 GuiMainWindow::pointer()->setBusy();
109 op->operate();
110 cout << "secs. for " << qPrintable(op->getTypeName()) << ": " << op->elapsedTime() << endl;
111 } catch (Error err) {
112 op->err = new Error();
113 *(op->err) = err;
115 GuiMainWindow::unlock();
116 GuiMainWindow::pointer()->setIdle();
119 void Operation::setTypeName(QString name)
121 int i = 0;
122 while ((i < name.size()) && (name[i].isDigit())) {
123 ++i;
125 m_TypeName = name.right(name.size() - i);
128 void Operation::operator()()
130 setStartTime();
131 if (gui) {
132 if (GuiMainWindow::tryLock()) {
133 checkGrid();
134 thread.setOperation(this);
135 GuiMainWindow::unlock();
136 thread.start(QThread::LowPriority);
137 } else {
138 QMessageBox::warning(NULL, "not permitted", "Operation is not permitted while background process is running!");
140 } else {
141 checkGrid();
142 const bool gui_thread = QThread::currentThread() == QCoreApplication::instance()->thread();
143 if (gui_thread) {
144 try {
145 operate();
146 //cout << "secs. for " << qPrintable(getTypeName()) << ": " << elapsedTime() << endl;
147 } catch (Error err) {
148 err.display();
150 } else {
151 operate();
153 if(m_resetoperationcounter) GuiMainWindow::pointer()->resetOperationCounter();
154 if(m_quicksave) GuiMainWindow::pointer()->quickSave();
158 void Operation::setAllCells()
160 QVector<vtkIdType> all_cells;
161 getAllCells(all_cells, grid);
162 setCells(all_cells);
165 void Operation::setAllVolumeCells()
167 QVector<vtkIdType> cells;
168 getAllVolumeCells(cells, grid);
169 setCells(cells);
172 void Operation::setAllSurfaceCells()
174 QVector<vtkIdType> cells;
175 getAllSurfaceCells(cells, grid);
176 setCells(cells);
179 void Operation::setVolume(QString volume_name)
181 m_Part.setGrid(grid);
182 m_Part.setVolume(volume_name);
185 void Operation::setMeshPartition(const MeshPartition &part)
187 m_Part.setGrid(part.getGrid());
188 m_Part.setCells(part.getCells());
191 void Operation::checkGrid()
193 if (grid == NULL) {
194 grid = GuiMainWindow::pointer()->getGrid();
196 l2g_t cells = getPartCells();
197 if ((cells.size() == 0) && autoset) {
198 setAllCells();
202 void Operation::updateActors()
204 mainWindow()->updateActors();
207 GuiMainWindow* Operation::mainWindow()
209 return GuiMainWindow::pointer();
212 void Operation::populateBoundaryCodes(QListWidget *lw)
214 QSet<int> bcs;
215 mainWindow()->getAllBoundaryCodes(bcs);
216 foreach(int bc, bcs) {
217 QListWidgetItem *lwi = new QListWidgetItem(lw);
218 lwi->setCheckState(Qt::Unchecked);
219 QString text = "";
220 QTextStream ts(&text);
221 ts << bc;
222 lwi->setText(text);
223 lwi->setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsEnabled);
227 void Operation::populateVolumes(QListWidget *lw)
229 QList<VolumeDefinition> vols = mainWindow()->getAllVols();
230 foreach (VolumeDefinition V, vols) {
231 QListWidgetItem *lwi = new QListWidgetItem(lw);
232 lwi->setText(V.getName());