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