43 "VAR_INPUT": "var_input", |
43 "VAR_INPUT": "var_input", |
44 "VAR_OUTPUT": "var_output", |
44 "VAR_OUTPUT": "var_output", |
45 "VAR_INOUT": "var_inout", |
45 "VAR_INOUT": "var_inout", |
46 } |
46 } |
47 |
47 |
48 # Helper function for reindenting text |
48 |
49 def ReIndentText(text, nb_spaces): |
49 def ReIndentText(text, nb_spaces): |
|
50 """ Helper function for reindenting text """ |
50 compute = "" |
51 compute = "" |
51 lines = text.splitlines() |
52 lines = text.splitlines() |
52 if len(lines) > 0: |
53 if len(lines) > 0: |
53 line_num = 0 |
54 line_num = 0 |
54 while line_num < len(lines) and len(lines[line_num].strip()) == 0: |
55 while line_num < len(lines) and len(lines[line_num].strip()) == 0: |
65 compute += "%s%s\n" % (indent, line) |
66 compute += "%s%s\n" % (indent, line) |
66 else: |
67 else: |
67 compute += "\n" |
68 compute += "\n" |
68 return compute |
69 return compute |
69 |
70 |
|
71 |
70 def SortInstances(a, b): |
72 def SortInstances(a, b): |
71 ax, ay = int(a.getx()), int(a.gety()) |
73 ax, ay = int(a.getx()), int(a.gety()) |
72 bx, by = int(b.getx()), int(b.gety()) |
74 bx, by = int(b.getx()), int(b.gety()) |
73 if abs(ay - by) < 10: |
75 if abs(ay - by) < 10: |
74 return cmp(ax, bx) |
76 return cmp(ax, bx) |
75 else: |
77 else: |
76 return cmp(ay, by) |
78 return cmp(ay, by) |
77 |
79 |
78 # Helper for emulate join on element list |
80 |
79 def JoinList(separator, mylist): |
81 def JoinList(separator, mylist): |
|
82 """ Helper for emulate join on element list """ |
80 if len(mylist) > 0 : |
83 if len(mylist) > 0 : |
81 return reduce(lambda x, y: x + separator + y, mylist) |
84 return reduce(lambda x, y: x + separator + y, mylist) |
82 else : |
85 else : |
83 return mylist |
86 return mylist |
84 |
87 |
497 for instance_name in ["step", "transition", "jumpStep", |
500 for instance_name in ["step", "transition", "jumpStep", |
498 "selectionConvergence", "selectionDivergence", |
501 "selectionConvergence", "selectionDivergence", |
499 "simultaneousConvergence", "simultaneousDivergence"]] |
502 "simultaneousConvergence", "simultaneousDivergence"]] |
500 TransitionObjClass = PLCOpenParser.GetElementClass("transition", "transitions") |
503 TransitionObjClass = PLCOpenParser.GetElementClass("transition", "transitions") |
501 ActionObjClass = PLCOpenParser.GetElementClass("action", "actions") |
504 ActionObjClass = PLCOpenParser.GetElementClass("action", "actions") |
|
505 |
502 |
506 |
503 class PouProgramGenerator: |
507 class PouProgramGenerator: |
504 |
508 |
505 # Create a new POU program generator |
509 # Create a new POU program generator |
506 def __init__(self, parent, name, type, errors, warnings): |
510 def __init__(self, parent, name, type, errors, warnings): |
1656 program += [("\n", ())] |
1660 program += [("\n", ())] |
1657 program += self.Program |
1661 program += self.Program |
1658 program += [("END_%s\n\n" % self.Type, ())] |
1662 program += [("END_%s\n\n" % self.Type, ())] |
1659 return program |
1663 return program |
1660 |
1664 |
|
1665 |
1661 def GenerateCurrentProgram(controler, project, errors, warnings): |
1666 def GenerateCurrentProgram(controler, project, errors, warnings): |
1662 generator = ProgramGenerator(controler, project, errors, warnings) |
1667 generator = ProgramGenerator(controler, project, errors, warnings) |
1663 generator.GenerateProgram() |
1668 generator.GenerateProgram() |
1664 return generator.GetGeneratedProgram() |
1669 return generator.GetGeneratedProgram() |