From be6915ecc16e1bddc8087d5f445146658daf8f86 Mon Sep 17 00:00:00 2001 From: Alexander Bock Date: Thu, 10 Jan 2019 23:06:35 +0100 Subject: [PATCH 1/2] Add Lua function to query property identifiers --- src/scene/scene.cpp | 8 ++++++++ src/scene/scene_lua.inl | 45 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) diff --git a/src/scene/scene.cpp b/src/scene/scene.cpp index f1b9915a9c..0785604346 100644 --- a/src/scene/scene.cpp +++ b/src/scene/scene.cpp @@ -605,6 +605,14 @@ scripting::LuaLibrary Scene::luaLibrary() { "Returns the value the property, identified by " "the provided URI." }, + { + "getProperty", + &luascriptfunctions::property_getProperty, + {}, + "string", + "Returns a list of property identifiers that match the passed regular " + "expression" + }, { "loadScene", &luascriptfunctions::loadScene, diff --git a/src/scene/scene_lua.inl b/src/scene/scene_lua.inl index 964bd0989d..a7494138e3 100644 --- a/src/scene/scene_lua.inl +++ b/src/scene/scene_lua.inl @@ -401,6 +401,51 @@ int property_getValue(lua_State* L) { return 1; } +/** + * \ingroup LuaScripts + * getProperty + * Returns a list of property identifiers that match the passed regular expression + */ +int property_getProperty(lua_State* L) { + ghoul::lua::checkArgumentsAndThrow(L, 1, "lua::property_getProperty"); + + std::string regex = ghoul::lua::value(L, 1); + lua_pop(L, 1); + + + // Replace all wildcards * with the correct regex (.*) + size_t startPos = regex.find("*"); + while (startPos != std::string::npos) { + regex.replace(startPos, 1, "(.*)"); + startPos += 4; // (.*) + startPos = regex.find("*", startPos); + } + + + + std::regex r(regex); + std::vector props = allProperties(); + std::vector res; + for (properties::Property* prop : props) { + // Check the regular expression for all properties + const std::string& id = prop->fullyQualifiedIdentifier(); + + if (std::regex_match(id, r)) { + res.push_back(id); + } + } + + lua_newtable(L); + int number = 1; + for (const std::string& s : res) { + lua_pushstring(L, s.c_str()); + lua_rawseti(L, -2, number); + ++number; + } + + return 1; +} + /** * \ingroup LuaScripts * getPropertyValue(string): From 0b7897fb8bcb31829ad985e9fa2468216e6a6682 Mon Sep 17 00:00:00 2001 From: Agnes Heppich Date: Thu, 10 Jan 2019 17:16:28 -0500 Subject: [PATCH 2/2] check if parsing is ready before using values --- modules/dsn/managers/radecmanager.cpp | 2 +- modules/dsn/managers/radecmanager.h | 1 + modules/dsn/translation/radectranslation.cpp | 17 +++++++++++------ 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/modules/dsn/managers/radecmanager.cpp b/modules/dsn/managers/radecmanager.cpp index 0779ab716f..6d69dc719f 100644 --- a/modules/dsn/managers/radecmanager.cpp +++ b/modules/dsn/managers/radecmanager.cpp @@ -111,8 +111,8 @@ namespace openspace { LERROR(fmt::format("{}: Error in json object number {} while reading file '{}'", objectIdentifier, objectCounter, filename)); } RadecManager::positions.push_back(position); - } + isReady = true; return true; } else return false; diff --git a/modules/dsn/managers/radecmanager.h b/modules/dsn/managers/radecmanager.h index 8484248aa3..b5b495b211 100644 --- a/modules/dsn/managers/radecmanager.h +++ b/modules/dsn/managers/radecmanager.h @@ -45,6 +45,7 @@ namespace openspace { mutable double lightTravelTime; //Downlink light time travel time in seconds mutable double lightTravelHours = 1; //Downlink light time travel time in seconds }; + mutable bool isReady = false; //Used to determine if we need to search for new data mutable int prevFileIndex; diff --git a/modules/dsn/translation/radectranslation.cpp b/modules/dsn/translation/radectranslation.cpp index 980ce37cf3..54dd6a6135 100644 --- a/modules/dsn/translation/radectranslation.cpp +++ b/modules/dsn/translation/radectranslation.cpp @@ -141,24 +141,29 @@ glm::dvec3 RadecTranslation::radecToCartesianCoordinates(glm::vec3 pos) const { } glm::dvec3 RadecTranslation::position(const UpdateData& data) const{ - double time = data.time.j2000Seconds(); + double time = data.time.j2000Seconds(); const bool haveDataForTime = (time >= _firstTimeInData) && (time < _lastTimeInData); if (haveDataForTime) { glm::dvec3 radecPos = radecManager.getPosForTime(time); - _position = radecToCartesianCoordinates(radecPos); + if (radecManager.isReady) { + _position = radecToCartesianCoordinates(radecPos); + } } else if(time < _firstTimeInData){ glm::dvec3 radecPos = radecManager.getPosForTime(_firstTimeInData); - _position = radecToCartesianCoordinates(radecPos); + if (radecManager.isReady) { + _position = radecToCartesianCoordinates(radecPos); + } } else { glm::dvec3 radecPos = radecManager.getPosForTime(_lastTimeInData); - _position = radecToCartesianCoordinates(radecPos); + if (radecManager.isReady) { + _position = radecToCartesianCoordinates(radecPos); + } } - return _position; -} +} } // namespace openspace