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