Coupure prévue mardi 3 Août au matin pour maintenance du serveur. Nous faisons au mieux pour que celle-ci soit la plus brève possible.

surface_render_dockTab.cpp 8.69 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114

	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();
		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
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
124
125
126
127
128
129
130
131
132
133
134
{
	if(!b_updatingUI)
	{
		View* view = m_schnapps->getSelectedView();
		MapHandlerGen* map = m_schnapps->getSelectedMap();
		if(view && map)
		{
			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
138
139
140
141
142
143
144
145
146
147
148
{
	if(!b_updatingUI)
	{
		View* view = m_schnapps->getSelectedView();
		MapHandlerGen* map = m_schnapps->getSelectedMap();
		if(view && map)
		{
			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
152
153
154
155
156
157
158
159
160
161
162
{
	if(!b_updatingUI)
	{
		View* view = m_schnapps->getSelectedView();
		MapHandlerGen* map = m_schnapps->getSelectedMap();
		if(view && map)
		{
			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
166
167
168
169
170
171
172
173
174
175
176
{
	if(!b_updatingUI)
	{
		View* view = m_schnapps->getSelectedView();
		MapHandlerGen* map = m_schnapps->getSelectedMap();
		if(view && map)
		{
			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
180
181
182
183
184
185
186
187
188
189
190
{
	if(!b_updatingUI)
	{
		View* view = m_schnapps->getSelectedView();
		MapHandlerGen* map = m_schnapps->getSelectedMap();
		if(view && map)
		{
			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
194
195
196
197
198
199
200
201
202
203
204
{
	if(!b_updatingUI)
	{
		View* view = m_schnapps->getSelectedView();
		MapHandlerGen* map = m_schnapps->getSelectedMap();
		if(view && map)
		{
			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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
{
	if(!b_updatingUI)
	{
		View* view = m_schnapps->getSelectedView();
		MapHandlerGen* map = m_schnapps->getSelectedMap();
		if(view && map)
		{
			if(radio_flatShading->isChecked())
				m_plugin->h_viewParameterSet[view][map].faceStyle = MapParameters::FLAT;
			else if(radio_phongShading->isChecked())
				m_plugin->h_viewParameterSet[view][map].faceStyle = MapParameters::PHONG;
			view->updateGL();
		}
	}
}

222
223
224
225
226
227
228
229
230
231
232
233
234
235
void Surface_Render_DockTab::renderBoundaryChanged(bool b)
{
	if(!b_updatingUI)
	{
		View* view = m_schnapps->getSelectedView();
		MapHandlerGen* map = m_schnapps->getSelectedMap();
		if(view && map)
		{
			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
252
253
254
255
256
257
{
	b_updatingUI = true;
	int curIndex = combo_positionVBO->currentIndex();
	int index = combo_positionVBO->findText(name, Qt::MatchExactly);
	if(curIndex == index)
		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
270
271
272
273
274
275
{
	b_updatingUI = true;
	int curIndex = combo_normalVBO->currentIndex();
	int index = combo_normalVBO->findText(name, Qt::MatchExactly);
	if(curIndex == index)
		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
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
	combo_normalVBO->addItem("- select VBO -");

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

	if(view && map)
	{
		const MapParameters& p = m_plugin->h_viewParameterSet[view][map];

		unsigned int i = 1;
		foreach(Utils::VBO* vbo, map->getVBOSet().values())
		{
			if(vbo->dataSize() == 3)
			{
				combo_positionVBO->addItem(QString::fromStdString(vbo->name()));
				if(vbo == p.positionVBO)
					combo_positionVBO->setCurrentIndex(i);

				combo_normalVBO->addItem(QString::fromStdString(vbo->name()));
				if(vbo == p.normalVBO)
					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
323
324
325
326

		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()+ " }");

		m_vertexColor = QColor(255*p.simpleColor[0],255*p.vertexColor[1],255*p.vertexColor[2]);
		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