diff --git a/data/assets/examples/timeframe/union.asset b/data/assets/examples/timeframe/union.asset new file mode 100644 index 0000000000..e7631ac7f5 --- /dev/null +++ b/data/assets/examples/timeframe/union.asset @@ -0,0 +1,40 @@ +-- This example creates a union out of two simpler TimeFrameIntervals and uses it for a +-- SceneGraphNode. The first TimeFrameInterval covers January 1st, 2000 and the second +-- TimeFrameInterval covers March 1st, 2002. The resulting TimeFrameUnion will cover both +-- January 1st, 2000 and March 1st, 2002. + +local Node = { + Identifier = "TimeFrameUnion_Example", + TimeFrame = { + Type = "TimeFrameUnion", + TimeFrames = { + -- The first TimeFrameInterval for the first day + { + Type = "TimeFrameInterval", + Start = "2000 JAN 01 00:00:00.000", + End = "2000 JAN 01 23:59:59.999" + }, + -- The second TimeFrameInterval for the second day + { + Type = "TimeFrameInterval", + Start = "2002 MAR 01 00:00:00.000", + End = "2002 MAR 01 23:59:59.999" + } + } + }, + Renderable = { + Type = "RenderableCartesianAxes" + }, + GUI = { + Name = "TimeFrameUnion", + Path = "/Examples" + } +} + +asset.onInitialize(function() + openspace.addSceneGraphNode(Node) +end) + +asset.onDeinitialize(function() + openspace.removeSceneGraphNode(Node) +end) diff --git a/modules/base/timeframe/timeframeunion.cpp b/modules/base/timeframe/timeframeunion.cpp index de9335ab76..bee5206165 100644 --- a/modules/base/timeframe/timeframeunion.cpp +++ b/modules/base/timeframe/timeframeunion.cpp @@ -40,6 +40,12 @@ namespace { openspace::properties::Property::Visibility::AdvancedUser }; + // This TimeFrame class will accept the union of all passed-in TimeFrames. This means + // that this TimeFrame will be active if at least one of the child TimeFrames is + // active and it will be inactive if none of the child TimeFrames are active. + // + // This can be used to create more complex TimeFrames that are made up of several, + // simpler TimeFrames themselves. struct [[codegen::Dictionary(TimeFrameUnion)]] Parameters { // [[codegen::verbatim(TimeFramesInfo.description)]] std::vector timeFrames @@ -51,7 +57,7 @@ namespace { namespace openspace { documentation::Documentation TimeFrameUnion::Documentation() { - return codegen::doc("base_time_frame_union"); + return codegen::doc("base_timeframe_union"); } bool TimeFrameUnion::isActive(const Time& time) const { @@ -64,21 +70,15 @@ bool TimeFrameUnion::isActive(const Time& time) const { } TimeFrameUnion::TimeFrameUnion(const ghoul::Dictionary& dictionary) { - // I don't know how we can actually help the reference attribute properly. Since the - // Parameter list only contains the monostate, there is no need to actually create - // the object here - codegen::bake(dictionary); + const Parameters p = codegen::bake(dictionary); - const ghoul::Dictionary frames = - dictionary.value(TimeFramesInfo.identifier); - - for (const std::string_view k : frames.keys()) { - const ghoul::Dictionary& subDictionary = frames.value(k); - _timeFrames.push_back(TimeFrame::createFromDictionary(subDictionary)); + for (size_t i = 0; i < p.timeFrames.size(); i++) { + const ghoul::Dictionary& frame = p.timeFrames[i]; + _timeFrames.push_back(TimeFrame::createFromDictionary(frame)); TimeFrame& subFrame = *_timeFrames.back(); - subFrame.setIdentifier(std::string(k)); - subFrame.setGuiName(std::string(k)); - subFrame.setDescription(std::string(k)); + subFrame.setIdentifier(std::format("{}", i)); + subFrame.setGuiName(std::format("{}", i)); + subFrame.setDescription(std::format("{}", i)); addPropertySubOwner(*_timeFrames.back()); } }