author | greg |
Wed, 16 Jan 2008 09:52:37 +0100 | |
changeset 149 | 189ebdde3eb9 |
parent 145 | 4fb225afddf4 |
child 151 | aaa80b48bead |
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 minixsv import pyxsval |
|
27 | 26 |
from xml.dom import minidom |
67
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
27 |
from types import StringType, UnicodeType |
0 | 28 |
import cPickle |
29 |
import os,sys,re |
|
145 | 30 |
from time import localtime |
24 | 31 |
from datetime import * |
0 | 32 |
|
33 |
from plcopen import plcopen |
|
34 |
from plcopen.structures import * |
|
35 |
from graphics.GraphicCommons import * |
|
36 |
from PLCGenerator import * |
|
37 |
||
42 | 38 |
duration_model = re.compile("(?:([0-9]{1,2})h)?(?:([0-9]{1,2})m(?!s))?(?:([0-9]{1,2})s)?(?:([0-9]{1,3}(?:.[0-9]*)?)ms)?") |
24 | 39 |
|
0 | 40 |
[ITEM_UNEDITABLE, ITEM_PROJECT, ITEM_POU, ITEM_CLASS, ITEM_VARIABLE, |
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
41 |
ITEM_TRANSITION, ITEM_ACTION, ITEM_CONFIGURATION, ITEM_RESOURCE, |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
42 |
ITEM_DATATYPE] = range(10) |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
43 |
|
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
44 |
ScriptDirectory = os.path.split(os.path.realpath(__file__))[0] |
0 | 45 |
|
2 | 46 |
""" |
47 |
pyxsval is not complete and the parts that are not supported print some error |
|
48 |
reports. This class is used for not displaying them |
|
49 |
""" |
|
50 |
class HolePseudoFile: |
|
51 |
""" Base class for file like objects to facilitate StdOut for the Shell.""" |
|
52 |
def __init__(self, output = None): |
|
53 |
if output is None: output = [] |
|
54 |
self.output = output |
|
55 |
||
56 |
def writelines(self, l): |
|
57 |
map(self.write, l) |
|
58 |
||
59 |
def write(self, s): |
|
60 |
pass |
|
61 |
||
62 |
def flush(self): |
|
63 |
pass |
|
64 |
||
65 |
def isatty(self): |
|
66 |
return false |
|
67 |
||
0 | 68 |
#------------------------------------------------------------------------------- |
69 |
# Undo Buffer for PLCOpenEditor |
|
70 |
#------------------------------------------------------------------------------- |
|
71 |
||
72 |
# Length of the buffer |
|
73 |
UNDO_BUFFER_LENGTH = 20 |
|
74 |
||
75 |
""" |
|
76 |
Class implementing a buffer of changes made on the current editing Object Dictionary |
|
77 |
""" |
|
78 |
class UndoBuffer: |
|
79 |
||
80 |
# Constructor initialising buffer |
|
81 |
def __init__(self, currentstate, issaved = False): |
|
82 |
self.Buffer = [] |
|
83 |
self.CurrentIndex = -1 |
|
84 |
self.MinIndex = -1 |
|
85 |
self.MaxIndex = -1 |
|
86 |
# if current state is defined |
|
87 |
if currentstate: |
|
88 |
self.CurrentIndex = 0 |
|
89 |
self.MinIndex = 0 |
|
90 |
self.MaxIndex = 0 |
|
91 |
# Initialising buffer with currentstate at the first place |
|
92 |
for i in xrange(UNDO_BUFFER_LENGTH): |
|
93 |
if i == 0: |
|
94 |
self.Buffer.append(currentstate) |
|
95 |
else: |
|
96 |
self.Buffer.append(None) |
|
97 |
# Initialising index of state saved |
|
98 |
if issaved: |
|
99 |
self.LastSave = 0 |
|
100 |
else: |
|
101 |
self.LastSave = -1 |
|
102 |
||
103 |
# Add a new state in buffer |
|
104 |
def Buffering(self, currentstate): |
|
105 |
self.CurrentIndex = (self.CurrentIndex + 1) % UNDO_BUFFER_LENGTH |
|
106 |
self.Buffer[self.CurrentIndex] = currentstate |
|
107 |
# Actualising buffer limits |
|
108 |
self.MaxIndex = self.CurrentIndex |
|
109 |
if self.MinIndex == self.CurrentIndex: |
|
110 |
# If the removed state was the state saved, there is no state saved in the buffer |
|
111 |
if self.LastSave == self.MinIndex: |
|
112 |
self.LastSave = -1 |
|
113 |
self.MinIndex = (self.MinIndex + 1) % UNDO_BUFFER_LENGTH |
|
114 |
self.MinIndex = max(self.MinIndex, 0) |
|
115 |
||
116 |
# Return current state of buffer |
|
117 |
def Current(self): |
|
118 |
return self.Buffer[self.CurrentIndex] |
|
119 |
||
120 |
# Change current state to previous in buffer and return new current state |
|
121 |
def Previous(self): |
|
122 |
if self.CurrentIndex != self.MinIndex: |
|
123 |
self.CurrentIndex = (self.CurrentIndex - 1) % UNDO_BUFFER_LENGTH |
|
124 |
return self.Buffer[self.CurrentIndex] |
|
125 |
return None |
|
126 |
||
127 |
# Change current state to next in buffer and return new current state |
|
128 |
def Next(self): |
|
129 |
if self.CurrentIndex != self.MaxIndex: |
|
130 |
self.CurrentIndex = (self.CurrentIndex + 1) % UNDO_BUFFER_LENGTH |
|
131 |
return self.Buffer[self.CurrentIndex] |
|
132 |
return None |
|
133 |
||
134 |
# Return True if current state is the first in buffer |
|
135 |
def IsFirst(self): |
|
136 |
return self.CurrentIndex == self.MinIndex |
|
137 |
||
138 |
# Return True if current state is the last in buffer |
|
139 |
def IsLast(self): |
|
140 |
return self.CurrentIndex == self.MaxIndex |
|
141 |
||
142 |
# Note that current state is saved |
|
143 |
def CurrentSaved(self): |
|
144 |
self.LastSave = self.CurrentIndex |
|
145 |
||
146 |
# Return True if current state is saved |
|
147 |
def IsCurrentSaved(self): |
|
148 |
return self.LastSave == self.CurrentIndex |
|
149 |
||
150 |
||
151 |
#------------------------------------------------------------------------------- |
|
152 |
# Controler for PLCOpenEditor |
|
153 |
#------------------------------------------------------------------------------- |
|
154 |
||
155 |
""" |
|
156 |
Class which controls the operations made on the plcopen model and answers to view requests |
|
157 |
""" |
|
158 |
class PLCControler: |
|
159 |
||
160 |
# Create a new PLCControler |
|
161 |
def __init__(self): |
|
162 |
self.LastNewIndex = 0 |
|
163 |
self.Reset() |
|
164 |
||
165 |
# Reset PLCControler internal variables |
|
166 |
def Reset(self): |
|
27 | 167 |
self.VerifyXML = False |
0 | 168 |
self.Project = None |
169 |
self.ProjectBuffer = None |
|
56
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
170 |
self.Buffering = False |
0 | 171 |
self.FilePath = "" |
172 |
self.FileName = "" |
|
42 | 173 |
self.ProgramFilePath = "" |
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
174 |
self.RefreshDataTypeUsingTree() |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
175 |
self.RefreshDataTypes() |
0 | 176 |
self.RefreshPouUsingTree() |
177 |
self.RefreshBlockTypes() |
|
178 |
||
179 |
def GetQualifierTypes(self): |
|
180 |
return plcopen.QualifierList |
|
181 |
||
182 |
||
183 |
#------------------------------------------------------------------------------- |
|
184 |
# Project management functions |
|
185 |
#------------------------------------------------------------------------------- |
|
186 |
||
187 |
# Return if a project is opened |
|
188 |
def HasOpenedProject(self): |
|
189 |
return self.Project != None |
|
190 |
||
191 |
# Create a new project by replacing the current one |
|
145 | 192 |
def CreateNewProject(self, properties): |
0 | 193 |
# Create the project |
194 |
self.Project = plcopen.project() |
|
145 | 195 |
properties["creationDateTime"] = datetime(*localtime()[:6]) |
196 |
self.Project.setFileHeader(properties) |
|
197 |
self.Project.setContentHeader(properties) |
|
56
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
198 |
self.SetFilePath("") |
0 | 199 |
# Initialize the project buffer |
56
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
200 |
self.ProjectBuffer = UndoBuffer(self.Copy(self.Project), False) |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
201 |
self.Buffering = False |
0 | 202 |
|
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
203 |
# Return project data type names |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
204 |
def GetProjectDataTypeNames(self): |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
205 |
if self.Project: |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
206 |
return [datatype.getName() for datatype in self.Project.getDataTypes()] |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
207 |
return [] |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
208 |
|
0 | 209 |
# Return project pou names |
210 |
def GetProjectPouNames(self): |
|
80 | 211 |
if self.Project: |
212 |
return [pou.getName() for pou in self.Project.getPous()] |
|
213 |
return [] |
|
0 | 214 |
|
215 |
# Return project pou names |
|
216 |
def GetProjectConfigNames(self): |
|
80 | 217 |
if self.Project: |
218 |
return [config.getName() for config in self.Project.getConfigurations()] |
|
219 |
return [] |
|
0 | 220 |
|
6 | 221 |
# Return project pou variables |
222 |
def GetProjectPouVariables(self, pou_name=None): |
|
223 |
variables = [] |
|
224 |
for pou in self.Project.getPous(): |
|
225 |
if not pou_name or pou_name == pou.getName(): |
|
226 |
variables.extend([var["Name"] for var in self.GetPouInterfaceVars(pou)]) |
|
70 | 227 |
for transition in pou.getTransitionList(): |
228 |
variables.append(transition.getName()) |
|
229 |
for action in pou.getActionList(): |
|
230 |
variables.append(action.getName()) |
|
6 | 231 |
return variables |
232 |
||
56
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
233 |
# Return if project is saved |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
234 |
def ProjectIsSaved(self): |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
235 |
return self.ProjectBuffer.IsCurrentSaved() |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
236 |
|
0 | 237 |
# Return file path if project is an open file |
238 |
def GetFilePath(self): |
|
239 |
return self.FilePath |
|
240 |
||
42 | 241 |
# Return file path if project is an open file |
242 |
def GetProgramFilePath(self): |
|
243 |
return self.ProgramFilePath |
|
244 |
||
0 | 245 |
# Return file name and point out if file is up to date |
246 |
def GetFilename(self): |
|
247 |
if self.ProjectBuffer.IsCurrentSaved(): |
|
248 |
return self.FileName |
|
249 |
else: |
|
250 |
return "~%s~"%self.FileName |
|
251 |
||
252 |
# Change file path and save file name or create a default one if file path not defined |
|
253 |
def SetFilePath(self, filepath): |
|
254 |
self.FilePath = filepath |
|
255 |
if filepath == "": |
|
256 |
self.LastNewIndex += 1 |
|
257 |
self.FileName = "Unnamed%d"%self.LastNewIndex |
|
258 |
else: |
|
259 |
self.FileName = os.path.splitext(os.path.basename(filepath))[0] |
|
260 |
||
261 |
# Change project properties |
|
56
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
262 |
def SetProjectProperties(self, name = None, properties = None): |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
263 |
if name != None: |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
264 |
self.Project.setName(name) |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
265 |
if properties != None: |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
266 |
self.Project.setFileHeader(properties) |
145 | 267 |
self.Project.setContentHeader(properties) |
56
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
268 |
if name != None or properties != None: |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
269 |
self.BufferProject() |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
270 |
|
0 | 271 |
# Return project properties |
272 |
def GetProjectProperties(self): |
|
56
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
273 |
properties = self.Project.getFileHeader() |
145 | 274 |
properties.update(self.Project.getContentHeader()) |
56
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
275 |
return properties |
0 | 276 |
|
277 |
# Return project informations |
|
278 |
def GetProjectInfos(self): |
|
279 |
if self.Project: |
|
280 |
infos = {"name": self.Project.getName(), "type": ITEM_PROJECT} |
|
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
281 |
datatypes = {"name": "Data Types", "type": ITEM_UNEDITABLE, "values":[]} |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
282 |
for datatype in self.Project.getDataTypes(): |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
283 |
datatypes["values"].append({"name": datatype.getName(), "type": ITEM_DATATYPE, "values": []}) |
0 | 284 |
pou_types = {"function": {"name": "Functions", "type": ITEM_UNEDITABLE, "values":[]}, |
285 |
"functionBlock": {"name": "Function Blocks", "type": ITEM_UNEDITABLE, "values":[]}, |
|
286 |
"program": {"name": "Programs", "type": ITEM_UNEDITABLE, "values":[]}} |
|
287 |
for pou in self.Project.getPous(): |
|
288 |
pou_type = pou.getPouType().getValue() |
|
289 |
pou_infos = {"name": pou.getName(), "type": ITEM_POU} |
|
290 |
pou_values = [] |
|
291 |
if pou.getBodyType() == "SFC": |
|
292 |
transitions = [] |
|
293 |
for transition in pou.getTransitionList(): |
|
294 |
transitions.append({"name": transition.getName(), "type": ITEM_TRANSITION, "values": []}) |
|
295 |
pou_values.append({"name": "Transitions", "type": ITEM_UNEDITABLE, "values": transitions}) |
|
296 |
actions = [] |
|
297 |
for action in pou.getActionList(): |
|
298 |
actions.append({"name": action.getName(), "type": ITEM_ACTION, "values": []}) |
|
299 |
pou_values.append({"name": "Actions", "type": ITEM_UNEDITABLE, "values": actions}) |
|
300 |
if pou_type in pou_types: |
|
301 |
pou_infos["values"] = pou_values |
|
302 |
pou_types[pou_type]["values"].append(pou_infos) |
|
303 |
configurations = {"name": "Configurations", "type": ITEM_UNEDITABLE, "values": []} |
|
304 |
for config in self.Project.getConfigurations(): |
|
305 |
config_name = config.getName() |
|
306 |
config_infos = {"name": config_name, "type": ITEM_CONFIGURATION, "values": []} |
|
307 |
resources = {"name": "Resources", "type": ITEM_UNEDITABLE, "values": []} |
|
308 |
for resource in config.getResource(): |
|
309 |
resource_name = resource.getName() |
|
310 |
resource_infos = {"name": resource_name, "type": ITEM_RESOURCE, "values": []} |
|
311 |
resources["values"].append(resource_infos) |
|
47
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
46
diff
changeset
|
312 |
config_infos["values"] = [resources] |
0 | 313 |
configurations["values"].append(config_infos) |
314 |
infos["values"] = [{"name": "Properties", "type": ITEM_UNEDITABLE, "values": []}, |
|
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
315 |
datatypes, pou_types["function"], pou_types["functionBlock"], |
0 | 316 |
pou_types["program"], configurations] |
317 |
return infos |
|
318 |
return None |
|
319 |
||
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
320 |
# Refresh the tree of user-defined data type cross-use |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
321 |
def RefreshDataTypeUsingTree(self): |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
322 |
# Reset the tree of user-defined pou cross-use |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
323 |
self.DataTypeUsingTree = {} |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
324 |
if self.Project: |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
325 |
datatypes = self.Project.getDataTypes() |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
326 |
# Reference all the user-defined data type names and initialize the tree of |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
327 |
# user-defined data type cross-use |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
328 |
datatypenames = [datatype.getName() for datatype in datatypes] |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
329 |
for name in datatypenames: |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
330 |
self.DataTypeUsingTree[name] = [] |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
331 |
# Analyze each data type |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
332 |
for datatype in datatypes: |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
333 |
name = datatype.getName() |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
334 |
basetype_content = datatype.getBaseType().getContent() |
141 | 335 |
if basetype_content["name"] == "derived": |
336 |
basetype_name = basetype_content["value"].getName() |
|
337 |
if basetype_name in datatypenames and name not in self.DataTypeUsingTree[basetype_name]: |
|
338 |
self.DataTypeUsingTree[basetype_name].append(name) |
|
339 |
elif basetype_content["name"] in ["subrangeSigned", "subrangeUnsigned", "array"]: |
|
340 |
base_type = basetype_content["value"].baseType.getContent() |
|
341 |
if base_type["value"] is not None: |
|
342 |
basetype_name = base_type["value"].getName() |
|
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
343 |
if basetype_name in datatypenames and name not in self.DataTypeUsingTree[basetype_name]: |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
344 |
self.DataTypeUsingTree[basetype_name].append(name) |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
345 |
|
0 | 346 |
# Refresh the tree of user-defined pou cross-use |
347 |
def RefreshPouUsingTree(self): |
|
348 |
# Reset the tree of user-defined pou cross-use |
|
349 |
self.PouUsingTree = {} |
|
350 |
if self.Project: |
|
351 |
pous = self.Project.getPous() |
|
352 |
# Reference all the user-defined pou names and initialize the tree of |
|
353 |
# user-defined pou cross-use |
|
354 |
pounames = [pou.getName() for pou in pous] |
|
355 |
for name in pounames: |
|
356 |
self.PouUsingTree[name] = [] |
|
357 |
# Analyze each pou |
|
358 |
for pou in pous: |
|
359 |
name = pou.getName() |
|
71 | 360 |
if pou.interface: |
361 |
# Extract variables from every varLists |
|
362 |
for type, varlist in pou.getVars(): |
|
363 |
for var in varlist.getVariable(): |
|
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
364 |
vartype_content = var.getType().getContent() |
141 | 365 |
if vartype_content["name"] == "derived": |
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
366 |
typename = vartype_content["value"].getName() |
71 | 367 |
if typename in pounames and name not in self.PouUsingTree[typename]: |
368 |
self.PouUsingTree[typename].append(name) |
|
0 | 369 |
bodytype = pou.getBodyType() |
370 |
# If pou is written in a graphical language |
|
371 |
if bodytype in ["FBD","LD","SFC"]: |
|
372 |
# Analyze each instance of the pou |
|
373 |
for instance in pou.getInstances(): |
|
374 |
if isinstance(instance, plcopen.block): |
|
375 |
typename = instance.getTypeName() |
|
376 |
# Update tree if there is a cross-use |
|
377 |
if typename in pounames and name not in self.PouUsingTree[typename]: |
|
378 |
self.PouUsingTree[typename].append(name) |
|
379 |
# If pou is written in a textual language |
|
380 |
elif bodytype in ["IL", "ST"]: |
|
381 |
text = pou.getText() |
|
382 |
# Search if each pou is mentioned in the pou text |
|
383 |
for typename in pounames: |
|
384 |
typename_model = re.compile("[ \t\n]%s[ \t\n]"%typename) |
|
385 |
# Update tree if there is a cross-use |
|
386 |
if typename != name and typename_model.search(text): |
|
387 |
self.PouUsingTree[typename].append(name) |
|
388 |
||
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
389 |
# Return if data type given by name is used by another data type or pou |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
390 |
def DataTypeIsUsed(self, name): |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
391 |
if name in self.DataTypeUsingTree: |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
392 |
return len(self.DataTypeUsingTree[name]) > 0 |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
393 |
return False |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
394 |
|
0 | 395 |
# Return if pou given by name is used by another pou |
396 |
def PouIsUsed(self, name): |
|
397 |
if name in self.PouUsingTree: |
|
398 |
return len(self.PouUsingTree[name]) > 0 |
|
399 |
return False |
|
400 |
||
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
401 |
# Return if data type given by name is directly or undirectly used by the reference data type |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
402 |
def DataTypeIsUsedBy(self, name, reference): |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
403 |
if name in self.DataTypeUsingTree: |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
404 |
list = self.DataTypeUsingTree[name] |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
405 |
# Test if data type is directly used by reference |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
406 |
if reference in list: |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
407 |
return True |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
408 |
else: |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
409 |
# Test if data type is undirectly used by reference, by testing if data types |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
410 |
# that directly use data type is directly or undirectly used by reference |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
411 |
used = False |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
412 |
for element in list: |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
413 |
used |= self.DataTypeIsUsedBy(element, reference) |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
414 |
return used |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
415 |
return False |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
416 |
|
0 | 417 |
# Return if pou given by name is directly or undirectly used by the reference pou |
418 |
def PouIsUsedBy(self, name, reference): |
|
419 |
if name in self.PouUsingTree: |
|
420 |
list = self.PouUsingTree[name] |
|
421 |
# Test if pou is directly used by reference |
|
422 |
if reference in list: |
|
423 |
return True |
|
424 |
else: |
|
425 |
# Test if pou is undirectly used by reference, by testing if pous |
|
426 |
# that directly use pou is directly or undirectly used by reference |
|
427 |
used = False |
|
428 |
for element in list: |
|
429 |
used |= self.PouIsUsedBy(element, reference) |
|
430 |
return used |
|
431 |
return False |
|
432 |
||
4
2de7fd952fdd
Adding File Dialog for choosing path to generated program
lbessard
parents:
2
diff
changeset
|
433 |
def GenerateProgram(self, filepath): |
0 | 434 |
if self.Project: |
97 | 435 |
try: |
436 |
program = GenerateCurrentProgram(self.Project) |
|
437 |
programfile = open(filepath, "w") |
|
438 |
programfile.write(program) |
|
439 |
programfile.close() |
|
440 |
self.ProgramFilePath = filepath |
|
441 |
return True |
|
442 |
except: |
|
443 |
pass |
|
4
2de7fd952fdd
Adding File Dialog for choosing path to generated program
lbessard
parents:
2
diff
changeset
|
444 |
return False |
0 | 445 |
|
446 |
#------------------------------------------------------------------------------- |
|
447 |
# Project Pous management functions |
|
448 |
#------------------------------------------------------------------------------- |
|
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
449 |
|
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
450 |
# Add a Data Type to Project |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
451 |
def ProjectAddDataType(self, datatype_name): |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
452 |
# Add the pou to project |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
453 |
self.Project.appendDataType(datatype_name) |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
454 |
self.RefreshDataTypeUsingTree() |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
455 |
self.RefreshDataTypes() |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
456 |
self.BufferProject() |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
457 |
|
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
458 |
# Remove a Data Type from project |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
459 |
def ProjectRemoveDataType(self, datatype_name): |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
460 |
self.Project.removeDataType(datatype_name) |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
461 |
self.RefreshDataTypeUsingTree() |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
462 |
self.RefreshDataTypes() |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
463 |
self.BufferProject() |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
464 |
|
0 | 465 |
# Add a Pou to Project |
107 | 466 |
def ProjectAddPou(self, pou_name, pou_type, body_type): |
0 | 467 |
# Add the pou to project |
107 | 468 |
self.Project.appendPou(pou_name, pou_type, body_type) |
469 |
if pou_type == "function": |
|
470 |
self.SetPouInterfaceReturnType(pou_name, "BOOL") |
|
0 | 471 |
self.RefreshPouUsingTree() |
472 |
self.RefreshBlockTypes() |
|
56
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
473 |
self.BufferProject() |
0 | 474 |
|
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
475 |
# Remove a Pou from project |
107 | 476 |
def ProjectRemovePou(self, pou_name): |
477 |
self.Project.removePou(pou_name) |
|
0 | 478 |
self.RefreshPouUsingTree() |
479 |
self.RefreshBlockTypes() |
|
56
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
480 |
self.BufferProject() |
0 | 481 |
|
482 |
# Add a configuration to Project |
|
107 | 483 |
def ProjectAddConfiguration(self, config_name): |
484 |
self.Project.addConfiguration(config_name) |
|
56
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
485 |
self.BufferProject() |
0 | 486 |
|
487 |
# Remove a configuration from project |
|
107 | 488 |
def ProjectRemoveConfiguration(self, config_name): |
489 |
self.Project.removeConfiguration(config_name) |
|
490 |
self.BufferProject() |
|
491 |
||
492 |
# Add a resource to a configuration of the Project |
|
493 |
def ProjectAddConfigurationResource(self, config_name, resource_name): |
|
494 |
self.Project.addConfigurationResource(config_name, resource_name) |
|
56
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
495 |
self.BufferProject() |
0 | 496 |
|
497 |
# Remove a resource from a configuration of the project |
|
107 | 498 |
def ProjectRemoveConfigurationResource(self, config_name, resource_name): |
499 |
self.Project.removeConfigurationResource(config_name, resource_name) |
|
56
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
500 |
self.BufferProject() |
0 | 501 |
|
502 |
# Add a Transition to a Project Pou |
|
503 |
def ProjectAddPouTransition(self, pou_name, transition_name, transition_type): |
|
504 |
pou = self.Project.getPou(pou_name) |
|
505 |
pou.addTransition(transition_name, transition_type) |
|
56
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
506 |
self.BufferProject() |
0 | 507 |
|
107 | 508 |
# Remove a Transition from a Project Pou |
509 |
def ProjectRemovePouTransition(self, pou_name, transition_name): |
|
510 |
pou = self.Project.getPou(pou_name) |
|
511 |
pou.removeTransition(transition_name) |
|
512 |
self.BufferProject() |
|
513 |
||
514 |
# Add an Action to a Project Pou |
|
0 | 515 |
def ProjectAddPouAction(self, pou_name, action_name, action_type): |
516 |
pou = self.Project.getPou(pou_name) |
|
517 |
pou.addAction(action_name, action_type) |
|
56
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
518 |
self.BufferProject() |
107 | 519 |
|
520 |
# Remove an Action from a Project Pou |
|
521 |
def ProjectRemovePouAction(self, pou_name, action_name): |
|
522 |
# Search if the pou removed is currently opened |
|
523 |
for i, element in enumerate(self.ElementsOpened): |
|
524 |
words = element.split("::") |
|
525 |
if words[0] == "A" and words[1] == pou_name and words[2] == action_name: |
|
526 |
self.RemoveElementEditing(i) |
|
527 |
pou = self.Project.getPou(pou_name) |
|
528 |
pou.removeAction(action_name) |
|
529 |
self.BufferProject() |
|
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
530 |
|
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
531 |
# Change the name of a pou |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
532 |
def ChangeDataTypeName(self, old_name, new_name): |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
533 |
# Found the pou corresponding to old name and change its name to new name |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
534 |
datatype = self.Project.getDataType(old_name) |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
535 |
datatype.setName(new_name) |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
536 |
self.Project.updateElementName(old_name, new_name) |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
537 |
self.BufferProject() |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
538 |
|
0 | 539 |
# Change the name of a pou |
540 |
def ChangePouName(self, old_name, new_name): |
|
541 |
# Found the pou corresponding to old name and change its name to new name |
|
542 |
pou = self.Project.getPou(old_name) |
|
543 |
pou.setName(new_name) |
|
58 | 544 |
self.Project.updateElementName(old_name, new_name) |
0 | 545 |
self.RefreshPouUsingTree() |
546 |
self.RefreshBlockTypes() |
|
56
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
547 |
self.BufferProject() |
0 | 548 |
|
549 |
# Change the name of a pou transition |
|
550 |
def ChangePouTransitionName(self, pou_name, old_name, new_name): |
|
551 |
# Found the pou transition corresponding to old name and change its name to new name |
|
552 |
pou = self.Project.getPou(pou_name) |
|
553 |
transition = pou.getTransition(old_name) |
|
554 |
transition.setName(new_name) |
|
108 | 555 |
pou.updateElementName(old_name, new_name) |
56
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
556 |
self.BufferProject() |
0 | 557 |
|
558 |
# Change the name of a pou action |
|
559 |
def ChangePouActionName(self, pou_name, old_name, new_name): |
|
560 |
# Found the pou action corresponding to old name and change its name to new name |
|
561 |
pou = self.Project.getPou(pou_name) |
|
562 |
action = pou.getAction(old_name) |
|
563 |
action.setName(new_name) |
|
108 | 564 |
pou.updateElementName(old_name, new_name) |
56
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
565 |
self.BufferProject() |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
566 |
|
80 | 567 |
# Change the name of a pou variable |
6 | 568 |
def ChangePouVariableName(self, pou_name, old_name, new_name): |
569 |
# Found the pou action corresponding to old name and change its name to new name |
|
570 |
pou = self.Project.getPou(pou_name) |
|
571 |
for type, varlist in pou.getVars(): |
|
572 |
for var in varlist.getVariable(): |
|
573 |
if var.getName() == old_name: |
|
574 |
var.setName(new_name) |
|
575 |
self.RefreshBlockTypes() |
|
56
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
576 |
self.BufferProject() |
6 | 577 |
|
0 | 578 |
# Change the name of a configuration |
579 |
def ChangeConfigurationName(self, old_name, new_name): |
|
580 |
# Found the configuration corresponding to old name and change its name to new name |
|
581 |
configuration = self.Project.getConfiguration(old_name) |
|
582 |
configuration.setName(new_name) |
|
56
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
583 |
self.BufferProject() |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
584 |
|
0 | 585 |
# Change the name of a configuration resource |
586 |
def ChangeConfigurationResourceName(self, config_name, old_name, new_name): |
|
587 |
# Found the resource corresponding to old name and change its name to new name |
|
588 |
resource = self.Project.getConfigurationResource(config_name) |
|
589 |
resource.setName(new_name) |
|
56
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
590 |
self.BufferProject() |
0 | 591 |
|
592 |
# Return the type of the pou given by its name |
|
593 |
def GetPouType(self, name): |
|
594 |
# Found the pou correponding to name and return its type |
|
595 |
pou = self.Project.getPou(name) |
|
596 |
return pou.pouType.getValue() |
|
597 |
||
598 |
# Return pous with SFC language |
|
599 |
def GetSFCPous(self): |
|
600 |
list = [] |
|
601 |
if self.Project: |
|
602 |
for pou in self.Project.getPous(): |
|
603 |
if pou.getBodyType() == "SFC": |
|
604 |
list.append(pou.getName()) |
|
605 |
return list |
|
606 |
||
607 |
# Return the body language of the pou given by its name |
|
608 |
def GetPouBodyType(self, name): |
|
609 |
# Found the pou correponding to name and return its body language |
|
610 |
pou = self.Project.getPou(name) |
|
611 |
return pou.getBodyType() |
|
612 |
||
46 | 613 |
# Return the actions of a pou |
614 |
def GetPouTransitions(self, pou_name): |
|
615 |
transitions = [] |
|
616 |
pou = self.Project.getPou(pou_name) |
|
617 |
if pou.getBodyType() == "SFC": |
|
618 |
for transition in pou.getTransitionList(): |
|
619 |
transitions.append(transition.getName()) |
|
620 |
return transitions |
|
621 |
||
0 | 622 |
# Return the body language of the transition given by its name |
623 |
def GetTransitionBodyType(self, pou_name, pou_transition): |
|
624 |
# Found the pou correponding to name and return its body language |
|
625 |
pou = self.Project.getPou(pou_name) |
|
626 |
transition = pou.getTransition(pou_transition) |
|
627 |
return transition.getBodyType() |
|
628 |
||
46 | 629 |
# Return the actions of a pou |
630 |
def GetPouActions(self, pou_name): |
|
631 |
actions = [] |
|
632 |
pou = self.Project.getPou(pou_name) |
|
633 |
if pou.getBodyType() == "SFC": |
|
634 |
for action in pou.getActionList(): |
|
635 |
actions.append(action.getName()) |
|
636 |
return actions |
|
637 |
||
0 | 638 |
# Return the body language of the pou given by its name |
639 |
def GetActionBodyType(self, pou_name, pou_action): |
|
640 |
# Found the pou correponding to name and return its body language |
|
641 |
pou = self.Project.getPou(pou_name) |
|
642 |
action = pou.getAction(pou_action) |
|
643 |
return action.getBodyType() |
|
644 |
||
645 |
# Extract varlists from a list of vars |
|
646 |
def ExtractVarLists(self, vars): |
|
647 |
varlist_list = [] |
|
648 |
current_varlist = None |
|
649 |
current_type = None |
|
650 |
for var in vars: |
|
34 | 651 |
if current_type != (var["Class"], var["Retain"], var["Constant"], var["Location"] in ["", None]): |
652 |
current_type = (var["Class"], var["Retain"], var["Constant"], var["Location"] in ["", None]) |
|
0 | 653 |
current_varlist = plcopen.varList() |
654 |
varlist_list.append((var["Class"], current_varlist)) |
|
655 |
if var["Retain"] == "Yes": |
|
656 |
varlist.setRetain(True) |
|
657 |
if var["Constant"] == "Yes": |
|
658 |
varlist.setConstant(True) |
|
659 |
# Create variable and change its properties |
|
660 |
tempvar = plcopen.varListPlain_variable() |
|
661 |
tempvar.setName(var["Name"]) |
|
662 |
var_type = plcopen.dataType() |
|
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
663 |
if var["Type"] not in var_type.getChoices(): |
141 | 664 |
if var["Type"] == "STRING": |
665 |
var_type.setContent("string", plcopen.string()) |
|
666 |
elif var["Type"] == "WSTRING": |
|
667 |
var_type.setContent("wstring", plcopen.wstring()) |
|
668 |
else: |
|
669 |
derived_type = plcopen.derived() |
|
670 |
derived_type.setName(var["Type"]) |
|
671 |
var_type.setContent("derived", derived_type) |
|
67
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
672 |
else: |
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
673 |
var_type.setContent(var["Type"], None) |
0 | 674 |
tempvar.setType(var_type) |
675 |
if var["Initial Value"] != "": |
|
676 |
value = plcopen.value() |
|
677 |
value.setValue(var["Initial Value"]) |
|
678 |
tempvar.setInitialValue(value) |
|
679 |
if var["Location"] != "": |
|
680 |
tempvar.setAddress(var["Location"]) |
|
53 | 681 |
else: |
682 |
tempvar.setAddress(None) |
|
0 | 683 |
# Add variable to varList |
684 |
current_varlist.appendVariable(tempvar) |
|
685 |
return varlist_list |
|
686 |
||
687 |
# Replace the configuration globalvars by those given |
|
688 |
def SetConfigurationGlobalVars(self, name, vars): |
|
689 |
# Found the configuration corresponding to name |
|
690 |
configuration = self.Project.getConfiguration(name) |
|
691 |
if configuration: |
|
692 |
# Set configuration global vars |
|
693 |
configuration.setGlobalVars([]) |
|
694 |
for vartype, varlist in self.ExtractVarLists(vars): |
|
695 |
configuration.globalVars.append(varlist) |
|
696 |
self.RefreshBlockTypes() |
|
56
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
697 |
|
0 | 698 |
# Return the configuration globalvars |
699 |
def GetConfigurationGlobalVars(self, name): |
|
700 |
vars = [] |
|
701 |
# Found the configuration corresponding to name |
|
702 |
configuration = self.Project.getConfiguration(name) |
|
703 |
if configuration: |
|
704 |
# Extract variables from every varLists |
|
705 |
for varlist in configuration.getGlobalVars(): |
|
706 |
for var in varlist.getVariable(): |
|
67
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
707 |
tempvar = {"Name":var.getName(),"Class":"Global"} |
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
708 |
vartype_content = var.getType().getContent() |
141 | 709 |
if vartype_content["name"] == "derived": |
710 |
tempvar["Type"] = vartype_content["value"].getName() |
|
711 |
elif vartype_content["name"] in ["string", "wstring"]: |
|
712 |
tempvar["Type"] = vartype_content["name"].upper() |
|
713 |
else: |
|
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
714 |
tempvar["Type"] = vartype_content["name"] |
68
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
715 |
tempvar["Edit"] = True |
0 | 716 |
initial = var.getInitialValue() |
717 |
if initial: |
|
718 |
tempvar["Initial Value"] = initial.getValue() |
|
719 |
else: |
|
720 |
tempvar["Initial Value"] = "" |
|
53 | 721 |
address = var.getAddress() |
722 |
if address: |
|
723 |
tempvar["Location"] = address |
|
724 |
else: |
|
725 |
tempvar["Location"] = "" |
|
0 | 726 |
if varlist.getRetain(): |
727 |
tempvar["Retain"] = "Yes" |
|
728 |
else: |
|
729 |
tempvar["Retain"] = "No" |
|
730 |
if varlist.getConstant(): |
|
731 |
tempvar["Constant"] = "Yes" |
|
732 |
else: |
|
733 |
tempvar["Constant"] = "No" |
|
734 |
vars.append(tempvar) |
|
735 |
return vars |
|
736 |
||
737 |
# Replace the resource globalvars by those given |
|
738 |
def SetConfigurationResourceGlobalVars(self, config_name, name, vars): |
|
739 |
# Found the resource corresponding to name |
|
740 |
resource = self.Project.getConfigurationResource(config_name, name) |
|
741 |
# Set resource global vars |
|
742 |
if resource: |
|
743 |
resource.setGlobalVars([]) |
|
744 |
for vartype, varlist in self.ExtractVarLists(vars): |
|
745 |
resource.globalVars.append(varlist) |
|
746 |
self.RefreshBlockTypes() |
|
56
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
747 |
|
0 | 748 |
# Return the resource globalvars |
749 |
def GetConfigurationResourceGlobalVars(self, config_name, name): |
|
750 |
vars = [] |
|
751 |
# Found the resource corresponding to name |
|
752 |
resource = self.Project.getConfigurationResource(config_name, name) |
|
753 |
if resource: |
|
754 |
# Extract variables from every varLists |
|
755 |
for varlist in resource.getGlobalVars(): |
|
756 |
for var in varlist.getVariable(): |
|
67
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
757 |
tempvar = {"Name":var.getName(),"Class":"Global"} |
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
758 |
vartype_content = var.getType().getContent() |
141 | 759 |
if vartype_content["name"] == "derived": |
760 |
tempvar["Type"] = vartype_content["value"].getName() |
|
761 |
elif vartype_content["name"] in ["string", "wstring"]: |
|
762 |
tempvar["Type"] = vartype_content["name"].upper() |
|
763 |
else: |
|
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
764 |
tempvar["Type"] = vartype_content["name"] |
68
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
765 |
tempvar["Edit"] = True |
0 | 766 |
initial = var.getInitialValue() |
767 |
if initial: |
|
768 |
tempvar["Initial Value"] = initial.getValue() |
|
769 |
else: |
|
770 |
tempvar["Initial Value"] = "" |
|
53 | 771 |
address = var.getAddress() |
772 |
if address: |
|
773 |
tempvar["Location"] = address |
|
774 |
else: |
|
775 |
tempvar["Location"] = "" |
|
0 | 776 |
if varlist.getRetain(): |
777 |
tempvar["Retain"] = "Yes" |
|
778 |
else: |
|
779 |
tempvar["Retain"] = "No" |
|
780 |
if varlist.getConstant(): |
|
781 |
tempvar["Constant"] = "Yes" |
|
782 |
else: |
|
783 |
tempvar["Constant"] = "No" |
|
784 |
vars.append(tempvar) |
|
785 |
return vars |
|
786 |
||
787 |
# Return the interface of the pou given by its name |
|
788 |
def GetPouInterfaceVarsByName(self, name): |
|
789 |
# Found the pou correponding to name and return the interface |
|
790 |
return self.GetPouInterfaceVars(self.Project.getPou(name)) |
|
791 |
||
792 |
# Return the interface for the given pou |
|
793 |
def GetPouInterfaceVars(self, pou): |
|
794 |
vars = [] |
|
795 |
# Verify that the pou has an interface |
|
796 |
if pou.interface: |
|
797 |
# Extract variables from every varLists |
|
798 |
for type, varlist in pou.getVars(): |
|
799 |
for var in varlist.getVariable(): |
|
67
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
800 |
tempvar = {"Name":var.getName(),"Class":type} |
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
801 |
vartype_content = var.getType().getContent() |
141 | 802 |
if vartype_content["name"] == "derived": |
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
803 |
tempvar["Type"] = vartype_content["value"].getName() |
68
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
804 |
tempvar["Edit"] = not pou.hasBlock(tempvar["Name"]) |
141 | 805 |
else: |
806 |
if vartype_content["name"] in ["string", "wstring"]: |
|
807 |
tempvar["Type"] = vartype_content["name"].upper() |
|
808 |
else: |
|
809 |
tempvar["Type"] = vartype_content["name"] |
|
810 |
tempvar["Edit"] = True |
|
0 | 811 |
initial = var.getInitialValue() |
812 |
if initial: |
|
813 |
tempvar["Initial Value"] = initial.getValue() |
|
814 |
else: |
|
815 |
tempvar["Initial Value"] = "" |
|
53 | 816 |
address = var.getAddress() |
817 |
if address: |
|
818 |
tempvar["Location"] = address |
|
819 |
else: |
|
820 |
tempvar["Location"] = "" |
|
0 | 821 |
if varlist.getRetain(): |
822 |
tempvar["Retain"] = "Yes" |
|
823 |
else: |
|
824 |
tempvar["Retain"] = "No" |
|
825 |
if varlist.getConstant(): |
|
826 |
tempvar["Constant"] = "Yes" |
|
827 |
else: |
|
828 |
tempvar["Constant"] = "No" |
|
829 |
vars.append(tempvar) |
|
830 |
return vars |
|
831 |
||
832 |
# Replace the Pou interface by the one given |
|
833 |
def SetPouInterfaceVars(self, name, vars): |
|
834 |
# Found the pou corresponding to name and add interface if there isn't one yet |
|
835 |
pou = self.Project.getPou(name) |
|
836 |
if not pou.interface: |
|
837 |
pou.interface = plcopen.pou_interface() |
|
838 |
# Set Pou interface |
|
839 |
pou.setVars(self.ExtractVarLists(vars)) |
|
71 | 840 |
self.RefreshPouUsingTree() |
0 | 841 |
self.RefreshBlockTypes() |
56
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
842 |
|
0 | 843 |
# Replace the return type of the pou given by its name (only for functions) |
844 |
def SetPouInterfaceReturnType(self, name, type): |
|
845 |
pou = self.Project.getPou(name) |
|
846 |
if not pou.interface: |
|
847 |
pou.interface = plcopen.pou_interface() |
|
848 |
# If there isn't any return type yet, add it |
|
849 |
return_type = pou.interface.getReturnType() |
|
850 |
if not return_type: |
|
851 |
return_type = plcopen.dataType() |
|
852 |
pou.interface.setReturnType(return_type) |
|
853 |
# Change return type |
|
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
854 |
if type in self.GetBaseTypes(): |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
855 |
return_type.setContent(type, None) |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
856 |
else: |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
857 |
derived_type = plcopen.derived() |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
858 |
derived_type.setName(type) |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
859 |
return_type.setContent("derived", derived_type) |
0 | 860 |
self.RefreshBlockTypes() |
58 | 861 |
|
862 |
def UpdateProjectUsedPous(self, old_name, new_name): |
|
863 |
if self.Project: |
|
864 |
self.Project.updateElementName(old_name, new_name) |
|
865 |
||
121 | 866 |
def UpdateEditedElementUsedVariable(self, tagname, old_name, new_name): |
867 |
pou = self.GetEditedElement(tagname) |
|
58 | 868 |
if pou: |
869 |
pou.updateElementName(old_name, new_name) |
|
0 | 870 |
|
871 |
# Return the return type of the pou given by its name |
|
872 |
def GetPouInterfaceReturnTypeByName(self, name): |
|
873 |
# Found the pou correponding to name and return the return type |
|
874 |
return self.GetPouInterfaceReturnType(self.Project.getPou(name)) |
|
875 |
||
876 |
# Return the return type of the given pou |
|
877 |
def GetPouInterfaceReturnType(self, pou): |
|
878 |
# Verify that the pou has an interface |
|
879 |
if pou.interface: |
|
880 |
# Return the return type if there is one |
|
881 |
return_type = pou.interface.getReturnType() |
|
882 |
if return_type: |
|
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
883 |
returntype_content = return_type.getContent() |
141 | 884 |
if returntype_content["name"] == "derived": |
885 |
return returntype_content["value"].getName() |
|
886 |
elif returntype_content["name"] in ["string", "wstring"]: |
|
887 |
return returntype_content["name"].upper() |
|
888 |
else: |
|
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
889 |
return returntype_content["name"] |
0 | 890 |
return None |
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
891 |
|
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
892 |
# Update data types with user-defined data types added |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
893 |
def RefreshDataTypes(self): |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
894 |
ResetTypeHierarchy() |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
895 |
ResetEnumeratedDataValues() |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
896 |
if self.Project: |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
897 |
for datatype in self.Project.getDataTypes(): |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
898 |
name = datatype.getName() |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
899 |
basetype_content = datatype.getBaseType().getContent() |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
900 |
if basetype_content["value"] is None: |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
901 |
AddDataTypeHierarchy(name, basetype_content["name"]) |
141 | 902 |
elif basetype_content["name"] in ["string", "wstring"]: |
903 |
AddDataTypeHierarchy(name, basetype_content["name"].upper()) |
|
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
904 |
elif basetype_content["name"] == "derived": |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
905 |
AddDataTypeHierarchy(name, basetype_content["value"].getName()) |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
906 |
elif basetype_content["name"] in ["subrangeSigned", "subrangeUnsigned"]: |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
907 |
base_type = basetype_content["value"].baseType.getContent() |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
908 |
if base_type["value"] is None: |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
909 |
AddDataTypeHierarchy(name, base_type["name"]) |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
910 |
else: |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
911 |
AddDataTypeHierarchy(name, base_type["value"].getName()) |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
912 |
else: |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
913 |
if basetype_content["name"] == "enum": |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
914 |
values = [] |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
915 |
for value in basetype_content["value"].values.getValue(): |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
916 |
values.append(value.getName()) |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
917 |
AddEnumeratedDataValues(values) |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
918 |
AddDataTypeHierarchy(name, "ANY_DERIVED") |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
919 |
|
0 | 920 |
# Update Block types with user-defined pou added |
921 |
def RefreshBlockTypes(self): |
|
922 |
if BlockTypes[-1]["name"] == "User-defined POUs": |
|
923 |
BlockTypes[-1]["list"] = [] |
|
924 |
else: |
|
925 |
BlockTypes.append({"name" : "User-defined POUs", "list": []}) |
|
926 |
if self.Project: |
|
927 |
for pou in self.Project.getPous(): |
|
928 |
pou_name = pou.getName() |
|
929 |
pou_type = pou.pouType.getValue() |
|
930 |
if pou_type != "program": |
|
931 |
block_infos = {"name" : pou_name, "type" : pou_type, "extensible" : False, |
|
81 | 932 |
"inputs" : [], "outputs" : [], "comment" : "", |
100 | 933 |
"generate" : generate_block, "initialise" : initialise_block } |
0 | 934 |
if pou.getInterface(): |
935 |
for type, varlist in pou.getVars(): |
|
936 |
if type == "InOut": |
|
937 |
for var in varlist.getVariable(): |
|
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
938 |
var_type = var.type.getContent() |
141 | 939 |
if var_type["name"] == "derived": |
940 |
block_infos["inputs"].append((var.getName(),var_type["value"].getName(),"none")) |
|
941 |
block_infos["outputs"].append((var.getName(),var_type["value"].getName(),"none")) |
|
942 |
elif var_type["name"] in ["string", "wstring"]: |
|
943 |
block_infos["inputs"].append((var.getName(),var_type["name"].upper(),"none")) |
|
944 |
block_infos["outputs"].append((var.getName(),var_type["name"].upper(),"none")) |
|
945 |
else: |
|
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
946 |
block_infos["inputs"].append((var.getName(),var_type["name"],"none")) |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
947 |
block_infos["outputs"].append((var.getName(),var_type["name"],"none")) |
0 | 948 |
elif type == "Input": |
949 |
for var in varlist.getVariable(): |
|
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
950 |
var_type = var.type.getContent() |
141 | 951 |
if var_type["name"] == "derived": |
952 |
block_infos["inputs"].append((var.getName(),var_type["value"].getName(),"none")) |
|
953 |
elif var_type["name"] in ["string", "wstring"]: |
|
954 |
block_infos["inputs"].append((var.getName(),var_type["name"].upper(),"none")) |
|
955 |
else: |
|
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
956 |
block_infos["inputs"].append((var.getName(),var_type["name"],"none")) |
0 | 957 |
elif type == "Output": |
958 |
for var in varlist.getVariable(): |
|
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
959 |
var_type = var.type.getContent() |
141 | 960 |
if var_type["name"] == "derived": |
961 |
block_infos["outputs"].append((var.getName(),var_type["value"].getName(),"none")) |
|
962 |
elif var_type["name"] in ["string", "wstring"]: |
|
963 |
block_infos["outputs"].append((var.getName(),var_type["name"].upper(),"none")) |
|
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
964 |
else: |
141 | 965 |
block_infos["outputs"].append((var.getName(),var_type["name"],"none")) |
0 | 966 |
return_type = pou.interface.getReturnType() |
967 |
if return_type: |
|
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
968 |
var_type = return_type.getContent() |
141 | 969 |
if var_type["name"] == "derived": |
970 |
block_infos["outputs"].append(("",var_type["value"].getName(),"none")) |
|
971 |
elif var_type["name"] in ["string", "wstring"]: |
|
972 |
block_infos["outputs"].append(("",var_type["name"].upper(),"none")) |
|
973 |
else: |
|
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
974 |
block_infos["outputs"].append(("",var_type["name"],"none")) |
0 | 975 |
if pou.getBodyType() in ["FBD","LD","SFC"]: |
976 |
for instance in pou.getInstances(): |
|
977 |
if isinstance(instance, plcopen.comment): |
|
978 |
block_infos["comment"] = instance.getContentText() |
|
979 |
BlockTypes[-1]["list"].append(block_infos) |
|
92
76d5001393df
Adding support for refreshing PLCOpenEditor block list
lbessard
parents:
90
diff
changeset
|
980 |
|
0 | 981 |
# Return Block types checking for recursion |
121 | 982 |
def GetBlockTypes(self, tagname = ""): |
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
983 |
name = "" |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
984 |
type = None |
121 | 985 |
if self.Project: |
986 |
words = tagname.split("::") |
|
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
987 |
if words[0] in ["P","T","A"]: |
121 | 988 |
name = words[1] |
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
989 |
type = self.GetPouType(name) |
121 | 990 |
if type == "function": |
991 |
blocktypes = [] |
|
992 |
for category in BlockTypes[:-1] + PluginTypes: |
|
993 |
cat = {"name" : category["name"], "list" : []} |
|
994 |
for block in category["list"]: |
|
995 |
if block["type"] == "function": |
|
996 |
cat["list"].append(block) |
|
997 |
if len(cat["list"]) > 0: |
|
998 |
blocktypes.append(cat) |
|
999 |
else: |
|
1000 |
blocktypes = [category for category in BlockTypes[:-1] + PluginTypes] |
|
1001 |
if self.Project: |
|
1002 |
blocktypes.append({"name" : "User-defined POUs", "list": []}) |
|
1003 |
for blocktype in BlockTypes[-1]["list"]: |
|
1004 |
if blocktype["name"] != name and not self.PouIsUsedBy(name, blocktype["name"]) and not (type == "function" and blocktype["type"] != "function"): |
|
1005 |
blocktypes[-1]["list"].append(blocktype) |
|
1006 |
return blocktypes |
|
1007 |
||
1008 |
# Return Function Block types checking for recursion |
|
1009 |
def GetFunctionBlockTypes(self, tagname = ""): |
|
1010 |
name = "" |
|
1011 |
type = None |
|
1012 |
if self.Project: |
|
1013 |
words = tagname.split("::") |
|
1014 |
if words[0] in ["P","T","A"]: |
|
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
1015 |
name = words[1] |
13
69075340d6a9
Adding support for forbidding insertion of function block into function
lbessard
parents:
6
diff
changeset
|
1016 |
type = self.GetPouType(name) |
121 | 1017 |
blocktypes = [] |
1018 |
for category in BlockTypes[:-1]: |
|
1019 |
for block in category["list"]: |
|
1020 |
if block["type"] != "function": |
|
1021 |
blocktypes.append(block["name"]) |
|
1022 |
if self.Project: |
|
1023 |
for blocktype in BlockTypes[-1]["list"]: |
|
1024 |
if blocktype["name"] != name and not self.PouIsUsedBy(name, blocktype["name"]) and not (type == "function" and blocktype["type"] != "function"): |
|
1025 |
blocktypes.append(blocktype["name"]) |
|
1026 |
return blocktypes |
|
68
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
1027 |
|
0 | 1028 |
# Return Block types checking for recursion |
1029 |
def GetBlockResource(self): |
|
1030 |
blocktypes = [] |
|
1031 |
for category in BlockTypes[:-1]: |
|
1032 |
for blocktype in category["list"]: |
|
29 | 1033 |
if blocktype["type"] == "program": |
0 | 1034 |
blocktypes.append(blocktype["name"]) |
1035 |
if self.Project: |
|
1036 |
for pou in self.Project.getPous(): |
|
29 | 1037 |
if pou.pouType.getValue() == "program": |
0 | 1038 |
blocktypes.append(pou.getName()) |
1039 |
return blocktypes |
|
1040 |
||
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
1041 |
# Return Data Types checking for recursion |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
1042 |
def GetDataTypes(self, tagname = "", basetypes = True): |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
1043 |
if basetypes: |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
1044 |
datatypes = self.GetBaseTypes() |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
1045 |
else: |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
1046 |
datatypes = [] |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
1047 |
if self.Project: |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
1048 |
words = tagname.split("::") |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
1049 |
if words[0] in ["D"]: |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
1050 |
name = words[1] |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
1051 |
else: |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
1052 |
name = "" |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
1053 |
for datatype in self.Project.getDataTypes(): |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
1054 |
datatype_name = datatype.getName() |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
1055 |
if datatype_name != name and not self.DataTypeIsUsedBy(name, datatype_name): |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
1056 |
datatypes.append(datatype_name) |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
1057 |
return datatypes |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
1058 |
|
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
1059 |
# Return Base Types |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
1060 |
def GetBaseTypes(self): |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
1061 |
return [value for value, parent in TypeHierarchy_list if not value.startswith("ANY")] |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
1062 |
|
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
1063 |
# Return Subrange types |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
1064 |
def GetSubrangeTypes(self): |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
1065 |
return [value for value, range in DataTypeRange_list] |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
1066 |
|
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
1067 |
# Return Enumerated Values |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
1068 |
def GetEnumeratedDataValues(self): |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
1069 |
return EnumeratedDataValues |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
1070 |
|
0 | 1071 |
#------------------------------------------------------------------------------- |
121 | 1072 |
# Project Element tag name computation functions |
0 | 1073 |
#------------------------------------------------------------------------------- |
1074 |
||
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
1075 |
# Compute a data type name |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
1076 |
def ComputeDataTypeName(self, datatype): |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
1077 |
return "D::%s" % datatype |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
1078 |
|
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
1079 |
# Compute a pou name |
80 | 1080 |
def ComputePouName(self, pou): |
1081 |
return "P::%s" % pou |
|
1082 |
||
1083 |
# Compute a pou transition name |
|
0 | 1084 |
def ComputePouTransitionName(self, pou, transition): |
1085 |
return "T::%s::%s" % (pou, transition) |
|
1086 |
||
1087 |
# Compute a pou action name |
|
1088 |
def ComputePouActionName(self, pou, action): |
|
1089 |
return "A::%s::%s" % (pou, action) |
|
1090 |
||
1091 |
# Compute a pou name |
|
47
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
46
diff
changeset
|
1092 |
def ComputeConfigurationName(self, config): |
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
46
diff
changeset
|
1093 |
return "C::%s" % config |
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
46
diff
changeset
|
1094 |
|
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
46
diff
changeset
|
1095 |
# Compute a pou name |
0 | 1096 |
def ComputeConfigurationResourceName(self, config, resource): |
1097 |
return "R::%s::%s" % (config, resource) |
|
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
1098 |
|
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
1099 |
#------------------------------------------------------------------------------- |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
1100 |
# Project opened Data types management functions |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
1101 |
#------------------------------------------------------------------------------- |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
1102 |
|
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
1103 |
# Return the data type informations |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
1104 |
def GetDataTypeInfos(self, tagname): |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
1105 |
words = tagname.split("::") |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
1106 |
if words[0] == "D": |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
1107 |
infos = {} |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
1108 |
datatype = self.Project.getDataType(words[1]) |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
1109 |
basetype_content = datatype.baseType.getContent() |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
1110 |
if basetype_content["value"] is None: |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
1111 |
infos["type"] = "Directly" |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
1112 |
infos["base_type"] = basetype_content["name"] |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
1113 |
elif basetype_content["name"] == "derived": |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
1114 |
infos["type"] = "Directly" |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
1115 |
infos["base_type"] = basetype_content["value"].getName() |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
1116 |
elif basetype_content["name"] in ["subrangeSigned", "subrangeUnsigned"]: |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
1117 |
infos["type"] = "Subrange" |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
1118 |
infos["min"] = basetype_content["value"].range.getLower() |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
1119 |
infos["max"] = basetype_content["value"].range.getUpper() |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
1120 |
base_type = basetype_content["value"].baseType.getContent() |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
1121 |
if base_type["value"] is None: |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
1122 |
infos["base_type"] = base_type["name"] |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
1123 |
else: |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
1124 |
infos["base_type"] = base_type["value"].getName() |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
1125 |
elif basetype_content["name"] == "enum": |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
1126 |
infos["type"] = "Enumerated" |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
1127 |
infos["values"] = [] |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
1128 |
for value in basetype_content["value"].values.getValue(): |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
1129 |
infos["values"].append(value.getName()) |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
1130 |
elif basetype_content["name"] == "array": |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
1131 |
infos["type"] = "Array" |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
1132 |
infos["dimensions"] = [] |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
1133 |
for dimension in basetype_content["value"].getDimension(): |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
1134 |
infos["dimensions"].append(str(dimension.getUpper())) |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
1135 |
base_type = basetype_content["value"].baseType.getContent() |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
1136 |
if base_type["value"] is None: |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
1137 |
infos["base_type"] = base_type["name"] |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
1138 |
else: |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
1139 |
infos["base_type"] = base_type["value"].getName() |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
1140 |
if datatype.initialValue is not None: |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
1141 |
infos["initial"] = str(datatype.initialValue.getValue()) |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
1142 |
else: |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
1143 |
infos["initial"] = "" |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
1144 |
return infos |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
1145 |
return None |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
1146 |
|
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
1147 |
# Change the data type informations |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
1148 |
def SetDataTypeInfos(self, tagname, infos): |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
1149 |
words = tagname.split("::") |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
1150 |
if words[0] == "D": |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
1151 |
datatype = self.Project.getDataType(words[1]) |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
1152 |
if infos["type"] == "Directly": |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
1153 |
if infos["base_type"] in self.GetBaseTypes(): |
141 | 1154 |
if infos["base_type"] == "STRING": |
1155 |
datatype.baseType.setContent("string", plcopen.string()) |
|
1156 |
elif infos["base_type"] == "WSTRING": |
|
1157 |
datatype.baseType.setContent("wstring", plcopen.wstring()) |
|
1158 |
else: |
|
1159 |
datatype.baseType.setContent(infos["base_type"], None) |
|
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
1160 |
else: |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
1161 |
derived_datatype = plcopen.derived() |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
1162 |
derived_datatype.setName(infos["base_type"]) |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
1163 |
datatype.baseType.setContent("derived", derived_datatype) |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
1164 |
elif infos["type"] == "Subrange": |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
1165 |
if infos["base_type"] in GetSubTypes("ANY_UINT"): |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
1166 |
subrange = plcopen.subrangeUnsigned() |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
1167 |
datatype.baseType.setContent("subrangeUnsigned", subrange) |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
1168 |
else: |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
1169 |
subrange = plcopen.subrangeSigned() |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
1170 |
datatype.baseType.setContent("subrangeSigned", subrange) |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
1171 |
subrange.range.setLower(infos["min"]) |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
1172 |
subrange.range.setUpper(infos["max"]) |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
1173 |
if infos["base_type"] in self.GetBaseTypes(): |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
1174 |
subrange.baseType.setContent(infos["base_type"], None) |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
1175 |
else: |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
1176 |
derived_datatype = plcopen.derived() |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
1177 |
derived_datatype.setName(infos["base_type"]) |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
1178 |
subrange.baseType.setContent("derived", derived_datatype) |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
1179 |
elif infos["type"] == "Enumerated": |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
1180 |
enumerated = plcopen.enum() |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
1181 |
for enum_value in infos["values"]: |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
1182 |
value = plcopen.values_value() |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
1183 |
value.setName(enum_value) |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
1184 |
enumerated.values.appendValue(value) |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
1185 |
datatype.baseType.setContent("enum", enumerated) |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
1186 |
elif infos["type"] == "Array": |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
1187 |
array = plcopen.array() |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
1188 |
for dimension in infos["dimensions"]: |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
1189 |
dimension_range = plcopen.rangeSigned() |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
1190 |
dimension_range.setLower(1) |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
1191 |
dimension_range.setUpper(int(dimension)) |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
1192 |
array.appendDimension(dimension_range) |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
1193 |
if infos["base_type"] in self.GetBaseTypes(): |
141 | 1194 |
if infos["base_type"] == "STRING": |
1195 |
array.baseType.setContent("string", plcopen.string()) |
|
1196 |
elif infos["base_type"] == "WSTRING": |
|
1197 |
array.baseType.setContent("wstring", plcopen.wstring()) |
|
1198 |
else: |
|
1199 |
array.baseType.setContent(infos["base_type"], None) |
|
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
1200 |
else: |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
1201 |
derived_datatype = plcopen.derived() |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
1202 |
derived_datatype.setName(infos["base_type"]) |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
1203 |
array.baseType.setContent("derived", derived_datatype) |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
1204 |
datatype.baseType.setContent("array", array) |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
1205 |
if infos["initial"] != "": |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
1206 |
if datatype.initialValue is None: |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
1207 |
datatype.initialValue = plcopen.value() |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
1208 |
datatype.initialValue.setValue(infos["initial"]) |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
1209 |
else: |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
1210 |
datatype.initialValue = None |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
1211 |
self.RefreshDataTypeUsingTree() |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
1212 |
self.RefreshDataTypes() |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
1213 |
self.BufferProject() |
0 | 1214 |
|
1215 |
#------------------------------------------------------------------------------- |
|
1216 |
# Project opened Pous management functions |
|
1217 |
#------------------------------------------------------------------------------- |
|
1218 |
||
121 | 1219 |
# Return edited element |
1220 |
def GetEditedElement(self, tagname): |
|
1221 |
words = tagname.split("::") |
|
1222 |
if words[0] == "P": |
|
1223 |
return self.Project.getPou(words[1]) |
|
1224 |
if words[0] in ['T', 'A']: |
|
1225 |
pou = self.Project.getPou(words[1]) |
|
1226 |
if words[0] == 'T': |
|
1227 |
return pou.getTransition(words[2]) |
|
1228 |
elif words[0] == 'A': |
|
1229 |
return pou.getAction(words[2]) |
|
1230 |
elif words[0] == 'C': |
|
1231 |
return self.Project.getConfiguration(words[1]) |
|
1232 |
elif words[0] == 'R': |
|
1233 |
return self.Project.getConfigurationResource(words[1], words[2]) |
|
0 | 1234 |
return None |
1235 |
||
121 | 1236 |
# Return edited element name |
1237 |
def GetEditedElementName(self, tagname): |
|
1238 |
words = tagname.split("::") |
|
1239 |
if words[0] in ["P","C"]: |
|
1240 |
return words[1] |
|
1241 |
else: |
|
1242 |
return words[2] |
|
1243 |
return None |
|
1244 |
||
1245 |
# Return edited element name and type |
|
1246 |
def GetEditedElementType(self, tagname): |
|
1247 |
words = tagname.split("::") |
|
1248 |
if words[0] in ["P","T","A"]: |
|
1249 |
return words[1], self.GetPouType(words[1]) |
|
1250 |
return None, None |
|
1251 |
||
1252 |
# Return language in which edited element is written |
|
1253 |
def GetEditedElementBodyType(self, tagname): |
|
1254 |
words = tagname.split("::") |
|
1255 |
if words[0] == "P": |
|
1256 |
return self.GetPouBodyType(words[1]) |
|
1257 |
elif words[0] == 'T': |
|
1258 |
return self.GetTransitionBodyType(words[1], words[2]) |
|
1259 |
elif words[0] == 'A': |
|
1260 |
return self.GetActionBodyType(words[1], words[2]) |
|
1261 |
return None |
|
1262 |
||
1263 |
# Return the edited element variables |
|
1264 |
def GetEditedElementInterfaceVars(self, tagname): |
|
1265 |
words = tagname.split("::") |
|
1266 |
if words[0] in ["P","T","A"]: |
|
1267 |
pou = self.Project.getPou(words[1]) |
|
1268 |
return self.GetPouInterfaceVars(pou) |
|
1269 |
return [] |
|
1270 |
||
1271 |
# Return the edited element return type |
|
1272 |
def GetEditedElementInterfaceReturnType(self, tagname): |
|
1273 |
words = tagname.split("::") |
|
1274 |
if words[0] == "P": |
|
1275 |
pou = self.Project.getPou(words[1]) |
|
1276 |
return self.GetPouInterfaceReturnType(pou) |
|
1277 |
elif words[0] == 'T': |
|
1278 |
return "BOOL" |
|
1279 |
return None |
|
1280 |
||
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
1281 |
# Change the edited element text |
121 | 1282 |
def SetEditedElementText(self, tagname, text): |
1283 |
element = self.GetEditedElement(tagname) |
|
1284 |
if element != None: |
|
1285 |
element.setText(text) |
|
1286 |
self.RefreshPouUsingTree() |
|
1287 |
||
1288 |
# Return the edited element text |
|
1289 |
def GetEditedElementText(self, tagname): |
|
1290 |
element = self.GetEditedElement(tagname) |
|
1291 |
if element != None: |
|
1292 |
return element.getText() |
|
1293 |
return "" |
|
1294 |
||
1295 |
# Return the edited element transitions |
|
1296 |
def GetEditedElementTransitions(self, tagname): |
|
1297 |
pou = self.GetEditedElement(tagname) |
|
1298 |
if pou != None and pou.getBodyType() == "SFC": |
|
1299 |
transitions = [] |
|
1300 |
for transition in pou.getTransitionList(): |
|
1301 |
transitions.append(transition.getName()) |
|
1302 |
return transitions |
|
1303 |
return [] |
|
1304 |
||
1305 |
# Return edited element transitions |
|
1306 |
def GetEditedElementActions(self, tagname): |
|
1307 |
pou = self.GetEditedElement(tagname) |
|
1308 |
if pou != None and pou.getBodyType() == "SFC": |
|
1309 |
actions = [] |
|
1310 |
for action in pou.getActionList(): |
|
1311 |
actions.append(action.getName()) |
|
1312 |
return actions |
|
1313 |
return [] |
|
1314 |
||
1315 |
# Return the names of the pou elements |
|
1316 |
def GetEditedElementVariables(self, tagname): |
|
1317 |
words = tagname.split("::") |
|
1318 |
if words[0] in ["P","T","A"]: |
|
1319 |
return self.GetProjectPouVariables(words[1]) |
|
1320 |
return [] |
|
1321 |
||
1322 |
# Return the current pou editing informations |
|
1323 |
def GetEditedElementInstanceInfos(self, tagname, id = None, exclude = []): |
|
1324 |
infos = {} |
|
1325 |
instance = None |
|
1326 |
element = self.GetEditedElement(tagname) |
|
1327 |
if element is not None: |
|
1328 |
# if id is defined |
|
1329 |
if id is not None: |
|
1330 |
instance = element.getInstance(id) |
|
0 | 1331 |
else: |
121 | 1332 |
instance = element.getRandomInstance(exclude) |
1333 |
if instance is not None: |
|
1334 |
if id is not None: |
|
0 | 1335 |
infos["id"] = id |
1336 |
else: |
|
1337 |
infos["id"] = instance.getLocalId() |
|
1338 |
infos["x"] = instance.getX() |
|
1339 |
infos["y"] = instance.getY() |
|
1340 |
infos["height"] = instance.getHeight() |
|
1341 |
infos["width"] = instance.getWidth() |
|
1342 |
if isinstance(instance, plcopen.block): |
|
1343 |
infos["name"] = instance.getInstanceName() |
|
1344 |
infos["type"] = instance.getTypeName() |
|
118
0c53d6a36013
Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents:
117
diff
changeset
|
1345 |
executionOrder = instance.getExecutionOrderId() |
0c53d6a36013
Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents:
117
diff
changeset
|
1346 |
if executionOrder is not None: |
0c53d6a36013
Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents:
117
diff
changeset
|
1347 |
infos["executionOrder"] = executionOrder |
0c53d6a36013
Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents:
117
diff
changeset
|
1348 |
else: |
0c53d6a36013
Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents:
117
diff
changeset
|
1349 |
infos["executionOrder"] = 0 |
0 | 1350 |
infos["connectors"] = {"inputs":[],"outputs":[]} |
1351 |
for variable in instance.inputVariables.getVariable(): |
|
1352 |
connector = {} |
|
90
2245e8776086
Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents:
81
diff
changeset
|
1353 |
connector["name"] = variable.getFormalParameter() |
0 | 1354 |
connector["position"] = variable.connectionPointIn.getRelPosition() |
1355 |
connector["negated"] = variable.getNegated() |
|
1356 |
connector["edge"] = variable.getConnectorEdge() |
|
1357 |
connector["links"] = [] |
|
1358 |
connections = variable.connectionPointIn.getConnections() |
|
1359 |
if connections: |
|
1360 |
for link in connections: |
|
27 | 1361 |
dic = {"refLocalId":link.getRefLocalId(),"points":link.getPoints(),"formalParameter":link.getFormalParameter()} |
0 | 1362 |
connector["links"].append(dic) |
1363 |
infos["connectors"]["inputs"].append(connector) |
|
1364 |
for variable in instance.outputVariables.getVariable(): |
|
1365 |
connector = {} |
|
90
2245e8776086
Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents:
81
diff
changeset
|
1366 |
connector["name"] = variable.getFormalParameter() |
0 | 1367 |
connector["position"] = variable.connectionPointOut.getRelPosition() |
1368 |
connector["negated"] = variable.getNegated() |
|
1369 |
connector["edge"] = variable.getConnectorEdge() |
|
1370 |
infos["connectors"]["outputs"].append(connector) |
|
1371 |
elif isinstance(instance, plcopen.inVariable): |
|
1372 |
infos["name"] = instance.getExpression() |
|
121 | 1373 |
infos["value_type"] = self.GetEditedElementVarValueType(tagname, infos["name"]) |
0 | 1374 |
infos["type"] = "input" |
118
0c53d6a36013
Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents:
117
diff
changeset
|
1375 |
executionOrder = instance.getExecutionOrderId() |
0c53d6a36013
Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents:
117
diff
changeset
|
1376 |
if executionOrder is not None: |
0c53d6a36013
Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents:
117
diff
changeset
|
1377 |
infos["executionOrder"] = executionOrder |
0c53d6a36013
Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents:
117
diff
changeset
|
1378 |
else: |
0c53d6a36013
Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents:
117
diff
changeset
|
1379 |
infos["executionOrder"] = 0 |
0 | 1380 |
infos["connector"] = {} |
1381 |
infos["connector"]["position"] = instance.connectionPointOut.getRelPosition() |
|
1382 |
infos["connector"]["negated"] = instance.getNegated() |
|
1383 |
infos["connector"]["edge"] = instance.getConnectorEdge() |
|
1384 |
elif isinstance(instance, plcopen.outVariable): |
|
1385 |
infos["name"] = instance.getExpression() |
|
121 | 1386 |
infos["value_type"] = self.GetEditedElementVarValueType(tagname, infos["name"]) |
0 | 1387 |
infos["type"] = "output" |
118
0c53d6a36013
Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents:
117
diff
changeset
|
1388 |
executionOrder = instance.getExecutionOrderId() |
0c53d6a36013
Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents:
117
diff
changeset
|
1389 |
if executionOrder is not None: |
0c53d6a36013
Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents:
117
diff
changeset
|
1390 |
infos["executionOrder"] = executionOrder |
0c53d6a36013
Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents:
117
diff
changeset
|
1391 |
else: |
0c53d6a36013
Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents:
117
diff
changeset
|
1392 |
infos["executionOrder"] = 0 |
0 | 1393 |
infos["connector"] = {} |
1394 |
infos["connector"]["position"] = instance.connectionPointIn.getRelPosition() |
|
1395 |
infos["connector"]["negated"] = instance.getNegated() |
|
1396 |
infos["connector"]["edge"] = instance.getConnectorEdge() |
|
1397 |
infos["connector"]["links"] = [] |
|
1398 |
connections = instance.connectionPointIn.getConnections() |
|
1399 |
if connections: |
|
1400 |
for link in connections: |
|
27 | 1401 |
dic = {"refLocalId":link.getRefLocalId(),"points":link.getPoints(),"formalParameter":link.getFormalParameter()} |
0 | 1402 |
infos["connector"]["links"].append(dic) |
1403 |
elif isinstance(instance, plcopen.inOutVariable): |
|
1404 |
infos["name"] = instance.getExpression() |
|
121 | 1405 |
infos["value_type"] = self.GetEditedElementVarValueType(tagname, infos["name"]) |
0 | 1406 |
infos["type"] = "inout" |
118
0c53d6a36013
Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents:
117
diff
changeset
|
1407 |
executionOrder = instance.getExecutionOrderId() |
0c53d6a36013
Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents:
117
diff
changeset
|
1408 |
if executionOrder is not None: |
0c53d6a36013
Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents:
117
diff
changeset
|
1409 |
infos["executionOrder"] = executionOrder |
0c53d6a36013
Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents:
117
diff
changeset
|
1410 |
else: |
0c53d6a36013
Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents:
117
diff
changeset
|
1411 |
infos["executionOrder"] = 0 |
0 | 1412 |
infos["connectors"] = {"input":{},"output":{}} |
1413 |
infos["connectors"]["output"]["position"] = instance.connectionPointOut.getRelPosition() |
|
1414 |
infos["connectors"]["output"]["negated"] = instance.getNegatedOut() |
|
1415 |
infos["connectors"]["output"]["edge"] = instance.getOutputEdge() |
|
1416 |
infos["connectors"]["input"]["position"] = instance.connectionPointIn.getRelPosition() |
|
1417 |
infos["connectors"]["input"]["negated"] = instance.getNegatedIn() |
|
1418 |
infos["connectors"]["input"]["edge"] = instance.getInputEdge() |
|
1419 |
infos["connectors"]["input"]["links"] = [] |
|
1420 |
connections = instance.connectionPointIn.getConnections() |
|
1421 |
if connections: |
|
1422 |
for link in connections: |
|
27 | 1423 |
dic = {"refLocalId":link.getRefLocalId(),"points":link.getPoints(),"formalParameter":link.getFormalParameter()} |
0 | 1424 |
infos["connectors"]["input"]["links"].append(dic) |
1425 |
elif isinstance(instance, plcopen.continuation): |
|
1426 |
infos["name"] = instance.getName() |
|
1427 |
infos["type"] = "continuation" |
|
1428 |
infos["connector"] = {} |
|
1429 |
infos["connector"]["position"] = instance.connectionPointOut.getRelPosition() |
|
1430 |
elif isinstance(instance, plcopen.connector): |
|
1431 |
infos["name"] = instance.getName() |
|
1432 |
infos["type"] = "connection" |
|
1433 |
infos["connector"] = {} |
|
1434 |
infos["connector"]["position"] = instance.connectionPointIn.getRelPosition() |
|
1435 |
infos["connector"]["links"] = [] |
|
1436 |
connections = instance.connectionPointIn.getConnections() |
|
1437 |
if connections: |
|
1438 |
for link in connections: |
|
27 | 1439 |
dic = {"refLocalId":link.getRefLocalId(),"points":link.getPoints(),"formalParameter":link.getFormalParameter()} |
0 | 1440 |
infos["connector"]["links"].append(dic) |
1441 |
elif isinstance(instance, plcopen.comment): |
|
1442 |
infos["type"] = "comment" |
|
1443 |
infos["content"] = instance.getContentText() |
|
1444 |
elif isinstance(instance, plcopen.leftPowerRail): |
|
1445 |
infos["type"] = "leftPowerRail" |
|
1446 |
infos["connectors"] = [] |
|
1447 |
for connection in instance.getConnectionPointOut(): |
|
1448 |
connector = {} |
|
1449 |
connector["position"] = connection.getRelPosition() |
|
1450 |
infos["connectors"].append(connector) |
|
1451 |
elif isinstance(instance, plcopen.rightPowerRail): |
|
1452 |
infos["type"] = "rightPowerRail" |
|
1453 |
infos["connectors"] = [] |
|
1454 |
for connection in instance.getConnectionPointIn(): |
|
1455 |
connector = {} |
|
1456 |
connector["position"] = connection.getRelPosition() |
|
1457 |
connector["links"] = [] |
|
144 | 1458 |
connections = connection.getConnections() |
1459 |
if connections: |
|
1460 |
for link in connection.getConnections(): |
|
1461 |
dic = {"refLocalId":link.getRefLocalId(),"points":link.getPoints(),"formalParameter":link.getFormalParameter()} |
|
1462 |
connector["links"].append(dic) |
|
0 | 1463 |
infos["connectors"].append(connector) |
1464 |
elif isinstance(instance, plcopen.contact): |
|
118
0c53d6a36013
Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents:
117
diff
changeset
|
1465 |
infos["name"] = instance.getVariable() |
0 | 1466 |
infos["type"] = "contact" |
118
0c53d6a36013
Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents:
117
diff
changeset
|
1467 |
executionOrder = instance.getExecutionOrderId() |
0c53d6a36013
Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents:
117
diff
changeset
|
1468 |
if executionOrder is not None: |
0c53d6a36013
Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents:
117
diff
changeset
|
1469 |
infos["executionOrder"] = executionOrder |
0c53d6a36013
Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents:
117
diff
changeset
|
1470 |
else: |
0c53d6a36013
Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents:
117
diff
changeset
|
1471 |
infos["executionOrder"] = 0 |
0 | 1472 |
infos["negated"] = instance.getNegated() |
1473 |
infos["edge"] = instance.getContactEdge() |
|
1474 |
infos["connectors"] = {"input":{},"output":{}} |
|
1475 |
infos["connectors"]["input"]["position"] = instance.connectionPointIn.getRelPosition() |
|
1476 |
infos["connectors"]["input"]["links"] = [] |
|
1477 |
connections = instance.connectionPointIn.getConnections() |
|
1478 |
if connections: |
|
1479 |
for link in connections: |
|
27 | 1480 |
dic = {"refLocalId":link.getRefLocalId(),"points":link.getPoints(),"formalParameter":link.getFormalParameter()} |
0 | 1481 |
infos["connectors"]["input"]["links"].append(dic) |
1482 |
infos["connectors"]["output"]["position"] = instance.connectionPointOut.getRelPosition() |
|
1483 |
elif isinstance(instance, plcopen.coil): |
|
118
0c53d6a36013
Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents:
117
diff
changeset
|
1484 |
infos["name"] = instance.getVariable() |
0 | 1485 |
infos["type"] = "coil" |
118
0c53d6a36013
Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents:
117
diff
changeset
|
1486 |
executionOrder = instance.getExecutionOrderId() |
0c53d6a36013
Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents:
117
diff
changeset
|
1487 |
if executionOrder is not None: |
0c53d6a36013
Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents:
117
diff
changeset
|
1488 |
infos["executionOrder"] = executionOrder |
0c53d6a36013
Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents:
117
diff
changeset
|
1489 |
else: |
0c53d6a36013
Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents:
117
diff
changeset
|
1490 |
infos["executionOrder"] = 0 |
0 | 1491 |
infos["negated"] = instance.getNegated() |
1492 |
infos["storage"] = instance.getCoilStorage() |
|
1493 |
infos["connectors"] = {"input":{},"output":{}} |
|
1494 |
infos["connectors"]["input"]["position"] = instance.connectionPointIn.getRelPosition() |
|
1495 |
infos["connectors"]["input"]["links"] = [] |
|
1496 |
connections = instance.connectionPointIn.getConnections() |
|
1497 |
if connections: |
|
1498 |
for link in connections: |
|
27 | 1499 |
dic = {"refLocalId":link.getRefLocalId(),"points":link.getPoints(),"formalParameter":link.getFormalParameter()} |
0 | 1500 |
infos["connectors"]["input"]["links"].append(dic) |
1501 |
infos["connectors"]["output"]["position"] = instance.connectionPointOut.getRelPosition() |
|
1502 |
elif isinstance(instance, plcopen.step): |
|
118
0c53d6a36013
Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents:
117
diff
changeset
|
1503 |
infos["name"] = instance.getName() |
0 | 1504 |
infos["type"] = "step" |
1505 |
infos["initial"] = instance.getInitialStep() |
|
1506 |
infos["connectors"] = {} |
|
1507 |
if instance.connectionPointIn: |
|
1508 |
infos["connectors"]["input"] = {} |
|
1509 |
infos["connectors"]["input"]["position"] = instance.connectionPointIn.getRelPosition() |
|
1510 |
infos["connectors"]["input"]["links"] = [] |
|
1511 |
connections = instance.connectionPointIn.getConnections() |
|
1512 |
if connections: |
|
1513 |
for link in connections: |
|
27 | 1514 |
dic = {"refLocalId":link.getRefLocalId(),"points":link.getPoints(),"formalParameter":link.getFormalParameter()} |
0 | 1515 |
infos["connectors"]["input"]["links"].append(dic) |
1516 |
if instance.connectionPointOut: |
|
1517 |
infos["connectors"]["output"] = {"position" : instance.connectionPointOut.getRelPosition()} |
|
1518 |
if instance.connectionPointOutAction: |
|
1519 |
infos["connectors"]["action"] = {"position" : instance.connectionPointOutAction.getRelPosition()} |
|
1520 |
elif isinstance(instance, plcopen.transition): |
|
1521 |
infos["type"] = "transition" |
|
1522 |
condition = instance.getConditionContent() |
|
80 | 1523 |
priority = instance.getPriority() |
1524 |
if priority == None: |
|
1525 |
infos["priority"] = 0 |
|
1526 |
else: |
|
1527 |
infos["priority"] = priority |
|
0 | 1528 |
infos["condition_type"] = condition["type"] |
1529 |
infos["connectors"] = {"input":{},"output":{}} |
|
1530 |
infos["connectors"]["input"]["position"] = instance.connectionPointIn.getRelPosition() |
|
1531 |
infos["connectors"]["input"]["links"] = [] |
|
1532 |
connections = instance.connectionPointIn.getConnections() |
|
1533 |
if connections: |
|
1534 |
for link in connections: |
|
27 | 1535 |
dic = {"refLocalId":link.getRefLocalId(),"points":link.getPoints(),"formalParameter":link.getFormalParameter()} |
0 | 1536 |
infos["connectors"]["input"]["links"].append(dic) |
1537 |
infos["connectors"]["output"]["position"] = instance.connectionPointOut.getRelPosition() |
|
63
04a02b4b2a57
Adding support for connecting transition to LD rung and FBD network
lbessard
parents:
62
diff
changeset
|
1538 |
if infos["condition_type"] == "connection": |
04a02b4b2a57
Adding support for connecting transition to LD rung and FBD network
lbessard
parents:
62
diff
changeset
|
1539 |
infos["connectors"]["connection"] = {} |
04a02b4b2a57
Adding support for connecting transition to LD rung and FBD network
lbessard
parents:
62
diff
changeset
|
1540 |
infos["connectors"]["connection"]["links"] = [] |
04a02b4b2a57
Adding support for connecting transition to LD rung and FBD network
lbessard
parents:
62
diff
changeset
|
1541 |
connections = instance.getConnections() |
04a02b4b2a57
Adding support for connecting transition to LD rung and FBD network
lbessard
parents:
62
diff
changeset
|
1542 |
if connections: |
04a02b4b2a57
Adding support for connecting transition to LD rung and FBD network
lbessard
parents:
62
diff
changeset
|
1543 |
for link in connections: |
04a02b4b2a57
Adding support for connecting transition to LD rung and FBD network
lbessard
parents:
62
diff
changeset
|
1544 |
dic = {"refLocalId":link.getRefLocalId(),"points":link.getPoints(),"formalParameter":link.getFormalParameter()} |
04a02b4b2a57
Adding support for connecting transition to LD rung and FBD network
lbessard
parents:
62
diff
changeset
|
1545 |
infos["connectors"]["connection"]["links"].append(dic) |
04a02b4b2a57
Adding support for connecting transition to LD rung and FBD network
lbessard
parents:
62
diff
changeset
|
1546 |
infos["condition"] = None |
04a02b4b2a57
Adding support for connecting transition to LD rung and FBD network
lbessard
parents:
62
diff
changeset
|
1547 |
else: |
04a02b4b2a57
Adding support for connecting transition to LD rung and FBD network
lbessard
parents:
62
diff
changeset
|
1548 |
infos["condition"] = condition["value"] |
0 | 1549 |
elif isinstance(instance, (plcopen.selectionDivergence, plcopen.simultaneousDivergence)): |
1550 |
if isinstance(instance, plcopen.selectionDivergence): |
|
1551 |
infos["type"] = "selectionDivergence" |
|
1552 |
else: |
|
1553 |
infos["type"] = "simultaneousDivergence" |
|
1554 |
infos["connectors"] = {"inputs":[],"outputs":[]} |
|
1555 |
connector = {} |
|
1556 |
connector["position"] = instance.connectionPointIn.getRelPosition() |
|
1557 |
connector["links"] = [] |
|
1558 |
connections = instance.connectionPointIn.getConnections() |
|
1559 |
if connections: |
|
1560 |
for link in connections: |
|
27 | 1561 |
dic = {"refLocalId":link.getRefLocalId(),"points":link.getPoints(),"formalParameter":link.getFormalParameter()} |
0 | 1562 |
connector["links"].append(dic) |
1563 |
infos["connectors"]["inputs"].append(connector) |
|
1564 |
for sequence in instance.getConnectionPointOut(): |
|
1565 |
connector = {} |
|
1566 |
connector["position"] = sequence.getRelPosition() |
|
1567 |
infos["connectors"]["outputs"].append(connector) |
|
1568 |
elif isinstance(instance, (plcopen.selectionConvergence, plcopen.simultaneousConvergence)): |
|
1569 |
if isinstance(instance, plcopen.selectionConvergence): |
|
1570 |
infos["type"] = "selectionConvergence" |
|
1571 |
else: |
|
1572 |
infos["type"] = "simultaneousConvergence" |
|
1573 |
infos["connectors"] = {"inputs":[],"outputs":[]} |
|
1574 |
for sequence in instance.getConnectionPointIn(): |
|
1575 |
connector = {} |
|
1576 |
connector["position"] = sequence.getRelPosition() |
|
1577 |
connector["links"] = [] |
|
1578 |
connections = sequence.getConnections() |
|
1579 |
if connections: |
|
1580 |
for link in connections: |
|
27 | 1581 |
dic = {"refLocalId":link.getRefLocalId(),"points":link.getPoints(),"formalParameter":link.getFormalParameter()} |
0 | 1582 |
connector["links"].append(dic) |
1583 |
infos["connectors"]["inputs"].append(connector) |
|
1584 |
connector = {} |
|
1585 |
connector["position"] = instance.connectionPointOut.getRelPosition() |
|
1586 |
infos["connectors"]["outputs"].append(connector) |
|
1587 |
elif isinstance(instance, plcopen.jumpStep): |
|
1588 |
infos["type"] = "jump" |
|
1589 |
infos["target"] = instance.getTargetName() |
|
1590 |
infos["connector"] = {} |
|
1591 |
infos["connector"]["position"] = instance.connectionPointIn.getRelPosition() |
|
1592 |
infos["connector"]["links"] = [] |
|
1593 |
connections = instance.connectionPointIn.getConnections() |
|
1594 |
if connections: |
|
1595 |
for link in connections: |
|
27 | 1596 |
dic = {"refLocalId":link.getRefLocalId(),"points":link.getPoints(),"formalParameter":link.getFormalParameter()} |
0 | 1597 |
infos["connector"]["links"].append(dic) |
1598 |
elif isinstance(instance, plcopen.actionBlock): |
|
1599 |
infos["type"] = "actionBlock" |
|
1600 |
infos["actions"] = instance.getActions() |
|
1601 |
infos["connector"] = {} |
|
1602 |
infos["connector"]["position"] = instance.connectionPointIn.getRelPosition() |
|
1603 |
infos["connector"]["links"] = [] |
|
1604 |
connections = instance.connectionPointIn.getConnections() |
|
1605 |
if connections: |
|
1606 |
for link in connections: |
|
27 | 1607 |
dic = {"refLocalId":link.getRefLocalId(),"points":link.getPoints(),"formalParameter":link.getFormalParameter()} |
0 | 1608 |
infos["connector"]["links"].append(dic) |
1609 |
return infos |
|
1610 |
return False |
|
1611 |
||
121 | 1612 |
def ClearEditedElementExecutionOrder(self, tagname): |
1613 |
element = self.GetEditedElement(tagname) |
|
1614 |
if element is not None: |
|
1615 |
element.resetExecutionOrder() |
|
1616 |
||
1617 |
def ResetEditedElementExecutionOrder(self, tagname): |
|
1618 |
element = self.GetEditedElement(tagname) |
|
1619 |
if element is not None: |
|
1620 |
element.compileExecutionOrder() |
|
118
0c53d6a36013
Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents:
117
diff
changeset
|
1621 |
|
0 | 1622 |
# Return the variable type of the given pou |
121 | 1623 |
def GetEditedElementVarValueType(self, tagname, varname): |
1624 |
words = tagname.split("::") |
|
80 | 1625 |
if words[0] in ["P","T","A"]: |
45 | 1626 |
pou = self.Project.getPou(words[1]) |
80 | 1627 |
for type, varlist in pou.getVars(): |
1628 |
for var in varlist.getVariable(): |
|
1629 |
if var.getName() == varname: |
|
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
1630 |
vartype_content = var.getType().getContent() |
141 | 1631 |
if vartype_content["name"] == "derived": |
1632 |
return vartype_content["value"].getName() |
|
1633 |
elif vartype_content["name"] in ["string", "wstring"]: |
|
1634 |
return vartype_content["name"].upper() |
|
1635 |
else: |
|
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
1636 |
return vartype_content["name"] |
101
3f06a178b960
Fixed crash while draging connector from pins with undefined types
etisserant
parents:
100
diff
changeset
|
1637 |
return None |
0 | 1638 |
|
1639 |
def SetConnectionWires(self, connection, connector): |
|
1640 |
wires = connector.GetWires() |
|
1641 |
idx = 0 |
|
1642 |
for wire, handle in wires: |
|
1643 |
points = wire.GetPoints(handle != 0) |
|
1644 |
if handle == 0: |
|
27 | 1645 |
result = wire.GetConnectedInfos(-1) |
0 | 1646 |
else: |
27 | 1647 |
result = wire.GetConnectedInfos(0) |
1648 |
if result != None: |
|
1649 |
refLocalId, formalParameter = result |
|
0 | 1650 |
connection.addConnection() |
1651 |
connection.setConnectionId(idx, refLocalId) |
|
1652 |
connection.setConnectionPoints(idx, points) |
|
27 | 1653 |
if formalParameter != "": |
1654 |
connection.setConnectionParameter(idx, formalParameter) |
|
1655 |
else: |
|
1656 |
connection.setConnectionParameter(idx, None) |
|
0 | 1657 |
idx += 1 |
1658 |
||
145 | 1659 |
def AddEditedElementPouVar(self, tagname, type, name): |
1660 |
words = tagname.split("::") |
|
1661 |
if words[0] in ['P', 'T', 'A']: |
|
1662 |
pou = self.Project.getPou(words[1]) |
|
1663 |
pou.addPouVar(type, name) |
|
1664 |
||
1665 |
def ChangeEditedElementPouVar(self, tagname, old_type, old_name, new_type, new_name): |
|
1666 |
words = tagname.split("::") |
|
1667 |
if words[0] in ['P', 'T', 'A']: |
|
1668 |
pou = self.Project.getPou(words[1]) |
|
1669 |
pou.changePouVar(old_type, old_name, new_type, new_name) |
|
1670 |
||
121 | 1671 |
def AddEditedElementBlock(self, tagname, id, blocktype, blockname = None): |
1672 |
element = self.GetEditedElement(tagname) |
|
1673 |
if element is not None: |
|
1674 |
block = plcopen.block() |
|
1675 |
block.setLocalId(id) |
|
1676 |
block.setTypeName(blocktype) |
|
1677 |
blocktype_infos = GetBlockType(blocktype) |
|
1678 |
if blocktype_infos["type"] != "function" and blockname is not None: |
|
1679 |
block.setInstanceName(blockname) |
|
145 | 1680 |
self.AddEditedElementPouVar(tagname, blocktype, blockname) |
121 | 1681 |
element.addInstance("block", block) |
1682 |
self.RefreshPouUsingTree() |
|
1683 |
||
1684 |
def SetEditedElementBlockInfos(self, tagname, id, infos): |
|
1685 |
element = self.GetEditedElement(tagname) |
|
1686 |
if element is not None: |
|
1687 |
block = element.getInstance(id) |
|
145 | 1688 |
blocktype = infos.get("type", block.getTypeName()) |
1689 |
blocktype_infos = GetBlockType(blocktype) |
|
1690 |
if blocktype_infos["type"] != "function": |
|
1691 |
if "name" in infos or "type" in infos: |
|
1692 |
old_name = block.getInstanceName() |
|
1693 |
old_type = block.getTypeName() |
|
1694 |
new_name = infos.get("name", old_name) |
|
1695 |
new_type = infos.get("type", old_type) |
|
1696 |
self.ChangeEditedElementPouVar(tagname, old_type, old_name, new_type, new_name) |
|
121 | 1697 |
for param, value in infos.items(): |
1698 |
if param == "name": |
|
1699 |
block.setInstanceName(value) |
|
1700 |
elif param == "type": |
|
1701 |
block.setTypeName(value) |
|
1702 |
elif param == "executionOrder" and block.getExecutionOrderId() != value: |
|
1703 |
self.GetEditedElement(tagname).setElementExecutionOrder(block, value) |
|
1704 |
elif param == "height": |
|
1705 |
block.setHeight(value) |
|
1706 |
elif param == "width": |
|
1707 |
block.setWidth(value) |
|
1708 |
elif param == "x": |
|
1709 |
block.setX(value) |
|
1710 |
elif param == "y": |
|
1711 |
block.setY(value) |
|
1712 |
elif param == "connectors": |
|
1713 |
block.inputVariables.setVariable([]) |
|
1714 |
block.outputVariables.setVariable([]) |
|
1715 |
for connector in value["inputs"]: |
|
1716 |
variable = plcopen.inputVariables_variable() |
|
1717 |
variable.setFormalParameter(connector.GetName()) |
|
1718 |
if connector.IsNegated(): |
|
1719 |
variable.setNegated(True) |
|
1720 |
if connector.GetEdge() != "none": |
|
1721 |
variable.setConnectorEdge(connector.GetEdge()) |
|
1722 |
position = connector.GetRelPosition() |
|
1723 |
variable.connectionPointIn.setRelPosition(position.x, position.y) |
|
1724 |
self.SetConnectionWires(variable.connectionPointIn, connector) |
|
1725 |
block.inputVariables.appendVariable(variable) |
|
1726 |
for connector in value["outputs"]: |
|
1727 |
variable = plcopen.outputVariables_variable() |
|
1728 |
variable.setFormalParameter(connector.GetName()) |
|
1729 |
if connector.IsNegated(): |
|
1730 |
variable.setNegated(True) |
|
1731 |
if connector.GetEdge() != "none": |
|
1732 |
variable.setConnectorEdge(connector.GetEdge()) |
|
1733 |
position = connector.GetRelPosition() |
|
1734 |
variable.addConnectionPointOut() |
|
1735 |
variable.connectionPointOut.setRelPosition(position.x, position.y) |
|
1736 |
block.outputVariables.appendVariable(variable) |
|
1737 |
self.RefreshPouUsingTree() |
|
0 | 1738 |
|
121 | 1739 |
def AddEditedElementVariable(self, tagname, id, type): |
1740 |
element = self.GetEditedElement(tagname) |
|
1741 |
if element is not None: |
|
1742 |
if type == INPUT: |
|
1743 |
name = "inVariable" |
|
1744 |
variable = plcopen.inVariable() |
|
1745 |
elif type == OUTPUT: |
|
1746 |
name = "outVariable" |
|
1747 |
variable = plcopen.outVariable() |
|
1748 |
elif type == INOUT: |
|
1749 |
name = "inOutVariable" |
|
1750 |
variable = plcopen.inOutVariable() |
|
1751 |
variable.setLocalId(id) |
|
1752 |
element.addInstance(name, variable) |
|
0 | 1753 |
|
121 | 1754 |
def SetEditedElementVariableInfos(self, tagname, id, infos): |
1755 |
element = self.GetEditedElement(tagname) |
|
1756 |
if element is not None: |
|
1757 |
variable = element.getInstance(id) |
|
1758 |
for param, value in infos.items(): |
|
1759 |
if param == "name": |
|
1760 |
variable.setExpression(value) |
|
1761 |
elif param == "executionOrder" and variable.getExecutionOrderId() != value: |
|
1762 |
self.GetEditedElement(tagname).setElementExecutionOrder(variable, value) |
|
1763 |
elif param == "height": |
|
1764 |
variable.setHeight(value) |
|
1765 |
elif param == "width": |
|
1766 |
variable.setWidth(value) |
|
1767 |
elif param == "x": |
|
1768 |
variable.setX(value) |
|
1769 |
elif param == "y": |
|
1770 |
variable.setY(value) |
|
1771 |
elif param == "connectors": |
|
1772 |
if isinstance(variable, plcopen.inVariable): |
|
1773 |
if value["output"].IsNegated(): |
|
1774 |
variable.setNegated(True) |
|
1775 |
if value["output"].GetEdge() != "none": |
|
1776 |
variable.setConnectorEdge(value["output"].GetEdge()) |
|
1777 |
position = value["output"].GetRelPosition() |
|
1778 |
variable.addConnectionPointOut() |
|
1779 |
variable.connectionPointOut.setRelPosition(position.x, position.y) |
|
1780 |
elif isinstance(variable, plcopen.outVariable): |
|
1781 |
if value["input"].IsNegated(): |
|
1782 |
variable.setNegated(True) |
|
1783 |
if value["input"].GetEdge() != "none": |
|
1784 |
variable.setConnectorEdge(value["input"].GetEdge()) |
|
1785 |
position = value["input"].GetRelPosition() |
|
1786 |
variable.addConnectionPointIn() |
|
1787 |
variable.connectionPointIn.setRelPosition(position.x, position.y) |
|
1788 |
self.SetConnectionWires(variable.connectionPointIn, value["input"]) |
|
1789 |
elif isinstance(variable, plcopen.inOutVariable): |
|
1790 |
if value["input"].IsNegated(): |
|
1791 |
variable.setNegatedIn(True) |
|
1792 |
if value["input"].GetEdge() != "none": |
|
1793 |
variable.setInputEdge(value["input"].GetEdge()) |
|
1794 |
if value["output"].IsNegated(): |
|
1795 |
variable.setNegatedOut(True) |
|
1796 |
if value["output"].GetEdge() != "none": |
|
1797 |
variable.setOutputEdge(value["output"].GetEdge()) |
|
1798 |
position = value["output"].GetRelPosition() |
|
1799 |
variable.addConnectionPointOut() |
|
1800 |
variable.connectionPointOut.setRelPosition(position.x, position.y) |
|
1801 |
position = value["input"].GetRelPosition() |
|
1802 |
variable.addConnectionPointIn() |
|
1803 |
variable.connectionPointIn.setRelPosition(position.x, position.y) |
|
1804 |
self.SetConnectionWires(variable.connectionPointIn, value["input"]) |
|
1805 |
||
1806 |
def AddEditedElementConnection(self, tagname, id, type): |
|
1807 |
element = self.GetEditedElement(tagname) |
|
1808 |
if element is not None: |
|
1809 |
if type == CONNECTOR: |
|
1810 |
name = "connector" |
|
1811 |
connection = plcopen.connector() |
|
1812 |
elif type == CONTINUATION: |
|
1813 |
name = "continuation" |
|
1814 |
connection = plcopen.continuation() |
|
1815 |
connection.setLocalId(id) |
|
1816 |
element.addInstance(name, connection) |
|
0 | 1817 |
|
121 | 1818 |
def SetEditedElementConnectionInfos(self, tagname, id, infos): |
1819 |
element = self.GetEditedElement(tagname) |
|
1820 |
if element is not None: |
|
1821 |
connection = element.getInstance(id) |
|
1822 |
for param, value in infos.items(): |
|
1823 |
if param == "name": |
|
1824 |
connection.setName(value) |
|
1825 |
elif param == "height": |
|
1826 |
connection.setHeight(value) |
|
1827 |
elif param == "width": |
|
1828 |
connection.setWidth(value) |
|
1829 |
elif param == "x": |
|
1830 |
connection.setX(value) |
|
1831 |
elif param == "y": |
|
1832 |
connection.setY(value) |
|
1833 |
elif param == "connector": |
|
1834 |
position = value.GetRelPosition() |
|
1835 |
if isinstance(connection, plcopen.continuation): |
|
1836 |
connection.addConnectionPointOut() |
|
1837 |
connection.connectionPointOut.setRelPosition(position.x, position.y) |
|
1838 |
elif isinstance(connection, plcopen.connector): |
|
1839 |
connection.addConnectionPointIn() |
|
1840 |
connection.connectionPointIn.setRelPosition(position.x, position.y) |
|
1841 |
self.SetConnectionWires(connection.connectionPointIn, value) |
|
1842 |
||
1843 |
def AddEditedElementComment(self, tagname, id): |
|
1844 |
element = self.GetEditedElement(tagname) |
|
1845 |
if element is not None: |
|
1846 |
comment = plcopen.comment() |
|
1847 |
comment.setLocalId(id) |
|
1848 |
element.addInstance("comment", comment) |
|
1849 |
||
1850 |
def SetEditedElementCommentInfos(self, tagname, id, infos): |
|
1851 |
element = self.GetEditedElement(tagname) |
|
1852 |
if element is not None: |
|
1853 |
comment = element.getInstance(id) |
|
1854 |
for param, value in infos.items(): |
|
1855 |
if param == "content": |
|
1856 |
comment.setContentText(value) |
|
1857 |
elif param == "height": |
|
1858 |
comment.setHeight(value) |
|
1859 |
elif param == "width": |
|
1860 |
comment.setWidth(value) |
|
1861 |
elif param == "x": |
|
1862 |
comment.setX(value) |
|
1863 |
elif param == "y": |
|
1864 |
comment.setY(value) |
|
1865 |
||
1866 |
def AddEditedElementPowerRail(self, tagname, id, type): |
|
1867 |
element = self.GetEditedElement(tagname) |
|
1868 |
if element is not None: |
|
1869 |
if type == LEFTRAIL: |
|
1870 |
name = "leftPowerRail" |
|
1871 |
powerrail = plcopen.leftPowerRail() |
|
1872 |
elif type == RIGHTRAIL: |
|
1873 |
name = "rightPowerRail" |
|
1874 |
powerrail = plcopen.rightPowerRail() |
|
1875 |
powerrail.setLocalId(id) |
|
1876 |
element.addInstance(name, powerrail) |
|
1877 |
||
1878 |
def SetEditedElementPowerRailInfos(self, tagname, id, infos): |
|
1879 |
element = self.GetEditedElement(tagname) |
|
1880 |
if element is not None: |
|
1881 |
powerrail = element.getInstance(id) |
|
1882 |
for param, value in infos.items(): |
|
1883 |
if param == "height": |
|
1884 |
powerrail.setHeight(value) |
|
1885 |
elif param == "width": |
|
1886 |
powerrail.setWidth(value) |
|
1887 |
elif param == "x": |
|
1888 |
powerrail.setX(value) |
|
1889 |
elif param == "y": |
|
1890 |
powerrail.setY(value) |
|
1891 |
elif param == "connectors": |
|
1892 |
if isinstance(powerrail, plcopen.leftPowerRail): |
|
1893 |
powerrail.setConnectionPointOut([]) |
|
1894 |
for connector in value: |
|
1895 |
position = connector.GetRelPosition() |
|
1896 |
connection = plcopen.leftPowerRail_connectionPointOut() |
|
1897 |
connection.setRelPosition(position.x, position.y) |
|
1898 |
powerrail.connectionPointOut.append(connection) |
|
1899 |
elif isinstance(powerrail, plcopen.rightPowerRail): |
|
1900 |
powerrail.setConnectionPointIn([]) |
|
1901 |
for connector in value: |
|
1902 |
position = connector.GetRelPosition() |
|
1903 |
connection = plcopen.connectionPointIn() |
|
1904 |
connection.setRelPosition(position.x, position.y) |
|
1905 |
self.SetConnectionWires(connection, connector) |
|
1906 |
powerrail.connectionPointIn.append(connection) |
|
1907 |
||
128 | 1908 |
def AddEditedElementContact(self, tagname, id): |
121 | 1909 |
element = self.GetEditedElement(tagname) |
1910 |
if element is not None: |
|
1911 |
contact = plcopen.contact() |
|
1912 |
contact.setLocalId(id) |
|
1913 |
element.addInstance("contact", contact) |
|
1914 |
||
1915 |
def SetEditedElementContactInfos(self, tagname, id, infos): |
|
1916 |
element = self.GetEditedElement(tagname) |
|
1917 |
if element is not None: |
|
1918 |
contact = element.getInstance(id) |
|
1919 |
for param, value in infos.items(): |
|
1920 |
if param == "name": |
|
1921 |
contact.setVariable(value) |
|
1922 |
elif param == "type": |
|
1923 |
if value == CONTACT_NORMAL: |
|
1924 |
contact.setNegated(False) |
|
1925 |
contact.setContactEdge("none") |
|
1926 |
elif value == CONTACT_REVERSE: |
|
1927 |
contact.setNegated(True) |
|
1928 |
contact.setContactEdge("none") |
|
1929 |
elif value == CONTACT_RISING: |
|
1930 |
contact.setNegated(False) |
|
1931 |
contact.setContactEdge("rising") |
|
1932 |
elif value == CONTACT_FALLING: |
|
1933 |
contact.setNegated(False) |
|
1934 |
contact.setContactEdge("falling") |
|
1935 |
elif param == "height": |
|
1936 |
contact.setHeight(value) |
|
1937 |
elif param == "width": |
|
1938 |
contact.setWidth(value) |
|
1939 |
elif param == "x": |
|
1940 |
contact.setX(value) |
|
1941 |
elif param == "y": |
|
1942 |
contact.setY(value) |
|
1943 |
elif param == "connectors": |
|
1944 |
input_connector = value["input"] |
|
0 | 1945 |
position = input_connector.GetRelPosition() |
121 | 1946 |
contact.addConnectionPointIn() |
1947 |
contact.connectionPointIn.setRelPosition(position.x, position.y) |
|
1948 |
self.SetConnectionWires(contact.connectionPointIn, input_connector) |
|
1949 |
output_connector = value["output"] |
|
0 | 1950 |
position = output_connector.GetRelPosition() |
121 | 1951 |
contact.addConnectionPointOut() |
1952 |
contact.connectionPointOut.setRelPosition(position.x, position.y) |
|
1953 |
||
1954 |
def AddEditedElementCoil(self, tagname, id): |
|
1955 |
element = self.GetEditedElement(tagname) |
|
1956 |
if element is not None: |
|
1957 |
coil = plcopen.coil() |
|
1958 |
coil.setLocalId(id) |
|
1959 |
element.addInstance("coil", coil) |
|
1960 |
||
1961 |
def SetEditedElementCoilInfos(self, tagname, id, infos): |
|
1962 |
element = self.GetEditedElement(tagname) |
|
1963 |
if element is not None: |
|
1964 |
coil = element.getInstance(id) |
|
1965 |
for param, value in infos.items(): |
|
1966 |
if param == "name": |
|
1967 |
coil.setVariable(value) |
|
1968 |
elif param == "type": |
|
1969 |
if value == COIL_NORMAL: |
|
1970 |
coil.setNegated(False) |
|
1971 |
coil.setCoilStorage("none") |
|
1972 |
elif value == COIL_REVERSE: |
|
1973 |
coil.setNegated(True) |
|
1974 |
coil.setCoilStorage("none") |
|
1975 |
elif value == COIL_SET: |
|
1976 |
coil.setNegated(False) |
|
1977 |
coil.setCoilStorage("set") |
|
1978 |
elif value == COIL_RESET: |
|
1979 |
coil.setNegated(False) |
|
1980 |
coil.setCoilStorage("reset") |
|
1981 |
elif param == "height": |
|
1982 |
coil.setHeight(value) |
|
1983 |
elif param == "width": |
|
1984 |
coil.setWidth(value) |
|
1985 |
elif param == "x": |
|
1986 |
coil.setX(value) |
|
1987 |
elif param == "y": |
|
1988 |
coil.setY(value) |
|
1989 |
elif param == "connectors": |
|
1990 |
input_connector = value["input"] |
|
1991 |
position = input_connector.GetRelPosition() |
|
1992 |
coil.addConnectionPointIn() |
|
1993 |
coil.connectionPointIn.setRelPosition(position.x, position.y) |
|
1994 |
self.SetConnectionWires(coil.connectionPointIn, input_connector) |
|
1995 |
output_connector = value["output"] |
|
1996 |
position = output_connector.GetRelPosition() |
|
1997 |
coil.addConnectionPointOut() |
|
1998 |
coil.connectionPointOut.setRelPosition(position.x, position.y) |
|
1999 |
||
2000 |
def AddEditedElementStep(self, tagname, id): |
|
2001 |
element = self.GetEditedElement(tagname) |
|
2002 |
if element is not None: |
|
2003 |
step = plcopen.step() |
|
2004 |
step.setLocalId(id) |
|
2005 |
element.addInstance("step", step) |
|
2006 |
||
2007 |
def SetEditedElementStepInfos(self, tagname, id, infos): |
|
2008 |
element = self.GetEditedElement(tagname) |
|
2009 |
if element is not None: |
|
2010 |
step = element.getInstance(id) |
|
2011 |
for param, value in infos.items(): |
|
2012 |
if param == "name": |
|
2013 |
step.setName(value) |
|
2014 |
elif param == "initial": |
|
2015 |
step.setInitialStep(value) |
|
2016 |
elif param == "height": |
|
2017 |
step.setHeight(value) |
|
2018 |
elif param == "width": |
|
2019 |
step.setWidth(value) |
|
2020 |
elif param == "x": |
|
2021 |
step.setX(value) |
|
2022 |
elif param == "y": |
|
2023 |
step.setY(value) |
|
2024 |
elif param == "connectors": |
|
2025 |
input_connector = value["input"] |
|
2026 |
if input_connector: |
|
0 | 2027 |
position = input_connector.GetRelPosition() |
121 | 2028 |
step.addConnectionPointIn() |
2029 |
step.connectionPointIn.setRelPosition(position.x, position.y) |
|
2030 |
self.SetConnectionWires(step.connectionPointIn, input_connector) |
|
2031 |
else: |
|
2032 |
step.deleteConnectionPointIn() |
|
2033 |
output_connector = value["output"] |
|
2034 |
if output_connector: |
|
0 | 2035 |
position = output_connector.GetRelPosition() |
121 | 2036 |
step.addConnectionPointOut() |
2037 |
step.connectionPointOut.setRelPosition(position.x, position.y) |
|
2038 |
else: |
|
2039 |
step.deleteConnectionPointOut() |
|
2040 |
action_connector = value["action"] |
|
2041 |
if action_connector: |
|
2042 |
position = action_connector.GetRelPosition() |
|
2043 |
step.addConnectionPointOutAction() |
|
2044 |
step.connectionPointOutAction.setRelPosition(position.x, position.y) |
|
2045 |
else: |
|
2046 |
step.deleteConnectionPointOutAction() |
|
2047 |
||
2048 |
def AddEditedElementTransition(self, tagname, id): |
|
2049 |
element = self.GetEditedElement(tagname) |
|
2050 |
if element is not None: |
|
2051 |
transition = plcopen.transition() |
|
2052 |
transition.setLocalId(id) |
|
2053 |
element.addInstance("transition", transition) |
|
2054 |
||
2055 |
def SetEditedElementTransitionInfos(self, tagname, id, infos): |
|
2056 |
element = self.GetEditedElement(tagname) |
|
2057 |
if element is not None: |
|
2058 |
transition = element.getInstance(id) |
|
2059 |
for param, value in infos.items(): |
|
2060 |
if param == "type" and value != "connection": |
|
2061 |
transition.setConditionContent(value, infos["condition"]) |
|
2062 |
elif param == "height": |
|
2063 |
transition.setHeight(value) |
|
2064 |
elif param == "width": |
|
2065 |
transition.setWidth(value) |
|
2066 |
elif param == "x": |
|
2067 |
transition.setX(value) |
|
2068 |
elif param == "y": |
|
2069 |
transition.setY(value) |
|
2070 |
elif param == "priority": |
|
2071 |
if value != 0: |
|
2072 |
transition.setPriority(value) |
|
2073 |
else: |
|
2074 |
transition.setPriority(None) |
|
2075 |
elif param == "connectors": |
|
2076 |
input_connector = value["input"] |
|
2077 |
position = input_connector.GetRelPosition() |
|
2078 |
transition.addConnectionPointIn() |
|
2079 |
transition.connectionPointIn.setRelPosition(position.x, position.y) |
|
2080 |
self.SetConnectionWires(transition.connectionPointIn, input_connector) |
|
2081 |
output_connector = value["output"] |
|
2082 |
position = output_connector.GetRelPosition() |
|
2083 |
transition.addConnectionPointOut() |
|
2084 |
transition.connectionPointOut.setRelPosition(position.x, position.y) |
|
2085 |
if infos.get("type", None) == "connection": |
|
2086 |
transition.setConditionContent("connection", None) |
|
2087 |
connection_connector = value["connection"] |
|
2088 |
self.SetConnectionWires(transition, connection_connector) |
|
2089 |
||
2090 |
def AddEditedElementDivergence(self, tagname, id, type): |
|
2091 |
element = self.GetEditedElement(tagname) |
|
2092 |
if element is not None: |
|
2093 |
if type == SELECTION_DIVERGENCE: |
|
2094 |
name = "selectionDivergence" |
|
2095 |
divergence = plcopen.selectionDivergence() |
|
2096 |
elif type == SELECTION_CONVERGENCE: |
|
2097 |
name = "selectionConvergence" |
|
2098 |
divergence = plcopen.selectionConvergence() |
|
2099 |
elif type == SIMULTANEOUS_DIVERGENCE: |
|
2100 |
name = "simultaneousDivergence" |
|
2101 |
divergence = plcopen.simultaneousDivergence() |
|
2102 |
elif type == SIMULTANEOUS_CONVERGENCE: |
|
2103 |
name = "simultaneousConvergence" |
|
2104 |
divergence = plcopen.simultaneousConvergence() |
|
2105 |
divergence.setLocalId(id) |
|
2106 |
element.addInstance(name, divergence) |
|
2107 |
||
2108 |
def SetEditedElementDivergenceInfos(self, tagname, id, infos): |
|
2109 |
element = self.GetEditedElement(tagname) |
|
2110 |
if element is not None: |
|
2111 |
divergence = element.getInstance(id) |
|
2112 |
for param, value in infos.items(): |
|
2113 |
if param == "height": |
|
2114 |
divergence.setHeight(value) |
|
2115 |
elif param == "width": |
|
2116 |
divergence.setWidth(value) |
|
2117 |
elif param == "x": |
|
2118 |
divergence.setX(value) |
|
2119 |
elif param == "y": |
|
2120 |
divergence.setY(value) |
|
2121 |
elif param == "connectors": |
|
2122 |
input_connectors = value["inputs"] |
|
2123 |
if isinstance(divergence, (plcopen.selectionDivergence, plcopen.simultaneousDivergence)): |
|
2124 |
position = input_connectors[0].GetRelPosition() |
|
2125 |
divergence.addConnectionPointIn() |
|
2126 |
divergence.connectionPointIn.setRelPosition(position.x, position.y) |
|
2127 |
self.SetConnectionWires(divergence.connectionPointIn, input_connectors[0]) |
|
2128 |
else: |
|
2129 |
divergence.setConnectionPointIn([]) |
|
2130 |
for input_connector in input_connectors: |
|
2131 |
position = input_connector.GetRelPosition() |
|
2132 |
if isinstance(divergence, plcopen.selectionConvergence): |
|
2133 |
connection = plcopen.selectionConvergence_connectionPointIn() |
|
2134 |
else: |
|
2135 |
connection = plcopen.connectionPointIn() |
|
2136 |
connection.setRelPosition(position.x, position.y) |
|
2137 |
self.SetConnectionWires(connection, input_connector) |
|
2138 |
divergence.appendConnectionPointIn(connection) |
|
2139 |
output_connectors = value["outputs"] |
|
2140 |
if isinstance(divergence, (plcopen.selectionConvergence, plcopen.simultaneousConvergence)): |
|
2141 |
position = output_connectors[0].GetRelPosition() |
|
2142 |
divergence.addConnectionPointOut() |
|
2143 |
divergence.connectionPointOut.setRelPosition(position.x, position.y) |
|
2144 |
else: |
|
2145 |
divergence.setConnectionPointOut([]) |
|
2146 |
for output_connector in output_connectors: |
|
2147 |
position = output_connector.GetRelPosition() |
|
2148 |
if isinstance(divergence, plcopen.selectionDivergence): |
|
2149 |
connection = plcopen.selectionDivergence_connectionPointOut() |
|
2150 |
else: |
|
2151 |
connection = plcopen.simultaneousDivergence_connectionPointOut() |
|
2152 |
connection.setRelPosition(position.x, position.y) |
|
2153 |
divergence.appendConnectionPointOut(connection) |
|
2154 |
||
2155 |
def AddEditedElementJump(self, tagname, id): |
|
2156 |
element = self.GetEditedElement(tagname) |
|
2157 |
if element is not None: |
|
2158 |
jump = plcopen.jumpStep() |
|
2159 |
jump.setLocalId(id) |
|
2160 |
element.addInstance("jumpStep", jump) |
|
2161 |
||
2162 |
def SetEditedElementJumpInfos(self, tagname, id, infos): |
|
2163 |
element = self.GetEditedElement(tagname) |
|
2164 |
if element is not None: |
|
2165 |
jump = element.getInstance(id) |
|
2166 |
for param, value in infos.items(): |
|
2167 |
if param == "target": |
|
2168 |
jump.setTargetName(value) |
|
2169 |
elif param == "height": |
|
2170 |
jump.setHeight(value) |
|
2171 |
elif param == "width": |
|
2172 |
jump.setWidth(value) |
|
2173 |
elif param == "x": |
|
2174 |
jump.setX(value) |
|
2175 |
elif param == "y": |
|
2176 |
jump.setY(value) |
|
2177 |
elif param == "connector": |
|
2178 |
position = value.GetRelPosition() |
|
2179 |
jump.addConnectionPointIn() |
|
2180 |
jump.connectionPointIn.setRelPosition(position.x, position.y) |
|
2181 |
self.SetConnectionWires(jump.connectionPointIn, value) |
|
0 | 2182 |
|
121 | 2183 |
def AddEditedElementActionBlock(self, tagname, id): |
2184 |
element = self.GetEditedElement(tagname) |
|
2185 |
if element is not None: |
|
2186 |
actionBlock = plcopen.actionBlock() |
|
2187 |
actionBlock.setLocalId(id) |
|
2188 |
element.addInstance("actionBlock", actionBlock) |
|
2189 |
||
2190 |
def SetEditedElementActionBlockInfos(self, tagname, id, infos): |
|
2191 |
element = self.GetEditedElement(tagname) |
|
2192 |
if element is not None: |
|
2193 |
actionBlock = element.getInstance(id) |
|
2194 |
for param, value in infos.items(): |
|
2195 |
if param == "actions": |
|
2196 |
actionBlock.setActions(value) |
|
2197 |
elif param == "height": |
|
2198 |
actionBlock.setHeight(value) |
|
2199 |
elif param == "width": |
|
2200 |
actionBlock.setWidth(value) |
|
2201 |
elif param == "x": |
|
2202 |
actionBlock.setX(value) |
|
2203 |
elif param == "y": |
|
2204 |
actionBlock.setY(value) |
|
2205 |
elif param == "connector": |
|
2206 |
position = value.GetRelPosition() |
|
2207 |
actionBlock.addConnectionPointIn() |
|
2208 |
actionBlock.connectionPointIn.setRelPosition(position.x, position.y) |
|
2209 |
self.SetConnectionWires(actionBlock.connectionPointIn, value) |
|
2210 |
||
2211 |
def RemoveEditedElementInstance(self, tagname, id): |
|
2212 |
element = self.GetEditedElement(tagname) |
|
2213 |
if element is not None: |
|
2214 |
instance = element.getInstance(id) |
|
2215 |
if isinstance(instance, plcopen.block): |
|
2216 |
blocktype = instance.getTypeName() |
|
2217 |
element.removePouVar(blocktype, instance.getInstanceName()) |
|
2218 |
element.removeInstance(id) |
|
2219 |
self.RefreshPouUsingTree() |
|
2220 |
||
2221 |
def GetEditedResourceVariables(self, tagname): |
|
0 | 2222 |
varlist = [] |
121 | 2223 |
words = tagname.split("::") |
0 | 2224 |
for var in self.GetConfigurationGlobalVars(words[1]): |
2225 |
if var["Type"] == "BOOL": |
|
2226 |
varlist.append(var["Name"]) |
|
2227 |
for var in self.GetConfigurationResourceGlobalVars(words[1], words[2]): |
|
2228 |
if var["Type"] == "BOOL": |
|
2229 |
varlist.append(var["Name"]) |
|
2230 |
return varlist |
|
2231 |
||
137 | 2232 |
def SetEditedResourceInfos(self, tagname, tasks, instances): |
121 | 2233 |
resource = self.GetEditedElement(tagname) |
2234 |
if resource is not None: |
|
2235 |
resource.setTask([]) |
|
2236 |
resource.setPouInstance([]) |
|
2237 |
task_list = {} |
|
2238 |
for task in tasks: |
|
2239 |
new_task = plcopen.resource_task() |
|
2240 |
new_task.setName(task["Name"]) |
|
2241 |
if task["Single"] != "": |
|
2242 |
new_task.setSingle(task["Single"]) |
|
2243 |
result = duration_model.match(task["Interval"]).groups() |
|
2244 |
if reduce(lambda x, y: x or y != None, result): |
|
2245 |
values = [] |
|
2246 |
for value in result[:-1]: |
|
2247 |
if value != None: |
|
2248 |
values.append(int(value)) |
|
2249 |
else: |
|
2250 |
values.append(0) |
|
2251 |
values.append(int(float(result[-1]) * 1000)) |
|
2252 |
new_task.setInterval(time(*values)) |
|
2253 |
new_task.priority.setValue(int(task["Priority"])) |
|
2254 |
if task["Name"] != "": |
|
2255 |
task_list[task["Name"]] = new_task |
|
2256 |
resource.appendTask(new_task) |
|
2257 |
for instance in instances: |
|
2258 |
new_instance = plcopen.pouInstance() |
|
2259 |
new_instance.setName(instance["Name"]) |
|
2260 |
new_instance.setType(instance["Type"]) |
|
2261 |
if instance["Task"] != "": |
|
2262 |
task_list[instance["Task"]].appendPouInstance(new_instance) |
|
2263 |
else: |
|
2264 |
resource.appendPouInstance(new_instance) |
|
2265 |
||
2266 |
def GetEditedResourceInfos(self, tagname): |
|
2267 |
resource = self.GetEditedElement(tagname) |
|
2268 |
if resource is not None: |
|
2269 |
tasks = resource.getTask() |
|
2270 |
instances = resource.getPouInstance() |
|
2271 |
tasks_data = [] |
|
2272 |
instances_data = [] |
|
2273 |
for task in tasks: |
|
2274 |
new_task = {} |
|
2275 |
new_task["Name"] = task.getName() |
|
2276 |
single = task.getSingle() |
|
2277 |
if single: |
|
2278 |
new_task["Single"] = single |
|
2279 |
else: |
|
2280 |
new_task["Single"] = "" |
|
2281 |
interval = task.getInterval() |
|
2282 |
if interval: |
|
2283 |
text = "" |
|
2284 |
if interval.hour != 0: |
|
2285 |
text += "%dh"%interval.hour |
|
2286 |
if interval.minute != 0: |
|
2287 |
text += "%dm"%interval.minute |
|
2288 |
if interval.second != 0: |
|
2289 |
text += "%ds"%interval.second |
|
2290 |
if interval.microsecond != 0: |
|
2291 |
if interval.microsecond % 1000 != 0: |
|
2292 |
text += "%.3fms"%(float(interval.microsecond) / 1000) |
|
2293 |
else: |
|
2294 |
text += "%dms"%(interval.microsecond / 1000) |
|
2295 |
new_task["Interval"] = text |
|
2296 |
else: |
|
2297 |
new_task["Interval"] = "" |
|
2298 |
new_task["Priority"] = str(task.priority.getValue()) |
|
2299 |
tasks_data.append(new_task) |
|
2300 |
for instance in task.getPouInstance(): |
|
2301 |
new_instance = {} |
|
2302 |
new_instance["Name"] = instance.getName() |
|
2303 |
new_instance["Type"] = instance.getType() |
|
2304 |
new_instance["Task"] = task.getName() |
|
2305 |
instances_data.append(new_instance) |
|
2306 |
for instance in instances: |
|
0 | 2307 |
new_instance = {} |
2308 |
new_instance["Name"] = instance.getName() |
|
2309 |
new_instance["Type"] = instance.getType() |
|
121 | 2310 |
new_instance["Task"] = "" |
0 | 2311 |
instances_data.append(new_instance) |
121 | 2312 |
return tasks_data, instances_data |
0 | 2313 |
|
2314 |
def OpenXMLFile(self, filepath): |
|
27 | 2315 |
if self.VerifyXML: |
2316 |
if sys: |
|
2317 |
sys.stdout = HolePseudoFile() |
|
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
2318 |
result = pyxsval.parseAndValidate(filepath, os.path.join(ScriptDirectory, "plcopen", "TC6_XML_V10_B.xsd")) |
27 | 2319 |
if sys: |
2320 |
sys.stdout = sys.__stdout__ |
|
2321 |
tree = result.getTree() |
|
2322 |
else: |
|
2323 |
xmlfile = open(filepath, 'r') |
|
2324 |
tree = minidom.parse(xmlfile) |
|
2325 |
xmlfile.close() |
|
0 | 2326 |
|
2327 |
self.Project = plcopen.project() |
|
116
58b9b84e385f
Adding support in xmlclass for timezone in datetime and for not paying attention to xml comments
lbessard
parents:
108
diff
changeset
|
2328 |
for child in tree.childNodes: |
58b9b84e385f
Adding support in xmlclass for timezone in datetime and for not paying attention to xml comments
lbessard
parents:
108
diff
changeset
|
2329 |
if child.nodeType == tree.ELEMENT_NODE and child.nodeName == "project": |
58b9b84e385f
Adding support in xmlclass for timezone in datetime and for not paying attention to xml comments
lbessard
parents:
108
diff
changeset
|
2330 |
self.Project.loadXMLTree(child) |
58b9b84e385f
Adding support in xmlclass for timezone in datetime and for not paying attention to xml comments
lbessard
parents:
108
diff
changeset
|
2331 |
self.SetFilePath(filepath) |
58b9b84e385f
Adding support in xmlclass for timezone in datetime and for not paying attention to xml comments
lbessard
parents:
108
diff
changeset
|
2332 |
self.ProjectBuffer = UndoBuffer(self.Copy(self.Project), True) |
58b9b84e385f
Adding support in xmlclass for timezone in datetime and for not paying attention to xml comments
lbessard
parents:
108
diff
changeset
|
2333 |
self.Buffering = False |
58b9b84e385f
Adding support in xmlclass for timezone in datetime and for not paying attention to xml comments
lbessard
parents:
108
diff
changeset
|
2334 |
self.ElementsOpened = [] |
58b9b84e385f
Adding support in xmlclass for timezone in datetime and for not paying attention to xml comments
lbessard
parents:
108
diff
changeset
|
2335 |
self.CurrentElementEditing = None |
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
2336 |
self.RefreshDataTypeUsingTree() |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
2337 |
self.RefreshDataTypes() |
116
58b9b84e385f
Adding support in xmlclass for timezone in datetime and for not paying attention to xml comments
lbessard
parents:
108
diff
changeset
|
2338 |
self.RefreshPouUsingTree() |
58b9b84e385f
Adding support in xmlclass for timezone in datetime and for not paying attention to xml comments
lbessard
parents:
108
diff
changeset
|
2339 |
self.RefreshBlockTypes() |
117 | 2340 |
return None |
2341 |
return "No PLC project found" |
|
0 | 2342 |
|
2343 |
def SaveXMLFile(self, filepath = None): |
|
2344 |
if not filepath and self.FilePath == "": |
|
2345 |
return False |
|
2346 |
else: |
|
145 | 2347 |
contentheader = self.Project.getContentHeader() |
2348 |
contentheader["modificationDateTime"] = datetime(*localtime()[:6]) |
|
2349 |
self.Project.setContentHeader(contentheader) |
|
2350 |
||
0 | 2351 |
text = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" |
2352 |
extras = {"xmlns" : "http://www.plcopen.org/xml/tc6.xsd", |
|
2353 |
"xmlns:xhtml" : "http://www.w3.org/1999/xhtml", |
|
2354 |
"xmlns:xsi" : "http://www.w3.org/2001/XMLSchema-instance", |
|
2355 |
"xsi:schemaLocation" : "http://www.plcopen.org/xml/tc6.xsd http://www.plcopen.org/xml/tc6.xsd"} |
|
2356 |
text += self.Project.generateXMLText("project", 0, extras) |
|
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
2357 |
|
27 | 2358 |
if self.VerifyXML: |
2359 |
if sys: |
|
2360 |
sys.stdout = HolePseudoFile() |
|
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
121
diff
changeset
|
2361 |
pyxsval.parseAndValidateString(text, open(os.path.join(ScriptDirectory, "plcopen", "TC6_XML_V10_B.xsd"),"r").read()) |
27 | 2362 |
if sys: |
2363 |
sys.stdout = sys.__stdout__ |
|
0 | 2364 |
|
2365 |
if filepath: |
|
2366 |
xmlfile = open(filepath,"w") |
|
2367 |
else: |
|
2368 |
xmlfile = open(self.FilePath,"w") |
|
2369 |
xmlfile.write(text) |
|
2370 |
xmlfile.close() |
|
56
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
2371 |
self.ProjectBuffer.CurrentSaved() |
0 | 2372 |
if filepath: |
2373 |
self.SetFilePath(filepath) |
|
2374 |
return True |
|
2375 |
||
2376 |
#------------------------------------------------------------------------------- |
|
2377 |
# Current Buffering Management Functions |
|
2378 |
#------------------------------------------------------------------------------- |
|
2379 |
||
2380 |
""" |
|
2381 |
Return a copy of the project |
|
2382 |
""" |
|
2383 |
def Copy(self, model): |
|
2384 |
return cPickle.loads(cPickle.dumps(model)) |
|
2385 |
||
2386 |
def BufferProject(self): |
|
56
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
2387 |
self.ProjectBuffer.Buffering(self.Copy(self.Project)) |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
2388 |
|
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
2389 |
def StartBuffering(self): |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
2390 |
self.ProjectBuffer.Buffering(self.Project) |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
2391 |
self.Buffering = True |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
2392 |
|
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
2393 |
def EndBuffering(self): |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
2394 |
if self.Buffering: |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
2395 |
self.Project = self.Copy(self.Project) |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
2396 |
self.Buffering = False |
0 | 2397 |
|
2398 |
def ProjectIsSaved(self): |
|
58 | 2399 |
if self.ProjectBuffer: |
2400 |
return self.ProjectBuffer.IsCurrentSaved() |
|
2401 |
else: |
|
62
1908c45f21ef
Adding sizer on some Dialogs for making them resizable
lbessard
parents:
58
diff
changeset
|
2402 |
return True |
0 | 2403 |
|
2404 |
def LoadPrevious(self): |
|
27 | 2405 |
self.Project = self.Copy(self.ProjectBuffer.Previous()) |
0 | 2406 |
|
2407 |
def LoadNext(self): |
|
27 | 2408 |
self.Project = self.Copy(self.ProjectBuffer.Next()) |
0 | 2409 |
|
2410 |
def GetBufferState(self): |
|
27 | 2411 |
first = self.ProjectBuffer.IsFirst() |
2412 |
last = self.ProjectBuffer.IsLast() |
|
0 | 2413 |
return not first, not last |