diff --git a/CMakeLists.txt b/CMakeLists.txt index 0b1fdfdc26a2c1efa679eb8ed457bb6eb74762e6..691e7989ef2740c3db7a186f2add20b01ea6fab2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -146,6 +146,7 @@ IF(WIN32) # set(CMAKE_CONFIGURATION_TYPES "Release Debug" CACHE STRING "Only Release or Debug" FORCE) ELSE(WIN32) SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -fPIC") + SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -fPIC") add_subdirectory(Release) add_subdirectory(Debug) add_subdirectory(${CGoGN_ROOT_DIR}/Apps Apps) diff --git a/SCHNApps/CMakeLists.txt b/SCHNApps/CMakeLists.txt index 553309398f9dc32814d1313c7823f78885bfbc7f..b50055a45cf3cd5d2db78817c30f4b113bb3721f 100644 --- a/SCHNApps/CMakeLists.txt +++ b/SCHNApps/CMakeLists.txt @@ -8,6 +8,7 @@ SET( QT_USE_QTDESIGNER TRUE ) SET( QT_USE_QTGUI TRUE ) SET( QT_USE_QTPLUGIN TRUE ) +SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -fPIC") #========CGoGN========# SET(CGoGN_ROOT_DIR ${CMAKE_SOURCE_DIR}/.. CACHE STRING "CGoGN root dir") diff --git a/SCHNApps/Debug/CMakeLists.txt b/SCHNApps/Debug/CMakeLists.txt index 76e148c2ac7a3fa31173e31d417c928298a92805..5f0cd6b4b2878e9bd71a10e871253ba2c3f389f0 100644 --- a/SCHNApps/Debug/CMakeLists.txt +++ b/SCHNApps/Debug/CMakeLists.txt @@ -39,9 +39,12 @@ file( ) SET(SCHNApps_H_OBJECT_FILES - ${SCHNApps_ROOT_DIR}/include/window.h - ${SCHNApps_ROOT_DIR}/include/view.h + ${SCHNApps_ROOT_DIR}/include/camera.h + ${SCHNApps_ROOT_DIR}/include/mapHandler.h + ${SCHNApps_ROOT_DIR}/include/plugin.h ${SCHNApps_ROOT_DIR}/include/splitArea.h + ${SCHNApps_ROOT_DIR}/include/view.h + ${SCHNApps_ROOT_DIR}/include/window.h ${SCHNApps_ROOT_DIR}/include/viewButtonArea.h ${SCHNApps_ROOT_DIR}/include/viewSelector.h ${SCHNApps_ROOT_DIR}/include/cameraDialog.h diff --git a/SCHNApps/Plugins/firstPlugin/include/firstPlugin.h b/SCHNApps/Plugins/firstPlugin/include/firstPlugin.h index ca4e3bd50bd1b59cc18671afae5afc19f176d917..fb53cc3de6093904b0ed8d70eb14bb54db66961f 100644 --- a/SCHNApps/Plugins/firstPlugin/include/firstPlugin.h +++ b/SCHNApps/Plugins/firstPlugin/include/firstPlugin.h @@ -6,7 +6,8 @@ /**---CGoGN includes **/ #include "Topology/generic/parameters.h" #include "Topology/map/embeddedMap2.h" -#include "Algo/Render/GL2/topoRender.h" +#include "Algo/Render/GL2/mapRender.h" +#include "Utils/Shaders/shaderFlat.h" /**---CGoGN includes **/ /**---Definitions specific to CGoGN ---*/ @@ -50,7 +51,6 @@ public: FirstPlugin() { setProvidesRendering(true); - glewInit(); } ~FirstPlugin() @@ -87,34 +87,11 @@ public: virtual void viewRemoved(View* view) {} protected: - /** Attributes that are specific to this plugin **/ MAP myMap; - - // attribute for vertices positions VertexAttribute position; - - // render (for the topo) - Algo::Render::GL2::TopoRender *m_render_topo; - - // just for more compact writing - inline Dart PHI1(Dart d) - { - return myMap.phi1(d); - } - inline Dart PHI_1(Dart d) - { - return myMap.phi_1(d); - } - inline Dart PHI2(Dart d) - { - return myMap.phi2(d); - } - template - Dart PHI(Dart d) - { - return myMap.phi(d); - } - /** Attributes that are specific to this plugin **/ + Algo::Render::GL2::MapRender* m_render ; + Utils::VBO* m_positionVBO ; + Utils::ShaderFlat* m_flatShader ; }; #endif // _FIRSTPLUGIN_H_ diff --git a/SCHNApps/Plugins/firstPlugin/src/firstPlugin.cpp b/SCHNApps/Plugins/firstPlugin/src/firstPlugin.cpp index 788765f95c34f5146a81a2f4c97770ef269ba920..0862e1e1ff8c9e0892db3b56cab731842bb88aa2 100644 --- a/SCHNApps/Plugins/firstPlugin/src/firstPlugin.cpp +++ b/SCHNApps/Plugins/firstPlugin/src/firstPlugin.cpp @@ -1,78 +1,48 @@ #include "firstPlugin.h" #include "Algo/Geometry/boundingbox.h" +#include "Algo/Import/import.h" bool FirstPlugin::enable() { - // creation of 2 new faces: 1 triangle and 1 square - Dart d1 = myMap.newFace(3); - Dart d2 = myMap.newFace(4); + m_render = new Algo::Render::GL2::MapRender() ; + m_positionVBO = new Utils::VBO() ; + m_flatShader = new Utils::ShaderFlat() ; + m_flatShader->setAttributePosition(m_positionVBO) ; + m_flatShader->setAmbiant(Geom::Vec4f(0.2f, 0.2f, 0.2f, 0.1f)) ; + m_flatShader->setDiffuse(Geom::Vec4f(0.8f, 0.9f, 0.7f, 1.0f)) ; + m_flatShader->setExplode(1.0f) ; + CGoGN::Utils::GLSLShader::registerShader(NULL, m_flatShader) ; - // sew these faces along one of their edge - myMap.sewFaces(d1, d2); + std::vector attrNames ; + CGoGN::Algo::Import::importMesh(myMap, "/home/kraemer/Media/Data/surface/lowRes/duck_163.ply", attrNames); + position = myMap.getAttribute(attrNames[0]) ; - // creation of a new attribute on vertices of type 3D vector for position. - // a handler to this attribute is returned - position = myMap.addAttribute("position"); + m_render->initPrimitives(myMap, allDarts, CGoGN::Algo::Render::GL2::POINTS) ; + m_render->initPrimitives(myMap, allDarts, CGoGN::Algo::Render::GL2::LINES) ; + m_render->initPrimitives(myMap, allDarts, CGoGN::Algo::Render::GL2::TRIANGLES) ; - // affect position by moving in the map - position[d1] = VEC3(0, 0, 0); - position[PHI1(d1)] = VEC3(2, 0, 0); - position[PHI_1(d1)] = VEC3(1, 2, 0); - position[PHI<11>(d2)] = VEC3(0, -2, 0); - position[PHI_1(d2)] = VEC3(2, -2, 0); - - m_render_topo = new Algo::Render::GL2::TopoRender() ; - - SelectorDartNoBoundary nb(myMap); - m_render_topo->updateData(myMap, position, 0.9f, 0.9f, nb); + m_positionVBO->updateData(position) ; return true; } void FirstPlugin::disable() { - if (m_render_topo) - { - delete m_render_topo; - } } void FirstPlugin::redraw(View* view) { - m_render_topo->drawTopo(); - -// const float nbSteps = 200.0; -// glBegin(GL_QUAD_STRIP); -// for (float i = 0; i < nbSteps; ++i) -// { -// float ratio = i/nbSteps; -// float angle = 21.0*ratio; -// float c = cos(angle); -// float s = sin(angle); -// float r1 = 1.0 - 0.8f*ratio; -// float r2 = 0.8f - 0.8f*ratio; -// float alt = ratio - 0.5f; -// const float nor = 0.5f; -// const float up = sqrt(1.0-nor*nor); -// glColor3f(1.0-ratio, 0.2f , ratio); -// glNormal3f(nor*c, up, nor*s); -// glVertex3f(r1*c, alt, r1*s); -// glVertex3f(r2*c, alt+0.05f, r2*s); -// } -// glEnd(); + glPolygonMode(GL_FRONT_AND_BACK, GL_FILL) ; + glEnable(GL_LIGHTING) ; + m_render->draw(m_flatShader, Algo::Render::GL2::TRIANGLES) ; } void FirstPlugin::viewAdded(View* view) { - // bounding box of scene - Geom::BoundingBox bb = Algo::Geometry::computeBoundingBox(myMap, position); - - PFP::VEC3& min = bb.min(); - PFP::VEC3& max = bb.max(); - qglviewer::Vec minV(min[0], min[1], min[2]); - qglviewer::Vec maxV(max[0], max[1], max[2]); - - view->setSceneBoundingBox(minV, maxV); + CGoGN::Geom::BoundingBox bb = Algo::Geometry::computeBoundingBox(myMap, position) ; + qglviewer::Vec min(bb.min()[0], bb.min()[1], bb.min()[2]); + qglviewer::Vec max(bb.max()[0], bb.max()[1], bb.max()[2]); + view->setSceneBoundingBox(min, max); } /** diff --git a/SCHNApps/Release/CMakeLists.txt b/SCHNApps/Release/CMakeLists.txt index ad62755f31a1e1da7361a40f5e14221da320221a..c5c140fa78c66dfc76a33b1a22cf5f09e5d96667 100644 --- a/SCHNApps/Release/CMakeLists.txt +++ b/SCHNApps/Release/CMakeLists.txt @@ -2,8 +2,6 @@ cmake_minimum_required(VERSION 2.8) SET(CMAKE_BUILD_TYPE Release) -ADD_DEFINITIONS(-fPIC) - IF(WIN32) link_directories( ${CGoGN_ROOT_DIR}/lib/Release ) ELSE (WIN32) @@ -41,9 +39,12 @@ file( ) SET(SCHNApps_H_OBJECT_FILES - ${SCHNApps_ROOT_DIR}/include/window.h - ${SCHNApps_ROOT_DIR}/include/view.h + ${SCHNApps_ROOT_DIR}/include/camera.h + ${SCHNApps_ROOT_DIR}/include/mapHandler.h + ${SCHNApps_ROOT_DIR}/include/plugin.h ${SCHNApps_ROOT_DIR}/include/splitArea.h + ${SCHNApps_ROOT_DIR}/include/view.h + ${SCHNApps_ROOT_DIR}/include/window.h ${SCHNApps_ROOT_DIR}/include/viewButtonArea.h ${SCHNApps_ROOT_DIR}/include/viewSelector.h ${SCHNApps_ROOT_DIR}/include/cameraDialog.h diff --git a/SCHNApps/include/camera.h b/SCHNApps/include/camera.h index 8c5eb410bcdea6e12b6fe1205d0418fec993df89..fedf8b2f096ff6f3b8d05380e9128e7fc820e0d4 100644 --- a/SCHNApps/include/camera.h +++ b/SCHNApps/include/camera.h @@ -8,6 +8,8 @@ class Window; class Camera : public qglviewer::Camera { + Q_OBJECT + public: static unsigned int cameraCount; @@ -79,6 +81,9 @@ protected: double m_drawPathScale; int m_snapCount; + +public slots: + void cb_viewRemoved(View* view); }; #endif diff --git a/SCHNApps/include/mapHandler.h b/SCHNApps/include/mapHandler.h index 53d5e1189cbc13f1cffdce48d6a7f6649d67fe83..87a51c1d612be8faf562353a731837bd38f34ed1 100644 --- a/SCHNApps/include/mapHandler.h +++ b/SCHNApps/include/mapHandler.h @@ -15,15 +15,20 @@ namespace CGoGN } } -class MapHandler +class MapHandler : public QObject { + Q_OBJECT + public: - MapHandler(const QString& name, CGoGN::GenericMap* map); + MapHandler(const QString& name, Window* window, CGoGN::GenericMap* map); ~MapHandler(); const QString& getName() { return m_name; } void setName(const QString& name) { m_name = name; } + Window* getWindow() { return m_window; } + void setWindow(Window* w) { m_window = w; } + CGoGN::GenericMap* getMap() { return m_map; } CGoGN::Utils::VBO* addVBO(const QString& name); @@ -45,11 +50,15 @@ public: protected: QString m_name; + Window* m_window; CGoGN::GenericMap* m_map; QList l_views; VBOHash h_vbo; + +public slots: + void cb_viewRemoved(View* view); }; #endif diff --git a/SCHNApps/include/plugin.h b/SCHNApps/include/plugin.h index 022ed5bbcb7d6a3dfce6de16a3a5bcf4d7487d19..2c57c3b49c14ac8724791104949c24a303b71433 100644 --- a/SCHNApps/include/plugin.h +++ b/SCHNApps/include/plugin.h @@ -15,10 +15,9 @@ class Plugin : public QObject { -public: - enum { UNLIMITED_NUMBER_OF_MAPS = -1 }; - enum { UNLIMITED_NUMBER_OF_SCENES = -1 }; + Q_OBJECT +public: Plugin(); virtual ~Plugin(); @@ -35,7 +34,12 @@ public: void setWindow(Window* w) { m_window = w; } bool getProvidesRendering() { return b_providesRendering; } - void setProvidesRendering(bool b) { b_providesRendering = b; } + void setProvidesRendering(bool b) + { + b_providesRendering = b; + if(b_providesRendering) + glewInit(); + } virtual void redraw(View* view) = 0; @@ -92,6 +96,9 @@ protected: QList l_menuActions; QList l_toolbarActions; +public slots: + void cb_viewRemoved(View* view); + // QList l_dependencies; // QList l_dependantPlugins; diff --git a/SCHNApps/include/system.h b/SCHNApps/include/system.h index 1c5f2afad4f589b03f603b8e9491aadbefece75c..51f711382e68ff6eecda8bb246e607cfc053cf9c 100644 --- a/SCHNApps/include/system.h +++ b/SCHNApps/include/system.h @@ -143,11 +143,11 @@ public: // static bool savePluginsInfo(Window *window, PluginHash *pluginHash, QStringList paths); //}; -typedef enum -{ - GLVIEWER_IN_DOCK, - SIMPLE_GLVIEWER -} QGLV_CREATE_SETTINGS; +//typedef enum +//{ +// GLVIEWER_IN_DOCK, +// SIMPLE_GLVIEWER +//} QGLV_CREATE_SETTINGS; extern QString app_path; diff --git a/SCHNApps/include/types.h b/SCHNApps/include/types.h index 89c3151d147f498c724f798f2857c89775a6e20b..0031dbe84a9d40f6a041c90f6a883532388ae014 100644 --- a/SCHNApps/include/types.h +++ b/SCHNApps/include/types.h @@ -8,6 +8,7 @@ class Window; class Plugin; class View; class Camera; +class Texture; class MapHandler; @@ -28,6 +29,8 @@ typedef QHash MapHash; typedef QHash VBOHash; typedef QHash ShaderHash; +typedef QHash TextureHash; + namespace Qt { extern int UserRoleType; diff --git a/SCHNApps/include/view.h b/SCHNApps/include/view.h index a2fbb978263e4be0ed1204f289d018b1df613c68..0b22d0098ac00467f66bcaf2b5cf47d41cce48ce 100644 --- a/SCHNApps/include/view.h +++ b/SCHNApps/include/view.h @@ -105,15 +105,18 @@ protected: QString m_textInfo; + qglviewer::Vec bbmin; + qglviewer::Vec bbmax; + CameraViewDialog* m_cameraViewDialog; PluginsViewDialog* m_pluginsViewDialog; MapsViewDialog* m_mapsViewDialog; public slots: - void cb_cameraView(int x, int y); - void cb_pluginsView(int x, int y); - void cb_mapsView(int x, int y); - void cb_closeView(int x, int y); + void cb_cameraView(int x, int y, int globalX, int globalY); + void cb_pluginsView(int x, int y, int globalX, int globalY); + void cb_mapsView(int x, int y, int globalX, int globalY); + void cb_closeView(int x, int y, int globalX, int globalY); //signals: // void currentCameraChanged(Camera* camera); diff --git a/SCHNApps/include/viewButtonArea.h b/SCHNApps/include/viewButtonArea.h index eab958bf7f7001d5934308c7c55b3a2a6744f084..0c022ee9f7859281da873cd7f44cafbba1f47ee0 100644 --- a/SCHNApps/include/viewButtonArea.h +++ b/SCHNApps/include/viewButtonArea.h @@ -10,6 +10,7 @@ #include class View; +class Texture; class ViewButton : public QObject { @@ -19,20 +20,18 @@ public: ViewButton(const QString& image, View* view); ~ViewButton(); - QSize getSize() { return m_GLimg.size(); } + QSize getSize(); - void click(int x, int y); + void click(int x, int y, int globalX, int globalY); void drawAt(int x, int y); protected: + QString m_img; View* m_view; - - QSize m_size; - QImage m_GLimg; - int m_texID; + Texture* m_tex; signals: - void clicked(int x, int y); + void clicked(int x, int y, int globalX, int globalY); }; class ViewButtonArea : public QObject @@ -49,7 +48,7 @@ public: void removeButton(ViewButton* button); bool isClicked(int x, int y); - void clickButton(int x, int y); + void clickButton(int x, int y, int globalX, int globalY); const QRect& getForm() { return m_form; } diff --git a/SCHNApps/include/window.h b/SCHNApps/include/window.h index d17f3673006f16fa57c0e5b2e54fa146b038c532..66e69dd918648126602abdbe55925c2dbe98c1dc 100644 --- a/SCHNApps/include/window.h +++ b/SCHNApps/include/window.h @@ -9,6 +9,7 @@ class SplitArea; class PluginDialog; class CameraDialog; +class Texture; class Window : public QMainWindow, Ui::Window { @@ -238,17 +239,12 @@ public: QList getMapsList() { return h_maps.values(); } const MapHash& getMapsHash() { return h_maps; } -// template -// T* getReferencedMap(QString map_name){ -// MapHash::iterator it; -// if((it=h_map.find(map_name))!=h_map.end()){ -// return ((T*)(*it)); -// } -// else{ -// System::Error::code= System::Error::MAP_UNREFERENCED_f(map_name); -// return NULL; -// } -// } + /********************************************************* + * MANAGE TEXTURES + *********************************************************/ + + Texture* getTexture(const QString& image); + void releaseTexture(const QString& image); protected: bool m_initialization; @@ -266,6 +262,8 @@ protected: CameraHash h_cameras; MapHash h_maps; + TextureHash h_textures; + PluginDialog* m_pluginDialog; CameraDialog* m_cameraDialog; @@ -330,7 +328,7 @@ signals: void viewAdded(View* view); void viewRemoved(View* view); - void mapAdded(MapHandler* camera); + void mapAdded(MapHandler* map); void mapRemoved(MapHandler* map); void pluginAdded(Plugin* plugin); diff --git a/SCHNApps/src/camera.cpp b/SCHNApps/src/camera.cpp index 495d4d21a8e345b20cc78a665df024efdba56c95..29a1c5754cef464d3ffe18d00f1f1a5dd665316c 100644 --- a/SCHNApps/src/camera.cpp +++ b/SCHNApps/src/camera.cpp @@ -15,6 +15,8 @@ Camera::Camera(const QString& name, Window* window) : { ++cameraCount; this->setZClippingCoefficient(100); + +// connect(m_window, SIGNAL(viewRemoved(View*)), this, SLOT(cb_viewRemoved(View*))); } Camera::~Camera() @@ -63,3 +65,8 @@ void Camera::saveSnapshot(QString snapPathName) view->saveSnapshot(snapPathName + view->getName() + '_' + QString::number(m_snapCount) + ".jpg", true); ++m_snapCount; } + +void Camera::cb_viewRemoved(View* view) +{ + unlinkView(view); +} diff --git a/SCHNApps/src/mapHandler.cpp b/SCHNApps/src/mapHandler.cpp index c3379fa7639c78ced24bfcd7c6069c45ef86d1c7..8f754909791d252802538e5d2c112e2ad3b82bcd 100644 --- a/SCHNApps/src/mapHandler.cpp +++ b/SCHNApps/src/mapHandler.cpp @@ -4,10 +4,13 @@ #include "Topology/generic/genericmap.h" #include "Utils/vbo.h" -MapHandler::MapHandler(const QString& name, CGoGN::GenericMap *map) : +MapHandler::MapHandler(const QString& name, Window* window, CGoGN::GenericMap *map) : m_name(name), + m_window(window), m_map(map) -{} +{ +// connect(m_window, SIGNAL(viewRemoved(View*)), this, SLOT(cb_viewRemoved(View*))); +} MapHandler::~MapHandler() { @@ -98,3 +101,8 @@ void MapHandler::unlinkView(View* view) view->updateGL(); } } + +void MapHandler::cb_viewRemoved(View* view) +{ + unlinkView(view); +} diff --git a/SCHNApps/src/plugin.cpp b/SCHNApps/src/plugin.cpp index 46db5d284147eae198bcc76a8c78b9a4677a967d..f636099209ed707a77cebd1467dc2c742a1a3b36 100644 --- a/SCHNApps/src/plugin.cpp +++ b/SCHNApps/src/plugin.cpp @@ -3,7 +3,9 @@ Plugin::Plugin() : m_window(NULL), b_providesRendering(false) -{} +{ +// connect(m_window, SIGNAL(viewRemoved(View*)), this, SLOT(cb_viewRemoved(View*))); +} Plugin::~Plugin() { @@ -114,3 +116,8 @@ void Plugin::removeToolbarAction(QAction* action) if(l_toolbarActions.removeOne(action)) m_window->removeToolbarAction(action); } + +void Plugin::cb_viewRemoved(View* view) +{ + unlinkView(view); +} diff --git a/SCHNApps/src/pluginDialog.cpp b/SCHNApps/src/pluginDialog.cpp index af653a894e00d9b59ef83eedabbc84b7a2dfd92d..5929ad58d5726406d006655ecc24e1838fe7e7c0 100644 --- a/SCHNApps/src/pluginDialog.cpp +++ b/SCHNApps/src/pluginDialog.cpp @@ -15,6 +15,7 @@ #include "system.h" #include "window.h" +#include "plugin.h" PluginDialog::PluginDialog(Window* window) : m_window(window), @@ -155,7 +156,7 @@ void PluginDialog::cb_addPlugins() QStringList files = QFileDialog::getOpenFileNames( this, "Select one or more plugins", - System::app_path, + System::app_path + QString("/../Plugins/"), "Plugins (lib*.so lib*.dylib)" ); @@ -189,7 +190,7 @@ void PluginDialog::cb_addPluginsDirectory() QString dir = QFileDialog::getExistingDirectory( this, tr("Select a directory"), - System::app_path, + System::app_path + QString("/../Plugins/"), QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks ); @@ -345,11 +346,25 @@ void PluginDialog::cb_togglePlugin(QTreeWidgetItem *item, int column) init = true; item->setCheckState(0, Qt::Unchecked); init = false; - return; } } else if (item->checkState(0) == Qt::Unchecked) - m_window->unloadPlugin(pluginName); + { + Plugin* p = m_window->getPlugin(pluginName); + + if(!p->getLinkedViews().empty()) + { + QMessageBox::warning(this, tr("Warning"), "Plugin is currently used"); + init = true; + item->setCheckState(0, Qt::Checked); + init = false; + return; + } + else + { + m_window->unloadPlugin(pluginName); + } + } } } diff --git a/SCHNApps/src/view.cpp b/SCHNApps/src/view.cpp index 49b20f8f4d066db2147ae64dfd11ea01b28fb743..29a87248f7660e1fd318cd14c78127c8ae3441b1 100644 --- a/SCHNApps/src/view.cpp +++ b/SCHNApps/src/view.cpp @@ -43,10 +43,16 @@ View::~View() this->setCamera(c); foreach(Plugin* plugin, l_plugins) + { + plugin->unlinkView(this); unlinkPlugin(plugin); + } foreach(MapHandler* map, l_maps) + { + map->unlinkView(this); unlinkMap(map); + } delete m_buttonArea; } @@ -58,19 +64,19 @@ void View::init() m_cameraButton = new ViewButton(":icons/icons/camera_32.png", this); m_buttonArea->addButton(m_cameraButton); - connect(m_cameraButton, SIGNAL(clicked(int, int)), this, SLOT(cb_cameraView(int, int))); + connect(m_cameraButton, SIGNAL(clicked(int, int, int, int)), this, SLOT(cb_cameraView(int, int, int, int))); m_pluginsButton = new ViewButton(":icons/icons/plugins_32.png", this); m_buttonArea->addButton(m_pluginsButton); - connect(m_pluginsButton, SIGNAL(clicked(int, int)), this, SLOT(cb_pluginsView(int, int))); + connect(m_pluginsButton, SIGNAL(clicked(int, int, int, int)), this, SLOT(cb_pluginsView(int, int, int, int))); m_mapsButton = new ViewButton(":icons/icons/maps_32.png", this); m_buttonArea->addButton(m_mapsButton); - connect(m_mapsButton, SIGNAL(clicked(int, int)), this, SLOT(cb_mapsView(int, int))); + connect(m_mapsButton, SIGNAL(clicked(int, int, int, int)), this, SLOT(cb_mapsView(int, int, int, int))); m_closeButton = new ViewButton(":icons/icons/close_32.png", this); m_buttonArea->addButton(m_closeButton); - connect(m_closeButton, SIGNAL(clicked(int, int)), this, SLOT(cb_closeView(int, int))); + connect(m_closeButton, SIGNAL(clicked(int, int, int, int)), this, SLOT(cb_closeView(int, int, int, int))); qglviewer::Camera* c = this->camera(); this->setCamera(m_currentCamera); @@ -83,8 +89,6 @@ void View::init() void View::preDraw() { - QGLViewer::preDraw(); - glm::mat4 mm = getCurrentModelViewMatrix(); glm::mat4 pm = getCurrentProjectionMatrix(); for(std::set< std::pair >::iterator it = CGoGN::Utils::GLSLShader::m_registeredShaders.begin(); @@ -93,6 +97,8 @@ void View::preDraw() { it->second->updateMatrices(pm, mm); } + + QGLViewer::preDraw(); } void View::draw() @@ -150,7 +156,7 @@ void View::keyReleaseEvent(QKeyEvent *event) void View::mousePressEvent(QMouseEvent* event) { if(m_buttonArea->isClicked(event->x(), event->y())) - m_buttonArea->clickButton(event->x(), event->y()); + m_buttonArea->clickButton(event->x(), event->y(), event->globalX(), event->globalY()); else { foreach(Plugin* plugin, l_plugins) @@ -303,23 +309,25 @@ void View::setCurrentProjectionMatrix(const glm::mat4& pm) this->camera()->setFromProjectionMatrix(gl_pm); } -void View::cb_cameraView(int x, int y) +void View::cb_cameraView(int x, int y, int globalX, int globalY) { -// m_cameraViewDialog->setGeometry(x, y, 150, 300); + m_cameraViewDialog->move(globalX, globalY); m_cameraViewDialog->show(); } -void View::cb_pluginsView(int x, int y) +void View::cb_pluginsView(int x, int y, int globalX, int globalY) { + m_pluginsViewDialog->move(globalX, globalY); m_pluginsViewDialog->show(); } -void View::cb_mapsView(int x, int y) +void View::cb_mapsView(int x, int y, int globalX, int globalY) { + m_mapsViewDialog->move(globalX, globalY); m_mapsViewDialog->show(); } -void View::cb_closeView(int x, int y) +void View::cb_closeView(int x, int y, int globalX, int globalY) { m_window->removeView(m_name); } diff --git a/SCHNApps/src/viewButtonArea.cpp b/SCHNApps/src/viewButtonArea.cpp index 47431569858b1a1fd32fb21fd7eec70de8135642..975a6741e8ba0f871f4956a3b3b5e46e86bc1e42 100644 --- a/SCHNApps/src/viewButtonArea.cpp +++ b/SCHNApps/src/viewButtonArea.cpp @@ -1,44 +1,48 @@ #include "viewButtonArea.h" +#include "window.h" +#include "view.h" +#include "texture.h" #include "camera.h" #include ViewButton::ViewButton(const QString& image, View* view) : + m_img(image), m_view(view) { - m_GLimg.load(image); - if(!m_GLimg.isNull()) - { - m_size = m_GLimg.size(); - m_GLimg = QGLWidget::convertToGLFormat(m_GLimg); - m_texID = m_view->bindTexture(m_GLimg, GL_TEXTURE_2D, GL_RGBA); - } + m_tex = m_view->getWindow()->getTexture(m_img); } ViewButton::~ViewButton() { - m_view->deleteTexture(m_texID); + m_view->getWindow()->releaseTexture(m_img); +} + +QSize ViewButton::getSize() +{ + return m_tex->size; } -void ViewButton::click(int x, int y) +void ViewButton::click(int x, int y, int globalX, int globalY) { - emit clicked(x, y); + emit clicked(x, y, globalX, globalY); } void ViewButton::drawAt(int x, int y) { - glBindTexture(GL_TEXTURE_2D, m_texID); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 32, 32, 0, GL_RGBA, GL_UNSIGNED_BYTE, m_GLimg.bits()); + int w = m_tex->size.width(); + int h = m_tex->size.height(); + glBindTexture(GL_TEXTURE_2D, m_tex->texID); glBegin (GL_QUADS); glTexCoord2i(0, 1); glVertex2i(x, y); glTexCoord2i(0, 0); - glVertex2i(x, y + m_size.height()); + glVertex2i(x, y + h); glTexCoord2i(1, 0); - glVertex2i(x + m_size.width(), y + m_size.height()); + glVertex2i(x + w, y + h); glTexCoord2i(1, 1); - glVertex2i(x + m_size.width(), y); + glVertex2i(x + w, y); glEnd(); } @@ -86,7 +90,7 @@ bool ViewButtonArea::isClicked(int x, int y) return m_form.contains(x, y); } -void ViewButtonArea::clickButton(int x, int y) +void ViewButtonArea::clickButton(int x, int y, int globalX, int globalY) { QPoint p = m_form.topLeft(); p.setY(p.y() + 3); @@ -94,7 +98,7 @@ void ViewButtonArea::clickButton(int x, int y) { if(QRect(p, b->getSize()).contains(x, y)) { - b->click(x, y); + b->click(x, y, globalX, globalY); return; } p.setX(p.x() + 3 + b->getSize().width()); diff --git a/SCHNApps/src/window.cpp b/SCHNApps/src/window.cpp index 37663034af5035d24fc2bac46be6ae510f976986..df1bd64b54c1f62366f1dba55b2fc6b5c0d31161 100644 --- a/SCHNApps/src/window.cpp +++ b/SCHNApps/src/window.cpp @@ -10,6 +10,7 @@ #include "plugin.h" #include "view.h" +#include "texture.h" #include "splitArea.h" #include "viewSelector.h" @@ -417,7 +418,6 @@ Plugin* Window::loadPlugin(QString pluginFilePath) return NULL; } - // QT's plugin loader class QPluginLoader loader(pluginFilePath); // if the loader loads a plugin instance @@ -435,8 +435,8 @@ Plugin* Window::loadPlugin(QString pluginFilePath) { // if it succeeded we reference this plugin h_plugins.insert(pluginName, plugin); - statusbar->showMessage(pluginName + QString(" successfully loaded."), 2000); + statusbar->showMessage(pluginName + QString(" successfully loaded."), 2000); emit(pluginAdded(plugin)); // method success @@ -467,12 +467,14 @@ void Window::unloadPlugin(const QString& pluginName) plugin->disable(); h_plugins.remove(pluginName); + QPluginLoader loader(plugin->getFilePath()); + loader.unload(); + + statusbar->showMessage(pluginName + QString(" successfully unloaded."), 2000); emit(pluginRemoved(plugin)); // delete plugin delete plugin; - - statusbar->showMessage(pluginName + QString(" successfully unloaded."), 2000); } } @@ -550,6 +552,47 @@ MapHandler* Window::getMap(const QString& name) } } +/********************************************************* + * MANAGE TEXTURES + *********************************************************/ + +Texture* Window::getTexture(const QString& image) +{ + if(h_textures.contains(image)) + { + Texture* t = h_textures[image]; + t->ref++; + return t; + } + else + { + Texture* t = NULL; + QImage img(image); + if(!img.isNull()) + { + GLuint texID = m_firstView->bindTexture(img); + t = new Texture(texID, img.size(), 1); + h_textures.insert(image, t); + } + return t; + } +} + +void Window::releaseTexture(const QString& image) +{ + if(h_textures.contains(image)) + { + Texture* t = h_textures[image]; + t->ref--; + if(t->ref == 0) + { + m_firstView->deleteTexture(h_textures[image]->texID); + h_textures.remove(image); + delete t; + } + } +} +