plugin.cpp 2.88 KB
Newer Older
Pierre Kraemer's avatar
Pierre Kraemer committed
1 2
#include "plugin.h"

3 4 5 6 7
#include <GL/glew.h>

#include "window.h"
#include "Utils/GLSLShader.h"

Pierre Kraemer's avatar
Pierre Kraemer committed
8 9 10 11 12 13
namespace CGoGN
{

namespace SCHNApps
{

Pierre Kraemer's avatar
Pierre Kraemer committed
14
Plugin::Plugin() :
15 16
	m_window(NULL),
	b_providesRendering(false)
17
{
18
	glewInit();
19
}
Pierre Kraemer's avatar
Pierre Kraemer committed
20 21 22

Plugin::~Plugin()
{
Pierre Kraemer's avatar
Pierre Kraemer committed
23 24
	foreach(View* view, l_views)
		unlinkView(view);
Pierre Kraemer's avatar
Pierre Kraemer committed
25 26 27 28 29 30 31 32 33 34 35 36

	foreach(QWidget* tabWidget, l_tabWidgets)
		removeTabInDock(tabWidget);

	foreach(QAction* action, l_menuActions)
		removeMenuAction(action);

	foreach(QAction* action, l_toolbarActions)
		removeToolbarAction(action);
}

/*********************************************************
37
 * MANAGE LINKED VIEWS
Pierre Kraemer's avatar
Pierre Kraemer committed
38 39
 *********************************************************/

40
void Plugin::linkView(View* view)
Pierre Kraemer's avatar
Pierre Kraemer committed
41
{
Pierre Kraemer's avatar
Pierre Kraemer committed
42 43
	if(view && !l_views.contains(view))
		l_views.push_back(view);
Pierre Kraemer's avatar
Pierre Kraemer committed
44 45
}

Pierre Kraemer's avatar
Pierre Kraemer committed
46
void Plugin::unlinkView(View* view)
Pierre Kraemer's avatar
Pierre Kraemer committed
47
{
48
	l_views.removeOne(view);
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
}

/*********************************************************
 * MANAGE SHADERS
 *********************************************************/

void Plugin::registerShader(Utils::GLSLShader* shader)
{
	if(shader && !l_shaders.contains(shader))
		l_shaders.push_back(shader);
}

void Plugin::unregisterShader(Utils::GLSLShader* shader)
{
	l_shaders.removeOne(shader);
Pierre Kraemer's avatar
Pierre Kraemer committed
64 65 66 67 68 69 70 71
}

/*********************************************************
 * MANAGE DOCK TABS
 *********************************************************/

bool Plugin::addTabInDock(QWidget* tabWidget, const QString& tabText)
{
72
	if(tabWidget && !l_tabWidgets.contains(tabWidget))
Pierre Kraemer's avatar
Pierre Kraemer committed
73
	{
74 75 76
		// tab created by plugins that do not provide rendering are always enabled,
		// the other are enabled only if they are linked to the current view
		m_window->addTabInDock(tabWidget, tabText, !b_providesRendering);
77
		l_tabWidgets.push_back(tabWidget);
Pierre Kraemer's avatar
Pierre Kraemer committed
78 79 80 81 82 83 84 85
		return true;
	}
	else
		return false;
}

void Plugin::removeTabInDock(QWidget* tabWidget)
{
86
	if(l_tabWidgets.removeOne(tabWidget))
Pierre Kraemer's avatar
Pierre Kraemer committed
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
		m_window->removeTabInDock(tabWidget);
}

/*********************************************************
 * MANAGE MENU ACTIONS
 *********************************************************/

bool Plugin::addMenuAction(const QString& menuPath, QAction* action)
{
	if(action && !l_menuActions.contains(action))
	{
		m_window->addMenuAction(menuPath, action);
		l_menuActions.push_back(action);
		return true;
	}
	else
		return false;
}

void Plugin::removeMenuAction(QAction* action)
{
	if(l_menuActions.removeOne(action))
		m_window->removeMenuAction(action);
}

/*********************************************************
 * MANAGE TOOLBAR ACTIONS
 *********************************************************/

bool Plugin::addToolbarAction(QAction* action)
{
	if(action && !l_toolbarActions.contains(action))
	{
		m_window->addToolbarAction(action);
		l_toolbarActions.push_back(action);
		return true;
	}
	else
		return false;
}

void Plugin::removeToolbarAction(QAction* action)
{
	if(l_toolbarActions.removeOne(action))
		m_window->removeToolbarAction(action);
}
Pierre Kraemer's avatar
Pierre Kraemer committed
133 134 135 136

} // namespace SCHNApps

} // namespace CGoGN