author | lbessard |
Tue, 10 Jul 2007 14:29:31 +0200 | |
changeset 31 | d833bf7567b1 |
parent 29 | 3b7e23a323a6 |
child 33 | 0dd4a876392f |
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 |
# |
|
7 |
#Copyright (C): Edouard TISSERANT and Laurent BESSARD |
|
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 |
|
19 |
#Lesser General Public License for more details. |
|
20 |
# |
|
5 | 21 |
#You should have received a copy of the GNU General Public |
0 | 22 |
#License along with this library; if not, write to the Free Software |
23 |
#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
24 |
||
25 |
from minixsv import pyxsval |
|
27 | 26 |
from xml.dom import minidom |
0 | 27 |
import cPickle |
28 |
import os,sys,re |
|
24 | 29 |
from datetime import * |
0 | 30 |
|
31 |
from plcopen import plcopen |
|
32 |
from plcopen.structures import * |
|
33 |
from graphics.GraphicCommons import * |
|
34 |
from PLCGenerator import * |
|
35 |
||
24 | 36 |
duration_model = re.compile("(?:([0-9]{1,2})h)?(?:([0-9]{1,2})m)?(?:([0-9]{1,2})s)?(?:([0-9]{1,3})ms)?") |
37 |
||
0 | 38 |
[ITEM_UNEDITABLE, ITEM_PROJECT, ITEM_POU, ITEM_CLASS, ITEM_VARIABLE, |
39 |
ITEM_TRANSITION, ITEM_ACTION, ITEM_CONFIGURATION, ITEM_RESOURCE] = range(9) |
|
40 |
||
2 | 41 |
""" |
42 |
pyxsval is not complete and the parts that are not supported print some error |
|
43 |
reports. This class is used for not displaying them |
|
44 |
""" |
|
45 |
class HolePseudoFile: |
|
46 |
""" Base class for file like objects to facilitate StdOut for the Shell.""" |
|
47 |
def __init__(self, output = None): |
|
48 |
if output is None: output = [] |
|
49 |
self.output = output |
|
50 |
||
51 |
def writelines(self, l): |
|
52 |
map(self.write, l) |
|
53 |
||
54 |
def write(self, s): |
|
55 |
pass |
|
56 |
||
57 |
def flush(self): |
|
58 |
pass |
|
59 |
||
60 |
def isatty(self): |
|
61 |
return false |
|
62 |
||
0 | 63 |
#------------------------------------------------------------------------------- |
64 |
# Undo Buffer for PLCOpenEditor |
|
65 |
#------------------------------------------------------------------------------- |
|
66 |
||
67 |
# Length of the buffer |
|
68 |
UNDO_BUFFER_LENGTH = 20 |
|
69 |
||
70 |
""" |
|
71 |
Class implementing a buffer of changes made on the current editing Object Dictionary |
|
72 |
""" |
|
73 |
class UndoBuffer: |
|
74 |
||
75 |
# Constructor initialising buffer |
|
76 |
def __init__(self, currentstate, issaved = False): |
|
77 |
self.Buffer = [] |
|
78 |
self.CurrentIndex = -1 |
|
79 |
self.MinIndex = -1 |
|
80 |
self.MaxIndex = -1 |
|
81 |
# if current state is defined |
|
82 |
if currentstate: |
|
83 |
self.CurrentIndex = 0 |
|
84 |
self.MinIndex = 0 |
|
85 |
self.MaxIndex = 0 |
|
86 |
# Initialising buffer with currentstate at the first place |
|
87 |
for i in xrange(UNDO_BUFFER_LENGTH): |
|
88 |
if i == 0: |
|
89 |
self.Buffer.append(currentstate) |
|
90 |
else: |
|
91 |
self.Buffer.append(None) |
|
92 |
# Initialising index of state saved |
|
93 |
if issaved: |
|
94 |
self.LastSave = 0 |
|
95 |
else: |
|
96 |
self.LastSave = -1 |
|
97 |
||
98 |
# Add a new state in buffer |
|
99 |
def Buffering(self, currentstate): |
|
100 |
self.CurrentIndex = (self.CurrentIndex + 1) % UNDO_BUFFER_LENGTH |
|
101 |
self.Buffer[self.CurrentIndex] = currentstate |
|
102 |
# Actualising buffer limits |
|
103 |
self.MaxIndex = self.CurrentIndex |
|
104 |
if self.MinIndex == self.CurrentIndex: |
|
105 |
# If the removed state was the state saved, there is no state saved in the buffer |
|
106 |
if self.LastSave == self.MinIndex: |
|
107 |
self.LastSave = -1 |
|
108 |
self.MinIndex = (self.MinIndex + 1) % UNDO_BUFFER_LENGTH |
|
109 |
self.MinIndex = max(self.MinIndex, 0) |
|
110 |
||
111 |
# Return current state of buffer |
|
112 |
def Current(self): |
|
113 |
return self.Buffer[self.CurrentIndex] |
|
114 |
||
115 |
# Change current state to previous in buffer and return new current state |
|
116 |
def Previous(self): |
|
117 |
if self.CurrentIndex != self.MinIndex: |
|
118 |
self.CurrentIndex = (self.CurrentIndex - 1) % UNDO_BUFFER_LENGTH |
|
119 |
return self.Buffer[self.CurrentIndex] |
|
120 |
return None |
|
121 |
||
122 |
# Change current state to next in buffer and return new current state |
|
123 |
def Next(self): |
|
124 |
if self.CurrentIndex != self.MaxIndex: |
|
125 |
self.CurrentIndex = (self.CurrentIndex + 1) % UNDO_BUFFER_LENGTH |
|
126 |
return self.Buffer[self.CurrentIndex] |
|
127 |
return None |
|
128 |
||
129 |
# Return True if current state is the first in buffer |
|
130 |
def IsFirst(self): |
|
131 |
return self.CurrentIndex == self.MinIndex |
|
132 |
||
133 |
# Return True if current state is the last in buffer |
|
134 |
def IsLast(self): |
|
135 |
return self.CurrentIndex == self.MaxIndex |
|
136 |
||
137 |
# Note that current state is saved |
|
138 |
def CurrentSaved(self): |
|
139 |
self.LastSave = self.CurrentIndex |
|
140 |
||
141 |
# Return True if current state is saved |
|
142 |
def IsCurrentSaved(self): |
|
143 |
return self.LastSave == self.CurrentIndex |
|
144 |
||
145 |
||
146 |
#------------------------------------------------------------------------------- |
|
147 |
# Controler for PLCOpenEditor |
|
148 |
#------------------------------------------------------------------------------- |
|
149 |
||
150 |
""" |
|
151 |
Class which controls the operations made on the plcopen model and answers to view requests |
|
152 |
""" |
|
153 |
class PLCControler: |
|
154 |
||
155 |
# Create a new PLCControler |
|
156 |
def __init__(self): |
|
157 |
self.LastNewIndex = 0 |
|
158 |
self.Reset() |
|
159 |
||
160 |
# Reset PLCControler internal variables |
|
161 |
def Reset(self): |
|
27 | 162 |
self.VerifyXML = False |
0 | 163 |
self.Project = None |
164 |
self.ProjectBuffer = None |
|
165 |
self.FilePath = "" |
|
166 |
self.FileName = "" |
|
167 |
self.ElementsOpened = [] |
|
168 |
self.CurrentElementEditing = None |
|
169 |
self.RefreshPouUsingTree() |
|
170 |
self.RefreshBlockTypes() |
|
171 |
||
172 |
def GetQualifierTypes(self): |
|
173 |
return plcopen.QualifierList |
|
174 |
||
175 |
||
176 |
#------------------------------------------------------------------------------- |
|
177 |
# Project management functions |
|
178 |
#------------------------------------------------------------------------------- |
|
179 |
||
180 |
# Return if a project is opened |
|
181 |
def HasOpenedProject(self): |
|
182 |
return self.Project != None |
|
183 |
||
184 |
# Create a new project by replacing the current one |
|
185 |
def CreateNewProject(self, name): |
|
186 |
# Create the project |
|
187 |
self.Project = plcopen.project() |
|
188 |
self.Project.setName(name) |
|
189 |
# Initialize the project buffer |
|
27 | 190 |
#self.ProjectBuffer = UndoBuffer(self.Copy(self.Project)) |
0 | 191 |
|
192 |
# Change project name |
|
193 |
def SetProjectName(self, name): |
|
194 |
self.Project.setName(name) |
|
195 |
||
196 |
# Return project name |
|
197 |
def GetProjectName(self): |
|
198 |
return self.Project.getName() |
|
199 |
||
200 |
# Return project pou names |
|
201 |
def GetProjectPouNames(self): |
|
202 |
return [pou.getName() for pou in self.Project.getPous()] |
|
203 |
||
204 |
# Return project pou names |
|
205 |
def GetProjectConfigNames(self): |
|
206 |
return [config.getName() for config in self.Project.getConfigurations()] |
|
207 |
||
6 | 208 |
# Return project pou variables |
209 |
def GetProjectPouVariables(self, pou_name=None): |
|
210 |
variables = [] |
|
211 |
for pou in self.Project.getPous(): |
|
212 |
if not pou_name or pou_name == pou.getName(): |
|
213 |
variables.extend([var["Name"] for var in self.GetPouInterfaceVars(pou)]) |
|
214 |
if pou.getBodyType() == "SFC": |
|
215 |
for transition in pou.getTransitionList(): |
|
216 |
variables.append(transition.getName()) |
|
217 |
for action in pou.getActionList(): |
|
218 |
variables.append(action.getName()) |
|
219 |
return variables |
|
220 |
||
0 | 221 |
# Return file path if project is an open file |
222 |
def GetFilePath(self): |
|
223 |
return self.FilePath |
|
224 |
||
225 |
# Return file name and point out if file is up to date |
|
226 |
def GetFilename(self): |
|
227 |
if self.ProjectBuffer.IsCurrentSaved(): |
|
228 |
return self.FileName |
|
229 |
else: |
|
230 |
return "~%s~"%self.FileName |
|
231 |
||
232 |
# Change file path and save file name or create a default one if file path not defined |
|
233 |
def SetFilePath(self, filepath): |
|
234 |
self.FilePath = filepath |
|
235 |
if filepath == "": |
|
236 |
self.LastNewIndex += 1 |
|
237 |
self.FileName = "Unnamed%d"%self.LastNewIndex |
|
238 |
else: |
|
239 |
self.FileName = os.path.splitext(os.path.basename(filepath))[0] |
|
240 |
||
241 |
# Change project properties |
|
242 |
def SetProjectProperties(self, values): |
|
243 |
self.Project.setFileHeader(values) |
|
244 |
||
245 |
# Return project properties |
|
246 |
def GetProjectProperties(self): |
|
247 |
return self.Project.getFileHeader() |
|
248 |
||
249 |
# Return project informations |
|
250 |
def GetProjectInfos(self): |
|
251 |
if self.Project: |
|
252 |
infos = {"name": self.Project.getName(), "type": ITEM_PROJECT} |
|
253 |
pou_types = {"function": {"name": "Functions", "type": ITEM_UNEDITABLE, "values":[]}, |
|
254 |
"functionBlock": {"name": "Function Blocks", "type": ITEM_UNEDITABLE, "values":[]}, |
|
255 |
"program": {"name": "Programs", "type": ITEM_UNEDITABLE, "values":[]}} |
|
256 |
for pou in self.Project.getPous(): |
|
257 |
pou_type = pou.getPouType().getValue() |
|
258 |
pou_infos = {"name": pou.getName(), "type": ITEM_POU} |
|
259 |
var_types = {"Input": {"name": "Input", "type": ITEM_CLASS, "values": []}, |
|
260 |
"Output": {"name": "Output", "type": ITEM_CLASS, "values": []}, |
|
261 |
"InOut": {"name": "InOut", "type": ITEM_CLASS, "values": []}, |
|
262 |
"External": {"name": "External", "type": ITEM_CLASS, "values": []}, |
|
263 |
"Local": {"name": "Local", "type": ITEM_CLASS, "values": []}, |
|
264 |
"Temp": {"name": "Temp", "type": ITEM_CLASS, "values": []}, |
|
265 |
"Global": {"name": "Global", "type": ITEM_CLASS, "values": []}} |
|
266 |
for var in self.GetPouInterfaceVars(pou): |
|
267 |
var_values = {"name": var["Name"], "type": ITEM_VARIABLE, "values": []} |
|
268 |
if var["Class"] in var_types.keys(): |
|
269 |
var_types[var["Class"]]["values"].append(var_values) |
|
270 |
pou_values = [] |
|
271 |
pou_values.append({"name": "Interface", "type": ITEM_CLASS, |
|
272 |
"values": [var_types["Input"], var_types["Output"], var_types["InOut"], var_types["External"]]}) |
|
273 |
pou_values.append({"name": "Variables", "type": ITEM_CLASS, |
|
274 |
"values": [var_types["Local"], var_types["Temp"]]}) |
|
275 |
if pou_type == "program": |
|
276 |
pou_values.append(var_types["Global"]) |
|
277 |
if pou.getBodyType() == "SFC": |
|
278 |
transitions = [] |
|
279 |
for transition in pou.getTransitionList(): |
|
280 |
transitions.append({"name": transition.getName(), "type": ITEM_TRANSITION, "values": []}) |
|
281 |
pou_values.append({"name": "Transitions", "type": ITEM_UNEDITABLE, "values": transitions}) |
|
282 |
actions = [] |
|
283 |
for action in pou.getActionList(): |
|
284 |
actions.append({"name": action.getName(), "type": ITEM_ACTION, "values": []}) |
|
285 |
pou_values.append({"name": "Actions", "type": ITEM_UNEDITABLE, "values": actions}) |
|
286 |
if pou_type in pou_types: |
|
287 |
pou_infos["values"] = pou_values |
|
288 |
pou_types[pou_type]["values"].append(pou_infos) |
|
289 |
configurations = {"name": "Configurations", "type": ITEM_UNEDITABLE, "values": []} |
|
290 |
for config in self.Project.getConfigurations(): |
|
291 |
config_name = config.getName() |
|
292 |
config_infos = {"name": config_name, "type": ITEM_CONFIGURATION, "values": []} |
|
293 |
config_vars = {"name": "Global", "type": ITEM_CLASS, "values": []} |
|
294 |
for var in self.GetConfigurationGlobalVars(config_name): |
|
295 |
var_values = {"name": var["Name"], "type": ITEM_VARIABLE, "values": []} |
|
296 |
config_vars["values"].append(var_values) |
|
297 |
resources = {"name": "Resources", "type": ITEM_UNEDITABLE, "values": []} |
|
298 |
for resource in config.getResource(): |
|
299 |
resource_name = resource.getName() |
|
300 |
resource_infos = {"name": resource_name, "type": ITEM_RESOURCE, "values": []} |
|
301 |
resource_vars = {"name": "Global", "type": ITEM_CLASS, "values": []} |
|
302 |
for var in self.GetConfigurationResourceGlobalVars(config_name, resource_name): |
|
303 |
var_values = {"name": var["Name"], "type": ITEM_VARIABLE, "values": []} |
|
304 |
resource_vars["values"].append(var_values) |
|
305 |
resource_infos["values"].append(resource_vars) |
|
306 |
resources["values"].append(resource_infos) |
|
307 |
config_infos["values"] = [config_vars, resources] |
|
308 |
configurations["values"].append(config_infos) |
|
309 |
infos["values"] = [{"name": "Properties", "type": ITEM_UNEDITABLE, "values": []}, |
|
310 |
pou_types["function"], pou_types["functionBlock"], |
|
311 |
pou_types["program"], configurations] |
|
312 |
return infos |
|
313 |
return None |
|
314 |
||
315 |
# Refresh the tree of user-defined pou cross-use |
|
316 |
def RefreshPouUsingTree(self): |
|
317 |
# Reset the tree of user-defined pou cross-use |
|
318 |
self.PouUsingTree = {} |
|
319 |
if self.Project: |
|
320 |
pous = self.Project.getPous() |
|
321 |
# Reference all the user-defined pou names and initialize the tree of |
|
322 |
# user-defined pou cross-use |
|
323 |
pounames = [pou.getName() for pou in pous] |
|
324 |
for name in pounames: |
|
325 |
self.PouUsingTree[name] = [] |
|
326 |
# Analyze each pou |
|
327 |
for pou in pous: |
|
328 |
name = pou.getName() |
|
329 |
bodytype = pou.getBodyType() |
|
330 |
# If pou is written in a graphical language |
|
331 |
if bodytype in ["FBD","LD","SFC"]: |
|
332 |
# Analyze each instance of the pou |
|
333 |
for instance in pou.getInstances(): |
|
334 |
if isinstance(instance, plcopen.block): |
|
335 |
typename = instance.getTypeName() |
|
336 |
# Update tree if there is a cross-use |
|
337 |
if typename in pounames and name not in self.PouUsingTree[typename]: |
|
338 |
self.PouUsingTree[typename].append(name) |
|
339 |
# If pou is written in a textual language |
|
340 |
elif bodytype in ["IL", "ST"]: |
|
341 |
text = pou.getText() |
|
342 |
# Search if each pou is mentioned in the pou text |
|
343 |
for typename in pounames: |
|
344 |
typename_model = re.compile("[ \t\n]%s[ \t\n]"%typename) |
|
345 |
# Update tree if there is a cross-use |
|
346 |
if typename != name and typename_model.search(text): |
|
347 |
self.PouUsingTree[typename].append(name) |
|
348 |
||
349 |
# Return if pou given by name is used by another pou |
|
350 |
def PouIsUsed(self, name): |
|
351 |
if name in self.PouUsingTree: |
|
352 |
return len(self.PouUsingTree[name]) > 0 |
|
353 |
return False |
|
354 |
||
355 |
# Return if pou given by name is directly or undirectly used by the reference pou |
|
356 |
def PouIsUsedBy(self, name, reference): |
|
357 |
if name in self.PouUsingTree: |
|
358 |
list = self.PouUsingTree[name] |
|
359 |
# Test if pou is directly used by reference |
|
360 |
if reference in list: |
|
361 |
return True |
|
362 |
else: |
|
363 |
# Test if pou is undirectly used by reference, by testing if pous |
|
364 |
# that directly use pou is directly or undirectly used by reference |
|
365 |
used = False |
|
366 |
for element in list: |
|
367 |
used |= self.PouIsUsedBy(element, reference) |
|
368 |
return used |
|
369 |
return False |
|
370 |
||
4
2de7fd952fdd
Adding File Dialog for choosing path to generated program
lbessard
parents:
2
diff
changeset
|
371 |
def GenerateProgram(self, filepath): |
0 | 372 |
if self.Project: |
28
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
373 |
#try: |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
374 |
program = GenerateCurrentProgram(self.Project) |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
375 |
programfile = open(filepath, "w") |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
376 |
programfile.write(program) |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
377 |
programfile.close() |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
378 |
return True |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
379 |
#except: |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
380 |
# pass |
4
2de7fd952fdd
Adding File Dialog for choosing path to generated program
lbessard
parents:
2
diff
changeset
|
381 |
return False |
0 | 382 |
|
383 |
#------------------------------------------------------------------------------- |
|
384 |
# Project Pous management functions |
|
385 |
#------------------------------------------------------------------------------- |
|
386 |
||
387 |
# Add a Pou to Project |
|
388 |
def ProjectAddPou(self, name, pou_type, body_type): |
|
389 |
# Add the pou to project |
|
390 |
self.Project.appendPou(name, pou_type, body_type) |
|
391 |
self.RefreshPouUsingTree() |
|
392 |
self.RefreshBlockTypes() |
|
393 |
||
394 |
# Remove a pou from project |
|
395 |
def ProjectRemovePou(self, name): |
|
396 |
removed = None |
|
397 |
# Search if the pou removed is currently opened |
|
398 |
for i, pou in enumerate(self.ElementsOpened): |
|
399 |
if pou == name: |
|
400 |
removed = i |
|
401 |
# If found, remove pou from list of opened pous and actualize current edited |
|
402 |
if removed != None: |
|
403 |
self.ElementsOpened.pop(removed) |
|
404 |
if self.CurrentElementEditing > removed: |
|
405 |
self.CurrentElementEditing -= 1 |
|
406 |
if len(self.ElementsOpened) > 0: |
|
407 |
self.CurrentElementEditing = max(0, min(self.CurrentElementEditing, len(self.ElementsOpened) - 1)) |
|
408 |
else: |
|
409 |
self.CurrentElementEditing = None |
|
410 |
# Remove pou from project |
|
411 |
self.Project.removePou(name) |
|
412 |
self.RefreshPouUsingTree() |
|
413 |
self.RefreshBlockTypes() |
|
414 |
||
415 |
# Add a configuration to Project |
|
416 |
def ProjectAddConfiguration(self, name): |
|
417 |
self.Project.addConfiguration(name) |
|
418 |
self.RefreshPouUsingTree() |
|
419 |
self.RefreshBlockTypes() |
|
420 |
||
421 |
# Remove a configuration from project |
|
422 |
def ProjectRemoveConfiguration(self, name): |
|
423 |
self.Project.removeConfiguration(name) |
|
424 |
self.RefreshPouUsingTree() |
|
425 |
self.RefreshBlockTypes() |
|
426 |
||
427 |
# Add a resource to a configuration of the Project |
|
428 |
def ProjectAddConfigurationResource(self, config, name): |
|
429 |
self.Project.addConfigurationResource(config, name) |
|
430 |
self.RefreshPouUsingTree() |
|
431 |
self.RefreshBlockTypes() |
|
432 |
||
433 |
# Remove a resource from a configuration of the project |
|
434 |
def ProjectRemoveConfigurationResource(self, config, name): |
|
435 |
self.Project.removeConfigurationResource(config, name) |
|
436 |
self.RefreshPouUsingTree() |
|
437 |
self.RefreshBlockTypes() |
|
438 |
||
439 |
# Add a Transition to a Project Pou |
|
440 |
def ProjectAddPouTransition(self, pou_name, transition_name, transition_type): |
|
441 |
pou = self.Project.getPou(pou_name) |
|
442 |
pou.addTransition(transition_name, transition_type) |
|
443 |
||
444 |
# Add a Transition to a Project Pou |
|
445 |
def ProjectAddPouAction(self, pou_name, action_name, action_type): |
|
446 |
pou = self.Project.getPou(pou_name) |
|
447 |
pou.addAction(action_name, action_type) |
|
448 |
||
449 |
# Change the name of a pou |
|
450 |
def ChangePouName(self, old_name, new_name): |
|
451 |
# Found the pou corresponding to old name and change its name to new name |
|
452 |
pou = self.Project.getPou(old_name) |
|
453 |
pou.setName(new_name) |
|
454 |
# If pou is currently opened, change its name in the list of opened pous |
|
455 |
if old_name in self.ElementsOpened: |
|
456 |
idx = self.ElementsOpened.index(old_name) |
|
457 |
self.ElementsOpened[idx] = new_name |
|
458 |
self.RefreshPouUsingTree() |
|
459 |
self.RefreshBlockTypes() |
|
460 |
||
461 |
# Change the name of a pou transition |
|
462 |
def ChangePouTransitionName(self, pou_name, old_name, new_name): |
|
463 |
# Found the pou transition corresponding to old name and change its name to new name |
|
464 |
pou = self.Project.getPou(pou_name) |
|
465 |
transition = pou.getTransition(old_name) |
|
466 |
transition.setName(new_name) |
|
467 |
# If pou transition is currently opened, change its name in the list of opened elements |
|
468 |
old_computedname = self.ComputePouTransitionName(pou_name, old_name) |
|
469 |
new_computedname = self.ComputePouTransitionName(pou_name, new_name) |
|
470 |
if old_computedname in self.ElementsOpened: |
|
471 |
idx = self.ElementsOpened.index(old_computedname) |
|
472 |
self.ElementsOpened[idx] = new_computedname |
|
473 |
||
474 |
# Change the name of a pou action |
|
475 |
def ChangePouActionName(self, pou_name, old_name, new_name): |
|
476 |
# Found the pou action corresponding to old name and change its name to new name |
|
477 |
pou = self.Project.getPou(pou_name) |
|
478 |
action = pou.getAction(old_name) |
|
479 |
action.setName(new_name) |
|
480 |
# If pou action is currently opened, change its name in the list of opened elements |
|
481 |
old_computedname = self.ComputePouActionName(pou_name, old_name) |
|
482 |
new_computedname = self.ComputePouActionName(pou_name, new_name) |
|
483 |
if old_computedname in self.ElementsOpened: |
|
484 |
idx = self.ElementsOpened.index(old_computedname) |
|
485 |
self.ElementsOpened[idx] = new_computedname |
|
486 |
||
6 | 487 |
# Change the name of a pou action |
488 |
def ChangePouVariableName(self, pou_name, old_name, new_name): |
|
489 |
# Found the pou action corresponding to old name and change its name to new name |
|
490 |
pou = self.Project.getPou(pou_name) |
|
491 |
for type, varlist in pou.getVars(): |
|
492 |
for var in varlist.getVariable(): |
|
493 |
if var.getName() == old_name: |
|
494 |
var.setName(new_name) |
|
495 |
self.RefreshBlockTypes() |
|
496 |
||
0 | 497 |
# Change the name of a configuration |
498 |
def ChangeConfigurationName(self, old_name, new_name): |
|
499 |
# Found the configuration corresponding to old name and change its name to new name |
|
500 |
configuration = self.Project.getConfiguration(old_name) |
|
501 |
configuration.setName(new_name) |
|
502 |
# If configuration is currently opened, change its name in the list of opened elements |
|
503 |
for idx, element in enumerate(self.ElementsOpened): |
|
504 |
self.ElementsOpened[idx] = element.replace(old_name, new_name) |
|
505 |
||
506 |
# Change the name of a configuration resource |
|
507 |
def ChangeConfigurationResourceName(self, config_name, old_name, new_name): |
|
508 |
# Found the resource corresponding to old name and change its name to new name |
|
509 |
resource = self.Project.getConfigurationResource(config_name) |
|
510 |
resource.setName(new_name) |
|
511 |
# If resource is currently opened, change its name in the list of opened elements |
|
512 |
old_computedname = self.ComputeConfigurationResourceName(config_name, old_name) |
|
513 |
new_computedname = self.ComputeConfigurationResourceName(config_name, new_name) |
|
514 |
if old_computedname in self.ElementsOpened: |
|
515 |
idx = self.ElementsOpened.index(old_computedname) |
|
516 |
self.ElementsOpened[idx] = new_computedname |
|
517 |
||
518 |
# Return the type of the pou given by its name |
|
519 |
def GetPouType(self, name): |
|
520 |
# Found the pou correponding to name and return its type |
|
521 |
pou = self.Project.getPou(name) |
|
522 |
return pou.pouType.getValue() |
|
523 |
||
524 |
# Return pous with SFC language |
|
525 |
def GetSFCPous(self): |
|
526 |
list = [] |
|
527 |
if self.Project: |
|
528 |
for pou in self.Project.getPous(): |
|
529 |
if pou.getBodyType() == "SFC": |
|
530 |
list.append(pou.getName()) |
|
531 |
return list |
|
532 |
||
533 |
# Return the body language of the pou given by its name |
|
534 |
def GetPouBodyType(self, name): |
|
535 |
# Found the pou correponding to name and return its body language |
|
536 |
pou = self.Project.getPou(name) |
|
537 |
return pou.getBodyType() |
|
538 |
||
539 |
# Return the body language of the transition given by its name |
|
540 |
def GetTransitionBodyType(self, pou_name, pou_transition): |
|
541 |
# Found the pou correponding to name and return its body language |
|
542 |
pou = self.Project.getPou(pou_name) |
|
543 |
transition = pou.getTransition(pou_transition) |
|
544 |
return transition.getBodyType() |
|
545 |
||
546 |
# Return the body language of the pou given by its name |
|
547 |
def GetActionBodyType(self, pou_name, pou_action): |
|
548 |
# Found the pou correponding to name and return its body language |
|
549 |
pou = self.Project.getPou(pou_name) |
|
550 |
action = pou.getAction(pou_action) |
|
551 |
return action.getBodyType() |
|
552 |
||
553 |
# Extract varlists from a list of vars |
|
554 |
def ExtractVarLists(self, vars): |
|
555 |
varlist_list = [] |
|
556 |
current_varlist = None |
|
557 |
current_type = None |
|
558 |
for var in vars: |
|
559 |
if current_type != (var["Class"], var["Retain"], var["Constant"]): |
|
560 |
current_type = (var["Class"], var["Retain"], var["Constant"]) |
|
561 |
current_varlist = plcopen.varList() |
|
562 |
varlist_list.append((var["Class"], current_varlist)) |
|
563 |
if var["Retain"] == "Yes": |
|
564 |
varlist.setRetain(True) |
|
565 |
if var["Constant"] == "Yes": |
|
566 |
varlist.setConstant(True) |
|
567 |
# Create variable and change its properties |
|
568 |
tempvar = plcopen.varListPlain_variable() |
|
569 |
tempvar.setName(var["Name"]) |
|
570 |
var_type = plcopen.dataType() |
|
571 |
var_type.setValue(var["Type"]) |
|
572 |
tempvar.setType(var_type) |
|
573 |
if var["Initial Value"] != "": |
|
574 |
value = plcopen.value() |
|
575 |
value.setValue(var["Initial Value"]) |
|
576 |
tempvar.setInitialValue(value) |
|
577 |
if var["Location"] != "": |
|
578 |
tempvar.setAddress(var["Location"]) |
|
579 |
# Add variable to varList |
|
580 |
current_varlist.appendVariable(tempvar) |
|
581 |
return varlist_list |
|
582 |
||
583 |
# Replace the configuration globalvars by those given |
|
584 |
def SetConfigurationGlobalVars(self, name, vars): |
|
585 |
# Found the configuration corresponding to name |
|
586 |
configuration = self.Project.getConfiguration(name) |
|
587 |
if configuration: |
|
588 |
# Set configuration global vars |
|
589 |
configuration.setGlobalVars([]) |
|
590 |
for vartype, varlist in self.ExtractVarLists(vars): |
|
591 |
configuration.globalVars.append(varlist) |
|
592 |
self.RefreshBlockTypes() |
|
593 |
||
594 |
# Return the configuration globalvars |
|
595 |
def GetConfigurationGlobalVars(self, name): |
|
596 |
vars = [] |
|
597 |
# Found the configuration corresponding to name |
|
598 |
configuration = self.Project.getConfiguration(name) |
|
599 |
if configuration: |
|
600 |
# Extract variables from every varLists |
|
601 |
for varlist in configuration.getGlobalVars(): |
|
602 |
for var in varlist.getVariable(): |
|
603 |
tempvar = {"Name":var.getName(),"Class":"Global","Type":var.getType().getValue(), |
|
604 |
"Location":var.getAddress()} |
|
605 |
initial = var.getInitialValue() |
|
606 |
if initial: |
|
607 |
tempvar["Initial Value"] = initial.getValue() |
|
608 |
else: |
|
609 |
tempvar["Initial Value"] = "" |
|
610 |
if varlist.getRetain(): |
|
611 |
tempvar["Retain"] = "Yes" |
|
612 |
else: |
|
613 |
tempvar["Retain"] = "No" |
|
614 |
if varlist.getConstant(): |
|
615 |
tempvar["Constant"] = "Yes" |
|
616 |
else: |
|
617 |
tempvar["Constant"] = "No" |
|
618 |
vars.append(tempvar) |
|
619 |
return vars |
|
620 |
||
621 |
# Replace the resource globalvars by those given |
|
622 |
def SetConfigurationResourceGlobalVars(self, config_name, name, vars): |
|
623 |
# Found the resource corresponding to name |
|
624 |
resource = self.Project.getConfigurationResource(config_name, name) |
|
625 |
# Set resource global vars |
|
626 |
if resource: |
|
627 |
resource.setGlobalVars([]) |
|
628 |
for vartype, varlist in self.ExtractVarLists(vars): |
|
629 |
resource.globalVars.append(varlist) |
|
630 |
self.RefreshBlockTypes() |
|
631 |
||
632 |
# Return the resource globalvars |
|
633 |
def GetConfigurationResourceGlobalVars(self, config_name, name): |
|
634 |
vars = [] |
|
635 |
# Found the resource corresponding to name |
|
636 |
resource = self.Project.getConfigurationResource(config_name, name) |
|
637 |
if resource: |
|
638 |
# Extract variables from every varLists |
|
639 |
for varlist in resource.getGlobalVars(): |
|
640 |
for var in varlist.getVariable(): |
|
641 |
tempvar = {"Name":var.getName(),"Class":"Global","Type":var.getType().getValue(), |
|
642 |
"Location":var.getAddress()} |
|
643 |
initial = var.getInitialValue() |
|
644 |
if initial: |
|
645 |
tempvar["Initial Value"] = initial.getValue() |
|
646 |
else: |
|
647 |
tempvar["Initial Value"] = "" |
|
648 |
if varlist.getRetain(): |
|
649 |
tempvar["Retain"] = "Yes" |
|
650 |
else: |
|
651 |
tempvar["Retain"] = "No" |
|
652 |
if varlist.getConstant(): |
|
653 |
tempvar["Constant"] = "Yes" |
|
654 |
else: |
|
655 |
tempvar["Constant"] = "No" |
|
656 |
vars.append(tempvar) |
|
657 |
return vars |
|
658 |
||
659 |
# Return the interface of the pou given by its name |
|
660 |
def GetPouInterfaceVarsByName(self, name): |
|
661 |
# Found the pou correponding to name and return the interface |
|
662 |
return self.GetPouInterfaceVars(self.Project.getPou(name)) |
|
663 |
||
664 |
# Return the interface for the given pou |
|
665 |
def GetPouInterfaceVars(self, pou): |
|
666 |
vars = [] |
|
667 |
# Verify that the pou has an interface |
|
668 |
if pou.interface: |
|
669 |
# Extract variables from every varLists |
|
670 |
for type, varlist in pou.getVars(): |
|
671 |
for var in varlist.getVariable(): |
|
672 |
tempvar = {"Name":var.getName(),"Class":type,"Type":var.getType().getValue(), |
|
673 |
"Location":var.getAddress()} |
|
674 |
initial = var.getInitialValue() |
|
675 |
if initial: |
|
676 |
tempvar["Initial Value"] = initial.getValue() |
|
677 |
else: |
|
678 |
tempvar["Initial Value"] = "" |
|
679 |
if varlist.getRetain(): |
|
680 |
tempvar["Retain"] = "Yes" |
|
681 |
else: |
|
682 |
tempvar["Retain"] = "No" |
|
683 |
if varlist.getConstant(): |
|
684 |
tempvar["Constant"] = "Yes" |
|
685 |
else: |
|
686 |
tempvar["Constant"] = "No" |
|
687 |
vars.append(tempvar) |
|
688 |
return vars |
|
689 |
||
690 |
# Replace the Pou interface by the one given |
|
691 |
def SetPouInterfaceVars(self, name, vars): |
|
692 |
# Found the pou corresponding to name and add interface if there isn't one yet |
|
693 |
pou = self.Project.getPou(name) |
|
694 |
if not pou.interface: |
|
695 |
pou.interface = plcopen.pou_interface() |
|
696 |
# Set Pou interface |
|
697 |
pou.setVars(self.ExtractVarLists(vars)) |
|
698 |
self.RefreshBlockTypes() |
|
699 |
||
700 |
# Replace the return type of the pou given by its name (only for functions) |
|
701 |
def SetPouInterfaceReturnType(self, name, type): |
|
702 |
pou = self.Project.getPou(name) |
|
703 |
if not pou.interface: |
|
704 |
pou.interface = plcopen.pou_interface() |
|
705 |
# If there isn't any return type yet, add it |
|
706 |
return_type = pou.interface.getReturnType() |
|
707 |
if not return_type: |
|
708 |
return_type = plcopen.dataType() |
|
709 |
pou.interface.setReturnType(return_type) |
|
710 |
# Change return type |
|
711 |
return_type.setValue(type) |
|
712 |
self.RefreshBlockTypes() |
|
713 |
||
714 |
# Return the return type of the pou given by its name |
|
715 |
def GetPouInterfaceReturnTypeByName(self, name): |
|
716 |
# Found the pou correponding to name and return the return type |
|
717 |
return self.GetPouInterfaceReturnType(self.Project.getPou(name)) |
|
718 |
||
719 |
# Return the return type of the given pou |
|
720 |
def GetPouInterfaceReturnType(self, pou): |
|
721 |
# Verify that the pou has an interface |
|
722 |
if pou.interface: |
|
723 |
# Return the return type if there is one |
|
724 |
return_type = pou.interface.getReturnType() |
|
725 |
if return_type: |
|
726 |
return return_type.getValue() |
|
727 |
return None |
|
728 |
||
729 |
# Update Block types with user-defined pou added |
|
730 |
def RefreshBlockTypes(self): |
|
731 |
if BlockTypes[-1]["name"] == "User-defined POUs": |
|
732 |
BlockTypes[-1]["list"] = [] |
|
733 |
else: |
|
734 |
BlockTypes.append({"name" : "User-defined POUs", "list": []}) |
|
735 |
if self.Project: |
|
736 |
for pou in self.Project.getPous(): |
|
737 |
pou_name = pou.getName() |
|
738 |
pou_type = pou.pouType.getValue() |
|
739 |
if pou_type != "program": |
|
740 |
block_infos = {"name" : pou_name, "type" : pou_type, "extensible" : False, |
|
741 |
"inputs" : [], "outputs" : [], "comment" : ""} |
|
742 |
if pou.getInterface(): |
|
743 |
for type, varlist in pou.getVars(): |
|
744 |
if type == "InOut": |
|
745 |
for var in varlist.getVariable(): |
|
746 |
block_infos["inputs"].append((var.getName(),var.getType().getValue(),"none")) |
|
747 |
block_infos["outputs"].append((var.getName(),var.getType().getValue(),"none")) |
|
748 |
elif type == "Input": |
|
749 |
for var in varlist.getVariable(): |
|
750 |
block_infos["inputs"].append((var.getName(),var.getType().getValue(),"none")) |
|
751 |
elif type == "Output": |
|
752 |
for var in varlist.getVariable(): |
|
753 |
block_infos["outputs"].append((var.getName(),var.getType().getValue(),"none")) |
|
754 |
return_type = pou.interface.getReturnType() |
|
755 |
if return_type: |
|
756 |
block_infos["outputs"].append(("",return_type.getValue(),"none")) |
|
757 |
if pou.getBodyType() in ["FBD","LD","SFC"]: |
|
758 |
for instance in pou.getInstances(): |
|
759 |
if isinstance(instance, plcopen.comment): |
|
760 |
block_infos["comment"] = instance.getContentText() |
|
761 |
BlockTypes[-1]["list"].append(block_infos) |
|
762 |
||
763 |
# Return Block types checking for recursion |
|
764 |
def GetBlockTypes(self): |
|
765 |
if self.CurrentElementEditing != None: |
|
13
69075340d6a9
Adding support for forbidding insertion of function block into function
lbessard
parents:
6
diff
changeset
|
766 |
if self.Project: |
69075340d6a9
Adding support for forbidding insertion of function block into function
lbessard
parents:
6
diff
changeset
|
767 |
current_name = self.ElementsOpened[self.CurrentElementEditing] |
69075340d6a9
Adding support for forbidding insertion of function block into function
lbessard
parents:
6
diff
changeset
|
768 |
words = current_name.split("::") |
69075340d6a9
Adding support for forbidding insertion of function block into function
lbessard
parents:
6
diff
changeset
|
769 |
if len(words) == 1: |
69075340d6a9
Adding support for forbidding insertion of function block into function
lbessard
parents:
6
diff
changeset
|
770 |
name = current_name |
69075340d6a9
Adding support for forbidding insertion of function block into function
lbessard
parents:
6
diff
changeset
|
771 |
else: |
69075340d6a9
Adding support for forbidding insertion of function block into function
lbessard
parents:
6
diff
changeset
|
772 |
name = words[1] |
69075340d6a9
Adding support for forbidding insertion of function block into function
lbessard
parents:
6
diff
changeset
|
773 |
type = self.GetPouType(name) |
0 | 774 |
else: |
13
69075340d6a9
Adding support for forbidding insertion of function block into function
lbessard
parents:
6
diff
changeset
|
775 |
name = "" |
69075340d6a9
Adding support for forbidding insertion of function block into function
lbessard
parents:
6
diff
changeset
|
776 |
type = None |
69075340d6a9
Adding support for forbidding insertion of function block into function
lbessard
parents:
6
diff
changeset
|
777 |
if type == "function": |
69075340d6a9
Adding support for forbidding insertion of function block into function
lbessard
parents:
6
diff
changeset
|
778 |
blocktypes = [] |
69075340d6a9
Adding support for forbidding insertion of function block into function
lbessard
parents:
6
diff
changeset
|
779 |
for category in BlockTypes[:-1]: |
69075340d6a9
Adding support for forbidding insertion of function block into function
lbessard
parents:
6
diff
changeset
|
780 |
cat = {"name" : category["name"], "list" : []} |
69075340d6a9
Adding support for forbidding insertion of function block into function
lbessard
parents:
6
diff
changeset
|
781 |
for block in category["list"]: |
69075340d6a9
Adding support for forbidding insertion of function block into function
lbessard
parents:
6
diff
changeset
|
782 |
if block["type"] == "function": |
69075340d6a9
Adding support for forbidding insertion of function block into function
lbessard
parents:
6
diff
changeset
|
783 |
cat["list"].append(block) |
69075340d6a9
Adding support for forbidding insertion of function block into function
lbessard
parents:
6
diff
changeset
|
784 |
if len(cat["list"]) > 0: |
69075340d6a9
Adding support for forbidding insertion of function block into function
lbessard
parents:
6
diff
changeset
|
785 |
blocktypes.append(cat) |
69075340d6a9
Adding support for forbidding insertion of function block into function
lbessard
parents:
6
diff
changeset
|
786 |
else: |
69075340d6a9
Adding support for forbidding insertion of function block into function
lbessard
parents:
6
diff
changeset
|
787 |
blocktypes = [category for category in BlockTypes[:-1]] |
0 | 788 |
if self.Project: |
13
69075340d6a9
Adding support for forbidding insertion of function block into function
lbessard
parents:
6
diff
changeset
|
789 |
blocktypes.append({"name" : "User-defined POUs", "list": []}) |
0 | 790 |
for blocktype in BlockTypes[-1]["list"]: |
13
69075340d6a9
Adding support for forbidding insertion of function block into function
lbessard
parents:
6
diff
changeset
|
791 |
if blocktype["name"] != name and not self.PouIsUsedBy(name, blocktype["name"]) and not (type == "function" and blocktype["type"] != "function"): |
0 | 792 |
blocktypes[-1]["list"].append(blocktype) |
793 |
return blocktypes |
|
794 |
return [] |
|
795 |
||
796 |
# Return Block types checking for recursion |
|
797 |
def GetBlockResource(self): |
|
798 |
blocktypes = [] |
|
799 |
for category in BlockTypes[:-1]: |
|
800 |
for blocktype in category["list"]: |
|
29 | 801 |
if blocktype["type"] == "program": |
0 | 802 |
blocktypes.append(blocktype["name"]) |
803 |
if self.Project: |
|
804 |
for pou in self.Project.getPous(): |
|
29 | 805 |
if pou.pouType.getValue() == "program": |
0 | 806 |
blocktypes.append(pou.getName()) |
807 |
return blocktypes |
|
808 |
||
809 |
#------------------------------------------------------------------------------- |
|
810 |
# Project opened Pous management functions |
|
811 |
#------------------------------------------------------------------------------- |
|
812 |
||
813 |
# Return the list of pou names |
|
814 |
def GetElementsOpenedNames(self): |
|
815 |
names = [] |
|
816 |
for pou_name in self.ElementsOpened: |
|
817 |
words = pou_name.split("::") |
|
818 |
if len(words) == 1: |
|
819 |
names.append(pou_name) |
|
820 |
else: |
|
821 |
names.append("%s-%s"%(words[1],words[2])) |
|
822 |
return names |
|
823 |
||
824 |
# Compute a pou transition name |
|
825 |
def ComputePouTransitionName(self, pou, transition): |
|
826 |
return "T::%s::%s" % (pou, transition) |
|
827 |
||
828 |
# Compute a pou action name |
|
829 |
def ComputePouActionName(self, pou, action): |
|
830 |
return "A::%s::%s" % (pou, action) |
|
831 |
||
832 |
# Compute a pou name |
|
833 |
def ComputeConfigurationResourceName(self, config, resource): |
|
834 |
return "R::%s::%s" % (config, resource) |
|
835 |
||
836 |
# Open a pou by giving its name |
|
837 |
def OpenElementEditing(self, name): |
|
838 |
# If pou not opened yet |
|
839 |
if name not in self.ElementsOpened: |
|
840 |
# Add pou name to list of pou opened and make it current editing |
|
841 |
self.ElementsOpened.append(name) |
|
842 |
self.CurrentElementEditing = len(self.ElementsOpened) - 1 |
|
843 |
return self.CurrentElementEditing |
|
844 |
return None |
|
845 |
||
846 |
# Open a pou transition by giving pou and transition names |
|
847 |
def OpenPouTransitionEditing(self, pou, transition): |
|
848 |
return self.OpenElementEditing(self.ComputePouTransitionName(pou, transition)) |
|
849 |
||
850 |
# Open a pou action by giving pou and action names |
|
851 |
def OpenPouActionEditing(self, pou, action): |
|
852 |
return self.OpenElementEditing(self.ComputePouActionName(pou, action)) |
|
853 |
||
854 |
# Open a configuration resource by giving configuration and resource names |
|
855 |
def OpenConfigurationResourceEditing(self, config, resource): |
|
856 |
return self.OpenElementEditing(self.ComputeConfigurationResourceName(config, resource)) |
|
857 |
||
858 |
# Return if pou given by name is opened |
|
859 |
def IsElementEditing(self, name): |
|
860 |
return name in self.ElementsOpened |
|
861 |
||
862 |
# Return if pou transition given by pou and transition names is opened |
|
863 |
def IsPouTransitionEditing(self, pou, transition): |
|
864 |
return self.ComputePouTransitionName(pou, transition) in self.ElementsOpened |
|
865 |
||
866 |
# Return if pou action given by pou and action names is opened |
|
867 |
def IsPouActionEditing(self, pou, action): |
|
868 |
return self.ComputePouActionName(pou, action) in self.ElementsOpened |
|
869 |
||
870 |
# Return if pou action given by pou and action names is opened |
|
871 |
def IsConfigurationResourceEditing(self, pou, action): |
|
872 |
return self.ComputeConfigurationResourceName(config, resource) in self.ElementsOpened |
|
873 |
||
874 |
# Close current pou editing |
|
875 |
def CloseElementEditing(self): |
|
876 |
# Remove pou from list of pou opened |
|
877 |
self.ElementsOpened.pop(self.CurrentElementEditing) |
|
878 |
# Update index of current pou editing |
|
879 |
if len(self.ElementsOpened) > 0: |
|
880 |
self.CurrentElementEditing = min(self.CurrentElementEditing, len(self.ElementsOpened) - 1) |
|
881 |
else: |
|
882 |
self.CurrentElementEditing = None |
|
883 |
||
884 |
# Change current pou editing for pou given by name |
|
885 |
def ChangeElementEditing(self, name): |
|
886 |
# Verify that pou is opened |
|
887 |
if name in self.ElementsOpened: |
|
888 |
# Change current pou editing |
|
889 |
self.CurrentElementEditing = self.ElementsOpened.index(name) |
|
890 |
return self.CurrentElementEditing |
|
891 |
return None |
|
892 |
||
893 |
# Change current pou editing for transition given by pou and transition names |
|
894 |
def ChangePouTransitionEditing(self, pou, transition): |
|
895 |
return self.ChangeElementEditing(self.ComputePouTransitionName(pou, transition)) |
|
896 |
||
897 |
# Change current pou editing for action given by pou and action names |
|
898 |
def ChangePouActionEditing(self, pou, action): |
|
899 |
return self.ChangeElementEditing(self.ComputePouActionName(pou, action)) |
|
900 |
||
901 |
# Change current pou editing for action given by configuration and resource names |
|
902 |
def ChangeConfigurationResourceEditing(self, config, resource): |
|
903 |
return self.ChangeElementEditing(self.ComputeConfigurationResourceName(config, resource)) |
|
904 |
||
905 |
#------------------------------------------------------------------------------- |
|
906 |
# Project opened Pous management functions |
|
907 |
#------------------------------------------------------------------------------- |
|
908 |
||
909 |
# Return current pou editing |
|
910 |
def GetCurrentElementEditing(self): |
|
911 |
# Verify that there's one editing and return it |
|
912 |
if self.CurrentElementEditing != None: |
|
913 |
name = self.ElementsOpened[self.CurrentElementEditing] |
|
914 |
words = name.split("::") |
|
915 |
if len(words) == 1: |
|
916 |
return self.Project.getPou(name) |
|
917 |
else: |
|
918 |
if words[0] in ['T', 'A']: |
|
919 |
pou = self.Project.getPou(words[1]) |
|
920 |
if words[0] == 'T': |
|
921 |
return pou.getTransition(words[2]) |
|
922 |
elif words[0] == 'A': |
|
923 |
return pou.getAction(words[2]) |
|
924 |
elif words[0] == 'R': |
|
925 |
result = self.Project.getConfigurationResource(words[1], words[2]) |
|
926 |
return result |
|
927 |
return None |
|
928 |
||
929 |
# Return current pou editing name |
|
930 |
def GetCurrentElementEditingName(self): |
|
931 |
# Verify that there's one editing and return its name |
|
932 |
if self.CurrentElementEditing != None: |
|
933 |
name = self.ElementsOpened[self.CurrentElementEditing] |
|
934 |
words = name.split("::") |
|
935 |
if len(words) == 1: |
|
936 |
return name |
|
937 |
else: |
|
938 |
return words[2] |
|
939 |
return None |
|
940 |
||
941 |
# Replace the index of current pou editing by the one given |
|
942 |
def RefreshCurrentElementEditing(self, index): |
|
943 |
self.CurrentElementEditing = index |
|
944 |
||
945 |
# Return language in which current pou editing is written |
|
13
69075340d6a9
Adding support for forbidding insertion of function block into function
lbessard
parents:
6
diff
changeset
|
946 |
def GetCurrentElementEditingType(self): |
69075340d6a9
Adding support for forbidding insertion of function block into function
lbessard
parents:
6
diff
changeset
|
947 |
if self.CurrentElementEditing != None: |
69075340d6a9
Adding support for forbidding insertion of function block into function
lbessard
parents:
6
diff
changeset
|
948 |
name = self.ElementsOpened[self.CurrentElementEditing] |
69075340d6a9
Adding support for forbidding insertion of function block into function
lbessard
parents:
6
diff
changeset
|
949 |
words = name.split("::") |
69075340d6a9
Adding support for forbidding insertion of function block into function
lbessard
parents:
6
diff
changeset
|
950 |
if len(words) == 1: |
69075340d6a9
Adding support for forbidding insertion of function block into function
lbessard
parents:
6
diff
changeset
|
951 |
return self.GetPouType(name) |
69075340d6a9
Adding support for forbidding insertion of function block into function
lbessard
parents:
6
diff
changeset
|
952 |
else: |
69075340d6a9
Adding support for forbidding insertion of function block into function
lbessard
parents:
6
diff
changeset
|
953 |
return self.GetPouType(words[1]) |
69075340d6a9
Adding support for forbidding insertion of function block into function
lbessard
parents:
6
diff
changeset
|
954 |
return None |
69075340d6a9
Adding support for forbidding insertion of function block into function
lbessard
parents:
6
diff
changeset
|
955 |
|
69075340d6a9
Adding support for forbidding insertion of function block into function
lbessard
parents:
6
diff
changeset
|
956 |
# Return language in which current pou editing is written |
0 | 957 |
def GetCurrentElementEditingBodyType(self): |
958 |
if self.CurrentElementEditing != None: |
|
959 |
name = self.ElementsOpened[self.CurrentElementEditing] |
|
960 |
words = name.split("::") |
|
961 |
if len(words) == 1: |
|
962 |
return self.GetPouBodyType(name) |
|
963 |
else: |
|
964 |
if words[0] == 'T': |
|
965 |
return self.GetTransitionBodyType(words[1], words[2]) |
|
966 |
elif words[0] == 'A': |
|
967 |
return self.GetActionBodyType(words[1], words[2]) |
|
968 |
return None |
|
969 |
||
970 |
# Return the variables of the current pou editing |
|
971 |
def GetCurrentElementEditingInterfaceVars(self): |
|
972 |
if self.CurrentElementEditing != None: |
|
973 |
current_name = self.ElementsOpened[self.CurrentElementEditing] |
|
974 |
words = current_name.split("::") |
|
975 |
if len(words) == 1: |
|
976 |
pou = self.Project.getPou(current_name) |
|
977 |
return self.GetPouInterfaceVars(pou) |
|
978 |
else: |
|
979 |
pou = self.Project.getPou(words[1]) |
|
980 |
return self.GetPouInterfaceVars(pou) |
|
981 |
return [] |
|
982 |
||
983 |
# Return the return type of the current pou editing |
|
984 |
def GetCurrentElementEditingInterfaceReturnType(self): |
|
985 |
if self.CurrentElementEditing != None: |
|
986 |
current_name = self.ElementsOpened[self.CurrentElementEditing] |
|
987 |
words = current_name.split("::") |
|
988 |
if len(words) == 1: |
|
989 |
pou = self.Project.getPou(current_name) |
|
990 |
return self.GetPouInterfaceReturnType(pou) |
|
991 |
elif words[0] == 'T': |
|
992 |
return "BOOL" |
|
993 |
return None |
|
994 |
||
995 |
# Change the text of the current pou editing |
|
996 |
def SetCurrentElementEditingText(self, text): |
|
997 |
if self.CurrentElementEditing != None: |
|
998 |
self.GetCurrentElementEditing().setText(text) |
|
999 |
self.RefreshPouUsingTree() |
|
1000 |
||
1001 |
# Return the current pou editing text |
|
1002 |
def GetCurrentElementEditingText(self): |
|
1003 |
if self.CurrentElementEditing != None: |
|
1004 |
return self.GetCurrentElementEditing().getText() |
|
1005 |
return "" |
|
1006 |
||
1007 |
# Return the current pou editing transitions |
|
1008 |
def GetCurrentElementEditingTransitions(self): |
|
1009 |
if self.CurrentElementEditing != None: |
|
1010 |
pou = self.GetCurrentElementEditing() |
|
1011 |
if pou.getBodyType() == "SFC": |
|
1012 |
transitions = [] |
|
1013 |
for transition in pou.getTransitionList(): |
|
1014 |
transitions.append(transition.getName()) |
|
1015 |
return transitions |
|
1016 |
return [] |
|
1017 |
||
1018 |
# Return the current pou editing transitions |
|
1019 |
def GetCurrentElementEditingActions(self): |
|
1020 |
if self.CurrentElementEditing != None: |
|
1021 |
pou = self.GetCurrentElementEditing() |
|
1022 |
if pou.getBodyType() == "SFC": |
|
1023 |
actions = [] |
|
1024 |
for action in pou.getActionList(): |
|
1025 |
actions.append(action.getName()) |
|
1026 |
return actions |
|
1027 |
return [] |
|
1028 |
||
1029 |
# Return the current pou editing informations |
|
1030 |
def GetCurrentElementEditingInstanceInfos(self, id = None, exclude = []): |
|
1031 |
infos = {} |
|
1032 |
# if id is defined |
|
1033 |
if id != None: |
|
1034 |
instance = self.GetCurrentElementEditing().getInstance(id) |
|
1035 |
else: |
|
1036 |
instance = self.GetCurrentElementEditing().getRandomInstance(exclude) |
|
1037 |
if instance: |
|
1038 |
if id != None: |
|
1039 |
infos["id"] = id |
|
1040 |
else: |
|
1041 |
infos["id"] = instance.getLocalId() |
|
1042 |
infos["x"] = instance.getX() |
|
1043 |
infos["y"] = instance.getY() |
|
1044 |
infos["height"] = instance.getHeight() |
|
1045 |
infos["width"] = instance.getWidth() |
|
1046 |
if isinstance(instance, plcopen.block): |
|
1047 |
infos["name"] = instance.getInstanceName() |
|
1048 |
infos["type"] = instance.getTypeName() |
|
1049 |
infos["connectors"] = {"inputs":[],"outputs":[]} |
|
1050 |
for variable in instance.inputVariables.getVariable(): |
|
1051 |
connector = {} |
|
1052 |
connector["position"] = variable.connectionPointIn.getRelPosition() |
|
1053 |
connector["negated"] = variable.getNegated() |
|
1054 |
connector["edge"] = variable.getConnectorEdge() |
|
1055 |
connector["links"] = [] |
|
1056 |
connections = variable.connectionPointIn.getConnections() |
|
1057 |
if connections: |
|
1058 |
for link in connections: |
|
27 | 1059 |
dic = {"refLocalId":link.getRefLocalId(),"points":link.getPoints(),"formalParameter":link.getFormalParameter()} |
0 | 1060 |
connector["links"].append(dic) |
1061 |
infos["connectors"]["inputs"].append(connector) |
|
1062 |
for variable in instance.outputVariables.getVariable(): |
|
1063 |
connector = {} |
|
1064 |
connector["position"] = variable.connectionPointOut.getRelPosition() |
|
1065 |
connector["negated"] = variable.getNegated() |
|
1066 |
connector["edge"] = variable.getConnectorEdge() |
|
1067 |
infos["connectors"]["outputs"].append(connector) |
|
1068 |
elif isinstance(instance, plcopen.inVariable): |
|
1069 |
infos["name"] = instance.getExpression() |
|
1070 |
infos["value_type"] = self.GetPouVarValueType(self.GetCurrentElementEditing(), infos["name"]) |
|
1071 |
infos["type"] = "input" |
|
1072 |
infos["connector"] = {} |
|
1073 |
infos["connector"]["position"] = instance.connectionPointOut.getRelPosition() |
|
1074 |
infos["connector"]["negated"] = instance.getNegated() |
|
1075 |
infos["connector"]["edge"] = instance.getConnectorEdge() |
|
1076 |
elif isinstance(instance, plcopen.outVariable): |
|
1077 |
infos["name"] = instance.getExpression() |
|
1078 |
infos["value_type"] = self.GetPouVarValueType(self.GetCurrentElementEditing(), infos["name"]) |
|
1079 |
infos["type"] = "output" |
|
1080 |
infos["connector"] = {} |
|
1081 |
infos["connector"]["position"] = instance.connectionPointIn.getRelPosition() |
|
1082 |
infos["connector"]["negated"] = instance.getNegated() |
|
1083 |
infos["connector"]["edge"] = instance.getConnectorEdge() |
|
1084 |
infos["connector"]["links"] = [] |
|
1085 |
connections = instance.connectionPointIn.getConnections() |
|
1086 |
if connections: |
|
1087 |
for link in connections: |
|
27 | 1088 |
dic = {"refLocalId":link.getRefLocalId(),"points":link.getPoints(),"formalParameter":link.getFormalParameter()} |
0 | 1089 |
infos["connector"]["links"].append(dic) |
1090 |
elif isinstance(instance, plcopen.inOutVariable): |
|
1091 |
infos["name"] = instance.getExpression() |
|
1092 |
infos["value_type"] = self.GetPouVarValueType(self.GetCurrentElementEditing(), infos["name"]) |
|
1093 |
infos["type"] = "inout" |
|
1094 |
infos["connectors"] = {"input":{},"output":{}} |
|
1095 |
infos["connectors"]["output"]["position"] = instance.connectionPointOut.getRelPosition() |
|
1096 |
infos["connectors"]["output"]["negated"] = instance.getNegatedOut() |
|
1097 |
infos["connectors"]["output"]["edge"] = instance.getOutputEdge() |
|
1098 |
infos["connectors"]["input"]["position"] = instance.connectionPointIn.getRelPosition() |
|
1099 |
infos["connectors"]["input"]["negated"] = instance.getNegatedIn() |
|
1100 |
infos["connectors"]["input"]["edge"] = instance.getInputEdge() |
|
1101 |
infos["connectors"]["input"]["links"] = [] |
|
1102 |
connections = instance.connectionPointIn.getConnections() |
|
1103 |
if connections: |
|
1104 |
for link in connections: |
|
27 | 1105 |
dic = {"refLocalId":link.getRefLocalId(),"points":link.getPoints(),"formalParameter":link.getFormalParameter()} |
0 | 1106 |
infos["connectors"]["input"]["links"].append(dic) |
1107 |
elif isinstance(instance, plcopen.continuation): |
|
1108 |
infos["name"] = instance.getName() |
|
1109 |
infos["value_type"] = self.GetPouVarValueType(self.GetCurrentElementEditing(), infos["name"]) |
|
1110 |
infos["type"] = "continuation" |
|
1111 |
infos["connector"] = {} |
|
1112 |
infos["connector"]["position"] = instance.connectionPointOut.getRelPosition() |
|
1113 |
elif isinstance(instance, plcopen.connector): |
|
1114 |
infos["name"] = instance.getName() |
|
1115 |
infos["value_type"] = self.GetPouVarValueType(self.GetCurrentElementEditing(), infos["name"]) |
|
1116 |
infos["type"] = "connection" |
|
1117 |
infos["connector"] = {} |
|
1118 |
infos["connector"]["position"] = instance.connectionPointIn.getRelPosition() |
|
1119 |
infos["connector"]["links"] = [] |
|
1120 |
connections = instance.connectionPointIn.getConnections() |
|
1121 |
if connections: |
|
1122 |
for link in connections: |
|
27 | 1123 |
dic = {"refLocalId":link.getRefLocalId(),"points":link.getPoints(),"formalParameter":link.getFormalParameter()} |
0 | 1124 |
infos["connector"]["links"].append(dic) |
1125 |
elif isinstance(instance, plcopen.comment): |
|
1126 |
infos["type"] = "comment" |
|
1127 |
infos["content"] = instance.getContentText() |
|
1128 |
elif isinstance(instance, plcopen.leftPowerRail): |
|
1129 |
infos["type"] = "leftPowerRail" |
|
1130 |
infos["connectors"] = [] |
|
1131 |
for connection in instance.getConnectionPointOut(): |
|
1132 |
connector = {} |
|
1133 |
connector["position"] = connection.getRelPosition() |
|
1134 |
infos["connectors"].append(connector) |
|
1135 |
elif isinstance(instance, plcopen.rightPowerRail): |
|
1136 |
infos["type"] = "rightPowerRail" |
|
1137 |
infos["connectors"] = [] |
|
1138 |
for connection in instance.getConnectionPointIn(): |
|
1139 |
connector = {} |
|
1140 |
connector["position"] = connection.getRelPosition() |
|
1141 |
connector["links"] = [] |
|
1142 |
for link in connection.getConnections(): |
|
27 | 1143 |
dic = {"refLocalId":link.getRefLocalId(),"points":link.getPoints(),"formalParameter":link.getFormalParameter()} |
0 | 1144 |
connector["links"].append(dic) |
1145 |
infos["connectors"].append(connector) |
|
1146 |
elif isinstance(instance, plcopen.contact): |
|
1147 |
infos["type"] = "contact" |
|
1148 |
infos["name"] = instance.getVariable() |
|
1149 |
infos["negated"] = instance.getNegated() |
|
1150 |
infos["edge"] = instance.getContactEdge() |
|
1151 |
infos["connectors"] = {"input":{},"output":{}} |
|
1152 |
infos["connectors"]["input"]["position"] = instance.connectionPointIn.getRelPosition() |
|
1153 |
infos["connectors"]["input"]["links"] = [] |
|
1154 |
connections = instance.connectionPointIn.getConnections() |
|
1155 |
if connections: |
|
1156 |
for link in connections: |
|
27 | 1157 |
dic = {"refLocalId":link.getRefLocalId(),"points":link.getPoints(),"formalParameter":link.getFormalParameter()} |
0 | 1158 |
infos["connectors"]["input"]["links"].append(dic) |
1159 |
infos["connectors"]["output"]["position"] = instance.connectionPointOut.getRelPosition() |
|
1160 |
elif isinstance(instance, plcopen.coil): |
|
1161 |
infos["type"] = "coil" |
|
1162 |
infos["name"] = instance.getVariable() |
|
1163 |
infos["negated"] = instance.getNegated() |
|
1164 |
infos["storage"] = instance.getCoilStorage() |
|
1165 |
infos["connectors"] = {"input":{},"output":{}} |
|
1166 |
infos["connectors"]["input"]["position"] = instance.connectionPointIn.getRelPosition() |
|
1167 |
infos["connectors"]["input"]["links"] = [] |
|
1168 |
connections = instance.connectionPointIn.getConnections() |
|
1169 |
if connections: |
|
1170 |
for link in connections: |
|
27 | 1171 |
dic = {"refLocalId":link.getRefLocalId(),"points":link.getPoints(),"formalParameter":link.getFormalParameter()} |
0 | 1172 |
infos["connectors"]["input"]["links"].append(dic) |
1173 |
infos["connectors"]["output"]["position"] = instance.connectionPointOut.getRelPosition() |
|
1174 |
elif isinstance(instance, plcopen.step): |
|
1175 |
infos["type"] = "step" |
|
1176 |
infos["name"] = instance.getName() |
|
1177 |
infos["initial"] = instance.getInitialStep() |
|
1178 |
infos["connectors"] = {} |
|
1179 |
if instance.connectionPointIn: |
|
1180 |
infos["connectors"]["input"] = {} |
|
1181 |
infos["connectors"]["input"]["position"] = instance.connectionPointIn.getRelPosition() |
|
1182 |
infos["connectors"]["input"]["links"] = [] |
|
1183 |
connections = instance.connectionPointIn.getConnections() |
|
1184 |
if connections: |
|
1185 |
for link in connections: |
|
27 | 1186 |
dic = {"refLocalId":link.getRefLocalId(),"points":link.getPoints(),"formalParameter":link.getFormalParameter()} |
0 | 1187 |
infos["connectors"]["input"]["links"].append(dic) |
1188 |
if instance.connectionPointOut: |
|
1189 |
infos["connectors"]["output"] = {"position" : instance.connectionPointOut.getRelPosition()} |
|
1190 |
if instance.connectionPointOutAction: |
|
1191 |
infos["connectors"]["action"] = {"position" : instance.connectionPointOutAction.getRelPosition()} |
|
1192 |
elif isinstance(instance, plcopen.transition): |
|
1193 |
infos["type"] = "transition" |
|
1194 |
condition = instance.getConditionContent() |
|
1195 |
infos["condition_type"] = condition["type"] |
|
1196 |
infos["condition"] = condition["value"] |
|
1197 |
infos["connectors"] = {"input":{},"output":{}} |
|
1198 |
infos["connectors"]["input"]["position"] = instance.connectionPointIn.getRelPosition() |
|
1199 |
infos["connectors"]["input"]["links"] = [] |
|
1200 |
connections = instance.connectionPointIn.getConnections() |
|
1201 |
if connections: |
|
1202 |
for link in connections: |
|
27 | 1203 |
dic = {"refLocalId":link.getRefLocalId(),"points":link.getPoints(),"formalParameter":link.getFormalParameter()} |
0 | 1204 |
infos["connectors"]["input"]["links"].append(dic) |
1205 |
infos["connectors"]["output"]["position"] = instance.connectionPointOut.getRelPosition() |
|
1206 |
elif isinstance(instance, (plcopen.selectionDivergence, plcopen.simultaneousDivergence)): |
|
1207 |
if isinstance(instance, plcopen.selectionDivergence): |
|
1208 |
infos["type"] = "selectionDivergence" |
|
1209 |
else: |
|
1210 |
infos["type"] = "simultaneousDivergence" |
|
1211 |
infos["connectors"] = {"inputs":[],"outputs":[]} |
|
1212 |
connector = {} |
|
1213 |
connector["position"] = instance.connectionPointIn.getRelPosition() |
|
1214 |
connector["links"] = [] |
|
1215 |
connections = instance.connectionPointIn.getConnections() |
|
1216 |
if connections: |
|
1217 |
for link in connections: |
|
27 | 1218 |
dic = {"refLocalId":link.getRefLocalId(),"points":link.getPoints(),"formalParameter":link.getFormalParameter()} |
0 | 1219 |
connector["links"].append(dic) |
1220 |
infos["connectors"]["inputs"].append(connector) |
|
1221 |
for sequence in instance.getConnectionPointOut(): |
|
1222 |
connector = {} |
|
1223 |
connector["position"] = sequence.getRelPosition() |
|
1224 |
infos["connectors"]["outputs"].append(connector) |
|
1225 |
elif isinstance(instance, (plcopen.selectionConvergence, plcopen.simultaneousConvergence)): |
|
1226 |
if isinstance(instance, plcopen.selectionConvergence): |
|
1227 |
infos["type"] = "selectionConvergence" |
|
1228 |
else: |
|
1229 |
infos["type"] = "simultaneousConvergence" |
|
1230 |
infos["connectors"] = {"inputs":[],"outputs":[]} |
|
1231 |
for sequence in instance.getConnectionPointIn(): |
|
1232 |
connector = {} |
|
1233 |
connector["position"] = sequence.getRelPosition() |
|
1234 |
connector["links"] = [] |
|
1235 |
connections = sequence.getConnections() |
|
1236 |
if connections: |
|
1237 |
for link in connections: |
|
27 | 1238 |
dic = {"refLocalId":link.getRefLocalId(),"points":link.getPoints(),"formalParameter":link.getFormalParameter()} |
0 | 1239 |
connector["links"].append(dic) |
1240 |
infos["connectors"]["inputs"].append(connector) |
|
1241 |
connector = {} |
|
1242 |
connector["position"] = instance.connectionPointOut.getRelPosition() |
|
1243 |
infos["connectors"]["outputs"].append(connector) |
|
1244 |
elif isinstance(instance, plcopen.jumpStep): |
|
1245 |
infos["type"] = "jump" |
|
1246 |
infos["target"] = instance.getTargetName() |
|
1247 |
infos["connector"] = {} |
|
1248 |
infos["connector"]["position"] = instance.connectionPointIn.getRelPosition() |
|
1249 |
infos["connector"]["links"] = [] |
|
1250 |
connections = instance.connectionPointIn.getConnections() |
|
1251 |
if connections: |
|
1252 |
for link in connections: |
|
27 | 1253 |
dic = {"refLocalId":link.getRefLocalId(),"points":link.getPoints(),"formalParameter":link.getFormalParameter()} |
0 | 1254 |
infos["connector"]["links"].append(dic) |
1255 |
elif isinstance(instance, plcopen.actionBlock): |
|
1256 |
infos["type"] = "actionBlock" |
|
1257 |
infos["actions"] = instance.getActions() |
|
1258 |
infos["connector"] = {} |
|
1259 |
infos["connector"]["position"] = instance.connectionPointIn.getRelPosition() |
|
1260 |
infos["connector"]["links"] = [] |
|
1261 |
connections = instance.connectionPointIn.getConnections() |
|
1262 |
if connections: |
|
1263 |
for link in connections: |
|
27 | 1264 |
dic = {"refLocalId":link.getRefLocalId(),"points":link.getPoints(),"formalParameter":link.getFormalParameter()} |
0 | 1265 |
infos["connector"]["links"].append(dic) |
1266 |
return infos |
|
1267 |
return False |
|
1268 |
||
1269 |
# Return the variable type of the given pou |
|
1270 |
def GetPouVarValueType(self, pou, varname): |
|
1271 |
for type, varlist in pou.getVars(): |
|
1272 |
for var in varlist.getVariable(): |
|
1273 |
if var.getName() == varname: |
|
1274 |
return var.getType() |
|
1275 |
return "" |
|
1276 |
||
1277 |
def SetConnectionWires(self, connection, connector): |
|
1278 |
wires = connector.GetWires() |
|
1279 |
idx = 0 |
|
1280 |
for wire, handle in wires: |
|
1281 |
points = wire.GetPoints(handle != 0) |
|
1282 |
if handle == 0: |
|
27 | 1283 |
result = wire.GetConnectedInfos(-1) |
0 | 1284 |
else: |
27 | 1285 |
result = wire.GetConnectedInfos(0) |
1286 |
if result != None: |
|
1287 |
refLocalId, formalParameter = result |
|
0 | 1288 |
connection.addConnection() |
1289 |
connection.setConnectionId(idx, refLocalId) |
|
1290 |
connection.setConnectionPoints(idx, points) |
|
27 | 1291 |
if formalParameter != "": |
1292 |
connection.setConnectionParameter(idx, formalParameter) |
|
1293 |
else: |
|
1294 |
connection.setConnectionParameter(idx, None) |
|
0 | 1295 |
idx += 1 |
1296 |
||
1297 |
def AddCurrentElementEditingBlock(self, id): |
|
1298 |
block = plcopen.block() |
|
1299 |
block.setLocalId(id) |
|
1300 |
self.GetCurrentElementEditing().addInstance("block", block) |
|
1301 |
self.RefreshPouUsingTree() |
|
1302 |
||
1303 |
def SetCurrentElementEditingBlockInfos(self, id, infos): |
|
1304 |
block = self.GetCurrentElementEditing().getInstance(id) |
|
1305 |
for param, value in infos.items(): |
|
1306 |
if param == "name": |
|
1307 |
block.setInstanceName(value) |
|
1308 |
elif param == "type": |
|
1309 |
block.setTypeName(value) |
|
1310 |
elif param == "height": |
|
1311 |
block.setHeight(value) |
|
1312 |
elif param == "width": |
|
1313 |
block.setWidth(value) |
|
1314 |
elif param == "x": |
|
1315 |
block.setX(value) |
|
1316 |
elif param == "y": |
|
1317 |
block.setY(value) |
|
1318 |
elif param == "connectors": |
|
1319 |
block.inputVariables.setVariable([]) |
|
1320 |
block.outputVariables.setVariable([]) |
|
1321 |
for connector in value["inputs"]: |
|
1322 |
variable = plcopen.inputVariables_variable() |
|
1323 |
variable.setFormalParameter(connector.GetName()) |
|
1324 |
if connector.IsNegated(): |
|
1325 |
variable.setNegated(True) |
|
1326 |
if connector.GetEdge() != "none": |
|
1327 |
variable.setConnectorEdge(connector.GetEdge()) |
|
1328 |
position = connector.GetRelPosition() |
|
1329 |
variable.connectionPointIn.setRelPosition(position.x, position.y) |
|
1330 |
self.SetConnectionWires(variable.connectionPointIn, connector) |
|
1331 |
block.inputVariables.appendVariable(variable) |
|
1332 |
for connector in value["outputs"]: |
|
1333 |
variable = plcopen.outputVariables_variable() |
|
1334 |
variable.setFormalParameter(connector.GetName()) |
|
1335 |
if connector.IsNegated(): |
|
1336 |
variable.setNegated(True) |
|
1337 |
if connector.GetEdge() != "none": |
|
1338 |
variable.setConnectorEdge(connector.GetEdge()) |
|
1339 |
position = connector.GetRelPosition() |
|
1340 |
variable.addConnectionPointOut() |
|
1341 |
variable.connectionPointOut.setRelPosition(position.x, position.y) |
|
1342 |
block.outputVariables.appendVariable(variable) |
|
1343 |
self.RefreshPouUsingTree() |
|
1344 |
||
1345 |
def AddCurrentElementEditingVariable(self, id, type): |
|
1346 |
if type == INPUT: |
|
1347 |
name = "inVariable" |
|
1348 |
variable = plcopen.inVariable() |
|
1349 |
elif type == OUTPUT: |
|
1350 |
name = "outVariable" |
|
1351 |
variable = plcopen.outVariable() |
|
1352 |
elif type == INOUT: |
|
1353 |
name = "inOutVariable" |
|
1354 |
variable = plcopen.inOutVariable() |
|
1355 |
variable.setLocalId(id) |
|
1356 |
self.GetCurrentElementEditing().addInstance(name, variable) |
|
1357 |
||
1358 |
def SetCurrentElementEditingVariableInfos(self, id, infos): |
|
1359 |
variable = self.GetCurrentElementEditing().getInstance(id) |
|
1360 |
for param, value in infos.items(): |
|
1361 |
if param == "name": |
|
1362 |
variable.setExpression(value) |
|
1363 |
elif param == "height": |
|
1364 |
variable.setHeight(value) |
|
1365 |
elif param == "width": |
|
1366 |
variable.setWidth(value) |
|
1367 |
elif param == "x": |
|
1368 |
variable.setX(value) |
|
1369 |
elif param == "y": |
|
1370 |
variable.setY(value) |
|
1371 |
elif param == "connectors": |
|
1372 |
if isinstance(variable, plcopen.inVariable): |
|
1373 |
if value["output"].IsNegated(): |
|
1374 |
variable.setNegated(True) |
|
1375 |
if value["output"].GetEdge() != "none": |
|
1376 |
variable.setConnectorEdge(value["output"].GetEdge()) |
|
1377 |
position = value["output"].GetRelPosition() |
|
1378 |
variable.addConnectionPointOut() |
|
1379 |
variable.connectionPointOut.setRelPosition(position.x, position.y) |
|
1380 |
elif isinstance(variable, plcopen.outVariable): |
|
1381 |
if value["input"].IsNegated(): |
|
1382 |
variable.setNegated(True) |
|
1383 |
if value["input"].GetEdge() != "none": |
|
1384 |
variable.setConnectorEdge(value["input"].GetEdge()) |
|
1385 |
position = value["input"].GetRelPosition() |
|
1386 |
variable.addConnectionPointIn() |
|
1387 |
variable.connectionPointIn.setRelPosition(position.x, position.y) |
|
1388 |
self.SetConnectionWires(variable.connectionPointIn, value["input"]) |
|
1389 |
elif isinstance(variable, plcopen.inOutVariable): |
|
1390 |
if value["input"].IsNegated(): |
|
1391 |
variable.setNegatedIn(True) |
|
1392 |
if value["input"].GetEdge() != "none": |
|
1393 |
variable.setInputEdge(value["input"].GetEdge()) |
|
1394 |
if value["output"].IsNegated(): |
|
1395 |
variable.setNegatedOut(True) |
|
1396 |
if value["output"].GetEdge() != "none": |
|
1397 |
variable.setOutputEdge(value["output"].GetEdge()) |
|
1398 |
position = value["output"].GetRelPosition() |
|
1399 |
variable.addConnectionPointOut() |
|
1400 |
variable.connectionPointOut.setRelPosition(position.x, position.y) |
|
1401 |
position = value["input"].GetRelPosition() |
|
1402 |
variable.addConnectionPointIn() |
|
1403 |
variable.connectionPointIn.setRelPosition(position.x, position.y) |
|
1404 |
self.SetConnectionWires(variable.connectionPointIn, value["input"]) |
|
1405 |
||
1406 |
||
1407 |
def AddCurrentElementEditingConnection(self, id, type): |
|
1408 |
if type == CONNECTOR: |
|
1409 |
name = "connector" |
|
1410 |
connection = plcopen.connector() |
|
1411 |
elif type == CONTINUATION: |
|
1412 |
name = "continuation" |
|
1413 |
connection = plcopen.continuation() |
|
1414 |
connection.setLocalId(id) |
|
1415 |
self.GetCurrentElementEditing().addInstance(name, connection) |
|
1416 |
||
1417 |
def SetCurrentElementEditingConnectionInfos(self, id, infos): |
|
1418 |
connection = self.GetCurrentElementEditing().getInstance(id) |
|
1419 |
for param, value in infos.items(): |
|
1420 |
if param == "name": |
|
1421 |
connection.setName(value) |
|
1422 |
elif param == "height": |
|
1423 |
connection.setHeight(value) |
|
1424 |
elif param == "width": |
|
1425 |
connection.setWidth(value) |
|
1426 |
elif param == "x": |
|
1427 |
connection.setX(value) |
|
1428 |
elif param == "y": |
|
1429 |
connection.setY(value) |
|
1430 |
elif param == "connector": |
|
1431 |
position = value.GetRelPosition() |
|
1432 |
if isinstance(connection, plcopen.continuation): |
|
1433 |
connection.addConnectionPointOut() |
|
1434 |
connection.connectionPointOut.setRelPosition(position.x, position.y) |
|
1435 |
elif isinstance(connection, plcopen.connector): |
|
1436 |
connection.addConnectionPointIn() |
|
1437 |
connection.connectionPointIn.setRelPosition(position.x, position.y) |
|
1438 |
self.SetConnectionWires(connection.connectionPointIn, value) |
|
1439 |
||
1440 |
def AddCurrentElementEditingComment(self, id): |
|
1441 |
comment = plcopen.comment() |
|
1442 |
comment.setLocalId(id) |
|
1443 |
self.GetCurrentElementEditing().addInstance("comment", comment) |
|
1444 |
||
1445 |
def SetCurrentElementEditingCommentInfos(self, id, infos): |
|
1446 |
comment = self.GetCurrentElementEditing().getInstance(id) |
|
1447 |
for param, value in infos.items(): |
|
1448 |
if param == "content": |
|
1449 |
comment.setContentText(value) |
|
1450 |
elif param == "height": |
|
1451 |
comment.setHeight(value) |
|
1452 |
elif param == "width": |
|
1453 |
comment.setWidth(value) |
|
1454 |
elif param == "x": |
|
1455 |
comment.setX(value) |
|
1456 |
elif param == "y": |
|
1457 |
comment.setY(value) |
|
1458 |
||
1459 |
def AddCurrentElementEditingPowerRail(self, id, type): |
|
1460 |
if type == LEFTRAIL: |
|
1461 |
name = "leftPowerRail" |
|
1462 |
powerrail = plcopen.leftPowerRail() |
|
1463 |
elif type == RIGHTRAIL: |
|
1464 |
name = "rightPowerRail" |
|
1465 |
powerrail = plcopen.rightPowerRail() |
|
1466 |
powerrail.setLocalId(id) |
|
1467 |
self.GetCurrentElementEditing().addInstance(name, powerrail) |
|
1468 |
||
1469 |
def SetCurrentElementEditingPowerRailInfos(self, id, infos): |
|
1470 |
powerrail = self.GetCurrentElementEditing().getInstance(id) |
|
1471 |
for param, value in infos.items(): |
|
1472 |
if param == "height": |
|
1473 |
powerrail.setHeight(value) |
|
1474 |
elif param == "width": |
|
1475 |
powerrail.setWidth(value) |
|
1476 |
elif param == "x": |
|
1477 |
powerrail.setX(value) |
|
1478 |
elif param == "y": |
|
1479 |
powerrail.setY(value) |
|
1480 |
elif param == "connectors": |
|
1481 |
if isinstance(powerrail, plcopen.leftPowerRail): |
|
1482 |
powerrail.setConnectionPointOut([]) |
|
1483 |
for connector in value: |
|
1484 |
position = connector.GetRelPosition() |
|
1485 |
connection = plcopen.leftPowerRail_connectionPointOut() |
|
1486 |
connection.setRelPosition(position.x, position.y) |
|
1487 |
powerrail.connectionPointOut.append(connection) |
|
1488 |
elif isinstance(powerrail, plcopen.rightPowerRail): |
|
1489 |
powerrail.setConnectionPointIn([]) |
|
1490 |
for connector in value: |
|
1491 |
position = connector.GetRelPosition() |
|
1492 |
connection = plcopen.connectionPointIn() |
|
1493 |
connection.setRelPosition(position.x, position.y) |
|
1494 |
self.SetConnectionWires(connection, connector) |
|
1495 |
powerrail.connectionPointIn.append(connection) |
|
1496 |
||
1497 |
def AddCurrentElementEditingContact(self, id): |
|
1498 |
contact = plcopen.contact() |
|
1499 |
contact.setLocalId(id) |
|
1500 |
self.GetCurrentElementEditing().addInstance("contact", contact) |
|
1501 |
||
1502 |
def SetCurrentElementEditingContactInfos(self, id, infos): |
|
1503 |
contact = self.GetCurrentElementEditing().getInstance(id) |
|
1504 |
for param, value in infos.items(): |
|
1505 |
if param == "name": |
|
1506 |
contact.setVariable(value) |
|
1507 |
elif param == "type": |
|
1508 |
if value == CONTACT_NORMAL: |
|
1509 |
contact.setNegated(False) |
|
1510 |
contact.setContactEdge("none") |
|
1511 |
elif value == CONTACT_REVERSE: |
|
1512 |
contact.setNegated(True) |
|
1513 |
contact.setContactEdge("none") |
|
1514 |
elif value == CONTACT_RISING: |
|
1515 |
contact.setNegated(False) |
|
1516 |
contact.setContactEdge("rising") |
|
1517 |
elif value == CONTACT_FALLING: |
|
1518 |
contact.setNegated(False) |
|
1519 |
contact.setContactEdge("falling") |
|
1520 |
elif param == "height": |
|
1521 |
contact.setHeight(value) |
|
1522 |
elif param == "width": |
|
1523 |
contact.setWidth(value) |
|
1524 |
elif param == "x": |
|
1525 |
contact.setX(value) |
|
1526 |
elif param == "y": |
|
1527 |
contact.setY(value) |
|
1528 |
elif param == "connectors": |
|
1529 |
input_connector = value["input"] |
|
1530 |
position = input_connector.GetRelPosition() |
|
1531 |
contact.addConnectionPointIn() |
|
1532 |
contact.connectionPointIn.setRelPosition(position.x, position.y) |
|
1533 |
self.SetConnectionWires(contact.connectionPointIn, input_connector) |
|
1534 |
output_connector = value["output"] |
|
1535 |
position = output_connector.GetRelPosition() |
|
1536 |
contact.addConnectionPointOut() |
|
1537 |
contact.connectionPointOut.setRelPosition(position.x, position.y) |
|
1538 |
||
1539 |
def AddCurrentElementEditingCoil(self, id): |
|
1540 |
coil = plcopen.coil() |
|
1541 |
coil.setLocalId(id) |
|
1542 |
self.GetCurrentElementEditing().addInstance("coil", coil) |
|
1543 |
||
1544 |
def SetCurrentElementEditingCoilInfos(self, id, infos): |
|
1545 |
coil = self.GetCurrentElementEditing().getInstance(id) |
|
1546 |
for param, value in infos.items(): |
|
1547 |
if param == "name": |
|
1548 |
coil.setVariable(value) |
|
1549 |
elif param == "type": |
|
1550 |
if value == COIL_NORMAL: |
|
1551 |
coil.setNegated(False) |
|
1552 |
coil.setCoilStorage("none") |
|
1553 |
elif value == COIL_REVERSE: |
|
1554 |
coil.setNegated(True) |
|
1555 |
coil.setCoilStorage("none") |
|
1556 |
elif value == COIL_SET: |
|
1557 |
coil.setNegated(False) |
|
1558 |
coil.setCoilStorage("set") |
|
1559 |
elif value == COIL_RESET: |
|
1560 |
coil.setNegated(False) |
|
1561 |
coil.setCoilStorage("reset") |
|
1562 |
elif param == "height": |
|
1563 |
coil.setHeight(value) |
|
1564 |
elif param == "width": |
|
1565 |
coil.setWidth(value) |
|
1566 |
elif param == "x": |
|
1567 |
coil.setX(value) |
|
1568 |
elif param == "y": |
|
1569 |
coil.setY(value) |
|
1570 |
elif param == "connectors": |
|
1571 |
input_connector = value["input"] |
|
1572 |
position = input_connector.GetRelPosition() |
|
1573 |
coil.addConnectionPointIn() |
|
1574 |
coil.connectionPointIn.setRelPosition(position.x, position.y) |
|
1575 |
self.SetConnectionWires(coil.connectionPointIn, input_connector) |
|
1576 |
output_connector = value["output"] |
|
1577 |
position = output_connector.GetRelPosition() |
|
1578 |
coil.addConnectionPointOut() |
|
1579 |
coil.connectionPointOut.setRelPosition(position.x, position.y) |
|
1580 |
||
1581 |
def AddCurrentElementEditingStep(self, id): |
|
1582 |
step = plcopen.step() |
|
1583 |
step.setLocalId(id) |
|
1584 |
self.GetCurrentElementEditing().addInstance("step", step) |
|
1585 |
||
1586 |
def SetCurrentElementEditingStepInfos(self, id, infos): |
|
1587 |
step = self.GetCurrentElementEditing().getInstance(id) |
|
1588 |
for param, value in infos.items(): |
|
1589 |
if param == "name": |
|
1590 |
step.setName(value) |
|
1591 |
elif param == "initial": |
|
1592 |
step.setInitialStep(value) |
|
1593 |
elif param == "height": |
|
1594 |
step.setHeight(value) |
|
1595 |
elif param == "width": |
|
1596 |
step.setWidth(value) |
|
1597 |
elif param == "x": |
|
1598 |
step.setX(value) |
|
1599 |
elif param == "y": |
|
1600 |
step.setY(value) |
|
1601 |
elif param == "connectors": |
|
1602 |
input_connector = value["input"] |
|
1603 |
if input_connector: |
|
1604 |
position = input_connector.GetRelPosition() |
|
1605 |
step.addConnectionPointIn() |
|
1606 |
step.connectionPointIn.setRelPosition(position.x, position.y) |
|
1607 |
self.SetConnectionWires(step.connectionPointIn, input_connector) |
|
1608 |
else: |
|
1609 |
step.deleteConnectionPointIn() |
|
1610 |
output_connector = value["output"] |
|
1611 |
if output_connector: |
|
1612 |
position = output_connector.GetRelPosition() |
|
1613 |
step.addConnectionPointOut() |
|
1614 |
step.connectionPointOut.setRelPosition(position.x, position.y) |
|
1615 |
else: |
|
1616 |
step.deleteConnectionPointOut() |
|
1617 |
action_connector = value["action"] |
|
1618 |
if action_connector: |
|
1619 |
position = action_connector.GetRelPosition() |
|
1620 |
step.addConnectionPointOutAction() |
|
1621 |
step.connectionPointOutAction.setRelPosition(position.x, position.y) |
|
1622 |
else: |
|
1623 |
step.deleteConnectionPointOutAction() |
|
1624 |
||
1625 |
def AddCurrentElementEditingTransition(self, id): |
|
1626 |
transition = plcopen.transition() |
|
1627 |
transition.setLocalId(id) |
|
1628 |
self.GetCurrentElementEditing().addInstance("transition", transition) |
|
1629 |
||
1630 |
def SetCurrentElementEditingTransitionInfos(self, id, infos): |
|
1631 |
transition = self.GetCurrentElementEditing().getInstance(id) |
|
1632 |
for param, value in infos.items(): |
|
1633 |
if param == "type" and "condition" in infos: |
|
1634 |
transition.setConditionContent(value, infos["condition"]) |
|
1635 |
elif param == "height": |
|
1636 |
transition.setHeight(value) |
|
1637 |
elif param == "width": |
|
1638 |
transition.setWidth(value) |
|
1639 |
elif param == "x": |
|
1640 |
transition.setX(value) |
|
1641 |
elif param == "y": |
|
1642 |
transition.setY(value) |
|
1643 |
elif param == "connectors": |
|
1644 |
input_connector = value["input"] |
|
1645 |
position = input_connector.GetRelPosition() |
|
1646 |
transition.addConnectionPointIn() |
|
1647 |
transition.connectionPointIn.setRelPosition(position.x, position.y) |
|
1648 |
self.SetConnectionWires(transition.connectionPointIn, input_connector) |
|
1649 |
output_connector = value["output"] |
|
1650 |
position = output_connector.GetRelPosition() |
|
1651 |
transition.addConnectionPointOut() |
|
1652 |
transition.connectionPointOut.setRelPosition(position.x, position.y) |
|
1653 |
||
1654 |
def AddCurrentElementEditingDivergence(self, id, type): |
|
1655 |
if type == SELECTION_DIVERGENCE: |
|
1656 |
name = "selectionDivergence" |
|
1657 |
divergence = plcopen.selectionDivergence() |
|
1658 |
elif type == SELECTION_CONVERGENCE: |
|
1659 |
name = "selectionConvergence" |
|
1660 |
divergence = plcopen.selectionConvergence() |
|
1661 |
elif type == SIMULTANEOUS_DIVERGENCE: |
|
1662 |
name = "simultaneousDivergence" |
|
1663 |
divergence = plcopen.simultaneousDivergence() |
|
1664 |
elif type == SIMULTANEOUS_CONVERGENCE: |
|
1665 |
name = "simultaneousConvergence" |
|
1666 |
divergence = plcopen.simultaneousConvergence() |
|
1667 |
divergence.setLocalId(id) |
|
1668 |
self.GetCurrentElementEditing().addInstance(name, divergence) |
|
1669 |
||
1670 |
def SetCurrentElementEditingDivergenceInfos(self, id, infos): |
|
1671 |
divergence = self.GetCurrentElementEditing().getInstance(id) |
|
1672 |
for param, value in infos.items(): |
|
1673 |
if param == "height": |
|
1674 |
divergence.setHeight(value) |
|
1675 |
elif param == "width": |
|
1676 |
divergence.setWidth(value) |
|
1677 |
elif param == "x": |
|
1678 |
divergence.setX(value) |
|
1679 |
elif param == "y": |
|
1680 |
divergence.setY(value) |
|
1681 |
elif param == "connectors": |
|
1682 |
input_connectors = value["inputs"] |
|
1683 |
if isinstance(divergence, (plcopen.selectionDivergence, plcopen.simultaneousDivergence)): |
|
1684 |
position = input_connectors[0].GetRelPosition() |
|
1685 |
divergence.addConnectionPointIn() |
|
1686 |
divergence.connectionPointIn.setRelPosition(position.x, position.y) |
|
1687 |
self.SetConnectionWires(divergence.connectionPointIn, input_connectors[0]) |
|
1688 |
else: |
|
1689 |
divergence.setConnectionPointIn([]) |
|
1690 |
for input_connector in input_connectors: |
|
1691 |
position = input_connector.GetRelPosition() |
|
1692 |
if isinstance(divergence, plcopen.selectionConvergence): |
|
1693 |
connection = plcopen.selectionConvergence_connectionPointIn() |
|
1694 |
else: |
|
1695 |
connection = plcopen.connectionPointIn() |
|
1696 |
connection.setRelPosition(position.x, position.y) |
|
1697 |
self.SetConnectionWires(connection, input_connector) |
|
1698 |
divergence.appendConnectionPointIn(connection) |
|
1699 |
output_connectors = value["outputs"] |
|
1700 |
if isinstance(divergence, (plcopen.selectionConvergence, plcopen.simultaneousConvergence)): |
|
1701 |
position = output_connectors[0].GetRelPosition() |
|
1702 |
divergence.addConnectionPointOut() |
|
1703 |
divergence.connectionPointOut.setRelPosition(position.x, position.y) |
|
1704 |
else: |
|
1705 |
divergence.setConnectionPointOut([]) |
|
1706 |
for output_connector in output_connectors: |
|
1707 |
position = output_connector.GetRelPosition() |
|
1708 |
if isinstance(divergence, plcopen.selectionDivergence): |
|
1709 |
connection = plcopen.selectionDivergence_connectionPointOut() |
|
1710 |
else: |
|
1711 |
connection = plcopen.simultaneousDivergence_connectionPointOut() |
|
1712 |
connection.setRelPosition(position.x, position.y) |
|
1713 |
divergence.appendConnectionPointOut(connection) |
|
1714 |
||
1715 |
def AddCurrentElementEditingJump(self, id): |
|
1716 |
jump = plcopen.jumpStep() |
|
1717 |
jump.setLocalId(id) |
|
1718 |
self.GetCurrentElementEditing().addInstance("jumpStep", jump) |
|
1719 |
||
1720 |
def SetCurrentElementEditingJumpInfos(self, id, infos): |
|
1721 |
jump = self.GetCurrentElementEditing().getInstance(id) |
|
1722 |
for param, value in infos.items(): |
|
1723 |
if param == "target": |
|
1724 |
jump.setTargetName(value) |
|
1725 |
elif param == "height": |
|
1726 |
jump.setHeight(value) |
|
1727 |
elif param == "width": |
|
1728 |
jump.setWidth(value) |
|
1729 |
elif param == "x": |
|
1730 |
jump.setX(value) |
|
1731 |
elif param == "y": |
|
1732 |
jump.setY(value) |
|
1733 |
elif param == "connector": |
|
1734 |
position = value.GetRelPosition() |
|
1735 |
jump.addConnectionPointIn() |
|
1736 |
jump.connectionPointIn.setRelPosition(position.x, position.y) |
|
1737 |
self.SetConnectionWires(jump.connectionPointIn, value) |
|
1738 |
||
1739 |
def AddCurrentElementEditingActionBlock(self, id): |
|
1740 |
actionBlock = plcopen.actionBlock() |
|
1741 |
actionBlock.setLocalId(id) |
|
1742 |
self.GetCurrentElementEditing().addInstance("actionBlock", actionBlock) |
|
1743 |
||
1744 |
def SetCurrentElementEditingActionBlockInfos(self, id, infos): |
|
1745 |
actionBlock = self.GetCurrentElementEditing().getInstance(id) |
|
1746 |
for param, value in infos.items(): |
|
1747 |
if param == "actions": |
|
1748 |
actionBlock.setActions(value) |
|
1749 |
elif param == "height": |
|
1750 |
actionBlock.setHeight(value) |
|
1751 |
elif param == "width": |
|
1752 |
actionBlock.setWidth(value) |
|
1753 |
elif param == "x": |
|
1754 |
actionBlock.setX(value) |
|
1755 |
elif param == "y": |
|
1756 |
actionBlock.setY(value) |
|
1757 |
elif param == "connector": |
|
1758 |
position = value.GetRelPosition() |
|
1759 |
actionBlock.addConnectionPointIn() |
|
1760 |
actionBlock.connectionPointIn.setRelPosition(position.x, position.y) |
|
1761 |
self.SetConnectionWires(actionBlock.connectionPointIn, value) |
|
1762 |
||
1763 |
def RemoveCurrentElementEditingInstance(self, id): |
|
1764 |
self.GetCurrentElementEditing().removeInstance(id) |
|
1765 |
self.RefreshPouUsingTree() |
|
1766 |
||
1767 |
def GetCurrentResourceEditingVariables(self): |
|
1768 |
varlist = [] |
|
1769 |
name = self.ElementsOpened[self.CurrentElementEditing] |
|
1770 |
words = name.split("::") |
|
1771 |
for var in self.GetConfigurationGlobalVars(words[1]): |
|
1772 |
if var["Type"] == "BOOL": |
|
1773 |
varlist.append(var["Name"]) |
|
1774 |
for var in self.GetConfigurationResourceGlobalVars(words[1], words[2]): |
|
1775 |
if var["Type"] == "BOOL": |
|
1776 |
varlist.append(var["Name"]) |
|
1777 |
return varlist |
|
1778 |
||
1779 |
def SetCurrentResourceEditingInfos(self, tasks, instances): |
|
1780 |
resource = self.GetCurrentElementEditing() |
|
1781 |
resource.setTask([]) |
|
1782 |
resource.setPouInstance([]) |
|
1783 |
task_list = {} |
|
1784 |
for task in tasks: |
|
1785 |
new_task = plcopen.resource_task() |
|
1786 |
new_task.setName(task["Name"]) |
|
1787 |
if task["Single"] != "": |
|
1788 |
new_task.setSingle(task["Single"]) |
|
24 | 1789 |
result = duration_model.match(task["Interval"]).groups() |
1790 |
if reduce(lambda x, y: x or y != None, result): |
|
1791 |
values = [] |
|
1792 |
for value in result: |
|
1793 |
if value != None: |
|
1794 |
values.append(int(value)) |
|
1795 |
else: |
|
1796 |
values.append(0) |
|
1797 |
values[3] = values[3] * 1000 |
|
1798 |
new_task.setInterval(time(*values)) |
|
0 | 1799 |
new_task.priority.setValue(int(task["Priority"])) |
1800 |
if task["Name"] != "": |
|
1801 |
task_list[task["Name"]] = new_task |
|
1802 |
resource.appendTask(new_task) |
|
1803 |
for instance in instances: |
|
1804 |
new_instance = plcopen.pouInstance() |
|
1805 |
new_instance.setName(instance["Name"]) |
|
1806 |
new_instance.setType(instance["Type"]) |
|
1807 |
if instance["Task"] != "": |
|
1808 |
task_list[instance["Task"]].appendPouInstance(new_instance) |
|
1809 |
else: |
|
1810 |
resource.appendPouInstance(new_instance) |
|
1811 |
||
1812 |
def GetCurrentResourceEditingInfos(self): |
|
1813 |
resource = self.GetCurrentElementEditing() |
|
1814 |
tasks = resource.getTask() |
|
1815 |
instances = resource.getPouInstance() |
|
1816 |
tasks_data = [] |
|
1817 |
instances_data = [] |
|
1818 |
for task in tasks: |
|
1819 |
new_task = {} |
|
1820 |
new_task["Name"] = task.getName() |
|
1821 |
single = task.getSingle() |
|
1822 |
if single: |
|
1823 |
new_task["Single"] = single |
|
1824 |
else: |
|
1825 |
new_task["Single"] = "" |
|
1826 |
interval = task.getInterval() |
|
1827 |
if interval: |
|
24 | 1828 |
text = "" |
1829 |
if interval.hour != 0: |
|
1830 |
text += "%dh"%interval.hour |
|
1831 |
if interval.minute != 0: |
|
1832 |
text += "%dm"%interval.minute |
|
1833 |
if interval.second != 0: |
|
1834 |
text += "%ds"%interval.second |
|
1835 |
if interval.microsecond != 0: |
|
1836 |
text += "%dms"%(interval.microsecond / 1000) |
|
1837 |
new_task["Interval"] = text |
|
0 | 1838 |
else: |
1839 |
new_task["Interval"] = "" |
|
1840 |
new_task["Priority"] = str(task.priority.getValue()) |
|
1841 |
tasks_data.append(new_task) |
|
1842 |
for instance in task.getPouInstance(): |
|
1843 |
new_instance = {} |
|
1844 |
new_instance["Name"] = instance.getName() |
|
1845 |
new_instance["Type"] = instance.getType() |
|
1846 |
new_instance["Task"] = task.getName() |
|
1847 |
instances_data.append(new_instance) |
|
1848 |
for instance in instances: |
|
1849 |
new_instance = {} |
|
1850 |
new_instance["Name"] = instance.getName() |
|
1851 |
new_instance["Type"] = instance.getType() |
|
1852 |
new_instance["Task"] = "" |
|
1853 |
instances_data.append(new_instance) |
|
1854 |
return tasks_data, instances_data |
|
1855 |
||
1856 |
def OpenXMLFile(self, filepath): |
|
27 | 1857 |
if self.VerifyXML: |
1858 |
if sys: |
|
1859 |
sys.stdout = HolePseudoFile() |
|
1860 |
result = pyxsval.parseAndValidate(filepath, os.path.join(sys.path[0], "plcopen/TC6_XML_V10_B.xsd")) |
|
1861 |
if sys: |
|
1862 |
sys.stdout = sys.__stdout__ |
|
1863 |
tree = result.getTree() |
|
1864 |
else: |
|
1865 |
xmlfile = open(filepath, 'r') |
|
1866 |
tree = minidom.parse(xmlfile) |
|
1867 |
xmlfile.close() |
|
0 | 1868 |
|
1869 |
self.Project = plcopen.project() |
|
27 | 1870 |
self.Project.loadXMLTree(tree.childNodes[0]) |
0 | 1871 |
self.UndoBuffer = UndoBuffer(self.Copy(self.Project), True) |
1872 |
self.SetFilePath(filepath) |
|
1873 |
self.ElementsOpened = [] |
|
1874 |
self.CurrentElementEditing = None |
|
1875 |
self.RefreshPouUsingTree() |
|
1876 |
self.RefreshBlockTypes() |
|
1877 |
||
1878 |
def SaveXMLFile(self, filepath = None): |
|
1879 |
if not filepath and self.FilePath == "": |
|
1880 |
return False |
|
1881 |
else: |
|
1882 |
text = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" |
|
1883 |
extras = {"xmlns" : "http://www.plcopen.org/xml/tc6.xsd", |
|
1884 |
"xmlns:xhtml" : "http://www.w3.org/1999/xhtml", |
|
1885 |
"xmlns:xsi" : "http://www.w3.org/2001/XMLSchema-instance", |
|
1886 |
"xsi:schemaLocation" : "http://www.plcopen.org/xml/tc6.xsd http://www.plcopen.org/xml/tc6.xsd"} |
|
1887 |
text += self.Project.generateXMLText("project", 0, extras) |
|
1888 |
||
27 | 1889 |
if self.VerifyXML: |
1890 |
if sys: |
|
1891 |
sys.stdout = HolePseudoFile() |
|
1892 |
pyxsval.parseAndValidateString(text, open(os.path.join(sys.path[0], "plcopen/TC6_XML_V10_B.xsd"),"r").read()) |
|
1893 |
if sys: |
|
1894 |
sys.stdout = sys.__stdout__ |
|
0 | 1895 |
|
1896 |
if filepath: |
|
1897 |
xmlfile = open(filepath,"w") |
|
1898 |
else: |
|
1899 |
xmlfile = open(self.FilePath,"w") |
|
1900 |
xmlfile.write(text) |
|
1901 |
xmlfile.close() |
|
27 | 1902 |
#self.ProjectBuffer.CurrentSaved() |
0 | 1903 |
if filepath: |
1904 |
self.SetFilePath(filepath) |
|
1905 |
return True |
|
1906 |
||
1907 |
#------------------------------------------------------------------------------- |
|
1908 |
# Current Buffering Management Functions |
|
1909 |
#------------------------------------------------------------------------------- |
|
1910 |
||
1911 |
""" |
|
1912 |
Return a copy of the project |
|
1913 |
""" |
|
1914 |
def Copy(self, model): |
|
1915 |
return cPickle.loads(cPickle.dumps(model)) |
|
1916 |
||
1917 |
def BufferProject(self): |
|
27 | 1918 |
self.ProjectBuffer.Buffering(self.Copy(self)) |
0 | 1919 |
|
1920 |
def ProjectIsSaved(self): |
|
27 | 1921 |
return self.ProjectBuffer.IsCurrentSaved() |
0 | 1922 |
|
1923 |
def LoadPrevious(self): |
|
27 | 1924 |
self.Project = self.Copy(self.ProjectBuffer.Previous()) |
0 | 1925 |
self.RefreshElementsOpened() |
1926 |
||
1927 |
def LoadNext(self): |
|
27 | 1928 |
self.Project = self.Copy(self.ProjectBuffer.Next()) |
0 | 1929 |
self.RefreshElementsOpened() |
1930 |
||
1931 |
def GetBufferState(self): |
|
27 | 1932 |
first = self.ProjectBuffer.IsFirst() |
1933 |
last = self.ProjectBuffer.IsLast() |
|
0 | 1934 |
return not first, not last |