From 27d50543e111fc8f2bd8ac518e45f3d16f1471c6 Mon Sep 17 00:00:00 2001 From: Pierre Kraemer Date: Thu, 6 Dec 2012 17:35:27 +0100 Subject: [PATCH] SCHNApps: la ca commence a etre pas mal.. --- SCHNApps/Plugins/CMakeLists.txt | 2 +- SCHNApps/Plugins/demo/demo.cpp | 52 ----- SCHNApps/Plugins/demo/demo.h | 101 -------- SCHNApps/Plugins/import/import.cpp | 15 +- SCHNApps/Plugins/import/import.h | 37 +-- .../Plugins/{demo => render}/CMakeLists.txt | 22 +- SCHNApps/Plugins/render/render.cpp | 154 +++++++++++++ SCHNApps/Plugins/render/render.h | 84 +++++++ .../{demo/demo.ui => render/render.ui} | 28 ++- SCHNApps/forms/window.ui | 23 +- SCHNApps/include/camera.h | 29 +-- SCHNApps/include/mapHandler.h | 31 +-- SCHNApps/include/plugin.h | 13 +- SCHNApps/include/system.h | 4 +- SCHNApps/include/view.h | 29 ++- SCHNApps/include/window.h | 73 +++--- SCHNApps/src/camera.cpp | 7 +- SCHNApps/src/cameraViewDialog.cpp | 2 +- SCHNApps/src/main.cpp | 19 +- SCHNApps/src/mapHandler.cpp | 65 +----- SCHNApps/src/pluginDialog.cpp | 5 +- SCHNApps/src/system.cpp | 2 - SCHNApps/src/view.cpp | 57 +++-- SCHNApps/src/window.cpp | 217 ++++++++++-------- src/Utils/GLSLShader.cpp | 7 +- 25 files changed, 581 insertions(+), 497 deletions(-) delete mode 100644 SCHNApps/Plugins/demo/demo.cpp delete mode 100644 SCHNApps/Plugins/demo/demo.h rename SCHNApps/Plugins/{demo => render}/CMakeLists.txt (68%) create mode 100644 SCHNApps/Plugins/render/render.cpp create mode 100644 SCHNApps/Plugins/render/render.h rename SCHNApps/Plugins/{demo/demo.ui => render/render.ui} (60%) diff --git a/SCHNApps/Plugins/CMakeLists.txt b/SCHNApps/Plugins/CMakeLists.txt index 1cde17c24..ee69ece4d 100644 --- a/SCHNApps/Plugins/CMakeLists.txt +++ b/SCHNApps/Plugins/CMakeLists.txt @@ -1,4 +1,4 @@ cmake_minimum_required(VERSION 2.8) ADD_SUBDIRECTORY(import) -ADD_SUBDIRECTORY(demo) +ADD_SUBDIRECTORY(render) diff --git a/SCHNApps/Plugins/demo/demo.cpp b/SCHNApps/Plugins/demo/demo.cpp deleted file mode 100644 index d1dfa7b87..000000000 --- a/SCHNApps/Plugins/demo/demo.cpp +++ /dev/null @@ -1,52 +0,0 @@ -#include "demo.h" - -#include "mapHandler.h" - -#include "Algo/Import/import.h" - -bool DemoPlugin::enable() -{ - addTabInDock(new DemoDockTab(), "demoTab"); - - m_flatShader = new CGoGN::Utils::ShaderFlat() ; - m_flatShader->setAmbiant(CGoGN::Geom::Vec4f(0.2f, 0.2f, 0.2f, 0.1f)) ; - m_flatShader->setDiffuse(CGoGN::Geom::Vec4f(0.8f, 0.9f, 0.7f, 1.0f)) ; - m_flatShader->setExplode(1.0f) ; - - CGoGN::Utils::GLSLShader::registerShader(NULL, m_flatShader) ; - - return true; -} - -void DemoPlugin::disable() -{ - delete m_flatShader; -} - -void DemoPlugin::redraw(View* view) -{ - glPolygonMode(GL_FRONT_AND_BACK, GL_FILL) ; - glEnable(GL_LIGHTING) ; - - QList maps = view->getLinkedMaps(); - foreach(MapHandlerGen* m, maps) - { - CGoGN::Utils::VBO* positionVBO = m->getVBO("position"); - m_flatShader->setAttributePosition(positionVBO); - m->draw(m_flatShader, CGoGN::Algo::Render::GL2::TRIANGLES) ; - } -} - -/** - * If we want to compile this plugin in debug mode, - * we also define a DEBUG macro at the compilation - */ -#ifndef DEBUG -// essential Qt function: -// arguments are -// - the compiled name of the plugin -// - the main class of our plugin -Q_EXPORT_PLUGIN2(DemoPlugin, DemoPlugin) -#else -Q_EXPORT_PLUGIN2(DemoPluginD, DemoPlugin) -#endif diff --git a/SCHNApps/Plugins/demo/demo.h b/SCHNApps/Plugins/demo/demo.h deleted file mode 100644 index 6c307f9d0..000000000 --- a/SCHNApps/Plugins/demo/demo.h +++ /dev/null @@ -1,101 +0,0 @@ -#ifndef _DEMO_PLUGIN_H_ -#define _DEMO_PLUGIN_H_ - -#include "plugin.h" -#include "ui_demo.h" - -#include "Topology/generic/functor.h" -#include "Topology/generic/parameters.h" -#include "Topology/map/embeddedMap2.h" - -#include "Utils/Shaders/shaderFlat.h" - - -struct PFP: public CGoGN::PFP_STANDARD -{ - // definition of the map - typedef CGoGN::EmbeddedMap2 MAP; -}; - -typedef PFP::MAP MAP; -typedef PFP::VEC3 VEC3; - - -class DemoDockTab : public QWidget, public Ui::DemoWidget -{ -public: - DemoDockTab() { setupUi(this); } -}; - - -struct TabParams -{ - bool b_showVertices; - bool b_showEdges; -}; - - -/** - * This class is a basic minimal plugin. - * All the methods in this class are overloaded methods. - * In order to create a valid plugin, all the method in this - * needs to be declared (they are actually overloaded methods - * from VisualPlugin), even if your plugin doesn't make any - * drawing. - */ - -/** - * Our plugin must inherit from Plugin - */ -class DemoPlugin : public Plugin -{ - /** - * Essential Qt macros. - */ - Q_OBJECT - Q_INTERFACES(Plugin) - -public: - DemoPlugin() - { - setProvidesRendering(true); - } - - ~DemoPlugin() - {} - - /** - * The plugin's enable method - * Each time the main application loads this plugin, - * it call this method. Writing this method is - * the occasion to initialize the plugin and check certain - * conditions. - * If this methods return 'false', the plugin load will be aborted. - */ - bool enable(); - - /** - * The plugin's disable method - * Each time the main application will unload the plugin - * it will call this method. - */ - void disable(); - - virtual void redraw(View *view); - - virtual void keyPress(View* view, int key) {} - virtual void keyRelease(View* view, int key) {} - virtual void mousePress(View* view, int button, int x, int y) {} - virtual void mouseRelease(View* view, int button, int x, int y) {} -// virtual void mouseClick(View* view, int button, int x, int y) {} - virtual void mouseMove(View* view, int buttons, int x, int y) {} - virtual void wheelEvent(View* view, int delta, int x, int y) {} - - virtual void viewLinked(View* view) {} - virtual void viewUnlinked(View* view) {} - -protected: - CGoGN::Utils::ShaderFlat* m_flatShader ; -}; - -#endif // _FIRSTPLUGIN_H_ diff --git a/SCHNApps/Plugins/import/import.cpp b/SCHNApps/Plugins/import/import.cpp index 9c661a53f..01ce01631 100644 --- a/SCHNApps/Plugins/import/import.cpp +++ b/SCHNApps/Plugins/import/import.cpp @@ -1,6 +1,10 @@ #include "import.h" +#include +#include +#include "system.h" #include "mapHandler.h" + #include "Algo/Import/import.h" bool ImportPlugin::enable() @@ -17,11 +21,14 @@ void ImportPlugin::disable() void ImportPlugin::cb_import() { + QString fileName = QFileDialog::getOpenFileName(m_window, "Import file", m_window->getAppPath(), "Mesh Files (*.ply *.off)"); + QFileInfo fi(fileName); + MAP* m = new MAP(); - MapHandler* h = new MapHandler("duck", m_window, m); + MapHandler* h = new MapHandler(fi.baseName(), m_window, m); std::vector attrNames ; - CGoGN::Algo::Import::importMesh(*m, "/home/kraemer/Media/Data/surface/lowRes/duck_163.ply", attrNames); + CGoGN::Algo::Import::importMesh(*m, fileName.toUtf8().constData(), attrNames); CGoGN::VertexAttribute position = m->getAttribute(attrNames[0]); @@ -36,10 +43,10 @@ void ImportPlugin::cb_import() h->updatePrimitives(CGoGN::Algo::Render::GL2::LINES, CGoGN::allDarts) ; h->updatePrimitives(CGoGN::Algo::Render::GL2::TRIANGLES, CGoGN::allDarts) ; - m_window->addMap(h); - CGoGN::Utils::VBO* positionVBO = h->getVBO(position.name()); positionVBO->updateData(position); + + m_window->addMap(h); } /** diff --git a/SCHNApps/Plugins/import/import.h b/SCHNApps/Plugins/import/import.h index 556e512c7..0bed1640b 100644 --- a/SCHNApps/Plugins/import/import.h +++ b/SCHNApps/Plugins/import/import.h @@ -18,23 +18,8 @@ typedef PFP::MAP MAP; typedef PFP::VEC3 VEC3; -/** - * This class is a basic minimal plugin. - * All the methods in this class are overloaded methods. - * In order to create a valid plugin, all the method in this - * needs to be declared (they are actually overloaded methods - * from VisualPlugin), even if your plugin doesn't make any - * drawing. - */ - -/** - * Our plugin must inherit from Plugin - */ class ImportPlugin : public Plugin { - /** - * Essential Qt macros. - */ Q_OBJECT Q_INTERFACES(Plugin) @@ -47,22 +32,8 @@ public: ~ImportPlugin() {} - /** - * The plugin's enable method - * Each time the main application loads this plugin, - * it call this method. Writing this method is - * the occasion to initialize the plugin and check certain - * conditions. - * If this methods return 'false', the plugin load will be aborted. - */ - bool enable(); - - /** - * The plugin's disable method - * Each time the main application will unload the plugin - * it will call this method. - */ - void disable(); + virtual bool enable(); + virtual void disable(); virtual void redraw(View *view) {} @@ -70,12 +41,12 @@ public: virtual void keyRelease(View* view, int key) {} virtual void mousePress(View* view, int button, int x, int y) {} virtual void mouseRelease(View* view, int button, int x, int y) {} -// virtual void mouseClick(View* view, int button, int x, int y) {} virtual void mouseMove(View* view, int buttons, int x, int y) {} virtual void wheelEvent(View* view, int delta, int x, int y) {} virtual void viewLinked(View* view) {} virtual void viewUnlinked(View* view) {} + virtual void currentViewChanged(View* view) {} public slots: void cb_import(); @@ -84,4 +55,4 @@ private: QAction* importAction; }; -#endif // _FIRSTPLUGIN_H_ +#endif diff --git a/SCHNApps/Plugins/demo/CMakeLists.txt b/SCHNApps/Plugins/render/CMakeLists.txt similarity index 68% rename from SCHNApps/Plugins/demo/CMakeLists.txt rename to SCHNApps/Plugins/render/CMakeLists.txt index d9f5275f2..8647a02ad 100644 --- a/SCHNApps/Plugins/demo/CMakeLists.txt +++ b/SCHNApps/Plugins/render/CMakeLists.txt @@ -2,20 +2,20 @@ cmake_minimum_required(VERSION 2.8) INCLUDE_DIRECTORIES( ${SCHNApps_ROOT_DIR}/include - ${SCHNApps_ROOT_DIR}/Plugins/demo + ${SCHNApps_ROOT_DIR}/Plugins/render ${CMAKE_CURRENT_BINARY_DIR} ) SET( PLUGIN_SRC - ${SCHNApps_ROOT_DIR}/Plugins/demo/demo.cpp + ${SCHNApps_ROOT_DIR}/Plugins/render/render.cpp ) SET( PLUGIN_H - ${SCHNApps_ROOT_DIR}/Plugins/demo/demo.h + ${SCHNApps_ROOT_DIR}/Plugins/render/render.h ) SET( PLUGIN_FORM - ${SCHNApps_ROOT_DIR}/Plugins/demo/demo.ui + ${SCHNApps_ROOT_DIR}/Plugins/render/render.ui ) IF( ${CMAKE_BUILD_TYPE} STREQUAL Debug ) @@ -31,21 +31,21 @@ IF( ${CMAKE_BUILD_TYPE} STREQUAL Debug ) QT4_WRAP_UI( PLUGIN_UI ${PLUGIN_FORM} ) QT4_WRAP_CPP( PLUGIN_MOC ${PLUGIN_H} ) - ADD_LIBRARY( DemoPluginD SHARED + ADD_LIBRARY( RenderPluginD SHARED ${PLUGIN_SRC} ${PLUGIN_UI} ${PLUGIN_MOC} ) - TARGET_LINK_LIBRARIES( DemoPluginD + TARGET_LINK_LIBRARIES( RenderPluginD ${CGoGN_LIBS_D} ${COMMON_LIBS} ${QGLVIEWER_LIBRARIES} ) - ADD_DEPENDENCIES( DemoPluginD SCHNAppsD ) + ADD_DEPENDENCIES( RenderPluginD SCHNAppsD ) - SET_TARGET_PROPERTIES( DemoPluginD PROPERTIES COMPILE_DEFINITIONS "DEBUG" ) + SET_TARGET_PROPERTIES( RenderPluginD PROPERTIES COMPILE_DEFINITIONS "DEBUG" ) ELSE ( ${CMAKE_BUILD_TYPE} STREQUAL Debug ) @@ -58,18 +58,18 @@ ELSE ( ${CMAKE_BUILD_TYPE} STREQUAL Debug ) QT4_WRAP_UI( PLUGIN_UI ${PLUGIN_FORM} ) QT4_WRAP_CPP( PLUGIN_MOC ${PLUGIN_H} ) - ADD_LIBRARY( DemoPlugin SHARED + ADD_LIBRARY( RenderPlugin SHARED ${PLUGIN_SRC} ${PLUGIN_UI} ${PLUGIN_MOC} ) - TARGET_LINK_LIBRARIES( DemoPlugin + TARGET_LINK_LIBRARIES( RenderPlugin ${CGoGN_LIBS_R} ${COMMON_LIBS} ${QGLVIEWER_LIBRARIES} ) - ADD_DEPENDENCIES( DemoPlugin SCHNApps ) + ADD_DEPENDENCIES( RenderPlugin SCHNApps ) ENDIF ( ${CMAKE_BUILD_TYPE} STREQUAL Debug ) diff --git a/SCHNApps/Plugins/render/render.cpp b/SCHNApps/Plugins/render/render.cpp new file mode 100644 index 000000000..9e3562925 --- /dev/null +++ b/SCHNApps/Plugins/render/render.cpp @@ -0,0 +1,154 @@ +#include "render.h" + +#include "mapHandler.h" + +#include "Algo/Import/import.h" + +bool RenderPlugin::enable() +{ + m_dockTab = new RenderDockTab(); + addTabInDock(m_dockTab, "Render"); + + m_flatShader = new CGoGN::Utils::ShaderFlat(); + m_flatShader->setAmbiant(CGoGN::Geom::Vec4f(0.2f, 0.2f, 0.2f, 0.1f)); + m_flatShader->setDiffuse(CGoGN::Geom::Vec4f(0.8f, 0.9f, 0.7f, 1.0f)); + m_flatShader->setExplode(1.0f); + + m_simpleColorShader = new CGoGN::Utils::ShaderSimpleColor(); + CGoGN::Geom::Vec4f c(0.1f, 0.1f, 0.1f, 1.0f); + m_simpleColorShader->setColor(c); + + m_pointSprite = new CGoGN::Utils::PointSprite(); + + connect(m_dockTab->check_renderVertices, SIGNAL(toggled(bool)), this, SLOT(cb_renderVerticesChanged(bool))); + connect(m_dockTab->slider_verticesScaleFactor, SIGNAL(valueChanged(int)), this, SLOT(cb_verticesScaleFactorChanged(int))); + connect(m_dockTab->check_renderEdges, SIGNAL(toggled(bool)), this, SLOT(cb_renderEdgesChanged(bool))); + connect(m_dockTab->check_renderFaces, SIGNAL(toggled(bool)), this, SLOT(cb_renderFacesChanged(bool))); + + return true; +} + +void RenderPlugin::disable() +{ + delete m_flatShader; + delete m_simpleColorShader; + delete m_pointSprite; +} + +void RenderPlugin::redraw(View* view) +{ + TabParams* params = h_viewParams[view]; + + const QList& maps = view->getLinkedMaps(); + foreach(MapHandlerGen* m, maps) + { + CGoGN::Utils::VBO* positionVBO = m->getVBO("position"); + if(params->renderVertices) + { + m_pointSprite->setSize(m->getBBdiagSize() / 100.0f * params->verticesScaleFactor); + m_pointSprite->setAttributePosition(positionVBO); + m_pointSprite->predraw(CGoGN::Geom::Vec3f(0.0f, 0.0f, 1.0f)); + m->draw(m_pointSprite, CGoGN::Algo::Render::GL2::POINTS); + m_pointSprite->postdraw(); + } + if(params->renderEdges) + { + glLineWidth(1.0f); + m_simpleColorShader->setAttributePosition(positionVBO); + m->draw(m_simpleColorShader, CGoGN::Algo::Render::GL2::LINES); + } + if(params->renderFaces) + { + glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); + glEnable(GL_LIGHTING); + glEnable(GL_POLYGON_OFFSET_FILL); + glPolygonOffset(1.0f, 1.0f); + m_flatShader->setAttributePosition(positionVBO); + m->draw(m_flatShader, CGoGN::Algo::Render::GL2::TRIANGLES); + glDisable(GL_POLYGON_OFFSET_FILL); + } + } +} + +void RenderPlugin::viewLinked(View* view) +{ + assert(!h_viewParams.contains(view)); + h_viewParams.insert(view, new TabParams(1.0, false, false, true)); + + CGoGN::Utils::GLSLShader::registerShader(view, m_flatShader); + CGoGN::Utils::GLSLShader::registerShader(view, m_simpleColorShader); + CGoGN::Utils::GLSLShader::registerShader(view, m_pointSprite); +} + +void RenderPlugin::viewUnlinked(View* view) +{ + assert(h_viewParams.contains(view)); + h_viewParams.remove(view); + + CGoGN::Utils::GLSLShader::unregisterShader(view, m_flatShader); + CGoGN::Utils::GLSLShader::unregisterShader(view, m_simpleColorShader); + CGoGN::Utils::GLSLShader::unregisterShader(view, m_pointSprite); +} + +void RenderPlugin::currentViewChanged(View* view) +{ + TabParams* params = h_viewParams[view]; + m_dockTab->check_renderVertices->setChecked(params->renderVertices); + m_dockTab->slider_verticesScaleFactor->setSliderPosition(params->verticesScaleFactor * 50.0); + m_dockTab->check_renderEdges->setChecked(params->renderEdges); + m_dockTab->check_renderFaces->setChecked(params->renderFaces); +} + +void RenderPlugin::cb_renderVerticesChanged(bool b) +{ + View* current = m_window->getCurrentView(); + assert(isLinkedToView(current)); + + TabParams* params = h_viewParams[current]; + params->renderVertices = b; + current->updateGL(); +} + +void RenderPlugin::cb_verticesScaleFactorChanged(int i) +{ + View* current = m_window->getCurrentView(); + assert(isLinkedToView(current)); + + TabParams* params = h_viewParams[current]; + params->verticesScaleFactor = i / 50.0; + current->updateGL(); +} + +void RenderPlugin::cb_renderEdgesChanged(bool b) +{ + View* current = m_window->getCurrentView(); + assert(isLinkedToView(current)); + + TabParams* params = h_viewParams[current]; + params->renderEdges = b; + current->updateGL(); +} + +void RenderPlugin::cb_renderFacesChanged(bool b) +{ + View* current = m_window->getCurrentView(); + assert(isLinkedToView(current)); + + TabParams* params = h_viewParams[current]; + params->renderFaces = b; + current->updateGL(); +} + +/** + * If we want to compile this plugin in debug mode, + * we also define a DEBUG macro at the compilation + */ +#ifndef DEBUG +// essential Qt function: +// arguments are +// - the compiled name of the plugin +// - the main class of our plugin +Q_EXPORT_PLUGIN2(RenderPlugin, RenderPlugin) +#else +Q_EXPORT_PLUGIN2(RenderPluginD, RenderPlugin) +#endif diff --git a/SCHNApps/Plugins/render/render.h b/SCHNApps/Plugins/render/render.h new file mode 100644 index 000000000..6e6119ece --- /dev/null +++ b/SCHNApps/Plugins/render/render.h @@ -0,0 +1,84 @@ +#ifndef _RENDER_PLUGIN_H_ +#define _RENDER_PLUGIN_H_ + +#include "plugin.h" +#include "ui_render.h" + +#include "Topology/generic/functor.h" +#include "Topology/generic/parameters.h" +#include "Topology/map/embeddedMap2.h" + +#include "Utils/Shaders/shaderFlat.h" +#include "Utils/Shaders/shaderSimpleColor.h" +#include "Utils/pointSprite.h" + + +class RenderDockTab : public QWidget, public Ui::RenderWidget +{ +public: + RenderDockTab() { setupUi(this); } +}; + + +struct TabParams +{ + TabParams(float vsf, bool rv, bool re, bool rf) : + verticesScaleFactor(vsf), + renderVertices(rv), + renderEdges(re), + renderFaces(rf) + {} + + float verticesScaleFactor; + bool renderVertices; + bool renderEdges; + bool renderFaces; +}; + + +class RenderPlugin : public Plugin +{ + Q_OBJECT + Q_INTERFACES(Plugin) + +public: + RenderPlugin() + { + setProvidesRendering(true); + } + + ~RenderPlugin() + {} + + virtual bool enable(); + virtual void disable(); + + virtual void redraw(View *view); + + virtual void keyPress(View* view, int key) {} + virtual void keyRelease(View* view, int key) {} + virtual void mousePress(View* view, int button, int x, int y) {} + virtual void mouseRelease(View* view, int button, int x, int y) {} + virtual void mouseMove(View* view, int buttons, int x, int y) {} + virtual void wheelEvent(View* view, int delta, int x, int y) {} + + virtual void viewLinked(View* view); + virtual void viewUnlinked(View* view); + virtual void currentViewChanged(View* view); + +protected: + RenderDockTab* m_dockTab; + QHash h_viewParams; + + CGoGN::Utils::ShaderFlat* m_flatShader; + CGoGN::Utils::ShaderSimpleColor* m_simpleColorShader ; + CGoGN::Utils::PointSprite* m_pointSprite ; + +public slots: + void cb_renderVerticesChanged(bool b); + void cb_verticesScaleFactorChanged(int i); + void cb_renderEdgesChanged(bool b); + void cb_renderFacesChanged(bool b); +}; + +#endif diff --git a/SCHNApps/Plugins/demo/demo.ui b/SCHNApps/Plugins/render/render.ui similarity index 60% rename from SCHNApps/Plugins/demo/demo.ui rename to SCHNApps/Plugins/render/render.ui index 6a70eb84b..3a39a043e 100644 --- a/SCHNApps/Plugins/demo/demo.ui +++ b/SCHNApps/Plugins/render/render.ui @@ -1,13 +1,13 @@ - DemoWidget - + RenderWidget + 0 0 177 - 211 + 293 @@ -21,6 +21,16 @@ + + + + 50 + + + Qt::Horizontal + + + @@ -28,6 +38,16 @@ + + + + render faces + + + true + + + @@ -36,7 +56,7 @@ 156 - 136 + 161 diff --git a/SCHNApps/forms/window.ui b/SCHNApps/forms/window.ui index 0e1296b0a..cfcd260ce 100644 --- a/SCHNApps/forms/window.ui +++ b/SCHNApps/forms/window.ui @@ -56,9 +56,9 @@ false - + @@ -84,15 +84,6 @@ Manage plugins - - - - :/icons/icons/add_view.png:/icons/icons/add_view.png - - - Add view - - @@ -107,6 +98,18 @@ Show/Hide Dock + + + + :/icons/icons/map_plugin.png:/icons/icons/map_plugin.png + + + ManageMaps + + + Manage maps + + diff --git a/SCHNApps/include/camera.h b/SCHNApps/include/camera.h index 8c5eb410b..51df63b4e 100644 --- a/SCHNApps/include/camera.h +++ b/SCHNApps/include/camera.h @@ -14,14 +14,14 @@ public: Camera(const QString& name, Window* window); ~Camera(); - const QString& getName() { return m_name; } + const QString& getName() const { return m_name; } void setName(const QString& name) { m_name = name; } - Window* getWindow() { return m_window; } + Window* getWindow() const { return m_window; } void setWindow(Window* w) { m_window = w; } - bool isUsed() { return l_views.size() > 0; } - bool isShared() { return l_views.size() > 1; } + bool isUsed() const { return l_views.size() > 0; } + bool isShared() const { return l_views.size() > 1; } /********************************************************* * CAMERA DRAWING @@ -29,22 +29,22 @@ public: void draw(); - bool getDraw() { return m_draw; } + bool getDraw() const { return m_draw; } void setDraw(bool b = true) { m_draw = b; } - bool getDrawFarPlane() { return m_drawFarPlane; } - void setDrawFarPlane(bool b = true) { m_drawFarPlane = b; } + bool getDrawFarPlane() const { return m_drawFarPlane; } + void setDrawFarPlane(bool b) { m_drawFarPlane = b; } - double getDrawScale() { return m_drawScale; } + double getDrawScale() const { return m_drawScale; } void setDrawScale(double s) { m_drawScale = s; } - bool getDrawPath() { return m_drawPath; } - void setDrawPath(bool b = true) { m_drawPath = b; } + bool getDrawPath() const { return m_drawPath; } + void setDrawPath(bool b) { m_drawPath = b; } - bool getDrawPathAxis() { return m_drawPathAxis; } - void setDrawPathAxis(bool b = true) { m_drawPathAxis = b; } + bool getDrawPathAxis() const { return m_drawPathAxis; } + void setDrawPathAxis(bool b) { m_drawPathAxis = b; } - double getDrawPathScale() { return m_drawPathScale; } + double getDrawPathScale() const { return m_drawPathScale; } void setDrawPathScale(double s) { m_drawPathScale = s;} /********************************************************* @@ -53,7 +53,8 @@ public: void linkView(View* view); void unlinkView(View* view); - bool isLinkedWithView(View* view); + const QList& getLinkedViews() const { return l_views; } + bool isLinkedToView(View* view) const { return l_views.contains(view); } void fitParamWith(View* view); diff --git a/SCHNApps/include/mapHandler.h b/SCHNApps/include/mapHandler.h index c8b179222..5642e1068 100644 --- a/SCHNApps/include/mapHandler.h +++ b/SCHNApps/include/mapHandler.h @@ -16,12 +16,10 @@ public: MapHandlerGen(const QString& name, Window* window); virtual ~MapHandlerGen(); - virtual void draw(CGoGN::Utils::GLSLShader* shader, int primitive) = 0; - - const QString& getName() { return m_name; } + const QString& getName() const { return m_name; } void setName(const QString& name) { m_name = name; } - Window* getWindow() { return m_window; } + Window* getWindow() const { return m_window; } void setWindow(Window* w) { m_window = w; } const qglviewer::Vec& getBBmin() const { return m_bbMin; } @@ -30,17 +28,16 @@ public: const qglviewer::Vec& getBBmax() const { return m_bbMax; } void setBBmax(qglviewer::Vec& v) { m_bbMax = v; } + float getBBdiagSize() { return (m_bbMax - m_bbMin).norm(); } + + void draw(CGoGN::Utils::GLSLShader* shader, int primitive); + /********************************************************* * MANAGE VBOs *********************************************************/ CGoGN::Utils::VBO* getVBO(const std::string& name); void deleteVBO(const std::string& name); -// CGoGN::Utils::VBO* addVBO(const QString& name); -// CGoGN::Utils::VBO* findFirstVBOMatching(const QRegExp& regexp); -// QList findVBOsMatching(const QRegExp& regexp); - - int getNbVBO() { return h_vbo.count(); } /********************************************************* * MANAGE LINKED VIEWS @@ -48,13 +45,15 @@ public: bool linkView(View* view); void unlinkView(View* view); - bool isLinkedToView(View* view) { return l_views.contains(view); } - QList getLinkedViews() { return l_views; } + const QList& getLinkedViews() const { return l_views; } + bool isLinkedToView(View* view) const { return l_views.contains(view); } protected: QString m_name; Window* m_window; + CGoGN::Algo::Render::GL2::MapRender* m_render; + qglviewer::Vec m_bbMin; qglviewer::Vec m_bbMax; @@ -70,9 +69,7 @@ public: MapHandler(const QString& name, Window* window, typename PFP::MAP* map) : MapHandlerGen(name, window), m_map(map) - { - m_render = new CGoGN::Algo::Render::GL2::MapRender(); - } + {} ~MapHandler() { @@ -87,14 +84,8 @@ public: m_render->initPrimitives(*m_map, good, primitive) ; } - void draw(CGoGN::Utils::GLSLShader* shader, int primitive) - { - m_render->draw(shader, primitive); - } - protected: typename PFP::MAP* m_map; - CGoGN::Algo::Render::GL2::MapRender* m_render; }; #endif diff --git a/SCHNApps/include/plugin.h b/SCHNApps/include/plugin.h index de78198e4..55242a11a 100644 --- a/SCHNApps/include/plugin.h +++ b/SCHNApps/include/plugin.h @@ -19,9 +19,6 @@ public: Plugin(); virtual ~Plugin(); - virtual bool enable() = 0; - virtual void disable() = 0; - const QString& getName() { return m_name; } void setName(const QString& name) { m_name = name; } @@ -34,18 +31,21 @@ public: bool getProvidesRendering() { return b_providesRendering; } void setProvidesRendering(bool b) { b_providesRendering = b; } + virtual bool enable() = 0; + virtual void disable() = 0; + virtual void redraw(View* view) = 0; virtual void keyPress(View* view, int key) = 0; virtual void keyRelease(View* view, int key) = 0; virtual void mousePress(View* view, int button, int x, int y) = 0; virtual void mouseRelease(View* view, int button, int x, int y) = 0; -// virtual void mouseClick(View* view, int button, int x, int y) = 0; virtual void mouseMove(View* view, int buttons, int x, int y) = 0; virtual void wheelEvent(View* view, int delta, int x, int y) = 0; virtual void viewLinked(View* view) = 0; virtual void viewUnlinked(View* view) = 0; + virtual void currentViewChanged(View* view) = 0; /********************************************************* * MANAGE LINKED VIEWS @@ -53,8 +53,8 @@ public: bool linkView(View* view); void unlinkView(View* view); - bool isLinkedToView(View* view) { return l_views.contains(view); } - QList getLinkedViews() { return l_views; } + const QList& getLinkedViews() const { return l_views; } + bool isLinkedToView(View* view) const { return l_views.contains(view); } /********************************************************* * MANAGE DOCK TABS @@ -62,6 +62,7 @@ public: bool addTabInDock(QWidget* tabWidget, const QString& tabText); void removeTabInDock(QWidget* tabWidget); + const QList& getTabWidgets() const { return l_tabWidgets; } /********************************************************* * MANAGE MENU ACTIONS diff --git a/SCHNApps/include/system.h b/SCHNApps/include/system.h index 51f711382..02fc2724b 100644 --- a/SCHNApps/include/system.h +++ b/SCHNApps/include/system.h @@ -149,9 +149,9 @@ public: // SIMPLE_GLVIEWER //} QGLV_CREATE_SETTINGS; -extern QString app_path; +//extern QString app_path; -extern QSplashScreen *splash; +//extern QSplashScreen *splash; } // namespace System diff --git a/SCHNApps/include/view.h b/SCHNApps/include/view.h index 4d43be116..cae162e3e 100644 --- a/SCHNApps/include/view.h +++ b/SCHNApps/include/view.h @@ -5,6 +5,7 @@ #include #include "types.h" +#include "window.h" #include "Utils/gl_matrices.h" class ViewButtonArea; @@ -24,12 +25,14 @@ public: View(const QString& name, Window* w, QWidget* parent, const QGLWidget* shareWidget = NULL); ~View(); - const QString& getName() { return m_name; } + const QString& getName() const { return m_name; } void setName(const QString& name) { m_name = name; } - Window* getWindow() { return m_window; } + Window* getWindow() const { return m_window; } void setWindow(Window* w) { m_window = w; } + bool isCurrentView() const { return m_window->getCurrentView() == this; } + virtual void init(); virtual void preDraw(); virtual void draw(); @@ -38,6 +41,7 @@ public: void drawText(); void drawButtons(); + void drawFrame(); void keyPressEvent(QKeyEvent* event); void keyReleaseEvent(QKeyEvent *event); @@ -46,16 +50,11 @@ public: void mouseMoveEvent(QMouseEvent* event); void wheelEvent(QWheelEvent* event); - void drawOverpaint(QPainter *painter); - -// virtual void paintGL() { update(); } -// virtual void paintEvent(QPaintEvent *event); - /********************************************************* * MANAGE LINKED CAMERA *********************************************************/ - Camera* getCurrentCamera() { return m_currentCamera; } + Camera* getCurrentCamera() const { return m_currentCamera; } void setCurrentCamera(Camera* c); /********************************************************* @@ -64,8 +63,8 @@ public: void linkPlugin(Plugin* plugin); void unlinkPlugin(Plugin* plugin); - QList getLinkedPlugins() { return l_plugins; } - bool isLinkedToPlugin(Plugin* plugin) { return l_plugins.contains(plugin); } + const QList& getLinkedPlugins() const { return l_plugins; } + bool isLinkedToPlugin(Plugin* plugin) const { return l_plugins.contains(plugin); } /********************************************************* * MANAGE LINKED MAPS @@ -73,17 +72,17 @@ public: void linkMap(MapHandlerGen* map); void unlinkMap(MapHandlerGen* map); - QList getLinkedMaps() { return l_maps; } - bool isLinkedToMap(MapHandlerGen* map) { return l_maps.contains(map); } + const QList& getLinkedMaps() const { return l_maps; } + bool isLinkedToMap(MapHandlerGen* map) const { return l_maps.contains(map); } void updateTextInfo(); - glm::mat4 getCurrentModelViewMatrix(); - glm::mat4 getCurrentProjectionMatrix(); - glm::mat4 getCurrentModelViewProjectionMatrix(); + glm::mat4 getCurrentModelViewMatrix() const; + glm::mat4 getCurrentProjectionMatrix() const; + glm::mat4 getCurrentModelViewProjectionMatrix() const; void setCurrentModelViewMatrix(const glm::mat4& mvm); void setCurrentProjectionMatrix(const glm::mat4& pm); diff --git a/SCHNApps/include/window.h b/SCHNApps/include/window.h index 4091da4fc..d8ca3c70c 100644 --- a/SCHNApps/include/window.h +++ b/SCHNApps/include/window.h @@ -30,6 +30,9 @@ public: */ ~Window(); + const QString& getAppPath() { return m_appPath; } + void setAppPath(const QString& path) { m_appPath = path; } + /********************************************************* * MANAGE DOCK *********************************************************/ @@ -40,7 +43,7 @@ public: * * \return a pointer to the TabWidget, NULL if not allocated yet */ - QTabWidget* getDockTabWidget(); + QTabWidget* getDockTabWidget() const { return m_dockTabWidget; } /** * \fn void addTabInDock(QWidget* tabWidget, const QString& tabText) @@ -65,6 +68,9 @@ public: */ void removeTabInDock(QWidget* tabWidget); + void enablePluginTabWidgets(Plugin* plugin); + void disablePluginTabWidgets(Plugin* plugin); + /********************************************************* * MANAGE MENU ACTIONS *********************************************************/ @@ -135,9 +141,9 @@ public: Camera* addCamera(const QString& name); Camera* addCamera(); void removeCamera(const QString& name); - Camera* getCamera(const QString& name); - QList getCamerasList() { return h_cameras.values(); } - const CameraHash& getCamerasHash() { return h_cameras; } + Camera* getCamera(const QString& name) const; + QList getCamerasList() const { return h_cameras.values(); } + const CameraHash& getCamerasHash() const { return h_cameras; } /********************************************************* * MANAGE VIEWS @@ -146,9 +152,24 @@ public: View* addView(const QString& name); View* addView(); void removeView(const QString& name); - View* getView(const QString& name); - QList getViewsList() { return h_views.values(); } - const ViewHash& getViewsHash() { return h_views; } + View* getView(const QString& name) const; + QList getViewsList() const { return h_views.values(); } + const ViewHash& getViewsHash() const { return h_views; } + + View* getCurrentView() const { return m_currentView; } + void setCurrentView(View* view); + + /** + * \fn void moveView() + * \brief shows a reordering dialog for the Views + * + * Make a call with the right parameters to the dialog class + * GLVSelector and show this dialog. + * + * This method is meant to be called when the user press + * CTRL+Shift+M. + */ + void moveView(); /********************************************************* * MANAGE PLUGINS @@ -182,7 +203,7 @@ public: * \see getPlugins() * \see Plugin::enable() */ - Plugin* loadPlugin(QString pluginFilePath); + Plugin* loadPlugin(const QString& pluginFilePath); /** * \fn void unloadPlugin(QString pluginName) @@ -225,9 +246,9 @@ public: */ // Plugin *checkPluginDependencie(QString name, Plugin *dependantPlugin); - Plugin* getPlugin(const QString& name); - QList getPluginsList() { return h_plugins.values(); } - const PluginHash& getPluginsHash() { return h_plugins; } + Plugin* getPlugin(const QString& name) const; + QList getPluginsList() const { return h_plugins.values(); } + const PluginHash& getPluginsHash() const { return h_plugins; } /********************************************************* * MANAGE MAPS @@ -235,9 +256,9 @@ public: bool addMap(MapHandlerGen* map); void removeMap(const QString& name); - MapHandlerGen* getMap(const QString& name); - QList getMapsList() { return h_maps.values(); } - const MapHash& getMapsHash() { return h_maps; } + MapHandlerGen* getMap(const QString& name) const; + QList getMapsList() const { return h_maps.values(); } + const MapHash& getMapsHash() const { return h_maps; } /********************************************************* * MANAGE TEXTURES @@ -247,12 +268,15 @@ public: void releaseTexture(const QString& image); protected: + QString m_appPath; + bool m_initialization; QVBoxLayout* m_verticalLayout; SplitArea* m_splitArea; View* m_firstView; + View* m_currentView; QDockWidget* m_dock; QTabWidget* m_dockTabWidget; @@ -275,18 +299,6 @@ protected: void keyPressEvent(QKeyEvent *event); void keyReleaseEvent(QKeyEvent *event); - /** - * \fn void moveView() - * \brief shows a reordering dialog for the Views - * - * Make a call with the right parameters to the dialog class - * GLVSelector and show this dialog. - * - * This method is meant to be called when the user press - * CTRL+Shift+M. - */ - void moveView(); - public slots: /** * \fn void cb_about_SCHNApps(); @@ -307,13 +319,6 @@ public slots: */ void cb_manageCameras(); - /** - * \fn void cb_manageViews() - * \brief method called when the "Views" action is triggered. - * Show the scenes management dialog: - */ - void cb_manageViews(); - /** * \fn void cb_managePlugins() * \brief method called when the "Plugins" action is triggered. @@ -321,6 +326,8 @@ public slots: */ void cb_managePlugins(); + void cb_manageMaps(); + signals: void cameraAdded(Camera* camera); void cameraRemoved(Camera* camera); diff --git a/SCHNApps/src/camera.cpp b/SCHNApps/src/camera.cpp index 495d4d21a..401afe067 100644 --- a/SCHNApps/src/camera.cpp +++ b/SCHNApps/src/camera.cpp @@ -14,7 +14,7 @@ Camera::Camera(const QString& name, Window* window) : m_snapCount(0) { ++cameraCount; - this->setZClippingCoefficient(100); +// setZClippingCoefficient(100); } Camera::~Camera() @@ -47,11 +47,6 @@ void Camera::unlinkView(View* view) l_views.removeOne(view); } -bool Camera::isLinkedWithView(View* view) -{ - return l_views.contains(view); -} - void Camera::fitParamWith(View* view) { setScreenWidthAndHeight(view->width(), view->height()); diff --git a/SCHNApps/src/cameraViewDialog.cpp b/SCHNApps/src/cameraViewDialog.cpp index 694f4988d..54a57b286 100644 --- a/SCHNApps/src/cameraViewDialog.cpp +++ b/SCHNApps/src/cameraViewDialog.cpp @@ -32,7 +32,7 @@ CameraViewDialog::~CameraViewDialog() void CameraViewDialog::selectCurrentCamera() { - Camera* current = m_view->getCurrentCamera(); + const Camera* current = m_view->getCurrentCamera(); for(int i = 0; i < cameraList->count(); ++i) { if(cameraList->item(i)->text() == current->getName()) diff --git a/SCHNApps/src/main.cpp b/SCHNApps/src/main.cpp index 271dbe7c9..39b6ebc11 100644 --- a/SCHNApps/src/main.cpp +++ b/SCHNApps/src/main.cpp @@ -1,27 +1,22 @@ #include "system.h" #include "window.h" -QSplashScreen* System::splash; - -//QString System::app_path = QString(); +//QSplashScreen* System::splash; int main(int argc, char* argv[]) { QApplication app(argc, argv); - - System::app_path = app.applicationDirPath(); - System::splash = new QSplashScreen(QPixmap(":splash/cgogn/splash.png")); - - System::splash->show(); + QSplashScreen* splash = new QSplashScreen(QPixmap(":splash/cgogn/splash.png")); + splash->show(); + splash->showMessage("Welcome to SCHNApps", Qt::AlignBottom | Qt::AlignCenter); Window window; + window.setAppPath(app.applicationDirPath()); window.show(); - sleep(1); - System::splash->finish(&window); - - delete System::splash; + splash->finish(&window); + delete splash; return app.exec(); } diff --git a/SCHNApps/src/mapHandler.cpp b/SCHNApps/src/mapHandler.cpp index 26a189fe2..ac16babc3 100644 --- a/SCHNApps/src/mapHandler.cpp +++ b/SCHNApps/src/mapHandler.cpp @@ -5,7 +5,9 @@ MapHandlerGen::MapHandlerGen(const QString& name, Window* window) : m_name(name), m_window(window) -{} +{ + m_render = new CGoGN::Algo::Render::GL2::MapRender(); +} MapHandlerGen::~MapHandlerGen() { @@ -13,6 +15,11 @@ MapHandlerGen::~MapHandlerGen() delete vbo; } +void MapHandlerGen::draw(CGoGN::Utils::GLSLShader* shader, int primitive) +{ + m_render->draw(shader, primitive); +} + CGoGN::Utils::VBO* MapHandlerGen::getVBO(const std::string& name) { if (h_vbo.contains(name)) @@ -35,60 +42,6 @@ void MapHandlerGen::deleteVBO(const std::string& name) } } -//CGoGN::Utils::VBO* MapHandlerGen::addVBO(const QString& name) -//{ -// if (h_vbo.contains(name)) -// { -// System::Error::code = System::Error::VBO_EXISTS; -// return NULL; -// } -// -// CGoGN::Utils::VBO* vbo = new CGoGN::Utils::VBO(); -// h_vbo.insert(name, vbo); -// return vbo; -//} -// -//void MapHandlerGen::removeVBO(const QString& name) -//{ -// if (h_vbo.contains(name)) -// { -// CGoGN::Utils::VBO* vbo = h_vbo[name]; -// h_vbo.remove(name); -// delete vbo; -// } -//} -// -//CGoGN::Utils::VBO* MapHandlerGen::getVBO(const QString& name) -//{ -// if (h_vbo.contains(name)) -// return h_vbo[name]; -// else -// return addVBO(name); -//} -// -//CGoGN::Utils::VBO* MapHandlerGen::findFirstVBOMatching(const QRegExp& regexp) -//{ -// QHash::iterator it; -// for (it = h_vbo.begin(); it != h_vbo.end(); ++it) -// { -// if (it.key().contains(regexp)) -// return it.value(); -// } -// return NULL; -//} -// -//QList MapHandlerGen::findVBOsMatching(const QRegExp& regexp) -//{ -// QList rlist; -// QHash::iterator it; -// for (it = h_vbo.begin(); it != h_vbo.end(); ++it) -// { -// if (it.key().contains(regexp)) -// rlist.push_back(it.value()); -// } -// return rlist; -//} - /********************************************************* * MANAGE LINKED VIEWS *********************************************************/ @@ -108,7 +61,5 @@ bool MapHandlerGen::linkView(View* view) void MapHandlerGen::unlinkView(View* view) { if(l_views.removeOne(view)) - { view->updateGL(); - } } diff --git a/SCHNApps/src/pluginDialog.cpp b/SCHNApps/src/pluginDialog.cpp index 5929ad58d..91c41d4ff 100644 --- a/SCHNApps/src/pluginDialog.cpp +++ b/SCHNApps/src/pluginDialog.cpp @@ -18,6 +18,7 @@ #include "plugin.h" PluginDialog::PluginDialog(Window* window) : + QDialog(window), m_window(window), init(true) { @@ -156,7 +157,7 @@ void PluginDialog::cb_addPlugins() QStringList files = QFileDialog::getOpenFileNames( this, "Select one or more plugins", - System::app_path + QString("/../Plugins/"), + m_window->getAppPath() + QString("/../Plugins/"), "Plugins (lib*.so lib*.dylib)" ); @@ -190,7 +191,7 @@ void PluginDialog::cb_addPluginsDirectory() QString dir = QFileDialog::getExistingDirectory( this, tr("Select a directory"), - System::app_path + QString("/../Plugins/"), + m_window->getAppPath() + QString("/../Plugins/"), QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks ); diff --git a/SCHNApps/src/system.cpp b/SCHNApps/src/system.cpp index 5fedb56df..49c8e9277 100644 --- a/SCHNApps/src/system.cpp +++ b/SCHNApps/src/system.cpp @@ -14,8 +14,6 @@ Error::ERROR_CODE Error::code = SUCCESS; QString Error::parameter = QString("???"); -QString app_path = QString(); - bool Events::movieDialogOpened = false; //bool Dialog::InfoDialog::setContent(QUrl urlHTMLFile) diff --git a/SCHNApps/src/view.cpp b/SCHNApps/src/view.cpp index f7ce10c3d..31537b0d0 100644 --- a/SCHNApps/src/view.cpp +++ b/SCHNApps/src/view.cpp @@ -1,6 +1,5 @@ #include "view.h" -#include "window.h" #include "plugin.h" #include "camera.h" #include "viewButtonArea.h" @@ -46,13 +45,13 @@ View::~View() foreach(Plugin* plugin, l_plugins) { plugin->unlinkView(this); - unlinkPlugin(plugin); +// unlinkPlugin(plugin); } foreach(MapHandlerGen* map, l_maps) { map->unlinkView(this); - unlinkMap(map); +// unlinkMap(map); } delete m_buttonArea; @@ -96,7 +95,8 @@ void View::preDraw() it != CGoGN::Utils::GLSLShader::m_registeredShaders.end(); ++it) { - it->second->updateMatrices(pm, mm); + if(it->first == this || it->first == NULL) + it->second->updateMatrices(pm, mm); } QGLViewer::preDraw(); @@ -113,6 +113,8 @@ void View::postDraw() glPushAttrib(GL_ALL_ATTRIB_BITS); drawButtons(); drawText(); + if(isCurrentView()) + drawFrame(); glPopAttrib(); QGLViewer::postDraw(); @@ -140,6 +142,20 @@ void View::drawButtons() glDisable(GL_TEXTURE_2D); } +void View::drawFrame() +{ + startScreenCoordinatesSystem(); + glColor3f(0.0f, 1.0f, 0.0f); + glLineWidth(2.0); + glBegin(GL_LINE_LOOP); + glVertex2i(1, 1); + glVertex2i(1, height()-1); + glVertex2i(width()-1, height()-1); + glVertex2i(width()-1, 1); + glEnd(); + stopScreenCoordinatesSystem(); +} + void View::keyPressEvent(QKeyEvent* event) { foreach(Plugin* plugin, l_plugins) @@ -156,6 +172,9 @@ void View::keyReleaseEvent(QKeyEvent *event) void View::mousePressEvent(QMouseEvent* event) { + if(!isCurrentView()) + m_window->setCurrentView(this); + if(m_buttonArea->isClicked(event->x(), event->y())) m_buttonArea->clickButton(event->x(), event->y(), event->globalX(), event->globalY()); else @@ -187,13 +206,6 @@ void View::wheelEvent(QWheelEvent* event) QGLViewer::wheelEvent(event); } -void View::drawOverpaint(QPainter *painter) -{ - painter->save(); - painter->setOpacity(0.8); - painter->restore(); -} - /********************************************************* * MANAGE LINKED CAMERA *********************************************************/ @@ -216,12 +228,18 @@ void View::setCurrentCamera(Camera* c) void View::linkPlugin(Plugin* plugin) { if(plugin && !l_plugins.contains(plugin)) + { l_plugins.push_back(plugin); + if(isCurrentView()) + m_window->enablePluginTabWidgets(plugin); + } } void View::unlinkPlugin(Plugin* plugin) { l_plugins.removeOne(plugin); + if(isCurrentView()) + m_window->disablePluginTabWidgets(plugin); } /********************************************************* @@ -236,6 +254,7 @@ void View::linkMap(MapHandlerGen* map) // TODO : update view global BB setSceneBoundingBox(map->getBBmin(), map->getBBmax()); + showEntireScene(); } } @@ -256,10 +275,10 @@ void View::updateTextInfo() QString(" / camera: ") + m_currentCamera->getName(); } -glm::mat4 View::getCurrentModelViewMatrix() +glm::mat4 View::getCurrentModelViewMatrix() const { GLdouble gl_mvm[16]; - this->camera()->getModelViewMatrix(gl_mvm); + camera()->getModelViewMatrix(gl_mvm); glm::mat4 mvm; for(unsigned int i = 0; i < 4; ++i) { @@ -269,10 +288,10 @@ glm::mat4 View::getCurrentModelViewMatrix() return mvm; } -glm::mat4 View::getCurrentProjectionMatrix() +glm::mat4 View::getCurrentProjectionMatrix() const { GLdouble gl_pm[16]; - this->camera()->getProjectionMatrix(gl_pm); + camera()->getProjectionMatrix(gl_pm); glm::mat4 pm; for(unsigned int i = 0; i < 4; ++i) { @@ -282,10 +301,10 @@ glm::mat4 View::getCurrentProjectionMatrix() return pm; } -glm::mat4 View::getCurrentModelViewProjectionMatrix() +glm::mat4 View::getCurrentModelViewProjectionMatrix() const { GLdouble gl_mvpm[16]; - this->camera()->getModelViewProjectionMatrix(gl_mvpm); + camera()->getModelViewProjectionMatrix(gl_mvpm); glm::mat4 mvpm; for(unsigned int i = 0; i < 4; ++i) { @@ -303,7 +322,7 @@ void View::setCurrentModelViewMatrix(const glm::mat4& mvm) for(unsigned int j = 0; j < 4; ++j) gl_mvm[i*4+j] = mvm[i][j]; } - this->camera()->setFromModelViewMatrix(gl_mvm); + camera()->setFromModelViewMatrix(gl_mvm); } void View::setCurrentProjectionMatrix(const glm::mat4& pm) @@ -314,7 +333,7 @@ void View::setCurrentProjectionMatrix(const glm::mat4& pm) for(unsigned int j = 0; j < 4; ++j) gl_pm[i*3+j] = pm[i][j]; } - this->camera()->setFromProjectionMatrix(gl_pm); + camera()->setFromProjectionMatrix(gl_pm); } void View::cb_cameraView(int x, int y, int globalX, int globalY) diff --git a/SCHNApps/src/window.cpp b/SCHNApps/src/window.cpp index 7bc54bdf8..0afd3f43e 100644 --- a/SCHNApps/src/window.cpp +++ b/SCHNApps/src/window.cpp @@ -20,8 +20,7 @@ Window::Window(QWidget *parent) : QMainWindow(parent), m_firstView(NULL), - m_dock(NULL), - m_dockTabWidget(NULL) + m_currentView(NULL) { // program in its initialization phase m_initialization = true; @@ -30,12 +29,9 @@ Window::Window(QWidget *parent) : m_cameraDialog = new CameraDialog(this); this->setupUi(this); - System::splash->showMessage("Welcome to SCHNApps", Qt::AlignBottom | Qt::AlignCenter); - sleep(1); // layout in which we store the main area m_verticalLayout = new QVBoxLayout(centralwidget); - m_verticalLayout->setObjectName(QString::fromUtf8("verticalLayout")); // the main area: multi GL views display area m_splitArea = new SplitArea(centralwidget); @@ -48,7 +44,7 @@ Window::Window(QWidget *parent) : m_dockTabWidget = new QTabWidget(m_dock); m_dockTabWidget->setObjectName("DockTabWidget"); - m_dockTabWidget->setLayoutDirection(Qt::RightToLeft); + m_dockTabWidget->setLayoutDirection(Qt::LeftToRight); m_dockTabWidget->setTabPosition(QTabWidget::East); m_dock->setWidget(m_dockTabWidget); @@ -59,6 +55,7 @@ Window::Window(QWidget *parent) : // add first view m_firstView = addView(); + m_currentView = m_firstView; m_splitArea->addFitElement(m_firstView); glewInit(); @@ -68,7 +65,7 @@ Window::Window(QWidget *parent) : connect(actionAboutCGoGN, SIGNAL(triggered()), this, SLOT(cb_aboutCGoGN())); connect(actionManagePlugins, SIGNAL(triggered()), this, SLOT(cb_managePlugins())); - connect(actionManageViews, SIGNAL(triggered()), this, SLOT(cb_manageViews())); + connect(actionManageMaps, SIGNAL(triggered()), this, SLOT(cb_manageMaps())); connect(actionManageCameras, SIGNAL(triggered()), this, SLOT(cb_manageCameras())); // System::StateHandler::loadState(this, &h_plugin, &h_scene, m_splitArea); @@ -86,19 +83,13 @@ Window::~Window() * MANAGE DOCK *********************************************************/ -QTabWidget* Window::getDockTabWidget() -{ - // if no dock or no tab widget: set error message - if (!m_dock || !m_dockTabWidget) - System::Error::code = System::Error::NO_DOCK; - - return m_dockTabWidget; -} - void Window::addTabInDock(QWidget* tabWidget, const QString& tabText) { if(tabWidget) - m_dockTabWidget->addTab(tabWidget, tabText); + { + int idx = m_dockTabWidget->addTab(tabWidget, tabText); + m_dockTabWidget->setTabEnabled(idx, false); + } } void Window::removeTabInDock(QWidget *tabWidget) @@ -107,6 +98,26 @@ void Window::removeTabInDock(QWidget *tabWidget) m_dockTabWidget->removeTab(m_dockTabWidget->indexOf(tabWidget)); } +void Window::enablePluginTabWidgets(Plugin* plugin) +{ + const QList tabWidgets = plugin->getTabWidgets(); + foreach(QWidget* w, tabWidgets) + { + int idx = m_dockTabWidget->indexOf(w); + m_dockTabWidget->setTabEnabled(idx, true); + } +} + +void Window::disablePluginTabWidgets(Plugin* plugin) +{ + const QList tabWidgets = plugin->getTabWidgets(); + foreach(QWidget* w, tabWidgets) + { + int idx = m_dockTabWidget->indexOf(w); + m_dockTabWidget->setTabEnabled(idx, false); + } +} + /********************************************************* * MANAGE MENU ACTIONS *********************************************************/ @@ -316,7 +327,7 @@ void Window::removeCamera(const QString& name) } } -Camera* Window::getCamera(const QString& name) +Camera* Window::getCamera(const QString& name) const { if (h_cameras.contains(name)) return h_cameras[name]; @@ -363,8 +374,22 @@ void Window::removeView(const QString& name) if(h_views.count() > 1) { View* view = h_views[name]; - if(m_firstView == view) - m_firstView = h_views.constBegin().value(); + if(view == m_firstView) + { + ViewHash::const_iterator i = h_views.constBegin(); + while (i != h_views.constEnd()) + { + if(i.value() != view) + { + m_firstView = i.value(); + i = h_views.constEnd(); + } + else + ++i; + } + } +// if(view == m_currentView) + setCurrentView(m_firstView); h_views.remove(name); emit(viewRemoved(view)); @@ -374,7 +399,7 @@ void Window::removeView(const QString& name) } } -View* Window::getView(const QString& name) +View* Window::getView(const QString& name) const { if (h_views.contains(name)) return h_views[name]; @@ -385,11 +410,84 @@ View* Window::getView(const QString& name) } } +void Window::setCurrentView(View* view) +{ + const QList& oldPlugins = m_currentView->getLinkedPlugins(); + foreach(Plugin* p, oldPlugins) + disablePluginTabWidgets(p); + + View* oldCurrent = m_currentView; + m_currentView = view; + + const QList& newPlugins = m_currentView->getLinkedPlugins(); + foreach(Plugin* p, newPlugins) + { + enablePluginTabWidgets(p); + p->currentViewChanged(m_currentView); + } + + oldCurrent->updateGL(); + m_currentView->updateGL(); +} + +void Window::moveView() +{ + // if splitArea not empty or has more than 1 element + if (m_splitArea->getNbRows() > 1 || ((QSplitter *)m_splitArea->widget(0))->count() > 1) + { + // map the splitArea + ViewPixMaps pm, finalPm; + pm.fromSplitArea(m_splitArea); + + // build a GLViewerSelector using this map + ViewSelector selector(pm, this, ViewSelector::MOVE); + + // show the move dialog box + selector.exec(); + + // the dialog is accepted: it has some modification + if (selector.result() == QDialog::Accepted) + { + // get back the modifier map + finalPm = selector.getGLVMap(); + + // creating a new split area and switch it with the old one + SplitArea *old = m_splitArea; + m_splitArea = new SplitArea(centralwidget); + m_verticalLayout->addWidget(m_splitArea); + + // fill the new SplitArea using the modified map + int x = 0; + int y = 0; + + for (ViewPixMaps::y_iterator y_it = finalPm.y_begin(); y_it != finalPm.y_end(); ++y_it) + { + for (ViewPixMaps::x_iterator x_it = finalPm.x_begin(y_it); x_it != finalPm.x_end(y_it); ++x_it) + { + x_it->view->setParent(m_splitArea); + m_splitArea->addElementAt(x_it->view, x, y); + ++x; + } + x = 0; + ++y; + } + + // delete the old splitArea + delete old; + } + + // key states at the end of the move dialog + keys[0] = selector.keys[0]; + keys[1] = selector.keys[1]; + keys[2] = selector.keys[2]; + } +} + /********************************************************* * MANAGE PLUGINS *********************************************************/ -Plugin* Window::loadPlugin(QString pluginFilePath) +Plugin* Window::loadPlugin(const QString& pluginFilePath) { QString pluginName = QFileInfo(pluginFilePath).baseName().remove(0, 3); @@ -460,7 +558,7 @@ void Window::unloadPlugin(const QString& pluginName) } } -Plugin* Window::getPlugin(const QString& name) +Plugin* Window::getPlugin(const QString& name) const { if (h_plugins.contains(name)) return h_plugins[name]; @@ -523,7 +621,7 @@ void Window::removeMap(const QString& name) } } -MapHandlerGen* Window::getMap(const QString& name) +MapHandlerGen* Window::getMap(const QString& name) const { if (h_maps.contains(name)) return h_maps[name]; @@ -601,58 +699,7 @@ void Window::keyReleaseEvent(QKeyEvent *event) keys[2] = false; } -void Window::moveView() -{ - // if splitArea not empty or has more than 1 element - if (m_splitArea->getNbRows() > 1 || ((QSplitter *)m_splitArea->widget(0))->count() > 1) - { - // map the splitArea - ViewPixMaps pm, finalPm; - pm.fromSplitArea(m_splitArea); - - // build a GLViewerSelector using this map - ViewSelector selector(pm, this, ViewSelector::MOVE); - - // show the move dialog box - selector.exec(); - - // the dialog is accepted: it has some modification - if (selector.result() == QDialog::Accepted) - { - // get back the modifier map - finalPm = selector.getGLVMap(); - // creating a new split area and switch it with the old one - SplitArea *old = m_splitArea; - m_splitArea = new SplitArea(centralwidget); - m_verticalLayout->addWidget(m_splitArea); - - // fill the new SplitArea using the modified map - int x = 0; - int y = 0; - - for (ViewPixMaps::y_iterator y_it = finalPm.y_begin(); y_it != finalPm.y_end(); ++y_it) - { - for (ViewPixMaps::x_iterator x_it = finalPm.x_begin(y_it); x_it != finalPm.x_end(y_it); ++x_it) - { - x_it->view->setParent(m_splitArea); - m_splitArea->addElementAt(x_it->view, x, y); - ++x; - } - x = 0; - ++y; - } - - // delete the old splitArea - delete old; - } - - // key states at the end of the move dialog - keys[0] = selector.keys[0]; - keys[1] = selector.keys[1]; - keys[2] = selector.keys[2]; - } -} void Window::cb_aboutSCHNApps() { @@ -676,24 +723,12 @@ void Window::cb_manageCameras() m_cameraDialog->show(); } -void Window::cb_manageViews() +void Window::cb_managePlugins() { - ViewPixMaps pm; - pm.fromSplitArea(m_splitArea); - - ViewSelector selector(pm, this, ViewSelector::SELECT); - selector.setInsertionName("new view"); - selector.exec(); - - if (selector.result() == QDialog::Accepted) - { - View* v = addView(); - QPoint insertPoint = selector.getInsertPoint(); - m_splitArea->addElementAt(v, insertPoint.x(), insertPoint.y()); - } + m_pluginDialog->show(); } -void Window::cb_managePlugins() +void Window::cb_manageMaps() { - m_pluginDialog->show(); + } diff --git a/src/Utils/GLSLShader.cpp b/src/Utils/GLSLShader.cpp index b6e8058f3..01e16287c 100644 --- a/src/Utils/GLSLShader.cpp +++ b/src/Utils/GLSLShader.cpp @@ -1045,6 +1045,8 @@ void GLSLShader::updateMatrices(const glm::mat4& projection, const glm::mat4& mo glm::mat4 normalMatrix = glm::gtx::inverse_transpose::inverseTranspose(modelview); glUniformMatrix4fv(*m_uniMat_Normal, 1 , false, &normalMatrix[0][0]); } + + this->unbind(); } void GLSLShader::updateMatrices(const glm::mat4& projection, const glm::mat4& modelview, const glm::mat4& PMV, const glm::mat4& normalMatrix) @@ -1066,6 +1068,8 @@ void GLSLShader::updateMatrices(const glm::mat4& projection, const glm::mat4& mo { glUniformMatrix4fv(*m_uniMat_Normal, 1 , false, &normalMatrix[0][0]); } + + this->unbind(); } @@ -1080,11 +1084,12 @@ void GLSLShader::enableVertexAttribs(unsigned int stride, unsigned int begin) co glEnableVertexAttribArray(it->va_id); glVertexAttribPointer(it->va_id, it->vbo_ptr->dataSize(), GL_FLOAT, false, stride, (const GLvoid*)begin); } +// this->unbind(); } void GLSLShader::disableVertexAttribs() const { - this->bind(); +// this->bind(); for (std::vector::const_iterator it = m_va_vbo_binding.begin(); it != m_va_vbo_binding.end(); ++it) glDisableVertexAttribArray(it->va_id); this->unbind(); -- GitLab