From dfd1968f0b85869befb9f0462e47857d9d74033d Mon Sep 17 00:00:00 2001 From: Sebastian Piwell Date: Tue, 3 May 2016 13:24:17 -0400 Subject: [PATCH] Lua script to add cygnet --- modules/iswa/rendering/iswacontainer.cpp | 37 +- modules/iswa/util/iswamanager.cpp | 614 ++++++++++++----------- modules/iswa/util/iswamanager.h | 4 + modules/iswa/util/iswamanager_lua.inl | 39 ++ modules/onscreengui/src/gui.cpp | 2 +- openspace.cfg | 3 +- scripts/iswa_startup.lua | 6 + src/engine/openspaceengine.cpp | 12 + 8 files changed, 401 insertions(+), 316 deletions(-) create mode 100644 modules/iswa/util/iswamanager_lua.inl create mode 100644 scripts/iswa_startup.lua diff --git a/modules/iswa/rendering/iswacontainer.cpp b/modules/iswa/rendering/iswacontainer.cpp index bd81deac09..b5bf1ea6a8 100644 --- a/modules/iswa/rendering/iswacontainer.cpp +++ b/modules/iswa/rendering/iswacontainer.cpp @@ -42,27 +42,26 @@ namespace openspace{ ISWAContainer::ISWAContainer(const ghoul::Dictionary& dictionary) :Renderable(dictionary) { - ISWAManager::initialize(); - std::string textureCygnets; - std::string dataCygnets; - dictionary.getValue("TextureCygnets", textureCygnets); - dictionary.getValue("DataCygnets", dataCygnets); - std::cout << textureCygnets << std::endl; - std::cout << dataCygnets << std::endl; + // std::string textureCygnets; + // std::string dataCygnets; + // dictionary.getValue("TextureCygnets", textureCygnets); + // dictionary.getValue("DataCygnets", dataCygnets); + // std::cout << textureCygnets << std::endl; + // std::cout << dataCygnets << std::endl; - if(textureCygnets != ""){ - json j = json::parse(textureCygnets); - for (auto& id : j) { - ISWAManager::ref().addISWACygnet(id, "TEXTURE"); - } - } + // if(textureCygnets != ""){ + // json j = json::parse(textureCygnets); + // for (auto& id : j) { + // ISWAManager::ref().addISWACygnet(id, "TEXTURE"); + // } + // } - if(dataCygnets != ""){ - json j = json::parse(dataCygnets); - for (auto& id : j) { - ISWAManager::ref().addISWACygnet(id, "DATA"); - } - } + // if(dataCygnets != ""){ + // json j = json::parse(dataCygnets); + // for (auto& id : j) { + // ISWAManager::ref().addISWACygnet(id, "DATA"); + // } + // } } ISWAContainer::~ISWAContainer(){} diff --git a/modules/iswa/util/iswamanager.cpp b/modules/iswa/util/iswamanager.cpp index e0ef850474..b59d2e066b 100644 --- a/modules/iswa/util/iswamanager.cpp +++ b/modules/iswa/util/iswamanager.cpp @@ -32,359 +32,383 @@ #include #include #include +#include +#include +#include +#include #include #include +#include "iswamanager_lua.inl"; + namespace { using json = nlohmann::json; const std::string _loggerCat = "ISWAManager"; } namespace openspace{ - ISWAManager::ISWAManager() - { - _month["JAN"] = "01"; - _month["FEB"] = "02"; - _month["MAR"] = "03"; - _month["APR"] = "04"; - _month["MAY"] = "05"; - _month["JUN"] = "06"; - _month["JUL"] = "07"; - _month["AUG"] = "08"; - _month["SEP"] = "09"; - _month["OCT"] = "10"; - _month["NOV"] = "11"; - _month["DEC"] = "12"; - _type[CygnetType::Texture] = "Texture"; - _type[CygnetType::Data] = "Data"; - _type[CygnetType::Kameleon] = "Kameleon"; +ISWAManager::ISWAManager() +{ + _month["JAN"] = "01"; + _month["FEB"] = "02"; + _month["MAR"] = "03"; + _month["APR"] = "04"; + _month["MAY"] = "05"; + _month["JUN"] = "06"; + _month["JUL"] = "07"; + _month["AUG"] = "08"; + _month["SEP"] = "09"; + _month["OCT"] = "10"; + _month["NOV"] = "11"; + _month["DEC"] = "12"; - _geom[CygnetGeometry::Plane] = "Plane"; - _geom[CygnetGeometry::Sphere] = "Sphere"; - } + _type[CygnetType::Texture] = "Texture"; + _type[CygnetType::Data] = "Data"; + _type[CygnetType::Kameleon] = "Kameleon"; - ISWAManager::~ISWAManager(){} + _geom[CygnetGeometry::Plane] = "Plane"; + _geom[CygnetGeometry::Sphere] = "Sphere"; +} - void ISWAManager::addISWACygnet(std::string info){ - std::string token; - std::stringstream ss(info); +ISWAManager::~ISWAManager(){} + +void ISWAManager::addISWACygnet(std::string info){ + std::string token; + std::stringstream ss(info); + getline(ss,token,','); + int cygnetId = std::stoi(token); + + if(!ss.eof()){ getline(ss,token,','); - int cygnetId = std::stoi(token); + std::string data = token; if(!ss.eof()){ - getline(ss,token,','); - std::string data = token; - - if(!ss.eof()){ - getline(ss, token, ','); - int group = std::stoi(token); - addISWACygnet(cygnetId, data, group); - return; - } - - addISWACygnet(cygnetId, data); + getline(ss, token, ','); + int group = std::stoi(token); + addISWACygnet(cygnetId, data, group); return; - } + } - addISWACygnet(cygnetId); + addISWACygnet(cygnetId, data); + return; + } + + addISWACygnet(cygnetId); + + /*if(data == "") + else*/ - /*if(data == "") - else*/ - - } +} - void ISWAManager::addISWACygnet(int id, std::string info, int group){ - if(id > 0){ - createScreenSpace(id); - }else if(id < 0){ - //download metadata to texture plane - std::shared_ptr metadataFuture = downloadMetadata(id); - metadataFuture->guiType = info; - metadataFuture->id = id; - metadataFuture->group = group; - _metadataFutures.push_back(metadataFuture); - }else{ - //create kameleonplane - createKameleonPlane(info); - } - } +void ISWAManager::addISWACygnet(int id, std::string info, int group){ + if(id > 0){ + createScreenSpace(id); + }else if(id < 0){ + //download metadata to texture plane + std::shared_ptr metadataFuture = downloadMetadata(id); + metadataFuture->guiType = info; + metadataFuture->id = id; + metadataFuture->group = group; + _metadataFutures.push_back(metadataFuture); + }else{ + //create kameleonplane + createKameleonPlane(info); + } +} - void ISWAManager::deleteISWACygnet(std::string name){ - OsEng.scriptEngine().queueScript("openspace.removeSceneGraphNode('" + name + "')"); - } +void ISWAManager::deleteISWACygnet(std::string name){ + OsEng.scriptEngine().queueScript("openspace.removeSceneGraphNode('" + name + "')"); +} - // std::shared_ptr ISWAManager::downloadImage(int id, std::string path){ - // return DlManager.downloadFile( - // iSWAurl(id), - // path, - // true, - // [path](const DownloadManager::FileFuture& f){ - // LDEBUG("Download finished: " << path); - // } - // ); - // } +// std::shared_ptr ISWAManager::downloadImage(int id, std::string path){ +// return DlManager.downloadFile( +// iSWAurl(id), +// path, +// true, +// [path](const DownloadManager::FileFuture& f){ +// LDEBUG("Download finished: " << path); +// } +// ); +// } - std::shared_ptr ISWAManager::downloadImageToMemory(int id, std::string& buffer){ - return DlManager.downloadToMemory( - iSWAurl(id, "image"), - buffer, - [](const DownloadManager::FileFuture& f){ - LDEBUG("Download to memory finished"); - } - ); - } - - std::shared_ptr ISWAManager::downloadDataToMemory(int id, std::string& buffer){ - return DlManager.downloadToMemory( - iSWAurl(id, "data"), - buffer, - [](const DownloadManager::FileFuture& f){ - LDEBUG("Download data finished"); - } - ); - } - - void ISWAManager::update(){ - for (auto it = _metadataFutures.begin(); it != _metadataFutures.end(); ){ - if((*it)->isFinished) { - if((*it)->guiType == "TEXTURE"){ - (*it)->type = CygnetType::Texture; - (*it)->geom = CygnetGeometry::Plane; - // (*it)->group = -1; - }else if ((*it)->guiType == "DATA"){ - (*it)->type = CygnetType::Data; - (*it)->geom = CygnetGeometry::Plane; - // (*it)->group = 1; - } else { - LERROR("\""+ (*it)->guiType + "\" is not a valid type"); - return; - } - createPlane((*it)); - it = _metadataFutures.erase( it ); - }else{ - ++it; +std::shared_ptr ISWAManager::downloadImageToMemory(int id, std::string& buffer){ + return DlManager.downloadToMemory( + iSWAurl(id, "image"), + buffer, + [](const DownloadManager::FileFuture& f){ + LDEBUG("Download to memory finished"); } - } + ); +} + +std::shared_ptr ISWAManager::downloadDataToMemory(int id, std::string& buffer){ + return DlManager.downloadToMemory( + iSWAurl(id, "data"), + buffer, + [](const DownloadManager::FileFuture& f){ + LDEBUG("Download data finished"); + } + ); +} + +void ISWAManager::update(){ + for (auto it = _metadataFutures.begin(); it != _metadataFutures.end(); ){ + if((*it)->isFinished) { + if((*it)->guiType == "TEXTURE"){ + (*it)->type = CygnetType::Texture; + (*it)->geom = CygnetGeometry::Plane; + // (*it)->group = -1; + }else if ((*it)->guiType == "DATA"){ + (*it)->type = CygnetType::Data; + (*it)->geom = CygnetGeometry::Plane; + // (*it)->group = 1; + } else { + LERROR("\""+ (*it)->guiType + "\" is not a valid type"); + return; + } + createPlane((*it)); + it = _metadataFutures.erase( it ); + }else{ + ++it; + } + } +} + +std::string ISWAManager::iSWAurl(int id, std::string type){ + std::string url; + if(id < 0){ + url = "http://128.183.168.116:3000/"+type+"/" + std::to_string(-id) + "/"; + // url = "http://10.0.0.76:3000/"+type+"/" + std::to_string(-id) + "/"; + } else{ + url = "http://iswa2.ccmc.gsfc.nasa.gov/IswaSystemWebApp/iSWACygnetStreamer?window=-1&cygnetId="+ std::to_string(id) +"×tamp="; + } + + std::string t = Time::ref().currentTimeUTC(); + std::stringstream ss(t); + std::string token; + + std::getline(ss, token, ' '); + url += token + "-"; + std::getline(ss, token, ' '); + url += _month[token] + "-"; + std::getline(ss, token, 'T'); + url += token + "%20"; + std::getline(ss, token, '.'); + url += token; + + return url; +} + +std::shared_ptr ISWAManager::downloadMetadata(int id){ + std::shared_ptr metaFuture = std::make_shared(); + + metaFuture->id = id; + DlManager.downloadToMemory( + "http://128.183.168.116:3000/" + std::to_string(-id), + // "http://10.0.0.76:3000/" + std::to_string(-id), + metaFuture->json, + [metaFuture](const DownloadManager::FileFuture& f){ + LDEBUG("Download to memory finished"); + metaFuture->isFinished = true; + } + ); + return metaFuture; +} + +void ISWAManager::createScreenSpace(int id){ + OsEng.renderEngine().registerScreenSpaceRenderable(std::make_shared(id)); +} + +void ISWAManager::createPlane(std::shared_ptr data){ + // check if this plane already exist + std::string name = _type[data->type] + _geom[data->geom] + std::to_string(data->id); + if(data->group > 0) + name += "_Group" + std::to_string(data->group); + + data->name = name; + + if( OsEng.renderEngine().scene()->sceneGraphNode(name) ){ + LERROR("A node with name \"" + name +"\" already exist"); + return; } - std::string ISWAManager::iSWAurl(int id, std::string type){ - std::string url; - if(id < 0){ - url = "http://128.183.168.116:3000/"+type+"/" + std::to_string(-id) + "/"; - // url = "http://10.0.0.76:3000/"+type+"/" + std::to_string(-id) + "/"; - } else{ - url = "http://iswa2.ccmc.gsfc.nasa.gov/IswaSystemWebApp/iSWACygnetStreamer?window=-1&cygnetId="+ std::to_string(id) +"×tamp="; - } - - std::string t = Time::ref().currentTimeUTC(); - std::stringstream ss(t); - std::string token; - - std::getline(ss, token, ' '); - url += token + "-"; - std::getline(ss, token, ' '); - url += _month[token] + "-"; - std::getline(ss, token, 'T'); - url += token + "%20"; - std::getline(ss, token, '.'); - url += token; - - return url; + std::string luaTable = parseJSONToLuaTable(data); + if(luaTable != ""){ + std::string script = "openspace.addSceneGraphNode(" + luaTable + ");"; + OsEng.scriptEngine().queueScript(script); } +} - std::shared_ptr ISWAManager::downloadMetadata(int id){ - std::shared_ptr metaFuture = std::make_shared(); +std::string ISWAManager::parseJSONToLuaTable(std::shared_ptr data){ + if(data->json != ""){ + json j = json::parse(data->json); - metaFuture->id = id; - DlManager.downloadToMemory( - "http://128.183.168.116:3000/" + std::to_string(-id), - // "http://10.0.0.76:3000/" + std::to_string(-id), - metaFuture->json, - [metaFuture](const DownloadManager::FileFuture& f){ - LDEBUG("Download to memory finished"); - metaFuture->isFinished = true; - } - ); - return metaFuture; - } + std::string parent = j["Central Body"]; + std::string frame = j["Coordinates"]; + std::string coordinateType = j["Coordinate Type"]; + int updateTime = j["ISWA_UPDATE_SECONDS"]; - void ISWAManager::createScreenSpace(int id){ - OsEng.renderEngine().registerScreenSpaceRenderable(std::make_shared(id)); - } + glm::vec3 max( + j["Plot XMAX"], + j["Plot YMAX"], + j["Plot ZMAX"] + ); - void ISWAManager::createPlane(std::shared_ptr data){ - // check if this plane already exist - std::string name = _type[data->type] + _geom[data->geom] + std::to_string(data->id); - if(data->group > 0) - name += "_Group" + std::to_string(data->group); + glm::vec3 min( + j["Plot XMIN"], + j["Plot YMIN"], + j["Plot ZMIN"] + ); - data->name = name; - - if( OsEng.renderEngine().scene()->sceneGraphNode(name) ){ - LERROR("A node with name \"" + name +"\" already exist"); - return; + glm::vec4 spatialScale(1, 1, 1, 10); + std::string spatial = j["Spatial Scale (Custom)"]; + if(spatial == "R_E"){ + spatialScale.x = 6.371f; + spatialScale.y = 6.371f; + spatialScale.z = 6.371f; + spatialScale.w = 6; } - std::string luaTable = parseJSONToLuaTable(data); - if(luaTable != ""){ + + std::string table = "{" + "Name = '" + data->name +"' , " + "Parent = '" + parent + "', " + "Renderable = {" + "Type = '" + _type[data->type] + _geom[data->geom] + "', " + "Id = " + std::to_string(data->id) + ", " + "Frame = '" + frame + "' , " + "GridMin = " + std::to_string(min) + ", " + "GridMax = " + std::to_string(max) + ", " + "SpatialScale = " + std::to_string(spatialScale) + ", " + "UpdateTime = " + std::to_string(updateTime) + ", " + "CoordinateType = '" + coordinateType + "', " + "Group = "+ std::to_string(data->group) + " ," + "}" + "}"; + + return table; + } + return ""; +} + +void ISWAManager::createKameleonPlane(std::string kwPath, int group){ + kwPath = "${OPENSPACE_DATA}/" + kwPath; + const std::string& extension = ghoul::filesystem::File(absPath(kwPath)).fileExtension(); + + if(FileSys.fileExists(absPath(kwPath)) && extension == "cdf"){ + std::string luaTable = parseKWToLuaTable(kwPath, group); + if(!luaTable.empty()){ + std::cout << luaTable << std::endl; std::string script = "openspace.addSceneGraphNode(" + luaTable + ");"; OsEng.scriptEngine().queueScript(script); } + }else{ + LWARNING( kwPath + " is not a cdf file or can't be found."); } +} - std::string ISWAManager::parseJSONToLuaTable(std::shared_ptr data){ - if(data->json != ""){ - json j = json::parse(data->json); +std::string ISWAManager::parseKWToLuaTable(std::string kwPath, int group){ + if(kwPath != ""){ + const std::string& extension = ghoul::filesystem::File(absPath(kwPath)).fileExtension(); + if(extension == "cdf"){ + KameleonWrapper kw = KameleonWrapper(absPath(kwPath)); + + std::string parent = kw.getParent(); + std::string frame = kw.getFrame(); + glm::vec3 min = kw.getGridMin(); + glm::vec3 max = kw.getGridMax(); - std::string parent = j["Central Body"]; - std::string frame = j["Coordinates"]; - std::string coordinateType = j["Coordinate Type"]; - int updateTime = j["ISWA_UPDATE_SECONDS"]; + glm::vec4 spatialScale; + std::string coordinateType; - glm::vec3 max( - j["Plot XMAX"], - j["Plot YMAX"], - j["Plot ZMAX"] - ); - - glm::vec3 min( - j["Plot XMIN"], - j["Plot YMIN"], - j["Plot ZMIN"] - ); - - glm::vec4 spatialScale(1, 1, 1, 10); - std::string spatial = j["Spatial Scale (Custom)"]; - if(spatial == "R_E"){ + std::tuple < std::string, std::string, std::string > gridUnits = kw.getGridUnits(); + if (std::get<0>(gridUnits) == "R" && std::get<1>(gridUnits) == "R" && std::get<2>(gridUnits) == "R") { spatialScale.x = 6.371f; spatialScale.y = 6.371f; spatialScale.z = 6.371f; spatialScale.w = 6; + + coordinateType = "Cartesian"; + }else{ + spatialScale = glm::vec4(1.0); + spatialScale.w = 1; //-log10(1.0f/max.x); + + coordinateType = "Polar"; } - - std::string table = "{" - "Name = '" + data->name +"' , " - "Parent = '" + parent + "', " - "Renderable = {" - "Type = '" + _type[data->type] + _geom[data->geom] + "', " - "Id = " + std::to_string(data->id) + ", " - "Frame = '" + frame + "' , " - "GridMin = " + std::to_string(min) + ", " - "GridMax = " + std::to_string(max) + ", " - "SpatialScale = " + std::to_string(spatialScale) + ", " - "UpdateTime = " + std::to_string(updateTime) + ", " - "CoordinateType = '" + coordinateType + "', " - "Group = "+ std::to_string(data->group) + " ," + "Name = 'KameleonPlane0'," + // "Parent = 'Earth', " + "Parent = '" + parent + "', " + "Renderable = {" + "Type = 'KameleonPlane', " + "Id = 0 ," + "Frame = '" + frame + "' , " + "GridMin = " + std::to_string(min) + ", " + "GridMax = " + std::to_string(max) + ", " + "SpatialScale = " + std::to_string(spatialScale) + ", " + "UpdateTime = 0, " + "kwPath = '" + kwPath + "' ," + "axisCut = 'y' ," + "CoordinateType = '" + coordinateType + "', " + "Group = "+ std::to_string(group) + " ," + "}" "}" - "}"; - + ; + // std::cout << table << std::endl; return table; } - return ""; + } + return ""; +} + +void ISWAManager::registerToGroup(int id, ISWACygnet* cygnet, CygnetType type){ + if(_groups.find(id) != _groups.end()){ + _groups[id]->registerCygnet(cygnet, type); + }else{ + _groups.insert(std::pair>(id, std::make_shared(id, type))); + _groups[id]->registerCygnet(cygnet, type); } - void ISWAManager::createKameleonPlane(std::string kwPath, int group){ - kwPath = "${OPENSPACE_DATA}/" + kwPath; - const std::string& extension = ghoul::filesystem::File(absPath(kwPath)).fileExtension(); +} - if(FileSys.fileExists(absPath(kwPath)) && extension == "cdf"){ - std::string luaTable = parseKWToLuaTable(kwPath, group); - if(!luaTable.empty()){ - std::cout << luaTable << std::endl; - std::string script = "openspace.addSceneGraphNode(" + luaTable + ");"; - OsEng.scriptEngine().queueScript(script); - } - }else{ - LWARNING( kwPath + " is not a cdf file or can't be found."); +void ISWAManager::unregisterFromGroup(int id, ISWACygnet* cygnet){ + if(_groups.find(id) != _groups.end()){ + _groups[id]->unregisterCygnet(cygnet); + } +} + +void ISWAManager::registerOptionsToGroup(int id, const std::vector& options){ + if(_groups.find(id) != _groups.end()){ + _groups[id]->registerOptions(options); + } +} + +std::shared_ptr ISWAManager::iSWAGroup(std::string name){ + for(auto group : _groups){ + if(group.second->name() == name){ + return group.second; } } - std::string ISWAManager::parseKWToLuaTable(std::string kwPath, int group){ - if(kwPath != ""){ - const std::string& extension = ghoul::filesystem::File(absPath(kwPath)).fileExtension(); - if(extension == "cdf"){ - KameleonWrapper kw = KameleonWrapper(absPath(kwPath)); - - std::string parent = kw.getParent(); - std::string frame = kw.getFrame(); - glm::vec3 min = kw.getGridMin(); - glm::vec3 max = kw.getGridMax(); + return nullptr; +} - glm::vec4 spatialScale; - std::string coordinateType; - - std::tuple < std::string, std::string, std::string > gridUnits = kw.getGridUnits(); - if (std::get<0>(gridUnits) == "R" && std::get<1>(gridUnits) == "R" && std::get<2>(gridUnits) == "R") { - spatialScale.x = 6.371f; - spatialScale.y = 6.371f; - spatialScale.z = 6.371f; - spatialScale.w = 6; - - coordinateType = "Cartesian"; - }else{ - spatialScale = glm::vec4(1.0); - spatialScale.w = 1; //-log10(1.0f/max.x); - - coordinateType = "Polar"; - } - std::string table = "{" - "Name = 'KameleonPlane0'," - // "Parent = 'Earth', " - "Parent = '" + parent + "', " - "Renderable = {" - "Type = 'KameleonPlane', " - "Id = 0 ," - "Frame = '" + frame + "' , " - "GridMin = " + std::to_string(min) + ", " - "GridMax = " + std::to_string(max) + ", " - "SpatialScale = " + std::to_string(spatialScale) + ", " - "UpdateTime = 0, " - "kwPath = '" + kwPath + "' ," - "axisCut = 'y' ," - "CoordinateType = '" + coordinateType + "', " - "Group = "+ std::to_string(group) + " ," - "}" - "}" - ; - // std::cout << table << std::endl; - return table; +scripting::ScriptEngine::LuaLibrary ISWAManager::luaLibrary() { + return { + "iswa", + { + { + "addCygnet", + &luascriptfunctions::iswa_addCygnet, + "string", + "Sets a property identified by the URI in " + "the first argument. The second argument can be any type, but it has to " + " agree with the type that the property expects", + true } } - return ""; - } - - void ISWAManager::registerToGroup(int id, ISWACygnet* cygnet, CygnetType type){ - if(_groups.find(id) != _groups.end()){ - _groups[id]->registerCygnet(cygnet, type); - }else{ - _groups.insert(std::pair>(id, std::make_shared(id, type))); - _groups[id]->registerCygnet(cygnet, type); - } - - } - - void ISWAManager::unregisterFromGroup(int id, ISWACygnet* cygnet){ - if(_groups.find(id) != _groups.end()){ - _groups[id]->unregisterCygnet(cygnet); - } - } - - void ISWAManager::registerOptionsToGroup(int id, const std::vector& options){ - if(_groups.find(id) != _groups.end()){ - _groups[id]->registerOptions(options); - } - } - - std::shared_ptr ISWAManager::iSWAGroup(std::string name){ - for(auto group : _groups){ - if(group.second->name() == name){ - return group.second; - } - } - - return nullptr; - } + }; +} }// namsepace openspace \ No newline at end of file diff --git a/modules/iswa/util/iswamanager.h b/modules/iswa/util/iswamanager.h index 6e5277a8a7..b3d08ebeba 100644 --- a/modules/iswa/util/iswamanager.h +++ b/modules/iswa/util/iswamanager.h @@ -32,6 +32,8 @@ #include #include #include +#include + // #include // #include @@ -78,6 +80,8 @@ public: void registerOptionsToGroup(int id, const std::vector& options); std::shared_ptr iSWAGroup(std::string name); + static scripting::ScriptEngine::LuaLibrary luaLibrary(); + private: std::string iSWAurl(int id, std::string type = "image"); std::shared_ptr downloadMetadata(int id); diff --git a/modules/iswa/util/iswamanager_lua.inl b/modules/iswa/util/iswamanager_lua.inl new file mode 100644 index 0000000000..6ce7cdcb8f --- /dev/null +++ b/modules/iswa/util/iswamanager_lua.inl @@ -0,0 +1,39 @@ +/***************************************************************************************** + * * + * OpenSpace * + * * + * Copyright (c) 2014-2016 * + * * + * Permission is hereby granted, free of charge, to any person obtaining a copy of this * + * software and associated documentation files (the "Software"), to deal in the Software * + * without restriction, including without limitation the rights to use, copy, modify, * + * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to * + * permit persons to whom the Software is furnished to do so, subject to the following * + * conditions: * + * * + * The above copyright notice and this permission notice shall be included in all copies * + * or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, * + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A * + * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT * + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF * + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE * + * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + ****************************************************************************************/ + +namespace openspace { + +namespace luascriptfunctions { + +int iswa_addCygnet(lua_State* L) { + std::string s = luaL_checkstring(L, -1); + // LERROR("String" << s); + // std::cout << "String is: " << s << std::endl; + ISWAManager::ref().addISWACygnet(s); + return 0; +} + +}// namespace luascriptfunctions + +}// namespace openspace \ No newline at end of file diff --git a/modules/onscreengui/src/gui.cpp b/modules/onscreengui/src/gui.cpp index 1290b8559e..d0ba30b0b4 100644 --- a/modules/onscreengui/src/gui.cpp +++ b/modules/onscreengui/src/gui.cpp @@ -437,7 +437,7 @@ void GUI::renderMainWindow() { ImGui::InputText("addCynget", addCygnetBuffer, addCygnetBufferSize); if(ImGui::SmallButton("Add Cygnet")){ - ISWAManager::ref().addISWACygnet(std::string(addCygnetBuffer)); + OsEng.scriptEngine().queueScript("openspace.iswa.addCygnet('"+std::string(addCygnetBuffer)+"');"); } } #endif diff --git a/openspace.cfg b/openspace.cfg index 35cc7a7812..c97c160e46 100644 --- a/openspace.cfg +++ b/openspace.cfg @@ -37,7 +37,8 @@ return { Light = "${FONTS}/Roboto/Roboto-Regular.ttf" }, StartupScripts = { - "${SCRIPTS}/default_startup.lua" + "${SCRIPTS}/default_startup.lua", + "${SCRIPTS}/iswa_startup.lua" }, SettingsScripts = { "${SCRIPTS}/default_settings.lua" diff --git a/scripts/iswa_startup.lua b/scripts/iswa_startup.lua new file mode 100644 index 0000000000..dcfdeb88af --- /dev/null +++ b/scripts/iswa_startup.lua @@ -0,0 +1,6 @@ +--[[ OpenSpace startup script ]]-- +-- This Lua script get executed once at the start of the application + +openspace.iswa.addCygnet("-1,DATA,1"); +openspace.iswa.addCygnet("-2,DATA,1"); +openspace.iswa.addCygnet("-3,DATA,1"); \ No newline at end of file diff --git a/src/engine/openspaceengine.cpp b/src/engine/openspaceengine.cpp index 9d3a6d4df9..32f466682c 100644 --- a/src/engine/openspaceengine.cpp +++ b/src/engine/openspaceengine.cpp @@ -66,6 +66,10 @@ #include #endif +#ifdef OPENSPACE_MODULE_ISWA_ENABLED +#include +#endif + #ifdef _MSC_VER #ifdef OPENSPACE_ENABLE_VLD #include @@ -134,6 +138,10 @@ OpenSpaceEngine::OpenSpaceEngine(std::string programName, SpiceManager::initialize(); Time::initialize(); ghoul::systemcapabilities::SystemCapabilities::initialize(); +#ifdef OPENSPACE_MODULE_ISWA_ENABLED + ISWAManager::initialize(); +#endif + } OpenSpaceEngine::~OpenSpaceEngine() { @@ -355,6 +363,10 @@ bool OpenSpaceEngine::initialize() { _scriptEngine->addLibrary(gui::GUI::luaLibrary()); _scriptEngine->addLibrary(network::ParallelConnection::luaLibrary()); +#ifdef OPENSPACE_MODULE_ISWA_ENABLED + _scriptEngine->addLibrary(ISWAManager::luaLibrary()); +#endif + // TODO: Maybe move all scenegraph and renderengine stuff to initializeGL scriptEngine().initialize();