diff -r f034fb2b1aab -r 9ffc49bfdf9d plcopen/plcopen.py --- a/plcopen/plcopen.py Fri Aug 30 10:59:06 2013 +0200 +++ b/plcopen/plcopen.py Fri Aug 30 18:10:30 2013 +0200 @@ -125,6 +125,38 @@ PLCOpenParser = GenerateParserFromXSD(os.path.join(os.path.split(__file__)[0], "tc6_xml_v201.xsd")) +LOAD_POU_PROJECT_TEMPLATE = """ + + + + + + + + + + + + %s + + + + + +""" + +def LOAD_POU_INSTANCES_PROJECT_TEMPLATE(body_type): + return LOAD_POU_PROJECT_TEMPLATE % """ + + + <%(body_type)s>%%s + +""" % locals() + def LoadProject(filepath): project_file = open(filepath) project_xml = project_file.read().replace( @@ -138,6 +170,22 @@ return etree.fromstring(project_xml, PLCOpenParser) +def LoadPou(xml_string): + root = etree.fromstring( + LOAD_POU_PROJECT_TEMPLATE % xml_string, + PLCOpenParser) + return root.xpath( + "/ppx:project/ppx:types/ppx:pous/ppx:pou", + namespaces=PLCOpenParser.NSMAP)[0] + +def LoadPouInstances(xml_string, body_type): + root = etree.fromstring( + LOAD_POU_INSTANCES_PROJECT_TEMPLATE(body_type) % xml_string, + PLCOpenParser) + return root.xpath( + "/ppx:project/ppx:types/ppx:pous/ppx:pou[@name='paste_pou']/ppx:body/ppx:%s/*" % body_type, + namespaces=PLCOpenParser.NSMAP) + def SaveProject(project, filepath): project_file = open(filepath, 'w') project_file.write(etree.tostring( @@ -2409,7 +2457,7 @@ def getconditionConnection(self): if self.condition is not None: content = self.condition.getcontent() - if content.getLocalTag() == "connection": + if content.getLocalTag() == "connectionPointIn": return content return None setattr(cls, "getconditionConnection", getconditionConnection) @@ -2425,7 +2473,7 @@ def translate(self, dx, dy): _translateSingle(self, dx, dy) condition_connection = self.getconditionConnection() - if condition_connection: + if condition_connection is not None: _translateConnections(condition_connection, dx, dy) setattr(cls, "translate", translate)