surface_render_dockTab.cpp 9.93 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 24 25 26 27 28
{
	setupUi(this);

	connect(combo_positionVBO, SIGNAL(currentIndexChanged(int)), this, SLOT(positionVBOChanged(int)));
	connect(combo_normalVBO, SIGNAL(currentIndexChanged(int)), this, SLOT(normalVBOChanged(int)));
	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*)));
29
	connect(check_renderBoundary, SIGNAL(toggled(bool)), this, SLOT(renderBoundaryChanged(bool)));
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

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

}



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();
75
		if (view && map)
76 77 78
		{
			m_plugin->h_viewParameterSet[view][map].diffuseColor = rgbCol;
			view->updateGL();
Sylvain Thery's avatar
Sylvain Thery committed
79
			m_plugin->pythonRecording("changeFaceColor", "", view->getName(), map->getName(), rgbCol[0], rgbCol[1], rgbCol[2]);
80 81 82 83 84 85 86 87 88 89 90 91 92
		}
	}

	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();
93
		if (view && map)
94 95 96
		{
			m_plugin->h_viewParameterSet[view][map].simpleColor = rgbCol;
			view->updateGL();
Sylvain Thery's avatar
Sylvain Thery committed
97
			m_plugin->pythonRecording("changeEdgeColor", "", view->getName(), map->getName(), rgbCol[0], rgbCol[1], rgbCol[2]);
98 99 100 101 102 103 104 105 106 107 108 109 110
		}
	}

	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();
111
		if (view && map)
112 113 114
		{
			m_plugin->h_viewParameterSet[view][map].vertexColor = rgbCol;
			view->updateGL();
Sylvain Thery's avatar
Sylvain Thery committed
115
			m_plugin->pythonRecording("changeVertexColor", "", view->getName(), map->getName(), rgbCol[0], rgbCol[1], rgbCol[2]);
116 117
		}
	}
Pierre Kraemer's avatar
Pierre Kraemer committed
118 119
}

Pierre Kraemer's avatar
Pierre Kraemer committed
120 121 122 123 124




void Surface_Render_DockTab::positionVBOChanged(int index)
Pierre Kraemer's avatar
Pierre Kraemer committed
125
{
126
	if (!b_updatingUI)
Pierre Kraemer's avatar
Pierre Kraemer committed
127 128 129
	{
		View* view = m_schnapps->getSelectedView();
		MapHandlerGen* map = m_schnapps->getSelectedMap();
130
		if (view && map)
Pierre Kraemer's avatar
Pierre Kraemer committed
131 132 133
		{
			m_plugin->h_viewParameterSet[view][map].positionVBO = map->getVBO(combo_positionVBO->currentText());
			view->updateGL();
Sylvain Thery's avatar
Sylvain Thery committed
134
			m_plugin->pythonRecording("changePositionVBO", "", view->getName(), map->getName(), combo_positionVBO->currentText());
Pierre Kraemer's avatar
Pierre Kraemer committed
135 136 137 138
		}
	}
}

Pierre Kraemer's avatar
Pierre Kraemer committed
139
void Surface_Render_DockTab::normalVBOChanged(int index)
Pierre Kraemer's avatar
Pierre Kraemer committed
140
{
141
	if (!b_updatingUI)
Pierre Kraemer's avatar
Pierre Kraemer committed
142 143 144
	{
		View* view = m_schnapps->getSelectedView();
		MapHandlerGen* map = m_schnapps->getSelectedMap();
145
		if (view && map)
Pierre Kraemer's avatar
Pierre Kraemer committed
146 147 148
		{
			m_plugin->h_viewParameterSet[view][map].normalVBO = map->getVBO(combo_normalVBO->currentText());
			view->updateGL();
Sylvain Thery's avatar
Sylvain Thery committed
149
			m_plugin->pythonRecording("changeNormalVBO", "", view->getName(), map->getName(), combo_normalVBO->currentText());
Pierre Kraemer's avatar
Pierre Kraemer committed
150 151 152 153
		}
	}
}

Pierre Kraemer's avatar
Pierre Kraemer committed
154
void Surface_Render_DockTab::renderVerticesChanged(bool b)
Pierre Kraemer's avatar
Pierre Kraemer committed
155
{
156
	if (!b_updatingUI)
Pierre Kraemer's avatar
Pierre Kraemer committed
157 158 159
	{
		View* view = m_schnapps->getSelectedView();
		MapHandlerGen* map = m_schnapps->getSelectedMap();
160
		if (view && map)
Pierre Kraemer's avatar
Pierre Kraemer committed
161 162 163
		{
			m_plugin->h_viewParameterSet[view][map].renderVertices = b;
			view->updateGL();
Sylvain Thery's avatar
Sylvain Thery committed
164
			m_plugin->pythonRecording("changeRenderVertices", "", view->getName(), map->getName(), b);
Pierre Kraemer's avatar
Pierre Kraemer committed
165 166 167 168
		}
	}
}

Pierre Kraemer's avatar
Pierre Kraemer committed
169
void Surface_Render_DockTab::verticesScaleFactorChanged(int i)
Pierre Kraemer's avatar
Pierre Kraemer committed
170
{
171
	if (!b_updatingUI)
Pierre Kraemer's avatar
Pierre Kraemer committed
172 173 174
	{
		View* view = m_schnapps->getSelectedView();
		MapHandlerGen* map = m_schnapps->getSelectedMap();
175
		if (view && map)
Pierre Kraemer's avatar
Pierre Kraemer committed
176 177 178
		{
			m_plugin->h_viewParameterSet[view][map].verticesScaleFactor = i / 50.0;
			view->updateGL();
Sylvain Thery's avatar
Sylvain Thery committed
179
			m_plugin->pythonRecording("changeVerticesScaleFactor", "", view->getName(), map->getName(), i / 50.0);
Pierre Kraemer's avatar
Pierre Kraemer committed
180 181 182 183
		}
	}
}

Pierre Kraemer's avatar
Pierre Kraemer committed
184
void Surface_Render_DockTab::renderEdgesChanged(bool b)
Pierre Kraemer's avatar
Pierre Kraemer committed
185
{
186
	if (!b_updatingUI)
Pierre Kraemer's avatar
Pierre Kraemer committed
187 188 189
	{
		View* view = m_schnapps->getSelectedView();
		MapHandlerGen* map = m_schnapps->getSelectedMap();
190
		if (view && map)
Pierre Kraemer's avatar
Pierre Kraemer committed
191 192 193
		{
			m_plugin->h_viewParameterSet[view][map].renderEdges = b;
			view->updateGL();
Sylvain Thery's avatar
Sylvain Thery committed
194
			m_plugin->pythonRecording("changeRenderEdges", "", view->getName(), map->getName(), b);
Pierre Kraemer's avatar
Pierre Kraemer committed
195 196 197 198
		}
	}
}

Pierre Kraemer's avatar
Pierre Kraemer committed
199
void Surface_Render_DockTab::renderFacesChanged(bool b)
Pierre Kraemer's avatar
Pierre Kraemer committed
200
{
201
	if (!b_updatingUI)
Pierre Kraemer's avatar
Pierre Kraemer committed
202 203 204
	{
		View* view = m_schnapps->getSelectedView();
		MapHandlerGen* map = m_schnapps->getSelectedMap();
205
		if (view && map)
Pierre Kraemer's avatar
Pierre Kraemer committed
206 207 208
		{
			m_plugin->h_viewParameterSet[view][map].renderFaces = b;
			view->updateGL();
Sylvain Thery's avatar
Sylvain Thery committed
209
			m_plugin->pythonRecording("changeRenderFaces", "", view->getName(), map->getName(), b);
Pierre Kraemer's avatar
Pierre Kraemer committed
210 211 212 213
		}
	}
}

Pierre Kraemer's avatar
Pierre Kraemer committed
214
void Surface_Render_DockTab::faceStyleChanged(QAbstractButton* b)
Pierre Kraemer's avatar
Pierre Kraemer committed
215
{
216
	if (!b_updatingUI)
Pierre Kraemer's avatar
Pierre Kraemer committed
217 218 219
	{
		View* view = m_schnapps->getSelectedView();
		MapHandlerGen* map = m_schnapps->getSelectedMap();
220
		if (view && map)
Pierre Kraemer's avatar
Pierre Kraemer committed
221
		{
222
			if (radio_flatShading->isChecked())
Pierre Kraemer's avatar
Pierre Kraemer committed
223
				m_plugin->h_viewParameterSet[view][map].faceStyle = MapParameters::FLAT;
224
			else if (radio_phongShading->isChecked())
Pierre Kraemer's avatar
Pierre Kraemer committed
225 226
				m_plugin->h_viewParameterSet[view][map].faceStyle = MapParameters::PHONG;
			view->updateGL();
Sylvain Thery's avatar
Sylvain Thery committed
227
			m_plugin->pythonRecording("changeFacesStyle", "", view->getName(), map->getName(), m_plugin->h_viewParameterSet[view][map].faceStyle);
Pierre Kraemer's avatar
Pierre Kraemer committed
228 229 230 231
		}
	}
}

232 233
void Surface_Render_DockTab::renderBoundaryChanged(bool b)
{
234
	if (!b_updatingUI)
235 236 237
	{
		View* view = m_schnapps->getSelectedView();
		MapHandlerGen* map = m_schnapps->getSelectedMap();
238
		if (view && map)
239 240 241
		{
			m_plugin->h_viewParameterSet[view][map].renderBoundary = b;
			view->updateGL();
Sylvain Thery's avatar
Sylvain Thery committed
242
			m_plugin->pythonRecording("changeRenderBoundary", "", view->getName(), map->getName(), b);
243 244 245 246
		}
	}
}

Pierre Kraemer's avatar
Pierre Kraemer committed
247 248 249 250




Pierre Kraemer's avatar
Pierre Kraemer committed
251
void Surface_Render_DockTab::addPositionVBO(QString name)
Pierre Kraemer's avatar
Pierre Kraemer committed
252 253 254 255 256 257
{
	b_updatingUI = true;
	combo_positionVBO->addItem(name);
	b_updatingUI = false;
}

Pierre Kraemer's avatar
Pierre Kraemer committed
258
void Surface_Render_DockTab::removePositionVBO(QString name)
Pierre Kraemer's avatar
Pierre Kraemer committed
259 260 261 262
{
	b_updatingUI = true;
	int curIndex = combo_positionVBO->currentIndex();
	int index = combo_positionVBO->findText(name, Qt::MatchExactly);
263
	if (curIndex == index)
Pierre Kraemer's avatar
Pierre Kraemer committed
264 265 266 267 268
		combo_positionVBO->setCurrentIndex(0);
	combo_positionVBO->removeItem(index);
	b_updatingUI = false;
}

Pierre Kraemer's avatar
Pierre Kraemer committed
269
void Surface_Render_DockTab::addNormalVBO(QString name)
Pierre Kraemer's avatar
Pierre Kraemer committed
270 271 272 273 274 275
{
	b_updatingUI = true;
	combo_normalVBO->addItem(name);
	b_updatingUI = false;
}

Pierre Kraemer's avatar
Pierre Kraemer committed
276
void Surface_Render_DockTab::removeNormalVBO(QString name)
Pierre Kraemer's avatar
Pierre Kraemer committed
277 278 279 280
{
	b_updatingUI = true;
	int curIndex = combo_normalVBO->currentIndex();
	int index = combo_normalVBO->findText(name, Qt::MatchExactly);
281
	if (curIndex == index)
Pierre Kraemer's avatar
Pierre Kraemer committed
282 283 284 285 286
		combo_normalVBO->setCurrentIndex(0);
	combo_normalVBO->removeItem(index);
	b_updatingUI = false;
}

Pierre Kraemer's avatar
Pierre Kraemer committed
287
void Surface_Render_DockTab::updateMapParameters()
Pierre Kraemer's avatar
Pierre Kraemer committed
288 289 290 291 292
{
	b_updatingUI = true;

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

	combo_normalVBO->clear();
Pierre Kraemer's avatar
Pierre Kraemer committed
295 296 297 298 299
	combo_normalVBO->addItem("- select VBO -");

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

300
	if (view && map)
Pierre Kraemer's avatar
Pierre Kraemer committed
301 302 303 304 305 306
	{
		const MapParameters& p = m_plugin->h_viewParameterSet[view][map];

		unsigned int i = 1;
		foreach(Utils::VBO* vbo, map->getVBOSet().values())
		{
307
			if (vbo->dataSize() == 3)
Pierre Kraemer's avatar
Pierre Kraemer committed
308 309
			{
				combo_positionVBO->addItem(QString::fromStdString(vbo->name()));
310
				if (vbo == p.positionVBO)
Pierre Kraemer's avatar
Pierre Kraemer committed
311 312 313
					combo_positionVBO->setCurrentIndex(i);

				combo_normalVBO->addItem(QString::fromStdString(vbo->name()));
314
				if (vbo == p.normalVBO)
Pierre Kraemer's avatar
Pierre Kraemer committed
315 316 317 318 319 320 321 322 323 324 325 326
					combo_normalVBO->setCurrentIndex(i);

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

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

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

334 335
		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
336 337 338 339 340 341 342 343
	}

	b_updatingUI = false;
}

} // namespace SCHNApps

} // namespace CGoGN