Browse Source

Fixed: issue #92 - testing for input/output nodes - if none found, the export is not possible

Fixed: issue #56 - import and cut, copy & paste works fine, I added a routine which increments the numbers at the end of the names, IDs will be generated automaticcaly, if the ID already exists, and the appropriate name will be increased (e.g. "mixerRight" -> "mixerRight0", "input3" -> "input4" etc.)
dds
Manfred Müller-Späth 9 years ago
parent
commit
f5b7c2abdf
4 changed files with 82 additions and 16 deletions
  1. +15
    -4
      gui/index.html
  2. +15
    -1
      gui/red/main.js
  3. +50
    -9
      gui/red/nodes.js
  4. +2
    -2
      gui/red/ui/view.js

+ 15
- 4
gui/index.html View File

<div id="node-dialog-confirm-deploy" class="hide"> <div id="node-dialog-confirm-deploy" class="hide">
<form class="form-horizontal"> <form class="form-horizontal">
<div id="node-dialog-confirm-deploy-config" style="text-align: center; padding-top: 30px;"> <div id="node-dialog-confirm-deploy-config" style="text-align: center; padding-top: 30px;">
Some of the nodes are not properly configured. Are you sure you want to deploy?
Some of the nodes are not properly configured. Are you sure you want to deploy?
</div> </div>
<div id="node-dialog-confirm-deploy-unknown" style="text-align: center; padding-top: 10px;"> <div id="node-dialog-confirm-deploy-unknown" style="text-align: center; padding-top: 10px;">
The workspace contains some unknown node types:
<ul style="width: 300px; margin: auto; text-align: left;" id="node-dialog-confirm-deploy-unknown-list"></ul>
Are you sure you want to deploy?
The workspace contains some unknown node types:
<ul style="width: 300px; margin: auto; text-align: left;" id="node-dialog-confirm-deploy-unknown-list"></ul>
Are you sure you want to deploy?
</div>
</form>
</div>

<div id="node-dialog-error-deploy" class="hide">
<form class="form-horizontal">
<div id="node-dialog-error-deploy-noio" style="text-align: center; padding-top: 10px;">
<p>The workspace contains no input/output nodes!</p>
<p>You need an input or an output to export the data!</p>
<p>Without such a input/output function the exported
code will not run properly!</p>
</div> </div>
</form> </form>
</div> </div>

+ 15
- 1
gui/red/main.js View File

function save(force) { function save(force) {
RED.storage.update(); RED.storage.update();


if (1) {
if (RED.nodes.hasIO()) {
var nns = RED.nodes.createCompleteNodeSet(); var nns = RED.nodes.createCompleteNodeSet();
// sort by horizontal position, plus slight vertical position, // sort by horizontal position, plus slight vertical position,
// for well defined update order that follows signal flow // for well defined update order that follows signal flow
$( "#dialog" ).dialog("option","title","Export to Arduino").dialog( "open" ); $( "#dialog" ).dialog("option","title","Export to Arduino").dialog( "open" );
}); });
//RED.view.dirty(false); //RED.view.dirty(false);
} else {
$( "#node-dialog-error-deploy" ).dialog({
title: "Error exporting data to Arduino IDE",
modal: true,
autoOpen: false,
width: 410,
height: 245,
buttons: [{
text: "Ok",
click: function() {
$( this ).dialog( "close" );
}
}]
}).dialog("open");
} }
} }



+ 50
- 9
gui/red/nodes.js View File

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
}; };

+ 2
- 2
gui/red/ui/view.js View File



if ($("#node-input-arduino").prop('checked') === true) { if ($("#node-input-arduino").prop('checked') === true) {
var nodesJSON = RED.nodes.cppToJSON(newNodesStr); var nodesJSON = RED.nodes.cppToJSON(newNodesStr);
if (nodesJSON.count <= 0 || nodesJSON.skipped > 0) {
var note = "No (or not all) nodes imported, because some IDs existed already!";
if (nodesJSON.count <= 0) {
var note = "No nodes imported!";
RED.notify("<strong>Note</strong>: " + note, "warning"); RED.notify("<strong>Note</strong>: " + note, "warning");
} }



Loading…
Cancel
Save