773 connector = None |
773 connector = None |
774 var_type = "ANY" |
774 var_type = "ANY" |
775 for element in body.getcontentInstances(): |
775 for element in body.getcontentInstances(): |
776 if isinstance(element, ConnectorClass) and element.getname() == name: |
776 if isinstance(element, ConnectorClass) and element.getname() == name: |
777 if connector is not None: |
777 if connector is not None: |
778 raise PLCGenException, _("More than one connector found corresponding to \"%s\" continuation in \"%s\" POU")%(name, self.Name) |
778 msg = _("More than one connector found corresponding to \"{a1}\" continuation in \"{a2}\" POU").format(a1 = name, a2 = self.Name) |
|
779 raise PLCGenException, msg |
779 connector = element |
780 connector = element |
780 if connector is not None: |
781 if connector is not None: |
781 undefined = [instance.connectionPointOut, connector.connectionPointIn] |
782 undefined = [instance.connectionPointOut, connector.connectionPointIn] |
782 connected = self.GetConnectedConnector(connector.connectionPointIn, body) |
783 connected = self.GetConnectedConnector(connector.connectionPointIn, body) |
783 if connected is not None: |
784 if connected is not None: |
792 self.RelatedConnections.append(related) |
793 self.RelatedConnections.append(related) |
793 else: |
794 else: |
794 for connection in related: |
795 for connection in related: |
795 self.ConnectionTypes[connection] = var_type |
796 self.ConnectionTypes[connection] = var_type |
796 else: |
797 else: |
797 raise PLCGenException, _("No connector found corresponding to \"%s\" continuation in \"%s\" POU")%(name, self.Name) |
798 msg = _("No connector found corresponding to \"{a1}\" continuation in \"{a2}\" POU").format(a1 = name, a2 = self.Name) |
|
799 raise PLCGenException, msg |
798 elif isinstance(instance, BlockClass): |
800 elif isinstance(instance, BlockClass): |
799 block_infos = self.GetBlockType(instance.gettypeName(), "undefined") |
801 block_infos = self.GetBlockType(instance.gettypeName(), "undefined") |
800 if block_infos is not None: |
802 if block_infos is not None: |
801 self.ComputeBlockInputTypes(instance, block_infos, body) |
803 self.ComputeBlockInputTypes(instance, block_infos, body) |
802 else: |
804 else: |
946 self.ParentGenerator.GeneratePouProgram(block_type) |
948 self.ParentGenerator.GeneratePouProgram(block_type) |
947 block_infos = self.GetBlockType(block_type, tuple([self.ConnectionTypes.get(variable.connectionPointIn, "ANY") for variable in instance.inputVariables.getvariable() if variable.getformalParameter() != "EN"])) |
949 block_infos = self.GetBlockType(block_type, tuple([self.ConnectionTypes.get(variable.connectionPointIn, "ANY") for variable in instance.inputVariables.getvariable() if variable.getformalParameter() != "EN"])) |
948 if block_infos is None: |
950 if block_infos is None: |
949 block_infos = self.GetBlockType(block_type) |
951 block_infos = self.GetBlockType(block_type) |
950 if block_infos is None: |
952 if block_infos is None: |
951 raise PLCGenException, _("Undefined block type \"%s\" in \"%s\" POU")%(block_type, self.Name) |
953 raise PLCGenException, _("Undefined block type \"{a1}\" in \"{a2}\" POU").format(a1 = block_type, a2 = self.Name) |
952 try: |
954 try: |
953 self.GenerateBlock(instance, block_infos, body, None) |
955 self.GenerateBlock(instance, block_infos, body, None) |
954 except ValueError, e: |
956 except ValueError, e: |
955 raise PLCGenException, e.message |
957 raise PLCGenException, e.message |
956 elif isinstance(instance, ConnectorClass): |
958 elif isinstance(instance, ConnectorClass): |
1086 (type, (self.TagName, "block", block.getlocalId(), "type")), |
1088 (type, (self.TagName, "block", block.getlocalId(), "type")), |
1087 ("(", ())] |
1089 ("(", ())] |
1088 self.Program += JoinList([(", ", ())], vars) |
1090 self.Program += JoinList([(", ", ())], vars) |
1089 self.Program += [(");\n", ())] |
1091 self.Program += [(");\n", ())] |
1090 else: |
1092 else: |
1091 self.Warnings.append(_("\"%s\" function cancelled in \"%s\" POU: No input connected")%(type, self.TagName.split("::")[-1])) |
1093 msg = _("\"{a1}\" function cancelled in \"{a2}\" POU: No input connected").format(a1 = type, a2 = self.TagName.split("::")[-1]) |
|
1094 self.Warnings.append(msg) |
1092 elif block_infos["type"] == "functionBlock": |
1095 elif block_infos["type"] == "functionBlock": |
1093 if not self.ComputedBlocks.get(block, False) and not order: |
1096 if not self.ComputedBlocks.get(block, False) and not order: |
1094 self.ComputedBlocks[block] = True |
1097 self.ComputedBlocks[block] = True |
1095 vars = [] |
1098 vars = [] |
1096 offset_idx = 0 |
1099 offset_idx = 0 |
1175 return output_name |
1178 return output_name |
1176 if link is not None: |
1179 if link is not None: |
1177 if output_parameter is None: |
1180 if output_parameter is None: |
1178 output_parameter = "" |
1181 output_parameter = "" |
1179 if name: |
1182 if name: |
1180 blockname = "%s(%s)" % (name, type) |
1183 blockname = "{a1}({a2})".format(a1 = name, a2 = type) |
1181 else: |
1184 else: |
1182 blockname = type |
1185 blockname = type |
1183 raise ValueError, _("No output %s variable found in block %s in POU %s. Connection must be broken") % \ |
1186 msg = _("No output {a1} variable found in block {a2} in POU {a3}. Connection must be broken").\ |
1184 (output_parameter, blockname, self.Name) |
1187 format(a1 = output_parameter, a2 = blockname, a3 = self.Name) |
|
1188 raise ValueError, msg |
1185 |
1189 |
1186 def GeneratePaths(self, connections, body, order = False, to_inout = False): |
1190 def GeneratePaths(self, connections, body, order = False, to_inout = False): |
1187 paths = [] |
1191 paths = [] |
1188 for connection in connections: |
1192 for connection in connections: |
1189 localId = connection.getrefLocalId() |
1193 localId = connection.getrefLocalId() |
1197 self.ParentGenerator.GeneratePouProgram(block_type) |
1201 self.ParentGenerator.GeneratePouProgram(block_type) |
1198 block_infos = self.GetBlockType(block_type, tuple([self.ConnectionTypes.get(variable.connectionPointIn, "ANY") for variable in next.inputVariables.getvariable() if variable.getformalParameter() != "EN"])) |
1202 block_infos = self.GetBlockType(block_type, tuple([self.ConnectionTypes.get(variable.connectionPointIn, "ANY") for variable in next.inputVariables.getvariable() if variable.getformalParameter() != "EN"])) |
1199 if block_infos is None: |
1203 if block_infos is None: |
1200 block_infos = self.GetBlockType(block_type) |
1204 block_infos = self.GetBlockType(block_type) |
1201 if block_infos is None: |
1205 if block_infos is None: |
1202 raise PLCGenException, _("Undefined block type \"%s\" in \"%s\" POU")%(block_type, self.Name) |
1206 msg = _("Undefined block type \"{a1}\" in \"{a2}\" POU").format(a1 = block_type, a2 = self.Name) |
|
1207 raise PLCGenException, msg |
1203 try: |
1208 try: |
1204 paths.append(str(self.GenerateBlock(next, block_infos, body, connection, order, to_inout))) |
1209 paths.append(str(self.GenerateBlock(next, block_infos, body, connection, order, to_inout))) |
1205 except ValueError, e: |
1210 except ValueError, e: |
1206 raise PLCGenException, e.message |
1211 raise PLCGenException, e.message |
1207 elif isinstance(next, ContinuationClass): |
1212 elif isinstance(next, ContinuationClass): |
1212 else: |
1217 else: |
1213 connector = None |
1218 connector = None |
1214 for instance in body.getcontentInstances(): |
1219 for instance in body.getcontentInstances(): |
1215 if isinstance(instance, ConnectorClass) and instance.getname() == name: |
1220 if isinstance(instance, ConnectorClass) and instance.getname() == name: |
1216 if connector is not None: |
1221 if connector is not None: |
1217 raise PLCGenException, _("More than one connector found corresponding to \"%s\" continuation in \"%s\" POU")%(name, self.Name) |
1222 msg = _("More than one connector found corresponding to \"{a1}\" continuation in \"{a2}\" POU").format(a1 = name, a2 = self.Name) |
|
1223 raise PLCGenException, msg |
1218 connector = instance |
1224 connector = instance |
1219 if connector is not None: |
1225 if connector is not None: |
1220 connections = connector.connectionPointIn.getconnections() |
1226 connections = connector.connectionPointIn.getconnections() |
1221 if connections is not None: |
1227 if connections is not None: |
1222 expression = self.ComputeExpression(body, connections, order) |
1228 expression = self.ComputeExpression(body, connections, order) |
1223 if expression is not None: |
1229 if expression is not None: |
1224 self.ComputedConnectors[name] = expression |
1230 self.ComputedConnectors[name] = expression |
1225 paths.append(str(expression)) |
1231 paths.append(str(expression)) |
1226 else: |
1232 else: |
1227 raise PLCGenException, _("No connector found corresponding to \"%s\" continuation in \"%s\" POU")%(name, self.Name) |
1233 msg = _("No connector found corresponding to \"{a1}\" continuation in \"{a2}\" POU").format(a1 = name, a2 = self.Name) |
|
1234 raise PLCGenException, msg |
1228 elif isinstance(next, ContactClass): |
1235 elif isinstance(next, ContactClass): |
1229 contact_info = (self.TagName, "contact", next.getlocalId()) |
1236 contact_info = (self.TagName, "contact", next.getlocalId()) |
1230 variable = str(self.ExtractModifier(next, [(next.getvariable(), contact_info + ("reference",))], contact_info)) |
1237 variable = str(self.ExtractModifier(next, [(next.getvariable(), contact_info + ("reference",))], contact_info)) |
1231 result = self.GeneratePaths(next.connectionPointIn.getconnections(), body, order) |
1238 result = self.GeneratePaths(next.connectionPointIn.getconnections(), body, order) |
1232 if len(result) > 1: |
1239 if len(result) > 1: |
1574 self.Program += JoinList([(", ", ())], transition_infos["from"]) |
1581 self.Program += JoinList([(", ", ())], transition_infos["from"]) |
1575 self.Program += [(")", ())] |
1582 self.Program += [(")", ())] |
1576 elif len(transition_infos["from"]) == 1: |
1583 elif len(transition_infos["from"]) == 1: |
1577 self.Program += transition_infos["from"][0] |
1584 self.Program += transition_infos["from"][0] |
1578 else: |
1585 else: |
1579 raise PLCGenException, _("Transition with content \"%s\" not connected to a previous step in \"%s\" POU")%(transition_infos["content"], self.Name) |
1586 msg = _("Transition with content \"{a1}\" not connected to a previous step in \"{a2}\" POU").\ |
|
1587 format(a1 = transition_infos["content"], a2 = self.Name) |
|
1588 raise PLCGenException, msg |
1580 self.Program += [(" TO ", ())] |
1589 self.Program += [(" TO ", ())] |
1581 if len(transition_infos["to"]) > 1: |
1590 if len(transition_infos["to"]) > 1: |
1582 self.Program += [("(", ())] |
1591 self.Program += [("(", ())] |
1583 self.Program += JoinList([(", ", ())], transition_infos["to"]) |
1592 self.Program += JoinList([(", ", ())], transition_infos["to"]) |
1584 self.Program += [(")", ())] |
1593 self.Program += [(")", ())] |
1585 elif len(transition_infos["to"]) == 1: |
1594 elif len(transition_infos["to"]) == 1: |
1586 self.Program += transition_infos["to"][0] |
1595 self.Program += transition_infos["to"][0] |
1587 else: |
1596 else: |
1588 raise PLCGenException, _("Transition with content \"%s\" not connected to a next step in \"%s\" POU")%(transition_infos["content"], self.Name) |
1597 msg = _("Transition with content \"{a1}\" not connected to a next step in \"{a2}\" POU").\ |
|
1598 format(a1 = transition_infos["content"], a2 = self.Name) |
|
1599 raise PLCGenException, msg |
1589 self.Program += transition_infos["content"] |
1600 self.Program += transition_infos["content"] |
1590 self.Program += [("%sEND_TRANSITION\n\n"%self.CurrentIndent, ())] |
1601 self.Program += [("%sEND_TRANSITION\n\n"%self.CurrentIndent, ())] |
1591 for [(step_name, step_infos)] in transition_infos["to"]: |
1602 for [(step_name, step_infos)] in transition_infos["to"]: |
1592 self.ComputeSFCStep(step_name) |
1603 self.ComputeSFCStep(step_name) |
1593 |
1604 |