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