| 178 | } |
| 179 | |
| 180 | NodeDefPtr Document::addNodeDefFromGraph(NodeGraphPtr nodeGraph, const string& nodeDefName, |
| 181 | const string& category, const string& newGraphName) |
| 182 | { |
| 183 | if (category.empty()) |
| 184 | { |
| 185 | throw Exception("Cannot create a nodedef without a category identifier"); |
| 186 | } |
| 187 | |
| 188 | if (getNodeDef(nodeDefName)) |
| 189 | { |
| 190 | throw Exception("Cannot create duplicate nodedef: " + nodeDefName); |
| 191 | } |
| 192 | |
| 193 | if (getNodeGraph(newGraphName)) |
| 194 | { |
| 195 | throw Exception("Cannot create duplicate nodegraph: " + newGraphName); |
| 196 | } |
| 197 | |
| 198 | // Create a new functional nodegraph, and copy over the |
| 199 | // contents from the compound nodegraph |
| 200 | NodeGraphPtr graph = addNodeGraph(newGraphName); |
| 201 | graph->copyContentFrom(nodeGraph); |
| 202 | |
| 203 | for (auto graphChild : graph->getChildren()) |
| 204 | { |
| 205 | graphChild->removeAttribute(Element::XPOS_ATTRIBUTE); |
| 206 | graphChild->removeAttribute(Element::YPOS_ATTRIBUTE); |
| 207 | } |
| 208 | graph->setNodeDefString(nodeDefName); |
| 209 | |
| 210 | // Create a new nodedef and set its category |
| 211 | NodeDefPtr nodeDef = addNodeDef(nodeDefName, EMPTY_STRING); |
| 212 | nodeDef->setNodeString(category); |
| 213 | |
| 214 | // Expose any existing interfaces from the graph. |
| 215 | // Any connection attributes ("nodegraph", "nodename", "interfacename") on the |
| 216 | // existing interface should be removed from the definition as well as any source URI. |
| 217 | |
| 218 | // Attributes which should not be copied over |
| 219 | StringSet filterAttributes = { PortElement::NODE_GRAPH_ATTRIBUTE, PortElement::NODE_NAME_ATTRIBUTE, |
| 220 | PortElement::INTERFACE_NAME_ATTRIBUTE, Element::XPOS_ATTRIBUTE, Element::YPOS_ATTRIBUTE }; |
| 221 | |
| 222 | // Transfer input interface from the graph to the nodedef |
| 223 | for (InputPtr input : graph->getInputs()) |
| 224 | { |
| 225 | InputPtr nodeDefInput = nodeDef->addInput(input->getName(), input->getType()); |
| 226 | if (nodeDefInput) |
| 227 | { |
| 228 | nodeDefInput->copyContentFrom(input); |
| 229 | for (const string& filterAttribute : filterAttributes) |
| 230 | { |
| 231 | nodeDefInput->removeAttribute(filterAttribute); |
| 232 | } |
| 233 | nodeDefInput->setSourceUri(EMPTY_STRING); |
| 234 | input->setInterfaceName(nodeDefInput->getName()); |
| 235 | } |
| 236 | } |
| 237 | // Remove interfaces from the nodegraph |
no test coverage detected