mapHandler.cpp 1.86 KB
Newer Older
1
#include "mapHandler.h"
2

3
#include "system.h"
4
#include "Topology/generic/genericmap.h"
5
#include "Utils/vbo.h"
6

7 8
MapHandler::MapHandler(const QString& name, CGoGN::GenericMap *map) :
	m_name(name),
9 10 11 12 13
	m_map(map)
{}

MapHandler::~MapHandler()
{
14 15
	foreach(CGoGN::Utils::VBO* vbo, h_vbo)
		delete vbo;
16 17 18 19 20

	if (m_map)
		delete m_map;
}

21
CGoGN::Utils::VBO* MapHandler::addVBO(const QString& name)
22
{
23
	if (h_vbo.contains(name))
24
	{
25 26
		System::Error::code = System::Error::VBO_EXISTS;
		return NULL;
27 28
	}

29 30 31
	CGoGN::Utils::VBO* vbo = new CGoGN::Utils::VBO();
	h_vbo.insert(name, vbo);
	return vbo;
32 33
}

34
void MapHandler::removeVBO(const QString& name)
35
{
36
	if (h_vbo.contains(name))
37
	{
38 39 40
		CGoGN::Utils::VBO* vbo = h_vbo[name];
		h_vbo.remove(name);
		delete vbo;
41 42 43
	}
}

44
CGoGN::Utils::VBO* MapHandler::getVBO(const QString& name)
45
{
46 47 48
	if (h_vbo.contains(name))
		return h_vbo[name];
	else
49
	{
50 51
		System::Error::code = System::Error::VBO_DOES_NOT_EXIST;
		return NULL;
52 53 54
	}
}

55
CGoGN::Utils::VBO* MapHandler::findFirstVBOMatching(const QRegExp& regexp)
56
{
57 58
	QHash<QString, CGoGN::Utils::VBO*>::iterator it;
	for (it = h_vbo.begin(); it != h_vbo.end(); ++it)
59
	{
60 61
		if (it.key().contains(regexp))
			return it.value();
62 63 64 65
	}
	return NULL;
}

66
QList<CGoGN::Utils::VBO*> MapHandler::findVBOsMatching(const QRegExp& regexp)
67
{
68 69 70
	QList<CGoGN::Utils::VBO*> rlist;
	QHash<QString, CGoGN::Utils::VBO*>::iterator it;
	for (it = h_vbo.begin(); it != h_vbo.end(); ++it)
71
	{
72 73
		if (it.key().contains(regexp))
			rlist.push_back(it.value());
74 75 76
	}
	return rlist;
}
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100

/*********************************************************
 * MANAGE VIEWS
 *********************************************************/

bool MapHandler::linkView(View* view)
{
	if(view && !l_views.contains(view))
	{
		l_views.push_back(view);
		view->updateGL();
		return true;
	}
	else
		return false;
}

void MapHandler::unlinkView(View* view)
{
	if(l_views.removeOne(view))
	{
		view->updateGL();
	}
}