surface_render_dockTab.cpp 8.71 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 79 80 81 82 83 84 85 86 87 88 89 90 91
		{
			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();
92
		if (view && map)
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
		{
			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();
109
		if (view && map)
110 111 112 113 114
		{
			m_plugin->h_viewParameterSet[view][map].vertexColor = rgbCol;
			view->updateGL();
		}
	}
Pierre Kraemer's avatar
Pierre Kraemer committed
115 116
}

Pierre Kraemer's avatar
Pierre Kraemer committed
117 118 119 120 121




void Surface_Render_DockTab::positionVBOChanged(int index)
Pierre Kraemer's avatar
Pierre Kraemer committed
122
{
123
	if (!b_updatingUI)
Pierre Kraemer's avatar
Pierre Kraemer committed
124 125 126
	{
		View* view = m_schnapps->getSelectedView();
		MapHandlerGen* map = m_schnapps->getSelectedMap();
127
		if (view && map)
Pierre Kraemer's avatar
Pierre Kraemer committed
128 129 130 131 132 133 134
		{
			m_plugin->h_viewParameterSet[view][map].positionVBO = map->getVBO(combo_positionVBO->currentText());
			view->updateGL();
		}
	}
}

Pierre Kraemer's avatar
Pierre Kraemer committed
135
void Surface_Render_DockTab::normalVBOChanged(int index)
Pierre Kraemer's avatar
Pierre Kraemer committed
136
{
137
	if (!b_updatingUI)
Pierre Kraemer's avatar
Pierre Kraemer committed
138 139 140
	{
		View* view = m_schnapps->getSelectedView();
		MapHandlerGen* map = m_schnapps->getSelectedMap();
141
		if (view && map)
Pierre Kraemer's avatar
Pierre Kraemer committed
142 143 144 145 146 147 148
		{
			m_plugin->h_viewParameterSet[view][map].normalVBO = map->getVBO(combo_normalVBO->currentText());
			view->updateGL();
		}
	}
}

Pierre Kraemer's avatar
Pierre Kraemer committed
149
void Surface_Render_DockTab::renderVerticesChanged(bool 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 158 159 160 161 162
		{
			m_plugin->h_viewParameterSet[view][map].renderVertices = b;
			view->updateGL();
		}
	}
}

Pierre Kraemer's avatar
Pierre Kraemer committed
163
void Surface_Render_DockTab::verticesScaleFactorChanged(int i)
Pierre Kraemer's avatar
Pierre Kraemer committed
164
{
165
	if (!b_updatingUI)
Pierre Kraemer's avatar
Pierre Kraemer committed
166 167 168
	{
		View* view = m_schnapps->getSelectedView();
		MapHandlerGen* map = m_schnapps->getSelectedMap();
169
		if (view && map)
Pierre Kraemer's avatar
Pierre Kraemer committed
170 171 172 173 174 175 176
		{
			m_plugin->h_viewParameterSet[view][map].verticesScaleFactor = i / 50.0;
			view->updateGL();
		}
	}
}

Pierre Kraemer's avatar
Pierre Kraemer committed
177
void Surface_Render_DockTab::renderEdgesChanged(bool b)
Pierre Kraemer's avatar
Pierre Kraemer committed
178
{
179
	if (!b_updatingUI)
Pierre Kraemer's avatar
Pierre Kraemer committed
180 181 182
	{
		View* view = m_schnapps->getSelectedView();
		MapHandlerGen* map = m_schnapps->getSelectedMap();
183
		if (view && map)
Pierre Kraemer's avatar
Pierre Kraemer committed
184 185 186 187 188 189 190
		{
			m_plugin->h_viewParameterSet[view][map].renderEdges = b;
			view->updateGL();
		}
	}
}

Pierre Kraemer's avatar
Pierre Kraemer committed
191
void Surface_Render_DockTab::renderFacesChanged(bool b)
Pierre Kraemer's avatar
Pierre Kraemer committed
192
{
193
	if (!b_updatingUI)
Pierre Kraemer's avatar
Pierre Kraemer committed
194 195 196
	{
		View* view = m_schnapps->getSelectedView();
		MapHandlerGen* map = m_schnapps->getSelectedMap();
197
		if (view && map)
Pierre Kraemer's avatar
Pierre Kraemer committed
198 199 200 201 202 203 204
		{
			m_plugin->h_viewParameterSet[view][map].renderFaces = b;
			view->updateGL();
		}
	}
}

Pierre Kraemer's avatar
Pierre Kraemer committed
205
void Surface_Render_DockTab::faceStyleChanged(QAbstractButton* b)
Pierre Kraemer's avatar
Pierre Kraemer committed
206
{
207
	if (!b_updatingUI)
Pierre Kraemer's avatar
Pierre Kraemer committed
208 209 210
	{
		View* view = m_schnapps->getSelectedView();
		MapHandlerGen* map = m_schnapps->getSelectedMap();
211
		if (view && map)
Pierre Kraemer's avatar
Pierre Kraemer committed
212
		{
213
			if (radio_flatShading->isChecked())
Pierre Kraemer's avatar
Pierre Kraemer committed
214
				m_plugin->h_viewParameterSet[view][map].faceStyle = MapParameters::FLAT;
215
			else if (radio_phongShading->isChecked())
Pierre Kraemer's avatar
Pierre Kraemer committed
216 217 218 219 220 221
				m_plugin->h_viewParameterSet[view][map].faceStyle = MapParameters::PHONG;
			view->updateGL();
		}
	}
}

222 223
void Surface_Render_DockTab::renderBoundaryChanged(bool b)
{
224
	if (!b_updatingUI)
225 226 227
	{
		View* view = m_schnapps->getSelectedView();
		MapHandlerGen* map = m_schnapps->getSelectedMap();
228
		if (view && map)
229 230 231 232 233 234 235
		{
			m_plugin->h_viewParameterSet[view][map].renderBoundary = b;
			view->updateGL();
		}
	}
}

Pierre Kraemer's avatar
Pierre Kraemer committed
236 237 238 239




Pierre Kraemer's avatar
Pierre Kraemer committed
240
void Surface_Render_DockTab::addPositionVBO(QString name)
Pierre Kraemer's avatar
Pierre Kraemer committed
241 242 243 244 245 246
{
	b_updatingUI = true;
	combo_positionVBO->addItem(name);
	b_updatingUI = false;
}

Pierre Kraemer's avatar
Pierre Kraemer committed
247
void Surface_Render_DockTab::removePositionVBO(QString name)
Pierre Kraemer's avatar
Pierre Kraemer committed
248 249 250 251
{
	b_updatingUI = true;
	int curIndex = combo_positionVBO->currentIndex();
	int index = combo_positionVBO->findText(name, Qt::MatchExactly);
252
	if (curIndex == index)
Pierre Kraemer's avatar
Pierre Kraemer committed
253 254 255 256 257
		combo_positionVBO->setCurrentIndex(0);
	combo_positionVBO->removeItem(index);
	b_updatingUI = false;
}

Pierre Kraemer's avatar
Pierre Kraemer committed
258
void Surface_Render_DockTab::addNormalVBO(QString name)
Pierre Kraemer's avatar
Pierre Kraemer committed
259 260 261 262 263 264
{
	b_updatingUI = true;
	combo_normalVBO->addItem(name);
	b_updatingUI = false;
}

Pierre Kraemer's avatar
Pierre Kraemer committed
265
void Surface_Render_DockTab::removeNormalVBO(QString name)
Pierre Kraemer's avatar
Pierre Kraemer committed
266 267 268 269
{
	b_updatingUI = true;
	int curIndex = combo_normalVBO->currentIndex();
	int index = combo_normalVBO->findText(name, Qt::MatchExactly);
270
	if (curIndex == index)
Pierre Kraemer's avatar
Pierre Kraemer committed
271 272 273 274 275
		combo_normalVBO->setCurrentIndex(0);
	combo_normalVBO->removeItem(index);
	b_updatingUI = false;
}

Pierre Kraemer's avatar
Pierre Kraemer committed
276
void Surface_Render_DockTab::updateMapParameters()
Pierre Kraemer's avatar
Pierre Kraemer committed
277 278 279 280 281
{
	b_updatingUI = true;

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

	combo_normalVBO->clear();
Pierre Kraemer's avatar
Pierre Kraemer committed
284 285 286 287 288
	combo_normalVBO->addItem("- select VBO -");

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

289
	if (view && map)
Pierre Kraemer's avatar
Pierre Kraemer committed
290 291 292 293 294 295
	{
		const MapParameters& p = m_plugin->h_viewParameterSet[view][map];

		unsigned int i = 1;
		foreach(Utils::VBO* vbo, map->getVBOSet().values())
		{
296
			if (vbo->dataSize() == 3)
Pierre Kraemer's avatar
Pierre Kraemer committed
297 298
			{
				combo_positionVBO->addItem(QString::fromStdString(vbo->name()));
299
				if (vbo == p.positionVBO)
Pierre Kraemer's avatar
Pierre Kraemer committed
300 301 302
					combo_positionVBO->setCurrentIndex(i);

				combo_normalVBO->addItem(QString::fromStdString(vbo->name()));
303
				if (vbo == p.normalVBO)
Pierre Kraemer's avatar
Pierre Kraemer committed
304 305 306 307 308 309 310 311 312 313 314 315
					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);
316 317 318 319 320 321 322

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

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

323
		m_vertexColor = QColor(255*p.vertexColor[0],255*p.vertexColor[1],255*p.vertexColor[2]);
324 325 326
		vcolorButton->setStyleSheet("QPushButton { background-color:"+m_vertexColor.name()+ " }");


Pierre Kraemer's avatar
Pierre Kraemer committed
327 328 329 330 331 332 333 334
	}

	b_updatingUI = false;
}

} // namespace SCHNApps

} // namespace CGoGN