surface_render_dockTab.cpp 5.83 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 16 17 18 19 20 21 22 23 24 25 26
	m_schnapps(s),
	m_plugin(p),
	b_updatingUI(false)
{
	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*)));
27
	connect(check_renderBoundary, SIGNAL(toggled(bool)), this, SLOT(renderBoundaryChanged(bool)));
Pierre Kraemer's avatar
Pierre Kraemer committed
28 29
}

Pierre Kraemer's avatar
Pierre Kraemer committed
30 31 32 33 34




void Surface_Render_DockTab::positionVBOChanged(int index)
Pierre Kraemer's avatar
Pierre Kraemer committed
35 36 37 38 39 40 41 42 43 44 45 46 47
{
	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
48
void Surface_Render_DockTab::normalVBOChanged(int index)
Pierre Kraemer's avatar
Pierre Kraemer committed
49 50 51 52 53 54 55 56 57 58 59 60 61
{
	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
62
void Surface_Render_DockTab::renderVerticesChanged(bool b)
Pierre Kraemer's avatar
Pierre Kraemer committed
63 64 65 66 67 68 69 70 71 72 73 74 75
{
	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
76
void Surface_Render_DockTab::verticesScaleFactorChanged(int i)
Pierre Kraemer's avatar
Pierre Kraemer committed
77 78 79 80 81 82 83 84 85 86 87 88 89
{
	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
90
void Surface_Render_DockTab::renderEdgesChanged(bool b)
Pierre Kraemer's avatar
Pierre Kraemer committed
91 92 93 94 95 96 97 98 99 100 101 102 103
{
	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
104
void Surface_Render_DockTab::renderFacesChanged(bool b)
Pierre Kraemer's avatar
Pierre Kraemer committed
105 106 107 108 109 110 111 112 113 114 115 116 117
{
	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
118
void Surface_Render_DockTab::faceStyleChanged(QAbstractButton* b)
Pierre Kraemer's avatar
Pierre Kraemer committed
119 120 121 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)
		{
			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();
		}
	}
}

135 136 137 138 139 140 141 142 143 144 145 146 147 148
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
149 150 151 152




Pierre Kraemer's avatar
Pierre Kraemer committed
153
void Surface_Render_DockTab::addPositionVBO(QString name)
Pierre Kraemer's avatar
Pierre Kraemer committed
154 155 156 157 158 159
{
	b_updatingUI = true;
	combo_positionVBO->addItem(name);
	b_updatingUI = false;
}

Pierre Kraemer's avatar
Pierre Kraemer committed
160
void Surface_Render_DockTab::removePositionVBO(QString name)
Pierre Kraemer's avatar
Pierre Kraemer committed
161 162 163 164 165 166 167 168 169 170
{
	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
171
void Surface_Render_DockTab::addNormalVBO(QString name)
Pierre Kraemer's avatar
Pierre Kraemer committed
172 173 174 175 176 177
{
	b_updatingUI = true;
	combo_normalVBO->addItem(name);
	b_updatingUI = false;
}

Pierre Kraemer's avatar
Pierre Kraemer committed
178
void Surface_Render_DockTab::removeNormalVBO(QString name)
Pierre Kraemer's avatar
Pierre Kraemer committed
179 180 181 182 183 184 185 186 187 188
{
	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
189
void Surface_Render_DockTab::updateMapParameters()
Pierre Kraemer's avatar
Pierre Kraemer committed
190 191 192 193 194
{
	b_updatingUI = true;

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

	combo_normalVBO->clear();
Pierre Kraemer's avatar
Pierre Kraemer committed
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
	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);
	}

	b_updatingUI = false;
}

} // namespace SCHNApps

} // namespace CGoGN