PLCControler.py
changeset 80 c798a68c5560
parent 71 0578bc212c20
child 81 11ca9ad9e3c3
equal deleted inserted replaced
79:b22f661cbcfb 80:c798a68c5560
   194         self.ProjectBuffer = UndoBuffer(self.Copy(self.Project), False)
   194         self.ProjectBuffer = UndoBuffer(self.Copy(self.Project), False)
   195         self.Buffering = False
   195         self.Buffering = False
   196     
   196     
   197     # Return project pou names
   197     # Return project pou names
   198     def GetProjectPouNames(self):
   198     def GetProjectPouNames(self):
   199         return [pou.getName() for pou in self.Project.getPous()]
   199         if self.Project:
       
   200             return [pou.getName() for pou in self.Project.getPous()]
       
   201         return []
   200     
   202     
   201     # Return project pou names
   203     # Return project pou names
   202     def GetProjectConfigNames(self):
   204     def GetProjectConfigNames(self):
   203         return [config.getName() for config in self.Project.getConfigurations()]
   205         if self.Project:
       
   206             return [config.getName() for config in self.Project.getConfigurations()]
       
   207         return []
   204     
   208     
   205     # Return project pou variables
   209     # Return project pou variables
   206     def GetProjectPouVariables(self, pou_name=None):
   210     def GetProjectPouVariables(self, pou_name=None):
   207         variables = []
   211         variables = []
   208         for pou in self.Project.getPous():
   212         for pou in self.Project.getPous():
   381     
   385     
   382     # Add a Pou to Project
   386     # Add a Pou to Project
   383     def ProjectAddPou(self, name, pou_type, body_type):
   387     def ProjectAddPou(self, name, pou_type, body_type):
   384         # Add the pou to project
   388         # Add the pou to project
   385         self.Project.appendPou(name, pou_type, body_type)
   389         self.Project.appendPou(name, pou_type, body_type)
       
   390         self.SetPouInterfaceReturnType(name, "BOOL")
   386         self.RefreshPouUsingTree()
   391         self.RefreshPouUsingTree()
   387         self.RefreshBlockTypes()
   392         self.RefreshBlockTypes()
   388         self.BufferProject()
   393         self.BufferProject()
   389     
   394     
   390     # Remove a pou from project
   395     # Remove a pou from project
   453     def ChangePouName(self, old_name, new_name):
   458     def ChangePouName(self, old_name, new_name):
   454         # Found the pou corresponding to old name and change its name to new name
   459         # Found the pou corresponding to old name and change its name to new name
   455         pou = self.Project.getPou(old_name)
   460         pou = self.Project.getPou(old_name)
   456         pou.setName(new_name)
   461         pou.setName(new_name)
   457         # If pou is currently opened, change its name in the list of opened pous
   462         # If pou is currently opened, change its name in the list of opened pous
   458         if old_name in self.ElementsOpened:
   463         for idx, element in enumerate(self.ElementsOpened):
   459             idx = self.ElementsOpened.index(old_name)
   464             words = element.split("::")
   460             self.ElementsOpened[idx] = new_name
   465             if words[0] in ["P","T","A"] and words[1] == old_name:
       
   466                 if words[0] == "P":
       
   467                     self.ElementsOpened[idx] = self.ComputePouName(new_name)
       
   468                 elif words[0] == "T":
       
   469                     self.ElementsOpened[idx] = self.ComputePouTransitionName(new_name, words[2])
       
   470                 else:
       
   471                     self.ElementsOpened[idx] = self.ComputePouActionName(new_name, words[2])
   461         self.Project.updateElementName(old_name, new_name)
   472         self.Project.updateElementName(old_name, new_name)
   462         self.RefreshPouUsingTree()
   473         self.RefreshPouUsingTree()
   463         self.RefreshBlockTypes()
   474         self.RefreshBlockTypes()
   464         self.BufferProject()
   475         self.BufferProject()
   465     
   476     
   489         if old_computedname in self.ElementsOpened:
   500         if old_computedname in self.ElementsOpened:
   490             idx = self.ElementsOpened.index(old_computedname)
   501             idx = self.ElementsOpened.index(old_computedname)
   491             self.ElementsOpened[idx] = new_computedname
   502             self.ElementsOpened[idx] = new_computedname
   492         self.BufferProject()
   503         self.BufferProject()
   493     
   504     
   494     # Change the name of a pou action
   505     # Change the name of a pou variable
   495     def ChangePouVariableName(self, pou_name, old_name, new_name):
   506     def ChangePouVariableName(self, pou_name, old_name, new_name):
   496         # Found the pou action corresponding to old name and change its name to new name
   507         # Found the pou action corresponding to old name and change its name to new name
   497         pou = self.Project.getPou(pou_name)
   508         pou = self.Project.getPou(pou_name)
   498         for type, varlist in pou.getVars():
   509         for type, varlist in pou.getVars():
   499             for var in varlist.getVariable():
   510             for var in varlist.getVariable():
   507         # Found the configuration corresponding to old name and change its name to new name
   518         # Found the configuration corresponding to old name and change its name to new name
   508         configuration = self.Project.getConfiguration(old_name)
   519         configuration = self.Project.getConfiguration(old_name)
   509         configuration.setName(new_name)
   520         configuration.setName(new_name)
   510         # If configuration is currently opened, change its name in the list of opened elements
   521         # If configuration is currently opened, change its name in the list of opened elements
   511         for idx, element in enumerate(self.ElementsOpened):
   522         for idx, element in enumerate(self.ElementsOpened):
   512             self.ElementsOpened[idx] = element.replace(old_name, new_name)
   523             words = element.split("::")
       
   524             if words[0] in ["C","R"] and words[1] == old_name:
       
   525                 if words[0] == "C":
       
   526                     self.ElementsOpened[idx] = self.ComputeConfigurationName(new_name)
       
   527                 else:
       
   528                     self.ElementsOpened[idx] = self.ComputeConfigurationResourceName(new_name, words[2])
   513         self.BufferProject()
   529         self.BufferProject()
   514     
   530     
   515     # Change the name of a configuration resource
   531     # Change the name of a configuration resource
   516     def ChangeConfigurationResourceName(self, config_name, old_name, new_name):
   532     def ChangeConfigurationResourceName(self, config_name, old_name, new_name):
   517         # Found the resource corresponding to old name and change its name to new name
   533         # Found the resource corresponding to old name and change its name to new name
   863                 name = ""
   879                 name = ""
   864                 type = None
   880                 type = None
   865             if type == "function":
   881             if type == "function":
   866                 blocktypes = []
   882                 blocktypes = []
   867                 for category in BlockTypes[:-1]:
   883                 for category in BlockTypes[:-1]:
   868                     if category["name"] != "SVGUI function blocks":
   884                     cat = {"name" : category["name"], "list" : []}
   869                         cat = {"name" : category["name"], "list" : []}
   885                     for block in category["list"]:
   870                         for block in category["list"]:
   886                         if block["type"] == "function":
   871                             if block["type"] == "function":
   887                             cat["list"].append(block)
   872                                 cat["list"].append(block)
   888                     if len(cat["list"]) > 0:
   873                         if len(cat["list"]) > 0:
   889                         blocktypes.append(cat)
   874                             blocktypes.append(cat)
       
   875             else:
   890             else:
   876                 blocktypes = [category for category in BlockTypes[:-1] if category["name"] != "SVGUI function blocks"]
   891                 blocktypes = [category for category in BlockTypes[:-1]]
   877             if self.Project:
   892             if self.Project:
   878                 blocktypes.append({"name" : "User-defined POUs", "list": []})
   893                 blocktypes.append({"name" : "User-defined POUs", "list": []})
   879                 for blocktype in BlockTypes[-1]["list"]:
   894                 for blocktype in BlockTypes[-1]["list"]:
   880                     if blocktype["name"] != name and not self.PouIsUsedBy(name, blocktype["name"]) and not (type == "function" and blocktype["type"] != "function"):
   895                     if blocktype["name"] != name and not self.PouIsUsedBy(name, blocktype["name"]) and not (type == "function" and blocktype["type"] != "function"):
   881                         blocktypes[-1]["list"].append(blocktype)
   896                         blocktypes[-1]["list"].append(blocktype)
   885     # Return Function Block types checking for recursion
   900     # Return Function Block types checking for recursion
   886     def GetFunctionBlockTypes(self):
   901     def GetFunctionBlockTypes(self):
   887         if self.CurrentElementEditing != None:
   902         if self.CurrentElementEditing != None:
   888             if self.Project:
   903             if self.Project:
   889                 current_name = self.ElementsOpened[self.CurrentElementEditing]
   904                 current_name = self.ElementsOpened[self.CurrentElementEditing]
       
   905                 print current_name
   890                 words = current_name.split("::")
   906                 words = current_name.split("::")
   891                 if len(words) == 1:
   907                 if len(words) == 1:
   892                     name = current_name
   908                     name = current_name
   893                 else:
   909                 else:
   894                     name = words[1]
   910                     name = words[1]
   896             else:
   912             else:
   897                 name = ""
   913                 name = ""
   898                 type = None
   914                 type = None
   899             blocktypes = []
   915             blocktypes = []
   900             for category in BlockTypes[:-1]:
   916             for category in BlockTypes[:-1]:
   901                 if category["name"] != "SVGUI function blocks":
   917                 for block in category["list"]:
   902                     for block in category["list"]:
   918                     if block["type"] != "function":
   903                         if block["type"] != "function":
   919                         blocktypes.append(block["name"])
   904                             blocktypes.append(block["name"])
       
   905             if self.Project:
   920             if self.Project:
   906                 for blocktype in BlockTypes[-1]["list"]:
   921                 for blocktype in BlockTypes[-1]["list"]:
   907                     if blocktype["name"] != name and not self.PouIsUsedBy(name, blocktype["name"]) and not (type == "function" and blocktype["type"] != "function"):
   922                     if blocktype["name"] != name and not self.PouIsUsedBy(name, blocktype["name"]) and not (type == "function" and blocktype["type"] != "function"):
   908                         blocktypes.append(blocktype["name"])
   923                         blocktypes.append(blocktype["name"])
   909             return blocktypes
   924             return blocktypes
   930     # Return the list of pou names
   945     # Return the list of pou names
   931     def GetElementsOpenedNames(self):
   946     def GetElementsOpenedNames(self):
   932         names = []
   947         names = []
   933         for pou_name in self.ElementsOpened:
   948         for pou_name in self.ElementsOpened:
   934             words = pou_name.split("::")
   949             words = pou_name.split("::")
   935             if len(words) == 1:
   950             if words[0] in ["P","C"]:
   936                 names.append(pou_name)
       
   937             elif len(words) == 2:
       
   938                 names.append(words[1])
   951                 names.append(words[1])
   939             else:
   952             else:
   940                 names.append("%s-%s"%(words[1],words[2]))
   953                 names.append("%s-%s"%(words[1],words[2]))
   941         return names
   954         return names
       
   955     
       
   956     # Compute a pou transition name
       
   957     def ComputePouName(self, pou):
       
   958         return "P::%s" % pou
   942     
   959     
   943     # Compute a pou transition name
   960     # Compute a pou transition name
   944     def ComputePouTransitionName(self, pou, transition):
   961     def ComputePouTransitionName(self, pou, transition):
   945         return "T::%s::%s" % (pou, transition)
   962         return "T::%s::%s" % (pou, transition)
   946     
   963     
   965             self.CurrentElementEditing = len(self.ElementsOpened) - 1
   982             self.CurrentElementEditing = len(self.ElementsOpened) - 1
   966             return self.CurrentElementEditing
   983             return self.CurrentElementEditing
   967         return None
   984         return None
   968 
   985 
   969     # Open a pou transition by giving pou and transition names
   986     # Open a pou transition by giving pou and transition names
       
   987     def OpenPouEditing(self, pou):
       
   988         return self.OpenElementEditing(self.ComputePouName(pou))
       
   989 
       
   990     # Open a pou transition by giving pou and transition names
   970     def OpenPouTransitionEditing(self, pou, transition):
   991     def OpenPouTransitionEditing(self, pou, transition):
   971         return self.OpenElementEditing(self.ComputePouTransitionName(pou, transition))
   992         return self.OpenElementEditing(self.ComputePouTransitionName(pou, transition))
   972 
   993 
   973     # Open a pou action by giving pou and action names
   994     # Open a pou action by giving pou and action names
   974     def OpenPouActionEditing(self, pou, action):
   995     def OpenPouActionEditing(self, pou, action):
   981     # Open a configuration resource by giving configuration and resource names
  1002     # Open a configuration resource by giving configuration and resource names
   982     def OpenConfigurationResourceEditing(self, config, resource):
  1003     def OpenConfigurationResourceEditing(self, config, resource):
   983         return self.OpenElementEditing(self.ComputeConfigurationResourceName(config, resource))
  1004         return self.OpenElementEditing(self.ComputeConfigurationResourceName(config, resource))
   984 
  1005 
   985     # Return if pou given by name is opened
  1006     # Return if pou given by name is opened
   986     def IsElementEditing(self, name):
  1007     def IsPouEditing(self, pou):
   987         return name in self.ElementsOpened
  1008         return self.ComputePouName(pou) in self.ElementsOpened
   988 
  1009 
   989     # Return if pou transition given by pou and transition names is opened
  1010     # Return if pou transition given by pou and transition names is opened
   990     def IsPouTransitionEditing(self, pou, transition):
  1011     def IsPouTransitionEditing(self, pou, transition):
   991         return self.ComputePouTransitionName(pou, transition) in self.ElementsOpened
  1012         return self.ComputePouTransitionName(pou, transition) in self.ElementsOpened
   992 
  1013 
   993     # Return if pou action given by pou and action names is opened
  1014     # Return if pou action given by pou and action names is opened
   994     def IsPouActionEditing(self, pou, action):
  1015     def IsPouActionEditing(self, pou, action):
   995         return self.ComputePouActionName(pou, action) in self.ElementsOpened
  1016         return self.ComputePouActionName(pou, action) in self.ElementsOpened
   996 
  1017 
   997     # Return if pou action given by configuration name is opened
  1018     # Return if pou action given by configuration name is opened
   998     def IsConfigurationEditing(self, pou):
  1019     def IsConfigurationEditing(self, config):
   999         return self.ComputeConfigurationName(config) in self.ElementsOpened
  1020         return self.ComputeConfigurationName(config) in self.ElementsOpened
  1000 
  1021 
  1001     # Return if pou action given by configuration and resource names is opened
  1022     # Return if pou action given by configuration and resource names is opened
  1002     def IsConfigurationResourceEditing(self, pou, resource):
  1023     def IsConfigurationResourceEditing(self, config, resource):
  1003         return self.ComputeConfigurationResourceName(config, resource) in self.ElementsOpened
  1024         return self.ComputeConfigurationResourceName(config, resource) in self.ElementsOpened
  1004 
  1025 
  1005     # Close current pou editing
  1026     # Close current element editing
  1006     def CloseElementEditing(self):
  1027     def CloseElementEditing(self):
  1007         # Remove pou from list of pou opened
  1028         # Remove pou from list of pou opened
  1008         self.ElementsOpened.pop(self.CurrentElementEditing)
  1029         self.ElementsOpened.pop(self.CurrentElementEditing)
  1009         # Update index of current pou editing
  1030         # Update index of current element editing
  1010         if len(self.ElementsOpened) > 0:
  1031         if len(self.ElementsOpened) > 0:
  1011             self.CurrentElementEditing = min(self.CurrentElementEditing, len(self.ElementsOpened) - 1)
  1032             self.CurrentElementEditing = min(self.CurrentElementEditing, len(self.ElementsOpened) - 1)
  1012         else:
  1033         else:
  1013             self.CurrentElementEditing = None
  1034             self.CurrentElementEditing = None
  1014 
  1035 
  1015     # Change current pou editing for pou given by name
  1036     # Change current element editing for pou given by name
  1016     def ChangeElementEditing(self, name):
  1037     def ChangeElementEditing(self, name):
  1017         # Verify that pou is opened
  1038         # Verify that element is opened
  1018         if name in self.ElementsOpened:
  1039         if name in self.ElementsOpened:
  1019             # Change current pou editing
  1040             # Change current element editing
  1020             self.CurrentElementEditing = self.ElementsOpened.index(name)
  1041             self.CurrentElementEditing = self.ElementsOpened.index(name)
  1021             return self.CurrentElementEditing
  1042             return self.CurrentElementEditing
  1022         return None
  1043         return None
  1023 
  1044     
  1024     # Change current pou editing for transition given by pou and transition names
  1045     # Change current element editing for pou given by pou name
       
  1046     def ChangePouEditing(self, pou):
       
  1047         return self.ChangeElementEditing(self.ComputePouName(pou))
       
  1048 
       
  1049     # Change current element editing for transition given by pou and transition names
  1025     def ChangePouTransitionEditing(self, pou, transition):
  1050     def ChangePouTransitionEditing(self, pou, transition):
  1026         return self.ChangeElementEditing(self.ComputePouTransitionName(pou, transition))
  1051         return self.ChangeElementEditing(self.ComputePouTransitionName(pou, transition))
  1027 
  1052 
  1028     # Change current pou editing for action given by pou and action names
  1053     # Change current element editing for action given by pou and action names
  1029     def ChangePouActionEditing(self, pou, action):
  1054     def ChangePouActionEditing(self, pou, action):
  1030         return self.ChangeElementEditing(self.ComputePouActionName(pou, action))
  1055         return self.ChangeElementEditing(self.ComputePouActionName(pou, action))
  1031 
  1056 
  1032     # Change current pou editing for action given by configuration name
  1057     # Change current element editing for configuration given by configuration name
  1033     def ChangeConfigurationEditing(self, config):
  1058     def ChangeConfigurationEditing(self, config):
  1034         return self.ChangeElementEditing(self.ComputeConfigurationName(config))
  1059         return self.ChangeElementEditing(self.ComputeConfigurationName(config))
  1035 
  1060 
  1036     # Change current pou editing for action given by configuration and resource names
  1061     # Change current element editing for resource given by configuration and resource names
  1037     def ChangeConfigurationResourceEditing(self, config, resource):
  1062     def ChangeConfigurationResourceEditing(self, config, resource):
  1038         return self.ChangeElementEditing(self.ComputeConfigurationResourceName(config, resource))
  1063         return self.ChangeElementEditing(self.ComputeConfigurationResourceName(config, resource))
  1039 
  1064 
  1040 #-------------------------------------------------------------------------------
  1065 #-------------------------------------------------------------------------------
  1041 #                       Project opened Pous management functions
  1066 #                       Project opened Pous management functions
  1045     def GetCurrentElementEditing(self):
  1070     def GetCurrentElementEditing(self):
  1046         # Verify that there's one editing and return it
  1071         # Verify that there's one editing and return it
  1047         if self.CurrentElementEditing != None:
  1072         if self.CurrentElementEditing != None:
  1048             name = self.ElementsOpened[self.CurrentElementEditing]
  1073             name = self.ElementsOpened[self.CurrentElementEditing]
  1049             words = name.split("::")
  1074             words = name.split("::")
  1050             if len(words) == 1:
  1075             if words[0] == "P":
  1051                 return self.Project.getPou(name)
  1076                 return self.Project.getPou(words[1])
  1052             else:
  1077             if words[0] in ['T', 'A']:
  1053                 if words[0] in ['T', 'A']:
  1078                 pou = self.Project.getPou(words[1])
  1054                     pou = self.Project.getPou(words[1])
  1079                 if words[0] == 'T':
  1055                     if words[0] == 'T':
  1080                     return pou.getTransition(words[2])
  1056                         return pou.getTransition(words[2])
  1081                 elif words[0] == 'A':
  1057                     elif words[0] == 'A':
  1082                     return pou.getAction(words[2])
  1058                         return pou.getAction(words[2])
  1083             elif words[0] == 'C':
  1059                 elif words[0] == 'C':
  1084                 return self.Project.getConfiguration(words[1])
  1060                     result = self.Project.getConfiguration(words[1])
  1085             elif words[0] == 'R':
  1061                     return result
  1086                 return self.Project.getConfigurationResource(words[1], words[2])
  1062                 elif words[0] == 'R':
       
  1063                     result = self.Project.getConfigurationResource(words[1], words[2])
       
  1064                     return result
       
  1065         return None
  1087         return None
  1066     
  1088     
  1067     # Return current pou editing name
  1089     # Return current pou editing name
  1068     def GetCurrentElementEditingName(self):
  1090     def GetCurrentElementEditingName(self):
  1069         # Verify that there's one editing and return its name
  1091         # Verify that there's one editing and return its name
  1070         if self.CurrentElementEditing != None:
  1092         if self.CurrentElementEditing != None:
  1071             name = self.ElementsOpened[self.CurrentElementEditing]
  1093             name = self.ElementsOpened[self.CurrentElementEditing]
  1072             words = name.split("::")
  1094             words = name.split("::")
  1073             if len(words) == 1:
  1095             if words[0] in ["P","C"]:
  1074                 return name
       
  1075             elif len(words) == 2:
       
  1076                 return words[1]
  1096                 return words[1]
  1077             else:
  1097             else:
  1078                 return words[2]
  1098                 return words[2]
  1079         return None
  1099         return None
  1080     
  1100     
  1085     # Return language in which current pou editing is written
  1105     # Return language in which current pou editing is written
  1086     def GetCurrentElementEditingType(self):
  1106     def GetCurrentElementEditingType(self):
  1087         if self.CurrentElementEditing != None:
  1107         if self.CurrentElementEditing != None:
  1088             name = self.ElementsOpened[self.CurrentElementEditing]
  1108             name = self.ElementsOpened[self.CurrentElementEditing]
  1089             words = name.split("::")
  1109             words = name.split("::")
  1090             if len(words) == 1:
  1110             if words[0] == "P":
  1091                 return self.GetPouType(name)
       
  1092             elif len(words) == 2:
       
  1093                 return None
       
  1094             elif words[0] != "R":
       
  1095                 return self.GetPouType(words[1])
  1111                 return self.GetPouType(words[1])
  1096         return None
  1112         return None
  1097 
  1113 
  1098     # Return language in which current pou editing is written
  1114     # Return language in which current pou editing is written
  1099     def GetCurrentElementEditingBodyType(self):
  1115     def GetCurrentElementEditingBodyType(self):
  1100         if self.CurrentElementEditing != None:
  1116         if self.CurrentElementEditing != None:
  1101             name = self.ElementsOpened[self.CurrentElementEditing]
  1117             name = self.ElementsOpened[self.CurrentElementEditing]
  1102             words = name.split("::")
  1118             words = name.split("::")
  1103             if len(words) == 1:
  1119             if words[0] == "P":
  1104                 return self.GetPouBodyType(name)
  1120                 return self.GetPouBodyType(words[1])
  1105             else:
  1121             elif words[0] == 'T':
  1106                 if words[0] == 'T':
  1122                 return self.GetTransitionBodyType(words[1], words[2])
  1107                     return self.GetTransitionBodyType(words[1], words[2])
  1123             elif words[0] == 'A':
  1108                 elif words[0] == 'A':
  1124                 return self.GetActionBodyType(words[1], words[2])
  1109                     return self.GetActionBodyType(words[1], words[2])
       
  1110         return None
  1125         return None
  1111 
  1126 
  1112     # Return the variables of the current pou editing
  1127     # Return the variables of the current pou editing
  1113     def GetCurrentElementEditingInterfaceVars(self):
  1128     def GetCurrentElementEditingInterfaceVars(self):
  1114         if self.CurrentElementEditing != None:
  1129         if self.CurrentElementEditing != None:
  1115             current_name = self.ElementsOpened[self.CurrentElementEditing]
  1130             current_name = self.ElementsOpened[self.CurrentElementEditing]
  1116             words = current_name.split("::")
  1131             words = current_name.split("::")
  1117             if len(words) == 1:
  1132             if words[0] in ["P","T","A"]:
  1118                 pou = self.Project.getPou(current_name)
       
  1119                 return self.GetPouInterfaceVars(pou)
       
  1120             else:
       
  1121                 pou = self.Project.getPou(words[1])
  1133                 pou = self.Project.getPou(words[1])
  1122                 return self.GetPouInterfaceVars(pou)
  1134                 return self.GetPouInterfaceVars(pou)
  1123         return []
  1135         return []
  1124 
  1136 
  1125     # Return the return type of the current pou editing
  1137     # Return the return type of the current pou editing
  1126     def GetCurrentElementEditingInterfaceReturnType(self):
  1138     def GetCurrentElementEditingInterfaceReturnType(self):
  1127         if self.CurrentElementEditing != None:
  1139         if self.CurrentElementEditing != None:
  1128             current_name = self.ElementsOpened[self.CurrentElementEditing]
  1140             current_name = self.ElementsOpened[self.CurrentElementEditing]
  1129             words = current_name.split("::")
  1141             words = current_name.split("::")
  1130             if len(words) == 1:
  1142             if words[0] == "P":
  1131                 pou = self.Project.getPou(current_name)
  1143                 pou = self.Project.getPou(words[1])
  1132                 return self.GetPouInterfaceReturnType(pou)
  1144                 return self.GetPouInterfaceReturnType(pou)
  1133             elif words[0] == 'T':
  1145             elif words[0] == 'T':
  1134                 return "BOOL"
  1146                 return "BOOL"
  1135         return None
  1147         return None
  1136     
  1148     
  1171     # Return the names of the pou elements
  1183     # Return the names of the pou elements
  1172     def GetCurrentElementEditingVariables(self):
  1184     def GetCurrentElementEditingVariables(self):
  1173         if self.CurrentElementEditing != None:
  1185         if self.CurrentElementEditing != None:
  1174             current_name = self.ElementsOpened[self.CurrentElementEditing]
  1186             current_name = self.ElementsOpened[self.CurrentElementEditing]
  1175             words = current_name.split("::")
  1187             words = current_name.split("::")
  1176             if len(words) == 1:
  1188             if words[0] in ["P","T","A"]:
  1177                 return self.GetProjectPouVariables(current_name)
       
  1178             else:
       
  1179                 return self.GetProjectPouVariables(words[1])
  1189                 return self.GetProjectPouVariables(words[1])
  1180         return []
  1190         return []
  1181 
  1191 
  1182     # Return the current pou editing informations
  1192     # Return the current pou editing informations
  1183     def GetCurrentElementEditingInstanceInfos(self, id = None, exclude = []):
  1193     def GetCurrentElementEditingInstanceInfos(self, id = None, exclude = []):
  1343                 if instance.connectionPointOutAction:
  1353                 if instance.connectionPointOutAction:
  1344                     infos["connectors"]["action"] = {"position" : instance.connectionPointOutAction.getRelPosition()}
  1354                     infos["connectors"]["action"] = {"position" : instance.connectionPointOutAction.getRelPosition()}
  1345             elif isinstance(instance, plcopen.transition):
  1355             elif isinstance(instance, plcopen.transition):
  1346                 infos["type"] = "transition"
  1356                 infos["type"] = "transition"
  1347                 condition = instance.getConditionContent()
  1357                 condition = instance.getConditionContent()
       
  1358                 priority = instance.getPriority()
       
  1359                 if priority == None:
       
  1360                     infos["priority"] = 0
       
  1361                 else:
       
  1362                     infos["priority"] = priority
  1348                 infos["condition_type"] = condition["type"]
  1363                 infos["condition_type"] = condition["type"]
  1349                 infos["connectors"] = {"input":{},"output":{}}
  1364                 infos["connectors"] = {"input":{},"output":{}}
  1350                 infos["connectors"]["input"]["position"] = instance.connectionPointIn.getRelPosition()
  1365                 infos["connectors"]["input"]["position"] = instance.connectionPointIn.getRelPosition()
  1351                 infos["connectors"]["input"]["links"] = []
  1366                 infos["connectors"]["input"]["links"] = []
  1352                 connections = instance.connectionPointIn.getConnections()
  1367                 connections = instance.connectionPointIn.getConnections()
  1431     
  1446     
  1432     # Return the variable type of the given pou
  1447     # Return the variable type of the given pou
  1433     def GetCurrentPouVarValueType(self, varname):
  1448     def GetCurrentPouVarValueType(self, varname):
  1434         current_name = self.ElementsOpened[self.CurrentElementEditing]
  1449         current_name = self.ElementsOpened[self.CurrentElementEditing]
  1435         words = current_name.split("::")
  1450         words = current_name.split("::")
  1436         if len(words) == 1:
  1451         if words[0] in ["P","T","A"]:
  1437             pou = self.Project.getPou(current_name)
       
  1438         else:
       
  1439             pou = self.Project.getPou(words[1])
  1452             pou = self.Project.getPou(words[1])
  1440         for type, varlist in pou.getVars():
  1453             for type, varlist in pou.getVars():
  1441             for var in varlist.getVariable():
  1454                 for var in varlist.getVariable():
  1442                 if var.getName() == varname:
  1455                     if var.getName() == varname:
  1443                     return var.getType()
  1456                         return var.getType()
  1444         return ""
  1457         return ""
  1445     
  1458     
  1446     def SetConnectionWires(self, connection, connector):
  1459     def SetConnectionWires(self, connection, connector):
  1447         wires = connector.GetWires()
  1460         wires = connector.GetWires()
  1448         idx = 0
  1461         idx = 0
  1473         blocktype_infos = GetBlockType(blocktype)
  1486         blocktype_infos = GetBlockType(blocktype)
  1474         if blocktype_infos["type"] != "function":
  1487         if blocktype_infos["type"] != "function":
  1475             if self.CurrentElementEditing != None:
  1488             if self.CurrentElementEditing != None:
  1476                 name = self.ElementsOpened[self.CurrentElementEditing]
  1489                 name = self.ElementsOpened[self.CurrentElementEditing]
  1477                 words = name.split("::")
  1490                 words = name.split("::")
  1478                 if len(words) == 1:
  1491                 if words[0] in ["P","T","A"]:
  1479                     element.addPouVar(blocktype, blockname)
       
  1480                 elif words[0] in ['T', 'A']:
       
  1481                     pou = self.Project.getPou(words[1])
  1492                     pou = self.Project.getPou(words[1])
  1482                     pou.addPouVar(blocktype, blockname)    
  1493                     pou.addPouVar(blocktype, blockname)    
  1483         element.addInstance("block", block)
  1494         element.addInstance("block", block)
  1484         self.RefreshPouUsingTree()
  1495         self.RefreshPouUsingTree()
  1485     
  1496     
  1821                 transition.setWidth(value)
  1832                 transition.setWidth(value)
  1822             elif param == "x":
  1833             elif param == "x":
  1823                 transition.setX(value)
  1834                 transition.setX(value)
  1824             elif param == "y":
  1835             elif param == "y":
  1825                 transition.setY(value)
  1836                 transition.setY(value)
       
  1837             elif param == "priority":
       
  1838                 if value != 0:
       
  1839                     transition.setPriority(value)
       
  1840                 else:
       
  1841                     transition.setPriority(None)
  1826             elif param == "connectors":
  1842             elif param == "connectors":
  1827                 input_connector = value["input"]
  1843                 input_connector = value["input"]
  1828                 position = input_connector.GetRelPosition()
  1844                 position = input_connector.GetRelPosition()
  1829                 transition.addConnectionPointIn()
  1845                 transition.addConnectionPointIn()
  1830                 transition.connectionPointIn.setRelPosition(position.x, position.y)
  1846                 transition.connectionPointIn.setRelPosition(position.x, position.y)