surface_render_dockTab.cpp 12.1 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),
Pierre Kraemer's avatar
Pierre Kraemer committed
16 17
	m_currentColorDial(0),
	b_updatingUI(false)
18

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

	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()));
36
	connect(bfcolorButton, SIGNAL(clicked()), this, SLOT(backColorClicked()));
37 38 39 40 41 42 43
	connect(m_colorDial,SIGNAL(colorSelected(const QColor&)),this,SLOT(colorSelected(const QColor&)));
}





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

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

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

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

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

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

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

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

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

Pierre Kraemer's avatar
Pierre Kraemer committed
182 183


Pierre Kraemer's avatar
Pierre Kraemer committed
184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204
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;
}

205 206 207 208 209 210 211
void Surface_Render_DockTab::backColorClicked()
{
	m_colorDial->show();
	m_colorDial->setCurrentColor(m_vertexColor);
	m_currentColorDial = 4;
}

Pierre Kraemer's avatar
Pierre Kraemer committed
212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227

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();
228
			m_plugin->pythonRecording("changeFaceColor", "", view->getName(), map->getName(), rgbCol[0], rgbCol[1], rgbCol[2]);
Pierre Kraemer's avatar
Pierre Kraemer committed
229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244
		}
	}

	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();
245
			m_plugin->pythonRecording("changeEdgeColor", "", view->getName(), map->getName(), rgbCol[0], rgbCol[1], rgbCol[2]);
Pierre Kraemer's avatar
Pierre Kraemer committed
246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261
		}
	}

	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();
262
			m_plugin->pythonRecording("changeVertexColor", "", view->getName(), map->getName(), rgbCol[0], rgbCol[1], rgbCol[2]);
Pierre Kraemer's avatar
Pierre Kraemer committed
263 264
		}
	}
265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281

	if (m_currentColorDial == 4)
	{
		m_backColor = col;
		bfcolorButton->setStyleSheet("QPushButton { background-color:" + col.name() + "}");

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

		View* view = m_schnapps->getSelectedView();
		MapHandlerGen* map = m_schnapps->getSelectedMap();
		if (view && map)
		{
			m_plugin->h_viewParameterSet[view][map].backColor = rgbCol;
			view->updateGL();
			m_plugin->pythonRecording("changeBackColor", "", view->getName(), map->getName(), rgbCol[0], rgbCol[1], rgbCol[2]);
		}
	}
Pierre Kraemer's avatar
Pierre Kraemer committed
282 283 284 285 286 287
}





Pierre Kraemer's avatar
Pierre Kraemer committed
288
void Surface_Render_DockTab::addPositionVBO(QString name)
Pierre Kraemer's avatar
Pierre Kraemer committed
289 290 291 292 293 294
{
	b_updatingUI = true;
	combo_positionVBO->addItem(name);
	b_updatingUI = false;
}

Pierre Kraemer's avatar
Pierre Kraemer committed
295
void Surface_Render_DockTab::removePositionVBO(QString name)
Pierre Kraemer's avatar
Pierre Kraemer committed
296 297 298 299
{
	b_updatingUI = true;
	int curIndex = combo_positionVBO->currentIndex();
	int index = combo_positionVBO->findText(name, Qt::MatchExactly);
300
	if (curIndex == index)
Pierre Kraemer's avatar
Pierre Kraemer committed
301 302 303 304 305
		combo_positionVBO->setCurrentIndex(0);
	combo_positionVBO->removeItem(index);
	b_updatingUI = false;
}

Pierre Kraemer's avatar
Pierre Kraemer committed
306
void Surface_Render_DockTab::addNormalVBO(QString name)
Pierre Kraemer's avatar
Pierre Kraemer committed
307 308 309 310 311 312
{
	b_updatingUI = true;
	combo_normalVBO->addItem(name);
	b_updatingUI = false;
}

Pierre Kraemer's avatar
Pierre Kraemer committed
313
void Surface_Render_DockTab::removeNormalVBO(QString name)
Pierre Kraemer's avatar
Pierre Kraemer committed
314 315 316 317
{
	b_updatingUI = true;
	int curIndex = combo_normalVBO->currentIndex();
	int index = combo_normalVBO->findText(name, Qt::MatchExactly);
318
	if (curIndex == index)
Pierre Kraemer's avatar
Pierre Kraemer committed
319 320 321 322 323
		combo_normalVBO->setCurrentIndex(0);
	combo_normalVBO->removeItem(index);
	b_updatingUI = false;
}

Pierre Kraemer's avatar
Pierre Kraemer committed
324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341
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
342
void Surface_Render_DockTab::updateMapParameters()
Pierre Kraemer's avatar
Pierre Kraemer committed
343 344 345 346 347
{
	b_updatingUI = true;

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

	combo_normalVBO->clear();
Pierre Kraemer's avatar
Pierre Kraemer committed
350 351
	combo_normalVBO->addItem("- select VBO -");

Pierre Kraemer's avatar
Pierre Kraemer committed
352 353 354
	combo_colorVBO->clear();
	combo_colorVBO->addItem("- select VBO -");

Pierre Kraemer's avatar
Pierre Kraemer committed
355 356 357
	View* view = m_schnapps->getSelectedView();
	MapHandlerGen* map = m_schnapps->getSelectedMap();

358
	if (view && map)
Pierre Kraemer's avatar
Pierre Kraemer committed
359 360 361 362 363 364
	{
		const MapParameters& p = m_plugin->h_viewParameterSet[view][map];

		unsigned int i = 1;
		foreach(Utils::VBO* vbo, map->getVBOSet().values())
		{
365
			if (vbo->dataSize() == 3)
Pierre Kraemer's avatar
Pierre Kraemer committed
366 367
			{
				combo_positionVBO->addItem(QString::fromStdString(vbo->name()));
368
				if (vbo == p.positionVBO)
Pierre Kraemer's avatar
Pierre Kraemer committed
369 370 371
					combo_positionVBO->setCurrentIndex(i);

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

Pierre Kraemer's avatar
Pierre Kraemer committed
375 376 377 378
				combo_colorVBO->addItem(QString::fromStdString(vbo->name()));
				if (vbo == p.colorVBO)
					combo_colorVBO->setCurrentIndex(i);

Pierre Kraemer's avatar
Pierre Kraemer committed
379 380 381 382 383 384 385 386 387 388
				++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);
389

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

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

396 397
		m_vertexColor = QColor(255 * p.vertexColor[0], 255 * p.vertexColor[1], 255 * p.vertexColor[2]);
		vcolorButton->setStyleSheet("QPushButton { background-color:" + m_vertexColor.name() + " }");
398 399 400

		m_backColor = QColor(255 * p.backColor[0], 255 * p.backColor[1], 255 * p.backColor[2]);
		bfcolorButton->setStyleSheet("QPushButton { background-color:" + m_backColor.name() + " }");
Pierre Kraemer's avatar
Pierre Kraemer committed
401 402 403 404 405 406 407 408
	}

	b_updatingUI = false;
}

} // namespace SCHNApps

} // namespace CGoGN