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