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 |
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) |
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 |
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 |
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 |