visualPlugin.h 4.08 KB
Newer Older
Pierre Kraemer's avatar
Pierre Kraemer committed
1 2 3
#ifndef _VISUALPLUGIN_H_
#define _VISUALPLUGIN_H_

4
#include "plugins/plugin.h"
Pierre Kraemer's avatar
Pierre Kraemer committed
5

6 7
class VisualPlugin : public QObject, public Plugin
{
Pierre Kraemer's avatar
Pierre Kraemer committed
8 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 41 42 43 44 45 46 47 48 49 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 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 144 145 146 147 148 149 150 151 152 153 154 155 156 157
	Q_OBJECT
public:
	VisualPlugin();
	~VisualPlugin();

	virtual void cb_updateMatrix(View* view);

	virtual void cb_redraw(Scene* scene) =0;

	virtual void cb_initGL(Scene* scene) =0;

	void updateGL();
	void updateGL(Scene* scene);



	bool cb_keyPress(Scene* scene, int event) {return false;}

	bool cb_keyRelease(Scene* scene, int event) {return false;}

	bool cb_mousePress(Scene* scene, int button, int x, int y) {return false;}

	bool cb_mouseRelease(Scene* scene, int button, int x, int y) {return false;}

	bool cb_mouseClick(Scene* scene, int button, int x, int y) {return false;}

	bool cb_mouseMove(Scene* scene, int buttons, int x, int y) {return false;}

	bool cb_wheelEvent(Scene* scene, int delta, int x, int y) {return false;}


	virtual void cb_recievedScene(Scene* scene){}
	virtual void cb_removingScene(Scene* scene){}

	virtual void cb_recievedMap(MapHandler* map){}
	virtual void cb_removingMap(MapHandler* map){}



	QString getName() {return m_name;}

	QString getPluginFilePath() {return m_pluginPathFile;}

	void addDependantPlugin(Plugin* dependant);
	void deleteDependantLink(Plugin* dependantPlugin);

	bool hasDependantPlugins(){ return !l_dependantPlugins.isEmpty(); }

	QStringList getDependantPluginNames();



	bool isWaitingForScene(){return (m_waitedScene>0 || m_waitedScene==UNLIMITED_NUMBER_OF_SCENES);}
	void recieveScene(Scene* scene);

	void setWindow(Window* window);

	void setName(QString name);

	void setPluginFilePath(QString path);


	bool activate(bool initializing);
	virtual	bool activate() =0;
	virtual	void disable() =0;

	void deleteLinkWith(Scene* scene);


	Plugin* addDependencie(QString dependencie);
	void suppressDependencieLink(Plugin* dependencie);
	void suppressAllDependencieLinks();
	void suppressDependantLink(Plugin* dependant);
	void suppressAllDependantLinks();

	void unloadDependantPlugins();

	bool hasManualLinkWith(Scene* scene){std::cout << "\ti" << std::endl;return l_recievedScene.contains(scene);}

	bool addMap(MapHandler* map);
	MapHandler* takeMap(MapHandler* map);
	QList<MapHandler*> workingMaps(){return l_map;}
	void setMapNumber(int n){if(n>=l_map.size() || n==UNLIMITED_MAP_NUMBER) m_mapNumber=n;}
	int remainingMapNumber(){return (m_mapNumber!=UNLIMITED_MAP_NUMBER)?(m_mapNumber-l_map.size()):(m_mapNumber);}


	enum {UNLIMITED_NUMBER_OF_SCENES=-1};
protected:

	template<typename T>
	T* getDependencie(QString dependencie){ return( (T*)(this->addDependencie(dependencie)) ); }


	std::list<Scene*> l_scene;

	bool associateScene(QString glv_name, Scene* &scene, bool cb_initGL=false);

	bool addNewScene(QString glv_name, Scene* &scene);
	bool addNewSceneDialog(QString name, Scene* &scene);

	bool addWidgetInDockTab(QWidget* newTabWidget, QString tabText);
	void removeTabInDock(QWidget* tabWidget);

	bool addReferencedMap(QString map_name, MapHandler* map);
	template<typename T>
	MapHandler* addNewReferencedMap(QString map_name, T* &map){
		if(m_window){
			MapHandler* vh= m_window->addNewReferencedMap<T>(map_name, map);
			if(vh) l_map.push_back(vh);
			return vh;
		}
		else{
			System::Error::code= System::Error::BAD_LINK_PLUGIN_WINDOW_f(m_name);
			return NULL;
		}
	}

	MapHandler*  getReferencedMap(QString map_name);


	QList<QAction*> l_action;

	QList<QWidget*> l_customWidget;

	QAction* addMenuAction(QString menuPath, const char* method);
	bool addMenuAction(QString menuPath, QAction* action);
	void deleteActions();
	QAction* addToolbarAction(const char* method, QIcon icon= QIcon());
	bool addToolbarAction(QAction* action);


	int m_waitedScene;
	QList<Scene*> l_recievedScene;

	bool m_allowSameViewSeveralTime;
	void allowSamerViewSeveralTime(bool b){m_allowSameViewSeveralTime=b;};

	void waitingForScene(int nb=UNLIMITED_NUMBER_OF_SCENES);

	ViewButton* addSceneNewViewButton(Scene* scene, QString imagePath);
	bool addSceneViewButton(Scene* scene, ViewButton* viewButton);
	void takeSceneViewButton(Scene* scene, ViewButton* viewButton);

	QList<ViewButton*> l_viewButtons;

signals:
	void recievedScene(Scene*);
};

#endif