55 if (key in graphDictionary) {
56 graphDictionary[key].push([item, nodetype, type, value]);
58 graphDictionary[key] = [[item, nodetype, type, value]];
71 let parentElem = item.getParent();
72 if (!parentElem || !(parentElem instanceof mx.GraphElement))
return;
74 let key = parentElem.getNamePath();
75 let value = item.getNamePath();
76 let itemType = item.getType();
77 let itemCategory = item.getCategory();
80 if (item instanceof mx.Node) {
81 let inputs = item.getInputs();
82 if (inputs.length === 1) {
83 itemValue = inputs[0].getValueString();
85 }
else if (item instanceof mx.Input) {
86 itemValue = item.getValueString();
180 let root =
doc.getDocument();
181 let port = root.getDescendant(portPath);
183 console.log(
'Element not found:', portPath);
187 if (!(port instanceof mx.Input) && !(port instanceof mx.Output)) {
188 console.log(
'Element is not an input or output');
192 let parent = port.getParent();
193 let parentPath = parent.getNamePath();
196 if ((port instanceof mx.Input) && (parent instanceof mx.NodeGraph)) {
197 parentGraph = parentGraph.getParent();
201 console.log(
'Cannot find parent graph of port', port);
204 let parentGraphPath = parentGraph.getNamePath();
206 let outputName = port.getOutputString();
208 let destNode = portIsNode ? portPath : parentPath;
209 let destPort = portIsNode ?
'' : port.getName();
211 let nodename = port.getAttribute(
'nodename');
214 if (!parentGraphPath) {
215 result = [this.
appendPath(nodename,
''), outputName, destNode, destPort,
'nodename'];
217 result = [this.
appendPath(parentGraphPath, nodename), outputName, destNode, destPort,
'nodename'];
219 connections.push(result);
223 let nodegraph = port.getNodeGraphString();
229 if (!parentGraphPath) {
230 result = [this.
appendPath(nodegraph, outputName),
'', destNode, destPort,
'nodename'];
232 result = [this.
appendPath(parentGraphPath, nodegraph), outputName, destNode, destPort,
'nodegraph'];
234 connections.push(result);
238 let interfaceName = port.getInterfaceName();
241 if (!parentGraphPath) {
245 result = [this.
appendPath(interfaceName, outputName),
'', destNode, destPort,
'nodename'];
249 if (destNode === parentGraphPath +
'/' + interfaceName) {
250 let dictItem = this.graphDictionary[parentGraphPath];
253 for (let item of dictItem) {
254 if (item[0] === parentGraphPath +
'/' + interfaceName) {
260 console.log(
'Warning: Rename duplicate interface:', parentGraphPath +
'/' + interfaceName +
':in');
261 interfaceName = interfaceName +
':in';
267 let dictItem = this.graphDictionary[parentGraphPath];
269 for (let item of dictItem) {
270 if (item[0] === parentGraphPath +
'/' + interfaceName) {
278 this.
updateGraphDictionaryPath(parentGraphPath, parentGraphPath +
'/' + interfaceName,
'input', port.getType(), itemValue,
this.graphDictionary);
280 result = [this.
appendPath(parentGraphPath, interfaceName), outputName, destNode, destPort,
'interfacename'];
282 connections.push(result);
288 if (!parentGraphPath) {
289 result = [this.
appendPath(outputName,
''),
'', parentPath, port.getName(),
'nodename'];
291 result = [this.
appendPath(parentGraphPath, outputName),
'', parentPath, port.getName(),
'output'];
293 connections.push(result);
306 let root =
doc.getDocument();
308 for (let elem of graphElement.getChildren()) {
309 if (!elem.hasSourceUri()) {
310 if (elem instanceof mx.Input) {
312 }
else if (elem instanceof mx.Output) {
314 }
else if (elem instanceof mx.Node) {
315 let nodeInputs = elem.getInputs();
316 for (let nodeInput of nodeInputs) {
319 }
else if (elem instanceof mx.NodeGraph) {
320 let nodedef = elem.getNodeDef();
322 connections.push([elem.getNamePath(),
'', nodedef.getName(),
'',
'nodedef']);
324 let visited =
new Set();
325 let path = elem.getNamePath();
326 if (!visited.has(path)) {
341 let graphDictionary = {};
342 let root =
doc.getDocument();
345 for (let elem of
doc.getChildren()) {
346 if (elem.hasSourceUri()) {
347 skipped.push(elem.getNamePath());
349 if ((elem instanceof mx.Input) || (elem instanceof mx.Output) || (elem instanceof mx.Node)) {
352 }
else if (elem instanceof mx.NodeGraph) {
354 if (elem.getAttribute(
'nodedef')) {
355 let nodeDef = elem.getAttribute(
'nodedef');
356 nodeDef = root.getDescendant(nodeDef);
358 for (let nodeDefInput of nodeDef.getInputs()) {
359 if (elem.getChild(
"def_" + nodeDefInput.getName())) {
362 let newInput = elem.addInput(
"def_" + nodeDefInput.getName(), nodeDefInput.getType());
363 newInput.copyContentFrom(nodeDefInput);
368 for (let node of elem.getInputs()) {
371 for (let node of elem.getOutputs()) {
374 for (let node of elem.getNodes()) {
377 for (let node of elem.getTokens()) {
380 }
else if ((elem instanceof mx.NodeDef) || (elem instanceof mx.Token)) {
386 return graphDictionary;
436 doc:
'Graph connections for: ' + inputFileName,
438 graph: this.graphDictionary,
439 connections: this.connections
445 let dataStr =
"data:text/json;charset=utf-8," + encodeURIComponent(JSON.stringify(data,
null, 2));
446 let downloadAnchorNode = document.createElement(
'a');
447 downloadAnchorNode.setAttribute(
"href", dataStr);
448 downloadAnchorNode.setAttribute(
"download", filename);
449 document.body.appendChild(downloadAnchorNode);
450 downloadAnchorNode.click();
451 downloadAnchorNode.remove();