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

#include "differentialProperties.h"
#include "window.h"
#include "mapHandler.h"

namespace CGoGN
{

namespace SCHNApps
{

13 14 15
ComputeNormalDialog::ComputeNormalDialog(Window* w) :
	m_window(w),
	m_selectedMap(NULL)
Pierre Kraemer's avatar
Pierre Kraemer committed
16 17 18
{
	setupUi(this);

19
	normalAttributeName->setText("normal");
20 21 22 23

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

24
	connect(mapList, SIGNAL(itemSelectionChanged()), this, SLOT(selectedMapChanged()));
25

Pierre Kraemer's avatar
Pierre Kraemer committed
26 27
	const QList<MapHandlerGen*>& maps = m_window->getMapsList();
	foreach(MapHandlerGen* map, maps)
28 29 30 31
	{
		QListWidgetItem* item = new QListWidgetItem(map->getName(), mapList);
		item->setCheckState(Qt::Unchecked);
	}
Pierre Kraemer's avatar
Pierre Kraemer committed
32 33
}

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

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

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

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

50
		unsigned int j = 0;
51 52
		const AttributeHash& attribs = mh->getAttributesList(VERTEX);
		for(AttributeHash::const_iterator i = attribs.constBegin(); i != attribs.constEnd(); ++i)
Pierre Kraemer's avatar
Pierre Kraemer committed
53
		{
54
			if(i.value() == vec3TypeName)
55
			{
56 57
				combo_positionAttribute->addItem(i.key());
				if(i.key() == "position") // try to select a position attribute named "position"
58
					combo_positionAttribute->setCurrentIndex(j);
59

60 61
				combo_normalAttribute->addItem(i.key());
				if(i.key() == "normal") // try to select a normal attribute named "normal"
62 63
					combo_normalAttribute->setCurrentIndex(j);

64 65
				++j;
			}
Pierre Kraemer's avatar
Pierre Kraemer committed
66
		}
67 68

		m_selectedMap = mh;
69
		connect(m_selectedMap, SIGNAL(attributeAdded(unsigned int, const QString&)), this, SLOT(addAttributeToList(unsigned int, const QString&)));
Pierre Kraemer's avatar
Pierre Kraemer committed
70
	}
71 72
	else
		m_selectedMap = NULL;
Pierre Kraemer's avatar
Pierre Kraemer committed
73 74
}

75 76
void ComputeNormalDialog::addMapToList(MapHandlerGen* m)
{
77 78
	QListWidgetItem* item = new QListWidgetItem(m->getName(), mapList);
	item->setCheckState(Qt::Unchecked);
79 80 81 82
}

void ComputeNormalDialog::removeMapFromList(MapHandlerGen* m)
{
83 84 85 86 87
	QList<QListWidgetItem*> items = mapList->findItems(m->getName(), Qt::MatchExactly);
	if(!items.empty())
		delete items[0];

	if(m_selectedMap == m)
88
	{
89
		disconnect(m_selectedMap, SIGNAL(attributeAdded(unsigned int, const QString&)), this, SLOT(addAttributeToList(unsigned int, const QString&)));
90
		m_selectedMap = NULL;
91 92 93
	}
}

94 95 96 97 98 99 100 101 102 103 104 105 106
void ComputeNormalDialog::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);
		combo_normalAttribute->addItem(nameAttr);
	}
}

Pierre Kraemer's avatar
Pierre Kraemer committed
107 108 109
} // namespace SCHNApps

} // namespace CGoGN