Enzo
Loading...
Searching...
No Matches
Node.h
1#pragma once
2#include "Engine/Core/Path.h"
3#include "Engine/Core/Types.h"
4#include "Engine/Network/CookContext.h"
5#include "Engine/Network/NodePacket.h"
6#include "Engine/Network/NodeType.h"
7#include "Engine/Parameter/NodeParameter.h"
8#include <memory>
9#include <optional>
10#include <string>
11
12namespace enzo::nt {
17class Node
18{
19 public:
31 Node(enzo::nt::NodeId nodeId, const nt::NodeType& nodeType, const Path& path);
32 virtual ~Node() = default;
34 Node(const Node&) = delete;
36 Node& operator=(const Node&) = delete;
37
40 void cook(nt::CookContext& context);
41
49 std::shared_ptr<const enzo::NodePacket> getOutputPacket(unsigned int outputIndex) const;
50
52 void setOutputPacket(unsigned int outputIndex, enzo::NodePacket packet);
53
56 bool outputRequested(unsigned int outputIndex) const;
57
59 std::vector<std::weak_ptr<prm::NodeParameter>> getParameters();
60
64 std::weak_ptr<prm::NodeParameter> getParameter(std::string_view parameterName);
65
68 bool isParameterEnabled(std::string_view parmName);
69
72 bool isParameterHidden(std::string_view parmName);
73
77 std::optional<std::string> getReferencedValue(const std::string& text);
78
81 const std::vector<prm::Template>& getTemplates() const;
82
91 std::string getName() const;
92
94 const Path& getPath() const { return path_; }
95
97 void setPath(const Path& path) { path_ = path; }
98
106 const nt::NodeType& getType() const;
107
115 void dirtyNode(bool dirtyDescendents = true);
116
119 bool isDirty();
120
122 bool takesInput() const;
123
125 unsigned int getMaxOutputs() const;
126
128 Vector2 getPosition() const { return position_; }
130 void setPosition(Vector2 pos) { position_ = pos; }
131
134 boost::signals2::signal<void(nt::NodeId nodeId, bool dirtyDescendents)> nodeDirtied;
135
137 boost::signals2::signal<void(const std::string& parmName)> parameterChanged;
138
139 private:
140 void initParameters();
141
144 bool isComparisonTrue(const std::string& conditionText);
145
147 void onParameterChanged(const std::string& parmName);
148
149 std::vector<std::shared_ptr<prm::NodeParameter>> parameters_;
150 std::vector<std::shared_ptr<const enzo::NodePacket>> outputPackets_;
151 enzo::nt::NodeId nodeId_;
152 const enzo::nt::NodeType& nodeType_;
153 // Full path locating this node within the network, its leaf is the node name
154 Path path_;
155 Vector2 position_{0.f, 0.f};
156 bool dirty_ = true;
157};
158} // namespace enzo::nt
Basic attribute, parameter, and node types for Enzo.
uint64_t NodeId
The unique ID assigned to each node in the network.
Definition Types.h:306
Definition NodePacket.h:9
A default path class for creation and manipulation of tree-based paths.
Definition Path.h:14
The handle a node holds while it cooks to get context about the network.
Definition CookContext.h:23
The unique runtime representation of a node.
Definition Node.h:18
bool takesInput() const
Returns whether the node takes any input at all.
Definition Node.cpp:226
void setPosition(Vector2 pos)
Sets the node's position in the network graph.
Definition Node.h:130
Node & operator=(const Node &)=delete
Deleted copy assignment operator to avoid accidental copies.
bool isDirty()
Returns true if the node is dirty and false if the node is clean (does not need cooking).
Definition Node.cpp:96
std::string getName() const
Returns the runtime name uniquely identifying this node among its siblings (eg. "grid1")
Definition Node.cpp:204
const Path & getPath() const
Returns the full path locating this node within the network.
Definition Node.h:94
Vector2 getPosition() const
Returns the node's position in the network graph.
Definition Node.h:128
const std::vector< prm::Template > & getTemplates() const
Returns the template tree declared by this node's type.
Definition Node.cpp:202
bool isParameterEnabled(std::string_view parmName)
Whether the named parameter's disable condition leaves it enabled.
Definition Node.cpp:166
const nt::NodeType & getType() const
Returns the static type definition this node was created from.
Definition Node.cpp:206
std::weak_ptr< prm::NodeParameter > getParameter(std::string_view parameterName)
Returns a parameter with the given name belonging to this node.
Definition Node.cpp:142
std::shared_ptr< const enzo::NodePacket > getOutputPacket(unsigned int outputIndex) const
Returns the current output geometry.
Definition Node.cpp:110
std::vector< std::weak_ptr< prm::NodeParameter > > getParameters()
Returns all parameters belonging to this node.
Definition Node.cpp:197
Node(const Node &)=delete
Deleted copy constructor to avoid accidental copies.
void dirtyNode(bool dirtyDescendents=true)
Marks the outputed geometry as outdated and notifies the network.
Definition Node.cpp:83
unsigned int getMaxOutputs() const
Returns the number of available outputs the node provides.
Definition Node.cpp:227
std::optional< std::string > getReferencedValue(const std::string &text)
Returns the value text written as prm(name) reads from that parameter, or the text itself when it nam...
Definition Node.cpp:186
boost::signals2::signal< void(nt::NodeId nodeId, bool dirtyDescendents)> nodeDirtied
A signal emitted when the node is dirtied. This will usually notify the NetworkManager.
Definition Node.h:134
void setPath(const Path &path)
Sets the full path locating this node within the network.
Definition Node.h:97
void cook(nt::CookContext &context)
Builds the node's implementation and runs its cook, filling the output packets.
Definition Node.cpp:98
void setOutputPacket(unsigned int outputIndex, enzo::NodePacket packet)
Stores finished geometry against one of the node's outputs.
Definition Node.cpp:120
bool isParameterHidden(std::string_view parmName)
Whether the named parameter's hide condition currently hides it.
Definition Node.cpp:176
boost::signals2::signal< void(const std::string &parmName)> parameterChanged
A signal emitted when one parameter's value changes, carrying its name.
Definition Node.h:137
bool outputRequested(unsigned int outputIndex) const
Returns whether anything downstream is asking for one of the node's outputs.
Definition Node.cpp:136
Node(enzo::nt::NodeId nodeId, const nt::NodeType &nodeType, const Path &path)
Constructs a new node.
Definition Node.cpp:49
Everything every node of one kind shares.
Definition NodeType.h:39