IswaManager loads cygnet info

This commit is contained in:
Sebastian Piwell
2016-05-12 18:49:16 -04:00
parent 03de689de3
commit 581002175c
8 changed files with 93 additions and 113 deletions
+2 -2
View File
@@ -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},
+2 -18
View File
@@ -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::milliseconds>(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::milliseconds>(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);
@@ -54,7 +54,6 @@ private:
std::chrono::milliseconds _realTime;
std::chrono::milliseconds _lastUpdateRealTime;
int _minRealTimeUpdateInterval;
bool _updateRealWorldTime;
};
} // namespace openspace
+47 -23
View File
@@ -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<MetadataFuture> 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<IswaGroup> 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<jCygnets.size(); i++){
json jCygnet = jCygnets.at(i);
CygnetInfo info = {
jCygnet["cygnetDisplayTitle"],
jCygnet["cygnetDescription"],
jCygnet["cygnetUpdateInterval"],
false
};
_cygnetInformation[jCygnet["cygnetID"]] = std::make_shared<CygnetInfo>(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
},
+16 -2
View File
@@ -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<DownloadManager::FileFuture> downloadImageToMemory(int id, std::string& buffer);
std::shared_ptr<DownloadManager::FileFuture> 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<int, std::shared_ptr<CygnetInfo>>& cygnetInformation(){
return _cygnetInformation;
}
private:
std::shared_ptr<MetadataFuture> 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<std::string, std::string> _month;
std::map<int, std::string> _type;
std::map<int, std::string> _geom;
@@ -109,6 +122,7 @@ private:
std::shared_ptr<ccmc::Kameleon> _kameleon;
std::set<std::string> _kameleonFrames;
std::map<int, std::shared_ptr<CygnetInfo>> _cygnetInformation;
// properties::SelectionProperty _iswaNames;
};
+3 -8
View File
@@ -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;
}
+3 -16
View File
@@ -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<Option> options;
bool gmdata;
bool gmimage;
bool iondata;
};
+20 -43
View File
@@ -40,6 +40,8 @@
#include <ext/json/json.hpp>
#include <openspace/engine/downloadmanager.h>
#include <modules/iswa/util/iswamanager.h>
#include <fstream>
@@ -210,18 +212,6 @@ namespace {
namespace openspace {
namespace gui {
void GuiIswaComponent::initialize(){
DlManager.fetchFile(
"http://iswa2.ccmc.gsfc.nasa.gov/IswaSystemWebApp/CygnetHealthServlet",
[this](const DownloadManager::MemoryFile& file){
fillOptions(std::string(file.buffer));
},
[](const std::string& err){
LWARNING("Download to memory was aborted: " + err);
}
);
}
void GuiIswaComponent::render() {
bool gmdatavalue = gmdata;
bool gmimagevalue = gmimage;
@@ -330,49 +320,36 @@ void GuiIswaComponent::render() {
}
if (ImGui::CollapsingHeader("iSWA screen space cygntes")) {
for (int i = 0; i < options.size(); ++i) {
// std::string name = options[i].name;
bool selected = options[i].selected;//std::find(selectedIndices.begin(), selectedIndices.end(), i) != selectedIndices.end();
ImGui::Checkbox(options[i].name.c_str(), &options[i].selected);
if (ImGui::CollapsingHeader("iSWA screen space cygntes")) {
auto map = IswaManager::ref().cygnetInformation();
for(auto cygnetInfo : map){
int id = cygnetInfo.first;
auto info = cygnetInfo.second;
bool selected = info->selected;
ImGui::Checkbox(info->name.c_str(), &info->selected);
ImGui::SameLine();
if (ImGui::CollapsingHeader(("Description" + std::to_string(options[i].id)).c_str())) {
ImGui::TextWrapped(options[i].description.c_str());
if(ImGui::CollapsingHeader(("Description" + std::to_string(id)).c_str())){
ImGui::TextWrapped(info->description.c_str());
ImGui::Spacing();
}
if(selected != options[i].selected){
if(options[i].selected){
std::string arguments = std::to_string(options[i].id) + ", '" + options[i].name + "'," + std::to_string(options[i].updateInterval);
OsEng.scriptEngine().queueScript("openspace.iswa.addScreenSpaceCygnet("+arguments+");");
if(selected != info->selected){
if(info->selected){
OsEng.scriptEngine().queueScript("openspace.iswa.addScreenSpaceCygnet("+std::to_string(id)+");");
}else{
OsEng.scriptEngine().queueScript("openspace.iswa.removeScreenSpaceCygnet('"+options[i].name+"');");
OsEng.scriptEngine().queueScript("openspace.iswa.removeScreenSpaceCygnet("+std::to_string(id)+");");
}
}
}
}
ImGui::End();
}
void GuiIswaComponent::fillOptions(std::string jsonString){
if(jsonString != ""){
json j = json::parse(jsonString);
json jCygnets = j["listOfPriorityCygnets"];
for(int i=0; i<jCygnets.size(); i++){
json jCygnet = jCygnets.at(i);
// std::cout << jCygnets.at(i) << std::endl;
options.push_back({
jCygnet["cygnetID"],
jCygnet["cygnetDisplayTitle"],
jCygnet["cygnetDescription"],
jCygnet["cygnetUpdateInterval"],
false
});
}
}
}
} // gui
} // openspace