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