surface_renderVector_dockTab.cpp 7 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
	b_updatingUI(false)
Pierre Kraemer's avatar
Pierre Kraemer committed
19 20 21
{
	setupUi(this);

22
	list_vectorVBO->setSelectionMode(QAbstractItemView::SingleSelection);
Sylvain Thery's avatar
Sylvain Thery committed
23 24 25
	slider_vectorsScaleFactor->setDisabled(true);
	combo_color->setDisabled(true);

Pierre Kraemer's avatar
Pierre Kraemer committed
26 27
	connect(combo_positionVBO, SIGNAL(currentIndexChanged(int)), this, SLOT(positionVBOChanged(int)));
	connect(slider_vectorsScaleFactor, SIGNAL(valueChanged(int)), this, SLOT(vectorsScaleFactorChanged(int)));
28 29
	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
30

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

void Surface_RenderVector_DockTab::positionVBOChanged(int index)
{
36
	if (!b_updatingUI)
Pierre Kraemer's avatar
Pierre Kraemer committed
37 38 39 40 41 42 43
	{
		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
44
			m_plugin->pythonRecording("changePositionVBO", "", view->getName(), map->getName(), combo_positionVBO->currentText());
Pierre Kraemer's avatar
Pierre Kraemer committed
45 46 47 48
		}
	}
}

49
void Surface_RenderVector_DockTab::selectedVectorVBOChanged(QListWidgetItem* item, QListWidgetItem* old)
Pierre Kraemer's avatar
Pierre Kraemer committed
50
{
51
	if (!b_updatingUI)
52
	{
53 54 55
		View* view = m_schnapps->getSelectedView();
		MapHandlerGen* map = m_schnapps->getSelectedMap();
		if (view && map)
56
		{
57
			if ((item->checkState() == Qt::Checked))
58 59 60
			{
				const MapParameters& p = m_plugin->h_viewParameterSet[view][map];
				Utils::VBO* v = map->getVBO(item->text());
61 62 63 64 65 66 67 68 69 70
				int idx = p.vectorVBOs.indexOf(v);
				slider_vectorsScaleFactor->setEnabled(true);
				slider_vectorsScaleFactor->setSliderPosition(p.scaleFactors[idx] * 50.0f);
				combo_color->setEnabled(true);
				combo_color->setColor(p.colors[idx]);
			}
			else
			{
				slider_vectorsScaleFactor->setDisabled(true);
				combo_color->setDisabled(true);
71 72 73 74 75 76 77 78
			}
		}
	}
}

void Surface_RenderVector_DockTab::vectorsVBOChecked(QListWidgetItem* item)
{
	if (!b_updatingUI)
Pierre Kraemer's avatar
Pierre Kraemer committed
79 80 81
	{
		View* view = m_schnapps->getSelectedView();
		MapHandlerGen* map = m_schnapps->getSelectedMap();
82
		if (view && map)
Pierre Kraemer's avatar
Pierre Kraemer committed
83
		{
84 85
			MapParameters& p = m_plugin->h_viewParameterSet[view][map];
			Utils::VBO* vbo = map->getVBO(item->text());
86

87
			if (item->checkState() == Qt::Checked)
Sylvain Thery's avatar
Sylvain Thery committed
88
			{
89 90 91 92 93 94 95 96
				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
97
			}
98
			else
Sylvain Thery's avatar
Sylvain Thery committed
99
			{
100 101 102 103
				int idx = p.vectorVBOs.indexOf(vbo);
				p.vectorVBOs.removeAt(idx);
				p.scaleFactors.removeAt(idx);
				p.colors.removeAt(idx);
104 105
//				list_vectorVBO->setCurrentItem(item);
//				list_vectorVBO->clearSelection();
Sylvain Thery's avatar
Sylvain Thery committed
106 107
				slider_vectorsScaleFactor->setDisabled(true);
				combo_color->setDisabled(true);
108
				m_plugin->pythonRecording("removeVectorVBO", "", view->getName(), map->getName(), QString(item->text()));
Sylvain Thery's avatar
Sylvain Thery committed
109
			}
Pierre Kraemer's avatar
Pierre Kraemer committed
110 111 112 113 114 115 116 117 118 119 120
			view->updateGL();
		}
	}
}

void Surface_RenderVector_DockTab::vectorsScaleFactorChanged(int i)
{
	if(!b_updatingUI)
	{
		View* view = m_schnapps->getSelectedView();
		MapHandlerGen* map = m_schnapps->getSelectedMap();
121 122
		QListWidgetItem* item = list_vectorVBO->currentItem();
		if (view && map && item)
Pierre Kraemer's avatar
Pierre Kraemer committed
123
		{
124 125 126 127
			MapParameters& p = m_plugin->h_viewParameterSet[view][map];
			Utils::VBO* vbo = map->getVBO(item->text());
			int idx = p.vectorVBOs.indexOf(vbo);
			float& scale = p.scaleFactors[idx];
Sylvain Thery's avatar
Sylvain Thery committed
128 129 130 131 132
			float newScale = float(i) / 50.0f;
			if (fabs(scale - newScale) > 0.01f)
			{
				scale = newScale;
				m_plugin->pythonRecording("changeVectorScaleFactor", "", view->getName(), map->getName(),
133
					item->text(), newScale);
Sylvain Thery's avatar
Sylvain Thery committed
134 135 136 137 138 139 140 141 142 143 144 145
				view->updateGL();
			}
		}
	}
}

void Surface_RenderVector_DockTab::colorChanged(int i)
{
	if (!b_updatingUI)
	{
		View* view = m_schnapps->getSelectedView();
		MapHandlerGen* map = m_schnapps->getSelectedMap();
146 147
		QListWidgetItem* item = list_vectorVBO->currentItem();
		if (view && map && item)
Sylvain Thery's avatar
Sylvain Thery committed
148
		{
149 150 151 152
			MapParameters& p = m_plugin->h_viewParameterSet[view][map];
			Utils::VBO* vbo = map->getVBO(item->text());
			int idx = p.vectorVBOs.indexOf(vbo);
			QColor& col = p.colors[idx];
Sylvain Thery's avatar
Sylvain Thery committed
153 154 155 156
			if (col != combo_color->color())
			{
				col = combo_color->color();
				m_plugin->pythonRecording("changeVectorColor", "", view->getName(), map->getName(),
157
					item->text(), combo_color->color().name());
Sylvain Thery's avatar
Sylvain Thery committed
158 159
				view->updateGL();
			}
Pierre Kraemer's avatar
Pierre Kraemer committed
160 161 162 163 164
		}
	}
}


165 166 167



Pierre Kraemer's avatar
Pierre Kraemer committed
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189
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);
190 191 192
	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
193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212
	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();
213
	list_vectorVBO->clearSelection();
Pierre Kraemer's avatar
Pierre Kraemer committed
214 215 216 217 218 219 220

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

221
		unsigned int i = 1;
Pierre Kraemer's avatar
Pierre Kraemer committed
222 223 224 225 226 227
		foreach(Utils::VBO* vbo, map->getVBOSet().values())
		{
			if(vbo->dataSize() == 3)
			{
				combo_positionVBO->addItem(QString::fromStdString(vbo->name()));
				if(vbo == p.positionVBO)
228 229
					combo_positionVBO->setCurrentIndex(i);

Pierre Kraemer's avatar
Pierre Kraemer committed
230
				list_vectorVBO->addItem(QString::fromStdString(vbo->name()));
231 232 233
				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
234
				if(p.vectorVBOs.contains(vbo))
235 236
					list_vectorVBO->item(i-1)->setCheckState(Qt::Checked);

Pierre Kraemer's avatar
Pierre Kraemer committed
237 238 239 240 241
				++i;
			}
		}
	}

242 243 244
	slider_vectorsScaleFactor->setDisabled(true);
	combo_color->setDisabled(true);

Pierre Kraemer's avatar
Pierre Kraemer committed
245 246 247 248 249 250
	b_updatingUI = false;
}

} // namespace SCHNApps

} // namespace CGoGN