mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-01-05 03:00:58 -06:00
Add example for TimeFrameUnion and properly use the parameters struct (#3179)
This commit is contained in:
40
data/assets/examples/timeframe/union.asset
Normal file
40
data/assets/examples/timeframe/union.asset
Normal file
@@ -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)
|
||||
@@ -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<ghoul::Dictionary> timeFrames
|
||||
@@ -51,7 +57,7 @@ namespace {
|
||||
namespace openspace {
|
||||
|
||||
documentation::Documentation TimeFrameUnion::Documentation() {
|
||||
return codegen::doc<Parameters>("base_time_frame_union");
|
||||
return codegen::doc<Parameters>("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<Parameters>(dictionary);
|
||||
const Parameters p = codegen::bake<Parameters>(dictionary);
|
||||
|
||||
const ghoul::Dictionary frames =
|
||||
dictionary.value<ghoul::Dictionary>(TimeFramesInfo.identifier);
|
||||
|
||||
for (const std::string_view k : frames.keys()) {
|
||||
const ghoul::Dictionary& subDictionary = frames.value<ghoul::Dictionary>(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());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user