renderScalarDockTab.cpp 4.01 KB
Newer Older
Pierre Kraemer's avatar
Pierre Kraemer committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
#include "renderScalarDockTab.h"

#include "renderScalar.h"
#include "window.h"
#include "mapHandler.h"

namespace CGoGN
{

namespace SCHNApps
{

RenderScalarDockTab::RenderScalarDockTab(Window* w, RenderScalarPlugin* 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)));
22
	connect(list_scalarVBO, SIGNAL(itemSelectionChanged()), this, SLOT(selectedScalarVBOChanged()));
23
	connect(combo_colorMap, SIGNAL(currentIndexChanged(int)), this, SLOT(colorMapChanged(int)));
24
	connect(slider_expansion, SIGNAL(valueChanged(int)), this, SLOT(expansionChanged(int)));
Pierre Kraemer's avatar
Pierre Kraemer committed
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
}

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

	b_refreshingUI = true;

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

	MapHandlerGen* map = params->selectedMap;

	QHash<QString, PerMapParameterSet*>::const_iterator i = params->perMap.constBegin();
	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);

			PerMapParameterSet* p = params->perMap[map->getName()];

			QList<Utils::VBO*> vbos = map->getVBOList();
			unsigned int j = 0;
52
			unsigned int k = 0;
Pierre Kraemer's avatar
Pierre Kraemer committed
53 54 55 56 57 58 59 60 61 62 63 64 65
			for(int i = 0; i < vbos.count(); ++i)
			{
				unsigned int dataSize = vbos[i]->dataSize();
				if(dataSize == 3)
				{
					combo_positionVBO->addItem(QString::fromStdString(vbos[i]->name()));
					if(vbos[i] == p->positionVBO)
						combo_positionVBO->setCurrentIndex(j);
					++j;
				}
				else if(dataSize == 1)
				{
					list_scalarVBO->addItem(QString::fromStdString(vbos[i]->name()));
66 67 68
					if(vbos[i] == p->scalarVBO)
						list_scalarVBO->item(k)->setSelected(true);
					++k;
Pierre Kraemer's avatar
Pierre Kraemer committed
69 70
				}
			}
71

72
			combo_colorMap->setCurrentIndex(p->colorMap);
73
			slider_expansion->setSliderPosition(p->expansion);
Pierre Kraemer's avatar
Pierre Kraemer committed
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
		}
		++i;
	}

	b_refreshingUI = false;
}

void RenderScalarDockTab::selectedMapChanged()
{
	if(!b_refreshingUI)
	{
		QList<QListWidgetItem*> currentItems = mapList->selectedItems();
		if(!currentItems.empty())
			m_plugin->changeSelectedMap(m_window->getCurrentView(), m_window->getMap(currentItems[0]->text()));
	}
}

void RenderScalarDockTab::positionVBOChanged(int index)
{
	if(!b_refreshingUI)
	{
		View* view = m_window->getCurrentView();
		MapHandlerGen* map = m_currentParams->selectedMap;
97 98
		if(map)
			m_plugin->changePositionVBO(view, map, map->getVBO(combo_positionVBO->currentText()), true);
Pierre Kraemer's avatar
Pierre Kraemer committed
99 100 101
	}
}

102 103 104 105 106 107
void RenderScalarDockTab::selectedScalarVBOChanged()
{
	if(!b_refreshingUI)
	{
		View* view = m_window->getCurrentView();
		MapHandlerGen* map = m_currentParams->selectedMap;
108
		if(map)
109
		{
110 111
			QList<QListWidgetItem*> selectedItems = list_scalarVBO->selectedItems();
			if(!selectedItems.empty())
112
			{
113 114 115 116 117 118
				foreach(QListWidgetItem* item, selectedItems)
				{
					if(item != list_scalarVBO->currentItem())
						item->setSelected(false);
				}
				m_plugin->changeScalarVBO(view, map, map->getVBO(list_scalarVBO->currentItem()->text()), true);
119
			}
120 121
			else
				m_plugin->changeScalarVBO(view, map, NULL, true);
122 123 124 125
		}
	}
}

126 127 128 129 130 131
void RenderScalarDockTab::colorMapChanged(int index)
{
	if(!b_refreshingUI)
	{
		View* view = m_window->getCurrentView();
		MapHandlerGen* map = m_currentParams->selectedMap;
132 133
		if(map)
			m_plugin->changeColorMap(view, map, index, true);
134 135 136
	}
}

137
void RenderScalarDockTab::expansionChanged(int i)
Pierre Kraemer's avatar
Pierre Kraemer committed
138 139 140 141 142
{
	if(!b_refreshingUI)
	{
		View* view = m_window->getCurrentView();
		MapHandlerGen* map = m_currentParams->selectedMap;
143 144
		if(map)
			m_plugin->changeExpansion(view, map, i, true);
Pierre Kraemer's avatar
Pierre Kraemer committed
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160
	}
}

void RenderScalarDockTab::addVBOToList(Utils::VBO* vbo)
{
	QString name = QString::fromStdString(vbo->name());
	unsigned int dataSize = vbo->dataSize();
	if(dataSize == 3)
		combo_positionVBO->addItem(name);
	else if(dataSize == 1)
		list_scalarVBO->addItem(name);
}

} // namespace SCHNApps

} // namespace CGoGN