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