--- a/PLCControler.py Fri Sep 27 16:22:40 2013 +0200
+++ b/PLCControler.py Fri Sep 27 16:27:54 2013 +0200
@@ -2287,24 +2287,25 @@
instance.translate(*diff)
return new_id, connections
- # Return the current pou editing informations
- def GetEditedElementInstanceInfos(self, tagname, id = None, exclude = [], debug = False):
+ # Return the current pou editing instances idx + def GetEditedElementInstancesIds(self, tagname, debug = False): element = self.GetEditedElement(tagname, debug)
- instance = element.getinstance(id)
- instance = element.getrandomInstance(exclude)
- if instance is not None:
- infos = instance.getinfos()
- if infos["type"] in ["input", "output", "inout"]:
- var_type = self.GetEditedElementVarValueType(tagname, infos["specific_values"]["name"], debug)
- infos["specific_values"]["value_type"] = var_type
+ return element.getinstancesIds() + # Return the current pou editing informations + def GetEditedElementInstanceInfos(self, tagname, id, debug = False): + element = self.GetEditedElement(tagname, debug) + if element is not None: + instance = element.getinstance(id) + if instance is not None: + infos = instance.getinfos() + if infos["type"] in ["input", "output", "inout"]: + var_type = self.GetEditedElementVarValueType(tagname, infos["specific_values"]["name"], debug) + infos["specific_values"]["value_type"] = var_type def ClearEditedElementExecutionOrder(self, tagname):
--- a/editors/Viewer.py Fri Sep 27 16:22:40 2013 +0200
+++ b/editors/Viewer.py Fri Sep 27 16:27:54 2013 +0200
@@ -1089,10 +1089,11 @@
# List of ids of already loaded blocks
+ ids = self.Controler.GetEditedElementInstancesIds(self.TagName, debug = self.Debug) # Load Blocks until they are all loaded
- while instance is not None:
- instance = self.Controler.GetEditedElementInstanceInfos(self.TagName, exclude = ids, debug = self.Debug)
+ instance = self.Controler.GetEditedElementInstanceInfos( + self.TagName, ids.popitem(0)[0], debug = self.Debug) self.loadInstance(instance, ids, selection)
@@ -1221,7 +1222,6 @@
# Load instance from given informations
def loadInstance(self, instance, ids, selection):
- ids.append(instance["id"])
self.current_id = max(self.current_id, instance["id"])
creation_function = ElementCreationFunctions.get(instance["type"], None)
connectors = {"inputs" : [], "outputs" : []}
@@ -1319,7 +1319,7 @@
- if refLocalId not in ids:
+ if ids.pop(refLocalId, False): new_instance = self.Controler.GetEditedElementInstanceInfos(self.TagName, refLocalId, debug = self.Debug)
if new_instance is not None:
self.loadInstance(new_instance, ids, selection)
--- a/plcopen/plcopen.py Fri Sep 27 16:22:40 2013 +0200
+++ b/plcopen/plcopen.py Fri Sep 27 16:27:54 2013 +0200
@@ -26,6 +26,8 @@
+from collections import OrderedDict Dictionary that makes the relation between var names in plcopen and displayed values
@@ -1089,11 +1091,11 @@
setattr(cls, "getinstance", getinstance)
- def getrandomInstance(self, exclude):
+ def getinstancesIds(self): - return self.body[0].getcontentRandomInstance(exclude)
- setattr(cls, "getrandomInstance", getrandomInstance)
+ return self.body[0].getcontentInstancesIds() + setattr(cls, "getinstancesIds", getinstancesIds) def getinstanceByName(self, name):
@@ -1609,18 +1611,13 @@
raise TypeError, _("%s body don't have instances!")%self.content.getLocalTag()
setattr(cls, "getcontentInstance", getcontentInstance)
- def getcontentRandomInstance(self, exclude):
+ def getcontentInstancesIds(self): if self.content.getLocalTag() in ["LD","FBD","SFC"]:
- instance = self.content.xpath("*%s[position()=1]" %
- ("[not(%s)]" % " or ".join(
- map(lambda x: "@localId=%d" % x, exclude))
- if len(exclude) > 0 else ""))
+ return OrderedDict([(instance.getlocalId(), True) + for instance in self.content]) raise TypeError, _("%s body don't have instances!")%self.content.getLocalTag()
- setattr(cls, "getcontentRandomInstance", getcontentRandomInstance)
+ setattr(cls, "getcontentInstancesIds", getcontentInstancesIds) def getcontentInstanceByName(self, name):
if self.content.getLocalTag() in ["LD","FBD","SFC"]: