1532 return None |
1533 return None |
1533 |
1534 |
1534 # Function that add a new confnode to the confnode list |
1535 # Function that add a new confnode to the confnode list |
1535 def AddConfNodeTypesList(self, typeslist): |
1536 def AddConfNodeTypesList(self, typeslist): |
1536 self.ConfNodeTypes.extend(typeslist) |
1537 self.ConfNodeTypes.extend(typeslist) |
|
1538 addedcat = [{"name": _("%s POUs") % confnodetypes["name"], |
|
1539 "list": confnodetypes["types"].GetCustomBlockTypes()} |
|
1540 for confnodetypes in typeslist] |
|
1541 self.TotalTypes.extend(addedcat) |
|
1542 for cat in addedcat: |
|
1543 for desc in cat["list"]: |
|
1544 BlkLst = self.TotalTypesDict.setdefault(desc["name"],[]) |
|
1545 BlkLst.append((section["name"], desc)) |
1537 |
1546 |
1538 # Function that clear the confnode list |
1547 # Function that clear the confnode list |
1539 def ClearConfNodeTypes(self): |
1548 def ClearConfNodeTypes(self): |
1540 for i in xrange(len(self.ConfNodeTypes)): |
1549 self.ConfNodeTypes = [] |
1541 self.ConfNodeTypes.pop(0) |
1550 self.TotalTypesDict = StdBlckDct.copy() |
|
1551 self.TotalTypes = StdBlckLst[:] |
1542 |
1552 |
1543 def GetConfNodeBlockTypes(self): |
1553 def GetConfNodeBlockTypes(self): |
1544 return [{"name": _("%s POUs") % confnodetypes["name"], |
1554 return [{"name": _("%s POUs") % confnodetypes["name"], |
1545 "list": confnodetypes["types"].GetCustomBlockTypes()} |
1555 "list": confnodetypes["types"].GetCustomBlockTypes()} |
1546 for confnodetypes in self.ConfNodeTypes] |
1556 for confnodetypes in self.ConfNodeTypes] |
1547 |
1557 |
1548 def GetConfNodeDataTypes(self, exclude = "", only_locatables = False): |
1558 def GetConfNodeDataTypes(self, exclude = None, only_locatables = False): |
1549 return [{"name": _("%s Data Types") % confnodetypes["name"], |
1559 return [{"name": _("%s Data Types") % confnodetypes["name"], |
1550 "list": [datatype["name"] for datatype in confnodetypes["types"].GetCustomDataTypes(exclude, only_locatables)]} |
1560 "list": [datatype["name"] for datatype in confnodetypes["types"].GetCustomDataTypes(exclude, only_locatables)]} |
1551 for confnodetypes in self.ConfNodeTypes] |
1561 for confnodetypes in self.ConfNodeTypes] |
1552 |
1562 |
1553 def GetConfNodeDataType(self, type): |
1563 def GetConfNodeDataType(self, typename): |
1554 for confnodetype in self.ConfNodeTypes: |
1564 for confnodetype in self.ConfNodeTypes: |
1555 datatype = confnodetype["types"].getdataType(type) |
1565 datatype = confnodetype["types"].getdataType(typename) |
1556 if datatype is not None: |
1566 if datatype is not None: |
1557 return datatype |
1567 return datatype |
1558 return None |
1568 return None |
1559 |
1569 |
1560 def GetVariableLocationTree(self): |
1570 def GetVariableLocationTree(self): |
1590 |
1600 |
1591 global_vars.append(tempvar) |
1601 global_vars.append(tempvar) |
1592 return global_vars |
1602 return global_vars |
1593 |
1603 |
1594 # Function that returns the block definition associated to the block type given |
1604 # Function that returns the block definition associated to the block type given |
1595 def GetBlockType(self, type, inputs = None, debug = False): |
1605 def GetBlockType(self, typename, inputs = None, debug = False): |
1596 result_blocktype = None |
1606 result_blocktype = None |
1597 for category in BlockTypes + self.GetConfNodeBlockTypes(): |
1607 for sectioname, blocktype in self.TotalTypesDict.get(typename,[]): |
1598 for blocktype in category["list"]: |
1608 if inputs is not None and inputs != "undefined": |
1599 if blocktype["name"] == type: |
1609 block_inputs = tuple([var_type for name, var_type, modifier in blocktype["inputs"]]) |
1600 if inputs is not None and inputs != "undefined": |
1610 if reduce(lambda x, y: x and y, map(lambda x: x[0] == "ANY" or self.IsOfType(*x), zip(inputs, block_inputs)), True): |
1601 block_inputs = tuple([var_type for name, var_type, modifier in blocktype["inputs"]]) |
1611 return blocktype |
1602 if reduce(lambda x, y: x and y, map(lambda x: x[0] == "ANY" or self.IsOfType(*x), zip(inputs, block_inputs)), True): |
1612 else: |
1603 return blocktype |
1613 if result_blocktype is not None: |
|
1614 if inputs == "undefined": |
|
1615 return None |
1604 else: |
1616 else: |
1605 if result_blocktype is not None: |
1617 result_blocktype["inputs"] = [(i[0], "ANY", i[2]) for i in result_blocktype["inputs"]] |
1606 if inputs == "undefined": |
1618 result_blocktype["outputs"] = [(o[0], "ANY", o[2]) for o in result_blocktype["outputs"]] |
1607 return None |
1619 return result_blocktype |
1608 else: |
1620 result_blocktype = blocktype.copy() |
1609 result_blocktype["inputs"] = [(i[0], "ANY", i[2]) for i in result_blocktype["inputs"]] |
|
1610 result_blocktype["outputs"] = [(o[0], "ANY", o[2]) for o in result_blocktype["outputs"]] |
|
1611 return result_blocktype |
|
1612 result_blocktype = blocktype.copy() |
|
1613 if result_blocktype is not None: |
1621 if result_blocktype is not None: |
1614 return result_blocktype |
1622 return result_blocktype |
1615 project = self.GetProject(debug) |
1623 project = self.GetProject(debug) |
1616 if project is not None: |
1624 if project is not None: |
1617 return project.GetCustomBlockType(type, inputs) |
1625 return project.GetCustomBlockType(typename, inputs) |
1618 return None |
1626 return None |
1619 |
1627 |
1620 # Return Block types checking for recursion |
1628 # Return Block types checking for recursion |
1621 def GetBlockTypes(self, tagname = "", debug = False): |
1629 def GetBlockTypes(self, tagname = "", debug = False): |
1622 type = None |
1630 typename = None |
1623 words = tagname.split("::") |
1631 words = tagname.split("::") |
1624 if self.Project: |
1632 name = None |
1625 name = "" |
1633 project = self.GetProject(debug) |
|
1634 if project is not None: |
|
1635 blocktypes = [] |
1626 if words[0] in ["P","T","A"]: |
1636 if words[0] in ["P","T","A"]: |
1627 name = words[1] |
1637 name = words[1] |
1628 type = self.GetPouType(name, debug) |
1638 typename = self.GetPouType(name, debug) |
1629 if type == "function": |
1639 if typename == "function": |
1630 blocktypes = [] |
1640 for category in self.TotalTypes: |
1631 for category in BlockTypes + self.GetConfNodeBlockTypes(): |
1641 cat = {"name" : category["name"], "list" : []} |
1632 cat = {"name" : category["name"], "list" : []} |
1642 for block in category["list"]: |
1633 for block in category["list"]: |
1643 if block["type"] == "function": |
1634 if block["type"] == "function": |
1644 cat["list"].append(block) |
1635 cat["list"].append(block) |
1645 if len(cat["list"]) > 0: |
1636 if len(cat["list"]) > 0: |
1646 blocktypes.append(cat) |
1637 blocktypes.append(cat) |
1647 blocktypes.append({"name" : USER_DEFINED_POUS, |
1638 else: |
1648 "list": project.GetCustomBlockTypes(name, |
1639 blocktypes = [category for category in BlockTypes + self.GetConfNodeBlockTypes()] |
1649 typename == "function" or words[0] == "T")}) |
1640 project = self.GetProject(debug) |
1650 return blocktypes |
1641 if project is not None: |
1651 return self.TotalTypes |
1642 blocktypes.append({"name" : USER_DEFINED_POUS, "list": project.GetCustomBlockTypes(name, type == "function" or words[0] == "T")}) |
|
1643 return blocktypes |
|
1644 |
1652 |
1645 # Return Function Block types checking for recursion |
1653 # Return Function Block types checking for recursion |
1646 def GetFunctionBlockTypes(self, tagname = "", debug = False): |
1654 def GetFunctionBlockTypes(self, tagname = "", debug = False): |
1647 blocktypes = [] |
1655 blocktypes = [] |
1648 for category in BlockTypes + self.GetConfNodeBlockTypes(): |
1656 for blocks in self.TotalTypesDict.itervalues(): |
1649 for block in category["list"]: |
1657 for sectioname,block in blocks: |
1650 if block["type"] == "functionBlock": |
1658 if block["type"] == "functionBlock": |
1651 blocktypes.append(block["name"]) |
1659 blocktypes.append(block["name"]) |
1652 project = self.GetProject(debug) |
1660 project = self.GetProject(debug) |
1653 if project is not None: |
1661 if project is not None: |
1654 name = "" |
1662 name = "" |