surface_renderVector_dockTab.cpp 6.31 KB
Newer Older
Pierre Kraemer's avatar
Pierre Kraemer committed
1 2 3 4 5 6
#include "surface_renderVector_dockTab.h"

#include "surface_renderVector.h"
#include "schnapps.h"
#include "mapHandler.h"

7 8
#include "Utils/vbo.h"

Pierre Kraemer's avatar
Pierre Kraemer committed
9 10 11 12 13 14 15 16 17
namespace CGoGN
{

namespace SCHNApps
{

Surface_RenderVector_DockTab::Surface_RenderVector_DockTab(SCHNApps* s, Surface_RenderVector_Plugin* p) :
	m_schnapps(s),
	m_plugin(p),
18 19
	b_updatingUI(false),
	m_current_vbo(-1)
Pierre Kraemer's avatar
Pierre Kraemer committed
20 21 22
{
	setupUi(this);

23 24 25 26
	list_vectorVBO->setSelectionMode(QAbstractItemView::SingleSelection);
	slider_vectorsScaleFactor->hide();
	combo_color->hide();

Pierre Kraemer's avatar
Pierre Kraemer committed
27 28
	connect(combo_positionVBO, SIGNAL(currentIndexChanged(int)), this, SLOT(positionVBOChanged(int)));
	connect(slider_vectorsScaleFactor, SIGNAL(valueChanged(int)), this, SLOT(vectorsScaleFactorChanged(int)));
29 30
	connect(list_vectorVBO, SIGNAL(itemChanged(QListWidgetItem*)), this, SLOT(vectorsVBOChecked(QListWidgetItem*)));
	connect(list_vectorVBO, SIGNAL(currentItemChanged(QListWidgetItem*, QListWidgetItem*)), this, SLOT(selectedVectorVBOChanged(QListWidgetItem*, QListWidgetItem*)));
Pierre Kraemer's avatar
Pierre Kraemer committed
31

32 33
	connect(combo_color, SIGNAL(currentIndexChanged(int)), this, SLOT(colorChanged(int)));
}
Pierre Kraemer's avatar
Pierre Kraemer committed
34 35


36 37 38 39 40 41 42 43 44 45 46 47 48
void Surface_RenderVector_DockTab::colorChanged(int i)
{
	if (!b_updatingUI)
	{
		View* view = m_schnapps->getSelectedView();
		MapHandlerGen* map = m_schnapps->getSelectedMap();
		if (view && map && (m_current_vbo >= 0))
		{
			m_plugin->h_viewParameterSet[view][map].colors[m_current_vbo] = combo_color->color();;
			view->updateGL();
		}
	}
}
Pierre Kraemer's avatar
Pierre Kraemer committed
49 50 51 52 53 54 55 56 57 58 59 60


void Surface_RenderVector_DockTab::positionVBOChanged(int index)
{
	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();
Sylvain Thery's avatar
Sylvain Thery committed
61
			m_plugin->pythonRecording("changePositionVBO", "", view->getName(), map->getName(), combo_positionVBO->currentText());
Pierre Kraemer's avatar
Pierre Kraemer committed
62 63 64 65
		}
	}
}

66
void Surface_RenderVector_DockTab::selectedVectorVBOChanged(QListWidgetItem* item, QListWidgetItem* old)
Pierre Kraemer's avatar
Pierre Kraemer committed
67 68
{
	if(!b_updatingUI)
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
	{
		if ((item->checkState() == Qt::Checked))
		{
			slider_vectorsScaleFactor->show();
			combo_color->show();
			View* view = m_schnapps->getSelectedView();
			MapHandlerGen* map = m_schnapps->getSelectedMap();
			if (view && map)
			{
				const MapParameters& p = m_plugin->h_viewParameterSet[view][map];
				Utils::VBO* v = map->getVBO(item->text());
				m_current_vbo = p.vectorVBOs.indexOf(v);
				if (m_current_vbo >= 0)
				{
					slider_vectorsScaleFactor->setSliderPosition(p.scaleFactors[m_current_vbo] * 50.0);
					combo_color->setColor(p.colors[m_current_vbo]);
				}
			}
		}
		else
		{
			slider_vectorsScaleFactor->hide();
			combo_color->hide();
		}
	}
}


void Surface_RenderVector_DockTab::vectorsVBOChecked(QListWidgetItem* item)
{
	if (!b_updatingUI)
Pierre Kraemer's avatar
Pierre Kraemer committed
100 101 102
	{
		View* view = m_schnapps->getSelectedView();
		MapHandlerGen* map = m_schnapps->getSelectedMap();
103
		if (view && map)
Pierre Kraemer's avatar
Pierre Kraemer committed
104
		{
105 106 107
			MapParameters& p = m_plugin->h_viewParameterSet[view][map];
			Utils::VBO* vbo = map->getVBO(item->text());
			if (item->checkState() == Qt::Checked)
Sylvain Thery's avatar
Sylvain Thery committed
108
			{
109 110 111 112 113 114 115 116
				p.vectorVBOs.append(vbo);
				p.scaleFactors.append(1.0f);
				p.colors.append(QColor("red"));
				if (list_vectorVBO->currentItem() == item)
					selectedVectorVBOChanged(item, NULL);
				else
					list_vectorVBO->setCurrentItem(item);
				m_plugin->pythonRecording("addVectorVBO", "", view->getName(), map->getName(), item->text());
Sylvain Thery's avatar
Sylvain Thery committed
117
			}
118
			else
Sylvain Thery's avatar
Sylvain Thery committed
119
			{
120 121 122 123 124 125 126 127 128 129
				int idx = p.vectorVBOs.indexOf(vbo);
				p.vectorVBOs.removeAt(idx);
				p.scaleFactors.removeAt(idx);
				p.colors.removeAt(idx);
				list_vectorVBO->setCurrentItem(item);
				list_vectorVBO->clearSelection();
				slider_vectorsScaleFactor->hide();
				combo_color->hide();
				m_current_vbo = -1;
				m_plugin->pythonRecording("removeVectorVBO", "", view->getName(), map->getName(), QString(item->text()));
Sylvain Thery's avatar
Sylvain Thery committed
130
			}
Pierre Kraemer's avatar
Pierre Kraemer committed
131 132 133 134 135
			view->updateGL();
		}
	}
}

136 137


Pierre Kraemer's avatar
Pierre Kraemer committed
138 139 140 141 142 143
void Surface_RenderVector_DockTab::vectorsScaleFactorChanged(int i)
{
	if(!b_updatingUI)
	{
		View* view = m_schnapps->getSelectedView();
		MapHandlerGen* map = m_schnapps->getSelectedMap();
144
		if (view && map && (m_current_vbo>=0))
Pierre Kraemer's avatar
Pierre Kraemer committed
145
		{
146
			m_plugin->h_viewParameterSet[view][map].scaleFactors[m_current_vbo] = i / 50.0;
Pierre Kraemer's avatar
Pierre Kraemer committed
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174
			view->updateGL();
		}
	}
}


void Surface_RenderVector_DockTab::addPositionVBO(QString name)
{
	b_updatingUI = true;
	combo_positionVBO->addItem(name);
	b_updatingUI = false;
}

void Surface_RenderVector_DockTab::removePositionVBO(QString name)
{
	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;
}

void Surface_RenderVector_DockTab::addVectorVBO(QString name)
{
	b_updatingUI = true;
	list_vectorVBO->addItem(name);
175 176 177
	QListWidgetItem* item = list_vectorVBO->item(list_vectorVBO->count() - 1);
	item->setFlags(item->flags() | Qt::ItemIsEditable);
	item->setCheckState(Qt::Unchecked);
Pierre Kraemer's avatar
Pierre Kraemer committed
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204
	b_updatingUI = false;
}

void Surface_RenderVector_DockTab::removeVectorVBO(QString name)
{
	b_updatingUI = true;
	QList<QListWidgetItem*> vbo = list_vectorVBO->findItems(name, Qt::MatchExactly);
	if(!vbo.empty())
		delete vbo[0];
	b_updatingUI = false;
}

void Surface_RenderVector_DockTab::updateMapParameters()
{
	b_updatingUI = true;

	combo_positionVBO->clear();
	combo_positionVBO->addItem("- select VBO -");

	list_vectorVBO->clear();

	View* view = m_schnapps->getSelectedView();
	MapHandlerGen* map = m_schnapps->getSelectedMap();
	if(view && map)
	{
		const MapParameters& p = m_plugin->h_viewParameterSet[view][map];

Sylvain Thery's avatar
Sylvain Thery committed
205
		unsigned int i = 0;
Pierre Kraemer's avatar
Pierre Kraemer committed
206 207 208 209 210 211 212 213 214
		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);

				list_vectorVBO->addItem(QString::fromStdString(vbo->name()));
215 216 217
				QListWidgetItem* item = list_vectorVBO->item(list_vectorVBO->count() - 1);
				item->setFlags(item->flags() | Qt::ItemIsEditable);
				item->setCheckState(Qt::Unchecked);
Pierre Kraemer's avatar
Pierre Kraemer committed
218
				if(p.vectorVBOs.contains(vbo))
219
					list_vectorVBO->item(i)->setCheckState(Qt::Checked);
Pierre Kraemer's avatar
Pierre Kraemer committed
220 221 222
				++i;
			}
		}
223 224 225
		if (m_current_vbo>=0)
			slider_vectorsScaleFactor->setSliderPosition(p.scaleFactors[m_current_vbo] * 50.0);
		// set color
Pierre Kraemer's avatar
Pierre Kraemer committed
226 227 228 229 230 231 232 233
	}

	b_updatingUI = false;
}

} // namespace SCHNApps

} // namespace CGoGN