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