0.2.0
Loading...
Searching...
No Matches
NodeManager.hpp
Go to the documentation of this file.
1// This file is part of INSTINCT, the INS Toolkit for Integrated
2// Navigation Concepts and Training by the Institute of Navigation of
3// the University of Stuttgart, Germany.
4//
5// This Source Code Form is subject to the terms of the Mozilla Public
6// License, v. 2.0. If a copy of the MPL was not distributed with this
7// file, You can obtain one at https://mozilla.org/MPL/2.0/.
8
13
14#pragma once
15
16#include <imgui_node_editor.h>
17
19#include "internal/Node/Pin.hpp"
20#include "util/Assert.h"
21
22#include "NodeData/NodeData.hpp"
23
24#include <vector>
25#include <functional>
26
27namespace NAV::NodeManager
28{
31
34
36const std::vector<Node*>& m_Nodes();
37
40void AddNode(Node* node);
41
44void UpdateNode(Node* node);
45
49bool DeleteNode(ax::NodeEditor::NodeId nodeId);
50
53
56void AddLink(ax::NodeEditor::LinkId linkId);
57
68InputPin* CreateInputPin(Node* node, const char* name, Pin::Type pinType, const std::vector<std::string>& dataIdentifier = {},
69 InputPin::Callback callback = static_cast<InputPin::FlowFirableCallbackFunc>(nullptr),
70 InputPin::FlowFirableCheckFunc firable = nullptr,
71 int priority = 0, int idx = -1);
72
84template<typename T,
85 typename = std::enable_if_t<std::is_base_of_v<Node, T>>>
86InputPin* CreateInputPin(Node* node, const char* name, Pin::Type pinType, const std::vector<std::string>& dataIdentifier = {},
87 void (T::*callback)(InputPin::NodeDataQueue&, size_t) = nullptr,
88 InputPin::FlowFirableCheckFunc firable = nullptr,
89 int priority = 0, int idx = -1)
90{
91 assert(pinType == Pin::Type::Flow);
92
93 return CreateInputPin(node, name, pinType, dataIdentifier, InputPin::Callback(static_cast<InputPin::FlowFirableCallbackFunc>(callback)), firable, priority, idx);
94}
95
105template<typename T,
106 typename = std::enable_if_t<std::is_base_of_v<Node, T>>>
107InputPin* CreateInputPin(Node* node, const char* name, Pin::Type pinType, const std::vector<std::string>& dataIdentifier,
108 void (T::*notifyFunc)(const InsTime&, size_t), int idx = -1)
109{
110 assert(pinType != Pin::Type::Flow && pinType != Pin::Type::Delegate);
111
112 return CreateInputPin(node, name, pinType, dataIdentifier, InputPin::Callback(static_cast<InputPin::DataChangedNotifyFunc>(notifyFunc)), nullptr, 0, idx);
113}
114
123OutputPin* CreateOutputPin(Node* node, const char* name, Pin::Type pinType, const std::vector<std::string>& dataIdentifier, OutputPin::PinData data = static_cast<void*>(nullptr), int idx = -1);
124
134template<typename T,
135 typename = std::enable_if_t<std::is_base_of_v<Node, T>>>
136OutputPin* CreateOutputPin(Node* node, const char* name, Pin::Type pinType, const std::vector<std::string>& dataIdentifier,
137 std::shared_ptr<const NAV::NodeData> (T::*peekPollDataFunc)(size_t, bool) = nullptr, int idx = -1)
138{
139 assert(pinType == Pin::Type::Flow);
140 INS_ASSERT_USER_ERROR(std::none_of(node->outputPins.begin(), node->outputPins.end(),
141 [](const OutputPin& outputPin) { return std::holds_alternative<OutputPin::PollDataFunc>(outputPin.data); }),
142 "You cannot mix PollDataFunc and PeekPollDataFunc output pins. Use only PeekPollDataFunc pins if multiple pins are needed.");
143
144 return CreateOutputPin(node, name, pinType, dataIdentifier, OutputPin::PinData(static_cast<OutputPin::PeekPollDataFunc>(peekPollDataFunc)), idx);
145}
146
156template<typename T,
157 typename = std::enable_if_t<std::is_base_of_v<Node, T>>>
158OutputPin* CreateOutputPin(Node* node, const char* name, Pin::Type pinType, const std::vector<std::string>& dataIdentifier,
159 std::shared_ptr<const NAV::NodeData> (T::*pollDataFunc)() = nullptr, int idx = -1)
160{
161 assert(pinType == Pin::Type::Flow);
162 INS_ASSERT_USER_ERROR(std::none_of(node->outputPins.begin(), node->outputPins.end(),
163 [](const OutputPin& outputPin) { return std::holds_alternative<OutputPin::PeekPollDataFunc>(outputPin.data)
164 || std::holds_alternative<OutputPin::PollDataFunc>(outputPin.data); }),
165 "There can only be one poll pin if the poll only data function is chosen. If multiple are needed, create PeekPollDataFunc pins.");
166
167 return CreateOutputPin(node, name, pinType, dataIdentifier, OutputPin::PinData(static_cast<OutputPin::PollDataFunc>(pollDataFunc)), idx);
168}
169
174
179
183Node* FindNode(ax::NodeEditor::NodeId id);
184
188OutputPin* FindOutputPin(ax::NodeEditor::PinId id);
189
193InputPin* FindInputPin(ax::NodeEditor::PinId id);
194
197
200
203
207
210
212ax::NodeEditor::NodeId GetNextNodeId();
213
215ax::NodeEditor::LinkId GetNextLinkId();
216
218ax::NodeEditor::PinId GetNextPinId();
219
220#ifdef TESTING
221
226void RegisterWatcherCallbackToInputPin(ax::NodeEditor::PinId id, const InputPin::WatcherCallback& callback);
227
232void RegisterWatcherCallbackToLink(ax::NodeEditor::LinkId id, const InputPin::WatcherCallback& callback);
233
235void ApplyWatcherCallbacks();
236
239void RegisterPreInitCallback(std::function<void()> callback);
240
242void CallPreInitCallback();
243
246void RegisterCleanupCallback(std::function<void()> callback);
247
249void CallCleanupCallback();
250
252void ClearRegisteredCallbacks();
253
254#endif
255
256} // namespace NAV::NodeManager
Assertion helpers.
#define INS_ASSERT_USER_ERROR(_EXP, _MSG)
Assert function with message.
Definition Assert.h:21
Abstract NodeData Class.
void ClearAllNodeQueues()
Clears all nodes queues.
InputPin * CreateInputPin(Node *node, const char *name, Pin::Type pinType, const std::vector< std::string > &dataIdentifier={}, InputPin::Callback callback=static_cast< InputPin::FlowFirableCallbackFunc >(nullptr), InputPin::FlowFirableCheckFunc firable=nullptr, int priority=0, int idx=-1)
Create an Input Pin object.
ax::NodeEditor::LinkId GetNextLinkId()
Generates a new link id.
bool showFlowWhenNotifyingValueChange
Flag if notifyOutputValueChanged & notifyInputValueChanged triggers a GUI Flow event.
bool DeleteOutputPin(OutputPin &pin)
Deletes the output pin. Invalidates the pin reference given.
bool DeleteNode(ax::NodeEditor::NodeId nodeId)
Delete the node provided by id.
InputPin * FindInputPin(ax::NodeEditor::PinId id)
Finds the Pin for the PinId.
const std::vector< Node * > & m_Nodes()
List of all registered Nodes.
void InitializeAllNodesAsync()
Initializes all nodes in a separate thread.
void UpdateNode(Node *node)
Update the provided node object.
void AddLink(ax::NodeEditor::LinkId linkId)
Adds the link.
OutputPin * FindOutputPin(ax::NodeEditor::PinId id)
Finds the Pin for the PinId.
Node * FindNode(ax::NodeEditor::NodeId id)
Finds the Node for the NodeId.
void EnableAllCallbacks()
Enables all Node callbacks.
void DisableAllCallbacks()
Disables all Node callbacks.
ax::NodeEditor::NodeId GetNextNodeId()
Generates a new node id.
bool InitializeAllNodes()
Initializes all nodes.
bool DeleteInputPin(InputPin &pin)
Deletes the input pin. Invalidates the pin reference given.
void DeleteAllNodes()
Delete all nodes.
void AddNode(Node *node)
Add the provided node object to the list of nodes.
ax::NodeEditor::PinId GetNextPinId()
Generates a new pin id.
bool showFlowWhenInvokingCallbacks
Flag if invokeCallbacks triggers a GUI Flow event.
OutputPin * CreateOutputPin(Node *node, const char *name, Pin::Type pinType, const std::vector< std::string > &dataIdentifier, OutputPin::PinData data=static_cast< void * >(nullptr), int idx=-1)
Create an Output Pin object.
Node Class.
Pin class.
Input pins of nodes.
Definition Pin.hpp:491
void(Node::*)(NodeDataQueue &, size_t) FlowFirableCallbackFunc
Definition Pin.hpp:708
std::variant< FlowFirableCallbackFunc, DataChangedNotifyFunc > Callback
Callback function types.
Definition Pin.hpp:714
bool(*)(const Node *, const InputPin &) FlowFirableCheckFunc
Function type to call when checking if a pin is firable.
Definition Pin.hpp:721
void(Node::*)(const InsTime &, size_t) DataChangedNotifyFunc
Definition Pin.hpp:712
The class is responsible for all time-related tasks.
Definition InsTime.hpp:667
Abstract parent class for all nodes.
Definition Node.hpp:86
std::vector< OutputPin > outputPins
List of output pins.
Definition Node.hpp:382
Output pins of nodes.
Definition Pin.hpp:338
std::shared_ptr< const NAV::NodeData >(Node::*)(size_t, bool) PeekPollDataFunc
FileReader/Simulator peekPollData function type for nodes with more than one polling pin.
Definition Pin.hpp:442
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.
Definition Pin.hpp:448
std::shared_ptr< const NAV::NodeData >(Node::*)() PollDataFunc
FileReader/Simulator pollData function type for nodes with a single poll pin.
Definition Pin.hpp:445
Type of the data on the Pin.
Definition Pin.hpp:47
@ Delegate
Reference to the Node object.
Definition Pin.hpp:59
@ Flow
NodeData Trigger.
Definition Pin.hpp:52