dialog_computeNormal.cpp 2.86 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
		{
			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;
}

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

74
void Dialog_ComputeNormal::removeMapFromList(MapHandlerGen* map)
Pierre Kraemer's avatar
Pierre Kraemer committed
75
{
76
	QList<QListWidgetItem*> items = list_maps->findItems(map->getName(), Qt::MatchExactly);
Pierre Kraemer's avatar
Pierre Kraemer committed
77 78 79
	if(!items.empty())
		delete items[0];

80
	if(m_selectedMap == map)
Pierre Kraemer's avatar
Pierre Kraemer committed
81 82 83 84 85 86
	{
		disconnect(m_selectedMap, SIGNAL(attributeAdded(unsigned int, const QString&)), this, SLOT(addAttributeToList(unsigned int, const QString&)));
		m_selectedMap = NULL;
	}
}

87
void Dialog_ComputeNormal::addAttributeToList(unsigned int orbit, const QString& nameAttr)
Pierre Kraemer's avatar
Pierre Kraemer committed
88
{
89 90 91
	if(orbit == VERTEX)
	{
		QString vec3TypeName = QString::fromStdString(nameOfType(PFP2::VEC3()));
Pierre Kraemer's avatar
Pierre Kraemer committed
92

93
		const QString& typeAttr = m_selectedMap->getAttributeTypeName(orbit, nameAttr);
Pierre Kraemer's avatar
Pierre Kraemer committed
94

95 96 97 98 99
		if(typeAttr == vec3TypeName)
		{
			combo_positionAttribute->addItem(nameAttr);
			combo_normalAttribute->addItem(nameAttr);
		}
Pierre Kraemer's avatar
Pierre Kraemer committed
100 101 102 103 104 105
	}
}

} // namespace SCHNApps

} // namespace CGoGN