20 #include <SDKDDKVer.h>
22 #include <boost/asio.hpp>
26#include <imgui_node_editor.h>
27#include <imgui_stdlib.h>
36#include <condition_variable>
41#include <nlohmann/json.hpp>
42using json = nlohmann::json;
70class NodeEditorApplication;
116 explicit Kind(
const std::string&
string)
118 if (
string ==
"Blueprint")
122 else if (
string ==
"Simple")
126 else if (
string ==
"GroupBox")
135 explicit operator bool() =
delete;
155 explicit operator std::string()
const
214 [[nodiscard]]
virtual std::string
type()
const = 0;
221 [[nodiscard]]
virtual json save()
const;
269 virtual void flush();
290 [[nodiscard]] std::optional<InputPin::IncomingLink::ValueWrapper<T>>
getInputValue(
size_t portIndex)
const
292 return inputPins.at(portIndex).link.getValue<T>();
306 void invokeCallbacks(
size_t portIndex,
const std::shared_ptr<const NodeData>& data);
329 [[nodiscard]] std::string
nameId()
const;
332 [[nodiscard]]
const ImVec2&
getSize()
const;
391 ax::NodeEditor::NodeId
id = 0;
405 std::multimap<InsTime, std::pair<OutputPin*, size_t>>
pollEvents;
nlohmann::json json
json namespace
The class is responsible for all time-related tasks.
The class is responsible for all time-related tasks.
Parent class for all data transmitted over Flow pins.
Abstract parent class for all nodes.
bool _workerWakeup
Variable to prevent the worker from sleeping.
bool isDisabled() const
Checks if the node is disabled.
bool isOnlyRealtime() const
Checks if the node is only working in real time (sensors, network interfaces, ...)
bool isInitialized() const
Checks if the node is initialized.
bool doDeinitialize(bool wait=false)
Asks the node worker to deinitialize the node.
static void workerThread(Node *node)
Worker thread.
virtual void restore(const json &j)
Restores the node from a json object.
void releaseInputValue(size_t portIndex)
Unblocks the connected node. Has to be called when the input value should be released and getInputVal...
bool _reinitialize
Flag if the node should be reinitialize after deinitializing.
virtual void workerTimeoutHandler()
Handler which gets triggered if the worker runs into a periodic timeout.
bool _disable
Flag if the node should be disabled after deinitializing.
bool doDisable(bool wait=false)
Asks the node worker to disable the node.
State
Possible states of the node.
@ DoInitialize
Node should be initialized.
@ Shutdown
Node is shutting down.
@ DoShutdown
Node should shut down.
@ Initializing
Node is currently initializing.
@ Initialized
Node is initialized (green)
@ DoDeinitialize
Node should be deinitialized.
@ Disabled
Node is disabled and won't be initialized.
@ Deinitializing
Node is currently deinitializing.
@ Deinitialized
Node is deinitialized (red)
void wakeWorker()
Wakes the worker thread.
ImVec2 _size
Size of the node in pixels.
std::mutex _configWindowMutex
Mutex to show the config window (prevents initialization to modify values within the config window)
State getState() const
Get the current state of the node.
ImVec2 _guiConfigDefaultWindowSize
bool workerInitializeNode()
Called by the worker to initialize the node.
void notifyOutputValueChanged(size_t pinIdx, const InsTime &insTime, const std::scoped_lock< std::mutex > &&guard)
Notifies connected nodes about the change.
const ImVec2 & getSize() const
Get the size of the node.
bool hasInputPinWithSameTime(const InsTime &insTime) const
Checks wether there is an input pin with the same time.
virtual void flush()
Function called by the flow executer after finishing to flush out remaining data.
std::vector< OutputPin > outputPins
List of output pins.
Node(Node &&)=delete
Move constructor.
Node(std::string name)
Constructor.
bool workerDeinitializeNode()
Called by the worker to deinitialize the node.
std::optional< InputPin::IncomingLink::ValueWrapper< T > > getInputValue(size_t portIndex) const
Get Input Value connected on the pin. Only const data types.
std::multimap< InsTime, std::pair< OutputPin *, size_t > > pollEvents
Map with callback events (sorted by time)
Kind kind
Kind of the Node.
Node & operator=(Node &&)=delete
Move assignment operator.
size_t outputPinIndexFromId(ax::NodeEditor::PinId pinId) const
Returns the index of the pin.
std::vector< InputPin > inputPins
List of input pins.
OutputPin & outputPinFromId(ax::NodeEditor::PinId pinId)
Returns the pin with the given id.
virtual void deinitialize()
Deinitialize the Node.
bool doInitialize(bool wait=false)
Asks the node worker to initialize the node.
State _state
Current state of the node.
Mode
Different Modes the Node can work in.
@ POST_PROCESSING
Node running in post-processing mode.
@ REAL_TIME
Node running in real-time mode.
bool callbacksEnabled
Enables the callbacks.
bool _configWindowFocus
Flag if the config window should be focused.
std::atomic< Mode > _mode
Mode the node is currently running in.
virtual bool resetNode()
Resets the node. It is guaranteed that the node is initialized when this is called.
std::string nameId() const
Node name and id.
bool _showConfig
Flag if the config window is shown.
virtual void afterCreateLink(OutputPin &startPin, InputPin &endPin)
Called when a new link was established.
std::thread _worker
Worker handling initialization and processing of data.
bool _lockConfigDuringRun
Lock the config when executing post-processing.
size_t inputPinIndexFromId(ax::NodeEditor::PinId pinId) const
Returns the index of the pin.
virtual void onDeleteLink(OutputPin &startPin, InputPin &endPin)
Called when a link is to be deleted.
Node & operator=(const Node &)=delete
Copy assignment operator.
virtual ~Node()
Destructor.
Mode getMode() const
Get the current mode of the node.
bool _configWindowIsCollapsed
Flag if the config window is collapsed.
std::mutex _workerMutex
Mutex to interact with the worker condition variable.
virtual void guiConfig()
ImGui config window which is shown on double click.
std::string name
Name of the Node.
bool _onlyRealTime
Whether the node can run in post-processing or only real-time.
bool doEnable()
Enable the node.
bool doReinitialize(bool wait=false)
Asks the node worker to reinitialize the node.
std::chrono::duration< int64_t > _workerTimeout
Periodic timeout of the worker to check if new data available.
std::condition_variable _workerConditionVariable
Condition variable to signal the worker thread to do something.
virtual void restoreAtferLink(const json &j)
Restores link related properties of the node from a json object.
Node(const Node &)=delete
Copy constructor.
virtual void afterDeleteLink(OutputPin &startPin, InputPin &endPin)
Called when a link was deleted.
bool _configWindowForceCollapse
Flag if the config window should be forced collapsed.
InputPin & inputPinFromId(ax::NodeEditor::PinId pinId)
Returns the pin with the given id.
std::scoped_lock< std::mutex > requestOutputValueLock(size_t pinIdx)
Blocks the thread till the output values was read by all connected nodes.
void invokeCallbacks(size_t portIndex, const std::shared_ptr< const NodeData > &data)
Calls all registered callbacks on the specified output port.
virtual json save() const
Saves the node into a json object.
static std::string toString(State state)
Converts the state into a printable text.
static bool _autostartWorker
Flag which prevents the worker to be autostarted if false.
virtual bool onCreateLink(OutputPin &startPin, InputPin &endPin)
Called when a new link is to be established.
bool _hasConfig
Flag if the config window should be shown.
virtual std::string type() const =0
String representation of the Class Type.
std::mutex _stateMutex
Mutex to interact with the worker state variable.
bool isTransient() const
Checks if the node is changing its state currently.
virtual bool initialize()
Initialize the Node.
Application class providing all relevant GUI callbacks.
void deinitialize()
Deinitialize all Nodes.
void execute()
Main task of the thread.
void RegisterNodeTypes()
Register all available Node types for the program.
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.
constexpr Kind(Value kind)
Implicit Constructor from Value type.
Kind()=default
Default Constructor.
Value value
Value of the node kind.
Value
Possible kinds of Nodes.
@ Blueprint
Node with header.
@ GroupBox
Group box which can group other nodes and drag them together.
@ Simple
Node without header, which displays its name in the center of the content.
Kind & operator=(Value v)
Assignment operator from Value type.
friend constexpr bool operator==(const Node::Kind &lhs, const Node::Kind &rhs)
Equal compares Node::Kind values.
Kind(const std::string &string)
Constructor from std::string.
friend constexpr bool operator!=(const Node::Kind &lhs, const Node::Kind &rhs)
Inequal compares Node::Kind values.