|
|
|
|
|
|
|
|
return name; |
|
|
return name; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function getUniqueName(n) { |
|
|
|
|
|
var newName = n.name; |
|
|
|
|
|
if (typeof newName === "string") { |
|
|
|
|
|
var parts = newName.match(/(\d*)$/); |
|
|
|
|
|
var count = 0; |
|
|
|
|
|
var base = newName; |
|
|
|
|
|
if (parts) { |
|
|
|
|
|
count = isNaN(parseInt(parts[1])) ? 0 : parseInt(parts[1]); |
|
|
|
|
|
base = newName.replace(count, ""); |
|
|
|
|
|
} |
|
|
|
|
|
while (RED.nodes.namedNode(newName) !== null) { |
|
|
|
|
|
count += 1; |
|
|
|
|
|
newName = base + count; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
return newName; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
function getType(type) { |
|
|
function getType(type) { |
|
|
return node_defs[type]; |
|
|
return node_defs[type]; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
configNodes[c.id] = c; |
|
|
configNodes[c.id] = c; |
|
|
} |
|
|
} |
|
|
*/ |
|
|
*/ |
|
|
|
|
|
function checkForIO() { |
|
|
|
|
|
var hasIO = false; |
|
|
|
|
|
RED.nodes.eachNode(function (node) { |
|
|
|
|
|
|
|
|
|
|
|
if ((node._def.category === "input-function") || |
|
|
|
|
|
(node._def.category === "output-function")) { |
|
|
|
|
|
hasIO = true; |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|
return hasIO; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
function getNode(id) { |
|
|
function getNode(id) { |
|
|
if (id in configNodes) { |
|
|
if (id in configNodes) { |
|
|
|
|
|
|
|
|
return null; |
|
|
return null; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function getNodeByName(name) { |
|
|
|
|
|
for (var n in nodes) { |
|
|
|
|
|
if (nodes[n].name == name) { |
|
|
|
|
|
return nodes[n]; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
return null; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
function removeNode(id) { |
|
|
function removeNode(id) { |
|
|
var removedLinks = []; |
|
|
var removedLinks = []; |
|
|
if (id in configNodes) { |
|
|
if (id in configNodes) { |
|
|
|
|
|
|
|
|
function cppToJSON(newNodesStr) { |
|
|
function cppToJSON(newNodesStr) { |
|
|
|
|
|
|
|
|
var newNodes = []; |
|
|
var newNodes = []; |
|
|
var skipped = []; |
|
|
|
|
|
var cables = []; |
|
|
var cables = []; |
|
|
var words = []; |
|
|
var words = []; |
|
|
var lastY = 0; |
|
|
|
|
|
|
|
|
|
|
|
const NODE_COMMENT = "//"; |
|
|
const NODE_COMMENT = "//"; |
|
|
const NODE_AC = "AudioConnection"; |
|
|
const NODE_AC = "AudioConnection"; |
|
|
|
|
|
|
|
|
var newY = parseInt(coords ? coords[1] : 0); |
|
|
var newY = parseInt(coords ? coords[1] : 0); |
|
|
//newY = newY == 0 ? lastY + (dH * n) + gap : newY; |
|
|
//newY = newY == 0 ? lastY + (dH * n) + gap : newY; |
|
|
//lastY = Math.max(lastY, newY); |
|
|
//lastY = Math.max(lastY, newY); |
|
|
var node = new Object({"order": n, "id": name, "type": type, "x": newX, "y": newY, "z": 0, "wires": []}); |
|
|
|
|
|
// first solution: skip existing id |
|
|
|
|
|
|
|
|
var node = new Object({"order": n, "id": name, "name": name, "type": type, "x": newX, "y": newY, "z": 0, "wires": []}); |
|
|
|
|
|
// netter solution: create new id |
|
|
if (RED.nodes.node(node.id) !== null) { |
|
|
if (RED.nodes.node(node.id) !== null) { |
|
|
skipped.push(node.id); |
|
|
|
|
|
} else { |
|
|
|
|
|
newNodes.push(node); |
|
|
|
|
|
|
|
|
node.z = RED.view.getWorkspace(); |
|
|
|
|
|
node.id = getID(); |
|
|
|
|
|
node.name = getUniqueName(node); |
|
|
} |
|
|
} |
|
|
|
|
|
newNodes.push(node); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ... and it has to end with an semikolon ... |
|
|
// ... and it has to end with an semikolon ... |
|
|
var pattSe = new RegExp(/.*;$/); |
|
|
var pattSe = new RegExp(/.*;$/); |
|
|
if (pattSe.test(line)) { |
|
|
|
|
|
|
|
|
var pattCoord = new RegExp(/.*\/\/xy=\d+,\d+$/); |
|
|
|
|
|
if (pattSe.test(line) || pattCoord.test(line)) { |
|
|
var word = parts[1].trim(); |
|
|
var word = parts[1].trim(); |
|
|
if (words.indexOf(word) >= 0) { |
|
|
if (words.indexOf(word) >= 0) { |
|
|
parseLine(line); |
|
|
parseLine(line); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return { |
|
|
return { |
|
|
count: newNodes.length, |
|
|
count: newNodes.length, |
|
|
skipped: skipped.length, |
|
|
|
|
|
data: newNodes.length > 0 ? JSON.stringify(newNodes) : "" |
|
|
data: newNodes.length > 0 ? JSON.stringify(newNodes) : "" |
|
|
}; |
|
|
}; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
node.name = getUniqueName(n); |
|
|
|
|
|
|
|
|
addNode(node); |
|
|
addNode(node); |
|
|
RED.editor.validateNode(node); |
|
|
RED.editor.validateNode(node); |
|
|
node_map[n.id] = node; |
|
|
node_map[n.id] = node; |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
}, |
|
|
}, |
|
|
node: getNode, |
|
|
node: getNode, |
|
|
|
|
|
namedNode: getNodeByName, |
|
|
cppToJSON: cppToJSON, |
|
|
cppToJSON: cppToJSON, |
|
|
import: importNodes, |
|
|
import: importNodes, |
|
|
refreshValidation: refreshValidation, |
|
|
refreshValidation: refreshValidation, |
|
|
|
|
|
|
|
|
createCompleteNodeSet: createCompleteNodeSet, |
|
|
createCompleteNodeSet: createCompleteNodeSet, |
|
|
id: getID, |
|
|
id: getID, |
|
|
cppName: createUniqueCppName, |
|
|
cppName: createUniqueCppName, |
|
|
|
|
|
hasIO: checkForIO, |
|
|
nodes: nodes, // TODO: exposed for d3 vis |
|
|
nodes: nodes, // TODO: exposed for d3 vis |
|
|
links: links // TODO: exposed for d3 vis |
|
|
links: links // TODO: exposed for d3 vis |
|
|
}; |
|
|
}; |