-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProjectData.cpp
216 lines (188 loc) · 6.52 KB
/
ProjectData.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
/**
* \file ProjectData.cpp
* 25/08/2010 KR Initial implementation
* \copyright
* Copyright (c) 2015, OpenGeoSys Community (http://www.opengeosys.org)
* Distributed under a Modified BSD License.
* See accompanying file LICENSE.txt or
* http://www.opengeosys.org/project/license
*/
#include "ProjectData.h"
#include "StringTools.h"
ProjectData::ProjectData() : _geoObjects(NULL)
{
}
ProjectData::~ProjectData()
{
delete _geoObjects;
for (std::map<std::string, MeshLib::CFEMesh*>::iterator it = _msh_vec.begin(); it != _msh_vec.end(); ++it)
delete it->second;
size_t nCond(_cond_vec.size());
for (size_t i = 0; i < nCond; i++)
delete _cond_vec[i];
}
void ProjectData::addMesh(MeshLib::CFEMesh* mesh, std::string& name)
{
isUniqueMeshName(name);
_msh_vec[name] = mesh;
}
const MeshLib::CFEMesh* ProjectData::getMesh(const std::string& name) const
{
return _msh_vec.find(name)->second;
}
bool ProjectData::removeMesh(const std::string& name)
{
delete _msh_vec[name];
size_t result = _msh_vec.erase(name);
return result > 0;
}
bool ProjectData::meshExists(const std::string& name)
{
if (_msh_vec.count(name) > 0)
return true;
return false;
}
void ProjectData::addProcess(ProcessInfo* pcs)
{
for (std::vector<ProcessInfo*>::const_iterator it = _pcs_vec.begin(); it != _pcs_vec.end(); ++it)
if ((*it)->getProcessType() == pcs->getProcessType())
{
std::cout << "Error in ProjectData::addProcess() - "
<< FiniteElement::convertProcessTypeToString(pcs->getProcessType()) << " process already exists."
<< "\n";
}
_pcs_vec.push_back(pcs);
}
const ProcessInfo* ProjectData::getProcess(FiniteElement::ProcessType type) const
{
for (std::vector<ProcessInfo*>::const_iterator it = _pcs_vec.begin(); it != _pcs_vec.end(); ++it)
if ((*it)->getProcessType() == type)
return *it;
std::cout << "Error in ProjectData::getProcess() - No " << FiniteElement::convertProcessTypeToString(type)
<< " process found..."
<< "\n";
return NULL;
}
bool ProjectData::removeProcess(FiniteElement::ProcessType type)
{
for (std::vector<ProcessInfo*>::iterator it = _pcs_vec.begin(); it != _pcs_vec.end(); ++it)
if ((*it)->getProcessType() == type)
{
delete *it;
_pcs_vec.erase(it);
return true;
}
std::cout << "Error in ProjectData::removeProcess() - No " << FiniteElement::convertProcessTypeToString(type)
<< " process found..."
<< "\n";
return false;
}
void ProjectData::addCondition(FEMCondition* cond)
{
_cond_vec.push_back(cond);
}
void ProjectData::addConditions(std::vector<FEMCondition*> conds)
{
for (size_t i = 0; i < conds.size(); i++)
_cond_vec.push_back(conds[i]);
}
const FEMCondition* ProjectData::getCondition(const std::string& geo_name,
GEOLIB::GEOTYPE type,
const std::string& cond_name) const
{
for (std::vector<FEMCondition*>::const_iterator it = _cond_vec.begin(); it != _cond_vec.end(); ++it)
if ((*it)->getAssociatedGeometryName().compare(geo_name) == 0)
if (((*it)->getGeoName().compare(cond_name) == 0) && ((*it)->getGeoType() == type))
return *it;
std::cout << "Error in ProjectData::getCondition() - No condition found with name \"" << cond_name << "\"..."
<< "\n";
return NULL;
}
const std::vector<FEMCondition*> ProjectData::getConditions(FiniteElement::ProcessType pcs_type,
std::string geo_name,
FEMCondition::CondType cond_type) const
{
// if all
if (pcs_type == FiniteElement::INVALID_PROCESS && geo_name.empty() && cond_type == FEMCondition::UNSPECIFIED)
return _cond_vec;
// else: filter according to parameters
std::vector<FEMCondition*> conds;
for (std::vector<FEMCondition*>::const_iterator it = _cond_vec.begin(); it != _cond_vec.end(); ++it)
{
if (((pcs_type == FiniteElement::INVALID_PROCESS) || (pcs_type == ((*it)->getProcessType())))
&& ((geo_name.empty() || ((*it)->getAssociatedGeometryName().compare(geo_name) == 0)))
&& ((cond_type == FEMCondition::UNSPECIFIED) || ((*it)->getCondType() == cond_type)))
conds.push_back(*it);
}
return conds;
}
void ProjectData::removeConditions(FiniteElement::ProcessType pcs_type,
std::string geo_name,
FEMCondition::CondType cond_type)
{
// if all
if (pcs_type == FiniteElement::INVALID_PROCESS && geo_name.empty() && cond_type == FEMCondition::UNSPECIFIED)
{
for (size_t i = 0; i < _cond_vec.size(); i++)
delete _cond_vec[i];
_cond_vec.clear();
return;
}
// else: filter according to parameters
for (std::vector<FEMCondition*>::iterator it = _cond_vec.begin(); it != _cond_vec.end();)
{
if (((pcs_type == FiniteElement::INVALID_PROCESS) || (pcs_type == ((*it)->getProcessType())))
&& ((geo_name.empty() || ((*it)->getAssociatedGeometryName().compare(geo_name) == 0)))
&& ((cond_type == FEMCondition::UNSPECIFIED) || ((*it)->getCondType() == cond_type)))
{
delete *it;
it = _cond_vec.erase(it);
}
else
++it;
}
}
bool ProjectData::removeCondition(const std::string& geo_name, GEOLIB::GEOTYPE type, const std::string& cond_name)
{
for (std::vector<FEMCondition*>::iterator it = _cond_vec.begin(); it != _cond_vec.end(); ++it)
{
if ((*it)->getAssociatedGeometryName().compare(geo_name) == 0)
if (((*it)->getGeoName().compare(cond_name) == 0) && ((*it)->getGeoType() == type))
{
delete *it;
_cond_vec.erase(it);
return true;
}
}
std::cout << "Error in ProjectData::removeCondition() - No condition found with name \"" << cond_name << "\"..."
<< "\n";
return false;
}
bool ProjectData::isUniqueMeshName(std::string& name)
{
int count(0);
bool isUnique(false);
std::string cpName;
while (!isUnique)
{
isUnique = true;
cpName = name;
count++;
// If the original name already exists we start to add numbers to name for
// as long as it takes to make the name unique.
if (count > 1)
cpName = cpName + "-" + number2str(count);
for (std::map<std::string, MeshLib::CFEMesh*>::iterator it = _msh_vec.begin(); it != _msh_vec.end(); ++it)
if (cpName.compare(it->first) == 0)
isUnique = false;
}
// At this point cpName is a unique name and isUnique is true.
// If cpName is not the original name, "name" is changed and isUnique is set to false,
// indicating that a vector with the original name already exists.
if (count > 1)
{
isUnique = false;
name = cpName;
}
return isUnique;
}