surface_render_dockTab.cpp 10.7 KB
Newer Older
Pierre Kraemer's avatar
Pierre Kraemer committed
1 2 3 4 5 6 7 8 9 10 11 12
#include "surface_render_dockTab.h"

#include "surface_render.h"
#include "schnapps.h"
#include "mapHandler.h"

namespace CGoGN
{

namespace SCHNApps
{

Pierre Kraemer's avatar
Pierre Kraemer committed
13
Surface_Render_DockTab::Surface_Render_DockTab(SCHNApps* s, Surface_Render_Plugin* p) :
Pierre Kraemer's avatar
Pierre Kraemer committed
14 15
	m_schnapps(s),
	m_plugin(p),
16 17 18
	b_updatingUI(false),
	m_currentColorDial(0)

Pierre Kraemer's avatar
Pierre Kraemer committed
19 20 21 22 23
{
	setupUi(this);

	connect(combo_positionVBO, SIGNAL(currentIndexChanged(int)), this, SLOT(positionVBOChanged(int)));
	connect(combo_normalVBO, SIGNAL(currentIndexChanged(int)), this, SLOT(normalVBOChanged(int)));
Pierre Kraemer's avatar
Pierre Kraemer committed
24
	connect(combo_colorVBO, SIGNAL(currentIndexChanged(int)), this, SLOT(colorVBOChanged(int)));
Pierre Kraemer's avatar
Pierre Kraemer committed
25 26 27 28 29
	connect(check_renderVertices, SIGNAL(toggled(bool)), this, SLOT(renderVerticesChanged(bool)));
	connect(slider_verticesScaleFactor, SIGNAL(valueChanged(int)), this, SLOT(verticesScaleFactorChanged(int)));
	connect(check_renderEdges, SIGNAL(toggled(bool)), this, SLOT(renderEdgesChanged(bool)));
	connect(check_renderFaces, SIGNAL(toggled(bool)), this, SLOT(renderFacesChanged(bool)));
	connect(group_faceShading, SIGNAL(buttonClicked(QAbstractButton*)), this, SLOT(faceStyleChanged(QAbstractButton*)));
30
	connect(check_renderBoundary, SIGNAL(toggled(bool)), this, SLOT(renderBoundaryChanged(bool)));
31 32 33 34 35 36 37 38 39 40 41 42

	m_colorDial  = new QColorDialog(m_diffuseColor,NULL);
	connect(dcolorButton,SIGNAL(clicked()),this,SLOT(diffuseColorClicked()));
	connect(scolorButton,SIGNAL(clicked()),this,SLOT(simpleColorClicked()));
	connect(vcolorButton,SIGNAL(clicked()),this,SLOT(vertexColorClicked()));
	connect(m_colorDial,SIGNAL(colorSelected(const QColor&)),this,SLOT(colorSelected(const QColor&)));
}





Pierre Kraemer's avatar
Pierre Kraemer committed
43
void Surface_Render_DockTab::positionVBOChanged(int index)
44
{
Pierre Kraemer's avatar
Pierre Kraemer committed
45
	if (!b_updatingUI)
46 47 48
	{
		View* view = m_schnapps->getSelectedView();
		MapHandlerGen* map = m_schnapps->getSelectedMap();
49
		if (view && map)
50
		{
Pierre Kraemer's avatar
Pierre Kraemer committed
51
			m_plugin->h_viewParameterSet[view][map].positionVBO = map->getVBO(combo_positionVBO->currentText());
52
			view->updateGL();
Sylvain Thery's avatar
Sylvain Thery committed
53
			m_plugin->pythonRecording("changeVertexColor", "", view->getName(), map->getName(), rgbCol[0], rgbCol[1], rgbCol[2]);
54 55
		}
	}
Pierre Kraemer's avatar
Pierre Kraemer committed
56 57
}

Pierre Kraemer's avatar
Pierre Kraemer committed
58
void Surface_Render_DockTab::normalVBOChanged(int index)
Pierre Kraemer's avatar
Pierre Kraemer committed
59
{
60
	if (!b_updatingUI)
Pierre Kraemer's avatar
Pierre Kraemer committed
61 62 63
	{
		View* view = m_schnapps->getSelectedView();
		MapHandlerGen* map = m_schnapps->getSelectedMap();
64
		if (view && map)
Pierre Kraemer's avatar
Pierre Kraemer committed
65
		{
Pierre Kraemer's avatar
Pierre Kraemer committed
66
			m_plugin->h_viewParameterSet[view][map].normalVBO = map->getVBO(combo_normalVBO->currentText());
Pierre Kraemer's avatar
Pierre Kraemer committed
67
			view->updateGL();
Sylvain Thery's avatar
Sylvain Thery committed
68
			m_plugin->pythonRecording("changePositionVBO", "", view->getName(), map->getName(), combo_positionVBO->currentText());
Pierre Kraemer's avatar
Pierre Kraemer committed
69 70 71 72
		}
	}
}

Pierre Kraemer's avatar
Pierre Kraemer committed
73
void Surface_Render_DockTab::colorVBOChanged(int index)
Pierre Kraemer's avatar
Pierre Kraemer committed
74
{
75
	if (!b_updatingUI)
Pierre Kraemer's avatar
Pierre Kraemer committed
76 77 78
	{
		View* view = m_schnapps->getSelectedView();
		MapHandlerGen* map = m_schnapps->getSelectedMap();
79
		if (view && map)
Pierre Kraemer's avatar
Pierre Kraemer committed
80
		{
Pierre Kraemer's avatar
Pierre Kraemer committed
81
			m_plugin->h_viewParameterSet[view][map].colorVBO = map->getVBO(combo_colorVBO->currentText());
Pierre Kraemer's avatar
Pierre Kraemer committed
82
			view->updateGL();
Sylvain Thery's avatar
Sylvain Thery committed
83
			m_plugin->pythonRecording("changeNormalVBO", "", view->getName(), map->getName(), combo_normalVBO->currentText());
Pierre Kraemer's avatar
Pierre Kraemer committed
84 85 86 87
		}
	}
}

Pierre Kraemer's avatar
Pierre Kraemer committed
88
void Surface_Render_DockTab::renderVerticesChanged(bool b)
Pierre Kraemer's avatar
Pierre Kraemer committed
89
{
90
	if (!b_updatingUI)
Pierre Kraemer's avatar
Pierre Kraemer committed
91 92 93
	{
		View* view = m_schnapps->getSelectedView();
		MapHandlerGen* map = m_schnapps->getSelectedMap();
94
		if (view && map)
Pierre Kraemer's avatar
Pierre Kraemer committed
95 96 97
		{
			m_plugin->h_viewParameterSet[view][map].renderVertices = b;
			view->updateGL();
Sylvain Thery's avatar
Sylvain Thery committed
98
			m_plugin->pythonRecording("changeRenderVertices", "", view->getName(), map->getName(), b);
Pierre Kraemer's avatar
Pierre Kraemer committed
99 100 101 102
		}
	}
}

Pierre Kraemer's avatar
Pierre Kraemer committed
103
void Surface_Render_DockTab::verticesScaleFactorChanged(int i)
Pierre Kraemer's avatar
Pierre Kraemer committed
104
{
105
	if (!b_updatingUI)
Pierre Kraemer's avatar
Pierre Kraemer committed
106 107 108
	{
		View* view = m_schnapps->getSelectedView();
		MapHandlerGen* map = m_schnapps->getSelectedMap();
109
		if (view && map)
Pierre Kraemer's avatar
Pierre Kraemer committed
110 111 112
		{
			m_plugin->h_viewParameterSet[view][map].verticesScaleFactor = i / 50.0;
			view->updateGL();
Sylvain Thery's avatar
Sylvain Thery committed
113
			m_plugin->pythonRecording("changeVerticesScaleFactor", "", view->getName(), map->getName(), i / 50.0);
Pierre Kraemer's avatar
Pierre Kraemer committed
114 115 116 117
		}
	}
}

Pierre Kraemer's avatar
Pierre Kraemer committed
118
void Surface_Render_DockTab::renderEdgesChanged(bool b)
Pierre Kraemer's avatar
Pierre Kraemer committed
119
{
120
	if (!b_updatingUI)
Pierre Kraemer's avatar
Pierre Kraemer committed
121 122 123
	{
		View* view = m_schnapps->getSelectedView();
		MapHandlerGen* map = m_schnapps->getSelectedMap();
124
		if (view && map)
Pierre Kraemer's avatar
Pierre Kraemer committed
125 126 127
		{
			m_plugin->h_viewParameterSet[view][map].renderEdges = b;
			view->updateGL();
Sylvain Thery's avatar
Sylvain Thery committed
128
			m_plugin->pythonRecording("changeRenderEdges", "", view->getName(), map->getName(), b);
Pierre Kraemer's avatar
Pierre Kraemer committed
129 130 131 132
		}
	}
}

Pierre Kraemer's avatar
Pierre Kraemer committed
133
void Surface_Render_DockTab::renderFacesChanged(bool b)
Pierre Kraemer's avatar
Pierre Kraemer committed
134
{
135
	if (!b_updatingUI)
Pierre Kraemer's avatar
Pierre Kraemer committed
136 137 138
	{
		View* view = m_schnapps->getSelectedView();
		MapHandlerGen* map = m_schnapps->getSelectedMap();
139
		if (view && map)
Pierre Kraemer's avatar
Pierre Kraemer committed
140 141 142
		{
			m_plugin->h_viewParameterSet[view][map].renderFaces = b;
			view->updateGL();
Sylvain Thery's avatar
Sylvain Thery committed
143
			m_plugin->pythonRecording("changeRenderFaces", "", view->getName(), map->getName(), b);
Pierre Kraemer's avatar
Pierre Kraemer committed
144 145 146 147
		}
	}
}

Pierre Kraemer's avatar
Pierre Kraemer committed
148
void Surface_Render_DockTab::faceStyleChanged(QAbstractButton* b)
Pierre Kraemer's avatar
Pierre Kraemer committed
149
{
150
	if (!b_updatingUI)
Pierre Kraemer's avatar
Pierre Kraemer committed
151 152 153
	{
		View* view = m_schnapps->getSelectedView();
		MapHandlerGen* map = m_schnapps->getSelectedMap();
154
		if (view && map)
Pierre Kraemer's avatar
Pierre Kraemer committed
155
		{
156
			if (radio_flatShading->isChecked())
Pierre Kraemer's avatar
Pierre Kraemer committed
157
				m_plugin->h_viewParameterSet[view][map].faceStyle = MapParameters::FLAT;
158
			else if (radio_phongShading->isChecked())
Pierre Kraemer's avatar
Pierre Kraemer committed
159 160
				m_plugin->h_viewParameterSet[view][map].faceStyle = MapParameters::PHONG;
			view->updateGL();
Sylvain Thery's avatar
Sylvain Thery committed
161
			m_plugin->pythonRecording("changeFacesStyle", "", view->getName(), map->getName(), m_plugin->h_viewParameterSet[view][map].faceStyle);
Pierre Kraemer's avatar
Pierre Kraemer committed
162 163 164 165
		}
	}
}

166 167
void Surface_Render_DockTab::renderBoundaryChanged(bool b)
{
168
	if (!b_updatingUI)
169 170 171
	{
		View* view = m_schnapps->getSelectedView();
		MapHandlerGen* map = m_schnapps->getSelectedMap();
172
		if (view && map)
173 174 175
		{
			m_plugin->h_viewParameterSet[view][map].renderBoundary = b;
			view->updateGL();
Sylvain Thery's avatar
Sylvain Thery committed
176
			m_plugin->pythonRecording("changeRenderBoundary", "", view->getName(), map->getName(), b);
177 178 179 180
		}
	}
}

Pierre Kraemer's avatar
Pierre Kraemer committed
181 182 183 184




Pierre Kraemer's avatar
Pierre Kraemer committed
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264
void Surface_Render_DockTab::diffuseColorClicked()
{
	m_colorDial->show();
	m_colorDial->setCurrentColor(m_diffuseColor);
	m_currentColorDial = 1;
}

void Surface_Render_DockTab::simpleColorClicked()
{
	m_colorDial->show();
	m_colorDial->setCurrentColor(m_simpleColor);
	m_currentColorDial = 2;
}

void Surface_Render_DockTab::vertexColorClicked()
{
	m_colorDial->show();
	m_colorDial->setCurrentColor(m_vertexColor);
	m_currentColorDial = 3;
}


void Surface_Render_DockTab::colorSelected(const QColor& col)
{
	if (m_currentColorDial == 1)
	{

		m_diffuseColor = col;
		dcolorButton->setStyleSheet("QPushButton { background-color:" + col.name() + "}");

		Geom::Vec4f rgbCol(1.0/255.0*m_diffuseColor.red(), 1.0/255.0*m_diffuseColor.green(),1.0/255.0*m_diffuseColor.blue(),0.0f);

		View* view = m_schnapps->getSelectedView();
		MapHandlerGen* map = m_schnapps->getSelectedMap();
		if (view && map)
		{
			m_plugin->h_viewParameterSet[view][map].diffuseColor = rgbCol;
			view->updateGL();
		}
	}

	if (m_currentColorDial == 2)
	{

		m_simpleColor = col;
		scolorButton->setStyleSheet("QPushButton { background-color:" + col.name() + "}");

		Geom::Vec4f rgbCol(1.0/255.0*m_simpleColor.red(), 1.0/255.0*m_simpleColor.green(),1.0/255.0*m_simpleColor.blue(),0.0f);

		View* view = m_schnapps->getSelectedView();
		MapHandlerGen* map = m_schnapps->getSelectedMap();
		if (view && map)
		{
			m_plugin->h_viewParameterSet[view][map].simpleColor = rgbCol;
			view->updateGL();
		}
	}

	if (m_currentColorDial == 3)
	{

		m_vertexColor = col;
		vcolorButton->setStyleSheet("QPushButton { background-color:" + col.name() + "}");

		Geom::Vec4f rgbCol(1.0/255.0*m_vertexColor.red(), 1.0/255.0*m_vertexColor.green(),1.0/255.0*m_vertexColor.blue(),0.0f);

		View* view = m_schnapps->getSelectedView();
		MapHandlerGen* map = m_schnapps->getSelectedMap();
		if (view && map)
		{
			m_plugin->h_viewParameterSet[view][map].vertexColor = rgbCol;
			view->updateGL();
		}
	}
}





Pierre Kraemer's avatar
Pierre Kraemer committed
265
void Surface_Render_DockTab::addPositionVBO(QString name)
Pierre Kraemer's avatar
Pierre Kraemer committed
266 267 268 269 270 271
{
	b_updatingUI = true;
	combo_positionVBO->addItem(name);
	b_updatingUI = false;
}

Pierre Kraemer's avatar
Pierre Kraemer committed
272
void Surface_Render_DockTab::removePositionVBO(QString name)
Pierre Kraemer's avatar
Pierre Kraemer committed
273 274 275 276
{
	b_updatingUI = true;
	int curIndex = combo_positionVBO->currentIndex();
	int index = combo_positionVBO->findText(name, Qt::MatchExactly);
277
	if (curIndex == index)
Pierre Kraemer's avatar
Pierre Kraemer committed
278 279 280 281 282
		combo_positionVBO->setCurrentIndex(0);
	combo_positionVBO->removeItem(index);
	b_updatingUI = false;
}

Pierre Kraemer's avatar
Pierre Kraemer committed
283
void Surface_Render_DockTab::addNormalVBO(QString name)
Pierre Kraemer's avatar
Pierre Kraemer committed
284 285 286 287 288 289
{
	b_updatingUI = true;
	combo_normalVBO->addItem(name);
	b_updatingUI = false;
}

Pierre Kraemer's avatar
Pierre Kraemer committed
290
void Surface_Render_DockTab::removeNormalVBO(QString name)
Pierre Kraemer's avatar
Pierre Kraemer committed
291 292 293 294
{
	b_updatingUI = true;
	int curIndex = combo_normalVBO->currentIndex();
	int index = combo_normalVBO->findText(name, Qt::MatchExactly);
295
	if (curIndex == index)
Pierre Kraemer's avatar
Pierre Kraemer committed
296 297 298 299 300
		combo_normalVBO->setCurrentIndex(0);
	combo_normalVBO->removeItem(index);
	b_updatingUI = false;
}

Pierre Kraemer's avatar
Pierre Kraemer committed
301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318
void Surface_Render_DockTab::addColorVBO(QString name)
{
	b_updatingUI = true;
	combo_colorVBO->addItem(name);
	b_updatingUI = false;
}

void Surface_Render_DockTab::removeColorVBO(QString name)
{
	b_updatingUI = true;
	int curIndex = combo_colorVBO->currentIndex();
	int index = combo_colorVBO->findText(name, Qt::MatchExactly);
	if (curIndex == index)
		combo_colorVBO->setCurrentIndex(0);
	combo_colorVBO->removeItem(index);
	b_updatingUI = false;
}

Pierre Kraemer's avatar
Pierre Kraemer committed
319
void Surface_Render_DockTab::updateMapParameters()
Pierre Kraemer's avatar
Pierre Kraemer committed
320 321 322 323 324
{
	b_updatingUI = true;

	combo_positionVBO->clear();
	combo_positionVBO->addItem("- select VBO -");
Pierre Kraemer's avatar
Pierre Kraemer committed
325 326

	combo_normalVBO->clear();
Pierre Kraemer's avatar
Pierre Kraemer committed
327 328 329 330 331
	combo_normalVBO->addItem("- select VBO -");

	View* view = m_schnapps->getSelectedView();
	MapHandlerGen* map = m_schnapps->getSelectedMap();

332
	if (view && map)
Pierre Kraemer's avatar
Pierre Kraemer committed
333 334 335 336 337 338
	{
		const MapParameters& p = m_plugin->h_viewParameterSet[view][map];

		unsigned int i = 1;
		foreach(Utils::VBO* vbo, map->getVBOSet().values())
		{
339
			if (vbo->dataSize() == 3)
Pierre Kraemer's avatar
Pierre Kraemer committed
340 341
			{
				combo_positionVBO->addItem(QString::fromStdString(vbo->name()));
342
				if (vbo == p.positionVBO)
Pierre Kraemer's avatar
Pierre Kraemer committed
343 344 345
					combo_positionVBO->setCurrentIndex(i);

				combo_normalVBO->addItem(QString::fromStdString(vbo->name()));
346
				if (vbo == p.normalVBO)
Pierre Kraemer's avatar
Pierre Kraemer committed
347 348
					combo_normalVBO->setCurrentIndex(i);

Pierre Kraemer's avatar
Pierre Kraemer committed
349 350 351 352
				combo_colorVBO->addItem(QString::fromStdString(vbo->name()));
				if (vbo == p.colorVBO)
					combo_colorVBO->setCurrentIndex(i);

Pierre Kraemer's avatar
Pierre Kraemer committed
353 354 355 356 357 358 359 360 361 362
				++i;
			}
		}

		check_renderVertices->setChecked(p.renderVertices);
		slider_verticesScaleFactor->setSliderPosition(p.verticesScaleFactor * 50.0);
		check_renderEdges->setChecked(p.renderEdges);
		check_renderFaces->setChecked(p.renderFaces);
		radio_flatShading->setChecked(p.faceStyle == MapParameters::FLAT);
		radio_phongShading->setChecked(p.faceStyle == MapParameters::PHONG);
363

364 365
		m_diffuseColor = QColor(255 * p.diffuseColor[0], 255 * p.diffuseColor[1], 255 * p.diffuseColor[2]);
		dcolorButton->setStyleSheet("QPushButton { background-color:" + m_diffuseColor.name() + " }");
366

367 368
		m_simpleColor = QColor(255 * p.simpleColor[0], 255 * p.simpleColor[1], 255 * p.simpleColor[2]);
		scolorButton->setStyleSheet("QPushButton { background-color:" + m_simpleColor.name() + " }");
369

370 371
		m_vertexColor = QColor(255 * p.vertexColor[0], 255 * p.vertexColor[1], 255 * p.vertexColor[2]);
		vcolorButton->setStyleSheet("QPushButton { background-color:" + m_vertexColor.name() + " }");
Pierre Kraemer's avatar
Pierre Kraemer committed
372 373 374 375 376 377 378 379
	}

	b_updatingUI = false;
}

} // namespace SCHNApps

} // namespace CGoGN