surface_deformation_dockTab.cpp 4.88 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
#include "surface_deformation_dockTab.h"

#include "surface_deformation.h"
#include "schnapps.h"
#include "mapHandler.h"

namespace CGoGN
{

namespace SCHNApps
{

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

	connect(combo_positionAttribute, SIGNAL(currentIndexChanged(int)), this, SLOT(positionAttributeChanged(int)));
	connect(combo_lockedSelector, SIGNAL(currentIndexChanged(int)), this, SLOT(lockedSelectorChanged(int)));
	connect(combo_handleSelector, SIGNAL(currentIndexChanged(int)), this, SLOT(handleSelectorChanged(int)));
	connect(button_start_stop, SIGNAL(clicked()), this, SLOT(startStopButtonClicked()));
}





void Surface_Deformation_DockTab::positionAttributeChanged(int index)
{
	if(!b_updatingUI)
	{
		MapHandlerGen* map = m_schnapps->getSelectedMap();
		if(map)
		{
			if(index == 0)
				;
			else
				m_plugin->h_parameterSet[map].positionAttribute = map->getAttribute<PFP2::VEC3, VERTEX>(combo_positionAttribute->currentText());
		}
	}
}

void Surface_Deformation_DockTab::lockedSelectorChanged(int index)
{
	if(!b_updatingUI)
	{
		MapHandlerGen* map = m_schnapps->getSelectedMap();
		if(map)
			m_plugin->h_parameterSet[map].lockedSelector = map->getCellSelector<VERTEX>(combo_lockedSelector->currentText());
	}
}

void Surface_Deformation_DockTab::handleSelectorChanged(int index)
{
	if(!b_updatingUI)
	{
		MapHandlerGen* map = m_schnapps->getSelectedMap();
		if(map)
			m_plugin->h_parameterSet[map].handleSelector = map->getCellSelector<VERTEX>(combo_handleSelector->currentText());
	}
}

void Surface_Deformation_DockTab::startStopButtonClicked()
{
	if(!b_updatingUI)
	{
		MapHandlerGen* map = m_schnapps->getSelectedMap();
		if(map)
			m_plugin->toggleMapDeformation(map);
	}
}





void Surface_Deformation_DockTab::addVertexAttribute(const QString& name)
{
	b_updatingUI = true;
	QString vec3TypeName = QString::fromStdString(nameOfType(PFP2::VEC3()));
	const QString& typeAttr = m_schnapps->getSelectedMap()->getAttributeTypeName(VERTEX, name);
	if(typeAttr == vec3TypeName)
		combo_positionAttribute->addItem(name);
	b_updatingUI = false;
}

void Surface_Deformation_DockTab::addVertexSelector(const QString& name)
{
	b_updatingUI = true;
	combo_lockedSelector->addItem(name);
	combo_handleSelector->addItem(name);
	b_updatingUI = false;
}

void Surface_Deformation_DockTab::removeVertexSelector(const QString& name)
{
	b_updatingUI = true;
	int curIndex = combo_lockedSelector->currentIndex();
	int index = combo_lockedSelector->findText(name, Qt::MatchExactly);
	if(curIndex == index)
		combo_lockedSelector->setCurrentIndex(0);
	combo_lockedSelector->removeItem(index);

	curIndex = combo_handleSelector->currentIndex();
	index = combo_handleSelector->findText(name, Qt::MatchExactly);
	if(curIndex == index)
		combo_handleSelector->setCurrentIndex(0);
	combo_handleSelector->removeItem(index);
	b_updatingUI = false;
}

void Surface_Deformation_DockTab::mapParametersInitialized(bool b)
{
116
	b_updatingUI = true;
117 118 119 120 121
	combo_positionAttribute->setEnabled(!b);
	combo_lockedSelector->setEnabled(!b);
	combo_handleSelector->setEnabled(!b);
	if(b) button_start_stop->setText("Stop");
	else button_start_stop->setText("Start");
122
	b_updatingUI = false;
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
}

void Surface_Deformation_DockTab::updateMapParameters()
{
	b_updatingUI = true;

	combo_positionAttribute->clear();
	combo_positionAttribute->addItem("- select attribute -");
	combo_lockedSelector->clear();
	combo_lockedSelector->addItem("- select selector -");
	combo_handleSelector->clear();
	combo_handleSelector->addItem("- select selector -");

	MapHandlerGen* map = m_schnapps->getSelectedMap();

	if(map)
	{
		const MapParameters& p = m_plugin->h_parameterSet[map];

		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);

				++i;
			}
		}

		i = 1;
		const CellSelectorSet& selectors = map->getCellSelectorSet(VERTEX);
		for(CellSelectorSet::const_iterator it = selectors.constBegin(); it != selectors.constEnd(); ++it)
		{
			combo_lockedSelector->addItem(it.key());
			if(p.lockedSelector && it.key() == p.lockedSelector->getName())
				combo_lockedSelector->setCurrentIndex(i);

			combo_handleSelector->addItem(it.key());
			if(p.handleSelector && it.key() == p.handleSelector->getName())
				combo_handleSelector->setCurrentIndex(i);

			++i;
		}

		if(p.initialized)
			button_start_stop->setText("Stop");
		else
			button_start_stop->setText("Start");
	}
178 179

	b_updatingUI = false;
180 181 182 183 184
}

} // namespace SCHNApps

} // namespace CGoGN