surface_renderVector_dockTab.cpp 4.13 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 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
namespace CGoGN
{

namespace SCHNApps
{

Surface_RenderVector_DockTab::Surface_RenderVector_DockTab(SCHNApps* s, Surface_RenderVector_Plugin* p) :
	m_schnapps(s),
	m_plugin(p),
	b_updatingUI(false)
{
	setupUi(this);

	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 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
41
			m_plugin->pythonRecording("changePositionVBO", "", view->getName(), map->getName(), combo_positionVBO->currentText());
Pierre Kraemer's avatar
Pierre Kraemer committed
42 43 44 45 46 47 48 49 50 51 52 53 54 55
		}
	}
}

void Surface_RenderVector_DockTab::selectedVectorsVBOChanged()
{
	if(!b_updatingUI)
	{
		View* view = m_schnapps->getSelectedView();
		MapHandlerGen* map = m_schnapps->getSelectedMap();
		if(view && map)
		{
			QList<QListWidgetItem*> currentItems = list_vectorVBO->selectedItems();
			QList<Utils::VBO*> vbos;
Sylvain Thery's avatar
Sylvain Thery committed
56
			const QList<Utils::VBO*>& vboList = m_plugin->h_viewParameterSet[view][map].vectorVBOs;
Pierre Kraemer's avatar
Pierre Kraemer committed
57
			foreach(QListWidgetItem* item, currentItems)
Sylvain Thery's avatar
Sylvain Thery committed
58 59 60 61 62 63 64 65 66 67 68 69 70
			{
				Utils::VBO* vbo = map->getVBO(item->text());
				vbos.append(vbo);
				if (!vboList.contains(vbo))
					m_plugin->pythonRecording("addVectorVBO", "", view->getName(), map->getName(), item->text());
			}

			foreach(Utils::VBO* vbo, vboList)
			{
				if (!vbos.contains(vbo))
					m_plugin->pythonRecording("removeVectorVBO", "", view->getName(), map->getName(), QString(vbo->name().c_str()));
			}

Pierre Kraemer's avatar
Pierre Kraemer committed
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 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
			m_plugin->h_viewParameterSet[view][map].vectorVBOs = vbos;
			view->updateGL();
		}
	}
}

void Surface_RenderVector_DockTab::vectorsScaleFactorChanged(int i)
{
	if(!b_updatingUI)
	{
		View* view = m_schnapps->getSelectedView();
		MapHandlerGen* map = m_schnapps->getSelectedMap();
		if(view && map)
		{
			m_plugin->h_viewParameterSet[view][map].vectorsScaleFactor = i / 50.0;
			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);
	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
144
		unsigned int i = 0;
Pierre Kraemer's avatar
Pierre Kraemer committed
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
		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()));
				if(p.vectorVBOs.contains(vbo))
					list_vectorVBO->item(i)->setSelected(true);

				++i;
			}
		}

		slider_vectorsScaleFactor->setSliderPosition(p.vectorsScaleFactor * 50.0);
	}

	b_updatingUI = false;
}

} // namespace SCHNApps

} // namespace CGoGN