1
// Gmsh - Copyright (C) 1997-2008 C. Geuzaine, J.-F. Remacle
3
// See the LICENSE.txt file for license information. Please report all
4
// bugs and problems to <gmsh@geuz.org>.
7
#include "Visibility.h"
11
#if !defined(HAVE_NO_PARSER)
15
VisibilityManager *VisibilityManager::manager = 0;
19
bool operator()(const Vis *v1, const Vis *v2) const
21
switch(VisibilityManager::instance()->getSortMode()){
22
case 1: return v1->getDim() < v2->getDim() ? true : false;
23
case -1: return v1->getDim() > v2->getDim() ? true : false;
24
case 2: return v1->getTag() < v2->getTag() ? true : false;
25
case -2: return v1->getTag() > v2->getTag() ? true : false;
27
return strcmp(VisibilityManager::instance()->getLabel(v1->getTag()).c_str(),
28
VisibilityManager::instance()->getLabel(v2->getTag()).c_str()) < 0 ?
31
return strcmp(VisibilityManager::instance()->getLabel(v1->getTag()).c_str(),
32
VisibilityManager::instance()->getLabel(v2->getTag()).c_str()) > 0 ?
38
void VisibilityManager::update(int type)
41
for(unsigned int i = 0; i < _entities.size(); i++)
45
GModel *m = GModel::current();
47
#if !defined(HAVE_NO_PARSER)
48
for(std::map<std::string, std::vector<double> >::iterator it = gmsh_yysymbols.begin();
49
it != gmsh_yysymbols.end(); ++it)
50
for(unsigned int i = 0; i < it->second.size(); i++)
51
VisibilityManager::instance()->setLabel((int)it->second[i], it->first, 0);
54
if(type == 0){ // elementary entities
55
for(GModel::piter it = m->firstElementaryName(); it != m->lastElementaryName(); ++it)
56
setLabel(it->first, it->second);
57
for(GModel::viter it = m->firstVertex(); it != m->lastVertex(); it++)
58
_entities.push_back(new VisElementary(*it));
59
for(GModel::eiter it = m->firstEdge(); it != m->lastEdge(); it++)
60
_entities.push_back(new VisElementary(*it));
61
for(GModel::fiter it = m->firstFace(); it != m->lastFace(); it++)
62
_entities.push_back(new VisElementary(*it));
63
for(GModel::riter it = m->firstRegion(); it != m->lastRegion(); it++)
64
_entities.push_back(new VisElementary(*it));
66
else if(type == 1){ // physical entities
67
for(GModel::piter it = m->firstPhysicalName(); it != m->lastPhysicalName(); ++it)
68
setLabel(it->first, it->second);
69
std::map<int, std::vector<GEntity*> > groups[4];
70
m->getPhysicalGroups(groups);
71
for(int i = 0; i < 4; i++){
72
std::map<int, std::vector<GEntity*> >::const_iterator it = groups[i].begin();
73
for(; it != groups[i].end(); ++it)
74
_entities.push_back(new VisPhysical(it->first, i, it->second));
77
else if(type == 2){ // partitions
78
std::set<int> part = m->getMeshPartitions();
79
for(std::set<int>::const_iterator it = part.begin(); it != part.end(); ++it)
80
_entities.push_back(new VisPartition(*it));
82
std::sort(_entities.begin(), _entities.end(), VisLessThan());
85
void VisibilityManager::setAllInvisible(int type)
87
GModel *m = GModel::current();
89
if(type == 0 || type == 1){
90
// elementary or physical mode: set all entities in the model invisible
91
for(GModel::viter it = m->firstVertex(); it != m->lastVertex(); it++)
92
(*it)->setVisibility(false);
93
for(GModel::eiter it = m->firstEdge(); it != m->lastEdge(); it++)
94
(*it)->setVisibility(false);
95
for(GModel::fiter it = m->firstFace(); it != m->lastFace(); it++)
96
(*it)->setVisibility(false);
97
for(GModel::riter it = m->firstRegion(); it != m->lastRegion(); it++)
98
(*it)->setVisibility(false);
101
// this is superfluous in elementary mode, but we don't care
102
for(int i = 0; i < getNumEntities(); i++) setVisibility(i, false);
105
std::string VisibilityManager::getBrowserLine(int n)
107
int tag = _entities[n]->getTag();
109
bool label_exists = _labels.count(tag);
110
const char *label_color = (label_exists && _labels[tag].second) ? "@b" : "";
111
sprintf(str, "\t%s\t%d\t%s%s", _entities[n]->getName().c_str(), tag,
112
label_color, label_exists ? _labels[tag].first.c_str() : "");
113
return std::string(str);
116
std::string VisibilityManager::getStringForGEO()
118
std::vector<int> state[4][2];
120
GModel *m = GModel::current();
122
for(GModel::viter it = m->firstVertex(); it != m->lastVertex(); it++)
123
(*it)->getVisibility() ?
124
state[0][1].push_back((*it)->tag()) : state[0][0].push_back((*it)->tag());
125
for(GModel::eiter it = m->firstEdge(); it != m->lastEdge(); it++)
126
(*it)->getVisibility() ?
127
state[1][1].push_back((*it)->tag()) : state[1][0].push_back((*it)->tag());
128
for(GModel::fiter it = m->firstFace(); it != m->lastFace(); it++)
129
(*it)->getVisibility() ?
130
state[2][1].push_back((*it)->tag()) : state[2][0].push_back((*it)->tag());
131
for(GModel::riter it = m->firstRegion(); it != m->lastRegion(); it++)
132
(*it)->getVisibility() ?
133
state[3][1].push_back((*it)->tag()) : state[3][0].push_back((*it)->tag());
136
const char *labels[4] = {"Point", "Line", "Surface", "Volume"};
141
for(int i = 0; i < 4; i++){
142
on += state[i][1].size();
143
off += state[i][0].size();
147
str = "Show \"*\";\n";
153
str = "Hide \"*\";\n";
159
for(int i = 0; i < 4; i++){
160
if(state[i][mode].size()){
163
for(unsigned int j = 0; j < state[i][mode].size(); j++){
165
sprintf(tmp, "%d", state[i][mode][j]);
175
void VisibilityManager::setVisibilityByNumber(int type, int num, char val, bool recursive)
177
bool all = (num < 0) ? true : false;
179
GModel *m = GModel::current();
183
for(GModel::viter it = m->firstVertex(); it != m->lastVertex(); it++)
184
for(unsigned int i = 0; i < (*it)->mesh_vertices.size(); i++)
185
if(all || (*it)->mesh_vertices[i]->getNum() == num)
186
(*it)->mesh_vertices[i]->setVisibility(val);
187
for(GModel::eiter it = m->firstEdge(); it != m->lastEdge(); it++)
188
for(unsigned int i = 0; i < (*it)->mesh_vertices.size(); i++)
189
if(all || (*it)->mesh_vertices[i]->getNum() == num)
190
(*it)->mesh_vertices[i]->setVisibility(val);
191
for(GModel::fiter it = m->firstFace(); it != m->lastFace(); it++)
192
for(unsigned int i = 0; i < (*it)->mesh_vertices.size(); i++)
193
if(all || (*it)->mesh_vertices[i]->getNum() == num)
194
(*it)->mesh_vertices[i]->setVisibility(val);
195
for(GModel::riter it = m->firstRegion(); it != m->lastRegion(); it++)
196
for(unsigned int i = 0; i < (*it)->mesh_vertices.size(); i++)
197
if(all || (*it)->mesh_vertices[i]->getNum() == num)
198
(*it)->mesh_vertices[i]->setVisibility(val);
201
for(GModel::eiter it = m->firstEdge(); it != m->lastEdge(); it++){
202
for(unsigned int i = 0; i < (*it)->lines.size(); i++)
203
if(all || (*it)->lines[i]->getNum() == num)
204
(*it)->lines[i]->setVisibility(val);
206
for(GModel::fiter it = m->firstFace(); it != m->lastFace(); it++){
207
for(unsigned int i = 0; i < (*it)->triangles.size(); i++)
208
if(all || (*it)->triangles[i]->getNum() == num)
209
(*it)->triangles[i]->setVisibility(val);
210
for(unsigned int i = 0; i < (*it)->quadrangles.size(); i++)
211
if(all || (*it)->quadrangles[i]->getNum() == num)
212
(*it)->quadrangles[i]->setVisibility(val);
214
for(GModel::riter it = m->firstRegion(); it != m->lastRegion(); it++){
215
for(unsigned int i = 0; i < (*it)->tetrahedra.size(); i++)
216
if(all || (*it)->tetrahedra[i]->getNum() == num)
217
(*it)->tetrahedra[i]->setVisibility(val);
218
for(unsigned int i = 0; i < (*it)->hexahedra.size(); i++)
219
if(all || (*it)->hexahedra[i]->getNum() == num)
220
(*it)->hexahedra[i]->setVisibility(val);
221
for(unsigned int i = 0; i < (*it)->prisms.size(); i++)
222
if(all || (*it)->prisms[i]->getNum() == num)
223
(*it)->prisms[i]->setVisibility(val);
224
for(unsigned int i = 0; i < (*it)->pyramids.size(); i++)
225
if(all || (*it)->pyramids[i]->getNum() == num)
226
(*it)->pyramids[i]->setVisibility(val);
230
for(GModel::viter it = m->firstVertex(); it != m->lastVertex(); it++)
231
if(all || (*it)->tag() == num) (*it)->setVisibility(val, recursive);
234
for(GModel::eiter it = m->firstEdge(); it != m->lastEdge(); it++)
235
if(all || (*it)->tag() == num) (*it)->setVisibility(val, recursive);
238
for(GModel::fiter it = m->firstFace(); it != m->lastFace(); it++)
239
if(all || (*it)->tag() == num) (*it)->setVisibility(val, recursive);
242
for(GModel::riter it = m->firstRegion(); it != m->lastRegion(); it++)
243
if(all || (*it)->tag() == num) (*it)->setVisibility(val, recursive);
245
case 6: // physical point
246
for(GModel::viter it = m->firstVertex(); it != m->lastVertex(); it++)
247
for(unsigned int i = 0; i < (*it)->physicals.size(); i++)
248
if (all || std::abs((*it)->physicals[i]) == num) (*it)->setVisibility(val, recursive);
250
case 7: // physical line
251
for(GModel::eiter it = m->firstEdge(); it != m->lastEdge(); it++)
252
for(unsigned int i = 0; i < (*it)->physicals.size(); i++)
253
if (all || std::abs((*it)->physicals[i]) == num) (*it)->setVisibility(val, recursive);
255
case 8: // physical surface
256
for(GModel::fiter it = m->firstFace(); it != m->lastFace(); it++)
257
for(unsigned int i = 0; i < (*it)->physicals.size(); i++)
258
if (all || std::abs((*it)->physicals[i]) == num) (*it)->setVisibility(val, recursive);
260
case 9: // physical volume
261
for(GModel::riter it = m->firstRegion(); it != m->lastRegion(); it++)
262
for(unsigned int i = 0; i < (*it)->physicals.size(); i++)
263
if (all || std::abs((*it)->physicals[i]) == num) (*it)->setVisibility(val, recursive);
268
void VisElementary::setVisibility(char val, bool recursive)
270
_e->setVisibility(val, recursive);
273
void VisPhysical::setVisibility(char val, bool recursive)
276
for(unsigned int i = 0; i < _list.size(); i++)
277
_list[i]->setVisibility(val, recursive);
280
void VisPartition::setVisibility(char val, bool recursive)
282
GModel *m = GModel::current();
285
for(GModel::eiter it = m->firstEdge(); it != m->lastEdge(); it++){
286
for(unsigned int i = 0; i < (*it)->lines.size(); i++)
287
if((*it)->lines[i]->getPartition() == _tag)
288
(*it)->lines[i]->setVisibility(val);
290
for(GModel::fiter it = m->firstFace(); it != m->lastFace(); it++){
291
for(unsigned int i = 0; i < (*it)->triangles.size(); i++)
292
if((*it)->triangles[i]->getPartition() == _tag)
293
(*it)->triangles[i]->setVisibility(val);
294
for(unsigned int i = 0; i < (*it)->quadrangles.size(); i++)
295
if((*it)->quadrangles[i]->getPartition() == _tag)
296
(*it)->quadrangles[i]->setVisibility(val);
298
for(GModel::riter it = m->firstRegion(); it != m->lastRegion(); it++){
299
for(unsigned int i = 0; i < (*it)->tetrahedra.size(); i++)
300
if((*it)->tetrahedra[i]->getPartition() == _tag)
301
(*it)->tetrahedra[i]->setVisibility(val);
302
for(unsigned int i = 0; i < (*it)->hexahedra.size(); i++)
303
if((*it)->hexahedra[i]->getPartition() == _tag)
304
(*it)->hexahedra[i]->setVisibility(val);
305
for(unsigned int i = 0; i < (*it)->prisms.size(); i++)
306
if((*it)->prisms[i]->getPartition() == _tag)
307
(*it)->prisms[i]->setVisibility(val);
308
for(unsigned int i = 0; i < (*it)->pyramids.size(); i++)
309
if((*it)->pyramids[i]->getPartition() == _tag)
310
(*it)->pyramids[i]->setVisibility(val);