surface_renderVector_dockTab.cpp 7.47 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
	list_vectorVBO->setSelectionMode(QAbstractItemView::SingleSelection);
Sylvain Thery's avatar
Sylvain Thery committed
24 25 26 27 28 29 30
	slider_vectorsScaleFactor->setDisabled(true);
	combo_color->setDisabled(true);

	QFont font = selectedName->font();
	font.setBold(true);
	selectedName->setFont(font);
	selectedName->setText("not selected");
31

Pierre Kraemer's avatar
Pierre Kraemer committed
32 33
	connect(combo_positionVBO, SIGNAL(currentIndexChanged(int)), this, SLOT(positionVBOChanged(int)));
	connect(slider_vectorsScaleFactor, SIGNAL(valueChanged(int)), this, SLOT(vectorsScaleFactorChanged(int)));
34 35
	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
36

37 38
	connect(combo_color, SIGNAL(currentIndexChanged(int)), this, SLOT(colorChanged(int)));
}
Pierre Kraemer's avatar
Pierre Kraemer committed
39 40 41 42 43 44 45 46 47 48 49 50


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
51
			m_plugin->pythonRecording("changePositionVBO", "", view->getName(), map->getName(), combo_positionVBO->currentText());
Pierre Kraemer's avatar
Pierre Kraemer committed
52 53 54 55
		}
	}
}

56
void Surface_RenderVector_DockTab::selectedVectorVBOChanged(QListWidgetItem* item, QListWidgetItem* old)
Pierre Kraemer's avatar
Pierre Kraemer committed
57 58
{
	if(!b_updatingUI)
59 60 61
	{
		if ((item->checkState() == Qt::Checked))
		{
Sylvain Thery's avatar
Sylvain Thery committed
62 63 64
			selectedName->setText(item->text());
			slider_vectorsScaleFactor->setEnabled(true);
			combo_color->setEnabled(true);
65 66 67 68 69 70 71 72 73
			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)
				{
Sylvain Thery's avatar
Sylvain Thery committed
74 75
					slider_vectorsScaleFactor->setSliderPosition(p.scaleFactors[m_current_vbo] * 50.0f);
					std::cout << item->text().toStdString() << " : " << p.scaleFactors[m_current_vbo] << " / " << slider_vectorsScaleFactor->value() << std::endl;
76 77 78 79 80 81
					combo_color->setColor(p.colors[m_current_vbo]);
				}
			}
		}
		else
		{
Sylvain Thery's avatar
Sylvain Thery committed
82 83 84
			selectedName->setText("not selected");
			slider_vectorsScaleFactor->setDisabled(true);
			combo_color->setDisabled(true);
85 86 87 88 89 90 91 92
		}
	}
}


void Surface_RenderVector_DockTab::vectorsVBOChecked(QListWidgetItem* item)
{
	if (!b_updatingUI)
Pierre Kraemer's avatar
Pierre Kraemer committed
93 94 95
	{
		View* view = m_schnapps->getSelectedView();
		MapHandlerGen* map = m_schnapps->getSelectedMap();
96
		if (view && map)
Pierre Kraemer's avatar
Pierre Kraemer committed
97
		{
98 99 100
			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
101
			{
102 103 104 105 106 107 108 109
				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
110
			}
111
			else
Sylvain Thery's avatar
Sylvain Thery committed
112
			{
113 114 115 116 117 118
				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();
Sylvain Thery's avatar
Sylvain Thery committed
119 120
				slider_vectorsScaleFactor->setDisabled(true);
				combo_color->setDisabled(true);
121 122
				m_current_vbo = -1;
				m_plugin->pythonRecording("removeVectorVBO", "", view->getName(), map->getName(), QString(item->text()));
Sylvain Thery's avatar
Sylvain Thery committed
123
			}
Pierre Kraemer's avatar
Pierre Kraemer committed
124 125 126 127 128
			view->updateGL();
		}
	}
}

129 130


Pierre Kraemer's avatar
Pierre Kraemer committed
131 132 133 134 135 136
void Surface_RenderVector_DockTab::vectorsScaleFactorChanged(int i)
{
	if(!b_updatingUI)
	{
		View* view = m_schnapps->getSelectedView();
		MapHandlerGen* map = m_schnapps->getSelectedMap();
137
		if (view && map && (m_current_vbo>=0))
Pierre Kraemer's avatar
Pierre Kraemer committed
138
		{
Sylvain Thery's avatar
Sylvain Thery committed
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169
			float& scale = m_plugin->h_viewParameterSet[view][map].scaleFactors[m_current_vbo];
			float newScale = float(i) / 50.0f;
			std::cout << "vectorsScaleFactorChanged " << i << " -> " << newScale << " / old:" << scale << std::endl;
			if (fabs(scale - newScale) > 0.01f)
			{
				scale = newScale;
				m_plugin->pythonRecording("changeVectorScaleFactor", "", view->getName(), map->getName(),
					selectedName->text(), newScale);
				view->updateGL();
			}
		}
	}
}


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))
		{
			QColor& col = m_plugin->h_viewParameterSet[view][map].colors[m_current_vbo];
			if (col != combo_color->color())
			{
				col = combo_color->color();
				m_plugin->pythonRecording("changeVectorColor", "", view->getName(), map->getName(),
					selectedName->text(), combo_color->color().name());
				view->updateGL();
			}
Pierre Kraemer's avatar
Pierre Kraemer committed
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196
		}
	}
}


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);
197 198 199
	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
200 201 202 203 204 205 206 207 208 209 210 211 212 213
	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()
{
Sylvain Thery's avatar
Sylvain Thery committed
214 215
	std::cout << "Surface_RenderVector_DockTab::updateMapParameters" << std::endl;

Pierre Kraemer's avatar
Pierre Kraemer committed
216 217 218 219 220 221 222 223 224 225 226 227 228
	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
229
		unsigned int i = 0;
Pierre Kraemer's avatar
Pierre Kraemer committed
230 231 232 233 234 235
		foreach(Utils::VBO* vbo, map->getVBOSet().values())
		{
			if(vbo->dataSize() == 3)
			{
				combo_positionVBO->addItem(QString::fromStdString(vbo->name()));
				if(vbo == p.positionVBO)
Sylvain Thery's avatar
Sylvain Thery committed
236
					combo_positionVBO->setCurrentIndex(i+1); // +1 for "- select VBO -"
Pierre Kraemer's avatar
Pierre Kraemer committed
237
				list_vectorVBO->addItem(QString::fromStdString(vbo->name()));
238 239 240
				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
241
				if(p.vectorVBOs.contains(vbo))
242
					list_vectorVBO->item(i)->setCheckState(Qt::Checked);
Pierre Kraemer's avatar
Pierre Kraemer committed
243 244 245
				++i;
			}
		}
Sylvain Thery's avatar
Sylvain Thery committed
246 247 248 249 250 251
		if (m_current_vbo >= 0)
		{
			slider_vectorsScaleFactor->setSliderPosition(p.scaleFactors[m_current_vbo] * 50.0f);
			combo_color->setColor(p.colors[m_current_vbo]);
		}
			
252
		// set color
Pierre Kraemer's avatar
Pierre Kraemer committed
253 254 255 256 257 258 259 260
	}

	b_updatingUI = false;
}

} // namespace SCHNApps

} // namespace CGoGN