surface_renderTopo.cpp 9.42 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12
#include "surface_renderTopo.h"

#include "mapHandler.h"

namespace CGoGN
{

namespace SCHNApps
{

bool Surface_RenderTopo_Plugin::enable()
{
13
	//	magic line that init static variables of GenericMap in the plugins
14
	GenericMap::copyAllStatics(m_schnapps->getStaticPointers());
15

16 17 18 19 20 21 22 23
	m_dockTab = new Surface_RenderTopo_DockTab(m_schnapps, this);
	m_schnapps->addPluginDockTab(this, m_dockTab, "Surface_RenderTopo");

	connect(m_schnapps, SIGNAL(selectedViewChanged(View*, View*)), this, SLOT(selectedViewChanged(View*, View*)));
	connect(m_schnapps, SIGNAL(selectedMapChanged(MapHandlerGen*, MapHandlerGen*)), this, SLOT(selectedMapChanged(MapHandlerGen*, MapHandlerGen*)));
	connect(m_schnapps, SIGNAL(mapAdded(MapHandlerGen*)), this, SLOT(mapAdded(MapHandlerGen*)));
	connect(m_schnapps, SIGNAL(mapRemoved(MapHandlerGen*)), this, SLOT(mapRemoved(MapHandlerGen*)));

24 25 26
	m_shaderTopo1 = new CGoGN::Utils::ShaderSimpleColor();
	registerShader(m_shaderTopo1);

27
	foreach(MapHandlerGen* map, m_schnapps->getMapSet().values())
28
	{
29
		mapAdded(map);
30
	}
31 32 33 34 35 36 37 38

	m_dockTab->updateMapParameters();

	return true;
}

void Surface_RenderTopo_Plugin::disable()
{
39 40 41 42 43
	disconnect(m_schnapps, SIGNAL(selectedViewChanged(View*, View*)), this, SLOT(selectedViewChanged(View*, View*)));
	disconnect(m_schnapps, SIGNAL(selectedMapChanged(MapHandlerGen*, MapHandlerGen*)), this, SLOT(selectedMapChanged(MapHandlerGen*, MapHandlerGen*)));
	disconnect(m_schnapps, SIGNAL(mapAdded(MapHandlerGen*)), this, SLOT(mapAdded(MapHandlerGen*)));
	disconnect(m_schnapps, SIGNAL(mapRemoved(MapHandlerGen*)), this, SLOT(mapRemoved(MapHandlerGen*)));

44 45 46 47 48 49
	foreach(MapHandlerGen* map, m_schnapps->getMapSet().values())
		mapRemoved(map);
}

void Surface_RenderTopo_Plugin::drawMap(View* view, MapHandlerGen* map)
{
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
	ViewMapParam& p = h_viewParameterSet[view][map];

	map->getTopoRender()->setInitialDartsColor(p.dartsColor.redF(),p.dartsColor.greenF(),p.dartsColor.blueF());
	map->getTopoRender()->setColorPhi1(Geom::Vec4f(p.phi1Color.redF(),p.phi1Color.greenF(),p.phi1Color.blueF(),0.0f));
	map->getTopoRender()->setColorPhi2(Geom::Vec4f(p.phi2Color.redF(),p.phi2Color.greenF(),p.phi2Color.blueF(),0.0f));

	MapParam& pm = h_parameterSet[map];

	if (pm.needUpdate)
	{
		map->getTopoRender()->setExplodeEdge(pm.edgesScaleFactor);
		map->getTopoRender()->setExplodeFace(pm.facesScaleFactor);
		QString pos = m_dockTab->combo_positionAttribute->currentText();
		map->updateTopoRender(pos);
		pm.needUpdate = false;
	}

	int code=0;
	if(p.drawDarts)
		code |= 1;
	if(p.drawPhi1)
		code |= 2;
	if(p.drawPhi2)
		code |= 4;
	map->drawTopoRender(code);
75 76 77 78 79 80 81 82 83 84 85 86 87 88
}





void Surface_RenderTopo_Plugin::selectedViewChanged(View *prev, View *cur)
{
	m_dockTab->updateMapParameters();
}

void Surface_RenderTopo_Plugin::selectedMapChanged(MapHandlerGen *prev, MapHandlerGen *cur)
{
	m_dockTab->updateMapParameters();
89 90 91 92 93

	if (cur==NULL)
		m_dockTab->setDisabled(true);
	else
		m_dockTab->setDisabled(false);
94 95 96 97 98
}

void Surface_RenderTopo_Plugin::mapAdded(MapHandlerGen* map)
{
	connect(map, SIGNAL(attributeAdded(unsigned int, const QString&)), this, SLOT(attributeAdded(unsigned int, const QString&)));
99
	map->createTopoRender(m_shaderTopo1);
100 101 102 103 104 105 106 107 108 109 110
}

void Surface_RenderTopo_Plugin::mapRemoved(MapHandlerGen* map)
{
	disconnect(map, SIGNAL(attributeAdded(unsigned int, const QString&)), this, SLOT(attributeAdded(unsigned int, const QString&)));
}





111
void Surface_RenderTopo_Plugin::attributeAdded(unsigned int orbit, const QString& name)
112 113
{
	MapHandlerGen* map = static_cast<MapHandlerGen*>(QObject::sender());
114
	if(orbit == VERTEX && map == m_schnapps->getSelectedMap())
115
	{
116
		m_dockTab->addVertexAttribute(name);
117
	}
118 119 120 121 122 123
}





Sylvain Thery's avatar
Sylvain Thery committed
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
void Surface_RenderTopo_Plugin::changePositionAttribute(const QString& map, const QString& attrName)
{
	MapHandlerGen* m = m_schnapps->getMap(map);
	if (m)
	{
		MapParam& p = h_parameterSet[m];
		p.posAttName = attrName;
		p.needUpdate = true;

		if (m == m_schnapps->getSelectedMap())
		{
			int index = m_dockTab->combo_positionAttribute->findText(attrName);
			if (index > 0)
				m_dockTab->combo_positionAttribute->setCurrentIndex(index);
		}
	}
}
141

Sylvain Thery's avatar
Sylvain Thery committed
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 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 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269
void Surface_RenderTopo_Plugin::changeEdgesScaleFactor(const QString& map, float s)
{
	MapHandlerGen* m = m_schnapps->getMap(map);
	if (m)
	{
		MapParam& p = h_parameterSet[m];
		p.edgesScaleFactor = s;
		p.needUpdate = true;

		if (m == m_schnapps->getSelectedMap())
		{
			m_dockTab->slider_edgesScaleFactor->setValue(int(100.0f*s));
		}
	}
}

void Surface_RenderTopo_Plugin::changeFacesScaleFactor(const QString& map, float s)
{
	MapHandlerGen* m = m_schnapps->getMap(map);
	if (m)
	{
		MapParam& p = h_parameterSet[m];
		p.facesScaleFactor = s;
		p.needUpdate = true;

		if (m == m_schnapps->getSelectedMap())
		{
			m_dockTab->slider_facesScaleFactor->setValue(int(100.0f*s));
		}
	}
}

void Surface_RenderTopo_Plugin::changeDrawDarts(const QString& view, const QString& map, bool b)
{
	View* v = m_schnapps->getView(view);
	MapHandlerGen* m = m_schnapps->getMap(map);
	if (v && m)
	{
		ViewMapParam& p = h_viewParameterSet[v][m];
		p.drawDarts = b;
		if (m == m_schnapps->getSelectedMap())
		{
			m_dockTab->check_drawDarts->setChecked(b);
		}
	}
}

void Surface_RenderTopo_Plugin::changeDrawPhi1(const QString& view, const QString& map, bool b)
{
	View* v = m_schnapps->getView(view);
	MapHandlerGen* m = m_schnapps->getMap(map);
	if (v && m)
	{
		ViewMapParam& p = h_viewParameterSet[v][m];
		p.drawPhi1 = b;
		if (m == m_schnapps->getSelectedMap())
		{
			m_dockTab->check_drawPhi1->setChecked(b);
		}
	}
}

void Surface_RenderTopo_Plugin::changeDrawPhi2(const QString& view, const QString& map, bool b)
{
	View* v = m_schnapps->getView(view);
	MapHandlerGen* m = m_schnapps->getMap(map);
	if (v && m)
	{
		ViewMapParam& p = h_viewParameterSet[v][m];
		p.drawPhi2 = b;
		if (m == m_schnapps->getSelectedMap())
		{
			m_dockTab->check_drawPhi2->setChecked(b);
		}
	}
}


void Surface_RenderTopo_Plugin::changeDartsColor(const QString& view, const QString& map, const QString& color)
{
	View* v = m_schnapps->getView(view);
	MapHandlerGen* m = m_schnapps->getMap(map);	
	if (v && m)
	{
		ViewMapParam& p = h_viewParameterSet[v][m];
		p.dartsColor = QColor(color);
		if (m == m_schnapps->getSelectedMap())
		{
			int index = m_dockTab->combo_dartsColor->findText(color);
			if (index > 0)
				m_dockTab->combo_dartsColor->setCurrentIndex(index);
		}
	}
}

void Surface_RenderTopo_Plugin::changePhi1Color(const QString& view, const QString& map, const QString& color)
{
	View* v = m_schnapps->getView(view);
	MapHandlerGen* m = m_schnapps->getMap(map);
	if (v && m)
	{
		ViewMapParam& p = h_viewParameterSet[v][m];
		p.phi1Color = QColor(color);
		if (m == m_schnapps->getSelectedMap())
		{
			int index = m_dockTab->combo_phi1Color->findText(color);
			if (index > 0)
				m_dockTab->combo_phi1Color->setCurrentIndex(index);
		}
	}
}

void Surface_RenderTopo_Plugin::changePhi2Color(const QString& view, const QString& map, const QString& color)
{
	View* v = m_schnapps->getView(view);
	MapHandlerGen* m = m_schnapps->getMap(map);
	if (v && m)
	{
		ViewMapParam& p = h_viewParameterSet[v][m];
		p.phi2Color = QColor(color);
		if (m == m_schnapps->getSelectedMap())
		{
			int index = m_dockTab->combo_phi2Color->findText(color);
			if (index > 0)
				m_dockTab->combo_phi2Color->setCurrentIndex(index);
		}
	}
}
270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353


//void Surface_RenderTopo_Plugin::changeDrawDarts(View* view, MapHandlerGen* map, bool b, bool fromUI)
//{
//	ParameterSet* params = h_viewParams[view];
//	params->perMap[map->getName()]->drawDarts = b;

//	if(view->isCurrentView())
//	{
//		if(!fromUI)
//			m_dockTab->refreshUI(params);
//		view->updateGL();
//	}
//}

//void Surface_RenderTopo_Plugin::changeDartsColor(View* view, MapHandlerGen* map, QColor c, bool fromUI)
//{
//	ParameterSet* params = h_viewParams[view];
//	PerMapParameterSet* perMap = params->perMap[map->getName()];
//	perMap->dartsColor = c;
//	perMap->m_renderTopo->setInitialDartsColor(c.redF(), c.greenF(), c.blueF());
//	perMap->m_renderTopo->setAllDartsColor(c.redF(), c.greenF(), c.blueF());

//	if(view->isCurrentView())
//	{
//		if(!fromUI)
//			m_dockTab->refreshUI(params);
//		view->updateGL();
//	}
//}

//void Surface_RenderTopo_Plugin::changeDrawPhi1(View* view, MapHandlerGen* map, bool b, bool fromUI)
//{
//	ParameterSet* params = h_viewParams[view];
//	params->perMap[map->getName()]->drawPhi1 = b;

//	if(view->isCurrentView())
//	{
//		if(!fromUI)
//			m_dockTab->refreshUI(params);
//		view->updateGL();
//	}
//}

//void Surface_RenderTopo_Plugin::changePhi1Color(View* view, MapHandlerGen* map, QColor c, bool fromUI)
//{
//	ParameterSet* params = h_viewParams[view];
//	params->perMap[map->getName()]->phi1Color = c;

//	if(view->isCurrentView())
//	{
//		if(!fromUI)
//			m_dockTab->refreshUI(params);
//		view->updateGL();
//	}
//}

//void Surface_RenderTopo_Plugin::changeDrawPhi2(View* view, MapHandlerGen* map, bool b, bool fromUI)
//{
//	ParameterSet* params = h_viewParams[view];
//	params->perMap[map->getName()]->drawPhi2 = b;

//	if(view->isCurrentView())
//	{
//		if(!fromUI)
//			m_dockTab->refreshUI(params);
//		view->updateGL();
//	}
//}

//void Surface_RenderTopo_Plugin::changePhi2Color(View* view, MapHandlerGen* map, QColor c, bool fromUI)
//{
//	ParameterSet* params = h_viewParams[view];
//	params->perMap[map->getName()]->phi2Color = c;

//	if(view->isCurrentView())
//	{
//		if(!fromUI)
//			m_dockTab->refreshUI(params);
//		view->updateGL();
//	}
//}


Sylvain Thery's avatar
Sylvain Thery committed
354 355 356 357 358 359 360

#if CGOGN_QT_DESIRED_VERSION == 5
	Q_PLUGIN_METADATA(IID "CGoGN.SCHNapps.Plugin")
#else
	Q_EXPORT_PLUGIN2(Surface_RenderTopo_Plugin, Surface_RenderTopo_Plugin)
#endif

361 362 363 364

} // namespace SCHNApps

} // namespace CGoGN