214 def LoadProjectXML(project_xml): |
214 def LoadProjectXML(project_xml): |
215 project_xml = project_xml.replace( |
215 project_xml = project_xml.replace( |
216 "http://www.plcopen.org/xml/tc6.xsd", |
216 "http://www.plcopen.org/xml/tc6.xsd", |
217 "http://www.plcopen.org/xml/tc6_0201") |
217 "http://www.plcopen.org/xml/tc6_0201") |
218 for cre, repl in [ |
218 for cre, repl in [ |
219 (re.compile("(?<!<xhtml:p>)(?:<!\[CDATA\[)"), "<xhtml:p><![CDATA["), |
219 (re.compile("(?<!<xhtml:p>)(?:<!\[CDATA\[)"), "<xhtml:p><![CDATA["), |
220 (re.compile("(?:]]>)(?!</xhtml:p>)"), "]]></xhtml:p>")]: |
220 (re.compile("(?:]]>)(?!</xhtml:p>)"), "]]></xhtml:p>")]: |
221 project_xml = cre.sub(repl, project_xml) |
221 project_xml = cre.sub(repl, project_xml) |
222 |
222 |
223 try: |
223 try: |
224 tree, error = PLCOpenParser.LoadXMLString(project_xml) |
224 tree, error = PLCOpenParser.LoadXMLString(project_xml) |
225 if error is None: |
225 if error is None: |
1317 setattr(cls, "hasstep", hasstep) |
1317 setattr(cls, "hasstep", hasstep) |
1318 |
1318 |
1319 def hasblock(self, name=None, block_type=None): |
1319 def hasblock(self, name=None, block_type=None): |
1320 if self.getbodyType() in ["FBD", "LD", "SFC"]: |
1320 if self.getbodyType() in ["FBD", "LD", "SFC"]: |
1321 for instance in self.getinstances(): |
1321 for instance in self.getinstances(): |
1322 if (isinstance(instance, PLCOpenParser.GetElementClass("block", "fbdObjects")) and |
1322 if isinstance(instance, PLCOpenParser.GetElementClass("block", "fbdObjects")) \ |
1323 (TextMatched(instance.getinstanceName(), name) or TextMatched(instance.gettypeName(), block_type))): |
1323 and (TextMatched(instance.getinstanceName(), name) or |
|
1324 TextMatched(instance.gettypeName(), block_type)): |
1324 return True |
1325 return True |
1325 if self.transitions: |
1326 if self.transitions: |
1326 for transition in self.transitions.gettransition(): |
1327 for transition in self.transitions.gettransition(): |
1327 result = transition.hasblock(name, block_type) |
1328 result = transition.hasblock(name, block_type) |
1328 if result: |
1329 if result: |
1563 |
1564 |
1564 |
1565 |
1565 def hasblock(self, name=None, block_type=None): |
1566 def hasblock(self, name=None, block_type=None): |
1566 if self.getbodyType() in ["FBD", "LD", "SFC"]: |
1567 if self.getbodyType() in ["FBD", "LD", "SFC"]: |
1567 for instance in self.getinstances(): |
1568 for instance in self.getinstances(): |
1568 if (isinstance(instance, PLCOpenParser.GetElementClass("block", "fbdObjects")) and |
1569 if isinstance(instance, PLCOpenParser.GetElementClass("block", "fbdObjects")) and \ |
1569 (TextMatched(instance.getinstanceName(), name) or TextMatched(instance.gettypeName(), block_type))): |
1570 (TextMatched(instance.getinstanceName(), name) or TextMatched(instance.gettypeName(), block_type)): |
1570 return True |
1571 return True |
1571 elif block_type is not None: |
1572 elif block_type is not None: |
1572 return self.body.hasblock(block_type) |
1573 return self.body.hasblock(block_type) |
1573 return False |
1574 return False |
1574 |
1575 |
1690 self.compileelementExecutionOrder(connections[0]) |
1691 self.compileelementExecutionOrder(connections[0]) |
1691 if instance.getexecutionOrderId() == 0: |
1692 if instance.getexecutionOrderId() == 0: |
1692 instance.setexecutionOrderId(self.getnewExecutionOrderId()) |
1693 instance.setexecutionOrderId(self.getnewExecutionOrderId()) |
1693 elif isinstance(instance, PLCOpenParser.GetElementClass("continuation", "commonObjects")) and instance.getexecutionOrderId() == 0: |
1694 elif isinstance(instance, PLCOpenParser.GetElementClass("continuation", "commonObjects")) and instance.getexecutionOrderId() == 0: |
1694 for tmp_instance in self.getcontentInstances(): |
1695 for tmp_instance in self.getcontentInstances(): |
1695 if (isinstance(tmp_instance, PLCOpenParser.GetElementClass("connector", "commonObjects")) and |
1696 if isinstance(tmp_instance, PLCOpenParser.GetElementClass("connector", "commonObjects")) and \ |
1696 TextMatched(tmp_instance.getname(), instance.getname()) and tmp_instance.getexecutionOrderId() == 0): |
1697 TextMatched(tmp_instance.getname(), instance.getname()) and \ |
|
1698 tmp_instance.getexecutionOrderId() == 0: |
1697 connections = tmp_instance.connectionPointIn.getconnections() |
1699 connections = tmp_instance.connectionPointIn.getconnections() |
1698 if connections and len(connections) == 1: |
1700 if connections and len(connections) == 1: |
1699 self.compileelementExecutionOrder(connections[0]) |
1701 self.compileelementExecutionOrder(connections[0]) |
1700 else: |
1702 else: |
1701 raise TypeError(_("Can only generate execution order on FBD networks!")) |
1703 raise TypeError(_("Can only generate execution order on FBD networks!")) |