author | lbessard |
Tue, 04 Sep 2007 17:16:42 +0200 | |
changeset 19 | 73257cea38bd |
parent 13 | f1f0edbeb313 |
child 20 | d3cb5020997b |
permissions | -rw-r--r-- |
12 | 1 |
import os |
2 |
from DEFControler import DEFControler |
|
3 |
from defeditor import EditorFrame |
|
11 | 4 |
|
13
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
5 |
class _EditorFramePlug(EditorFrame): |
12 | 6 |
def OnClose(self, event): |
13
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
7 |
self.OnPlugClose() |
12 | 8 |
event.Skip() |
9 |
||
13
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
10 |
class _DEFControlerPlug(DEFControler): |
12 | 11 |
|
13
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
12 |
ViewClass = _EditorFramePlug |
12 | 13 |
|
14 |
def __init__(self, buspath): |
|
15 |
filepath = os.path.join(buspath, "gui.def") |
|
16 |
if os.path.isfile(filepath): |
|
17 |
self.OpenXMLFile(filepath) |
|
13
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
18 |
else: |
12 | 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 |
||
13
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
34 |
class RootClass: |
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
35 |
|
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
36 |
ChildsType = _DEFControlerPlug |
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
37 |
|
12 | 38 |
def BlockTypesFactory(self): |
39 |
def generate_svgui_block(generator, block, body, link): |
|
40 |
controller = generator.GetController() |
|
41 |
name = block.getInstanceName() |
|
42 |
type = block.getTypeName() |
|
43 |
block_infos = GetBlockType(type) |
|
44 |
bus_id, name = [word for word in name.split("_") if word != ""] |
|
13
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
45 |
block_id = self.PlugChilds[bus_id].GetElementIdFromName(name) |
12 | 46 |
if block_id == None: |
47 |
raise ValueError, "No corresponding block found" |
|
48 |
if not generator.ComputedBlocks.get(name, False): |
|
49 |
for num, variable in enumerate(block.inputVariables.getVariable()): |
|
50 |
connections = variable.connectionPointIn.getConnections() |
|
51 |
if connections and len(connections) == 1: |
|
52 |
parameter = "__I%s%d_%d_%d"%(TYPECONVERSION[block_infos["inputs"][num][1]], bus_id, block_id, num) |
|
53 |
value = generator.ComputeFBDExpression(body, connections[0]) |
|
54 |
generator.Program += (" %s := %s;\n"%(parameter, generator.ExtractModifier(variable, value))) |
|
55 |
generator.ComputedBlocks[name] = True |
|
56 |
if link: |
|
57 |
connectionPoint = link.getPosition()[-1] |
|
58 |
for num, variable in enumerate(block.outputVariables.getVariable()): |
|
59 |
blockPointx, blockPointy = variable.connectionPointOut.getRelPosition() |
|
60 |
if block.getX() + blockPointx == connectionPoint.getX() and block.getY() + blockPointy == connectionPoint.getY(): |
|
61 |
return "__Q%s%d_%d_%d"%(TYPECONVERSION[block_infos["outputs"][num][1]], bus_id, block_id, num) |
|
62 |
raise ValueError, "No output variable found" |
|
63 |
else: |
|
64 |
return None |
|
11 | 65 |
|
12 | 66 |
return [{"name" : "SVGUI function blocks", "list" : |
67 |
[{"name" : "Container", "type" : "functionBlock", "extensible" : False, |
|
68 |
"inputs" : [("X","FLOAT","none"),("SetX","BOOL","none"),("Y","FLOAT","none"),("SetY","BOOL","none"),("Angle","FLOAT","none"),("SetAngle","BOOL","none")], |
|
69 |
"outputs" : [("X","FLOAT","none"),("X Changed","BOOL","none"),("Y","FLOAT","none"),("Y Changed","BOOL","none"),("Angle","FLOAT","none"),("Angle Changed","BOOL","none")], |
|
70 |
"comment" : "SVGUI Container", "generate": generate_svgui_block}, |
|
71 |
{"name" : "Button", "type" : "functionBlock", "extensible" : False, |
|
72 |
"inputs" : [("Show","BOOL","none"),("Toggle","BOOL","none")], |
|
73 |
"outputs" : [("Visible","BOOL","none"),("State","BOOL","none")], |
|
74 |
"comment" : "SVGUI Button", "generate": generate_svgui_block}, |
|
75 |
{"name" : "TextCtrl", "type" : "functionBlock", "extensible" : False, |
|
76 |
"inputs" : [("Text","STRING","none"),("Set Text","BOOL","none")], |
|
77 |
"outputs" : [("Text","STRING","none"),("Text Changed","BOOL","none")], |
|
78 |
"comment" : "SVGUI Text Control", "generate": generate_svgui_block}, |
|
79 |
{"name" : "ScrollBar", "type" : "functionBlock", "extensible" : False, |
|
80 |
"inputs" : [("Position","UINT","none"),("Set Position","BOOL","none")], |
|
81 |
"outputs" : [("Position","UINT","none"),("Position Changed","BOOL","none")], |
|
82 |
"comment" : "SVGUI ScrollBar", "generate": generate_svgui_block}, |
|
83 |
{"name" : "NoteBook", "type" : "functionBlock", "extensible" : False, |
|
84 |
"inputs" : [("Selected","UINT","none"),("Set Selected","BOOL","none")], |
|
85 |
"outputs" : [("Selected","UINT","none"),("Selected Changed","BOOL","none")], |
|
86 |
"comment" : "SVGUI Notebook", "generate": generate_svgui_block}, |
|
87 |
{"name" : "RotatingCtrl", "type" : "functionBlock", "extensible" : False, |
|
88 |
"inputs" : [("Angle","FLOAT","none"),("Set Angle","BOOL","none")], |
|
89 |
"outputs" : [("Angle","FLOAT","none"),("Angle changed","BOOL","none")], |
|
90 |
"comment" : "SVGUI Rotating Control", "generate": generate_svgui_block} |
|
91 |
]}] |
|
92 |
||
93 |
||
94 |
||
95 |
||
96 |
||
97 |
||
98 |
||
99 |
||
100 |