fix infinite recursion in 'Reset Execution Order' functionality if FBD body contains feedback connections
authorAndrey Skvortsov <andrej.skvortzov@gmail.com>
Tue, 04 Oct 2016 17:26:38 +0300
changeset 1534 d2abe4109467
parent 1532 a191e137a5bb
child 1535 b3c43aa29d94
fix infinite recursion in 'Reset Execution Order' functionality if FBD body contains feedback connections
plcopen/plcopen.py
--- a/plcopen/plcopen.py	Mon Sep 12 16:49:24 2016 +0300
+++ b/plcopen/plcopen.py	Tue Oct 04 17:26:38 2016 +0300
@@ -1559,7 +1559,7 @@
 cls = PLCOpenParser.GetElementClass("body")
 if cls:
     cls.currentExecutionOrderId = 0
-    
+    checkedBlocksDict = {}
     def resetcurrentExecutionOrderId(self):
         object.__setattr__(self, "currentExecutionOrderId", 0)
     setattr(cls, "resetcurrentExecutionOrderId", resetcurrentExecutionOrderId)
@@ -1576,6 +1576,7 @@
                                             PLCOpenParser.GetElementClass("connector", "commonObjects"), 
                                             PLCOpenParser.GetElementClass("continuation", "commonObjects"))):
                     element.setexecutionOrderId(0)
+            checkedBlocksDict.clear()
         else:
             raise TypeError, _("Can only generate execution order on FBD networks!")
     setattr(cls, "resetexecutionOrder", resetexecutionOrder)
@@ -1598,12 +1599,15 @@
         if self.content.getLocalTag() == "FBD":
             localid = link.getrefLocalId()
             instance = self.getcontentInstance(localid)
+            checkedBlocksDict[localid] = True
             if isinstance(instance, PLCOpenParser.GetElementClass("block", "fbdObjects")) and instance.getexecutionOrderId() == 0:
                 for variable in instance.inputVariables.getvariable():
                     connections = variable.connectionPointIn.getconnections()
                     if connections and len(connections) == 1:
-                        self.compileelementExecutionOrder(connections[0])
-                instance.setexecutionOrderId(self.getnewExecutionOrderId())
+                        if (checkedBlocksDict.has_key(connections[0].getrefLocalId()) == False):
+                            self.compileelementExecutionOrder(connections[0])
+                if instance.getexecutionOrderId() == 0:
+                    instance.setexecutionOrderId(self.getnewExecutionOrderId())
             elif isinstance(instance, PLCOpenParser.GetElementClass("continuation", "commonObjects")) and instance.getexecutionOrderId() == 0:
                 name = instance.getname()
                 for tmp_instance in self.getcontentInstances():