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