Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
ElmerCSC
GitHub Repository: ElmerCSC/elmerfem
Path: blob/devel/ElmerGUI/Application/src/operation.cpp
3203 views
1
/*****************************************************************************
2
* *
3
* Elmer, A Finite Element Software for Multiphysical Problems *
4
* *
5
* Copyright 1st April 1995 - , CSC - IT Center for Science Ltd., Finland *
6
* *
7
* This program is free software; you can redistribute it and/or *
8
* modify it under the terms of the GNU General Public License *
9
* as published by the Free Software Foundation; either version 2 *
10
* of the License, or (at your option) any later version. *
11
* *
12
* This program 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. *
16
* *
17
* You should have received a copy of the GNU General Public License *
18
* along with this program (in file fem/GPL-2); if not, write to the *
19
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, *
20
* Boston, MA 02110-1301, USA. *
21
* *
22
*****************************************************************************/
23
24
/*****************************************************************************
25
* *
26
* ElmerGUI operation_t *
27
* *
28
*****************************************************************************
29
* *
30
* Authors: Mikko Lyly, Juha Ruokolainen and Peter Råback *
31
* Email: [email protected] *
32
* Web: http://www.csc.fi/elmer *
33
* Address: CSC - IT Center for Science Ltd. *
34
* Keilaranta 14 *
35
* 02101 Espoo, Finland *
36
* *
37
* Original Date: 15 Mar 2008 *
38
* *
39
*****************************************************************************/
40
41
#include <iostream>
42
#include "operation.h"
43
44
using namespace std;
45
46
operation_t::operation_t()
47
{
48
next = 0;
49
type = 0;
50
angle = 0.0;
51
selected = 0;
52
select_set = 0;
53
}
54
55
operation_t::~operation_t()
56
{
57
}
58
59
void operation_t::appendToProject(QDomDocument *projectDoc, QDomElement *ops)
60
{
61
operation_t *p = this->next;
62
for(int index = 0; p; p = p->next, index++) {
63
QDomElement op = projectDoc->createElement("operation");
64
op.setAttribute("index", QString::number(index));
65
ops->appendChild(op);
66
67
QDomElement type = projectDoc->createElement("type");
68
QDomText typeValue = projectDoc->createTextNode(QString::number(p->type));
69
type.appendChild(typeValue);
70
op.appendChild(type);
71
72
QDomElement angle = projectDoc->createElement("angle");
73
QDomText angleValue = projectDoc->createTextNode(QString::number(p->angle));
74
angle.appendChild(angleValue);
75
op.appendChild(angle);
76
77
QDomElement selected = projectDoc->createElement("selected");
78
selected.setAttribute("lists", QString::number(p->selected));
79
op.appendChild(selected);
80
81
for(int list = 0; list < p->selected; list++) {
82
QDomElement selection = projectDoc->createElement("list");
83
QDomText selectionValue = projectDoc->createTextNode(QString::number(p->select_set[list]));
84
selection.appendChild(selectionValue);
85
selected.appendChild(selection);
86
}
87
}
88
}
89
90
91
int operation_t::readFromProject(QDomDocument *projectDoc, QDomElement *ops)
92
{
93
operation_t *p = this->next;
94
operation_t *q = NULL;
95
96
while(p != NULL) {
97
if(p->select_set != NULL)
98
delete [] p->select_set;
99
q = p->next;
100
if(p != NULL)
101
delete p;
102
p = q;
103
}
104
105
int operations = 0;
106
q = this;
107
q->next = NULL;
108
109
QDomElement op = ops->firstChildElement("operation");
110
111
for( ; !op.isNull(); op = op.nextSiblingElement()) {
112
operations++;
113
114
p = new operation_t;
115
p->next = NULL;
116
q->next = p;
117
q = p;
118
119
p->type = op.firstChildElement("type").text().toInt();
120
p->angle = op.firstChildElement("angle").text().toDouble();
121
122
QDomElement selected = op.firstChildElement("selected");
123
p->selected = selected.attribute("lists").toInt();
124
125
p->select_set = new int[p->selected];
126
127
QDomElement selection = selected.firstChildElement("list");
128
129
for(int list = 0; !selection.isNull(); selection = selection.nextSiblingElement(), list++) {
130
if(list >= p->selected) {
131
cout << "Project loader: load operations: index out of bounds" << endl;
132
return 0;
133
}
134
p->select_set[list] = selection.text().toInt();
135
}
136
}
137
138
return operations;
139
}
140
141