Création d'un compte pour un collaborateur extérieur au laboratoire depuis l'intranet ICube : https://intranet.icube.unistra.fr/fr/labs/member/profile

view.cpp 19.6 KB
Newer Older
Pierre Kraemer's avatar
Pierre Kraemer committed
1
2
3
4
5
6
7
8
9
10
#include "view.h"

#include "camera.h"
#include "viewButtonArea.h"
#include "plugin_interaction.h"
#include "mapHandler.h"

#include "Utils/GLSLShader.h"
#include "Algo/Geometry/boundingbox.h"

11
12
#include "slot_debug.h"

Pierre Kraemer's avatar
Pierre Kraemer committed
13
14
15
16
17
18
19
20
21
22
23
#include <QKeyEvent>
#include <QMouseEvent>
#include <QWheelEvent>

namespace CGoGN
{

namespace SCHNApps
{

unsigned int View::viewCount = 0;
24
View::View(const QString& name, SCHNApps* s, QGLFormat& format) :
25
26
27
28
29
30
31
32
33
34
35
36
37
38
	QGLViewer(format, NULL, NULL),
	b_updatingUI(false),
	m_name(name),
	m_schnapps(s),
	m_currentCamera(NULL),
	m_lastSelectedMap(NULL),
	m_buttonArea(NULL),
	m_closeButton(NULL),
	m_VsplitButton(NULL),
	m_HsplitButton(NULL),
	m_buttonAreaLeft(NULL),
	m_mapsButton(NULL),
	m_pluginsButton(NULL),
	m_camerasButton(NULL),
39
40
41
42
43
	m_dialogMaps(NULL),
	m_dialogPlugins(NULL),
	m_dialogCameras(NULL),
	m_frameDrawer(NULL),
	m_textureWallpaper(NULL),
44
45
	m_shaderWallpaper(NULL),
	b_saveSnapshots(false)
46
47
48
{
	++viewCount;

49
50
	setSnapshotFormat("JPEG");
	setSnapshotFileName(m_name);
51
	setSnapshotQuality(100);
52

53
54
55
56
57
58
59
60
	m_currentCamera = m_schnapps->addCamera();
	m_currentCamera->linkView(this);

	connect(m_schnapps, SIGNAL(selectedMapChanged(MapHandlerGen*,MapHandlerGen*)), this, SLOT(selectedMapChanged(MapHandlerGen*,MapHandlerGen*)));

	m_dialogMaps = new ListPopUp("Linked Maps");
	m_dialogPlugins = new ListPopUp("Enabled Plugins");
	m_dialogCameras = new ListPopUp("Cameras");
Pierre Kraemer's avatar
Pierre Kraemer committed
61

62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
//	setCurrentCamera(m_schnapps->addCamera());

	connect(m_schnapps, SIGNAL(mapAdded(MapHandlerGen*)), this, SLOT(mapAdded(MapHandlerGen*)));
	connect(m_schnapps, SIGNAL(mapRemoved(MapHandlerGen*)), this, SLOT(mapRemoved(MapHandlerGen*)));
	connect(m_dialogMaps->list(), SIGNAL(itemChanged(QListWidgetItem*)), this, SLOT(mapCheckStateChanged(QListWidgetItem*)));

	foreach(MapHandlerGen* map, m_schnapps->getMapSet().values())
		mapAdded(map);

	connect(m_schnapps, SIGNAL(pluginEnabled(Plugin*)), this, SLOT(pluginEnabled(Plugin*)));
	connect(m_schnapps, SIGNAL(pluginDisabled(Plugin*)), this, SLOT(pluginDisabled(Plugin*)));
	connect(m_dialogPlugins->list(), SIGNAL(itemChanged(QListWidgetItem*)), this, SLOT(pluginCheckStateChanged(QListWidgetItem*)));

	foreach(Plugin* plug, m_schnapps->getPluginSet().values())
		pluginEnabled(plug);

	connect(m_schnapps, SIGNAL(cameraAdded(Camera*)), this, SLOT(cameraAdded(Camera*)));
	connect(m_schnapps, SIGNAL(cameraRemoved(Camera*)), this, SLOT(cameraRemoved(Camera*)));
	connect(m_dialogCameras->list(), SIGNAL(itemChanged(QListWidgetItem*)), this, SLOT(cameraCheckStateChanged(QListWidgetItem*)));

	foreach(Camera* cam, m_schnapps->getCameraSet().values())
		cameraAdded(cam);

	m_dialogCameras->check(m_currentCamera->getName(),Qt::Checked);
}

88
View::View(const QString& name, SCHNApps* s, QGLFormat& format, const QGLWidget* shareWidget) :
89
	QGLViewer(format, NULL, shareWidget),
Sylvain Thery's avatar
Sylvain Thery committed
90
	b_updatingUI(false),
Pierre Kraemer's avatar
Pierre Kraemer committed
91
92
93
	m_name(name),
	m_schnapps(s),
	m_currentCamera(NULL),
94
	m_lastSelectedMap(NULL),
Pierre Kraemer's avatar
Pierre Kraemer committed
95
96
97
	m_buttonArea(NULL),
	m_closeButton(NULL),
	m_VsplitButton(NULL),
Sylvain Thery's avatar
Sylvain Thery committed
98
99
100
101
102
	m_HsplitButton(NULL),
	m_buttonAreaLeft(NULL),
	m_mapsButton(NULL),
	m_pluginsButton(NULL),
	m_camerasButton(NULL),
103
104
105
106
107
108
	m_dialogMaps(NULL),
	m_dialogPlugins(NULL),
	m_dialogCameras(NULL),
	m_frameDrawer(NULL),
	m_textureWallpaper(NULL),
	m_shaderWallpaper(NULL)
Pierre Kraemer's avatar
Pierre Kraemer committed
109
110
111
{
	++viewCount;

112
113
	setSnapshotFormat("JPEG");
	setSnapshotFileName(m_name);
114
	setSnapshotQuality(100);
115

Pierre Kraemer's avatar
Pierre Kraemer committed
116
	m_currentCamera = m_schnapps->addCamera();
Sylvain Thery's avatar
Sylvain Thery committed
117
	m_currentCamera->linkView(this);
Pierre Kraemer's avatar
Pierre Kraemer committed
118

119
	connect(m_schnapps, SIGNAL(selectedMapChanged(MapHandlerGen*,MapHandlerGen*)), this, SLOT(selectedMapChanged(MapHandlerGen*,MapHandlerGen*)));
Sylvain Thery's avatar
Sylvain Thery committed
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148

	m_dialogMaps = new ListPopUp("Linked Maps");
	m_dialogPlugins = new ListPopUp("Enabled Plugins");
	m_dialogCameras = new ListPopUp("Cameras");

//	setCurrentCamera(m_schnapps->addCamera());

	connect(m_schnapps, SIGNAL(mapAdded(MapHandlerGen*)), this, SLOT(mapAdded(MapHandlerGen*)));
	connect(m_schnapps, SIGNAL(mapRemoved(MapHandlerGen*)), this, SLOT(mapRemoved(MapHandlerGen*)));
	connect(m_dialogMaps->list(), SIGNAL(itemChanged(QListWidgetItem*)), this, SLOT(mapCheckStateChanged(QListWidgetItem*)));

	foreach(MapHandlerGen* map, m_schnapps->getMapSet().values())
		mapAdded(map);

	connect(m_schnapps, SIGNAL(pluginEnabled(Plugin*)), this, SLOT(pluginEnabled(Plugin*)));
	connect(m_schnapps, SIGNAL(pluginDisabled(Plugin*)), this, SLOT(pluginDisabled(Plugin*)));
	connect(m_dialogPlugins->list(), SIGNAL(itemChanged(QListWidgetItem*)), this, SLOT(pluginCheckStateChanged(QListWidgetItem*)));

	foreach(Plugin* plug, m_schnapps->getPluginSet().values())
		pluginEnabled(plug);

	connect(m_schnapps, SIGNAL(cameraAdded(Camera*)), this, SLOT(cameraAdded(Camera*)));
	connect(m_schnapps, SIGNAL(cameraRemoved(Camera*)), this, SLOT(cameraRemoved(Camera*)));
	connect(m_dialogCameras->list(), SIGNAL(itemChanged(QListWidgetItem*)), this, SLOT(cameraCheckStateChanged(QListWidgetItem*)));

	foreach(Camera* cam, m_schnapps->getCameraSet().values())
		cameraAdded(cam);

	m_dialogCameras->check(m_currentCamera->getName(),Qt::Checked);
Pierre Kraemer's avatar
Pierre Kraemer committed
149
150
151
152
153
154
155
156
}

View::~View()
{
	qglviewer::Camera* c = new qglviewer::Camera();
	this->setCamera(c);
	m_currentCamera->unlinkView(this);

Sylvain Thery's avatar
Sylvain Thery committed
157

Pierre Kraemer's avatar
Pierre Kraemer committed
158
159
160
161
162
163
	foreach(PluginInteraction* p, l_plugins)
		unlinkPlugin(p);

	foreach(MapHandlerGen* m, l_maps)
		unlinkMap(m);

Sylvain Thery's avatar
Sylvain Thery committed
164

Pierre Kraemer's avatar
Pierre Kraemer committed
165
	delete m_buttonArea;
Sylvain Thery's avatar
Sylvain Thery committed
166
167
168
169
170
171
172
173
174
175
176
177
	delete m_buttonAreaLeft;

	delete m_dialogMaps;
	delete m_dialogPlugins;
	delete m_dialogCameras;
}

void View::closeDialogs()
{
	m_dialogMaps->close();
	m_dialogPlugins->close();
	m_dialogCameras->close();
Pierre Kraemer's avatar
Pierre Kraemer committed
178
179
180
181
}

void View::setCurrentCamera(Camera* c)
{
Sylvain Thery's avatar
Sylvain Thery committed
182
//	DEBUG_SLOT();
Pierre Kraemer's avatar
Pierre Kraemer committed
183
184
185
186
187
188
189
190
191
192
	if(c != m_currentCamera && c != NULL)
	{
		Camera* prev = m_currentCamera;
		if(prev)
			prev->unlinkView(this);

		m_currentCamera = c;
		this->setCamera(m_currentCamera);
		m_currentCamera->linkView(this);

Sylvain Thery's avatar
Sylvain Thery committed
193
194
//		DEBUG_EMIT("currentCameraChanged");
//		emit(currentCameraChanged(prev, c));
Pierre Kraemer's avatar
Pierre Kraemer committed
195

Sylvain Thery's avatar
Sylvain Thery committed
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
		if(prev)
		{
			QListWidgetItem* prevItem = m_dialogCameras->findItem(prev->getName());
			if(prevItem)
			{
				b_updatingUI = true;
				prevItem->setCheckState(Qt::Unchecked);
				b_updatingUI = false;
			}
		}
		if(m_currentCamera)
		{
			QListWidgetItem* curItem = m_dialogCameras->findItem(m_currentCamera->getName());
			if(curItem)
			{
				b_updatingUI = true;
				curItem->setCheckState(Qt::Checked);
				b_updatingUI = false;
			}
		}

//		b_updatingUI = true;
//		m_dialogCameras->check(c->getName(),Qt::Checked);
//		b_updatingUI = false;

//		updateCurrentCameraBB();
		m_currentCamera->updateParams();
Pierre Kraemer's avatar
Pierre Kraemer committed
223
224
225
226
227
		updateGL();
	}
}

void View::setCurrentCamera(const QString& name)
228
{	
Pierre Kraemer's avatar
Pierre Kraemer committed
229
230
231
232
233
234
235
236
237
238
239
240
	Camera* c = m_schnapps->getCamera(name);
	if(c)
		setCurrentCamera(c);
}

bool View::usesCamera(const QString& cameraName) const
{
	return m_currentCamera->getName() == cameraName;
}

void View::linkPlugin(PluginInteraction* plugin)
{
241
	DEBUG_SLOT();
Pierre Kraemer's avatar
Pierre Kraemer committed
242
243
244
245
	if(plugin && !l_plugins.contains(plugin))
	{
		l_plugins.push_back(plugin);
		plugin->linkView(this);
246
		DEBUG_EMIT("pluginLinked");
Pierre Kraemer's avatar
Pierre Kraemer committed
247
		emit(pluginLinked(plugin));
Sylvain Thery's avatar
Sylvain Thery committed
248
249

		b_updatingUI = true;
250
		m_dialogPlugins->check(plugin->getName(), Qt::Checked);
Sylvain Thery's avatar
Sylvain Thery committed
251
252
		b_updatingUI = false;

Pierre Kraemer's avatar
Pierre Kraemer committed
253
254
255
256
257
258
259
260
261
262
263
264
265
		updateGL();
	}
}

void View::linkPlugin(const QString& name)
{
	PluginInteraction* p = dynamic_cast<PluginInteraction*>(m_schnapps->getPlugin(name));
	if(p)
		linkPlugin(p);
}

void View::unlinkPlugin(PluginInteraction* plugin)
{
266
	DEBUG_SLOT();
Pierre Kraemer's avatar
Pierre Kraemer committed
267
268
269
	if(l_plugins.removeOne(plugin))
	{
		plugin->unlinkView(this);
270
		DEBUG_EMIT("pluginUnlinked");
Pierre Kraemer's avatar
Pierre Kraemer committed
271
		emit(pluginUnlinked(plugin));
Sylvain Thery's avatar
Sylvain Thery committed
272
273

		b_updatingUI = true;
274
		m_dialogPlugins->check(plugin->getName(), Qt::Unchecked);
Sylvain Thery's avatar
Sylvain Thery committed
275
276
		b_updatingUI = false;

277
		updateGL();
Pierre Kraemer's avatar
Pierre Kraemer committed
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
	}
}

void View::unlinkPlugin(const QString& name)
{
	PluginInteraction* p = dynamic_cast<PluginInteraction*>(m_schnapps->getPlugin(name));
	if(p)
		unlinkPlugin(p);
}

bool View::isLinkedToPlugin(const QString& name) const
{
	PluginInteraction* p = dynamic_cast<PluginInteraction*>(m_schnapps->getPlugin(name));
	return l_plugins.contains(p);
}

void View::linkMap(MapHandlerGen* map)
{
296
	DEBUG_SLOT();
Pierre Kraemer's avatar
Pierre Kraemer committed
297
298
299
300
	if(map && !l_maps.contains(map))
	{
		l_maps.push_back(map);
		map->linkView(this);
301
		DEBUG_EMIT("mapLinked");
Pierre Kraemer's avatar
Pierre Kraemer committed
302
		emit(mapLinked(map));
303

Sylvain Thery's avatar
Sylvain Thery committed
304
305
		std::cout << "View::linkMap Maps:"<<map->getName().toStdString()<< std::endl;
		m_currentCamera->updateParams();
Pierre Kraemer's avatar
Pierre Kraemer committed
306
		updateGL();
307

Sylvain Thery's avatar
Sylvain Thery committed
308
309
//		connect(map->getFrame(), SIGNAL(modified()), this, SLOT(updateGL()));
//		connect(map->getFrame(), SIGNAL(modified()), m_currentCamera, SLOT(BBModified(map)));
310
		connect(map, SIGNAL(selectedCellsChanged(CellSelectorGen*)), this, SLOT(updateGL()));
311

312
		if(map->isSelectedMap())
313
			setManipulatedFrame(map->getFrame());
Sylvain Thery's avatar
Sylvain Thery committed
314
315

		b_updatingUI = true;
316
		m_dialogMaps->check(map->getName(), Qt::Checked);
Sylvain Thery's avatar
Sylvain Thery committed
317
		b_updatingUI = false;
Pierre Kraemer's avatar
Pierre Kraemer committed
318
319
320
321
322
323
324
325
326
327
328
329
	}
}

void View::linkMap(const QString& name)
{
	MapHandlerGen* m = m_schnapps->getMap(name);
	if(m)
		linkMap(m);
}

void View::unlinkMap(MapHandlerGen* map)
{
330
	DEBUG_SLOT();
Pierre Kraemer's avatar
Pierre Kraemer committed
331
332
333
	if(l_maps.removeOne(map))
	{
		map->unlinkView(this);
334
		DEBUG_EMIT("mapUnlinked");
Pierre Kraemer's avatar
Pierre Kraemer committed
335
		emit(mapUnlinked(map));
336

Sylvain Thery's avatar
Sylvain Thery committed
337
338
//		updateCurrentCameraBB();
		m_currentCamera->updateParams();
339
		updateGL();
340

Pierre Kraemer's avatar
Pierre Kraemer committed
341
		disconnect(map->getFrame(), SIGNAL(modified()), this, SLOT(updateGL()));
Pierre Kraemer's avatar
Pierre Kraemer committed
342
		disconnect(map, SIGNAL(selectedCellsChanged(CellSelectorGen*)), this, SLOT(updateGL()));
343
344
345

		if(map == m_schnapps->getSelectedMap())
			setManipulatedFrame(NULL);
Sylvain Thery's avatar
Sylvain Thery committed
346
347

		b_updatingUI = true;
348
		m_dialogMaps->check(map->getName(), Qt::Unchecked);
Sylvain Thery's avatar
Sylvain Thery committed
349
350
		b_updatingUI = false;

Pierre Kraemer's avatar
Pierre Kraemer committed
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
	}
}

void View::unlinkMap(const QString& name)
{
	MapHandlerGen* m = m_schnapps->getMap(name);
	if(m)
		unlinkMap(m);
}

bool View::isLinkedToMap(const QString& name) const
{
	MapHandlerGen* m = m_schnapps->getMap(name);
	return l_maps.contains(m);
}

void View::init()
{
369
370
371
372
373
374
375
376
377
378
379
	glewExperimental = GL_TRUE; // needed for GL Core Profile 3.3
	glewInit();

//	int major = 0;
//	int minor = 0;
//	glGetIntegerv(GL_MAJOR_VERSION, &major);
//	glGetIntegerv(GL_MINOR_VERSION, &minor);
//	std::cout << this->getName().toStdString() << "is using GL "<< major <<"."<< minor << std::endl;

	qglviewer::Camera* c = this->camera();
	this->setCamera(m_currentCamera);
Sylvain Thery's avatar
Sylvain Thery committed
380
//	delete c;
381
382
383
384
385

	this->setBackgroundColor(QColor(0,0,0));
	glEnable(GL_DEPTH_TEST);
	glDepthFunc(GL_LESS);

Pierre Kraemer's avatar
Pierre Kraemer committed
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
	m_buttonArea = new ViewButtonArea(this);
	m_buttonArea->setTopRightPosition(this->width(), 0);

	m_VsplitButton = new ViewButton(":icons/icons/Vsplit.png", this);
	m_buttonArea->addButton(m_VsplitButton);
	connect(m_VsplitButton, SIGNAL(clicked(int, int, int, int)), this, SLOT(ui_verticalSplitView(int, int, int, int)));

	m_HsplitButton = new ViewButton(":icons/icons/Hsplit.png", this);
	m_buttonArea->addButton(m_HsplitButton);
	connect(m_HsplitButton, SIGNAL(clicked(int, int, int, int)), this, SLOT(ui_horizontalSplitView(int, int, int, int)));

	m_closeButton = new ViewButton(":icons/icons/close.png", this);
	m_buttonArea->addButton(m_closeButton);
	connect(m_closeButton, SIGNAL(clicked(int, int, int, int)), this, SLOT(ui_closeView(int, int, int, int)));

Sylvain Thery's avatar
Sylvain Thery committed
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
	m_buttonAreaLeft = new ViewButtonArea(this);
	m_buttonAreaLeft->setTopLeftPosition(0, 0);

	m_mapsButton = new ViewButton(":icons/icons/maps.png", this);
	m_buttonAreaLeft->addButton(m_mapsButton);
	connect(m_mapsButton, SIGNAL(clicked(int, int, int, int)), this, SLOT(ui_mapsListView(int, int, int, int)));

	m_pluginsButton = new ViewButton(":icons/icons/plugins.png", this);
	m_buttonAreaLeft->addButton(m_pluginsButton);
	connect(m_pluginsButton, SIGNAL(clicked(int, int, int, int)), this, SLOT(ui_pluginsListView(int, int, int, int)));

	m_camerasButton = new ViewButton(":icons/icons/cameras.png", this);
	m_buttonAreaLeft->addButton(m_camerasButton);
	connect(m_camerasButton, SIGNAL(clicked(int, int, int, int)), this, SLOT(ui_camerasListView(int, int, int, int)));

416
	// FRAME DRAWER
Sylvain Thery's avatar
Sylvain Thery committed
417

418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
	m_frameDrawer = new Utils::Drawer();
	glm::mat4 mm(1.0);
	glm::mat4 pm(1.0);
	m_frameDrawer->getShader()->updateMatrices(mm, pm);

	m_frameDrawer->newList(GL_COMPILE);
	m_frameDrawer->color3f(0.0f,1.0f,0.0f);
	m_frameDrawer->lineWidth(4.0f);
	m_frameDrawer->begin(GL_LINE_LOOP);
	m_frameDrawer->vertex3f(-1.0f,-1.0f, 0.0f);
	m_frameDrawer->vertex3f( 1.0f,-1.0f, 0.0f);
	m_frameDrawer->vertex3f( 1.0f, 1.0f, 0.0f);
	m_frameDrawer->vertex3f(-1.0f, 1.0f, 0.0f);
	m_frameDrawer->end();
	m_frameDrawer->endList();

//	qglviewer::Camera* c = this->camera();
//	this->setCamera(m_currentCamera);
//	delete c;
Pierre Kraemer's avatar
Pierre Kraemer committed
437

438
439
440
441
442
	m_textureWallpaper = new Utils::Texture<2, Geom::Vec3uc>(GL_UNSIGNED_BYTE);
	m_textureWallpaper->create(Geom::Vec2ui(1024, 1024));
	const float max = m_textureWallpaper->size()[0];
	for (unsigned int ki = 0; ki < m_textureWallpaper->size()[0]; ++ki)
	{
443
		for (unsigned int kj = 0; kj < m_textureWallpaper->size()[1]; ++kj)
444
		{
445
446
			float col = 255 - (255 * ((kj/max)*0.6 + 0.2));
			(*m_textureWallpaper)(ki, kj) = Geom::Vec3f(col, col, col);
447
448
449
450
451
452
453
454
455
		}
	}
	m_textureWallpaper->update();
	m_textureWallpaper->setWrapping(GL_CLAMP_TO_EDGE);

	m_shaderWallpaper = new Utils::ShaderWallPaper();
	m_shaderWallpaper->setTextureUnit(GL_TEXTURE0);
	m_shaderWallpaper->setTexture(m_textureWallpaper);

Pierre Kraemer's avatar
Pierre Kraemer committed
456
457
458
459
460
	this->setBackgroundColor(QColor(0,0,0));
}

void View::preDraw()
{
461
	if (Utils::GLSLShader::CURRENT_OGL_VERSION >= 3)
462
		makeCurrent();
Pierre Kraemer's avatar
Pierre Kraemer committed
463
464
465
466
467
468
469
	m_currentCamera->setScreenWidthAndHeight(width(), height());

	QGLViewer::preDraw();
}

void View::draw()
{
470
	if (Utils::GLSLShader::CURRENT_OGL_VERSION >= 3)
471
472
473
474
475
476
	{
		glEnable(GL_DEPTH_TEST);
		glDepthFunc(GL_LESS);
		glClear(GL_DEPTH_BUFFER_BIT|GL_COLOR_BUFFER_BIT);
	}

Sylvain Thery's avatar
Sylvain Thery committed
477
478
479
	const CameraSet& cams = m_schnapps->getCameraSet();
	QList<Camera*> lc = cams.values();
	foreach(Camera* camera, lc)
Pierre Kraemer's avatar
Pierre Kraemer committed
480
481
482
483
484
485
486
487
	{
		if(camera != m_currentCamera)
		{
			if(camera->getDraw()) camera->draw();
			if(camera->getDrawPath()) camera->drawAllPaths();
		}
	}

Sylvain Thery's avatar
Sylvain Thery committed
488
489
490
// for debugging
//	m_currentCamera->drawBBCam();

491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
	glm::mat4 mm = getCurrentModelViewMatrix();
	glm::mat4 pm = getCurrentProjectionMatrix();

	MapHandlerGen* selectedMap = m_schnapps->getSelectedMap();

	foreach(MapHandlerGen* map, l_maps)
	{
		glm::mat4 map_mm = mm * map->getFrameMatrix();

		if(map == selectedMap)
		{
			Utils::GLSLShader* bbShader = map->getBBDrawerShader();
			if(bbShader)
				bbShader->updateMatrices(pm, map_mm);
			map->drawBB();
		}

		foreach(PluginInteraction* plugin, l_plugins)
		{
			foreach(Utils::GLSLShader* shader, plugin->getShaders())
				shader->updateMatrices(pm, map_mm);
			plugin->drawMap(this, map);
		}
	}
Pierre Kraemer's avatar
Pierre Kraemer committed
515
516

	foreach(PluginInteraction* plugin, l_plugins)
517
		plugin->draw(this);
518
519

	m_shaderWallpaper->draw();
Pierre Kraemer's avatar
Pierre Kraemer committed
520
521
522
523
524
525
}

void View::postDraw()
{
	if(isSelectedView())
		drawFrame();
526
	drawButtons();
Pierre Kraemer's avatar
Pierre Kraemer committed
527
528
529
530
531
532
533
534
	QGLViewer::postDraw();
}

void View::resizeGL(int width, int height)
{
	QGLViewer::resizeGL(width, height);
	if(m_buttonArea)
		m_buttonArea->setTopRightPosition(width, 0);
Sylvain Thery's avatar
Sylvain Thery committed
535
536
537

	if(m_buttonAreaLeft)
		m_buttonAreaLeft->setTopLeftPosition(0, 0);
Pierre Kraemer's avatar
Pierre Kraemer committed
538
539
540
541
542
}

void View::drawButtons()
{
	m_buttonArea->draw();
Sylvain Thery's avatar
Sylvain Thery committed
543
	m_buttonAreaLeft->draw();
Pierre Kraemer's avatar
Pierre Kraemer committed
544
545
546
547
}

void View::drawFrame()
{
548
549
550
	glDisable(GL_DEPTH_TEST);
	m_frameDrawer->callList();
	glEnable(GL_DEPTH_TEST);
Pierre Kraemer's avatar
Pierre Kraemer committed
551
552
553
554
}

void View::keyPressEvent(QKeyEvent* event)
{
555
556
557
558
559
560
561
562
563
564
565
566
567
568
	if (event->key() == Qt::Key_S)
	{
		b_saveSnapshots = !b_saveSnapshots;
		if (b_saveSnapshots)
			connect(this, SIGNAL(drawFinished(bool)), this, SLOT(saveSnapshot(bool)));
		else
			disconnect(this, SIGNAL(drawFinished(bool)), this, SLOT(saveSnapshot(bool)));
	}
	else
	{
		foreach(PluginInteraction* plugin, l_plugins)
			plugin->keyPress(this, event);
		QGLViewer::keyPressEvent(event);
	}
Pierre Kraemer's avatar
Pierre Kraemer committed
569
570
571
572
573
574
575
576
577
578
579
580
581
}

void View::keyReleaseEvent(QKeyEvent *event)
{
	foreach(PluginInteraction* plugin, l_plugins)
		plugin->keyRelease(this, event);
	QGLViewer::keyReleaseEvent(event);
}

void View::mousePressEvent(QMouseEvent* event)
{
	if(m_buttonArea->isClicked(event->x(), event->y()))
		m_buttonArea->clickButton(event->x(), event->y(), event->globalX(), event->globalY());
Sylvain Thery's avatar
Sylvain Thery committed
582
583
	else if(m_buttonAreaLeft->isClicked(event->x(), event->y()))
		m_buttonAreaLeft->clickButton(event->x(), event->y(), event->globalX(), event->globalY());
Pierre Kraemer's avatar
Pierre Kraemer committed
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
	else
	{
		if(!isSelectedView())
			m_schnapps->setSelectedView(this);
		foreach(PluginInteraction* plugin, l_plugins)
			plugin->mousePress(this, event);
		QGLViewer::mousePressEvent(event);
	}
}

void View::mouseReleaseEvent(QMouseEvent* event)
{
	foreach(PluginInteraction* plugin, l_plugins)
		plugin->mouseRelease(this, event);
	QGLViewer::mouseReleaseEvent(event);
}

void View::mouseMoveEvent(QMouseEvent* event)
{
	foreach(PluginInteraction* plugin, l_plugins)
		plugin->mouseMove(this, event);
	QGLViewer::mouseMoveEvent(event);
}

void View::wheelEvent(QWheelEvent* event)
{
	foreach(PluginInteraction* plugin, l_plugins)
		plugin->wheelEvent(this, event);
	QGLViewer::wheelEvent(event);
}

glm::mat4 View::getCurrentModelViewMatrix() const
{
	GLdouble gl_mvm[16];
	camera()->getModelViewMatrix(gl_mvm);
	glm::mat4 mvm;
	for(unsigned int i = 0; i < 4; ++i)
	{
		for(unsigned int j = 0; j < 4; ++j)
			mvm[i][j] = (float)gl_mvm[i*4+j];
	}
	return mvm;
}

glm::mat4 View::getCurrentProjectionMatrix() const
{
	GLdouble gl_pm[16];
	camera()->getProjectionMatrix(gl_pm);
	glm::mat4 pm;
	for(unsigned int i = 0; i < 4; ++i)
	{
		for(unsigned int j = 0; j < 4; ++j)
			pm[i][j] = (float)gl_pm[i*4+j];
	}
	return pm;
}

glm::mat4 View::getCurrentModelViewProjectionMatrix() const
{
	GLdouble gl_mvpm[16];
	camera()->getModelViewProjectionMatrix(gl_mvpm);
	glm::mat4 mvpm;
	for(unsigned int i = 0; i < 4; ++i)
	{
		for(unsigned int j = 0; j < 4; ++j)
			mvpm[i][j] = (float)gl_mvpm[i*4+j];
	}
	return mvpm;
}

654
655
void View::selectedMapChanged(MapHandlerGen* prev, MapHandlerGen* cur)
{
656
	DEBUG_SLOT();
657
658
659
660
661
	if(cur && isLinkedToMap(cur))
		setManipulatedFrame(cur->getFrame());
	updateGL();
}

Sylvain Thery's avatar
Sylvain Thery committed
662
void View::ui_verticalSplitView(int x, int y, int /*globalX*/, int /*globalY*/)
Pierre Kraemer's avatar
Pierre Kraemer committed
663
664
665
666
{
	m_schnapps->splitView(m_name, Qt::Horizontal);
}

Sylvain Thery's avatar
Sylvain Thery committed
667
void View::ui_horizontalSplitView(int x, int y, int /*globalX*/, int /*globalY*/)
Pierre Kraemer's avatar
Pierre Kraemer committed
668
669
670
671
{
	m_schnapps->splitView(m_name, Qt::Vertical);
}

Sylvain Thery's avatar
Sylvain Thery committed
672
void View::ui_closeView(int x, int y, int /*globalX*/, int /*globalY*/)
Pierre Kraemer's avatar
Pierre Kraemer committed
673
674
675
676
{
	m_schnapps->removeView(m_name);
}

Sylvain Thery's avatar
Sylvain Thery committed
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
void View::ui_mapsListView(int x, int y, int globalX, int globalY)
{
	if (m_dialogMaps->isHidden())
	{
		m_dialogMaps->show();
		m_dialogMaps->move(QPoint(globalX,globalY+8));
		m_dialogCameras->hide();
		m_dialogPlugins->hide();
	}
}

void View::ui_pluginsListView(int x, int y, int globalX, int globalY)
{
	if (m_dialogPlugins->isHidden())
	{
		m_dialogPlugins->show();
		m_dialogPlugins->move(QPoint(globalX,globalY+8));
		m_dialogMaps->hide();
		m_dialogCameras->hide();
	}
}

void View::ui_camerasListView(int x, int y, int globalX, int globalY)
{
	if (m_dialogCameras->isHidden())
	{
		m_dialogCameras->show();
		m_dialogCameras->move(QPoint(globalX,globalY+8));
		m_dialogPlugins->hide();
		m_dialogMaps->hide();
	}
}

void View::mapAdded(MapHandlerGen* mh )
{
	DEBUG_SLOT();
	if (mh)
	{
		m_dialogMaps->addItem(mh->getName());
	}
}

void View::mapRemoved(MapHandlerGen* mh )
{
	DEBUG_SLOT();
	if (mh)
	{
		m_dialogMaps->removeItem(mh->getName());
	}
}

void View::pluginEnabled(Plugin *plugin)
{
	DEBUG_SLOT();
	if (dynamic_cast<PluginInteraction*>(plugin))
	{
		m_dialogPlugins->addItem(plugin->getName());
	}

}

void View::pluginDisabled(Plugin *plugin)
{
	DEBUG_SLOT();
	if (dynamic_cast<PluginInteraction*>(plugin))
	{
		m_dialogPlugins->removeItem(plugin->getName());
	}
}


void View::cameraAdded(Camera* camera)
{
	DEBUG_SLOT();
	if (camera)
	{
		m_dialogCameras->addItem(camera->getName());
	}
}

void View::cameraRemoved(Camera* camera)
{
	DEBUG_SLOT();
	if (camera)
	{
		m_dialogCameras->removeItem(camera->getName());
	}
}

void View::mapCheckStateChanged(QListWidgetItem* item)
{
	if (b_updatingUI)
		return;

	DEBUG_SLOT();
772
	if (item->checkState() == Qt::Checked)
Sylvain Thery's avatar
Sylvain Thery committed
773
774
775
776
777
778
779
780
781
782
783
		linkMap(item->text());
	else
		unlinkMap(item->text());
}

void View::pluginCheckStateChanged(QListWidgetItem* item)
{
	if (b_updatingUI)
		return;

	DEBUG_SLOT();
784
	if (item->checkState() == Qt::Checked)
Sylvain Thery's avatar
Sylvain Thery committed
785
786
787
788
789
790
791
792
793
794
795
		linkPlugin(item->text());
	else
		unlinkPlugin(item->text());
}

void View::cameraCheckStateChanged(QListWidgetItem* item)
{
	if (b_updatingUI)
		return;

	DEBUG_SLOT();
796
	if (item->checkState() == Qt::Checked)
Sylvain Thery's avatar
Sylvain Thery committed
797
798
799
		setCurrentCamera(item->text());
}

Pierre Kraemer's avatar
Pierre Kraemer committed
800
801
802
} // namespace SCHNApps

} // namespace CGoGN