|
From: <ma...@us...> - 2011-05-11 16:04:22
|
Revision: 330
http://openautomation.svn.sourceforge.net/openautomation/?rev=330&view=rev
Author: mayerch
Date: 2011-05-11 16:04:16 +0000 (Wed, 11 May 2011)
Log Message:
-----------
Added a scope block the Logic Editor (this was quite hackish and has to be cleaned up later)
NOTE: The performance in the browser (expecially FireFox) can get real bad, there's a big optimisation needed
Modified Paths:
--------------
PyWireGate/trunk/logic_editor/backendCommunication.js
PyWireGate/trunk/logic_editor/gle/gle.block.js
PyWireGate/trunk/logic_editor/logicEditor.js
PyWireGate/trunk/logic_server/LogicLibrary.py
PyWireGate/trunk/logik.json
PyWireGate/trunk/logik2.json
Modified: PyWireGate/trunk/logic_editor/backendCommunication.js
===================================================================
--- PyWireGate/trunk/logic_editor/backendCommunication.js 2011-05-10 21:04:09 UTC (rev 329)
+++ PyWireGate/trunk/logic_editor/backendCommunication.js 2011-05-11 16:04:16 UTC (rev 330)
@@ -282,14 +282,16 @@
// tweak backend communication, should also be done on demand
live = new CometVisu( '/live/' );
liveUpdateCalls = [];
+count = 10;
live.update = function( json )
{
$.each( liveUpdateCalls, function(){
- for( var i = json.length-1; i >= 0; i-- )
+ for( var i = 0; i < json.length; i++ )
{
- if( json[i].block == this[0] )
+ var last = i == json.length-1;
+ if( json[i].block == this[0] && ( last || !this[1] ) )
{
- this[1]( json[i].value );
+ this[2]( json[i].value );
}
}
});
Modified: PyWireGate/trunk/logic_editor/gle/gle.block.js
===================================================================
--- PyWireGate/trunk/logic_editor/gle/gle.block.js 2011-05-10 21:04:09 UTC (rev 329)
+++ PyWireGate/trunk/logic_editor/gle/gle.block.js 2011-05-11 16:04:16 UTC (rev 330)
@@ -50,6 +50,8 @@
var parameters = prototype.parameters || {};
var parameter = prototype.parameter || createParameter( prototype.parameters );
var postParameterUpdateFn = maskOptions.postParameterUpdate;
+ var cElem = false; // if that block has a <canvas> it's cached here
+ var cCtx = false; // as well as it's context
var canvas = svg || $('#editor').svg('get');
var addEvent = interactive !== undefined ? interactive : true;
@@ -85,8 +87,28 @@
// Draw the body
//var body = canvas.group( g, {'transform':'translate(6,1)'} );
var body = canvas.group( g );
- if( mask )
+ if( 'MainLib/scope' == type )
{
+ gB = body;
+ var xhtmlNS = 'http://www.w3.org/1999/xhtml',
+ svgNS = 'http://www.w3.org/2000/svg',
+ xlinkNS = 'http://www.w3.org/1999/xlink';
+ var f = document.createElementNS( svgNS, 'foreignObject' );
+ f.x.baseVal.value = 0;
+ f.y.baseVal.value = 0;
+ f.width.baseVal.value = width;
+ f.height.baseVal.value = height;
+ var c = document.createElementNS( xhtmlNS, 'canvas' );
+ c.width = width;
+ c.height = height;
+ var foObj = body.appendChild(f);
+ cElem = foObj.appendChild(c);
+ cCtx = cElem.getContext( '2d' );
+ cCtx.fillStyle="rgba(0,0,0,255)";
+ cCtx.fillRect(0,0,width,height);
+ }
+ else if( mask )
+ {
var path = canvas.createPath();
for( var i in mask )
{
@@ -223,14 +245,30 @@
}
// private function for live updating of param = {'text-anchor':'start'}a display
+ var scopeLastX = -1;
this._updateValue = function( value )
{
- if( g )
+ if( 'MainLib/scope' == type )
{
- //console.log( '_updateValue', value.toString(), g, 10, height/2 );
- $( g ).find( '.valueString').remove();
- param = {'text-anchor':'start','class':'valueString'};
- canvas.text( g, 10, height/2, value.toString(), param );
+ scopeLastX = ( scopeLastX + 1 ) % width;
+ var thisY = Math.round( (2.0+value)*(height/4.0) );
+ var imgdA = cCtx.getImageData( 0, 0, width-1, height );
+ cCtx.putImageData( imgdA, 1, 0 );
+ var imgdI = cCtx.createImageData( 1, height );
+ var pix = imgdI.data;
+ for( var i = 0; i < height; i++ )
+ pix[ 4 * i + 3 ] = 255; // set alpha
+ pix[ 4 * thisY + 0 ] = 0 ; // red
+ pix[ 4 * thisY + 1 ] = 255; // green
+ pix[ 4 * thisY + 2 ] = 0 ; // blue
+ cCtx.putImageData( imgdI, 0, 0 );
+ } else {
+ if( g )
+ {
+ $( g ).find( '.valueString').remove();
+ param = {'text-anchor':'start','class':'valueString'};
+ canvas.text( g, 10, height/2, value.toString(), param );
+ }
}
}
Modified: PyWireGate/trunk/logic_editor/logicEditor.js
===================================================================
--- PyWireGate/trunk/logic_editor/logicEditor.js 2011-05-10 21:04:09 UTC (rev 329)
+++ PyWireGate/trunk/logic_editor/logicEditor.js 2011-05-11 16:04:16 UTC (rev 330)
@@ -200,10 +200,11 @@
var b = new Block( element, svg, addEvent );
if( addEvent ) blockRegistry[ element.name ] = b;
// FIXME this should become more generalized
- if( 'MainLib/display' == element.type ) // make display interactive
+ if( 'MainLib/display' == element.type || 'MainLib/scope' == element.type ) // make display and scope interactive
{
liveUpdateCalls.push( [
b.getName(),
+ 'MainLib/display' == element.type,
b._updateValue
] );
}
Modified: PyWireGate/trunk/logic_server/LogicLibrary.py
===================================================================
--- PyWireGate/trunk/logic_server/LogicLibrary.py 2011-05-10 21:04:09 UTC (rev 329)
+++ PyWireGate/trunk/logic_server/LogicLibrary.py 2011-05-11 16:04:16 UTC (rev 330)
@@ -37,6 +37,16 @@
#_codingInstructions = lambda s, n, i, o, p: ( None, "print __time,',','\"%%s\"' %% globalVariables['__name'],',','%s',',',%s" % ( n, i[0]) )
_codingInstructions = lambda s, n, i, o, p: ( None, "inspector['%s'] = %s" % ( n, i[0]) )
+class ScopeBlock( LogicModule.LogicModule ):
+ _name = "scope"
+ _inPorts = [ 'in' ]
+ _outPorts = []
+ _parameters = []
+ _drawingInstructions = ""
+ _maskOptions = { 'showLabel': False }
+ _codingInstructions = lambda s, n, i, o, p: ( None, "inspector['%s'] = %s" % ( n, i[0]) )
+
+
class GainBlock( LogicModule.LogicModule ):
_name = "gain"
_inPorts = [ 'in' ]
@@ -80,6 +90,7 @@
def __init__( self ):
self.addBlock( ConstBlock )
self.addBlock( DisplayBlock )
+ self.addBlock( ScopeBlock )
self.addBlock( GainBlock )
self.addBlock( SumBlock )
self.addBlock( MemoryBlock )
Modified: PyWireGate/trunk/logik.json
===================================================================
--- PyWireGate/trunk/logik.json 2011-05-10 21:04:09 UTC (rev 329)
+++ PyWireGate/trunk/logik.json 2011-05-11 16:04:16 UTC (rev 330)
@@ -38,8 +38,13 @@
},
"Display3": {
"type": "MainLib/display",
- "x": 250, "y": 250, "width": 150, "height": 50,
+ "x": 250, "y": 350, "width": 150, "height": 50,
"parameters": {}
+ },
+ "Scope_1": {
+ "type": "MainLib/scope",
+ "x": 500, "y": 125, "width": 600, "height": 300,
+ "parameters": {}
}
},
"signals": [
@@ -49,6 +54,7 @@
[ "Integral1", 0, "Integral2" , 0, {} ],
[ "Integral2", 0, "Gain2" , 0, {} ],
[ "Gain2" , 0, "Integral1" , 0, {} ],
- [ "Integral2", 0, "Display3" , 0, {} ]
+ [ "Integral2", 0, "Display3" , 0, {} ],
+ [ "Integral2", 0, "Scope_1" , 0, {} ]
]
}
\ No newline at end of file
Modified: PyWireGate/trunk/logik2.json
===================================================================
--- PyWireGate/trunk/logik2.json 2011-05-10 21:04:09 UTC (rev 329)
+++ PyWireGate/trunk/logik2.json 2011-05-11 16:04:16 UTC (rev 330)
@@ -18,7 +18,7 @@
},
"Display22": {
"type": "MainLib/display",
- "x": 350, "y": 150, "width": 150, "height": 50,
+ "x": 350, "y": 50, "width": 150, "height": 50,
"parameters": {}
},
"Integral2": {
@@ -31,6 +31,11 @@
"x": 150, "y": 50, "width": 50, "height": 50,
"parameters": { "gain": -1.0 },
"flip" : true
+ },
+ "Scope_2": {
+ "type": "MainLib/scope",
+ "x": 350, "y": 150, "width": 600, "height": 300,
+ "parameters": {}
}
},
"signals": [
@@ -40,6 +45,7 @@
[ "Memory1" , 0, "Sum1" , 1, {} ],
[ "Integral2", 0, "Gain2" , 0, {} ],
[ "Gain2" , 0, "Gain1" , 0, {} ],
- [ "Integral2", 0, "Display22" , 0, {} ]
+ [ "Integral2", 0, "Display22" , 0, {} ],
+ [ "Integral2", 0, "Scope_2" , 0, {} ]
]
}
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|