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