mapHandler.cpp 2.04 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
MapHandler::MapHandler(const QString& name, Window* window, CGoGN::GenericMap *map) :
8
	m_name(name),
9
	m_window(window),
10
	m_map(map)
11 12 13
{
//	connect(m_window, SIGNAL(viewRemoved(View*)), this, SLOT(cb_viewRemoved(View*)));
}
14 15 16

MapHandler::~MapHandler()
{
17 18
	foreach(CGoGN::Utils::VBO* vbo, h_vbo)
		delete vbo;
19 20 21 22 23

	if (m_map)
		delete m_map;
}

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

32 33 34
	CGoGN::Utils::VBO* vbo = new CGoGN::Utils::VBO();
	h_vbo.insert(name, vbo);
	return vbo;
35 36
}

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

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

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

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

/*********************************************************
 * 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();
	}
}
104 105 106 107 108

void MapHandler::cb_viewRemoved(View* view)
{
	unlinkView(view);
}