PLCControler.py
changeset 1302 7856cd7767d6
parent 1301 fcca121a000f
child 1304 6be6c1e0e4d0
equal deleted inserted replaced
1301:fcca121a000f 1302:7856cd7767d6
   566                     var_type = vartype_content.getname()
   566                     var_type = vartype_content.getname()
   567                     if var_type == pou_type:
   567                     if var_type == pou_type:
   568                         instances.append(var_path)
   568                         instances.append(var_path)
   569                     else:
   569                     else:
   570                         pou = project.getpou(var_type)
   570                         pou = project.getpou(var_type)
   571                         if pou is not None and project.ElementIsUsedBy(pou_type, var_type):
   571                         if pou is not None:# and project.ElementIsUsedBy(pou_type, var_type):
   572                             instances.extend(
   572                             instances.extend(
   573                                 self.RecursiveSearchPouInstances(
   573                                 self.RecursiveSearchPouInstances(
   574                                     project, pou_type, var_path, 
   574                                     project, pou_type, var_path, 
   575                                     [varlist for type, varlist in pou.getvars()], 
   575                                     [varlist for type, varlist in pou.getvars()], 
   576                                     debug))
   576                                     debug))
   601                             pou_path = "%s.%s" % (res_path, pou_instance.getname())
   601                             pou_path = "%s.%s" % (res_path, pou_instance.getname())
   602                             pou_type = pou_instance.gettypeName()
   602                             pou_type = pou_instance.gettypeName()
   603                             if pou_type == words[1]:
   603                             if pou_type == words[1]:
   604                                 instances.append(pou_path)
   604                                 instances.append(pou_path)
   605                             pou = project.getpou(pou_type)
   605                             pou = project.getpou(pou_type)
   606                             if pou is not None and project.ElementIsUsedBy(words[1], pou_type):
   606                             if pou is not None:# and project.ElementIsUsedBy(words[1], pou_type):
   607                                 instances.extend(
   607                                 instances.extend(
   608                                     self.RecursiveSearchPouInstances(
   608                                     self.RecursiveSearchPouInstances(
   609                                         project, words[1], pou_path, 
   609                                         project, words[1], pou_path, 
   610                                         [varlist for type, varlist in pou.getvars()], 
   610                                         [varlist for type, varlist in pou.getvars()], 
   611                                         debug))
   611                                         debug))
   731                         return var_infos
   731                         return var_infos
   732         return None
   732         return None
   733     
   733     
   734     # Return if data type given by name is used by another data type or pou
   734     # Return if data type given by name is used by another data type or pou
   735     def DataTypeIsUsed(self, name, debug = False):
   735     def DataTypeIsUsed(self, name, debug = False):
   736         project = self.GetProject(debug)
   736         #project = self.GetProject(debug)
   737         if project is not None:
   737         #if project is not None:
   738             return project.ElementIsUsed(name)
   738         #    return project.ElementIsUsed(name)
   739         return False
   739         return False
   740 
   740 
   741     # Return if pou given by name is used by another pou
   741     # Return if pou given by name is used by another pou
   742     def PouIsUsed(self, name, debug = False):
   742     def PouIsUsed(self, name, debug = False):
   743         project = self.GetProject(debug)
   743         #project = self.GetProject(debug)
   744         if project is not None:
   744         #if project is not None:
   745             return project.ElementIsUsed(name)
   745         #    return project.ElementIsUsed(name)
   746         return False
   746         return False
   747 
   747 
   748     # Return if pou given by name is directly or undirectly used by the reference pou
   748     # Return if pou given by name is directly or undirectly used by the reference pou
   749     def PouIsUsedBy(self, name, reference, debug = False):
   749     def PouIsUsedBy(self, name, reference, debug = False):
   750         project = self.GetProject(debug)
   750         #project = self.GetProject(debug)
   751         if project is not None:
   751         #if project is not None:
   752             return project.ElementIsUsedBy(name, reference)
   752         #    return project.ElementIsUsedBy(name, reference)
   753         return False
   753         return False
   754 
   754 
   755     def GenerateProgram(self, filepath=None):
   755     def GenerateProgram(self, filepath=None):
   756         errors = []
   756         errors = []
   757         warnings = []
   757         warnings = []
   835     def ProjectChangePouType(self, name, pou_type):
   835     def ProjectChangePouType(self, name, pou_type):
   836         if self.Project is not None:
   836         if self.Project is not None:
   837             pou = self.Project.getpou(name)
   837             pou = self.Project.getpou(name)
   838             if pou is not None:
   838             if pou is not None:
   839                 pou.setpouType(pou_type)
   839                 pou.setpouType(pou_type)
   840                 self.Project.RefreshCustomBlockTypes()
       
   841                 self.BufferProject()
   840                 self.BufferProject()
   842                 
   841                 
   843     def GetPouXml(self, pou_name):
   842     def GetPouXml(self, pou_name):
   844         if self.Project is not None:
   843         if self.Project is not None:
   845             pou = self.Project.getpou(pou_name)
   844             pou = self.Project.getpou(pou_name)
   978             # Found the pou corresponding to old name and change its name to new name
   977             # Found the pou corresponding to old name and change its name to new name
   979             datatype = self.Project.getdataType(old_name)
   978             datatype = self.Project.getdataType(old_name)
   980             if datatype is not None:
   979             if datatype is not None:
   981                 datatype.setname(new_name)
   980                 datatype.setname(new_name)
   982                 self.Project.updateElementName(old_name, new_name)
   981                 self.Project.updateElementName(old_name, new_name)
   983                 self.Project.RefreshElementUsingTree()
       
   984                 self.BufferProject()
   982                 self.BufferProject()
   985     
   983     
   986     # Change the name of a pou
   984     # Change the name of a pou
   987     def ChangePouName(self, old_name, new_name):
   985     def ChangePouName(self, old_name, new_name):
   988         if self.Project is not None:
   986         if self.Project is not None:
   989             # Found the pou corresponding to old name and change its name to new name
   987             # Found the pou corresponding to old name and change its name to new name
   990             pou = self.Project.getpou(old_name)
   988             pou = self.Project.getpou(old_name)
   991             if pou is not None:
   989             if pou is not None:
   992                 pou.setname(new_name)
   990                 pou.setname(new_name)
   993                 self.Project.updateElementName(old_name, new_name)
   991                 self.Project.updateElementName(old_name, new_name)
   994                 self.Project.RefreshElementUsingTree()
       
   995                 self.Project.RefreshCustomBlockTypes()
       
   996                 self.BufferProject()
   992                 self.BufferProject()
   997     
   993     
   998     # Change the name of a pou transition
   994     # Change the name of a pou transition
   999     def ChangePouTransitionName(self, pou_name, old_name, new_name):
   995     def ChangePouTransitionName(self, pou_name, old_name, new_name):
  1000         if self.Project is not None:
   996         if self.Project is not None:
  1027             if pou is not None:
  1023             if pou is not None:
  1028                 for type, varlist in pou.getvars():
  1024                 for type, varlist in pou.getvars():
  1029                     for var in varlist.getvariable():
  1025                     for var in varlist.getvariable():
  1030                         if var.getname() == old_name:
  1026                         if var.getname() == old_name:
  1031                             var.setname(new_name)
  1027                             var.setname(new_name)
  1032                 self.Project.RefreshCustomBlockTypes()
       
  1033                 self.BufferProject()
  1028                 self.BufferProject()
  1034         
  1029         
  1035     # Change the name of a configuration
  1030     # Change the name of a configuration
  1036     def ChangeConfigurationName(self, old_name, new_name):
  1031     def ChangeConfigurationName(self, old_name, new_name):
  1037         if self.Project is not None:
  1032         if self.Project is not None:
  1066         if project is not None:
  1061         if project is not None:
  1067             # Found the pou correponding to name and return its type
  1062             # Found the pou correponding to name and return its type
  1068             pou = project.getpou(name)
  1063             pou = project.getpou(name)
  1069             if pou is not None:
  1064             if pou is not None:
  1070                 pou.setdescription(description)
  1065                 pou.setdescription(description)
  1071                 project.RefreshCustomBlockTypes()
       
  1072                 self.BufferProject()
  1066                 self.BufferProject()
  1073     
  1067     
  1074     # Return the type of the pou given by its name
  1068     # Return the type of the pou given by its name
  1075     def GetPouType(self, name, debug = False):
  1069     def GetPouType(self, name, debug = False):
  1076         project = self.GetProject(debug)
  1070         project = self.GetProject(debug)
  1400                 if not eno:
  1394                 if not eno:
  1401                     tree.insert(0, ("ENO", "BOOL", ([], [])))
  1395                     tree.insert(0, ("ENO", "BOOL", ([], [])))
  1402                 if not en:
  1396                 if not en:
  1403                     tree.insert(0, ("EN", "BOOL", ([], [])))
  1397                     tree.insert(0, ("EN", "BOOL", ([], [])))
  1404                 return tree, []
  1398                 return tree, []
  1405             datatype = project.getdataType(typename)
  1399             datatype = self.GetDataType(typename)
  1406             if datatype is None:
       
  1407                 datatype = self.GetConfNodeDataType(typename)
       
  1408             if datatype is not None:
  1400             if datatype is not None:
  1409                 tree = []
  1401                 tree = []
  1410                 basetype_content = datatype.baseType.getcontent()
  1402                 basetype_content = datatype.baseType.getcontent()
  1411                 basetype_content_type = basetype_content.getLocalTag()
  1403                 basetype_content_type = basetype_content.getLocalTag()
  1412                 if basetype_content_type == "derived":
  1404                 if basetype_content_type == "derived":
  1461             if pou is not None:
  1453             if pou is not None:
  1462                 if pou.interface is None:
  1454                 if pou.interface is None:
  1463                     pou.interface = PLCOpenParser.CreateElement("interface", "pou")
  1455                     pou.interface = PLCOpenParser.CreateElement("interface", "pou")
  1464                 # Set Pou interface
  1456                 # Set Pou interface
  1465                 pou.setvars([varlist for varlist_type, varlist in self.ExtractVarLists(vars)])
  1457                 pou.setvars([varlist for varlist_type, varlist in self.ExtractVarLists(vars)])
  1466                 self.Project.RefreshElementUsingTree()
  1458                 
  1467                 self.Project.RefreshCustomBlockTypes()
       
  1468     
       
  1469     # Replace the return type of the pou given by its name (only for functions)
  1459     # Replace the return type of the pou given by its name (only for functions)
  1470     def SetPouInterfaceReturnType(self, name, return_type):
  1460     def SetPouInterfaceReturnType(self, name, return_type):
  1471         if self.Project is not None:
  1461         if self.Project is not None:
  1472             pou = self.Project.getpou(name)
  1462             pou = self.Project.getpou(name)
  1473             if pou is not None:
  1463             if pou is not None:
  1486                         else return_type, "dataType"))
  1476                         else return_type, "dataType"))
  1487                 else:
  1477                 else:
  1488                     derived_type = PLCOpenParser.CreateElement("derived", "dataType")
  1478                     derived_type = PLCOpenParser.CreateElement("derived", "dataType")
  1489                     derived_type.setname(return_type)
  1479                     derived_type.setname(return_type)
  1490                     return_type.setcontent(derived_type)
  1480                     return_type.setcontent(derived_type)
  1491                 self.Project.RefreshElementUsingTree()
  1481                 
  1492                 self.Project.RefreshCustomBlockTypes()
       
  1493     
       
  1494     def UpdateProjectUsedPous(self, old_name, new_name):
  1482     def UpdateProjectUsedPous(self, old_name, new_name):
  1495         if self.Project is not None:
  1483         if self.Project is not None:
  1496             self.Project.updateElementName(old_name, new_name)
  1484             self.Project.updateElementName(old_name, new_name)
  1497     
  1485     
  1498     def UpdateEditedElementUsedVariable(self, tagname, old_name, new_name):
  1486     def UpdateEditedElementUsedVariable(self, tagname, old_name, new_name):
  1527 
  1515 
  1528     # Function that add a new confnode to the confnode list
  1516     # Function that add a new confnode to the confnode list
  1529     def AddConfNodeTypesList(self, typeslist):
  1517     def AddConfNodeTypesList(self, typeslist):
  1530         self.ConfNodeTypes.extend(typeslist)
  1518         self.ConfNodeTypes.extend(typeslist)
  1531         addedcat = [{"name": _("%s POUs") % confnodetypes["name"],
  1519         addedcat = [{"name": _("%s POUs") % confnodetypes["name"],
  1532                      "list": confnodetypes["types"].GetCustomBlockTypes()}
  1520                      "list": [pou.getblockInfos()
       
  1521                               for pou in confnodetypes["types"].getpous()]}
  1533                      for confnodetypes in typeslist]
  1522                      for confnodetypes in typeslist]
  1534         self.TotalTypes.extend(addedcat)
  1523         self.TotalTypes.extend(addedcat)
  1535         for cat in addedcat:
  1524         for cat in addedcat:
  1536             for desc in cat["list"]:
  1525             for desc in cat["list"]:
  1537                 BlkLst = self.TotalTypesDict.setdefault(desc["name"],[])
  1526                 BlkLst = self.TotalTypesDict.setdefault(desc["name"],[])
  1541     def ClearConfNodeTypes(self):
  1530     def ClearConfNodeTypes(self):
  1542         self.ConfNodeTypes = []
  1531         self.ConfNodeTypes = []
  1543         self.TotalTypesDict = StdBlckDct.copy()
  1532         self.TotalTypesDict = StdBlckDct.copy()
  1544         self.TotalTypes = StdBlckLst[:]
  1533         self.TotalTypes = StdBlckLst[:]
  1545 
  1534 
  1546     def GetConfNodeBlockTypes(self):
       
  1547         return [{"name": _("%s POUs") % confnodetypes["name"],
       
  1548                  "list": confnodetypes["types"].GetCustomBlockTypes()}
       
  1549                 for confnodetypes in self.ConfNodeTypes]
       
  1550         
       
  1551     def GetConfNodeDataTypes(self, exclude = None, only_locatables = False):
  1535     def GetConfNodeDataTypes(self, exclude = None, only_locatables = False):
  1552         return [{"name": _("%s Data Types") % confnodetypes["name"],
  1536         return [{"name": _("%s Data Types") % confnodetypes["name"],
  1553                  "list": [datatype["name"] for datatype in confnodetypes["types"].GetCustomDataTypes(exclude, only_locatables)]}
  1537                  "list": [
       
  1538                     datatype.getname() 
       
  1539                     for datatype in confnodetypes["types"].getdataTypes()
       
  1540                     if not only_locatables or self.IsLocatableDataType(datatype, debug)]}
  1554                 for confnodetypes in self.ConfNodeTypes]
  1541                 for confnodetypes in self.ConfNodeTypes]
  1555     
       
  1556     def GetConfNodeDataType(self, typename):
       
  1557         for confnodetype in self.ConfNodeTypes:
       
  1558             datatype = confnodetype["types"].getdataType(typename)
       
  1559             if datatype is not None:
       
  1560                 return datatype
       
  1561         return None
       
  1562     
  1542     
  1563     def GetVariableLocationTree(self):
  1543     def GetVariableLocationTree(self):
  1564         return []
  1544         return []
  1565 
  1545 
  1566     def GetConfNodeGlobalInstances(self):
  1546     def GetConfNodeGlobalInstances(self):
  1611                 result_blocktype = blocktype.copy()
  1591                 result_blocktype = blocktype.copy()
  1612         if result_blocktype is not None:
  1592         if result_blocktype is not None:
  1613             return result_blocktype
  1593             return result_blocktype
  1614         project = self.GetProject(debug)
  1594         project = self.GetProject(debug)
  1615         if project is not None:
  1595         if project is not None:
  1616             return project.GetCustomBlockType(typename, inputs)
  1596             blocktype = project.getpou(typename)
       
  1597             if blocktype is not None:
       
  1598                 blocktype_infos = blocktype.getblockInfos()
       
  1599                 if inputs in [None, "undefined"]:
       
  1600                     return blocktype_infos
       
  1601             
       
  1602                 if inputs == tuple([var_type 
       
  1603                     for name, var_type, modifier in blocktype_infos["inputs"]]):
       
  1604                     return blocktype_infos
       
  1605         
  1617         return None
  1606         return None
  1618 
  1607 
  1619     # Return Block types checking for recursion
  1608     # Return Block types checking for recursion
  1620     def GetBlockTypes(self, tagname = "", debug = False):
  1609     def GetBlockTypes(self, tagname = "", debug = False):
  1621         typename = None
  1610         typename = None
  1623         name = None
  1612         name = None
  1624         project = self.GetProject(debug)
  1613         project = self.GetProject(debug)
  1625         if project is not None:
  1614         if project is not None:
  1626             pou_type = None
  1615             pou_type = None
  1627             if words[0] in ["P","T","A"]:
  1616             if words[0] in ["P","T","A"]:
  1628                 blocktypes = []
       
  1629                 name = words[1]
  1617                 name = words[1]
  1630                 pou_type = self.GetPouType(name, debug)
  1618                 pou_type = self.GetPouType(name, debug)
  1631             if pou_type == "function":
  1619             filter = (["function"] 
  1632                 for category in self.TotalTypes:
  1620                       if pou_type == "function" or words[0] == "T" 
  1633                     cat = {"name" : category["name"], "list" : []}
  1621                       else ["functionBlock", "function"])
  1634                     for block in category["list"]:
  1622             blocktypes = [
  1635                         if block["type"] == "function":
  1623                 {"name": category["name"],
  1636                             cat["list"].append(block)
  1624                  "list": [block for block in category["list"]
  1637                     if len(cat["list"]) > 0:
  1625                           if block["type"] in filter]}
  1638                         blocktypes.append(cat)
  1626                 for category in self.TotalTypes]
  1639             else:
       
  1640                 blocktypes = [category for category in self.TotalTypes]
       
  1641             blocktypes.append({"name" : USER_DEFINED_POUS, 
  1627             blocktypes.append({"name" : USER_DEFINED_POUS, 
  1642                 "list": project.GetCustomBlockTypes(name, 
  1628                 "list": [pou.getblockInfos()
  1643                     pou_type == "function" or words[0] == "T")})
  1629                          for pou in project.getpous(name, filter)]})
  1644             return blocktypes
  1630             return blocktypes
  1645         return self.TotalTypes
  1631         return self.TotalTypes
  1646 
  1632 
  1647     # Return Function Block types checking for recursion
  1633     # Return Function Block types checking for recursion
  1648     def GetFunctionBlockTypes(self, tagname = "", debug = False):
  1634     def GetFunctionBlockTypes(self, tagname = "", debug = False):
  1651             for sectioname,block in blocks:
  1637             for sectioname,block in blocks:
  1652                 if block["type"] == "functionBlock":
  1638                 if block["type"] == "functionBlock":
  1653                     blocktypes.append(block["name"])
  1639                     blocktypes.append(block["name"])
  1654         project = self.GetProject(debug)
  1640         project = self.GetProject(debug)
  1655         if project is not None:
  1641         if project is not None:
  1656             name = ""
       
  1657             words = tagname.split("::")
  1642             words = tagname.split("::")
  1658             if words[0] in ["P","T","A"]:
  1643             blocktypes.extend([pou.getname()
  1659                 name = words[1]
  1644                 for pou in project.getpous(
  1660             blocktypes.extend(project.GetCustomFunctionBlockTypes(name))
  1645                     words[1] if words[0] in ["P","T","A"] else None,
       
  1646                     ["functionBlock"])])
  1661         return blocktypes
  1647         return blocktypes
  1662 
  1648 
  1663     # Return Block types checking for recursion
  1649     # Return Block types checking for recursion
  1664     def GetBlockResource(self, debug = False):
  1650     def GetBlockResource(self, debug = False):
  1665         blocktypes = []
  1651         blocktypes = []
  1667             for blocktype in category["list"]:
  1653             for blocktype in category["list"]:
  1668                 if blocktype["type"] == "program":
  1654                 if blocktype["type"] == "program":
  1669                     blocktypes.append(blocktype["name"])
  1655                     blocktypes.append(blocktype["name"])
  1670         project = self.GetProject(debug)
  1656         project = self.GetProject(debug)
  1671         if project is not None:
  1657         if project is not None:
  1672             blocktypes.extend(project.GetCustomBlockResource())
  1658             blocktypes.extend(
       
  1659                 [pou.getblockInfos()
       
  1660                  for pou in project.getpous(filter=["program"])])
  1673         return blocktypes
  1661         return blocktypes
  1674 
  1662 
  1675     # Return Data Types checking for recursion
  1663     # Return Data Types checking for recursion
  1676     def GetDataTypes(self, tagname = "", basetypes = True, confnodetypes = True, only_locatables = False, debug = False):
  1664     def GetDataTypes(self, tagname = "", basetypes = True, confnodetypes = True, only_locatables = False, debug = False):
  1677         if basetypes:
  1665         if basetypes:
  1682         name = None
  1670         name = None
  1683         if project is not None:
  1671         if project is not None:
  1684             words = tagname.split("::")
  1672             words = tagname.split("::")
  1685             if words[0] in ["D"]:
  1673             if words[0] in ["D"]:
  1686                 name = words[1]
  1674                 name = words[1]
  1687             datatypes.extend([datatype["name"] for datatype in project.GetCustomDataTypes(name, only_locatables)])
  1675             datatypes.extend([
       
  1676                 datatype.getname() 
       
  1677                 for datatype in project.getdataTypes(name)
       
  1678                 if not only_locatables or self.IsLocatableDataType(datatype, debug)])
  1688         if confnodetypes:
  1679         if confnodetypes:
  1689             for category in self.GetConfNodeDataTypes(name, only_locatables):
  1680             for category in self.GetConfNodeDataTypes(name, only_locatables):
  1690                 datatypes.extend(category["list"])
  1681                 datatypes.extend(category["list"])
  1691         return datatypes
  1682         return datatypes
  1692 
  1683 
  1757     def IsEndType(self, typename):
  1748     def IsEndType(self, typename):
  1758         if typename is not None:
  1749         if typename is not None:
  1759             return not typename.startswith("ANY")
  1750             return not typename.startswith("ANY")
  1760         return True
  1751         return True
  1761 
  1752 
       
  1753     def IsLocatableDataType(self, datatype, debug = False):
       
  1754         basetype_content = datatype.baseType.getcontent()
       
  1755         basetype_content_type = basetype_content.getLocalTag()
       
  1756         if basetype_content_type in ["enum", "struct"]:
       
  1757             return False
       
  1758         elif basetype_content_type == "derived":
       
  1759             return self.IsLocatableType(basetype_content.getname())
       
  1760         elif basetype_content_name == "array":
       
  1761             array_base_type = basetype_content.baseType.getcontent()
       
  1762             if array_base_type.getLocalTag() == "derived":
       
  1763                 return self.IsLocatableType(array_base_type.getname(), debug)
       
  1764         return True
       
  1765         
  1762     def IsLocatableType(self, typename, debug = False):
  1766     def IsLocatableType(self, typename, debug = False):
  1763         if isinstance(typename, TupleType) or self.GetBlockType(type) is not None:
  1767         if isinstance(typename, TupleType) or self.GetBlockType(typename) is not None:
  1764             return False
  1768             return False
  1765         
  1769         
  1766         datatype = self.GetDataType(typename, debug)
  1770         datatype = self.GetDataType(typename, debug)
  1767         if datatype is not None:
  1771         if datatype is not None:
  1768             basetype_content = datatype.baseType.getcontent()
  1772             return self.IsLocatableDataType(datatype)
  1769             basetype_content_type = basetype_content.getLocalTag()
       
  1770             if basetype_content_type in ["enum", "struct"]:
       
  1771                 return False
       
  1772             elif basetype_content_type == "derived":
       
  1773                 return self.IsLocatableType(basetype_content.getname())
       
  1774             elif basetype_content_name == "array":
       
  1775                 array_base_type = basetype_content.baseType.getcontent()
       
  1776                 if array_base_type.getLocalTag() == "derived":
       
  1777                     return self.IsLocatableType(array_base_type.getname(), debug)
       
  1778         
       
  1779         return True
  1773         return True
  1780     
  1774     
  1781     def IsEnumeratedType(self, typename, debug = False):
  1775     def IsEnumeratedType(self, typename, debug = False):
  1782         datatype = self.GetDataType(typename, debug)
  1776         datatype = self.GetDataType(typename, debug)
  1783         if datatype is not None:
  1777         if datatype is not None:
  2086                 if datatype.initialValue is None:
  2080                 if datatype.initialValue is None:
  2087                     datatype.initialValue = PLCOpenParser.CreateElement("initialValue", "dataType")
  2081                     datatype.initialValue = PLCOpenParser.CreateElement("initialValue", "dataType")
  2088                 datatype.initialValue.setvalue(infos["initial"])
  2082                 datatype.initialValue.setvalue(infos["initial"])
  2089             else:
  2083             else:
  2090                 datatype.initialValue = None
  2084                 datatype.initialValue = None
  2091             self.Project.RefreshElementUsingTree()
       
  2092             self.BufferProject()
  2085             self.BufferProject()
  2093     
  2086     
  2094 #-------------------------------------------------------------------------------
  2087 #-------------------------------------------------------------------------------
  2095 #                       Project opened Pous management functions
  2088 #                       Project opened Pous management functions
  2096 #-------------------------------------------------------------------------------
  2089 #-------------------------------------------------------------------------------
  2172     def SetEditedElementText(self, tagname, text):
  2165     def SetEditedElementText(self, tagname, text):
  2173         if self.Project is not None:
  2166         if self.Project is not None:
  2174             element = self.GetEditedElement(tagname)
  2167             element = self.GetEditedElement(tagname)
  2175             if element is not None:
  2168             if element is not None:
  2176                 element.settext(text)
  2169                 element.settext(text)
  2177                 self.Project.RefreshElementUsingTree()
       
  2178     
  2170     
  2179     # Return the edited element text
  2171     # Return the edited element text
  2180     def GetEditedElementText(self, tagname, debug = False):
  2172     def GetEditedElementText(self, tagname, debug = False):
  2181         element = self.GetEditedElement(tagname, debug)
  2173         element = self.GetEditedElement(tagname, debug)
  2182         if element is not None:
  2174         if element is not None:
  2494             blocktype_infos = self.GetBlockType(blocktype)
  2486             blocktype_infos = self.GetBlockType(blocktype)
  2495             if blocktype_infos["type"] != "function" and blockname is not None:
  2487             if blocktype_infos["type"] != "function" and blockname is not None:
  2496                 block.setinstanceName(blockname)
  2488                 block.setinstanceName(blockname)
  2497                 self.AddEditedElementPouVar(tagname, blocktype, blockname)
  2489                 self.AddEditedElementPouVar(tagname, blocktype, blockname)
  2498             element.addinstance(block)
  2490             element.addinstance(block)
  2499             self.Project.RefreshElementUsingTree()
       
  2500     
  2491     
  2501     def SetEditedElementBlockInfos(self, tagname, id, infos):
  2492     def SetEditedElementBlockInfos(self, tagname, id, infos):
  2502         element = self.GetEditedElement(tagname)
  2493         element = self.GetEditedElement(tagname)
  2503         if element is not None:
  2494         if element is not None:
  2504             block = element.getinstance(id)
  2495             block = element.getinstance(id)
  2561                             variable.setedge(connector.GetEdge())
  2552                             variable.setedge(connector.GetEdge())
  2562                         position = connector.GetRelPosition()
  2553                         position = connector.GetRelPosition()
  2563                         variable.addconnectionPointOut()
  2554                         variable.addconnectionPointOut()
  2564                         variable.connectionPointOut.setrelPositionXY(position.x, position.y)
  2555                         variable.connectionPointOut.setrelPositionXY(position.x, position.y)
  2565             block.tostring()
  2556             block.tostring()
  2566             self.Project.RefreshElementUsingTree()
       
  2567         
  2557         
  2568     def AddEditedElementVariable(self, tagname, id, var_type):
  2558     def AddEditedElementVariable(self, tagname, id, var_type):
  2569         element = self.GetEditedElement(tagname)
  2559         element = self.GetEditedElement(tagname)
  2570         if element is not None:
  2560         if element is not None:
  2571             variable = PLCOpenParser.CreateElement(
  2561             variable = PLCOpenParser.CreateElement(
  3040         if element is not None:
  3030         if element is not None:
  3041             instance = element.getinstance(id)
  3031             instance = element.getinstance(id)
  3042             if isinstance(instance, PLCOpenParser.GetElementClass("block", "fbdObjects")):
  3032             if isinstance(instance, PLCOpenParser.GetElementClass("block", "fbdObjects")):
  3043                 self.RemoveEditedElementPouVar(tagname, instance.gettypeName(), instance.getinstanceName())
  3033                 self.RemoveEditedElementPouVar(tagname, instance.gettypeName(), instance.getinstanceName())
  3044             element.removeinstance(id)
  3034             element.removeinstance(id)
  3045             self.Project.RefreshElementUsingTree()
       
  3046 
  3035 
  3047     def GetEditedResourceVariables(self, tagname, debug = False):
  3036     def GetEditedResourceVariables(self, tagname, debug = False):
  3048         varlist = []
  3037         varlist = []
  3049         words = tagname.split("::")
  3038         words = tagname.split("::")
  3050         for var in self.GetConfigurationGlobalVars(words[1], debug):
  3039         for var in self.GetConfigurationGlobalVars(words[1], debug):
  3153         try:
  3142         try:
  3154             self.Project = LoadProject(filepath)
  3143             self.Project = LoadProject(filepath)
  3155         except Exception, e:
  3144         except Exception, e:
  3156             return _("Project file syntax error:\n\n") + str(e)
  3145             return _("Project file syntax error:\n\n") + str(e)
  3157         self.SetFilePath(filepath)
  3146         self.SetFilePath(filepath)
  3158         self.Project.RefreshElementUsingTree()
       
  3159         self.Project.RefreshCustomBlockTypes()
       
  3160         
  3147         
  3161         ## To remove when project buffering ready
  3148         ## To remove when project buffering ready
  3162         self.ProjectBufferEnabled = False
  3149         self.ProjectBufferEnabled = False
  3163         
  3150         
  3164         self.CreateProjectBuffer(True)
  3151         self.CreateProjectBuffer(True)