PLCGenerator.py
changeset 742 75096d6c271c
parent 684 f10449b18dbe
child 754 48966b6ceedc
equal deleted inserted replaced
741:330f578e228d 742:75096d6c271c
    25 from plcopen import plcopen
    25 from plcopen import plcopen
    26 from plcopen.structures import *
    26 from plcopen.structures import *
    27 from types import *
    27 from types import *
    28 import re
    28 import re
    29 
    29 
    30 
       
    31 # Dictionary associating PLCOpen variable categories to the corresponding 
    30 # Dictionary associating PLCOpen variable categories to the corresponding 
    32 # IEC 61131-3 variable categories
    31 # IEC 61131-3 variable categories
    33 varTypeNames = {"localVars" : "VAR", "tempVars" : "VAR_TEMP", "inputVars" : "VAR_INPUT", 
    32 varTypeNames = {"localVars" : "VAR", "tempVars" : "VAR_TEMP", "inputVars" : "VAR_INPUT", 
    34                 "outputVars" : "VAR_OUTPUT", "inOutVars" : "VAR_IN_OUT", "externalVars" : "VAR_EXTERNAL",
    33                 "outputVars" : "VAR_OUTPUT", "inOutVars" : "VAR_IN_OUT", "externalVars" : "VAR_EXTERNAL",
    35                 "globalVars" : "VAR_GLOBAL", "accessVars" : "VAR_ACCESS"}
    34                 "globalVars" : "VAR_GLOBAL", "accessVars" : "VAR_ACCESS"}
    73     bx, by = int(b.getx()), int(b.gety())
    72     bx, by = int(b.getx()), int(b.gety())
    74     if abs(ay - by) < 10:
    73     if abs(ay - by) < 10:
    75         return cmp(ax, bx)
    74         return cmp(ax, bx)
    76     else:
    75     else:
    77         return cmp(ay, by)
    76         return cmp(ay, by)
       
    77 
       
    78 REAL_MODEL = re.compile("[0-9]+\.[0-9]+$")
       
    79 INTEGER_MODEL = re.compile("[0-9]+$")
    78 
    80 
    79 #-------------------------------------------------------------------------------
    81 #-------------------------------------------------------------------------------
    80 #                  Specific exception for PLC generating errors
    82 #                  Specific exception for PLC generating errors
    81 #-------------------------------------------------------------------------------
    83 #-------------------------------------------------------------------------------
    82 
    84 
   483                     return True
   485                     return True
   484         return False
   486         return False
   485     
   487     
   486     # Return the type of a variable defined in interface
   488     # Return the type of a variable defined in interface
   487     def GetVariableType(self, name):
   489     def GetVariableType(self, name):
   488         for list_type, option, located, vars in self.Interface:
   490         parts = name.split('.')
   489             for var_type, var_name, var_address, var_initial in vars:
   491         current_type = None
   490                 if name == var_name:
   492         if len(parts) > 0:
   491                     return var_type
   493             name = parts.pop(0)
   492         return None
   494             for list_type, option, located, vars in self.Interface:
       
   495                 for var_type, var_name, var_address, var_initial in vars:
       
   496                     if name == var_name:
       
   497                         current_type = var_type
       
   498                         break
       
   499             while current_type is not None and len(parts) > 0:
       
   500                 tagname = self.ParentGenerator.Controler.ComputeDataTypeName(current_type)
       
   501                 infos = self.ParentGenerator.Controler.GetDataTypeInfos(tagname)
       
   502                 name = parts.pop(0)
       
   503                 current_type = None
       
   504                 if infos is not None and infos["type"] == "Structure":
       
   505                     for element in infos["elements"]:
       
   506                         if element["Name"] == name:
       
   507                             current_type = element["Type"]
       
   508                             break
       
   509         return current_type
   493     
   510     
   494     # Return connectors linked by a connection to the given connector
   511     # Return connectors linked by a connection to the given connector
   495     def GetConnectedConnector(self, connector, body):
   512     def GetConnectedConnector(self, connector, body):
   496         links = connector.getconnections()
   513         links = connector.getconnections()
   497         if links and len(links) == 1:
   514         if links and len(links) == 1:
   630                             var_type = returntype_content["name"]
   647                             var_type = returntype_content["name"]
   631                     elif var_type is None:
   648                     elif var_type is None:
   632                         parts = expression.split("#")
   649                         parts = expression.split("#")
   633                         if len(parts) > 1:
   650                         if len(parts) > 1:
   634                             var_type = parts[0]
   651                             var_type = parts[0]
       
   652                         elif REAL_MODEL.match(expression):
       
   653                             var_type = "ANY_REAL"
       
   654                         elif INTEGER_MODEL.match(expression):
       
   655                             var_type = "ANY_NUM"
   635                         elif expression.startswith("'"):
   656                         elif expression.startswith("'"):
   636                             var_type = "STRING"
   657                             var_type = "STRING"
   637                         elif expression.startswith('"'):
   658                         elif expression.startswith('"'):
   638                             var_type = "WSTRING"
   659                             var_type = "WSTRING"
   639                     if var_type is not None:
   660                     if var_type is not None: