computeNormalDialog.cpp 2.92 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
28
29
30
	const QList<MapHandlerGen*>& maps = m_window->getMapsList();
	foreach(MapHandlerGen* map, maps)
		mapList->addItem(map->getName());
}

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

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

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

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

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

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

61
62
				++j;
			}
Pierre Kraemer's avatar
Pierre Kraemer committed
63
		}
64
65

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

72
73
74
75
76
77
78
void ComputeNormalDialog::addMapToList(MapHandlerGen* m)
{
	mapList->addItem(m->getName());
}

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

	if(m_selectedMap == m)
84
	{
85
		disconnect(m_selectedMap, SIGNAL(attributeAdded(unsigned int, const QString&)), this, SLOT(addAttributeToList(unsigned int, const QString&)));
86
		m_selectedMap = NULL;
87
88
89
	}
}

90
91
92
93
94
95
96
97
98
99
100
101
102
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
103
104
105
} // namespace SCHNApps

} // namespace CGoGN