15 float posY, boost::uuids::uuid nodeID)
16 : mType{std::move(nodeType)},
20 mContext{&mType->context()},
22 mGraphModule{&func->module()} {
23 assert(mType !=
nullptr && mFunction !=
nullptr);
25 mType->mNodeInstance =
this;
37 : mType(other.
type().clone()),
41 mContext{&other.context()},
42 mFunction{&other.function()} {
43 assert(mType !=
nullptr && mFunction !=
nullptr);
45 mType->mNodeInstance =
this;
81 if (conn.first ==
nullptr) {
89 if (newType->dataInputs().size() >
id &&
102 inputDataConnections.resize(newType->dataInputs().size(), std::make_pair(
nullptr, ~0ull));
107 if (newType->dataOutputs().size() >
id &&
113 while (!connSlot.empty()) {
114 assert(connSlot[0].first);
118 assert(res.mSuccess);
122 outputDataConnections.resize(newType->dataOutputs().size());
124 mType = std::move(newType);
125 mType->mNodeInstance =
this;
138 auto dataOutputs = nlohmann::json::array();
140 dataOutputs.push_back({{output.name, output.type.qualifiedName()}});
143 res.
addEntry(
"E22",
"Output Data connection doesn't exist in node",
144 {{
"Requested ID", lhsConnID},
147 {
"Node Output Data Connections", dataOutputs}});
150 auto dataInputs = nlohmann::json::array();
152 dataInputs.push_back({{output.name, output.type.qualifiedName()}});
155 res.
addEntry(
"E23",
"Input Data connection doesn't exist in node",
156 {{
"Requested ID", rhsConnID},
159 {
"Node Input Data Connections", dataInputs}});
163 if (!res) {
return res; }
166 res.
addEntry(
"E24",
"Connecting data nodes with different types is invalid",
167 {{
"Left Hand Type", lhs.
type().
dataOutputs()[lhsConnID].type.qualifiedName()},
168 {
"Right Hand Type", rhs.
type().
dataInputs()[rhsConnID].type.qualifiedName()},
177 if (!res) {
return res; }
195 auto execOutputs = nlohmann::json::array();
196 for (
auto& output : lhs.
type().
execOutputs()) { execOutputs.push_back(output); }
198 res.
addEntry(
"E22",
"Output exec connection doesn't exist in node",
199 {{
"Requested ID", lhsConnID},
201 {
"Node Output Exec Connections", execOutputs}});
204 auto execInputs = nlohmann::json::array();
205 for (
auto& output : rhs.
type().
execInputs()) { execInputs.push_back(output); }
207 res.
addEntry(
"E23",
"Input exec connection doesn't exist in node",
208 {{
"Requested ID", lhsConnID},
210 {
"Node Input Exec Connections", execInputs}
215 if (!res) {
return res; }
219 if (!res) {
return res; }
237 auto dataOutputs = nlohmann::json::array();
239 dataOutputs.push_back({{output.name, output.type.qualifiedName()}});
242 res.
addEntry(
"E22",
"Output data connection in node doesn't exist",
243 {{
"Requested ID", lhsConnID},
246 {
"Node Output Data Connections", dataOutputs}});
254 [&](
auto& pair) {
return pair.first == &rhs; });
257 res.
addEntry(
"EUKN",
"Cannot disconnect from connection that doesn't exist",
260 {
"Left dock ID", lhsConnID}});
266 auto dataInputs = nlohmann::json::array();
268 dataInputs.push_back({{output.name, output.type.qualifiedName()}});
271 res.
addEntry(
"E23",
"Input Data connection doesn't exist in node",
272 {{
"Requested ID", iter->second},
275 {
"Node Input Data Connections", dataInputs}});
281 res.
addEntry(
"EUKN",
"Cannot disconnect from connection that doesn't exist",
300 auto execOutputs = nlohmann::json::array();
301 for (
auto& output : lhs.
type().
execOutputs()) { execOutputs.push_back(output); }
303 res.
addEntry(
"E22",
"Output exec connection doesn't exist in node",
304 {{
"Requested ID", lhsConnID},
306 {
"Node Output Exec Connections", execOutputs}});
310 auto& rhsconns = lhsconn.first->inputExecConnections[lhsconn.second];
312 auto iter = std::find_if(rhsconns.begin(), rhsconns.end(),
313 [&](
auto pair) {
return pair == std::make_pair(&lhs, lhsConnID); });
315 if (iter == rhsconns.end()) {
316 res.
addEntry(
"EUKN",
"Cannot disconnect an exec connection that doesn't connect back",
317 {{
"Left node ID", lhs.
stringId()}, {
"Left node dock id", lhsConnID}});
321 rhsconns.erase(iter);
322 lhsconn = {
nullptr, ~0ull};
const std::vector< std::string > & execInputs() const
Get the execution inputs for the node.
std::vector< std::vector< std::pair< NodeInstance *, size_t > > > inputExecConnections
The connections that lead to this node, exec.
Defines functions for validating GraphFunction objects.
this is an AST-like representation of a function in a graph It is used for IDE-like behavior...
void addEntry(const char *ec, const char *overview, nlohmann::json data)
Add a entry to the result, either a warning or an error.
void setType(std::unique_ptr< NodeType > newType)
Set the type of the node instance.
std::string stringId() const
Get the ID as a string.
Defines the Result class and related functions.
std::vector< std::vector< std::pair< NodeInstance *, size_t > > > outputDataConnections
The connections that lead out of this node, data.
const std::vector< NamedDataType > & dataOutputs() const
Get the data outputs for the node.
NodeType & type()
Get the type of the instance.
std::vector< std::pair< NodeInstance *, size_t > > inputDataConnections
The connections that go into this node, data.
GraphModule & module() const
Get the containing GraphModule.
NodeInstance(GraphFunction *func, std::unique_ptr< NodeType > nodeType, float posX, float posY, boost::uuids::uuid nodeID=boost::uuids::random_generator()())
Construct a nodeinstace with a type location and an ID, usually called from GraphFunction::insertNode...
virtual nlohmann::json toJSON() const
Create the JSON necessary to store the object.
const std::vector< std::string > & execOutputs() const
Get the execution outputs for the node.
~NodeInstance()
Destructor.
Result disconnectData(NodeInstance &lhs, size_t lhsConnID, NodeInstance &rhs)
Disconnect a data connection.
Result connectData(NodeInstance &lhs, size_t lhsConnID, NodeInstance &rhs, size_t rhsConnID)
Connects two nodes' data connections.
Result connectExec(NodeInstance &lhs, size_t lhsConnID, NodeInstance &rhs, size_t rhsConnID)
Connects two nodes' exec connections.
GraphFunction & function() const
Get the containing GraphFunction.
Defines the NodeType class.
Defines the DataType class.
void updateLastEditTime(std::time_t newLastEditTime=std::time(nullptr))
Update the last edit time, signifying that it's been edited.
std::vector< std::pair< NodeInstance *, size_t > > outputExecConnections
The connections that go out of this node, exec.
const std::vector< NamedDataType > & dataInputs() const
Get the data inputs for the node.
Result disconnectExec(NodeInstance &lhs, size_t lhsConnID)
Disconnect a exec connection.
Defines the GraphModule class.
float x() const
Get the X location of the instance.
The namespace where chigraph lives.
std::string qualifiedName() const
Get the qualified name of the node type, like module.name():name()
boost::uuids::uuid id() const
Get the ID of the instance, unique to the graph.
The result object, used for identifiying errors with good diagnostics.
Declares the GraphFunction class.
Defines the NodeInstance class and related functions.