plcopen/plcopen.py
changeset 1740 b789b695b5c6
parent 1739 ec153828ded2
child 1742 92932cd370a4
equal deleted inserted replaced
1739:ec153828ded2 1740:b789b695b5c6
    52 }
    52 }
    53 
    53 
    54 """
    54 """
    55 Define in which order var types must be displayed
    55 Define in which order var types must be displayed
    56 """
    56 """
    57 VarOrder = ["Local","Temp","Input","Output","InOut","External","Global","Access"]
    57 VarOrder = ["Local", "Temp", "Input", "Output", "InOut", "External", "Global", "Access"]
    58 
    58 
    59 """
    59 """
    60 Define which action qualifier must be associated with a duration
    60 Define which action qualifier must be associated with a duration
    61 """
    61 """
    62 QualifierList = OrderedDict([("N", False), ("R", False), ("S", False),
    62 QualifierList = OrderedDict([("N", False), ("R", False), ("S", False),
  1690         else:
  1690         else:
  1691             raise TypeError, _("Can only generate execution order on FBD networks!")
  1691             raise TypeError, _("Can only generate execution order on FBD networks!")
  1692     setattr(cls, "setelementExecutionOrder", setelementExecutionOrder)
  1692     setattr(cls, "setelementExecutionOrder", setelementExecutionOrder)
  1693 
  1693 
  1694     def appendcontentInstance(self, instance):
  1694     def appendcontentInstance(self, instance):
  1695         if self.content.getLocalTag() in ["LD","FBD","SFC"]:
  1695         if self.content.getLocalTag() in ["LD", "FBD", "SFC"]:
  1696             self.content.appendcontent(instance)
  1696             self.content.appendcontent(instance)
  1697         else:
  1697         else:
  1698             raise TypeError, _("%s body don't have instances!") % self.content.getLocalTag()
  1698             raise TypeError, _("%s body don't have instances!") % self.content.getLocalTag()
  1699     setattr(cls, "appendcontentInstance", appendcontentInstance)
  1699     setattr(cls, "appendcontentInstance", appendcontentInstance)
  1700 
  1700 
  1701     def getcontentInstances(self):
  1701     def getcontentInstances(self):
  1702         if self.content.getLocalTag() in ["LD","FBD","SFC"]:
  1702         if self.content.getLocalTag() in ["LD", "FBD", "SFC"]:
  1703             return self.content.getcontent()
  1703             return self.content.getcontent()
  1704         else:
  1704         else:
  1705             raise TypeError, _("%s body don't have instances!") % self.content.getLocalTag()
  1705             raise TypeError, _("%s body don't have instances!") % self.content.getLocalTag()
  1706     setattr(cls, "getcontentInstances", getcontentInstances)
  1706     setattr(cls, "getcontentInstances", getcontentInstances)
  1707 
  1707 
  1708     instance_by_id_xpath = PLCOpen_XPath("*[@localId=$localId]")
  1708     instance_by_id_xpath = PLCOpen_XPath("*[@localId=$localId]")
  1709     instance_by_name_xpath = PLCOpen_XPath("ppx:block[@instanceName=$name]")
  1709     instance_by_name_xpath = PLCOpen_XPath("ppx:block[@instanceName=$name]")
  1710     def getcontentInstance(self, local_id):
  1710     def getcontentInstance(self, local_id):
  1711         if self.content.getLocalTag() in ["LD","FBD","SFC"]:
  1711         if self.content.getLocalTag() in ["LD", "FBD", "SFC"]:
  1712             instance = instance_by_id_xpath(self.content, localId=local_id)
  1712             instance = instance_by_id_xpath(self.content, localId=local_id)
  1713             if len(instance) > 0:
  1713             if len(instance) > 0:
  1714                 return instance[0]
  1714                 return instance[0]
  1715             return None
  1715             return None
  1716         else:
  1716         else:
  1717             raise TypeError, _("%s body don't have instances!") % self.content.getLocalTag()
  1717             raise TypeError, _("%s body don't have instances!") % self.content.getLocalTag()
  1718     setattr(cls, "getcontentInstance", getcontentInstance)
  1718     setattr(cls, "getcontentInstance", getcontentInstance)
  1719 
  1719 
  1720     def getcontentInstancesIds(self):
  1720     def getcontentInstancesIds(self):
  1721         if self.content.getLocalTag() in ["LD","FBD","SFC"]:
  1721         if self.content.getLocalTag() in ["LD", "FBD", "SFC"]:
  1722             return OrderedDict([(instance.getlocalId(), True)
  1722             return OrderedDict([(instance.getlocalId(), True)
  1723                                 for instance in self.content])
  1723                                 for instance in self.content])
  1724         else:
  1724         else:
  1725             raise TypeError, _("%s body don't have instances!") % self.content.getLocalTag()
  1725             raise TypeError, _("%s body don't have instances!") % self.content.getLocalTag()
  1726     setattr(cls, "getcontentInstancesIds", getcontentInstancesIds)
  1726     setattr(cls, "getcontentInstancesIds", getcontentInstancesIds)
  1727 
  1727 
  1728     def getcontentInstanceByName(self, name):
  1728     def getcontentInstanceByName(self, name):
  1729         if self.content.getLocalTag() in ["LD","FBD","SFC"]:
  1729         if self.content.getLocalTag() in ["LD", "FBD", "SFC"]:
  1730             instance = instance_by_name_xpath(self.content)
  1730             instance = instance_by_name_xpath(self.content)
  1731             if len(instance) > 0:
  1731             if len(instance) > 0:
  1732                 return instance[0]
  1732                 return instance[0]
  1733             return None
  1733             return None
  1734         else:
  1734         else:
  1735             raise TypeError, _("%s body don't have instances!") % self.content.getLocalTag()
  1735             raise TypeError, _("%s body don't have instances!") % self.content.getLocalTag()
  1736     setattr(cls, "getcontentInstanceByName", getcontentInstanceByName)
  1736     setattr(cls, "getcontentInstanceByName", getcontentInstanceByName)
  1737 
  1737 
  1738     def removecontentInstance(self, local_id):
  1738     def removecontentInstance(self, local_id):
  1739         if self.content.getLocalTag() in ["LD","FBD","SFC"]:
  1739         if self.content.getLocalTag() in ["LD", "FBD", "SFC"]:
  1740             instance = instance_by_id_xpath(self.content, localId=local_id)
  1740             instance = instance_by_id_xpath(self.content, localId=local_id)
  1741             if len(instance) > 0:
  1741             if len(instance) > 0:
  1742                 self.content.remove(instance[0])
  1742                 self.content.remove(instance[0])
  1743             else:
  1743             else:
  1744                 raise ValueError, _("Instance with id %d doesn't exist!") % id
  1744                 raise ValueError, _("Instance with id %d doesn't exist!") % id
  1745         else:
  1745         else:
  1746             raise TypeError, "%s body don't have instances!" % self.content.getLocalTag()
  1746             raise TypeError, "%s body don't have instances!" % self.content.getLocalTag()
  1747     setattr(cls, "removecontentInstance", removecontentInstance)
  1747     setattr(cls, "removecontentInstance", removecontentInstance)
  1748 
  1748 
  1749     def settext(self, text):
  1749     def settext(self, text):
  1750         if self.content.getLocalTag() in ["IL","ST"]:
  1750         if self.content.getLocalTag() in ["IL", "ST"]:
  1751             self.content.setanyText(text)
  1751             self.content.setanyText(text)
  1752         else:
  1752         else:
  1753             raise TypeError, _("%s body don't have text!") % self.content.getLocalTag()
  1753             raise TypeError, _("%s body don't have text!") % self.content.getLocalTag()
  1754     setattr(cls, "settext", settext)
  1754     setattr(cls, "settext", settext)
  1755 
  1755 
  1756     def gettext(self):
  1756     def gettext(self):
  1757         if self.content.getLocalTag() in ["IL","ST"]:
  1757         if self.content.getLocalTag() in ["IL", "ST"]:
  1758             return self.content.getanyText()
  1758             return self.content.getanyText()
  1759         else:
  1759         else:
  1760             raise TypeError, _("%s body don't have text!") % self.content.getLocalTag()
  1760             raise TypeError, _("%s body don't have text!") % self.content.getLocalTag()
  1761     setattr(cls, "gettext", gettext)
  1761     setattr(cls, "gettext", gettext)
  1762 
  1762 
  1763     def hasblock(self, block_type):
  1763     def hasblock(self, block_type):
  1764         if self.content.getLocalTag() in ["IL","ST"]:
  1764         if self.content.getLocalTag() in ["IL", "ST"]:
  1765             return self.content.hasblock(block_type)
  1765             return self.content.hasblock(block_type)
  1766         else:
  1766         else:
  1767             raise TypeError, _("%s body don't have text!") % self.content.getLocalTag()
  1767             raise TypeError, _("%s body don't have text!") % self.content.getLocalTag()
  1768     setattr(cls, "hasblock", hasblock)
  1768     setattr(cls, "hasblock", hasblock)
  1769 
  1769 
  2363     setattr(cls, "setpoints", setpoints)
  2363     setattr(cls, "setpoints", setpoints)
  2364 
  2364 
  2365     def getpoints(self):
  2365     def getpoints(self):
  2366         points = []
  2366         points = []
  2367         for position in self.position:
  2367         for position in self.position:
  2368             points.append((position.getx(),position.gety()))
  2368             points.append((position.getx(), position.gety()))
  2369         return points
  2369         return points
  2370     setattr(cls, "getpoints", getpoints)
  2370     setattr(cls, "getpoints", getpoints)
  2371 
  2371 
  2372 cls = PLCOpenParser.GetElementClass("connectionPointIn")
  2372 cls = PLCOpenParser.GetElementClass("connectionPointIn")
  2373 if cls:
  2373 if cls: