surface_selection_dockTab.cpp 3.5 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
#include "surface_selection_dockTab.h"

#include "surface_selection.h"
#include "mapHandler.h"

namespace CGoGN
{

namespace SCHNApps
{

Surface_Selection_DockTab::Surface_Selection_DockTab(SCHNApps* s, Surface_Selection_Plugin* p) :
	m_schnapps(s),
	m_plugin(p),
	b_updatingUI(false)
{
	setupUi(this);

	connect(combo_positionAttribute, SIGNAL(currentIndexChanged(int)), this, SLOT(positionAttributeChanged(int)));
20
	connect(combo_normalAttribute, SIGNAL(currentIndexChanged(int)), this, SLOT(normalAttributeChanged(int)));
21
	connect(combo_selectionMethod, SIGNAL(currentIndexChanged(int)), this, SLOT(selectionMethodChanged(int)));
22 23 24 25 26 27 28 29 30 31 32
}





void Surface_Selection_DockTab::positionAttributeChanged(int index)
{
	if(!b_updatingUI)
	{
		MapHandlerGen* map = m_schnapps->getSelectedMap();
33
		if(map)
Pierre Kraemer's avatar
Pierre Kraemer committed
34 35 36
		{
			MapHandler<PFP2>* mh = static_cast<MapHandler<PFP2>*>(map);
			m_plugin->h_parameterSet[map].positionAttribute = mh->getAttribute<PFP2::VEC3, VERTEX>(combo_positionAttribute->currentText());
Sylvain Thery's avatar
Sylvain Thery committed
37
			m_plugin->pythonRecording("changePositionAttribute", "", map->getName(), combo_positionAttribute->currentText());
Pierre Kraemer's avatar
Pierre Kraemer committed
38
		}
39 40 41
	}
}

42 43 44 45 46 47
void Surface_Selection_DockTab::normalAttributeChanged(int index)
{
	if(!b_updatingUI)
	{
		MapHandlerGen* map = m_schnapps->getSelectedMap();
		if(map)
Pierre Kraemer's avatar
Pierre Kraemer committed
48 49 50
		{
			MapHandler<PFP2>* mh = static_cast<MapHandler<PFP2>*>(map);
			m_plugin->h_parameterSet[map].normalAttribute = mh->getAttribute<PFP2::VEC3, VERTEX>(combo_normalAttribute->currentText());
Sylvain Thery's avatar
Sylvain Thery committed
51
			m_plugin->pythonRecording("changeNormalAttribute", "", map->getName(), combo_normalAttribute->currentText());
Pierre Kraemer's avatar
Pierre Kraemer committed
52
		}
53 54 55
	}
}

56 57 58 59 60
void Surface_Selection_DockTab::selectionMethodChanged(int index)
{
	if(!b_updatingUI)
	{
		MapHandlerGen* map = m_schnapps->getSelectedMap();
Sylvain Thery's avatar
Sylvain Thery committed
61 62
		if (map)
		{
63
			m_plugin->h_parameterSet[map].selectionMethod = SelectionMethod(index);
Sylvain Thery's avatar
Sylvain Thery committed
64 65 66
			m_plugin->pythonRecording("changeSelectionMethod", "", map->getName(), index);
		}

67 68 69 70 71 72 73
	}
}





74 75 76 77 78 79
void Surface_Selection_DockTab::addVertexAttribute(const QString& nameAttr)
{
	b_updatingUI = true;
	QString vec3TypeName = QString::fromStdString(nameOfType(PFP2::VEC3()));
	const QString& typeAttr = m_schnapps->getSelectedMap()->getAttributeTypeName(VERTEX, nameAttr);
	if(typeAttr == vec3TypeName)
80
	{
81
		combo_positionAttribute->addItem(nameAttr);
82 83
		combo_normalAttribute->addItem(nameAttr);
	}
84 85 86
	b_updatingUI = false;
}

87 88 89 90 91 92
void Surface_Selection_DockTab::updateMapParameters()
{
	b_updatingUI = true;

	combo_positionAttribute->clear();
	combo_positionAttribute->addItem("- select attribute -");
93 94
	combo_normalAttribute->clear();
	combo_normalAttribute->addItem("- select attribute -");
95 96 97

	MapHandlerGen* map = m_schnapps->getSelectedMap();

98
	if(map)
99
	{
100
		const MapParameters& p = m_plugin->h_parameterSet[map];
101 102 103 104 105 106 107 108 109 110 111 112 113

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

		unsigned int i = 1;
		const AttributeSet& attribs = map->getAttributeSet(VERTEX);
		for(AttributeSet::const_iterator it = attribs.constBegin(); it != attribs.constEnd(); ++it)
		{
			if(it.value() == vec3TypeName)
			{
				combo_positionAttribute->addItem(it.key());
				if(p.positionAttribute.isValid() && it.key() == QString::fromStdString(p.positionAttribute.name()))
					combo_positionAttribute->setCurrentIndex(i);

114 115 116 117
				combo_normalAttribute->addItem(it.key());
				if(p.normalAttribute.isValid() && it.key() == QString::fromStdString(p.normalAttribute.name()))
					combo_normalAttribute->setCurrentIndex(i);

118 119 120
				++i;
			}
		}
121 122

		combo_selectionMethod->setCurrentIndex(p.selectionMethod);
123 124 125 126 127 128 129 130
	}

	b_updatingUI = false;
}

} // namespace SCHNApps

} // namespace CGoGN