11
|
1 |
|
|
2 |
TYPECONVERSION = {"BOOL" : "X", "SINT" : "B", "INT" : "W", "DINT" : "D", "LINT" : "L",
|
|
3 |
"USINT" : "B", "UINT" : "W", "UDINT" : "D", "ULINT" : "L", "REAL" : "D", "LREAL" : "L",
|
|
4 |
"STRING" : "B", "BYTE" : "B", "WORD" : "W", "DWORD" : "D", "LWORD" : "L", "WSTRING" : "W"}
|
|
5 |
|
|
6 |
def GetBlockGenerationFunction(beremiz):
|
|
7 |
def generate_svgui_block(generator, block, body, link):
|
|
8 |
controller = generator.GetController()
|
|
9 |
name = block.getInstanceName()
|
|
10 |
type = block.getTypeName()
|
|
11 |
block_infos = GetBlockType(type)
|
|
12 |
bus_id, name = [word for word in name.split("_") if word != ""]
|
|
13 |
block_id = beremiz.GetSVGUIElementId(bus_id, name)
|
|
14 |
if block_id == None:
|
|
15 |
raise ValueError, "No corresponding block found"
|
|
16 |
if not generator.ComputedBlocks.get(name, False):
|
|
17 |
for num, variable in enumerate(block.inputVariables.getVariable()):
|
|
18 |
connections = variable.connectionPointIn.getConnections()
|
|
19 |
if connections and len(connections) == 1:
|
|
20 |
parameter = "__I%s%d_%d_%d"%(TYPECONVERSION[block_infos["inputs"][num][1]], bus_id, block_id, num)
|
|
21 |
value = generator.ComputeFBDExpression(body, connections[0])
|
|
22 |
generator.Program += (" %s := %s;\n"%(parameter, generator.ExtractModifier(variable, value)))
|
|
23 |
generator.ComputedBlocks[name] = True
|
|
24 |
if link:
|
|
25 |
connectionPoint = link.getPosition()[-1]
|
|
26 |
for num, variable in enumerate(block.outputVariables.getVariable()):
|
|
27 |
blockPointx, blockPointy = variable.connectionPointOut.getRelPosition()
|
|
28 |
if block.getX() + blockPointx == connectionPoint.getX() and block.getY() + blockPointy == connectionPoint.getY():
|
|
29 |
return "__Q%s%d_%d_%d"%(TYPECONVERSION[block_infos["outputs"][num][1]], bus_id, block_id, num)
|
|
30 |
raise ValueError, "No output variable found"
|
|
31 |
else:
|
|
32 |
return None
|
|
33 |
return generate_svgui_block
|
|
34 |
|
|
35 |
BlockList = {"name" : "SVGUI function blocks", "list" :
|
|
36 |
[{"name" : "Container", "type" : "functionBlock", "extensible" : False,
|
|
37 |
"inputs" : [("X","FLOAT","none"),("SetX","BOOL","none"),("Y","FLOAT","none"),("SetY","BOOL","none"),("Angle","FLOAT","none"),("SetAngle","BOOL","none")],
|
|
38 |
"outputs" : [("X","FLOAT","none"),("X Changed","BOOL","none"),("Y","FLOAT","none"),("Y Changed","BOOL","none"),("Angle","FLOAT","none"),("Angle Changed","BOOL","none")],
|
|
39 |
"comment" : "SVGUI Container"},
|
|
40 |
{"name" : "Button", "type" : "functionBlock", "extensible" : False,
|
|
41 |
"inputs" : [("Show","BOOL","none"),("Toggle","BOOL","none")],
|
|
42 |
"outputs" : [("Visible","BOOL","none"),("State","BOOL","none")],
|
|
43 |
"comment" : "SVGUI Button"},
|
|
44 |
{"name" : "TextCtrl", "type" : "functionBlock", "extensible" : False,
|
|
45 |
"inputs" : [("Text","STRING","none"),("Set Text","BOOL","none")],
|
|
46 |
"outputs" : [("Text","STRING","none"),("Text Changed","BOOL","none")],
|
|
47 |
"comment" : "SVGUI Text Control"},
|
|
48 |
{"name" : "ScrollBar", "type" : "functionBlock", "extensible" : False,
|
|
49 |
"inputs" : [("Position","UINT","none"),("Set Position","BOOL","none")],
|
|
50 |
"outputs" : [("Position","UINT","none"),("Position Changed","BOOL","none")],
|
|
51 |
"comment" : "SVGUI ScrollBar"},
|
|
52 |
{"name" : "NoteBook", "type" : "functionBlock", "extensible" : False,
|
|
53 |
"inputs" : [("Selected","UINT","none"),("Set Selected","BOOL","none")],
|
|
54 |
"outputs" : [("Selected","UINT","none"),("Selected Changed","BOOL","none")],
|
|
55 |
"comment" : "SVGUI Notebook"},
|
|
56 |
{"name" : "RotatingCtrl", "type" : "functionBlock", "extensible" : False,
|
|
57 |
"inputs" : [("Angle","FLOAT","none"),("Set Angle","BOOL","none")],
|
|
58 |
"outputs" : [("Angle","FLOAT","none"),("Angle changed","BOOL","none")],
|
|
59 |
"comment" : "SVGUI Rotating Control"},
|
|
60 |
]}
|