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