Bug on custom POU list in plcopen model fixed
authorlbessard
Fri, 21 Nov 2008 13:45:25 +0100
changeset 286 67da12c94d2d
parent 285 ed45a7118af1
child 287 fab9a51d5b57
Bug on custom POU list in plcopen model fixed
PLCControler.py
plcopen/plcopen.py
--- a/PLCControler.py	Fri Oct 24 16:39:57 2008 +0200
+++ b/PLCControler.py	Fri Nov 21 13:45:25 2008 +0100
@@ -1134,7 +1134,7 @@
         blocktypes = []
         for category in BlockTypes + self.PluginTypes:
             for block in category["list"]:
-                if block["type"] != "function":
+                if block["type"] == "functionBlock":
                     blocktypes.append(block["name"])
         project = self.GetProject(debug)
         if project is not None:
--- a/plcopen/plcopen.py	Fri Oct 24 16:39:57 2008 +0200
+++ b/plcopen/plcopen.py	Fri Nov 21 13:45:25 2008 +0100
@@ -310,56 +310,55 @@
     def AddCustomBlockType(self, pou): 
         pou_name = pou.getname()
         pou_type = pou.getpouType()
-        if pou_type != "program":
-            block_infos = {"name" : pou_name, "type" : pou_type, "extensible" : False,
-                           "inputs" : [], "outputs" : [], "comment" : "",
-                           "generate" : generate_block, "initialise" : initialise_block}
-            if pou.getinterface():
-                return_type = pou.interface.getreturnType()
-                if return_type:
-                    var_type = return_type.getcontent()
-                    if var_type["name"] == "derived":
-                        block_infos["outputs"].append(("", var_type["value"].getname(), "none"))
-                    elif var_type["name"] in ["string", "wstring"]:
-                        block_infos["outputs"].append(("", var_type["name"].upper(), "none"))
-                    else:
-                        block_infos["outputs"].append(("", var_type["name"], "none"))
-                for type, varlist in pou.getvars():
-                    if type == "InOut":
-                        for var in varlist.getvariable():
-                            var_type = var.type.getcontent()
-                            if var_type["name"] == "derived":
-                                block_infos["inputs"].append((var.getname(), var_type["value"].getname(), "none"))
-                                block_infos["outputs"].append((var.getname(), var_type["value"].getname(), "none"))
-                            elif var_type["name"] in ["string", "wstring"]:
-                                block_infos["inputs"].append((var.getname(), var_type["name"].upper(), "none"))
-                                block_infos["outputs"].append((var.getname(), var_type["name"].upper(), "none"))
-                            else:
-                                block_infos["inputs"].append((var.getname(), var_type["name"], "none"))
-                                block_infos["outputs"].append((var.getname(), var_type["name"], "none"))
-                    elif type == "Input":
-                        for var in varlist.getvariable():
-                            var_type = var.type.getcontent()
-                            if var_type["name"] == "derived":
-                                block_infos["inputs"].append((var.getname(), var_type["value"].getname(), "none"))
-                            elif var_type["name"] in ["string", "wstring"]:
-                                block_infos["inputs"].append((var.getname(), var_type["name"].upper(), "none"))
-                            else:
-                                block_infos["inputs"].append((var.getname(), var_type["name"], "none"))
-                    elif type == "Output":
-                        for var in varlist.getvariable():
-                            var_type = var.type.getcontent()
-                            if var_type["name"] == "derived":
-                                block_infos["outputs"].append((var.getname(), var_type["value"].getname(), "none"))
-                            elif var_type["name"] in ["string", "wstring"]:
-                                block_infos["outputs"].append((var.getname(), var_type["name"].upper(), "none"))
-                            else:
-                                block_infos["outputs"].append((var.getname(), var_type["name"], "none"))    
-            if pou.getbodyType() in ["FBD","LD","SFC"]:
-                for instance in pou.getinstances():
-                    if isinstance(instance, PLCOpenClasses.get("commonObjects_comment", None)):
-                        block_infos["comment"] = instance.getcontentText()
-            self.CustomBlockTypes.append(block_infos)
+        block_infos = {"name" : pou_name, "type" : pou_type, "extensible" : False,
+                       "inputs" : [], "outputs" : [], "comment" : "",
+                       "generate" : generate_block, "initialise" : initialise_block}
+        if pou.getinterface():
+            return_type = pou.interface.getreturnType()
+            if return_type:
+                var_type = return_type.getcontent()
+                if var_type["name"] == "derived":
+                    block_infos["outputs"].append(("", var_type["value"].getname(), "none"))
+                elif var_type["name"] in ["string", "wstring"]:
+                    block_infos["outputs"].append(("", var_type["name"].upper(), "none"))
+                else:
+                    block_infos["outputs"].append(("", var_type["name"], "none"))
+            for type, varlist in pou.getvars():
+                if type == "InOut":
+                    for var in varlist.getvariable():
+                        var_type = var.type.getcontent()
+                        if var_type["name"] == "derived":
+                            block_infos["inputs"].append((var.getname(), var_type["value"].getname(), "none"))
+                            block_infos["outputs"].append((var.getname(), var_type["value"].getname(), "none"))
+                        elif var_type["name"] in ["string", "wstring"]:
+                            block_infos["inputs"].append((var.getname(), var_type["name"].upper(), "none"))
+                            block_infos["outputs"].append((var.getname(), var_type["name"].upper(), "none"))
+                        else:
+                            block_infos["inputs"].append((var.getname(), var_type["name"], "none"))
+                            block_infos["outputs"].append((var.getname(), var_type["name"], "none"))
+                elif type == "Input":
+                    for var in varlist.getvariable():
+                        var_type = var.type.getcontent()
+                        if var_type["name"] == "derived":
+                            block_infos["inputs"].append((var.getname(), var_type["value"].getname(), "none"))
+                        elif var_type["name"] in ["string", "wstring"]:
+                            block_infos["inputs"].append((var.getname(), var_type["name"].upper(), "none"))
+                        else:
+                            block_infos["inputs"].append((var.getname(), var_type["name"], "none"))
+                elif type == "Output":
+                    for var in varlist.getvariable():
+                        var_type = var.type.getcontent()
+                        if var_type["name"] == "derived":
+                            block_infos["outputs"].append((var.getname(), var_type["value"].getname(), "none"))
+                        elif var_type["name"] in ["string", "wstring"]:
+                            block_infos["outputs"].append((var.getname(), var_type["name"].upper(), "none"))
+                        else:
+                            block_infos["outputs"].append((var.getname(), var_type["name"], "none"))    
+        if pou.getbodyType() in ["FBD","LD","SFC"]:
+            for instance in pou.getinstances():
+                if isinstance(instance, PLCOpenClasses.get("commonObjects_comment", None)):
+                    block_infos["comment"] = instance.getcontentText()
+        self.CustomBlockTypes.append(block_infos)
     setattr(cls, "AddCustomBlockType", AddCustomBlockType)
 
     def RefreshElementUsingTree(self):
@@ -501,7 +500,7 @@
                 type = pou.getpouType()
         customblocktypes = []
         for customblocktype in self.CustomBlockTypes:
-            if customblocktype["name"] != exclude and not self.ElementIsUsedBy(exclude, customblocktype["name"]) and not (onlyfunctions and customblocktype["type"] != "function"):
+            if customblocktype["type"] != "program" and customblocktype["name"] != exclude and not self.ElementIsUsedBy(exclude, customblocktype["name"]) and not (onlyfunctions and customblocktype["type"] != "function"):
                 customblocktypes.append(customblocktype)
         return customblocktypes
     setattr(cls, "GetCustomBlockTypes", GetCustomBlockTypes)
@@ -510,7 +509,7 @@
     def GetCustomFunctionBlockTypes(self, exclude = ""):
         customblocktypes = []
         for customblocktype in self.CustomBlockTypes:
-            if customblocktype["name"] != exclude and not self.ElementIsUsedBy(exclude, customblocktype["name"]):
+            if customblocktype["type"] == "functionBlock" and customblocktype["name"] != exclude and not self.ElementIsUsedBy(exclude, customblocktype["name"]):
                 customblocktypes.append(customblocktype["name"])
         return customblocktypes
     setattr(cls, "GetCustomFunctionBlockTypes", GetCustomFunctionBlockTypes)