mapHandler.cpp 4.24 KB
Newer Older
Pierre Kraemer's avatar
Pierre Kraemer committed
1 2 3 4 5 6 7 8 9 10 11 12
#include "mapHandler.h"

namespace CGoGN
{

namespace SCHNApps
{

MapHandlerGen::MapHandlerGen(const QString& name, SCHNApps* s, GenericMap* map) :
	m_name(name),
	m_schnapps(s),
	m_map(map),
13
	m_frame(NULL),
14
	m_bbDrawer(NULL),
15
	m_render(NULL)
16 17 18
{
	m_frame = new qglviewer::ManipulatedFrame();
}
Pierre Kraemer's avatar
Pierre Kraemer committed
19 20 21

MapHandlerGen::~MapHandlerGen()
{
Pierre Kraemer's avatar
Pierre Kraemer committed
22 23
	if(m_frame)
		delete m_frame;
24 25
	if(m_bbDrawer)
		delete m_bbDrawer;
Pierre Kraemer's avatar
Pierre Kraemer committed
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
	if(m_render)
		delete m_render;
	foreach(CGoGN::Utils::VBO* vbo, m_vbo)
		delete vbo;
}

/*********************************************************
 * MANAGE VBOs
 *********************************************************/

Utils::VBO* MapHandlerGen::createVBO(const AttributeMultiVectorGen* attr)
{
	if(attr)
	{
		QString name = QString::fromStdString(attr->getName());
		Utils::VBO* vbo = getVBO(name);
		if(!vbo)
		{
			vbo = new Utils::VBO(attr->getName());
			vbo->updateData(attr);
			m_vbo.insert(name, vbo);
			emit(vboAdded(vbo));
		}
		else
			vbo->updateData(attr);
		return vbo;
	}
	else
		return NULL;
}

Utils::VBO* MapHandlerGen::createVBO(const AttributeHandlerGen& attr)
{
	return createVBO(attr.getDataVectorGen());
}

Utils::VBO* MapHandlerGen::createVBO(const QString& name)
{
	return createVBO(static_cast<AttribMap*>(m_map)->getAttributeVectorGen(VERTEX, name.toUtf8().constData()));
}

void MapHandlerGen::updateVBO(const AttributeMultiVectorGen* attr)
{
	if(attr)
	{
		Utils::VBO* vbo = getVBO(QString::fromStdString(attr->getName()));
		if(vbo)
			vbo->updateData(attr);
	}
}

void MapHandlerGen::updateVBO(const AttributeHandlerGen& attr)
{
	return updateVBO(attr.getDataVectorGen());
}

void MapHandlerGen::updateVBO(const QString& name)
{
	updateVBO(static_cast<AttribMap*>(m_map)->getAttributeVectorGen(VERTEX, name.toUtf8().constData()));
}

Utils::VBO* MapHandlerGen::getVBO(const QString& name) const
{
	if (m_vbo.contains(name))
		return m_vbo[name];
	else
		return NULL;
}

void MapHandlerGen::deleteVBO(const QString& name)
{
	if (m_vbo.contains(name))
	{
		Utils::VBO* vbo = m_vbo[name];
		m_vbo.remove(name);
		emit(vboRemoved(vbo));
		delete vbo;
	}
}

Pierre Kraemer's avatar
Pierre Kraemer committed
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
/*********************************************************
 * MANAGE CELL SELECTORS
 *********************************************************/

CellSelectorGen* MapHandlerGen::addCellSelector(unsigned int orbit, const QString& name)
{
	if(m_cellSelectors[orbit].contains(name))
		return NULL;

	CellSelectorGen* cs = NULL;

	switch(orbit)
	{
		case DART: cs = new CellSelector<DART>(*m_map, name); break;
		case VERTEX: cs = new CellSelector<VERTEX>(*m_map, name); break;
		case EDGE: cs = new CellSelector<EDGE>(*m_map, name); break;
		case FACE: cs = new CellSelector<FACE>(*m_map, name); break;
		case VOLUME: cs = new CellSelector<VOLUME>(*m_map, name); break;
	}

	if(!cs)
		return NULL;

	m_cellSelectors[orbit].insert(name, cs);
	emit(cellSelectorAdded(orbit, name));
131

132
	connect(cs, SIGNAL(selectedCellsChanged()), this, SLOT(selectedCellsChanged()));
133

Pierre Kraemer's avatar
Pierre Kraemer committed
134 135 136 137 138 139 140 141 142 143
	return cs;
}

void MapHandlerGen::removeCellSelector(unsigned int orbit, const QString& name)
{
	CellSelectorGen* cs = getCellSelector(orbit, name);
	if (cs)
	{
		m_cellSelectors[orbit].remove(name);
		emit(cellSelectorRemoved(orbit, name));
144 145 146

		disconnect(cs, SIGNAL(selectedCellsChanged()), this, SIGNAL(selectedCellsChanged()));

Pierre Kraemer's avatar
Pierre Kraemer committed
147 148 149 150 151 152 153 154 155 156 157 158
		delete cs;
	}
}

CellSelectorGen* MapHandlerGen::getCellSelector(unsigned int orbit, const QString& name) const
{
	if (m_cellSelectors[orbit].contains(name))
		return m_cellSelectors[orbit][name];
	else
		return NULL;
}

159 160 161 162 163 164
void MapHandlerGen::selectedCellsChanged()
{
	CellSelectorGen* cs = static_cast<CellSelectorGen*>(QObject::sender());
	emit(selectedCellsChanged(cs));
}

165 166 167 168 169 170 171 172 173 174 175 176
void MapHandlerGen::updateMutuallyExclusiveSelectors(unsigned int orbit)
{
	QList<CellSelectorGen*> mex;
	foreach(CellSelectorGen* cs, m_cellSelectors[orbit])
	{
		if(cs->isMutuallyExclusive())
			mex.append(cs);
	}
	foreach(CellSelectorGen* cs, m_cellSelectors[orbit])
		cs->setMutuallyExclusiveSet(mex);
}

Pierre Kraemer's avatar
Pierre Kraemer committed
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194
/*********************************************************
 * MANAGE LINKED VIEWS
 *********************************************************/

void MapHandlerGen::linkView(View* view)
{
	if(view && !l_views.contains(view))
		l_views.push_back(view);
}

void MapHandlerGen::unlinkView(View* view)
{
	l_views.removeOne(view);
}

} // namespace SCHNApps

} // namespace CGoGN