152 text = text[:result.start()] + new_address + text[result.end():] |
152 text = text[:result.start()] + new_address + text[result.end():] |
153 startpos = result.start() + len(new_address) |
153 startpos = result.start() + len(new_address) |
154 result = address_model.search(self.text, startpos) |
154 result = address_model.search(self.text, startpos) |
155 self.text = text |
155 self.text = text |
156 setattr(cls, "updateElementAddress", updateElementAddress) |
156 setattr(cls, "updateElementAddress", updateElementAddress) |
|
157 |
|
158 def hasblock(self, block_type): |
|
159 text = self.text.upper() |
|
160 index = text.find(block_type.upper()) |
|
161 while index != -1: |
|
162 if (not (index > 0 and (text[index - 1].isalnum() or text[index - 1] == "_")) and |
|
163 not (index < len(text) - len(block_type) and text[index + len(block_type)] != "(")): |
|
164 return True |
|
165 index = text.find(block_type.upper(), index + len(block_type)) |
|
166 return False |
|
167 setattr(cls, "hasblock", hasblock) |
157 |
168 |
158 def Search(self, criteria, parent_infos): |
169 def Search(self, criteria, parent_infos): |
159 return [(tuple(parent_infos),) + result for result in TestTextElement(self.gettext(), criteria)] |
170 return [(tuple(parent_infos),) + result for result in TestTextElement(self.gettext(), criteria)] |
160 setattr(cls, "Search", Search) |
171 setattr(cls, "Search", Search) |
161 |
172 |
531 vartype_content = var.gettype().getcontent() |
542 vartype_content = var.gettype().getcontent() |
532 if vartype_content["name"] == "derived": |
543 if vartype_content["name"] == "derived": |
533 typename = vartype_content["value"].getname() |
544 typename = vartype_content["value"].getname() |
534 if self.ElementUsingTree.has_key(typename) and name not in self.ElementUsingTree[typename]: |
545 if self.ElementUsingTree.has_key(typename) and name not in self.ElementUsingTree[typename]: |
535 self.ElementUsingTree[typename].append(name) |
546 self.ElementUsingTree[typename].append(name) |
|
547 for typename in self.ElementUsingTree.iterkeys(): |
|
548 if typename != name and pou.hasblock(block_type=typename) and name not in self.ElementUsingTree[typename]: |
|
549 self.ElementUsingTree[typename].append(name) |
|
550 |
536 setattr(cls, "RefreshElementUsingTree", RefreshElementUsingTree) |
551 setattr(cls, "RefreshElementUsingTree", RefreshElementUsingTree) |
537 |
552 |
538 def GetParentType(self, type): |
553 def GetParentType(self, type): |
539 if self.CustomTypeHierarchy.has_key(type): |
554 if self.CustomTypeHierarchy.has_key(type): |
540 return self.CustomTypeHierarchy[type] |
555 return self.CustomTypeHierarchy[type] |
1380 if len(varlist["value"].getvariable()) == 0: |
1395 if len(varlist["value"].getvariable()) == 0: |
1381 content.remove(varlist) |
1396 content.remove(varlist) |
1382 break |
1397 break |
1383 setattr(cls, "removepouVar", removepouVar) |
1398 setattr(cls, "removepouVar", removepouVar) |
1384 |
1399 |
1385 def hasblock(self, name): |
1400 def hasblock(self, name=None, block_type=None): |
1386 if name != "" and self.getbodyType() in ["FBD", "LD", "SFC"]: |
1401 if self.getbodyType() in ["FBD", "LD", "SFC"]: |
1387 for instance in self.getinstances(): |
1402 for instance in self.getinstances(): |
1388 if isinstance(instance, PLCOpenClasses["fbdObjects_block"]) and instance.getinstanceName() == name: |
1403 if (isinstance(instance, PLCOpenClasses["fbdObjects_block"]) and |
|
1404 (name and instance.getinstanceName() == name or |
|
1405 block_type and instance.gettypeName() == block_type)): |
1389 return True |
1406 return True |
1390 if self.transitions: |
1407 if self.transitions: |
1391 for transition in self.transitions.gettransition(): |
1408 for transition in self.transitions.gettransition(): |
1392 result = transition.hasblock(name) |
1409 result = transition.hasblock(name, block_type) |
1393 if result: |
1410 if result: |
1394 return result |
1411 return result |
1395 if self.actions: |
1412 if self.actions: |
1396 for action in self.actions.getaction(): |
1413 for action in self.actions.getaction(): |
1397 result = action.hasblock(name) |
1414 result = action.hasblock(name, block_type) |
1398 if result: |
1415 if result: |
1399 return result |
1416 return result |
|
1417 elif block_type is not None and len(self.body) > 0: |
|
1418 return self.body[0].hasblock(block_type) |
1400 return False |
1419 return False |
1401 setattr(cls, "hasblock", hasblock) |
1420 setattr(cls, "hasblock", hasblock) |
1402 |
1421 |
1403 def addtransition(self, name, type): |
1422 def addtransition(self, name, type): |
1404 if not self.transitions: |
1423 if not self.transitions: |
1624 self.body.settext(text) |
1643 self.body.settext(text) |
1625 |
1644 |
1626 def gettext(self): |
1645 def gettext(self): |
1627 return self.body.gettext() |
1646 return self.body.gettext() |
1628 |
1647 |
|
1648 def hasblock(self, name=None, block_type=None): |
|
1649 if self.getbodyType() in ["FBD", "LD", "SFC"]: |
|
1650 for instance in self.getinstances(): |
|
1651 if (isinstance(instance, PLCOpenClasses["fbdObjects_block"]) and |
|
1652 (name and instance.getinstanceName() == name or |
|
1653 block_type and instance.gettypeName() == block_type)): |
|
1654 return True |
|
1655 elif block_type is not None: |
|
1656 return self.body.hasblock(block_type) |
|
1657 return False |
|
1658 |
|
1659 def updateElementName(self, old_name, new_name): |
|
1660 self.body.updateElementName(old_name, new_name) |
|
1661 |
|
1662 def updateElementAddress(self, address_model, new_leading): |
|
1663 self.body.updateElementAddress(address_model, new_leading) |
|
1664 |
|
1665 |
1629 cls = PLCOpenClasses.get("transitions_transition", None) |
1666 cls = PLCOpenClasses.get("transitions_transition", None) |
1630 if cls: |
1667 if cls: |
1631 setattr(cls, "setbodyType", setbodyType) |
1668 setattr(cls, "setbodyType", setbodyType) |
1632 setattr(cls, "getbodyType", getbodyType) |
1669 setattr(cls, "getbodyType", getbodyType) |
1633 setattr(cls, "resetexecutionOrder", resetexecutionOrder) |
1670 setattr(cls, "resetexecutionOrder", resetexecutionOrder) |
1639 setattr(cls, "getrandomInstance", getrandomInstance) |
1676 setattr(cls, "getrandomInstance", getrandomInstance) |
1640 setattr(cls, "getinstanceByName", getinstanceByName) |
1677 setattr(cls, "getinstanceByName", getinstanceByName) |
1641 setattr(cls, "removeinstance", removeinstance) |
1678 setattr(cls, "removeinstance", removeinstance) |
1642 setattr(cls, "settext", settext) |
1679 setattr(cls, "settext", settext) |
1643 setattr(cls, "gettext", gettext) |
1680 setattr(cls, "gettext", gettext) |
1644 |
1681 setattr(cls, "hasblock", hasblock) |
1645 def updateElementName(self, old_name, new_name): |
|
1646 self.body.updateElementName(old_name, new_name) |
|
1647 setattr(cls, "updateElementName", updateElementName) |
1682 setattr(cls, "updateElementName", updateElementName) |
1648 |
|
1649 def updateElementAddress(self, address_model, new_leading): |
|
1650 self.body.updateElementAddress(address_model, new_leading) |
|
1651 setattr(cls, "updateElementAddress", updateElementAddress) |
1683 setattr(cls, "updateElementAddress", updateElementAddress) |
1652 |
1684 |
1653 def hasblock(self, name): |
|
1654 if self.getbodyType() in ["FBD", "LD", "SFC"]: |
|
1655 for instance in self.getinstances(): |
|
1656 if isinstance(instance, PLCOpenClasses["fbdObjects_block"]) and instance.getinstanceName() == name: |
|
1657 return True |
|
1658 return False |
|
1659 setattr(cls, "hasblock", hasblock) |
|
1660 |
|
1661 def Search(self, criteria, parent_infos): |
1685 def Search(self, criteria, parent_infos): |
1662 search_result = [] |
1686 search_result = [] |
1663 parent_infos = parent_infos[:-1] + ["T::%s::%s" % (parent_infos[-1].split("::")[1], self.getname())] |
1687 parent_infos = parent_infos[:-1] + ["T::%s::%s" % (parent_infos[-1].split("::")[1], self.getname())] |
1664 for result in TestTextElement(self.getname(), criteria): |
1688 for result in TestTextElement(self.getname(), criteria): |
1665 search_result.append((tuple(parent_infos + ["name"]),) + result) |
1689 search_result.append((tuple(parent_infos + ["name"]),) + result) |
1680 setattr(cls, "getrandomInstance", getrandomInstance) |
1704 setattr(cls, "getrandomInstance", getrandomInstance) |
1681 setattr(cls, "getinstanceByName", getinstanceByName) |
1705 setattr(cls, "getinstanceByName", getinstanceByName) |
1682 setattr(cls, "removeinstance", removeinstance) |
1706 setattr(cls, "removeinstance", removeinstance) |
1683 setattr(cls, "settext", settext) |
1707 setattr(cls, "settext", settext) |
1684 setattr(cls, "gettext", gettext) |
1708 setattr(cls, "gettext", gettext) |
1685 |
1709 setattr(cls, "hasblock", hasblock) |
1686 def updateElementName(self, old_name, new_name): |
|
1687 self.body.updateElementName(old_name, new_name) |
|
1688 setattr(cls, "updateElementName", updateElementName) |
1710 setattr(cls, "updateElementName", updateElementName) |
1689 |
|
1690 def updateElementAddress(self, address_model, new_leading): |
|
1691 self.body.updateElementAddress(address_model, new_leading) |
|
1692 setattr(cls, "updateElementAddress", updateElementAddress) |
1711 setattr(cls, "updateElementAddress", updateElementAddress) |
1693 |
1712 |
1694 def hasblock(self, name): |
|
1695 if self.getbodyType() in ["FBD", "LD", "SFC"]: |
|
1696 for instance in self.getinstances(): |
|
1697 if isinstance(instance, PLCOpenClasses["fbdObjects_block"]) and instance.getinstanceName() == name: |
|
1698 return True |
|
1699 return False |
|
1700 setattr(cls, "hasblock", hasblock) |
|
1701 |
|
1702 def Search(self, criteria, parent_infos): |
1713 def Search(self, criteria, parent_infos): |
1703 search_result = [] |
1714 search_result = [] |
1704 parent_infos = parent_infos[:-1] + ["A::%s::%s" % (parent_infos[-1].split("::")[1], self.getname())] |
1715 parent_infos = parent_infos[:-1] + ["A::%s::%s" % (parent_infos[-1].split("::")[1], self.getname())] |
1705 for result in TestTextElement(self.getname(), criteria): |
1716 for result in TestTextElement(self.getname(), criteria): |
1706 search_result.append((tuple(parent_infos + ["name"]),) + result) |
1717 search_result.append((tuple(parent_infos + ["name"]),) + result) |
1856 if self.content["name"] in ["IL","ST"]: |
1867 if self.content["name"] in ["IL","ST"]: |
1857 return self.content["value"].gettext() |
1868 return self.content["value"].gettext() |
1858 else: |
1869 else: |
1859 raise TypeError, _("%s body don't have text!")%self.content["name"] |
1870 raise TypeError, _("%s body don't have text!")%self.content["name"] |
1860 setattr(cls, "gettext", gettext) |
1871 setattr(cls, "gettext", gettext) |
|
1872 |
|
1873 def hasblock(self, block_type): |
|
1874 if self.content["name"] in ["IL","ST"]: |
|
1875 return self.content["value"].hasblock(block_type) |
|
1876 else: |
|
1877 raise TypeError, _("%s body don't have text!")%self.content["name"] |
|
1878 setattr(cls, "hasblock", hasblock) |
1861 |
1879 |
1862 def updateElementName(self, old_name, new_name): |
1880 def updateElementName(self, old_name, new_name): |
1863 if self.content["name"] in ["IL", "ST"]: |
1881 if self.content["name"] in ["IL", "ST"]: |
1864 self.content["value"].updateElementName(old_name, new_name) |
1882 self.content["value"].updateElementName(old_name, new_name) |
1865 else: |
1883 else: |