surfaceDeformationDockTab.cpp 3.44 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
#include "surfaceDeformationDockTab.h"

#include "surfaceDeformation.h"
#include "window.h"
#include "mapHandler.h"

namespace CGoGN
{

namespace SCHNApps
{

SurfaceDeformationDockTab::SurfaceDeformationDockTab(Window* w, SurfaceDeformationPlugin* p) :
	m_window(w),
	m_plugin(p),
	b_refreshingUI(false)
{
	setupUi(this);

	connect(mapList, SIGNAL(itemSelectionChanged()), this, SLOT(selectedMapChanged()));
	connect(combo_positionAttribute, SIGNAL(currentIndexChanged(int)), this, SLOT(positionAttributeChanged(int)));
	connect(radio_locked, SIGNAL(toggled(bool)), this, SLOT(selectLockedVertices(bool)));
	connect(radio_handle, SIGNAL(toggled(bool)), this, SLOT(selectHandleVertices(bool)));
}

void SurfaceDeformationDockTab::refreshUI(ParameterSet* params)
{
	m_currentParams = params;

	b_refreshingUI = true;

	mapList->clear();
	combo_positionAttribute->clear();

	MapHandlerGen* mh = params->selectedMap;

	QHash<QString, PerMapParameterSet*>::const_iterator i = params->perMap.constBegin();
	while (i != params->perMap.constEnd())
	{
		mapList->addItem(i.key());
		if(mh != NULL && i.key() == mh->getName())
		{
			QList<QListWidgetItem*> item = mapList->findItems(mh->getName(), Qt::MatchExactly);
			item[0]->setSelected(true);

			PerMapParameterSet* p = params->perMap[mh->getName()];

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

			unsigned int j = 0;
			const AttributeHash& attribs = mh->getAttributesList(VERTEX);
			for(AttributeHash::const_iterator i = attribs.constBegin(); i != attribs.constEnd(); ++i)
			{
				if(i.value() == vec3TypeName)
				{
					combo_positionAttribute->addItem(i.key());
					if(i.key() == QString::fromStdString(p->positionAttribute.name()))
						combo_positionAttribute->setCurrentIndex(j);
					++j;
				}
			}

			radio_locked->setChecked(p->verticesSelectionMode == LOCKED);
			radio_handle->setChecked(p->verticesSelectionMode == HANDLE);
		}
		++i;
	}

	b_refreshingUI = false;
}

void SurfaceDeformationDockTab::selectedMapChanged()
{
	if(!b_refreshingUI)
	{
		QList<QListWidgetItem*> currentItems = mapList->selectedItems();
		if(!currentItems.empty())
78
			m_plugin->changeSelectedMap(m_window->getCurrentView(), m_window->getMap(currentItems[0]->text()));
79 80 81 82 83 84 85 86 87
	}
}

void SurfaceDeformationDockTab::positionAttributeChanged(int index)
{
	if(!b_refreshingUI)
	{
		View* view = m_window->getCurrentView();
		MapHandlerGen* map = m_currentParams->selectedMap;
88 89
		if(map)
			m_plugin->changePositionAttribute(view, map, map->getAttribute<PFP2::VEC3, VERTEX>(combo_positionAttribute->currentText()), true);
90 91 92 93 94 95 96 97 98
	}
}

void SurfaceDeformationDockTab::selectLockedVertices(bool b)
{
	if(!b_refreshingUI)
	{
		View* view = m_window->getCurrentView();
		MapHandlerGen* map = m_currentParams->selectedMap;
99 100
		if(map)
			m_plugin->changeVerticesSelectionMode(view, map, LOCKED, true);
101 102 103 104 105 106 107 108 109
	}
}

void SurfaceDeformationDockTab::selectHandleVertices(bool b)
{
	if(!b_refreshingUI)
	{
		View* view = m_window->getCurrentView();
		MapHandlerGen* map = m_currentParams->selectedMap;
110 111
		if(map)
			m_plugin->changeVerticesSelectionMode(view, map, HANDLE, true);
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129
	}
}

void SurfaceDeformationDockTab::addAttributeToList(unsigned int orbit, const QString& nameAttr)
{
	QString vec3TypeName = QString::fromStdString(nameOfType(PFP2::VEC3()));

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

	if(typeAttr == vec3TypeName)
	{
		combo_positionAttribute->addItem(nameAttr);
	}
}

} // namespace SCHNApps

} // namespace CGoGN