author | lbessard |
Fri, 13 Mar 2009 16:20:37 +0100 | |
changeset 317 | bb25a8edd3e4 |
parent 307 | fd1f6ae26d4f |
child 340 | 5a305b7c6735 |
permissions | -rw-r--r-- |
0 | 1 |
#!/usr/bin/env python |
2 |
# -*- coding: utf-8 -*- |
|
3 |
||
4 |
#This file is part of PLCOpenEditor, a library implementing an IEC 61131-3 editor |
|
5 |
#based on the plcopen standard. |
|
6 |
# |
|
58 | 7 |
#Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD |
0 | 8 |
# |
9 |
#See COPYING file for copyrights details. |
|
10 |
# |
|
11 |
#This library is free software; you can redistribute it and/or |
|
5 | 12 |
#modify it under the terms of the GNU General Public |
0 | 13 |
#License as published by the Free Software Foundation; either |
14 |
#version 2.1 of the License, or (at your option) any later version. |
|
15 |
# |
|
16 |
#This library is distributed in the hope that it will be useful, |
|
17 |
#but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
18 |
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
58 | 19 |
#General Public License for more details. |
0 | 20 |
# |
5 | 21 |
#You should have received a copy of the GNU General Public |
0 | 22 |
#License along with this library; if not, write to the Free Software |
23 |
#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
24 |
||
25 |
from plcopen import plcopen |
|
26 |
from plcopen.structures import * |
|
27 |
from types import * |
|
28 |
||
227
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
29 |
|
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
30 |
# Dictionary associating PLCOpen variable categories to the corresponding |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
31 |
# IEC 61131-3 variable categories |
0 | 32 |
varTypeNames = {"localVars" : "VAR", "tempVars" : "VAR_TEMP", "inputVars" : "VAR_INPUT", |
33 |
"outputVars" : "VAR_OUTPUT", "inOutVars" : "VAR_IN_OUT", "externalVars" : "VAR_EXTERNAL", |
|
34 |
"globalVars" : "VAR_GLOBAL", "accessVars" : "VAR_ACCESS"} |
|
1 | 35 |
|
227
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
36 |
|
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
37 |
# Dictionary associating PLCOpen POU categories to the corresponding |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
38 |
# IEC 61131-3 POU categories |
6 | 39 |
pouTypeNames = {"function" : "FUNCTION", "functionBlock" : "FUNCTION_BLOCK", "program" : "PROGRAM"} |
40 |
||
227
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
41 |
|
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
42 |
# Helper function for reindenting text |
1 | 43 |
def ReIndentText(text, nb_spaces): |
44 |
compute = "" |
|
45 |
lines = text.splitlines() |
|
46 |
if len(lines) > 0: |
|
151 | 47 |
line_num = 0 |
48 |
while line_num < len(lines) and len(lines[line_num].strip()) == 0: |
|
49 |
line_num += 1 |
|
50 |
if line_num < len(lines): |
|
51 |
spaces = 0 |
|
52 |
while lines[line_num][spaces] == " ": |
|
53 |
spaces += 1 |
|
54 |
indent = "" |
|
55 |
for i in xrange(spaces, nb_spaces): |
|
56 |
indent += " " |
|
57 |
for line in lines: |
|
58 |
if line != "": |
|
59 |
compute += "%s%s\n"%(indent, line) |
|
60 |
else: |
|
61 |
compute += "\n" |
|
1 | 62 |
return compute |
63 |
||
269
34eff05909b0
Adding support for EN/ENO variables (temporarily disabled, waiting for matiec support)
lbessard
parents:
261
diff
changeset
|
64 |
def SortInstances(a, b): |
34eff05909b0
Adding support for EN/ENO variables (temporarily disabled, waiting for matiec support)
lbessard
parents:
261
diff
changeset
|
65 |
ax, ay = int(a.getx()), int(a.gety()) |
34eff05909b0
Adding support for EN/ENO variables (temporarily disabled, waiting for matiec support)
lbessard
parents:
261
diff
changeset
|
66 |
bx, by = int(b.getx()), int(b.gety()) |
280
9ca192486f2f
Bug in coil and output element sorting function fixed
lbessard
parents:
276
diff
changeset
|
67 |
if abs(ay - by) < 10: |
9ca192486f2f
Bug in coil and output element sorting function fixed
lbessard
parents:
276
diff
changeset
|
68 |
return cmp(ax, bx) |
269
34eff05909b0
Adding support for EN/ENO variables (temporarily disabled, waiting for matiec support)
lbessard
parents:
261
diff
changeset
|
69 |
else: |
280
9ca192486f2f
Bug in coil and output element sorting function fixed
lbessard
parents:
276
diff
changeset
|
70 |
return cmp(ay, by) |
227
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
71 |
|
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
72 |
#------------------------------------------------------------------------------- |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
73 |
# Specific exception for PLC generating errors |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
74 |
#------------------------------------------------------------------------------- |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
75 |
|
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
76 |
|
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
77 |
class PLCGenException(Exception): |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
78 |
pass |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
79 |
|
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
80 |
|
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
81 |
#------------------------------------------------------------------------------- |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
82 |
# Generator of PLC program |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
83 |
#------------------------------------------------------------------------------- |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
84 |
|
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
85 |
|
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
86 |
class ProgramGenerator: |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
87 |
|
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
88 |
# Create a new PCL program generator |
307
fd1f6ae26d4f
Adding support for cancelling code generation of function with no input connected
lbessard
parents:
295
diff
changeset
|
89 |
def __init__(self, controler, project, errors, warnings): |
227
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
90 |
# Keep reference of the controler and project |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
91 |
self.Controler = controler |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
92 |
self.Project = project |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
93 |
# Reset the internal variables used to generate PLC programs |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
94 |
self.Program = [] |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
95 |
self.DatatypeComputed = {} |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
96 |
self.PouComputed = {} |
307
fd1f6ae26d4f
Adding support for cancelling code generation of function with no input connected
lbessard
parents:
295
diff
changeset
|
97 |
self.Errors = errors |
fd1f6ae26d4f
Adding support for cancelling code generation of function with no input connected
lbessard
parents:
295
diff
changeset
|
98 |
self.Warnings = warnings |
227
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
99 |
|
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
100 |
# Compute value according to type given |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
101 |
def ComputeValue(self, value, var_type): |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
102 |
base_type = self.Controler.GetBaseType(var_type) |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
103 |
if base_type == "STRING": |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
104 |
return "'%s'"%value |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
105 |
elif base_type == "WSTRING": |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
106 |
return "\"%s\""%value |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
107 |
return value |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
108 |
|
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
109 |
# Generate a data type from its name |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
110 |
def GenerateDataType(self, datatype_name): |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
111 |
# Verify that data type hasn't been generated yet |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
112 |
if not self.DatatypeComputed.get(datatype_name, True): |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
113 |
# If not mark data type as computed |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
114 |
self.DatatypeComputed[datatype_name] = True |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
115 |
|
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
116 |
# Getting datatype model from project |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
117 |
datatype = self.Project.getdataType(datatype_name) |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
118 |
tagname = self.Controler.ComputeDataTypeName(datatype.getname()) |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
119 |
datatype_def = [(" ", ()), |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
120 |
(datatype.getname(), (tagname, "name")), |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
121 |
(" : ", ())] |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
122 |
basetype_content = datatype.baseType.getcontent() |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
123 |
# Data type derived directly from a string type |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
124 |
if basetype_content["name"] in ["string", "wstring"]: |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
125 |
datatype_def += [(basetype_content["name"].upper(), (tagname, "base"))] |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
126 |
# Data type derived directly from a user defined type |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
127 |
elif basetype_content["name"] == "derived": |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
128 |
basetype_name = basetype_content["value"].getname() |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
129 |
self.GenerateDataType(basetype_name) |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
130 |
datatype_def += [(basetype_name, (tagname, "base"))] |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
131 |
# Data type is a subrange |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
132 |
elif basetype_content["name"] in ["subrangeSigned", "subrangeUnsigned"]: |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
133 |
base_type = basetype_content["value"].baseType.getcontent() |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
134 |
# Subrange derived directly from a user defined type |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
135 |
if base_type["name"] == "derived": |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
136 |
basetype_name = base_type["value"].getname() |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
137 |
self.GenerateDataType(basetype_name) |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
138 |
# Subrange derived directly from an elementary type |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
139 |
else: |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
140 |
basetype_name = base_type["name"] |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
141 |
min_value = basetype_content["value"].range.getlower() |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
142 |
max_value = basetype_content["value"].range.getupper() |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
143 |
datatype_def += [(basetype_name, (tagname, "base")), |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
144 |
(" (", ()), |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
145 |
("%d"%min_value, (tagname, "lower")), |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
146 |
("..", ()), |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
147 |
("%d"%max_value, (tagname, "upper")), |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
148 |
(")",())] |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
149 |
# Data type is an enumerated type |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
150 |
elif basetype_content["name"] == "enum": |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
151 |
values = [[(value.getname(), (tagname, "value", i))] |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
152 |
for i, value in enumerate(basetype_content["value"].values.getvalue())] |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
153 |
datatype_def += [("(", ())] |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
154 |
datatype_def += JoinList([(", ", ())], values) |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
155 |
datatype_def += [(")", ())] |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
156 |
# Data type is an array |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
157 |
elif basetype_content["name"] == "array": |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
158 |
base_type = basetype_content["value"].baseType.getcontent() |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
159 |
# Array derived directly from a user defined type |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
160 |
if base_type["name"] == "derived": |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
161 |
basetype_name = base_type["value"].getname() |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
162 |
self.GenerateDataType(basetype_name) |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
163 |
# Array derived directly from a string type |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
164 |
elif base_type["name"] in ["string", "wstring"]: |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
165 |
basetype_name = base_type["name"].upper() |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
166 |
# Array derived directly from an elementary type |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
167 |
else: |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
168 |
basetype_name = base_type["name"] |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
169 |
dimensions = [[("%d"%dimension.getlower(), (tagname, "range", i, "lower")), |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
170 |
("..", ()), |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
171 |
("%d"%dimension.getupper(), (tagname, "range", i, "upper"))] |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
172 |
for i, dimension in enumerate(basetype_content["value"].getdimension())] |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
173 |
datatype_def += [("ARRAY [", ())] |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
174 |
datatype_def += JoinList([(",", ())], dimensions) |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
175 |
datatype_def += [("] OF " , ()), |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
176 |
(basetype_name, (tagname, "base"))] |
295
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
281
diff
changeset
|
177 |
# Data type is a structure |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
281
diff
changeset
|
178 |
elif basetype_content["name"] == "struct": |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
281
diff
changeset
|
179 |
elements = [] |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
281
diff
changeset
|
180 |
for i, element in enumerate(basetype_content["value"].getvariable()): |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
281
diff
changeset
|
181 |
element_type = element.type.getcontent() |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
281
diff
changeset
|
182 |
# Structure element derived directly from a user defined type |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
281
diff
changeset
|
183 |
if element_type["name"] == "derived": |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
281
diff
changeset
|
184 |
elementtype_name = element_type["value"].getname() |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
281
diff
changeset
|
185 |
self.GenerateDataType(elementtype_name) |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
281
diff
changeset
|
186 |
# Structure element derived directly from a string type |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
281
diff
changeset
|
187 |
elif element_type["name"] in ["string", "wstring"]: |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
281
diff
changeset
|
188 |
elementtype_name = element_type["name"].upper() |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
281
diff
changeset
|
189 |
# Structure element derived directly from an elementary type |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
281
diff
changeset
|
190 |
else: |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
281
diff
changeset
|
191 |
elementtype_name = element_type["name"] |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
281
diff
changeset
|
192 |
element_text = [("\n ", ()), |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
281
diff
changeset
|
193 |
(element.getname(), (tagname, "struct", i, "name")), |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
281
diff
changeset
|
194 |
(" : ", ()), |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
281
diff
changeset
|
195 |
(elementtype_name, (tagname, "struct", i, "type"))] |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
281
diff
changeset
|
196 |
if element.initialValue is not None: |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
281
diff
changeset
|
197 |
element_text.extend([(" := ", ()), |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
281
diff
changeset
|
198 |
(self.ComputeValue(element.initialValue.getvalue(), elementtype_name), (tagname, "struct", i, "initial"))]) |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
281
diff
changeset
|
199 |
element_text.append((";", ())) |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
281
diff
changeset
|
200 |
elements.append(element_text) |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
281
diff
changeset
|
201 |
datatype_def += [("STRUCT", ())] |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
281
diff
changeset
|
202 |
datatype_def += JoinList([("", ())], elements) |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
281
diff
changeset
|
203 |
datatype_def += [("\n END_STRUCT", ())] |
227
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
204 |
# Data type derived directly from a elementary type |
141 | 205 |
else: |
227
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
206 |
datatype_def += [(basetype_content["name"], (tagname, "base"))] |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
207 |
# Data type has an initial value |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
208 |
if datatype.initialValue is not None: |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
209 |
datatype_def += [(" := ", ()), |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
210 |
(self.ComputeValue(datatype.initialValue.getvalue(), datatype_name), (tagname, "initial"))] |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
211 |
datatype_def += [(";\n", ())] |
295
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
281
diff
changeset
|
212 |
self.Program += datatype_def |
227
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
213 |
|
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
214 |
# Generate a POU from its name |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
215 |
def GeneratePouProgram(self, pou_name): |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
216 |
# Verify that POU hasn't been generated yet |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
217 |
if not self.PouComputed.get(pou_name, True): |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
218 |
# If not mark POU as computed |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
219 |
self.PouComputed[pou_name] = True |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
220 |
|
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
221 |
# Getting POU model from project |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
222 |
pou = self.Project.getpou(pou_name) |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
223 |
pou_type = pou.getpouType() |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
224 |
# Verify that POU type exists |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
225 |
if pou_type in pouTypeNames: |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
226 |
# Create a POU program generator |
307
fd1f6ae26d4f
Adding support for cancelling code generation of function with no input connected
lbessard
parents:
295
diff
changeset
|
227 |
pou_program = PouProgramGenerator(self, pou.getname(), pouTypeNames[pou_type], self.Errors, self.Warnings) |
227
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
228 |
program = pou_program.GenerateProgram(pou) |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
229 |
self.Program += program |
141 | 230 |
else: |
227
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
231 |
raise PLCGenException, "Undefined pou type \"%s\""%pou_type |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
232 |
|
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
233 |
# Generate a configuration from its model |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
234 |
def GenerateConfiguration(self, configuration): |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
235 |
tagname = self.Controler.ComputeConfigurationName(configuration.getname()) |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
236 |
config = [("\nCONFIGURATION ", ()), |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
237 |
(configuration.getname(), (tagname, "name")), |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
238 |
("\n", ())] |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
239 |
var_number = 0 |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
240 |
# Generate any global variable in configuration |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
241 |
for varlist in configuration.getglobalVars(): |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
242 |
# Generate variable block with modifier |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
243 |
config += [(" VAR_GLOBAL", ())] |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
244 |
if varlist.getretain(): |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
245 |
config += [(" RETAIN", (tagname, "variable", (var_number, var_number + len(varlist.getvariable())), "retain"))] |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
246 |
if varlist.getconstant(): |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
247 |
config += [(" CONSTANT", (tagname, "variable", (var_number, var_number + len(varlist.getvariable())), "constant"))] |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
248 |
config += [("\n", ())] |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
249 |
# Generate any variable of this block |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
250 |
for var in varlist.getvariable(): |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
251 |
vartype_content = var.gettype().getcontent() |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
252 |
# Variable type is a user data type |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
253 |
if vartype_content["name"] == "derived": |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
254 |
var_type = vartype_content["value"].getname() |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
255 |
# Variable type is a string type |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
256 |
elif vartype_content["name"] in ["string", "wstring"]: |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
257 |
var_type = vartype_content["name"].upper() |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
258 |
# Variable type is an elementary type |
78
049f2e7090a2
Adding support for adding block types with particular behaviour
lbessard
parents:
72
diff
changeset
|
259 |
else: |
227
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
260 |
var_type = vartype_content["name"] |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
261 |
config += [(" ", ()), |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
262 |
(var.getname(), (tagname, "variable", var_number, "name")), |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
263 |
(" ", ())] |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
264 |
# Generate variable address if exists |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
265 |
address = var.getaddress() |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
266 |
if address: |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
267 |
config += [("AT ", ()), |
232 | 268 |
(address, (tagname, "variable", var_number, "address")), |
227
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
269 |
(" ", ())] |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
270 |
config += [(": ", ()), |
232 | 271 |
(var_type, (tagname, "variable", var_number, "type"))] |
227
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
272 |
# Generate variable initial value if exists |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
273 |
initial = var.getinitialValue() |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
274 |
if initial: |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
275 |
config += [(" := ", ()), |
232 | 276 |
(self.ComputeValue(initial.getvalue(), var_type), (tagname, "variable", var_number, "initial"))] |
227
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
277 |
config += [(";\n", ())] |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
278 |
var_number += 1 |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
279 |
config += [(" END_VAR\n", ())] |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
280 |
# Generate any resource in the configuration |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
281 |
for resource in configuration.getresource(): |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
282 |
config += self.GenerateResource(resource, configuration.getname()) |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
283 |
config += [("END_CONFIGURATION\n", ())] |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
284 |
return config |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
285 |
|
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
286 |
# Generate a resource from its model |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
287 |
def GenerateResource(self, resource, config_name): |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
288 |
tagname = self.Controler.ComputeConfigurationResourceName(config_name, resource.getname()) |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
289 |
resrce = [("\n RESOURCE ", ()), |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
290 |
(resource.getname(), (tagname, "name")), |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
291 |
(" ON PLC\n", ())] |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
292 |
var_number = 0 |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
293 |
# Generate any global variable in configuration |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
294 |
for varlist in resource.getglobalVars(): |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
295 |
# Generate variable block with modifier |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
296 |
resrce += [(" VAR_GLOBAL", ())] |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
297 |
if varlist.getretain(): |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
298 |
resrce += [(" RETAIN", (tagname, "variable", (var_number, var_number + len(varlist.getvariable())), "retain"))] |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
299 |
if varlist.getconstant(): |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
300 |
resrce += [(" CONSTANT", (tagname, "variable", (var_number, var_number + len(varlist.getvariable())), "constant"))] |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
301 |
resrce += "\n" |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
302 |
# Generate any variable of this block |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
303 |
for var in varlist.getvariable(): |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
304 |
vartype_content = var.gettype().getcontent() |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
305 |
# Variable type is a user data type |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
306 |
if vartype_content["name"] == "derived": |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
307 |
var_type = vartype_content["value"].getname() |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
308 |
# Variable type is a string type |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
309 |
elif vartype_content["name"] in ["string", "wstring"]: |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
310 |
var_type = vartype_content["name"].upper() |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
311 |
# Variable type is an elementary type |
78
049f2e7090a2
Adding support for adding block types with particular behaviour
lbessard
parents:
72
diff
changeset
|
312 |
else: |
227
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
313 |
var_type = vartype_content["name"] |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
314 |
resrce += [(" ", ()), |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
315 |
(var.getname(), (tagname, "variable", var_number, "name")), |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
316 |
(" ", ())] |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
317 |
address = var.getaddress() |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
318 |
# Generate variable address if exists |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
319 |
if address: |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
320 |
resrce += [("AT ", ()), |
232 | 321 |
(address, (tagname, "variable", var_number, "address")), |
227
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
322 |
(" ", ())] |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
323 |
resrce += [(": ", ()), |
232 | 324 |
(var_type, (tagname, "variable", var_number, "type"))] |
227
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
325 |
# Generate variable initial value if exists |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
326 |
initial = var.getinitialValue() |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
327 |
if initial: |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
328 |
resrce += [(" := ", ()), |
232 | 329 |
(self.ComputeValue(initial.getvalue(), var_type), (tagname, "variable", var_number, "initial"))] |
227
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
330 |
resrce += [(";\n", ())] |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
331 |
var_number += 1 |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
332 |
resrce += [(" END_VAR\n", ())] |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
333 |
# Generate any task in the resource |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
334 |
tasks = resource.gettask() |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
335 |
task_number = 0 |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
336 |
for task in tasks: |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
337 |
# Task declaration |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
338 |
resrce += [(" TASK ", ()), |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
339 |
(task.getname(), (tagname, "task", task_number, "name")), |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
340 |
("(", ())] |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
341 |
args = [] |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
342 |
single = task.getsingle() |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
343 |
# Single argument if exists |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
344 |
if single: |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
345 |
resrce += [("SINGLE := ", ()), |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
346 |
(single, (tagname, "task", task_number, "single")), |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
347 |
(",", ())] |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
348 |
# Interval argument if exists |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
349 |
interval = task.getinterval() |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
350 |
if interval: |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
351 |
resrce += [("INTERVAL := t#", ())] |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
352 |
if interval.hour != 0: |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
353 |
resrce += [("%dh"%interval.hour, (tagname, "task", task_number, "interval", "hour"))] |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
354 |
if interval.minute != 0: |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
355 |
resrce += [("%dm"%interval.minute, (tagname, "task", task_number, "interval", "minute"))] |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
356 |
if interval.second != 0: |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
357 |
resrce += [("%ds"%interval.second, (tagname, "task", task_number, "interval", "second"))] |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
358 |
if interval.microsecond != 0: |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
359 |
resrce += [("%dms"%(interval.microsecond / 1000), (tagname, "task", task_number, "interval", "millisecond"))] |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
360 |
resrce += [(",", ())] |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
361 |
# Priority argument |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
362 |
resrce += [("PRIORITY := ", ()), |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
363 |
("%d"%task.getpriority(), (tagname, "task", task_number, "priority")), |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
364 |
(");\n", ())] |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
365 |
task_number += 1 |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
366 |
instance_number = 0 |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
367 |
# Generate any program assign to each task |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
368 |
for task in tasks: |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
369 |
for instance in task.getpouInstance(): |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
370 |
resrce += [(" PROGRAM ", ()), |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
371 |
(instance.getname(), (tagname, "instance", instance_number, "name")), |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
372 |
(" WITH ", ()), |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
373 |
(task.getname(), (tagname, "instance", instance_number, "task")), |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
374 |
(" : ", ()), |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
375 |
(instance.gettype(), (tagname, "instance", instance_number, "type")), |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
376 |
(";\n", ())] |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
377 |
instance_number += 1 |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
378 |
# Generate any program assign to no task |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
379 |
for instance in resource.getpouInstance(): |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
380 |
resrce += [(" PROGRAM ", ()), |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
381 |
(instance.getname(), (tagname, "instance", instance_number, "name")), |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
382 |
(" : ", ()), |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
383 |
(instance.gettype(), (tagname, "instance", instance_number, "type")), |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
384 |
(";\n", ())] |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
385 |
instance_number += 1 |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
386 |
resrce += [(" END_RESOURCE\n", ())] |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
387 |
return resrce |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
388 |
|
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
389 |
# Generate the entire program for current project |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
390 |
def GenerateProgram(self): |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
391 |
# Find all data types defined |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
392 |
for datatype in self.Project.getdataTypes(): |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
393 |
self.DatatypeComputed[datatype.getname()] = False |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
394 |
# Find all data types defined |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
395 |
for pou in self.Project.getpous(): |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
396 |
self.PouComputed[pou.getname()] = False |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
397 |
# Generate data type declaration structure if there is at least one data |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
398 |
# type defined |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
399 |
if len(self.DatatypeComputed) > 0: |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
400 |
self.Program += [("TYPE\n", ())] |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
401 |
# Generate every data types defined |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
402 |
for datatype_name in self.DatatypeComputed.keys(): |
295
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
281
diff
changeset
|
403 |
self.GenerateDataType(datatype_name) |
227
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
404 |
self.Program += [("END_TYPE\n\n", ())] |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
405 |
# Generate every POUs defined |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
406 |
for pou_name in self.PouComputed.keys(): |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
407 |
self.GeneratePouProgram(pou_name) |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
408 |
# Generate every configurations defined |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
409 |
for config in self.Project.getconfigurations(): |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
410 |
self.Program += self.GenerateConfiguration(config) |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
411 |
|
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
412 |
# Return generated program |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
413 |
def GetGeneratedProgram(self): |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
414 |
return self.Program |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
415 |
|
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
416 |
|
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
417 |
#------------------------------------------------------------------------------- |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
418 |
# Generator of POU programs |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
419 |
#------------------------------------------------------------------------------- |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
420 |
|
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
421 |
|
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
422 |
class PouProgramGenerator: |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
423 |
|
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
424 |
# Create a new POU program generator |
307
fd1f6ae26d4f
Adding support for cancelling code generation of function with no input connected
lbessard
parents:
295
diff
changeset
|
425 |
def __init__(self, parent, name, type, errors, warnings): |
227
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
426 |
# Keep Reference to the parent generator |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
427 |
self.ParentGenerator = parent |
0 | 428 |
self.Name = name |
429 |
self.Type = type |
|
227
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
430 |
self.TagName = self.ParentGenerator.Controler.ComputePouName(name) |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
431 |
self.CurrentIndent = " " |
1 | 432 |
self.ReturnType = None |
433 |
self.Interface = [] |
|
434 |
self.InitialSteps = [] |
|
72
73212220ad22
Adding support for generating FBD with connectors and continuations
lbessard
parents:
71
diff
changeset
|
435 |
self.ComputedBlocks = {} |
73212220ad22
Adding support for generating FBD with connectors and continuations
lbessard
parents:
71
diff
changeset
|
436 |
self.ComputedConnectors = {} |
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
108
diff
changeset
|
437 |
self.ConnectionTypes = {} |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
108
diff
changeset
|
438 |
self.RelatedConnections = [] |
1 | 439 |
self.SFCNetworks = {"Steps":{}, "Transitions":{}, "Actions":{}} |
227
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
440 |
self.SFCComputedBlocks = [] |
46 | 441 |
self.ActionNumber = 0 |
227
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
442 |
self.Program = [] |
307
fd1f6ae26d4f
Adding support for cancelling code generation of function with no input connected
lbessard
parents:
295
diff
changeset
|
443 |
self.Errors = errors |
fd1f6ae26d4f
Adding support for cancelling code generation of function with no input connected
lbessard
parents:
295
diff
changeset
|
444 |
self.Warnings = warnings |
227
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
445 |
|
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
446 |
def GetBlockType(self, type): |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
447 |
return self.ParentGenerator.Controler.GetBlockType(type) |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
448 |
|
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
449 |
def IndentLeft(self): |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
450 |
if len(self.CurrentIndent) >= 2: |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
451 |
self.CurrentIndent = self.CurrentIndent[:-2] |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
452 |
|
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
453 |
def IndentRight(self): |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
454 |
self.CurrentIndent += " " |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
455 |
|
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
456 |
# Generator of unique ID for inline actions |
46 | 457 |
def GetActionNumber(self): |
458 |
self.ActionNumber += 1 |
|
459 |
return self.ActionNumber |
|
460 |
||
227
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
461 |
# Test if a variable has already been defined |
1 | 462 |
def IsAlreadyDefined(self, name): |
33 | 463 |
for list_type, retain, constant, located, vars in self.Interface: |
30 | 464 |
for var_type, var_name, var_address, var_initial in vars: |
1 | 465 |
if name == var_name: |
466 |
return True |
|
467 |
return False |
|
468 |
||
227
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
469 |
# Return the type of a variable defined in interface |
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
108
diff
changeset
|
470 |
def GetVariableType(self, name): |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
108
diff
changeset
|
471 |
for list_type, retain, constant, located, vars in self.Interface: |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
108
diff
changeset
|
472 |
for var_type, var_name, var_address, var_initial in vars: |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
108
diff
changeset
|
473 |
if name == var_name: |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
108
diff
changeset
|
474 |
return var_type |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
108
diff
changeset
|
475 |
return None |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
108
diff
changeset
|
476 |
|
227
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
477 |
# Return connectors linked by a connection to the given connector |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
478 |
def GetConnectedConnector(self, connector, body): |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
479 |
links = connector.getconnections() |
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
108
diff
changeset
|
480 |
if links and len(links) == 1: |
227
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
481 |
return self.GetLinkedConnector(links[0], body) |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
482 |
return None |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
483 |
|
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
484 |
def GetLinkedConnector(self, link, body): |
151 | 485 |
parameter = link.getformalParameter() |
486 |
instance = body.getcontentInstance(link.getrefLocalId()) |
|
487 |
if isinstance(instance, (plcopen.fbdObjects_inVariable, plcopen.fbdObjects_inOutVariable, plcopen.commonObjects_continuation, plcopen.ldObjects_contact, plcopen.ldObjects_coil)): |
|
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
108
diff
changeset
|
488 |
return instance.connectionPointOut |
151 | 489 |
elif isinstance(instance, plcopen.fbdObjects_block): |
490 |
outputvariables = instance.outputVariables.getvariable() |
|
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
108
diff
changeset
|
491 |
if len(outputvariables) == 1: |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
108
diff
changeset
|
492 |
return outputvariables[0].connectionPointOut |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
108
diff
changeset
|
493 |
elif parameter: |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
108
diff
changeset
|
494 |
for variable in outputvariables: |
151 | 495 |
if variable.getformalParameter() == parameter: |
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
108
diff
changeset
|
496 |
return variable.connectionPointOut |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
108
diff
changeset
|
497 |
else: |
276 | 498 |
point = link.getposition()[-1] |
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
108
diff
changeset
|
499 |
for variable in outputvariables: |
151 | 500 |
relposition = variable.connectionPointOut.getrelPositionXY() |
501 |
blockposition = instance.getposition() |
|
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
108
diff
changeset
|
502 |
if point.x == blockposition.x + relposition[0] and point.y == blockposition.y + relposition[1]: |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
108
diff
changeset
|
503 |
return variable.connectionPointOut |
151 | 504 |
elif isinstance(instance, plcopen.ldObjects_leftPowerRail): |
505 |
outputconnections = instance.getconnectionPointOut() |
|
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
108
diff
changeset
|
506 |
if len(outputconnections) == 1: |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
108
diff
changeset
|
507 |
return outputconnections[0] |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
108
diff
changeset
|
508 |
else: |
151 | 509 |
point = link.getposition()[-1] |
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
108
diff
changeset
|
510 |
for outputconnection in outputconnections: |
151 | 511 |
relposition = outputconnection.getrelPositionXY() |
512 |
powerrailposition = instance.getposition() |
|
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
108
diff
changeset
|
513 |
if point.x == powerrailposition.x + relposition[0] and point.y == powerrailposition.y + relposition[1]: |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
108
diff
changeset
|
514 |
return outputconnection |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
108
diff
changeset
|
515 |
return None |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
108
diff
changeset
|
516 |
|
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
108
diff
changeset
|
517 |
def ExtractRelatedConnections(self, connection): |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
108
diff
changeset
|
518 |
for i, related in enumerate(self.RelatedConnections): |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
108
diff
changeset
|
519 |
if connection in related: |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
108
diff
changeset
|
520 |
return self.RelatedConnections.pop(i) |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
108
diff
changeset
|
521 |
return [connection] |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
108
diff
changeset
|
522 |
|
227
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
523 |
def ComputeInterface(self, pou): |
194
1b3f8b4f8e04
Adding support for Beremiz svgui plugin variable declaration
lbessard
parents:
191
diff
changeset
|
524 |
interface = pou.getinterface() |
1b3f8b4f8e04
Adding support for Beremiz svgui plugin variable declaration
lbessard
parents:
191
diff
changeset
|
525 |
if interface is not None: |
1b3f8b4f8e04
Adding support for Beremiz svgui plugin variable declaration
lbessard
parents:
191
diff
changeset
|
526 |
body = pou.getbody() |
1b3f8b4f8e04
Adding support for Beremiz svgui plugin variable declaration
lbessard
parents:
191
diff
changeset
|
527 |
body_content = body.getcontent() |
1b3f8b4f8e04
Adding support for Beremiz svgui plugin variable declaration
lbessard
parents:
191
diff
changeset
|
528 |
if self.Type == "FUNCTION": |
1b3f8b4f8e04
Adding support for Beremiz svgui plugin variable declaration
lbessard
parents:
191
diff
changeset
|
529 |
returntype_content = interface.getreturnType().getcontent() |
227
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
530 |
if returntype_content["name"] == "derived": |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
531 |
self.ReturnType = returntype_content["value"].getname() |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
532 |
elif returntype_content["name"] in ["string", "wstring"]: |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
533 |
self.ReturnType = returntype_content["name"].upper() |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
534 |
else: |
194
1b3f8b4f8e04
Adding support for Beremiz svgui plugin variable declaration
lbessard
parents:
191
diff
changeset
|
535 |
self.ReturnType = returntype_content["name"] |
1b3f8b4f8e04
Adding support for Beremiz svgui plugin variable declaration
lbessard
parents:
191
diff
changeset
|
536 |
for varlist in interface.getcontent(): |
1b3f8b4f8e04
Adding support for Beremiz svgui plugin variable declaration
lbessard
parents:
191
diff
changeset
|
537 |
variables = [] |
1b3f8b4f8e04
Adding support for Beremiz svgui plugin variable declaration
lbessard
parents:
191
diff
changeset
|
538 |
located = [] |
1b3f8b4f8e04
Adding support for Beremiz svgui plugin variable declaration
lbessard
parents:
191
diff
changeset
|
539 |
for var in varlist["value"].getvariable(): |
1b3f8b4f8e04
Adding support for Beremiz svgui plugin variable declaration
lbessard
parents:
191
diff
changeset
|
540 |
vartype_content = var.gettype().getcontent() |
1b3f8b4f8e04
Adding support for Beremiz svgui plugin variable declaration
lbessard
parents:
191
diff
changeset
|
541 |
if vartype_content["name"] == "derived": |
1b3f8b4f8e04
Adding support for Beremiz svgui plugin variable declaration
lbessard
parents:
191
diff
changeset
|
542 |
var_type = vartype_content["value"].getname() |
227
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
543 |
blocktype = self.GetBlockType(var_type) |
194
1b3f8b4f8e04
Adding support for Beremiz svgui plugin variable declaration
lbessard
parents:
191
diff
changeset
|
544 |
if blocktype is not None: |
227
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
545 |
self.ParentGenerator.GeneratePouProgram(var_type) |
194
1b3f8b4f8e04
Adding support for Beremiz svgui plugin variable declaration
lbessard
parents:
191
diff
changeset
|
546 |
if body_content["name"] in ["FBD", "LD", "SFC"]: |
1b3f8b4f8e04
Adding support for Beremiz svgui plugin variable declaration
lbessard
parents:
191
diff
changeset
|
547 |
block = pou.getinstanceByName(var.getname()) |
191
d77f9b783ce8
Bug with located variables generated by Beremiz svgui plugin fixed
lbessard
parents:
189
diff
changeset
|
548 |
else: |
194
1b3f8b4f8e04
Adding support for Beremiz svgui plugin variable declaration
lbessard
parents:
191
diff
changeset
|
549 |
block = None |
1b3f8b4f8e04
Adding support for Beremiz svgui plugin variable declaration
lbessard
parents:
191
diff
changeset
|
550 |
for variable in blocktype["initialise"](var_type, var.getname(), block): |
1b3f8b4f8e04
Adding support for Beremiz svgui plugin variable declaration
lbessard
parents:
191
diff
changeset
|
551 |
if variable[2] is not None: |
1b3f8b4f8e04
Adding support for Beremiz svgui plugin variable declaration
lbessard
parents:
191
diff
changeset
|
552 |
located.append(variable) |
1b3f8b4f8e04
Adding support for Beremiz svgui plugin variable declaration
lbessard
parents:
191
diff
changeset
|
553 |
else: |
1b3f8b4f8e04
Adding support for Beremiz svgui plugin variable declaration
lbessard
parents:
191
diff
changeset
|
554 |
variables.append(variable) |
1b3f8b4f8e04
Adding support for Beremiz svgui plugin variable declaration
lbessard
parents:
191
diff
changeset
|
555 |
else: |
1b3f8b4f8e04
Adding support for Beremiz svgui plugin variable declaration
lbessard
parents:
191
diff
changeset
|
556 |
initial = var.getinitialValue() |
1b3f8b4f8e04
Adding support for Beremiz svgui plugin variable declaration
lbessard
parents:
191
diff
changeset
|
557 |
if initial: |
1b3f8b4f8e04
Adding support for Beremiz svgui plugin variable declaration
lbessard
parents:
191
diff
changeset
|
558 |
initial_value = initial.getvalue() |
1b3f8b4f8e04
Adding support for Beremiz svgui plugin variable declaration
lbessard
parents:
191
diff
changeset
|
559 |
else: |
1b3f8b4f8e04
Adding support for Beremiz svgui plugin variable declaration
lbessard
parents:
191
diff
changeset
|
560 |
initial_value = None |
1b3f8b4f8e04
Adding support for Beremiz svgui plugin variable declaration
lbessard
parents:
191
diff
changeset
|
561 |
address = var.getaddress() |
1b3f8b4f8e04
Adding support for Beremiz svgui plugin variable declaration
lbessard
parents:
191
diff
changeset
|
562 |
if address is not None: |
1b3f8b4f8e04
Adding support for Beremiz svgui plugin variable declaration
lbessard
parents:
191
diff
changeset
|
563 |
located.append((vartype_content["value"].getname(), var.getname(), address, initial_value)) |
1b3f8b4f8e04
Adding support for Beremiz svgui plugin variable declaration
lbessard
parents:
191
diff
changeset
|
564 |
else: |
1b3f8b4f8e04
Adding support for Beremiz svgui plugin variable declaration
lbessard
parents:
191
diff
changeset
|
565 |
variables.append((vartype_content["value"].getname(), var.getname(), None, initial_value)) |
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
108
diff
changeset
|
566 |
else: |
151 | 567 |
initial = var.getinitialValue() |
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
108
diff
changeset
|
568 |
if initial: |
151 | 569 |
initial_value = initial.getvalue() |
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
108
diff
changeset
|
570 |
else: |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
108
diff
changeset
|
571 |
initial_value = None |
151 | 572 |
address = var.getaddress() |
194
1b3f8b4f8e04
Adding support for Beremiz svgui plugin variable declaration
lbessard
parents:
191
diff
changeset
|
573 |
if vartype_content["name"] in ["string", "wstring"]: |
1b3f8b4f8e04
Adding support for Beremiz svgui plugin variable declaration
lbessard
parents:
191
diff
changeset
|
574 |
if address is not None: |
1b3f8b4f8e04
Adding support for Beremiz svgui plugin variable declaration
lbessard
parents:
191
diff
changeset
|
575 |
located.append((vartype_content["name"].upper(), var.getname(), address, initial_value)) |
1b3f8b4f8e04
Adding support for Beremiz svgui plugin variable declaration
lbessard
parents:
191
diff
changeset
|
576 |
else: |
1b3f8b4f8e04
Adding support for Beremiz svgui plugin variable declaration
lbessard
parents:
191
diff
changeset
|
577 |
variables.append((vartype_content["name"].upper(), var.getname(), None, initial_value)) |
1b3f8b4f8e04
Adding support for Beremiz svgui plugin variable declaration
lbessard
parents:
191
diff
changeset
|
578 |
elif address is not None: |
1b3f8b4f8e04
Adding support for Beremiz svgui plugin variable declaration
lbessard
parents:
191
diff
changeset
|
579 |
located.append((vartype_content["name"], var.getname(), address, initial_value)) |
191
d77f9b783ce8
Bug with located variables generated by Beremiz svgui plugin fixed
lbessard
parents:
189
diff
changeset
|
580 |
else: |
194
1b3f8b4f8e04
Adding support for Beremiz svgui plugin variable declaration
lbessard
parents:
191
diff
changeset
|
581 |
variables.append((vartype_content["name"], var.getname(), None, initial_value)) |
1b3f8b4f8e04
Adding support for Beremiz svgui plugin variable declaration
lbessard
parents:
191
diff
changeset
|
582 |
if len(variables) > 0: |
1b3f8b4f8e04
Adding support for Beremiz svgui plugin variable declaration
lbessard
parents:
191
diff
changeset
|
583 |
self.Interface.append((varTypeNames[varlist["name"]], varlist["value"].getretain(), |
1b3f8b4f8e04
Adding support for Beremiz svgui plugin variable declaration
lbessard
parents:
191
diff
changeset
|
584 |
varlist["value"].getconstant(), False, variables)) |
1b3f8b4f8e04
Adding support for Beremiz svgui plugin variable declaration
lbessard
parents:
191
diff
changeset
|
585 |
if len(located) > 0: |
1b3f8b4f8e04
Adding support for Beremiz svgui plugin variable declaration
lbessard
parents:
191
diff
changeset
|
586 |
self.Interface.append((varTypeNames[varlist["name"]], varlist["value"].getretain(), |
1b3f8b4f8e04
Adding support for Beremiz svgui plugin variable declaration
lbessard
parents:
191
diff
changeset
|
587 |
varlist["value"].getconstant(), True, located)) |
191
d77f9b783ce8
Bug with located variables generated by Beremiz svgui plugin fixed
lbessard
parents:
189
diff
changeset
|
588 |
|
227
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
589 |
def ComputeConnectionTypes(self, pou): |
151 | 590 |
body = pou.getbody() |
591 |
body_content = body.getcontent() |
|
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
108
diff
changeset
|
592 |
body_type = body_content["name"] |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
108
diff
changeset
|
593 |
if body_type in ["FBD", "LD", "SFC"]: |
151 | 594 |
for instance in body.getcontentInstances(): |
595 |
if isinstance(instance, (plcopen.fbdObjects_inVariable, plcopen.fbdObjects_outVariable, plcopen.fbdObjects_inOutVariable)): |
|
596 |
expression = instance.getexpression() |
|
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
108
diff
changeset
|
597 |
var_type = self.GetVariableType(expression) |
151 | 598 |
if expression == pou.getname(): |
599 |
returntype_content = pou.interface.getreturnType().getcontent() |
|
141 | 600 |
if returntype_content["name"] == "derived": |
151 | 601 |
var_type = returntype_content["value"].getname() |
141 | 602 |
elif returntype_content["name"] in ["string", "wstring"]: |
603 |
var_type = returntype_content["name"].upper() |
|
604 |
else: |
|
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
108
diff
changeset
|
605 |
var_type = returntype_content["name"] |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
108
diff
changeset
|
606 |
elif var_type is None: |
269
34eff05909b0
Adding support for EN/ENO variables (temporarily disabled, waiting for matiec support)
lbessard
parents:
261
diff
changeset
|
607 |
parts = expression.split("#") |
34eff05909b0
Adding support for EN/ENO variables (temporarily disabled, waiting for matiec support)
lbessard
parents:
261
diff
changeset
|
608 |
if len(parts) > 1: |
34eff05909b0
Adding support for EN/ENO variables (temporarily disabled, waiting for matiec support)
lbessard
parents:
261
diff
changeset
|
609 |
var_type = parts[0] |
34eff05909b0
Adding support for EN/ENO variables (temporarily disabled, waiting for matiec support)
lbessard
parents:
261
diff
changeset
|
610 |
if var_type is not None: |
34eff05909b0
Adding support for EN/ENO variables (temporarily disabled, waiting for matiec support)
lbessard
parents:
261
diff
changeset
|
611 |
if isinstance(instance, (plcopen.fbdObjects_inVariable, plcopen.fbdObjects_inOutVariable)): |
34eff05909b0
Adding support for EN/ENO variables (temporarily disabled, waiting for matiec support)
lbessard
parents:
261
diff
changeset
|
612 |
for connection in self.ExtractRelatedConnections(instance.connectionPointOut): |
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
108
diff
changeset
|
613 |
self.ConnectionTypes[connection] = var_type |
269
34eff05909b0
Adding support for EN/ENO variables (temporarily disabled, waiting for matiec support)
lbessard
parents:
261
diff
changeset
|
614 |
if isinstance(instance, (plcopen.fbdObjects_outVariable, plcopen.fbdObjects_inOutVariable)): |
34eff05909b0
Adding support for EN/ENO variables (temporarily disabled, waiting for matiec support)
lbessard
parents:
261
diff
changeset
|
615 |
self.ConnectionTypes[instance.connectionPointIn] = var_type |
34eff05909b0
Adding support for EN/ENO variables (temporarily disabled, waiting for matiec support)
lbessard
parents:
261
diff
changeset
|
616 |
connected = self.GetConnectedConnector(instance.connectionPointIn, body) |
34eff05909b0
Adding support for EN/ENO variables (temporarily disabled, waiting for matiec support)
lbessard
parents:
261
diff
changeset
|
617 |
if connected and connected not in self.ConnectionTypes: |
34eff05909b0
Adding support for EN/ENO variables (temporarily disabled, waiting for matiec support)
lbessard
parents:
261
diff
changeset
|
618 |
for connection in self.ExtractRelatedConnections(connected): |
34eff05909b0
Adding support for EN/ENO variables (temporarily disabled, waiting for matiec support)
lbessard
parents:
261
diff
changeset
|
619 |
self.ConnectionTypes[connection] = var_type |
151 | 620 |
elif isinstance(instance, (plcopen.ldObjects_contact, plcopen.ldObjects_coil)): |
208
c70aefcadf66
Bugs with feedback path in View, Controler and Generator fixed
lbessard
parents:
207
diff
changeset
|
621 |
for connection in self.ExtractRelatedConnections(instance.connectionPointOut): |
c70aefcadf66
Bugs with feedback path in View, Controler and Generator fixed
lbessard
parents:
207
diff
changeset
|
622 |
self.ConnectionTypes[connection] = "BOOL" |
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
108
diff
changeset
|
623 |
self.ConnectionTypes[instance.connectionPointIn] = "BOOL" |
227
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
624 |
connected = self.GetConnectedConnector(instance.connectionPointIn, body) |
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
108
diff
changeset
|
625 |
if connected and connected not in self.ConnectionTypes: |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
108
diff
changeset
|
626 |
for connection in self.ExtractRelatedConnections(connected): |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
108
diff
changeset
|
627 |
self.ConnectionTypes[connection] = "BOOL" |
151 | 628 |
elif isinstance(instance, plcopen.ldObjects_leftPowerRail): |
629 |
for connection in instance.getconnectionPointOut(): |
|
208
c70aefcadf66
Bugs with feedback path in View, Controler and Generator fixed
lbessard
parents:
207
diff
changeset
|
630 |
for related in self.ExtractRelatedConnections(connection): |
c70aefcadf66
Bugs with feedback path in View, Controler and Generator fixed
lbessard
parents:
207
diff
changeset
|
631 |
self.ConnectionTypes[related] = "BOOL" |
151 | 632 |
elif isinstance(instance, plcopen.ldObjects_rightPowerRail): |
633 |
for connection in instance.getconnectionPointIn(): |
|
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
108
diff
changeset
|
634 |
self.ConnectionTypes[connection] = "BOOL" |
227
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
635 |
connected = self.GetConnectedConnector(connection, body) |
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
108
diff
changeset
|
636 |
if connected and connected not in self.ConnectionTypes: |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
108
diff
changeset
|
637 |
for connection in self.ExtractRelatedConnections(connected): |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
108
diff
changeset
|
638 |
self.ConnectionTypes[connection] = "BOOL" |
151 | 639 |
elif isinstance(instance, plcopen.sfcObjects_transition): |
640 |
content = instance.condition.getcontent() |
|
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
108
diff
changeset
|
641 |
if content["name"] == "connection" and len(content["value"]) == 1: |
227
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
642 |
connected = self.GetLinkedConnector(content["value"][0], body) |
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
108
diff
changeset
|
643 |
if connected and connected not in self.ConnectionTypes: |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
108
diff
changeset
|
644 |
for connection in self.ExtractRelatedConnections(connected): |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
108
diff
changeset
|
645 |
self.ConnectionTypes[connection] = "BOOL" |
151 | 646 |
elif isinstance(instance, plcopen.fbdObjects_block): |
227
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
647 |
block_infos = self.GetBlockType(instance.gettypeName()) |
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
108
diff
changeset
|
648 |
undefined = {} |
151 | 649 |
for variable in instance.outputVariables.getvariable(): |
650 |
output_name = variable.getformalParameter() |
|
269
34eff05909b0
Adding support for EN/ENO variables (temporarily disabled, waiting for matiec support)
lbessard
parents:
261
diff
changeset
|
651 |
if output_name == "ENO": |
34eff05909b0
Adding support for EN/ENO variables (temporarily disabled, waiting for matiec support)
lbessard
parents:
261
diff
changeset
|
652 |
for connection in self.ExtractRelatedConnections(variable.connectionPointOut): |
34eff05909b0
Adding support for EN/ENO variables (temporarily disabled, waiting for matiec support)
lbessard
parents:
261
diff
changeset
|
653 |
self.ConnectionTypes[connection] = "BOOL" |
34eff05909b0
Adding support for EN/ENO variables (temporarily disabled, waiting for matiec support)
lbessard
parents:
261
diff
changeset
|
654 |
else: |
34eff05909b0
Adding support for EN/ENO variables (temporarily disabled, waiting for matiec support)
lbessard
parents:
261
diff
changeset
|
655 |
for oname, otype, oqualifier in block_infos["outputs"]: |
34eff05909b0
Adding support for EN/ENO variables (temporarily disabled, waiting for matiec support)
lbessard
parents:
261
diff
changeset
|
656 |
if output_name == oname and variable.connectionPointOut not in self.ConnectionTypes: |
34eff05909b0
Adding support for EN/ENO variables (temporarily disabled, waiting for matiec support)
lbessard
parents:
261
diff
changeset
|
657 |
if otype.startswith("ANY"): |
34eff05909b0
Adding support for EN/ENO variables (temporarily disabled, waiting for matiec support)
lbessard
parents:
261
diff
changeset
|
658 |
if otype not in undefined: |
34eff05909b0
Adding support for EN/ENO variables (temporarily disabled, waiting for matiec support)
lbessard
parents:
261
diff
changeset
|
659 |
undefined[otype] = [] |
34eff05909b0
Adding support for EN/ENO variables (temporarily disabled, waiting for matiec support)
lbessard
parents:
261
diff
changeset
|
660 |
undefined[otype].append(variable.connectionPointOut) |
34eff05909b0
Adding support for EN/ENO variables (temporarily disabled, waiting for matiec support)
lbessard
parents:
261
diff
changeset
|
661 |
else: |
34eff05909b0
Adding support for EN/ENO variables (temporarily disabled, waiting for matiec support)
lbessard
parents:
261
diff
changeset
|
662 |
for connection in self.ExtractRelatedConnections(variable.connectionPointOut): |
34eff05909b0
Adding support for EN/ENO variables (temporarily disabled, waiting for matiec support)
lbessard
parents:
261
diff
changeset
|
663 |
self.ConnectionTypes[connection] = otype |
151 | 664 |
for variable in instance.inputVariables.getvariable(): |
665 |
input_name = variable.getformalParameter() |
|
269
34eff05909b0
Adding support for EN/ENO variables (temporarily disabled, waiting for matiec support)
lbessard
parents:
261
diff
changeset
|
666 |
if input_name == "EN": |
34eff05909b0
Adding support for EN/ENO variables (temporarily disabled, waiting for matiec support)
lbessard
parents:
261
diff
changeset
|
667 |
for connection in self.ExtractRelatedConnections(variable.connectionPointIn): |
34eff05909b0
Adding support for EN/ENO variables (temporarily disabled, waiting for matiec support)
lbessard
parents:
261
diff
changeset
|
668 |
self.ConnectionTypes[connection] = "BOOL" |
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
108
diff
changeset
|
669 |
for iname, itype, iqualifier in block_infos["inputs"]: |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
108
diff
changeset
|
670 |
if input_name == iname: |
227
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
671 |
connected = self.GetConnectedConnector(variable.connectionPointIn, body) |
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
108
diff
changeset
|
672 |
if itype.startswith("ANY"): |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
108
diff
changeset
|
673 |
if itype not in undefined: |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
108
diff
changeset
|
674 |
undefined[itype] = [] |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
108
diff
changeset
|
675 |
undefined[itype].append(variable.connectionPointIn) |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
108
diff
changeset
|
676 |
if connected: |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
108
diff
changeset
|
677 |
undefined[itype].append(connected) |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
108
diff
changeset
|
678 |
else: |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
108
diff
changeset
|
679 |
self.ConnectionTypes[variable.connectionPointIn] = itype |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
108
diff
changeset
|
680 |
if connected and connected not in self.ConnectionTypes: |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
108
diff
changeset
|
681 |
for connection in self.ExtractRelatedConnections(connected): |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
108
diff
changeset
|
682 |
self.ConnectionTypes[connection] = itype |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
108
diff
changeset
|
683 |
for var_type, connections in undefined.items(): |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
108
diff
changeset
|
684 |
related = [] |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
108
diff
changeset
|
685 |
for connection in connections: |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
108
diff
changeset
|
686 |
if connection in self.ConnectionTypes: |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
108
diff
changeset
|
687 |
var_type = self.ConnectionTypes[connection] |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
108
diff
changeset
|
688 |
else: |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
108
diff
changeset
|
689 |
related.extend(self.ExtractRelatedConnections(connection)) |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
108
diff
changeset
|
690 |
if var_type.startswith("ANY") and len(related) > 0: |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
108
diff
changeset
|
691 |
self.RelatedConnections.append(related) |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
108
diff
changeset
|
692 |
else: |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
108
diff
changeset
|
693 |
for connection in related: |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
108
diff
changeset
|
694 |
self.ConnectionTypes[connection] = var_type |
227
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
695 |
|
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
696 |
def ComputeProgram(self, pou): |
151 | 697 |
body = pou.getbody() |
698 |
body_content = body.getcontent() |
|
0 | 699 |
body_type = body_content["name"] |
700 |
if body_type in ["IL","ST"]: |
|
227
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
701 |
self.Program = [(ReIndentText(body_content["value"].gettext(), len(self.CurrentIndent)), |
228
da7ddaf27cca
Bug with indentation in textual languages while error display fixed
lbessard
parents:
227
diff
changeset
|
702 |
(self.TagName, "body", len(self.CurrentIndent)))] |
0 | 703 |
elif body_type == "SFC": |
227
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
704 |
self.IndentRight() |
151 | 705 |
for instance in body.getcontentInstances(): |
706 |
if isinstance(instance, plcopen.sfcObjects_step): |
|
1 | 707 |
self.GenerateSFCStep(instance, pou) |
151 | 708 |
elif isinstance(instance, plcopen.commonObjects_actionBlock): |
1 | 709 |
self.GenerateSFCStepActions(instance, pou) |
151 | 710 |
elif isinstance(instance, plcopen.sfcObjects_transition): |
1 | 711 |
self.GenerateSFCTransition(instance, pou) |
151 | 712 |
elif isinstance(instance, plcopen.sfcObjects_jumpStep): |
0 | 713 |
self.GenerateSFCJump(instance, pou) |
227
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
714 |
if len(self.InitialSteps) > 0 and len(self.SFCComputedBlocks) > 0: |
66
fd138fc77510
Adding support for generating network and rung connected to transitions into SFC
lbessard
parents:
58
diff
changeset
|
715 |
action_name = "COMPUTE_FUNCTION_BLOCKS" |
fd138fc77510
Adding support for generating network and rung connected to transitions into SFC
lbessard
parents:
58
diff
changeset
|
716 |
action_infos = {"qualifier" : "S", "content" : action_name} |
fd138fc77510
Adding support for generating network and rung connected to transitions into SFC
lbessard
parents:
58
diff
changeset
|
717 |
self.SFCNetworks["Steps"][self.InitialSteps[0]]["actions"].append(action_infos) |
227
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
718 |
self.SFCNetworks["Actions"][action_name] = (self.SFCComputedBlocks, ()) |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
719 |
self.Program = [] |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
720 |
self.IndentLeft() |
1 | 721 |
for initialstep in self.InitialSteps: |
722 |
self.ComputeSFCStep(initialstep) |
|
248
f7df265edd54
Problem with multi-connection on block in LD fixed
lbessard
parents:
244
diff
changeset
|
723 |
else: |
269
34eff05909b0
Adding support for EN/ENO variables (temporarily disabled, waiting for matiec support)
lbessard
parents:
261
diff
changeset
|
724 |
otherInstances = {"outVariables&coils" : [], "blocks" : [], "connectors" : []} |
248
f7df265edd54
Problem with multi-connection on block in LD fixed
lbessard
parents:
244
diff
changeset
|
725 |
orderedInstances = [] |
f7df265edd54
Problem with multi-connection on block in LD fixed
lbessard
parents:
244
diff
changeset
|
726 |
for instance in body.getcontentInstances(): |
f7df265edd54
Problem with multi-connection on block in LD fixed
lbessard
parents:
244
diff
changeset
|
727 |
if isinstance(instance, (plcopen.fbdObjects_outVariable, plcopen.fbdObjects_inOutVariable, plcopen.fbdObjects_block)): |
f7df265edd54
Problem with multi-connection on block in LD fixed
lbessard
parents:
244
diff
changeset
|
728 |
executionOrderId = instance.getexecutionOrderId() |
f7df265edd54
Problem with multi-connection on block in LD fixed
lbessard
parents:
244
diff
changeset
|
729 |
if executionOrderId > 0: |
f7df265edd54
Problem with multi-connection on block in LD fixed
lbessard
parents:
244
diff
changeset
|
730 |
orderedInstances.append((executionOrderId, instance)) |
f7df265edd54
Problem with multi-connection on block in LD fixed
lbessard
parents:
244
diff
changeset
|
731 |
elif isinstance(instance, (plcopen.fbdObjects_outVariable, plcopen.fbdObjects_inOutVariable)): |
269
34eff05909b0
Adding support for EN/ENO variables (temporarily disabled, waiting for matiec support)
lbessard
parents:
261
diff
changeset
|
732 |
otherInstances["outVariables&coils"].append(instance) |
248
f7df265edd54
Problem with multi-connection on block in LD fixed
lbessard
parents:
244
diff
changeset
|
733 |
elif isinstance(instance, plcopen.fbdObjects_block): |
269
34eff05909b0
Adding support for EN/ENO variables (temporarily disabled, waiting for matiec support)
lbessard
parents:
261
diff
changeset
|
734 |
otherInstances["blocks"].append(instance) |
248
f7df265edd54
Problem with multi-connection on block in LD fixed
lbessard
parents:
244
diff
changeset
|
735 |
elif isinstance(instance, plcopen.commonObjects_connector): |
269
34eff05909b0
Adding support for EN/ENO variables (temporarily disabled, waiting for matiec support)
lbessard
parents:
261
diff
changeset
|
736 |
otherInstances["connectors"].append(instance) |
248
f7df265edd54
Problem with multi-connection on block in LD fixed
lbessard
parents:
244
diff
changeset
|
737 |
elif isinstance(instance, plcopen.ldObjects_coil): |
269
34eff05909b0
Adding support for EN/ENO variables (temporarily disabled, waiting for matiec support)
lbessard
parents:
261
diff
changeset
|
738 |
otherInstances["outVariables&coils"].append(instance) |
248
f7df265edd54
Problem with multi-connection on block in LD fixed
lbessard
parents:
244
diff
changeset
|
739 |
orderedInstances.sort() |
269
34eff05909b0
Adding support for EN/ENO variables (temporarily disabled, waiting for matiec support)
lbessard
parents:
261
diff
changeset
|
740 |
otherInstances["outVariables&coils"].sort(SortInstances) |
248
f7df265edd54
Problem with multi-connection on block in LD fixed
lbessard
parents:
244
diff
changeset
|
741 |
instances = [instance for (executionOrderId, instance) in orderedInstances] |
269
34eff05909b0
Adding support for EN/ENO variables (temporarily disabled, waiting for matiec support)
lbessard
parents:
261
diff
changeset
|
742 |
instances.extend(otherInstances["connectors"] + otherInstances["outVariables&coils"] + otherInstances["blocks"]) |
248
f7df265edd54
Problem with multi-connection on block in LD fixed
lbessard
parents:
244
diff
changeset
|
743 |
for instance in instances: |
f7df265edd54
Problem with multi-connection on block in LD fixed
lbessard
parents:
244
diff
changeset
|
744 |
if isinstance(instance, (plcopen.fbdObjects_outVariable, plcopen.fbdObjects_inOutVariable)): |
f7df265edd54
Problem with multi-connection on block in LD fixed
lbessard
parents:
244
diff
changeset
|
745 |
connections = instance.connectionPointIn.getconnections() |
f7df265edd54
Problem with multi-connection on block in LD fixed
lbessard
parents:
244
diff
changeset
|
746 |
if connections is not None: |
f7df265edd54
Problem with multi-connection on block in LD fixed
lbessard
parents:
244
diff
changeset
|
747 |
expression = self.ComputeExpression(body, connections) |
f7df265edd54
Problem with multi-connection on block in LD fixed
lbessard
parents:
244
diff
changeset
|
748 |
self.Program += [(self.CurrentIndent, ()), |
f7df265edd54
Problem with multi-connection on block in LD fixed
lbessard
parents:
244
diff
changeset
|
749 |
(instance.getexpression(), (self.TagName, "io_variable", instance.getlocalId(), "expression")), |
f7df265edd54
Problem with multi-connection on block in LD fixed
lbessard
parents:
244
diff
changeset
|
750 |
(" := ", ())] |
f7df265edd54
Problem with multi-connection on block in LD fixed
lbessard
parents:
244
diff
changeset
|
751 |
self.Program += expression |
f7df265edd54
Problem with multi-connection on block in LD fixed
lbessard
parents:
244
diff
changeset
|
752 |
self.Program += [(";\n", ())] |
f7df265edd54
Problem with multi-connection on block in LD fixed
lbessard
parents:
244
diff
changeset
|
753 |
elif isinstance(instance, plcopen.fbdObjects_block): |
f7df265edd54
Problem with multi-connection on block in LD fixed
lbessard
parents:
244
diff
changeset
|
754 |
block_type = instance.gettypeName() |
f7df265edd54
Problem with multi-connection on block in LD fixed
lbessard
parents:
244
diff
changeset
|
755 |
self.ParentGenerator.GeneratePouProgram(block_type) |
f7df265edd54
Problem with multi-connection on block in LD fixed
lbessard
parents:
244
diff
changeset
|
756 |
block_infos = self.GetBlockType(block_type) |
f7df265edd54
Problem with multi-connection on block in LD fixed
lbessard
parents:
244
diff
changeset
|
757 |
block_infos["generate"](self, instance, body, None) |
f7df265edd54
Problem with multi-connection on block in LD fixed
lbessard
parents:
244
diff
changeset
|
758 |
elif isinstance(instance, plcopen.commonObjects_connector): |
f7df265edd54
Problem with multi-connection on block in LD fixed
lbessard
parents:
244
diff
changeset
|
759 |
connector = instance.getname() |
f7df265edd54
Problem with multi-connection on block in LD fixed
lbessard
parents:
244
diff
changeset
|
760 |
if self.ComputedConnectors.get(connector, None): |
f7df265edd54
Problem with multi-connection on block in LD fixed
lbessard
parents:
244
diff
changeset
|
761 |
continue |
f7df265edd54
Problem with multi-connection on block in LD fixed
lbessard
parents:
244
diff
changeset
|
762 |
self.ComputedConnectors[connector] = self.ComputeExpression(body, instance.connectionPointIn.getconnections()) |
f7df265edd54
Problem with multi-connection on block in LD fixed
lbessard
parents:
244
diff
changeset
|
763 |
elif isinstance(instance, plcopen.ldObjects_coil): |
f7df265edd54
Problem with multi-connection on block in LD fixed
lbessard
parents:
244
diff
changeset
|
764 |
connections = instance.connectionPointIn.getconnections() |
f7df265edd54
Problem with multi-connection on block in LD fixed
lbessard
parents:
244
diff
changeset
|
765 |
if connections is not None: |
f7df265edd54
Problem with multi-connection on block in LD fixed
lbessard
parents:
244
diff
changeset
|
766 |
coil_info = (self.TagName, "coil", instance.getlocalId()) |
269
34eff05909b0
Adding support for EN/ENO variables (temporarily disabled, waiting for matiec support)
lbessard
parents:
261
diff
changeset
|
767 |
expression = self.ExtractModifier(instance, self.ComputeExpression(body, connections), coil_info) |
34eff05909b0
Adding support for EN/ENO variables (temporarily disabled, waiting for matiec support)
lbessard
parents:
261
diff
changeset
|
768 |
self.Program += [(self.CurrentIndent, ())] |
34eff05909b0
Adding support for EN/ENO variables (temporarily disabled, waiting for matiec support)
lbessard
parents:
261
diff
changeset
|
769 |
self.Program += [(instance.getvariable(), coil_info + ("reference",))] |
248
f7df265edd54
Problem with multi-connection on block in LD fixed
lbessard
parents:
244
diff
changeset
|
770 |
self.Program += [(" := ", ())] + expression + [(";\n", ())] |
269
34eff05909b0
Adding support for EN/ENO variables (temporarily disabled, waiting for matiec support)
lbessard
parents:
261
diff
changeset
|
771 |
|
248
f7df265edd54
Problem with multi-connection on block in LD fixed
lbessard
parents:
244
diff
changeset
|
772 |
def FactorizePaths(self, paths): |
242 | 773 |
same_paths = {} |
774 |
uncomputed_index = range(len(paths)) |
|
775 |
factorized_paths = [] |
|
776 |
for num, path in enumerate(paths): |
|
777 |
if type(path) == ListType: |
|
273
5b18d98aa4f9
Support for unhandled factorization cases added by fixing bug
lbessard
parents:
269
diff
changeset
|
778 |
if len(path) > 1: |
5b18d98aa4f9
Support for unhandled factorization cases added by fixing bug
lbessard
parents:
269
diff
changeset
|
779 |
str_path = str(path[-1:]) |
242 | 780 |
same_paths.setdefault(str_path, []) |
273
5b18d98aa4f9
Support for unhandled factorization cases added by fixing bug
lbessard
parents:
269
diff
changeset
|
781 |
same_paths[str_path].append((path[:-1], num)) |
242 | 782 |
else: |
783 |
factorized_paths.append(path) |
|
784 |
uncomputed_index.remove(num) |
|
785 |
for same_path, elements in same_paths.items(): |
|
786 |
if len(elements) > 1: |
|
273
5b18d98aa4f9
Support for unhandled factorization cases added by fixing bug
lbessard
parents:
269
diff
changeset
|
787 |
elements_paths = self.FactorizePaths([path for path, num in elements]) |
5b18d98aa4f9
Support for unhandled factorization cases added by fixing bug
lbessard
parents:
269
diff
changeset
|
788 |
if len(elements_paths) > 1: |
5b18d98aa4f9
Support for unhandled factorization cases added by fixing bug
lbessard
parents:
269
diff
changeset
|
789 |
factorized_paths.append([tuple(elements_paths)] + eval(same_path)) |
5b18d98aa4f9
Support for unhandled factorization cases added by fixing bug
lbessard
parents:
269
diff
changeset
|
790 |
else: |
5b18d98aa4f9
Support for unhandled factorization cases added by fixing bug
lbessard
parents:
269
diff
changeset
|
791 |
factorized_paths.append(elements_paths + eval(same_path)) |
242 | 792 |
for path, num in elements: |
793 |
uncomputed_index.remove(num) |
|
794 |
for num in uncomputed_index: |
|
795 |
factorized_paths.append(paths[num]) |
|
244
05f6e0d7710c
Adding sort in LD factorized paths to avoid combination problem
lbessard
parents:
242
diff
changeset
|
796 |
factorized_paths.sort() |
242 | 797 |
return factorized_paths |
798 |
||
248
f7df265edd54
Problem with multi-connection on block in LD fixed
lbessard
parents:
244
diff
changeset
|
799 |
def GeneratePaths(self, connections, body, order = False): |
0 | 800 |
paths = [] |
801 |
for connection in connections: |
|
151 | 802 |
localId = connection.getrefLocalId() |
803 |
next = body.getcontentInstance(localId) |
|
804 |
if isinstance(next, plcopen.ldObjects_leftPowerRail): |
|
0 | 805 |
paths.append(None) |
248
f7df265edd54
Problem with multi-connection on block in LD fixed
lbessard
parents:
244
diff
changeset
|
806 |
elif isinstance(next, (plcopen.fbdObjects_inVariable, plcopen.fbdObjects_inOutVariable)): |
f7df265edd54
Problem with multi-connection on block in LD fixed
lbessard
parents:
244
diff
changeset
|
807 |
paths.append(str([(next.getexpression(), (self.TagName, "io_variable", localId, "expression"))])) |
151 | 808 |
elif isinstance(next, plcopen.fbdObjects_block): |
809 |
block_type = next.gettypeName() |
|
227
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
810 |
self.ParentGenerator.GeneratePouProgram(block_type) |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
811 |
block_infos = self.GetBlockType(block_type) |
248
f7df265edd54
Problem with multi-connection on block in LD fixed
lbessard
parents:
244
diff
changeset
|
812 |
paths.append(str(block_infos["generate"](self, next, body, connection, order))) |
f7df265edd54
Problem with multi-connection on block in LD fixed
lbessard
parents:
244
diff
changeset
|
813 |
elif isinstance(next, plcopen.commonObjects_continuation): |
f7df265edd54
Problem with multi-connection on block in LD fixed
lbessard
parents:
244
diff
changeset
|
814 |
name = next.getname() |
f7df265edd54
Problem with multi-connection on block in LD fixed
lbessard
parents:
244
diff
changeset
|
815 |
computed_value = self.ComputedConnectors.get(name, None) |
f7df265edd54
Problem with multi-connection on block in LD fixed
lbessard
parents:
244
diff
changeset
|
816 |
if computed_value != None: |
257 | 817 |
paths.append(str(computed_value)) |
818 |
else: |
|
819 |
connector = None |
|
820 |
for instance in body.getcontentInstances(): |
|
821 |
if isinstance(instance, plcopen.commonObjects_connector) and instance.getname() == name: |
|
822 |
if connector is not None: |
|
823 |
raise PLCGenException, "More than one connector found corresponding to \"%s\" continuation in \"%s\" POU"%(name, self.Name) |
|
824 |
connector = instance |
|
825 |
if connector is not None: |
|
826 |
connections = connector.connectionPointIn.getconnections() |
|
827 |
if connections is not None: |
|
828 |
expression = self.ComputeExpression(body, connections, order) |
|
829 |
self.ComputedConnectors[name] = expression |
|
830 |
paths.append(str(expression)) |
|
831 |
else: |
|
832 |
raise PLCGenException, "No connector found corresponding to \"%s\" continuation in \"%s\" POU"%(name, self.Name) |
|
833 |
elif isinstance(next, plcopen.ldObjects_contact): |
|
227
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
834 |
contact_info = (self.TagName, "contact", next.getlocalId()) |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
835 |
variable = str(self.ExtractModifier(next, [(next.getvariable(), contact_info + ("reference",))], contact_info)) |
248
f7df265edd54
Problem with multi-connection on block in LD fixed
lbessard
parents:
244
diff
changeset
|
836 |
result = self.GeneratePaths(next.connectionPointIn.getconnections(), body, order) |
66
fd138fc77510
Adding support for generating network and rung connected to transitions into SFC
lbessard
parents:
58
diff
changeset
|
837 |
if len(result) > 1: |
248
f7df265edd54
Problem with multi-connection on block in LD fixed
lbessard
parents:
244
diff
changeset
|
838 |
factorized_paths = self.FactorizePaths(result) |
242 | 839 |
if len(factorized_paths) > 1: |
840 |
paths.append([variable, tuple(factorized_paths)]) |
|
841 |
else: |
|
842 |
paths.append([variable] + factorized_paths) |
|
66
fd138fc77510
Adding support for generating network and rung connected to transitions into SFC
lbessard
parents:
58
diff
changeset
|
843 |
elif type(result[0]) == ListType: |
fd138fc77510
Adding support for generating network and rung connected to transitions into SFC
lbessard
parents:
58
diff
changeset
|
844 |
paths.append([variable] + result[0]) |
242 | 845 |
elif result[0] is not None: |
66
fd138fc77510
Adding support for generating network and rung connected to transitions into SFC
lbessard
parents:
58
diff
changeset
|
846 |
paths.append([variable, result[0]]) |
fd138fc77510
Adding support for generating network and rung connected to transitions into SFC
lbessard
parents:
58
diff
changeset
|
847 |
else: |
fd138fc77510
Adding support for generating network and rung connected to transitions into SFC
lbessard
parents:
58
diff
changeset
|
848 |
paths.append(variable) |
257 | 849 |
elif isinstance(next, plcopen.ldObjects_coil): |
850 |
paths.append(str(self.GeneratePaths(next.connectionPointIn.getconnections(), body, order))) |
|
66
fd138fc77510
Adding support for generating network and rung connected to transitions into SFC
lbessard
parents:
58
diff
changeset
|
851 |
return paths |
fd138fc77510
Adding support for generating network and rung connected to transitions into SFC
lbessard
parents:
58
diff
changeset
|
852 |
|
248
f7df265edd54
Problem with multi-connection on block in LD fixed
lbessard
parents:
244
diff
changeset
|
853 |
def ComputePaths(self, paths, first = False): |
227
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
854 |
if type(paths) == TupleType: |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
855 |
if None in paths: |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
856 |
return [("TRUE", ())] |
66
fd138fc77510
Adding support for generating network and rung connected to transitions into SFC
lbessard
parents:
58
diff
changeset
|
857 |
else: |
248
f7df265edd54
Problem with multi-connection on block in LD fixed
lbessard
parents:
244
diff
changeset
|
858 |
vars = [self.ComputePaths(path) for path in paths] |
227
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
859 |
if first: |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
860 |
return JoinList([(" OR ", ())], vars) |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
861 |
else: |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
862 |
return [("(", ())] + JoinList([(" OR ", ())], vars) + [(")", ())] |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
863 |
elif type(paths) == ListType: |
248
f7df265edd54
Problem with multi-connection on block in LD fixed
lbessard
parents:
244
diff
changeset
|
864 |
vars = [self.ComputePaths(path) for path in paths] |
227
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
865 |
return JoinList([(" AND ", ())], vars) |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
866 |
else: |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
867 |
return eval(paths) |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
868 |
|
248
f7df265edd54
Problem with multi-connection on block in LD fixed
lbessard
parents:
244
diff
changeset
|
869 |
def ComputeExpression(self, body, connections, order = False): |
f7df265edd54
Problem with multi-connection on block in LD fixed
lbessard
parents:
244
diff
changeset
|
870 |
paths = self.GeneratePaths(connections, body, order) |
242 | 871 |
if len(paths) > 1: |
248
f7df265edd54
Problem with multi-connection on block in LD fixed
lbessard
parents:
244
diff
changeset
|
872 |
factorized_paths = self.FactorizePaths(paths) |
242 | 873 |
if len(factorized_paths) > 1: |
874 |
paths = tuple(factorized_paths) |
|
875 |
else: |
|
876 |
paths = factorized_paths[0] |
|
877 |
else: |
|
878 |
paths = paths[0] |
|
248
f7df265edd54
Problem with multi-connection on block in LD fixed
lbessard
parents:
244
diff
changeset
|
879 |
return self.ComputePaths(paths, True) |
242 | 880 |
|
227
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
881 |
def ExtractModifier(self, variable, expression, var_info): |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
882 |
if variable.getnegated(): |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
883 |
return [("NOT(", var_info + ("negated",))] + expression + [(")", ())] |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
884 |
else: |
269
34eff05909b0
Adding support for EN/ENO variables (temporarily disabled, waiting for matiec support)
lbessard
parents:
261
diff
changeset
|
885 |
storage = variable.getstorage() |
34eff05909b0
Adding support for EN/ENO variables (temporarily disabled, waiting for matiec support)
lbessard
parents:
261
diff
changeset
|
886 |
if storage in ["set", "reset"]: |
34eff05909b0
Adding support for EN/ENO variables (temporarily disabled, waiting for matiec support)
lbessard
parents:
261
diff
changeset
|
887 |
self.Program += [(self.CurrentIndent + "IF ", var_info + (storage,))] + expression |
34eff05909b0
Adding support for EN/ENO variables (temporarily disabled, waiting for matiec support)
lbessard
parents:
261
diff
changeset
|
888 |
self.Program += [(" THEN\n ", ())] |
34eff05909b0
Adding support for EN/ENO variables (temporarily disabled, waiting for matiec support)
lbessard
parents:
261
diff
changeset
|
889 |
if storage == "set": |
281 | 890 |
return [("TRUE; (*set*)\n" + self.CurrentIndent + "END_IF", ())] |
891 |
else: |
|
892 |
return [("FALSE; (*reset*)\n" + self.CurrentIndent + "END_IF", ())] |
|
227
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
893 |
edge = variable.getedge() |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
894 |
if edge == "rising": |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
895 |
return self.AddTrigger("R_TRIG", expression, var_info + ("rising",)) |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
896 |
elif edge == "falling": |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
897 |
return self.AddTrigger("F_TRIG", expression, var_info + ("falling",)) |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
898 |
return expression |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
899 |
|
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
900 |
def AddTrigger(self, edge, expression, var_info): |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
901 |
if self.Interface[-1][0] != "VAR" or self.Interface[-1][1] or self.Interface[-1][2] or self.Interface[-1][3]: |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
902 |
self.Interface.append(("VAR", False, False, False, [])) |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
903 |
i = 1 |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
904 |
name = "%s%d"%(edge, i) |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
905 |
while self.IsAlreadyDefined(name): |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
906 |
i += 1 |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
907 |
name = "%s%d"%(edge, i) |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
908 |
self.Interface[-1][4].append((edge, name, None, None)) |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
909 |
self.Program += [(self.CurrentIndent, ()), (name, var_info), ("(CLK := ", ())] |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
910 |
self.Program += expression |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
911 |
self.Program += [(");\n", ())] |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
912 |
return [("%s.Q"%name, var_info)] |
66
fd138fc77510
Adding support for generating network and rung connected to transitions into SFC
lbessard
parents:
58
diff
changeset
|
913 |
|
2 | 914 |
def ExtractDivergenceInput(self, divergence, pou): |
151 | 915 |
connectionPointIn = divergence.getconnectionPointIn() |
2 | 916 |
if connectionPointIn: |
151 | 917 |
connections = connectionPointIn.getconnections() |
201 | 918 |
if connections is not None and len(connections) == 1: |
151 | 919 |
instanceLocalId = connections[0].getrefLocalId() |
920 |
return pou.body.getcontentInstance(instanceLocalId) |
|
2 | 921 |
return None |
922 |
||
923 |
def ExtractConvergenceInputs(self, convergence, pou): |
|
924 |
instances = [] |
|
151 | 925 |
for connectionPointIn in convergence.getconnectionPointIn(): |
926 |
connections = connectionPointIn.getconnections() |
|
2 | 927 |
if len(connections) == 1: |
151 | 928 |
instanceLocalId = connections[0].getrefLocalId() |
929 |
instances.append(pou.body.getcontentInstance(instanceLocalId)) |
|
2 | 930 |
return instances |
931 |
||
1 | 932 |
def GenerateSFCStep(self, step, pou): |
151 | 933 |
step_name = step.getname() |
1 | 934 |
if step_name not in self.SFCNetworks["Steps"].keys(): |
151 | 935 |
if step.getinitialStep(): |
1 | 936 |
self.InitialSteps.append(step_name) |
227
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
937 |
step_infos = {"id" : step.getlocalId(), |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
938 |
"initial" : step.getinitialStep(), |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
939 |
"transitions" : [], |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
940 |
"actions" : []} |
0 | 941 |
if step.connectionPointIn: |
942 |
instances = [] |
|
151 | 943 |
connections = step.connectionPointIn.getconnections() |
0 | 944 |
if len(connections) == 1: |
151 | 945 |
instanceLocalId = connections[0].getrefLocalId() |
946 |
instance = pou.body.getcontentInstance(instanceLocalId) |
|
947 |
if isinstance(instance, plcopen.sfcObjects_transition): |
|
0 | 948 |
instances.append(instance) |
151 | 949 |
elif isinstance(instance, plcopen.sfcObjects_selectionConvergence): |
2 | 950 |
instances.extend(self.ExtractConvergenceInputs(instance, pou)) |
151 | 951 |
elif isinstance(instance, plcopen.sfcObjects_simultaneousDivergence): |
2 | 952 |
transition = self.ExtractDivergenceInput(instance, pou) |
953 |
if transition: |
|
151 | 954 |
if isinstance(transition, plcopen.sfcObjects_transition): |
1 | 955 |
instances.append(transition) |
151 | 956 |
elif isinstance(transition, plcopen.sfcObjects_selectionConvergence): |
2 | 957 |
instances.extend(self.ExtractConvergenceInputs(transition, pou)) |
0 | 958 |
for instance in instances: |
2 | 959 |
self.GenerateSFCTransition(instance, pou) |
1 | 960 |
if instance in self.SFCNetworks["Transitions"].keys(): |
227
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
961 |
target_info = (self.TagName, "transition", instance.getlocalId(), "to", step_infos["id"]) |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
962 |
self.SFCNetworks["Transitions"][instance]["to"].append([(step_name, target_info)]) |
1 | 963 |
self.SFCNetworks["Steps"][step_name] = step_infos |
0 | 964 |
|
965 |
def GenerateSFCJump(self, jump, pou): |
|
151 | 966 |
jump_target = jump.gettargetName() |
0 | 967 |
if jump.connectionPointIn: |
968 |
instances = [] |
|
151 | 969 |
connections = jump.connectionPointIn.getconnections() |
0 | 970 |
if len(connections) == 1: |
151 | 971 |
instanceLocalId = connections[0].getrefLocalId() |
972 |
instance = pou.body.getcontentInstance(instanceLocalId) |
|
973 |
if isinstance(instance, plcopen.sfcObjects_transition): |
|
0 | 974 |
instances.append(instance) |
151 | 975 |
elif isinstance(instance, plcopen.sfcObjects_selectionConvergence): |
2 | 976 |
instances.extend(self.ExtractConvergenceInputs(instance, pou)) |
151 | 977 |
elif isinstance(instance, plcopen.sfcObjects_simultaneousDivergence): |
2 | 978 |
transition = self.ExtractDivergenceInput(instance, pou) |
979 |
if transition: |
|
151 | 980 |
if isinstance(transition, plcopen.sfcObjects_transition): |
1 | 981 |
instances.append(transition) |
151 | 982 |
elif isinstance(transition, plcopen.sfcObjects_selectionConvergence): |
2 | 983 |
instances.extend(self.ExtractConvergenceInputs(transition, pou)) |
0 | 984 |
for instance in instances: |
2 | 985 |
self.GenerateSFCTransition(instance, pou) |
1 | 986 |
if instance in self.SFCNetworks["Transitions"].keys(): |
227
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
987 |
target_info = (self.TagName, "jump", jump.getlocalId(), "target") |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
988 |
self.SFCNetworks["Transitions"][instance]["to"].append([(jump_target, target_info)]) |
1 | 989 |
|
990 |
def GenerateSFCStepActions(self, actionBlock, pou): |
|
151 | 991 |
connections = actionBlock.connectionPointIn.getconnections() |
201 | 992 |
if connections is not None and len(connections) == 1: |
151 | 993 |
stepLocalId = connections[0].getrefLocalId() |
994 |
step = pou.body.getcontentInstance(stepLocalId) |
|
1 | 995 |
self.GenerateSFCStep(step, pou) |
151 | 996 |
step_name = step.getname() |
1 | 997 |
if step_name in self.SFCNetworks["Steps"].keys(): |
151 | 998 |
actions = actionBlock.getactions() |
227
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
999 |
for i, action in enumerate(actions): |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
1000 |
action_infos = {"id" : actionBlock.getlocalId(), |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
1001 |
"qualifier" : action["qualifier"], |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
1002 |
"content" : action["value"], |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
1003 |
"num" : i} |
1 | 1004 |
if "duration" in action: |
1005 |
action_infos["duration"] = action["duration"] |
|
1006 |
if "indicator" in action: |
|
1007 |
action_infos["indicator"] = action["indicator"] |
|
1008 |
if action["type"] == "reference": |
|
1009 |
self.GenerateSFCAction(action["value"], pou) |
|
46 | 1010 |
else: |
168
fb500cc79164
Adding support for structure variable list generation module in matiec
lbessard
parents:
151
diff
changeset
|
1011 |
action_name = "%s_INLINE%d"%(step_name.upper(), self.GetActionNumber()) |
227
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
1012 |
self.SFCNetworks["Actions"][action_name] = ([(self.CurrentIndent, ()), |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
1013 |
(action["value"], (self.TagName, "action_block", action_infos["id"], "action", i, "inline")), |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
1014 |
("\n", ())], ()) |
46 | 1015 |
action_infos["content"] = action_name |
1 | 1016 |
self.SFCNetworks["Steps"][step_name]["actions"].append(action_infos) |
1017 |
||
1018 |
def GenerateSFCAction(self, action_name, pou): |
|
1019 |
if action_name not in self.SFCNetworks["Actions"].keys(): |
|
151 | 1020 |
actionContent = pou.getaction(action_name) |
1 | 1021 |
if actionContent: |
227
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
1022 |
previous_tagname = self.TagName |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
1023 |
self.TagName = self.ParentGenerator.Controler.ComputePouActionName(self.Name, action_name) |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
1024 |
self.ComputeProgram(actionContent) |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
1025 |
self.SFCNetworks["Actions"][action_name] = (self.Program, (self.TagName, "name")) |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
1026 |
self.Program = [] |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
1027 |
self.TagName = previous_tagname |
1 | 1028 |
|
1029 |
def GenerateSFCTransition(self, transition, pou): |
|
1030 |
if transition not in self.SFCNetworks["Transitions"].keys(): |
|
1031 |
steps = [] |
|
151 | 1032 |
connections = transition.connectionPointIn.getconnections() |
201 | 1033 |
if connections is not None and len(connections) == 1: |
151 | 1034 |
instanceLocalId = connections[0].getrefLocalId() |
1035 |
instance = pou.body.getcontentInstance(instanceLocalId) |
|
1036 |
if isinstance(instance, plcopen.sfcObjects_step): |
|
2 | 1037 |
steps.append(instance) |
151 | 1038 |
elif isinstance(instance, plcopen.sfcObjects_selectionDivergence): |
2 | 1039 |
step = self.ExtractDivergenceInput(instance, pou) |
1040 |
if step: |
|
151 | 1041 |
if isinstance(step, plcopen.sfcObjects_step): |
2 | 1042 |
steps.append(step) |
151 | 1043 |
elif isinstance(step, plcopen.sfcObjects_simultaneousConvergence): |
2 | 1044 |
steps.extend(self.ExtractConvergenceInputs(step, pou)) |
151 | 1045 |
elif isinstance(instance, plcopen.sfcObjects_simultaneousConvergence): |
2 | 1046 |
steps.extend(self.ExtractConvergenceInputs(instance, pou)) |
227
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
1047 |
transition_infos = {"id" : transition.getlocalId(), |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
1048 |
"priority": transition.getpriority(), |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
1049 |
"from": [], |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
1050 |
"to" : []} |
151 | 1051 |
transitionValues = transition.getconditionContent() |
1 | 1052 |
if transitionValues["type"] == "inline": |
227
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
1053 |
transition_infos["content"] = [("\n%s:= "%self.CurrentIndent, ()), |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
1054 |
(transitionValues["value"], (self.TagName, "transition", transition.getlocalId(), "inline")), |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
1055 |
(";\n", ())] |
66
fd138fc77510
Adding support for generating network and rung connected to transitions into SFC
lbessard
parents:
58
diff
changeset
|
1056 |
elif transitionValues["type"] == "reference": |
151 | 1057 |
transitionContent = pou.gettransition(transitionValues["value"]) |
1058 |
transitionType = transitionContent.getbodyType() |
|
1059 |
transitionBody = transitionContent.getbody() |
|
227
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
1060 |
previous_tagname = self.TagName |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
1061 |
self.TagName = self.ParentGenerator.Controler.ComputePouTransitionName(self.Name, transitionValues["value"]) |
1 | 1062 |
if transitionType == "IL": |
227
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
1063 |
transition_infos["content"] = [(":\n", ()), |
228
da7ddaf27cca
Bug with indentation in textual languages while error display fixed
lbessard
parents:
227
diff
changeset
|
1064 |
(ReIndentText(transitionBody.gettext(), len(self.CurrentIndent)), (self.TagName, "body", len(self.CurrentIndent)))] |
1 | 1065 |
elif transitionType == "ST": |
227
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
1066 |
transition_infos["content"] = [("\n", ()), |
228
da7ddaf27cca
Bug with indentation in textual languages while error display fixed
lbessard
parents:
227
diff
changeset
|
1067 |
(ReIndentText(transitionBody.gettext(), len(self.CurrentIndent)), (self.TagName, "body", len(self.CurrentIndent)))] |
248
f7df265edd54
Problem with multi-connection on block in LD fixed
lbessard
parents:
244
diff
changeset
|
1068 |
else: |
151 | 1069 |
for instance in transitionBody.getcontentInstances(): |
248
f7df265edd54
Problem with multi-connection on block in LD fixed
lbessard
parents:
244
diff
changeset
|
1070 |
if isinstance(instance, plcopen.fbdObjects_outVariable) and instance.getexpression() == transitionValues["value"]\ |
f7df265edd54
Problem with multi-connection on block in LD fixed
lbessard
parents:
244
diff
changeset
|
1071 |
or isinstance(instance, plcopen.ldObjects_coil) and instance.getvariable() == transitionValues["value"]: |
151 | 1072 |
connections = instance.connectionPointIn.getconnections() |
248
f7df265edd54
Problem with multi-connection on block in LD fixed
lbessard
parents:
244
diff
changeset
|
1073 |
if connections is not None: |
f7df265edd54
Problem with multi-connection on block in LD fixed
lbessard
parents:
244
diff
changeset
|
1074 |
expression = self.ComputeExpression(transitionBody, connections) |
227
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
1075 |
transition_infos["content"] = [("\n%s:= "%self.CurrentIndent, ())] + expression + [(";\n", ())] |
72
73212220ad22
Adding support for generating FBD with connectors and continuations
lbessard
parents:
71
diff
changeset
|
1076 |
self.SFCComputedBlocks += self.Program |
227
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
1077 |
self.Program = [] |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
1078 |
self.TagName = previous_tagname |
66
fd138fc77510
Adding support for generating network and rung connected to transitions into SFC
lbessard
parents:
58
diff
changeset
|
1079 |
elif transitionValues["type"] == "connection": |
151 | 1080 |
body = pou.getbody() |
1081 |
connections = transition.getconnections() |
|
248
f7df265edd54
Problem with multi-connection on block in LD fixed
lbessard
parents:
244
diff
changeset
|
1082 |
if connections is not None: |
f7df265edd54
Problem with multi-connection on block in LD fixed
lbessard
parents:
244
diff
changeset
|
1083 |
expression = self.ComputeExpression(body, connections) |
f7df265edd54
Problem with multi-connection on block in LD fixed
lbessard
parents:
244
diff
changeset
|
1084 |
transition_infos["content"] = [("\n%s:= "%self.CurrentIndent, ())] + expression + [(";\n", ())] |
f7df265edd54
Problem with multi-connection on block in LD fixed
lbessard
parents:
244
diff
changeset
|
1085 |
self.SFCComputedBlocks += self.Program |
f7df265edd54
Problem with multi-connection on block in LD fixed
lbessard
parents:
244
diff
changeset
|
1086 |
self.Program = [] |
2 | 1087 |
for step in steps: |
1088 |
self.GenerateSFCStep(step, pou) |
|
151 | 1089 |
step_name = step.getname() |
1 | 1090 |
if step_name in self.SFCNetworks["Steps"].keys(): |
227
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
1091 |
transition_infos["from"].append([(step_name, (self.TagName, "transition", transition.getlocalId(), "from", step.getlocalId()))]) |
1 | 1092 |
self.SFCNetworks["Steps"][step_name]["transitions"].append(transition) |
1093 |
self.SFCNetworks["Transitions"][transition] = transition_infos |
|
1094 |
||
1095 |
def ComputeSFCStep(self, step_name): |
|
1096 |
if step_name in self.SFCNetworks["Steps"].keys(): |
|
1097 |
step_infos = self.SFCNetworks["Steps"].pop(step_name) |
|
227
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
1098 |
self.Program += [(self.CurrentIndent, ())] |
1 | 1099 |
if step_infos["initial"]: |
227
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
1100 |
self.Program += [("INITIAL_", ())] |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
1101 |
self.Program += [("STEP ", ()), |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
1102 |
(step_name, (self.TagName, "step", step_infos["id"], "name")), |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
1103 |
(":\n", ())] |
1 | 1104 |
actions = [] |
227
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
1105 |
self.IndentRight() |
1 | 1106 |
for action_infos in step_infos["actions"]: |
227
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
1107 |
if action_infos.get("id", None) is not None: |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
1108 |
action_info = (self.TagName, "action_block", action_infos["id"], "action", action_infos["num"]) |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
1109 |
else: |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
1110 |
action_info = () |
1 | 1111 |
actions.append(action_infos["content"]) |
227
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
1112 |
self.Program += [(self.CurrentIndent, ()), |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
1113 |
(action_infos["content"], action_info + ("reference",)), |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
1114 |
("(", ()), |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
1115 |
(action_infos["qualifier"], action_info + ("qualifier",))] |
1 | 1116 |
if "duration" in action_infos: |
227
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
1117 |
self.Program += [(", ", ()), |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
1118 |
(action_infos["duration"], action_info + ("duration",))] |
1 | 1119 |
if "indicator" in action_infos: |
227
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
1120 |
self.Program += [(", ", ()), |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
1121 |
(action_infos["indicator"], action_info + ("indicator",))] |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
1122 |
self.Program += [(");\n", ())] |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
1123 |
self.IndentLeft() |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
1124 |
self.Program += [("%sEND_STEP\n\n"%self.CurrentIndent, ())] |
1 | 1125 |
for action in actions: |
1126 |
self.ComputeSFCAction(action) |
|
1127 |
for transition in step_infos["transitions"]: |
|
1128 |
self.ComputeSFCTransition(transition) |
|
1129 |
||
1130 |
def ComputeSFCAction(self, action_name): |
|
1131 |
if action_name in self.SFCNetworks["Actions"].keys(): |
|
227
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
1132 |
action_content, action_info = self.SFCNetworks["Actions"].pop(action_name) |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
1133 |
self.Program += [("%sACTION "%self.CurrentIndent, ()), |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
1134 |
(action_name, action_info), |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
1135 |
(" :\n", ())] |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
1136 |
self.Program += action_content |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
1137 |
self.Program += [("%sEND_ACTION\n\n"%self.CurrentIndent, ())] |
1 | 1138 |
|
1139 |
def ComputeSFCTransition(self, transition): |
|
1140 |
if transition in self.SFCNetworks["Transitions"].keys(): |
|
1141 |
transition_infos = self.SFCNetworks["Transitions"].pop(transition) |
|
227
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
1142 |
self.Program += [("%sTRANSITION"%self.CurrentIndent, ())] |
80 | 1143 |
if transition_infos["priority"] != None: |
227
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
1144 |
self.Program += [(" (PRIORITY := ", ()), |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
1145 |
("%d"%transition_infos["priority"], (self.TagName, "transition", transition_infos["id"], "priority")), |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
1146 |
(")", ())] |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
1147 |
self.Program += [(" FROM ", ())] |
1 | 1148 |
if len(transition_infos["from"]) > 1: |
227
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
1149 |
self.Program += [("(", ())] |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
1150 |
self.Program += JoinList([(", ", ())], transition_infos["from"]) |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
1151 |
self.Program += [(")", ())] |
201 | 1152 |
elif len(transition_infos["from"]) == 1: |
227
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
1153 |
self.Program += transition_infos["from"][0] |
201 | 1154 |
else: |
214
a88b377f75cb
Adding tests for detecting POUs with no variables or/and no body
lbessard
parents:
208
diff
changeset
|
1155 |
raise PLCGenException, "Transition with content \"%s\" not connected to a previous step in \"%s\" POU"%(transition_infos["content"], self.Name) |
227
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
1156 |
self.Program += [(" TO ", ())] |
1 | 1157 |
if len(transition_infos["to"]) > 1: |
227
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
1158 |
self.Program += [("(", ())] |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
1159 |
self.Program += JoinList([(", ", ())], transition_infos["to"]) |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
1160 |
self.Program += [(")", ())] |
201 | 1161 |
elif len(transition_infos["to"]) == 1: |
227
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
1162 |
self.Program += transition_infos["to"][0] |
201 | 1163 |
else: |
214
a88b377f75cb
Adding tests for detecting POUs with no variables or/and no body
lbessard
parents:
208
diff
changeset
|
1164 |
raise PLCGenException, "Transition with content \"%s\" not connected to a next step in \"%s\" POU"%(transition_infos["content"], self.Name) |
1 | 1165 |
self.Program += transition_infos["content"] |
227
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
1166 |
self.Program += [("%sEND_TRANSITION\n\n"%self.CurrentIndent, ())] |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
1167 |
for [(step_name, step_infos)] in transition_infos["to"]: |
1 | 1168 |
self.ComputeSFCStep(step_name) |
227
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
1169 |
|
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
1170 |
def GenerateProgram(self, pou): |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
1171 |
self.ComputeInterface(pou) |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
1172 |
self.ComputeConnectionTypes(pou) |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
1173 |
self.ComputeProgram(pou) |
1 | 1174 |
|
227
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
1175 |
program = [("%s "%self.Type, ()), |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
1176 |
(self.Name, (self.TagName, "name"))] |
1 | 1177 |
if self.ReturnType: |
227
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
1178 |
program += [(" : ", ()), |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
1179 |
(self.ReturnType, (self.TagName, "return"))] |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
1180 |
program += [("\n", ())] |
214
a88b377f75cb
Adding tests for detecting POUs with no variables or/and no body
lbessard
parents:
208
diff
changeset
|
1181 |
if len(self.Interface) == 0: |
a88b377f75cb
Adding tests for detecting POUs with no variables or/and no body
lbessard
parents:
208
diff
changeset
|
1182 |
raise PLCGenException, "No variable defined in \"%s\" POU"%self.Name |
227
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
1183 |
if len(self.Program) == 0 : |
214
a88b377f75cb
Adding tests for detecting POUs with no variables or/and no body
lbessard
parents:
208
diff
changeset
|
1184 |
raise PLCGenException, "No body defined in \"%s\" POU"%self.Name |
227
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
1185 |
var_number = 0 |
33 | 1186 |
for list_type, retain, constant, located, variables in self.Interface: |
227
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
1187 |
program += [(" %s"%list_type, ())] |
1 | 1188 |
if retain: |
227
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
1189 |
program += [(" RETAIN", (self.TagName, "variable", (var_number, var_number + len(variables)), "retain"))] |
1 | 1190 |
if constant: |
227
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
1191 |
program += [(" CONSTANT", (self.TagName, "variable", (var_number, var_number + len(variables)), "constant"))] |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
1192 |
program += [("\n", ())] |
30 | 1193 |
for var_type, var_name, var_address, var_initial in variables: |
227
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
1194 |
program += [(" ", ())] |
93 | 1195 |
if var_name: |
227
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
1196 |
program += [(var_name, (self.TagName, "variable", var_number, "name")), |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
1197 |
(" ", ())] |
30 | 1198 |
if var_address != None: |
227
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
1199 |
program += [("AT ", ()), |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
1200 |
(var_address, (self.TagName, "variable", var_number, "address")), |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
1201 |
(" ", ())] |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
1202 |
program += [(": ", ()), |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
1203 |
(var_type, (self.TagName, "variable", var_number, "type"))] |
28
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
6
diff
changeset
|
1204 |
if var_initial != None: |
227
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
1205 |
program += [(" := ", ()), |
232 | 1206 |
(self.ParentGenerator.ComputeValue(var_initial, var_type), (self.TagName, "variable", var_number, "initial"))] |
227
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
1207 |
program += [(";\n", ())] |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
1208 |
var_number += 1 |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
1209 |
program += [(" END_VAR\n", ())] |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
1210 |
program += [("\n", ())] |
0 | 1211 |
program += self.Program |
227
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
1212 |
program += [("END_%s\n\n"%self.Type, ())] |
0 | 1213 |
return program |
71 | 1214 |
|
307
fd1f6ae26d4f
Adding support for cancelling code generation of function with no input connected
lbessard
parents:
295
diff
changeset
|
1215 |
def GenerateCurrentProgram(controler, project, errors, warnings): |
fd1f6ae26d4f
Adding support for cancelling code generation of function with no input connected
lbessard
parents:
295
diff
changeset
|
1216 |
generator = ProgramGenerator(controler, project, errors, warnings) |
227
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
1217 |
generator.GenerateProgram() |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
1218 |
return generator.GetGeneratedProgram() |
c6fee379d446
Adding informations to program chunks to allow display of compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
1219 |