/***************************************************************************************** * * * OpenSpace * * * * Copyright (c) 2014-2025 * * * * 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. * ****************************************************************************************/ #include #include #include #include #include #include namespace { constexpr openspace::properties::Property::PropertyInfo HasStartInfo = { "HasStart", "Has start", "If enabled, this TimeFrame will be inactive before the Start.", openspace::properties::Property::Visibility::User }; constexpr openspace::properties::Property::PropertyInfo StartInfo = { "Start", "Start", "Specifies the time when this TimeFrame becomes active.", openspace::properties::Property::Visibility::User }; constexpr openspace::properties::Property::PropertyInfo HasEndInfo = { "HasEnd", "Has end", "If enabled, this TimeFrame will be inactive after the End.", openspace::properties::Property::Visibility::User }; constexpr openspace::properties::Property::PropertyInfo EndInfo = { "End", "End", "Specifies the time when this TimeFrame becomes inactive.", openspace::properties::Property::Visibility::User }; // This `TimeFrame`'s validity is determined by a single start and end time in between // which the scene graph node is valid. The start time is inclusive, while the end // time is exclusive. If the start time or end time is not specified, the value // corresponds to $-\infty$ and $\infty$ respectively. If both the start and end time // are not specified, the `TimeFrameInterval` will always be valid. struct [[codegen::Dictionary(TimeFrameInterval)]] Parameters { // [[codegen::verbatim(StartInfo.description)]] std::optional> start; // [[codegen::verbatim(EndInfo.description)]] std::optional> end; }; #include "timeframeinterval_codegen.cpp" } // namespace namespace openspace { documentation::Documentation TimeFrameInterval::Documentation() { return codegen::doc("base_time_frame_interval"); } TimeFrameInterval::TimeFrameInterval(const ghoul::Dictionary& dictionary) : _hasStart(HasStartInfo, false) , _start(StartInfo, 0, 0, 1E9) , _hasEnd(HasEndInfo, false) , _end(EndInfo, 0, 0, 1E9) { const Parameters p = codegen::bake(dictionary); if (p.start.has_value()) { if (std::holds_alternative(*p.start)) { _start = std::get(*p.start); } else { _start = SpiceManager::ref().ephemerisTimeFromDate( std::get(*p.start) ); } } _hasStart = p.start.has_value(); addProperty(_hasStart); addProperty(_start); if (p.end.has_value()) { if (std::holds_alternative(*p.end)) { _end = std::get(*p.end); } else { _end = SpiceManager::ref().ephemerisTimeFromDate( std::get(*p.end) ); } } _hasEnd = p.end.has_value(); addProperty(_hasEnd); addProperty(_end); } void TimeFrameInterval::update(const Time& time) { if (_hasStart && time.j2000Seconds() < _start) { _isInTimeFrame = false; } else if (_hasEnd && time.j2000Seconds() >= _end) { _isInTimeFrame = false; } else { _isInTimeFrame = true; } } } // namespace openspace