renderVectorDockTab.cpp 3.45 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
#include "renderVectorDockTab.h"

#include "renderVector.h"
#include "window.h"
#include "mapHandler.h"

namespace CGoGN
{

namespace SCHNApps
{

RenderVectorDockTab::RenderVectorDockTab(Window* w, RenderVectorPlugin* p) :
	m_window(w),
	m_plugin(p),
	b_refreshingUI(false)
{
	setupUi(this);

	connect(mapList, SIGNAL(itemSelectionChanged()), this, SLOT(selectedMapChanged()));
	connect(combo_positionVBO, SIGNAL(currentIndexChanged(int)), this, SLOT(positionVBOChanged(int)));
	connect(list_vectorVBO, SIGNAL(itemSelectionChanged()), this, SLOT(selectedVectorsVBOChanged()));
	connect(slider_vectorsScaleFactor, SIGNAL(valueChanged(int)), this, SLOT(vectorsScaleFactorChanged(int)));
}

void RenderVectorDockTab::refreshUI(ParameterSet* params)
{
	m_currentParams = params;

	b_refreshingUI = true;

	mapList->clear();
	combo_positionVBO->clear();
	list_vectorVBO->clear();

	MapHandlerGen* map = params->selectedMap;

38
	QHash<QString, PerMapParameterSet*>::const_iterator i = params->perMap.constBegin();
39 40 41 42 43 44 45 46
	while (i != params->perMap.constEnd())
	{
		mapList->addItem(i.key());
		if(map != NULL && i.key() == map->getName())
		{
			QList<QListWidgetItem*> item = mapList->findItems(map->getName(), Qt::MatchExactly);
			item[0]->setSelected(true);

47
			PerMapParameterSet* p = params->perMap[map->getName()];
48 49 50 51 52 53 54 55

			QList<Utils::VBO*> vbos = map->getVBOList();
			unsigned int j = 0;
			for(int i = 0; i < vbos.count(); ++i)
			{
				if(vbos[i]->dataSize() == 3)
				{
					combo_positionVBO->addItem(QString::fromStdString(vbos[i]->name()));
56
					if(vbos[i] == p->positionVBO)
57 58 59
						combo_positionVBO->setCurrentIndex(j);

					list_vectorVBO->addItem(QString::fromStdString(vbos[i]->name()));
60
					if(std::find(p->vectorVBO.begin(), p->vectorVBO.end(), vbos[i]) != p->vectorVBO.end())
61 62 63 64 65 66
						list_vectorVBO->item(j)->setSelected(true);

					++j;
				}
			}

67
			slider_vectorsScaleFactor->setSliderPosition(p->vectorsScaleFactor * 50.0);
68 69 70 71 72 73 74 75 76 77 78 79 80
		}
		++i;
	}

	b_refreshingUI = false;
}

void RenderVectorDockTab::selectedMapChanged()
{
	if(!b_refreshingUI)
	{
		QList<QListWidgetItem*> currentItems = mapList->selectedItems();
		if(!currentItems.empty())
81
			m_plugin->changeSelectedMap(m_window->getCurrentView(), m_window->getMap(currentItems[0]->text()));
82 83 84 85 86 87 88 89 90
	}
}

void RenderVectorDockTab::positionVBOChanged(int index)
{
	if(!b_refreshingUI)
	{
		View* view = m_window->getCurrentView();
		MapHandlerGen* map = m_currentParams->selectedMap;
91 92
		if(map)
			m_plugin->changePositionVBO(view, map, map->getVBO(combo_positionVBO->currentText()), true);
93 94 95 96 97 98 99 100 101
	}
}

void RenderVectorDockTab::selectedVectorsVBOChanged()
{
	if(!b_refreshingUI)
	{
		View* view = m_window->getCurrentView();
		MapHandlerGen* map = m_currentParams->selectedMap;
102 103 104 105 106 107 108 109
		if(map)
		{
			QList<QListWidgetItem*> currentItems = list_vectorVBO->selectedItems();
			std::vector<Utils::VBO*> vbos;
			foreach(QListWidgetItem* item, currentItems)
				vbos.push_back(map->getVBO(item->text()));
			m_plugin->changeSelectedVectorsVBO(view, map, vbos, true);
		}
110 111 112 113 114 115 116 117 118
	}
}

void RenderVectorDockTab::vectorsScaleFactorChanged(int i)
{
	if(!b_refreshingUI)
	{
		View* view = m_window->getCurrentView();
		MapHandlerGen* map = m_currentParams->selectedMap;
119 120
		if(map)
			m_plugin->changeVectorsScaleFactor(view, map, i, true);
121 122 123
	}
}

124 125 126 127 128 129 130 131 132 133
void RenderVectorDockTab::addVBOToList(Utils::VBO* vbo)
{
	if(vbo->dataSize() == 3)
	{
		QString name = QString::fromStdString(vbo->name());
		combo_positionVBO->addItem(name);
		list_vectorVBO->addItem(name);
	}
}

134 135 136
} // namespace SCHNApps

} // namespace CGoGN