Created
June 5, 2013 19:25
-
-
Save subtleGradient/5716505 to your computer and use it in GitHub Desktop.
MeeMoo.org DataFlow Graph from Quartz Composer QTZ file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var bplistParser = require('bplist-parser') | |
var bplistCreator = require('node-bplist-creator') | |
var fs = require('fs') | |
var DFGraph = {} | |
DFGraph.edgeFromQCConnection = function(qcConnection, connectionKey){ | |
return { | |
source:{node: qcConnection.sourceNode, port:qcConnection.sourcePort}, | |
target:{node: qcConnection.destinationNode, port:qcConnection.destinationPort} | |
} | |
} | |
DFGraph.mergeStateFromQCState = function(state, qcState){ | |
if (!qcState) return | |
Object.keys(qcState).forEach(function(key){ | |
state[key] = qcState[key].value | |
}) | |
} | |
DFGraph.fromQCNode = function(qcNode){ | |
var node = {} | |
node.type = qcNode['class'] | |
node.id = qcNode.key | |
// console.log(qcNode) | |
// console.log(qcNode.state.nodes[0]) | |
// console.log(Object.keys(qcNode.state)) | |
if (qcNode.state.ivarInputPortStates || qcNode.state.systemInputPortStates || qcNode.state.customInputPortStates){ | |
node.state = {} | |
DFGraph.mergeStateFromQCState(node.state, qcNode.state.systemInputPortStates) | |
DFGraph.mergeStateFromQCState(node.state, qcNode.state.ivarInputPortStates) | |
DFGraph.mergeStateFromQCState(node.state, qcNode.state.customInputPortStates) | |
} | |
if (qcNode.state.connections){ | |
node.graph = {} | |
node.graph.nodes = qcNode.state.nodes.map(DFGraph.fromQCNode) | |
// FIXME: support publishedInputPorts and publishedOutputPorts | |
// console.log(qcNode.state.publishedInputPorts) | |
// console.log(qcNode.state.publishedOutputPorts) | |
node.graph.edges = Object.keys(qcNode.state.connections).map(function(connectionKey){ | |
return DFGraph.edgeFromQCConnection(qcNode.state.connections[connectionKey], connectionKey) | |
}) | |
} | |
return node | |
} | |
bplistParser.parseFile(__dirname + '/test/stuff/Basic.qtz', function(error, qtz){ | |
// console.log(qtz[0].rootPatch) | |
var dfGraph = DFGraph.fromQCNode(qtz[0].rootPatch) | |
// console.log(dfGraph) | |
require('fs').writeFile(__dirname + '/test/stuff/Basic.dataflow.json', JSON.stringify(dfGraph, null, 2), function(error){ | |
console.log(error || 'Success') | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
cc @forresto