computeNormalDialog.cpp 2.51 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(refreshUI()));
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::refreshUI()
Pierre Kraemer's avatar
Pierre Kraemer committed
32
{
33
34
35
	if(m_selectedMap)
		disconnect(m_selectedMap, SIGNAL(attributeAdded()), this, SLOT(refreshUI()));

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();
Pierre Kraemer's avatar
Pierre Kraemer committed
41
42
43
44
45
46
47
48
49
		const QString& mapname = currentItems[0]->text();
		MapHandlerGen* mh = m_window->getMap(mapname);
		GenericMap* map = mh->getGenericMap();
		AttributeContainer& cont = map->getAttributeContainer<VERTEX>();

		std::vector<std::string> names;
		std::vector<std::string> types;
		cont.getAttributesNames(names);
		cont.getAttributesTypes(types);
Pierre Kraemer's avatar
Pierre Kraemer committed
50
		std::string vec3TypeName = nameOfType(PFP2::VEC3());
51
		unsigned int j = 0;
Pierre Kraemer's avatar
Pierre Kraemer committed
52
53
54
		for(unsigned int i = 0; i < names.size(); ++i)
		{
			if(types[i] == vec3TypeName)
55
			{
Pierre Kraemer's avatar
Pierre Kraemer committed
56
				combo_positionAttribute->addItem(QString::fromStdString(names[i]));
57
				if(names[i] == "position") // try to select a position attribute named "position"
58
					combo_positionAttribute->setCurrentIndex(j);
59
60
61
62
63

				combo_normalAttribute->addItem(QString::fromStdString(names[i]));
				if(names[i] == "normal") // try to select a normal attribute named "normal"
					combo_normalAttribute->setCurrentIndex(j);

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

		m_selectedMap = mh;
		connect(m_selectedMap, SIGNAL(attributeAdded()), this, SLOT(refreshUI()));
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
77
78
79
80
81
void ComputeNormalDialog::addMapToList(MapHandlerGen* m)
{
	mapList->addItem(m->getName());
}

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

	if(m_selectedMap == m)
87
	{
88
89
		disconnect(m_selectedMap, SIGNAL(attributeAdded()), this, SLOT(refreshUI()));
		m_selectedMap = NULL;
90
91
92
	}
}

Pierre Kraemer's avatar
Pierre Kraemer committed
93
94
95
} // namespace SCHNApps

} // namespace CGoGN