|
From: <ma...@us...> - 2011-05-10 17:49:55
|
Revision: 328
http://openautomation.svn.sourceforge.net/openautomation/?rev=328&view=rev
Author: mayerch
Date: 2011-05-10 17:49:48 +0000 (Tue, 10 May 2011)
Log Message:
-----------
Finish the display the current values of the LogicServer in the current LogicEditor view
(The solution is quite hackish and has to be cleaned up later)
Modified Paths:
--------------
PyWireGate/trunk/logic_editor/LogicEditor.py
PyWireGate/trunk/logic_editor/backendCommunication.js
PyWireGate/trunk/logic_editor/gle/gle.block.js
PyWireGate/trunk/logic_editor/logicEditor.js
PyWireGate/trunk/logic_server/LogicImportJSON.py
PyWireGate/trunk/logic_server/LogicLibrary.py
PyWireGate/trunk/logic_server/LogicModule.py
PyWireGate/trunk/logic_server/LogicServer.py
PyWireGate/trunk/logik.json
PyWireGate/trunk/logik2.json
Modified: PyWireGate/trunk/logic_editor/LogicEditor.py
===================================================================
--- PyWireGate/trunk/logic_editor/LogicEditor.py 2011-05-10 15:13:52 UTC (rev 327)
+++ PyWireGate/trunk/logic_editor/LogicEditor.py 2011-05-10 17:49:48 UTC (rev 328)
@@ -81,11 +81,12 @@
f.write('{ \x22v\x22:\x220.0.1\x22, \x22s\x22:\x22SESSION\x22 }\n\n')
elif self.path.startswith("/logicLib"):
lib = LogicLibrary.LogicLibrary().getLibrary()
- f.write( '{"MainLib":{' )
+ thisLib = 'MainLib' # FIXME iterate over it...
+ f.write( '{"%s":{' % thisLib )
blockPrefix = ''
- for blockName in lib:
+ for blockName in lib[ thisLib ]:
f.write( '%s"%s":{"name":"%s",' % (blockPrefix, blockName, blockName) )
- block = lib[ blockName ]
+ block = lib[ thisLib ][ blockName ]
f.write( '"inPorts":[' )
prefix = ''
@@ -111,6 +112,21 @@
prefix = ','
f.write( '],' )
+ f.write( '"maskOptions":{' )
+ prefix = ''
+ maskOptions = block.maskOptions()
+ for maskOption in maskOptions:
+ option = maskOptions[maskOption]
+ if type(option) in (int, float):
+ f.write( '%s"%s":%s' % (prefix, maskOption, option) )
+ elif type(option) == bool:
+ option = 'true' if option else 'false'
+ f.write( '%s"%s":%s' % (prefix, maskOption, option) )
+ else:
+ f.write( '%s"%s":"%s"' % (prefix, maskOption, option) )
+ prefix = ','
+ f.write( '},' )
+
f.write( '"width":100,"height":50,"rotation":0,"flip":false,"color":[0.0,0.0,0.0],"background":[1.0, 1.0, 1.0]' )
f.write( '}' )
Modified: PyWireGate/trunk/logic_editor/backendCommunication.js
===================================================================
--- PyWireGate/trunk/logic_editor/backendCommunication.js 2011-05-10 15:13:52 UTC (rev 327)
+++ PyWireGate/trunk/logic_editor/backendCommunication.js 2011-05-10 17:49:48 UTC (rev 328)
@@ -280,28 +280,22 @@
});
// tweak backend communication, should also be done on demand
-XXX = new CometVisu( '/live/' );
-XXX.update = function( json )
+live = new CometVisu( '/live/' );
+liveUpdateCalls = [];
+live.update = function( json )
{
- console.log( json );
+ $.each( liveUpdateCalls, function(){
+ for( var i = json.length-1; i >= 0; i-- )
+ {
+ if( json[i].block == this[0] )
+ {
+ this[1]( json[i].value );
+ }
+ }
+ });
}
-XXX.subscribe( ['ALL'] );
+live.subscribe( ['ALL'] );
$(window).unload(function() {
- XXX.stop();
-});
-/*XXX=$.ajax({
- url: '/live',
- cache: false,
- success: function(html){
- console.log('success', html);
- }
-});*/
-/*
- var ws = new websocket("/live");
- ws.onopen = function() {
- ws.send("Hello Mr. Server!");
- };
- ws.onmessage = function (e) { console.log(e.data); };
- ws.onclose = function() { console.log('close'); };
- */
\ No newline at end of file
+ live.stop();
+});
\ No newline at end of file
Modified: PyWireGate/trunk/logic_editor/gle/gle.block.js
===================================================================
--- PyWireGate/trunk/logic_editor/gle/gle.block.js 2011-05-10 15:13:52 UTC (rev 327)
+++ PyWireGate/trunk/logic_editor/gle/gle.block.js 2011-05-10 17:49:48 UTC (rev 328)
@@ -21,11 +21,11 @@
/**
* The block constructor.
- * type: the block (proto)type in JSON notation
+ * prototype: the block (proto)type in JSON notation
* svg: the link to the SVG canvas
* interactive: event handlers will be added, set to false to create picture only
*/
-function Block( type, svg, interactive )
+function Block( prototype, svg, interactive )
{
// setup the private "constants"
var that = this;
@@ -33,21 +33,22 @@
var outset = 3; // how far should the handle stick out
// setup the private variables
- var name = type.name || 'UNKNOWN';
- var x = type.x || 0;
- var y = type.y || 0;
- var width = type.width || 100;
- var height = type.height || 100;
- var rotation = type.rotation || 0;
- var flip = type.flip || false;
- var mask = type.mask || undefined;
- var maskOptions = type.maskOptions || { showLabel: true };
- var color = type.color || [0.0, 0.0, 0.0];
- var background = type.background || [1.0, 1.0, 1.0];
- var inPorts = type.inPorts || [];
- var outPorts = type.outPorts || [];
- var parameters = type.parameters || {};
- var parameter = type.parameter || createParameter( type.parameters );
+ var type = prototype.type || 'UNKNOWN';
+ var name = prototype.name || 'UNKNOWN';
+ var x = prototype.x || 0;
+ var y = prototype.y || 0;
+ var width = prototype.width || 100;
+ var height = prototype.height || 100;
+ var rotation = prototype.rotation || 0;
+ var flip = prototype.flip || false;
+ var mask = prototype.mask || undefined;
+ var maskOptions = prototype.maskOptions || { showLabel: true };
+ var color = prototype.color || [0.0, 0.0, 0.0];
+ var background = prototype.background || [1.0, 1.0, 1.0];
+ var inPorts = prototype.inPorts || [];
+ var outPorts = prototype.outPorts || [];
+ var parameters = prototype.parameters || {};
+ var parameter = prototype.parameter || createParameter( prototype.parameters );
var postParameterUpdateFn = maskOptions.postParameterUpdate;
var canvas = svg || $('#editor').svg('get');
@@ -221,6 +222,18 @@
}
+ // private function for live updating of param = {'text-anchor':'start'}a display
+ this._updateValue = function( value )
+ {
+ if( g )
+ {
+ //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 );
+ }
+ }
+
function createParameter( structure )
{
var retVal = {};
@@ -339,6 +352,8 @@
}
// the public (privileged) methods:
+ this.getType = function() { return type ; }
+ this.getName = function() { return name ; }
this.getWidth = function() { return width ; }
this.setWidth = function( _width ) { width = _width ; draw(); }
this.getHeight = function() { return height; }
Modified: PyWireGate/trunk/logic_editor/logicEditor.js
===================================================================
--- PyWireGate/trunk/logic_editor/logicEditor.js 2011-05-10 15:13:52 UTC (rev 327)
+++ PyWireGate/trunk/logic_editor/logicEditor.js 2011-05-10 17:49:48 UTC (rev 328)
@@ -137,6 +137,7 @@
$.each( this, function( element ){
var entry = $('<div class="libEntry"></div>');
var obj = this;
+ obj.type = libName + '/' + element;
var width = this.width+20;
var height = this.height+35;
entry.prepend(
@@ -165,12 +166,13 @@
{
logic = logics[ logicName ];
- // clean canvas first
- $('#editor g').remove();
+ $('#editor g').remove(); // clean canvas first
+ blockRegistry = {}; // and then the block registry
// draw all the blocks
$.each( logic.blocks, function( name, def ){
- var newBlock = $.extend( true, {}, libJSON['MainLib'][ def.type ], def, {'name':name} );
+ var type = def.type.split('/');
+ var newBlock = $.extend( true, {}, libJSON[ type[0] ][ type[1] ], def, {'name':name} );
drawElement( undefined, newBlock, true );
});
@@ -197,6 +199,14 @@
if( addEvent === undefined ) addEvent = true;
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
+ {
+ liveUpdateCalls.push( [
+ b.getName(),
+ b._updateValue
+ ] );
+ }
}
function colorByArray( a )
Modified: PyWireGate/trunk/logic_server/LogicImportJSON.py
===================================================================
--- PyWireGate/trunk/logic_server/LogicImportJSON.py 2011-05-10 15:13:52 UTC (rev 327)
+++ PyWireGate/trunk/logic_server/LogicImportJSON.py 2011-05-10 17:49:48 UTC (rev 328)
@@ -36,7 +36,8 @@
stateupdate = '' # the string containing the update of the states
for name, attribute in loaddict['blocks'].iteritems():
- block = lib[ attribute['type'] ]
+ blockType = attribute['type'].split('/')
+ block = lib[ blockType[0] ][ blockType[1] ]
G.add_node( name, attribute )
# Add aditional, virtual node "<name>.state" that is treates as an additional
# input with no dependancy as the state won't change during an update cycle,
@@ -49,7 +50,8 @@
for signal in loaddict['signals']:
b = loaddict['blocks']
- if lib[ loaddict['blocks'][ signal[0] ]['type'] ].outPortNumberHasState( signal[1] ):
+ blockType = loaddict['blocks'][ signal[0] ]['type'].split('/')
+ if lib[ blockType[0] ][ blockType[1] ].outPortNumberHasState( signal[1] ):
G.add_edge( signal[0] + '.state', signal[2], { 'ports': ( signal[1], signal[3] ), 'start': signal[0] } )
else:
G.add_edge( signal[0], signal[2], { 'ports': ( signal[1], signal[3] ), 'start': signal[0] } )
@@ -59,12 +61,14 @@
for instruction in intructionOrder:
if not instruction in loaddict['blocks']:
continue # ignore the virtual state nodes
- libBlock = lib[ loaddict['blocks'][ instruction ]['type'] ]
+ blockType = loaddict['blocks'][ instruction ]['type'].split('/')
+ libBlock = lib[ blockType[0] ][ blockType[1] ]
ins = []
for i in range(len(libBlock.inPorts())):
for e in G.in_edges_iter( instruction, True ):
if e[2]['ports'][1] == i:
- if lib[ loaddict['blocks'][ e[2]['start'] ]['type'] ].outPortNumberHasState( e[2]['ports'][0] ):
+ blockType = loaddict['blocks'][ e[2]['start'] ]['type'].split('/')
+ if lib[ blockType[0] ][ blockType[1] ].outPortNumberHasState( e[2]['ports'][0] ):
ins.append( "self.%s_%s" % ( e[2]['start'], e[2]['ports'][0] ) )
else:
ins.append( "%s_%s" % ( e[2]['start'], e[2]['ports'][0] ) )
Modified: PyWireGate/trunk/logic_server/LogicLibrary.py
===================================================================
--- PyWireGate/trunk/logic_server/LogicLibrary.py 2011-05-10 15:13:52 UTC (rev 327)
+++ PyWireGate/trunk/logic_server/LogicLibrary.py 2011-05-10 17:49:48 UTC (rev 328)
@@ -24,14 +24,16 @@
_outPorts = [ ( 'out', 'const' ) ]
_parameters = [ 'value' ]
_drawingInstructions = ""
+ _maskOptions = { 'showLabel': True }
_codingInstructions = lambda s, n, i, o, p: ( "%s = %s" % ( o[0], p[0] ), "%s_next = %s" % ( o[0], p[0] ) )
-class LogBlock( LogicModule.LogicModule ):
+class DisplayBlock( LogicModule.LogicModule ):
_name = "display"
_inPorts = [ 'in' ]
_outPorts = []
_parameters = []
_drawingInstructions = ""
+ _maskOptions = { 'showLabel': False }
#_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]) )
@@ -41,6 +43,7 @@
_outPorts = [ ( 'out', 'signal' ) ]
_parameters = [ 'gain' ]
_drawingInstructions = ""
+ _maskOptions = { 'showLabel': True }
_codingInstructions = lambda s, n, i, o, p: ( None, "%s = %s * %s" % ( o[0], p[0], i[0] ) )
class SumBlock( LogicModule.LogicModule ):
@@ -49,6 +52,7 @@
_outPorts = [ ( 'out', 'signal' ) ]
_parameters = []
_drawingInstructions = ""
+ _maskOptions = { 'showLabel': True }
_codingInstructions = lambda s, n, i, o, p: ( None, "%s = %s + %s" % ( o[0], i[0], i[1] ) )
class MemoryBlock( LogicModule.LogicModule ):
@@ -57,6 +61,7 @@
_outPorts = [ ( 'out', 'state' ) ]
_parameters = [ 'inital_value' ]
_drawingInstructions = ""
+ _maskOptions = { 'showLabel': True }
_codingInstructions = lambda s, n, i, o, p: ( "%s = %s" % (o[0], p[0]), "%s_next = %s" % ( o[0], i[0] ) )
class IntegralBlock( LogicModule.LogicModule ):
@@ -65,23 +70,25 @@
_outPorts = [ ( 'out', 'state' ) ]
_parameters = [ 'initial_value' ]
_drawingInstructions = ""
+ _maskOptions = { 'showLabel': True }
_codingInstructions = lambda s, n, i, o, p: ( "%s = %s" % (o[0], p[0]), "%s_next = %s * %s + self.%s" % ( o[0], "__dt", i[0], o[0] ) )
class LogicLibrary:
"""The container for all known library blocks"""
- _db = {}
+ _db = {'MainLib':{}}
def __init__( self ):
self.addBlock( ConstBlock )
- self.addBlock( LogBlock )
+ self.addBlock( DisplayBlock )
self.addBlock( GainBlock )
self.addBlock( SumBlock )
self.addBlock( MemoryBlock )
self.addBlock( IntegralBlock )
def addBlock( self, block ):
+ l = 'MainLib'
b = block()
- self._db[ b.name() ] = b
+ self._db[ l ][ b.name() ] = b
def getLibrary( self ):
return self._db
Modified: PyWireGate/trunk/logic_server/LogicModule.py
===================================================================
--- PyWireGate/trunk/logic_server/LogicModule.py 2011-05-10 15:13:52 UTC (rev 327)
+++ PyWireGate/trunk/logic_server/LogicModule.py 2011-05-10 17:49:48 UTC (rev 328)
@@ -33,6 +33,9 @@
def drawingIntructions( self ):
return self._drawingInstructions
+ def maskOptions( self ):
+ return self._maskOptions
+
def codingIntructions( self, name, ins, outs, params ):
return self._codingInstructions( name, ins, outs, params )
Modified: PyWireGate/trunk/logic_server/LogicServer.py
===================================================================
--- PyWireGate/trunk/logic_server/LogicServer.py 2011-05-10 15:13:52 UTC (rev 327)
+++ PyWireGate/trunk/logic_server/LogicServer.py 2011-05-10 17:49:48 UTC (rev 328)
@@ -79,8 +79,8 @@
self.Logik2 = LogikClass
t = TaskManager.TaskManager(self)
- t.addInterval( 'Interval 1 - 75 ms Task', 0.75 )
- t.addInterval( 'Interval 2 - 10 ms Task', 0.910 )
+ t.addInterval( 'Interval 1 - 75 ms Task', 0.075 )
+ t.addInterval( 'Interval 2 - 10 ms Task', 0.010 )
t.addTask( 'Interval 1 - 75 ms Task', 'Logik1', self.Logik1 )
t.addTask( 'Interval 2 - 10 ms Task', 'Logik2', self.Logik2 )
t.start()
Modified: PyWireGate/trunk/logik.json
===================================================================
--- PyWireGate/trunk/logik.json 2011-05-10 15:13:52 UTC (rev 327)
+++ PyWireGate/trunk/logik.json 2011-05-10 17:49:48 UTC (rev 328)
@@ -1,42 +1,42 @@
{
"blocks": {
"Const1": {
- "type": "const",
+ "type": "MainLib/const",
"x": 50, "y": 50, "width": 50, "height": 50,
"parameters": { "value": 1.0 }
},
"Gain1": {
- "type": "gain",
+ "type": "MainLib/gain",
"x": 150, "y": 50, "width": 50, "height": 50,
"parameters": { "gain": 5.0 }
},
"Display1": {
- "type": "display",
+ "type": "MainLib/display",
"x": 250, "y": 150, "width": 150, "height": 50,
"parameters": {}
},
"Display2": {
- "type": "display",
+ "type": "MainLib/display",
"x": 250, "y": 50, "width": 150, "height": 50,
"parameters": {}
},
"Integral1": {
- "type": "integral",
+ "type": "MainLib/integral",
"x": 50, "y": 250, "width": 50, "height": 50,
"parameters": { "inital_value": 1.0 }
},
"Integral2": {
- "type": "integral",
+ "type": "MainLib/integral",
"x": 150, "y": 250, "width": 50, "height": 50,
"parameters": { "inital_value": 0.0 }
},
"Gain2": {
- "type": "gain",
+ "type": "MainLib/gain",
"x": 150, "y": 350, "width": 50, "height": 50,
"parameters": { "gain": -1.0 }
},
"Display3": {
- "type": "display",
+ "type": "MainLib/display",
"x": 250, "y": 250, "width": 150, "height": 50,
"parameters": {}
}
Modified: PyWireGate/trunk/logik2.json
===================================================================
--- PyWireGate/trunk/logik2.json 2011-05-10 15:13:52 UTC (rev 327)
+++ PyWireGate/trunk/logik2.json 2011-05-10 17:49:48 UTC (rev 328)
@@ -1,32 +1,32 @@
{
"blocks": {
"Memory1": {
- "type": "memory",
+ "type": "MainLib/memory",
"x": 150, "y": 300, "width": 50, "height": 50,
"parameters": { "initial_value": 1.0 }
},
"Gain1": {
- "type": "gain",
+ "type": "MainLib/gain",
"x": 50, "y": 150, "width": 50, "height": 50,
"parameters": { "gain": "__dt" }
},
"Sum1": {
- "type": "sum",
+ "type": "MainLib/sum",
"x": 150, "y": 200, "width": 50, "height": 50,
"parameters": {}
},
"Display22": {
- "type": "display",
+ "type": "MainLib/display",
"x": 350, "y": 300, "width": 150, "height": 50,
"parameters": {}
},
"Integral2": {
- "type": "integral",
+ "type": "MainLib/integral",
"x": 250, "y": 300, "width": 50, "height": 50,
"parameters": { "inital_value": 0.0 }
},
"Gain2": {
- "type": "gain",
+ "type": "MainLib/gain",
"x": 150, "y": 50, "width": 50, "height": 50,
"parameters": { "gain": -1.0 }
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|