Added support for standard functions type compatibility check
authorlbessard
Wed, 19 Sep 2007 17:23:15 +0200
changeset 99 2b18a72dcaf0
parent 98 ec5d7af033d8
child 100 4e3f5b320bc3
Added support for standard functions type compatibility check
PLCControler.py
graphics/FBD_Objects.py
graphics/GraphicCommons.py
plcopen/structures.py
--- a/PLCControler.py	Wed Sep 19 15:20:59 2007 +0200
+++ b/PLCControler.py	Wed Sep 19 17:23:15 2007 +0200
@@ -903,7 +903,6 @@
         if self.CurrentElementEditing != None:
             if self.Project:
                 current_name = self.ElementsOpened[self.CurrentElementEditing]
-                print current_name
                 words = current_name.split("::")
                 if len(words) == 1:
                     name = current_name
--- a/graphics/FBD_Objects.py	Wed Sep 19 15:20:59 2007 +0200
+++ b/graphics/FBD_Objects.py	Wed Sep 19 17:23:15 2007 +0200
@@ -26,7 +26,7 @@
 
 from GraphicCommons import *
 from plcopen.structures import *
-
+from plcopen.structures import IsOfType
 
 #-------------------------------------------------------------------------------
 #                         Function Block Diagram Block
@@ -138,6 +138,22 @@
     def GetInputTypes(self):
         return tuple([input.GetType() for input in self.Inputs])
     
+    def GetConnectionResultType(self, connector):
+        resulttype = None
+        for input in self.Inputs:
+            name = input.GetName()
+            if input != connector and (name.startswith("IN") or name in ["MN", "MX"]):
+                inputtype = input.GetConnectedType()
+                if resulttype is None or inputtype is not None and IsOfType(inputtype, resulttype):
+                    resulttype = inputtype
+        for output in self.Outputs:
+            name = output.GetName()
+            if output != connector and name == "OUT":
+                outputtype = output.GetConnectedType()
+                if resulttype is None or outputtype is not None and IsOfType(outputtype, resulttype):
+                    resulttype = outputtype
+        return resulttype
+    
     # Returns all the block connectors 
     def GetConnectors(self):
         return {"inputs" : self.Inputs, "outputs" : self.Outputs}
--- a/graphics/GraphicCommons.py	Wed Sep 19 15:20:59 2007 +0200
+++ b/graphics/GraphicCommons.py	Wed Sep 19 17:23:15 2007 +0200
@@ -24,7 +24,7 @@
 
 import wx
 from math import *
-from plcopen.structures import IsOfType
+from plcopen.structures import IsOfType, IsEndType
 
 #-------------------------------------------------------------------------------
 #                               Common constants
@@ -703,13 +703,25 @@
     def GetParentBlock(self):
         return self.ParentBlock
     
-    # Returns the connector name
+    # Returns the connector type
     def GetType(self):
+        if IsEndType(self.Type):
+            return self.Type
+        else:
+            return self.ParentBlock.GetConnectionResultType(self)
+    
+    # Returns the connector type
+    def GetConnectedType(self):
+        if IsEndType(self.Type):
+            return self.Type
+        elif len(self.Wires) == 1:
+            return self.Wires[0][0].GetOtherConnectedType(self.Wires[0][1])
         return self.Type
     
     # Returns if connector type is compatible with type given
     def IsCompatible(self, type):
-        return IsOfType(type, self.Type) or IsOfType(self.Type, type)
+        reference = self.GetType()
+        return IsOfType(type, reference) or IsOfType(reference, type)
     
     # Changes the connector name
     def SetType(self, type):
@@ -988,6 +1000,12 @@
             return self.EndConnected.GetType()
         return None
     
+    def GetOtherConnectedType(self, handle):
+        if handle == 0:
+            return self.GetEndConnectedType()
+        else:
+            return self.GetStartConnectedType()
+    
     def IsConnectedCompatible(self):
         if self.StartConnected:
             return self.StartConnected.IsCompatible(self.GetEndConnectedType())
--- a/plcopen/structures.py	Wed Sep 19 15:20:59 2007 +0200
+++ b/plcopen/structures.py	Wed Sep 19 17:23:15 2007 +0200
@@ -270,6 +270,12 @@
         test = TypeHierarchy[test]
     return False
 
+def IsEndType(reference):
+    if reference is not None:
+        return len([typename for typename, parenttype in TypeHierarchy_list if parenttype == reference]) == 0
+    else:
+        return True
+
 """
 returns list of all types that correspont to the ANY* meta type
 """