for Doxygen
[engrid.git] / operation.cpp
blob24bbb211606e7465aaea77b692497d0a8c89f2e2
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"
24 #include "guimainwindow.h"
26 #include <QApplication>
29 QSet<Operation*> Operation::garbage_operations;
31 void Operation::collectGarbage()
33 QSet<Operation*> delete_operations;
34 foreach (Operation *op, garbage_operations) {
35 if (!op->getThread().isRunning()) {
36 delete_operations.insert(op);
37 cout << "deleting Operation " << op << endl;
38 delete op;
41 foreach (Operation *op, delete_operations) {
42 garbage_operations.remove(op);
46 Operation::Operation()
48 grid = NULL;
49 gui = false;
50 err = NULL;
51 autoset = true;
54 Operation::~Operation()
56 if (err) {
57 err->display();
58 delete err;
62 void OperationThread::run()
64 try {
65 GuiMainWindow::lock();
66 GuiMainWindow::pointer()->setBusy();
67 op->operate();
68 } catch (Error err) {
69 op->err = new Error();
70 *(op->err) = err;
72 GuiMainWindow::unlock();
73 GuiMainWindow::pointer()->setIdle();
76 void Operation::operator()()
78 if (gui) {
79 if (GuiMainWindow::tryLock()) {
80 checkGrid();
81 thread.setOperation(this);
82 GuiMainWindow::unlock();
83 thread.start(QThread::LowPriority);
84 } else {
85 QMessageBox::warning(NULL, "not permitted", "Operation is not permitted while background process is running!");
87 } else {
88 checkGrid();
89 operate();
92 checkGrid();
93 operate();
97 void Operation::setAllCells()
99 QVector<vtkIdType> all_cells;
100 getAllCells(all_cells, grid);
101 setCells(all_cells);
104 void Operation::setAllVolumeCells()
106 QVector<vtkIdType> cells;
107 getAllVolumeCells(cells, grid);
108 setCells(cells);
111 void Operation::setAllSurfaceCells()
113 QVector<vtkIdType> cells;
114 getAllSurfaceCells(cells, grid);
115 setCells(cells);
118 void Operation::initMapping()
120 nodes_map.resize(nodes.size());
121 for (int i_nodes = 0; i_nodes < nodes.size(); ++i_nodes) {
122 nodes_map[i_nodes] = nodes[i_nodes];
124 cells_map.resize(cells.size());
125 for (int i_cells = 0; i_cells < cells.size(); ++i_cells) {
126 cells_map[i_cells] = cells[i_cells];
130 void Operation::checkGrid()
132 if (grid == NULL) {
133 grid = GuiMainWindow::pointer()->getGrid();
135 if ((cells.size() == 0) && autoset) {
136 setAllCells();
140 void Operation::updateActors()
142 mainWindow()->updateActors();
145 GuiMainWindow* Operation::mainWindow()
147 return GuiMainWindow::pointer();