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