renderVector.cpp 5.78 KB
Newer Older
1 2 3 4 5 6 7 8
#include "renderVector.h"

#include "mapHandler.h"

#include "Algo/Import/import.h"

bool RenderVectorPlugin::enable()
{
9
	m_dockTab = new RenderVectorDockTab(this);
10 11
	addTabInDock(m_dockTab, "RenderVector");

12 13
	m_vectorShader = new Utils::ShaderVectorPerVertex();
	m_vectorShader->setColor(Geom::Vec4f(1.0f, 0.0f, 0.0f, 1.0f));
14 15 16

	registerShader(m_vectorShader);

17 18 19 20
	connect(m_dockTab->mapList, SIGNAL(itemSelectionChanged()), this, SLOT(cb_selectedMapChanged()));
	connect(m_dockTab->combo_positionVBO, SIGNAL(currentIndexChanged(int)), this, SLOT(cb_positionVBOChanged(int)));
	connect(m_dockTab->combo_vectorVBO, SIGNAL(currentIndexChanged(int)), this, SLOT(cb_vectorVBOChanged(int)));
	connect(m_dockTab->button_refreshVBOs, SIGNAL(clicked()), this, SLOT(cb_refreshVBOs()));
21 22 23 24 25 26 27 28 29 30 31 32
	connect(m_dockTab->slider_vectorsScaleFactor, SIGNAL(valueChanged(int)), this, SLOT(cb_vectorsScaleFactorChanged(int)));

	return true;
}

void RenderVectorPlugin::disable()
{
	delete m_vectorShader;
}

void RenderVectorPlugin::redraw(View* view)
{
33
	ParameterSet* params = h_viewParams[view];
34 35 36 37

	const QList<MapHandlerGen*>& maps = view->getLinkedMaps();
	foreach(MapHandlerGen* m, maps)
	{
38
		const PerMapParameterSet& p = params->perMap[m->getName()];
39 40 41 42 43 44 45 46
		if(p.positionVBO != NULL && p.vectorVBO != NULL)
		{
			m_vectorShader->setScale(m->getBBdiagSize() / 100.0f * p.vectorsScaleFactor) ;
			m_vectorShader->setAttributePosition(p.positionVBO) ;
			m_vectorShader->setAttributeVector(p.vectorVBO) ;
			glLineWidth(1.0f) ;
			m->draw(m_vectorShader, Algo::Render::GL2::POINTS) ;
		}
47 48 49 50 51
	}
}

void RenderVectorPlugin::viewLinked(View* view)
{
52
	ParameterSet* params = new ParameterSet();
53 54
	h_viewParams.insert(view, params);
	const QList<MapHandlerGen*>& maps = view->getLinkedMaps();
55
	foreach(MapHandlerGen* map, maps)
56
	{
57 58
		PerMapParameterSet p;
		params->perMap.insert(map->getName(), p);
59
	}
60 61

	m_dockTab->refreshUI(params);
62 63 64 65 66
}

void RenderVectorPlugin::viewUnlinked(View* view)
{
	h_viewParams.remove(view);
67 68 69 70 71 72 73 74

	View* current = m_window->getCurrentView();
	if(isLinkedToView(current))
		m_dockTab->refreshUI(h_viewParams[current]);
}

void RenderVectorPlugin::currentViewChanged(View* view)
{
75
	assert(isLinkedToView(view));
76
	m_dockTab->refreshUI(h_viewParams[view]);
77 78
}

79 80 81
void RenderVectorPlugin::mapLinked(View* view, MapHandlerGen* m)
{
	assert(isLinkedToView(view));
82 83
	ParameterSet* params = h_viewParams[view];
	PerMapParameterSet p;
84
	params->perMap.insert(m->getName(), p);
85 86

	m_dockTab->refreshUI(params);
87 88 89 90 91
}

void RenderVectorPlugin::mapUnlinked(View* view, MapHandlerGen* m)
{
	assert(isLinkedToView(view));
92
	ParameterSet* params = h_viewParams[view];
93
	params->perMap.remove(m->getName());
94 95 96 97 98 99

	if(params->selectedMap == m)
	{
		params->selectedMap = NULL;
		m_dockTab->refreshUI(params);
	}
100 101
}

102
void RenderVectorPlugin::cb_selectedMapChanged()
103
{
104
	if(!b_refreshingUI)
105
	{
106 107 108 109
		View* view = m_window->getCurrentView();
		ParameterSet* params = h_viewParams[view];
		QList<QListWidgetItem*> currentItems = m_dockTab->mapList->selectedItems();
		if(!currentItems.empty())
110
		{
111 112 113 114
			const QString& mapname = currentItems[0]->text();
			params->selectedMap = m_window->getMap(mapname);
			m_dockTab->refreshUI(params);
			view->updateGL();
115 116 117 118
		}
	}
}

119
void RenderVectorPlugin::cb_positionVBOChanged(int index)
120
{
121
	if(!b_refreshingUI)
122
	{
123 124 125 126 127
		View* current = m_window->getCurrentView();
		ParameterSet* params = h_viewParams[current];
		MapHandlerGen* map = params->selectedMap;
		params->perMap[map->getName()].positionVBO = map->getVBO(m_dockTab->combo_positionVBO->currentText());
		current->updateGL();
128
	}
129
}
130

131 132 133
void RenderVectorPlugin::cb_vectorVBOChanged(int index)
{
	if(!b_refreshingUI)
134
	{
135 136 137 138 139
		View* current = m_window->getCurrentView();
		ParameterSet* params = h_viewParams[current];
		MapHandlerGen* map = params->selectedMap;
		params->perMap[map->getName()].vectorVBO = map->getVBO(m_dockTab->combo_vectorVBO->currentText());
		current->updateGL();
140 141 142
	}
}

143
void RenderVectorPlugin::cb_refreshVBOs()
144 145
{
	View* current = m_window->getCurrentView();
146 147 148
	if(isLinkedToView(current))
		m_dockTab->refreshUI(h_viewParams[current]);
}
149

150 151 152
void RenderVectorPlugin::cb_vectorsScaleFactorChanged(int i)
{
	if(!b_refreshingUI)
153
	{
154 155 156 157 158
		View* current = m_window->getCurrentView();
		ParameterSet* params = h_viewParams[current];
		MapHandlerGen* m = params->selectedMap;
		params->perMap[m->getName()].vectorsScaleFactor = i / 50.0;
		current->updateGL();
159 160 161 162 163
	}
}



164
void RenderVectorDockTab::refreshUI(ParameterSet* params)
165
{
166
	plugin->setRefreshingUI(true);
167

168 169 170
	mapList->clear();
	combo_positionVBO->clear();
	combo_vectorVBO->clear();
171

172
	MapHandlerGen* map = params->selectedMap;
173

174 175
	QHash<QString, PerMapParameterSet>::const_iterator i = params->perMap.constBegin();
	while (i != params->perMap.constEnd())
176
	{
177 178
		mapList->addItem(i.key());
		if(map != NULL && i.key() == map->getName())
179
		{
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204
			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();
			for(int i = 0; i < vbos.count(); ++i)
			{
				combo_positionVBO->addItem(QString::fromStdString(vbos[i]->name()));
				if(vbos[i] == p.positionVBO)
					combo_positionVBO->setCurrentIndex(i);
				combo_vectorVBO->addItem(QString::fromStdString(vbos[i]->name()));
				if(vbos[i] == p.vectorVBO)
					combo_vectorVBO->setCurrentIndex(i);
			}
			if(p.positionVBO == NULL && vbos.count() > 0)
			{
				p.positionVBO = vbos[0];
				combo_positionVBO->setCurrentIndex(0);
			}
			if(p.vectorVBO == NULL && vbos.count() > 0)
			{
				p.vectorVBO = vbos[0];
				combo_vectorVBO->setCurrentIndex(0);
			}
205 206

			slider_vectorsScaleFactor->setSliderPosition(p.vectorsScaleFactor * 50.0);
207
		}
208
		++i;
209
	}
210 211

	plugin->setRefreshingUI(false);
212 213 214 215 216 217 218 219 220
}



#ifndef DEBUG
Q_EXPORT_PLUGIN2(RenderVectorPlugin, RenderVectorPlugin)
#else
Q_EXPORT_PLUGIN2(RenderVectorPluginD, RenderVectorPlugin)
#endif