--- a/plcopen/plcopen.py Thu Aug 09 18:07:44 2007 +0200
+++ b/plcopen/plcopen.py Fri Aug 10 16:14:33 2007 +0200
@@ -413,7 +413,12 @@
def addPouVar(self, type, name):
content = self.interface.getContent()
if len(content) == 0 or content[-1]["name"] != "localVars":
- self.interface.appendContent("localVars", PLCOpenClasses["varList"]())
+ content.append({"name" : "localVars", "value" : PLCOpenClasses["varList"]()})
+ else:
+ varlist = content[-1]["value"]
+ variables = varlist.getVariable()
+ if varlist.getConstant() or varlist.getRetain() or len(variables) > 0 and variables[0].getAddress():
+ content.append({"name" : "localVars", "value" : PLCOpenClasses["varList"]()})
var = PLCOpenClasses["varListPlain_variable"]()
var.setName(name)
var_type = PLCOpenClasses["dataType"]()
@@ -438,7 +443,23 @@
content.remove(varlist)
break
setattr(cls, "removePouVar", removePouVar)
-
+
+ def hasBlock(self, name):
+ if self.getBodyType() in ["FBD", "LD", "SFC"]:
+ for instance in self.getInstances():
+ if isinstance(instance, PLCOpenClasses["block"]) and instance.getInstanceName() == name:
+ return True
+ for transition in self.transitions.getTransition():
+ result = transition.hasBlock(name)
+ if result:
+ return result
+ for action in self.actions.getAction():
+ result = action.hasBlock(name)
+ if result:
+ return result
+ return False
+ setattr(cls, "hasBlock", hasBlock)
+
def addTransition(self, name, type):
if not self.transitions:
self.addTransitions()
@@ -540,6 +561,14 @@
self.body.updateElementName(old_name, new_name)
setattr(cls, "updateElementName", updateElementName)
+ def hasBlock(self, name):
+ if self.getBodyType() in ["FBD", "LD", "SFC"]:
+ for instance in self.getInstances():
+ if isinstance(instance, PLCOpenClasses["block"]) and instance.getInstanceName() == name:
+ return True
+ return False
+ setattr(cls, "hasBlock", hasBlock)
+
cls = PLCOpenClasses.get("actions_action", None)
if cls:
setattr(cls, "setBodyType", setBodyType)
@@ -557,6 +586,14 @@
self.body.updateElementName(old_name, new_name)
setattr(cls, "updateElementName", updateElementName)
+ def hasBlock(self, name):
+ if self.getBodyType() in ["FBD", "LD", "SFC"]:
+ for instance in self.getInstances():
+ if isinstance(instance, PLCOpenClasses["block"]) and instance.getInstanceName() == name:
+ return True
+ return False
+ setattr(cls, "hasBlock", hasBlock)
+
cls = PLCOpenClasses.get("body", None)
if cls:
def appendContentInstance(self, name, instance):