120 end = TextLenInRowColumn(text[:result.end() - 1]) |
119 end = TextLenInRowColumn(text[:result.end() - 1]) |
121 test_result.append((start, end, "\n".join(lines[start[0]:end[0] + 1]))) |
120 test_result.append((start, end, "\n".join(lines[start[0]:end[0] + 1]))) |
122 result = criteria["pattern"].search(text, result.end()) |
121 result = criteria["pattern"].search(text, result.end()) |
123 return test_result |
122 return test_result |
124 |
123 |
125 PLCOpenClasses = GenerateClassesFromXSD(os.path.join(os.path.split(__file__)[0], "tc6_xml_v201.xsd")) |
124 PLCOpenParser = GenerateParserFromXSD(os.path.join(os.path.split(__file__)[0], "tc6_xml_v201.xsd")) |
126 |
125 PLCOpen_XPath = lambda xpath: etree.XPath(xpath, namespaces=PLCOpenParser.NSMAP) |
127 ElementNameToClass = {} |
126 |
128 |
127 LOAD_POU_PROJECT_TEMPLATE = """ |
129 cls = PLCOpenClasses.get("formattedText", None) |
128 <project xmlns:ns1="http://www.plcopen.org/xml/tc6_0201" |
|
129 xmlns:xhtml="http://www.w3.org/1999/xhtml" |
|
130 xmlns:xsd="http://www.w3.org/2001/XMLSchema" |
|
131 xmlns="http://www.plcopen.org/xml/tc6_0201"> |
|
132 <fileHeader companyName="" productName="" productVersion="" |
|
133 creationDateTime="1970-01-01T00:00:00"/> |
|
134 <contentHeader name="paste_project"> |
|
135 <coordinateInfo> |
|
136 <fbd><scaling x="0" y="0"/></fbd> |
|
137 <ld><scaling x="0" y="0"/></ld> |
|
138 <sfc><scaling x="0" y="0"/></sfc> |
|
139 </coordinateInfo> |
|
140 </contentHeader> |
|
141 <types> |
|
142 <dataTypes/> |
|
143 <pous>%s</pous> |
|
144 </types> |
|
145 <instances> |
|
146 <configurations/> |
|
147 </instances> |
|
148 </project> |
|
149 """ |
|
150 |
|
151 def LOAD_POU_INSTANCES_PROJECT_TEMPLATE(body_type): |
|
152 return LOAD_POU_PROJECT_TEMPLATE % """ |
|
153 <pou name="paste_pou" pouType="program"> |
|
154 <body> |
|
155 <%(body_type)s>%%s</%(body_type)s> |
|
156 </body> |
|
157 </pou>""" % locals() |
|
158 |
|
159 def LoadProject(filepath): |
|
160 project_file = open(filepath) |
|
161 project_xml = project_file.read().replace( |
|
162 "http://www.plcopen.org/xml/tc6.xsd", |
|
163 "http://www.plcopen.org/xml/tc6_0201") |
|
164 for cre, repl in [ |
|
165 (re.compile("(?<!<xhtml:p>)(?:<!\[CDATA\[)"), "<xhtml:p><![CDATA["), |
|
166 (re.compile("(?:]]>)(?!</xhtml:p>)"), "]]></xhtml:p>")]: |
|
167 project_xml = cre.sub(repl, project_xml) |
|
168 project_file.close() |
|
169 |
|
170 return etree.fromstring(project_xml, PLCOpenParser) |
|
171 |
|
172 project_pou_xpath = PLCOpen_XPath("/ppx:project/ppx:types/ppx:pous/ppx:pou") |
|
173 def LoadPou(xml_string): |
|
174 root = etree.fromstring( |
|
175 LOAD_POU_PROJECT_TEMPLATE % xml_string, |
|
176 PLCOpenParser) |
|
177 return project_pou_xpath(root)[0] |
|
178 |
|
179 project_pou_instances_xpath = { |
|
180 body_type: PLCOpen_XPath( |
|
181 "/ppx:project/ppx:types/ppx:pous/ppx:pou[@name='paste_pou']/ppx:body/ppx:%s/*" % body_type) |
|
182 for body_type in ["FBD", "LD", "SFC"]} |
|
183 def LoadPouInstances(xml_string, body_type): |
|
184 root = etree.fromstring( |
|
185 LOAD_POU_INSTANCES_PROJECT_TEMPLATE(body_type) % xml_string, |
|
186 PLCOpenParser) |
|
187 return project_pou_instances_xpath[body_type](root) |
|
188 |
|
189 def SaveProject(project, filepath): |
|
190 project_file = open(filepath, 'w') |
|
191 project_file.write(etree.tostring( |
|
192 project, |
|
193 pretty_print=True, |
|
194 xml_declaration=True, |
|
195 encoding='utf-8')) |
|
196 project_file.close() |
|
197 |
|
198 cls = PLCOpenParser.GetElementClass("formattedText") |
130 if cls: |
199 if cls: |
131 def updateElementName(self, old_name, new_name): |
200 def updateElementName(self, old_name, new_name): |
132 text = self.text |
201 text = self.getanyText() |
133 index = text.find(old_name) |
202 index = text.find(old_name) |
134 while index != -1: |
203 while index != -1: |
135 if index > 0 and (text[index - 1].isalnum() or text[index - 1] == "_"): |
204 if index > 0 and (text[index - 1].isalnum() or text[index - 1] == "_"): |
136 index = text.find(old_name, index + len(old_name)) |
205 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)] == "_"): |
206 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)) |
207 index = text.find(old_name, index + len(old_name)) |
139 else: |
208 else: |
140 text = text[:index] + new_name + text[index + len(old_name):] |
209 text = text[:index] + new_name + text[index + len(old_name):] |
141 index = text.find(old_name, index + len(new_name)) |
210 index = text.find(old_name, index + len(new_name)) |
142 self.text = text |
211 self.setanyText(text) |
143 setattr(cls, "updateElementName", updateElementName) |
212 setattr(cls, "updateElementName", updateElementName) |
144 |
213 |
145 def updateElementAddress(self, address_model, new_leading): |
214 def updateElementAddress(self, address_model, new_leading): |
146 text = self.text |
215 text = self.getanyText() |
147 startpos = 0 |
216 startpos = 0 |
148 result = address_model.search(text, startpos) |
217 result = address_model.search(text, startpos) |
149 while result is not None: |
218 while result is not None: |
150 groups = result.groups() |
219 groups = result.groups() |
151 new_address = groups[0] + new_leading + groups[2] |
220 new_address = groups[0] + new_leading + groups[2] |
152 text = text[:result.start()] + new_address + text[result.end():] |
221 text = text[:result.start()] + new_address + text[result.end():] |
153 startpos = result.start() + len(new_address) |
222 startpos = result.start() + len(new_address) |
154 result = address_model.search(self.text, startpos) |
223 result = address_model.search(text, startpos) |
155 self.text = text |
224 self.setanyText(text) |
156 setattr(cls, "updateElementAddress", updateElementAddress) |
225 setattr(cls, "updateElementAddress", updateElementAddress) |
157 |
226 |
158 def hasblock(self, block_type): |
227 def hasblock(self, block_type): |
159 text = self.text.upper() |
228 text = self.getanyText().upper() |
160 index = text.find(block_type.upper()) |
229 index = text.find(block_type.upper()) |
161 while index != -1: |
230 while index != -1: |
162 if (not (index > 0 and (text[index - 1].isalnum() or text[index - 1] == "_")) and |
231 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)] != "(")): |
232 not (index < len(text) - len(block_type) and text[index + len(block_type)] != "(")): |
164 return True |
233 return True |
165 index = text.find(block_type.upper(), index + len(block_type)) |
234 index = text.find(block_type.upper(), index + len(block_type)) |
166 return False |
235 return False |
167 setattr(cls, "hasblock", hasblock) |
236 setattr(cls, "hasblock", hasblock) |
168 |
237 |
169 def Search(self, criteria, parent_infos): |
238 def Search(self, criteria, parent_infos): |
170 return [(tuple(parent_infos),) + result for result in TestTextElement(self.gettext(), criteria)] |
239 return [(tuple(parent_infos),) + result for result in TestTextElement(self.getanyText(), criteria)] |
171 setattr(cls, "Search", Search) |
240 setattr(cls, "Search", Search) |
172 |
241 |
173 cls = PLCOpenClasses.get("project", None) |
242 cls = PLCOpenParser.GetElementClass("project") |
174 if cls: |
243 if cls: |
175 cls.singleLineAttributes = False |
|
176 cls.EnumeratedDataTypeValues = {} |
|
177 cls.CustomDataTypeRange = {} |
|
178 cls.CustomTypeHierarchy = {} |
|
179 cls.ElementUsingTree = {} |
|
180 cls.CustomBlockTypes = OrderedDict() |
|
181 |
244 |
182 def setname(self, name): |
245 def setname(self, name): |
183 self.contentHeader.setname(name) |
246 self.contentHeader.setname(name) |
184 setattr(cls, "setname", setname) |
247 setattr(cls, "setname", setname) |
185 |
248 |
186 def getname(self): |
249 def getname(self): |
187 return self.contentHeader.getname() |
250 return self.contentHeader.getname() |
188 setattr(cls, "getname", getname) |
251 setattr(cls, "getname", getname) |
189 |
252 |
190 def getfileHeader(self): |
253 def getfileHeader(self): |
191 fileheader = {} |
254 fileheader_obj = self.fileHeader |
192 for name, value in [("companyName", self.fileHeader.getcompanyName()), |
255 return { |
193 ("companyURL", self.fileHeader.getcompanyURL()), |
256 attr: value if value is not None else "" |
194 ("productName", self.fileHeader.getproductName()), |
257 for attr, value in [ |
195 ("productVersion", self.fileHeader.getproductVersion()), |
258 ("companyName", fileheader_obj.getcompanyName()), |
196 ("productRelease", self.fileHeader.getproductRelease()), |
259 ("companyURL", fileheader_obj.getcompanyURL()), |
197 ("creationDateTime", self.fileHeader.getcreationDateTime()), |
260 ("productName", fileheader_obj.getproductName()), |
198 ("contentDescription", self.fileHeader.getcontentDescription())]: |
261 ("productVersion", fileheader_obj.getproductVersion()), |
|
262 ("productRelease", fileheader_obj.getproductRelease()), |
|
263 ("creationDateTime", fileheader_obj.getcreationDateTime()), |
|
264 ("contentDescription", fileheader_obj.getcontentDescription())] |
|
265 } |
|
266 setattr(cls, "getfileHeader", getfileHeader) |
|
267 |
|
268 def setfileHeader(self, fileheader): |
|
269 fileheader_obj = self.fileHeader |
|
270 for attr in ["companyName", "companyURL", "productName", |
|
271 "productVersion", "productRelease", "creationDateTime", |
|
272 "contentDescription"]: |
|
273 value = fileheader.get(attr) |
199 if value is not None: |
274 if value is not None: |
200 fileheader[name] = value |
275 setattr(fileheader_obj, attr, value) |
201 else: |
|
202 fileheader[name] = "" |
|
203 return fileheader |
|
204 setattr(cls, "getfileHeader", getfileHeader) |
|
205 |
|
206 def setfileHeader(self, fileheader): |
|
207 if fileheader.has_key("companyName"): |
|
208 self.fileHeader.setcompanyName(fileheader["companyName"]) |
|
209 if fileheader.has_key("companyURL"): |
|
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) |
276 setattr(cls, "setfileHeader", setfileHeader) |
222 |
277 |
223 def getcontentHeader(self): |
278 def getcontentHeader(self): |
224 contentheader = {} |
279 contentheader_obj = self.contentHeader |
225 for name, value in [("projectName", self.contentHeader.getname()), |
280 contentheader = { |
226 ("projectVersion", self.contentHeader.getversion()), |
281 attr: value if value is not None else "" |
227 ("modificationDateTime", self.contentHeader.getmodificationDateTime()), |
282 for attr, value in [ |
228 ("organization", self.contentHeader.getorganization()), |
283 ("projectName", contentheader_obj.getname()), |
229 ("authorName", self.contentHeader.getauthor()), |
284 ("projectVersion", contentheader_obj.getversion()), |
230 ("language", self.contentHeader.getlanguage())]: |
285 ("modificationDateTime", contentheader_obj.getmodificationDateTime()), |
231 if value is not None: |
286 ("organization", contentheader_obj.getorganization()), |
232 contentheader[name] = value |
287 ("authorName", contentheader_obj.getauthor()), |
233 else: |
288 ("language", contentheader_obj.getlanguage())] |
234 contentheader[name] = "" |
289 } |
235 contentheader["pageSize"] = self.contentHeader.getpageSize() |
290 contentheader["pageSize"] = self.contentHeader.getpageSize() |
236 contentheader["scaling"] = self.contentHeader.getscaling() |
291 contentheader["scaling"] = self.contentHeader.getscaling() |
237 return contentheader |
292 return contentheader |
238 setattr(cls, "getcontentHeader", getcontentHeader) |
293 setattr(cls, "getcontentHeader", getcontentHeader) |
239 |
294 |
240 def setcontentHeader(self, contentheader): |
295 def setcontentHeader(self, contentheader): |
241 if contentheader.has_key("projectName"): |
296 contentheader_obj = self.contentHeader |
242 self.contentHeader.setname(contentheader["projectName"]) |
297 for attr, value in contentheader.iteritems(): |
243 if contentheader.has_key("projectVersion"): |
298 func = {"projectName": contentheader_obj.setname, |
244 self.contentHeader.setversion(contentheader["projectVersion"]) |
299 "projectVersion": contentheader_obj.setversion, |
245 if contentheader.has_key("modificationDateTime"): |
300 "authorName": contentheader_obj.setauthor, |
246 self.contentHeader.setmodificationDateTime(contentheader["modificationDateTime"]) |
301 "pageSize": lambda v: contentheader_obj.setpageSize(*v), |
247 if contentheader.has_key("organization"): |
302 "scaling": contentheader_obj.setscaling}.get(attr) |
248 self.contentHeader.setorganization(contentheader["organization"]) |
303 if func is not None: |
249 if contentheader.has_key("authorName"): |
304 func(value) |
250 self.contentHeader.setauthor(contentheader["authorName"]) |
305 elif attr in ["modificationDateTime", "organization", "language"]: |
251 if contentheader.has_key("language"): |
306 setattr(contentheader_obj, attr, value) |
252 self.contentHeader.setlanguage(contentheader["language"]) |
|
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) |
307 setattr(cls, "setcontentHeader", setcontentHeader) |
258 |
308 |
259 def getdataTypes(self): |
309 def gettypeElementFunc(element_type): |
260 return self.types.getdataTypeElements() |
310 elements_xpath = PLCOpen_XPath( |
|
311 "ppx:types/ppx:%(element_type)ss/ppx:%(element_type)s[@name=$name]" % locals()) |
|
312 def gettypeElement(self, name): |
|
313 elements = elements_xpath(self, name=name) |
|
314 if len(elements) == 1: |
|
315 return elements[0] |
|
316 return None |
|
317 return gettypeElement |
|
318 |
|
319 datatypes_xpath = PLCOpen_XPath("ppx:types/ppx:dataTypes/ppx:dataType") |
|
320 filtered_datatypes_xpath = PLCOpen_XPath( |
|
321 "ppx:types/ppx:dataTypes/ppx:dataType[@name!=$exclude]") |
|
322 def getdataTypes(self, exclude=None): |
|
323 if exclude is not None: |
|
324 return filtered_datatypes_xpath(self, exclude=exclude) |
|
325 return datatypes_xpath(self) |
261 setattr(cls, "getdataTypes", getdataTypes) |
326 setattr(cls, "getdataTypes", getdataTypes) |
262 |
327 |
263 def getdataType(self, name): |
328 setattr(cls, "getdataType", gettypeElementFunc("dataType")) |
264 return self.types.getdataTypeElement(name) |
|
265 setattr(cls, "getdataType", getdataType) |
|
266 |
329 |
267 def appenddataType(self, name): |
330 def appenddataType(self, name): |
268 if self.CustomTypeHierarchy.has_key(name): |
331 if self.getdataType(name) is not None: |
269 raise ValueError, "\"%s\" Data Type already exists !!!"%name |
332 raise ValueError, "\"%s\" Data Type already exists !!!"%name |
270 self.types.appenddataTypeElement(name) |
333 self.types.appenddataTypeElement(name) |
271 self.AddCustomDataType(self.getdataType(name)) |
|
272 setattr(cls, "appenddataType", appenddataType) |
334 setattr(cls, "appenddataType", appenddataType) |
273 |
335 |
274 def insertdataType(self, index, datatype): |
336 def insertdataType(self, index, datatype): |
275 self.types.insertdataTypeElement(index, datatype) |
337 self.types.insertdataTypeElement(index, datatype) |
276 self.AddCustomDataType(datatype) |
|
277 setattr(cls, "insertdataType", insertdataType) |
338 setattr(cls, "insertdataType", insertdataType) |
278 |
339 |
279 def removedataType(self, name): |
340 def removedataType(self, name): |
280 self.types.removedataTypeElement(name) |
341 self.types.removedataTypeElement(name) |
281 self.RefreshDataTypeHierarchy() |
|
282 self.RefreshElementUsingTree() |
|
283 setattr(cls, "removedataType", removedataType) |
342 setattr(cls, "removedataType", removedataType) |
284 |
343 |
285 def getpous(self): |
344 def getpous(self, exclude=None, filter=[]): |
286 return self.types.getpouElements() |
345 return self.xpath( |
|
346 "ppx:types/ppx:pous/ppx:pou%s%s" % |
|
347 (("[@name!='%s']" % exclude) if exclude is not None else '', |
|
348 ("[%s]" % " or ".join( |
|
349 map(lambda x: "@pouType='%s'" % x, filter))) |
|
350 if len(filter) > 0 else ""), |
|
351 namespaces=PLCOpenParser.NSMAP) |
287 setattr(cls, "getpous", getpous) |
352 setattr(cls, "getpous", getpous) |
288 |
353 |
289 def getpou(self, name): |
354 setattr(cls, "getpou", gettypeElementFunc("pou")) |
290 return self.types.getpouElement(name) |
|
291 setattr(cls, "getpou", getpou) |
|
292 |
355 |
293 def appendpou(self, name, pou_type, body_type): |
356 def appendpou(self, name, pou_type, body_type): |
294 self.types.appendpouElement(name, pou_type, body_type) |
357 self.types.appendpouElement(name, pou_type, body_type) |
295 self.AddCustomBlockType(self.getpou(name)) |
|
296 setattr(cls, "appendpou", appendpou) |
358 setattr(cls, "appendpou", appendpou) |
297 |
359 |
298 def insertpou(self, index, pou): |
360 def insertpou(self, index, pou): |
299 self.types.insertpouElement(index, pou) |
361 self.types.insertpouElement(index, pou) |
300 self.AddCustomBlockType(pou) |
|
301 setattr(cls, "insertpou", insertpou) |
362 setattr(cls, "insertpou", insertpou) |
302 |
363 |
303 def removepou(self, name): |
364 def removepou(self, name): |
304 self.types.removepouElement(name) |
365 self.types.removepouElement(name) |
305 self.RefreshCustomBlockTypes() |
|
306 self.RefreshElementUsingTree() |
|
307 setattr(cls, "removepou", removepou) |
366 setattr(cls, "removepou", removepou) |
308 |
367 |
|
368 configurations_xpath = PLCOpen_XPath( |
|
369 "ppx:instances/ppx:configurations/ppx:configuration") |
309 def getconfigurations(self): |
370 def getconfigurations(self): |
310 configurations = self.instances.configurations.getconfiguration() |
371 return configurations_xpath(self) |
311 if configurations: |
|
312 return configurations |
|
313 return [] |
|
314 setattr(cls, "getconfigurations", getconfigurations) |
372 setattr(cls, "getconfigurations", getconfigurations) |
315 |
373 |
|
374 configuration_xpath = PLCOpen_XPath( |
|
375 "ppx:instances/ppx:configurations/ppx:configuration[@name=$name]") |
316 def getconfiguration(self, name): |
376 def getconfiguration(self, name): |
317 for configuration in self.instances.configurations.getconfiguration(): |
377 configurations = configuration_xpath(self, name=name) |
318 if configuration.getname() == name: |
378 if len(configurations) == 1: |
319 return configuration |
379 return configurations[0] |
320 return None |
380 return None |
321 setattr(cls, "getconfiguration", getconfiguration) |
381 setattr(cls, "getconfiguration", getconfiguration) |
322 |
382 |
323 def addconfiguration(self, name): |
383 def addconfiguration(self, name): |
324 for configuration in self.instances.configurations.getconfiguration(): |
384 if self.getconfiguration(name) is not None: |
325 if configuration.getname() == name: |
385 raise ValueError, _("\"%s\" configuration already exists !!!") % name |
326 raise ValueError, _("\"%s\" configuration already exists !!!")%name |
386 new_configuration = PLCOpenParser.CreateElement("configuration", "configurations") |
327 new_configuration = PLCOpenClasses["configurations_configuration"]() |
|
328 new_configuration.setname(name) |
387 new_configuration.setname(name) |
329 self.instances.configurations.appendconfiguration(new_configuration) |
388 self.instances.configurations.appendconfiguration(new_configuration) |
330 setattr(cls, "addconfiguration", addconfiguration) |
389 setattr(cls, "addconfiguration", addconfiguration) |
331 |
390 |
332 def removeconfiguration(self, name): |
391 def removeconfiguration(self, name): |
333 found = False |
392 configuration = self.getconfiguration(name) |
334 for idx, configuration in enumerate(self.instances.configurations.getconfiguration()): |
393 if configuration is None: |
335 if configuration.getname() == name: |
394 raise ValueError, ("\"%s\" configuration doesn't exist !!!") % name |
336 self.instances.configurations.removeconfiguration(idx) |
395 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) |
396 setattr(cls, "removeconfiguration", removeconfiguration) |
342 |
397 |
|
398 resources_xpath = PLCOpen_XPath( |
|
399 "ppx:instances/ppx:configurations/ppx:configuration[@name=$configname]/ppx:resource[@name=$name]") |
343 def getconfigurationResource(self, config_name, name): |
400 def getconfigurationResource(self, config_name, name): |
344 configuration = self.getconfiguration(config_name) |
401 resources = resources_xpath(self, configname=config_name, name=name) |
345 if configuration: |
402 if len(resources) == 1: |
346 for resource in configuration.getresource(): |
403 return resources[0] |
347 if resource.getname() == name: |
|
348 return resource |
|
349 return None |
404 return None |
350 setattr(cls, "getconfigurationResource", getconfigurationResource) |
405 setattr(cls, "getconfigurationResource", getconfigurationResource) |
351 |
406 |
352 def addconfigurationResource(self, config_name, name): |
407 def addconfigurationResource(self, config_name, name): |
|
408 if self.getconfigurationResource(config_name, name) is not None: |
|
409 raise ValueError, _("\"%s\" resource already exists in \"%s\" configuration !!!") % (name, config_name) |
353 configuration = self.getconfiguration(config_name) |
410 configuration = self.getconfiguration(config_name) |
354 if configuration: |
411 if configuration is not None: |
355 for resource in configuration.getresource(): |
412 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) |
413 new_resource.setname(name) |
360 configuration.appendresource(new_resource) |
414 configuration.appendresource(new_resource) |
361 setattr(cls, "addconfigurationResource", addconfigurationResource) |
415 setattr(cls, "addconfigurationResource", addconfigurationResource) |
362 |
416 |
363 def removeconfigurationResource(self, config_name, name): |
417 def removeconfigurationResource(self, config_name, name): |
364 configuration = self.getconfiguration(config_name) |
418 configuration = self.getconfiguration(config_name) |
365 if configuration: |
419 found = False |
366 found = False |
420 if configuration is not None: |
367 for idx, resource in enumerate(configuration.getresource()): |
421 resource = self.getconfigurationResource(config_name, name) |
368 if resource.getname() == name: |
422 if resource is not None: |
369 configuration.removeresource(idx) |
423 configuration.remove(resource) |
370 found = True |
424 found = True |
371 break |
425 if not found: |
372 if not found: |
426 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) |
427 setattr(cls, "removeconfigurationResource", removeconfigurationResource) |
375 |
428 |
376 def updateElementName(self, old_name, new_name): |
429 def updateElementName(self, old_name, new_name): |
377 for datatype in self.types.getdataTypeElements(): |
430 for datatype in self.getdataTypes(): |
378 datatype.updateElementName(old_name, new_name) |
431 datatype.updateElementName(old_name, new_name) |
379 for pou in self.types.getpouElements(): |
432 for pou in self.getpous(): |
380 pou.updateElementName(old_name, new_name) |
433 pou.updateElementName(old_name, new_name) |
381 for configuration in self.instances.configurations.getconfiguration(): |
434 for configuration in self.getconfigurations(): |
382 configuration.updateElementName(old_name, new_name) |
435 configuration.updateElementName(old_name, new_name) |
383 setattr(cls, "updateElementName", updateElementName) |
436 setattr(cls, "updateElementName", updateElementName) |
384 |
437 |
385 def updateElementAddress(self, old_leading, new_leading): |
438 def updateElementAddress(self, old_leading, new_leading): |
386 address_model = re.compile(FILTER_ADDRESS_MODEL % old_leading) |
439 address_model = re.compile(FILTER_ADDRESS_MODEL % old_leading) |
387 for pou in self.types.getpouElements(): |
440 for pou in self.getpous(): |
388 pou.updateElementAddress(address_model, new_leading) |
441 pou.updateElementAddress(address_model, new_leading) |
389 for configuration in self.instances.configurations.getconfiguration(): |
442 for configuration in self.getconfigurations(): |
390 configuration.updateElementAddress(address_model, new_leading) |
443 configuration.updateElementAddress(address_model, new_leading) |
391 setattr(cls, "updateElementAddress", updateElementAddress) |
444 setattr(cls, "updateElementAddress", updateElementAddress) |
392 |
445 |
393 def removeVariableByAddress(self, address): |
446 def removeVariableByAddress(self, address): |
394 for pou in self.types.getpouElements(): |
447 for pou in self.getpous(): |
395 pou.removeVariableByAddress(address) |
448 pou.removeVariableByAddress(address) |
396 for configuration in self.instances.configurations.getconfiguration(): |
449 for configuration in self.getconfigurations(): |
397 configuration.removeVariableByAddress(address) |
450 configuration.removeVariableByAddress(address) |
398 setattr(cls, "removeVariableByAddress", removeVariableByAddress) |
451 setattr(cls, "removeVariableByAddress", removeVariableByAddress) |
399 |
452 |
400 def removeVariableByFilter(self, leading): |
453 def removeVariableByFilter(self, leading): |
401 address_model = re.compile(FILTER_ADDRESS_MODEL % leading) |
454 address_model = re.compile(FILTER_ADDRESS_MODEL % leading) |
402 for pou in self.types.getpouElements(): |
455 for pou in self.getpous(): |
403 pou.removeVariableByFilter(address_model) |
456 pou.removeVariableByFilter(address_model) |
404 for configuration in self.instances.configurations.getconfiguration(): |
457 for configuration in self.getconfigurations(): |
405 configuration.removeVariableByFilter(address_model) |
458 configuration.removeVariableByFilter(address_model) |
406 setattr(cls, "removeVariableByFilter", removeVariableByFilter) |
459 setattr(cls, "removeVariableByFilter", removeVariableByFilter) |
407 |
460 |
408 def RefreshDataTypeHierarchy(self): |
461 enumerated_values_xpath = PLCOpen_XPath( |
409 self.EnumeratedDataTypeValues = {} |
462 "ppx:types/ppx:dataTypes/ppx:dataType/ppx:baseType/ppx:enum/ppx:values/ppx:value") |
410 self.CustomDataTypeRange = {} |
463 def GetEnumeratedDataTypeValues(self): |
411 self.CustomTypeHierarchy = {} |
464 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) |
465 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 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 |
466 |
707 def Search(self, criteria, parent_infos=[]): |
467 def Search(self, criteria, parent_infos=[]): |
708 result = self.types.Search(criteria, parent_infos) |
468 result = self.types.Search(criteria, parent_infos) |
709 for configuration in self.instances.configurations.getconfiguration(): |
469 for configuration in self.instances.configurations.getconfiguration(): |
710 result.extend(configuration.Search(criteria, parent_infos)) |
470 result.extend(configuration.Search(criteria, parent_infos)) |
711 return result |
471 return result |
712 setattr(cls, "Search", Search) |
472 setattr(cls, "Search", Search) |
713 |
473 |
714 cls = PLCOpenClasses.get("project_fileHeader", None) |
474 cls = PLCOpenParser.GetElementClass("contentHeader", "project") |
715 if cls: |
475 if cls: |
716 cls.singleLineAttributes = False |
|
717 |
|
718 cls = PLCOpenClasses.get("project_contentHeader", None) |
|
719 if cls: |
|
720 cls.singleLineAttributes = False |
|
721 |
476 |
722 def setpageSize(self, width, height): |
477 def setpageSize(self, width, height): |
723 self.coordinateInfo.setpageSize(width, height) |
478 self.coordinateInfo.setpageSize(width, height) |
724 setattr(cls, "setpageSize", setpageSize) |
479 setattr(cls, "setpageSize", setpageSize) |
725 |
480 |
1324 if self.interface is not None: |
1113 if self.interface is not None: |
1325 reverse_types = {} |
1114 reverse_types = {} |
1326 for name, value in VarTypes.items(): |
1115 for name, value in VarTypes.items(): |
1327 reverse_types[value] = name |
1116 reverse_types[value] = name |
1328 for varlist in self.interface.getcontent(): |
1117 for varlist in self.interface.getcontent(): |
1329 vars.append((reverse_types[varlist["name"]], varlist["value"])) |
1118 vars.append((reverse_types[varlist.getLocalTag()], varlist)) |
1330 return vars |
1119 return vars |
1331 setattr(cls, "getvars", getvars) |
1120 setattr(cls, "getvars", getvars) |
1332 |
1121 |
1333 def setvars(self, vars): |
1122 def setvars(self, vars): |
1334 if self.interface is None: |
1123 if self.interface is None: |
1335 self.interface = PLCOpenClasses["pou_interface"]() |
1124 self.interface = PLCOpenParser.CreateElement("interface", "pou") |
1336 self.interface.setcontent([]) |
1125 self.interface.setcontent(vars) |
1337 for vartype, varlist in vars: |
|
1338 self.interface.appendcontent({"name" : VarTypes[vartype], "value" : varlist}) |
|
1339 setattr(cls, "setvars", setvars) |
1126 setattr(cls, "setvars", setvars) |
1340 |
1127 |
1341 def addpouLocalVar(self, type, name, location="", description=""): |
1128 def addpouLocalVar(self, var_type, name, location="", description=""): |
1342 self.addpouVar(type, name, location=location, description=description) |
1129 self.addpouVar(var_type, name, location=location, description=description) |
1343 setattr(cls, "addpouLocalVar", addpouLocalVar) |
1130 setattr(cls, "addpouLocalVar", addpouLocalVar) |
1344 |
1131 |
1345 def addpouExternalVar(self, type, name): |
1132 def addpouExternalVar(self, var_type, name): |
1346 self.addpouVar(type, name, "externalVars") |
1133 self.addpouVar(type, name, "externalVars") |
1347 setattr(cls, "addpouExternalVar", addpouExternalVar) |
1134 setattr(cls, "addpouExternalVar", addpouExternalVar) |
1348 |
1135 |
1349 def addpouVar(self, type, name, var_class="localVars", location="", description=""): |
1136 def addpouVar(self, var_type, name, var_class="localVars", location="", description=""): |
1350 if self.interface is None: |
1137 if self.interface is None: |
1351 self.interface = PLCOpenClasses["pou_interface"]() |
1138 self.interface = PLCOpenParser.CreateElement("interface", "pou") |
1352 content = self.interface.getcontent() |
1139 content = self.interface.getcontent() |
1353 if len(content) == 0 or content[-1]["name"] != var_class: |
1140 if len(content) == 0: |
1354 content.append({"name" : var_class, "value" : PLCOpenClasses["interface_%s" % var_class]()}) |
1141 varlist = PLCOpenParser.CreateElement(var_class, "interface") |
|
1142 self.interface.setcontent([varlist]) |
|
1143 elif content[-1] != var_class: |
|
1144 varlist = PLCOpenParser.CreateElement(var_class, "interface") |
|
1145 content[-1].addnext(varlist) |
1355 else: |
1146 else: |
1356 varlist = content[-1]["value"] |
1147 varlist = content[-1] |
1357 variables = varlist.getvariable() |
1148 variables = varlist.getvariable() |
1358 if varlist.getconstant() or varlist.getretain() or len(variables) > 0 and variables[0].getaddress(): |
1149 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]()}) |
1150 varlist = PLCOpenParser.CreateElement(var_class, "interface") |
1360 var = PLCOpenClasses["varListPlain_variable"]() |
1151 content[-1].addnext(varlist) |
|
1152 var = PLCOpenParser.CreateElement("variable", "varListPlain") |
1361 var.setname(name) |
1153 var.setname(name) |
1362 var_type = PLCOpenClasses["dataType"]() |
|
1363 if type in [x for x,y in TypeHierarchy_list if not x.startswith("ANY")]: |
|
1364 if type == "STRING": |
|
1365 var_type.setcontent({"name" : "string", "value" : PLCOpenClasses["elementaryTypes_string"]()}) |
|
1366 elif type == "WSTRING": |
|
1367 var_type.setcontent({"name" : "wstring", "value" : PLCOpenClasses["elementaryTypes_wstring"]()}) |
|
1368 else: |
|
1369 var_type.setcontent({"name" : type, "value" : None}) |
|
1370 else: |
|
1371 derived_type = PLCOpenClasses["derivedTypes_derived"]() |
|
1372 derived_type.setname(type) |
|
1373 var_type.setcontent({"name" : "derived", "value" : derived_type}) |
|
1374 var.settype(var_type) |
1154 var.settype(var_type) |
1375 if location != "": |
1155 if location != "": |
1376 var.setaddress(location) |
1156 var.setaddress(location) |
1377 if description != "": |
1157 if description != "": |
1378 ft = PLCOpenClasses["formattedText"]() |
1158 ft = PLCOpenParser.CreateElement("documentation", "variable") |
1379 ft.settext(description) |
1159 ft.setanyText(description) |
1380 var.setdocumentation(ft) |
1160 var.setdocumentation(ft) |
1381 |
1161 |
1382 content[-1]["value"].appendvariable(var) |
1162 varlist.appendvariable(var) |
1383 setattr(cls, "addpouVar", addpouVar) |
1163 setattr(cls, "addpouVar", addpouVar) |
1384 |
1164 |
1385 def changepouVar(self, old_type, old_name, new_type, new_name): |
1165 def changepouVar(self, old_type, old_name, new_type, new_name): |
1386 if self.interface is not None: |
1166 if self.interface is not None: |
1387 content = self.interface.getcontent() |
1167 content = self.interface.getcontent() |
1388 for varlist in content: |
1168 for varlist in content: |
1389 variables = varlist["value"].getvariable() |
1169 variables = varlist.getvariable() |
1390 for var in variables: |
1170 for var in variables: |
1391 if var.getname() == old_name: |
1171 if var.getname() == old_name: |
1392 vartype_content = var.gettype().getcontent() |
1172 vartype_content = var.gettype().getcontent() |
1393 if vartype_content["name"] == "derived" and vartype_content["value"].getname() == old_type: |
1173 if vartype_content.getLocalTag() == "derived" and vartype_content.getname() == old_type: |
1394 var.setname(new_name) |
1174 var.setname(new_name) |
1395 vartype_content["value"].setname(new_type) |
1175 vartype_content.setname(new_type) |
1396 return |
1176 return |
1397 setattr(cls, "changepouVar", changepouVar) |
1177 setattr(cls, "changepouVar", changepouVar) |
1398 |
1178 |
1399 def removepouVar(self, type, name): |
1179 def removepouVar(self, var_type, name): |
1400 if self.interface is not None: |
1180 if self.interface is not None: |
1401 content = self.interface.getcontent() |
1181 content = self.interface.getcontent() |
1402 for varlist in content: |
1182 for varlist in content: |
1403 variables = varlist["value"].getvariable() |
1183 for var in varlist.getvariable(): |
1404 for var in variables: |
|
1405 if var.getname() == name: |
1184 if var.getname() == name: |
1406 vartype_content = var.gettype().getcontent() |
1185 vartype_content = var.gettype().getcontent() |
1407 if vartype_content["name"] == "derived" and vartype_content["value"].getname() == type: |
1186 if vartype_content.getLocalTag() == "derived" and vartype_content.getname() == var_type: |
1408 variables.remove(var) |
1187 varlist.remove(var) |
1409 break |
1188 break |
1410 if len(varlist["value"].getvariable()) == 0: |
1189 if len(varlist.getvariable()) == 0: |
1411 content.remove(varlist) |
1190 content.remove(varlist) |
1412 break |
1191 break |
1413 setattr(cls, "removepouVar", removepouVar) |
1192 setattr(cls, "removepouVar", removepouVar) |
1414 |
1193 |
1415 def hasblock(self, name=None, block_type=None): |
1194 def hasblock(self, name=None, block_type=None): |
1416 if self.getbodyType() in ["FBD", "LD", "SFC"]: |
1195 if self.getbodyType() in ["FBD", "LD", "SFC"]: |
1417 for instance in self.getinstances(): |
1196 for instance in self.getinstances(): |
1418 if (isinstance(instance, PLCOpenClasses["fbdObjects_block"]) and |
1197 if (isinstance(instance, PLCOpenParser.GetElementClass("block", "fbdObjects")) and |
1419 (name and instance.getinstanceName() == name or |
1198 (name and instance.getinstanceName() == name or |
1420 block_type and instance.gettypeName() == block_type)): |
1199 block_type and instance.gettypeName() == block_type)): |
1421 return True |
1200 return True |
1422 if self.transitions: |
1201 if self.transitions: |
1423 for transition in self.transitions.gettransition(): |
1202 for transition in self.transitions.gettransition(): |
1764 object.__setattr__(self, "currentExecutionOrderId", self.currentExecutionOrderId + 1) |
1511 object.__setattr__(self, "currentExecutionOrderId", self.currentExecutionOrderId + 1) |
1765 return self.currentExecutionOrderId |
1512 return self.currentExecutionOrderId |
1766 setattr(cls, "getnewExecutionOrderId", getnewExecutionOrderId) |
1513 setattr(cls, "getnewExecutionOrderId", getnewExecutionOrderId) |
1767 |
1514 |
1768 def resetexecutionOrder(self): |
1515 def resetexecutionOrder(self): |
1769 if self.content["name"] == "FBD": |
1516 if self.content.getLocalTag() == "FBD": |
1770 for element in self.content["value"].getcontent(): |
1517 for element in self.content.getcontent(): |
1771 if not isinstance(element["value"], (PLCOpenClasses.get("commonObjects_comment", None), |
1518 if not isinstance(element, (PLCOpenParser.GetElementClass("comment", "commonObjects"), |
1772 PLCOpenClasses.get("commonObjects_connector", None), |
1519 PLCOpenParser.GetElementClass("connector", "commonObjects"), |
1773 PLCOpenClasses.get("commonObjects_continuation", None))): |
1520 PLCOpenParser.GetElementClass("continuation", "commonObjects"))): |
1774 element["value"].setexecutionOrderId(0) |
1521 element.setexecutionOrderId(0) |
1775 else: |
1522 else: |
1776 raise TypeError, _("Can only generate execution order on FBD networks!") |
1523 raise TypeError, _("Can only generate execution order on FBD networks!") |
1777 setattr(cls, "resetexecutionOrder", resetexecutionOrder) |
1524 setattr(cls, "resetexecutionOrder", resetexecutionOrder) |
1778 |
1525 |
1779 def compileexecutionOrder(self): |
1526 def compileexecutionOrder(self): |
1780 if self.content["name"] == "FBD": |
1527 if self.content.getLocalTag() == "FBD": |
1781 self.resetexecutionOrder() |
1528 self.resetexecutionOrder() |
1782 self.resetcurrentExecutionOrderId() |
1529 self.resetcurrentExecutionOrderId() |
1783 for element in self.content["value"].getcontent(): |
1530 for element in self.content.getcontent(): |
1784 if isinstance(element["value"], PLCOpenClasses.get("fbdObjects_outVariable", None)) and element["value"].getexecutionOrderId() == 0: |
1531 if isinstance(element, PLCOpenParser.GetElementClass("outVariable", "fbdObjects")) and element.getexecutionOrderId() == 0: |
1785 connections = element["value"].connectionPointIn.getconnections() |
1532 connections = element.connectionPointIn.getconnections() |
1786 if connections and len(connections) == 1: |
1533 if connections and len(connections) == 1: |
1787 self.compileelementExecutionOrder(connections[0]) |
1534 self.compileelementExecutionOrder(connections[0]) |
1788 element["value"].setexecutionOrderId(self.getnewExecutionOrderId()) |
1535 element.setexecutionOrderId(self.getnewExecutionOrderId()) |
1789 else: |
1536 else: |
1790 raise TypeError, _("Can only generate execution order on FBD networks!") |
1537 raise TypeError, _("Can only generate execution order on FBD networks!") |
1791 setattr(cls, "compileexecutionOrder", compileexecutionOrder) |
1538 setattr(cls, "compileexecutionOrder", compileexecutionOrder) |
1792 |
1539 |
1793 def compileelementExecutionOrder(self, link): |
1540 def compileelementExecutionOrder(self, link): |
1794 if self.content["name"] == "FBD": |
1541 if self.content.getLocalTag() == "FBD": |
1795 localid = link.getrefLocalId() |
1542 localid = link.getrefLocalId() |
1796 instance = self.getcontentInstance(localid) |
1543 instance = self.getcontentInstance(localid) |
1797 if isinstance(instance, PLCOpenClasses.get("fbdObjects_block", None)) and instance.getexecutionOrderId() == 0: |
1544 if isinstance(instance, PLCOpenParser.GetElementClass("block", "fbdObjects")) and instance.getexecutionOrderId() == 0: |
1798 for variable in instance.inputVariables.getvariable(): |
1545 for variable in instance.inputVariables.getvariable(): |
1799 connections = variable.connectionPointIn.getconnections() |
1546 connections = variable.connectionPointIn.getconnections() |
1800 if connections and len(connections) == 1: |
1547 if connections and len(connections) == 1: |
1801 self.compileelementExecutionOrder(connections[0]) |
1548 self.compileelementExecutionOrder(connections[0]) |
1802 instance.setexecutionOrderId(self.getnewExecutionOrderId()) |
1549 instance.setexecutionOrderId(self.getnewExecutionOrderId()) |
1803 elif isinstance(instance, PLCOpenClasses.get("commonObjects_continuation", None)) and instance.getexecutionOrderId() == 0: |
1550 elif isinstance(instance, PLCOpenParser.GetElementClass("continuation", "commonObjects")) and instance.getexecutionOrderId() == 0: |
1804 name = instance.getname() |
1551 name = instance.getname() |
1805 for tmp_instance in self.getcontentInstances(): |
1552 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: |
1553 if isinstance(tmp_instance, PLCOpenParser.GetElementClass("connector", "commonObjects")) and tmp_instance.getname() == name and tmp_instance.getexecutionOrderId() == 0: |
1807 connections = tmp_instance.connectionPointIn.getconnections() |
1554 connections = tmp_instance.connectionPointIn.getconnections() |
1808 if connections and len(connections) == 1: |
1555 if connections and len(connections) == 1: |
1809 self.compileelementExecutionOrder(connections[0]) |
1556 self.compileelementExecutionOrder(connections[0]) |
1810 else: |
1557 else: |
1811 raise TypeError, _("Can only generate execution order on FBD networks!") |
1558 raise TypeError, _("Can only generate execution order on FBD networks!") |
1812 setattr(cls, "compileelementExecutionOrder", compileelementExecutionOrder) |
1559 setattr(cls, "compileelementExecutionOrder", compileelementExecutionOrder) |
1813 |
1560 |
1814 def setelementExecutionOrder(self, instance, new_executionOrder): |
1561 def setelementExecutionOrder(self, instance, new_executionOrder): |
1815 if self.content["name"] == "FBD": |
1562 if self.content.getLocalTag() == "FBD": |
1816 old_executionOrder = instance.getexecutionOrderId() |
1563 old_executionOrder = instance.getexecutionOrderId() |
1817 if old_executionOrder is not None and old_executionOrder != 0 and new_executionOrder != 0: |
1564 if old_executionOrder is not None and old_executionOrder != 0 and new_executionOrder != 0: |
1818 for element in self.content["value"].getcontent(): |
1565 for element in self.content.getcontent(): |
1819 if element["value"] != instance and not isinstance(element["value"], PLCOpenClasses.get("commonObjects_comment", None)): |
1566 if element != instance and not isinstance(element, PLCOpenParser.GetElementClass("comment", "commonObjects")): |
1820 element_executionOrder = element["value"].getexecutionOrderId() |
1567 element_executionOrder = element.getexecutionOrderId() |
1821 if old_executionOrder <= element_executionOrder <= new_executionOrder: |
1568 if old_executionOrder <= element_executionOrder <= new_executionOrder: |
1822 element["value"].setexecutionOrderId(element_executionOrder - 1) |
1569 element.setexecutionOrderId(element_executionOrder - 1) |
1823 if new_executionOrder <= element_executionOrder <= old_executionOrder: |
1570 if new_executionOrder <= element_executionOrder <= old_executionOrder: |
1824 element["value"].setexecutionOrderId(element_executionOrder + 1) |
1571 element.setexecutionOrderId(element_executionOrder + 1) |
1825 instance.setexecutionOrderId(new_executionOrder) |
1572 instance.setexecutionOrderId(new_executionOrder) |
1826 else: |
1573 else: |
1827 raise TypeError, _("Can only generate execution order on FBD networks!") |
1574 raise TypeError, _("Can only generate execution order on FBD networks!") |
1828 setattr(cls, "setelementExecutionOrder", setelementExecutionOrder) |
1575 setattr(cls, "setelementExecutionOrder", setelementExecutionOrder) |
1829 |
1576 |
1830 def appendcontentInstance(self, name, instance): |
1577 def appendcontentInstance(self, instance): |
1831 if self.content["name"] in ["LD","FBD","SFC"]: |
1578 if self.content.getLocalTag() in ["LD","FBD","SFC"]: |
1832 element = {"name" : name, "value" : instance} |
1579 self.content.appendcontent(instance) |
1833 self.content["value"].appendcontent(element) |
|
1834 self.instances_dict[instance.getlocalId()] = element |
|
1835 else: |
1580 else: |
1836 raise TypeError, _("%s body don't have instances!")%self.content["name"] |
1581 raise TypeError, _("%s body don't have instances!")%self.content.getLocalTag() |
1837 setattr(cls, "appendcontentInstance", appendcontentInstance) |
1582 setattr(cls, "appendcontentInstance", appendcontentInstance) |
1838 |
1583 |
1839 def getcontentInstances(self): |
1584 def getcontentInstances(self): |
1840 if self.content["name"] in ["LD","FBD","SFC"]: |
1585 if self.content.getLocalTag() in ["LD","FBD","SFC"]: |
1841 instances = [] |
1586 return self.content.getcontent() |
1842 for element in self.content["value"].getcontent(): |
|
1843 instances.append(element["value"]) |
|
1844 return instances |
|
1845 else: |
1587 else: |
1846 raise TypeError, _("%s body don't have instances!")%self.content["name"] |
1588 raise TypeError, _("%s body don't have instances!")%self.content.getLocalTag() |
1847 setattr(cls, "getcontentInstances", getcontentInstances) |
1589 setattr(cls, "getcontentInstances", getcontentInstances) |
1848 |
1590 |
1849 def getcontentInstance(self, id): |
1591 instance_by_id_xpath = PLCOpen_XPath("*[@localId=$localId]") |
1850 if self.content["name"] in ["LD","FBD","SFC"]: |
1592 instance_by_name_xpath = PLCOpen_XPath("ppx:block[@instanceName=$name]") |
1851 instance = self.instances_dict.get(id, None) |
1593 def getcontentInstance(self, local_id): |
1852 if instance is not None: |
1594 if self.content.getLocalTag() in ["LD","FBD","SFC"]: |
1853 return instance["value"] |
1595 instance = instance_by_id_xpath(self.content, localId=local_id) |
|
1596 if len(instance) > 0: |
|
1597 return instance[0] |
1854 return None |
1598 return None |
1855 else: |
1599 else: |
1856 raise TypeError, _("%s body don't have instances!")%self.content["name"] |
1600 raise TypeError, _("%s body don't have instances!")%self.content.getLocalTag() |
1857 setattr(cls, "getcontentInstance", getcontentInstance) |
1601 setattr(cls, "getcontentInstance", getcontentInstance) |
1858 |
1602 |
1859 def getcontentRandomInstance(self, exclude): |
1603 def getcontentRandomInstance(self, exclude): |
1860 if self.content["name"] in ["LD","FBD","SFC"]: |
1604 if self.content.getLocalTag() in ["LD","FBD","SFC"]: |
1861 ids = self.instances_dict.viewkeys() - exclude |
1605 instance = self.content.xpath("*%s[position()=1]" % |
1862 if len(ids) > 0: |
1606 ("[not(%s)]" % " or ".join( |
1863 return self.instances_dict[ids.pop()]["value"] |
1607 map(lambda x: "@localId=%d" % x, exclude)) |
|
1608 if len(exclude) > 0 else "")) |
|
1609 if len(instance) > 0: |
|
1610 return instance[0] |
1864 return None |
1611 return None |
1865 else: |
1612 else: |
1866 raise TypeError, _("%s body don't have instances!")%self.content["name"] |
1613 raise TypeError, _("%s body don't have instances!")%self.content.getLocalTag() |
1867 setattr(cls, "getcontentRandomInstance", getcontentRandomInstance) |
1614 setattr(cls, "getcontentRandomInstance", getcontentRandomInstance) |
1868 |
1615 |
1869 def getcontentInstanceByName(self, name): |
1616 def getcontentInstanceByName(self, name): |
1870 if self.content["name"] in ["LD","FBD","SFC"]: |
1617 if self.content.getLocalTag() in ["LD","FBD","SFC"]: |
1871 for element in self.content["value"].getcontent(): |
1618 instance = instance_by_name_xpath(self.content) |
1872 if isinstance(element["value"], PLCOpenClasses.get("fbdObjects_block", None)) and element["value"].getinstanceName() == name: |
1619 if len(instance) > 0: |
1873 return element["value"] |
1620 return instance[0] |
|
1621 return None |
1874 else: |
1622 else: |
1875 raise TypeError, _("%s body don't have instances!")%self.content["name"] |
1623 raise TypeError, _("%s body don't have instances!")%self.content.getLocalTag() |
1876 setattr(cls, "getcontentInstanceByName", getcontentInstanceByName) |
1624 setattr(cls, "getcontentInstanceByName", getcontentInstanceByName) |
1877 |
1625 |
1878 def removecontentInstance(self, id): |
1626 def removecontentInstance(self, local_id): |
1879 if self.content["name"] in ["LD","FBD","SFC"]: |
1627 if self.content.getLocalTag() in ["LD","FBD","SFC"]: |
1880 element = self.instances_dict.pop(id, None) |
1628 instance = instance_by_id_xpath(self.content, localId=local_id) |
1881 if element is not None: |
1629 if len(instance) > 0: |
1882 self.content["value"].getcontent().remove(element) |
1630 self.content.remove(instance[0]) |
1883 else: |
1631 else: |
1884 raise ValueError, _("Instance with id %d doesn't exist!")%id |
1632 raise ValueError, _("Instance with id %d doesn't exist!")%id |
1885 else: |
1633 else: |
1886 raise TypeError, "%s body don't have instances!"%self.content["name"] |
1634 raise TypeError, "%s body don't have instances!"%self.content.getLocalTag() |
1887 setattr(cls, "removecontentInstance", removecontentInstance) |
1635 setattr(cls, "removecontentInstance", removecontentInstance) |
1888 |
1636 |
1889 def settext(self, text): |
1637 def settext(self, text): |
1890 if self.content["name"] in ["IL","ST"]: |
1638 if self.content.getLocalTag() in ["IL","ST"]: |
1891 self.content["value"].settext(text) |
1639 self.content.setanyText(text) |
1892 else: |
1640 else: |
1893 raise TypeError, _("%s body don't have text!")%self.content["name"] |
1641 raise TypeError, _("%s body don't have text!")%self.content.getLocalTag() |
1894 setattr(cls, "settext", settext) |
1642 setattr(cls, "settext", settext) |
1895 |
1643 |
1896 def gettext(self): |
1644 def gettext(self): |
1897 if self.content["name"] in ["IL","ST"]: |
1645 if self.content.getLocalTag() in ["IL","ST"]: |
1898 return self.content["value"].gettext() |
1646 return self.content.getanyText() |
1899 else: |
1647 else: |
1900 raise TypeError, _("%s body don't have text!")%self.content["name"] |
1648 raise TypeError, _("%s body don't have text!")%self.content.getLocalTag() |
1901 setattr(cls, "gettext", gettext) |
1649 setattr(cls, "gettext", gettext) |
1902 |
1650 |
1903 def hasblock(self, block_type): |
1651 def hasblock(self, block_type): |
1904 if self.content["name"] in ["IL","ST"]: |
1652 if self.content.getLocalTag() in ["IL","ST"]: |
1905 return self.content["value"].hasblock(block_type) |
1653 return self.content.hasblock(block_type) |
1906 else: |
1654 else: |
1907 raise TypeError, _("%s body don't have text!")%self.content["name"] |
1655 raise TypeError, _("%s body don't have text!")%self.content.getLocalTag() |
1908 setattr(cls, "hasblock", hasblock) |
1656 setattr(cls, "hasblock", hasblock) |
1909 |
1657 |
1910 def updateElementName(self, old_name, new_name): |
1658 def updateElementName(self, old_name, new_name): |
1911 if self.content["name"] in ["IL", "ST"]: |
1659 if self.content.getLocalTag() in ["IL", "ST"]: |
1912 self.content["value"].updateElementName(old_name, new_name) |
1660 self.content.updateElementName(old_name, new_name) |
1913 else: |
1661 else: |
1914 for element in self.content["value"].getcontent(): |
1662 for element in self.content.getcontent(): |
1915 element["value"].updateElementName(old_name, new_name) |
1663 element.updateElementName(old_name, new_name) |
1916 setattr(cls, "updateElementName", updateElementName) |
1664 setattr(cls, "updateElementName", updateElementName) |
1917 |
1665 |
1918 def updateElementAddress(self, address_model, new_leading): |
1666 def updateElementAddress(self, address_model, new_leading): |
1919 if self.content["name"] in ["IL", "ST"]: |
1667 if self.content.getLocalTag() in ["IL", "ST"]: |
1920 self.content["value"].updateElementAddress(address_model, new_leading) |
1668 self.content.updateElementAddress(address_model, new_leading) |
1921 else: |
1669 else: |
1922 for element in self.content["value"].getcontent(): |
1670 for element in self.content.getcontent(): |
1923 element["value"].updateElementAddress(address_model, new_leading) |
1671 element.updateElementAddress(address_model, new_leading) |
1924 setattr(cls, "updateElementAddress", updateElementAddress) |
1672 setattr(cls, "updateElementAddress", updateElementAddress) |
1925 |
1673 |
1926 def Search(self, criteria, parent_infos=[]): |
1674 def Search(self, criteria, parent_infos=[]): |
1927 if self.content["name"] in ["IL", "ST"]: |
1675 if self.content.getLocalTag() in ["IL", "ST"]: |
1928 search_result = self.content["value"].Search(criteria, parent_infos + ["body", 0]) |
1676 search_result = self.content.Search(criteria, parent_infos + ["body", 0]) |
1929 else: |
1677 else: |
1930 search_result = [] |
1678 search_result = [] |
1931 for element in self.content["value"].getcontent(): |
1679 for element in self.content.getcontent(): |
1932 search_result.extend(element["value"].Search(criteria, parent_infos)) |
1680 search_result.extend(element.Search(criteria, parent_infos)) |
1933 return search_result |
1681 return search_result |
1934 setattr(cls, "Search", Search) |
1682 setattr(cls, "Search", Search) |
1935 |
1683 |
1936 def getx(self): |
1684 def getx(self): |
1937 return self.position.getx() |
1685 return self.position.getx() |
2397 infos["inputs"].append(_getconnectioninfos(self, self.connectionPointIn, True)) |
2132 infos["inputs"].append(_getconnectioninfos(self, self.connectionPointIn, True)) |
2398 infos["outputs"].append(_getconnectioninfos(self, self.connectionPointOut)) |
2133 infos["outputs"].append(_getconnectioninfos(self, self.connectionPointOut)) |
2399 return infos |
2134 return infos |
2400 setattr(cls, "getinfos", getinfos) |
2135 setattr(cls, "getinfos", getinfos) |
2401 |
2136 |
2402 def setconditionContent(self, type, value): |
2137 def setconditionContent(self, condition_type, value): |
2403 if not self.condition: |
2138 if self.condition is None: |
2404 self.addcondition() |
2139 self.addcondition() |
2405 if type == "reference": |
2140 if condition_type == "connection": |
2406 condition = PLCOpenClasses["condition_reference"]() |
2141 condition = PLCOpenParser.CreateElement("connectionPointIn", "condition") |
|
2142 else: |
|
2143 condition = PLCOpenParser.CreateElement(condition_type, "condition") |
|
2144 self.condition.setcontent(condition) |
|
2145 if condition_type == "reference": |
2407 condition.setname(value) |
2146 condition.setname(value) |
2408 elif type == "inline": |
2147 elif condition_type == "inline": |
2409 condition = PLCOpenClasses["condition_inline"]() |
2148 condition.setcontent(PLCOpenParser.CreateElement("ST", "inline")) |
2410 condition.setcontent({"name" : "ST", "value" : PLCOpenClasses["formattedText"]()}) |
|
2411 condition.settext(value) |
2149 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) |
2150 setattr(cls, "setconditionContent", setconditionContent) |
2417 |
2151 |
2418 def getconditionContent(self): |
2152 def getconditionContent(self): |
2419 if self.condition: |
2153 if self.condition is not None: |
2420 content = self.condition.getcontent() |
2154 content = self.condition.getcontent() |
2421 values = {"type" : content["name"]} |
2155 values = {"type" : content.getLocalTag()} |
2422 if values["type"] == "reference": |
2156 if values["type"] == "reference": |
2423 values["value"] = content["value"].getname() |
2157 values["value"] = content.getname() |
2424 elif values["type"] == "inline": |
2158 elif values["type"] == "inline": |
2425 values["value"] = content["value"].gettext() |
2159 values["value"] = content.gettext() |
2426 elif values["type"] == "connectionPointIn": |
2160 elif values["type"] == "connectionPointIn": |
2427 values["type"] = "connection" |
2161 values["type"] = "connection" |
2428 values["value"] = content["value"] |
2162 values["value"] = content |
2429 return values |
2163 return values |
2430 return "" |
2164 return "" |
2431 setattr(cls, "getconditionContent", getconditionContent) |
2165 setattr(cls, "getconditionContent", getconditionContent) |
2432 |
2166 |
2433 def getconditionConnection(self): |
2167 def getconditionConnection(self): |
2434 if self.condition: |
2168 if self.condition is not None: |
2435 content = self.condition.getcontent() |
2169 content = self.condition.getcontent() |
2436 if content["name"] == "connectionPointIn": |
2170 if content.getLocalTag() == "connectionPointIn": |
2437 return content["value"] |
2171 return content |
2438 return None |
2172 return None |
2439 setattr(cls, "getconditionConnection", getconditionConnection) |
2173 setattr(cls, "getconditionConnection", getconditionConnection) |
2440 |
2174 |
2441 def getBoundingBox(self): |
2175 def getBoundingBox(self): |
2442 bbox = _getBoundingBoxSingle(self) |
2176 bbox = _getBoundingBoxSingle(self) |
2443 condition_connection = self.getconditionConnection() |
2177 condition_connection = self.getconditionConnection() |
2444 if condition_connection: |
2178 if condition_connection is not None: |
2445 bbox.union(_getConnectionsBoundingBox(condition_connection)) |
2179 bbox.union(_getConnectionsBoundingBox(condition_connection)) |
2446 return bbox |
2180 return bbox |
2447 setattr(cls, "getBoundingBox", getBoundingBox) |
2181 setattr(cls, "getBoundingBox", getBoundingBox) |
2448 |
2182 |
2449 def translate(self, dx, dy): |
2183 def translate(self, dx, dy): |
2450 _translateSingle(self, dx, dy) |
2184 _translateSingle(self, dx, dy) |
2451 condition_connection = self.getconditionConnection() |
2185 condition_connection = self.getconditionConnection() |
2452 if condition_connection: |
2186 if condition_connection is not None: |
2453 _translateConnections(condition_connection, dx, dy) |
2187 _translateConnections(condition_connection, dx, dy) |
2454 setattr(cls, "translate", translate) |
2188 setattr(cls, "translate", translate) |
2455 |
2189 |
2456 def filterConnections(self, connections): |
2190 def filterConnections(self, connections): |
2457 _filterConnectionsSingle(self, connections) |
2191 _filterConnectionsSingle(self, connections) |
2458 condition_connection = self.getconditionConnection() |
2192 condition_connection = self.getconditionConnection() |
2459 if condition_connection: |
2193 if condition_connection is not None: |
2460 _filterConnections(condition_connection, self.localId, connections) |
2194 _filterConnections(condition_connection, self.localId, connections) |
2461 setattr(cls, "filterConnections", filterConnections) |
2195 setattr(cls, "filterConnections", filterConnections) |
2462 |
2196 |
2463 def updateConnectionsId(self, translation): |
2197 def updateConnectionsId(self, translation): |
2464 connections_end = [] |
2198 connections_end = [] |
2465 if self.connectionPointIn is not None: |
2199 if self.connectionPointIn is not None: |
2466 connections_end = _updateConnectionsId(self.connectionPointIn, translation) |
2200 connections_end = _updateConnectionsId(self.connectionPointIn, translation) |
2467 condition_connection = self.getconditionConnection() |
2201 condition_connection = self.getconditionConnection() |
2468 if condition_connection: |
2202 if condition_connection is not None: |
2469 connections_end.extend(_updateConnectionsId(condition_connection, translation)) |
2203 connections_end.extend(_updateConnectionsId(condition_connection, translation)) |
2470 return _getconnectionsdefinition(self, connections_end) |
2204 return _getconnectionsdefinition(self, connections_end) |
2471 setattr(cls, "updateConnectionsId", updateConnectionsId) |
2205 setattr(cls, "updateConnectionsId", updateConnectionsId) |
2472 |
2206 |
2473 def updateElementName(self, old_name, new_name): |
2207 def updateElementName(self, old_name, new_name): |
2474 if self.condition: |
2208 if self.condition is not None: |
2475 content = self.condition.getcontent() |
2209 content = self.condition.getcontent() |
2476 if content["name"] == "reference": |
2210 content_name = content.getLocalTag() |
2477 if content["value"].getname() == old_name: |
2211 if content_name == "reference": |
2478 content["value"].setname(new_name) |
2212 if content.getname() == old_name: |
2479 elif content["name"] == "inline": |
2213 content.setname(new_name) |
2480 content["value"].updateElementName(old_name, new_name) |
2214 elif content_name == "inline": |
|
2215 content.updateElementName(old_name, new_name) |
2481 setattr(cls, "updateElementName", updateElementName) |
2216 setattr(cls, "updateElementName", updateElementName) |
2482 |
2217 |
2483 def updateElementAddress(self, address_model, new_leading): |
2218 def updateElementAddress(self, address_model, new_leading): |
2484 if self.condition: |
2219 if self.condition is not None: |
2485 content = self.condition.getcontent() |
2220 content = self.condition.getcontent() |
2486 if content["name"] == "reference": |
2221 content_name = content.getLocalTag() |
2487 content["value"].setname(update_address(content["value"].getname(), address_model, new_leading)) |
2222 if content_name == "reference": |
2488 elif content["name"] == "inline": |
2223 content.setname(update_address(content.getname(), address_model, new_leading)) |
2489 content["value"].updateElementAddress(address_model, new_leading) |
2224 elif content_name == "inline": |
|
2225 content.updateElementAddress(address_model, new_leading) |
2490 setattr(cls, "updateElementAddress", updateElementAddress) |
2226 setattr(cls, "updateElementAddress", updateElementAddress) |
2491 |
2227 |
2492 def getconnections(self): |
2228 def getconnections(self): |
2493 condition_connection = self.getconditionConnection() |
2229 condition_connection = self.getconditionConnection() |
2494 if condition_connection: |
2230 if condition_connection is not None: |
2495 return condition_connection.getconnections() |
2231 return condition_connection.getconnections() |
2496 return None |
2232 return None |
2497 setattr(cls, "getconnections", getconnections) |
2233 setattr(cls, "getconnections", getconnections) |
2498 |
2234 |
2499 def Search(self, criteria, parent_infos=[]): |
2235 def Search(self, criteria, parent_infos=[]): |
2500 parent_infos = parent_infos + ["transition", self.getlocalId()] |
2236 parent_infos = parent_infos + ["transition", self.getlocalId()] |
2501 search_result = [] |
2237 search_result = [] |
2502 content = self.condition.getcontent() |
2238 content = self.condition.getcontent() |
2503 if content["name"] == "reference": |
2239 content_name = content.getLocalTag() |
2504 search_result.extend(_Search([("reference", content["value"].getname())], criteria, parent_infos)) |
2240 if content_name == "reference": |
2505 elif content["name"] == "inline": |
2241 search_result.extend(_Search([("reference", content.getname())], criteria, parent_infos)) |
2506 search_result.extend(content["value"].Search(criteria, parent_infos + ["inline"])) |
2242 elif content_name == "inline": |
|
2243 search_result.extend(content.Search(criteria, parent_infos + ["inline"])) |
2507 return search_result |
2244 return search_result |
2508 setattr(cls, "Search", Search) |
2245 setattr(cls, "Search", Search) |
2509 |
2246 |
2510 cls = _initElementClass("selectionDivergence", "sfcObjects_selectionDivergence", "single") |
2247 cls = _initElementClass("selectionDivergence", "sfcObjects", "single") |
2511 if cls: |
2248 if cls: |
2512 setattr(cls, "getinfos", _getdivergenceinfosFunction(True, False)) |
2249 setattr(cls, "getinfos", _getdivergenceinfosFunction(True, False)) |
2513 |
2250 |
2514 cls = _initElementClass("selectionConvergence", "sfcObjects_selectionConvergence", "multiple") |
2251 cls = _initElementClass("selectionConvergence", "sfcObjects", "multiple") |
2515 if cls: |
2252 if cls: |
2516 setattr(cls, "getinfos", _getdivergenceinfosFunction(False, False)) |
2253 setattr(cls, "getinfos", _getdivergenceinfosFunction(False, False)) |
2517 |
2254 |
2518 cls = _initElementClass("simultaneousDivergence", "sfcObjects_simultaneousDivergence", "single") |
2255 cls = _initElementClass("simultaneousDivergence", "sfcObjects", "single") |
2519 if cls: |
2256 if cls: |
2520 setattr(cls, "getinfos", _getdivergenceinfosFunction(True, True)) |
2257 setattr(cls, "getinfos", _getdivergenceinfosFunction(True, True)) |
2521 |
2258 |
2522 cls = _initElementClass("simultaneousConvergence", "sfcObjects_simultaneousConvergence", "multiple") |
2259 cls = _initElementClass("simultaneousConvergence", "sfcObjects", "multiple") |
2523 if cls: |
2260 if cls: |
2524 setattr(cls, "getinfos", _getdivergenceinfosFunction(False, True)) |
2261 setattr(cls, "getinfos", _getdivergenceinfosFunction(False, True)) |
2525 |
2262 |
2526 cls = _initElementClass("jumpStep", "sfcObjects_jumpStep", "single") |
2263 cls = _initElementClass("jumpStep", "sfcObjects", "single") |
2527 if cls: |
2264 if cls: |
2528 def getinfos(self): |
2265 def getinfos(self): |
2529 infos = _getelementinfos(self) |
2266 infos = _getelementinfos(self) |
2530 infos["type"] = "jump" |
2267 infos["type"] = "jump" |
2531 infos["specific_values"]["target"] = self.gettargetName() |
2268 infos["specific_values"]["target"] = self.gettargetName() |
2673 search_result.extend(action.Search(criteria, parent_infos + ["action", idx])) |
2410 search_result.extend(action.Search(criteria, parent_infos + ["action", idx])) |
2674 return search_result |
2411 return search_result |
2675 setattr(cls, "Search", Search) |
2412 setattr(cls, "Search", Search) |
2676 |
2413 |
2677 def _SearchInIOVariable(self, criteria, parent_infos=[]): |
2414 def _SearchInIOVariable(self, criteria, parent_infos=[]): |
2678 return _Search([("expression", self.getexpression())], criteria, parent_infos + ["io_variable", self.getlocalId()]) |
2415 return _Search([("expression", self.expression)], criteria, parent_infos + ["io_variable", self.getlocalId()]) |
2679 |
2416 |
2680 cls = _initElementClass("inVariable", "fbdObjects_inVariable") |
2417 def _UpdateIOElementName(self, old_name, new_name): |
|
2418 if self.expression == old_name: |
|
2419 self.expression = new_name |
|
2420 |
|
2421 def _UpdateIOElementAddress(self, old_name, new_name): |
|
2422 self.expression = update_address(self.expression, address_model, new_leading) |
|
2423 |
|
2424 cls = _initElementClass("inVariable", "fbdObjects") |
2681 if cls: |
2425 if cls: |
2682 setattr(cls, "getinfos", _getvariableinfosFunction("input", False, True)) |
2426 setattr(cls, "getinfos", _getvariableinfosFunction("input", False, True)) |
2683 |
2427 setattr(cls, "updateElementName", _UpdateIOElementName) |
2684 def updateElementName(self, old_name, new_name): |
2428 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) |
2429 setattr(cls, "Search", _SearchInIOVariable) |
2694 |
2430 |
2695 cls = _initElementClass("outVariable", "fbdObjects_outVariable", "single") |
2431 cls = _initElementClass("outVariable", "fbdObjects", "single") |
2696 if cls: |
2432 if cls: |
2697 setattr(cls, "getinfos", _getvariableinfosFunction("output", True, False)) |
2433 setattr(cls, "getinfos", _getvariableinfosFunction("output", True, False)) |
2698 |
2434 setattr(cls, "updateElementName", _UpdateIOElementName) |
2699 def updateElementName(self, old_name, new_name): |
2435 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) |
2436 setattr(cls, "Search", _SearchInIOVariable) |
2709 |
2437 |
2710 cls = _initElementClass("inOutVariable", "fbdObjects_inOutVariable", "single") |
2438 cls = _initElementClass("inOutVariable", "fbdObjects", "single") |
2711 if cls: |
2439 if cls: |
2712 setattr(cls, "getinfos", _getvariableinfosFunction("inout", True, True)) |
2440 setattr(cls, "getinfos", _getvariableinfosFunction("inout", True, True)) |
2713 |
2441 setattr(cls, "updateElementName", _UpdateIOElementName) |
2714 def updateElementName(self, old_name, new_name): |
2442 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) |
2443 setattr(cls, "Search", _SearchInIOVariable) |
2724 |
2444 |
2725 |
2445 |
2726 def _SearchInConnector(self, criteria, parent_infos=[]): |
2446 def _SearchInConnector(self, criteria, parent_infos=[]): |
2727 return _Search([("name", self.getname())], criteria, parent_infos + ["connector", self.getlocalId()]) |
2447 return _Search([("name", self.getname())], criteria, parent_infos + ["connector", self.getlocalId()]) |
2728 |
2448 |
2729 cls = _initElementClass("continuation", "commonObjects_continuation") |
2449 cls = _initElementClass("continuation", "commonObjects") |
2730 if cls: |
2450 if cls: |
2731 setattr(cls, "getinfos", _getconnectorinfosFunction("continuation")) |
2451 setattr(cls, "getinfos", _getconnectorinfosFunction("continuation")) |
2732 setattr(cls, "Search", _SearchInConnector) |
2452 setattr(cls, "Search", _SearchInConnector) |
2733 |
2453 |
2734 def updateElementName(self, old_name, new_name): |
2454 def updateElementName(self, old_name, new_name): |
2735 if self.name == old_name: |
2455 if self.name == old_name: |
2736 self.name = new_name |
2456 self.name = new_name |
2737 setattr(cls, "updateElementName", updateElementName) |
2457 setattr(cls, "updateElementName", updateElementName) |
2738 |
2458 |
2739 cls = _initElementClass("connector", "commonObjects_connector", "single") |
2459 cls = _initElementClass("connector", "commonObjects", "single") |
2740 if cls: |
2460 if cls: |
2741 setattr(cls, "getinfos", _getconnectorinfosFunction("connector")) |
2461 setattr(cls, "getinfos", _getconnectorinfosFunction("connector")) |
2742 setattr(cls, "Search", _SearchInConnector) |
2462 setattr(cls, "Search", _SearchInConnector) |
2743 |
2463 |
2744 def updateElementName(self, old_name, new_name): |
2464 def updateElementName(self, old_name, new_name): |
2745 if self.name == old_name: |
2465 if self.name == old_name: |
2746 self.name = new_name |
2466 self.name = new_name |
2747 setattr(cls, "updateElementName", updateElementName) |
2467 setattr(cls, "updateElementName", updateElementName) |
2748 |
2468 |
2749 cls = PLCOpenClasses.get("connection", None) |
2469 cls = PLCOpenParser.GetElementClass("connection") |
2750 if cls: |
2470 if cls: |
2751 def setpoints(self, points): |
2471 def setpoints(self, points): |
2752 self.position = [] |
2472 positions = [] |
2753 for point in points: |
2473 for point in points: |
2754 position = PLCOpenClasses["position"]() |
2474 position = PLCOpenParser.CreateElement("position", "connection") |
2755 position.setx(point.x) |
2475 position.setx(point.x) |
2756 position.sety(point.y) |
2476 position.sety(point.y) |
2757 self.position.append(position) |
2477 positions.append(position) |
|
2478 self.position = positions |
2758 setattr(cls, "setpoints", setpoints) |
2479 setattr(cls, "setpoints", setpoints) |
2759 |
2480 |
2760 def getpoints(self): |
2481 def getpoints(self): |
2761 points = [] |
2482 points = [] |
2762 for position in self.position: |
2483 for position in self.position: |
2763 points.append((position.getx(),position.gety())) |
2484 points.append((position.getx(),position.gety())) |
2764 return points |
2485 return points |
2765 setattr(cls, "getpoints", getpoints) |
2486 setattr(cls, "getpoints", getpoints) |
2766 |
2487 |
2767 cls = PLCOpenClasses.get("connectionPointIn", None) |
2488 cls = PLCOpenParser.GetElementClass("connectionPointIn") |
2768 if cls: |
2489 if cls: |
2769 def setrelPositionXY(self, x, y): |
2490 def setrelPositionXY(self, x, y): |
2770 self.relPosition = PLCOpenClasses["position"]() |
2491 self.relPosition = PLCOpenParser.CreateElement("relPosition", "connectionPointIn") |
2771 self.relPosition.setx(x) |
2492 self.relPosition.setx(x) |
2772 self.relPosition.sety(y) |
2493 self.relPosition.sety(y) |
2773 setattr(cls, "setrelPositionXY", setrelPositionXY) |
2494 setattr(cls, "setrelPositionXY", setrelPositionXY) |
2774 |
2495 |
2775 def getrelPositionXY(self): |
2496 def getrelPositionXY(self): |
2776 if self.relPosition: |
2497 if self.relPosition is not None: |
2777 return self.relPosition.getx(), self.relPosition.gety() |
2498 return self.relPosition.getx(), self.relPosition.gety() |
2778 else: |
2499 return self.relPosition |
2779 return self.relPosition |
|
2780 setattr(cls, "getrelPositionXY", getrelPositionXY) |
2500 setattr(cls, "getrelPositionXY", getrelPositionXY) |
2781 |
2501 |
2782 def addconnection(self): |
2502 def addconnection(self): |
2783 if not self.content: |
2503 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) |
2504 setattr(cls, "addconnection", addconnection) |
2788 |
2505 |
2789 def removeconnection(self, idx): |
2506 def removeconnection(self, idx): |
2790 if self.content: |
2507 if len(self.content) > idx: |
2791 self.content["value"].pop(idx) |
2508 self.remove(self.content[idx]) |
2792 if len(self.content["value"]) == 0: |
|
2793 self.content = None |
|
2794 setattr(cls, "removeconnection", removeconnection) |
2509 setattr(cls, "removeconnection", removeconnection) |
2795 |
2510 |
2796 def removeconnections(self): |
2511 def removeconnections(self): |
2797 if self.content: |
2512 self.content = None |
2798 self.content = None |
|
2799 setattr(cls, "removeconnections", removeconnections) |
2513 setattr(cls, "removeconnections", removeconnections) |
2800 |
2514 |
|
2515 connection_xpath = PLCOpen_XPath("ppx:connection") |
|
2516 connection_by_position_xpath = PLCOpen_XPath("ppx:connection[position()=$pos]") |
2801 def getconnections(self): |
2517 def getconnections(self): |
2802 if self.content: |
2518 return connection_xpath(self) |
2803 return self.content["value"] |
|
2804 return [] |
|
2805 setattr(cls, "getconnections", getconnections) |
2519 setattr(cls, "getconnections", getconnections) |
2806 |
2520 |
2807 def setconnectionId(self, idx, id): |
2521 def getconnection(self, idx): |
2808 if self.content: |
2522 connection = connection_by_position_xpath(self, pos=idx+1) |
2809 self.content["value"][idx].setrefLocalId(id) |
2523 if len(connection) > 0: |
|
2524 return connection[0] |
|
2525 return None |
|
2526 setattr(cls, "getconnection", getconnection) |
|
2527 |
|
2528 def setconnectionId(self, idx, local_id): |
|
2529 connection = self.getconnection(idx) |
|
2530 if connection is not None: |
|
2531 connection.setrefLocalId(local_id) |
2810 setattr(cls, "setconnectionId", setconnectionId) |
2532 setattr(cls, "setconnectionId", setconnectionId) |
2811 |
2533 |
2812 def getconnectionId(self, idx): |
2534 def getconnectionId(self, idx): |
2813 if self.content: |
2535 connection = self.getconnection(idx) |
2814 return self.content["value"][idx].getrefLocalId() |
2536 if connection is not None: |
|
2537 return connection.getrefLocalId() |
2815 return None |
2538 return None |
2816 setattr(cls, "getconnectionId", getconnectionId) |
2539 setattr(cls, "getconnectionId", getconnectionId) |
2817 |
2540 |
2818 def setconnectionPoints(self, idx, points): |
2541 def setconnectionPoints(self, idx, points): |
2819 if self.content: |
2542 connection = self.getconnection(idx) |
2820 self.content["value"][idx].setpoints(points) |
2543 if connection is not None: |
|
2544 connection.setpoints(points) |
2821 setattr(cls, "setconnectionPoints", setconnectionPoints) |
2545 setattr(cls, "setconnectionPoints", setconnectionPoints) |
2822 |
2546 |
2823 def getconnectionPoints(self, idx): |
2547 def getconnectionPoints(self, idx): |
2824 if self.content: |
2548 connection = self.getconnection(idx) |
2825 return self.content["value"][idx].getpoints() |
2549 if connection is not None: |
|
2550 return connection.getpoints() |
2826 return [] |
2551 return [] |
2827 setattr(cls, "getconnectionPoints", getconnectionPoints) |
2552 setattr(cls, "getconnectionPoints", getconnectionPoints) |
2828 |
2553 |
2829 def setconnectionParameter(self, idx, parameter): |
2554 def setconnectionParameter(self, idx, parameter): |
2830 if self.content: |
2555 connection = self.getconnection(idx) |
2831 self.content["value"][idx].setformalParameter(parameter) |
2556 if connection is not None: |
|
2557 connection.setformalParameter(parameter) |
2832 setattr(cls, "setconnectionParameter", setconnectionParameter) |
2558 setattr(cls, "setconnectionParameter", setconnectionParameter) |
2833 |
2559 |
2834 def getconnectionParameter(self, idx): |
2560 def getconnectionParameter(self, idx): |
2835 if self.content: |
2561 connection = self.getconnection(idx) |
2836 return self.content["value"][idx].getformalParameter() |
2562 if connection is not None: |
|
2563 return connection.getformalParameter() |
2837 return None |
2564 return None |
2838 setattr(cls, "getconnectionParameter", getconnectionParameter) |
2565 setattr(cls, "getconnectionParameter", getconnectionParameter) |
2839 |
2566 |
2840 cls = PLCOpenClasses.get("connectionPointOut", None) |
2567 cls = PLCOpenParser.GetElementClass("connectionPointOut") |
2841 if cls: |
2568 if cls: |
2842 def setrelPositionXY(self, x, y): |
2569 def setrelPositionXY(self, x, y): |
2843 self.relPosition = PLCOpenClasses["position"]() |
2570 self.relPosition = PLCOpenParser.CreateElement("relPosition", "connectionPointOut") |
2844 self.relPosition.setx(x) |
2571 self.relPosition.setx(x) |
2845 self.relPosition.sety(y) |
2572 self.relPosition.sety(y) |
2846 setattr(cls, "setrelPositionXY", setrelPositionXY) |
2573 setattr(cls, "setrelPositionXY", setrelPositionXY) |
2847 |
2574 |
2848 def getrelPositionXY(self): |
2575 def getrelPositionXY(self): |
2849 if self.relPosition: |
2576 if self.relPosition is not None: |
2850 return self.relPosition.getx(), self.relPosition.gety() |
2577 return self.relPosition.getx(), self.relPosition.gety() |
2851 return self.relPosition |
2578 return self.relPosition |
2852 setattr(cls, "getrelPositionXY", getrelPositionXY) |
2579 setattr(cls, "getrelPositionXY", getrelPositionXY) |
2853 |
2580 |
2854 cls = PLCOpenClasses.get("value", None) |
2581 cls = PLCOpenParser.GetElementClass("value") |
2855 if cls: |
2582 if cls: |
2856 def setvalue(self, value): |
2583 def setvalue(self, value): |
2857 value = value.strip() |
2584 value = value.strip() |
2858 if value.startswith("[") and value.endswith("]"): |
2585 if value.startswith("[") and value.endswith("]"): |
2859 arrayValue = PLCOpenClasses["value_arrayValue"]() |
2586 content = PLCOpenParser.CreateElement("arrayValue", "value") |
2860 self.content = {"name" : "arrayValue", "value" : arrayValue} |
|
2861 elif value.startswith("(") and value.endswith(")"): |
2587 elif value.startswith("(") and value.endswith(")"): |
2862 structValue = PLCOpenClasses["value_structValue"]() |
2588 content = PLCOpenParser.CreateElement("structValue", "value") |
2863 self.content = {"name" : "structValue", "value" : structValue} |
|
2864 else: |
2589 else: |
2865 simpleValue = PLCOpenClasses["value_simpleValue"]() |
2590 content = PLCOpenParser.CreateElement("simpleValue", "value") |
2866 self.content = {"name" : "simpleValue", "value": simpleValue} |
2591 content.setvalue(value) |
2867 self.content["value"].setvalue(value) |
2592 self.setcontent(content) |
2868 setattr(cls, "setvalue", setvalue) |
2593 setattr(cls, "setvalue", setvalue) |
2869 |
2594 |
2870 def getvalue(self): |
2595 def getvalue(self): |
2871 return self.content["value"].getvalue() |
2596 return self.content.getvalue() |
2872 setattr(cls, "getvalue", getvalue) |
2597 setattr(cls, "getvalue", getvalue) |
2873 |
2598 |
2874 def extractValues(values): |
2599 def extractValues(values): |
2875 items = values.split(",") |
2600 items = values.split(",") |
2876 i = 1 |
2601 i = 1 |