From 222b99597e1e3d2ccd9b73f2016a1f83c4392de8 Mon Sep 17 00:00:00 2001 From: Pierre Kraemer Date: Wed, 23 Jan 2013 14:59:41 +0100 Subject: [PATCH] SCHNApps: new addMap method --- .../Plugins/importSurface/importSurface.cpp | 35 ++++++++++--------- SCHNApps/include/window.h | 3 +- SCHNApps/src/window.cpp | 19 +++++----- 3 files changed, 27 insertions(+), 30 deletions(-) diff --git a/SCHNApps/Plugins/importSurface/importSurface.cpp b/SCHNApps/Plugins/importSurface/importSurface.cpp index 5c857f06..4d53b184 100644 --- a/SCHNApps/Plugins/importSurface/importSurface.cpp +++ b/SCHNApps/Plugins/importSurface/importSurface.cpp @@ -20,28 +20,29 @@ void ImportSurfacePlugin::importFromFile(const QString& fileName) QFileInfo fi(fileName); if(fi.exists()) { - GenericMap* m = m_window->createMap(2); - PFP2::MAP* map = static_cast(m); - MapHandler* h = new MapHandler(fi.baseName(), m_window, map); + MapHandlerGen* mhg = m_window->addMap(fi.baseName(), 2); + if(mhg) + { + MapHandler* mh = static_cast*>(mhg); + PFP2::MAP* map = mh->getMap(); - std::vector attrNames ; - Algo::Surface::Import::importMesh(*map, fileName.toUtf8().constData(), attrNames); + std::vector attrNames ; + Algo::Surface::Import::importMesh(*map, fileName.toUtf8().constData(), attrNames); - // get vertex position attribute - VertexAttribute position = map->getAttribute(attrNames[0]); + // get vertex position attribute + VertexAttribute position = map->getAttribute(attrNames[0]); - // create VBO for vertex position attribute - h->createVBO(position); + // create VBO for vertex position attribute + mh->createVBO(position); - // compute map bounding box - h->updateBB(position); + // compute map bounding box + mh->updateBB(position); - // compute primitive connectivity VBOs - h->updatePrimitives(Algo::Render::GL2::POINTS); - h->updatePrimitives(Algo::Render::GL2::LINES); - h->updatePrimitives(Algo::Render::GL2::TRIANGLES); - - m_window->addMap(h); + // compute primitive connectivity VBOs + mh->updatePrimitives(Algo::Render::GL2::POINTS); + mh->updatePrimitives(Algo::Render::GL2::LINES); + mh->updatePrimitives(Algo::Render::GL2::TRIANGLES); + } } } diff --git a/SCHNApps/include/window.h b/SCHNApps/include/window.h index 3d4eb5e3..61468d77 100644 --- a/SCHNApps/include/window.h +++ b/SCHNApps/include/window.h @@ -213,8 +213,7 @@ public: * MANAGE MAPS *********************************************************/ - GenericMap* createMap(unsigned int dim); - bool addMap(MapHandlerGen* map); + MapHandlerGen* addMap(const QString& name, unsigned int dim); void removeMap(const QString& name); MapHandlerGen* getMap(const QString& name) const; QList getMapsList() const { return h_maps.values(); } diff --git a/SCHNApps/src/window.cpp b/SCHNApps/src/window.cpp index 79cbcd8c..33d807ad 100644 --- a/SCHNApps/src/window.cpp +++ b/SCHNApps/src/window.cpp @@ -514,8 +514,11 @@ Plugin* Window::checkPluginDependencie(QString name, Plugin* dependantPlugin) * MANAGE MAPS *********************************************************/ -GenericMap* Window::createMap(unsigned int dim) +MapHandlerGen* Window::addMap(const QString& name, unsigned int dim) { + if (h_maps.contains(name)) + return NULL; + GenericMap* map = NULL; switch(dim) { @@ -526,19 +529,13 @@ GenericMap* Window::createMap(unsigned int dim) map = new PFP3::MAP(); break; } - return map; -} -bool Window::addMap(MapHandlerGen* map) -{ - if (h_maps.contains(map->getName())) - return false; + MapHandlerGen* mh = new MapHandlerGen(name, this, map); + h_maps.insert(name, mh); - h_maps.insert(map->getName(), map); + emit(mapAdded(mh)); - emit(mapAdded(map)); - - return true; + return mh; } void Window::removeMap(const QString& name) -- GitLab