2 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4 // + This file is part of enGrid. +
6 // + Copyright 2008,2009 Oliver Gloth +
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 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
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>
41 #include <vtkCharArray.h>
43 #include <QApplication>
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
;
74 foreach (Operation
*op
, delete_operations
)
76 garbage_operations
.remove(op
);
80 Operation::Operation()
85 m_resetoperationcounter
= false;
88 m_TypeName
= "undefined";
91 Operation::~Operation()
101 garbage_operations
.insert(this);
104 void OperationThread::run()
107 GuiMainWindow::lock();
108 GuiMainWindow::pointer()->setBusy();
110 cout
<< "secs. for " << qPrintable(op
->getTypeName()) << ": " << op
->elapsedTime() << endl
;
111 } catch (Error err
) {
112 op
->err
= new Error();
115 GuiMainWindow::unlock();
116 GuiMainWindow::pointer()->setIdle();
119 void Operation::setTypeName(QString name
)
122 while ((i
< name
.size()) && (name
[i
].isDigit())) {
125 m_TypeName
= name
.right(name
.size() - i
);
128 void Operation::operator()()
132 if (GuiMainWindow::tryLock()) {
134 thread
.setOperation(this);
135 GuiMainWindow::unlock();
136 thread
.start(QThread::LowPriority
);
138 QMessageBox::warning(NULL
, "not permitted", "Operation is not permitted while background process is running!");
142 const bool gui_thread
= QThread::currentThread() == QCoreApplication::instance()->thread();
146 //cout << "secs. for " << qPrintable(getTypeName()) << ": " << elapsedTime() << endl;
147 } catch (Error err
) {
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
);
165 void Operation::setAllVolumeCells()
167 QVector
<vtkIdType
> cells
;
168 getAllVolumeCells(cells
, grid
);
172 void Operation::setAllSurfaceCells()
174 QVector
<vtkIdType
> cells
;
175 getAllSurfaceCells(cells
, grid
);
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()
194 grid
= GuiMainWindow::pointer()->getGrid();
196 l2g_t cells
= getPartCells();
197 if ((cells
.size() == 0) && autoset
) {
202 void Operation::updateActors()
204 mainWindow()->updateActors();
207 GuiMainWindow
* Operation::mainWindow()
209 return GuiMainWindow::pointer();
212 void Operation::populateBoundaryCodes(QListWidget
*lw
)
215 mainWindow()->getAllBoundaryCodes(bcs
);
216 foreach(int bc
, bcs
) {
217 QListWidgetItem
*lwi
= new QListWidgetItem(lw
);
218 lwi
->setCheckState(Qt::Unchecked
);
220 QTextStream
ts(&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());