Преглед изворни кода

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 година
родитељ
комит
f5b7c2abdf
4 измењених фајлова са 82 додато и 16 уклоњено
  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 Прегледај датотеку

@@ -154,12 +154,23 @@ span.mainfunction {color: #993300; font-weight: bolder}
<div id="node-dialog-confirm-deploy" class="hide">
<form class="form-horizontal">
<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 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>
</form>
</div>

+ 15
- 1
gui/red/main.js Прегледај датотеку

@@ -48,7 +48,7 @@ var RED = (function() {
function save(force) {
RED.storage.update();

if (1) {
if (RED.nodes.hasIO()) {
var nns = RED.nodes.createCompleteNodeSet();
// sort by horizontal position, plus slight vertical position,
// for well defined update order that follows signal flow
@@ -129,6 +129,20 @@ var RED = (function() {
$( "#dialog" ).dialog("option","title","Export to Arduino").dialog( "open" );
});
//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 Прегледај датотеку

@@ -68,6 +68,24 @@ RED.nodes = (function() {
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) {
return node_defs[type];
}
@@ -111,6 +129,17 @@ RED.nodes = (function() {
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) {
if (id in configNodes) {
@@ -125,6 +154,15 @@ RED.nodes = (function() {
return null;
}

function getNodeByName(name) {
for (var n in nodes) {
if (nodes[n].name == name) {
return nodes[n];
}
}
return null;
}

function removeNode(id) {
var removedLinks = [];
if (id in configNodes) {
@@ -318,10 +356,8 @@ RED.nodes = (function() {
function cppToJSON(newNodesStr) {

var newNodes = [];
var skipped = [];
var cables = [];
var words = [];
var lastY = 0;

const NODE_COMMENT = "//";
const NODE_AC = "AudioConnection";
@@ -383,13 +419,14 @@ RED.nodes = (function() {
var newY = parseInt(coords ? coords[1] : 0);
//newY = newY == 0 ? lastY + (dH * n) + gap : 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) {
skipped.push(node.id);
} else {
newNodes.push(node);
node.z = RED.view.getWorkspace();
node.id = getID();
node.name = getUniqueName(node);
}
newNodes.push(node);
}
}
};
@@ -449,7 +486,8 @@ RED.nodes = (function() {

// ... and it has to end with an semikolon ...
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();
if (words.indexOf(word) >= 0) {
parseLine(line);
@@ -491,7 +529,6 @@ RED.nodes = (function() {

return {
count: newNodes.length,
skipped: skipped.length,
data: newNodes.length > 0 ? JSON.stringify(newNodes) : ""
};
}
@@ -610,6 +647,8 @@ RED.nodes = (function() {
}
}

node.name = getUniqueName(n);

addNode(node);
RED.editor.validateNode(node);
node_map[n.id] = node;
@@ -672,6 +711,7 @@ RED.nodes = (function() {
}
},
node: getNode,
namedNode: getNodeByName,
cppToJSON: cppToJSON,
import: importNodes,
refreshValidation: refreshValidation,
@@ -680,6 +720,7 @@ RED.nodes = (function() {
createCompleteNodeSet: createCompleteNodeSet,
id: getID,
cppName: createUniqueCppName,
hasIO: checkForIO,
nodes: nodes, // TODO: exposed for d3 vis
links: links // TODO: exposed for d3 vis
};

+ 2
- 2
gui/red/ui/view.js Прегледај датотеку

@@ -1492,8 +1492,8 @@ RED.view = (function() {

if ($("#node-input-arduino").prop('checked') === true) {
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");
}


Loading…
Откажи
Сачувај