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