computeNormalDialog.cpp 3.39 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 32
	{
		QListWidgetItem* item = new QListWidgetItem(map->getName(), mapList);
		item->setCheckState(Qt::Unchecked);
		connect(map, SIGNAL(attributeModified(unsigned int, QString)), this, SLOT(attributeModified(unsigned int, QString)));
	}
Pierre Kraemer's avatar
Pierre Kraemer committed
33 34
}

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

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

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

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

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

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

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

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

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

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

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

95 96 97 98 99 100 101 102 103 104 105 106 107
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);
	}
}

108 109 110 111 112 113 114 115 116
void ComputeNormalDialog::attributeModified(unsigned int orbit, QString nameAttr)
{
	MapHandlerGen* map = static_cast<MapHandlerGen*>(QObject::sender());
//	if(orbit == VERTEX && nameAttr == )
//	{

//	}
}

Pierre Kraemer's avatar
Pierre Kraemer committed
117 118 119
} // namespace SCHNApps

} // namespace CGoGN