computeNormalDialog.cpp 2.16 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
ComputeNormalDialog::ComputeNormalDialog(Window* w) : m_window(w)
Pierre Kraemer's avatar
Pierre Kraemer committed
14 15 16
{
	setupUi(this);

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

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

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

Pierre Kraemer's avatar
Pierre Kraemer committed
24 25 26 27 28
	const QList<MapHandlerGen*>& maps = m_window->getMapsList();
	foreach(MapHandlerGen* map, maps)
		mapList->addItem(map->getName());
}

29
void ComputeNormalDialog::selectedMapChanged()
Pierre Kraemer's avatar
Pierre Kraemer committed
30 31 32 33 34
{
	QList<QListWidgetItem*> currentItems = mapList->selectedItems();
	if(!currentItems.empty())
	{
		combo_positionAttribute->clear();
35
		combo_normalAttribute->clear();
Pierre Kraemer's avatar
Pierre Kraemer committed
36 37 38 39 40 41 42 43 44
		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
45
		std::string vec3TypeName = nameOfType(PFP2::VEC3());
46
		unsigned int j = 0;
Pierre Kraemer's avatar
Pierre Kraemer committed
47 48 49
		for(unsigned int i = 0; i < names.size(); ++i)
		{
			if(types[i] == vec3TypeName)
50
			{
Pierre Kraemer's avatar
Pierre Kraemer committed
51
				combo_positionAttribute->addItem(QString::fromStdString(names[i]));
52
				if(names[i] == "position") // try to select a position attribute named "position"
53
					combo_positionAttribute->setCurrentIndex(j);
54 55 56 57 58

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

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

65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
void ComputeNormalDialog::addMapToList(MapHandlerGen* m)
{
	mapList->addItem(m->getName());
}

void ComputeNormalDialog::removeMapFromList(MapHandlerGen* m)
{
	for(int i = 0; i < mapList->count(); ++i)
	{
		if(mapList->item(i)->text() == m->getName())
		{
			delete mapList->item(i);
			return;
		}
	}
}

Pierre Kraemer's avatar
Pierre Kraemer committed
82 83 84
} // namespace SCHNApps

} // namespace CGoGN