#ifndef INTERFACES_H #define INTERFACES_H #include #include #include //#include class ProjectorWidget; class ProjectorData; /** * Projector plugin interface class to have common interface with all projector plugins. * */ class ProjectorInterface { public: /** * Destructor (virtual because the class is pure virtual). * */ virtual ~ProjectorInterface() {} /** * Gets the name of the plugin. * * @return The name of the plugin. * */ virtual QString name(void) const = 0; /** * Gets the list of the available projectors. * * @return The list of the available projectors. * */ virtual QStringList projectors(void) const = 0; /** * Instanciates a new ProjectorWidget for the specified projector. * This function is called by the QChannelWidget constructor, when the * stackedWidget is built. * * @param projector A const reference on a string that contains the name of * the projector, such as projectors() has returned it. * * @return A pointer on the new instanciated ProjectorWidget. * */ virtual ProjectorWidget *newProjectorWidget(const QString& projector) = 0; /** * Instanciates a new ProjectorData for the specified projector. * This function is called by the Channel when it needs to create or copy * some ProjectorData. * * @param projector A const reference on a string that contains the name of * the projector, such as projectors() has returned it. * * @return A pointer on the new instanciated ProjectorData. * */ virtual ProjectorData *newProjectorData(const QString& projector) = 0; }; /** * Projector data class to store informations about Projectors. * This class is not a pure virtual class, so projector plugins does not need to * instanciate it if it is not necessary. * */ class ProjectorData { public: /** * Constructor. * * @param plugin A pointer on the plugin that owns the projector. * */ ProjectorData(ProjectorInterface *plugin): m_bShow(true), m_bShowArea(true), m_plugin(plugin) { Q_ASSERT(NULL!=plugin); } /** * Copy constructor. * * @param data A const reference on the source data. * */ ProjectorData (const ProjectorData& data) { copy_from(data); } /** * Destructor. * */ virtual ~ProjectorData() {} /** * Gets the ProjectorInterface which instanciated the ProjectorData. * * @return A pointer on the ProjectorInterface which instanciated the * ProjectorData. * */ ProjectorInterface* plugin() {return m_plugin;} /** * Gets the ProjectorInterface which instanciated the ProjectorData. * This fonction differs from the previous one by the "const" attribute. * * @return A const pointer on the ProjectorInterface which instanciated the * ProjectorData. * */ const ProjectorInterface* plugin() const {return m_plugin;} /** * Draws the projector. * This method draws the geometric projector data. For instance, for a * standard projector, it draws the frustum in the scene. * * @param bSelected true if the projector is selected. * */ virtual void draw(bool bSelected) {Q_UNUSED(bSelected);} /** * Starts the rendering through the projector. * For a standard projector, this is the call to 'glFrustum()'. * */ virtual void beginDraw(void){} /** * Ends the rendering through the projector. * For a standard projector, this is the call to 'glPop...()'. * This method restores the state of OpenGL before the call to beginDraw(). * */ virtual void endDraw(void){} /** * Starts the projection of the image. * This is used by Screen::draw(source) when source is * PROJECT_SOURCE_PROJECTORAREA or PROJECT_SOURCE_EXPORT_BLENDING * */ virtual void beginProjection(void){} /** * Ends the projection of the image. * This is used by Screen::draw(source) when source is * PROJECT_SOURCE_PROJECTORAREA or PROJECT_SOURCE_EXPORT_BLENDING * */ virtual void endProjection(void){} /** * Sets the VisibleFar distance parameter. * * The Visible Far dist is used for the representation of the projector from * outside. The name comes from the frustum case, but it is used for any * kind of projector now. * * @param farDist The new visible-far distance. * */ virtual void setVisibleFar(float farDist) {Q_UNUSED(farDist);} /** * Copies the data from a ProjectorData. * * @param data A const-reference on the data to be copied. * * @return true if the copy suceeds, false otherwise. * */ virtual bool copy_from(const ProjectorData& data) {Q_ASSERT(m_plugin==data.m_plugin); m_bShow=data.m_bShow; m_bShowArea=data.m_bShowArea; return true;} /** * Check if 2 datas are equal. * * @param data A const-reference on the data to be checked. * @return true if the datas are the same, false otherwise. * */ virtual bool is_equal_to(const ProjectorData& data) const {return m_plugin==data.m_plugin && m_bShow==data.m_bShow && m_bShowArea==data.m_bShowArea;} /** * Sets the Show parameter. * * @param bShow The new Show parameter. * */ void setShow(bool bShow) {m_bShow = bShow;} /** * Gets the Show parameter. * * @return The Show parameter. * */ bool getShow() const {return m_bShow;} /** * Sets the ShowArea parameter. * * @param bShow The new ShowArea parameter. * */ void setShowArea(bool bShowArea) {m_bShowArea = bShowArea;} /** * Gets the ShowArea parameter. * * @return The ShowArea parameter. * */ bool getShowArea() const {return m_bShowArea;} /** * Restore the export settings from XML data. * * @param element Parent XML element of the export settings data. * */ virtual void initFromDOMElement(const QDomElement& element) {if (!element.isNull()) {m_bShow=element.attribute("show").toLower()=="true"; m_bShowArea=element.attribute("showArea").toLower()=="true";}} /** * Store the current export settings as XML data. * * @param name XML node name of the data. * @param doc XML document to store the data. * * @return Current export settings data as XML data. * */ virtual QDomElement domElement(const QString& name, QDomDocument& doc) const { QDomElement de = doc.createElement(name); de.setAttribute("show", (m_bShow?"true":"false")); de.setAttribute("showArea", (m_bShowArea?"true":"false")); return de;} /** * Gets the projector name. * This is the name that is in the projector list of the * ProjectorInterface::projectors(). * * @return The name of the projector. * */ virtual const QString& projector(void) const = 0; /** * Gets the projector full name. * This name can be used in the interface of Projection Designer to define in a unique way the projector. * * @return the fullname of the projector. * */ QString getFullName(void) const { Q_ASSERT(m_plugin); QString projector_fullname = projector(); projector_fullname += " ("; projector_fullname += m_plugin->name(); projector_fullname += ")"; return projector_fullname; } protected: bool m_bShow; ///< Visibility flag bool m_bShowArea; ///< Area visibility flag private: ProjectorInterface *m_plugin; ///< The ProjectorInterface in which the projector is. }; /** * Projector widget class implementation. * * The ProjectorWidget is used by the ChannelWidget, for the Projector part of * each channel. Concerning the interface, the channel manager has a * stackedWidget and a combo that are linked together. When the combo changes, * the stackedWidget also changes. This defines the kind of projector to be used * for the channel. The default plugin offers the frustum camera. * * Each widget has its own data. They can be retrieved using data(). * */ class ProjectorWidget: public QWidget { Q_OBJECT public: /** * Default constructor. * */ ProjectorWidget(ProjectorInterface *plugin=NULL, QWidget* pParent=0, Qt::WFlags flag=0): QWidget(pParent, flag), m_plugin(plugin) {Q_ASSERT(NULL!=plugin);} /** * Destructor. * */ virtual ~ProjectorWidget() {} /** * Gets the projector interface associated with the widget. * * @return The associated projector interfacec. * */ ProjectorInterface* plugin() {return m_plugin;} /** * Updates the GUI. * * This method *must* be implemented by derived classes. * * @param data The data used to update the GUI. The data can be NULL. In * this case, the current data are used. * */ virtual void updateGUI(const ProjectorData* data) = 0; /** * Clears the widget. * * This can be used before disabling the widget. * */ virtual void clear(void) = 0; /** * Gets the data of the widget. * * @return The widget data. * */ virtual const ProjectorData& data(void) const = 0; signals: /** * Notify that data has changed. * * @param data The new data. * */ virtual void dataChanged(const ProjectorData&)=0; private: ProjectorInterface *m_plugin; ///< The ProjectorInterface that owns the Widget. }; Q_DECLARE_INTERFACE(ProjectorInterface, "jp.orihalcon.projdesigner.ProjectorInterface/1.0"); ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// class SceneContent; class SceneWidget; /** * Scene Plugin Interface Implementation. * */ class SceneInterface { public: /** * Destructor. * */ virtual ~SceneInterface() {} /** * Gets the name of the Interface. * * This name must be unique, to avoid conflicting plugins, just like the * name of the interface is unique to avoid conflicting interfaces. * * @return The name of the interface. * */ virtual QString name(void) const = 0; /** * Gets the list of the available scenes. * * @return The list of the available scenes. * */ virtual QStringList scenes(void) const = 0; /** * Instanciates a new SceneContent for the specified scene. * * @param scene A const reference on a string that contains the name of the * scene, such as projectors() has returned it. * * @return A pointer on the new instanciated SceneContent. * */ virtual SceneContent *newSceneContent(const QString& scene) = 0; /** * Instanciates a new SceneWidget for the specified scene. * * @param scene A const reference on a string that contains the name of * the scene, such as scenes() has returned it. * * @return A pointer on the new instanciated SceneWidget. * */ virtual SceneWidget *newSceneWidget(const QString& scene) = 0; }; /** * Scene content class to store informations about Scenes. * This class is not a pure virtual class, so scene plugins does not need to * instanciate it if it is not necessary. * */ class SceneContent { public: /** * Constructor. * * @param plugin A pointer on the plugin that owns the projector. * */ SceneContent(SceneInterface *plugin): m_plugin(plugin) {Q_ASSERT(NULL!=plugin);} /** * Copy constructor. * * @param data A const reference on the source content. * */ SceneContent (const SceneContent& content) {copy_from(content);} /** * Destructor. * */ virtual ~SceneContent() {} /** * Gets the SceneInterface which instanciated the SceneContent. * * @return A pointer on the SceneInterface which instanciated the * SceneContent. * */ SceneInterface* plugin() {return m_plugin;} /** * Gets the SceneInterface which instanciated the SceneContent. * This fonction differs from the previous one by the "const" attribute. * * @return A const pointer on the SceneInterface which instanciated the * SceneContent. * */ const SceneInterface* plugin() const {return m_plugin;} /** * Copies the content from a SceneContent. * * @param content A const-reference on the content to be copied. * * @return true if the copy suceeds, false otherwise. * */ virtual bool copy_from(const SceneContent& content) {Q_ASSERT(m_plugin==content.m_plugin); Q_UNUSED(content); return true;} /** * Check if 2 contents are equal. * * @param content A const-reference on the content to be checked. * @return true if the contents are the same, false otherwise. * */ virtual bool is_equal_to(const SceneContent& content) const {return m_plugin==content.m_plugin;} /** * Restore the export settings from XML content. * * @param element Parent XML element of the export settings content. * */ virtual void initFromDOMElement(const QDomElement& element) {if (!element.isNull()) {}} /** * Store the current export settings as XML content. * * @param name XML node name of the content. * @param doc XML document to store the content. * * @return Current export settings content as XML content. * */ virtual QDomElement domElement(const QString& name, QDomDocument& doc) const { QDomElement de = doc.createElement(name); de.setAttribute("name", getFullName()); return de;} /** * Gets the scene name. * This is the name that is in the scene list of the * SceneInterface::scenes(). * * @return the name of the scene. * */ virtual const QString& scene_name(void) const = 0; /** * Gets the scene full name. * This name can be used in the interface of Projection Designer to define in a unique way the scene. * * @return The fullname of the scene. * */ QString getFullName(void) const { Q_ASSERT(m_plugin); QString scene_fullname = scene_name(); scene_fullname += " ("; scene_fullname += m_plugin->name(); scene_fullname += ")"; return scene_fullname; } /** * Draws the scene. * This method draws the geometric scene content. For instance, for a * standard scene, it draws the frustum in the scene. * */ virtual void draw(QGLWidget *glWidget, const float* cameraMatrix) {Q_UNUSED(glWidget);Q_UNUSED(cameraMatrix);} /** * Resets the content. * * This method was added for the grids, to fix the fact that a * "New project" did not clear the grids. * */ virtual void reset (void)=0; private: SceneInterface *m_plugin; ///< The SceneInterface in which the scene is. }; /** * Scene widget class implementation. * * Each widget has its own content. They can be retrieved using content(). * */ class SceneWidget: public QWidget { Q_OBJECT public: /** * Default constructor. * */ SceneWidget(SceneInterface *plugin=NULL, QWidget* pParent=0, Qt::WFlags flag=0): QWidget(pParent, flag), m_plugin(plugin) {Q_ASSERT(NULL!=plugin);} /** * Destructor. * */ virtual ~SceneWidget() {} /** * Gets the scene interface associated with the widget. * * @return The associated scene interfacec. * */ SceneInterface* plugin() {return m_plugin;} /** * Updates the GUI. * * This method *must* be implemented by derived classes. * * @param content The content used to update the GUI. The content can be * NULL. In this case, the current content are used. * */ virtual void updateGUI(const SceneContent* data) = 0; /** * Gets the content of the widget. * * @return The widget content. * */ virtual const SceneContent& content(void) const = 0; signals: /** * Notify that contents have changed. * * @param data The new contents. * */ virtual void dataChanged(const SceneContent&)=0; private: SceneInterface *m_plugin; ///< The SceneInterface that owns the Widget. }; Q_DECLARE_INTERFACE(SceneInterface, "jp.orihalcon.projdesigner.SceneInterface/1.0"); #endif