Enzo
Loading...
Searching...
No Matches
NodeType.h
1#pragma once
2#include "Engine/Core/InstallPaths.h"
3#include "Engine/Parameter/Template.h"
4#include <filesystem>
5#include <string>
6#include <vector>
7
8namespace enzo::nt {
9class Node;
10class NodeImpl;
11class CookContext;
12
14using nodeConstructor = NodeImpl* (*)(Node&, CookContext&);
15
23{
24 std::string label;
25 bool multiInput = false;
26
28 bool optional = false;
29};
30
40{
41 std::string internalName;
42
45 std::string typeNamespace;
46
47 std::string displayName;
48 nodeConstructor ctorFunc = nullptr;
49 std::vector<enzo::prm::Template> templates;
50
52 std::vector<InputPort> inputPorts;
53
54 unsigned int maxOutputs = 1;
55
57 std::vector<std::string> tags;
58
60 std::filesystem::path folder;
61
63 std::string iconPath;
64
66 std::string docsPath;
67
74 std::string childScopeType;
75
78 const std::string& getName() const { return internalName; }
81 std::string getFullName() const { return typeNamespace + "::" + internalName; }
83 const std::string& getLabel() const { return displayName; }
84
86 bool hasChildScope() const { return !childScopeType.empty(); }
87
89 bool hasMultiInputPort() const { return !inputPorts.empty() && inputPorts.back().multiInput; }
90
92 unsigned int getSinglePortCount() const
93 {
94 const auto declaredCount = static_cast<unsigned int>(inputPorts.size());
95 return hasMultiInputPort() ? declaredCount - 1 : declaredCount;
96 }
97
99 bool isMultiInputPortAt(unsigned int inputIndex) const
100 {
101 return hasMultiInputPort() && inputIndex >= getSinglePortCount();
102 }
103
107 const InputPort* getPortAt(unsigned int inputIndex) const
108 {
109 if (inputIndex < getSinglePortCount()) return &inputPorts[inputIndex];
110 if (hasMultiInputPort()) return &inputPorts.back();
111 return nullptr;
112 }
113
116 std::filesystem::path getIconFile() const
117 {
118 if (iconPath.empty()) return getStaticDir() / "icons" / "nodeDefault.svg";
119 return folder / iconPath;
120 }
121};
122} // namespace enzo::nt
One input port a node type declares.
Definition NodeType.h:23
bool optional
Whether the node cooks with nothing wired into this port.
Definition NodeType.h:28
Everything every node of one kind shares.
Definition NodeType.h:40
std::filesystem::path folder
The folder the node was loaded from, which is also where its assets live.
Definition NodeType.h:60
bool hasChildScope() const
Returns whether this node holds a scope of other nodes inside it.
Definition NodeType.h:86
std::vector< InputPort > inputPorts
The input ports the node declares, in the order their inputs run.
Definition NodeType.h:52
bool hasMultiInputPort() const
Returns whether the last declared port holds any number of inputs.
Definition NodeType.h:89
std::string typeNamespace
The namespace the node was published under, such as "enzo".
Definition NodeType.h:45
std::vector< std::string > tags
The words the tab menu searches on, such as "curve" or "primitive".
Definition NodeType.h:57
std::filesystem::path getIconFile() const
Returns the icon file on disk.
Definition NodeType.h:116
std::string docsPath
The documentation file relative to the folder, empty when there is none.
Definition NodeType.h:66
unsigned int getSinglePortCount() const
Returns the number of ports that hold a single input each.
Definition NodeType.h:92
const std::string & getName() const
Returns the internal type name shared by all nodes of this type (eg. "copy_to_points")
Definition NodeType.h:78
std::string getFullName() const
Returns the name that uniquely identifies this type (eg. "enzo::copy_to_points")
Definition NodeType.h:81
const std::string & getLabel() const
Returns the human readable type label shown in the UI (eg. "Copy To Points")
Definition NodeType.h:83
bool isMultiInputPortAt(unsigned int inputIndex) const
Returns whether the input at this index belongs to the multi input port.
Definition NodeType.h:99
std::string iconPath
The icon file relative to the folder, empty when the node ships none.
Definition NodeType.h:63
std::string childScopeType
The kind of scope this node holds inside it, empty when it holds none.
Definition NodeType.h:74
const InputPort * getPortAt(unsigned int inputIndex) const
Returns the port holding an input.
Definition NodeType.h:107