PLCControler.py
changeset 1973 cc7a46953471
parent 1959 ce1bfd04b3f6
parent 1968 64827679f3f1
child 2418 5587c490a070
equal deleted inserted replaced
1961:b4a1ba9dbaf3 1973:cc7a46953471
    42 from plcopen.VariableInfoCollector import VariableInfoCollector
    42 from plcopen.VariableInfoCollector import VariableInfoCollector
    43 from graphics.GraphicCommons import *
    43 from graphics.GraphicCommons import *
    44 from PLCGenerator import *
    44 from PLCGenerator import *
    45 
    45 
    46 duration_model = re.compile("(?:([0-9]{1,2})h)?(?:([0-9]{1,2})m(?!s))?(?:([0-9]{1,2})s)?(?:([0-9]{1,3}(?:\.[0-9]*)?)ms)?")
    46 duration_model = re.compile("(?:([0-9]{1,2})h)?(?:([0-9]{1,2})m(?!s))?(?:([0-9]{1,2})s)?(?:([0-9]{1,3}(?:\.[0-9]*)?)ms)?")
       
    47 VARIABLE_NAME_SUFFIX_MODEL = re.compile('(\d+)$')
    47 
    48 
    48 ScriptDirectory = paths.AbsDir(__file__)
    49 ScriptDirectory = paths.AbsDir(__file__)
    49 
    50 
    50 # Length of the buffer
    51 # Length of the buffer
    51 UNDO_BUFFER_LENGTH = 20
    52 UNDO_BUFFER_LENGTH = 20
  1812                     text += instance_copy.tostring()
  1813                     text += instance_copy.tostring()
  1813             element.remove(copy_body)
  1814             element.remove(copy_body)
  1814         return text
  1815         return text
  1815 
  1816 
  1816     def GenerateNewName(self, tagname, name, format, start_idx=0, exclude=None, debug=False):
  1817     def GenerateNewName(self, tagname, name, format, start_idx=0, exclude=None, debug=False):
       
  1818         if name is not None:
       
  1819             result = re.search(VARIABLE_NAME_SUFFIX_MODEL, name)
       
  1820             if result is not None:
       
  1821                 format = name[:result.start(1)] + '%d'
       
  1822                 start_idx = int(result.group(1))
       
  1823             else:
       
  1824                 format = name + '%d'
       
  1825 
  1817         names = {} if exclude is None else exclude.copy()
  1826         names = {} if exclude is None else exclude.copy()
  1818         if tagname is not None:
  1827         if tagname is not None:
  1819             names.update(dict([(varname.upper(), True)
  1828             names.update(dict([(varname.upper(), True)
  1820                                for varname in self.GetEditedElementVariables(tagname, debug)]))
  1829                                for varname in self.GetEditedElementVariables(tagname, debug)]))
  1821             words = tagname.split("::")
  1830             words = tagname.split("::")
  1827                                 instance,
  1836                                 instance,
  1828                                 (PLCOpenParser.GetElementClass("step",         "sfcObjects"),
  1837                                 (PLCOpenParser.GetElementClass("step",         "sfcObjects"),
  1829                                  PLCOpenParser.GetElementClass("connector",    "commonObjects"),
  1838                                  PLCOpenParser.GetElementClass("connector",    "commonObjects"),
  1830                                  PLCOpenParser.GetElementClass("continuation", "commonObjects"))):
  1839                                  PLCOpenParser.GetElementClass("continuation", "commonObjects"))):
  1831                             names[instance.getname().upper()] = True
  1840                             names[instance.getname().upper()] = True
       
  1841             elif words[0] == 'R':
       
  1842                 element = self.GetEditedElement(tagname, debug)
       
  1843                 for task in element.gettask():
       
  1844                     names[task.getname().upper()] = True
       
  1845                     for instance in task.getpouInstance():
       
  1846                         names[instance.getname().upper()] = True
       
  1847                 for instance in element.getpouInstance():
       
  1848                     names[instance.getname().upper()] = True
  1832         else:
  1849         else:
  1833             project = self.GetProject(debug)
  1850             project = self.GetProject(debug)
  1834             if project is not None:
  1851             if project is not None:
  1835                 for datatype in project.getdataTypes():
  1852                 for datatype in project.getdataTypes():
  1836                     names[datatype.getname().upper()] = True
  1853                     names[datatype.getname().upper()] = True