16#include <imgui_node_editor.h>
18#include <nlohmann/json.hpp>
19using json = nlohmann::json;
28#include <condition_variable>
63 constexpr Type() =
default;
73 explicit Type(
const std::string& typeString)
75 if (typeString ==
"Flow")
79 else if (typeString ==
"Bool")
83 else if (typeString ==
"Int")
87 else if (typeString ==
"Float")
91 else if (typeString ==
"String")
95 else if (typeString ==
"Object")
99 else if (typeString ==
"Matrix")
103 else if (typeString ==
"Delegate")
112 explicit operator bool() =
delete;
132 explicit operator std::string()
const
185 explicit Kind(
const std::string& kindString)
187 if (kindString ==
"Input")
191 else if (kindString ==
"Output")
200 explicit operator bool() =
delete;
220 explicit operator std::string()
const
285 [[nodiscard]]
static bool dataIdentifierHaveCommon(
const std::vector<std::string>& a,
const std::vector<std::string>& b);
297 ax::NodeEditor::PinId
id;
356 :
Pin(std::move(other)),
357 links(std::move(other.links)),
369 links = std::move(other.links);
373 Pin::operator=(std::move(other));
509 :
Pin(std::move(other)),
534 queue = std::move(other.queue);
535 Pin::operator=(std::move(other));
593 std::scoped_lock guard(
outputPin->dataAccessMutex);
594 if (!dataChangeNotification)
598 dataChangeNotification =
false;
605 std::scoped_lock guard(
outputPin->dataAccessMutex);
611 outputPin->dataAccessConditionVariable.notify_all();
621 std::scoped_lock guard(
outputPin->dataAccessMutex);
626 :
v(std::move(other.v)),
outputPin(other.outputPin)
628 other.outputPin =
nullptr;
637 std::scoped_lock guard(
outputPin->dataAccessMutex);
647 v = std::move(other.v);
649 other.outputPin =
nullptr;
666 [[nodiscard]] std::optional<ValueWrapper<T>>
getValue()
const
673 return link.linkId == linkId;
677 if constexpr (std::is_same_v<T, bool>
678 || std::is_same_v<T, int>
679 || std::is_same_v<T, float>
680 || std::is_same_v<T, double>
681 || std::is_same_v<T, std::string>)
683 if (
const auto* pVal = std::get_if<const T*>(&(connectedPin->data));
686 return ValueWrapper<T>(*pVal, connectedPin, outgoingLink->dataChangeNotification);
691 if (
const auto* pVal = std::get_if<const void*>(&(connectedPin->data));
694 return ValueWrapper<T>(
static_cast<const T*
>(*pVal), connectedPin, outgoingLink->dataChangeNotification);
749 using FlowFirableWatcherCallbackFunc = std::function<void(
const Node*,
const NodeDataQueue&,
size_t)>;
753 using DataChangedWatcherNotifyFunc = std::function<void(
const Node*,
const InsTime&,
size_t)>;
756 using WatcherCallback = std::variant<FlowFirableWatcherCallbackFunc,
757 DataChangedWatcherNotifyFunc>;
760 std::vector<WatcherCallback> watcherCallbacks;
nlohmann::json json
json namespace
The class is responsible for all time-related tasks.
Utility class for logging to console and file.
The class is responsible for all time-related tasks.
Parent class for all data transmitted over Flow pins.
Abstract parent class for all nodes.
OutputPin(ax::NodeEditor::PinId id, const char *name, Type type, Node *parentNode)
Constructor.
bool recreateLink(InputPin &endPin)
Destroys and recreates a link from this pin to another.
std::mutex dataAccessMutex
Mutex to interact with the data object and also the dataAccessCounter variable.
bool createLink(InputPin &endPin, ax::NodeEditor::LinkId linkId=0)
Creates a link from this pin to another, calling all node specific callbacks.
void deleteLink(InputPin &endPin)
Disconnects the link.
void deleteLinks()
Disconnects all links.
OutputPin(const OutputPin &)=delete
Copy constructor.
void connect(InputPin &endPin, ax::NodeEditor::LinkId linkId=0)
Connects this pin to another.
std::shared_ptr< const NAV::NodeData >(Node::*)(size_t, bool) PeekPollDataFunc
FileReader/Simulator peekPollData function type for nodes with more than one polling pin.
void disconnect(InputPin &endPin)
Disconnects the link.
OutputPin & operator=(const OutputPin &)=delete
Copy assignment operator.
std::condition_variable dataAccessConditionVariable
Condition variable to signal that the data was read by connected nodes (used for non-flow pins)
size_t dataAccessCounter
Counter for data accessing.
std::variant< const void *, const bool *, const int *, const float *, const double *, const std::string *, PeekPollDataFunc, PollDataFunc > PinData
Possible Types represented by an output pin.
OutputPin()=default
Default constructor (for serialization)
OutputPin & operator=(OutputPin &&other) noexcept
Move assignment operator.
PinData data
Pointer to data (owned by this node) which is transferred over this pin.
OutputPin(OutputPin &&other) noexcept
Move constructor.
bool isPinLinked() const
Checks if the pin is linked.
std::vector< OutgoingLink > links
Info to identify the linked pins.
std::shared_ptr< const NAV::NodeData >(Node::*)() PollDataFunc
FileReader/Simulator pollData function type for nodes with a single poll pin.
std::atomic< bool > blocksConnectedNodeFromFinishing
Flag, whether connected nodes can finish with this pin not being finished yet (needed to make a loop ...
std::atomic< bool > noMoreDataAvailable
Flag set, when no more data is available on this pin.
bool canCreateLink(const InputPin &other) const
Checks if this pin can connect to the provided pin.
~OutputPin()=default
Destructor.
Node * parentNode
Reference to the parent node.
static void deleteLink(OutputPin &startPin, InputPin &endPin)
Disconnects the link.
static bool recreateLink(OutputPin &startPin, InputPin &endPin)
Destroys and recreates a link from this pin to another.
std::string name
Name of the Pin.
static constexpr int m_PinIconSize
Size of the Pin Icons in [px].
void drawPinIcon(bool connected, int alpha) const
Draw the Pin Icon.
ax::NodeEditor::PinId id
Unique Id of the Pin.
std::vector< std::string > dataIdentifier
One or multiple Data Identifiers (Unique name which is used for data flows)
Type type
Type of the Pin.
static bool dataIdentifierHaveCommon(const std::vector< std::string > &a, const std::vector< std::string > &b)
Checks if the first list of data identifiers has a common entry with the second.
static bool createLink(OutputPin &startPin, InputPin &endPin, ax::NodeEditor::LinkId linkId=0)
Create a Link between the two given pins.
Pin(ax::NodeEditor::PinId id, const char *name, Type type, Kind kind, Node *parentNode)
Constructor.
Kind kind
Kind of the Pin (Input/Output)
ImColor getIconColor() const
Get the Icon Color object.
static bool canCreateLink(const OutputPin &startPin, const InputPin &endPin)
Checks if pins can connect.
Pin()=default
Default constructor.
void to_json(json &j, const Node &node)
Converts the provided node into a json object.
void from_json(const json &j, Node &node)
Converts the provided json object into a node object.
constexpr bool operator!=(const Node::Kind &lhs, const Node::Kind &rhs)
Inequal compares Node::Kind values.
constexpr bool operator==(const Node::Kind &lhs, const Node::Kind &rhs)
Equal compares Node::Kind values.
Collection of information about the connected node and pin.
OutgoingLink()=default
Default Constructor.
bool dataChangeNotification
Flag to signal the connected node, that the data was changed.
InputPin * getConnectedPin() const
Returns a pointer to the pin which is connected to this one.
OutgoingLink(ax::NodeEditor::LinkId linkId, Node *connectedNode, ax::NodeEditor::PinId connectedPinId)
Constructor.
Kind of the Pin (Input/Output)
Kind & operator=(Value v)
Assignment operator from Value type.
constexpr Kind(Value kind)
Implicit Constructor from Value type.
Value
Kind of the Pin (Input/Output)
friend constexpr bool operator!=(const Pin::Kind &lhs, const Pin::Kind &rhs)
Inequal compares Pin::Kind values.
friend constexpr bool operator==(const Pin::Kind &lhs, const Pin::Kind &rhs)
Equal compares Pin::Kind values.
Value value
Value of the pin kind.
Kind()=default
Default Constructor.
Kind(const std::string &kindString)
Constructor from std::string.
Link()=default
Default Constructor.
Link(ax::NodeEditor::LinkId linkId, Node *connectedNode, ax::NodeEditor::PinId connectedPinId)
Constructor.
ax::NodeEditor::LinkId linkId
Unique id of the link.
Node * connectedNode
Pointer to the node, which is connected to this pin.
ax::NodeEditor::PinId connectedPinId
Id of the pin, which is connected to this pin.
Type of the data on the Pin.
Value
Type of the data on the Pin.
@ Delegate
Reference to the Node object.
@ Float
Floating Point Number.
constexpr Type(Value type)
Implicit Constructor from Value type.
friend constexpr bool operator!=(const Pin::Type &lhs, const Pin::Type &rhs)
Inequal compares Pin::Type values.
Value value
Value of the pin type.
Type(const std::string &typeString)
Constructor from std::string.
friend constexpr bool operator==(const Pin::Type &lhs, const Pin::Type &rhs)
Equal compares Pin::Type values.
Type & operator=(Value v)
Assignment operator from Value type.
constexpr Type()=default
Default Constructor.