--- a/plcopen/plcopen.py Fri Sep 02 18:16:58 2011 +0200
+++ b/plcopen/plcopen.py Wed Sep 07 15:53:28 2011 +0200
@@ -649,15 +649,34 @@
setattr(cls, "GetCustomBlockResource", GetCustomBlockResource)
# Return Data Types checking for recursion
- def GetCustomDataTypes(self, exclude = ""):
+ def GetCustomDataTypes(self, exclude = "", only_locatable = False):
customdatatypes = []
for customdatatype in self.getdataTypes():
- customdatatype_name = customdatatype.getname()
- if customdatatype_name != exclude and not self.ElementIsUsedBy(exclude, customdatatype_name):
- customdatatypes.append(customdatatype_name)
+ if not only_locatable or self.IsLocatableType(customdatatype):
+ customdatatype_name = customdatatype.getname()
+ if customdatatype_name != exclude and not self.ElementIsUsedBy(exclude, customdatatype_name):
+ customdatatypes.append(customdatatype_name)
return customdatatypes
setattr(cls, "GetCustomDataTypes", GetCustomDataTypes)
+ # Return if Data Type can be used for located variables
+ def IsLocatableType(self, datatype):
+ basetype_content = datatype.baseType.getcontent()
+ if basetype_content["name"] in ["enum", "struct"]:
+ return False
+ elif basetype_content["name"] == "derived":
+ base_type = self.getdataType(basetype_content["value"].getname())
+ if base_type is not None:
+ return self.IsLocatableType(base_type)
+ elif basetype_content["name"] == "array":
+ array_base_type = basetype_content["value"].baseType.getcontent()
+ if array_base_type["value"] is not None and array_base_type["name"] not in ["string", "wstring"]:
+ base_type = self.getdataType(array_base_type["value"].getname())
+ if base_type is not None:
+ return self.IsLocatableType(base_type)
+ return True
+ setattr(cls, "IsLocatableType", IsLocatableType)
+
cls = PLCOpenClasses.get("project_fileHeader", None)
if cls:
cls.singleLineAttributes = False