20#include <imgui_node_editor.h>
29 bool dataTypesMatch =
true;
34 dataTypesMatch =
false;
41 dataTypesMatch =
false;
47 dataTypesMatch =
false;
50 return startPin.
id != endPin.
id
59 return !a.empty() && !b.empty()
60 && std::ranges::find_if(a, [&b](
const std::string&
str) {
return std::ranges::find(b,
str) != b.end(); }) != a.end();
70 if (ax::NodeEditor::GetStyle().Colors[ax::NodeEditor::StyleColor_NodeBg].x
71 + ax::NodeEditor::GetStyle().Colors[ax::NodeEditor::StyleColor_NodeBg].y
72 + ax::NodeEditor::GetStyle().Colors[ax::NodeEditor::StyleColor_NodeBg].z
77 return { 255, 255, 255 };
79 return { 220, 48, 48 };
81 return { 68, 201, 156 };
83 return { 147, 226, 74 };
85 return { 124, 21, 153 };
87 return { 51, 150, 215 };
89 return { 255, 165, 0 };
91 return { 255, 48, 48 };
100 PinIcon::Type iconType = PinIcon::Type::Flow;
102 color.Value.w =
static_cast<float>(alpha) / 255.0F;
106 iconType = PinIcon::Type::Grid;
109 iconType = PinIcon::Type::Flow;
118 iconType = PinIcon::Type::Circle;
121 iconType = PinIcon::Type::RoundSquare;
127 iconType = PinIcon::Type::Diamond;
130 iconType = PinIcon::Type::Square;
138 iconType, connected, color, ImColor(32, 32, 32, alpha));
152 LOG_ERROR(
"The new Link between node '{}' and '{}' was refused by its start node.",
158 LOG_ERROR(
"The new Link between node '{}' and '{}' was refused by its end node.",
163 LOG_DEBUG(
"Creating link from pin {} of [{}] ==> {} of [{}]",
167 startPin.
connect(endPin, linkId);
168 endPin.
connect(startPin, linkId);
210 LOG_ERROR(
"Cannot delete the link, because the nodes '{}' and '{}' are not linked over pins '{}' => '{}'.",
212 size_t(startPin.
id),
size_t(endPin.
id));
216 LOG_DEBUG(
"Deleting link {} from pin {} of [{}] ==> pin {} of [{}]",
size_t(endPin.
link.
linkId),
244 return !
links.empty();
252 return iter !=
links.cend();
272 while (!
links.empty())
274 if (
auto* endPin =
links.back().getConnectedPin())
290 if (iter ==
links.end())
322 if (iter !=
links.end())
355 return link.linkId &&
link.connectedNode &&
link.connectedPinId;
370 if (
auto* startPin =
link.getConnectedPin())
381 link.connectedPinId = startPin.
id;
384 return link.connectedNode == parentNode && link.connectedPinId == id;
390 link.linkId = linkId;
391 if (iter != startPin.
links.end() && iter->linkId != linkId)
394 startPin.
connect(*
this, linkId);
397 else if (iter != startPin.
links.end())
400 link.linkId = iter->linkId;
414 if (
link.connectedNode ||
link.connectedPinId ||
link.linkId)
416 auto* startPin =
link.getConnectedPin();
419 link.connectedNode =
nullptr;
420 link.connectedPinId = 0;
425 return link.connectedNode == parentNode && link.connectedPinId == id;
428 if (iter != startPin->links.end())
430 startPin->disconnect(*
this);
453 {
"id", size_t(pin.
id) },
454 {
"name", pin.
name },
459 pin.
id = j.at(
"id").get<
size_t>();
460 if (j.contains(
"name")) { j.at(
"name").get_to(pin.
name); }
466 {
"id", size_t(pin.
id) },
467 {
"name", pin.
name },
472 pin.
id = j.at(
"id").get<
size_t>();
473 if (j.contains(
"name")) { j.at(
"name").get_to(pin.
name); }
nlohmann::json json
json namespace
#define LOG_DEBUG
Debug information. Should not be called on functions which receive observations (spamming)
#define LOG_ERROR
Error occurred, which stops part of the program to work, but not everything.
#define LOG_TRACE
Detailled info to trace the execution of the program. Should not be called on functions which receive...
Utility class which specifies available nodes.
bool isInitialized() const
Checks if the node is initialized.
bool doDeinitialize(bool wait=false)
Asks the node worker to deinitialize the node.
std::string nameId() const
Node name and id.
virtual void afterCreateLink(OutputPin &startPin, InputPin &endPin)
Called when a new link was established.
virtual void onDeleteLink(OutputPin &startPin, InputPin &endPin)
Called when a link is to be deleted.
virtual void afterDeleteLink(OutputPin &startPin, InputPin &endPin)
Called when a link was deleted.
virtual bool onCreateLink(OutputPin &startPin, InputPin &endPin)
Called when a new link is to be established.
virtual std::string type() const =0
String representation of the Class Type.
bool recreateLink(InputPin &endPin)
Destroys and recreates a link from this pin to another.
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.
void connect(InputPin &endPin, ax::NodeEditor::LinkId linkId=0)
Connects this pin to another.
void disconnect(InputPin &endPin)
Disconnects the link.
bool isPinLinked() const
Checks if the pin is linked.
std::vector< OutgoingLink > links
Info to identify the linked pins.
bool canCreateLink(const InputPin &other) const
Checks if this pin can connect to the provided pin.
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.
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.
static float defaultFontRatio()
Ratio to multiply for default GUI elements.
bool NodeDataTypeAnyIsChildOf(const std::vector< std::string > &childTypes, const std::vector< std::string > &parentTypes)
Checks if any of the provided child types is a child of any of the provided parent types.
ax::NodeEditor::LinkId GetNextLinkId()
Generates a new link id.
void ApplyChanges()
Signals that there have been changes to the flow.
void AddLink(ax::NodeEditor::LinkId linkId)
Adds the link.
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.
Collection of information about the connected node and pin.
InputPin * getConnectedPin() const
Returns a pointer to the pin which is connected to this one.
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.
Value
Type of the data on the Pin.
@ Delegate
Reference to the Node object.
@ Float
Floating Point Number.