Browse Source

Gui - requirements

Step #1
Load and check for requirements.
Output - at the moment - on Javascript console.
Step #2: Make conflicts visible (with an Icon), and with a Text-Hint, eventually

Test here: https://forum.pjrc.com/threads/60109-Audio-GUI-for-T4?p=241364&viewfull=1#post241364
dds
Frank Bösing 4 years ago
parent
commit
f88a09f8a3
3 changed files with 56 additions and 19 deletions
  1. BIN
      gui/icons/attention.png
  2. +4
    -0
      gui/red/main.js
  3. +52
    -19
      gui/red/ui/view.js

BIN
gui/icons/attention.png View File

Before After
Width: 880  |  Height: 833  |  Size: 87KB

+ 4
- 0
gui/red/main.js View File

var server = false && patt.test(location.protocol); var server = false && patt.test(location.protocol);


if (!server) { if (!server) {
var metaData = $.parseJSON($("script[data-container-name|='InputOutputCompatibilityMetadata']").html());
requirements = metaData["requirements"];
var data = $.parseJSON($("script[data-container-name|='NodeDefinitions']").html()); var data = $.parseJSON($("script[data-container-name|='NodeDefinitions']").html());
var nodes = data["nodes"]; var nodes = data["nodes"];
$.each(nodes, function (key, val) { $.each(nodes, function (key, val) {

+ 52
- 19
gui/red/ui/view.js View File

scaleFactor = 1, scaleFactor = 1,
node_width = 100, node_width = 100,
node_height = 30; node_height = 30;
var touchLongPressTimeout = 1000, var touchLongPressTimeout = 1000,
startTouchDistance = 0, startTouchDistance = 0,
startTouchCenter = [], startTouchCenter = [],
lasso.remove(); lasso.remove();
lasso = null; lasso = null;
} }
if (!touchStartTime) { if (!touchStartTime) {
var point = d3.mouse(this); var point = d3.mouse(this);
lasso = vis.append('rect') lasso = vis.append('rect')
var minX = 0; var minX = 0;
var minY = 0; var minY = 0;
var node; var node;
for (var i=0;i<moving_set.length;i++) { for (var i=0;i<moving_set.length;i++) {
node = moving_set[i]; node = moving_set[i];
if (node.ox == null && node.oy == null) { if (node.ox == null && node.oy == null) {


dblClickPrimed = (lastClickNode == mousedown_node); dblClickPrimed = (lastClickNode == mousedown_node);
lastClickNode = mousedown_node; lastClickNode = mousedown_node;
var i; var i;
if (d.selected && d3.event.ctrlKey) { if (d.selected && d3.event.ctrlKey) {
d.selected = false; d.selected = false;
for (i=0;i<moving_set.length;i+=1) { for (i=0;i<moving_set.length;i+=1) {
options.push({name:"edit",disabled:(moving_set.length != 1),onselect:function() { RED.editor.edit(mdn);}}); options.push({name:"edit",disabled:(moving_set.length != 1),onselect:function() { RED.editor.edit(mdn);}});
options.push({name:"select",onselect:function() {selectAll();}}); options.push({name:"select",onselect:function() {selectAll();}});
options.push({name:"undo",disabled:(RED.history.depth() === 0),onselect:function() {RED.history.pop();}}); options.push({name:"undo",disabled:(RED.history.depth() === 0),onselect:function() {RED.history.pop();}});
RED.touch.radialMenu.show(obj,pos,options); RED.touch.radialMenu.show(obj,pos,options);
resetMouseVars(); resetMouseVars();
} }
//var l = d._def.label; //var l = d._def.label;
//l = (typeof l === "function" ? l.call(d) : l)||""; //l = (typeof l === "function" ? l.call(d) : l)||"";
var l = d.name ? d.name : d.id; var l = d.name ? d.name : d.id;


/**********************************************************************/
//Add requirements
d.requirementError = false;
d.requirements = new Array();
requirements.forEach(function(r) {
if (r.type == d.type) d.requirements.push(r);
});

//check for conflicts with other nodes:
d.requirements.forEach(function(r) {
RED.nodes.eachNode(function (n2) {
if (n2 != d && n2.requirements != null ) {
n2.requirements.forEach(function(r2) {
if (r["resource"] == r2["resource"]) {
if (r["shareable"] == false) {
console.log("Conflict: shareable '"+r["resource"]+"' "+d.name+" and "+n2.name);
d.requirementError = true;
}
else
if (r["setting"] != r2["setting"]) {
console.log("Conflict: "+ d.name + " setting['"+r["setting"]+"'] and "+n2.name+" setting['"+r2["setting"]+"']");
d.requirementError = true;
}
}
});
}
});
});

/**********************************************************************/

d.w = Math.max(node_width,calculateTextWidth(l)+(d._def.inputs>0?7:0) ); d.w = Math.max(node_width,calculateTextWidth(l)+(d._def.inputs>0?7:0) );
d.h = Math.max(node_height,(Math.max(d.outputs,d._def.inputs)||0) * 15); d.h = Math.max(node_height,(Math.max(d.outputs,d._def.inputs)||0) * 15);


touchStartTime = setTimeout(function() { touchStartTime = setTimeout(function() {
showTouchMenu(obj,pos); showTouchMenu(obj,pos);
},touchLongPressTimeout); },touchLongPressTimeout);
nodeMouseDown.call(this,d)
nodeMouseDown.call(this,d)
}) })
.on("touchend", function(d) { .on("touchend", function(d) {
clearTimeout(touchStartTime); clearTimeout(touchStartTime);
//node.append("rect").attr("class", "node-gradient-bottom").attr("rx", 6).attr("ry", 6).attr("height",30).attr("stroke","none").attr("fill","url(#gradient-bottom)").style("pointer-events","none"); //node.append("rect").attr("class", "node-gradient-bottom").attr("rx", 6).attr("ry", 6).attr("height",30).attr("stroke","none").attr("fill","url(#gradient-bottom)").style("pointer-events","none");


if (d._def.icon) { if (d._def.icon) {
var icon_group = node.append("g") var icon_group = node.append("g")
.attr("class","node_icon_group") .attr("class","node_icon_group")
.attr("x",0).attr("y",0); .attr("x",0).attr("y",0);
var icon_shade = icon_group.append("rect") var icon_shade = icon_group.append("rect")
.attr("x",0).attr("y",0) .attr("x",0).attr("y",0)
.attr("class","node_icon_shade") .attr("class","node_icon_shade")
.attr("fill","#000") .attr("fill","#000")
.attr("fill-opacity","0.05") .attr("fill-opacity","0.05")
.attr("height",function(d){return Math.min(50,d.h-4);}); .attr("height",function(d){return Math.min(50,d.h-4);});
var icon = icon_group.append("image") var icon = icon_group.append("image")
.attr("xlink:href","icons/"+d._def.icon) .attr("xlink:href","icons/"+d._def.icon)
.attr("class","node_icon") .attr("class","node_icon")
.attr("x",0) .attr("x",0)
.attr("width","30") .attr("width","30")
.attr("height","30"); .attr("height","30");
var icon_shade_border = icon_group.append("path") var icon_shade_border = icon_group.append("path")
.attr("d",function(d) { return "M 30 1 l 0 "+(d.h-2)}) .attr("d",function(d) { return "M 30 1 l 0 "+(d.h-2)})
.attr("class","node_icon_shade_border") .attr("class","node_icon_shade_border")
//icon.attr('class','node_icon_shade node_icon_shade_'+d._def.align); //icon.attr('class','node_icon_shade node_icon_shade_'+d._def.align);
//icon.attr('class','node_icon_shade_border node_icon_shade_border_'+d._def.align); //icon.attr('class','node_icon_shade_border node_icon_shade_border_'+d._def.align);
} }
//if (d._def.inputs > 0 && d._def.align == null) { //if (d._def.inputs > 0 && d._def.align == null) {
// icon_shade.attr("width",35); // icon_shade.attr("width",35);
// icon.attr("transform","translate(5,0)"); // icon.attr("transform","translate(5,0)");
//if (d._def.outputs > 0 && "right" == d._def.align) { //if (d._def.outputs > 0 && "right" == d._def.align) {
// icon_shade.attr("width",35); //icon.attr("x",5); // icon_shade.attr("width",35); //icon.attr("x",5);
//} //}
var img = new Image(); var img = new Image();
img.src = "icons/"+d._def.icon; img.src = "icons/"+d._def.icon;
img.onload = function() { img.onload = function() {
// icon_shade_border.attr("d",function(d){return "M "+(d.w-30)+" 1 l 0 "+(d.h-2);}); // icon_shade_border.attr("d",function(d){return "M "+(d.w-30)+" 1 l 0 "+(d.h-2);});
//} //}
}; };
//icon.style("pointer-events","none"); //icon.style("pointer-events","none");
icon_group.style("pointer-events","none"); icon_group.style("pointer-events","none");
} }
//thisNode.selectAll(".node_icon_shade_right").attr("x",function(d){return d.w-30;}); //thisNode.selectAll(".node_icon_shade_right").attr("x",function(d){return d.w-30;});
//thisNode.selectAll(".node_icon_shade_border_right").attr("d",function(d){return "M "+(d.w-30)+" 1 l 0 "+(d.h-2)}); //thisNode.selectAll(".node_icon_shade_border_right").attr("d",function(d){return "M "+(d.w-30)+" 1 l 0 "+(d.h-2)});


var numOutputs = d.outputs; var numOutputs = d.outputs;
var y = (d.h/2)-((numOutputs-1)/2)*13; var y = (d.h/2)-((numOutputs-1)/2)*13;
d.ports = d.ports || d3.range(numOutputs); d.ports = d.ports || d3.range(numOutputs);
thisNode.selectAll(".node_icon_shade").attr("height",function(d){return d.h;}); thisNode.selectAll(".node_icon_shade").attr("height",function(d){return d.h;});
thisNode.selectAll(".node_icon_shade_border").attr("d",function(d){ return "M "+(("right" == d._def.align) ?0:30)+" 1 l 0 "+(d.h-2)}); thisNode.selectAll(".node_icon_shade_border").attr("d",function(d){ return "M "+(("right" == d._def.align) ?0:30)+" 1 l 0 "+(d.h-2)});


thisNode.selectAll('.node_right_button').attr("transform",function(d){ thisNode.selectAll('.node_right_button').attr("transform",function(d){
var x = d.w-6; var x = d.w-6;
if (d._def.button.toggle && !d[d._def.button.toggle]) { if (d._def.button.toggle && !d[d._def.button.toggle]) {
var link = vis.selectAll(".link").data(RED.nodes.links.filter(function(d) { return d.source.z == activeWorkspace && d.target.z == activeWorkspace }),function(d) { return d.source.id+":"+d.sourcePort+":"+d.target.id+":"+d.targetPort;}); var link = vis.selectAll(".link").data(RED.nodes.links.filter(function(d) { return d.source.z == activeWorkspace && d.target.z == activeWorkspace }),function(d) { return d.source.id+":"+d.sourcePort+":"+d.target.id+":"+d.targetPort;});


var linkEnter = link.enter().insert("g",".node").attr("class","link"); var linkEnter = link.enter().insert("g",".node").attr("class","link");
linkEnter.each(function(d,i) { linkEnter.each(function(d,i) {
var l = d3.select(this); var l = d3.select(this);
l.append("svg:path").attr("class","link_background link_path") l.append("svg:path").attr("class","link_background link_path")
* - attached to mouse for placing - 'IMPORT_DRAGGING' * - attached to mouse for placing - 'IMPORT_DRAGGING'
*/ */
function importNodes(newNodesStr,touchImport) { function importNodes(newNodesStr,touchImport) {
var createNewIds = true; var createNewIds = true;
var useStorage = false; var useStorage = false;


var minY = 0; var minY = 0;
var i; var i;
var node; var node;
for (i=0;i<new_ms.length;i++) { for (i=0;i<new_ms.length;i++) {
node = new_ms[i]; node = new_ms[i];
node.n.selected = true; node.n.selected = true;

Loading…
Cancel
Save