|
From: <ma...@us...> - 2011-05-10 21:04:16
|
Revision: 329
http://openautomation.svn.sourceforge.net/openautomation/?rev=329&view=rev
Author: mayerch
Date: 2011-05-10 21:04:09 +0000 (Tue, 10 May 2011)
Log Message:
-----------
Added feature to allow to flip blocks
Modified Paths:
--------------
PyWireGate/trunk/logic_editor/LogicEditor.py
PyWireGate/trunk/logic_editor/gle/gle.block.js
PyWireGate/trunk/logic_server/LogicModule.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 17:49:48 UTC (rev 328)
+++ PyWireGate/trunk/logic_editor/LogicEditor.py 2011-05-10 21:04:09 UTC (rev 329)
@@ -112,18 +112,14 @@
prefix = ','
f.write( '],' )
+ f.write( '"flip":%s,' % self._convert2JSON( block.flip() ) )
+
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) )
+ f.write( '%s"%s":%s' % (prefix, maskOption, self._convert2JSON( option ) ) )
prefix = ','
f.write( '},' )
@@ -189,4 +185,15 @@
def copyfile(self, source, outputfile):
shutil.copyfileobj(source, outputfile)
-
\ No newline at end of file
+
+ # create a JSON representation out of the Python value
+ def _convert2JSON( self, value ):
+ if type( value ) in ( int, float ):
+ return str( value )
+ elif type( value ) == bool:
+ if value:
+ return 'true'
+ else:
+ return 'false'
+ else:
+ return '"%s"' % value
Modified: PyWireGate/trunk/logic_editor/gle/gle.block.js
===================================================================
--- PyWireGate/trunk/logic_editor/gle/gle.block.js 2011-05-10 17:49:48 UTC (rev 328)
+++ PyWireGate/trunk/logic_editor/gle/gle.block.js 2011-05-10 21:04:09 UTC (rev 329)
@@ -176,7 +176,7 @@
}
if( maskOptions.showLabel )
canvas.text( g, 1.2*p[0].x-0.2*p[1].x, 1.2*p[0].y-0.2*p[1].y, this.name,
- {'dominant-baseline':'middle','text-anchor':'start'} );
+ {'dominant-baseline':'middle','text-anchor': flip?'end':'start'} );
});
// Draw the outports
@@ -198,7 +198,7 @@
}
if( maskOptions.showLabel )
canvas.text( g, 1.2*p[0].x-0.2*p[1].x, 1.2*p[0].y-0.2*p[1].y, this.name,
- {'dominant-baseline':'middle','text-anchor':'end'} );
+ {'dominant-baseline':'middle','text-anchor': flip?'start':'end'} );
});
// Draw the label
@@ -379,15 +379,15 @@
return maskOptions.inPortPos( number, that, maskOptions, parameter );
} else
return [
- { x: x , y: y + height * (0.5 + number) / inPorts.length },
- { x: x - 20, y: y + height * (0.5 + number) / inPorts.length }
+ { x: flip ? x + width : x , y: y + height * (0.5 + number) / inPorts.length },
+ { x: flip ? x + width + 20 : x - 20, y: y + height * (0.5 + number) / inPorts.length }
];
}
this.outPortPos = function( number )
{
return [
- { x: x + width , y: y + height * (0.5 + number) / outPorts.length },
- { x: x + width + 20, y: y + height * (0.5 + number) / outPorts.length }
+ { x: flip ? x : x + width , y: y + height * (0.5 + number) / outPorts.length },
+ { x: flip ? x - 20 : x + width + 20, y: y + height * (0.5 + number) / outPorts.length }
];
}
Modified: PyWireGate/trunk/logic_server/LogicModule.py
===================================================================
--- PyWireGate/trunk/logic_server/LogicModule.py 2011-05-10 17:49:48 UTC (rev 328)
+++ PyWireGate/trunk/logic_server/LogicModule.py 2011-05-10 21:04:09 UTC (rev 329)
@@ -18,6 +18,10 @@
class LogicModule:
"""The base class for a generic logic module"""
+
+ # default values
+ _flip = False
+
def name( self ):
return self._name
@@ -30,6 +34,9 @@
def parameters( self ):
return self._parameters
+ def flip( self ):
+ return self._flip
+
def drawingIntructions( self ):
return self._drawingInstructions
Modified: PyWireGate/trunk/logik.json
===================================================================
--- PyWireGate/trunk/logik.json 2011-05-10 17:49:48 UTC (rev 328)
+++ PyWireGate/trunk/logik.json 2011-05-10 21:04:09 UTC (rev 329)
@@ -33,7 +33,8 @@
"Gain2": {
"type": "MainLib/gain",
"x": 150, "y": 350, "width": 50, "height": 50,
- "parameters": { "gain": -1.0 }
+ "parameters": { "gain": -1.0 },
+ "flip" : true
},
"Display3": {
"type": "MainLib/display",
Modified: PyWireGate/trunk/logik2.json
===================================================================
--- PyWireGate/trunk/logik2.json 2011-05-10 17:49:48 UTC (rev 328)
+++ PyWireGate/trunk/logik2.json 2011-05-10 21:04:09 UTC (rev 329)
@@ -2,8 +2,9 @@
"blocks": {
"Memory1": {
"type": "MainLib/memory",
- "x": 150, "y": 300, "width": 50, "height": 50,
- "parameters": { "initial_value": 1.0 }
+ "x": 150, "y": 250, "width": 50, "height": 50,
+ "parameters": { "initial_value": 1.0 },
+ "flip" : true
},
"Gain1": {
"type": "MainLib/gain",
@@ -12,27 +13,28 @@
},
"Sum1": {
"type": "MainLib/sum",
- "x": 150, "y": 200, "width": 50, "height": 50,
+ "x": 150, "y": 150, "width": 50, "height": 50,
"parameters": {}
},
"Display22": {
"type": "MainLib/display",
- "x": 350, "y": 300, "width": 150, "height": 50,
+ "x": 350, "y": 150, "width": 150, "height": 50,
"parameters": {}
},
"Integral2": {
"type": "MainLib/integral",
- "x": 250, "y": 300, "width": 50, "height": 50,
+ "x": 250, "y": 150, "width": 50, "height": 50,
"parameters": { "inital_value": 0.0 }
},
"Gain2": {
"type": "MainLib/gain",
"x": 150, "y": 50, "width": 50, "height": 50,
- "parameters": { "gain": -1.0 }
+ "parameters": { "gain": -1.0 },
+ "flip" : true
}
},
"signals": [
- [ "Memory1" , 0, "Integral2" , 0, {} ],
+ [ "Sum1" , 0, "Integral2" , 0, {} ],
[ "Gain1" , 0, "Sum1" , 0, {} ],
[ "Sum1" , 0, "Memory1" , 0, {} ],
[ "Memory1" , 0, "Sum1" , 1, {} ],
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|