17#include <imgui_node_editor.h>
18#include <imgui_stdlib.h>
30#include <condition_variable>
35#include <nlohmann/json.hpp>
36using json = nlohmann::json;
64class NodeEditorApplication;
110 explicit Kind(
const std::string&
string)
112 if (
string ==
"Blueprint")
116 else if (
string ==
"Simple")
120 else if (
string ==
"GroupBox")
127 explicit operator Value()
const {
return value; }
129 explicit operator bool() =
delete;
149 explicit operator std::string()
const
208 [[nodiscard]]
virtual std::string
type()
const = 0;
277 [[nodiscard]] std::optional<InputPin::IncomingLink::ValueWrapper<T>>
getInputValue(
size_t portIndex)
const
279 return inputPins.at(portIndex).link.getValue<T>();
312 [[nodiscard]] std::string
nameId()
const;
374 ax::NodeEditor::NodeId
id = 0;
388 std::multimap<InsTime, std::pair<OutputPin*, size_t>>
pollEvents;
406 mutable std::mutex _stateMutex;
412 bool _reinitialize =
false;
415 bool _disable =
false;
418 bool _showConfig =
false;
421 std::mutex _configWindowMutex;
423 bool _configWindowForceCollapse =
false;
425 bool _configWindowIsCollapsed =
false;
428 bool _configWindowFocus =
false;
431 ImVec2 _size{ 0, 0 };
434 static inline bool _autostartWorker =
true;
436 std::chrono::duration<int64_t> _workerTimeout = std::chrono::minutes(1);
438 std::mutex _workerMutex;
439 std::condition_variable _workerConditionVariable;
440 bool _workerWakeup =
false;
444 static void workerThread(
Node* node);
447 virtual void workerTimeoutHandler();
451 bool workerInitializeNode();
455 bool workerDeinitializeNode();
461 friend void NAV::FlowExecutor::execute();
463 friend void NAV::FlowExecutor::deinitialize();
465 friend void NAV::NodeRegistry::RegisterNodeTypes();
nlohmann::json json
json namespace
Definition FlowManager.hpp:21
The class is responsible for all time-related tasks.
Utility class for logging to console and file.
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.
void RegisterNodeTypes()
Register all available Node types for the program.
void execute()
Main task of the FlowExecutor thread.
Group Box.
Definition GroupBox.hpp:22
The class is responsible for all time-related tasks.
Definition InsTime.hpp:667
Abstract parent class for all nodes.
Definition Node.hpp:86
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, ...)
State
Possible states of the node.
Definition Node.hpp:170
@ 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)
bool isInitialized() const
Checks if the node is initialized.
bool doDeinitialize(bool wait=false)
Asks the node worker to deinitialize the node.
void releaseInputValue(size_t portIndex)
Unblocks the connected node. Has to be called when the input value should be released and getInputVal...
bool doDisable(bool wait=false)
Asks the node worker to disable the node.
void wakeWorker()
Wakes the worker thread.
OutputPin & outputPinFromId(ax::NodeEditor::PinId pinId)
Returns the pin with the given id.
virtual void onDeleteLink(OutputPin &startPin, InputPin &endPin)
Called when a link is to be deleted.
ImVec2 _guiConfigDefaultWindowSize
Definition Node.hpp:393
const ImVec2 & getSize() const
Get the size of the node.
std::vector< OutputPin > outputPins
List of output pins.
Definition Node.hpp:382
void notifyOutputValueChanged(size_t pinIdx, const InsTime &insTime, const std::scoped_lock< std::mutex > &guard)
Notifies connected nodes about the change.
Mode
Different Modes the Node can work in.
Definition Node.hpp:184
@ POST_PROCESSING
Node running in post-processing mode.
@ REAL_TIME
Node running in real-time mode.
Node(Node &&)=delete
Move constructor.
virtual void restore(const json &j)
Restores the node from a json object.
Node(std::string name)
Constructor.
virtual void afterCreateLink(OutputPin &startPin, InputPin &endPin)
Called when a new link was established.
virtual void deinitialize()
Deinitialize the Node.
virtual bool initialize()
Initialize the Node.
std::optional< InputPin::IncomingLink::ValueWrapper< T > > getInputValue(size_t portIndex) const
Get Input Value connected on the pin. Only const data types.
Definition Node.hpp:277
std::multimap< InsTime, std::pair< OutputPin *, size_t > > pollEvents
Map with callback events (sorted by time)
Definition Node.hpp:388
virtual void afterDeleteLink(OutputPin &startPin, InputPin &endPin)
Called when a link was deleted.
Kind kind
Kind of the Node.
Definition Node.hpp:376
Node & operator=(Node &&)=delete
Move assignment operator.
static std::string toString(State state)
Converts the state into a printable text.
InputPin & inputPinFromId(ax::NodeEditor::PinId pinId)
Returns the pin with the given id.
size_t outputPinIndexFromId(ax::NodeEditor::PinId pinId) const
Returns the index of the pin.
std::vector< InputPin > inputPins
List of input pins.
Definition Node.hpp:380
bool doInitialize(bool wait=false)
Asks the node worker to initialize the node.
virtual json save() const
Saves the node into a json object.
bool callbacksEnabled
Enables the callbacks.
Definition Node.hpp:385
std::string nameId() const
Node name and id.
bool _lockConfigDuringRun
Lock the config when executing post-processing.
Definition Node.hpp:399
virtual void restoreAtferLink(const json &j)
Restores link related properties of the node from a json object.
size_t inputPinIndexFromId(ax::NodeEditor::PinId pinId) const
Returns the index of the pin.
Node & operator=(const Node &)=delete
Copy assignment operator.
friend void gui::menus::ShowRunMenu()
Show the run menu dropdown.
std::string name
Name of the Node.
Definition Node.hpp:378
bool _onlyRealTime
Whether the node can run in post-processing or only real-time.
Definition Node.hpp:402
bool doEnable()
Enable the node.
virtual void flush()
Function called by the flow executer after finishing to flush out remaining data.
bool doReinitialize(bool wait=false)
Asks the node worker to reinitialize the node.
Node(const Node &)=delete
Copy constructor.
virtual ~Node()
Destructor.
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 bool resetNode()
Resets the node. It is guaranteed that the node is initialized when this is called.
State getState() const
Get the current state of the node.
Mode getMode() const
Get the current mode of the node.
bool _hasConfig
Flag if the config window should be shown.
Definition Node.hpp:396
virtual std::string type() const =0
String representation of the Class Type.
virtual void guiConfig()
ImGui config window which is shown on double click.
virtual bool onCreateLink(OutputPin &startPin, InputPin &endPin)
Called when a new link is to be established.
bool isTransient() const
Checks if the node is changing its state currently.
Output pins of nodes.
Definition Pin.hpp:338
Application class providing all relevant GUI callbacks.
Definition NodeEditorApplication.hpp:35
bool operator==(const ImVec4 &lhs, const ImVec4 &rhs)
Equal comparison operator.
bool operator!=(const ImVec4 &lhs, const ImVec4 &rhs)
Unequal comparison operator.
Kind information class.
Definition Node.hpp:90
constexpr Kind(Value kind)
Implicit Constructor from Value type.
Definition Node.hpp:104
Kind()=default
Default Constructor.
Value
Possible kinds of Nodes.
Definition Node.hpp:93
@ Blueprint
Node with header.
Definition Node.hpp:94
@ GroupBox
Group box which can group other nodes and drag them together.
Definition Node.hpp:96
@ Simple
Node without header, which displays its name in the center of the content.
Definition Node.hpp:95
Kind & operator=(Value v)
Assignment operator from Value type.
Definition Node.hpp:133
friend constexpr bool operator==(const Node::Kind &lhs, const Node::Kind &rhs)
Equal compares Node::Kind values.
Definition Node.hpp:484
Kind(const std::string &string)
Constructor from std::string.
Definition Node.hpp:110
friend constexpr bool operator!=(const Node::Kind &lhs, const Node::Kind &rhs)
Inequal compares Node::Kind values.
Definition Node.hpp:489