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