120 end = TextLenInRowColumn(text[:result.end() - 1]) |
122 end = TextLenInRowColumn(text[:result.end() - 1]) |
121 test_result.append((start, end, "\n".join(lines[start[0]:end[0] + 1]))) |
123 test_result.append((start, end, "\n".join(lines[start[0]:end[0] + 1]))) |
122 result = criteria["pattern"].search(text, result.end()) |
124 result = criteria["pattern"].search(text, result.end()) |
123 return test_result |
125 return test_result |
124 |
126 |
125 PLCOpenClasses = GenerateClassesFromXSD(os.path.join(os.path.split(__file__)[0], "tc6_xml_v201.xsd")) |
127 PLCOpenParser = GenerateParserFromXSD(os.path.join(os.path.split(__file__)[0], "tc6_xml_v201.xsd")) |
126 |
128 PLCOpen_XPath = lambda xpath: etree.XPath(xpath, namespaces=PLCOpenParser.NSMAP) |
127 ElementNameToClass = {} |
129 |
128 |
130 LOAD_POU_PROJECT_TEMPLATE = """ |
129 cls = PLCOpenClasses.get("formattedText", None) |
131 <project xmlns:ns1="http://www.plcopen.org/xml/tc6_0201" |
|
132 xmlns:xhtml="http://www.w3.org/1999/xhtml" |
|
133 xmlns:xsd="http://www.w3.org/2001/XMLSchema" |
|
134 xmlns="http://www.plcopen.org/xml/tc6_0201"> |
|
135 <fileHeader companyName="" productName="" productVersion="" |
|
136 creationDateTime="1970-01-01T00:00:00"/> |
|
137 <contentHeader name="paste_project"> |
|
138 <coordinateInfo> |
|
139 <fbd><scaling x="0" y="0"/></fbd> |
|
140 <ld><scaling x="0" y="0"/></ld> |
|
141 <sfc><scaling x="0" y="0"/></sfc> |
|
142 </coordinateInfo> |
|
143 </contentHeader> |
|
144 <types> |
|
145 <dataTypes/> |
|
146 <pous>%s</pous> |
|
147 </types> |
|
148 <instances> |
|
149 <configurations/> |
|
150 </instances> |
|
151 </project> |
|
152 """ |
|
153 |
|
154 def LOAD_POU_INSTANCES_PROJECT_TEMPLATE(body_type): |
|
155 return LOAD_POU_PROJECT_TEMPLATE % """ |
|
156 <pou name="paste_pou" pouType="program"> |
|
157 <body> |
|
158 <%(body_type)s>%%s</%(body_type)s> |
|
159 </body> |
|
160 </pou>""" % locals() |
|
161 |
|
162 PLCOpen_v1_file = open(os.path.join(os.path.split(__file__)[0], "TC6_XML_V10_B.xsd")) |
|
163 PLCOpen_v1_xml = PLCOpen_v1_file.read() |
|
164 PLCOpen_v1_file.close() |
|
165 PLCOpen_v1_xml = PLCOpen_v1_xml.replace( |
|
166 "http://www.plcopen.org/xml/tc6.xsd", |
|
167 "http://www.plcopen.org/xml/tc6_0201") |
|
168 PLCOpen_v1_xsd = etree.XMLSchema(etree.fromstring(PLCOpen_v1_xml)) |
|
169 |
|
170 # XPath for file compatibility process |
|
171 ProjectResourcesXPath = PLCOpen_XPath("ppx:instances/ppx:configurations/ppx:configuration/ppx:resource") |
|
172 ResourceInstancesXpath = PLCOpen_XPath("ppx:pouInstance | ppx:task/ppx:pouInstance") |
|
173 TransitionsConditionXPath = PLCOpen_XPath("ppx:types/ppx:pous/ppx:pou/ppx:body/*/ppx:transition/ppx:condition") |
|
174 ConditionConnectionsXPath = PLCOpen_XPath("ppx:connection") |
|
175 ActionBlocksXPath = PLCOpen_XPath("ppx:types/ppx:pous/ppx:pou/ppx:body/*/ppx:actionBlock") |
|
176 ActionBlocksConnectionPointOutXPath = PLCOpen_XPath("ppx:connectionPointOut") |
|
177 |
|
178 def LoadProjectXML(project_xml): |
|
179 project_xml = project_xml.replace( |
|
180 "http://www.plcopen.org/xml/tc6.xsd", |
|
181 "http://www.plcopen.org/xml/tc6_0201") |
|
182 for cre, repl in [ |
|
183 (re.compile("(?<!<xhtml:p>)(?:<!\[CDATA\[)"), "<xhtml:p><![CDATA["), |
|
184 (re.compile("(?:]]>)(?!</xhtml:p>)"), "]]></xhtml:p>")]: |
|
185 project_xml = cre.sub(repl, project_xml) |
|
186 |
|
187 try: |
|
188 tree, error = PLCOpenParser.LoadXMLString(project_xml) |
|
189 if error is None: |
|
190 return tree, None |
|
191 |
|
192 if PLCOpen_v1_xsd.validate(tree): |
|
193 # Make file compatible with PLCOpen v2 |
|
194 |
|
195 # Update resource interval value |
|
196 for resource in ProjectResourcesXPath(tree): |
|
197 for task in resource.gettask(): |
|
198 interval = task.get("interval") |
|
199 if interval is not None: |
|
200 result = time_model.match(interval) |
|
201 if result is not None: |
|
202 values = result.groups() |
|
203 time_values = [int(v) for v in values[:2]] |
|
204 seconds = float(values[2]) |
|
205 time_values.extend([int(seconds), int((seconds % 1) * 1000000)]) |
|
206 text = "T#" |
|
207 if time_values[0] != 0: |
|
208 text += "%dh"%time_values[0] |
|
209 if time_values[1] != 0: |
|
210 text += "%dm"%time_values[1] |
|
211 if time_values[2] != 0: |
|
212 text += "%ds"%time_values[2] |
|
213 if time_values[3] != 0: |
|
214 if time_values[3] % 1000 != 0: |
|
215 text += "%.3fms"%(float(time_values[3]) / 1000) |
|
216 else: |
|
217 text += "%dms"%(time_values[3] / 1000) |
|
218 task.set("interval", text) |
|
219 |
|
220 # Update resources pou instance attributes |
|
221 for pouInstance in ResourceInstancesXpath(resource): |
|
222 type_name = pouInstance.attrib.pop("type") |
|
223 if type_name is not None: |
|
224 pouInstance.set("typeName", type_name) |
|
225 |
|
226 # Update transitions condition |
|
227 for transition_condition in TransitionsConditionXPath(tree): |
|
228 connections = ConditionConnectionsXPath(transition_condition) |
|
229 if len(connections) > 0: |
|
230 connectionPointIn = PLCOpenParser.CreateElement("connectionPointIn", "condition") |
|
231 transition_condition.setcontent(connectionPointIn) |
|
232 connectionPointIn.setrelPositionXY(0, 0) |
|
233 for connection in connections: |
|
234 connectionPointIn.append(connection) |
|
235 |
|
236 # Update actionBlocks |
|
237 for actionBlock in ActionBlocksXPath(tree): |
|
238 for connectionPointOut in ActionBlocksConnectionPointOutXPath(actionBlock): |
|
239 actionBlock.remove(connectionPointOut) |
|
240 |
|
241 for action in actionBlock.getaction(): |
|
242 action.set("localId", "0") |
|
243 relPosition = PLCOpenParser.CreateElement("relPosition", "action") |
|
244 relPosition.set("x", "0") |
|
245 relPosition.set("y", "0") |
|
246 action.setrelPosition(relPosition) |
|
247 |
|
248 return tree, None |
|
249 |
|
250 return tree, error |
|
251 |
|
252 except Exception, e: |
|
253 return None, e.message |
|
254 |
|
255 def LoadProject(filepath): |
|
256 project_file = open(filepath) |
|
257 project_xml = project_file.read() |
|
258 project_file.close() |
|
259 return LoadProjectXML(project_xml) |
|
260 |
|
261 project_pou_xpath = PLCOpen_XPath("/ppx:project/ppx:types/ppx:pous/ppx:pou") |
|
262 def LoadPou(xml_string): |
|
263 root, error = LoadProjectXML(LOAD_POU_PROJECT_TEMPLATE % xml_string) |
|
264 return project_pou_xpath(root)[0], error |
|
265 |
|
266 project_pou_instances_xpath = { |
|
267 body_type: PLCOpen_XPath( |
|
268 "/ppx:project/ppx:types/ppx:pous/ppx:pou[@name='paste_pou']/ppx:body/ppx:%s/*" % body_type) |
|
269 for body_type in ["FBD", "LD", "SFC"]} |
|
270 def LoadPouInstances(xml_string, body_type): |
|
271 root, error = LoadProjectXML( |
|
272 LOAD_POU_INSTANCES_PROJECT_TEMPLATE(body_type) % xml_string) |
|
273 return project_pou_instances_xpath[body_type](root), error |
|
274 |
|
275 def SaveProject(project, filepath): |
|
276 project_file = open(filepath, 'w') |
|
277 project_file.write(etree.tostring( |
|
278 project, |
|
279 pretty_print=True, |
|
280 xml_declaration=True, |
|
281 encoding='utf-8')) |
|
282 project_file.close() |
|
283 |
|
284 cls = PLCOpenParser.GetElementClass("formattedText") |
130 if cls: |
285 if cls: |
131 def updateElementName(self, old_name, new_name): |
286 def updateElementName(self, old_name, new_name): |
132 text = self.text |
287 text = self.getanyText() |
133 index = text.find(old_name) |
288 index = text.find(old_name) |
134 while index != -1: |
289 while index != -1: |
135 if index > 0 and (text[index - 1].isalnum() or text[index - 1] == "_"): |
290 if index > 0 and (text[index - 1].isalnum() or text[index - 1] == "_"): |
136 index = text.find(old_name, index + len(old_name)) |
291 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)] == "_"): |
292 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)) |
293 index = text.find(old_name, index + len(old_name)) |
139 else: |
294 else: |
140 text = text[:index] + new_name + text[index + len(old_name):] |
295 text = text[:index] + new_name + text[index + len(old_name):] |
141 index = text.find(old_name, index + len(new_name)) |
296 index = text.find(old_name, index + len(new_name)) |
142 self.text = text |
297 self.setanyText(text) |
143 setattr(cls, "updateElementName", updateElementName) |
298 setattr(cls, "updateElementName", updateElementName) |
144 |
299 |
145 def updateElementAddress(self, address_model, new_leading): |
300 def updateElementAddress(self, address_model, new_leading): |
146 text = self.text |
301 text = self.getanyText() |
147 startpos = 0 |
302 startpos = 0 |
148 result = address_model.search(text, startpos) |
303 result = address_model.search(text, startpos) |
149 while result is not None: |
304 while result is not None: |
150 groups = result.groups() |
305 groups = result.groups() |
151 new_address = groups[0] + new_leading + groups[2] |
306 new_address = groups[0] + new_leading + groups[2] |
152 text = text[:result.start()] + new_address + text[result.end():] |
307 text = text[:result.start()] + new_address + text[result.end():] |
153 startpos = result.start() + len(new_address) |
308 startpos = result.start() + len(new_address) |
154 result = address_model.search(self.text, startpos) |
309 result = address_model.search(text, startpos) |
155 self.text = text |
310 self.setanyText(text) |
156 setattr(cls, "updateElementAddress", updateElementAddress) |
311 setattr(cls, "updateElementAddress", updateElementAddress) |
157 |
312 |
158 def hasblock(self, block_type): |
313 def hasblock(self, block_type): |
159 text = self.text.upper() |
314 text = self.getanyText().upper() |
160 index = text.find(block_type.upper()) |
315 index = text.find(block_type.upper()) |
161 while index != -1: |
316 while index != -1: |
162 if (not (index > 0 and (text[index - 1].isalnum() or text[index - 1] == "_")) and |
317 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)] != "(")): |
318 not (index < len(text) - len(block_type) and text[index + len(block_type)] != "(")): |
164 return True |
319 return True |
165 index = text.find(block_type.upper(), index + len(block_type)) |
320 index = text.find(block_type.upper(), index + len(block_type)) |
166 return False |
321 return False |
167 setattr(cls, "hasblock", hasblock) |
322 setattr(cls, "hasblock", hasblock) |
168 |
323 |
169 def Search(self, criteria, parent_infos): |
324 def Search(self, criteria, parent_infos): |
170 return [(tuple(parent_infos),) + result for result in TestTextElement(self.gettext(), criteria)] |
325 return [(tuple(parent_infos),) + result for result in TestTextElement(self.getanyText(), criteria)] |
171 setattr(cls, "Search", Search) |
326 setattr(cls, "Search", Search) |
172 |
327 |
173 cls = PLCOpenClasses.get("project", None) |
328 cls = PLCOpenParser.GetElementClass("project") |
174 if cls: |
329 if cls: |
175 cls.singleLineAttributes = False |
|
176 cls.EnumeratedDataTypeValues = {} |
|
177 cls.CustomDataTypeRange = {} |
|
178 cls.CustomTypeHierarchy = {} |
|
179 cls.ElementUsingTree = {} |
|
180 cls.CustomBlockTypes = [] |
|
181 |
330 |
182 def setname(self, name): |
331 def setname(self, name): |
183 self.contentHeader.setname(name) |
332 self.contentHeader.setname(name) |
184 setattr(cls, "setname", setname) |
333 setattr(cls, "setname", setname) |
185 |
334 |
186 def getname(self): |
335 def getname(self): |
187 return self.contentHeader.getname() |
336 return self.contentHeader.getname() |
188 setattr(cls, "getname", getname) |
337 setattr(cls, "getname", getname) |
189 |
338 |
190 def getfileHeader(self): |
339 def getfileHeader(self): |
191 fileheader = {} |
340 fileheader_obj = self.fileHeader |
192 for name, value in [("companyName", self.fileHeader.getcompanyName()), |
341 return { |
193 ("companyURL", self.fileHeader.getcompanyURL()), |
342 attr: value if value is not None else "" |
194 ("productName", self.fileHeader.getproductName()), |
343 for attr, value in [ |
195 ("productVersion", self.fileHeader.getproductVersion()), |
344 ("companyName", fileheader_obj.getcompanyName()), |
196 ("productRelease", self.fileHeader.getproductRelease()), |
345 ("companyURL", fileheader_obj.getcompanyURL()), |
197 ("creationDateTime", self.fileHeader.getcreationDateTime()), |
346 ("productName", fileheader_obj.getproductName()), |
198 ("contentDescription", self.fileHeader.getcontentDescription())]: |
347 ("productVersion", fileheader_obj.getproductVersion()), |
|
348 ("productRelease", fileheader_obj.getproductRelease()), |
|
349 ("creationDateTime", fileheader_obj.getcreationDateTime()), |
|
350 ("contentDescription", fileheader_obj.getcontentDescription())] |
|
351 } |
|
352 setattr(cls, "getfileHeader", getfileHeader) |
|
353 |
|
354 def setfileHeader(self, fileheader): |
|
355 fileheader_obj = self.fileHeader |
|
356 for attr in ["companyName", "companyURL", "productName", |
|
357 "productVersion", "productRelease", "creationDateTime", |
|
358 "contentDescription"]: |
|
359 value = fileheader.get(attr) |
199 if value is not None: |
360 if value is not None: |
200 fileheader[name] = value |
361 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) |
362 setattr(cls, "setfileHeader", setfileHeader) |
222 |
363 |
223 def getcontentHeader(self): |
364 def getcontentHeader(self): |
224 contentheader = {} |
365 contentheader_obj = self.contentHeader |
225 for name, value in [("projectName", self.contentHeader.getname()), |
366 contentheader = { |
226 ("projectVersion", self.contentHeader.getversion()), |
367 attr: value if value is not None else "" |
227 ("modificationDateTime", self.contentHeader.getmodificationDateTime()), |
368 for attr, value in [ |
228 ("organization", self.contentHeader.getorganization()), |
369 ("projectName", contentheader_obj.getname()), |
229 ("authorName", self.contentHeader.getauthor()), |
370 ("projectVersion", contentheader_obj.getversion()), |
230 ("language", self.contentHeader.getlanguage())]: |
371 ("modificationDateTime", contentheader_obj.getmodificationDateTime()), |
231 if value is not None: |
372 ("organization", contentheader_obj.getorganization()), |
232 contentheader[name] = value |
373 ("authorName", contentheader_obj.getauthor()), |
233 else: |
374 ("language", contentheader_obj.getlanguage())] |
234 contentheader[name] = "" |
375 } |
235 contentheader["pageSize"] = self.contentHeader.getpageSize() |
376 contentheader["pageSize"] = self.contentHeader.getpageSize() |
236 contentheader["scaling"] = self.contentHeader.getscaling() |
377 contentheader["scaling"] = self.contentHeader.getscaling() |
237 return contentheader |
378 return contentheader |
238 setattr(cls, "getcontentHeader", getcontentHeader) |
379 setattr(cls, "getcontentHeader", getcontentHeader) |
239 |
380 |
240 def setcontentHeader(self, contentheader): |
381 def setcontentHeader(self, contentheader): |
241 if contentheader.has_key("projectName"): |
382 contentheader_obj = self.contentHeader |
242 self.contentHeader.setname(contentheader["projectName"]) |
383 for attr, value in contentheader.iteritems(): |
243 if contentheader.has_key("projectVersion"): |
384 func = {"projectName": contentheader_obj.setname, |
244 self.contentHeader.setversion(contentheader["projectVersion"]) |
385 "projectVersion": contentheader_obj.setversion, |
245 if contentheader.has_key("modificationDateTime"): |
386 "authorName": contentheader_obj.setauthor, |
246 self.contentHeader.setmodificationDateTime(contentheader["modificationDateTime"]) |
387 "pageSize": lambda v: contentheader_obj.setpageSize(*v), |
247 if contentheader.has_key("organization"): |
388 "scaling": contentheader_obj.setscaling}.get(attr) |
248 self.contentHeader.setorganization(contentheader["organization"]) |
389 if func is not None: |
249 if contentheader.has_key("authorName"): |
390 func(value) |
250 self.contentHeader.setauthor(contentheader["authorName"]) |
391 elif attr in ["modificationDateTime", "organization", "language"]: |
251 if contentheader.has_key("language"): |
392 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) |
393 setattr(cls, "setcontentHeader", setcontentHeader) |
258 |
394 |
259 def getdataTypes(self): |
395 def gettypeElementFunc(element_type): |
260 return self.types.getdataTypeElements() |
396 elements_xpath = PLCOpen_XPath( |
|
397 "ppx:types/ppx:%(element_type)ss/ppx:%(element_type)s[@name=$name]" % locals()) |
|
398 def gettypeElement(self, name): |
|
399 elements = elements_xpath(self, name=name) |
|
400 if len(elements) == 1: |
|
401 return elements[0] |
|
402 return None |
|
403 return gettypeElement |
|
404 |
|
405 datatypes_xpath = PLCOpen_XPath("ppx:types/ppx:dataTypes/ppx:dataType") |
|
406 filtered_datatypes_xpath = PLCOpen_XPath( |
|
407 "ppx:types/ppx:dataTypes/ppx:dataType[@name!=$exclude]") |
|
408 def getdataTypes(self, exclude=None): |
|
409 if exclude is not None: |
|
410 return filtered_datatypes_xpath(self, exclude=exclude) |
|
411 return datatypes_xpath(self) |
261 setattr(cls, "getdataTypes", getdataTypes) |
412 setattr(cls, "getdataTypes", getdataTypes) |
262 |
413 |
263 def getdataType(self, name): |
414 setattr(cls, "getdataType", gettypeElementFunc("dataType")) |
264 return self.types.getdataTypeElement(name) |
|
265 setattr(cls, "getdataType", getdataType) |
|
266 |
415 |
267 def appenddataType(self, name): |
416 def appenddataType(self, name): |
268 if self.CustomTypeHierarchy.has_key(name): |
417 if self.getdataType(name) is not None: |
269 raise ValueError, "\"%s\" Data Type already exists !!!"%name |
418 raise ValueError, "\"%s\" Data Type already exists !!!"%name |
270 self.types.appenddataTypeElement(name) |
419 self.types.appenddataTypeElement(name) |
271 self.AddCustomDataType(self.getdataType(name)) |
|
272 setattr(cls, "appenddataType", appenddataType) |
420 setattr(cls, "appenddataType", appenddataType) |
273 |
421 |
274 def insertdataType(self, index, datatype): |
422 def insertdataType(self, index, datatype): |
275 self.types.insertdataTypeElement(index, datatype) |
423 self.types.insertdataTypeElement(index, datatype) |
276 self.AddCustomDataType(datatype) |
|
277 setattr(cls, "insertdataType", insertdataType) |
424 setattr(cls, "insertdataType", insertdataType) |
278 |
425 |
279 def removedataType(self, name): |
426 def removedataType(self, name): |
280 self.types.removedataTypeElement(name) |
427 self.types.removedataTypeElement(name) |
281 self.RefreshDataTypeHierarchy() |
|
282 self.RefreshElementUsingTree() |
|
283 setattr(cls, "removedataType", removedataType) |
428 setattr(cls, "removedataType", removedataType) |
284 |
429 |
285 def getpous(self): |
430 def getpous(self, exclude=None, filter=[]): |
286 return self.types.getpouElements() |
431 return self.xpath( |
|
432 "ppx:types/ppx:pous/ppx:pou%s%s" % |
|
433 (("[@name!='%s']" % exclude) if exclude is not None else '', |
|
434 ("[%s]" % " or ".join( |
|
435 map(lambda x: "@pouType='%s'" % x, filter))) |
|
436 if len(filter) > 0 else ""), |
|
437 namespaces=PLCOpenParser.NSMAP) |
287 setattr(cls, "getpous", getpous) |
438 setattr(cls, "getpous", getpous) |
288 |
439 |
289 def getpou(self, name): |
440 setattr(cls, "getpou", gettypeElementFunc("pou")) |
290 return self.types.getpouElement(name) |
|
291 setattr(cls, "getpou", getpou) |
|
292 |
441 |
293 def appendpou(self, name, pou_type, body_type): |
442 def appendpou(self, name, pou_type, body_type): |
294 self.types.appendpouElement(name, pou_type, body_type) |
443 self.types.appendpouElement(name, pou_type, body_type) |
295 self.AddCustomBlockType(self.getpou(name)) |
|
296 setattr(cls, "appendpou", appendpou) |
444 setattr(cls, "appendpou", appendpou) |
297 |
445 |
298 def insertpou(self, index, pou): |
446 def insertpou(self, index, pou): |
299 self.types.insertpouElement(index, pou) |
447 self.types.insertpouElement(index, pou) |
300 self.AddCustomBlockType(pou) |
|
301 setattr(cls, "insertpou", insertpou) |
448 setattr(cls, "insertpou", insertpou) |
302 |
449 |
303 def removepou(self, name): |
450 def removepou(self, name): |
304 self.types.removepouElement(name) |
451 self.types.removepouElement(name) |
305 self.RefreshCustomBlockTypes() |
|
306 self.RefreshElementUsingTree() |
|
307 setattr(cls, "removepou", removepou) |
452 setattr(cls, "removepou", removepou) |
308 |
453 |
|
454 configurations_xpath = PLCOpen_XPath( |
|
455 "ppx:instances/ppx:configurations/ppx:configuration") |
309 def getconfigurations(self): |
456 def getconfigurations(self): |
310 configurations = self.instances.configurations.getconfiguration() |
457 return configurations_xpath(self) |
311 if configurations: |
|
312 return configurations |
|
313 return [] |
|
314 setattr(cls, "getconfigurations", getconfigurations) |
458 setattr(cls, "getconfigurations", getconfigurations) |
315 |
459 |
|
460 configuration_xpath = PLCOpen_XPath( |
|
461 "ppx:instances/ppx:configurations/ppx:configuration[@name=$name]") |
316 def getconfiguration(self, name): |
462 def getconfiguration(self, name): |
317 for configuration in self.instances.configurations.getconfiguration(): |
463 configurations = configuration_xpath(self, name=name) |
318 if configuration.getname() == name: |
464 if len(configurations) == 1: |
319 return configuration |
465 return configurations[0] |
320 return None |
466 return None |
321 setattr(cls, "getconfiguration", getconfiguration) |
467 setattr(cls, "getconfiguration", getconfiguration) |
322 |
468 |
323 def addconfiguration(self, name): |
469 def addconfiguration(self, name): |
324 for configuration in self.instances.configurations.getconfiguration(): |
470 if self.getconfiguration(name) is not None: |
325 if configuration.getname() == name: |
471 raise ValueError, _("\"%s\" configuration already exists !!!") % name |
326 raise ValueError, _("\"%s\" configuration already exists !!!")%name |
472 new_configuration = PLCOpenParser.CreateElement("configuration", "configurations") |
327 new_configuration = PLCOpenClasses["configurations_configuration"]() |
|
328 new_configuration.setname(name) |
473 new_configuration.setname(name) |
329 self.instances.configurations.appendconfiguration(new_configuration) |
474 self.instances.configurations.appendconfiguration(new_configuration) |
330 setattr(cls, "addconfiguration", addconfiguration) |
475 setattr(cls, "addconfiguration", addconfiguration) |
331 |
476 |
332 def removeconfiguration(self, name): |
477 def removeconfiguration(self, name): |
333 found = False |
478 configuration = self.getconfiguration(name) |
334 for idx, configuration in enumerate(self.instances.configurations.getconfiguration()): |
479 if configuration is None: |
335 if configuration.getname() == name: |
480 raise ValueError, ("\"%s\" configuration doesn't exist !!!") % name |
336 self.instances.configurations.removeconfiguration(idx) |
481 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) |
482 setattr(cls, "removeconfiguration", removeconfiguration) |
342 |
483 |
|
484 resources_xpath = PLCOpen_XPath( |
|
485 "ppx:instances/ppx:configurations/ppx:configuration[@name=$configname]/ppx:resource[@name=$name]") |
343 def getconfigurationResource(self, config_name, name): |
486 def getconfigurationResource(self, config_name, name): |
344 configuration = self.getconfiguration(config_name) |
487 resources = resources_xpath(self, configname=config_name, name=name) |
345 if configuration: |
488 if len(resources) == 1: |
346 for resource in configuration.getresource(): |
489 return resources[0] |
347 if resource.getname() == name: |
|
348 return resource |
|
349 return None |
490 return None |
350 setattr(cls, "getconfigurationResource", getconfigurationResource) |
491 setattr(cls, "getconfigurationResource", getconfigurationResource) |
351 |
492 |
352 def addconfigurationResource(self, config_name, name): |
493 def addconfigurationResource(self, config_name, name): |
|
494 if self.getconfigurationResource(config_name, name) is not None: |
|
495 raise ValueError, _("\"%s\" resource already exists in \"%s\" configuration !!!") % (name, config_name) |
353 configuration = self.getconfiguration(config_name) |
496 configuration = self.getconfiguration(config_name) |
354 if configuration: |
497 if configuration is not None: |
355 for resource in configuration.getresource(): |
498 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) |
499 new_resource.setname(name) |
360 configuration.appendresource(new_resource) |
500 configuration.appendresource(new_resource) |
361 setattr(cls, "addconfigurationResource", addconfigurationResource) |
501 setattr(cls, "addconfigurationResource", addconfigurationResource) |
362 |
502 |
363 def removeconfigurationResource(self, config_name, name): |
503 def removeconfigurationResource(self, config_name, name): |
364 configuration = self.getconfiguration(config_name) |
504 configuration = self.getconfiguration(config_name) |
365 if configuration: |
505 found = False |
366 found = False |
506 if configuration is not None: |
367 for idx, resource in enumerate(configuration.getresource()): |
507 resource = self.getconfigurationResource(config_name, name) |
368 if resource.getname() == name: |
508 if resource is not None: |
369 configuration.removeresource(idx) |
509 configuration.remove(resource) |
370 found = True |
510 found = True |
371 break |
511 if not found: |
372 if not found: |
512 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) |
513 setattr(cls, "removeconfigurationResource", removeconfigurationResource) |
375 |
514 |
376 def updateElementName(self, old_name, new_name): |
515 def updateElementName(self, old_name, new_name): |
377 for datatype in self.types.getdataTypeElements(): |
516 for datatype in self.getdataTypes(): |
378 datatype.updateElementName(old_name, new_name) |
517 datatype.updateElementName(old_name, new_name) |
379 for pou in self.types.getpouElements(): |
518 for pou in self.getpous(): |
380 pou.updateElementName(old_name, new_name) |
519 pou.updateElementName(old_name, new_name) |
381 for configuration in self.instances.configurations.getconfiguration(): |
520 for configuration in self.getconfigurations(): |
382 configuration.updateElementName(old_name, new_name) |
521 configuration.updateElementName(old_name, new_name) |
383 setattr(cls, "updateElementName", updateElementName) |
522 setattr(cls, "updateElementName", updateElementName) |
384 |
523 |
385 def updateElementAddress(self, old_leading, new_leading): |
524 def updateElementAddress(self, old_leading, new_leading): |
386 address_model = re.compile(FILTER_ADDRESS_MODEL % old_leading) |
525 address_model = re.compile(FILTER_ADDRESS_MODEL % old_leading) |
387 for pou in self.types.getpouElements(): |
526 for pou in self.getpous(): |
388 pou.updateElementAddress(address_model, new_leading) |
527 pou.updateElementAddress(address_model, new_leading) |
389 for configuration in self.instances.configurations.getconfiguration(): |
528 for configuration in self.getconfigurations(): |
390 configuration.updateElementAddress(address_model, new_leading) |
529 configuration.updateElementAddress(address_model, new_leading) |
391 setattr(cls, "updateElementAddress", updateElementAddress) |
530 setattr(cls, "updateElementAddress", updateElementAddress) |
392 |
531 |
393 def removeVariableByAddress(self, address): |
532 def removeVariableByAddress(self, address): |
394 for pou in self.types.getpouElements(): |
533 for pou in self.getpous(): |
395 pou.removeVariableByAddress(address) |
534 pou.removeVariableByAddress(address) |
396 for configuration in self.instances.configurations.getconfiguration(): |
535 for configuration in self.getconfigurations(): |
397 configuration.removeVariableByAddress(address) |
536 configuration.removeVariableByAddress(address) |
398 setattr(cls, "removeVariableByAddress", removeVariableByAddress) |
537 setattr(cls, "removeVariableByAddress", removeVariableByAddress) |
399 |
538 |
400 def removeVariableByFilter(self, leading): |
539 def removeVariableByFilter(self, leading): |
401 address_model = re.compile(FILTER_ADDRESS_MODEL % leading) |
540 address_model = re.compile(FILTER_ADDRESS_MODEL % leading) |
402 for pou in self.types.getpouElements(): |
541 for pou in self.getpous(): |
403 pou.removeVariableByFilter(address_model) |
542 pou.removeVariableByFilter(address_model) |
404 for configuration in self.instances.configurations.getconfiguration(): |
543 for configuration in self.getconfigurations(): |
405 configuration.removeVariableByFilter(address_model) |
544 configuration.removeVariableByFilter(address_model) |
406 setattr(cls, "removeVariableByFilter", removeVariableByFilter) |
545 setattr(cls, "removeVariableByFilter", removeVariableByFilter) |
407 |
546 |
408 def RefreshDataTypeHierarchy(self): |
547 enumerated_values_xpath = PLCOpen_XPath( |
409 self.EnumeratedDataTypeValues = {} |
548 "ppx:types/ppx:dataTypes/ppx:dataType/ppx:baseType/ppx:enum/ppx:values/ppx:value") |
410 self.CustomDataTypeRange = {} |
549 def GetEnumeratedDataTypeValues(self): |
411 self.CustomTypeHierarchy = {} |
550 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 = [] |
|
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.append(block_infos) |
|
501 setattr(cls, "AddCustomBlockType", AddCustomBlockType) |
|
502 |
|
503 def AddElementUsingTreeInstance(self, name, type_infos): |
|
504 typename = type_infos.getname() |
|
505 if not self.ElementUsingTree.has_key(typename): |
|
506 self.ElementUsingTree[typename] = [name] |
|
507 elif name not in self.ElementUsingTree[typename]: |
|
508 self.ElementUsingTree[typename].append(name) |
|
509 setattr(cls, "AddElementUsingTreeInstance", AddElementUsingTreeInstance) |
|
510 |
|
511 def RefreshElementUsingTree(self): |
|
512 # Reset the tree of user-defined element cross-use |
|
513 self.ElementUsingTree = {} |
|
514 pous = self.getpous() |
|
515 datatypes = self.getdataTypes() |
|
516 # Analyze each datatype |
|
517 for datatype in datatypes: |
|
518 name = datatype.getname() |
|
519 basetype_content = datatype.baseType.getcontent() |
|
520 if basetype_content["name"] == "derived": |
|
521 typename = basetype_content["value"].getname() |
|
522 if name in self.ElementUsingTree[typename]: |
|
523 self.ElementUsingTree[typename].append(name) |
|
524 elif basetype_content["name"] in ["subrangeSigned", "subrangeUnsigned", "array"]: |
|
525 base_type = basetype_content["value"].baseType.getcontent() |
|
526 if base_type["name"] == "derived": |
|
527 self.AddElementUsingTreeInstance(name, base_type["value"]) |
|
528 elif basetype_content["name"] == "struct": |
|
529 for element in basetype_content["value"].getvariable(): |
|
530 type_content = element.type.getcontent() |
|
531 if type_content["name"] == "derived": |
|
532 self.AddElementUsingTreeInstance(name, type_content["value"]) |
|
533 # Analyze each pou |
|
534 for pou in pous: |
|
535 name = pou.getname() |
|
536 if pou.interface: |
|
537 # Extract variables from every varLists |
|
538 for type, varlist in pou.getvars(): |
|
539 for var in varlist.getvariable(): |
|
540 vartype_content = var.gettype().getcontent() |
|
541 if vartype_content["name"] == "derived": |
|
542 self.AddElementUsingTreeInstance(name, vartype_content["value"]) |
|
543 for typename in self.ElementUsingTree.iterkeys(): |
|
544 if typename != name and pou.hasblock(block_type=typename) and name not in self.ElementUsingTree[typename]: |
|
545 self.ElementUsingTree[typename].append(name) |
|
546 |
|
547 setattr(cls, "RefreshElementUsingTree", RefreshElementUsingTree) |
|
548 |
|
549 def GetParentType(self, type): |
|
550 if self.CustomTypeHierarchy.has_key(type): |
|
551 return self.CustomTypeHierarchy[type] |
|
552 elif TypeHierarchy.has_key(type): |
|
553 return TypeHierarchy[type] |
|
554 return None |
|
555 setattr(cls, "GetParentType", GetParentType) |
|
556 |
|
557 def GetBaseType(self, type): |
|
558 parent_type = self.GetParentType(type) |
|
559 if parent_type is not None: |
|
560 if parent_type.startswith("ANY"): |
|
561 return type |
|
562 else: |
|
563 return self.GetBaseType(parent_type) |
|
564 return None |
|
565 setattr(cls, "GetBaseType", GetBaseType) |
|
566 |
|
567 def GetSubrangeBaseTypes(self, exclude): |
|
568 derived = [] |
|
569 for type in self.CustomTypeHierarchy.keys(): |
|
570 for base_type in DataTypeRange.keys(): |
|
571 if self.IsOfType(type, base_type) and not self.IsOfType(type, exclude): |
|
572 derived.append(type) |
|
573 break |
|
574 return derived |
|
575 setattr(cls, "GetSubrangeBaseTypes", GetSubrangeBaseTypes) |
|
576 |
|
577 """ |
|
578 returns true if the given data type is the same that "reference" meta-type or one of its types. |
|
579 """ |
|
580 def IsOfType(self, type, reference): |
|
581 if reference is None: |
|
582 return True |
|
583 elif type == reference: |
|
584 return True |
|
585 else: |
|
586 parent_type = self.GetParentType(type) |
|
587 if parent_type is not None: |
|
588 return self.IsOfType(parent_type, reference) |
|
589 return False |
|
590 setattr(cls, "IsOfType", IsOfType) |
|
591 |
|
592 # Return if pou given by name is used by another pou |
|
593 def ElementIsUsed(self, name): |
|
594 if self.ElementUsingTree.has_key(name): |
|
595 return len(self.ElementUsingTree[name]) > 0 |
|
596 return False |
|
597 setattr(cls, "ElementIsUsed", ElementIsUsed) |
|
598 |
|
599 def DataTypeIsDerived(self, name): |
|
600 return name in self.CustomTypeHierarchy.values() |
|
601 setattr(cls, "DataTypeIsDerived", DataTypeIsDerived) |
|
602 |
|
603 # Return if pou given by name is directly or undirectly used by the reference pou |
|
604 def ElementIsUsedBy(self, name, reference): |
|
605 if self.ElementUsingTree.has_key(name): |
|
606 list = self.ElementUsingTree[name] |
|
607 # Test if pou is directly used by reference |
|
608 if reference in list: |
|
609 return True |
|
610 else: |
|
611 # Test if pou is undirectly used by reference, by testing if pous |
|
612 # that directly use pou is directly or undirectly used by reference |
|
613 used = False |
|
614 for element in list: |
|
615 used |= self.ElementIsUsedBy(element, reference) |
|
616 return used |
|
617 return False |
|
618 setattr(cls, "ElementIsUsedBy", ElementIsUsedBy) |
|
619 |
|
620 def GetDataTypeRange(self, type): |
|
621 if self.CustomDataTypeRange.has_key(type): |
|
622 return self.CustomDataTypeRange[type] |
|
623 elif DataTypeRange.has_key(type): |
|
624 return DataTypeRange[type] |
|
625 else: |
|
626 parent_type = self.GetParentType(type) |
|
627 if parent_type is not None: |
|
628 return self.GetDataTypeRange(parent_type) |
|
629 return None |
|
630 setattr(cls, "GetDataTypeRange", GetDataTypeRange) |
|
631 |
|
632 def GetEnumeratedDataTypeValues(self, type = None): |
|
633 if type is None: |
|
634 all_values = [] |
|
635 for values in self.EnumeratedDataTypeValues.values(): |
|
636 all_values.extend(values) |
|
637 return all_values |
|
638 elif self.EnumeratedDataTypeValues.has_key(type): |
|
639 return self.EnumeratedDataTypeValues[type] |
|
640 return [] |
|
641 setattr(cls, "GetEnumeratedDataTypeValues", GetEnumeratedDataTypeValues) |
551 setattr(cls, "GetEnumeratedDataTypeValues", GetEnumeratedDataTypeValues) |
642 |
|
643 # Function that returns the block definition associated to the block type given |
|
644 def GetCustomBlockType(self, type, inputs = None): |
|
645 for customblocktype in self.CustomBlockTypes: |
|
646 if inputs is not None and inputs != "undefined": |
|
647 customblock_inputs = tuple([var_type for name, var_type, modifier in customblocktype["inputs"]]) |
|
648 same_inputs = inputs == customblock_inputs |
|
649 else: |
|
650 same_inputs = True |
|
651 if customblocktype["name"] == type and same_inputs: |
|
652 return customblocktype |
|
653 return None |
|
654 setattr(cls, "GetCustomBlockType", GetCustomBlockType) |
|
655 |
|
656 # Return Block types checking for recursion |
|
657 def GetCustomBlockTypes(self, exclude = "", onlyfunctions = False): |
|
658 type = None |
|
659 if exclude != "": |
|
660 pou = self.getpou(exclude) |
|
661 if pou is not None: |
|
662 type = pou.getpouType() |
|
663 customblocktypes = [] |
|
664 for customblocktype in self.CustomBlockTypes: |
|
665 if customblocktype["type"] != "program" and customblocktype["name"] != exclude and not self.ElementIsUsedBy(exclude, customblocktype["name"]) and not (onlyfunctions and customblocktype["type"] != "function"): |
|
666 customblocktypes.append(customblocktype) |
|
667 return customblocktypes |
|
668 setattr(cls, "GetCustomBlockTypes", GetCustomBlockTypes) |
|
669 |
|
670 # Return Function Block types checking for recursion |
|
671 def GetCustomFunctionBlockTypes(self, exclude = ""): |
|
672 customblocktypes = [] |
|
673 for customblocktype in self.CustomBlockTypes: |
|
674 if customblocktype["type"] == "functionBlock" and customblocktype["name"] != exclude and not self.ElementIsUsedBy(exclude, customblocktype["name"]): |
|
675 customblocktypes.append(customblocktype["name"]) |
|
676 return customblocktypes |
|
677 setattr(cls, "GetCustomFunctionBlockTypes", GetCustomFunctionBlockTypes) |
|
678 |
|
679 # Return Block types checking for recursion |
|
680 def GetCustomBlockResource(self): |
|
681 customblocktypes = [] |
|
682 for customblocktype in self.CustomBlockTypes: |
|
683 if customblocktype["type"] == "program": |
|
684 customblocktypes.append(customblocktype["name"]) |
|
685 return customblocktypes |
|
686 setattr(cls, "GetCustomBlockResource", GetCustomBlockResource) |
|
687 |
|
688 # Return Data Types checking for recursion |
|
689 def GetCustomDataTypes(self, exclude = "", only_locatable = False): |
|
690 customdatatypes = [] |
|
691 for customdatatype in self.getdataTypes(): |
|
692 if not only_locatable or self.IsLocatableType(customdatatype): |
|
693 customdatatype_name = customdatatype.getname() |
|
694 if customdatatype_name != exclude and not self.ElementIsUsedBy(exclude, customdatatype_name): |
|
695 customdatatypes.append({"name": customdatatype_name, "infos": customdatatype}) |
|
696 return customdatatypes |
|
697 setattr(cls, "GetCustomDataTypes", GetCustomDataTypes) |
|
698 |
|
699 # Return if Data Type can be used for located variables |
|
700 def IsLocatableType(self, datatype): |
|
701 basetype_content = datatype.baseType.getcontent() |
|
702 if basetype_content["name"] in ["enum", "struct"]: |
|
703 return False |
|
704 elif basetype_content["name"] == "derived": |
|
705 base_type = self.getdataType(basetype_content["value"].getname()) |
|
706 if base_type is not None: |
|
707 return self.IsLocatableType(base_type) |
|
708 elif basetype_content["name"] == "array": |
|
709 array_base_type = basetype_content["value"].baseType.getcontent() |
|
710 if array_base_type["value"] is not None and array_base_type["name"] not in ["string", "wstring"]: |
|
711 base_type = self.getdataType(array_base_type["value"].getname()) |
|
712 if base_type is not None: |
|
713 return self.IsLocatableType(base_type) |
|
714 return True |
|
715 setattr(cls, "IsLocatableType", IsLocatableType) |
|
716 |
552 |
717 def Search(self, criteria, parent_infos=[]): |
553 def Search(self, criteria, parent_infos=[]): |
718 result = self.types.Search(criteria, parent_infos) |
554 result = self.types.Search(criteria, parent_infos) |
719 for configuration in self.instances.configurations.getconfiguration(): |
555 for configuration in self.instances.configurations.getconfiguration(): |
720 result.extend(configuration.Search(criteria, parent_infos)) |
556 result.extend(configuration.Search(criteria, parent_infos)) |
721 return result |
557 return result |
722 setattr(cls, "Search", Search) |
558 setattr(cls, "Search", Search) |
723 |
559 |
724 cls = PLCOpenClasses.get("project_fileHeader", None) |
560 cls = PLCOpenParser.GetElementClass("contentHeader", "project") |
725 if cls: |
561 if cls: |
726 cls.singleLineAttributes = False |
|
727 |
|
728 cls = PLCOpenClasses.get("project_contentHeader", None) |
|
729 if cls: |
|
730 cls.singleLineAttributes = False |
|
731 |
562 |
732 def setpageSize(self, width, height): |
563 def setpageSize(self, width, height): |
733 self.coordinateInfo.setpageSize(width, height) |
564 self.coordinateInfo.setpageSize(width, height) |
734 setattr(cls, "setpageSize", setpageSize) |
565 setattr(cls, "setpageSize", setpageSize) |
735 |
566 |
1774 object.__setattr__(self, "currentExecutionOrderId", self.currentExecutionOrderId + 1) |
1567 object.__setattr__(self, "currentExecutionOrderId", self.currentExecutionOrderId + 1) |
1775 return self.currentExecutionOrderId |
1568 return self.currentExecutionOrderId |
1776 setattr(cls, "getnewExecutionOrderId", getnewExecutionOrderId) |
1569 setattr(cls, "getnewExecutionOrderId", getnewExecutionOrderId) |
1777 |
1570 |
1778 def resetexecutionOrder(self): |
1571 def resetexecutionOrder(self): |
1779 if self.content["name"] == "FBD": |
1572 if self.content.getLocalTag() == "FBD": |
1780 for element in self.content["value"].getcontent(): |
1573 for element in self.content.getcontent(): |
1781 if not isinstance(element["value"], (PLCOpenClasses.get("commonObjects_comment", None), |
1574 if not isinstance(element, (PLCOpenParser.GetElementClass("comment", "commonObjects"), |
1782 PLCOpenClasses.get("commonObjects_connector", None), |
1575 PLCOpenParser.GetElementClass("connector", "commonObjects"), |
1783 PLCOpenClasses.get("commonObjects_continuation", None))): |
1576 PLCOpenParser.GetElementClass("continuation", "commonObjects"))): |
1784 element["value"].setexecutionOrderId(0) |
1577 element.setexecutionOrderId(0) |
1785 else: |
1578 else: |
1786 raise TypeError, _("Can only generate execution order on FBD networks!") |
1579 raise TypeError, _("Can only generate execution order on FBD networks!") |
1787 setattr(cls, "resetexecutionOrder", resetexecutionOrder) |
1580 setattr(cls, "resetexecutionOrder", resetexecutionOrder) |
1788 |
1581 |
1789 def compileexecutionOrder(self): |
1582 def compileexecutionOrder(self): |
1790 if self.content["name"] == "FBD": |
1583 if self.content.getLocalTag() == "FBD": |
1791 self.resetexecutionOrder() |
1584 self.resetexecutionOrder() |
1792 self.resetcurrentExecutionOrderId() |
1585 self.resetcurrentExecutionOrderId() |
1793 for element in self.content["value"].getcontent(): |
1586 for element in self.content.getcontent(): |
1794 if isinstance(element["value"], PLCOpenClasses.get("fbdObjects_outVariable", None)) and element["value"].getexecutionOrderId() == 0: |
1587 if isinstance(element, PLCOpenParser.GetElementClass("outVariable", "fbdObjects")) and element.getexecutionOrderId() == 0: |
1795 connections = element["value"].connectionPointIn.getconnections() |
1588 connections = element.connectionPointIn.getconnections() |
1796 if connections and len(connections) == 1: |
1589 if connections and len(connections) == 1: |
1797 self.compileelementExecutionOrder(connections[0]) |
1590 self.compileelementExecutionOrder(connections[0]) |
1798 element["value"].setexecutionOrderId(self.getnewExecutionOrderId()) |
1591 element.setexecutionOrderId(self.getnewExecutionOrderId()) |
1799 else: |
1592 else: |
1800 raise TypeError, _("Can only generate execution order on FBD networks!") |
1593 raise TypeError, _("Can only generate execution order on FBD networks!") |
1801 setattr(cls, "compileexecutionOrder", compileexecutionOrder) |
1594 setattr(cls, "compileexecutionOrder", compileexecutionOrder) |
1802 |
1595 |
1803 def compileelementExecutionOrder(self, link): |
1596 def compileelementExecutionOrder(self, link): |
1804 if self.content["name"] == "FBD": |
1597 if self.content.getLocalTag() == "FBD": |
1805 localid = link.getrefLocalId() |
1598 localid = link.getrefLocalId() |
1806 instance = self.getcontentInstance(localid) |
1599 instance = self.getcontentInstance(localid) |
1807 if isinstance(instance, PLCOpenClasses.get("fbdObjects_block", None)) and instance.getexecutionOrderId() == 0: |
1600 if isinstance(instance, PLCOpenParser.GetElementClass("block", "fbdObjects")) and instance.getexecutionOrderId() == 0: |
1808 for variable in instance.inputVariables.getvariable(): |
1601 for variable in instance.inputVariables.getvariable(): |
1809 connections = variable.connectionPointIn.getconnections() |
1602 connections = variable.connectionPointIn.getconnections() |
1810 if connections and len(connections) == 1: |
1603 if connections and len(connections) == 1: |
1811 self.compileelementExecutionOrder(connections[0]) |
1604 self.compileelementExecutionOrder(connections[0]) |
1812 instance.setexecutionOrderId(self.getnewExecutionOrderId()) |
1605 instance.setexecutionOrderId(self.getnewExecutionOrderId()) |
1813 elif isinstance(instance, PLCOpenClasses.get("commonObjects_continuation", None)) and instance.getexecutionOrderId() == 0: |
1606 elif isinstance(instance, PLCOpenParser.GetElementClass("continuation", "commonObjects")) and instance.getexecutionOrderId() == 0: |
1814 name = instance.getname() |
1607 name = instance.getname() |
1815 for tmp_instance in self.getcontentInstances(): |
1608 for tmp_instance in self.getcontentInstances(): |
1816 if isinstance(tmp_instance, PLCOpenClasses.get("commonObjects_connector", None)) and tmp_instance.getname() == name and tmp_instance.getexecutionOrderId() == 0: |
1609 if isinstance(tmp_instance, PLCOpenParser.GetElementClass("connector", "commonObjects")) and tmp_instance.getname() == name and tmp_instance.getexecutionOrderId() == 0: |
1817 connections = tmp_instance.connectionPointIn.getconnections() |
1610 connections = tmp_instance.connectionPointIn.getconnections() |
1818 if connections and len(connections) == 1: |
1611 if connections and len(connections) == 1: |
1819 self.compileelementExecutionOrder(connections[0]) |
1612 self.compileelementExecutionOrder(connections[0]) |
1820 else: |
1613 else: |
1821 raise TypeError, _("Can only generate execution order on FBD networks!") |
1614 raise TypeError, _("Can only generate execution order on FBD networks!") |
1822 setattr(cls, "compileelementExecutionOrder", compileelementExecutionOrder) |
1615 setattr(cls, "compileelementExecutionOrder", compileelementExecutionOrder) |
1823 |
1616 |
1824 def setelementExecutionOrder(self, instance, new_executionOrder): |
1617 def setelementExecutionOrder(self, instance, new_executionOrder): |
1825 if self.content["name"] == "FBD": |
1618 if self.content.getLocalTag() == "FBD": |
1826 old_executionOrder = instance.getexecutionOrderId() |
1619 old_executionOrder = instance.getexecutionOrderId() |
1827 if old_executionOrder is not None and old_executionOrder != 0 and new_executionOrder != 0: |
1620 if old_executionOrder is not None and old_executionOrder != 0 and new_executionOrder != 0: |
1828 for element in self.content["value"].getcontent(): |
1621 for element in self.content.getcontent(): |
1829 if element["value"] != instance and not isinstance(element["value"], PLCOpenClasses.get("commonObjects_comment", None)): |
1622 if element != instance and not isinstance(element, PLCOpenParser.GetElementClass("comment", "commonObjects")): |
1830 element_executionOrder = element["value"].getexecutionOrderId() |
1623 element_executionOrder = element.getexecutionOrderId() |
1831 if old_executionOrder <= element_executionOrder <= new_executionOrder: |
1624 if old_executionOrder <= element_executionOrder <= new_executionOrder: |
1832 element["value"].setexecutionOrderId(element_executionOrder - 1) |
1625 element.setexecutionOrderId(element_executionOrder - 1) |
1833 if new_executionOrder <= element_executionOrder <= old_executionOrder: |
1626 if new_executionOrder <= element_executionOrder <= old_executionOrder: |
1834 element["value"].setexecutionOrderId(element_executionOrder + 1) |
1627 element.setexecutionOrderId(element_executionOrder + 1) |
1835 instance.setexecutionOrderId(new_executionOrder) |
1628 instance.setexecutionOrderId(new_executionOrder) |
1836 else: |
1629 else: |
1837 raise TypeError, _("Can only generate execution order on FBD networks!") |
1630 raise TypeError, _("Can only generate execution order on FBD networks!") |
1838 setattr(cls, "setelementExecutionOrder", setelementExecutionOrder) |
1631 setattr(cls, "setelementExecutionOrder", setelementExecutionOrder) |
1839 |
1632 |
1840 def appendcontentInstance(self, name, instance): |
1633 def appendcontentInstance(self, instance): |
1841 if self.content["name"] in ["LD","FBD","SFC"]: |
1634 if self.content.getLocalTag() in ["LD","FBD","SFC"]: |
1842 element = {"name" : name, "value" : instance} |
1635 self.content.appendcontent(instance) |
1843 self.content["value"].appendcontent(element) |
|
1844 self.instances_dict[instance.getlocalId()] = element |
|
1845 else: |
1636 else: |
1846 raise TypeError, _("%s body don't have instances!")%self.content["name"] |
1637 raise TypeError, _("%s body don't have instances!")%self.content.getLocalTag() |
1847 setattr(cls, "appendcontentInstance", appendcontentInstance) |
1638 setattr(cls, "appendcontentInstance", appendcontentInstance) |
1848 |
1639 |
1849 def getcontentInstances(self): |
1640 def getcontentInstances(self): |
1850 if self.content["name"] in ["LD","FBD","SFC"]: |
1641 if self.content.getLocalTag() in ["LD","FBD","SFC"]: |
1851 instances = [] |
1642 return self.content.getcontent() |
1852 for element in self.content["value"].getcontent(): |
|
1853 instances.append(element["value"]) |
|
1854 return instances |
|
1855 else: |
1643 else: |
1856 raise TypeError, _("%s body don't have instances!")%self.content["name"] |
1644 raise TypeError, _("%s body don't have instances!")%self.content.getLocalTag() |
1857 setattr(cls, "getcontentInstances", getcontentInstances) |
1645 setattr(cls, "getcontentInstances", getcontentInstances) |
1858 |
1646 |
1859 def getcontentInstance(self, id): |
1647 instance_by_id_xpath = PLCOpen_XPath("*[@localId=$localId]") |
1860 if self.content["name"] in ["LD","FBD","SFC"]: |
1648 instance_by_name_xpath = PLCOpen_XPath("ppx:block[@instanceName=$name]") |
1861 instance = self.instances_dict.get(id, None) |
1649 def getcontentInstance(self, local_id): |
1862 if instance is not None: |
1650 if self.content.getLocalTag() in ["LD","FBD","SFC"]: |
1863 return instance["value"] |
1651 instance = instance_by_id_xpath(self.content, localId=local_id) |
|
1652 if len(instance) > 0: |
|
1653 return instance[0] |
1864 return None |
1654 return None |
1865 else: |
1655 else: |
1866 raise TypeError, _("%s body don't have instances!")%self.content["name"] |
1656 raise TypeError, _("%s body don't have instances!")%self.content.getLocalTag() |
1867 setattr(cls, "getcontentInstance", getcontentInstance) |
1657 setattr(cls, "getcontentInstance", getcontentInstance) |
1868 |
1658 |
1869 def getcontentRandomInstance(self, exclude): |
1659 def getcontentInstancesIds(self): |
1870 if self.content["name"] in ["LD","FBD","SFC"]: |
1660 if self.content.getLocalTag() in ["LD","FBD","SFC"]: |
1871 ids = self.instances_dict.viewkeys() - exclude |
1661 return OrderedDict([(instance.getlocalId(), True) |
1872 if len(ids) > 0: |
1662 for instance in self.content]) |
1873 return self.instances_dict[ids.pop()]["value"] |
1663 else: |
|
1664 raise TypeError, _("%s body don't have instances!")%self.content.getLocalTag() |
|
1665 setattr(cls, "getcontentInstancesIds", getcontentInstancesIds) |
|
1666 |
|
1667 def getcontentInstanceByName(self, name): |
|
1668 if self.content.getLocalTag() in ["LD","FBD","SFC"]: |
|
1669 instance = instance_by_name_xpath(self.content) |
|
1670 if len(instance) > 0: |
|
1671 return instance[0] |
1874 return None |
1672 return None |
1875 else: |
1673 else: |
1876 raise TypeError, _("%s body don't have instances!")%self.content["name"] |
1674 raise TypeError, _("%s body don't have instances!")%self.content.getLocalTag() |
1877 setattr(cls, "getcontentRandomInstance", getcontentRandomInstance) |
|
1878 |
|
1879 def getcontentInstanceByName(self, name): |
|
1880 if self.content["name"] in ["LD","FBD","SFC"]: |
|
1881 for element in self.content["value"].getcontent(): |
|
1882 if isinstance(element["value"], PLCOpenClasses.get("fbdObjects_block", None)) and element["value"].getinstanceName() == name: |
|
1883 return element["value"] |
|
1884 else: |
|
1885 raise TypeError, _("%s body don't have instances!")%self.content["name"] |
|
1886 setattr(cls, "getcontentInstanceByName", getcontentInstanceByName) |
1675 setattr(cls, "getcontentInstanceByName", getcontentInstanceByName) |
1887 |
1676 |
1888 def removecontentInstance(self, id): |
1677 def removecontentInstance(self, local_id): |
1889 if self.content["name"] in ["LD","FBD","SFC"]: |
1678 if self.content.getLocalTag() in ["LD","FBD","SFC"]: |
1890 element = self.instances_dict.pop(id, None) |
1679 instance = instance_by_id_xpath(self.content, localId=local_id) |
1891 if element is not None: |
1680 if len(instance) > 0: |
1892 self.content["value"].getcontent().remove(element) |
1681 self.content.remove(instance[0]) |
1893 else: |
1682 else: |
1894 raise ValueError, _("Instance with id %d doesn't exist!")%id |
1683 raise ValueError, _("Instance with id %d doesn't exist!")%id |
1895 else: |
1684 else: |
1896 raise TypeError, "%s body don't have instances!"%self.content["name"] |
1685 raise TypeError, "%s body don't have instances!"%self.content.getLocalTag() |
1897 setattr(cls, "removecontentInstance", removecontentInstance) |
1686 setattr(cls, "removecontentInstance", removecontentInstance) |
1898 |
1687 |
1899 def settext(self, text): |
1688 def settext(self, text): |
1900 if self.content["name"] in ["IL","ST"]: |
1689 if self.content.getLocalTag() in ["IL","ST"]: |
1901 self.content["value"].settext(text) |
1690 self.content.setanyText(text) |
1902 else: |
1691 else: |
1903 raise TypeError, _("%s body don't have text!")%self.content["name"] |
1692 raise TypeError, _("%s body don't have text!")%self.content.getLocalTag() |
1904 setattr(cls, "settext", settext) |
1693 setattr(cls, "settext", settext) |
1905 |
1694 |
1906 def gettext(self): |
1695 def gettext(self): |
1907 if self.content["name"] in ["IL","ST"]: |
1696 if self.content.getLocalTag() in ["IL","ST"]: |
1908 return self.content["value"].gettext() |
1697 return self.content.getanyText() |
1909 else: |
1698 else: |
1910 raise TypeError, _("%s body don't have text!")%self.content["name"] |
1699 raise TypeError, _("%s body don't have text!")%self.content.getLocalTag() |
1911 setattr(cls, "gettext", gettext) |
1700 setattr(cls, "gettext", gettext) |
1912 |
1701 |
1913 def hasblock(self, block_type): |
1702 def hasblock(self, block_type): |
1914 if self.content["name"] in ["IL","ST"]: |
1703 if self.content.getLocalTag() in ["IL","ST"]: |
1915 return self.content["value"].hasblock(block_type) |
1704 return self.content.hasblock(block_type) |
1916 else: |
1705 else: |
1917 raise TypeError, _("%s body don't have text!")%self.content["name"] |
1706 raise TypeError, _("%s body don't have text!")%self.content.getLocalTag() |
1918 setattr(cls, "hasblock", hasblock) |
1707 setattr(cls, "hasblock", hasblock) |
1919 |
1708 |
1920 def updateElementName(self, old_name, new_name): |
1709 def updateElementName(self, old_name, new_name): |
1921 if self.content["name"] in ["IL", "ST"]: |
1710 if self.content.getLocalTag() in ["IL", "ST"]: |
1922 self.content["value"].updateElementName(old_name, new_name) |
1711 self.content.updateElementName(old_name, new_name) |
1923 else: |
1712 else: |
1924 for element in self.content["value"].getcontent(): |
1713 for element in self.content.getcontent(): |
1925 element["value"].updateElementName(old_name, new_name) |
1714 element.updateElementName(old_name, new_name) |
1926 setattr(cls, "updateElementName", updateElementName) |
1715 setattr(cls, "updateElementName", updateElementName) |
1927 |
1716 |
1928 def updateElementAddress(self, address_model, new_leading): |
1717 def updateElementAddress(self, address_model, new_leading): |
1929 if self.content["name"] in ["IL", "ST"]: |
1718 if self.content.getLocalTag() in ["IL", "ST"]: |
1930 self.content["value"].updateElementAddress(address_model, new_leading) |
1719 self.content.updateElementAddress(address_model, new_leading) |
1931 else: |
1720 else: |
1932 for element in self.content["value"].getcontent(): |
1721 for element in self.content.getcontent(): |
1933 element["value"].updateElementAddress(address_model, new_leading) |
1722 element.updateElementAddress(address_model, new_leading) |
1934 setattr(cls, "updateElementAddress", updateElementAddress) |
1723 setattr(cls, "updateElementAddress", updateElementAddress) |
1935 |
1724 |
1936 def Search(self, criteria, parent_infos=[]): |
1725 def Search(self, criteria, parent_infos=[]): |
1937 if self.content["name"] in ["IL", "ST"]: |
1726 if self.content.getLocalTag() in ["IL", "ST"]: |
1938 search_result = self.content["value"].Search(criteria, parent_infos + ["body", 0]) |
1727 search_result = self.content.Search(criteria, parent_infos + ["body", 0]) |
1939 else: |
1728 else: |
1940 search_result = [] |
1729 search_result = [] |
1941 for element in self.content["value"].getcontent(): |
1730 for element in self.content.getcontent(): |
1942 search_result.extend(element["value"].Search(criteria, parent_infos)) |
1731 search_result.extend(element.Search(criteria, parent_infos)) |
1943 return search_result |
1732 return search_result |
1944 setattr(cls, "Search", Search) |
1733 setattr(cls, "Search", Search) |
1945 |
1734 |
1946 def getx(self): |
1735 def getx(self): |
1947 return self.position.getx() |
1736 return self.position.getx() |
2306 for result in TestTextElement(variable.getformalParameter(), criteria): |
1940 for result in TestTextElement(variable.getformalParameter(), criteria): |
2307 search_result.append((tuple(parent_infos + ["output", i]),) + result) |
1941 search_result.append((tuple(parent_infos + ["output", i]),) + result) |
2308 return search_result |
1942 return search_result |
2309 setattr(cls, "Search", Search) |
1943 setattr(cls, "Search", Search) |
2310 |
1944 |
2311 cls = _initElementClass("leftPowerRail", "ldObjects_leftPowerRail") |
1945 _initElementClass("leftPowerRail", "ldObjects") |
2312 if cls: |
1946 _initElementClass("rightPowerRail", "ldObjects", "multiple") |
2313 setattr(cls, "getinfos", _getpowerrailinfosFunction("leftPowerRail")) |
1947 |
2314 |
1948 def _UpdateLDElementName(self, old_name, new_name): |
2315 cls = _initElementClass("rightPowerRail", "ldObjects_rightPowerRail", "multiple") |
1949 if self.variable == old_name: |
2316 if cls: |
1950 self.variable = new_name |
2317 setattr(cls, "getinfos", _getpowerrailinfosFunction("rightPowerRail")) |
1951 |
2318 |
1952 def _UpdateLDElementAddress(self, address_model, new_leading): |
2319 cls = _initElementClass("contact", "ldObjects_contact", "single") |
1953 self.variable = update_address(self.variable, address_model, new_leading) |
2320 if cls: |
1954 |
2321 setattr(cls, "getinfos", _getldelementinfosFunction("contact")) |
1955 def _getSearchInLDElement(ld_element_type): |
2322 |
1956 def SearchInLDElement(self, criteria, parent_infos=[]): |
2323 def updateElementName(self, old_name, new_name): |
1957 return _Search([("reference", self.variable)], criteria, parent_infos + [ld_element_type, self.getlocalId()]) |
2324 if self.variable == old_name: |
1958 return SearchInLDElement |
2325 self.variable = new_name |
1959 |
2326 setattr(cls, "updateElementName", updateElementName) |
1960 cls = _initElementClass("contact", "ldObjects", "single") |
2327 |
1961 if cls: |
2328 def updateElementAddress(self, address_model, new_leading): |
1962 setattr(cls, "updateElementName", _UpdateLDElementName) |
2329 self.variable = update_address(self.variable, address_model, new_leading) |
1963 setattr(cls, "updateElementAddress", _UpdateLDElementAddress) |
2330 setattr(cls, "updateElementAddress", updateElementAddress) |
1964 setattr(cls, "Search", _getSearchInLDElement("contact")) |
2331 |
1965 |
2332 def Search(self, criteria, parent_infos=[]): |
1966 cls = _initElementClass("coil", "ldObjects", "single") |
2333 return _Search([("reference", self.getvariable())], criteria, parent_infos + ["contact", self.getlocalId()]) |
1967 if cls: |
2334 setattr(cls, "Search", Search) |
1968 setattr(cls, "updateElementName", _UpdateLDElementName) |
2335 |
1969 setattr(cls, "updateElementAddress", _UpdateLDElementAddress) |
2336 cls = _initElementClass("coil", "ldObjects_coil", "single") |
1970 setattr(cls, "Search", _getSearchInLDElement("coil")) |
2337 if cls: |
1971 |
2338 setattr(cls, "getinfos", _getldelementinfosFunction("coil")) |
1972 cls = _initElementClass("step", "sfcObjects", "single") |
2339 |
1973 if cls: |
2340 def updateElementName(self, old_name, new_name): |
|
2341 if self.variable == old_name: |
|
2342 self.variable = new_name |
|
2343 setattr(cls, "updateElementName", updateElementName) |
|
2344 |
|
2345 def updateElementAddress(self, address_model, new_leading): |
|
2346 self.variable = update_address(self.variable, address_model, new_leading) |
|
2347 setattr(cls, "updateElementAddress", updateElementAddress) |
|
2348 |
|
2349 def Search(self, criteria, parent_infos=[]): |
|
2350 return _Search([("reference", self.getvariable())], criteria, parent_infos + ["coil", self.getlocalId()]) |
|
2351 setattr(cls, "Search", Search) |
|
2352 |
|
2353 cls = _initElementClass("step", "sfcObjects_step", "single") |
|
2354 if cls: |
|
2355 def getinfos(self): |
|
2356 infos = _getelementinfos(self) |
|
2357 infos["type"] = "step" |
|
2358 specific_values = infos["specific_values"] |
|
2359 specific_values["name"] = self.getname() |
|
2360 specific_values["initial"] = self.getinitialStep() |
|
2361 if self.connectionPointIn: |
|
2362 infos["inputs"].append(_getconnectioninfos(self, self.connectionPointIn, True)) |
|
2363 if self.connectionPointOut: |
|
2364 infos["outputs"].append(_getconnectioninfos(self, self.connectionPointOut)) |
|
2365 if self.connectionPointOutAction: |
|
2366 specific_values["action"] = _getconnectioninfos(self, self.connectionPointOutAction) |
|
2367 return infos |
|
2368 setattr(cls, "getinfos", getinfos) |
|
2369 |
|
2370 def Search(self, criteria, parent_infos=[]): |
1974 def Search(self, criteria, parent_infos=[]): |
2371 return _Search([("name", self.getname())], criteria, parent_infos + ["step", self.getlocalId()]) |
1975 return _Search([("name", self.getname())], criteria, parent_infos + ["step", self.getlocalId()]) |
2372 setattr(cls, "Search", Search) |
1976 setattr(cls, "Search", Search) |
2373 |
1977 |
2374 cls = PLCOpenClasses.get("transition_condition", None) |
1978 cls = _initElementClass("transition", "sfcObjects") |
2375 if cls: |
1979 if cls: |
2376 def compatibility(self, tree): |
1980 def setconditionContent(self, condition_type, value): |
2377 connections = [] |
1981 if self.condition is None: |
2378 for child in tree.childNodes: |
1982 self.addcondition() |
2379 if child.nodeName == "connection": |
1983 if condition_type == "connection": |
2380 connections.append(child) |
1984 condition = PLCOpenParser.CreateElement("connectionPointIn", "condition") |
2381 if len(connections) > 0: |
|
2382 node = CreateNode("connectionPointIn") |
|
2383 relPosition = CreateNode("relPosition") |
|
2384 NodeSetAttr(relPosition, "x", "0") |
|
2385 NodeSetAttr(relPosition, "y", "0") |
|
2386 node.childNodes.append(relPosition) |
|
2387 node.childNodes.extend(connections) |
|
2388 tree.childNodes = [node] |
|
2389 setattr(cls, "compatibility", compatibility) |
|
2390 |
|
2391 cls = _initElementClass("transition", "sfcObjects_transition") |
|
2392 if cls: |
|
2393 def getinfos(self): |
|
2394 infos = _getelementinfos(self) |
|
2395 infos["type"] = "transition" |
|
2396 specific_values = infos["specific_values"] |
|
2397 priority = self.getpriority() |
|
2398 if priority is None: |
|
2399 priority = 0 |
|
2400 specific_values["priority"] = priority |
|
2401 condition = self.getconditionContent() |
|
2402 specific_values["condition_type"] = condition["type"] |
|
2403 if specific_values["condition_type"] == "connection": |
|
2404 specific_values["connection"] = _getconnectioninfos(self, condition["value"], True) |
|
2405 else: |
1985 else: |
2406 specific_values["condition"] = condition["value"] |
1986 condition = PLCOpenParser.CreateElement(condition_type, "condition") |
2407 infos["inputs"].append(_getconnectioninfos(self, self.connectionPointIn, True)) |
1987 self.condition.setcontent(condition) |
2408 infos["outputs"].append(_getconnectioninfos(self, self.connectionPointOut)) |
1988 if condition_type == "reference": |
2409 return infos |
|
2410 setattr(cls, "getinfos", getinfos) |
|
2411 |
|
2412 def setconditionContent(self, type, value): |
|
2413 if not self.condition: |
|
2414 self.addcondition() |
|
2415 if type == "reference": |
|
2416 condition = PLCOpenClasses["condition_reference"]() |
|
2417 condition.setname(value) |
1989 condition.setname(value) |
2418 elif type == "inline": |
1990 elif condition_type == "inline": |
2419 condition = PLCOpenClasses["condition_inline"]() |
1991 condition.setcontent(PLCOpenParser.CreateElement("ST", "inline")) |
2420 condition.setcontent({"name" : "ST", "value" : PLCOpenClasses["formattedText"]()}) |
|
2421 condition.settext(value) |
1992 condition.settext(value) |
2422 elif type == "connection": |
|
2423 type = "connectionPointIn" |
|
2424 condition = PLCOpenClasses["connectionPointIn"]() |
|
2425 self.condition.setcontent({"name" : type, "value" : condition}) |
|
2426 setattr(cls, "setconditionContent", setconditionContent) |
1993 setattr(cls, "setconditionContent", setconditionContent) |
2427 |
1994 |
2428 def getconditionContent(self): |
1995 def getconditionContent(self): |
2429 if self.condition: |
1996 if self.condition is not None: |
2430 content = self.condition.getcontent() |
1997 content = self.condition.getcontent() |
2431 values = {"type" : content["name"]} |
1998 values = {"type" : content.getLocalTag()} |
2432 if values["type"] == "reference": |
1999 if values["type"] == "reference": |
2433 values["value"] = content["value"].getname() |
2000 values["value"] = content.getname() |
2434 elif values["type"] == "inline": |
2001 elif values["type"] == "inline": |
2435 values["value"] = content["value"].gettext() |
2002 values["value"] = content.gettext() |
2436 elif values["type"] == "connectionPointIn": |
2003 elif values["type"] == "connectionPointIn": |
2437 values["type"] = "connection" |
2004 values["type"] = "connection" |
2438 values["value"] = content["value"] |
2005 values["value"] = content |
2439 return values |
2006 return values |
2440 return "" |
2007 return "" |
2441 setattr(cls, "getconditionContent", getconditionContent) |
2008 setattr(cls, "getconditionContent", getconditionContent) |
2442 |
2009 |
2443 def getconditionConnection(self): |
2010 def getconditionConnection(self): |
2444 if self.condition: |
2011 if self.condition is not None: |
2445 content = self.condition.getcontent() |
2012 content = self.condition.getcontent() |
2446 if content["name"] == "connectionPointIn": |
2013 if content.getLocalTag() == "connectionPointIn": |
2447 return content["value"] |
2014 return content |
2448 return None |
2015 return None |
2449 setattr(cls, "getconditionConnection", getconditionConnection) |
2016 setattr(cls, "getconditionConnection", getconditionConnection) |
2450 |
2017 |
2451 def getBoundingBox(self): |
2018 def getBoundingBox(self): |
2452 bbox = _getBoundingBoxSingle(self) |
2019 bbox = _getBoundingBoxSingle(self) |
2453 condition_connection = self.getconditionConnection() |
2020 condition_connection = self.getconditionConnection() |
2454 if condition_connection: |
2021 if condition_connection is not None: |
2455 bbox.union(_getConnectionsBoundingBox(condition_connection)) |
2022 bbox.union(_getConnectionsBoundingBox(condition_connection)) |
2456 return bbox |
2023 return bbox |
2457 setattr(cls, "getBoundingBox", getBoundingBox) |
2024 setattr(cls, "getBoundingBox", getBoundingBox) |
2458 |
2025 |
2459 def translate(self, dx, dy): |
2026 def translate(self, dx, dy): |
2460 _translateSingle(self, dx, dy) |
2027 _translateSingle(self, dx, dy) |
2461 condition_connection = self.getconditionConnection() |
2028 condition_connection = self.getconditionConnection() |
2462 if condition_connection: |
2029 if condition_connection is not None: |
2463 _translateConnections(condition_connection, dx, dy) |
2030 _translateConnections(condition_connection, dx, dy) |
2464 setattr(cls, "translate", translate) |
2031 setattr(cls, "translate", translate) |
2465 |
2032 |
2466 def filterConnections(self, connections): |
2033 def filterConnections(self, connections): |
2467 _filterConnectionsSingle(self, connections) |
2034 _filterConnectionsSingle(self, connections) |
2468 condition_connection = self.getconditionConnection() |
2035 condition_connection = self.getconditionConnection() |
2469 if condition_connection: |
2036 if condition_connection is not None: |
2470 _filterConnections(condition_connection, self.localId, connections) |
2037 _filterConnections(condition_connection, self.localId, connections) |
2471 setattr(cls, "filterConnections", filterConnections) |
2038 setattr(cls, "filterConnections", filterConnections) |
2472 |
2039 |
2473 def updateConnectionsId(self, translation): |
2040 def updateConnectionsId(self, translation): |
2474 connections_end = [] |
2041 connections_end = [] |
2475 if self.connectionPointIn is not None: |
2042 if self.connectionPointIn is not None: |
2476 connections_end = _updateConnectionsId(self.connectionPointIn, translation) |
2043 connections_end = _updateConnectionsId(self.connectionPointIn, translation) |
2477 condition_connection = self.getconditionConnection() |
2044 condition_connection = self.getconditionConnection() |
2478 if condition_connection: |
2045 if condition_connection is not None: |
2479 connections_end.extend(_updateConnectionsId(condition_connection, translation)) |
2046 connections_end.extend(_updateConnectionsId(condition_connection, translation)) |
2480 return _getconnectionsdefinition(self, connections_end) |
2047 return _getconnectionsdefinition(self, connections_end) |
2481 setattr(cls, "updateConnectionsId", updateConnectionsId) |
2048 setattr(cls, "updateConnectionsId", updateConnectionsId) |
2482 |
2049 |
2483 def updateElementName(self, old_name, new_name): |
2050 def updateElementName(self, old_name, new_name): |
2484 if self.condition: |
2051 if self.condition is not None: |
2485 content = self.condition.getcontent() |
2052 content = self.condition.getcontent() |
2486 if content["name"] == "reference": |
2053 content_name = content.getLocalTag() |
2487 if content["value"].getname() == old_name: |
2054 if content_name == "reference": |
2488 content["value"].setname(new_name) |
2055 if content.getname() == old_name: |
2489 elif content["name"] == "inline": |
2056 content.setname(new_name) |
2490 content["value"].updateElementName(old_name, new_name) |
2057 elif content_name == "inline": |
|
2058 content.updateElementName(old_name, new_name) |
2491 setattr(cls, "updateElementName", updateElementName) |
2059 setattr(cls, "updateElementName", updateElementName) |
2492 |
2060 |
2493 def updateElementAddress(self, address_model, new_leading): |
2061 def updateElementAddress(self, address_model, new_leading): |
2494 if self.condition: |
2062 if self.condition is not None: |
2495 content = self.condition.getcontent() |
2063 content = self.condition.getcontent() |
2496 if content["name"] == "reference": |
2064 content_name = content.getLocalTag() |
2497 content["value"].setname(update_address(content["value"].getname(), address_model, new_leading)) |
2065 if content_name == "reference": |
2498 elif content["name"] == "inline": |
2066 content.setname(update_address(content.getname(), address_model, new_leading)) |
2499 content["value"].updateElementAddress(address_model, new_leading) |
2067 elif content_name == "inline": |
|
2068 content.updateElementAddress(address_model, new_leading) |
2500 setattr(cls, "updateElementAddress", updateElementAddress) |
2069 setattr(cls, "updateElementAddress", updateElementAddress) |
2501 |
2070 |
2502 def getconnections(self): |
2071 def getconnections(self): |
2503 condition_connection = self.getconditionConnection() |
2072 condition_connection = self.getconditionConnection() |
2504 if condition_connection: |
2073 if condition_connection is not None: |
2505 return condition_connection.getconnections() |
2074 return condition_connection.getconnections() |
2506 return None |
2075 return None |
2507 setattr(cls, "getconnections", getconnections) |
2076 setattr(cls, "getconnections", getconnections) |
2508 |
2077 |
2509 def Search(self, criteria, parent_infos=[]): |
2078 def Search(self, criteria, parent_infos=[]): |
2510 parent_infos = parent_infos + ["transition", self.getlocalId()] |
2079 parent_infos = parent_infos + ["transition", self.getlocalId()] |
2511 search_result = [] |
2080 search_result = [] |
2512 content = self.condition.getcontent() |
2081 content = self.condition.getcontent() |
2513 if content["name"] == "reference": |
2082 content_name = content.getLocalTag() |
2514 search_result.extend(_Search([("reference", content["value"].getname())], criteria, parent_infos)) |
2083 if content_name == "reference": |
2515 elif content["name"] == "inline": |
2084 search_result.extend(_Search([("reference", content.getname())], criteria, parent_infos)) |
2516 search_result.extend(content["value"].Search(criteria, parent_infos + ["inline"])) |
2085 elif content_name == "inline": |
|
2086 search_result.extend(content.Search(criteria, parent_infos + ["inline"])) |
2517 return search_result |
2087 return search_result |
2518 setattr(cls, "Search", Search) |
2088 setattr(cls, "Search", Search) |
2519 |
2089 |
2520 cls = _initElementClass("selectionDivergence", "sfcObjects_selectionDivergence", "single") |
2090 _initElementClass("selectionDivergence", "sfcObjects", "single") |
2521 if cls: |
2091 _initElementClass("selectionConvergence", "sfcObjects", "multiple") |
2522 setattr(cls, "getinfos", _getdivergenceinfosFunction(True, False)) |
2092 _initElementClass("simultaneousDivergence", "sfcObjects", "single") |
2523 |
2093 _initElementClass("simultaneousConvergence", "sfcObjects", "multiple") |
2524 cls = _initElementClass("selectionConvergence", "sfcObjects_selectionConvergence", "multiple") |
2094 |
2525 if cls: |
2095 cls = _initElementClass("jumpStep", "sfcObjects", "single") |
2526 setattr(cls, "getinfos", _getdivergenceinfosFunction(False, False)) |
2096 if cls: |
2527 |
|
2528 cls = _initElementClass("simultaneousDivergence", "sfcObjects_simultaneousDivergence", "single") |
|
2529 if cls: |
|
2530 setattr(cls, "getinfos", _getdivergenceinfosFunction(True, True)) |
|
2531 |
|
2532 cls = _initElementClass("simultaneousConvergence", "sfcObjects_simultaneousConvergence", "multiple") |
|
2533 if cls: |
|
2534 setattr(cls, "getinfos", _getdivergenceinfosFunction(False, True)) |
|
2535 |
|
2536 cls = _initElementClass("jumpStep", "sfcObjects_jumpStep", "single") |
|
2537 if cls: |
|
2538 def getinfos(self): |
|
2539 infos = _getelementinfos(self) |
|
2540 infos["type"] = "jump" |
|
2541 infos["specific_values"]["target"] = self.gettargetName() |
|
2542 infos["inputs"].append(_getconnectioninfos(self, self.connectionPointIn, True)) |
|
2543 return infos |
|
2544 setattr(cls, "getinfos", getinfos) |
|
2545 |
|
2546 def Search(self, criteria, parent_infos): |
2097 def Search(self, criteria, parent_infos): |
2547 return _Search([("target", self.gettargetName())], criteria, parent_infos + ["jump", self.getlocalId()]) |
2098 return _Search([("target", self.gettargetName())], criteria, parent_infos + ["jump", self.getlocalId()]) |
2548 setattr(cls, "Search", Search) |
2099 setattr(cls, "Search", Search) |
2549 |
2100 |
2550 cls = PLCOpenClasses.get("actionBlock_action", None) |
2101 cls = PLCOpenParser.GetElementClass("action", "actionBlock") |
2551 if cls: |
2102 if cls: |
2552 def compatibility(self, tree): |
|
2553 relPosition = reduce(lambda x, y: x | (y.nodeName == "relPosition"), tree.childNodes, False) |
|
2554 if not tree.hasAttribute("localId"): |
|
2555 NodeSetAttr(tree, "localId", "0") |
|
2556 if not relPosition: |
|
2557 node = CreateNode("relPosition") |
|
2558 NodeSetAttr(node, "x", "0") |
|
2559 NodeSetAttr(node, "y", "0") |
|
2560 tree.childNodes.insert(0, node) |
|
2561 setattr(cls, "compatibility", compatibility) |
|
2562 |
|
2563 def setreferenceName(self, name): |
2103 def setreferenceName(self, name): |
2564 if self.reference: |
2104 if self.reference is not None: |
2565 self.reference.setname(name) |
2105 self.reference.setname(name) |
2566 setattr(cls, "setreferenceName", setreferenceName) |
2106 setattr(cls, "setreferenceName", setreferenceName) |
2567 |
2107 |
2568 def getreferenceName(self): |
2108 def getreferenceName(self): |
2569 if self.reference: |
2109 if self.reference is not None: |
2570 return self.reference.getname() |
2110 return self.reference.getname() |
2571 return None |
2111 return None |
2572 setattr(cls, "getreferenceName", getreferenceName) |
2112 setattr(cls, "getreferenceName", getreferenceName) |
2573 |
2113 |
2574 def setinlineContent(self, content): |
2114 def setinlineContent(self, content): |
2575 if self.inline: |
2115 if self.inline is not None: |
2576 self.inline.setcontent({"name" : "ST", "value" : PLCOpenClasses["formattedText"]()}) |
2116 self.inline.setcontent(PLCOpenParser.CreateElement("ST", "inline")) |
2577 self.inline.settext(content) |
2117 self.inline.settext(content) |
2578 setattr(cls, "setinlineContent", setinlineContent) |
2118 setattr(cls, "setinlineContent", setinlineContent) |
2579 |
2119 |
2580 def getinlineContent(self): |
2120 def getinlineContent(self): |
2581 if self.inline: |
2121 if self.inline is not None: |
2582 return self.inline.gettext() |
2122 return self.inline.gettext() |
2583 return None |
2123 return None |
2584 setattr(cls, "getinlineContent", getinlineContent) |
2124 setattr(cls, "getinlineContent", getinlineContent) |
2585 |
2125 |
2586 def updateElementName(self, old_name, new_name): |
2126 def updateElementName(self, old_name, new_name): |
2587 if self.reference and self.reference.getname() == old_name: |
2127 if self.reference is not None and self.reference.getname() == old_name: |
2588 self.reference.setname(new_name) |
2128 self.reference.setname(new_name) |
2589 if self.inline: |
2129 if self.inline is not None: |
2590 self.inline.updateElementName(old_name, new_name) |
2130 self.inline.updateElementName(old_name, new_name) |
2591 setattr(cls, "updateElementName", updateElementName) |
2131 setattr(cls, "updateElementName", updateElementName) |
2592 |
2132 |
2593 def updateElementAddress(self, address_model, new_leading): |
2133 def updateElementAddress(self, address_model, new_leading): |
2594 if self.reference: |
2134 if self.reference is not None: |
2595 self.reference.setname(update_address(self.reference.getname(), address_model, new_leading)) |
2135 self.reference.setname(update_address(self.reference.getname(), address_model, new_leading)) |
2596 if self.inline: |
2136 if self.inline is not None: |
2597 self.inline.updateElementAddress(address_model, new_leading) |
2137 self.inline.updateElementAddress(address_model, new_leading) |
2598 setattr(cls, "updateElementAddress", updateElementAddress) |
2138 setattr(cls, "updateElementAddress", updateElementAddress) |
2599 |
2139 |
2600 def Search(self, criteria, parent_infos=[]): |
2140 def Search(self, criteria, parent_infos=[]): |
2601 qualifier = self.getqualifier() |
2141 qualifier = self.getqualifier() |
2683 search_result.extend(action.Search(criteria, parent_infos + ["action", idx])) |
2209 search_result.extend(action.Search(criteria, parent_infos + ["action", idx])) |
2684 return search_result |
2210 return search_result |
2685 setattr(cls, "Search", Search) |
2211 setattr(cls, "Search", Search) |
2686 |
2212 |
2687 def _SearchInIOVariable(self, criteria, parent_infos=[]): |
2213 def _SearchInIOVariable(self, criteria, parent_infos=[]): |
2688 return _Search([("expression", self.getexpression())], criteria, parent_infos + ["io_variable", self.getlocalId()]) |
2214 return _Search([("expression", self.expression)], criteria, parent_infos + ["io_variable", self.getlocalId()]) |
2689 |
2215 |
2690 cls = _initElementClass("inVariable", "fbdObjects_inVariable") |
2216 def _UpdateIOElementName(self, old_name, new_name): |
2691 if cls: |
2217 if self.expression == old_name: |
2692 setattr(cls, "getinfos", _getvariableinfosFunction("input", False, True)) |
2218 self.expression = new_name |
2693 |
2219 |
2694 def updateElementName(self, old_name, new_name): |
2220 def _UpdateIOElementAddress(self, old_name, new_name): |
2695 if self.expression == old_name: |
2221 self.expression = update_address(self.expression, address_model, new_leading) |
2696 self.expression = new_name |
2222 |
2697 setattr(cls, "updateElementName", updateElementName) |
2223 cls = _initElementClass("inVariable", "fbdObjects") |
2698 |
2224 if cls: |
2699 def updateElementAddress(self, address_model, new_leading): |
2225 setattr(cls, "updateElementName", _UpdateIOElementName) |
2700 self.expression = update_address(self.expression, address_model, new_leading) |
2226 setattr(cls, "updateElementAddress", _UpdateIOElementAddress) |
2701 setattr(cls, "updateElementAddress", updateElementAddress) |
|
2702 |
|
2703 setattr(cls, "Search", _SearchInIOVariable) |
2227 setattr(cls, "Search", _SearchInIOVariable) |
2704 |
2228 |
2705 cls = _initElementClass("outVariable", "fbdObjects_outVariable", "single") |
2229 cls = _initElementClass("outVariable", "fbdObjects", "single") |
2706 if cls: |
2230 if cls: |
2707 setattr(cls, "getinfos", _getvariableinfosFunction("output", True, False)) |
2231 setattr(cls, "updateElementName", _UpdateIOElementName) |
2708 |
2232 setattr(cls, "updateElementAddress", _UpdateIOElementAddress) |
2709 def updateElementName(self, old_name, new_name): |
|
2710 if self.expression == old_name: |
|
2711 self.expression = new_name |
|
2712 setattr(cls, "updateElementName", updateElementName) |
|
2713 |
|
2714 def updateElementAddress(self, address_model, new_leading): |
|
2715 self.expression = update_address(self.expression, address_model, new_leading) |
|
2716 setattr(cls, "updateElementAddress", updateElementAddress) |
|
2717 |
|
2718 setattr(cls, "Search", _SearchInIOVariable) |
2233 setattr(cls, "Search", _SearchInIOVariable) |
2719 |
2234 |
2720 cls = _initElementClass("inOutVariable", "fbdObjects_inOutVariable", "single") |
2235 cls = _initElementClass("inOutVariable", "fbdObjects", "single") |
2721 if cls: |
2236 if cls: |
2722 setattr(cls, "getinfos", _getvariableinfosFunction("inout", True, True)) |
2237 setattr(cls, "updateElementName", _UpdateIOElementName) |
2723 |
2238 setattr(cls, "updateElementAddress", _UpdateIOElementAddress) |
2724 def updateElementName(self, old_name, new_name): |
|
2725 if self.expression == old_name: |
|
2726 self.expression = new_name |
|
2727 setattr(cls, "updateElementName", updateElementName) |
|
2728 |
|
2729 def updateElementAddress(self, address_model, new_leading): |
|
2730 self.expression = update_address(self.expression, address_model, new_leading) |
|
2731 setattr(cls, "updateElementAddress", updateElementAddress) |
|
2732 |
|
2733 setattr(cls, "Search", _SearchInIOVariable) |
2239 setattr(cls, "Search", _SearchInIOVariable) |
2734 |
2240 |
2735 |
2241 |
2736 def _SearchInConnector(self, criteria, parent_infos=[]): |
2242 def _SearchInConnector(self, criteria, parent_infos=[]): |
2737 return _Search([("name", self.getname())], criteria, parent_infos + ["connector", self.getlocalId()]) |
2243 return _Search([("name", self.getname())], criteria, parent_infos + ["connector", self.getlocalId()]) |
2738 |
2244 |
2739 cls = _initElementClass("continuation", "commonObjects_continuation") |
2245 cls = _initElementClass("continuation", "commonObjects") |
2740 if cls: |
2246 if cls: |
2741 setattr(cls, "getinfos", _getconnectorinfosFunction("continuation")) |
|
2742 setattr(cls, "Search", _SearchInConnector) |
2247 setattr(cls, "Search", _SearchInConnector) |
2743 |
2248 |
2744 def updateElementName(self, old_name, new_name): |
2249 def updateElementName(self, old_name, new_name): |
2745 if self.name == old_name: |
2250 if self.name == old_name: |
2746 self.name = new_name |
2251 self.name = new_name |
2747 setattr(cls, "updateElementName", updateElementName) |
2252 setattr(cls, "updateElementName", updateElementName) |
2748 |
2253 |
2749 cls = _initElementClass("connector", "commonObjects_connector", "single") |
2254 cls = _initElementClass("connector", "commonObjects", "single") |
2750 if cls: |
2255 if cls: |
2751 setattr(cls, "getinfos", _getconnectorinfosFunction("connector")) |
|
2752 setattr(cls, "Search", _SearchInConnector) |
2256 setattr(cls, "Search", _SearchInConnector) |
2753 |
2257 |
2754 def updateElementName(self, old_name, new_name): |
2258 def updateElementName(self, old_name, new_name): |
2755 if self.name == old_name: |
2259 if self.name == old_name: |
2756 self.name = new_name |
2260 self.name = new_name |
2757 setattr(cls, "updateElementName", updateElementName) |
2261 setattr(cls, "updateElementName", updateElementName) |
2758 |
2262 |
2759 cls = PLCOpenClasses.get("connection", None) |
2263 cls = PLCOpenParser.GetElementClass("connection") |
2760 if cls: |
2264 if cls: |
2761 def setpoints(self, points): |
2265 def setpoints(self, points): |
2762 self.position = [] |
2266 positions = [] |
2763 for point in points: |
2267 for point in points: |
2764 position = PLCOpenClasses["position"]() |
2268 position = PLCOpenParser.CreateElement("position", "connection") |
2765 position.setx(point.x) |
2269 position.setx(point.x) |
2766 position.sety(point.y) |
2270 position.sety(point.y) |
2767 self.position.append(position) |
2271 positions.append(position) |
|
2272 self.position = positions |
2768 setattr(cls, "setpoints", setpoints) |
2273 setattr(cls, "setpoints", setpoints) |
2769 |
2274 |
2770 def getpoints(self): |
2275 def getpoints(self): |
2771 points = [] |
2276 points = [] |
2772 for position in self.position: |
2277 for position in self.position: |
2773 points.append((position.getx(),position.gety())) |
2278 points.append((position.getx(),position.gety())) |
2774 return points |
2279 return points |
2775 setattr(cls, "getpoints", getpoints) |
2280 setattr(cls, "getpoints", getpoints) |
2776 |
2281 |
2777 cls = PLCOpenClasses.get("connectionPointIn", None) |
2282 cls = PLCOpenParser.GetElementClass("connectionPointIn") |
2778 if cls: |
2283 if cls: |
2779 def setrelPositionXY(self, x, y): |
2284 def setrelPositionXY(self, x, y): |
2780 self.relPosition = PLCOpenClasses["position"]() |
2285 self.relPosition = PLCOpenParser.CreateElement("relPosition", "connectionPointIn") |
2781 self.relPosition.setx(x) |
2286 self.relPosition.setx(x) |
2782 self.relPosition.sety(y) |
2287 self.relPosition.sety(y) |
2783 setattr(cls, "setrelPositionXY", setrelPositionXY) |
2288 setattr(cls, "setrelPositionXY", setrelPositionXY) |
2784 |
2289 |
2785 def getrelPositionXY(self): |
2290 def getrelPositionXY(self): |
2786 if self.relPosition: |
2291 if self.relPosition is not None: |
2787 return self.relPosition.getx(), self.relPosition.gety() |
2292 return self.relPosition.getx(), self.relPosition.gety() |
2788 else: |
2293 return self.relPosition |
2789 return self.relPosition |
|
2790 setattr(cls, "getrelPositionXY", getrelPositionXY) |
2294 setattr(cls, "getrelPositionXY", getrelPositionXY) |
2791 |
2295 |
2792 def addconnection(self): |
2296 def addconnection(self): |
2793 if not self.content: |
2297 self.append(PLCOpenParser.CreateElement("connection", "connectionPointIn")) |
2794 self.content = {"name" : "connection", "value" : [PLCOpenClasses["connection"]()]} |
|
2795 else: |
|
2796 self.content["value"].append(PLCOpenClasses["connection"]()) |
|
2797 setattr(cls, "addconnection", addconnection) |
2298 setattr(cls, "addconnection", addconnection) |
2798 |
2299 |
2799 def removeconnection(self, idx): |
2300 def removeconnection(self, idx): |
2800 if self.content: |
2301 if len(self.content) > idx: |
2801 self.content["value"].pop(idx) |
2302 self.remove(self.content[idx]) |
2802 if len(self.content["value"]) == 0: |
|
2803 self.content = None |
|
2804 setattr(cls, "removeconnection", removeconnection) |
2303 setattr(cls, "removeconnection", removeconnection) |
2805 |
2304 |
2806 def removeconnections(self): |
2305 def removeconnections(self): |
2807 if self.content: |
2306 self.content = None |
2808 self.content = None |
|
2809 setattr(cls, "removeconnections", removeconnections) |
2307 setattr(cls, "removeconnections", removeconnections) |
2810 |
2308 |
|
2309 connection_xpath = PLCOpen_XPath("ppx:connection") |
|
2310 connection_by_position_xpath = PLCOpen_XPath("ppx:connection[position()=$pos]") |
2811 def getconnections(self): |
2311 def getconnections(self): |
2812 if self.content: |
2312 return connection_xpath(self) |
2813 return self.content["value"] |
|
2814 setattr(cls, "getconnections", getconnections) |
2313 setattr(cls, "getconnections", getconnections) |
2815 |
2314 |
2816 def setconnectionId(self, idx, id): |
2315 def getconnection(self, idx): |
2817 if self.content: |
2316 connection = connection_by_position_xpath(self, pos=idx+1) |
2818 self.content["value"][idx].setrefLocalId(id) |
2317 if len(connection) > 0: |
|
2318 return connection[0] |
|
2319 return None |
|
2320 setattr(cls, "getconnection", getconnection) |
|
2321 |
|
2322 def setconnectionId(self, idx, local_id): |
|
2323 connection = self.getconnection(idx) |
|
2324 if connection is not None: |
|
2325 connection.setrefLocalId(local_id) |
2819 setattr(cls, "setconnectionId", setconnectionId) |
2326 setattr(cls, "setconnectionId", setconnectionId) |
2820 |
2327 |
2821 def getconnectionId(self, idx): |
2328 def getconnectionId(self, idx): |
2822 if self.content: |
2329 connection = self.getconnection(idx) |
2823 return self.content["value"][idx].getrefLocalId() |
2330 if connection is not None: |
|
2331 return connection.getrefLocalId() |
2824 return None |
2332 return None |
2825 setattr(cls, "getconnectionId", getconnectionId) |
2333 setattr(cls, "getconnectionId", getconnectionId) |
2826 |
2334 |
2827 def setconnectionPoints(self, idx, points): |
2335 def setconnectionPoints(self, idx, points): |
2828 if self.content: |
2336 connection = self.getconnection(idx) |
2829 self.content["value"][idx].setpoints(points) |
2337 if connection is not None: |
|
2338 connection.setpoints(points) |
2830 setattr(cls, "setconnectionPoints", setconnectionPoints) |
2339 setattr(cls, "setconnectionPoints", setconnectionPoints) |
2831 |
2340 |
2832 def getconnectionPoints(self, idx): |
2341 def getconnectionPoints(self, idx): |
2833 if self.content: |
2342 connection = self.getconnection(idx) |
2834 return self.content["value"][idx].getpoints() |
2343 if connection is not None: |
2835 return None |
2344 return connection.getpoints() |
|
2345 return [] |
2836 setattr(cls, "getconnectionPoints", getconnectionPoints) |
2346 setattr(cls, "getconnectionPoints", getconnectionPoints) |
2837 |
2347 |
2838 def setconnectionParameter(self, idx, parameter): |
2348 def setconnectionParameter(self, idx, parameter): |
2839 if self.content: |
2349 connection = self.getconnection(idx) |
2840 self.content["value"][idx].setformalParameter(parameter) |
2350 if connection is not None: |
|
2351 connection.setformalParameter(parameter) |
2841 setattr(cls, "setconnectionParameter", setconnectionParameter) |
2352 setattr(cls, "setconnectionParameter", setconnectionParameter) |
2842 |
2353 |
2843 def getconnectionParameter(self, idx): |
2354 def getconnectionParameter(self, idx): |
2844 if self.content: |
2355 connection = self.getconnection(idx) |
2845 return self.content["value"][idx].getformalParameter() |
2356 if connection is not None: |
|
2357 return connection.getformalParameter() |
2846 return None |
2358 return None |
2847 setattr(cls, "getconnectionParameter", getconnectionParameter) |
2359 setattr(cls, "getconnectionParameter", getconnectionParameter) |
2848 |
2360 |
2849 cls = PLCOpenClasses.get("connectionPointOut", None) |
2361 cls = PLCOpenParser.GetElementClass("connectionPointOut") |
2850 if cls: |
2362 if cls: |
2851 def setrelPositionXY(self, x, y): |
2363 def setrelPositionXY(self, x, y): |
2852 self.relPosition = PLCOpenClasses["position"]() |
2364 self.relPosition = PLCOpenParser.CreateElement("relPosition", "connectionPointOut") |
2853 self.relPosition.setx(x) |
2365 self.relPosition.setx(x) |
2854 self.relPosition.sety(y) |
2366 self.relPosition.sety(y) |
2855 setattr(cls, "setrelPositionXY", setrelPositionXY) |
2367 setattr(cls, "setrelPositionXY", setrelPositionXY) |
2856 |
2368 |
2857 def getrelPositionXY(self): |
2369 def getrelPositionXY(self): |
2858 if self.relPosition: |
2370 if self.relPosition is not None: |
2859 return self.relPosition.getx(), self.relPosition.gety() |
2371 return self.relPosition.getx(), self.relPosition.gety() |
2860 return self.relPosition |
2372 return self.relPosition |
2861 setattr(cls, "getrelPositionXY", getrelPositionXY) |
2373 setattr(cls, "getrelPositionXY", getrelPositionXY) |
2862 |
2374 |
2863 cls = PLCOpenClasses.get("value", None) |
2375 cls = PLCOpenParser.GetElementClass("value") |
2864 if cls: |
2376 if cls: |
2865 def setvalue(self, value): |
2377 def setvalue(self, value): |
2866 value = value.strip() |
2378 value = value.strip() |
2867 if value.startswith("[") and value.endswith("]"): |
2379 if value.startswith("[") and value.endswith("]"): |
2868 arrayValue = PLCOpenClasses["value_arrayValue"]() |
2380 content = PLCOpenParser.CreateElement("arrayValue", "value") |
2869 self.content = {"name" : "arrayValue", "value" : arrayValue} |
|
2870 elif value.startswith("(") and value.endswith(")"): |
2381 elif value.startswith("(") and value.endswith(")"): |
2871 structValue = PLCOpenClasses["value_structValue"]() |
2382 content = PLCOpenParser.CreateElement("structValue", "value") |
2872 self.content = {"name" : "structValue", "value" : structValue} |
|
2873 else: |
2383 else: |
2874 simpleValue = PLCOpenClasses["value_simpleValue"]() |
2384 content = PLCOpenParser.CreateElement("simpleValue", "value") |
2875 self.content = {"name" : "simpleValue", "value": simpleValue} |
2385 content.setvalue(value) |
2876 self.content["value"].setvalue(value) |
2386 self.setcontent(content) |
2877 setattr(cls, "setvalue", setvalue) |
2387 setattr(cls, "setvalue", setvalue) |
2878 |
2388 |
2879 def getvalue(self): |
2389 def getvalue(self): |
2880 return self.content["value"].getvalue() |
2390 return self.content.getvalue() |
2881 setattr(cls, "getvalue", getvalue) |
2391 setattr(cls, "getvalue", getvalue) |
2882 |
2392 |
2883 def extractValues(values): |
2393 def extractValues(values): |
2884 items = values.split(",") |
2394 items = values.split(",") |
2885 i = 1 |
2395 i = 1 |