From 581002175c0040b9552c530e59b33572544f3ea3 Mon Sep 17 00:00:00 2001 From: Sebastian Piwell Date: Thu, 12 May 2016 18:49:16 -0400 Subject: [PATCH] IswaManager loads cygnet info --- data/scene/default.scene | 4 +- modules/iswa/rendering/screenspacecygnet.cpp | 20 +----- modules/iswa/rendering/screenspacecygnet.h | 1 - modules/iswa/util/iswamanager.cpp | 70 +++++++++++++------ modules/iswa/util/iswamanager.h | 18 ++++- modules/iswa/util/iswamanager_lua.inl | 11 +-- .../onscreengui/include/guiiswacomponent.h | 19 +---- modules/onscreengui/src/guiiswacomponent.cpp | 63 ++++++----------- 8 files changed, 93 insertions(+), 113 deletions(-) diff --git a/data/scene/default.scene b/data/scene/default.scene index 53b597dcb1..8ee52e9ea9 100644 --- a/data/scene/default.scene +++ b/data/scene/default.scene @@ -34,10 +34,10 @@ function postInitialization() --openspace.iswa.addCygnet("-1,Data,1"); --openspace.iswa.addCygnet("-2,Data,1"); --openspace.iswa.addCygnet("-3,Data,1"); + + openspace.iswa.addScreenSpaceCygnet(7); --[[ - openspace.registerScreenSpaceRenderable( { - Name = "iSWACygnet7", Type = "ScreenSpaceCygnet", CygnetId = 7, Position = {0.0, 0.0}, diff --git a/modules/iswa/rendering/screenspacecygnet.cpp b/modules/iswa/rendering/screenspacecygnet.cpp index 3adbcae553..bb8e5d6c92 100644 --- a/modules/iswa/rendering/screenspacecygnet.cpp +++ b/modules/iswa/rendering/screenspacecygnet.cpp @@ -46,18 +46,8 @@ ScreenSpaceCygnet::ScreenSpaceCygnet(const ghoul::Dictionary& dictionary) float interval; dictionary.getValue("UpdateInterval", interval); _updateTime = (int) interval; - // setName("iSWACygnet" + std::to_string(_cygnetId)); - // addProperty(_updateInterval); - - _updateRealWorldTime = (_updateTime == 0); - if(_updateRealWorldTime){ - _minRealTimeUpdateInterval = 1000; - }else{ - _minRealTimeUpdateInterval = 100; - } _downloadImage = true; - _url = IswaManager::ref().iswaUrl(_cygnetId); _openSpaceTime = Time::ref().currentTime(); @@ -65,6 +55,7 @@ ScreenSpaceCygnet::ScreenSpaceCygnet(const ghoul::Dictionary& dictionary) _realTime = std::chrono::duration_cast(std::chrono::system_clock::now().time_since_epoch()); _lastUpdateRealTime = _realTime; + _minRealTimeUpdateInterval = 100; } @@ -74,15 +65,8 @@ void ScreenSpaceCygnet::update(){ _openSpaceTime = Time::ref().currentTime(); _realTime = std::chrono::duration_cast(std::chrono::system_clock::now().time_since_epoch()); - bool timeToUpdate; - - if(_updateRealWorldTime){ - timeToUpdate = (((_realTime.count()-_lastUpdateRealTime.count()) > _minRealTimeUpdateInterval) && - Time::ref().deltaTime() != 0); - }else{ - timeToUpdate = (fabs(_openSpaceTime-_lastUpdateOpenSpaceTime) >= _updateTime && + bool timeToUpdate = (fabs(_openSpaceTime-_lastUpdateOpenSpaceTime) >= _updateTime && (_realTime.count()-_lastUpdateRealTime.count()) > _minRealTimeUpdateInterval); - } if((Time::ref().timeJumped() || timeToUpdate )){ _url = IswaManager::ref().iswaUrl(_cygnetId); diff --git a/modules/iswa/rendering/screenspacecygnet.h b/modules/iswa/rendering/screenspacecygnet.h index f8eaf938f3..55166c5517 100644 --- a/modules/iswa/rendering/screenspacecygnet.h +++ b/modules/iswa/rendering/screenspacecygnet.h @@ -54,7 +54,6 @@ private: std::chrono::milliseconds _realTime; std::chrono::milliseconds _lastUpdateRealTime; int _minRealTimeUpdateInterval; - bool _updateRealWorldTime; }; } // namespace openspace diff --git a/modules/iswa/util/iswamanager.cpp b/modules/iswa/util/iswamanager.cpp index 3248edfff5..3b3f381743 100644 --- a/modules/iswa/util/iswamanager.cpp +++ b/modules/iswa/util/iswamanager.cpp @@ -72,22 +72,15 @@ IswaManager::IswaManager() _geom[CygnetGeometry::Plane] = "Plane"; _geom[CygnetGeometry::Sphere] = "Sphere"; - // setName("IswaManager"); - // addProperty(_iswaNames); - // OsEng.gui()._iswa.registerProperty(&_iswaNames); - - // _iswaNames.addOption({7, std::string("Red Sun")}); - // _iswaNames.addOption({6, std::string("Yellow Sun")}); - // _iswaNames.addOption({5, std::string("Green Sun")}); - // _iswaNames.addOption({4, std::string("Blue Sun")}); - - // _iswaNames.onChange([this]{ - // for(auto v : _iswaNames.value()){ - // std::cout << v << " "; - // } - // std::cout << std::endl; - // // std::cout << std::to_string(_iswaNames.value()) << std::endl; - // }); + DlManager.fetchFile( + "http://iswa2.ccmc.gsfc.nasa.gov/IswaSystemWebApp/CygnetHealthServlet", + [this](const DownloadManager::MemoryFile& file){ + fillCygnetInfo(std::string(file.buffer)); + }, + [](const std::string& err){ + LWARNING("Download to memory was aborted: " + err); + } + ); } @@ -186,8 +179,13 @@ void IswaManager::deleteIswaCygnet(std::string name){ OsEng.scriptEngine().queueScript("openspace.removeSceneGraphNode('" + name + "')"); } -void IswaManager::deleteScreenSpaceCygnet(std::string name){ - std::string script = "openspace.unregisterScreenSpaceRenderable('" + name + "');"; +void IswaManager::deleteScreenSpaceCygnet(int id){ + if(_cygnetInformation.find(id) == _cygnetInformation.end()){ + LWARNING("Could not find Cygnet with id = " + std::to_string(id)); + return; + } + + std::string script = "openspace.unregisterScreenSpaceRenderable('" + _cygnetInformation[id]->name + "');"; OsEng.scriptEngine().queueScript(script); } @@ -289,9 +287,16 @@ std::shared_ptr IswaManager::downloadMetadata(int id){ return metaFuture; } -void IswaManager::createScreenSpace(int id, std::string name, int updateInterval){ - if(name == "") - name = "iSWACygnet" + std::to_string(id); +void IswaManager::createScreenSpace(int id){ + if(_cygnetInformation.find(id) == _cygnetInformation.end()){ + LWARNING("Could not find Cygnet with id = " + std::to_string(id)); + return; + } + + auto info = _cygnetInformation[id]; + std::string name = info->name; + int updateInterval = info->updateInterval; + info->selected = true; if(OsEng.renderEngine().screenSpaceRenderable(name)){ LERROR("A cygnet with the name \"" + name +"\" already exist"); @@ -491,6 +496,25 @@ std::shared_ptr IswaManager::iswaGroup(std::string name){ return nullptr; } +void IswaManager::fillCygnetInfo(std::string jsonString){ + if(jsonString != ""){ + json j = json::parse(jsonString); + + json jCygnets = j["listOfPriorityCygnets"]; + for(int i=0; i(info); + } + } +} + scripting::ScriptEngine::LuaLibrary IswaManager::luaLibrary() { return { "iswa", @@ -505,7 +529,7 @@ scripting::ScriptEngine::LuaLibrary IswaManager::luaLibrary() { { "addScreenSpaceCygnet", &luascriptfunctions::iswa_addScreenSpaceCygnet, - "int, string", + "int", "Adds a Screen Space Cygnets", true }, @@ -519,7 +543,7 @@ scripting::ScriptEngine::LuaLibrary IswaManager::luaLibrary() { { "removeScreenSpaceCygnet", &luascriptfunctions::iswa_removeScrenSpaceCygnet, - "string", + "int", "Remove a Screen Space Cygnets", true }, diff --git a/modules/iswa/util/iswamanager.h b/modules/iswa/util/iswamanager.h index c91c54974e..12b76630b1 100644 --- a/modules/iswa/util/iswamanager.h +++ b/modules/iswa/util/iswamanager.h @@ -47,6 +47,12 @@ namespace openspace { class IswaGroup; class IswaCygnet; +struct CygnetInfo { + std::string name; + std::string description; + int updateInterval; + bool selected; +}; struct MetadataFuture { int id; @@ -72,7 +78,7 @@ public: void addIswaCygnet(std::string info); void addIswaCygnet(int id, std::string info = "Texture", int group = -1); void deleteIswaCygnet(std::string); - void deleteScreenSpaceCygnet(std::string name); + void deleteScreenSpaceCygnet(int id); std::shared_ptr downloadImageToMemory(int id, std::string& buffer); std::shared_ptr downloadDataToMemory(int id, std::string& buffer); @@ -90,7 +96,12 @@ public: static scripting::ScriptEngine::LuaLibrary luaLibrary(); std::string iswaUrl(int id, std::string type = "image"); - void createScreenSpace(int id, std::string name = "", int updateInterval = 0); + void createScreenSpace(int id); + + std::map>& cygnetInformation(){ + return _cygnetInformation; + } + private: std::shared_ptr downloadMetadata(int id); @@ -100,6 +111,8 @@ private: void createKameleonPlane(std::string kwPath, int group = -1); std::string parseKWToLuaTable(std::string kwPath, int group); + void fillCygnetInfo(std::string jsonString); + std::map _month; std::map _type; std::map _geom; @@ -109,6 +122,7 @@ private: std::shared_ptr _kameleon; std::set _kameleonFrames; + std::map> _cygnetInformation; // properties::SelectionProperty _iswaNames; }; diff --git a/modules/iswa/util/iswamanager_lua.inl b/modules/iswa/util/iswamanager_lua.inl index d480718b85..47a0760edd 100644 --- a/modules/iswa/util/iswamanager_lua.inl +++ b/modules/iswa/util/iswamanager_lua.inl @@ -34,12 +34,7 @@ int iswa_addCygnet(lua_State* L) { int iswa_addScreenSpaceCygnet(lua_State* L){ int id = lua_tonumber(L, 1); - std::string name = luaL_checkstring(L, 2); - int interval = lua_tonumber(L, 3); - - std::cout << id << " " << name << " " << interval << std::endl; - - IswaManager::ref().createScreenSpace(id,name, interval); + IswaManager::ref().createScreenSpace(id); } int iswa_removeCygnet(lua_State* L){ @@ -49,8 +44,8 @@ int iswa_removeCygnet(lua_State* L){ } int iswa_removeScrenSpaceCygnet(lua_State* L){ - std::string s = luaL_checkstring(L, -1); - IswaManager::ref().deleteScreenSpaceCygnet(s); + int id = lua_tonumber(L, 1); + IswaManager::ref().deleteScreenSpaceCygnet(id); return 0; } diff --git a/modules/onscreengui/include/guiiswacomponent.h b/modules/onscreengui/include/guiiswacomponent.h index 64ba5f5004..c5968ef03d 100644 --- a/modules/onscreengui/include/guiiswacomponent.h +++ b/modules/onscreengui/include/guiiswacomponent.h @@ -31,28 +31,15 @@ namespace openspace { namespace gui { -struct Option { - int id; - std::string name; - std::string description; - int updateInterval; - bool selected; -}; - class GuiIswaComponent : public GuiPropertyComponent { public: - virtual void initialize() override; virtual void render() override; private: - void fillOptions(std::string jsonString); - - bool gmdata; - bool gmimage; - bool iondata; - - std::vector