12
|
1 |
import os
|
|
2 |
from DEFControler import DEFControler
|
|
3 |
from defeditor import EditorFrame
|
11
|
4 |
|
12
|
5 |
class _EditorFramePlugg(EditorFrame):
|
|
6 |
def OnClose(self, event):
|
|
7 |
self.OnPluggClose()
|
|
8 |
event.Skip()
|
|
9 |
|
|
10 |
class BusController(DEFControler):
|
|
11 |
|
|
12 |
ViewClass = _EditorFramePlugg
|
|
13 |
|
|
14 |
def __init__(self, buspath):
|
|
15 |
filepath = os.path.join(buspath, "gui.def")
|
|
16 |
if os.path.isfile(filepath):
|
|
17 |
self.OpenXMLFile(filepath)
|
|
18 |
else
|
|
19 |
self.CreateRootElement()
|
|
20 |
self.SetFilePath(filepath)
|
|
21 |
|
|
22 |
def ReqSave(self):
|
|
23 |
self.SaveXMLFile()
|
|
24 |
return True
|
|
25 |
|
|
26 |
def Generate_C(self, dirpath, locations):
|
|
27 |
self.GenerateProgram(filepath)
|
|
28 |
return {"headers":["program.h"],"sources":["program.cpp"]}
|
|
29 |
|
11
|
30 |
TYPECONVERSION = {"BOOL" : "X", "SINT" : "B", "INT" : "W", "DINT" : "D", "LINT" : "L",
|
|
31 |
"USINT" : "B", "UINT" : "W", "UDINT" : "D", "ULINT" : "L", "REAL" : "D", "LREAL" : "L",
|
|
32 |
"STRING" : "B", "BYTE" : "B", "WORD" : "W", "DWORD" : "D", "LWORD" : "L", "WSTRING" : "W"}
|
|
33 |
|
12
|
34 |
class PluginController:
|
|
35 |
def BlockTypesFactory(self):
|
|
36 |
def generate_svgui_block(generator, block, body, link):
|
|
37 |
controller = generator.GetController()
|
|
38 |
name = block.getInstanceName()
|
|
39 |
type = block.getTypeName()
|
|
40 |
block_infos = GetBlockType(type)
|
|
41 |
bus_id, name = [word for word in name.split("_") if word != ""]
|
|
42 |
block_id = self.PluginBuses[bus_id].GetElementIdFromName(name)
|
|
43 |
if block_id == None:
|
|
44 |
raise ValueError, "No corresponding block found"
|
|
45 |
if not generator.ComputedBlocks.get(name, False):
|
|
46 |
for num, variable in enumerate(block.inputVariables.getVariable()):
|
|
47 |
connections = variable.connectionPointIn.getConnections()
|
|
48 |
if connections and len(connections) == 1:
|
|
49 |
parameter = "__I%s%d_%d_%d"%(TYPECONVERSION[block_infos["inputs"][num][1]], bus_id, block_id, num)
|
|
50 |
value = generator.ComputeFBDExpression(body, connections[0])
|
|
51 |
generator.Program += (" %s := %s;\n"%(parameter, generator.ExtractModifier(variable, value)))
|
|
52 |
generator.ComputedBlocks[name] = True
|
|
53 |
if link:
|
|
54 |
connectionPoint = link.getPosition()[-1]
|
|
55 |
for num, variable in enumerate(block.outputVariables.getVariable()):
|
|
56 |
blockPointx, blockPointy = variable.connectionPointOut.getRelPosition()
|
|
57 |
if block.getX() + blockPointx == connectionPoint.getX() and block.getY() + blockPointy == connectionPoint.getY():
|
|
58 |
return "__Q%s%d_%d_%d"%(TYPECONVERSION[block_infos["outputs"][num][1]], bus_id, block_id, num)
|
|
59 |
raise ValueError, "No output variable found"
|
|
60 |
else:
|
|
61 |
return None
|
11
|
62 |
|
12
|
63 |
return [{"name" : "SVGUI function blocks", "list" :
|
|
64 |
[{"name" : "Container", "type" : "functionBlock", "extensible" : False,
|
|
65 |
"inputs" : [("X","FLOAT","none"),("SetX","BOOL","none"),("Y","FLOAT","none"),("SetY","BOOL","none"),("Angle","FLOAT","none"),("SetAngle","BOOL","none")],
|
|
66 |
"outputs" : [("X","FLOAT","none"),("X Changed","BOOL","none"),("Y","FLOAT","none"),("Y Changed","BOOL","none"),("Angle","FLOAT","none"),("Angle Changed","BOOL","none")],
|
|
67 |
"comment" : "SVGUI Container", "generate": generate_svgui_block},
|
|
68 |
{"name" : "Button", "type" : "functionBlock", "extensible" : False,
|
|
69 |
"inputs" : [("Show","BOOL","none"),("Toggle","BOOL","none")],
|
|
70 |
"outputs" : [("Visible","BOOL","none"),("State","BOOL","none")],
|
|
71 |
"comment" : "SVGUI Button", "generate": generate_svgui_block},
|
|
72 |
{"name" : "TextCtrl", "type" : "functionBlock", "extensible" : False,
|
|
73 |
"inputs" : [("Text","STRING","none"),("Set Text","BOOL","none")],
|
|
74 |
"outputs" : [("Text","STRING","none"),("Text Changed","BOOL","none")],
|
|
75 |
"comment" : "SVGUI Text Control", "generate": generate_svgui_block},
|
|
76 |
{"name" : "ScrollBar", "type" : "functionBlock", "extensible" : False,
|
|
77 |
"inputs" : [("Position","UINT","none"),("Set Position","BOOL","none")],
|
|
78 |
"outputs" : [("Position","UINT","none"),("Position Changed","BOOL","none")],
|
|
79 |
"comment" : "SVGUI ScrollBar", "generate": generate_svgui_block},
|
|
80 |
{"name" : "NoteBook", "type" : "functionBlock", "extensible" : False,
|
|
81 |
"inputs" : [("Selected","UINT","none"),("Set Selected","BOOL","none")],
|
|
82 |
"outputs" : [("Selected","UINT","none"),("Selected Changed","BOOL","none")],
|
|
83 |
"comment" : "SVGUI Notebook", "generate": generate_svgui_block},
|
|
84 |
{"name" : "RotatingCtrl", "type" : "functionBlock", "extensible" : False,
|
|
85 |
"inputs" : [("Angle","FLOAT","none"),("Set Angle","BOOL","none")],
|
|
86 |
"outputs" : [("Angle","FLOAT","none"),("Angle changed","BOOL","none")],
|
|
87 |
"comment" : "SVGUI Rotating Control", "generate": generate_svgui_block}
|
|
88 |
]}]
|
|
89 |
|
|
90 |
|
|
91 |
|
|
92 |
|
|
93 |
|
|
94 |
|
|
95 |
|
|
96 |
|
|
97 |
|