From 7eb312d10beb8fda42669edc2cfda7e235e0060d Mon Sep 17 00:00:00 2001 From: Sebastian Piwell Date: Mon, 4 Apr 2016 11:58:42 -0400 Subject: [PATCH] Delete cygnets --- modules/iswa/rendering/dataplane.cpp | 30 ++--------------- modules/iswa/rendering/iswacontainer.cpp | 21 ++++++++++++ modules/iswa/rendering/iswacontainer.h | 7 ++-- modules/iswa/rendering/iswacygnet.cpp | 12 +++++-- modules/iswa/rendering/iswacygnet.h | 2 ++ modules/iswa/rendering/screenspacecygnet.cpp | 13 ++++++-- modules/iswa/util/iswamanager.cpp | 20 ++++++++++- modules/iswa/util/iswamanager.h | 8 +++++ modules/onscreengui/include/gui.h | 1 + .../include/guipropertycomponent.h | 1 + modules/onscreengui/src/gui.cpp | 6 ++++ .../onscreengui/src/guipropertycomponent.cpp | 33 ++++++++++++++++++- 12 files changed, 117 insertions(+), 37 deletions(-) diff --git a/modules/iswa/rendering/dataplane.cpp b/modules/iswa/rendering/dataplane.cpp index 988c344736..ea78e0a930 100644 --- a/modules/iswa/rendering/dataplane.cpp +++ b/modules/iswa/rendering/dataplane.cpp @@ -91,7 +91,9 @@ bool DataPlane::initialize(){ } bool DataPlane::deinitialize(){ - ISWACygnet::deinitialize(); + CygnetPlane::deinitialize(); + _kw = nullptr; + return true; } @@ -215,32 +217,6 @@ void DataPlane::loadTexture() { } -// void DataPlane::createPlane() { -// // ============================ -// // GEOMETRY (quad) -// // ============================ -// const GLfloat x = _modelScale.x/2.0; -// const GLfloat y = _modelScale.z/2.0; -// const GLfloat w = _modelScale.w; -// const GLfloat vertex_data[] = { // square of two triangles (sigh) -// // x y z w s t -// -x, -y, 0, w, 0, 1, -// x, y, 0, w, 1, 0, -// -x, y, 0, w, 0, 0, -// -x, -y, 0, w, 0, 1, -// x, -y, 0, w, 1, 1, -// x, y, 0, w, 1, 0, -// }; - -// glBindVertexArray(_quad); // bind array -// glBindBuffer(GL_ARRAY_BUFFER, _vertexPositionBuffer); // bind buffer -// glBufferData(GL_ARRAY_BUFFER, sizeof(vertex_data), vertex_data, GL_STATIC_DRAW); -// glEnableVertexAttribArray(0); -// glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, sizeof(GLfloat) * 6, reinterpret_cast(0)); -// glEnableVertexAttribArray(1); -// glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(GLfloat) * 6, reinterpret_cast(sizeof(GLfloat) * 4)); -// } - void DataPlane::updateTexture(){} int DataPlane::id(){ diff --git a/modules/iswa/rendering/iswacontainer.cpp b/modules/iswa/rendering/iswacontainer.cpp index cab4ae2e32..82eee347bd 100644 --- a/modules/iswa/rendering/iswacontainer.cpp +++ b/modules/iswa/rendering/iswacontainer.cpp @@ -44,6 +44,7 @@ bool ISWAContainer::initialize(){ std::cout << "Initialized ISWAContainer" << std::endl; ISWAManager::initialize(); + ISWAManager::ref().setContainer(this); addISWACygnet("${OPENSPACE_DATA}/BATSRUS.cdf"); // addISWACygnet("${OPENSPACE_DATA}/ENLIL.cdf"); @@ -72,6 +73,10 @@ void ISWAContainer::render(const RenderData& data){ } void ISWAContainer::update(const UpdateData& data){ + if(!_deletedCygnets.empty()) + _deletedCygnets.clear(); + + for(auto iSWACygnet : _iSWACygnets) iSWACygnet->update(); } @@ -99,6 +104,22 @@ void ISWAContainer::addISWACygnet(std::string path){ // } } +void ISWAContainer::deleteCygnet(std::string name){ + std::shared_ptr c = iSWACygnet(name); + + auto it = std::find( + _iSWACygnets.begin(), + _iSWACygnets.end(), + c + ); + + if (it != _iSWACygnets.end()) { + c->deinitialize(); + _deletedCygnets.push_back(c); + _iSWACygnets.erase(it); + } +} + std::shared_ptr ISWAContainer::iSWACygnet(std::string name){ for(auto cygnet : _iSWACygnets){ diff --git a/modules/iswa/rendering/iswacontainer.h b/modules/iswa/rendering/iswacontainer.h index d1ea848ba2..2a1ba9a75d 100644 --- a/modules/iswa/rendering/iswacontainer.h +++ b/modules/iswa/rendering/iswacontainer.h @@ -29,7 +29,7 @@ namespace openspace{ class ISWACygnet; -class ISWAContainer : public Renderable { +class ISWAContainer : public Renderable{ public: ISWAContainer(const ghoul::Dictionary& dictionary); ~ISWAContainer(); @@ -44,11 +44,14 @@ public: void addISWACygnet(std::string path); + void deleteCygnet(ISWACygnet*); + void deleteCygnet(std::string); + std::shared_ptr iSWACygnet(std::string name); private: std::vector> _iSWACygnets; - +std::vector> _deletedCygnets; }; }//namespace openspace diff --git a/modules/iswa/rendering/iswacygnet.cpp b/modules/iswa/rendering/iswacygnet.cpp index 17d18f34dd..6ecd8e14e1 100644 --- a/modules/iswa/rendering/iswacygnet.cpp +++ b/modules/iswa/rendering/iswacygnet.cpp @@ -35,6 +35,7 @@ ISWACygnet::ISWACygnet() :_enabled("enabled", "Is Enabled", true) ,_cygnetId("cygnetId", "CygnetID",7, 0, 10) ,_updateInterval("updateInterval", "Update Interval", 3, 1, 10) + ,_delete("delete", "Delete") ,_shader(nullptr) ,_texture(nullptr) ,_frame("GALACTIC") @@ -42,6 +43,9 @@ ISWACygnet::ISWACygnet() addProperty(_enabled); addProperty(_cygnetId); addProperty(_updateInterval); + addProperty(_delete); + + _delete.onChange([this](){ISWAManager::ref().deleteCygnet(name());}); } ISWACygnet::~ISWACygnet(){} @@ -52,6 +56,7 @@ bool ISWACygnet::initialize(){ } bool ISWACygnet::deinitialize(){ + OsEng.gui()._iSWAproperty.unregisterProperties(name()); _parent = nullptr; return true; } @@ -74,9 +79,10 @@ void ISWACygnet::setPscUniforms( } void ISWACygnet::registerProperties(){ - OsEng.gui()._property.registerProperty(&_enabled); - OsEng.gui()._property.registerProperty(&_cygnetId); - OsEng.gui()._property.registerProperty(&_updateInterval); + OsEng.gui()._iSWAproperty.registerProperty(&_enabled); + OsEng.gui()._iSWAproperty.registerProperty(&_cygnetId); + OsEng.gui()._iSWAproperty.registerProperty(&_updateInterval); + OsEng.gui()._iSWAproperty.registerProperty(&_delete); } }//namespace openspac \ No newline at end of file diff --git a/modules/iswa/rendering/iswacygnet.h b/modules/iswa/rendering/iswacygnet.h index 2b2466d092..9a8b288005 100644 --- a/modules/iswa/rendering/iswacygnet.h +++ b/modules/iswa/rendering/iswacygnet.h @@ -33,6 +33,7 @@ #include #include #include +#include #include #include #include @@ -61,6 +62,7 @@ protected: properties::BoolProperty _enabled; properties::IntProperty _cygnetId; properties::FloatProperty _updateInterval; + properties::TriggerProperty _delete; std::unique_ptr _shader; std::unique_ptr _texture; diff --git a/modules/iswa/rendering/screenspacecygnet.cpp b/modules/iswa/rendering/screenspacecygnet.cpp index 9807df3362..ab08b3f27e 100644 --- a/modules/iswa/rendering/screenspacecygnet.cpp +++ b/modules/iswa/rendering/screenspacecygnet.cpp @@ -44,9 +44,16 @@ ScreenSpaceCygnet::ScreenSpaceCygnet(int cygnetId) addProperty(_cygnetId); addProperty(_updateInterval); - registerProperties(); - OsEng.gui()._property.registerProperty(&_cygnetId); - OsEng.gui()._property.registerProperty(&_updateInterval); + // registerProperties(); + OsEng.gui()._iSWAproperty.registerProperty(&_enabled); + OsEng.gui()._iSWAproperty.registerProperty(&_useFlatScreen); + OsEng.gui()._iSWAproperty.registerProperty(&_euclideanPosition); + OsEng.gui()._iSWAproperty.registerProperty(&_sphericalPosition); + OsEng.gui()._iSWAproperty.registerProperty(&_depth); + OsEng.gui()._iSWAproperty.registerProperty(&_scale); + OsEng.gui()._iSWAproperty.registerProperty(&_alpha); + OsEng.gui()._iSWAproperty.registerProperty(&_cygnetId); + OsEng.gui()._iSWAproperty.registerProperty(&_updateInterval); _fileExtension = ""; _path = ""; diff --git a/modules/iswa/util/iswamanager.cpp b/modules/iswa/util/iswamanager.cpp index bc92337c64..f31f59c00d 100644 --- a/modules/iswa/util/iswamanager.cpp +++ b/modules/iswa/util/iswamanager.cpp @@ -28,9 +28,13 @@ #include #include #include +#include + namespace openspace{ - ISWAManager::ISWAManager(){ + ISWAManager::ISWAManager() + :_container(nullptr) + { _month["JAN"] = "01"; _month["FEB"] = "02"; _month["MAR"] = "03"; @@ -102,6 +106,20 @@ namespace openspace{ ); } + void ISWAManager::setContainer(ISWAContainer* container){ + _container = container; + } + + std::shared_ptr ISWAManager::iSWACygnet(std::string name){ + if(_container) + return _container->iSWACygnet(name); + return nullptr; + } + + void ISWAManager::deleteCygnet(std::string name){ + _container->deleteCygnet(name); + } + std::string ISWAManager::iSWAurl(int id){ std::string url = "http://iswa2.ccmc.gsfc.nasa.gov/IswaSystemWebApp/iSWACygnetStreamer?timestamp="; std::string t = Time::ref().currentTimeUTC(); diff --git a/modules/iswa/util/iswamanager.h b/modules/iswa/util/iswamanager.h index 6245a3a664..cc42d59fcb 100644 --- a/modules/iswa/util/iswamanager.h +++ b/modules/iswa/util/iswamanager.h @@ -31,6 +31,7 @@ namespace openspace { class ISWACygnet; +class ISWAContainer; class ISWAManager : public ghoul::Singleton { friend class ghoul::Singleton; @@ -42,9 +43,16 @@ public: DownloadManager::FileFuture* downloadImage(int, std::string); void downloadData(); void fileExtension(int, std::string*); + + void setContainer(ISWAContainer*); + std::shared_ptr iSWACygnet(std::string); + void deleteCygnet(ISWACygnet*); + void deleteCygnet(std::string); private: std::string iSWAurl(int); + std::map _month; + ISWAContainer* _container; }; } //namespace openspace diff --git a/modules/onscreengui/include/gui.h b/modules/onscreengui/include/gui.h index ee3144ceb8..8e9b6a4403 100644 --- a/modules/onscreengui/include/gui.h +++ b/modules/onscreengui/include/gui.h @@ -71,6 +71,7 @@ public: GuiOriginComponent _origin; GuiPerformanceComponent _performance; GuiPropertyComponent _property; + GuiPropertyComponent _iSWAproperty; GuiTimeComponent _time; bool _isEnabled; diff --git a/modules/onscreengui/include/guipropertycomponent.h b/modules/onscreengui/include/guipropertycomponent.h index 8a54c0c591..2fcb94303a 100644 --- a/modules/onscreengui/include/guipropertycomponent.h +++ b/modules/onscreengui/include/guipropertycomponent.h @@ -44,6 +44,7 @@ class GuiPropertyComponent : public GuiComponent { public: //void registerProperty(const std::string& propertyDescription); void registerProperty(properties::Property* prop); + void unregisterProperties(std::string owner); void render(); protected: diff --git a/modules/onscreengui/src/gui.cpp b/modules/onscreengui/src/gui.cpp index 9ac7074d63..3a83c4f078 100644 --- a/modules/onscreengui/src/gui.cpp +++ b/modules/onscreengui/src/gui.cpp @@ -203,6 +203,7 @@ void GUI::initialize() { //io.GetClipboardTextFn = ImImpl_GetClipboardTextFn; // @TODO implement? ---abock _property.initialize(); + _iSWAproperty.initialize(); _performance.initialize(); _help.initialize(); } @@ -249,6 +250,7 @@ void GUI::initializeGL() { _property.initializeGL(); + _iSWAproperty.initializeGL(); _performance.initializeGL(); _help.initializeGL(); } @@ -260,6 +262,7 @@ void GUI::deinitializeGL() { glDeleteBuffers(1, &vbo); _property.deinitializeGL(); + _iSWAproperty.deinitializeGL(); _performance.deinitializeGL(); _help.deinitializeGL(); } @@ -288,6 +291,8 @@ void GUI::endFrame() { if (_property.isEnabled()) _property.render(); + if (_iSWAproperty.isEnabled()) + _iSWAproperty.render(); if (_performance.isEnabled()) _performance.render(); if (_help.isEnabled()) @@ -387,6 +392,7 @@ void GUI::renderMainWindow() { ImGui::Begin("OpenSpace GUI", nullptr); ImGui::Checkbox("Properties", &_property._isEnabled); + ImGui::Checkbox("iSWA Properties", &_iSWAproperty._isEnabled); ImGui::Checkbox("Performance", &_performance._isEnabled); _origin.render(); _time.render(); diff --git a/modules/onscreengui/src/guipropertycomponent.cpp b/modules/onscreengui/src/guipropertycomponent.cpp index bf006eb507..05e853aec1 100644 --- a/modules/onscreengui/src/guipropertycomponent.cpp +++ b/modules/onscreengui/src/guipropertycomponent.cpp @@ -195,7 +195,7 @@ namespace { std::string name = prop->guiName(); bool pressed = ImGui::Button((ownerName + "." + name).c_str()); if (pressed) - executeScript(prop->fullyQualifiedIdentifier(), "0"); + executeScript(prop->fullyQualifiedIdentifier(), "nil"); } //void renderBoolProperty(Property* prop, const std::string& ownerName) { @@ -383,6 +383,37 @@ void GuiPropertyComponent::registerProperty(properties::Property* prop) { //handleProperty(dictionary); } +void GuiPropertyComponent::unregisterProperties(std::string owner){ + auto it = _propertiesByOwner.find(owner); + if(it != _propertiesByOwner.end()){ + for(prop : it->second){ + std::string className = prop->className(); + if (className == "BoolProperty") + _boolProperties.insert(prop); + else if (className == "IntProperty") + _intProperties.insert(prop); + else if (className == "FloatProperty") + _floatProperties.insert(prop); + else if (className == "StringProperty") + _stringProperties.insert(prop); + else if (className == "Vec2Property") + _vec2Properties.insert(prop); + else if (className == "Vec3Property") + _vec3Properties.insert(prop); + else if (className == "Vec4Property") + _vec4Properties.insert(prop); + else if (className == "OptionProperty") + _optionProperties.insert(prop); + else if (className == "TriggerProperty") + _triggerProperties.insert(prop); + else if (className == "SelectionProperty") + _selectionProperties.insert(prop); + } + it->second.clear(); + _propertiesByOwner.erase(it); + } +} + void GuiPropertyComponent::handleProperty(const ghoul::Dictionary& dictionary) { //static const std::string TypeKey = "Type"; //static const std::string IdentifierKey = "Identifier";