120 end = TextLenInRowColumn(text[:result.end() - 1]) |
121 end = TextLenInRowColumn(text[:result.end() - 1]) |
121 test_result.append((start, end, "\n".join(lines[start[0]:end[0] + 1]))) |
122 test_result.append((start, end, "\n".join(lines[start[0]:end[0] + 1]))) |
122 result = criteria["pattern"].search(text, result.end()) |
123 result = criteria["pattern"].search(text, result.end()) |
123 return test_result |
124 return test_result |
124 |
125 |
125 PLCOpenClasses = GenerateClassesFromXSD(os.path.join(os.path.split(__file__)[0], "tc6_xml_v201.xsd")) |
126 PLCOpenParser = GenerateParserFromXSD(os.path.join(os.path.split(__file__)[0], "tc6_xml_v201.xsd")) |
126 |
127 PLCOpen_XPath = lambda xpath: etree.XPath(xpath, namespaces=PLCOpenParser.NSMAP) |
127 ElementNameToClass = {} |
128 |
128 |
129 LOAD_POU_PROJECT_TEMPLATE = """ |
129 cls = PLCOpenClasses.get("formattedText", None) |
130 <project xmlns:ns1="http://www.plcopen.org/xml/tc6_0201" |
|
131 xmlns:xhtml="http://www.w3.org/1999/xhtml" |
|
132 xmlns:xsd="http://www.w3.org/2001/XMLSchema" |
|
133 xmlns="http://www.plcopen.org/xml/tc6_0201"> |
|
134 <fileHeader companyName="" productName="" productVersion="" |
|
135 creationDateTime="1970-01-01T00:00:00"/> |
|
136 <contentHeader name="paste_project"> |
|
137 <coordinateInfo> |
|
138 <fbd><scaling x="0" y="0"/></fbd> |
|
139 <ld><scaling x="0" y="0"/></ld> |
|
140 <sfc><scaling x="0" y="0"/></sfc> |
|
141 </coordinateInfo> |
|
142 </contentHeader> |
|
143 <types> |
|
144 <dataTypes/> |
|
145 <pous>%s</pous> |
|
146 </types> |
|
147 <instances> |
|
148 <configurations/> |
|
149 </instances> |
|
150 </project> |
|
151 """ |
|
152 |
|
153 def LOAD_POU_INSTANCES_PROJECT_TEMPLATE(body_type): |
|
154 return LOAD_POU_PROJECT_TEMPLATE % """ |
|
155 <pou name="paste_pou" pouType="program"> |
|
156 <body> |
|
157 <%(body_type)s>%%s</%(body_type)s> |
|
158 </body> |
|
159 </pou>""" % locals() |
|
160 |
|
161 def LoadProject(filepath): |
|
162 project_file = open(filepath) |
|
163 project_xml = project_file.read().replace( |
|
164 "http://www.plcopen.org/xml/tc6.xsd", |
|
165 "http://www.plcopen.org/xml/tc6_0201") |
|
166 for cre, repl in [ |
|
167 (re.compile("(?<!<xhtml:p>)(?:<!\[CDATA\[)"), "<xhtml:p><![CDATA["), |
|
168 (re.compile("(?:]]>)(?!</xhtml:p>)"), "]]></xhtml:p>")]: |
|
169 project_xml = cre.sub(repl, project_xml) |
|
170 project_file.close() |
|
171 |
|
172 return etree.fromstring(project_xml, PLCOpenParser) |
|
173 |
|
174 project_pou_xpath = PLCOpen_XPath("/ppx:project/ppx:types/ppx:pous/ppx:pou") |
|
175 def LoadPou(xml_string): |
|
176 root = etree.fromstring( |
|
177 LOAD_POU_PROJECT_TEMPLATE % xml_string, |
|
178 PLCOpenParser) |
|
179 return project_pou_xpath(root)[0] |
|
180 |
|
181 project_pou_instances_xpath = { |
|
182 body_type: PLCOpen_XPath( |
|
183 "/ppx:project/ppx:types/ppx:pous/ppx:pou[@name='paste_pou']/ppx:body/ppx:%s/*" % body_type) |
|
184 for body_type in ["FBD", "LD", "SFC"]} |
|
185 def LoadPouInstances(xml_string, body_type): |
|
186 root = etree.fromstring( |
|
187 LOAD_POU_INSTANCES_PROJECT_TEMPLATE(body_type) % xml_string, |
|
188 PLCOpenParser) |
|
189 return project_pou_instances_xpath[body_type](root) |
|
190 |
|
191 def SaveProject(project, filepath): |
|
192 project_file = open(filepath, 'w') |
|
193 project_file.write(etree.tostring( |
|
194 project, |
|
195 pretty_print=True, |
|
196 xml_declaration=True, |
|
197 encoding='utf-8')) |
|
198 project_file.close() |
|
199 |
|
200 cls = PLCOpenParser.GetElementClass("formattedText") |
130 if cls: |
201 if cls: |
131 def updateElementName(self, old_name, new_name): |
202 def updateElementName(self, old_name, new_name): |
132 text = self.text |
203 text = self.getanyText() |
133 index = text.find(old_name) |
204 index = text.find(old_name) |
134 while index != -1: |
205 while index != -1: |
135 if index > 0 and (text[index - 1].isalnum() or text[index - 1] == "_"): |
206 if index > 0 and (text[index - 1].isalnum() or text[index - 1] == "_"): |
136 index = text.find(old_name, index + len(old_name)) |
207 index = text.find(old_name, index + len(old_name)) |
137 elif index < len(text) - len(old_name) and (text[index + len(old_name)].isalnum() or text[index + len(old_name)] == "_"): |
208 elif index < len(text) - len(old_name) and (text[index + len(old_name)].isalnum() or text[index + len(old_name)] == "_"): |
138 index = text.find(old_name, index + len(old_name)) |
209 index = text.find(old_name, index + len(old_name)) |
139 else: |
210 else: |
140 text = text[:index] + new_name + text[index + len(old_name):] |
211 text = text[:index] + new_name + text[index + len(old_name):] |
141 index = text.find(old_name, index + len(new_name)) |
212 index = text.find(old_name, index + len(new_name)) |
142 self.text = text |
213 self.setanyText(text) |
143 setattr(cls, "updateElementName", updateElementName) |
214 setattr(cls, "updateElementName", updateElementName) |
144 |
215 |
145 def updateElementAddress(self, address_model, new_leading): |
216 def updateElementAddress(self, address_model, new_leading): |
146 text = self.text |
217 text = self.getanyText() |
147 startpos = 0 |
218 startpos = 0 |
148 result = address_model.search(text, startpos) |
219 result = address_model.search(text, startpos) |
149 while result is not None: |
220 while result is not None: |
150 groups = result.groups() |
221 groups = result.groups() |
151 new_address = groups[0] + new_leading + groups[2] |
222 new_address = groups[0] + new_leading + groups[2] |
152 text = text[:result.start()] + new_address + text[result.end():] |
223 text = text[:result.start()] + new_address + text[result.end():] |
153 startpos = result.start() + len(new_address) |
224 startpos = result.start() + len(new_address) |
154 result = address_model.search(self.text, startpos) |
225 result = address_model.search(self.text, startpos) |
155 self.text = text |
226 self.setanyText(text) |
156 setattr(cls, "updateElementAddress", updateElementAddress) |
227 setattr(cls, "updateElementAddress", updateElementAddress) |
157 |
228 |
158 def hasblock(self, block_type): |
229 def hasblock(self, block_type): |
159 text = self.text.upper() |
230 text = self.getanyText().upper() |
160 index = text.find(block_type.upper()) |
231 index = text.find(block_type.upper()) |
161 while index != -1: |
232 while index != -1: |
162 if (not (index > 0 and (text[index - 1].isalnum() or text[index - 1] == "_")) and |
233 if (not (index > 0 and (text[index - 1].isalnum() or text[index - 1] == "_")) and |
163 not (index < len(text) - len(block_type) and text[index + len(block_type)] != "(")): |
234 not (index < len(text) - len(block_type) and text[index + len(block_type)] != "(")): |
164 return True |
235 return True |
165 index = text.find(block_type.upper(), index + len(block_type)) |
236 index = text.find(block_type.upper(), index + len(block_type)) |
166 return False |
237 return False |
167 setattr(cls, "hasblock", hasblock) |
238 setattr(cls, "hasblock", hasblock) |
168 |
239 |
169 def Search(self, criteria, parent_infos): |
240 def Search(self, criteria, parent_infos): |
170 return [(tuple(parent_infos),) + result for result in TestTextElement(self.gettext(), criteria)] |
241 return [(tuple(parent_infos),) + result for result in TestTextElement(self.getanyText(), criteria)] |
171 setattr(cls, "Search", Search) |
242 setattr(cls, "Search", Search) |
172 |
243 |
173 cls = PLCOpenClasses.get("project", None) |
244 cls = PLCOpenParser.GetElementClass("project") |
174 if cls: |
245 if cls: |
175 cls.singleLineAttributes = False |
|
176 cls.EnumeratedDataTypeValues = {} |
|
177 cls.CustomDataTypeRange = {} |
|
178 cls.CustomTypeHierarchy = {} |
|
179 cls.ElementUsingTree = {} |
|
180 cls.CustomBlockTypes = OrderedDict() |
|
181 |
246 |
182 def setname(self, name): |
247 def setname(self, name): |
183 self.contentHeader.setname(name) |
248 self.contentHeader.setname(name) |
184 setattr(cls, "setname", setname) |
249 setattr(cls, "setname", setname) |
185 |
250 |
186 def getname(self): |
251 def getname(self): |
187 return self.contentHeader.getname() |
252 return self.contentHeader.getname() |
188 setattr(cls, "getname", getname) |
253 setattr(cls, "getname", getname) |
189 |
254 |
190 def getfileHeader(self): |
255 def getfileHeader(self): |
191 fileheader = {} |
256 fileheader_obj = self.fileHeader |
192 for name, value in [("companyName", self.fileHeader.getcompanyName()), |
257 return { |
193 ("companyURL", self.fileHeader.getcompanyURL()), |
258 attr: value if value is not None else "" |
194 ("productName", self.fileHeader.getproductName()), |
259 for attr, value in [ |
195 ("productVersion", self.fileHeader.getproductVersion()), |
260 ("companyName", fileheader_obj.getcompanyName()), |
196 ("productRelease", self.fileHeader.getproductRelease()), |
261 ("companyURL", fileheader_obj.getcompanyURL()), |
197 ("creationDateTime", self.fileHeader.getcreationDateTime()), |
262 ("productName", fileheader_obj.getproductName()), |
198 ("contentDescription", self.fileHeader.getcontentDescription())]: |
263 ("productVersion", fileheader_obj.getproductVersion()), |
199 if value is not None: |
264 ("productRelease", fileheader_obj.getproductRelease()), |
200 fileheader[name] = value |
265 ("creationDateTime", fileheader_obj.getcreationDateTime()), |
201 else: |
266 ("contentDescription", fileheader_obj.getcontentDescription())] |
202 fileheader[name] = "" |
267 } |
203 return fileheader |
|
204 setattr(cls, "getfileHeader", getfileHeader) |
268 setattr(cls, "getfileHeader", getfileHeader) |
205 |
269 |
206 def setfileHeader(self, fileheader): |
270 def setfileHeader(self, fileheader): |
207 if fileheader.has_key("companyName"): |
271 fileheader_obj = self.fileHeader |
208 self.fileHeader.setcompanyName(fileheader["companyName"]) |
272 for attr, value in fileheader.iteritems(): |
209 if fileheader.has_key("companyURL"): |
273 setattr(fileheader_obj, attr, value) |
210 self.fileHeader.setcompanyURL(fileheader["companyURL"]) |
|
211 if fileheader.has_key("productName"): |
|
212 self.fileHeader.setproductName(fileheader["productName"]) |
|
213 if fileheader.has_key("productVersion"): |
|
214 self.fileHeader.setproductVersion(fileheader["productVersion"]) |
|
215 if fileheader.has_key("productRelease"): |
|
216 self.fileHeader.setproductRelease(fileheader["productRelease"]) |
|
217 if fileheader.has_key("creationDateTime"): |
|
218 self.fileHeader.setcreationDateTime(fileheader["creationDateTime"]) |
|
219 if fileheader.has_key("contentDescription"): |
|
220 self.fileHeader.setcontentDescription(fileheader["contentDescription"]) |
|
221 setattr(cls, "setfileHeader", setfileHeader) |
274 setattr(cls, "setfileHeader", setfileHeader) |
222 |
275 |
223 def getcontentHeader(self): |
276 def getcontentHeader(self): |
224 contentheader = {} |
277 contentheader_obj = self.contentHeader |
225 for name, value in [("projectName", self.contentHeader.getname()), |
278 contentheader = { |
226 ("projectVersion", self.contentHeader.getversion()), |
279 attr: value if value is not None else "" |
227 ("modificationDateTime", self.contentHeader.getmodificationDateTime()), |
280 for attr, value in [ |
228 ("organization", self.contentHeader.getorganization()), |
281 ("projectName", contentheader_obj.getname()), |
229 ("authorName", self.contentHeader.getauthor()), |
282 ("projectVersion", contentheader_obj.getversion()), |
230 ("language", self.contentHeader.getlanguage())]: |
283 ("modificationDateTime", contentheader_obj.getmodificationDateTime()), |
231 if value is not None: |
284 ("organization", contentheader_obj.getorganization()), |
232 contentheader[name] = value |
285 ("authorName", contentheader_obj.getauthor()), |
233 else: |
286 ("language", contentheader_obj.getlanguage())] |
234 contentheader[name] = "" |
287 } |
235 contentheader["pageSize"] = self.contentHeader.getpageSize() |
288 contentheader["pageSize"] = self.contentHeader.getpageSize() |
236 contentheader["scaling"] = self.contentHeader.getscaling() |
289 contentheader["scaling"] = self.contentHeader.getscaling() |
237 return contentheader |
290 return contentheader |
238 setattr(cls, "getcontentHeader", getcontentHeader) |
291 setattr(cls, "getcontentHeader", getcontentHeader) |
239 |
292 |
240 def setcontentHeader(self, contentheader): |
293 def setcontentHeader(self, contentheader): |
241 if contentheader.has_key("projectName"): |
294 contentheader_obj = self.contentHeader |
242 self.contentHeader.setname(contentheader["projectName"]) |
295 for attr, value in contentheader.iteritems(): |
243 if contentheader.has_key("projectVersion"): |
296 if attr == "projectName": |
244 self.contentHeader.setversion(contentheader["projectVersion"]) |
297 contentheader_obj.setname(value) |
245 if contentheader.has_key("modificationDateTime"): |
298 elif attr == "projectVersion": |
246 self.contentHeader.setmodificationDateTime(contentheader["modificationDateTime"]) |
299 contentheader_obj.setversion(value) |
247 if contentheader.has_key("organization"): |
300 elif attr == "pageSize": |
248 self.contentHeader.setorganization(contentheader["organization"]) |
301 contentheader_obj.setpageSize(*contentheader["pageSize"]) |
249 if contentheader.has_key("authorName"): |
302 elif attr == "scaling": |
250 self.contentHeader.setauthor(contentheader["authorName"]) |
303 contentheader_obj.setscaling(contentheader["scaling"]) |
251 if contentheader.has_key("language"): |
304 else: |
252 self.contentHeader.setlanguage(contentheader["language"]) |
305 setattr(contentheader_obj, attr, value) |
253 if contentheader.has_key("pageSize"): |
|
254 self.contentHeader.setpageSize(*contentheader["pageSize"]) |
|
255 if contentheader.has_key("scaling"): |
|
256 self.contentHeader.setscaling(contentheader["scaling"]) |
|
257 setattr(cls, "setcontentHeader", setcontentHeader) |
306 setattr(cls, "setcontentHeader", setcontentHeader) |
258 |
307 |
259 def getdataTypes(self): |
308 def gettypeElementFunc(element_type): |
260 return self.types.getdataTypeElements() |
309 elements_xpath = PLCOpen_XPath( |
|
310 "ppx:types/ppx:%(element_type)ss/ppx:%(element_type)s[@name=$name]" % locals()) |
|
311 def gettypeElement(self, name): |
|
312 elements = elements_xpath(self, name=name) |
|
313 if len(elements) == 1: |
|
314 return elements[0] |
|
315 return None |
|
316 return gettypeElement |
|
317 |
|
318 datatypes_xpath = PLCOpen_XPath("ppx:types/ppx:dataTypes/ppx:dataType") |
|
319 filtered_datatypes_xpath = PLCOpen_XPath( |
|
320 "ppx:types/ppx:dataTypes/ppx:dataType[@name!=$exclude]") |
|
321 def getdataTypes(self, exclude=None): |
|
322 if exclude is not None: |
|
323 return filtered_datatypes_xpath(self, exclude=exclude) |
|
324 return datatypes_xpath(self) |
261 setattr(cls, "getdataTypes", getdataTypes) |
325 setattr(cls, "getdataTypes", getdataTypes) |
262 |
326 |
263 def getdataType(self, name): |
327 setattr(cls, "getdataType", gettypeElementFunc("dataType")) |
264 return self.types.getdataTypeElement(name) |
|
265 setattr(cls, "getdataType", getdataType) |
|
266 |
328 |
267 def appenddataType(self, name): |
329 def appenddataType(self, name): |
268 if self.CustomTypeHierarchy.has_key(name): |
330 if self.getdataType(name) is not None: |
269 raise ValueError, "\"%s\" Data Type already exists !!!"%name |
331 raise ValueError, "\"%s\" Data Type already exists !!!"%name |
270 self.types.appenddataTypeElement(name) |
332 self.types.appenddataTypeElement(name) |
271 self.AddCustomDataType(self.getdataType(name)) |
|
272 setattr(cls, "appenddataType", appenddataType) |
333 setattr(cls, "appenddataType", appenddataType) |
273 |
334 |
274 def insertdataType(self, index, datatype): |
335 def insertdataType(self, index, datatype): |
275 self.types.insertdataTypeElement(index, datatype) |
336 self.types.insertdataTypeElement(index, datatype) |
276 self.AddCustomDataType(datatype) |
|
277 setattr(cls, "insertdataType", insertdataType) |
337 setattr(cls, "insertdataType", insertdataType) |
278 |
338 |
279 def removedataType(self, name): |
339 def removedataType(self, name): |
280 self.types.removedataTypeElement(name) |
340 self.types.removedataTypeElement(name) |
281 self.RefreshDataTypeHierarchy() |
|
282 self.RefreshElementUsingTree() |
|
283 setattr(cls, "removedataType", removedataType) |
341 setattr(cls, "removedataType", removedataType) |
284 |
342 |
285 def getpous(self): |
343 def getpous(self, exclude=None, filter=[]): |
286 return self.types.getpouElements() |
344 return self.xpath( |
|
345 "ppx:types/ppx:pous/ppx:pou%s%s" % |
|
346 (("[@name!='%s']" % exclude) if exclude is not None else '', |
|
347 ("[%s]" % " or ".join( |
|
348 map(lambda x: "@pouType='%s'" % x, filter))) |
|
349 if len(filter) > 0 else ""), |
|
350 namespaces=PLCOpenParser.NSMAP) |
287 setattr(cls, "getpous", getpous) |
351 setattr(cls, "getpous", getpous) |
288 |
352 |
289 def getpou(self, name): |
353 setattr(cls, "getpou", gettypeElementFunc("pou")) |
290 return self.types.getpouElement(name) |
|
291 setattr(cls, "getpou", getpou) |
|
292 |
354 |
293 def appendpou(self, name, pou_type, body_type): |
355 def appendpou(self, name, pou_type, body_type): |
294 self.types.appendpouElement(name, pou_type, body_type) |
356 self.types.appendpouElement(name, pou_type, body_type) |
295 self.AddCustomBlockType(self.getpou(name)) |
|
296 setattr(cls, "appendpou", appendpou) |
357 setattr(cls, "appendpou", appendpou) |
297 |
358 |
298 def insertpou(self, index, pou): |
359 def insertpou(self, index, pou): |
299 self.types.insertpouElement(index, pou) |
360 self.types.insertpouElement(index, pou) |
300 self.AddCustomBlockType(pou) |
|
301 setattr(cls, "insertpou", insertpou) |
361 setattr(cls, "insertpou", insertpou) |
302 |
362 |
303 def removepou(self, name): |
363 def removepou(self, name): |
304 self.types.removepouElement(name) |
364 self.types.removepouElement(name) |
305 self.RefreshCustomBlockTypes() |
|
306 self.RefreshElementUsingTree() |
|
307 setattr(cls, "removepou", removepou) |
365 setattr(cls, "removepou", removepou) |
308 |
366 |
|
367 configurations_xpath = PLCOpen_XPath( |
|
368 "ppx:instances/ppx:configurations/ppx:configuration") |
309 def getconfigurations(self): |
369 def getconfigurations(self): |
310 configurations = self.instances.configurations.getconfiguration() |
370 return configurations_xpath(self) |
311 if configurations: |
|
312 return configurations |
|
313 return [] |
|
314 setattr(cls, "getconfigurations", getconfigurations) |
371 setattr(cls, "getconfigurations", getconfigurations) |
315 |
372 |
|
373 configuration_xpath = PLCOpen_XPath( |
|
374 "ppx:instances/ppx:configurations/ppx:configuration[@name=$name]") |
316 def getconfiguration(self, name): |
375 def getconfiguration(self, name): |
317 for configuration in self.instances.configurations.getconfiguration(): |
376 configurations = configuration_xpath(self, name=name) |
318 if configuration.getname() == name: |
377 if len(configurations) == 1: |
319 return configuration |
378 return configurations[0] |
320 return None |
379 return None |
321 setattr(cls, "getconfiguration", getconfiguration) |
380 setattr(cls, "getconfiguration", getconfiguration) |
322 |
381 |
323 def addconfiguration(self, name): |
382 def addconfiguration(self, name): |
324 for configuration in self.instances.configurations.getconfiguration(): |
383 if self.getconfiguration(name) is not None: |
325 if configuration.getname() == name: |
384 raise ValueError, _("\"%s\" configuration already exists !!!") % name |
326 raise ValueError, _("\"%s\" configuration already exists !!!")%name |
385 new_configuration = PLCOpenParser.CreateElement("configuration", "configurations") |
327 new_configuration = PLCOpenClasses["configurations_configuration"]() |
|
328 new_configuration.setname(name) |
386 new_configuration.setname(name) |
329 self.instances.configurations.appendconfiguration(new_configuration) |
387 self.instances.configurations.appendconfiguration(new_configuration) |
330 setattr(cls, "addconfiguration", addconfiguration) |
388 setattr(cls, "addconfiguration", addconfiguration) |
331 |
389 |
332 def removeconfiguration(self, name): |
390 def removeconfiguration(self, name): |
333 found = False |
391 configuration = self.getconfiguration(name) |
334 for idx, configuration in enumerate(self.instances.configurations.getconfiguration()): |
392 if configuration is None: |
335 if configuration.getname() == name: |
393 raise ValueError, ("\"%s\" configuration doesn't exist !!!") % name |
336 self.instances.configurations.removeconfiguration(idx) |
394 self.instances.configurations.remove(configuration) |
337 found = True |
|
338 break |
|
339 if not found: |
|
340 raise ValueError, ("\"%s\" configuration doesn't exist !!!")%name |
|
341 setattr(cls, "removeconfiguration", removeconfiguration) |
395 setattr(cls, "removeconfiguration", removeconfiguration) |
342 |
396 |
|
397 resources_xpath = PLCOpen_XPath( |
|
398 "ppx:instances/ppx:configurations/ppx:configuration[@name=$configname]/ppx:resource[@name=$name]") |
343 def getconfigurationResource(self, config_name, name): |
399 def getconfigurationResource(self, config_name, name): |
344 configuration = self.getconfiguration(config_name) |
400 resources = resources_xpath(self, configname=config_name, name=name) |
345 if configuration: |
401 if len(resources) == 1: |
346 for resource in configuration.getresource(): |
402 return resources[0] |
347 if resource.getname() == name: |
|
348 return resource |
|
349 return None |
403 return None |
350 setattr(cls, "getconfigurationResource", getconfigurationResource) |
404 setattr(cls, "getconfigurationResource", getconfigurationResource) |
351 |
405 |
352 def addconfigurationResource(self, config_name, name): |
406 def addconfigurationResource(self, config_name, name): |
|
407 if self.getconfigurationResource(config_name, name) is not None: |
|
408 raise ValueError, _("\"%s\" resource already exists in \"%s\" configuration !!!") % (name, config_name) |
353 configuration = self.getconfiguration(config_name) |
409 configuration = self.getconfiguration(config_name) |
354 if configuration: |
410 if configuration is not None: |
355 for resource in configuration.getresource(): |
411 new_resource = PLCOpenParser.CreateElement("resource", "configuration") |
356 if resource.getname() == name: |
|
357 raise ValueError, _("\"%s\" resource already exists in \"%s\" configuration !!!")%(name, config_name) |
|
358 new_resource = PLCOpenClasses["configuration_resource"]() |
|
359 new_resource.setname(name) |
412 new_resource.setname(name) |
360 configuration.appendresource(new_resource) |
413 configuration.appendresource(new_resource) |
361 setattr(cls, "addconfigurationResource", addconfigurationResource) |
414 setattr(cls, "addconfigurationResource", addconfigurationResource) |
362 |
415 |
363 def removeconfigurationResource(self, config_name, name): |
416 def removeconfigurationResource(self, config_name, name): |
364 configuration = self.getconfiguration(config_name) |
417 configuration = self.getconfiguration(config_name) |
365 if configuration: |
418 found = False |
366 found = False |
419 if configuration is not None: |
367 for idx, resource in enumerate(configuration.getresource()): |
420 resource = self.getconfigurationResource(config_name, name) |
368 if resource.getname() == name: |
421 if resource is not None: |
369 configuration.removeresource(idx) |
422 configuration.remove(resource) |
370 found = True |
423 found = True |
371 break |
424 if not found: |
372 if not found: |
425 raise ValueError, _("\"%s\" resource doesn't exist in \"%s\" configuration !!!")%(name, config_name) |
373 raise ValueError, _("\"%s\" resource doesn't exist in \"%s\" configuration !!!")%(name, config_name) |
|
374 setattr(cls, "removeconfigurationResource", removeconfigurationResource) |
426 setattr(cls, "removeconfigurationResource", removeconfigurationResource) |
375 |
427 |
376 def updateElementName(self, old_name, new_name): |
428 def updateElementName(self, old_name, new_name): |
377 for datatype in self.types.getdataTypeElements(): |
429 for datatype in self.getdataTypes(): |
378 datatype.updateElementName(old_name, new_name) |
430 datatype.updateElementName(old_name, new_name) |
379 for pou in self.types.getpouElements(): |
431 for pou in self.getpous(): |
380 pou.updateElementName(old_name, new_name) |
432 pou.updateElementName(old_name, new_name) |
381 for configuration in self.instances.configurations.getconfiguration(): |
433 for configuration in self.getconfigurations(): |
382 configuration.updateElementName(old_name, new_name) |
434 configuration.updateElementName(old_name, new_name) |
383 setattr(cls, "updateElementName", updateElementName) |
435 setattr(cls, "updateElementName", updateElementName) |
384 |
436 |
385 def updateElementAddress(self, old_leading, new_leading): |
437 def updateElementAddress(self, old_leading, new_leading): |
386 address_model = re.compile(FILTER_ADDRESS_MODEL % old_leading) |
438 address_model = re.compile(FILTER_ADDRESS_MODEL % old_leading) |
387 for pou in self.types.getpouElements(): |
439 for pou in self.getpous(): |
388 pou.updateElementAddress(address_model, new_leading) |
440 pou.updateElementAddress(address_model, new_leading) |
389 for configuration in self.instances.configurations.getconfiguration(): |
441 for configuration in self.getconfigurations(): |
390 configuration.updateElementAddress(address_model, new_leading) |
442 configuration.updateElementAddress(address_model, new_leading) |
391 setattr(cls, "updateElementAddress", updateElementAddress) |
443 setattr(cls, "updateElementAddress", updateElementAddress) |
392 |
444 |
393 def removeVariableByAddress(self, address): |
445 def removeVariableByAddress(self, address): |
394 for pou in self.types.getpouElements(): |
446 for pou in self.getpous(): |
395 pou.removeVariableByAddress(address) |
447 pou.removeVariableByAddress(address) |
396 for configuration in self.instances.configurations.getconfiguration(): |
448 for configuration in self.getconfigurations(): |
397 configuration.removeVariableByAddress(address) |
449 configuration.removeVariableByAddress(address) |
398 setattr(cls, "removeVariableByAddress", removeVariableByAddress) |
450 setattr(cls, "removeVariableByAddress", removeVariableByAddress) |
399 |
451 |
400 def removeVariableByFilter(self, leading): |
452 def removeVariableByFilter(self, leading): |
401 address_model = re.compile(FILTER_ADDRESS_MODEL % leading) |
453 address_model = re.compile(FILTER_ADDRESS_MODEL % leading) |
402 for pou in self.types.getpouElements(): |
454 for pou in self.getpous(): |
403 pou.removeVariableByFilter(address_model) |
455 pou.removeVariableByFilter(address_model) |
404 for configuration in self.instances.configurations.getconfiguration(): |
456 for configuration in self.getconfigurations(): |
405 configuration.removeVariableByFilter(address_model) |
457 configuration.removeVariableByFilter(address_model) |
406 setattr(cls, "removeVariableByFilter", removeVariableByFilter) |
458 setattr(cls, "removeVariableByFilter", removeVariableByFilter) |
407 |
459 |
408 def RefreshDataTypeHierarchy(self): |
460 enumerated_values_xpath = PLCOpen_XPath( |
409 self.EnumeratedDataTypeValues = {} |
461 "ppx:types/ppx:dataTypes/ppx:dataType/ppx:baseType/ppx:enum/ppx:values/ppx:value") |
410 self.CustomDataTypeRange = {} |
462 def GetEnumeratedDataTypeValues(self): |
411 self.CustomTypeHierarchy = {} |
463 return [value.getname() for value in enumerated_values_xpath(self)] |
412 for datatype in self.getdataTypes(): |
|
413 self.AddCustomDataType(datatype) |
|
414 setattr(cls, "RefreshDataTypeHierarchy", RefreshDataTypeHierarchy) |
|
415 |
|
416 def AddCustomDataType(self, datatype): |
|
417 name = datatype.getname() |
|
418 basetype_content = datatype.getbaseType().getcontent() |
|
419 if basetype_content["value"] is None: |
|
420 self.CustomTypeHierarchy[name] = basetype_content["name"] |
|
421 elif basetype_content["name"] in ["string", "wstring"]: |
|
422 self.CustomTypeHierarchy[name] = basetype_content["name"].upper() |
|
423 elif basetype_content["name"] == "derived": |
|
424 self.CustomTypeHierarchy[name] = basetype_content["value"].getname() |
|
425 elif basetype_content["name"] in ["subrangeSigned", "subrangeUnsigned"]: |
|
426 range = (basetype_content["value"].range.getlower(), |
|
427 basetype_content["value"].range.getupper()) |
|
428 self.CustomDataTypeRange[name] = range |
|
429 base_type = basetype_content["value"].baseType.getcontent() |
|
430 if base_type["value"] is None: |
|
431 self.CustomTypeHierarchy[name] = base_type["name"] |
|
432 else: |
|
433 self.CustomTypeHierarchy[name] = base_type["value"].getname() |
|
434 else: |
|
435 if basetype_content["name"] == "enum": |
|
436 values = [] |
|
437 for value in basetype_content["value"].values.getvalue(): |
|
438 values.append(value.getname()) |
|
439 self.EnumeratedDataTypeValues[name] = values |
|
440 self.CustomTypeHierarchy[name] = "ANY_DERIVED" |
|
441 setattr(cls, "AddCustomDataType", AddCustomDataType) |
|
442 |
|
443 # Update Block types with user-defined pou added |
|
444 def RefreshCustomBlockTypes(self): |
|
445 # Reset the tree of user-defined pou cross-use |
|
446 self.CustomBlockTypes = OrderedDict() |
|
447 for pou in self.getpous(): |
|
448 self.AddCustomBlockType(pou) |
|
449 setattr(cls, "RefreshCustomBlockTypes", RefreshCustomBlockTypes) |
|
450 |
|
451 def AddCustomBlockType(self, pou): |
|
452 pou_name = pou.getname() |
|
453 pou_type = pou.getpouType() |
|
454 block_infos = {"name" : pou_name, "type" : pou_type, "extensible" : False, |
|
455 "inputs" : [], "outputs" : [], "comment" : pou.getdescription(), |
|
456 "generate" : generate_block, "initialise" : initialise_block} |
|
457 if pou.getinterface(): |
|
458 return_type = pou.interface.getreturnType() |
|
459 if return_type: |
|
460 var_type = return_type.getcontent() |
|
461 if var_type["name"] == "derived": |
|
462 block_infos["outputs"].append(("OUT", var_type["value"].getname(), "none")) |
|
463 elif var_type["name"] in ["string", "wstring"]: |
|
464 block_infos["outputs"].append(("OUT", var_type["name"].upper(), "none")) |
|
465 else: |
|
466 block_infos["outputs"].append(("OUT", var_type["name"], "none")) |
|
467 for type, varlist in pou.getvars(): |
|
468 if type == "InOut": |
|
469 for var in varlist.getvariable(): |
|
470 var_type = var.type.getcontent() |
|
471 if var_type["name"] == "derived": |
|
472 block_infos["inputs"].append((var.getname(), var_type["value"].getname(), "none")) |
|
473 block_infos["outputs"].append((var.getname(), var_type["value"].getname(), "none")) |
|
474 elif var_type["name"] in ["string", "wstring"]: |
|
475 block_infos["inputs"].append((var.getname(), var_type["name"].upper(), "none")) |
|
476 block_infos["outputs"].append((var.getname(), var_type["name"].upper(), "none")) |
|
477 else: |
|
478 block_infos["inputs"].append((var.getname(), var_type["name"], "none")) |
|
479 block_infos["outputs"].append((var.getname(), var_type["name"], "none")) |
|
480 elif type == "Input": |
|
481 for var in varlist.getvariable(): |
|
482 var_type = var.type.getcontent() |
|
483 if var_type["name"] == "derived": |
|
484 block_infos["inputs"].append((var.getname(), var_type["value"].getname(), "none")) |
|
485 elif var_type["name"] in ["string", "wstring"]: |
|
486 block_infos["inputs"].append((var.getname(), var_type["name"].upper(), "none")) |
|
487 else: |
|
488 block_infos["inputs"].append((var.getname(), var_type["name"], "none")) |
|
489 elif type == "Output": |
|
490 for var in varlist.getvariable(): |
|
491 var_type = var.type.getcontent() |
|
492 if var_type["name"] == "derived": |
|
493 block_infos["outputs"].append((var.getname(), var_type["value"].getname(), "none")) |
|
494 elif var_type["name"] in ["string", "wstring"]: |
|
495 block_infos["outputs"].append((var.getname(), var_type["name"].upper(), "none")) |
|
496 else: |
|
497 block_infos["outputs"].append((var.getname(), var_type["name"], "none")) |
|
498 block_infos["usage"] = "\n (%s) => (%s)" % (", ".join(["%s:%s" % (input[1], input[0]) for input in block_infos["inputs"]]), |
|
499 ", ".join(["%s:%s" % (output[1], output[0]) for output in block_infos["outputs"]])) |
|
500 self.CustomBlockTypes[pou_name]=block_infos |
|
501 setattr(cls, "AddCustomBlockType", AddCustomBlockType) |
|
502 |
|
503 def AddElementUsingTreeInstance(self, name, type_infos): |
|
504 typename = type_infos.getname() |
|
505 elements = self.ElementUsingTree.setdefault(typename, set()) |
|
506 elements.add(name) |
|
507 setattr(cls, "AddElementUsingTreeInstance", AddElementUsingTreeInstance) |
|
508 |
|
509 def RefreshElementUsingTree(self): |
|
510 # Reset the tree of user-defined element cross-use |
|
511 self.ElementUsingTree = {} |
|
512 pous = self.getpous() |
|
513 datatypes = self.getdataTypes() |
|
514 # Analyze each datatype |
|
515 for datatype in datatypes: |
|
516 name = datatype.getname() |
|
517 basetype_content = datatype.baseType.getcontent() |
|
518 if basetype_content["name"] == "derived": |
|
519 self.AddElementUsingTreeInstance(name, |
|
520 basetype_content["value"]) |
|
521 elif basetype_content["name"] in ["subrangeSigned", "subrangeUnsigned", "array"]: |
|
522 base_type = basetype_content["value"].baseType.getcontent() |
|
523 if base_type["name"] == "derived": |
|
524 self.AddElementUsingTreeInstance(name, base_type["value"]) |
|
525 elif basetype_content["name"] == "struct": |
|
526 for element in basetype_content["value"].getvariable(): |
|
527 type_content = element.type.getcontent() |
|
528 if type_content["name"] == "derived": |
|
529 self.AddElementUsingTreeInstance(name, type_content["value"]) |
|
530 # Analyze each pou |
|
531 for pou in pous: |
|
532 name = pou.getname() |
|
533 if pou.interface: |
|
534 # Extract variables from every varLists |
|
535 for type, varlist in pou.getvars(): |
|
536 for var in varlist.getvariable(): |
|
537 vartype_content = var.gettype().getcontent() |
|
538 if vartype_content["name"] == "derived": |
|
539 self.AddElementUsingTreeInstance(name, vartype_content["value"]) |
|
540 |
|
541 setattr(cls, "RefreshElementUsingTree", RefreshElementUsingTree) |
|
542 |
|
543 def GetParentType(self, type): |
|
544 if self.CustomTypeHierarchy.has_key(type): |
|
545 return self.CustomTypeHierarchy[type] |
|
546 elif TypeHierarchy.has_key(type): |
|
547 return TypeHierarchy[type] |
|
548 return None |
|
549 setattr(cls, "GetParentType", GetParentType) |
|
550 |
|
551 def GetBaseType(self, type): |
|
552 parent_type = self.GetParentType(type) |
|
553 if parent_type is not None: |
|
554 if parent_type.startswith("ANY"): |
|
555 return type |
|
556 else: |
|
557 return self.GetBaseType(parent_type) |
|
558 return None |
|
559 setattr(cls, "GetBaseType", GetBaseType) |
|
560 |
|
561 def GetSubrangeBaseTypes(self, exclude): |
|
562 derived = [] |
|
563 for type in self.CustomTypeHierarchy.keys(): |
|
564 for base_type in DataTypeRange.keys(): |
|
565 if self.IsOfType(type, base_type) and not self.IsOfType(type, exclude): |
|
566 derived.append(type) |
|
567 break |
|
568 return derived |
|
569 setattr(cls, "GetSubrangeBaseTypes", GetSubrangeBaseTypes) |
|
570 |
|
571 """ |
|
572 returns true if the given data type is the same that "reference" meta-type or one of its types. |
|
573 """ |
|
574 def IsOfType(self, type, reference): |
|
575 if reference is None: |
|
576 return True |
|
577 elif type == reference: |
|
578 return True |
|
579 else: |
|
580 parent_type = self.GetParentType(type) |
|
581 if parent_type is not None: |
|
582 return self.IsOfType(parent_type, reference) |
|
583 return False |
|
584 setattr(cls, "IsOfType", IsOfType) |
|
585 |
|
586 # Return if pou given by name is used by another pou |
|
587 def ElementIsUsed(self, name): |
|
588 elements = self.ElementUsingTree.get(name, None) |
|
589 return elements is not None |
|
590 setattr(cls, "ElementIsUsed", ElementIsUsed) |
|
591 |
|
592 def DataTypeIsDerived(self, name): |
|
593 return name in self.CustomTypeHierarchy.values() |
|
594 setattr(cls, "DataTypeIsDerived", DataTypeIsDerived) |
|
595 |
|
596 # Return if pou given by name is directly or undirectly used by the reference pou |
|
597 def ElementIsUsedBy(self, name, reference): |
|
598 elements = self.ElementUsingTree.get(name, set()) |
|
599 # Test if pou is directly used by reference |
|
600 if reference in elements: |
|
601 return True |
|
602 else: |
|
603 # Test if pou is undirectly used by reference, by testing if pous |
|
604 # that directly use pou is directly or undirectly used by reference |
|
605 selffn = self.ElementIsUsedBy |
|
606 for element in elements: |
|
607 if selffn(element, reference): |
|
608 return True |
|
609 return False |
|
610 setattr(cls, "ElementIsUsedBy", ElementIsUsedBy) |
|
611 |
|
612 def GetDataTypeRange(self, type): |
|
613 if self.CustomDataTypeRange.has_key(type): |
|
614 return self.CustomDataTypeRange[type] |
|
615 elif DataTypeRange.has_key(type): |
|
616 return DataTypeRange[type] |
|
617 else: |
|
618 parent_type = self.GetParentType(type) |
|
619 if parent_type is not None: |
|
620 return self.GetDataTypeRange(parent_type) |
|
621 return None |
|
622 setattr(cls, "GetDataTypeRange", GetDataTypeRange) |
|
623 |
|
624 def GetEnumeratedDataTypeValues(self, type = None): |
|
625 if type is None: |
|
626 all_values = [] |
|
627 for values in self.EnumeratedDataTypeValues.values(): |
|
628 all_values.extend(values) |
|
629 return all_values |
|
630 elif self.EnumeratedDataTypeValues.has_key(type): |
|
631 return self.EnumeratedDataTypeValues[type] |
|
632 return [] |
|
633 setattr(cls, "GetEnumeratedDataTypeValues", GetEnumeratedDataTypeValues) |
464 setattr(cls, "GetEnumeratedDataTypeValues", GetEnumeratedDataTypeValues) |
634 |
|
635 # Function that returns the block definition associated to the block type given |
|
636 def GetCustomBlockType(self, typename, inputs = None): |
|
637 customblocktype = self.CustomBlockTypes.get(typename,None) |
|
638 if customblocktype is not None: |
|
639 if inputs is not None and inputs != "undefined": |
|
640 customblock_inputs = tuple([var_type for name, var_type, modifier in customblocktype["inputs"]]) |
|
641 if inputs == customblock_inputs: |
|
642 return customblocktype |
|
643 else: |
|
644 return customblocktype |
|
645 return None |
|
646 setattr(cls, "GetCustomBlockType", GetCustomBlockType) |
|
647 |
|
648 # Return Block types checking for recursion |
|
649 def GetCustomBlockTypes(self, exclude = None, onlyfunctions = False): |
|
650 if exclude is not None: |
|
651 return [customblocktype for name,customblocktype in self.CustomBlockTypes.iteritems() |
|
652 if (customblocktype["type"] != "program" |
|
653 and name != exclude |
|
654 and not self.ElementIsUsedBy(exclude, name) |
|
655 and not (onlyfunctions and customblocktype["type"] != "function"))] |
|
656 return [customblocktype for customblocktype in self.CustomBlockTypes.itervalues() |
|
657 if (customblocktype["type"] != "program" |
|
658 and not (onlyfunctions and customblocktype["type"] != "function"))] |
|
659 setattr(cls, "GetCustomBlockTypes", GetCustomBlockTypes) |
|
660 |
|
661 # Return Function Block types checking for recursion |
|
662 def GetCustomFunctionBlockTypes(self, exclude = None): |
|
663 if exclude is not None: |
|
664 return [customblocktype for name,customblocktype in self.CustomBlockTypes.iteritems() |
|
665 if (customblocktype["type"] == "functionBlock" |
|
666 and name != exclude |
|
667 and not self.ElementIsUsedBy(exclude, name))] |
|
668 return [customblocktype for customblocktype in self.CustomBlockTypes.itervalues() |
|
669 if customblocktype["type"] == "functionBlock"] |
|
670 setattr(cls, "GetCustomFunctionBlockTypes", GetCustomFunctionBlockTypes) |
|
671 |
|
672 # Return Block types checking for recursion |
|
673 def GetCustomBlockResource(self): |
|
674 return [customblocktype["name"] for customblocktype in self.CustomBlockTypes.itervalues() |
|
675 if customblocktype["type"] == "program"] |
|
676 setattr(cls, "GetCustomBlockResource", GetCustomBlockResource) |
|
677 |
|
678 # Return Data Types checking for recursion |
|
679 def GetCustomDataTypes(self, exclude = "", only_locatable = False): |
|
680 customdatatypes = [] |
|
681 for customdatatype in self.getdataTypes(): |
|
682 if not only_locatable or self.IsLocatableType(customdatatype): |
|
683 customdatatype_name = customdatatype.getname() |
|
684 if customdatatype_name != exclude and not self.ElementIsUsedBy(exclude, customdatatype_name): |
|
685 customdatatypes.append({"name": customdatatype_name, "infos": customdatatype}) |
|
686 return customdatatypes |
|
687 setattr(cls, "GetCustomDataTypes", GetCustomDataTypes) |
|
688 |
|
689 # Return if Data Type can be used for located variables |
|
690 def IsLocatableType(self, datatype): |
|
691 basetype_content = datatype.baseType.getcontent() |
|
692 if basetype_content["name"] in ["enum", "struct"]: |
|
693 return False |
|
694 elif basetype_content["name"] == "derived": |
|
695 base_type = self.getdataType(basetype_content["value"].getname()) |
|
696 if base_type is not None: |
|
697 return self.IsLocatableType(base_type) |
|
698 elif basetype_content["name"] == "array": |
|
699 array_base_type = basetype_content["value"].baseType.getcontent() |
|
700 if array_base_type["value"] is not None and array_base_type["name"] not in ["string", "wstring"]: |
|
701 base_type = self.getdataType(array_base_type["value"].getname()) |
|
702 if base_type is not None: |
|
703 return self.IsLocatableType(base_type) |
|
704 return True |
|
705 setattr(cls, "IsLocatableType", IsLocatableType) |
|
706 |
465 |
707 def Search(self, criteria, parent_infos=[]): |
466 def Search(self, criteria, parent_infos=[]): |
708 result = self.types.Search(criteria, parent_infos) |
467 result = self.types.Search(criteria, parent_infos) |
709 for configuration in self.instances.configurations.getconfiguration(): |
468 for configuration in self.instances.configurations.getconfiguration(): |
710 result.extend(configuration.Search(criteria, parent_infos)) |
469 result.extend(configuration.Search(criteria, parent_infos)) |
711 return result |
470 return result |
712 setattr(cls, "Search", Search) |
471 setattr(cls, "Search", Search) |
713 |
472 |
714 cls = PLCOpenClasses.get("project_fileHeader", None) |
473 cls = PLCOpenParser.GetElementClass("contentHeader", "project") |
715 if cls: |
474 if cls: |
716 cls.singleLineAttributes = False |
|
717 |
|
718 cls = PLCOpenClasses.get("project_contentHeader", None) |
|
719 if cls: |
|
720 cls.singleLineAttributes = False |
|
721 |
475 |
722 def setpageSize(self, width, height): |
476 def setpageSize(self, width, height): |
723 self.coordinateInfo.setpageSize(width, height) |
477 self.coordinateInfo.setpageSize(width, height) |
724 setattr(cls, "setpageSize", setpageSize) |
478 setattr(cls, "setpageSize", setpageSize) |
725 |
479 |
1324 if self.interface is not None: |
1123 if self.interface is not None: |
1325 reverse_types = {} |
1124 reverse_types = {} |
1326 for name, value in VarTypes.items(): |
1125 for name, value in VarTypes.items(): |
1327 reverse_types[value] = name |
1126 reverse_types[value] = name |
1328 for varlist in self.interface.getcontent(): |
1127 for varlist in self.interface.getcontent(): |
1329 vars.append((reverse_types[varlist["name"]], varlist["value"])) |
1128 vars.append((reverse_types[varlist.getLocalTag()], varlist)) |
1330 return vars |
1129 return vars |
1331 setattr(cls, "getvars", getvars) |
1130 setattr(cls, "getvars", getvars) |
1332 |
1131 |
1333 def setvars(self, vars): |
1132 def setvars(self, vars): |
1334 if self.interface is None: |
1133 if self.interface is None: |
1335 self.interface = PLCOpenClasses["pou_interface"]() |
1134 self.interface = PLCOpenParser.CreateElement("interface", "pou") |
1336 self.interface.setcontent([]) |
1135 self.interface.setcontent(vars) |
1337 for vartype, varlist in vars: |
|
1338 self.interface.appendcontent({"name" : VarTypes[vartype], "value" : varlist}) |
|
1339 setattr(cls, "setvars", setvars) |
1136 setattr(cls, "setvars", setvars) |
1340 |
1137 |
1341 def addpouLocalVar(self, type, name, location="", description=""): |
1138 def addpouLocalVar(self, var_type, name, location="", description=""): |
1342 self.addpouVar(type, name, location=location, description=description) |
1139 self.addpouVar(var_type, name, location=location, description=description) |
1343 setattr(cls, "addpouLocalVar", addpouLocalVar) |
1140 setattr(cls, "addpouLocalVar", addpouLocalVar) |
1344 |
1141 |
1345 def addpouExternalVar(self, type, name): |
1142 def addpouExternalVar(self, var_type, name): |
1346 self.addpouVar(type, name, "externalVars") |
1143 self.addpouVar(type, name, "externalVars") |
1347 setattr(cls, "addpouExternalVar", addpouExternalVar) |
1144 setattr(cls, "addpouExternalVar", addpouExternalVar) |
1348 |
1145 |
1349 def addpouVar(self, type, name, var_class="localVars", location="", description=""): |
1146 def addpouVar(self, var_type, name, var_class="localVars", location="", description=""): |
1350 if self.interface is None: |
1147 if self.interface is None: |
1351 self.interface = PLCOpenClasses["pou_interface"]() |
1148 self.interface = PLCOpenParser.CreateElement("interface", "pou") |
1352 content = self.interface.getcontent() |
1149 content = self.interface.getcontent() |
1353 if len(content) == 0 or content[-1]["name"] != var_class: |
1150 if len(content) == 0: |
1354 content.append({"name" : var_class, "value" : PLCOpenClasses["interface_%s" % var_class]()}) |
1151 varlist = PLCOpenParser.CreateElement(var_class, "interface") |
|
1152 self.interface.setcontent([varlist]) |
|
1153 elif content[-1] != var_class: |
|
1154 varlist = PLCOpenParser.CreateElement(var_class, "interface") |
|
1155 content[-1].addnext(varlist) |
1355 else: |
1156 else: |
1356 varlist = content[-1]["value"] |
1157 varlist = content[-1] |
1357 variables = varlist.getvariable() |
1158 variables = varlist.getvariable() |
1358 if varlist.getconstant() or varlist.getretain() or len(variables) > 0 and variables[0].getaddress(): |
1159 if varlist.getconstant() or varlist.getretain() or len(variables) > 0 and variables[0].getaddress(): |
1359 content.append({"name" : var_class, "value" : PLCOpenClasses["interface_%s" % var_class]()}) |
1160 varlist = PLCOpenParser.CreateElement(var_class, "interface") |
1360 var = PLCOpenClasses["varListPlain_variable"]() |
1161 content[-1].addnext(varlist) |
|
1162 var = PLCOpenParser.CreateElement("variable", "varListPlain") |
1361 var.setname(name) |
1163 var.setname(name) |
1362 var_type = PLCOpenClasses["dataType"]() |
1164 var_type_obj = PLCOpenParser.CreateElement("type", "variable") |
1363 if type in [x for x,y in TypeHierarchy_list if not x.startswith("ANY")]: |
1165 if var_type in [x for x,y in TypeHierarchy_list if not x.startswith("ANY")]: |
1364 if type == "STRING": |
1166 var_type_obj.setcontent(PLCOpenParser.CreateElement( |
1365 var_type.setcontent({"name" : "string", "value" : PLCOpenClasses["elementaryTypes_string"]()}) |
1167 var_type.lower() if var_type in ["STRING", "WSTRING"] |
1366 elif type == "WSTRING": |
1168 else var_type, "dataType")) |
1367 var_type.setcontent({"name" : "wstring", "value" : PLCOpenClasses["elementaryTypes_wstring"]()}) |
|
1368 else: |
|
1369 var_type.setcontent({"name" : type, "value" : None}) |
|
1370 else: |
1169 else: |
1371 derived_type = PLCOpenClasses["derivedTypes_derived"]() |
1170 derived_type = PLCOpenParser.CreateElement("derived", "dataType") |
1372 derived_type.setname(type) |
1171 derived_type.setname(var_type) |
1373 var_type.setcontent({"name" : "derived", "value" : derived_type}) |
1172 var_type_obj.setcontent(derived_type) |
1374 var.settype(var_type) |
1173 var.settype(var_type_obj) |
1375 if location != "": |
1174 if location != "": |
1376 var.setaddress(location) |
1175 var.setaddress(location) |
1377 if description != "": |
1176 if description != "": |
1378 ft = PLCOpenClasses["formattedText"]() |
1177 ft = PLCOpenParser.CreateElement("documentation", "variable") |
1379 ft.settext(description) |
1178 ft.setanyText(description) |
1380 var.setdocumentation(ft) |
1179 var.setdocumentation(ft) |
1381 |
1180 |
1382 content[-1]["value"].appendvariable(var) |
1181 varlist.appendvariable(var) |
1383 setattr(cls, "addpouVar", addpouVar) |
1182 setattr(cls, "addpouVar", addpouVar) |
1384 |
1183 |
1385 def changepouVar(self, old_type, old_name, new_type, new_name): |
1184 def changepouVar(self, old_type, old_name, new_type, new_name): |
1386 if self.interface is not None: |
1185 if self.interface is not None: |
1387 content = self.interface.getcontent() |
1186 content = self.interface.getcontent() |
1388 for varlist in content: |
1187 for varlist in content: |
1389 variables = varlist["value"].getvariable() |
1188 variables = varlist.getvariable() |
1390 for var in variables: |
1189 for var in variables: |
1391 if var.getname() == old_name: |
1190 if var.getname() == old_name: |
1392 vartype_content = var.gettype().getcontent() |
1191 vartype_content = var.gettype().getcontent() |
1393 if vartype_content["name"] == "derived" and vartype_content["value"].getname() == old_type: |
1192 if vartype_content.getLocalTag() == "derived" and vartype_content.getname() == old_type: |
1394 var.setname(new_name) |
1193 var.setname(new_name) |
1395 vartype_content["value"].setname(new_type) |
1194 vartype_content.setname(new_type) |
1396 return |
1195 return |
1397 setattr(cls, "changepouVar", changepouVar) |
1196 setattr(cls, "changepouVar", changepouVar) |
1398 |
1197 |
1399 def removepouVar(self, type, name): |
1198 def removepouVar(self, var_type, name): |
1400 if self.interface is not None: |
1199 if self.interface is not None: |
1401 content = self.interface.getcontent() |
1200 content = self.interface.getcontent() |
1402 for varlist in content: |
1201 for varlist in content: |
1403 variables = varlist["value"].getvariable() |
1202 for var in varlist.getvariable(): |
1404 for var in variables: |
|
1405 if var.getname() == name: |
1203 if var.getname() == name: |
1406 vartype_content = var.gettype().getcontent() |
1204 vartype_content = var.gettype().getcontent() |
1407 if vartype_content["name"] == "derived" and vartype_content["value"].getname() == type: |
1205 if vartype_content.getLocalTag() == "derived" and vartype_content.getname() == var_type: |
1408 variables.remove(var) |
1206 varlist.remove(var) |
1409 break |
1207 break |
1410 if len(varlist["value"].getvariable()) == 0: |
1208 if len(varlist.getvariable()) == 0: |
1411 content.remove(varlist) |
1209 content.remove(varlist) |
1412 break |
1210 break |
1413 setattr(cls, "removepouVar", removepouVar) |
1211 setattr(cls, "removepouVar", removepouVar) |
1414 |
1212 |
1415 def hasblock(self, name=None, block_type=None): |
1213 def hasblock(self, name=None, block_type=None): |
1416 if self.getbodyType() in ["FBD", "LD", "SFC"]: |
1214 if self.getbodyType() in ["FBD", "LD", "SFC"]: |
1417 for instance in self.getinstances(): |
1215 for instance in self.getinstances(): |
1418 if (isinstance(instance, PLCOpenClasses["fbdObjects_block"]) and |
1216 if (isinstance(instance, PLCOpenParser.GetElementClass("block", "fbdObjects")) and |
1419 (name and instance.getinstanceName() == name or |
1217 (name and instance.getinstanceName() == name or |
1420 block_type and instance.gettypeName() == block_type)): |
1218 block_type and instance.gettypeName() == block_type)): |
1421 return True |
1219 return True |
1422 if self.transitions: |
1220 if self.transitions: |
1423 for transition in self.transitions.gettransition(): |
1221 for transition in self.transitions.gettransition(): |
1764 object.__setattr__(self, "currentExecutionOrderId", self.currentExecutionOrderId + 1) |
1530 object.__setattr__(self, "currentExecutionOrderId", self.currentExecutionOrderId + 1) |
1765 return self.currentExecutionOrderId |
1531 return self.currentExecutionOrderId |
1766 setattr(cls, "getnewExecutionOrderId", getnewExecutionOrderId) |
1532 setattr(cls, "getnewExecutionOrderId", getnewExecutionOrderId) |
1767 |
1533 |
1768 def resetexecutionOrder(self): |
1534 def resetexecutionOrder(self): |
1769 if self.content["name"] == "FBD": |
1535 if self.content.getLocalTag() == "FBD": |
1770 for element in self.content["value"].getcontent(): |
1536 for element in self.content.getcontent(): |
1771 if not isinstance(element["value"], (PLCOpenClasses.get("commonObjects_comment", None), |
1537 if not isinstance(element, (PLCOpenParser.GetElementClass("comment", "commonObjects"), |
1772 PLCOpenClasses.get("commonObjects_connector", None), |
1538 PLCOpenParser.GetElementClass("connector", "commonObjects"), |
1773 PLCOpenClasses.get("commonObjects_continuation", None))): |
1539 PLCOpenParser.GetElementClass("continuation", "commonObjects"))): |
1774 element["value"].setexecutionOrderId(0) |
1540 element.setexecutionOrderId(0) |
1775 else: |
1541 else: |
1776 raise TypeError, _("Can only generate execution order on FBD networks!") |
1542 raise TypeError, _("Can only generate execution order on FBD networks!") |
1777 setattr(cls, "resetexecutionOrder", resetexecutionOrder) |
1543 setattr(cls, "resetexecutionOrder", resetexecutionOrder) |
1778 |
1544 |
1779 def compileexecutionOrder(self): |
1545 def compileexecutionOrder(self): |
1780 if self.content["name"] == "FBD": |
1546 if self.content.getLocalTag() == "FBD": |
1781 self.resetexecutionOrder() |
1547 self.resetexecutionOrder() |
1782 self.resetcurrentExecutionOrderId() |
1548 self.resetcurrentExecutionOrderId() |
1783 for element in self.content["value"].getcontent(): |
1549 for element in self.content.getcontent(): |
1784 if isinstance(element["value"], PLCOpenClasses.get("fbdObjects_outVariable", None)) and element["value"].getexecutionOrderId() == 0: |
1550 if isinstance(element, PLCOpenParser.GetElementClass("outVariable", "fbdObjects")) and element.getexecutionOrderId() == 0: |
1785 connections = element["value"].connectionPointIn.getconnections() |
1551 connections = element.connectionPointIn.getconnections() |
1786 if connections and len(connections) == 1: |
1552 if connections and len(connections) == 1: |
1787 self.compileelementExecutionOrder(connections[0]) |
1553 self.compileelementExecutionOrder(connections[0]) |
1788 element["value"].setexecutionOrderId(self.getnewExecutionOrderId()) |
1554 element.setexecutionOrderId(self.getnewExecutionOrderId()) |
1789 else: |
1555 else: |
1790 raise TypeError, _("Can only generate execution order on FBD networks!") |
1556 raise TypeError, _("Can only generate execution order on FBD networks!") |
1791 setattr(cls, "compileexecutionOrder", compileexecutionOrder) |
1557 setattr(cls, "compileexecutionOrder", compileexecutionOrder) |
1792 |
1558 |
1793 def compileelementExecutionOrder(self, link): |
1559 def compileelementExecutionOrder(self, link): |
1794 if self.content["name"] == "FBD": |
1560 if self.content.getLocalTag() == "FBD": |
1795 localid = link.getrefLocalId() |
1561 localid = link.getrefLocalId() |
1796 instance = self.getcontentInstance(localid) |
1562 instance = self.getcontentInstance(localid) |
1797 if isinstance(instance, PLCOpenClasses.get("fbdObjects_block", None)) and instance.getexecutionOrderId() == 0: |
1563 if isinstance(instance, PLCOpenParser.GetElementClass("block", "fbdObjects")) and instance.getexecutionOrderId() == 0: |
1798 for variable in instance.inputVariables.getvariable(): |
1564 for variable in instance.inputVariables.getvariable(): |
1799 connections = variable.connectionPointIn.getconnections() |
1565 connections = variable.connectionPointIn.getconnections() |
1800 if connections and len(connections) == 1: |
1566 if connections and len(connections) == 1: |
1801 self.compileelementExecutionOrder(connections[0]) |
1567 self.compileelementExecutionOrder(connections[0]) |
1802 instance.setexecutionOrderId(self.getnewExecutionOrderId()) |
1568 instance.setexecutionOrderId(self.getnewExecutionOrderId()) |
1803 elif isinstance(instance, PLCOpenClasses.get("commonObjects_continuation", None)) and instance.getexecutionOrderId() == 0: |
1569 elif isinstance(instance, PLCOpenParser.GetElementClass("continuation", "commonObjects")) and instance.getexecutionOrderId() == 0: |
1804 name = instance.getname() |
1570 name = instance.getname() |
1805 for tmp_instance in self.getcontentInstances(): |
1571 for tmp_instance in self.getcontentInstances(): |
1806 if isinstance(tmp_instance, PLCOpenClasses.get("commonObjects_connector", None)) and tmp_instance.getname() == name and tmp_instance.getexecutionOrderId() == 0: |
1572 if isinstance(tmp_instance, PLCOpenParser.GetElementClass("connector", "commonObjects")) and tmp_instance.getname() == name and tmp_instance.getexecutionOrderId() == 0: |
1807 connections = tmp_instance.connectionPointIn.getconnections() |
1573 connections = tmp_instance.connectionPointIn.getconnections() |
1808 if connections and len(connections) == 1: |
1574 if connections and len(connections) == 1: |
1809 self.compileelementExecutionOrder(connections[0]) |
1575 self.compileelementExecutionOrder(connections[0]) |
1810 else: |
1576 else: |
1811 raise TypeError, _("Can only generate execution order on FBD networks!") |
1577 raise TypeError, _("Can only generate execution order on FBD networks!") |
1812 setattr(cls, "compileelementExecutionOrder", compileelementExecutionOrder) |
1578 setattr(cls, "compileelementExecutionOrder", compileelementExecutionOrder) |
1813 |
1579 |
1814 def setelementExecutionOrder(self, instance, new_executionOrder): |
1580 def setelementExecutionOrder(self, instance, new_executionOrder): |
1815 if self.content["name"] == "FBD": |
1581 if self.content.getLocalTag() == "FBD": |
1816 old_executionOrder = instance.getexecutionOrderId() |
1582 old_executionOrder = instance.getexecutionOrderId() |
1817 if old_executionOrder is not None and old_executionOrder != 0 and new_executionOrder != 0: |
1583 if old_executionOrder is not None and old_executionOrder != 0 and new_executionOrder != 0: |
1818 for element in self.content["value"].getcontent(): |
1584 for element in self.content.getcontent(): |
1819 if element["value"] != instance and not isinstance(element["value"], PLCOpenClasses.get("commonObjects_comment", None)): |
1585 if element != instance and not isinstance(element, PLCOpenParser.GetElementClass("comment", "commonObjects")): |
1820 element_executionOrder = element["value"].getexecutionOrderId() |
1586 element_executionOrder = element.getexecutionOrderId() |
1821 if old_executionOrder <= element_executionOrder <= new_executionOrder: |
1587 if old_executionOrder <= element_executionOrder <= new_executionOrder: |
1822 element["value"].setexecutionOrderId(element_executionOrder - 1) |
1588 element.setexecutionOrderId(element_executionOrder - 1) |
1823 if new_executionOrder <= element_executionOrder <= old_executionOrder: |
1589 if new_executionOrder <= element_executionOrder <= old_executionOrder: |
1824 element["value"].setexecutionOrderId(element_executionOrder + 1) |
1590 element.setexecutionOrderId(element_executionOrder + 1) |
1825 instance.setexecutionOrderId(new_executionOrder) |
1591 instance.setexecutionOrderId(new_executionOrder) |
1826 else: |
1592 else: |
1827 raise TypeError, _("Can only generate execution order on FBD networks!") |
1593 raise TypeError, _("Can only generate execution order on FBD networks!") |
1828 setattr(cls, "setelementExecutionOrder", setelementExecutionOrder) |
1594 setattr(cls, "setelementExecutionOrder", setelementExecutionOrder) |
1829 |
1595 |
1830 def appendcontentInstance(self, name, instance): |
1596 def appendcontentInstance(self, instance): |
1831 if self.content["name"] in ["LD","FBD","SFC"]: |
1597 if self.content.getLocalTag() in ["LD","FBD","SFC"]: |
1832 element = {"name" : name, "value" : instance} |
1598 self.content.appendcontent(instance) |
1833 self.content["value"].appendcontent(element) |
|
1834 self.instances_dict[instance.getlocalId()] = element |
|
1835 else: |
1599 else: |
1836 raise TypeError, _("%s body don't have instances!")%self.content["name"] |
1600 raise TypeError, _("%s body don't have instances!")%self.content.getLocalTag() |
1837 setattr(cls, "appendcontentInstance", appendcontentInstance) |
1601 setattr(cls, "appendcontentInstance", appendcontentInstance) |
1838 |
1602 |
1839 def getcontentInstances(self): |
1603 def getcontentInstances(self): |
1840 if self.content["name"] in ["LD","FBD","SFC"]: |
1604 if self.content.getLocalTag() in ["LD","FBD","SFC"]: |
1841 instances = [] |
1605 return self.content.getcontent() |
1842 for element in self.content["value"].getcontent(): |
|
1843 instances.append(element["value"]) |
|
1844 return instances |
|
1845 else: |
1606 else: |
1846 raise TypeError, _("%s body don't have instances!")%self.content["name"] |
1607 raise TypeError, _("%s body don't have instances!")%self.content.getLocalTag() |
1847 setattr(cls, "getcontentInstances", getcontentInstances) |
1608 setattr(cls, "getcontentInstances", getcontentInstances) |
1848 |
1609 |
1849 def getcontentInstance(self, id): |
1610 instance_by_id_xpath = PLCOpen_XPath("*[@localId=$localId]") |
1850 if self.content["name"] in ["LD","FBD","SFC"]: |
1611 instance_by_name_xpath = PLCOpen_XPath("ppx:block[@instanceName=$name]") |
1851 instance = self.instances_dict.get(id, None) |
1612 def getcontentInstance(self, local_id): |
1852 if instance is not None: |
1613 if self.content.getLocalTag() in ["LD","FBD","SFC"]: |
1853 return instance["value"] |
1614 instance = instance_by_id_xpath(self.content, localId=local_id) |
|
1615 if len(instance) > 0: |
|
1616 return instance[0] |
1854 return None |
1617 return None |
1855 else: |
1618 else: |
1856 raise TypeError, _("%s body don't have instances!")%self.content["name"] |
1619 raise TypeError, _("%s body don't have instances!")%self.content.getLocalTag() |
1857 setattr(cls, "getcontentInstance", getcontentInstance) |
1620 setattr(cls, "getcontentInstance", getcontentInstance) |
1858 |
1621 |
1859 def getcontentRandomInstance(self, exclude): |
1622 def getcontentRandomInstance(self, exclude): |
1860 if self.content["name"] in ["LD","FBD","SFC"]: |
1623 if self.content.getLocalTag() in ["LD","FBD","SFC"]: |
1861 ids = self.instances_dict.viewkeys() - exclude |
1624 instance = self.content.xpath("*%s[position()=1]" % |
1862 if len(ids) > 0: |
1625 ("[not(%s)]" % " or ".join( |
1863 return self.instances_dict[ids.pop()]["value"] |
1626 map(lambda x: "@localId=%d" % x, exclude)) |
|
1627 if len(exclude) > 0 else "")) |
|
1628 if len(instance) > 0: |
|
1629 return instance[0] |
1864 return None |
1630 return None |
1865 else: |
1631 else: |
1866 raise TypeError, _("%s body don't have instances!")%self.content["name"] |
1632 raise TypeError, _("%s body don't have instances!")%self.content.getLocalTag() |
1867 setattr(cls, "getcontentRandomInstance", getcontentRandomInstance) |
1633 setattr(cls, "getcontentRandomInstance", getcontentRandomInstance) |
1868 |
1634 |
1869 def getcontentInstanceByName(self, name): |
1635 def getcontentInstanceByName(self, name): |
1870 if self.content["name"] in ["LD","FBD","SFC"]: |
1636 if self.content.getLocalTag() in ["LD","FBD","SFC"]: |
1871 for element in self.content["value"].getcontent(): |
1637 instance = instance_by_name_xpath(self.content) |
1872 if isinstance(element["value"], PLCOpenClasses.get("fbdObjects_block", None)) and element["value"].getinstanceName() == name: |
1638 if len(instance) > 0: |
1873 return element["value"] |
1639 return instance[0] |
|
1640 return None |
1874 else: |
1641 else: |
1875 raise TypeError, _("%s body don't have instances!")%self.content["name"] |
1642 raise TypeError, _("%s body don't have instances!")%self.content.getLocalTag() |
1876 setattr(cls, "getcontentInstanceByName", getcontentInstanceByName) |
1643 setattr(cls, "getcontentInstanceByName", getcontentInstanceByName) |
1877 |
1644 |
1878 def removecontentInstance(self, id): |
1645 def removecontentInstance(self, local_id): |
1879 if self.content["name"] in ["LD","FBD","SFC"]: |
1646 if self.content.getLocalTag() in ["LD","FBD","SFC"]: |
1880 element = self.instances_dict.pop(id, None) |
1647 instance = instance_by_id_xpath(self.content) |
1881 if element is not None: |
1648 if len(instance) > 0: |
1882 self.content["value"].getcontent().remove(element) |
1649 self.content.remove(instance[0]) |
1883 else: |
1650 else: |
1884 raise ValueError, _("Instance with id %d doesn't exist!")%id |
1651 raise ValueError, _("Instance with id %d doesn't exist!")%id |
1885 else: |
1652 else: |
1886 raise TypeError, "%s body don't have instances!"%self.content["name"] |
1653 raise TypeError, "%s body don't have instances!"%self.content.getLocalTag() |
1887 setattr(cls, "removecontentInstance", removecontentInstance) |
1654 setattr(cls, "removecontentInstance", removecontentInstance) |
1888 |
1655 |
1889 def settext(self, text): |
1656 def settext(self, text): |
1890 if self.content["name"] in ["IL","ST"]: |
1657 if self.content.getLocalTag() in ["IL","ST"]: |
1891 self.content["value"].settext(text) |
1658 self.content.setanyText(text) |
1892 else: |
1659 else: |
1893 raise TypeError, _("%s body don't have text!")%self.content["name"] |
1660 raise TypeError, _("%s body don't have text!")%self.content.getLocalTag() |
1894 setattr(cls, "settext", settext) |
1661 setattr(cls, "settext", settext) |
1895 |
1662 |
1896 def gettext(self): |
1663 def gettext(self): |
1897 if self.content["name"] in ["IL","ST"]: |
1664 if self.content.getLocalTag() in ["IL","ST"]: |
1898 return self.content["value"].gettext() |
1665 return self.content.getanyText() |
1899 else: |
1666 else: |
1900 raise TypeError, _("%s body don't have text!")%self.content["name"] |
1667 raise TypeError, _("%s body don't have text!")%self.content.getLocalTag() |
1901 setattr(cls, "gettext", gettext) |
1668 setattr(cls, "gettext", gettext) |
1902 |
1669 |
1903 def hasblock(self, block_type): |
1670 def hasblock(self, block_type): |
1904 if self.content["name"] in ["IL","ST"]: |
1671 if self.content.getLocalTag() in ["IL","ST"]: |
1905 return self.content["value"].hasblock(block_type) |
1672 return self.content.hasblock(block_type) |
1906 else: |
1673 else: |
1907 raise TypeError, _("%s body don't have text!")%self.content["name"] |
1674 raise TypeError, _("%s body don't have text!")%self.content.getLocalTag() |
1908 setattr(cls, "hasblock", hasblock) |
1675 setattr(cls, "hasblock", hasblock) |
1909 |
1676 |
1910 def updateElementName(self, old_name, new_name): |
1677 def updateElementName(self, old_name, new_name): |
1911 if self.content["name"] in ["IL", "ST"]: |
1678 if self.content.getLocalTag() in ["IL", "ST"]: |
1912 self.content["value"].updateElementName(old_name, new_name) |
1679 self.content.updateElementName(old_name, new_name) |
1913 else: |
1680 else: |
1914 for element in self.content["value"].getcontent(): |
1681 for element in self.content.getcontent(): |
1915 element["value"].updateElementName(old_name, new_name) |
1682 element.updateElementName(old_name, new_name) |
1916 setattr(cls, "updateElementName", updateElementName) |
1683 setattr(cls, "updateElementName", updateElementName) |
1917 |
1684 |
1918 def updateElementAddress(self, address_model, new_leading): |
1685 def updateElementAddress(self, address_model, new_leading): |
1919 if self.content["name"] in ["IL", "ST"]: |
1686 if self.content.getLocalTag() in ["IL", "ST"]: |
1920 self.content["value"].updateElementAddress(address_model, new_leading) |
1687 self.content.updateElementAddress(address_model, new_leading) |
1921 else: |
1688 else: |
1922 for element in self.content["value"].getcontent(): |
1689 for element in self.content.getcontent(): |
1923 element["value"].updateElementAddress(address_model, new_leading) |
1690 element.updateElementAddress(address_model, new_leading) |
1924 setattr(cls, "updateElementAddress", updateElementAddress) |
1691 setattr(cls, "updateElementAddress", updateElementAddress) |
1925 |
1692 |
1926 def Search(self, criteria, parent_infos=[]): |
1693 def Search(self, criteria, parent_infos=[]): |
1927 if self.content["name"] in ["IL", "ST"]: |
1694 if self.content.getLocalTag() in ["IL", "ST"]: |
1928 search_result = self.content["value"].Search(criteria, parent_infos + ["body", 0]) |
1695 search_result = self.content.Search(criteria, parent_infos + ["body", 0]) |
1929 else: |
1696 else: |
1930 search_result = [] |
1697 search_result = [] |
1931 for element in self.content["value"].getcontent(): |
1698 for element in self.content.getcontent(): |
1932 search_result.extend(element["value"].Search(criteria, parent_infos)) |
1699 search_result.extend(element.Search(criteria, parent_infos)) |
1933 return search_result |
1700 return search_result |
1934 setattr(cls, "Search", Search) |
1701 setattr(cls, "Search", Search) |
1935 |
1702 |
1936 def getx(self): |
1703 def getx(self): |
1937 return self.position.getx() |
1704 return self.position.getx() |
2397 infos["inputs"].append(_getconnectioninfos(self, self.connectionPointIn, True)) |
2151 infos["inputs"].append(_getconnectioninfos(self, self.connectionPointIn, True)) |
2398 infos["outputs"].append(_getconnectioninfos(self, self.connectionPointOut)) |
2152 infos["outputs"].append(_getconnectioninfos(self, self.connectionPointOut)) |
2399 return infos |
2153 return infos |
2400 setattr(cls, "getinfos", getinfos) |
2154 setattr(cls, "getinfos", getinfos) |
2401 |
2155 |
2402 def setconditionContent(self, type, value): |
2156 def setconditionContent(self, condition_type, value): |
2403 if not self.condition: |
2157 if self.condition is None: |
2404 self.addcondition() |
2158 self.addcondition() |
2405 if type == "reference": |
2159 if condition_type == "connection": |
2406 condition = PLCOpenClasses["condition_reference"]() |
2160 condition = PLCOpenParser.CreateElement("connectionPointIn", "condition") |
|
2161 else: |
|
2162 condition = PLCOpenParser.CreateElement(condition_type, "condition") |
|
2163 self.condition.setcontent(condition) |
|
2164 if condition_type == "reference": |
2407 condition.setname(value) |
2165 condition.setname(value) |
2408 elif type == "inline": |
2166 elif condition_type == "inline": |
2409 condition = PLCOpenClasses["condition_inline"]() |
2167 condition.setcontent(PLCOpenParser.CreateElement("ST", "inline")) |
2410 condition.setcontent({"name" : "ST", "value" : PLCOpenClasses["formattedText"]()}) |
|
2411 condition.settext(value) |
2168 condition.settext(value) |
2412 elif type == "connection": |
|
2413 type = "connectionPointIn" |
|
2414 condition = PLCOpenClasses["connectionPointIn"]() |
|
2415 self.condition.setcontent({"name" : type, "value" : condition}) |
|
2416 setattr(cls, "setconditionContent", setconditionContent) |
2169 setattr(cls, "setconditionContent", setconditionContent) |
2417 |
2170 |
2418 def getconditionContent(self): |
2171 def getconditionContent(self): |
2419 if self.condition: |
2172 if self.condition is not None: |
2420 content = self.condition.getcontent() |
2173 content = self.condition.getcontent() |
2421 values = {"type" : content["name"]} |
2174 values = {"type" : content.getLocalTag()} |
2422 if values["type"] == "reference": |
2175 if values["type"] == "reference": |
2423 values["value"] = content["value"].getname() |
2176 values["value"] = content.getname() |
2424 elif values["type"] == "inline": |
2177 elif values["type"] == "inline": |
2425 values["value"] = content["value"].gettext() |
2178 values["value"] = content.gettext() |
2426 elif values["type"] == "connectionPointIn": |
2179 elif values["type"] == "connectionPointIn": |
2427 values["type"] = "connection" |
2180 values["type"] = "connection" |
2428 values["value"] = content["value"] |
2181 values["value"] = content |
2429 return values |
2182 return values |
2430 return "" |
2183 return "" |
2431 setattr(cls, "getconditionContent", getconditionContent) |
2184 setattr(cls, "getconditionContent", getconditionContent) |
2432 |
2185 |
2433 def getconditionConnection(self): |
2186 def getconditionConnection(self): |
2434 if self.condition: |
2187 if self.condition is not None: |
2435 content = self.condition.getcontent() |
2188 content = self.condition.getcontent() |
2436 if content["name"] == "connectionPointIn": |
2189 if content.getLocalTag() == "connectionPointIn": |
2437 return content["value"] |
2190 return content |
2438 return None |
2191 return None |
2439 setattr(cls, "getconditionConnection", getconditionConnection) |
2192 setattr(cls, "getconditionConnection", getconditionConnection) |
2440 |
2193 |
2441 def getBoundingBox(self): |
2194 def getBoundingBox(self): |
2442 bbox = _getBoundingBoxSingle(self) |
2195 bbox = _getBoundingBoxSingle(self) |
2443 condition_connection = self.getconditionConnection() |
2196 condition_connection = self.getconditionConnection() |
2444 if condition_connection: |
2197 if condition_connection is not None: |
2445 bbox.union(_getConnectionsBoundingBox(condition_connection)) |
2198 bbox.union(_getConnectionsBoundingBox(condition_connection)) |
2446 return bbox |
2199 return bbox |
2447 setattr(cls, "getBoundingBox", getBoundingBox) |
2200 setattr(cls, "getBoundingBox", getBoundingBox) |
2448 |
2201 |
2449 def translate(self, dx, dy): |
2202 def translate(self, dx, dy): |
2450 _translateSingle(self, dx, dy) |
2203 _translateSingle(self, dx, dy) |
2451 condition_connection = self.getconditionConnection() |
2204 condition_connection = self.getconditionConnection() |
2452 if condition_connection: |
2205 if condition_connection is not None: |
2453 _translateConnections(condition_connection, dx, dy) |
2206 _translateConnections(condition_connection, dx, dy) |
2454 setattr(cls, "translate", translate) |
2207 setattr(cls, "translate", translate) |
2455 |
2208 |
2456 def filterConnections(self, connections): |
2209 def filterConnections(self, connections): |
2457 _filterConnectionsSingle(self, connections) |
2210 _filterConnectionsSingle(self, connections) |
2458 condition_connection = self.getconditionConnection() |
2211 condition_connection = self.getconditionConnection() |
2459 if condition_connection: |
2212 if condition_connection is not None: |
2460 _filterConnections(condition_connection, self.localId, connections) |
2213 _filterConnections(condition_connection, self.localId, connections) |
2461 setattr(cls, "filterConnections", filterConnections) |
2214 setattr(cls, "filterConnections", filterConnections) |
2462 |
2215 |
2463 def updateConnectionsId(self, translation): |
2216 def updateConnectionsId(self, translation): |
2464 connections_end = [] |
2217 connections_end = [] |
2465 if self.connectionPointIn is not None: |
2218 if self.connectionPointIn is not None: |
2466 connections_end = _updateConnectionsId(self.connectionPointIn, translation) |
2219 connections_end = _updateConnectionsId(self.connectionPointIn, translation) |
2467 condition_connection = self.getconditionConnection() |
2220 condition_connection = self.getconditionConnection() |
2468 if condition_connection: |
2221 if condition_connection is not None: |
2469 connections_end.extend(_updateConnectionsId(condition_connection, translation)) |
2222 connections_end.extend(_updateConnectionsId(condition_connection, translation)) |
2470 return _getconnectionsdefinition(self, connections_end) |
2223 return _getconnectionsdefinition(self, connections_end) |
2471 setattr(cls, "updateConnectionsId", updateConnectionsId) |
2224 setattr(cls, "updateConnectionsId", updateConnectionsId) |
2472 |
2225 |
2473 def updateElementName(self, old_name, new_name): |
2226 def updateElementName(self, old_name, new_name): |
2474 if self.condition: |
2227 if self.condition is not None: |
2475 content = self.condition.getcontent() |
2228 content = self.condition.getcontent() |
2476 if content["name"] == "reference": |
2229 content_name = content.getLocalTag() |
2477 if content["value"].getname() == old_name: |
2230 if content_name == "reference": |
2478 content["value"].setname(new_name) |
2231 if content.getname() == old_name: |
2479 elif content["name"] == "inline": |
2232 content.setname(new_name) |
2480 content["value"].updateElementName(old_name, new_name) |
2233 elif content_name == "inline": |
|
2234 content.updateElementName(old_name, new_name) |
2481 setattr(cls, "updateElementName", updateElementName) |
2235 setattr(cls, "updateElementName", updateElementName) |
2482 |
2236 |
2483 def updateElementAddress(self, address_model, new_leading): |
2237 def updateElementAddress(self, address_model, new_leading): |
2484 if self.condition: |
2238 if self.condition is not None: |
2485 content = self.condition.getcontent() |
2239 content = self.condition.getcontent() |
2486 if content["name"] == "reference": |
2240 content_name = content.getLocalTag() |
2487 content["value"].setname(update_address(content["value"].getname(), address_model, new_leading)) |
2241 if content_name == "reference": |
2488 elif content["name"] == "inline": |
2242 content.setname(update_address(content.getname(), address_model, new_leading)) |
2489 content["value"].updateElementAddress(address_model, new_leading) |
2243 elif content_name == "inline": |
|
2244 content.updateElementAddress(address_model, new_leading) |
2490 setattr(cls, "updateElementAddress", updateElementAddress) |
2245 setattr(cls, "updateElementAddress", updateElementAddress) |
2491 |
2246 |
2492 def getconnections(self): |
2247 def getconnections(self): |
2493 condition_connection = self.getconditionConnection() |
2248 condition_connection = self.getconditionConnection() |
2494 if condition_connection: |
2249 if condition_connection is not None: |
2495 return condition_connection.getconnections() |
2250 return condition_connection.getconnections() |
2496 return None |
2251 return None |
2497 setattr(cls, "getconnections", getconnections) |
2252 setattr(cls, "getconnections", getconnections) |
2498 |
2253 |
2499 def Search(self, criteria, parent_infos=[]): |
2254 def Search(self, criteria, parent_infos=[]): |
2500 parent_infos = parent_infos + ["transition", self.getlocalId()] |
2255 parent_infos = parent_infos + ["transition", self.getlocalId()] |
2501 search_result = [] |
2256 search_result = [] |
2502 content = self.condition.getcontent() |
2257 content = self.condition.getcontent() |
2503 if content["name"] == "reference": |
2258 content_name = content.getLocalTag() |
2504 search_result.extend(_Search([("reference", content["value"].getname())], criteria, parent_infos)) |
2259 if content_name == "reference": |
2505 elif content["name"] == "inline": |
2260 search_result.extend(_Search([("reference", content.getname())], criteria, parent_infos)) |
2506 search_result.extend(content["value"].Search(criteria, parent_infos + ["inline"])) |
2261 elif content_name == "inline": |
|
2262 search_result.extend(content.Search(criteria, parent_infos + ["inline"])) |
2507 return search_result |
2263 return search_result |
2508 setattr(cls, "Search", Search) |
2264 setattr(cls, "Search", Search) |
2509 |
2265 |
2510 cls = _initElementClass("selectionDivergence", "sfcObjects_selectionDivergence", "single") |
2266 cls = _initElementClass("selectionDivergence", "sfcObjects", "single") |
2511 if cls: |
2267 if cls: |
2512 setattr(cls, "getinfos", _getdivergenceinfosFunction(True, False)) |
2268 setattr(cls, "getinfos", _getdivergenceinfosFunction(True, False)) |
2513 |
2269 |
2514 cls = _initElementClass("selectionConvergence", "sfcObjects_selectionConvergence", "multiple") |
2270 cls = _initElementClass("selectionConvergence", "sfcObjects", "multiple") |
2515 if cls: |
2271 if cls: |
2516 setattr(cls, "getinfos", _getdivergenceinfosFunction(False, False)) |
2272 setattr(cls, "getinfos", _getdivergenceinfosFunction(False, False)) |
2517 |
2273 |
2518 cls = _initElementClass("simultaneousDivergence", "sfcObjects_simultaneousDivergence", "single") |
2274 cls = _initElementClass("simultaneousDivergence", "sfcObjects", "single") |
2519 if cls: |
2275 if cls: |
2520 setattr(cls, "getinfos", _getdivergenceinfosFunction(True, True)) |
2276 setattr(cls, "getinfos", _getdivergenceinfosFunction(True, True)) |
2521 |
2277 |
2522 cls = _initElementClass("simultaneousConvergence", "sfcObjects_simultaneousConvergence", "multiple") |
2278 cls = _initElementClass("simultaneousConvergence", "sfcObjects", "multiple") |
2523 if cls: |
2279 if cls: |
2524 setattr(cls, "getinfos", _getdivergenceinfosFunction(False, True)) |
2280 setattr(cls, "getinfos", _getdivergenceinfosFunction(False, True)) |
2525 |
2281 |
2526 cls = _initElementClass("jumpStep", "sfcObjects_jumpStep", "single") |
2282 cls = _initElementClass("jumpStep", "sfcObjects", "single") |
2527 if cls: |
2283 if cls: |
2528 def getinfos(self): |
2284 def getinfos(self): |
2529 infos = _getelementinfos(self) |
2285 infos = _getelementinfos(self) |
2530 infos["type"] = "jump" |
2286 infos["type"] = "jump" |
2531 infos["specific_values"]["target"] = self.gettargetName() |
2287 infos["specific_values"]["target"] = self.gettargetName() |
2673 search_result.extend(action.Search(criteria, parent_infos + ["action", idx])) |
2429 search_result.extend(action.Search(criteria, parent_infos + ["action", idx])) |
2674 return search_result |
2430 return search_result |
2675 setattr(cls, "Search", Search) |
2431 setattr(cls, "Search", Search) |
2676 |
2432 |
2677 def _SearchInIOVariable(self, criteria, parent_infos=[]): |
2433 def _SearchInIOVariable(self, criteria, parent_infos=[]): |
2678 return _Search([("expression", self.getexpression())], criteria, parent_infos + ["io_variable", self.getlocalId()]) |
2434 return _Search([("expression", self.expression.text)], criteria, parent_infos + ["io_variable", self.getlocalId()]) |
2679 |
2435 |
2680 cls = _initElementClass("inVariable", "fbdObjects_inVariable") |
2436 def _UpdateIOElementName(self, old_name, new_name): |
|
2437 if self.expression.text == old_name: |
|
2438 self.expression.text = new_name |
|
2439 |
|
2440 def _UpdateIOElementAddress(self, old_name, new_name): |
|
2441 self.expression.text = update_address(self.expression.text, address_model, new_leading) |
|
2442 |
|
2443 cls = _initElementClass("inVariable", "fbdObjects") |
2681 if cls: |
2444 if cls: |
2682 setattr(cls, "getinfos", _getvariableinfosFunction("input", False, True)) |
2445 setattr(cls, "getinfos", _getvariableinfosFunction("input", False, True)) |
2683 |
2446 setattr(cls, "updateElementName", _UpdateIOElementName) |
2684 def updateElementName(self, old_name, new_name): |
2447 setattr(cls, "updateElementAddress", _UpdateIOElementAddress) |
2685 if self.expression == old_name: |
|
2686 self.expression = new_name |
|
2687 setattr(cls, "updateElementName", updateElementName) |
|
2688 |
|
2689 def updateElementAddress(self, address_model, new_leading): |
|
2690 self.expression = update_address(self.expression, address_model, new_leading) |
|
2691 setattr(cls, "updateElementAddress", updateElementAddress) |
|
2692 |
|
2693 setattr(cls, "Search", _SearchInIOVariable) |
2448 setattr(cls, "Search", _SearchInIOVariable) |
2694 |
2449 |
2695 cls = _initElementClass("outVariable", "fbdObjects_outVariable", "single") |
2450 cls = _initElementClass("outVariable", "fbdObjects", "single") |
2696 if cls: |
2451 if cls: |
2697 setattr(cls, "getinfos", _getvariableinfosFunction("output", True, False)) |
2452 setattr(cls, "getinfos", _getvariableinfosFunction("output", True, False)) |
2698 |
2453 setattr(cls, "updateElementName", _UpdateIOElementName) |
2699 def updateElementName(self, old_name, new_name): |
2454 setattr(cls, "updateElementAddress", _UpdateIOElementAddress) |
2700 if self.expression == old_name: |
|
2701 self.expression = new_name |
|
2702 setattr(cls, "updateElementName", updateElementName) |
|
2703 |
|
2704 def updateElementAddress(self, address_model, new_leading): |
|
2705 self.expression = update_address(self.expression, address_model, new_leading) |
|
2706 setattr(cls, "updateElementAddress", updateElementAddress) |
|
2707 |
|
2708 setattr(cls, "Search", _SearchInIOVariable) |
2455 setattr(cls, "Search", _SearchInIOVariable) |
2709 |
2456 |
2710 cls = _initElementClass("inOutVariable", "fbdObjects_inOutVariable", "single") |
2457 cls = _initElementClass("inOutVariable", "fbdObjects", "single") |
2711 if cls: |
2458 if cls: |
2712 setattr(cls, "getinfos", _getvariableinfosFunction("inout", True, True)) |
2459 setattr(cls, "getinfos", _getvariableinfosFunction("inout", True, True)) |
2713 |
2460 setattr(cls, "updateElementName", _UpdateIOElementName) |
2714 def updateElementName(self, old_name, new_name): |
2461 setattr(cls, "updateElementAddress", _UpdateIOElementAddress) |
2715 if self.expression == old_name: |
|
2716 self.expression = new_name |
|
2717 setattr(cls, "updateElementName", updateElementName) |
|
2718 |
|
2719 def updateElementAddress(self, address_model, new_leading): |
|
2720 self.expression = update_address(self.expression, address_model, new_leading) |
|
2721 setattr(cls, "updateElementAddress", updateElementAddress) |
|
2722 |
|
2723 setattr(cls, "Search", _SearchInIOVariable) |
2462 setattr(cls, "Search", _SearchInIOVariable) |
2724 |
2463 |
2725 |
2464 |
2726 def _SearchInConnector(self, criteria, parent_infos=[]): |
2465 def _SearchInConnector(self, criteria, parent_infos=[]): |
2727 return _Search([("name", self.getname())], criteria, parent_infos + ["connector", self.getlocalId()]) |
2466 return _Search([("name", self.getname())], criteria, parent_infos + ["connector", self.getlocalId()]) |
2728 |
2467 |
2729 cls = _initElementClass("continuation", "commonObjects_continuation") |
2468 cls = _initElementClass("continuation", "commonObjects") |
2730 if cls: |
2469 if cls: |
2731 setattr(cls, "getinfos", _getconnectorinfosFunction("continuation")) |
2470 setattr(cls, "getinfos", _getconnectorinfosFunction("continuation")) |
2732 setattr(cls, "Search", _SearchInConnector) |
2471 setattr(cls, "Search", _SearchInConnector) |
2733 |
2472 |
2734 def updateElementName(self, old_name, new_name): |
2473 def updateElementName(self, old_name, new_name): |
2735 if self.name == old_name: |
2474 if self.name == old_name: |
2736 self.name = new_name |
2475 self.name = new_name |
2737 setattr(cls, "updateElementName", updateElementName) |
2476 setattr(cls, "updateElementName", updateElementName) |
2738 |
2477 |
2739 cls = _initElementClass("connector", "commonObjects_connector", "single") |
2478 cls = _initElementClass("connector", "commonObjects", "single") |
2740 if cls: |
2479 if cls: |
2741 setattr(cls, "getinfos", _getconnectorinfosFunction("connector")) |
2480 setattr(cls, "getinfos", _getconnectorinfosFunction("connector")) |
2742 setattr(cls, "Search", _SearchInConnector) |
2481 setattr(cls, "Search", _SearchInConnector) |
2743 |
2482 |
2744 def updateElementName(self, old_name, new_name): |
2483 def updateElementName(self, old_name, new_name): |
2745 if self.name == old_name: |
2484 if self.name == old_name: |
2746 self.name = new_name |
2485 self.name = new_name |
2747 setattr(cls, "updateElementName", updateElementName) |
2486 setattr(cls, "updateElementName", updateElementName) |
2748 |
2487 |
2749 cls = PLCOpenClasses.get("connection", None) |
2488 cls = PLCOpenParser.GetElementClass("connection") |
2750 if cls: |
2489 if cls: |
2751 def setpoints(self, points): |
2490 def setpoints(self, points): |
2752 self.position = [] |
2491 positions = [] |
2753 for point in points: |
2492 for point in points: |
2754 position = PLCOpenClasses["position"]() |
2493 position = PLCOpenParser.CreateElement("position", "connection") |
2755 position.setx(point.x) |
2494 position.setx(point.x) |
2756 position.sety(point.y) |
2495 position.sety(point.y) |
2757 self.position.append(position) |
2496 positions.append(position) |
|
2497 self.position = positions |
2758 setattr(cls, "setpoints", setpoints) |
2498 setattr(cls, "setpoints", setpoints) |
2759 |
2499 |
2760 def getpoints(self): |
2500 def getpoints(self): |
2761 points = [] |
2501 points = [] |
2762 for position in self.position: |
2502 for position in self.position: |
2763 points.append((position.getx(),position.gety())) |
2503 points.append((position.getx(),position.gety())) |
2764 return points |
2504 return points |
2765 setattr(cls, "getpoints", getpoints) |
2505 setattr(cls, "getpoints", getpoints) |
2766 |
2506 |
2767 cls = PLCOpenClasses.get("connectionPointIn", None) |
2507 cls = PLCOpenParser.GetElementClass("connectionPointIn") |
2768 if cls: |
2508 if cls: |
2769 def setrelPositionXY(self, x, y): |
2509 def setrelPositionXY(self, x, y): |
2770 self.relPosition = PLCOpenClasses["position"]() |
2510 self.relPosition = PLCOpenParser.CreateElement("relPosition", "connectionPointIn") |
2771 self.relPosition.setx(x) |
2511 self.relPosition.setx(x) |
2772 self.relPosition.sety(y) |
2512 self.relPosition.sety(y) |
2773 setattr(cls, "setrelPositionXY", setrelPositionXY) |
2513 setattr(cls, "setrelPositionXY", setrelPositionXY) |
2774 |
2514 |
2775 def getrelPositionXY(self): |
2515 def getrelPositionXY(self): |
2776 if self.relPosition: |
2516 if self.relPosition is not None: |
2777 return self.relPosition.getx(), self.relPosition.gety() |
2517 return self.relPosition.getx(), self.relPosition.gety() |
2778 else: |
2518 return self.relPosition |
2779 return self.relPosition |
|
2780 setattr(cls, "getrelPositionXY", getrelPositionXY) |
2519 setattr(cls, "getrelPositionXY", getrelPositionXY) |
2781 |
2520 |
2782 def addconnection(self): |
2521 def addconnection(self): |
2783 if not self.content: |
2522 self.append(PLCOpenParser.CreateElement("connection", "connectionPointIn")) |
2784 self.content = {"name" : "connection", "value" : [PLCOpenClasses["connection"]()]} |
|
2785 else: |
|
2786 self.content["value"].append(PLCOpenClasses["connection"]()) |
|
2787 setattr(cls, "addconnection", addconnection) |
2523 setattr(cls, "addconnection", addconnection) |
2788 |
2524 |
2789 def removeconnection(self, idx): |
2525 def removeconnection(self, idx): |
2790 if self.content: |
2526 if len(self.content) > idx: |
2791 self.content["value"].pop(idx) |
2527 self.remove(self.content[idx]) |
2792 if len(self.content["value"]) == 0: |
|
2793 self.content = None |
|
2794 setattr(cls, "removeconnection", removeconnection) |
2528 setattr(cls, "removeconnection", removeconnection) |
2795 |
2529 |
2796 def removeconnections(self): |
2530 def removeconnections(self): |
2797 if self.content: |
2531 self.content = None |
2798 self.content = None |
|
2799 setattr(cls, "removeconnections", removeconnections) |
2532 setattr(cls, "removeconnections", removeconnections) |
2800 |
2533 |
|
2534 connection_xpath = PLCOpen_XPath("ppx:connection") |
|
2535 connection_by_position_xpath = PLCOpen_XPath("ppx:connection[position()=$pos]") |
2801 def getconnections(self): |
2536 def getconnections(self): |
2802 if self.content: |
2537 return connection_xpath(self) |
2803 return self.content["value"] |
|
2804 return [] |
|
2805 setattr(cls, "getconnections", getconnections) |
2538 setattr(cls, "getconnections", getconnections) |
2806 |
2539 |
2807 def setconnectionId(self, idx, id): |
2540 def getconnection(self, idx): |
2808 if self.content: |
2541 connection = connection_by_position_xpath(self, pos=idx+1) |
2809 self.content["value"][idx].setrefLocalId(id) |
2542 if len(connection) > 0: |
|
2543 return connection[0] |
|
2544 return None |
|
2545 setattr(cls, "getconnection", getconnection) |
|
2546 |
|
2547 def setconnectionId(self, idx, local_id): |
|
2548 connection = self.getconnection(idx) |
|
2549 if connection is not None: |
|
2550 connection.setrefLocalId(local_id) |
2810 setattr(cls, "setconnectionId", setconnectionId) |
2551 setattr(cls, "setconnectionId", setconnectionId) |
2811 |
2552 |
2812 def getconnectionId(self, idx): |
2553 def getconnectionId(self, idx): |
2813 if self.content: |
2554 connection = self.getconnection(idx) |
2814 return self.content["value"][idx].getrefLocalId() |
2555 if connection is not None: |
|
2556 return connection.getrefLocalId() |
2815 return None |
2557 return None |
2816 setattr(cls, "getconnectionId", getconnectionId) |
2558 setattr(cls, "getconnectionId", getconnectionId) |
2817 |
2559 |
2818 def setconnectionPoints(self, idx, points): |
2560 def setconnectionPoints(self, idx, points): |
2819 if self.content: |
2561 connection = self.getconnection(idx) |
2820 self.content["value"][idx].setpoints(points) |
2562 if connection is not None: |
|
2563 connection.setpoints(points) |
2821 setattr(cls, "setconnectionPoints", setconnectionPoints) |
2564 setattr(cls, "setconnectionPoints", setconnectionPoints) |
2822 |
2565 |
2823 def getconnectionPoints(self, idx): |
2566 def getconnectionPoints(self, idx): |
2824 if self.content: |
2567 connection = self.getconnection(idx) |
2825 return self.content["value"][idx].getpoints() |
2568 if connection is not None: |
|
2569 return connection.getpoints() |
2826 return [] |
2570 return [] |
2827 setattr(cls, "getconnectionPoints", getconnectionPoints) |
2571 setattr(cls, "getconnectionPoints", getconnectionPoints) |
2828 |
2572 |
2829 def setconnectionParameter(self, idx, parameter): |
2573 def setconnectionParameter(self, idx, parameter): |
2830 if self.content: |
2574 connection = self.getconnection(idx) |
2831 self.content["value"][idx].setformalParameter(parameter) |
2575 if connection is not None: |
|
2576 connection.setformalParameter(parameter) |
2832 setattr(cls, "setconnectionParameter", setconnectionParameter) |
2577 setattr(cls, "setconnectionParameter", setconnectionParameter) |
2833 |
2578 |
2834 def getconnectionParameter(self, idx): |
2579 def getconnectionParameter(self, idx): |
2835 if self.content: |
2580 connection = self.getconnection(idx) |
2836 return self.content["value"][idx].getformalParameter() |
2581 if connection is not None: |
|
2582 return connection.getformalParameter() |
2837 return None |
2583 return None |
2838 setattr(cls, "getconnectionParameter", getconnectionParameter) |
2584 setattr(cls, "getconnectionParameter", getconnectionParameter) |
2839 |
2585 |
2840 cls = PLCOpenClasses.get("connectionPointOut", None) |
2586 cls = PLCOpenParser.GetElementClass("connectionPointOut") |
2841 if cls: |
2587 if cls: |
2842 def setrelPositionXY(self, x, y): |
2588 def setrelPositionXY(self, x, y): |
2843 self.relPosition = PLCOpenClasses["position"]() |
2589 self.relPosition = PLCOpenParser.CreateElement("relPosition", "connectionPointOut") |
2844 self.relPosition.setx(x) |
2590 self.relPosition.setx(x) |
2845 self.relPosition.sety(y) |
2591 self.relPosition.sety(y) |
2846 setattr(cls, "setrelPositionXY", setrelPositionXY) |
2592 setattr(cls, "setrelPositionXY", setrelPositionXY) |
2847 |
2593 |
2848 def getrelPositionXY(self): |
2594 def getrelPositionXY(self): |
2849 if self.relPosition: |
2595 if self.relPosition is not None: |
2850 return self.relPosition.getx(), self.relPosition.gety() |
2596 return self.relPosition.getx(), self.relPosition.gety() |
2851 return self.relPosition |
2597 return self.relPosition |
2852 setattr(cls, "getrelPositionXY", getrelPositionXY) |
2598 setattr(cls, "getrelPositionXY", getrelPositionXY) |
2853 |
2599 |
2854 cls = PLCOpenClasses.get("value", None) |
2600 cls = PLCOpenParser.GetElementClass("value") |
2855 if cls: |
2601 if cls: |
2856 def setvalue(self, value): |
2602 def setvalue(self, value): |
2857 value = value.strip() |
2603 value = value.strip() |
2858 if value.startswith("[") and value.endswith("]"): |
2604 if value.startswith("[") and value.endswith("]"): |
2859 arrayValue = PLCOpenClasses["value_arrayValue"]() |
2605 content = PLCOpenParser.CreateElement("arrayValue", "value") |
2860 self.content = {"name" : "arrayValue", "value" : arrayValue} |
|
2861 elif value.startswith("(") and value.endswith(")"): |
2606 elif value.startswith("(") and value.endswith(")"): |
2862 structValue = PLCOpenClasses["value_structValue"]() |
2607 content = PLCOpenParser.CreateElement("structValue", "value") |
2863 self.content = {"name" : "structValue", "value" : structValue} |
|
2864 else: |
2608 else: |
2865 simpleValue = PLCOpenClasses["value_simpleValue"]() |
2609 content = PLCOpenParser.CreateElement("simpleValue", "value") |
2866 self.content = {"name" : "simpleValue", "value": simpleValue} |
2610 content.setvalue(value) |
2867 self.content["value"].setvalue(value) |
2611 self.setcontent(content) |
2868 setattr(cls, "setvalue", setvalue) |
2612 setattr(cls, "setvalue", setvalue) |
2869 |
2613 |
2870 def getvalue(self): |
2614 def getvalue(self): |
2871 return self.content["value"].getvalue() |
2615 return self.content.getvalue() |
2872 setattr(cls, "getvalue", getvalue) |
2616 setattr(cls, "getvalue", getvalue) |
2873 |
2617 |
2874 def extractValues(values): |
2618 def extractValues(values): |
2875 items = values.split(",") |
2619 items = values.split(",") |
2876 i = 1 |
2620 i = 1 |