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