989 |
904 |
990 # Compute a pou name |
905 # Compute a pou name |
991 def ComputeConfigurationResourceName(self, config, resource): |
906 def ComputeConfigurationResourceName(self, config, resource): |
992 return "R::%s::%s" % (config, resource) |
907 return "R::%s::%s" % (config, resource) |
993 |
908 |
994 # Open a pou by giving its name |
|
995 def OpenElementEditing(self, name): |
|
996 # If pou not opened yet |
|
997 if name not in self.ElementsOpened: |
|
998 # Add pou name to list of pou opened and make it current editing |
|
999 self.ElementsOpened.append(name) |
|
1000 self.CurrentElementEditing = len(self.ElementsOpened) - 1 |
|
1001 return self.CurrentElementEditing |
|
1002 return None |
|
1003 |
|
1004 # Open a pou transition by giving pou and transition names |
|
1005 def OpenPouEditing(self, pou): |
|
1006 return self.OpenElementEditing(self.ComputePouName(pou)) |
|
1007 |
|
1008 # Open a pou transition by giving pou and transition names |
|
1009 def OpenPouTransitionEditing(self, pou, transition): |
|
1010 return self.OpenElementEditing(self.ComputePouTransitionName(pou, transition)) |
|
1011 |
|
1012 # Open a pou action by giving pou and action names |
|
1013 def OpenPouActionEditing(self, pou, action): |
|
1014 return self.OpenElementEditing(self.ComputePouActionName(pou, action)) |
|
1015 |
|
1016 # Open a configuration resource by giving configuration name |
|
1017 def OpenConfigurationEditing(self, config): |
|
1018 return self.OpenElementEditing(self.ComputeConfigurationName(config)) |
|
1019 |
|
1020 # Open a configuration resource by giving configuration and resource names |
|
1021 def OpenConfigurationResourceEditing(self, config, resource): |
|
1022 return self.OpenElementEditing(self.ComputeConfigurationResourceName(config, resource)) |
|
1023 |
|
1024 # Return if pou given by name is opened |
|
1025 def IsPouEditing(self, pou): |
|
1026 return self.ComputePouName(pou) in self.ElementsOpened |
|
1027 |
|
1028 # Return if pou transition given by pou and transition names is opened |
|
1029 def IsPouTransitionEditing(self, pou, transition): |
|
1030 return self.ComputePouTransitionName(pou, transition) in self.ElementsOpened |
|
1031 |
|
1032 # Return if pou action given by pou and action names is opened |
|
1033 def IsPouActionEditing(self, pou, action): |
|
1034 return self.ComputePouActionName(pou, action) in self.ElementsOpened |
|
1035 |
|
1036 # Return if pou action given by configuration name is opened |
|
1037 def IsConfigurationEditing(self, config): |
|
1038 return self.ComputeConfigurationName(config) in self.ElementsOpened |
|
1039 |
|
1040 # Return if pou action given by configuration and resource names is opened |
|
1041 def IsConfigurationResourceEditing(self, config, resource): |
|
1042 return self.ComputeConfigurationResourceName(config, resource) in self.ElementsOpened |
|
1043 |
|
1044 # Close current element editing |
|
1045 def CloseElementEditing(self): |
|
1046 # Remove pou from list of pou opened |
|
1047 self.ElementsOpened.pop(self.CurrentElementEditing) |
|
1048 # Update index of current element editing |
|
1049 if len(self.ElementsOpened) > 0: |
|
1050 self.CurrentElementEditing = min(self.CurrentElementEditing, len(self.ElementsOpened) - 1) |
|
1051 else: |
|
1052 self.CurrentElementEditing = None |
|
1053 |
|
1054 # Close current element editing |
|
1055 def CloseAllElements(self): |
|
1056 # Clear the pou opened list |
|
1057 self.ElementsOpened = [] |
|
1058 self.CurrentElementEditing = None |
|
1059 |
|
1060 # Change current element editing for pou given by name |
|
1061 def ChangeElementEditing(self, name): |
|
1062 # Verify that element is opened |
|
1063 if name in self.ElementsOpened: |
|
1064 # Change current element editing |
|
1065 self.CurrentElementEditing = self.ElementsOpened.index(name) |
|
1066 return self.CurrentElementEditing |
|
1067 return None |
|
1068 |
|
1069 # Change current element editing for pou given by pou name |
|
1070 def ChangePouEditing(self, pou): |
|
1071 return self.ChangeElementEditing(self.ComputePouName(pou)) |
|
1072 |
|
1073 # Change current element editing for transition given by pou and transition names |
|
1074 def ChangePouTransitionEditing(self, pou, transition): |
|
1075 return self.ChangeElementEditing(self.ComputePouTransitionName(pou, transition)) |
|
1076 |
|
1077 # Change current element editing for action given by pou and action names |
|
1078 def ChangePouActionEditing(self, pou, action): |
|
1079 return self.ChangeElementEditing(self.ComputePouActionName(pou, action)) |
|
1080 |
|
1081 # Change current element editing for configuration given by configuration name |
|
1082 def ChangeConfigurationEditing(self, config): |
|
1083 return self.ChangeElementEditing(self.ComputeConfigurationName(config)) |
|
1084 |
|
1085 # Change current element editing for resource given by configuration and resource names |
|
1086 def ChangeConfigurationResourceEditing(self, config, resource): |
|
1087 return self.ChangeElementEditing(self.ComputeConfigurationResourceName(config, resource)) |
|
1088 |
|
1089 #------------------------------------------------------------------------------- |
909 #------------------------------------------------------------------------------- |
1090 # Project opened Pous management functions |
910 # Project opened Pous management functions |
1091 #------------------------------------------------------------------------------- |
911 #------------------------------------------------------------------------------- |
1092 |
912 |
1093 # Return current pou editing |
913 # Return edited element |
1094 def GetCurrentElementEditing(self): |
914 def GetEditedElement(self, tagname): |
1095 # Verify that there's one editing and return it |
915 words = tagname.split("::") |
1096 if self.CurrentElementEditing != None: |
916 if words[0] == "P": |
1097 name = self.ElementsOpened[self.CurrentElementEditing] |
917 return self.Project.getPou(words[1]) |
1098 words = name.split("::") |
918 if words[0] in ['T', 'A']: |
1099 if words[0] == "P": |
919 pou = self.Project.getPou(words[1]) |
1100 return self.Project.getPou(words[1]) |
920 if words[0] == 'T': |
1101 if words[0] in ['T', 'A']: |
921 return pou.getTransition(words[2]) |
1102 pou = self.Project.getPou(words[1]) |
922 elif words[0] == 'A': |
1103 if words[0] == 'T': |
923 return pou.getAction(words[2]) |
1104 return pou.getTransition(words[2]) |
924 elif words[0] == 'C': |
1105 elif words[0] == 'A': |
925 return self.Project.getConfiguration(words[1]) |
1106 return pou.getAction(words[2]) |
926 elif words[0] == 'R': |
1107 elif words[0] == 'C': |
927 return self.Project.getConfigurationResource(words[1], words[2]) |
1108 return self.Project.getConfiguration(words[1]) |
|
1109 elif words[0] == 'R': |
|
1110 return self.Project.getConfigurationResource(words[1], words[2]) |
|
1111 return None |
928 return None |
1112 |
929 |
1113 # Return current pou editing name |
930 # Return edited element name |
1114 def GetCurrentElementEditingName(self): |
931 def GetEditedElementName(self, tagname): |
1115 # Verify that there's one editing and return its name |
932 words = tagname.split("::") |
1116 if self.CurrentElementEditing != None: |
933 if words[0] in ["P","C"]: |
1117 name = self.ElementsOpened[self.CurrentElementEditing] |
934 return words[1] |
1118 words = name.split("::") |
935 else: |
1119 if words[0] in ["P","C"]: |
936 return words[2] |
1120 return words[1] |
937 return None |
|
938 |
|
939 # Return edited element name and type |
|
940 def GetEditedElementType(self, tagname): |
|
941 words = tagname.split("::") |
|
942 if words[0] in ["P","T","A"]: |
|
943 return words[1], self.GetPouType(words[1]) |
|
944 return None, None |
|
945 |
|
946 # Return language in which edited element is written |
|
947 def GetEditedElementBodyType(self, tagname): |
|
948 words = tagname.split("::") |
|
949 if words[0] == "P": |
|
950 return self.GetPouBodyType(words[1]) |
|
951 elif words[0] == 'T': |
|
952 return self.GetTransitionBodyType(words[1], words[2]) |
|
953 elif words[0] == 'A': |
|
954 return self.GetActionBodyType(words[1], words[2]) |
|
955 return None |
|
956 |
|
957 # Return the edited element variables |
|
958 def GetEditedElementInterfaceVars(self, tagname): |
|
959 words = tagname.split("::") |
|
960 if words[0] in ["P","T","A"]: |
|
961 pou = self.Project.getPou(words[1]) |
|
962 return self.GetPouInterfaceVars(pou) |
|
963 return [] |
|
964 |
|
965 # Return the edited element return type |
|
966 def GetEditedElementInterfaceReturnType(self, tagname): |
|
967 words = tagname.split("::") |
|
968 if words[0] == "P": |
|
969 pou = self.Project.getPou(words[1]) |
|
970 return self.GetPouInterfaceReturnType(pou) |
|
971 elif words[0] == 'T': |
|
972 return "BOOL" |
|
973 return None |
|
974 |
|
975 # Change the edited element taxt |
|
976 def SetEditedElementText(self, tagname, text): |
|
977 element = self.GetEditedElement(tagname) |
|
978 if element != None: |
|
979 element.setText(text) |
|
980 self.RefreshPouUsingTree() |
|
981 |
|
982 # Return the edited element text |
|
983 def GetEditedElementText(self, tagname): |
|
984 element = self.GetEditedElement(tagname) |
|
985 if element != None: |
|
986 return element.getText() |
|
987 return "" |
|
988 |
|
989 # Return the edited element transitions |
|
990 def GetEditedElementTransitions(self, tagname): |
|
991 pou = self.GetEditedElement(tagname) |
|
992 if pou != None and pou.getBodyType() == "SFC": |
|
993 transitions = [] |
|
994 for transition in pou.getTransitionList(): |
|
995 transitions.append(transition.getName()) |
|
996 return transitions |
|
997 return [] |
|
998 |
|
999 # Return edited element transitions |
|
1000 def GetEditedElementActions(self, tagname): |
|
1001 pou = self.GetEditedElement(tagname) |
|
1002 if pou != None and pou.getBodyType() == "SFC": |
|
1003 actions = [] |
|
1004 for action in pou.getActionList(): |
|
1005 actions.append(action.getName()) |
|
1006 return actions |
|
1007 return [] |
|
1008 |
|
1009 # Return the names of the pou elements |
|
1010 def GetEditedElementVariables(self, tagname): |
|
1011 words = tagname.split("::") |
|
1012 if words[0] in ["P","T","A"]: |
|
1013 return self.GetProjectPouVariables(words[1]) |
|
1014 return [] |
|
1015 |
|
1016 # Return the current pou editing informations |
|
1017 def GetEditedElementInstanceInfos(self, tagname, id = None, exclude = []): |
|
1018 infos = {} |
|
1019 instance = None |
|
1020 element = self.GetEditedElement(tagname) |
|
1021 if element is not None: |
|
1022 # if id is defined |
|
1023 if id is not None: |
|
1024 instance = element.getInstance(id) |
1121 else: |
1025 else: |
1122 return words[2] |
1026 instance = element.getRandomInstance(exclude) |
1123 return None |
1027 if instance is not None: |
1124 |
1028 if id is not None: |
1125 # Replace the index of current pou editing by the one given |
|
1126 def RefreshCurrentElementEditing(self, index): |
|
1127 self.CurrentElementEditing = index |
|
1128 |
|
1129 # Return current pou editing name and type |
|
1130 def GetCurrentElementEditingType(self): |
|
1131 if self.CurrentElementEditing != None: |
|
1132 name = self.ElementsOpened[self.CurrentElementEditing] |
|
1133 words = name.split("::") |
|
1134 if words[0] in ["P","T","A"]: |
|
1135 return words[1], self.GetPouType(words[1]) |
|
1136 return None, None |
|
1137 |
|
1138 # Return language in which current pou editing is written |
|
1139 def GetCurrentElementEditingBodyType(self): |
|
1140 if self.CurrentElementEditing != None: |
|
1141 name = self.ElementsOpened[self.CurrentElementEditing] |
|
1142 words = name.split("::") |
|
1143 if words[0] == "P": |
|
1144 return self.GetPouBodyType(words[1]) |
|
1145 elif words[0] == 'T': |
|
1146 return self.GetTransitionBodyType(words[1], words[2]) |
|
1147 elif words[0] == 'A': |
|
1148 return self.GetActionBodyType(words[1], words[2]) |
|
1149 return None |
|
1150 |
|
1151 # Return the variables of the current pou editing |
|
1152 def GetCurrentElementEditingInterfaceVars(self): |
|
1153 if self.CurrentElementEditing != None: |
|
1154 current_name = self.ElementsOpened[self.CurrentElementEditing] |
|
1155 words = current_name.split("::") |
|
1156 if words[0] in ["P","T","A"]: |
|
1157 pou = self.Project.getPou(words[1]) |
|
1158 return self.GetPouInterfaceVars(pou) |
|
1159 return [] |
|
1160 |
|
1161 # Return the return type of the current pou editing |
|
1162 def GetCurrentElementEditingInterfaceReturnType(self): |
|
1163 if self.CurrentElementEditing != None: |
|
1164 current_name = self.ElementsOpened[self.CurrentElementEditing] |
|
1165 words = current_name.split("::") |
|
1166 if words[0] == "P": |
|
1167 pou = self.Project.getPou(words[1]) |
|
1168 return self.GetPouInterfaceReturnType(pou) |
|
1169 elif words[0] == 'T': |
|
1170 return "BOOL" |
|
1171 return None |
|
1172 |
|
1173 # Change the text of the current pou editing |
|
1174 def SetCurrentElementEditingText(self, text): |
|
1175 if self.CurrentElementEditing != None: |
|
1176 self.GetCurrentElementEditing().setText(text) |
|
1177 self.RefreshPouUsingTree() |
|
1178 |
|
1179 # Return the current pou editing text |
|
1180 def GetCurrentElementEditingText(self): |
|
1181 if self.CurrentElementEditing != None: |
|
1182 return self.GetCurrentElementEditing().getText() |
|
1183 return "" |
|
1184 |
|
1185 # Return the current pou editing transitions |
|
1186 def GetCurrentElementEditingTransitions(self): |
|
1187 if self.CurrentElementEditing != None: |
|
1188 pou = self.GetCurrentElementEditing() |
|
1189 if pou.getBodyType() == "SFC": |
|
1190 transitions = [] |
|
1191 for transition in pou.getTransitionList(): |
|
1192 transitions.append(transition.getName()) |
|
1193 return transitions |
|
1194 return [] |
|
1195 |
|
1196 # Return the current pou editing transitions |
|
1197 def GetCurrentElementEditingActions(self): |
|
1198 if self.CurrentElementEditing != None: |
|
1199 pou = self.GetCurrentElementEditing() |
|
1200 if pou.getBodyType() == "SFC": |
|
1201 actions = [] |
|
1202 for action in pou.getActionList(): |
|
1203 actions.append(action.getName()) |
|
1204 return actions |
|
1205 return [] |
|
1206 |
|
1207 # Return the names of the pou elements |
|
1208 def GetCurrentElementEditingVariables(self): |
|
1209 if self.CurrentElementEditing != None: |
|
1210 current_name = self.ElementsOpened[self.CurrentElementEditing] |
|
1211 words = current_name.split("::") |
|
1212 if words[0] in ["P","T","A"]: |
|
1213 return self.GetProjectPouVariables(words[1]) |
|
1214 return [] |
|
1215 |
|
1216 # Return the current pou editing informations |
|
1217 def GetCurrentElementEditingInstanceInfos(self, id = None, exclude = []): |
|
1218 infos = {} |
|
1219 # if id is defined |
|
1220 if id != None: |
|
1221 instance = self.GetCurrentElementEditing().getInstance(id) |
|
1222 else: |
|
1223 instance = self.GetCurrentElementEditing().getRandomInstance(exclude) |
|
1224 if instance: |
|
1225 if id != None: |
|
1226 infos["id"] = id |
1029 infos["id"] = id |
1227 else: |
1030 else: |
1228 infos["id"] = instance.getLocalId() |
1031 infos["id"] = instance.getLocalId() |
1229 infos["x"] = instance.getX() |
1032 infos["x"] = instance.getX() |
1230 infos["y"] = instance.getY() |
1033 infos["y"] = instance.getY() |
1546 connection.setConnectionParameter(idx, formalParameter) |
1352 connection.setConnectionParameter(idx, formalParameter) |
1547 else: |
1353 else: |
1548 connection.setConnectionParameter(idx, None) |
1354 connection.setConnectionParameter(idx, None) |
1549 idx += 1 |
1355 idx += 1 |
1550 |
1356 |
1551 def AddCurrentElementEditingBlock(self, id, blocktype, blockname = None): |
1357 def AddEditedElementBlock(self, tagname, id, blocktype, blockname = None): |
1552 block = plcopen.block() |
1358 element = self.GetEditedElement(tagname) |
1553 block.setLocalId(id) |
1359 if element is not None: |
1554 block.setTypeName(blocktype) |
1360 block = plcopen.block() |
1555 if blockname: |
1361 block.setLocalId(id) |
1556 block.setInstanceName(blockname) |
1362 block.setTypeName(blocktype) |
1557 element = self.GetCurrentElementEditing() |
1363 blocktype_infos = GetBlockType(blocktype) |
1558 blocktype_infos = GetBlockType(blocktype) |
1364 if blocktype_infos["type"] != "function" and blockname is not None: |
1559 if blocktype_infos["type"] != "function": |
1365 block.setInstanceName(blockname) |
1560 if self.CurrentElementEditing != None: |
1366 element.addPouVar(blocktype, blockname) |
1561 name = self.ElementsOpened[self.CurrentElementEditing] |
1367 element.addInstance("block", block) |
1562 words = name.split("::") |
1368 self.RefreshPouUsingTree() |
1563 if words[0] in ["P","T","A"]: |
1369 |
1564 pou = self.Project.getPou(words[1]) |
1370 def SetEditedElementBlockInfos(self, tagname, id, infos): |
1565 pou.addPouVar(blocktype, blockname) |
1371 element = self.GetEditedElement(tagname) |
1566 element.addInstance("block", block) |
1372 if element is not None: |
1567 self.RefreshPouUsingTree() |
1373 block = element.getInstance(id) |
1568 |
1374 if "name" in infos or "type" in infos: |
1569 def SetCurrentElementEditingBlockInfos(self, id, infos): |
1375 old_name = block.getInstanceName() |
1570 block = self.GetCurrentElementEditing().getInstance(id) |
1376 old_type = block.getTypeName() |
1571 if "name" in infos or "type" in infos: |
1377 new_name = infos.get("name", old_name) |
1572 old_name = block.getInstanceName() |
1378 new_type = infos.get("type", old_type) |
1573 old_type = block.getTypeName() |
1379 self.GetEditedElement(tagname).changePouVar(old_type, old_name, new_type, new_name) |
1574 new_name = infos.get("name", old_name) |
1380 for param, value in infos.items(): |
1575 new_type = infos.get("type", old_type) |
1381 if param == "name": |
1576 self.GetCurrentElementEditing().changePouVar(old_type, old_name, new_type, new_name) |
1382 block.setInstanceName(value) |
1577 for param, value in infos.items(): |
1383 elif param == "type": |
1578 if param == "name": |
1384 block.setTypeName(value) |
1579 block.setInstanceName(value) |
1385 elif param == "executionOrder" and block.getExecutionOrderId() != value: |
1580 elif param == "type": |
1386 self.GetEditedElement(tagname).setElementExecutionOrder(block, value) |
1581 block.setTypeName(value) |
1387 elif param == "height": |
1582 elif param == "executionOrder" and block.getExecutionOrderId() != value: |
1388 block.setHeight(value) |
1583 self.GetCurrentElementEditing().setElementExecutionOrder(block, value) |
1389 elif param == "width": |
1584 elif param == "height": |
1390 block.setWidth(value) |
1585 block.setHeight(value) |
1391 elif param == "x": |
1586 elif param == "width": |
1392 block.setX(value) |
1587 block.setWidth(value) |
1393 elif param == "y": |
1588 elif param == "x": |
1394 block.setY(value) |
1589 block.setX(value) |
1395 elif param == "connectors": |
1590 elif param == "y": |
1396 block.inputVariables.setVariable([]) |
1591 block.setY(value) |
1397 block.outputVariables.setVariable([]) |
1592 elif param == "connectors": |
1398 for connector in value["inputs"]: |
1593 block.inputVariables.setVariable([]) |
1399 variable = plcopen.inputVariables_variable() |
1594 block.outputVariables.setVariable([]) |
1400 variable.setFormalParameter(connector.GetName()) |
1595 for connector in value["inputs"]: |
1401 if connector.IsNegated(): |
1596 variable = plcopen.inputVariables_variable() |
1402 variable.setNegated(True) |
1597 variable.setFormalParameter(connector.GetName()) |
1403 if connector.GetEdge() != "none": |
1598 if connector.IsNegated(): |
1404 variable.setConnectorEdge(connector.GetEdge()) |
1599 variable.setNegated(True) |
1405 position = connector.GetRelPosition() |
1600 if connector.GetEdge() != "none": |
1406 variable.connectionPointIn.setRelPosition(position.x, position.y) |
1601 variable.setConnectorEdge(connector.GetEdge()) |
1407 self.SetConnectionWires(variable.connectionPointIn, connector) |
1602 position = connector.GetRelPosition() |
1408 block.inputVariables.appendVariable(variable) |
1603 variable.connectionPointIn.setRelPosition(position.x, position.y) |
1409 for connector in value["outputs"]: |
1604 self.SetConnectionWires(variable.connectionPointIn, connector) |
1410 variable = plcopen.outputVariables_variable() |
1605 block.inputVariables.appendVariable(variable) |
1411 variable.setFormalParameter(connector.GetName()) |
1606 for connector in value["outputs"]: |
1412 if connector.IsNegated(): |
1607 variable = plcopen.outputVariables_variable() |
1413 variable.setNegated(True) |
1608 variable.setFormalParameter(connector.GetName()) |
1414 if connector.GetEdge() != "none": |
1609 if connector.IsNegated(): |
1415 variable.setConnectorEdge(connector.GetEdge()) |
1610 variable.setNegated(True) |
1416 position = connector.GetRelPosition() |
1611 if connector.GetEdge() != "none": |
1417 variable.addConnectionPointOut() |
1612 variable.setConnectorEdge(connector.GetEdge()) |
1418 variable.connectionPointOut.setRelPosition(position.x, position.y) |
1613 position = connector.GetRelPosition() |
1419 block.outputVariables.appendVariable(variable) |
1614 variable.addConnectionPointOut() |
1420 self.RefreshPouUsingTree() |
1615 variable.connectionPointOut.setRelPosition(position.x, position.y) |
|
1616 block.outputVariables.appendVariable(variable) |
|
1617 self.RefreshPouUsingTree() |
|
1618 |
1421 |
1619 def AddCurrentElementEditingVariable(self, id, type): |
1422 def AddEditedElementVariable(self, tagname, id, type): |
1620 if type == INPUT: |
1423 element = self.GetEditedElement(tagname) |
1621 name = "inVariable" |
1424 if element is not None: |
1622 variable = plcopen.inVariable() |
1425 if type == INPUT: |
1623 elif type == OUTPUT: |
1426 name = "inVariable" |
1624 name = "outVariable" |
1427 variable = plcopen.inVariable() |
1625 variable = plcopen.outVariable() |
1428 elif type == OUTPUT: |
1626 elif type == INOUT: |
1429 name = "outVariable" |
1627 name = "inOutVariable" |
1430 variable = plcopen.outVariable() |
1628 variable = plcopen.inOutVariable() |
1431 elif type == INOUT: |
1629 variable.setLocalId(id) |
1432 name = "inOutVariable" |
1630 self.GetCurrentElementEditing().addInstance(name, variable) |
1433 variable = plcopen.inOutVariable() |
|
1434 variable.setLocalId(id) |
|
1435 element.addInstance(name, variable) |
1631 |
1436 |
1632 def SetCurrentElementEditingVariableInfos(self, id, infos): |
1437 def SetEditedElementVariableInfos(self, tagname, id, infos): |
1633 variable = self.GetCurrentElementEditing().getInstance(id) |
1438 element = self.GetEditedElement(tagname) |
1634 for param, value in infos.items(): |
1439 if element is not None: |
1635 if param == "name": |
1440 variable = element.getInstance(id) |
1636 variable.setExpression(value) |
1441 for param, value in infos.items(): |
1637 elif param == "executionOrder" and variable.getExecutionOrderId() != value: |
1442 if param == "name": |
1638 self.GetCurrentElementEditing().setElementExecutionOrder(variable, value) |
1443 variable.setExpression(value) |
1639 elif param == "height": |
1444 elif param == "executionOrder" and variable.getExecutionOrderId() != value: |
1640 variable.setHeight(value) |
1445 self.GetEditedElement(tagname).setElementExecutionOrder(variable, value) |
1641 elif param == "width": |
1446 elif param == "height": |
1642 variable.setWidth(value) |
1447 variable.setHeight(value) |
1643 elif param == "x": |
1448 elif param == "width": |
1644 variable.setX(value) |
1449 variable.setWidth(value) |
1645 elif param == "y": |
1450 elif param == "x": |
1646 variable.setY(value) |
1451 variable.setX(value) |
1647 elif param == "connectors": |
1452 elif param == "y": |
1648 if isinstance(variable, plcopen.inVariable): |
1453 variable.setY(value) |
1649 if value["output"].IsNegated(): |
1454 elif param == "connectors": |
1650 variable.setNegated(True) |
1455 if isinstance(variable, plcopen.inVariable): |
1651 if value["output"].GetEdge() != "none": |
1456 if value["output"].IsNegated(): |
1652 variable.setConnectorEdge(value["output"].GetEdge()) |
1457 variable.setNegated(True) |
1653 position = value["output"].GetRelPosition() |
1458 if value["output"].GetEdge() != "none": |
1654 variable.addConnectionPointOut() |
1459 variable.setConnectorEdge(value["output"].GetEdge()) |
1655 variable.connectionPointOut.setRelPosition(position.x, position.y) |
1460 position = value["output"].GetRelPosition() |
1656 elif isinstance(variable, plcopen.outVariable): |
1461 variable.addConnectionPointOut() |
1657 if value["input"].IsNegated(): |
1462 variable.connectionPointOut.setRelPosition(position.x, position.y) |
1658 variable.setNegated(True) |
1463 elif isinstance(variable, plcopen.outVariable): |
1659 if value["input"].GetEdge() != "none": |
1464 if value["input"].IsNegated(): |
1660 variable.setConnectorEdge(value["input"].GetEdge()) |
1465 variable.setNegated(True) |
1661 position = value["input"].GetRelPosition() |
1466 if value["input"].GetEdge() != "none": |
1662 variable.addConnectionPointIn() |
1467 variable.setConnectorEdge(value["input"].GetEdge()) |
1663 variable.connectionPointIn.setRelPosition(position.x, position.y) |
1468 position = value["input"].GetRelPosition() |
1664 self.SetConnectionWires(variable.connectionPointIn, value["input"]) |
1469 variable.addConnectionPointIn() |
1665 elif isinstance(variable, plcopen.inOutVariable): |
1470 variable.connectionPointIn.setRelPosition(position.x, position.y) |
1666 if value["input"].IsNegated(): |
1471 self.SetConnectionWires(variable.connectionPointIn, value["input"]) |
1667 variable.setNegatedIn(True) |
1472 elif isinstance(variable, plcopen.inOutVariable): |
1668 if value["input"].GetEdge() != "none": |
1473 if value["input"].IsNegated(): |
1669 variable.setInputEdge(value["input"].GetEdge()) |
1474 variable.setNegatedIn(True) |
1670 if value["output"].IsNegated(): |
1475 if value["input"].GetEdge() != "none": |
1671 variable.setNegatedOut(True) |
1476 variable.setInputEdge(value["input"].GetEdge()) |
1672 if value["output"].GetEdge() != "none": |
1477 if value["output"].IsNegated(): |
1673 variable.setOutputEdge(value["output"].GetEdge()) |
1478 variable.setNegatedOut(True) |
1674 position = value["output"].GetRelPosition() |
1479 if value["output"].GetEdge() != "none": |
1675 variable.addConnectionPointOut() |
1480 variable.setOutputEdge(value["output"].GetEdge()) |
1676 variable.connectionPointOut.setRelPosition(position.x, position.y) |
1481 position = value["output"].GetRelPosition() |
1677 position = value["input"].GetRelPosition() |
1482 variable.addConnectionPointOut() |
1678 variable.addConnectionPointIn() |
1483 variable.connectionPointOut.setRelPosition(position.x, position.y) |
1679 variable.connectionPointIn.setRelPosition(position.x, position.y) |
1484 position = value["input"].GetRelPosition() |
1680 self.SetConnectionWires(variable.connectionPointIn, value["input"]) |
1485 variable.addConnectionPointIn() |
1681 |
1486 variable.connectionPointIn.setRelPosition(position.x, position.y) |
1682 |
1487 self.SetConnectionWires(variable.connectionPointIn, value["input"]) |
1683 def AddCurrentElementEditingConnection(self, id, type): |
1488 |
1684 if type == CONNECTOR: |
1489 def AddEditedElementConnection(self, tagname, id, type): |
1685 name = "connector" |
1490 element = self.GetEditedElement(tagname) |
1686 connection = plcopen.connector() |
1491 if element is not None: |
1687 elif type == CONTINUATION: |
1492 if type == CONNECTOR: |
1688 name = "continuation" |
1493 name = "connector" |
1689 connection = plcopen.continuation() |
1494 connection = plcopen.connector() |
1690 connection.setLocalId(id) |
1495 elif type == CONTINUATION: |
1691 self.GetCurrentElementEditing().addInstance(name, connection) |
1496 name = "continuation" |
|
1497 connection = plcopen.continuation() |
|
1498 connection.setLocalId(id) |
|
1499 element.addInstance(name, connection) |
1692 |
1500 |
1693 def SetCurrentElementEditingConnectionInfos(self, id, infos): |
1501 def SetEditedElementConnectionInfos(self, tagname, id, infos): |
1694 connection = self.GetCurrentElementEditing().getInstance(id) |
1502 element = self.GetEditedElement(tagname) |
1695 for param, value in infos.items(): |
1503 if element is not None: |
1696 if param == "name": |
1504 connection = element.getInstance(id) |
1697 connection.setName(value) |
1505 for param, value in infos.items(): |
1698 elif param == "height": |
1506 if param == "name": |
1699 connection.setHeight(value) |
1507 connection.setName(value) |
1700 elif param == "width": |
1508 elif param == "height": |
1701 connection.setWidth(value) |
1509 connection.setHeight(value) |
1702 elif param == "x": |
1510 elif param == "width": |
1703 connection.setX(value) |
1511 connection.setWidth(value) |
1704 elif param == "y": |
1512 elif param == "x": |
1705 connection.setY(value) |
1513 connection.setX(value) |
1706 elif param == "connector": |
1514 elif param == "y": |
1707 position = value.GetRelPosition() |
1515 connection.setY(value) |
1708 if isinstance(connection, plcopen.continuation): |
1516 elif param == "connector": |
1709 connection.addConnectionPointOut() |
1517 position = value.GetRelPosition() |
1710 connection.connectionPointOut.setRelPosition(position.x, position.y) |
1518 if isinstance(connection, plcopen.continuation): |
1711 elif isinstance(connection, plcopen.connector): |
1519 connection.addConnectionPointOut() |
1712 connection.addConnectionPointIn() |
1520 connection.connectionPointOut.setRelPosition(position.x, position.y) |
1713 connection.connectionPointIn.setRelPosition(position.x, position.y) |
1521 elif isinstance(connection, plcopen.connector): |
1714 self.SetConnectionWires(connection.connectionPointIn, value) |
1522 connection.addConnectionPointIn() |
1715 |
1523 connection.connectionPointIn.setRelPosition(position.x, position.y) |
1716 def AddCurrentElementEditingComment(self, id): |
1524 self.SetConnectionWires(connection.connectionPointIn, value) |
1717 comment = plcopen.comment() |
1525 |
1718 comment.setLocalId(id) |
1526 def AddEditedElementComment(self, tagname, id): |
1719 self.GetCurrentElementEditing().addInstance("comment", comment) |
1527 element = self.GetEditedElement(tagname) |
1720 |
1528 if element is not None: |
1721 def SetCurrentElementEditingCommentInfos(self, id, infos): |
1529 comment = plcopen.comment() |
1722 comment = self.GetCurrentElementEditing().getInstance(id) |
1530 comment.setLocalId(id) |
1723 for param, value in infos.items(): |
1531 element.addInstance("comment", comment) |
1724 if param == "content": |
1532 |
1725 comment.setContentText(value) |
1533 def SetEditedElementCommentInfos(self, tagname, id, infos): |
1726 elif param == "height": |
1534 element = self.GetEditedElement(tagname) |
1727 comment.setHeight(value) |
1535 if element is not None: |
1728 elif param == "width": |
1536 comment = element.getInstance(id) |
1729 comment.setWidth(value) |
1537 for param, value in infos.items(): |
1730 elif param == "x": |
1538 if param == "content": |
1731 comment.setX(value) |
1539 comment.setContentText(value) |
1732 elif param == "y": |
1540 elif param == "height": |
1733 comment.setY(value) |
1541 comment.setHeight(value) |
1734 |
1542 elif param == "width": |
1735 def AddCurrentElementEditingPowerRail(self, id, type): |
1543 comment.setWidth(value) |
1736 if type == LEFTRAIL: |
1544 elif param == "x": |
1737 name = "leftPowerRail" |
1545 comment.setX(value) |
1738 powerrail = plcopen.leftPowerRail() |
1546 elif param == "y": |
1739 elif type == RIGHTRAIL: |
1547 comment.setY(value) |
1740 name = "rightPowerRail" |
1548 |
1741 powerrail = plcopen.rightPowerRail() |
1549 def AddEditedElementPowerRail(self, tagname, id, type): |
1742 powerrail.setLocalId(id) |
1550 element = self.GetEditedElement(tagname) |
1743 self.GetCurrentElementEditing().addInstance(name, powerrail) |
1551 if element is not None: |
1744 |
1552 if type == LEFTRAIL: |
1745 def SetCurrentElementEditingPowerRailInfos(self, id, infos): |
1553 name = "leftPowerRail" |
1746 powerrail = self.GetCurrentElementEditing().getInstance(id) |
1554 powerrail = plcopen.leftPowerRail() |
1747 for param, value in infos.items(): |
1555 elif type == RIGHTRAIL: |
1748 if param == "height": |
1556 name = "rightPowerRail" |
1749 powerrail.setHeight(value) |
1557 powerrail = plcopen.rightPowerRail() |
1750 elif param == "width": |
1558 powerrail.setLocalId(id) |
1751 powerrail.setWidth(value) |
1559 element.addInstance(name, powerrail) |
1752 elif param == "x": |
1560 |
1753 powerrail.setX(value) |
1561 def SetEditedElementPowerRailInfos(self, tagname, id, infos): |
1754 elif param == "y": |
1562 element = self.GetEditedElement(tagname) |
1755 powerrail.setY(value) |
1563 if element is not None: |
1756 elif param == "connectors": |
1564 powerrail = element.getInstance(id) |
1757 if isinstance(powerrail, plcopen.leftPowerRail): |
1565 for param, value in infos.items(): |
1758 powerrail.setConnectionPointOut([]) |
1566 if param == "height": |
1759 for connector in value: |
1567 powerrail.setHeight(value) |
1760 position = connector.GetRelPosition() |
1568 elif param == "width": |
1761 connection = plcopen.leftPowerRail_connectionPointOut() |
1569 powerrail.setWidth(value) |
1762 connection.setRelPosition(position.x, position.y) |
1570 elif param == "x": |
1763 powerrail.connectionPointOut.append(connection) |
1571 powerrail.setX(value) |
1764 elif isinstance(powerrail, plcopen.rightPowerRail): |
1572 elif param == "y": |
1765 powerrail.setConnectionPointIn([]) |
1573 powerrail.setY(value) |
1766 for connector in value: |
1574 elif param == "connectors": |
1767 position = connector.GetRelPosition() |
1575 if isinstance(powerrail, plcopen.leftPowerRail): |
1768 connection = plcopen.connectionPointIn() |
1576 powerrail.setConnectionPointOut([]) |
1769 connection.setRelPosition(position.x, position.y) |
1577 for connector in value: |
1770 self.SetConnectionWires(connection, connector) |
1578 position = connector.GetRelPosition() |
1771 powerrail.connectionPointIn.append(connection) |
1579 connection = plcopen.leftPowerRail_connectionPointOut() |
1772 |
1580 connection.setRelPosition(position.x, position.y) |
1773 def AddCurrentElementEditingContact(self, id): |
1581 powerrail.connectionPointOut.append(connection) |
1774 contact = plcopen.contact() |
1582 elif isinstance(powerrail, plcopen.rightPowerRail): |
1775 contact.setLocalId(id) |
1583 powerrail.setConnectionPointIn([]) |
1776 self.GetCurrentElementEditing().addInstance("contact", contact) |
1584 for connector in value: |
1777 |
1585 position = connector.GetRelPosition() |
1778 def SetCurrentElementEditingContactInfos(self, id, infos): |
1586 connection = plcopen.connectionPointIn() |
1779 contact = self.GetCurrentElementEditing().getInstance(id) |
1587 connection.setRelPosition(position.x, position.y) |
1780 for param, value in infos.items(): |
1588 self.SetConnectionWires(connection, connector) |
1781 if param == "name": |
1589 powerrail.connectionPointIn.append(connection) |
1782 contact.setVariable(value) |
1590 |
1783 elif param == "type": |
1591 def AddEditedElementEditingContact(self, tagname, id): |
1784 if value == CONTACT_NORMAL: |
1592 element = self.GetEditedElement(tagname) |
1785 contact.setNegated(False) |
1593 if element is not None: |
1786 contact.setContactEdge("none") |
1594 contact = plcopen.contact() |
1787 elif value == CONTACT_REVERSE: |
1595 contact.setLocalId(id) |
1788 contact.setNegated(True) |
1596 element.addInstance("contact", contact) |
1789 contact.setContactEdge("none") |
1597 |
1790 elif value == CONTACT_RISING: |
1598 def SetEditedElementContactInfos(self, tagname, id, infos): |
1791 contact.setNegated(False) |
1599 element = self.GetEditedElement(tagname) |
1792 contact.setContactEdge("rising") |
1600 if element is not None: |
1793 elif value == CONTACT_FALLING: |
1601 contact = element.getInstance(id) |
1794 contact.setNegated(False) |
1602 for param, value in infos.items(): |
1795 contact.setContactEdge("falling") |
1603 if param == "name": |
1796 elif param == "height": |
1604 contact.setVariable(value) |
1797 contact.setHeight(value) |
1605 elif param == "type": |
1798 elif param == "width": |
1606 if value == CONTACT_NORMAL: |
1799 contact.setWidth(value) |
1607 contact.setNegated(False) |
1800 elif param == "x": |
1608 contact.setContactEdge("none") |
1801 contact.setX(value) |
1609 elif value == CONTACT_REVERSE: |
1802 elif param == "y": |
1610 contact.setNegated(True) |
1803 contact.setY(value) |
1611 contact.setContactEdge("none") |
1804 elif param == "connectors": |
1612 elif value == CONTACT_RISING: |
1805 input_connector = value["input"] |
1613 contact.setNegated(False) |
1806 position = input_connector.GetRelPosition() |
1614 contact.setContactEdge("rising") |
1807 contact.addConnectionPointIn() |
1615 elif value == CONTACT_FALLING: |
1808 contact.connectionPointIn.setRelPosition(position.x, position.y) |
1616 contact.setNegated(False) |
1809 self.SetConnectionWires(contact.connectionPointIn, input_connector) |
1617 contact.setContactEdge("falling") |
1810 output_connector = value["output"] |
1618 elif param == "height": |
1811 position = output_connector.GetRelPosition() |
1619 contact.setHeight(value) |
1812 contact.addConnectionPointOut() |
1620 elif param == "width": |
1813 contact.connectionPointOut.setRelPosition(position.x, position.y) |
1621 contact.setWidth(value) |
1814 |
1622 elif param == "x": |
1815 def AddCurrentElementEditingCoil(self, id): |
1623 contact.setX(value) |
1816 coil = plcopen.coil() |
1624 elif param == "y": |
1817 coil.setLocalId(id) |
1625 contact.setY(value) |
1818 self.GetCurrentElementEditing().addInstance("coil", coil) |
1626 elif param == "connectors": |
1819 |
1627 input_connector = value["input"] |
1820 def SetCurrentElementEditingCoilInfos(self, id, infos): |
|
1821 coil = self.GetCurrentElementEditing().getInstance(id) |
|
1822 for param, value in infos.items(): |
|
1823 if param == "name": |
|
1824 coil.setVariable(value) |
|
1825 elif param == "type": |
|
1826 if value == COIL_NORMAL: |
|
1827 coil.setNegated(False) |
|
1828 coil.setCoilStorage("none") |
|
1829 elif value == COIL_REVERSE: |
|
1830 coil.setNegated(True) |
|
1831 coil.setCoilStorage("none") |
|
1832 elif value == COIL_SET: |
|
1833 coil.setNegated(False) |
|
1834 coil.setCoilStorage("set") |
|
1835 elif value == COIL_RESET: |
|
1836 coil.setNegated(False) |
|
1837 coil.setCoilStorage("reset") |
|
1838 elif param == "height": |
|
1839 coil.setHeight(value) |
|
1840 elif param == "width": |
|
1841 coil.setWidth(value) |
|
1842 elif param == "x": |
|
1843 coil.setX(value) |
|
1844 elif param == "y": |
|
1845 coil.setY(value) |
|
1846 elif param == "connectors": |
|
1847 input_connector = value["input"] |
|
1848 position = input_connector.GetRelPosition() |
|
1849 coil.addConnectionPointIn() |
|
1850 coil.connectionPointIn.setRelPosition(position.x, position.y) |
|
1851 self.SetConnectionWires(coil.connectionPointIn, input_connector) |
|
1852 output_connector = value["output"] |
|
1853 position = output_connector.GetRelPosition() |
|
1854 coil.addConnectionPointOut() |
|
1855 coil.connectionPointOut.setRelPosition(position.x, position.y) |
|
1856 |
|
1857 def AddCurrentElementEditingStep(self, id): |
|
1858 step = plcopen.step() |
|
1859 step.setLocalId(id) |
|
1860 self.GetCurrentElementEditing().addInstance("step", step) |
|
1861 |
|
1862 def SetCurrentElementEditingStepInfos(self, id, infos): |
|
1863 step = self.GetCurrentElementEditing().getInstance(id) |
|
1864 for param, value in infos.items(): |
|
1865 if param == "name": |
|
1866 step.setName(value) |
|
1867 elif param == "initial": |
|
1868 step.setInitialStep(value) |
|
1869 elif param == "height": |
|
1870 step.setHeight(value) |
|
1871 elif param == "width": |
|
1872 step.setWidth(value) |
|
1873 elif param == "x": |
|
1874 step.setX(value) |
|
1875 elif param == "y": |
|
1876 step.setY(value) |
|
1877 elif param == "connectors": |
|
1878 input_connector = value["input"] |
|
1879 if input_connector: |
|
1880 position = input_connector.GetRelPosition() |
1628 position = input_connector.GetRelPosition() |
1881 step.addConnectionPointIn() |
1629 contact.addConnectionPointIn() |
1882 step.connectionPointIn.setRelPosition(position.x, position.y) |
1630 contact.connectionPointIn.setRelPosition(position.x, position.y) |
1883 self.SetConnectionWires(step.connectionPointIn, input_connector) |
1631 self.SetConnectionWires(contact.connectionPointIn, input_connector) |
1884 else: |
1632 output_connector = value["output"] |
1885 step.deleteConnectionPointIn() |
|
1886 output_connector = value["output"] |
|
1887 if output_connector: |
|
1888 position = output_connector.GetRelPosition() |
1633 position = output_connector.GetRelPosition() |
1889 step.addConnectionPointOut() |
1634 contact.addConnectionPointOut() |
1890 step.connectionPointOut.setRelPosition(position.x, position.y) |
1635 contact.connectionPointOut.setRelPosition(position.x, position.y) |
1891 else: |
1636 |
1892 step.deleteConnectionPointOut() |
1637 def AddEditedElementCoil(self, tagname, id): |
1893 action_connector = value["action"] |
1638 element = self.GetEditedElement(tagname) |
1894 if action_connector: |
1639 if element is not None: |
1895 position = action_connector.GetRelPosition() |
1640 coil = plcopen.coil() |
1896 step.addConnectionPointOutAction() |
1641 coil.setLocalId(id) |
1897 step.connectionPointOutAction.setRelPosition(position.x, position.y) |
1642 element.addInstance("coil", coil) |
1898 else: |
1643 |
1899 step.deleteConnectionPointOutAction() |
1644 def SetEditedElementCoilInfos(self, tagname, id, infos): |
1900 |
1645 element = self.GetEditedElement(tagname) |
1901 def AddCurrentElementEditingTransition(self, id): |
1646 if element is not None: |
1902 transition = plcopen.transition() |
1647 coil = element.getInstance(id) |
1903 transition.setLocalId(id) |
1648 for param, value in infos.items(): |
1904 self.GetCurrentElementEditing().addInstance("transition", transition) |
1649 if param == "name": |
1905 |
1650 coil.setVariable(value) |
1906 def SetCurrentElementEditingTransitionInfos(self, id, infos): |
1651 elif param == "type": |
1907 transition = self.GetCurrentElementEditing().getInstance(id) |
1652 if value == COIL_NORMAL: |
1908 for param, value in infos.items(): |
1653 coil.setNegated(False) |
1909 if param == "type" and value != "connection": |
1654 coil.setCoilStorage("none") |
1910 transition.setConditionContent(value, infos["condition"]) |
1655 elif value == COIL_REVERSE: |
1911 elif param == "height": |
1656 coil.setNegated(True) |
1912 transition.setHeight(value) |
1657 coil.setCoilStorage("none") |
1913 elif param == "width": |
1658 elif value == COIL_SET: |
1914 transition.setWidth(value) |
1659 coil.setNegated(False) |
1915 elif param == "x": |
1660 coil.setCoilStorage("set") |
1916 transition.setX(value) |
1661 elif value == COIL_RESET: |
1917 elif param == "y": |
1662 coil.setNegated(False) |
1918 transition.setY(value) |
1663 coil.setCoilStorage("reset") |
1919 elif param == "priority": |
1664 elif param == "height": |
1920 if value != 0: |
1665 coil.setHeight(value) |
1921 transition.setPriority(value) |
1666 elif param == "width": |
1922 else: |
1667 coil.setWidth(value) |
1923 transition.setPriority(None) |
1668 elif param == "x": |
1924 elif param == "connectors": |
1669 coil.setX(value) |
1925 input_connector = value["input"] |
1670 elif param == "y": |
1926 position = input_connector.GetRelPosition() |
1671 coil.setY(value) |
1927 transition.addConnectionPointIn() |
1672 elif param == "connectors": |
1928 transition.connectionPointIn.setRelPosition(position.x, position.y) |
1673 input_connector = value["input"] |
1929 self.SetConnectionWires(transition.connectionPointIn, input_connector) |
1674 position = input_connector.GetRelPosition() |
1930 output_connector = value["output"] |
1675 coil.addConnectionPointIn() |
1931 position = output_connector.GetRelPosition() |
1676 coil.connectionPointIn.setRelPosition(position.x, position.y) |
1932 transition.addConnectionPointOut() |
1677 self.SetConnectionWires(coil.connectionPointIn, input_connector) |
1933 transition.connectionPointOut.setRelPosition(position.x, position.y) |
1678 output_connector = value["output"] |
1934 if infos.get("type", None) == "connection": |
1679 position = output_connector.GetRelPosition() |
1935 transition.setConditionContent("connection", None) |
1680 coil.addConnectionPointOut() |
1936 connection_connector = value["connection"] |
1681 coil.connectionPointOut.setRelPosition(position.x, position.y) |
1937 self.SetConnectionWires(transition, connection_connector) |
1682 |
1938 |
1683 def AddEditedElementStep(self, tagname, id): |
1939 def AddCurrentElementEditingDivergence(self, id, type): |
1684 element = self.GetEditedElement(tagname) |
1940 if type == SELECTION_DIVERGENCE: |
1685 if element is not None: |
1941 name = "selectionDivergence" |
1686 step = plcopen.step() |
1942 divergence = plcopen.selectionDivergence() |
1687 step.setLocalId(id) |
1943 elif type == SELECTION_CONVERGENCE: |
1688 element.addInstance("step", step) |
1944 name = "selectionConvergence" |
1689 |
1945 divergence = plcopen.selectionConvergence() |
1690 def SetEditedElementStepInfos(self, tagname, id, infos): |
1946 elif type == SIMULTANEOUS_DIVERGENCE: |
1691 element = self.GetEditedElement(tagname) |
1947 name = "simultaneousDivergence" |
1692 if element is not None: |
1948 divergence = plcopen.simultaneousDivergence() |
1693 step = element.getInstance(id) |
1949 elif type == SIMULTANEOUS_CONVERGENCE: |
1694 for param, value in infos.items(): |
1950 name = "simultaneousConvergence" |
1695 if param == "name": |
1951 divergence = plcopen.simultaneousConvergence() |
1696 step.setName(value) |
1952 divergence.setLocalId(id) |
1697 elif param == "initial": |
1953 self.GetCurrentElementEditing().addInstance(name, divergence) |
1698 step.setInitialStep(value) |
1954 |
1699 elif param == "height": |
1955 def SetCurrentElementEditingDivergenceInfos(self, id, infos): |
1700 step.setHeight(value) |
1956 divergence = self.GetCurrentElementEditing().getInstance(id) |
1701 elif param == "width": |
1957 for param, value in infos.items(): |
1702 step.setWidth(value) |
1958 if param == "height": |
1703 elif param == "x": |
1959 divergence.setHeight(value) |
1704 step.setX(value) |
1960 elif param == "width": |
1705 elif param == "y": |
1961 divergence.setWidth(value) |
1706 step.setY(value) |
1962 elif param == "x": |
1707 elif param == "connectors": |
1963 divergence.setX(value) |
1708 input_connector = value["input"] |
1964 elif param == "y": |
1709 if input_connector: |
1965 divergence.setY(value) |
|
1966 elif param == "connectors": |
|
1967 input_connectors = value["inputs"] |
|
1968 if isinstance(divergence, (plcopen.selectionDivergence, plcopen.simultaneousDivergence)): |
|
1969 position = input_connectors[0].GetRelPosition() |
|
1970 divergence.addConnectionPointIn() |
|
1971 divergence.connectionPointIn.setRelPosition(position.x, position.y) |
|
1972 self.SetConnectionWires(divergence.connectionPointIn, input_connectors[0]) |
|
1973 else: |
|
1974 divergence.setConnectionPointIn([]) |
|
1975 for input_connector in input_connectors: |
|
1976 position = input_connector.GetRelPosition() |
1710 position = input_connector.GetRelPosition() |
1977 if isinstance(divergence, plcopen.selectionConvergence): |
1711 step.addConnectionPointIn() |
1978 connection = plcopen.selectionConvergence_connectionPointIn() |
1712 step.connectionPointIn.setRelPosition(position.x, position.y) |
1979 else: |
1713 self.SetConnectionWires(step.connectionPointIn, input_connector) |
1980 connection = plcopen.connectionPointIn() |
1714 else: |
1981 connection.setRelPosition(position.x, position.y) |
1715 step.deleteConnectionPointIn() |
1982 self.SetConnectionWires(connection, input_connector) |
1716 output_connector = value["output"] |
1983 divergence.appendConnectionPointIn(connection) |
1717 if output_connector: |
1984 output_connectors = value["outputs"] |
|
1985 if isinstance(divergence, (plcopen.selectionConvergence, plcopen.simultaneousConvergence)): |
|
1986 position = output_connectors[0].GetRelPosition() |
|
1987 divergence.addConnectionPointOut() |
|
1988 divergence.connectionPointOut.setRelPosition(position.x, position.y) |
|
1989 else: |
|
1990 divergence.setConnectionPointOut([]) |
|
1991 for output_connector in output_connectors: |
|
1992 position = output_connector.GetRelPosition() |
1718 position = output_connector.GetRelPosition() |
1993 if isinstance(divergence, plcopen.selectionDivergence): |
1719 step.addConnectionPointOut() |
1994 connection = plcopen.selectionDivergence_connectionPointOut() |
1720 step.connectionPointOut.setRelPosition(position.x, position.y) |
1995 else: |
1721 else: |
1996 connection = plcopen.simultaneousDivergence_connectionPointOut() |
1722 step.deleteConnectionPointOut() |
1997 connection.setRelPosition(position.x, position.y) |
1723 action_connector = value["action"] |
1998 divergence.appendConnectionPointOut(connection) |
1724 if action_connector: |
1999 |
1725 position = action_connector.GetRelPosition() |
2000 def AddCurrentElementEditingJump(self, id): |
1726 step.addConnectionPointOutAction() |
2001 jump = plcopen.jumpStep() |
1727 step.connectionPointOutAction.setRelPosition(position.x, position.y) |
2002 jump.setLocalId(id) |
1728 else: |
2003 self.GetCurrentElementEditing().addInstance("jumpStep", jump) |
1729 step.deleteConnectionPointOutAction() |
2004 |
1730 |
2005 def SetCurrentElementEditingJumpInfos(self, id, infos): |
1731 def AddEditedElementTransition(self, tagname, id): |
2006 jump = self.GetCurrentElementEditing().getInstance(id) |
1732 element = self.GetEditedElement(tagname) |
2007 for param, value in infos.items(): |
1733 if element is not None: |
2008 if param == "target": |
1734 transition = plcopen.transition() |
2009 jump.setTargetName(value) |
1735 transition.setLocalId(id) |
2010 elif param == "height": |
1736 element.addInstance("transition", transition) |
2011 jump.setHeight(value) |
1737 |
2012 elif param == "width": |
1738 def SetEditedElementTransitionInfos(self, tagname, id, infos): |
2013 jump.setWidth(value) |
1739 element = self.GetEditedElement(tagname) |
2014 elif param == "x": |
1740 if element is not None: |
2015 jump.setX(value) |
1741 transition = element.getInstance(id) |
2016 elif param == "y": |
1742 for param, value in infos.items(): |
2017 jump.setY(value) |
1743 if param == "type" and value != "connection": |
2018 elif param == "connector": |
1744 transition.setConditionContent(value, infos["condition"]) |
2019 position = value.GetRelPosition() |
1745 elif param == "height": |
2020 jump.addConnectionPointIn() |
1746 transition.setHeight(value) |
2021 jump.connectionPointIn.setRelPosition(position.x, position.y) |
1747 elif param == "width": |
2022 self.SetConnectionWires(jump.connectionPointIn, value) |
1748 transition.setWidth(value) |
|
1749 elif param == "x": |
|
1750 transition.setX(value) |
|
1751 elif param == "y": |
|
1752 transition.setY(value) |
|
1753 elif param == "priority": |
|
1754 if value != 0: |
|
1755 transition.setPriority(value) |
|
1756 else: |
|
1757 transition.setPriority(None) |
|
1758 elif param == "connectors": |
|
1759 input_connector = value["input"] |
|
1760 position = input_connector.GetRelPosition() |
|
1761 transition.addConnectionPointIn() |
|
1762 transition.connectionPointIn.setRelPosition(position.x, position.y) |
|
1763 self.SetConnectionWires(transition.connectionPointIn, input_connector) |
|
1764 output_connector = value["output"] |
|
1765 position = output_connector.GetRelPosition() |
|
1766 transition.addConnectionPointOut() |
|
1767 transition.connectionPointOut.setRelPosition(position.x, position.y) |
|
1768 if infos.get("type", None) == "connection": |
|
1769 transition.setConditionContent("connection", None) |
|
1770 connection_connector = value["connection"] |
|
1771 self.SetConnectionWires(transition, connection_connector) |
|
1772 |
|
1773 def AddEditedElementDivergence(self, tagname, id, type): |
|
1774 element = self.GetEditedElement(tagname) |
|
1775 if element is not None: |
|
1776 if type == SELECTION_DIVERGENCE: |
|
1777 name = "selectionDivergence" |
|
1778 divergence = plcopen.selectionDivergence() |
|
1779 elif type == SELECTION_CONVERGENCE: |
|
1780 name = "selectionConvergence" |
|
1781 divergence = plcopen.selectionConvergence() |
|
1782 elif type == SIMULTANEOUS_DIVERGENCE: |
|
1783 name = "simultaneousDivergence" |
|
1784 divergence = plcopen.simultaneousDivergence() |
|
1785 elif type == SIMULTANEOUS_CONVERGENCE: |
|
1786 name = "simultaneousConvergence" |
|
1787 divergence = plcopen.simultaneousConvergence() |
|
1788 divergence.setLocalId(id) |
|
1789 element.addInstance(name, divergence) |
|
1790 |
|
1791 def SetEditedElementDivergenceInfos(self, tagname, id, infos): |
|
1792 element = self.GetEditedElement(tagname) |
|
1793 if element is not None: |
|
1794 divergence = element.getInstance(id) |
|
1795 for param, value in infos.items(): |
|
1796 if param == "height": |
|
1797 divergence.setHeight(value) |
|
1798 elif param == "width": |
|
1799 divergence.setWidth(value) |
|
1800 elif param == "x": |
|
1801 divergence.setX(value) |
|
1802 elif param == "y": |
|
1803 divergence.setY(value) |
|
1804 elif param == "connectors": |
|
1805 input_connectors = value["inputs"] |
|
1806 if isinstance(divergence, (plcopen.selectionDivergence, plcopen.simultaneousDivergence)): |
|
1807 position = input_connectors[0].GetRelPosition() |
|
1808 divergence.addConnectionPointIn() |
|
1809 divergence.connectionPointIn.setRelPosition(position.x, position.y) |
|
1810 self.SetConnectionWires(divergence.connectionPointIn, input_connectors[0]) |
|
1811 else: |
|
1812 divergence.setConnectionPointIn([]) |
|
1813 for input_connector in input_connectors: |
|
1814 position = input_connector.GetRelPosition() |
|
1815 if isinstance(divergence, plcopen.selectionConvergence): |
|
1816 connection = plcopen.selectionConvergence_connectionPointIn() |
|
1817 else: |
|
1818 connection = plcopen.connectionPointIn() |
|
1819 connection.setRelPosition(position.x, position.y) |
|
1820 self.SetConnectionWires(connection, input_connector) |
|
1821 divergence.appendConnectionPointIn(connection) |
|
1822 output_connectors = value["outputs"] |
|
1823 if isinstance(divergence, (plcopen.selectionConvergence, plcopen.simultaneousConvergence)): |
|
1824 position = output_connectors[0].GetRelPosition() |
|
1825 divergence.addConnectionPointOut() |
|
1826 divergence.connectionPointOut.setRelPosition(position.x, position.y) |
|
1827 else: |
|
1828 divergence.setConnectionPointOut([]) |
|
1829 for output_connector in output_connectors: |
|
1830 position = output_connector.GetRelPosition() |
|
1831 if isinstance(divergence, plcopen.selectionDivergence): |
|
1832 connection = plcopen.selectionDivergence_connectionPointOut() |
|
1833 else: |
|
1834 connection = plcopen.simultaneousDivergence_connectionPointOut() |
|
1835 connection.setRelPosition(position.x, position.y) |
|
1836 divergence.appendConnectionPointOut(connection) |
|
1837 |
|
1838 def AddEditedElementJump(self, tagname, id): |
|
1839 element = self.GetEditedElement(tagname) |
|
1840 if element is not None: |
|
1841 jump = plcopen.jumpStep() |
|
1842 jump.setLocalId(id) |
|
1843 element.addInstance("jumpStep", jump) |
|
1844 |
|
1845 def SetEditedElementJumpInfos(self, tagname, id, infos): |
|
1846 element = self.GetEditedElement(tagname) |
|
1847 if element is not None: |
|
1848 jump = element.getInstance(id) |
|
1849 for param, value in infos.items(): |
|
1850 if param == "target": |
|
1851 jump.setTargetName(value) |
|
1852 elif param == "height": |
|
1853 jump.setHeight(value) |
|
1854 elif param == "width": |
|
1855 jump.setWidth(value) |
|
1856 elif param == "x": |
|
1857 jump.setX(value) |
|
1858 elif param == "y": |
|
1859 jump.setY(value) |
|
1860 elif param == "connector": |
|
1861 position = value.GetRelPosition() |
|
1862 jump.addConnectionPointIn() |
|
1863 jump.connectionPointIn.setRelPosition(position.x, position.y) |
|
1864 self.SetConnectionWires(jump.connectionPointIn, value) |
2023 |
1865 |
2024 def AddCurrentElementEditingActionBlock(self, id): |
1866 def AddEditedElementActionBlock(self, tagname, id): |
2025 actionBlock = plcopen.actionBlock() |
1867 element = self.GetEditedElement(tagname) |
2026 actionBlock.setLocalId(id) |
1868 if element is not None: |
2027 self.GetCurrentElementEditing().addInstance("actionBlock", actionBlock) |
1869 actionBlock = plcopen.actionBlock() |
2028 |
1870 actionBlock.setLocalId(id) |
2029 def SetCurrentElementEditingActionBlockInfos(self, id, infos): |
1871 element.addInstance("actionBlock", actionBlock) |
2030 actionBlock = self.GetCurrentElementEditing().getInstance(id) |
1872 |
2031 for param, value in infos.items(): |
1873 def SetEditedElementActionBlockInfos(self, tagname, id, infos): |
2032 if param == "actions": |
1874 element = self.GetEditedElement(tagname) |
2033 actionBlock.setActions(value) |
1875 if element is not None: |
2034 elif param == "height": |
1876 actionBlock = element.getInstance(id) |
2035 actionBlock.setHeight(value) |
1877 for param, value in infos.items(): |
2036 elif param == "width": |
1878 if param == "actions": |
2037 actionBlock.setWidth(value) |
1879 actionBlock.setActions(value) |
2038 elif param == "x": |
1880 elif param == "height": |
2039 actionBlock.setX(value) |
1881 actionBlock.setHeight(value) |
2040 elif param == "y": |
1882 elif param == "width": |
2041 actionBlock.setY(value) |
1883 actionBlock.setWidth(value) |
2042 elif param == "connector": |
1884 elif param == "x": |
2043 position = value.GetRelPosition() |
1885 actionBlock.setX(value) |
2044 actionBlock.addConnectionPointIn() |
1886 elif param == "y": |
2045 actionBlock.connectionPointIn.setRelPosition(position.x, position.y) |
1887 actionBlock.setY(value) |
2046 self.SetConnectionWires(actionBlock.connectionPointIn, value) |
1888 elif param == "connector": |
2047 |
1889 position = value.GetRelPosition() |
2048 def RemoveCurrentElementEditingInstance(self, id): |
1890 actionBlock.addConnectionPointIn() |
2049 element = self.GetCurrentElementEditing() |
1891 actionBlock.connectionPointIn.setRelPosition(position.x, position.y) |
2050 instance = element.getInstance(id) |
1892 self.SetConnectionWires(actionBlock.connectionPointIn, value) |
2051 if isinstance(instance, plcopen.block): |
1893 |
2052 blocktype = instance.getTypeName() |
1894 def RemoveEditedElementInstance(self, tagname, id): |
2053 if self.CurrentElementEditing != None: |
1895 element = self.GetEditedElement(tagname) |
2054 name = self.ElementsOpened[self.CurrentElementEditing] |
1896 if element is not None: |
2055 words = name.split("::") |
1897 instance = element.getInstance(id) |
2056 if words[0] in ["P","T","A"]: |
1898 if isinstance(instance, plcopen.block): |
2057 pou = self.Project.getPou(words[1]) |
1899 blocktype = instance.getTypeName() |
2058 pou.removePouVar(blocktype, instance.getInstanceName()) |
1900 element.removePouVar(blocktype, instance.getInstanceName()) |
2059 element.removeInstance(id) |
1901 element.removeInstance(id) |
2060 self.RefreshPouUsingTree() |
1902 self.RefreshPouUsingTree() |
2061 |
1903 |
2062 def GetCurrentResourceEditingVariables(self): |
1904 def GetEditedResourceVariables(self, tagname): |
2063 varlist = [] |
1905 varlist = [] |
2064 name = self.ElementsOpened[self.CurrentElementEditing] |
1906 words = tagname.split("::") |
2065 words = name.split("::") |
|
2066 for var in self.GetConfigurationGlobalVars(words[1]): |
1907 for var in self.GetConfigurationGlobalVars(words[1]): |
2067 if var["Type"] == "BOOL": |
1908 if var["Type"] == "BOOL": |
2068 varlist.append(var["Name"]) |
1909 varlist.append(var["Name"]) |
2069 for var in self.GetConfigurationResourceGlobalVars(words[1], words[2]): |
1910 for var in self.GetConfigurationResourceGlobalVars(words[1], words[2]): |
2070 if var["Type"] == "BOOL": |
1911 if var["Type"] == "BOOL": |
2071 varlist.append(var["Name"]) |
1912 varlist.append(var["Name"]) |
2072 return varlist |
1913 return varlist |
2073 |
1914 |
2074 def SetCurrentResourceEditingInfos(self, tasks, instances): |
1915 def SetEditedResourceInfos(self, tasks, instances): |
2075 resource = self.GetCurrentElementEditing() |
1916 resource = self.GetEditedElement(tagname) |
2076 resource.setTask([]) |
1917 if resource is not None: |
2077 resource.setPouInstance([]) |
1918 resource.setTask([]) |
2078 task_list = {} |
1919 resource.setPouInstance([]) |
2079 for task in tasks: |
1920 task_list = {} |
2080 new_task = plcopen.resource_task() |
1921 for task in tasks: |
2081 new_task.setName(task["Name"]) |
1922 new_task = plcopen.resource_task() |
2082 if task["Single"] != "": |
1923 new_task.setName(task["Name"]) |
2083 new_task.setSingle(task["Single"]) |
1924 if task["Single"] != "": |
2084 result = duration_model.match(task["Interval"]).groups() |
1925 new_task.setSingle(task["Single"]) |
2085 if reduce(lambda x, y: x or y != None, result): |
1926 result = duration_model.match(task["Interval"]).groups() |
2086 values = [] |
1927 if reduce(lambda x, y: x or y != None, result): |
2087 for value in result[:-1]: |
1928 values = [] |
2088 if value != None: |
1929 for value in result[:-1]: |
2089 values.append(int(value)) |
1930 if value != None: |
2090 else: |
1931 values.append(int(value)) |
2091 values.append(0) |
1932 else: |
2092 values.append(int(float(result[-1]) * 1000)) |
1933 values.append(0) |
2093 new_task.setInterval(time(*values)) |
1934 values.append(int(float(result[-1]) * 1000)) |
2094 new_task.priority.setValue(int(task["Priority"])) |
1935 new_task.setInterval(time(*values)) |
2095 if task["Name"] != "": |
1936 new_task.priority.setValue(int(task["Priority"])) |
2096 task_list[task["Name"]] = new_task |
1937 if task["Name"] != "": |
2097 resource.appendTask(new_task) |
1938 task_list[task["Name"]] = new_task |
2098 for instance in instances: |
1939 resource.appendTask(new_task) |
2099 new_instance = plcopen.pouInstance() |
1940 for instance in instances: |
2100 new_instance.setName(instance["Name"]) |
1941 new_instance = plcopen.pouInstance() |
2101 new_instance.setType(instance["Type"]) |
1942 new_instance.setName(instance["Name"]) |
2102 if instance["Task"] != "": |
1943 new_instance.setType(instance["Type"]) |
2103 task_list[instance["Task"]].appendPouInstance(new_instance) |
1944 if instance["Task"] != "": |
2104 else: |
1945 task_list[instance["Task"]].appendPouInstance(new_instance) |
2105 resource.appendPouInstance(new_instance) |
1946 else: |
2106 |
1947 resource.appendPouInstance(new_instance) |
2107 def GetCurrentResourceEditingInfos(self): |
1948 |
2108 resource = self.GetCurrentElementEditing() |
1949 def GetEditedResourceInfos(self, tagname): |
2109 tasks = resource.getTask() |
1950 resource = self.GetEditedElement(tagname) |
2110 instances = resource.getPouInstance() |
1951 if resource is not None: |
2111 tasks_data = [] |
1952 tasks = resource.getTask() |
2112 instances_data = [] |
1953 instances = resource.getPouInstance() |
2113 for task in tasks: |
1954 tasks_data = [] |
2114 new_task = {} |
1955 instances_data = [] |
2115 new_task["Name"] = task.getName() |
1956 for task in tasks: |
2116 single = task.getSingle() |
1957 new_task = {} |
2117 if single: |
1958 new_task["Name"] = task.getName() |
2118 new_task["Single"] = single |
1959 single = task.getSingle() |
2119 else: |
1960 if single: |
2120 new_task["Single"] = "" |
1961 new_task["Single"] = single |
2121 interval = task.getInterval() |
1962 else: |
2122 if interval: |
1963 new_task["Single"] = "" |
2123 text = "" |
1964 interval = task.getInterval() |
2124 if interval.hour != 0: |
1965 if interval: |
2125 text += "%dh"%interval.hour |
1966 text = "" |
2126 if interval.minute != 0: |
1967 if interval.hour != 0: |
2127 text += "%dm"%interval.minute |
1968 text += "%dh"%interval.hour |
2128 if interval.second != 0: |
1969 if interval.minute != 0: |
2129 text += "%ds"%interval.second |
1970 text += "%dm"%interval.minute |
2130 if interval.microsecond != 0: |
1971 if interval.second != 0: |
2131 if interval.microsecond % 1000 != 0: |
1972 text += "%ds"%interval.second |
2132 text += "%.3fms"%(float(interval.microsecond) / 1000) |
1973 if interval.microsecond != 0: |
2133 else: |
1974 if interval.microsecond % 1000 != 0: |
2134 text += "%dms"%(interval.microsecond / 1000) |
1975 text += "%.3fms"%(float(interval.microsecond) / 1000) |
2135 new_task["Interval"] = text |
1976 else: |
2136 else: |
1977 text += "%dms"%(interval.microsecond / 1000) |
2137 new_task["Interval"] = "" |
1978 new_task["Interval"] = text |
2138 new_task["Priority"] = str(task.priority.getValue()) |
1979 else: |
2139 tasks_data.append(new_task) |
1980 new_task["Interval"] = "" |
2140 for instance in task.getPouInstance(): |
1981 new_task["Priority"] = str(task.priority.getValue()) |
|
1982 tasks_data.append(new_task) |
|
1983 for instance in task.getPouInstance(): |
|
1984 new_instance = {} |
|
1985 new_instance["Name"] = instance.getName() |
|
1986 new_instance["Type"] = instance.getType() |
|
1987 new_instance["Task"] = task.getName() |
|
1988 instances_data.append(new_instance) |
|
1989 for instance in instances: |
2141 new_instance = {} |
1990 new_instance = {} |
2142 new_instance["Name"] = instance.getName() |
1991 new_instance["Name"] = instance.getName() |
2143 new_instance["Type"] = instance.getType() |
1992 new_instance["Type"] = instance.getType() |
2144 new_instance["Task"] = task.getName() |
1993 new_instance["Task"] = "" |
2145 instances_data.append(new_instance) |
1994 instances_data.append(new_instance) |
2146 for instance in instances: |
1995 return tasks_data, instances_data |
2147 new_instance = {} |
|
2148 new_instance["Name"] = instance.getName() |
|
2149 new_instance["Type"] = instance.getType() |
|
2150 new_instance["Task"] = "" |
|
2151 instances_data.append(new_instance) |
|
2152 return tasks_data, instances_data |
|
2153 |
1996 |
2154 def OpenXMLFile(self, filepath): |
1997 def OpenXMLFile(self, filepath): |
2155 if self.VerifyXML: |
1998 if self.VerifyXML: |
2156 if sys: |
1999 if sys: |
2157 sys.stdout = HolePseudoFile() |
2000 sys.stdout = HolePseudoFile() |