subdivideSurfaceDialog.cpp 2.65 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12
#include "subdivideSurfaceDialog.h"

#include "subdivideSurface.h"
#include "window.h"
#include "mapHandler.h"

namespace CGoGN
{

namespace SCHNApps
{

13 14 15
SubdivideSurfaceDialog::SubdivideSurfaceDialog(Window* w) :
	m_window(w),
	m_selectedMap(NULL)
16 17 18
{
	setupUi(this);

19 20 21
	connect(m_window, SIGNAL(mapAdded(MapHandlerGen*)), this, SLOT(addMapToList(MapHandlerGen*)));
	connect(m_window, SIGNAL(mapRemoved(MapHandlerGen*)), this, SLOT(removeMapFromList(MapHandlerGen*)));

22
	connect(mapList, SIGNAL(itemSelectionChanged()), this, SLOT(selectedMapChanged()));
23

24 25 26 27 28
	const QList<MapHandlerGen*>& maps = m_window->getMapsList();
	foreach(MapHandlerGen* map, maps)
		mapList->addItem(map->getName());
}

29
void SubdivideSurfaceDialog::selectedMapChanged()
30
{
31
	if(m_selectedMap)
32
		disconnect(m_selectedMap, SIGNAL(attributeAdded(unsigned int, const QString&)), this, SLOT(addAttributeToList(unsigned int, const QString&)));
33

34 35 36 37
	QList<QListWidgetItem*> currentItems = mapList->selectedItems();
	if(!currentItems.empty())
	{
		combo_positionAttribute->clear();
38

39 40
		const QString& mapname = currentItems[0]->text();
		MapHandlerGen* mh = m_window->getMap(mapname);
41 42 43

		QString vec3TypeName = QString::fromStdString(nameOfType(PFP2::VEC3()));

44
		unsigned int j = 0;
45 46
		const AttributeHash& attribs = mh->getAttributesList(VERTEX);
		for(AttributeHash::const_iterator i = attribs.constBegin(); i != attribs.constEnd(); ++i)
47
		{
48
			if(i.value() == vec3TypeName)
49
			{
50 51
				combo_positionAttribute->addItem(i.key());
				if(i.key() == "position") // try to select a position attribute named "position"
52 53 54 55 56
					combo_positionAttribute->setCurrentIndex(j);

				++j;
			}
		}
57 58

		m_selectedMap = mh;
59
		connect(m_selectedMap, SIGNAL(attributeAdded(unsigned int, const QString&)), this, SLOT(addAttributeToList(unsigned int, const QString&)));
60
	}
61 62
	else
		m_selectedMap = NULL;
63 64
}

65 66 67 68 69 70 71
void SubdivideSurfaceDialog::addMapToList(MapHandlerGen* m)
{
	mapList->addItem(m->getName());
}

void SubdivideSurfaceDialog::removeMapFromList(MapHandlerGen* m)
{
72 73 74 75 76
	QList<QListWidgetItem*> items = mapList->findItems(m->getName(), Qt::MatchExactly);
	if(!items.empty())
		delete items[0];

	if(m_selectedMap == m)
77
	{
78
		disconnect(m_selectedMap, SIGNAL(attributeAdded(unsigned int, const QString&)), this, SLOT(addAttributeToList(unsigned int, const QString&)));
79
		m_selectedMap = NULL;
80 81 82
	}
}

83 84 85 86 87 88 89 90 91 92 93 94
void SubdivideSurfaceDialog::addAttributeToList(unsigned int orbit, const QString& nameAttr)
{
	QString vec3TypeName = QString::fromStdString(nameOfType(PFP2::VEC3()));

	const QString& typeAttr = m_selectedMap->getAttributeTypeName(orbit, nameAttr);

	if(typeAttr == vec3TypeName)
	{
		combo_positionAttribute->addItem(nameAttr);
	}
}

95 96 97
} // namespace SCHNApps

} // namespace CGoGN