surface_render_dockTab.cpp 5.44 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 27 28
	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*)));
}

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




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





Pierre Kraemer's avatar
Pierre Kraemer committed
138
void Surface_Render_DockTab::addPositionVBO(QString name)
Pierre Kraemer's avatar
Pierre Kraemer committed
139 140 141 142 143 144
{
	b_updatingUI = true;
	combo_positionVBO->addItem(name);
	b_updatingUI = false;
}

Pierre Kraemer's avatar
Pierre Kraemer committed
145
void Surface_Render_DockTab::removePositionVBO(QString name)
Pierre Kraemer's avatar
Pierre Kraemer committed
146 147 148 149 150 151 152 153 154 155
{
	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
156
void Surface_Render_DockTab::addNormalVBO(QString name)
Pierre Kraemer's avatar
Pierre Kraemer committed
157 158 159 160 161 162
{
	b_updatingUI = true;
	combo_normalVBO->addItem(name);
	b_updatingUI = false;
}

Pierre Kraemer's avatar
Pierre Kraemer committed
163
void Surface_Render_DockTab::removeNormalVBO(QString name)
Pierre Kraemer's avatar
Pierre Kraemer committed
164 165 166 167 168 169 170 171 172 173
{
	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
174
void Surface_Render_DockTab::updateMapParameters()
Pierre Kraemer's avatar
Pierre Kraemer committed
175 176 177 178 179
{
	b_updatingUI = true;

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

	combo_normalVBO->clear();
Pierre Kraemer's avatar
Pierre Kraemer committed
182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 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
	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