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