author | Andrey Skvortsov <andrej.skvortzov@gmail.com> |
Thu, 22 Jun 2017 16:07:56 +0300 | |
changeset 1704 | 794a47ef5323 |
parent 1626 | 0779c1b18c01 |
child 1730 | 64d8f52bc8c8 |
permissions | -rw-r--r-- |
814 | 1 |
#!/usr/bin/env python |
2 |
# -*- coding: utf-8 -*- |
|
3 |
||
1571
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1450
diff
changeset
|
4 |
# This file is part of Beremiz, a Integrated Development Environment for |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1450
diff
changeset
|
5 |
# programming IEC 61131-3 automates supporting plcopen standard and CanFestival. |
814 | 6 |
# |
1571
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1450
diff
changeset
|
7 |
# Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD |
814 | 8 |
# |
1571
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1450
diff
changeset
|
9 |
# See COPYING file for copyrights details. |
814 | 10 |
# |
1571
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1450
diff
changeset
|
11 |
# This program is free software; you can redistribute it and/or |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1450
diff
changeset
|
12 |
# modify it under the terms of the GNU General Public License |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1450
diff
changeset
|
13 |
# as published by the Free Software Foundation; either version 2 |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1450
diff
changeset
|
14 |
# of the License, or (at your option) any later version. |
814 | 15 |
# |
1571
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1450
diff
changeset
|
16 |
# This program is distributed in the hope that it will be useful, |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1450
diff
changeset
|
17 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1450
diff
changeset
|
18 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1450
diff
changeset
|
19 |
# GNU General Public License for more details. |
814 | 20 |
# |
1571
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1450
diff
changeset
|
21 |
# You should have received a copy of the GNU General Public License |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1450
diff
changeset
|
22 |
# along with this program; if not, write to the Free Software |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1450
diff
changeset
|
23 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
814 | 24 |
|
1297 | 25 |
from plcopen import PLCOpenParser |
814 | 26 |
from plcopen.structures import * |
27 |
from types import * |
|
28 |
import re |
|
29 |
||
1418
c97dc5281419
Fixed declaration and ST code gen for IEC function that return derivated types
Edouard Tisserant
parents:
1358
diff
changeset
|
30 |
# Dictionary associating PLCOpen variable categories to the corresponding |
814 | 31 |
# IEC 61131-3 variable categories |
1418
c97dc5281419
Fixed declaration and ST code gen for IEC function that return derivated types
Edouard Tisserant
parents:
1358
diff
changeset
|
32 |
varTypeNames = {"localVars" : "VAR", "tempVars" : "VAR_TEMP", "inputVars" : "VAR_INPUT", |
814 | 33 |
"outputVars" : "VAR_OUTPUT", "inOutVars" : "VAR_IN_OUT", "externalVars" : "VAR_EXTERNAL", |
34 |
"globalVars" : "VAR_GLOBAL", "accessVars" : "VAR_ACCESS"} |
|
35 |
||
36 |
||
1418
c97dc5281419
Fixed declaration and ST code gen for IEC function that return derivated types
Edouard Tisserant
parents:
1358
diff
changeset
|
37 |
# Dictionary associating PLCOpen POU categories to the corresponding |
814 | 38 |
# IEC 61131-3 POU categories |
39 |
pouTypeNames = {"function" : "FUNCTION", "functionBlock" : "FUNCTION_BLOCK", "program" : "PROGRAM"} |
|
40 |
||
41 |
||
42 |
errorVarTypes = { |
|
43 |
"VAR_INPUT": "var_input", |
|
44 |
"VAR_OUTPUT": "var_output", |
|
45 |
"VAR_INOUT": "var_inout", |
|
46 |
} |
|
47 |
||
48 |
# Helper function for reindenting text |
|
49 |
def ReIndentText(text, nb_spaces): |
|
50 |
compute = "" |
|
51 |
lines = text.splitlines() |
|
52 |
if len(lines) > 0: |
|
53 |
line_num = 0 |
|
54 |
while line_num < len(lines) and len(lines[line_num].strip()) == 0: |
|
55 |
line_num += 1 |
|
56 |
if line_num < len(lines): |
|
57 |
spaces = 0 |
|
58 |
while lines[line_num][spaces] == " ": |
|
59 |
spaces += 1 |
|
60 |
indent = "" |
|
61 |
for i in xrange(spaces, nb_spaces): |
|
62 |
indent += " " |
|
63 |
for line in lines: |
|
64 |
if line != "": |
|
65 |
compute += "%s%s\n"%(indent, line) |
|
66 |
else: |
|
67 |
compute += "\n" |
|
68 |
return compute |
|
69 |
||
70 |
def SortInstances(a, b): |
|
71 |
ax, ay = int(a.getx()), int(a.gety()) |
|
72 |
bx, by = int(b.getx()), int(b.gety()) |
|
73 |
if abs(ay - by) < 10: |
|
74 |
return cmp(ax, bx) |
|
75 |
else: |
|
76 |
return cmp(ay, by) |
|
77 |
||
1310
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
78 |
# Helper for emulate join on element list |
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
79 |
def JoinList(separator, mylist): |
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
80 |
if len(mylist) > 0 : |
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
81 |
return reduce(lambda x, y: x + separator + y, mylist) |
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
82 |
else : |
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
83 |
return mylist |
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
84 |
|
814 | 85 |
#------------------------------------------------------------------------------- |
86 |
# Specific exception for PLC generating errors |
|
87 |
#------------------------------------------------------------------------------- |
|
88 |
||
89 |
||
90 |
class PLCGenException(Exception): |
|
91 |
pass |
|
92 |
||
93 |
||
94 |
#------------------------------------------------------------------------------- |
|
95 |
# Generator of PLC program |
|
96 |
#------------------------------------------------------------------------------- |
|
97 |
||
98 |
||
99 |
class ProgramGenerator: |
|
100 |
||
101 |
# Create a new PCL program generator |
|
102 |
def __init__(self, controler, project, errors, warnings): |
|
103 |
# Keep reference of the controler and project |
|
104 |
self.Controler = controler |
|
105 |
self.Project = project |
|
106 |
# Reset the internal variables used to generate PLC programs |
|
107 |
self.Program = [] |
|
108 |
self.DatatypeComputed = {} |
|
109 |
self.PouComputed = {} |
|
110 |
self.Errors = errors |
|
111 |
self.Warnings = warnings |
|
112 |
||
113 |
# Compute value according to type given |
|
114 |
def ComputeValue(self, value, var_type): |
|
115 |
base_type = self.Controler.GetBaseType(var_type) |
|
1032
c4989e53f9c3
Fix bug defining string initial value using quotes
Laurent Bessard
parents:
893
diff
changeset
|
116 |
if base_type == "STRING" and not value.startswith("'") and not value.endswith("'"): |
814 | 117 |
return "'%s'"%value |
1032
c4989e53f9c3
Fix bug defining string initial value using quotes
Laurent Bessard
parents:
893
diff
changeset
|
118 |
elif base_type == "WSTRING" and not value.startswith('"') and not value.endswith('"'): |
814 | 119 |
return "\"%s\""%value |
120 |
return value |
|
121 |
||
122 |
# Generate a data type from its name |
|
123 |
def GenerateDataType(self, datatype_name): |
|
124 |
# Verify that data type hasn't been generated yet |
|
125 |
if not self.DatatypeComputed.get(datatype_name, True): |
|
126 |
# If not mark data type as computed |
|
127 |
self.DatatypeComputed[datatype_name] = True |
|
1418
c97dc5281419
Fixed declaration and ST code gen for IEC function that return derivated types
Edouard Tisserant
parents:
1358
diff
changeset
|
128 |
|
814 | 129 |
# Getting datatype model from project |
130 |
datatype = self.Project.getdataType(datatype_name) |
|
131 |
tagname = self.Controler.ComputeDataTypeName(datatype.getname()) |
|
1418
c97dc5281419
Fixed declaration and ST code gen for IEC function that return derivated types
Edouard Tisserant
parents:
1358
diff
changeset
|
132 |
datatype_def = [(" ", ()), |
814 | 133 |
(datatype.getname(), (tagname, "name")), |
134 |
(" : ", ())] |
|
135 |
basetype_content = datatype.baseType.getcontent() |
|
1297 | 136 |
basetype_content_type = basetype_content.getLocalTag() |
1418
c97dc5281419
Fixed declaration and ST code gen for IEC function that return derivated types
Edouard Tisserant
parents:
1358
diff
changeset
|
137 |
# Data type derived directly from a user defined type |
1297 | 138 |
if basetype_content_type == "derived": |
139 |
basetype_name = basetype_content.getname() |
|
814 | 140 |
self.GenerateDataType(basetype_name) |
141 |
datatype_def += [(basetype_name, (tagname, "base"))] |
|
142 |
# Data type is a subrange |
|
1297 | 143 |
elif basetype_content_type in ["subrangeSigned", "subrangeUnsigned"]: |
144 |
base_type = basetype_content.baseType.getcontent() |
|
145 |
base_type_type = base_type.getLocalTag() |
|
1418
c97dc5281419
Fixed declaration and ST code gen for IEC function that return derivated types
Edouard Tisserant
parents:
1358
diff
changeset
|
146 |
# Subrange derived directly from a user defined type |
1297 | 147 |
if base_type_type == "derived": |
148 |
basetype_name = base_type_type.getname() |
|
814 | 149 |
self.GenerateDataType(basetype_name) |
1418
c97dc5281419
Fixed declaration and ST code gen for IEC function that return derivated types
Edouard Tisserant
parents:
1358
diff
changeset
|
150 |
# Subrange derived directly from an elementary type |
814 | 151 |
else: |
1297 | 152 |
basetype_name = base_type_type |
153 |
min_value = basetype_content.range.getlower() |
|
154 |
max_value = basetype_content.range.getupper() |
|
814 | 155 |
datatype_def += [(basetype_name, (tagname, "base")), |
156 |
(" (", ()), |
|
157 |
("%s"%min_value, (tagname, "lower")), |
|
158 |
("..", ()), |
|
159 |
("%s"%max_value, (tagname, "upper")), |
|
160 |
(")",())] |
|
161 |
# Data type is an enumerated type |
|
1297 | 162 |
elif basetype_content_type == "enum": |
814 | 163 |
values = [[(value.getname(), (tagname, "value", i))] |
1297 | 164 |
for i, value in enumerate( |
1418
c97dc5281419
Fixed declaration and ST code gen for IEC function that return derivated types
Edouard Tisserant
parents:
1358
diff
changeset
|
165 |
basetype_content.xpath("ppx:values/ppx:value", |
1297 | 166 |
namespaces=PLCOpenParser.NSMAP))] |
814 | 167 |
datatype_def += [("(", ())] |
168 |
datatype_def += JoinList([(", ", ())], values) |
|
169 |
datatype_def += [(")", ())] |
|
170 |
# Data type is an array |
|
1297 | 171 |
elif basetype_content_type == "array": |
172 |
base_type = basetype_content.baseType.getcontent() |
|
173 |
base_type_type = base_type.getLocalTag() |
|
1418
c97dc5281419
Fixed declaration and ST code gen for IEC function that return derivated types
Edouard Tisserant
parents:
1358
diff
changeset
|
174 |
# Array derived directly from a user defined type |
1297 | 175 |
if base_type_type == "derived": |
176 |
basetype_name = base_type.getname() |
|
814 | 177 |
self.GenerateDataType(basetype_name) |
1418
c97dc5281419
Fixed declaration and ST code gen for IEC function that return derivated types
Edouard Tisserant
parents:
1358
diff
changeset
|
178 |
# Array derived directly from an elementary type |
814 | 179 |
else: |
1297 | 180 |
basetype_name = base_type_type.upper() |
814 | 181 |
dimensions = [[("%s"%dimension.getlower(), (tagname, "range", i, "lower")), |
182 |
("..", ()), |
|
1418
c97dc5281419
Fixed declaration and ST code gen for IEC function that return derivated types
Edouard Tisserant
parents:
1358
diff
changeset
|
183 |
("%s"%dimension.getupper(), (tagname, "range", i, "upper"))] |
1297 | 184 |
for i, dimension in enumerate(basetype_content.getdimension())] |
814 | 185 |
datatype_def += [("ARRAY [", ())] |
186 |
datatype_def += JoinList([(",", ())], dimensions) |
|
187 |
datatype_def += [("] OF " , ()), |
|
188 |
(basetype_name, (tagname, "base"))] |
|
189 |
# Data type is a structure |
|
1297 | 190 |
elif basetype_content_type == "struct": |
814 | 191 |
elements = [] |
1297 | 192 |
for i, element in enumerate(basetype_content.getvariable()): |
814 | 193 |
element_type = element.type.getcontent() |
1297 | 194 |
element_type_type = element_type.getLocalTag() |
1418
c97dc5281419
Fixed declaration and ST code gen for IEC function that return derivated types
Edouard Tisserant
parents:
1358
diff
changeset
|
195 |
# Structure element derived directly from a user defined type |
1297 | 196 |
if element_type_type == "derived": |
197 |
elementtype_name = element_type.getname() |
|
814 | 198 |
self.GenerateDataType(elementtype_name) |
1297 | 199 |
elif element_type_type == "array": |
200 |
base_type = element_type.baseType.getcontent() |
|
201 |
base_type_type = base_type.getLocalTag() |
|
1418
c97dc5281419
Fixed declaration and ST code gen for IEC function that return derivated types
Edouard Tisserant
parents:
1358
diff
changeset
|
202 |
# Array derived directly from a user defined type |
1297 | 203 |
if base_type_type == "derived": |
204 |
basetype_name = base_type.getname() |
|
864
bf4f7f0801b9
Adding support for direct array declaration in structure element declaration
Laurent Bessard
parents:
854
diff
changeset
|
205 |
self.GenerateDataType(basetype_name) |
1418
c97dc5281419
Fixed declaration and ST code gen for IEC function that return derivated types
Edouard Tisserant
parents:
1358
diff
changeset
|
206 |
# Array derived directly from an elementary type |
864
bf4f7f0801b9
Adding support for direct array declaration in structure element declaration
Laurent Bessard
parents:
854
diff
changeset
|
207 |
else: |
1297 | 208 |
basetype_name = base_type_type.upper() |
864
bf4f7f0801b9
Adding support for direct array declaration in structure element declaration
Laurent Bessard
parents:
854
diff
changeset
|
209 |
dimensions = ["%s..%s" % (dimension.getlower(), dimension.getupper()) |
1297 | 210 |
for dimension in element_type.getdimension()] |
864
bf4f7f0801b9
Adding support for direct array declaration in structure element declaration
Laurent Bessard
parents:
854
diff
changeset
|
211 |
elementtype_name = "ARRAY [%s] OF %s" % (",".join(dimensions), basetype_name) |
1418
c97dc5281419
Fixed declaration and ST code gen for IEC function that return derivated types
Edouard Tisserant
parents:
1358
diff
changeset
|
212 |
# Structure element derived directly from an elementary type |
814 | 213 |
else: |
1297 | 214 |
elementtype_name = element_type_type.upper() |
814 | 215 |
element_text = [("\n ", ()), |
216 |
(element.getname(), (tagname, "struct", i, "name")), |
|
217 |
(" : ", ()), |
|
218 |
(elementtype_name, (tagname, "struct", i, "type"))] |
|
219 |
if element.initialValue is not None: |
|
220 |
element_text.extend([(" := ", ()), |
|
221 |
(self.ComputeValue(element.initialValue.getvalue(), elementtype_name), (tagname, "struct", i, "initial value"))]) |
|
222 |
element_text.append((";", ())) |
|
223 |
elements.append(element_text) |
|
224 |
datatype_def += [("STRUCT", ())] |
|
225 |
datatype_def += JoinList([("", ())], elements) |
|
226 |
datatype_def += [("\n END_STRUCT", ())] |
|
1418
c97dc5281419
Fixed declaration and ST code gen for IEC function that return derivated types
Edouard Tisserant
parents:
1358
diff
changeset
|
227 |
# Data type derived directly from a elementary type |
814 | 228 |
else: |
1297 | 229 |
datatype_def += [(basetype_content_type.upper(), (tagname, "base"))] |
814 | 230 |
# Data type has an initial value |
231 |
if datatype.initialValue is not None: |
|
232 |
datatype_def += [(" := ", ()), |
|
233 |
(self.ComputeValue(datatype.initialValue.getvalue(), datatype_name), (tagname, "initial value"))] |
|
234 |
datatype_def += [(";\n", ())] |
|
235 |
self.Program += datatype_def |
|
236 |
||
237 |
# Generate a POU from its name |
|
238 |
def GeneratePouProgram(self, pou_name): |
|
239 |
# Verify that POU hasn't been generated yet |
|
240 |
if not self.PouComputed.get(pou_name, True): |
|
241 |
# If not mark POU as computed |
|
242 |
self.PouComputed[pou_name] = True |
|
1418
c97dc5281419
Fixed declaration and ST code gen for IEC function that return derivated types
Edouard Tisserant
parents:
1358
diff
changeset
|
243 |
|
814 | 244 |
# Getting POU model from project |
245 |
pou = self.Project.getpou(pou_name) |
|
246 |
pou_type = pou.getpouType() |
|
247 |
# Verify that POU type exists |
|
248 |
if pouTypeNames.has_key(pou_type): |
|
249 |
# Create a POU program generator |
|
250 |
pou_program = PouProgramGenerator(self, pou.getname(), pouTypeNames[pou_type], self.Errors, self.Warnings) |
|
251 |
program = pou_program.GenerateProgram(pou) |
|
252 |
self.Program += program |
|
253 |
else: |
|
254 |
raise PLCGenException, _("Undefined pou type \"%s\"")%pou_type |
|
1418
c97dc5281419
Fixed declaration and ST code gen for IEC function that return derivated types
Edouard Tisserant
parents:
1358
diff
changeset
|
255 |
|
814 | 256 |
# Generate a POU defined and used in text |
257 |
def GeneratePouProgramInText(self, text): |
|
258 |
for pou_name in self.PouComputed.keys(): |
|
259 |
model = re.compile("(?:^|[^0-9^A-Z])%s(?:$|[^0-9^A-Z])"%pou_name.upper()) |
|
260 |
if model.search(text) is not None: |
|
261 |
self.GeneratePouProgram(pou_name) |
|
1418
c97dc5281419
Fixed declaration and ST code gen for IEC function that return derivated types
Edouard Tisserant
parents:
1358
diff
changeset
|
262 |
|
814 | 263 |
# Generate a configuration from its model |
264 |
def GenerateConfiguration(self, configuration): |
|
265 |
tagname = self.Controler.ComputeConfigurationName(configuration.getname()) |
|
266 |
config = [("\nCONFIGURATION ", ()), |
|
267 |
(configuration.getname(), (tagname, "name")), |
|
268 |
("\n", ())] |
|
269 |
var_number = 0 |
|
1418
c97dc5281419
Fixed declaration and ST code gen for IEC function that return derivated types
Edouard Tisserant
parents:
1358
diff
changeset
|
270 |
|
883
235a9ec83b95
Adding support for defining specific global variables for ConfTreeNodes
Laurent Bessard
parents:
864
diff
changeset
|
271 |
varlists = [(varlist, varlist.getvariable()[:]) for varlist in configuration.getglobalVars()] |
1418
c97dc5281419
Fixed declaration and ST code gen for IEC function that return derivated types
Edouard Tisserant
parents:
1358
diff
changeset
|
272 |
|
883
235a9ec83b95
Adding support for defining specific global variables for ConfTreeNodes
Laurent Bessard
parents:
864
diff
changeset
|
273 |
extra_variables = self.Controler.GetConfigurationExtraVariables() |
1315
ff14a66bbd12
Fixed Beremiz for working with new xmlclass support using lxml
Laurent Bessard
parents:
1310
diff
changeset
|
274 |
extra_global_vars = None |
ff14a66bbd12
Fixed Beremiz for working with new xmlclass support using lxml
Laurent Bessard
parents:
1310
diff
changeset
|
275 |
if len(extra_variables) > 0 and len(varlists) == 0: |
ff14a66bbd12
Fixed Beremiz for working with new xmlclass support using lxml
Laurent Bessard
parents:
1310
diff
changeset
|
276 |
extra_global_vars = PLCOpenParser.CreateElement("globalVars", "interface") |
ff14a66bbd12
Fixed Beremiz for working with new xmlclass support using lxml
Laurent Bessard
parents:
1310
diff
changeset
|
277 |
configuration.setglobalVars([extra_global_vars]) |
ff14a66bbd12
Fixed Beremiz for working with new xmlclass support using lxml
Laurent Bessard
parents:
1310
diff
changeset
|
278 |
varlists = [(extra_global_vars, [])] |
1418
c97dc5281419
Fixed declaration and ST code gen for IEC function that return derivated types
Edouard Tisserant
parents:
1358
diff
changeset
|
279 |
|
1315
ff14a66bbd12
Fixed Beremiz for working with new xmlclass support using lxml
Laurent Bessard
parents:
1310
diff
changeset
|
280 |
for variable in extra_variables: |
ff14a66bbd12
Fixed Beremiz for working with new xmlclass support using lxml
Laurent Bessard
parents:
1310
diff
changeset
|
281 |
varlists[-1][0].appendvariable(variable) |
ff14a66bbd12
Fixed Beremiz for working with new xmlclass support using lxml
Laurent Bessard
parents:
1310
diff
changeset
|
282 |
varlists[-1][1].append(variable) |
1418
c97dc5281419
Fixed declaration and ST code gen for IEC function that return derivated types
Edouard Tisserant
parents:
1358
diff
changeset
|
283 |
|
814 | 284 |
# Generate any global variable in configuration |
883
235a9ec83b95
Adding support for defining specific global variables for ConfTreeNodes
Laurent Bessard
parents:
864
diff
changeset
|
285 |
for varlist, varlist_variables in varlists: |
814 | 286 |
variable_type = errorVarTypes.get("VAR_GLOBAL", "var_local") |
287 |
# Generate variable block with modifier |
|
288 |
config += [(" VAR_GLOBAL", ())] |
|
289 |
if varlist.getconstant(): |
|
290 |
config += [(" CONSTANT", (tagname, variable_type, (var_number, var_number + len(varlist.getvariable())), "constant"))] |
|
291 |
elif varlist.getretain(): |
|
292 |
config += [(" RETAIN", (tagname, variable_type, (var_number, var_number + len(varlist.getvariable())), "retain"))] |
|
293 |
elif varlist.getnonretain(): |
|
294 |
config += [(" NON_RETAIN", (tagname, variable_type, (var_number, var_number + len(varlist.getvariable())), "non_retain"))] |
|
295 |
config += [("\n", ())] |
|
296 |
# Generate any variable of this block |
|
883
235a9ec83b95
Adding support for defining specific global variables for ConfTreeNodes
Laurent Bessard
parents:
864
diff
changeset
|
297 |
for var in varlist_variables: |
814 | 298 |
vartype_content = var.gettype().getcontent() |
1297 | 299 |
if vartype_content.getLocalTag() == "derived": |
300 |
var_type = vartype_content.getname() |
|
814 | 301 |
self.GenerateDataType(var_type) |
302 |
else: |
|
303 |
var_type = var.gettypeAsText() |
|
1418
c97dc5281419
Fixed declaration and ST code gen for IEC function that return derivated types
Edouard Tisserant
parents:
1358
diff
changeset
|
304 |
|
814 | 305 |
config += [(" ", ()), |
306 |
(var.getname(), (tagname, variable_type, var_number, "name")), |
|
307 |
(" ", ())] |
|
308 |
# Generate variable address if exists |
|
309 |
address = var.getaddress() |
|
310 |
if address: |
|
311 |
config += [("AT ", ()), |
|
312 |
(address, (tagname, variable_type, var_number, "location")), |
|
313 |
(" ", ())] |
|
314 |
config += [(": ", ()), |
|
315 |
(var.gettypeAsText(), (tagname, variable_type, var_number, "type"))] |
|
316 |
# Generate variable initial value if exists |
|
317 |
initial = var.getinitialValue() |
|
1315
ff14a66bbd12
Fixed Beremiz for working with new xmlclass support using lxml
Laurent Bessard
parents:
1310
diff
changeset
|
318 |
if initial is not None: |
814 | 319 |
config += [(" := ", ()), |
320 |
(self.ComputeValue(initial.getvalue(), var_type), (tagname, variable_type, var_number, "initial value"))] |
|
321 |
config += [(";\n", ())] |
|
322 |
var_number += 1 |
|
323 |
config += [(" END_VAR\n", ())] |
|
1418
c97dc5281419
Fixed declaration and ST code gen for IEC function that return derivated types
Edouard Tisserant
parents:
1358
diff
changeset
|
324 |
|
1315
ff14a66bbd12
Fixed Beremiz for working with new xmlclass support using lxml
Laurent Bessard
parents:
1310
diff
changeset
|
325 |
if extra_global_vars is not None: |
ff14a66bbd12
Fixed Beremiz for working with new xmlclass support using lxml
Laurent Bessard
parents:
1310
diff
changeset
|
326 |
configuration.remove(extra_global_vars) |
ff14a66bbd12
Fixed Beremiz for working with new xmlclass support using lxml
Laurent Bessard
parents:
1310
diff
changeset
|
327 |
else: |
ff14a66bbd12
Fixed Beremiz for working with new xmlclass support using lxml
Laurent Bessard
parents:
1310
diff
changeset
|
328 |
for variable in extra_variables: |
1358
fe7770a30527
Fixed bug when building project with configuration extra variables
Laurent Bessard
parents:
1322
diff
changeset
|
329 |
varlists[-1][0].remove(variable) |
1418
c97dc5281419
Fixed declaration and ST code gen for IEC function that return derivated types
Edouard Tisserant
parents:
1358
diff
changeset
|
330 |
|
814 | 331 |
# Generate any resource in the configuration |
332 |
for resource in configuration.getresource(): |
|
333 |
config += self.GenerateResource(resource, configuration.getname()) |
|
334 |
config += [("END_CONFIGURATION\n", ())] |
|
335 |
return config |
|
1418
c97dc5281419
Fixed declaration and ST code gen for IEC function that return derivated types
Edouard Tisserant
parents:
1358
diff
changeset
|
336 |
|
814 | 337 |
# Generate a resource from its model |
338 |
def GenerateResource(self, resource, config_name): |
|
339 |
tagname = self.Controler.ComputeConfigurationResourceName(config_name, resource.getname()) |
|
340 |
resrce = [("\n RESOURCE ", ()), |
|
341 |
(resource.getname(), (tagname, "name")), |
|
342 |
(" ON PLC\n", ())] |
|
343 |
var_number = 0 |
|
344 |
# Generate any global variable in configuration |
|
345 |
for varlist in resource.getglobalVars(): |
|
346 |
variable_type = errorVarTypes.get("VAR_GLOBAL", "var_local") |
|
347 |
# Generate variable block with modifier |
|
348 |
resrce += [(" VAR_GLOBAL", ())] |
|
349 |
if varlist.getconstant(): |
|
350 |
resrce += [(" CONSTANT", (tagname, variable_type, (var_number, var_number + len(varlist.getvariable())), "constant"))] |
|
351 |
elif varlist.getretain(): |
|
352 |
resrce += [(" RETAIN", (tagname, variable_type, (var_number, var_number + len(varlist.getvariable())), "retain"))] |
|
353 |
elif varlist.getnonretain(): |
|
354 |
resrce += [(" NON_RETAIN", (tagname, variable_type, (var_number, var_number + len(varlist.getvariable())), "non_retain"))] |
|
355 |
resrce += [("\n", ())] |
|
356 |
# Generate any variable of this block |
|
357 |
for var in varlist.getvariable(): |
|
358 |
vartype_content = var.gettype().getcontent() |
|
1297 | 359 |
if vartype_content.getLocalTag() == "derived": |
360 |
var_type = vartype_content.getname() |
|
814 | 361 |
self.GenerateDataType(var_type) |
362 |
else: |
|
363 |
var_type = var.gettypeAsText() |
|
1418
c97dc5281419
Fixed declaration and ST code gen for IEC function that return derivated types
Edouard Tisserant
parents:
1358
diff
changeset
|
364 |
|
814 | 365 |
resrce += [(" ", ()), |
366 |
(var.getname(), (tagname, variable_type, var_number, "name")), |
|
367 |
(" ", ())] |
|
368 |
address = var.getaddress() |
|
369 |
# Generate variable address if exists |
|
370 |
if address: |
|
371 |
resrce += [("AT ", ()), |
|
372 |
(address, (tagname, variable_type, var_number, "location")), |
|
373 |
(" ", ())] |
|
374 |
resrce += [(": ", ()), |
|
375 |
(var.gettypeAsText(), (tagname, variable_type, var_number, "type"))] |
|
376 |
# Generate variable initial value if exists |
|
377 |
initial = var.getinitialValue() |
|
1315
ff14a66bbd12
Fixed Beremiz for working with new xmlclass support using lxml
Laurent Bessard
parents:
1310
diff
changeset
|
378 |
if initial is not None: |
814 | 379 |
resrce += [(" := ", ()), |
380 |
(self.ComputeValue(initial.getvalue(), var_type), (tagname, variable_type, var_number, "initial value"))] |
|
381 |
resrce += [(";\n", ())] |
|
382 |
var_number += 1 |
|
383 |
resrce += [(" END_VAR\n", ())] |
|
384 |
# Generate any task in the resource |
|
385 |
tasks = resource.gettask() |
|
386 |
task_number = 0 |
|
387 |
for task in tasks: |
|
388 |
# Task declaration |
|
389 |
resrce += [(" TASK ", ()), |
|
390 |
(task.getname(), (tagname, "task", task_number, "name")), |
|
391 |
("(", ())] |
|
392 |
args = [] |
|
393 |
single = task.getsingle() |
|
394 |
# Single argument if exists |
|
1315
ff14a66bbd12
Fixed Beremiz for working with new xmlclass support using lxml
Laurent Bessard
parents:
1310
diff
changeset
|
395 |
if single is not None: |
1614
f8f05f849831
check during program generation whether source signal is defined for single task
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1603
diff
changeset
|
396 |
if len(single) == 0: |
f8f05f849831
check during program generation whether source signal is defined for single task
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1603
diff
changeset
|
397 |
msg = _("Source signal has to be defined for single task '{a1}' in resource '{a2}.{a3}'.").\ |
f8f05f849831
check during program generation whether source signal is defined for single task
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1603
diff
changeset
|
398 |
format(a1 = task.getname(), a2 = config_name, a3 = resource.getname()) |
f8f05f849831
check during program generation whether source signal is defined for single task
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1603
diff
changeset
|
399 |
raise PLCGenException, msg |
f8f05f849831
check during program generation whether source signal is defined for single task
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1603
diff
changeset
|
400 |
|
1420
71b1545d746f
Enable overloading of task triggerring source cell editor (SINGLE) in resource editor. PLCGenerator now generates MULTI keywork instead of SINGLE when task's activation is surroundes with square brackets
Edouard Tisserant
parents:
1418
diff
changeset
|
401 |
if single[0]=='[' and single[-1]==']' : |
71b1545d746f
Enable overloading of task triggerring source cell editor (SINGLE) in resource editor. PLCGenerator now generates MULTI keywork instead of SINGLE when task's activation is surroundes with square brackets
Edouard Tisserant
parents:
1418
diff
changeset
|
402 |
SNGLKW = "MULTI" |
71b1545d746f
Enable overloading of task triggerring source cell editor (SINGLE) in resource editor. PLCGenerator now generates MULTI keywork instead of SINGLE when task's activation is surroundes with square brackets
Edouard Tisserant
parents:
1418
diff
changeset
|
403 |
else: |
71b1545d746f
Enable overloading of task triggerring source cell editor (SINGLE) in resource editor. PLCGenerator now generates MULTI keywork instead of SINGLE when task's activation is surroundes with square brackets
Edouard Tisserant
parents:
1418
diff
changeset
|
404 |
SNGLKW = "SINGLE" |
71b1545d746f
Enable overloading of task triggerring source cell editor (SINGLE) in resource editor. PLCGenerator now generates MULTI keywork instead of SINGLE when task's activation is surroundes with square brackets
Edouard Tisserant
parents:
1418
diff
changeset
|
405 |
resrce += [(SNGLKW + " := ", ()), |
814 | 406 |
(single, (tagname, "task", task_number, "single")), |
407 |
(",", ())] |
|
408 |
# Interval argument if exists |
|
409 |
interval = task.getinterval() |
|
1315
ff14a66bbd12
Fixed Beremiz for working with new xmlclass support using lxml
Laurent Bessard
parents:
1310
diff
changeset
|
410 |
if interval is not None: |
814 | 411 |
resrce += [("INTERVAL := ", ()), |
412 |
(interval, (tagname, "task", task_number, "interval")), |
|
413 |
(",", ())] |
|
414 |
## resrce += [("INTERVAL := t#", ())] |
|
415 |
## if interval.hour != 0: |
|
416 |
## resrce += [("%dh"%interval.hour, (tagname, "task", task_number, "interval", "hour"))] |
|
417 |
## if interval.minute != 0: |
|
418 |
## resrce += [("%dm"%interval.minute, (tagname, "task", task_number, "interval", "minute"))] |
|
419 |
## if interval.second != 0: |
|
420 |
## resrce += [("%ds"%interval.second, (tagname, "task", task_number, "interval", "second"))] |
|
421 |
## if interval.microsecond != 0: |
|
422 |
## resrce += [("%dms"%(interval.microsecond / 1000), (tagname, "task", task_number, "interval", "millisecond"))] |
|
423 |
## resrce += [(",", ())] |
|
424 |
# Priority argument |
|
1418
c97dc5281419
Fixed declaration and ST code gen for IEC function that return derivated types
Edouard Tisserant
parents:
1358
diff
changeset
|
425 |
resrce += [("PRIORITY := ", ()), |
814 | 426 |
("%d"%task.getpriority(), (tagname, "task", task_number, "priority")), |
427 |
(");\n", ())] |
|
428 |
task_number += 1 |
|
429 |
instance_number = 0 |
|
430 |
# Generate any program assign to each task |
|
431 |
for task in tasks: |
|
432 |
for instance in task.getpouInstance(): |
|
433 |
resrce += [(" PROGRAM ", ()), |
|
434 |
(instance.getname(), (tagname, "instance", instance_number, "name")), |
|
435 |
(" WITH ", ()), |
|
436 |
(task.getname(), (tagname, "instance", instance_number, "task")), |
|
437 |
(" : ", ()), |
|
438 |
(instance.gettypeName(), (tagname, "instance", instance_number, "type")), |
|
439 |
(";\n", ())] |
|
440 |
instance_number += 1 |
|
441 |
# Generate any program assign to no task |
|
442 |
for instance in resource.getpouInstance(): |
|
443 |
resrce += [(" PROGRAM ", ()), |
|
444 |
(instance.getname(), (tagname, "instance", instance_number, "name")), |
|
445 |
(" : ", ()), |
|
446 |
(instance.gettypeName(), (tagname, "instance", instance_number, "type")), |
|
447 |
(";\n", ())] |
|
448 |
instance_number += 1 |
|
449 |
resrce += [(" END_RESOURCE\n", ())] |
|
450 |
return resrce |
|
1418
c97dc5281419
Fixed declaration and ST code gen for IEC function that return derivated types
Edouard Tisserant
parents:
1358
diff
changeset
|
451 |
|
814 | 452 |
# Generate the entire program for current project |
1418
c97dc5281419
Fixed declaration and ST code gen for IEC function that return derivated types
Edouard Tisserant
parents:
1358
diff
changeset
|
453 |
def GenerateProgram(self): |
814 | 454 |
# Find all data types defined |
455 |
for datatype in self.Project.getdataTypes(): |
|
456 |
self.DatatypeComputed[datatype.getname()] = False |
|
457 |
# Find all data types defined |
|
458 |
for pou in self.Project.getpous(): |
|
459 |
self.PouComputed[pou.getname()] = False |
|
1418
c97dc5281419
Fixed declaration and ST code gen for IEC function that return derivated types
Edouard Tisserant
parents:
1358
diff
changeset
|
460 |
# Generate data type declaration structure if there is at least one data |
814 | 461 |
# type defined |
462 |
if len(self.DatatypeComputed) > 0: |
|
463 |
self.Program += [("TYPE\n", ())] |
|
464 |
# Generate every data types defined |
|
465 |
for datatype_name in self.DatatypeComputed.keys(): |
|
466 |
self.GenerateDataType(datatype_name) |
|
467 |
self.Program += [("END_TYPE\n\n", ())] |
|
468 |
# Generate every POUs defined |
|
469 |
for pou_name in self.PouComputed.keys(): |
|
470 |
self.GeneratePouProgram(pou_name) |
|
471 |
# Generate every configurations defined |
|
472 |
for config in self.Project.getconfigurations(): |
|
473 |
self.Program += self.GenerateConfiguration(config) |
|
1418
c97dc5281419
Fixed declaration and ST code gen for IEC function that return derivated types
Edouard Tisserant
parents:
1358
diff
changeset
|
474 |
|
814 | 475 |
# Return generated program |
476 |
def GetGeneratedProgram(self): |
|
477 |
return self.Program |
|
478 |
||
479 |
||
480 |
#------------------------------------------------------------------------------- |
|
481 |
# Generator of POU programs |
|
482 |
#------------------------------------------------------------------------------- |
|
483 |
||
1297 | 484 |
[ConnectorClass, ContinuationClass, ActionBlockClass] = [ |
485 |
PLCOpenParser.GetElementClass(instance_name, "commonObjects") |
|
486 |
for instance_name in ["connector", "continuation", "actionBlock"]] |
|
487 |
[InVariableClass, InOutVariableClass, OutVariableClass, BlockClass] = [ |
|
488 |
PLCOpenParser.GetElementClass(instance_name, "fbdObjects") |
|
489 |
for instance_name in ["inVariable", "inOutVariable", "outVariable", "block"]] |
|
490 |
[ContactClass, CoilClass, LeftPowerRailClass, RightPowerRailClass] = [ |
|
491 |
PLCOpenParser.GetElementClass(instance_name, "ldObjects") |
|
492 |
for instance_name in ["contact", "coil", "leftPowerRail", "rightPowerRail"]] |
|
1418
c97dc5281419
Fixed declaration and ST code gen for IEC function that return derivated types
Edouard Tisserant
parents:
1358
diff
changeset
|
493 |
[StepClass, TransitionClass, JumpStepClass, |
1297 | 494 |
SelectionConvergenceClass, SelectionDivergenceClass, |
495 |
SimultaneousConvergenceClass, SimultaneousDivergenceClass] = [ |
|
496 |
PLCOpenParser.GetElementClass(instance_name, "sfcObjects") |
|
1418
c97dc5281419
Fixed declaration and ST code gen for IEC function that return derivated types
Edouard Tisserant
parents:
1358
diff
changeset
|
497 |
for instance_name in ["step", "transition", "jumpStep", |
1297 | 498 |
"selectionConvergence", "selectionDivergence", |
499 |
"simultaneousConvergence", "simultaneousDivergence"]] |
|
500 |
TransitionObjClass = PLCOpenParser.GetElementClass("transition", "transitions") |
|
501 |
ActionObjClass = PLCOpenParser.GetElementClass("action", "actions") |
|
814 | 502 |
|
503 |
class PouProgramGenerator: |
|
1418
c97dc5281419
Fixed declaration and ST code gen for IEC function that return derivated types
Edouard Tisserant
parents:
1358
diff
changeset
|
504 |
|
814 | 505 |
# Create a new POU program generator |
506 |
def __init__(self, parent, name, type, errors, warnings): |
|
507 |
# Keep Reference to the parent generator |
|
508 |
self.ParentGenerator = parent |
|
509 |
self.Name = name |
|
510 |
self.Type = type |
|
511 |
self.TagName = self.ParentGenerator.Controler.ComputePouName(name) |
|
512 |
self.CurrentIndent = " " |
|
513 |
self.ReturnType = None |
|
514 |
self.Interface = [] |
|
515 |
self.InitialSteps = [] |
|
516 |
self.ComputedBlocks = {} |
|
517 |
self.ComputedConnectors = {} |
|
518 |
self.ConnectionTypes = {} |
|
519 |
self.RelatedConnections = [] |
|
520 |
self.SFCNetworks = {"Steps":{}, "Transitions":{}, "Actions":{}} |
|
521 |
self.SFCComputedBlocks = [] |
|
522 |
self.ActionNumber = 0 |
|
523 |
self.Program = [] |
|
524 |
self.Errors = errors |
|
525 |
self.Warnings = warnings |
|
1418
c97dc5281419
Fixed declaration and ST code gen for IEC function that return derivated types
Edouard Tisserant
parents:
1358
diff
changeset
|
526 |
|
814 | 527 |
def GetBlockType(self, type, inputs=None): |
528 |
return self.ParentGenerator.Controler.GetBlockType(type, inputs) |
|
1418
c97dc5281419
Fixed declaration and ST code gen for IEC function that return derivated types
Edouard Tisserant
parents:
1358
diff
changeset
|
529 |
|
814 | 530 |
def IndentLeft(self): |
531 |
if len(self.CurrentIndent) >= 2: |
|
532 |
self.CurrentIndent = self.CurrentIndent[:-2] |
|
1418
c97dc5281419
Fixed declaration and ST code gen for IEC function that return derivated types
Edouard Tisserant
parents:
1358
diff
changeset
|
533 |
|
814 | 534 |
def IndentRight(self): |
535 |
self.CurrentIndent += " " |
|
1418
c97dc5281419
Fixed declaration and ST code gen for IEC function that return derivated types
Edouard Tisserant
parents:
1358
diff
changeset
|
536 |
|
814 | 537 |
# Generator of unique ID for inline actions |
538 |
def GetActionNumber(self): |
|
539 |
self.ActionNumber += 1 |
|
540 |
return self.ActionNumber |
|
1418
c97dc5281419
Fixed declaration and ST code gen for IEC function that return derivated types
Edouard Tisserant
parents:
1358
diff
changeset
|
541 |
|
814 | 542 |
# Test if a variable has already been defined |
543 |
def IsAlreadyDefined(self, name): |
|
544 |
for list_type, option, located, vars in self.Interface: |
|
545 |
for var_type, var_name, var_address, var_initial in vars: |
|
546 |
if name == var_name: |
|
547 |
return True |
|
548 |
return False |
|
1418
c97dc5281419
Fixed declaration and ST code gen for IEC function that return derivated types
Edouard Tisserant
parents:
1358
diff
changeset
|
549 |
|
814 | 550 |
# Return the type of a variable defined in interface |
551 |
def GetVariableType(self, name): |
|
552 |
parts = name.split('.') |
|
553 |
current_type = None |
|
554 |
if len(parts) > 0: |
|
555 |
name = parts.pop(0) |
|
556 |
for list_type, option, located, vars in self.Interface: |
|
557 |
for var_type, var_name, var_address, var_initial in vars: |
|
558 |
if name == var_name: |
|
559 |
current_type = var_type |
|
560 |
break |
|
561 |
while current_type is not None and len(parts) > 0: |
|
883
235a9ec83b95
Adding support for defining specific global variables for ConfTreeNodes
Laurent Bessard
parents:
864
diff
changeset
|
562 |
blocktype = self.ParentGenerator.Controler.GetBlockType(current_type) |
235a9ec83b95
Adding support for defining specific global variables for ConfTreeNodes
Laurent Bessard
parents:
864
diff
changeset
|
563 |
if blocktype is not None: |
235a9ec83b95
Adding support for defining specific global variables for ConfTreeNodes
Laurent Bessard
parents:
864
diff
changeset
|
564 |
name = parts.pop(0) |
235a9ec83b95
Adding support for defining specific global variables for ConfTreeNodes
Laurent Bessard
parents:
864
diff
changeset
|
565 |
current_type = None |
235a9ec83b95
Adding support for defining specific global variables for ConfTreeNodes
Laurent Bessard
parents:
864
diff
changeset
|
566 |
for var_name, var_type, var_modifier in blocktype["inputs"] + blocktype["outputs"]: |
235a9ec83b95
Adding support for defining specific global variables for ConfTreeNodes
Laurent Bessard
parents:
864
diff
changeset
|
567 |
if var_name == name: |
235a9ec83b95
Adding support for defining specific global variables for ConfTreeNodes
Laurent Bessard
parents:
864
diff
changeset
|
568 |
current_type = var_type |
814 | 569 |
break |
883
235a9ec83b95
Adding support for defining specific global variables for ConfTreeNodes
Laurent Bessard
parents:
864
diff
changeset
|
570 |
else: |
235a9ec83b95
Adding support for defining specific global variables for ConfTreeNodes
Laurent Bessard
parents:
864
diff
changeset
|
571 |
tagname = self.ParentGenerator.Controler.ComputeDataTypeName(current_type) |
235a9ec83b95
Adding support for defining specific global variables for ConfTreeNodes
Laurent Bessard
parents:
864
diff
changeset
|
572 |
infos = self.ParentGenerator.Controler.GetDataTypeInfos(tagname) |
235a9ec83b95
Adding support for defining specific global variables for ConfTreeNodes
Laurent Bessard
parents:
864
diff
changeset
|
573 |
if infos is not None and infos["type"] == "Structure": |
235a9ec83b95
Adding support for defining specific global variables for ConfTreeNodes
Laurent Bessard
parents:
864
diff
changeset
|
574 |
name = parts.pop(0) |
235a9ec83b95
Adding support for defining specific global variables for ConfTreeNodes
Laurent Bessard
parents:
864
diff
changeset
|
575 |
current_type = None |
235a9ec83b95
Adding support for defining specific global variables for ConfTreeNodes
Laurent Bessard
parents:
864
diff
changeset
|
576 |
for element in infos["elements"]: |
235a9ec83b95
Adding support for defining specific global variables for ConfTreeNodes
Laurent Bessard
parents:
864
diff
changeset
|
577 |
if element["Name"] == name: |
235a9ec83b95
Adding support for defining specific global variables for ConfTreeNodes
Laurent Bessard
parents:
864
diff
changeset
|
578 |
current_type = element["Type"] |
235a9ec83b95
Adding support for defining specific global variables for ConfTreeNodes
Laurent Bessard
parents:
864
diff
changeset
|
579 |
break |
814 | 580 |
return current_type |
1418
c97dc5281419
Fixed declaration and ST code gen for IEC function that return derivated types
Edouard Tisserant
parents:
1358
diff
changeset
|
581 |
|
814 | 582 |
# Return connectors linked by a connection to the given connector |
583 |
def GetConnectedConnector(self, connector, body): |
|
584 |
links = connector.getconnections() |
|
1298
f034fb2b1aab
Fixed SFC block edition and SFC to SFC_textual code generating
Laurent Bessard
parents:
1297
diff
changeset
|
585 |
if links is not None and len(links) == 1: |
814 | 586 |
return self.GetLinkedConnector(links[0], body) |
1418
c97dc5281419
Fixed declaration and ST code gen for IEC function that return derivated types
Edouard Tisserant
parents:
1358
diff
changeset
|
587 |
return None |
814 | 588 |
|
589 |
def GetLinkedConnector(self, link, body): |
|
590 |
parameter = link.getformalParameter() |
|
591 |
instance = body.getcontentInstance(link.getrefLocalId()) |
|
1418
c97dc5281419
Fixed declaration and ST code gen for IEC function that return derivated types
Edouard Tisserant
parents:
1358
diff
changeset
|
592 |
if isinstance(instance, (InVariableClass, InOutVariableClass, |
1297 | 593 |
ContinuationClass, ContactClass, CoilClass)): |
814 | 594 |
return instance.connectionPointOut |
1297 | 595 |
elif isinstance(instance, BlockClass): |
814 | 596 |
outputvariables = instance.outputVariables.getvariable() |
597 |
if len(outputvariables) == 1: |
|
598 |
return outputvariables[0].connectionPointOut |
|
599 |
elif parameter: |
|
600 |
for variable in outputvariables: |
|
601 |
if variable.getformalParameter() == parameter: |
|
602 |
return variable.connectionPointOut |
|
603 |
else: |
|
604 |
point = link.getposition()[-1] |
|
605 |
for variable in outputvariables: |
|
606 |
relposition = variable.connectionPointOut.getrelPositionXY() |
|
607 |
blockposition = instance.getposition() |
|
608 |
if point.x == blockposition.x + relposition[0] and point.y == blockposition.y + relposition[1]: |
|
609 |
return variable.connectionPointOut |
|
1297 | 610 |
elif isinstance(instance, LeftPowerRailClass): |
814 | 611 |
outputconnections = instance.getconnectionPointOut() |
612 |
if len(outputconnections) == 1: |
|
613 |
return outputconnections[0] |
|
614 |
else: |
|
615 |
point = link.getposition()[-1] |
|
616 |
for outputconnection in outputconnections: |
|
617 |
relposition = outputconnection.getrelPositionXY() |
|
618 |
powerrailposition = instance.getposition() |
|
619 |
if point.x == powerrailposition.x + relposition[0] and point.y == powerrailposition.y + relposition[1]: |
|
620 |
return outputconnection |
|
621 |
return None |
|
1418
c97dc5281419
Fixed declaration and ST code gen for IEC function that return derivated types
Edouard Tisserant
parents:
1358
diff
changeset
|
622 |
|
814 | 623 |
def ExtractRelatedConnections(self, connection): |
624 |
for i, related in enumerate(self.RelatedConnections): |
|
625 |
if connection in related: |
|
626 |
return self.RelatedConnections.pop(i) |
|
627 |
return [connection] |
|
1418
c97dc5281419
Fixed declaration and ST code gen for IEC function that return derivated types
Edouard Tisserant
parents:
1358
diff
changeset
|
628 |
|
814 | 629 |
def ComputeInterface(self, pou): |
630 |
interface = pou.getinterface() |
|
631 |
if interface is not None: |
|
632 |
body = pou.getbody() |
|
633 |
if isinstance(body, ListType): |
|
634 |
body = body[0] |
|
635 |
body_content = body.getcontent() |
|
1297 | 636 |
body_type = body_content.getLocalTag() |
814 | 637 |
if self.Type == "FUNCTION": |
1418
c97dc5281419
Fixed declaration and ST code gen for IEC function that return derivated types
Edouard Tisserant
parents:
1358
diff
changeset
|
638 |
returntype_content = interface.getreturnType()[0] |
1297 | 639 |
returntype_content_type = returntype_content.getLocalTag() |
640 |
if returntype_content_type == "derived": |
|
641 |
self.ReturnType = returntype_content.getname() |
|
642 |
else: |
|
643 |
self.ReturnType = returntype_content_type.upper() |
|
814 | 644 |
for varlist in interface.getcontent(): |
645 |
variables = [] |
|
646 |
located = [] |
|
1297 | 647 |
varlist_type = varlist.getLocalTag() |
648 |
for var in varlist.getvariable(): |
|
814 | 649 |
vartype_content = var.gettype().getcontent() |
1297 | 650 |
if vartype_content.getLocalTag() == "derived": |
651 |
var_type = vartype_content.getname() |
|
814 | 652 |
blocktype = self.GetBlockType(var_type) |
653 |
if blocktype is not None: |
|
654 |
self.ParentGenerator.GeneratePouProgram(var_type) |
|
1310
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
655 |
variables.append((var_type, var.getname(), None, None)) |
814 | 656 |
else: |
657 |
self.ParentGenerator.GenerateDataType(var_type) |
|
658 |
initial = var.getinitialValue() |
|
1310
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
659 |
if initial is not None: |
814 | 660 |
initial_value = initial.getvalue() |
661 |
else: |
|
662 |
initial_value = None |
|
663 |
address = var.getaddress() |
|
664 |
if address is not None: |
|
1297 | 665 |
located.append((vartype_content.getname(), var.getname(), address, initial_value)) |
814 | 666 |
else: |
1297 | 667 |
variables.append((vartype_content.getname(), var.getname(), None, initial_value)) |
814 | 668 |
else: |
669 |
var_type = var.gettypeAsText() |
|
670 |
initial = var.getinitialValue() |
|
1310
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
671 |
if initial is not None: |
814 | 672 |
initial_value = initial.getvalue() |
673 |
else: |
|
674 |
initial_value = None |
|
675 |
address = var.getaddress() |
|
676 |
if address is not None: |
|
677 |
located.append((var_type, var.getname(), address, initial_value)) |
|
678 |
else: |
|
679 |
variables.append((var_type, var.getname(), None, initial_value)) |
|
1297 | 680 |
if varlist.getconstant(): |
814 | 681 |
option = "CONSTANT" |
1297 | 682 |
elif varlist.getretain(): |
814 | 683 |
option = "RETAIN" |
1297 | 684 |
elif varlist.getnonretain(): |
814 | 685 |
option = "NON_RETAIN" |
686 |
else: |
|
687 |
option = None |
|
688 |
if len(variables) > 0: |
|
1297 | 689 |
self.Interface.append((varTypeNames[varlist_type], option, False, variables)) |
814 | 690 |
if len(located) > 0: |
1297 | 691 |
self.Interface.append((varTypeNames[varlist_type], option, True, located)) |
1418
c97dc5281419
Fixed declaration and ST code gen for IEC function that return derivated types
Edouard Tisserant
parents:
1358
diff
changeset
|
692 |
|
1181
21e6db77eb29
Fixed bug in PLC code generated with binary, octal and hexadecimal literals
Laurent Bessard
parents:
1134
diff
changeset
|
693 |
LITERAL_TYPES = { |
21e6db77eb29
Fixed bug in PLC code generated with binary, octal and hexadecimal literals
Laurent Bessard
parents:
1134
diff
changeset
|
694 |
"T": "TIME", |
21e6db77eb29
Fixed bug in PLC code generated with binary, octal and hexadecimal literals
Laurent Bessard
parents:
1134
diff
changeset
|
695 |
"D": "DATE", |
21e6db77eb29
Fixed bug in PLC code generated with binary, octal and hexadecimal literals
Laurent Bessard
parents:
1134
diff
changeset
|
696 |
"TOD": "TIME_OF_DAY", |
21e6db77eb29
Fixed bug in PLC code generated with binary, octal and hexadecimal literals
Laurent Bessard
parents:
1134
diff
changeset
|
697 |
"DT": "DATE_AND_TIME", |
1183
a01618805821
Fixed bug in PLC code generated with binary, octal and hexadecimal literals
Laurent Bessard
parents:
1181
diff
changeset
|
698 |
"2": None, |
a01618805821
Fixed bug in PLC code generated with binary, octal and hexadecimal literals
Laurent Bessard
parents:
1181
diff
changeset
|
699 |
"8": None, |
a01618805821
Fixed bug in PLC code generated with binary, octal and hexadecimal literals
Laurent Bessard
parents:
1181
diff
changeset
|
700 |
"16": None, |
1181
21e6db77eb29
Fixed bug in PLC code generated with binary, octal and hexadecimal literals
Laurent Bessard
parents:
1134
diff
changeset
|
701 |
} |
814 | 702 |
def ComputeConnectionTypes(self, pou): |
703 |
body = pou.getbody() |
|
704 |
if isinstance(body, ListType): |
|
705 |
body = body[0] |
|
706 |
body_content = body.getcontent() |
|
1297 | 707 |
body_type = body_content.getLocalTag() |
814 | 708 |
if body_type in ["FBD", "LD", "SFC"]: |
709 |
undefined_blocks = [] |
|
710 |
for instance in body.getcontentInstances(): |
|
1418
c97dc5281419
Fixed declaration and ST code gen for IEC function that return derivated types
Edouard Tisserant
parents:
1358
diff
changeset
|
711 |
if isinstance(instance, (InVariableClass, OutVariableClass, |
1297 | 712 |
InOutVariableClass)): |
1322
0a9227f743b3
Fixed xmlclass for working with included files, adding support for SimpleType elements and solving ambiguity in extension class when different elements share the same name and parent name
Laurent Bessard
parents:
1315
diff
changeset
|
713 |
expression = instance.getexpression() |
814 | 714 |
var_type = self.GetVariableType(expression) |
1418
c97dc5281419
Fixed declaration and ST code gen for IEC function that return derivated types
Edouard Tisserant
parents:
1358
diff
changeset
|
715 |
if (isinstance(pou, TransitionObjClass) |
1297 | 716 |
and expression == pou.getname()): |
822
050045c32d98
Fix bug in PLCGenerator connection types not computed for SFC actions and transitions body
laurent
parents:
814
diff
changeset
|
717 |
var_type = "BOOL" |
1297 | 718 |
elif (not isinstance(pou, (TransitionObjClass, ActionObjClass)) and |
822
050045c32d98
Fix bug in PLCGenerator connection types not computed for SFC actions and transitions body
laurent
parents:
814
diff
changeset
|
719 |
pou.getpouType() == "function" and expression == pou.getname()): |
814 | 720 |
returntype_content = pou.interface.getreturnType().getcontent() |
1297 | 721 |
returntype_content_type = returntype_content.getLocalTag() |
722 |
if returntype_content_type == "derived": |
|
723 |
var_type = returntype_content.getname() |
|
814 | 724 |
else: |
1297 | 725 |
var_type = returntype_content_type.upper() |
814 | 726 |
elif var_type is None: |
727 |
parts = expression.split("#") |
|
728 |
if len(parts) > 1: |
|
1181
21e6db77eb29
Fixed bug in PLC code generated with binary, octal and hexadecimal literals
Laurent Bessard
parents:
1134
diff
changeset
|
729 |
literal_prefix = parts[0].upper() |
1418
c97dc5281419
Fixed declaration and ST code gen for IEC function that return derivated types
Edouard Tisserant
parents:
1358
diff
changeset
|
730 |
var_type = self.LITERAL_TYPES.get(literal_prefix, |
1181
21e6db77eb29
Fixed bug in PLC code generated with binary, octal and hexadecimal literals
Laurent Bessard
parents:
1134
diff
changeset
|
731 |
literal_prefix) |
814 | 732 |
elif expression.startswith("'"): |
733 |
var_type = "STRING" |
|
734 |
elif expression.startswith('"'): |
|
735 |
var_type = "WSTRING" |
|
736 |
if var_type is not None: |
|
1297 | 737 |
if isinstance(instance, (InVariableClass, InOutVariableClass)): |
814 | 738 |
for connection in self.ExtractRelatedConnections(instance.connectionPointOut): |
739 |
self.ConnectionTypes[connection] = var_type |
|
1297 | 740 |
if isinstance(instance, (OutVariableClass, InOutVariableClass)): |
814 | 741 |
self.ConnectionTypes[instance.connectionPointIn] = var_type |
742 |
connected = self.GetConnectedConnector(instance.connectionPointIn, body) |
|
1298
f034fb2b1aab
Fixed SFC block edition and SFC to SFC_textual code generating
Laurent Bessard
parents:
1297
diff
changeset
|
743 |
if connected is not None and not self.ConnectionTypes.has_key(connected): |
f034fb2b1aab
Fixed SFC block edition and SFC to SFC_textual code generating
Laurent Bessard
parents:
1297
diff
changeset
|
744 |
for related in self.ExtractRelatedConnections(connected): |
f034fb2b1aab
Fixed SFC block edition and SFC to SFC_textual code generating
Laurent Bessard
parents:
1297
diff
changeset
|
745 |
self.ConnectionTypes[related] = var_type |
1297 | 746 |
elif isinstance(instance, (ContactClass, CoilClass)): |
814 | 747 |
for connection in self.ExtractRelatedConnections(instance.connectionPointOut): |
748 |
self.ConnectionTypes[connection] = "BOOL" |
|
749 |
self.ConnectionTypes[instance.connectionPointIn] = "BOOL" |
|
1298
f034fb2b1aab
Fixed SFC block edition and SFC to SFC_textual code generating
Laurent Bessard
parents:
1297
diff
changeset
|
750 |
for link in instance.connectionPointIn.getconnections(): |
f034fb2b1aab
Fixed SFC block edition and SFC to SFC_textual code generating
Laurent Bessard
parents:
1297
diff
changeset
|
751 |
connected = self.GetLinkedConnector(link, body) |
f034fb2b1aab
Fixed SFC block edition and SFC to SFC_textual code generating
Laurent Bessard
parents:
1297
diff
changeset
|
752 |
if connected is not None and not self.ConnectionTypes.has_key(connected): |
f034fb2b1aab
Fixed SFC block edition and SFC to SFC_textual code generating
Laurent Bessard
parents:
1297
diff
changeset
|
753 |
for related in self.ExtractRelatedConnections(connected): |
f034fb2b1aab
Fixed SFC block edition and SFC to SFC_textual code generating
Laurent Bessard
parents:
1297
diff
changeset
|
754 |
self.ConnectionTypes[related] = "BOOL" |
1297 | 755 |
elif isinstance(instance, LeftPowerRailClass): |
814 | 756 |
for connection in instance.getconnectionPointOut(): |
757 |
for related in self.ExtractRelatedConnections(connection): |
|
758 |
self.ConnectionTypes[related] = "BOOL" |
|
1297 | 759 |
elif isinstance(instance, RightPowerRailClass): |
814 | 760 |
for connection in instance.getconnectionPointIn(): |
761 |
self.ConnectionTypes[connection] = "BOOL" |
|
1298
f034fb2b1aab
Fixed SFC block edition and SFC to SFC_textual code generating
Laurent Bessard
parents:
1297
diff
changeset
|
762 |
for link in connection.getconnections(): |
f034fb2b1aab
Fixed SFC block edition and SFC to SFC_textual code generating
Laurent Bessard
parents:
1297
diff
changeset
|
763 |
connected = self.GetLinkedConnector(link, body) |
f034fb2b1aab
Fixed SFC block edition and SFC to SFC_textual code generating
Laurent Bessard
parents:
1297
diff
changeset
|
764 |
if connected is not None and not self.ConnectionTypes.has_key(connected): |
f034fb2b1aab
Fixed SFC block edition and SFC to SFC_textual code generating
Laurent Bessard
parents:
1297
diff
changeset
|
765 |
for related in self.ExtractRelatedConnections(connected): |
f034fb2b1aab
Fixed SFC block edition and SFC to SFC_textual code generating
Laurent Bessard
parents:
1297
diff
changeset
|
766 |
self.ConnectionTypes[related] = "BOOL" |
1297 | 767 |
elif isinstance(instance, TransitionClass): |
768 |
content = instance.getconditionContent() |
|
769 |
if content["type"] == "connection": |
|
1298
f034fb2b1aab
Fixed SFC block edition and SFC to SFC_textual code generating
Laurent Bessard
parents:
1297
diff
changeset
|
770 |
self.ConnectionTypes[content["value"]] = "BOOL" |
1603
18279f12a6be
fix issue with compiling SFC POU with non-connected transition (type "connection")
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1581
diff
changeset
|
771 |
connections = content["value"].getconnections() |
18279f12a6be
fix issue with compiling SFC POU with non-connected transition (type "connection")
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1581
diff
changeset
|
772 |
if not connections: |
18279f12a6be
fix issue with compiling SFC POU with non-connected transition (type "connection")
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1581
diff
changeset
|
773 |
raise PLCGenException, _("SFC transition in POU \"%s\" must be connected.") % self.Name |
18279f12a6be
fix issue with compiling SFC POU with non-connected transition (type "connection")
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1581
diff
changeset
|
774 |
for link in connections: |
1298
f034fb2b1aab
Fixed SFC block edition and SFC to SFC_textual code generating
Laurent Bessard
parents:
1297
diff
changeset
|
775 |
connected = self.GetLinkedConnector(link, body) |
f034fb2b1aab
Fixed SFC block edition and SFC to SFC_textual code generating
Laurent Bessard
parents:
1297
diff
changeset
|
776 |
if connected is not None and not self.ConnectionTypes.has_key(connected): |
f034fb2b1aab
Fixed SFC block edition and SFC to SFC_textual code generating
Laurent Bessard
parents:
1297
diff
changeset
|
777 |
for related in self.ExtractRelatedConnections(connected): |
f034fb2b1aab
Fixed SFC block edition and SFC to SFC_textual code generating
Laurent Bessard
parents:
1297
diff
changeset
|
778 |
self.ConnectionTypes[related] = "BOOL" |
1297 | 779 |
elif isinstance(instance, ContinuationClass): |
814 | 780 |
name = instance.getname() |
781 |
connector = None |
|
782 |
var_type = "ANY" |
|
783 |
for element in body.getcontentInstances(): |
|
1297 | 784 |
if isinstance(element, ConnectorClass) and element.getname() == name: |
814 | 785 |
if connector is not None: |
1581
2295fdc5c271
fix translation strings with multiple parameters
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
786 |
msg = _("More than one connector found corresponding to \"{a1}\" continuation in \"{a2}\" POU").format(a1 = name, a2 = self.Name) |
2295fdc5c271
fix translation strings with multiple parameters
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
787 |
raise PLCGenException, msg |
814 | 788 |
connector = element |
789 |
if connector is not None: |
|
790 |
undefined = [instance.connectionPointOut, connector.connectionPointIn] |
|
791 |
connected = self.GetConnectedConnector(connector.connectionPointIn, body) |
|
1298
f034fb2b1aab
Fixed SFC block edition and SFC to SFC_textual code generating
Laurent Bessard
parents:
1297
diff
changeset
|
792 |
if connected is not None: |
814 | 793 |
undefined.append(connected) |
794 |
related = [] |
|
795 |
for connection in undefined: |
|
796 |
if self.ConnectionTypes.has_key(connection): |
|
797 |
var_type = self.ConnectionTypes[connection] |
|
798 |
else: |
|
799 |
related.extend(self.ExtractRelatedConnections(connection)) |
|
800 |
if var_type.startswith("ANY") and len(related) > 0: |
|
801 |
self.RelatedConnections.append(related) |
|
802 |
else: |
|
803 |
for connection in related: |
|
804 |
self.ConnectionTypes[connection] = var_type |
|
805 |
else: |
|
1581
2295fdc5c271
fix translation strings with multiple parameters
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
806 |
msg = _("No connector found corresponding to \"{a1}\" continuation in \"{a2}\" POU").format(a1 = name, a2 = self.Name) |
2295fdc5c271
fix translation strings with multiple parameters
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
807 |
raise PLCGenException, msg |
1297 | 808 |
elif isinstance(instance, BlockClass): |
814 | 809 |
block_infos = self.GetBlockType(instance.gettypeName(), "undefined") |
810 |
if block_infos is not None: |
|
811 |
self.ComputeBlockInputTypes(instance, block_infos, body) |
|
812 |
else: |
|
813 |
for variable in instance.inputVariables.getvariable(): |
|
814 |
connected = self.GetConnectedConnector(variable.connectionPointIn, body) |
|
815 |
if connected is not None: |
|
816 |
var_type = self.ConnectionTypes.get(connected, None) |
|
817 |
if var_type is not None: |
|
818 |
self.ConnectionTypes[variable.connectionPointIn] = var_type |
|
819 |
else: |
|
820 |
related = self.ExtractRelatedConnections(connected) |
|
821 |
related.append(variable.connectionPointIn) |
|
822 |
self.RelatedConnections.append(related) |
|
823 |
undefined_blocks.append(instance) |
|
824 |
for instance in undefined_blocks: |
|
825 |
block_infos = self.GetBlockType(instance.gettypeName(), tuple([self.ConnectionTypes.get(variable.connectionPointIn, "ANY") for variable in instance.inputVariables.getvariable() if variable.getformalParameter() != "EN"])) |
|
826 |
if block_infos is not None: |
|
827 |
self.ComputeBlockInputTypes(instance, block_infos, body) |
|
828 |
else: |
|
829 |
raise PLCGenException, _("No informations found for \"%s\" block")%(instance.gettypeName()) |
|
822
050045c32d98
Fix bug in PLCGenerator connection types not computed for SFC actions and transitions body
laurent
parents:
814
diff
changeset
|
830 |
if body_type == "SFC": |
050045c32d98
Fix bug in PLCGenerator connection types not computed for SFC actions and transitions body
laurent
parents:
814
diff
changeset
|
831 |
previous_tagname = self.TagName |
050045c32d98
Fix bug in PLCGenerator connection types not computed for SFC actions and transitions body
laurent
parents:
814
diff
changeset
|
832 |
for action in pou.getactionList(): |
050045c32d98
Fix bug in PLCGenerator connection types not computed for SFC actions and transitions body
laurent
parents:
814
diff
changeset
|
833 |
self.TagName = self.ParentGenerator.Controler.ComputePouActionName(self.Name, action.getname()) |
050045c32d98
Fix bug in PLCGenerator connection types not computed for SFC actions and transitions body
laurent
parents:
814
diff
changeset
|
834 |
self.ComputeConnectionTypes(action) |
050045c32d98
Fix bug in PLCGenerator connection types not computed for SFC actions and transitions body
laurent
parents:
814
diff
changeset
|
835 |
for transition in pou.gettransitionList(): |
050045c32d98
Fix bug in PLCGenerator connection types not computed for SFC actions and transitions body
laurent
parents:
814
diff
changeset
|
836 |
self.TagName = self.ParentGenerator.Controler.ComputePouTransitionName(self.Name, transition.getname()) |
050045c32d98
Fix bug in PLCGenerator connection types not computed for SFC actions and transitions body
laurent
parents:
814
diff
changeset
|
837 |
self.ComputeConnectionTypes(transition) |
050045c32d98
Fix bug in PLCGenerator connection types not computed for SFC actions and transitions body
laurent
parents:
814
diff
changeset
|
838 |
self.TagName = previous_tagname |
1418
c97dc5281419
Fixed declaration and ST code gen for IEC function that return derivated types
Edouard Tisserant
parents:
1358
diff
changeset
|
839 |
|
814 | 840 |
def ComputeBlockInputTypes(self, instance, block_infos, body): |
841 |
undefined = {} |
|
842 |
for variable in instance.outputVariables.getvariable(): |
|
843 |
output_name = variable.getformalParameter() |
|
844 |
if output_name == "ENO": |
|
845 |
for connection in self.ExtractRelatedConnections(variable.connectionPointOut): |
|
846 |
self.ConnectionTypes[connection] = "BOOL" |
|
847 |
else: |
|
848 |
for oname, otype, oqualifier in block_infos["outputs"]: |
|
849 |
if output_name == oname: |
|
850 |
if otype.startswith("ANY"): |
|
851 |
if not undefined.has_key(otype): |
|
852 |
undefined[otype] = [] |
|
853 |
undefined[otype].append(variable.connectionPointOut) |
|
854 |
elif not self.ConnectionTypes.has_key(variable.connectionPointOut): |
|
855 |
for connection in self.ExtractRelatedConnections(variable.connectionPointOut): |
|
856 |
self.ConnectionTypes[connection] = otype |
|
857 |
for variable in instance.inputVariables.getvariable(): |
|
858 |
input_name = variable.getformalParameter() |
|
859 |
if input_name == "EN": |
|
860 |
for connection in self.ExtractRelatedConnections(variable.connectionPointIn): |
|
861 |
self.ConnectionTypes[connection] = "BOOL" |
|
862 |
else: |
|
863 |
for iname, itype, iqualifier in block_infos["inputs"]: |
|
864 |
if input_name == iname: |
|
865 |
connected = self.GetConnectedConnector(variable.connectionPointIn, body) |
|
866 |
if itype.startswith("ANY"): |
|
867 |
if not undefined.has_key(itype): |
|
868 |
undefined[itype] = [] |
|
869 |
undefined[itype].append(variable.connectionPointIn) |
|
1298
f034fb2b1aab
Fixed SFC block edition and SFC to SFC_textual code generating
Laurent Bessard
parents:
1297
diff
changeset
|
870 |
if connected is not None: |
814 | 871 |
undefined[itype].append(connected) |
872 |
else: |
|
873 |
self.ConnectionTypes[variable.connectionPointIn] = itype |
|
1298
f034fb2b1aab
Fixed SFC block edition and SFC to SFC_textual code generating
Laurent Bessard
parents:
1297
diff
changeset
|
874 |
if connected is not None and not self.ConnectionTypes.has_key(connected): |
814 | 875 |
for connection in self.ExtractRelatedConnections(connected): |
876 |
self.ConnectionTypes[connection] = itype |
|
877 |
for var_type, connections in undefined.items(): |
|
878 |
related = [] |
|
879 |
for connection in connections: |
|
854
c10f2092c43a
Fixing bug in PLCGenerator with user defined functions and standard overloaded function
Laurent Bessard
parents:
822
diff
changeset
|
880 |
connection_type = self.ConnectionTypes.get(connection) |
c10f2092c43a
Fixing bug in PLCGenerator with user defined functions and standard overloaded function
Laurent Bessard
parents:
822
diff
changeset
|
881 |
if connection_type and not connection_type.startswith("ANY"): |
c10f2092c43a
Fixing bug in PLCGenerator with user defined functions and standard overloaded function
Laurent Bessard
parents:
822
diff
changeset
|
882 |
var_type = connection_type |
814 | 883 |
else: |
884 |
related.extend(self.ExtractRelatedConnections(connection)) |
|
885 |
if var_type.startswith("ANY") and len(related) > 0: |
|
886 |
self.RelatedConnections.append(related) |
|
887 |
else: |
|
888 |
for connection in related: |
|
889 |
self.ConnectionTypes[connection] = var_type |
|
890 |
||
891 |
def ComputeProgram(self, pou): |
|
892 |
body = pou.getbody() |
|
893 |
if isinstance(body, ListType): |
|
894 |
body = body[0] |
|
895 |
body_content = body.getcontent() |
|
1297 | 896 |
body_type = body_content.getLocalTag() |
814 | 897 |
if body_type in ["IL","ST"]: |
1297 | 898 |
text = body_content.getanyText() |
814 | 899 |
self.ParentGenerator.GeneratePouProgramInText(text.upper()) |
1418
c97dc5281419
Fixed declaration and ST code gen for IEC function that return derivated types
Edouard Tisserant
parents:
1358
diff
changeset
|
900 |
self.Program = [(ReIndentText(text, len(self.CurrentIndent)), |
814 | 901 |
(self.TagName, "body", len(self.CurrentIndent)))] |
902 |
elif body_type == "SFC": |
|
903 |
self.IndentRight() |
|
904 |
for instance in body.getcontentInstances(): |
|
1297 | 905 |
if isinstance(instance, StepClass): |
814 | 906 |
self.GenerateSFCStep(instance, pou) |
1297 | 907 |
elif isinstance(instance, ActionBlockClass): |
814 | 908 |
self.GenerateSFCStepActions(instance, pou) |
1297 | 909 |
elif isinstance(instance, TransitionClass): |
814 | 910 |
self.GenerateSFCTransition(instance, pou) |
1298
f034fb2b1aab
Fixed SFC block edition and SFC to SFC_textual code generating
Laurent Bessard
parents:
1297
diff
changeset
|
911 |
elif isinstance(instance, JumpStepClass): |
814 | 912 |
self.GenerateSFCJump(instance, pou) |
913 |
if len(self.InitialSteps) > 0 and len(self.SFCComputedBlocks) > 0: |
|
914 |
action_name = "COMPUTE_FUNCTION_BLOCKS" |
|
915 |
action_infos = {"qualifier" : "S", "content" : action_name} |
|
916 |
self.SFCNetworks["Steps"][self.InitialSteps[0]]["actions"].append(action_infos) |
|
917 |
self.SFCNetworks["Actions"][action_name] = (self.SFCComputedBlocks, ()) |
|
918 |
self.Program = [] |
|
919 |
self.IndentLeft() |
|
920 |
for initialstep in self.InitialSteps: |
|
921 |
self.ComputeSFCStep(initialstep) |
|
922 |
else: |
|
923 |
otherInstances = {"outVariables&coils" : [], "blocks" : [], "connectors" : []} |
|
924 |
orderedInstances = [] |
|
925 |
for instance in body.getcontentInstances(): |
|
1297 | 926 |
if isinstance(instance, (OutVariableClass, InOutVariableClass, BlockClass)): |
814 | 927 |
executionOrderId = instance.getexecutionOrderId() |
928 |
if executionOrderId > 0: |
|
929 |
orderedInstances.append((executionOrderId, instance)) |
|
1297 | 930 |
elif isinstance(instance, (OutVariableClass, InOutVariableClass)): |
814 | 931 |
otherInstances["outVariables&coils"].append(instance) |
1297 | 932 |
elif isinstance(instance, BlockClass): |
814 | 933 |
otherInstances["blocks"].append(instance) |
1297 | 934 |
elif isinstance(instance, ConnectorClass): |
814 | 935 |
otherInstances["connectors"].append(instance) |
1297 | 936 |
elif isinstance(instance, CoilClass): |
814 | 937 |
otherInstances["outVariables&coils"].append(instance) |
938 |
orderedInstances.sort() |
|
939 |
otherInstances["outVariables&coils"].sort(SortInstances) |
|
940 |
otherInstances["blocks"].sort(SortInstances) |
|
941 |
instances = [instance for (executionOrderId, instance) in orderedInstances] |
|
1048
b450202605ab
Fixed bug in program elements computation order in PLCGenerator
Laurent Bessard
parents:
1032
diff
changeset
|
942 |
instances.extend(otherInstances["outVariables&coils"] + otherInstances["blocks"] + otherInstances["connectors"]) |
814 | 943 |
for instance in instances: |
1297 | 944 |
if isinstance(instance, (OutVariableClass, InOutVariableClass)): |
814 | 945 |
connections = instance.connectionPointIn.getconnections() |
946 |
if connections is not None: |
|
947 |
expression = self.ComputeExpression(body, connections) |
|
1239
d1f6ea56555d
Fixed bug when generating ST code and connection is broken in POU using graphical language
Laurent Bessard
parents:
1183
diff
changeset
|
948 |
if expression is not None: |
d1f6ea56555d
Fixed bug when generating ST code and connection is broken in POU using graphical language
Laurent Bessard
parents:
1183
diff
changeset
|
949 |
self.Program += [(self.CurrentIndent, ()), |
1322
0a9227f743b3
Fixed xmlclass for working with included files, adding support for SimpleType elements and solving ambiguity in extension class when different elements share the same name and parent name
Laurent Bessard
parents:
1315
diff
changeset
|
950 |
(instance.getexpression(), (self.TagName, "io_variable", instance.getlocalId(), "expression")), |
1239
d1f6ea56555d
Fixed bug when generating ST code and connection is broken in POU using graphical language
Laurent Bessard
parents:
1183
diff
changeset
|
951 |
(" := ", ())] |
d1f6ea56555d
Fixed bug when generating ST code and connection is broken in POU using graphical language
Laurent Bessard
parents:
1183
diff
changeset
|
952 |
self.Program += expression |
d1f6ea56555d
Fixed bug when generating ST code and connection is broken in POU using graphical language
Laurent Bessard
parents:
1183
diff
changeset
|
953 |
self.Program += [(";\n", ())] |
1297 | 954 |
elif isinstance(instance, BlockClass): |
814 | 955 |
block_type = instance.gettypeName() |
956 |
self.ParentGenerator.GeneratePouProgram(block_type) |
|
957 |
block_infos = self.GetBlockType(block_type, tuple([self.ConnectionTypes.get(variable.connectionPointIn, "ANY") for variable in instance.inputVariables.getvariable() if variable.getformalParameter() != "EN"])) |
|
958 |
if block_infos is None: |
|
959 |
block_infos = self.GetBlockType(block_type) |
|
960 |
if block_infos is None: |
|
1581
2295fdc5c271
fix translation strings with multiple parameters
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
961 |
raise PLCGenException, _("Undefined block type \"{a1}\" in \"{a2}\" POU").format(a1 = block_type, a2 = self.Name) |
1134
1c7a4ad86aa1
Fixed PLC code generator when interface of an already used POU has changed
Laurent Bessard
parents:
1048
diff
changeset
|
962 |
try: |
1310
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
963 |
self.GenerateBlock(instance, block_infos, body, None) |
1134
1c7a4ad86aa1
Fixed PLC code generator when interface of an already used POU has changed
Laurent Bessard
parents:
1048
diff
changeset
|
964 |
except ValueError, e: |
1c7a4ad86aa1
Fixed PLC code generator when interface of an already used POU has changed
Laurent Bessard
parents:
1048
diff
changeset
|
965 |
raise PLCGenException, e.message |
1297 | 966 |
elif isinstance(instance, ConnectorClass): |
814 | 967 |
connector = instance.getname() |
968 |
if self.ComputedConnectors.get(connector, None): |
|
1239
d1f6ea56555d
Fixed bug when generating ST code and connection is broken in POU using graphical language
Laurent Bessard
parents:
1183
diff
changeset
|
969 |
continue |
d1f6ea56555d
Fixed bug when generating ST code and connection is broken in POU using graphical language
Laurent Bessard
parents:
1183
diff
changeset
|
970 |
expression = self.ComputeExpression(body, instance.connectionPointIn.getconnections()) |
d1f6ea56555d
Fixed bug when generating ST code and connection is broken in POU using graphical language
Laurent Bessard
parents:
1183
diff
changeset
|
971 |
if expression is not None: |
d1f6ea56555d
Fixed bug when generating ST code and connection is broken in POU using graphical language
Laurent Bessard
parents:
1183
diff
changeset
|
972 |
self.ComputedConnectors[connector] = expression |
1297 | 973 |
elif isinstance(instance, CoilClass): |
814 | 974 |
connections = instance.connectionPointIn.getconnections() |
975 |
if connections is not None: |
|
976 |
coil_info = (self.TagName, "coil", instance.getlocalId()) |
|
1239
d1f6ea56555d
Fixed bug when generating ST code and connection is broken in POU using graphical language
Laurent Bessard
parents:
1183
diff
changeset
|
977 |
expression = self.ComputeExpression(body, connections) |
d1f6ea56555d
Fixed bug when generating ST code and connection is broken in POU using graphical language
Laurent Bessard
parents:
1183
diff
changeset
|
978 |
if expression is not None: |
d1f6ea56555d
Fixed bug when generating ST code and connection is broken in POU using graphical language
Laurent Bessard
parents:
1183
diff
changeset
|
979 |
expression = self.ExtractModifier(instance, expression, coil_info) |
d1f6ea56555d
Fixed bug when generating ST code and connection is broken in POU using graphical language
Laurent Bessard
parents:
1183
diff
changeset
|
980 |
self.Program += [(self.CurrentIndent, ())] |
1322
0a9227f743b3
Fixed xmlclass for working with included files, adding support for SimpleType elements and solving ambiguity in extension class when different elements share the same name and parent name
Laurent Bessard
parents:
1315
diff
changeset
|
981 |
self.Program += [(instance.getvariable(), coil_info + ("reference",))] |
1239
d1f6ea56555d
Fixed bug when generating ST code and connection is broken in POU using graphical language
Laurent Bessard
parents:
1183
diff
changeset
|
982 |
self.Program += [(" := ", ())] + expression + [(";\n", ())] |
1418
c97dc5281419
Fixed declaration and ST code gen for IEC function that return derivated types
Edouard Tisserant
parents:
1358
diff
changeset
|
983 |
|
814 | 984 |
def FactorizePaths(self, paths): |
985 |
same_paths = {} |
|
986 |
uncomputed_index = range(len(paths)) |
|
987 |
factorized_paths = [] |
|
988 |
for num, path in enumerate(paths): |
|
989 |
if type(path) == ListType: |
|
990 |
if len(path) > 1: |
|
991 |
str_path = str(path[-1:]) |
|
992 |
same_paths.setdefault(str_path, []) |
|
993 |
same_paths[str_path].append((path[:-1], num)) |
|
994 |
else: |
|
995 |
factorized_paths.append(path) |
|
996 |
uncomputed_index.remove(num) |
|
997 |
for same_path, elements in same_paths.items(): |
|
998 |
if len(elements) > 1: |
|
999 |
elements_paths = self.FactorizePaths([path for path, num in elements]) |
|
1000 |
if len(elements_paths) > 1: |
|
1418
c97dc5281419
Fixed declaration and ST code gen for IEC function that return derivated types
Edouard Tisserant
parents:
1358
diff
changeset
|
1001 |
factorized_paths.append([tuple(elements_paths)] + eval(same_path)) |
814 | 1002 |
else: |
1003 |
factorized_paths.append(elements_paths + eval(same_path)) |
|
1004 |
for path, num in elements: |
|
1005 |
uncomputed_index.remove(num) |
|
1006 |
for num in uncomputed_index: |
|
1007 |
factorized_paths.append(paths[num]) |
|
1008 |
factorized_paths.sort() |
|
1009 |
return factorized_paths |
|
1010 |
||
1310
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1011 |
def GenerateBlock(self, block, block_infos, body, link, order=False, to_inout=False): |
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1012 |
body_type = body.getcontent().getLocalTag() |
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1013 |
name = block.getinstanceName() |
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1014 |
type = block.gettypeName() |
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1015 |
executionOrderId = block.getexecutionOrderId() |
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1016 |
input_variables = block.inputVariables.getvariable() |
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1017 |
output_variables = block.outputVariables.getvariable() |
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1018 |
inout_variables = {} |
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1019 |
for input_variable in input_variables: |
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1020 |
for output_variable in output_variables: |
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1021 |
if input_variable.getformalParameter() == output_variable.getformalParameter(): |
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1022 |
inout_variables[input_variable.getformalParameter()] = "" |
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1023 |
input_names = [input[0] for input in block_infos["inputs"]] |
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1024 |
output_names = [output[0] for output in block_infos["outputs"]] |
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1025 |
if block_infos["type"] == "function": |
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1026 |
if not self.ComputedBlocks.get(block, False) and not order: |
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1027 |
self.ComputedBlocks[block] = True |
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1028 |
connected_vars = [] |
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1029 |
if not block_infos["extensible"]: |
1418
c97dc5281419
Fixed declaration and ST code gen for IEC function that return derivated types
Edouard Tisserant
parents:
1358
diff
changeset
|
1030 |
input_connected = dict([("EN", None)] + |
1310
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1031 |
[(input_name, None) for input_name in input_names]) |
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1032 |
for variable in input_variables: |
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1033 |
parameter = variable.getformalParameter() |
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1034 |
if input_connected.has_key(parameter): |
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1035 |
input_connected[parameter] = variable |
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1036 |
if input_connected["EN"] is None: |
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1037 |
input_connected.pop("EN") |
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1038 |
input_parameters = input_names |
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1039 |
else: |
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1040 |
input_parameters = ["EN"] + input_names |
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1041 |
else: |
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1042 |
input_connected = dict([(variable.getformalParameter(), variable) |
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1043 |
for variable in input_variables]) |
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1044 |
input_parameters = [variable.getformalParameter() |
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1045 |
for variable in input_variables] |
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1046 |
one_input_connected = False |
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1047 |
all_input_connected = True |
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1048 |
for i, parameter in enumerate(input_parameters): |
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1049 |
variable = input_connected.get(parameter) |
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1050 |
if variable is not None: |
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1051 |
input_info = (self.TagName, "block", block.getlocalId(), "input", i) |
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1052 |
connections = variable.connectionPointIn.getconnections() |
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1053 |
if connections is not None: |
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1054 |
if parameter != "EN": |
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1055 |
one_input_connected = True |
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1056 |
if inout_variables.has_key(parameter): |
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1057 |
expression = self.ComputeExpression(body, connections, executionOrderId > 0, True) |
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1058 |
if expression is not None: |
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1059 |
inout_variables[parameter] = value |
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1060 |
else: |
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1061 |
expression = self.ComputeExpression(body, connections, executionOrderId > 0) |
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1062 |
if expression is not None: |
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1063 |
connected_vars.append(([(parameter, input_info), (" := ", ())], |
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1064 |
self.ExtractModifier(variable, expression, input_info))) |
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1065 |
else: |
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1066 |
all_input_connected = False |
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1067 |
else: |
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1068 |
all_input_connected = False |
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1069 |
if len(output_variables) > 1 or not all_input_connected: |
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1070 |
vars = [name + value for name, value in connected_vars] |
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1071 |
else: |
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1072 |
vars = [value for name, value in connected_vars] |
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1073 |
if one_input_connected: |
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1074 |
for i, variable in enumerate(output_variables): |
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1075 |
parameter = variable.getformalParameter() |
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1076 |
if not inout_variables.has_key(parameter) and parameter in output_names + ["", "ENO"]: |
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1077 |
if variable.getformalParameter() == "": |
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1078 |
variable_name = "%s%d"%(type, block.getlocalId()) |
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1079 |
else: |
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1080 |
variable_name = "%s%d_%s"%(type, block.getlocalId(), parameter) |
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1081 |
if self.Interface[-1][0] != "VAR" or self.Interface[-1][1] is not None or self.Interface[-1][2]: |
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1082 |
self.Interface.append(("VAR", None, False, [])) |
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1083 |
if variable.connectionPointOut in self.ConnectionTypes: |
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1084 |
self.Interface[-1][3].append((self.ConnectionTypes[variable.connectionPointOut], variable_name, None, None)) |
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1085 |
else: |
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1086 |
self.Interface[-1][3].append(("ANY", variable_name, None, None)) |
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1087 |
if len(output_variables) > 1 and parameter not in ["", "OUT"]: |
1418
c97dc5281419
Fixed declaration and ST code gen for IEC function that return derivated types
Edouard Tisserant
parents:
1358
diff
changeset
|
1088 |
vars.append([(parameter, (self.TagName, "block", block.getlocalId(), "output", i)), |
1310
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1089 |
(" => %s"%variable_name, ())]) |
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1090 |
else: |
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1091 |
output_info = (self.TagName, "block", block.getlocalId(), "output", i) |
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1092 |
output_name = variable_name |
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1093 |
self.Program += [(self.CurrentIndent, ()), |
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1094 |
(output_name, output_info), |
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1095 |
(" := ", ()), |
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1096 |
(type, (self.TagName, "block", block.getlocalId(), "type")), |
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1097 |
("(", ())] |
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1098 |
self.Program += JoinList([(", ", ())], vars) |
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1099 |
self.Program += [(");\n", ())] |
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1100 |
else: |
1581
2295fdc5c271
fix translation strings with multiple parameters
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
1101 |
msg = _("\"{a1}\" function cancelled in \"{a2}\" POU: No input connected").format(a1 = type, a2 = self.TagName.split("::")[-1]) |
2295fdc5c271
fix translation strings with multiple parameters
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
1102 |
self.Warnings.append(msg) |
1310
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1103 |
elif block_infos["type"] == "functionBlock": |
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1104 |
if not self.ComputedBlocks.get(block, False) and not order: |
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1105 |
self.ComputedBlocks[block] = True |
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1106 |
vars = [] |
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1107 |
offset_idx = 0 |
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1108 |
for variable in input_variables: |
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1109 |
parameter = variable.getformalParameter() |
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1110 |
if parameter in input_names or parameter == "EN": |
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1111 |
if parameter == "EN": |
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1112 |
input_idx = 0 |
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1113 |
offset_idx = 1 |
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1114 |
else: |
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1115 |
input_idx = offset_idx + input_names.index(parameter) |
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1116 |
input_info = (self.TagName, "block", block.getlocalId(), "input", input_idx) |
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1117 |
connections = variable.connectionPointIn.getconnections() |
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1118 |
if connections is not None: |
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1119 |
expression = self.ComputeExpression(body, connections, executionOrderId > 0, inout_variables.has_key(parameter)) |
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1120 |
if expression is not None: |
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1121 |
vars.append([(parameter, input_info), |
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1122 |
(" := ", ())] + self.ExtractModifier(variable, expression, input_info)) |
1418
c97dc5281419
Fixed declaration and ST code gen for IEC function that return derivated types
Edouard Tisserant
parents:
1358
diff
changeset
|
1123 |
self.Program += [(self.CurrentIndent, ()), |
1310
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1124 |
(name, (self.TagName, "block", block.getlocalId(), "name")), |
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1125 |
("(", ())] |
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1126 |
self.Program += JoinList([(", ", ())], vars) |
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1127 |
self.Program += [(");\n", ())] |
1418
c97dc5281419
Fixed declaration and ST code gen for IEC function that return derivated types
Edouard Tisserant
parents:
1358
diff
changeset
|
1128 |
|
1310
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1129 |
if link is not None: |
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1130 |
connectionPoint = link.getposition()[-1] |
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1131 |
output_parameter = link.getformalParameter() |
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1132 |
else: |
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1133 |
connectionPoint = None |
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1134 |
output_parameter = None |
1418
c97dc5281419
Fixed declaration and ST code gen for IEC function that return derivated types
Edouard Tisserant
parents:
1358
diff
changeset
|
1135 |
|
1310
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1136 |
output_variable = None |
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1137 |
output_idx = 0 |
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1138 |
if output_parameter is not None: |
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1139 |
if output_parameter in output_names or output_parameter == "ENO": |
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1140 |
for variable in output_variables: |
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1141 |
if variable.getformalParameter() == output_parameter: |
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1142 |
output_variable = variable |
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1143 |
if output_parameter != "ENO": |
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1144 |
output_idx = output_names.index(output_parameter) |
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1145 |
else: |
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1146 |
for i, variable in enumerate(output_variables): |
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1147 |
blockPointx, blockPointy = variable.connectionPointOut.getrelPositionXY() |
1418
c97dc5281419
Fixed declaration and ST code gen for IEC function that return derivated types
Edouard Tisserant
parents:
1358
diff
changeset
|
1148 |
if (connectionPoint is None or |
c97dc5281419
Fixed declaration and ST code gen for IEC function that return derivated types
Edouard Tisserant
parents:
1358
diff
changeset
|
1149 |
block.getx() + blockPointx == connectionPoint.getx() and |
1310
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1150 |
block.gety() + blockPointy == connectionPoint.gety()): |
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1151 |
output_variable = variable |
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1152 |
output_parameter = variable.getformalParameter() |
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1153 |
output_idx = i |
1418
c97dc5281419
Fixed declaration and ST code gen for IEC function that return derivated types
Edouard Tisserant
parents:
1358
diff
changeset
|
1154 |
|
1310
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1155 |
if output_variable is not None: |
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1156 |
if block_infos["type"] == "function": |
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1157 |
output_info = (self.TagName, "block", block.getlocalId(), "output", output_idx) |
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1158 |
if inout_variables.has_key(output_parameter): |
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1159 |
output_value = inout_variables[output_parameter] |
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1160 |
else: |
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1161 |
if output_parameter == "": |
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1162 |
output_name = "%s%d"%(type, block.getlocalId()) |
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1163 |
else: |
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1164 |
output_name = "%s%d_%s"%(type, block.getlocalId(), output_parameter) |
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1165 |
output_value = [(output_name, output_info)] |
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1166 |
return self.ExtractModifier(output_variable, output_value, output_info) |
1418
c97dc5281419
Fixed declaration and ST code gen for IEC function that return derivated types
Edouard Tisserant
parents:
1358
diff
changeset
|
1167 |
|
1310
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1168 |
if block_infos["type"] == "functionBlock": |
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1169 |
output_info = (self.TagName, "block", block.getlocalId(), "output", output_idx) |
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1170 |
output_name = self.ExtractModifier(output_variable, [("%s.%s"%(name, output_parameter), output_info)], output_info) |
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1171 |
if to_inout: |
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1172 |
variable_name = "%s_%s"%(name, output_parameter) |
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1173 |
if not self.IsAlreadyDefined(variable_name): |
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1174 |
if self.Interface[-1][0] != "VAR" or self.Interface[-1][1] is not None or self.Interface[-1][2]: |
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1175 |
self.Interface.append(("VAR", None, False, [])) |
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1176 |
if variable.connectionPointOut in self.ConnectionTypes: |
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1177 |
self.Interface[-1][3].append( |
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1178 |
(self.ConnectionTypes[output_variable.connectionPointOut], variable_name, None, None)) |
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1179 |
else: |
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1180 |
self.Interface[-1][3].append(("ANY", variable_name, None, None)) |
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1181 |
self.Program += [(self.CurrentIndent, ()), |
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1182 |
("%s := "%variable_name, ())] |
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1183 |
self.Program += output_name |
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1184 |
self.Program += [(";\n", ())] |
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1185 |
return [(variable_name, ())] |
1418
c97dc5281419
Fixed declaration and ST code gen for IEC function that return derivated types
Edouard Tisserant
parents:
1358
diff
changeset
|
1186 |
return output_name |
1310
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1187 |
if link is not None: |
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1188 |
if output_parameter is None: |
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1189 |
output_parameter = "" |
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1190 |
if name: |
1581
2295fdc5c271
fix translation strings with multiple parameters
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
1191 |
blockname = "{a1}({a2})".format(a1 = name, a2 = type) |
1310
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1192 |
else: |
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1193 |
blockname = type |
1581
2295fdc5c271
fix translation strings with multiple parameters
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
1194 |
msg = _("No output {a1} variable found in block {a2} in POU {a3}. Connection must be broken").\ |
2295fdc5c271
fix translation strings with multiple parameters
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
1195 |
format(a1 = output_parameter, a2 = blockname, a3 = self.Name) |
2295fdc5c271
fix translation strings with multiple parameters
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
1196 |
raise ValueError, msg |
1310
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1197 |
|
814 | 1198 |
def GeneratePaths(self, connections, body, order = False, to_inout = False): |
1199 |
paths = [] |
|
1200 |
for connection in connections: |
|
1201 |
localId = connection.getrefLocalId() |
|
1202 |
next = body.getcontentInstance(localId) |
|
1297 | 1203 |
if isinstance(next, LeftPowerRailClass): |
814 | 1204 |
paths.append(None) |
1297 | 1205 |
elif isinstance(next, (InVariableClass, InOutVariableClass)): |
1322
0a9227f743b3
Fixed xmlclass for working with included files, adding support for SimpleType elements and solving ambiguity in extension class when different elements share the same name and parent name
Laurent Bessard
parents:
1315
diff
changeset
|
1206 |
paths.append(str([(next.getexpression(), (self.TagName, "io_variable", localId, "expression"))])) |
1297 | 1207 |
elif isinstance(next, BlockClass): |
814 | 1208 |
block_type = next.gettypeName() |
1209 |
self.ParentGenerator.GeneratePouProgram(block_type) |
|
1210 |
block_infos = self.GetBlockType(block_type, tuple([self.ConnectionTypes.get(variable.connectionPointIn, "ANY") for variable in next.inputVariables.getvariable() if variable.getformalParameter() != "EN"])) |
|
1211 |
if block_infos is None: |
|
1212 |
block_infos = self.GetBlockType(block_type) |
|
1213 |
if block_infos is None: |
|
1581
2295fdc5c271
fix translation strings with multiple parameters
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
1214 |
msg = _("Undefined block type \"{a1}\" in \"{a2}\" POU").format(a1 = block_type, a2 = self.Name) |
2295fdc5c271
fix translation strings with multiple parameters
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
1215 |
raise PLCGenException, msg |
1134
1c7a4ad86aa1
Fixed PLC code generator when interface of an already used POU has changed
Laurent Bessard
parents:
1048
diff
changeset
|
1216 |
try: |
1310
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1217 |
paths.append(str(self.GenerateBlock(next, block_infos, body, connection, order, to_inout))) |
1134
1c7a4ad86aa1
Fixed PLC code generator when interface of an already used POU has changed
Laurent Bessard
parents:
1048
diff
changeset
|
1218 |
except ValueError, e: |
1c7a4ad86aa1
Fixed PLC code generator when interface of an already used POU has changed
Laurent Bessard
parents:
1048
diff
changeset
|
1219 |
raise PLCGenException, e.message |
1297 | 1220 |
elif isinstance(next, ContinuationClass): |
814 | 1221 |
name = next.getname() |
1222 |
computed_value = self.ComputedConnectors.get(name, None) |
|
1223 |
if computed_value != None: |
|
1224 |
paths.append(str(computed_value)) |
|
1225 |
else: |
|
1226 |
connector = None |
|
1227 |
for instance in body.getcontentInstances(): |
|
1297 | 1228 |
if isinstance(instance, ConnectorClass) and instance.getname() == name: |
814 | 1229 |
if connector is not None: |
1581
2295fdc5c271
fix translation strings with multiple parameters
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
1230 |
msg = _("More than one connector found corresponding to \"{a1}\" continuation in \"{a2}\" POU").format(a1 = name, a2 = self.Name) |
2295fdc5c271
fix translation strings with multiple parameters
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
1231 |
raise PLCGenException, msg |
814 | 1232 |
connector = instance |
1233 |
if connector is not None: |
|
1234 |
connections = connector.connectionPointIn.getconnections() |
|
1235 |
if connections is not None: |
|
1236 |
expression = self.ComputeExpression(body, connections, order) |
|
1239
d1f6ea56555d
Fixed bug when generating ST code and connection is broken in POU using graphical language
Laurent Bessard
parents:
1183
diff
changeset
|
1237 |
if expression is not None: |
d1f6ea56555d
Fixed bug when generating ST code and connection is broken in POU using graphical language
Laurent Bessard
parents:
1183
diff
changeset
|
1238 |
self.ComputedConnectors[name] = expression |
d1f6ea56555d
Fixed bug when generating ST code and connection is broken in POU using graphical language
Laurent Bessard
parents:
1183
diff
changeset
|
1239 |
paths.append(str(expression)) |
814 | 1240 |
else: |
1581
2295fdc5c271
fix translation strings with multiple parameters
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
1241 |
msg = _("No connector found corresponding to \"{a1}\" continuation in \"{a2}\" POU").format(a1 = name, a2 = self.Name) |
2295fdc5c271
fix translation strings with multiple parameters
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
1242 |
raise PLCGenException, msg |
1297 | 1243 |
elif isinstance(next, ContactClass): |
814 | 1244 |
contact_info = (self.TagName, "contact", next.getlocalId()) |
1322
0a9227f743b3
Fixed xmlclass for working with included files, adding support for SimpleType elements and solving ambiguity in extension class when different elements share the same name and parent name
Laurent Bessard
parents:
1315
diff
changeset
|
1245 |
variable = str(self.ExtractModifier(next, [(next.getvariable(), contact_info + ("reference",))], contact_info)) |
814 | 1246 |
result = self.GeneratePaths(next.connectionPointIn.getconnections(), body, order) |
1247 |
if len(result) > 1: |
|
1248 |
factorized_paths = self.FactorizePaths(result) |
|
1249 |
if len(factorized_paths) > 1: |
|
1250 |
paths.append([variable, tuple(factorized_paths)]) |
|
1251 |
else: |
|
1252 |
paths.append([variable] + factorized_paths) |
|
1253 |
elif type(result[0]) == ListType: |
|
1254 |
paths.append([variable] + result[0]) |
|
1255 |
elif result[0] is not None: |
|
1256 |
paths.append([variable, result[0]]) |
|
1257 |
else: |
|
1258 |
paths.append(variable) |
|
1297 | 1259 |
elif isinstance(next, CoilClass): |
814 | 1260 |
paths.append(str(self.GeneratePaths(next.connectionPointIn.getconnections(), body, order))) |
1261 |
return paths |
|
1262 |
||
1263 |
def ComputePaths(self, paths, first = False): |
|
1264 |
if type(paths) == TupleType: |
|
1265 |
if None in paths: |
|
1266 |
return [("TRUE", ())] |
|
1267 |
else: |
|
1268 |
vars = [self.ComputePaths(path) for path in paths] |
|
1269 |
if first: |
|
1270 |
return JoinList([(" OR ", ())], vars) |
|
1271 |
else: |
|
1272 |
return [("(", ())] + JoinList([(" OR ", ())], vars) + [(")", ())] |
|
1273 |
elif type(paths) == ListType: |
|
1274 |
vars = [self.ComputePaths(path) for path in paths] |
|
1275 |
return JoinList([(" AND ", ())], vars) |
|
1276 |
elif paths is None: |
|
1277 |
return [("TRUE", ())] |
|
1278 |
else: |
|
1279 |
return eval(paths) |
|
1280 |
||
1281 |
def ComputeExpression(self, body, connections, order = False, to_inout = False): |
|
1282 |
paths = self.GeneratePaths(connections, body, order, to_inout) |
|
1239
d1f6ea56555d
Fixed bug when generating ST code and connection is broken in POU using graphical language
Laurent Bessard
parents:
1183
diff
changeset
|
1283 |
if len(paths) == 0: |
d1f6ea56555d
Fixed bug when generating ST code and connection is broken in POU using graphical language
Laurent Bessard
parents:
1183
diff
changeset
|
1284 |
return None |
814 | 1285 |
if len(paths) > 1: |
1286 |
factorized_paths = self.FactorizePaths(paths) |
|
1287 |
if len(factorized_paths) > 1: |
|
1288 |
paths = tuple(factorized_paths) |
|
1289 |
else: |
|
1290 |
paths = factorized_paths[0] |
|
1291 |
else: |
|
1292 |
paths = paths[0] |
|
1293 |
return self.ComputePaths(paths, True) |
|
1294 |
||
1295 |
def ExtractModifier(self, variable, expression, var_info): |
|
1296 |
if variable.getnegated(): |
|
1297 |
return [("NOT(", var_info + ("negated",))] + expression + [(")", ())] |
|
1298 |
else: |
|
1299 |
storage = variable.getstorage() |
|
1300 |
if storage in ["set", "reset"]: |
|
1301 |
self.Program += [(self.CurrentIndent + "IF ", var_info + (storage,))] + expression |
|
1302 |
self.Program += [(" THEN\n ", ())] |
|
1303 |
if storage == "set": |
|
1304 |
return [("TRUE; (*set*)\n" + self.CurrentIndent + "END_IF", ())] |
|
1305 |
else: |
|
1306 |
return [("FALSE; (*reset*)\n" + self.CurrentIndent + "END_IF", ())] |
|
1307 |
edge = variable.getedge() |
|
1308 |
if edge == "rising": |
|
1309 |
return self.AddTrigger("R_TRIG", expression, var_info + ("rising",)) |
|
1310 |
elif edge == "falling": |
|
1311 |
return self.AddTrigger("F_TRIG", expression, var_info + ("falling",)) |
|
1312 |
return expression |
|
1418
c97dc5281419
Fixed declaration and ST code gen for IEC function that return derivated types
Edouard Tisserant
parents:
1358
diff
changeset
|
1313 |
|
814 | 1314 |
def AddTrigger(self, edge, expression, var_info): |
1315 |
if self.Interface[-1][0] != "VAR" or self.Interface[-1][1] is not None or self.Interface[-1][2]: |
|
1316 |
self.Interface.append(("VAR", None, False, [])) |
|
1317 |
i = 1 |
|
1318 |
name = "%s%d"%(edge, i) |
|
1319 |
while self.IsAlreadyDefined(name): |
|
1320 |
i += 1 |
|
1321 |
name = "%s%d"%(edge, i) |
|
1322 |
self.Interface[-1][3].append((edge, name, None, None)) |
|
1418
c97dc5281419
Fixed declaration and ST code gen for IEC function that return derivated types
Edouard Tisserant
parents:
1358
diff
changeset
|
1323 |
self.Program += [(self.CurrentIndent, ()), (name, var_info), ("(CLK := ", ())] |
814 | 1324 |
self.Program += expression |
1325 |
self.Program += [(");\n", ())] |
|
1326 |
return [("%s.Q"%name, var_info)] |
|
1418
c97dc5281419
Fixed declaration and ST code gen for IEC function that return derivated types
Edouard Tisserant
parents:
1358
diff
changeset
|
1327 |
|
814 | 1328 |
def ExtractDivergenceInput(self, divergence, pou): |
1329 |
connectionPointIn = divergence.getconnectionPointIn() |
|
1298
f034fb2b1aab
Fixed SFC block edition and SFC to SFC_textual code generating
Laurent Bessard
parents:
1297
diff
changeset
|
1330 |
if connectionPointIn is not None: |
814 | 1331 |
connections = connectionPointIn.getconnections() |
1332 |
if connections is not None and len(connections) == 1: |
|
1333 |
instanceLocalId = connections[0].getrefLocalId() |
|
1334 |
body = pou.getbody() |
|
1335 |
if isinstance(body, ListType): |
|
1336 |
body = body[0] |
|
1337 |
return body.getcontentInstance(instanceLocalId) |
|
1338 |
return None |
|
1339 |
||
1340 |
def ExtractConvergenceInputs(self, convergence, pou): |
|
1341 |
instances = [] |
|
1342 |
for connectionPointIn in convergence.getconnectionPointIn(): |
|
1343 |
connections = connectionPointIn.getconnections() |
|
1344 |
if connections is not None and len(connections) == 1: |
|
1345 |
instanceLocalId = connections[0].getrefLocalId() |
|
1346 |
body = pou.getbody() |
|
1347 |
if isinstance(body, ListType): |
|
1348 |
body = body[0] |
|
1349 |
instances.append(body.getcontentInstance(instanceLocalId)) |
|
1350 |
return instances |
|
1351 |
||
1352 |
def GenerateSFCStep(self, step, pou): |
|
1353 |
step_name = step.getname() |
|
1354 |
if step_name not in self.SFCNetworks["Steps"].keys(): |
|
1355 |
if step.getinitialStep(): |
|
1356 |
self.InitialSteps.append(step_name) |
|
1418
c97dc5281419
Fixed declaration and ST code gen for IEC function that return derivated types
Edouard Tisserant
parents:
1358
diff
changeset
|
1357 |
step_infos = {"id" : step.getlocalId(), |
c97dc5281419
Fixed declaration and ST code gen for IEC function that return derivated types
Edouard Tisserant
parents:
1358
diff
changeset
|
1358 |
"initial" : step.getinitialStep(), |
c97dc5281419
Fixed declaration and ST code gen for IEC function that return derivated types
Edouard Tisserant
parents:
1358
diff
changeset
|
1359 |
"transitions" : [], |
814 | 1360 |
"actions" : []} |
889
ac18acb6917f
Fix bug when using feedback loop in SFC program instead of jump
Laurent Bessard
parents:
883
diff
changeset
|
1361 |
self.SFCNetworks["Steps"][step_name] = step_infos |
1298
f034fb2b1aab
Fixed SFC block edition and SFC to SFC_textual code generating
Laurent Bessard
parents:
1297
diff
changeset
|
1362 |
if step.connectionPointIn is not None: |
814 | 1363 |
instances = [] |
1364 |
connections = step.connectionPointIn.getconnections() |
|
1365 |
if connections is not None and len(connections) == 1: |
|
1366 |
instanceLocalId = connections[0].getrefLocalId() |
|
1367 |
body = pou.getbody() |
|
1368 |
if isinstance(body, ListType): |
|
1369 |
body = body[0] |
|
1370 |
instance = body.getcontentInstance(instanceLocalId) |
|
1297 | 1371 |
if isinstance(instance, TransitionClass): |
814 | 1372 |
instances.append(instance) |
1297 | 1373 |
elif isinstance(instance, SelectionConvergenceClass): |
814 | 1374 |
instances.extend(self.ExtractConvergenceInputs(instance, pou)) |
1297 | 1375 |
elif isinstance(instance, SimultaneousDivergenceClass): |
814 | 1376 |
transition = self.ExtractDivergenceInput(instance, pou) |
1298
f034fb2b1aab
Fixed SFC block edition and SFC to SFC_textual code generating
Laurent Bessard
parents:
1297
diff
changeset
|
1377 |
if transition is not None: |
1297 | 1378 |
if isinstance(transition, TransitionClass): |
814 | 1379 |
instances.append(transition) |
1297 | 1380 |
elif isinstance(transition, SelectionConvergenceClass): |
814 | 1381 |
instances.extend(self.ExtractConvergenceInputs(transition, pou)) |
1382 |
for instance in instances: |
|
1383 |
self.GenerateSFCTransition(instance, pou) |
|
1384 |
if instance in self.SFCNetworks["Transitions"].keys(): |
|
1385 |
target_info = (self.TagName, "transition", instance.getlocalId(), "to", step_infos["id"]) |
|
1386 |
self.SFCNetworks["Transitions"][instance]["to"].append([(step_name, target_info)]) |
|
1418
c97dc5281419
Fixed declaration and ST code gen for IEC function that return derivated types
Edouard Tisserant
parents:
1358
diff
changeset
|
1387 |
|
814 | 1388 |
def GenerateSFCJump(self, jump, pou): |
1389 |
jump_target = jump.gettargetName() |
|
1626
0779c1b18c01
check before program generation whether SFC step, that is referenced
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1614
diff
changeset
|
1390 |
if not pou.hasstep(jump_target): |
0779c1b18c01
check before program generation whether SFC step, that is referenced
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1614
diff
changeset
|
1391 |
pname = pou.getname() |
0779c1b18c01
check before program generation whether SFC step, that is referenced
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1614
diff
changeset
|
1392 |
msg = _("SFC jump in pou \"{a1}\" refers to non-existent SFC step \"{a2}\"").format( a1 = pname, a2 = jump_target) |
0779c1b18c01
check before program generation whether SFC step, that is referenced
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1614
diff
changeset
|
1393 |
raise PLCGenException, msg |
1298
f034fb2b1aab
Fixed SFC block edition and SFC to SFC_textual code generating
Laurent Bessard
parents:
1297
diff
changeset
|
1394 |
if jump.connectionPointIn is not None: |
814 | 1395 |
instances = [] |
1396 |
connections = jump.connectionPointIn.getconnections() |
|
1397 |
if connections is not None and len(connections) == 1: |
|
1398 |
instanceLocalId = connections[0].getrefLocalId() |
|
1399 |
body = pou.getbody() |
|
1400 |
if isinstance(body, ListType): |
|
1401 |
body = body[0] |
|
1402 |
instance = body.getcontentInstance(instanceLocalId) |
|
1297 | 1403 |
if isinstance(instance, TransitionClass): |
814 | 1404 |
instances.append(instance) |
1297 | 1405 |
elif isinstance(instance, SelectionConvergenceClass): |
814 | 1406 |
instances.extend(self.ExtractConvergenceInputs(instance, pou)) |
1297 | 1407 |
elif isinstance(instance, SimultaneousDivergenceClass): |
814 | 1408 |
transition = self.ExtractDivergenceInput(instance, pou) |
1298
f034fb2b1aab
Fixed SFC block edition and SFC to SFC_textual code generating
Laurent Bessard
parents:
1297
diff
changeset
|
1409 |
if transition is not None: |
1297 | 1410 |
if isinstance(transition, TransitionClass): |
814 | 1411 |
instances.append(transition) |
1297 | 1412 |
elif isinstance(transition, SelectionConvergenceClass): |
814 | 1413 |
instances.extend(self.ExtractConvergenceInputs(transition, pou)) |
1414 |
for instance in instances: |
|
1415 |
self.GenerateSFCTransition(instance, pou) |
|
1416 |
if instance in self.SFCNetworks["Transitions"].keys(): |
|
1417 |
target_info = (self.TagName, "jump", jump.getlocalId(), "target") |
|
1418 |
self.SFCNetworks["Transitions"][instance]["to"].append([(jump_target, target_info)]) |
|
1418
c97dc5281419
Fixed declaration and ST code gen for IEC function that return derivated types
Edouard Tisserant
parents:
1358
diff
changeset
|
1419 |
|
814 | 1420 |
def GenerateSFCStepActions(self, actionBlock, pou): |
1421 |
connections = actionBlock.connectionPointIn.getconnections() |
|
1422 |
if connections is not None and len(connections) == 1: |
|
1423 |
stepLocalId = connections[0].getrefLocalId() |
|
1424 |
body = pou.getbody() |
|
1425 |
if isinstance(body, ListType): |
|
1426 |
body = body[0] |
|
1427 |
step = body.getcontentInstance(stepLocalId) |
|
1428 |
self.GenerateSFCStep(step, pou) |
|
1429 |
step_name = step.getname() |
|
1430 |
if step_name in self.SFCNetworks["Steps"].keys(): |
|
1431 |
actions = actionBlock.getactions() |
|
1432 |
for i, action in enumerate(actions): |
|
1418
c97dc5281419
Fixed declaration and ST code gen for IEC function that return derivated types
Edouard Tisserant
parents:
1358
diff
changeset
|
1433 |
action_infos = {"id" : actionBlock.getlocalId(), |
c97dc5281419
Fixed declaration and ST code gen for IEC function that return derivated types
Edouard Tisserant
parents:
1358
diff
changeset
|
1434 |
"qualifier" : action["qualifier"], |
814 | 1435 |
"content" : action["value"], |
1436 |
"num" : i} |
|
1437 |
if "duration" in action: |
|
1438 |
action_infos["duration"] = action["duration"] |
|
1439 |
if "indicator" in action: |
|
1440 |
action_infos["indicator"] = action["indicator"] |
|
1441 |
if action["type"] == "reference": |
|
1442 |
self.GenerateSFCAction(action["value"], pou) |
|
1443 |
else: |
|
1444 |
action_name = "%s_INLINE%d"%(step_name.upper(), self.GetActionNumber()) |
|
1418
c97dc5281419
Fixed declaration and ST code gen for IEC function that return derivated types
Edouard Tisserant
parents:
1358
diff
changeset
|
1445 |
self.SFCNetworks["Actions"][action_name] = ([(self.CurrentIndent, ()), |
814 | 1446 |
(action["value"], (self.TagName, "action_block", action_infos["id"], "action", i, "inline")), |
1447 |
("\n", ())], ()) |
|
1448 |
action_infos["content"] = action_name |
|
1449 |
self.SFCNetworks["Steps"][step_name]["actions"].append(action_infos) |
|
1418
c97dc5281419
Fixed declaration and ST code gen for IEC function that return derivated types
Edouard Tisserant
parents:
1358
diff
changeset
|
1450 |
|
814 | 1451 |
def GenerateSFCAction(self, action_name, pou): |
1452 |
if action_name not in self.SFCNetworks["Actions"].keys(): |
|
1453 |
actionContent = pou.getaction(action_name) |
|
1298
f034fb2b1aab
Fixed SFC block edition and SFC to SFC_textual code generating
Laurent Bessard
parents:
1297
diff
changeset
|
1454 |
if actionContent is not None: |
814 | 1455 |
previous_tagname = self.TagName |
1456 |
self.TagName = self.ParentGenerator.Controler.ComputePouActionName(self.Name, action_name) |
|
1457 |
self.ComputeProgram(actionContent) |
|
1458 |
self.SFCNetworks["Actions"][action_name] = (self.Program, (self.TagName, "name")) |
|
1459 |
self.Program = [] |
|
1460 |
self.TagName = previous_tagname |
|
1418
c97dc5281419
Fixed declaration and ST code gen for IEC function that return derivated types
Edouard Tisserant
parents:
1358
diff
changeset
|
1461 |
|
814 | 1462 |
def GenerateSFCTransition(self, transition, pou): |
1463 |
if transition not in self.SFCNetworks["Transitions"].keys(): |
|
1464 |
steps = [] |
|
1465 |
connections = transition.connectionPointIn.getconnections() |
|
1466 |
if connections is not None and len(connections) == 1: |
|
1467 |
instanceLocalId = connections[0].getrefLocalId() |
|
1468 |
body = pou.getbody() |
|
1469 |
if isinstance(body, ListType): |
|
1470 |
body = body[0] |
|
1471 |
instance = body.getcontentInstance(instanceLocalId) |
|
1297 | 1472 |
if isinstance(instance, StepClass): |
814 | 1473 |
steps.append(instance) |
1297 | 1474 |
elif isinstance(instance, SelectionDivergenceClass): |
814 | 1475 |
step = self.ExtractDivergenceInput(instance, pou) |
1298
f034fb2b1aab
Fixed SFC block edition and SFC to SFC_textual code generating
Laurent Bessard
parents:
1297
diff
changeset
|
1476 |
if step is not None: |
1297 | 1477 |
if isinstance(step, StepClass): |
814 | 1478 |
steps.append(step) |
1297 | 1479 |
elif isinstance(step, SimultaneousConvergenceClass): |
814 | 1480 |
steps.extend(self.ExtractConvergenceInputs(step, pou)) |
1297 | 1481 |
elif isinstance(instance, SimultaneousConvergenceClass): |
814 | 1482 |
steps.extend(self.ExtractConvergenceInputs(instance, pou)) |
1418
c97dc5281419
Fixed declaration and ST code gen for IEC function that return derivated types
Edouard Tisserant
parents:
1358
diff
changeset
|
1483 |
transition_infos = {"id" : transition.getlocalId(), |
c97dc5281419
Fixed declaration and ST code gen for IEC function that return derivated types
Edouard Tisserant
parents:
1358
diff
changeset
|
1484 |
"priority": transition.getpriority(), |
c97dc5281419
Fixed declaration and ST code gen for IEC function that return derivated types
Edouard Tisserant
parents:
1358
diff
changeset
|
1485 |
"from": [], |
1298
f034fb2b1aab
Fixed SFC block edition and SFC to SFC_textual code generating
Laurent Bessard
parents:
1297
diff
changeset
|
1486 |
"to" : [], |
f034fb2b1aab
Fixed SFC block edition and SFC to SFC_textual code generating
Laurent Bessard
parents:
1297
diff
changeset
|
1487 |
"content": []} |
889
ac18acb6917f
Fix bug when using feedback loop in SFC program instead of jump
Laurent Bessard
parents:
883
diff
changeset
|
1488 |
self.SFCNetworks["Transitions"][transition] = transition_infos |
814 | 1489 |
transitionValues = transition.getconditionContent() |
1490 |
if transitionValues["type"] == "inline": |
|
1491 |
transition_infos["content"] = [("\n%s:= "%self.CurrentIndent, ()), |
|
1492 |
(transitionValues["value"], (self.TagName, "transition", transition.getlocalId(), "inline")), |
|
1493 |
(";\n", ())] |
|
1494 |
elif transitionValues["type"] == "reference": |
|
1495 |
transitionContent = pou.gettransition(transitionValues["value"]) |
|
1496 |
transitionType = transitionContent.getbodyType() |
|
1497 |
transitionBody = transitionContent.getbody() |
|
1498 |
previous_tagname = self.TagName |
|
1499 |
self.TagName = self.ParentGenerator.Controler.ComputePouTransitionName(self.Name, transitionValues["value"]) |
|
1500 |
if transitionType == "IL": |
|
1501 |
transition_infos["content"] = [(":\n", ()), |
|
1450
44bf0ba866e9
Fixed SFC code generation bug detected by Mario
Edouard Tisserant
parents:
1420
diff
changeset
|
1502 |
(ReIndentText(transitionBody.getcontent().getanyText(), len(self.CurrentIndent)), (self.TagName, "body", len(self.CurrentIndent)))] |
814 | 1503 |
elif transitionType == "ST": |
1504 |
transition_infos["content"] = [("\n", ()), |
|
1450
44bf0ba866e9
Fixed SFC code generation bug detected by Mario
Edouard Tisserant
parents:
1420
diff
changeset
|
1505 |
(ReIndentText(transitionBody.getcontent().getanyText(), len(self.CurrentIndent)), (self.TagName, "body", len(self.CurrentIndent)))] |
814 | 1506 |
else: |
1507 |
for instance in transitionBody.getcontentInstances(): |
|
1322
0a9227f743b3
Fixed xmlclass for working with included files, adding support for SimpleType elements and solving ambiguity in extension class when different elements share the same name and parent name
Laurent Bessard
parents:
1315
diff
changeset
|
1508 |
if isinstance(instance, OutVariableClass) and instance.getexpression() == transitionValues["value"]\ |
0a9227f743b3
Fixed xmlclass for working with included files, adding support for SimpleType elements and solving ambiguity in extension class when different elements share the same name and parent name
Laurent Bessard
parents:
1315
diff
changeset
|
1509 |
or isinstance(instance, CoilClass) and instance.getvariable() == transitionValues["value"]: |
814 | 1510 |
connections = instance.connectionPointIn.getconnections() |
1511 |
if connections is not None: |
|
1512 |
expression = self.ComputeExpression(transitionBody, connections) |
|
1239
d1f6ea56555d
Fixed bug when generating ST code and connection is broken in POU using graphical language
Laurent Bessard
parents:
1183
diff
changeset
|
1513 |
if expression is not None: |
d1f6ea56555d
Fixed bug when generating ST code and connection is broken in POU using graphical language
Laurent Bessard
parents:
1183
diff
changeset
|
1514 |
transition_infos["content"] = [("\n%s:= "%self.CurrentIndent, ())] + expression + [(";\n", ())] |
d1f6ea56555d
Fixed bug when generating ST code and connection is broken in POU using graphical language
Laurent Bessard
parents:
1183
diff
changeset
|
1515 |
self.SFCComputedBlocks += self.Program |
d1f6ea56555d
Fixed bug when generating ST code and connection is broken in POU using graphical language
Laurent Bessard
parents:
1183
diff
changeset
|
1516 |
self.Program = [] |
814 | 1517 |
if not transition_infos.has_key("content"): |
1518 |
raise PLCGenException, _("Transition \"%s\" body must contain an output variable or coil referring to its name") % transitionValues["value"] |
|
1519 |
self.TagName = previous_tagname |
|
1520 |
elif transitionValues["type"] == "connection": |
|
1521 |
body = pou.getbody() |
|
1522 |
if isinstance(body, ListType): |
|
1523 |
body = body[0] |
|
1298
f034fb2b1aab
Fixed SFC block edition and SFC to SFC_textual code generating
Laurent Bessard
parents:
1297
diff
changeset
|
1524 |
connections = transitionValues["value"].getconnections() |
814 | 1525 |
if connections is not None: |
1526 |
expression = self.ComputeExpression(body, connections) |
|
1239
d1f6ea56555d
Fixed bug when generating ST code and connection is broken in POU using graphical language
Laurent Bessard
parents:
1183
diff
changeset
|
1527 |
if expression is not None: |
d1f6ea56555d
Fixed bug when generating ST code and connection is broken in POU using graphical language
Laurent Bessard
parents:
1183
diff
changeset
|
1528 |
transition_infos["content"] = [("\n%s:= "%self.CurrentIndent, ())] + expression + [(";\n", ())] |
d1f6ea56555d
Fixed bug when generating ST code and connection is broken in POU using graphical language
Laurent Bessard
parents:
1183
diff
changeset
|
1529 |
self.SFCComputedBlocks += self.Program |
d1f6ea56555d
Fixed bug when generating ST code and connection is broken in POU using graphical language
Laurent Bessard
parents:
1183
diff
changeset
|
1530 |
self.Program = [] |
814 | 1531 |
for step in steps: |
1532 |
self.GenerateSFCStep(step, pou) |
|
1533 |
step_name = step.getname() |
|
1534 |
if step_name in self.SFCNetworks["Steps"].keys(): |
|
1535 |
transition_infos["from"].append([(step_name, (self.TagName, "transition", transition.getlocalId(), "from", step.getlocalId()))]) |
|
1536 |
self.SFCNetworks["Steps"][step_name]["transitions"].append(transition) |
|
1537 |
||
1538 |
def ComputeSFCStep(self, step_name): |
|
1539 |
if step_name in self.SFCNetworks["Steps"].keys(): |
|
1540 |
step_infos = self.SFCNetworks["Steps"].pop(step_name) |
|
1541 |
self.Program += [(self.CurrentIndent, ())] |
|
1542 |
if step_infos["initial"]: |
|
1543 |
self.Program += [("INITIAL_", ())] |
|
1544 |
self.Program += [("STEP ", ()), |
|
1545 |
(step_name, (self.TagName, "step", step_infos["id"], "name")), |
|
1546 |
(":\n", ())] |
|
1547 |
actions = [] |
|
1548 |
self.IndentRight() |
|
1549 |
for action_infos in step_infos["actions"]: |
|
1550 |
if action_infos.get("id", None) is not None: |
|
1551 |
action_info = (self.TagName, "action_block", action_infos["id"], "action", action_infos["num"]) |
|
1552 |
else: |
|
1553 |
action_info = () |
|
1554 |
actions.append(action_infos["content"]) |
|
1555 |
self.Program += [(self.CurrentIndent, ()), |
|
1556 |
(action_infos["content"], action_info + ("reference",)), |
|
1557 |
("(", ()), |
|
1558 |
(action_infos["qualifier"], action_info + ("qualifier",))] |
|
1559 |
if "duration" in action_infos: |
|
1560 |
self.Program += [(", ", ()), |
|
1561 |
(action_infos["duration"], action_info + ("duration",))] |
|
1562 |
if "indicator" in action_infos: |
|
1563 |
self.Program += [(", ", ()), |
|
1564 |
(action_infos["indicator"], action_info + ("indicator",))] |
|
1565 |
self.Program += [(");\n", ())] |
|
1566 |
self.IndentLeft() |
|
1567 |
self.Program += [("%sEND_STEP\n\n"%self.CurrentIndent, ())] |
|
1568 |
for action in actions: |
|
1569 |
self.ComputeSFCAction(action) |
|
1570 |
for transition in step_infos["transitions"]: |
|
1571 |
self.ComputeSFCTransition(transition) |
|
1418
c97dc5281419
Fixed declaration and ST code gen for IEC function that return derivated types
Edouard Tisserant
parents:
1358
diff
changeset
|
1572 |
|
814 | 1573 |
def ComputeSFCAction(self, action_name): |
1574 |
if action_name in self.SFCNetworks["Actions"].keys(): |
|
1575 |
action_content, action_info = self.SFCNetworks["Actions"].pop(action_name) |
|
1576 |
self.Program += [("%sACTION "%self.CurrentIndent, ()), |
|
1577 |
(action_name, action_info), |
|
1298
f034fb2b1aab
Fixed SFC block edition and SFC to SFC_textual code generating
Laurent Bessard
parents:
1297
diff
changeset
|
1578 |
(":\n", ())] |
814 | 1579 |
self.Program += action_content |
1580 |
self.Program += [("%sEND_ACTION\n\n"%self.CurrentIndent, ())] |
|
1418
c97dc5281419
Fixed declaration and ST code gen for IEC function that return derivated types
Edouard Tisserant
parents:
1358
diff
changeset
|
1581 |
|
814 | 1582 |
def ComputeSFCTransition(self, transition): |
1583 |
if transition in self.SFCNetworks["Transitions"].keys(): |
|
1584 |
transition_infos = self.SFCNetworks["Transitions"].pop(transition) |
|
1585 |
self.Program += [("%sTRANSITION"%self.CurrentIndent, ())] |
|
1586 |
if transition_infos["priority"] != None: |
|
1587 |
self.Program += [(" (PRIORITY := ", ()), |
|
1588 |
("%d"%transition_infos["priority"], (self.TagName, "transition", transition_infos["id"], "priority")), |
|
1589 |
(")", ())] |
|
1590 |
self.Program += [(" FROM ", ())] |
|
1591 |
if len(transition_infos["from"]) > 1: |
|
1592 |
self.Program += [("(", ())] |
|
1593 |
self.Program += JoinList([(", ", ())], transition_infos["from"]) |
|
1594 |
self.Program += [(")", ())] |
|
1595 |
elif len(transition_infos["from"]) == 1: |
|
1596 |
self.Program += transition_infos["from"][0] |
|
1597 |
else: |
|
1581
2295fdc5c271
fix translation strings with multiple parameters
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
1598 |
msg = _("Transition with content \"{a1}\" not connected to a previous step in \"{a2}\" POU").\ |
2295fdc5c271
fix translation strings with multiple parameters
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
1599 |
format(a1 = transition_infos["content"], a2 = self.Name) |
2295fdc5c271
fix translation strings with multiple parameters
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
1600 |
raise PLCGenException, msg |
814 | 1601 |
self.Program += [(" TO ", ())] |
1602 |
if len(transition_infos["to"]) > 1: |
|
1603 |
self.Program += [("(", ())] |
|
1604 |
self.Program += JoinList([(", ", ())], transition_infos["to"]) |
|
1605 |
self.Program += [(")", ())] |
|
1606 |
elif len(transition_infos["to"]) == 1: |
|
1607 |
self.Program += transition_infos["to"][0] |
|
1608 |
else: |
|
1581
2295fdc5c271
fix translation strings with multiple parameters
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
1609 |
msg = _("Transition with content \"{a1}\" not connected to a next step in \"{a2}\" POU").\ |
2295fdc5c271
fix translation strings with multiple parameters
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
1610 |
format(a1 = transition_infos["content"], a2 = self.Name) |
2295fdc5c271
fix translation strings with multiple parameters
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
1611 |
raise PLCGenException, msg |
814 | 1612 |
self.Program += transition_infos["content"] |
1613 |
self.Program += [("%sEND_TRANSITION\n\n"%self.CurrentIndent, ())] |
|
1614 |
for [(step_name, step_infos)] in transition_infos["to"]: |
|
1615 |
self.ComputeSFCStep(step_name) |
|
1418
c97dc5281419
Fixed declaration and ST code gen for IEC function that return derivated types
Edouard Tisserant
parents:
1358
diff
changeset
|
1616 |
|
814 | 1617 |
def GenerateProgram(self, pou): |
1618 |
self.ComputeInterface(pou) |
|
1619 |
self.ComputeConnectionTypes(pou) |
|
1620 |
self.ComputeProgram(pou) |
|
1418
c97dc5281419
Fixed declaration and ST code gen for IEC function that return derivated types
Edouard Tisserant
parents:
1358
diff
changeset
|
1621 |
|
814 | 1622 |
program = [("%s "%self.Type, ()), |
1623 |
(self.Name, (self.TagName, "name"))] |
|
1310
3d7fa2257b24
Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents:
1298
diff
changeset
|
1624 |
if self.ReturnType is not None: |
814 | 1625 |
program += [(" : ", ()), |
1626 |
(self.ReturnType, (self.TagName, "return"))] |
|
1627 |
program += [("\n", ())] |
|
1628 |
if len(self.Interface) == 0: |
|
1629 |
raise PLCGenException, _("No variable defined in \"%s\" POU")%self.Name |
|
1630 |
if len(self.Program) == 0 : |
|
1631 |
raise PLCGenException, _("No body defined in \"%s\" POU")%self.Name |
|
1632 |
var_number = 0 |
|
1633 |
for list_type, option, located, variables in self.Interface: |
|
1634 |
variable_type = errorVarTypes.get(list_type, "var_local") |
|
1635 |
program += [(" %s"%list_type, ())] |
|
1636 |
if option is not None: |
|
1637 |
program += [(" %s"%option, (self.TagName, variable_type, (var_number, var_number + len(variables)), option.lower()))] |
|
1638 |
program += [("\n", ())] |
|
1639 |
for var_type, var_name, var_address, var_initial in variables: |
|
1640 |
program += [(" ", ())] |
|
1641 |
if var_name: |
|
1642 |
program += [(var_name, (self.TagName, variable_type, var_number, "name")), |
|
1643 |
(" ", ())] |
|
1644 |
if var_address != None: |
|
1645 |
program += [("AT ", ()), |
|
1646 |
(var_address, (self.TagName, variable_type, var_number, "location")), |
|
1647 |
(" ", ())] |
|
1648 |
program += [(": ", ()), |
|
1649 |
(var_type, (self.TagName, variable_type, var_number, "type"))] |
|
1650 |
if var_initial != None: |
|
1651 |
program += [(" := ", ()), |
|
1652 |
(self.ParentGenerator.ComputeValue(var_initial, var_type), (self.TagName, variable_type, var_number, "initial value"))] |
|
1653 |
program += [(";\n", ())] |
|
1654 |
var_number += 1 |
|
1655 |
program += [(" END_VAR\n", ())] |
|
1656 |
program += [("\n", ())] |
|
1657 |
program += self.Program |
|
1658 |
program += [("END_%s\n\n"%self.Type, ())] |
|
1659 |
return program |
|
1660 |
||
1661 |
def GenerateCurrentProgram(controler, project, errors, warnings): |
|
1662 |
generator = ProgramGenerator(controler, project, errors, warnings) |
|
1663 |
generator.GenerateProgram() |
|
1664 |
return generator.GetGeneratedProgram() |
|
1665 |