surface_selection_dockTab.cpp 7.14 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
#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);

Sylvain Thery's avatar
Sylvain Thery committed
19 20
	combo_color->setEnabled(true);

21
	connect(combo_positionAttribute, SIGNAL(currentIndexChanged(int)), this, SLOT(positionAttributeChanged(int)));
22
	connect(combo_normalAttribute, SIGNAL(currentIndexChanged(int)), this, SLOT(normalAttributeChanged(int)));
23
	connect(combo_selectionMethod, SIGNAL(currentIndexChanged(int)), this, SLOT(selectionMethodChanged(int)));
Sylvain Thery's avatar
Sylvain Thery committed
24 25
	connect(slider_verticesScaleFactor, SIGNAL(valueChanged(int)), this, SLOT(verticesScaleFactorChanged(int)));
	connect(slider_verticesScaleFactor, SIGNAL(sliderPressed()), this, SLOT(verticesScaleFactorPressed()));
Sylvain Thery's avatar
Sylvain Thery committed
26
	connect(combo_color, SIGNAL(currentIndexChanged(int)), this, SLOT(colorChanged(int)));
27
	connect(button_clear, SIGNAL(pressed()), this, SLOT(clearPressed()));
Sylvain Thery's avatar
Sylvain Thery committed
28 29

	// force color for map parameter updating
Sylvain Thery's avatar
bugs  
Sylvain Thery committed
30
//	combo_color->setCurrentIndex(0);
31 32 33 34 35 36 37 38 39 40 41
}





void Surface_Selection_DockTab::positionAttributeChanged(int index)
{
	if(!b_updatingUI)
	{
		MapHandlerGen* map = m_schnapps->getSelectedMap();
42
		if(map)
Pierre Kraemer's avatar
Pierre Kraemer committed
43 44 45
		{
			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
46
			m_plugin->updateSelectedCellsRendering();
Sylvain Thery's avatar
Sylvain Thery committed
47
			m_plugin->pythonRecording("changePositionAttribute", "", map->getName(), combo_positionAttribute->currentText());
Pierre Kraemer's avatar
Pierre Kraemer committed
48
		}
49 50 51
	}
}

52 53 54 55 56 57
void Surface_Selection_DockTab::normalAttributeChanged(int index)
{
	if(!b_updatingUI)
	{
		MapHandlerGen* map = m_schnapps->getSelectedMap();
		if(map)
Pierre Kraemer's avatar
Pierre Kraemer committed
58 59 60
		{
			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
61
			m_plugin->updateSelectedCellsRendering();
Sylvain Thery's avatar
Sylvain Thery committed
62
			m_plugin->pythonRecording("changeNormalAttribute", "", map->getName(), combo_normalAttribute->currentText());
Pierre Kraemer's avatar
Pierre Kraemer committed
63
		}
64 65 66
	}
}

67 68 69 70 71
void Surface_Selection_DockTab::selectionMethodChanged(int index)
{
	if(!b_updatingUI)
	{
		MapHandlerGen* map = m_schnapps->getSelectedMap();
Sylvain Thery's avatar
Sylvain Thery committed
72 73
		if (map)
		{
74
			m_plugin->h_parameterSet[map].selectionMethod = SelectionMethod(index);
Sylvain Thery's avatar
Sylvain Thery committed
75 76
			m_plugin->pythonRecording("changeSelectionMethod", "", map->getName(), index);
		}
Sylvain Thery's avatar
Sylvain Thery committed
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
		
		switch (index)
		{
		case 0:
			this->spin_angle_radius->setHidden(true);
			this->label_angle_radius->setText(QString());
			break;
		case 1:
			this->spin_angle_radius->setHidden(false);
			this->spin_angle_radius->setValue(m_plugin->m_selectionRadiusBase * m_plugin->m_selectionRadiusCoeff);
			this->label_angle_radius->setText(QString("Radius:"));
			break;
		case 2:
			this->spin_angle_radius->setHidden(false);
			this->spin_angle_radius->setValue(m_plugin->m_normalAngleThreshold / M_PI * 180);
			this->label_angle_radius->setText(QString("Angle:"));
			break;
		default:
			break;
		}
Sylvain Thery's avatar
Sylvain Thery committed
97

98 99 100
	}
}

Sylvain Thery's avatar
Sylvain Thery committed
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
void Surface_Selection_DockTab::verticesScaleFactorPressed()
{
	if (!b_updatingUI)
	{
		MapHandlerGen* map = m_schnapps->getSelectedMap();
		if (map)
		{
			m_plugin->h_parameterSet[map].basePSradius = map->getBBdiagSize() / (std::sqrt(map->getNbOrbits(EDGE)));
			m_plugin->pythonRecording("changeVerticesBaseSize", "", map->getName(), m_plugin->h_parameterSet[map].basePSradius);

			View* view = m_schnapps->getSelectedView();
			if (view)
				view->updateGL();
		}
	}
}

118

Sylvain Thery's avatar
Sylvain Thery committed
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
void Surface_Selection_DockTab::verticesScaleFactorChanged(int i)
{
	if (!b_updatingUI)
	{
		MapHandlerGen* map = m_schnapps->getSelectedMap();
		if (map)
		{
			m_plugin->h_parameterSet[map].verticesScaleFactor = i / 50.0;
			m_plugin->pythonRecording("changeVerticesScaleFactor", "", map->getName(), i / 50.0);

			View* view = m_schnapps->getSelectedView();
			if (view)
				view->updateGL();

		}
	}
}
136 137 138



139 140 141 142 143 144
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)
145
	{
146
		combo_positionAttribute->addItem(nameAttr);
147 148
		combo_normalAttribute->addItem(nameAttr);
	}
149 150 151
	b_updatingUI = false;
}

Sylvain Thery's avatar
Sylvain Thery committed
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174

void Surface_Selection_DockTab::colorChanged(int i)
{
	if (!b_updatingUI)
	{
		View* view = m_schnapps->getSelectedView();
		MapHandlerGen* map = m_schnapps->getSelectedMap();

		if (view && map )
		{
			QColor& col = m_plugin->h_parameterSet[map].color;
			if (col != combo_color->color())
			{
				col = combo_color->color();
				m_plugin->updateSelectedCellsRendering();
				m_plugin->pythonRecording("changeSelectedColor", "", map->getName(), combo_color->color().name());
			}
			view->updateGL();
		}
	}
}


175 176 177 178 179 180
void Surface_Selection_DockTab::clearPressed()
{
	if (!b_updatingUI)
	{
		MapHandlerGen* map = m_schnapps->getSelectedMap();
		unsigned int orbit = m_schnapps->getCurrentOrbit();
181 182
		CellSelectorGen* sel = m_schnapps->getSelectedSelector(orbit);
		if (map && sel)
183
		{
184 185
			m_plugin->clearSelection(map->getName(), orbit, sel->getName());
			m_plugin->pythonRecording("clearSelection", "", map->getName(), orbit, sel->getName());
186 187 188 189
		}
	}
}

190 191 192 193 194 195
void Surface_Selection_DockTab::updateMapParameters()
{
	b_updatingUI = true;

	combo_positionAttribute->clear();
	combo_positionAttribute->addItem("- select attribute -");
196 197
	combo_normalAttribute->clear();
	combo_normalAttribute->addItem("- select attribute -");
198 199 200

	MapHandlerGen* map = m_schnapps->getSelectedMap();

201
	if(map)
202
	{
203
		const MapParameters& p = m_plugin->h_parameterSet[map];
204 205 206 207 208 209 210 211 212 213 214 215 216

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

217 218 219 220
				combo_normalAttribute->addItem(it.key());
				if(p.normalAttribute.isValid() && it.key() == QString::fromStdString(p.normalAttribute.name()))
					combo_normalAttribute->setCurrentIndex(i);

221 222 223
				++i;
			}
		}
224 225

		combo_selectionMethod->setCurrentIndex(p.selectionMethod);
Sylvain Thery's avatar
Sylvain Thery committed
226
		combo_color->setColor(p.color);
227 228

		slider_verticesScaleFactor->setValue(int(50.0*p.verticesScaleFactor));
Sylvain Thery's avatar
Sylvain Thery committed
229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249

		switch (p.selectionMethod)
		{
		case 0:
			this->spin_angle_radius->setHidden(true);
			this->label_angle_radius->setText(QString());
			break;
		case 1:
			this->spin_angle_radius->setHidden(false);
			this->spin_angle_radius->setValue(m_plugin->m_selectionRadiusBase * m_plugin->m_selectionRadiusCoeff);
			this->label_angle_radius->setText(QString("Radius:"));
			break;
		case 2:
			this->spin_angle_radius->setHidden(false);
			this->spin_angle_radius->setValue(m_plugin->m_normalAngleThreshold / M_PI * 180);
			this->label_angle_radius->setText(QString("Angle:"));
			break;
		default:
			break;
		}

250 251 252 253 254 255 256 257
	}

	b_updatingUI = false;
}

} // namespace SCHNApps

} // namespace CGoGN