| 126 | } |
| 127 | |
| 128 | Result connectData(NodeInstance& lhs, size_t lhsConnID, NodeInstance& rhs, size_t rhsConnID) { |
| 129 | Result res = {}; |
| 130 | |
| 131 | assert(&lhs.function() == &rhs.function()); |
| 132 | |
| 133 | rhs.module().updateLastEditTime(); |
| 134 | |
| 135 | // make sure the connection exists |
| 136 | // the input to the connection is the output to the node |
| 137 | if (lhsConnID >= lhs.outputDataConnections.size()) { |
| 138 | auto dataOutputs = nlohmann::json::array(); |
| 139 | for (auto& output : lhs.type().dataOutputs()) { |
| 140 | dataOutputs.push_back({{output.name, output.type.qualifiedName()}}); |
| 141 | } |
| 142 | |
| 143 | res.addEntry("E22", "Output Data connection doesn't exist in node", |
| 144 | {{"Requested ID", lhsConnID}, |
| 145 | {"Node Type", lhs.type().qualifiedName()}, |
| 146 | {"Node JSON", rhs.type().toJSON()}, |
| 147 | {"Node Output Data Connections", dataOutputs}}); |
| 148 | } |
| 149 | if (rhsConnID >= rhs.inputDataConnections.size()) { |
| 150 | auto dataInputs = nlohmann::json::array(); |
| 151 | for (auto& output : rhs.type().dataInputs()) { |
| 152 | dataInputs.push_back({{output.name, output.type.qualifiedName()}}); |
| 153 | } |
| 154 | |
| 155 | res.addEntry("E23", "Input Data connection doesn't exist in node", |
| 156 | {{"Requested ID", rhsConnID}, |
| 157 | {"Node Type", rhs.type().qualifiedName()}, |
| 158 | {"Node JSON", rhs.type().toJSON()}, |
| 159 | {"Node Input Data Connections", dataInputs}}); |
| 160 | } |
| 161 | |
| 162 | // if there are errors, back out |
| 163 | if (!res) { return res; } |
| 164 | // make sure the connection is of the right type |
| 165 | if (lhs.type().dataOutputs()[lhsConnID].type != rhs.type().dataInputs()[rhsConnID].type) { |
| 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()}, |
| 169 | {"Left Node JSON", rhs.type().toJSON()}, |
| 170 | {"Right Node JSON", rhs.type().toJSON()}}); |
| 171 | return res; |
| 172 | } |
| 173 | |
| 174 | // if we are replacing a connection, disconnect it |
| 175 | if (rhs.inputDataConnections[rhsConnID].first != nullptr) { |
| 176 | res += disconnectData(lhs, lhsConnID, rhs); |
| 177 | if (!res) { return res; } |
| 178 | } |
| 179 | |
| 180 | lhs.outputDataConnections[lhsConnID].emplace_back(&rhs, rhsConnID); |
| 181 | rhs.inputDataConnections[rhsConnID] = {&lhs, lhsConnID}; |
| 182 | |
| 183 | return res; |
| 184 | } |
| 185 |
no test coverage detected