dialog_computeDistance.cpp 5.37 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181
#include "dialog_computeDistance.h"

#include "surface_distance.h"
#include "schnapps.h"
#include "mapHandler.h"

namespace CGoGN
{

namespace SCHNApps
{

Dialog_ComputeDistance::Dialog_ComputeDistance(SCHNApps* s) :
	m_schnapps(s),
	m_selectedMap1(NULL),
	m_selectedMap2(NULL)
{
	setupUi(this);

	distanceAttributeName_1->setText("distance");
	distanceAttributeName_2->setText("distance");

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

	connect(list_maps_1, SIGNAL(itemSelectionChanged()), this, SLOT(selectedMap1Changed()));
	connect(list_maps_2, SIGNAL(itemSelectionChanged()), this, SLOT(selectedMap2Changed()));

	foreach(MapHandlerGen* map, m_schnapps->getMapSet().values())
	{
		QListWidgetItem* item1 = new QListWidgetItem(map->getName(), list_maps_1);
		QListWidgetItem* item2 = new QListWidgetItem(map->getName(), list_maps_2);
	}
}

void Dialog_ComputeDistance::selectedMap1Changed()
{
	if(m_selectedMap1)
		disconnect(m_selectedMap1, SIGNAL(attributeAdded(unsigned int, const QString&)), this, SLOT(addAttributeToList1(unsigned int, const QString&)));

	QList<QListWidgetItem*> currentItems = list_maps_1->selectedItems();
	if(!currentItems.empty())
	{
		combo_positionAttribute_1->clear();
		combo_distanceAttribute_1->clear();

		const QString& mapname = currentItems[0]->text();
		MapHandlerGen* mh = m_schnapps->getMap(mapname);

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

		const AttributeSet& attribs = mh->getAttributeSet(VERTEX);
		for(AttributeSet::const_iterator i = attribs.constBegin(); i != attribs.constEnd(); ++i)
		{
			if(i.value() == vec3TypeName)
			{
				combo_positionAttribute_1->addItem(i.key());
			}
			if(i.value() == realTypeName)
			{
				combo_distanceAttribute_1->addItem(i.key());
			}
		}

		m_selectedMap1 = mh;
		connect(m_selectedMap1, SIGNAL(attributeAdded(unsigned int, const QString&)), this, SLOT(addAttributeToList1(unsigned int, const QString&)));
	}
	else
		m_selectedMap1 = NULL;
}

void Dialog_ComputeDistance::selectedMap2Changed()
{
	if(m_selectedMap2)
		disconnect(m_selectedMap2, SIGNAL(attributeAdded(unsigned int, const QString&)), this, SLOT(addAttributeToList2(unsigned int, const QString&)));

	QList<QListWidgetItem*> currentItems = list_maps_2->selectedItems();
	if(!currentItems.empty())
	{
		combo_positionAttribute_2->clear();
		combo_distanceAttribute_2->clear();

		const QString& mapname = currentItems[0]->text();
		MapHandlerGen* mh = m_schnapps->getMap(mapname);

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

		const AttributeSet& attribs = mh->getAttributeSet(VERTEX);
		for(AttributeSet::const_iterator i = attribs.constBegin(); i != attribs.constEnd(); ++i)
		{
			if(i.value() == vec3TypeName)
			{
				combo_positionAttribute_2->addItem(i.key());
			}
			if(i.value() == realTypeName)
			{
				combo_distanceAttribute_2->addItem(i.key());
			}
		}

		m_selectedMap2 = mh;
		connect(m_selectedMap2, SIGNAL(attributeAdded(unsigned int, const QString&)), this, SLOT(addAttributeToList2(unsigned int, const QString&)));
	}
	else
		m_selectedMap2 = NULL;
}

void Dialog_ComputeDistance::addMapToList(MapHandlerGen* map)
{
	QListWidgetItem* item1 = new QListWidgetItem(map->getName(), list_maps_1);
	QListWidgetItem* item2 = new QListWidgetItem(map->getName(), list_maps_2);
}

void Dialog_ComputeDistance::removeMapFromList(MapHandlerGen* map)
{
	QList<QListWidgetItem*> items1 = list_maps_1->findItems(map->getName(), Qt::MatchExactly);
	if(!items1.empty())
		delete items1[0];

	QList<QListWidgetItem*> items2 = list_maps_2->findItems(map->getName(), Qt::MatchExactly);
	if(!items2.empty())
		delete items2[0];

	if(m_selectedMap1 == map)
	{
		disconnect(m_selectedMap1, SIGNAL(attributeAdded(unsigned int, const QString&)), this, SLOT(addAttributeToList1(unsigned int, const QString&)));
		m_selectedMap1 = NULL;
	}

	if(m_selectedMap2 == map)
	{
		disconnect(m_selectedMap2, SIGNAL(attributeAdded(unsigned int, const QString&)), this, SLOT(addAttributeToList2(unsigned int, const QString&)));
		m_selectedMap2 = NULL;
	}
}

void Dialog_ComputeDistance::addAttributeToList1(unsigned int orbit, const QString& nameAttr)
{
	if(orbit == VERTEX)
	{
		QString vec3TypeName = QString::fromStdString(nameOfType(PFP2::VEC3()));
		QString realTypeName = QString::fromStdString(nameOfType(PFP2::REAL()));

		const QString& typeAttr = m_selectedMap1->getAttributeTypeName(orbit, nameAttr);

		if(typeAttr == vec3TypeName)
		{
			combo_positionAttribute_1->addItem(nameAttr);
		}
		if(typeAttr == realTypeName)
		{
			combo_distanceAttribute_1->addItem(nameAttr);
		}
	}
}

void Dialog_ComputeDistance::addAttributeToList2(unsigned int orbit, const QString& nameAttr)
{
	if(orbit == VERTEX)
	{
		QString vec3TypeName = QString::fromStdString(nameOfType(PFP2::VEC3()));
		QString realTypeName = QString::fromStdString(nameOfType(PFP2::REAL()));

		const QString& typeAttr = m_selectedMap2->getAttributeTypeName(orbit, nameAttr);

		if(typeAttr == vec3TypeName)
		{
			combo_positionAttribute_2->addItem(nameAttr);
		}
		if(typeAttr == realTypeName)
		{
			combo_distanceAttribute_2->addItem(nameAttr);
		}
	}
}

} // namespace SCHNApps

} // namespace CGoGN