dialog_computeNormal.cpp 2.81 KB
Newer Older
1
#include "dialog_computeNormal.h"
Pierre Kraemer's avatar
Pierre Kraemer committed
2

3 4
#include "surface_differentialProperties.h"
#include "schnapps.h"
Pierre Kraemer's avatar
Pierre Kraemer committed
5 6 7 8 9 10 11 12
#include "mapHandler.h"

namespace CGoGN
{

namespace SCHNApps
{

13 14
Dialog_ComputeNormal::Dialog_ComputeNormal(SCHNApps* s) :
	m_schnapps(s),
Pierre Kraemer's avatar
Pierre Kraemer committed
15 16 17 18 19 20
	m_selectedMap(NULL)
{
	setupUi(this);

	normalAttributeName->setText("normal");

21 22
	connect(m_schnapps, SIGNAL(mapAdded(MapHandlerGen*)), this, SLOT(addMapToList(MapHandlerGen*)));
	connect(m_schnapps, SIGNAL(mapRemoved(MapHandlerGen*)), this, SLOT(removeMapFromList(MapHandlerGen*)));
Pierre Kraemer's avatar
Pierre Kraemer committed
23

24
	connect(list_maps, SIGNAL(itemSelectionChanged()), this, SLOT(selectedMapChanged()));
Pierre Kraemer's avatar
Pierre Kraemer committed
25

26
	foreach(MapHandlerGen* map, m_schnapps->getMapSet().values())
Pierre Kraemer's avatar
Pierre Kraemer committed
27
	{
28
		QListWidgetItem* item = new QListWidgetItem(map->getName(), list_maps);
Pierre Kraemer's avatar
Pierre Kraemer committed
29 30 31 32
		item->setCheckState(Qt::Unchecked);
	}
}

33
void Dialog_ComputeNormal::selectedMapChanged()
Pierre Kraemer's avatar
Pierre Kraemer committed
34 35 36 37
{
	if(m_selectedMap)
		disconnect(m_selectedMap, SIGNAL(attributeAdded(unsigned int, const QString&)), this, SLOT(addAttributeToList(unsigned int, const QString&)));

38
	QList<QListWidgetItem*> currentItems = list_maps->selectedItems();
Pierre Kraemer's avatar
Pierre Kraemer committed
39 40 41 42 43 44
	if(!currentItems.empty())
	{
		combo_positionAttribute->clear();
		combo_normalAttribute->clear();

		const QString& mapname = currentItems[0]->text();
45
		MapHandlerGen* mh = m_schnapps->getMap(mapname);
Pierre Kraemer's avatar
Pierre Kraemer committed
46 47 48 49

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

		unsigned int j = 0;
50 51
		const AttributeSet& attribs = mh->getAttributeSet(VERTEX);
		for(AttributeSet::const_iterator i = attribs.constBegin(); i != attribs.constEnd(); ++i)
Pierre Kraemer's avatar
Pierre Kraemer committed
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
		{
			if(i.value() == vec3TypeName)
			{
				combo_positionAttribute->addItem(i.key());
				combo_normalAttribute->addItem(i.key());

				++j;
			}
		}

		m_selectedMap = mh;
		connect(m_selectedMap, SIGNAL(attributeAdded(unsigned int, const QString&)), this, SLOT(addAttributeToList(unsigned int, const QString&)));
	}
	else
		m_selectedMap = NULL;
}

69
void Dialog_ComputeNormal::addMapToList(MapHandlerGen* m)
Pierre Kraemer's avatar
Pierre Kraemer committed
70
{
71
	QListWidgetItem* item = new QListWidgetItem(m->getName(), list_maps);
Pierre Kraemer's avatar
Pierre Kraemer committed
72 73 74
	item->setCheckState(Qt::Unchecked);
}

75
void Dialog_ComputeNormal::removeMapFromList(MapHandlerGen* m)
Pierre Kraemer's avatar
Pierre Kraemer committed
76
{
77
	QList<QListWidgetItem*> items = list_maps->findItems(m->getName(), Qt::MatchExactly);
Pierre Kraemer's avatar
Pierre Kraemer committed
78 79 80 81 82 83 84 85 86 87
	if(!items.empty())
		delete items[0];

	if(m_selectedMap == m)
	{
		disconnect(m_selectedMap, SIGNAL(attributeAdded(unsigned int, const QString&)), this, SLOT(addAttributeToList(unsigned int, const QString&)));
		m_selectedMap = NULL;
	}
}

88
void Dialog_ComputeNormal::addAttributeToList(unsigned int orbit, const QString& nameAttr)
Pierre Kraemer's avatar
Pierre Kraemer committed
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
{
	QString vec3TypeName = QString::fromStdString(nameOfType(PFP2::VEC3()));

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

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

} // namespace SCHNApps

} // namespace CGoGN