227 # Create a POU program generator |
227 # Create a POU program generator |
228 pou_program = PouProgramGenerator(self, pou.getname(), pouTypeNames[pou_type], self.Errors, self.Warnings) |
228 pou_program = PouProgramGenerator(self, pou.getname(), pouTypeNames[pou_type], self.Errors, self.Warnings) |
229 program = pou_program.GenerateProgram(pou) |
229 program = pou_program.GenerateProgram(pou) |
230 self.Program += program |
230 self.Program += program |
231 else: |
231 else: |
232 raise PLCGenException, "Undefined pou type \"%s\""%pou_type |
232 raise PLCGenException, _("Undefined pou type \"%s\"")%pou_type |
233 |
233 |
234 # Generate a POU defined and used in text |
234 # Generate a POU defined and used in text |
235 def GeneratePouProgramInText(self, text): |
235 def GeneratePouProgramInText(self, text): |
236 for pou_name in self.PouComputed.keys(): |
236 for pou_name in self.PouComputed.keys(): |
237 model = re.compile("(?:^|[^0-9^A-Z])%s(?:$|[^0-9^A-Z])"%pou_name.upper()) |
237 model = re.compile("(?:^|[^0-9^A-Z])%s(?:$|[^0-9^A-Z])"%pou_name.upper()) |
667 connector = None |
667 connector = None |
668 var_type = "ANY" |
668 var_type = "ANY" |
669 for element in body.getcontentInstances(): |
669 for element in body.getcontentInstances(): |
670 if isinstance(element, plcopen.commonObjects_connector) and element.getname() == name: |
670 if isinstance(element, plcopen.commonObjects_connector) and element.getname() == name: |
671 if connector is not None: |
671 if connector is not None: |
672 raise PLCGenException, "More than one connector found corresponding to \"%s\" continuation in \"%s\" POU"%(name, self.Name) |
672 raise PLCGenException, _("More than one connector found corresponding to \"%s\" continuation in \"%s\" POU")%(name, self.Name) |
673 connector = element |
673 connector = element |
674 if connector is not None: |
674 if connector is not None: |
675 undefined = [instance.connectionPointOut, connector.connectionPointIn] |
675 undefined = [instance.connectionPointOut, connector.connectionPointIn] |
676 connected = self.GetConnectedConnector(connector.connectionPointIn, body) |
676 connected = self.GetConnectedConnector(connector.connectionPointIn, body) |
677 if connected: |
677 if connected: |
686 self.RelatedConnections.append(related) |
686 self.RelatedConnections.append(related) |
687 else: |
687 else: |
688 for connection in related: |
688 for connection in related: |
689 self.ConnectionTypes[connection] = var_type |
689 self.ConnectionTypes[connection] = var_type |
690 else: |
690 else: |
691 raise PLCGenException, "No connector found corresponding to \"%s\" continuation in \"%s\" POU"%(name, self.Name) |
691 raise PLCGenException, _("No connector found corresponding to \"%s\" continuation in \"%s\" POU")%(name, self.Name) |
692 elif isinstance(instance, plcopen.fbdObjects_block): |
692 elif isinstance(instance, plcopen.fbdObjects_block): |
693 block_infos = self.GetBlockType(instance.gettypeName()) |
693 block_infos = self.GetBlockType(instance.gettypeName()) |
694 if block_infos is not None: |
694 if block_infos is not None: |
695 undefined = {} |
695 undefined = {} |
696 for variable in instance.outputVariables.getvariable(): |
696 for variable in instance.outputVariables.getvariable(): |
871 else: |
871 else: |
872 connector = None |
872 connector = None |
873 for instance in body.getcontentInstances(): |
873 for instance in body.getcontentInstances(): |
874 if isinstance(instance, plcopen.commonObjects_connector) and instance.getname() == name: |
874 if isinstance(instance, plcopen.commonObjects_connector) and instance.getname() == name: |
875 if connector is not None: |
875 if connector is not None: |
876 raise PLCGenException, "More than one connector found corresponding to \"%s\" continuation in \"%s\" POU"%(name, self.Name) |
876 raise PLCGenException, _("More than one connector found corresponding to \"%s\" continuation in \"%s\" POU")%(name, self.Name) |
877 connector = instance |
877 connector = instance |
878 if connector is not None: |
878 if connector is not None: |
879 connections = connector.connectionPointIn.getconnections() |
879 connections = connector.connectionPointIn.getconnections() |
880 if connections is not None: |
880 if connections is not None: |
881 expression = self.ComputeExpression(body, connections, order) |
881 expression = self.ComputeExpression(body, connections, order) |
882 self.ComputedConnectors[name] = expression |
882 self.ComputedConnectors[name] = expression |
883 paths.append(str(expression)) |
883 paths.append(str(expression)) |
884 else: |
884 else: |
885 raise PLCGenException, "No connector found corresponding to \"%s\" continuation in \"%s\" POU"%(name, self.Name) |
885 raise PLCGenException, _("No connector found corresponding to \"%s\" continuation in \"%s\" POU")%(name, self.Name) |
886 elif isinstance(next, plcopen.ldObjects_contact): |
886 elif isinstance(next, plcopen.ldObjects_contact): |
887 contact_info = (self.TagName, "contact", next.getlocalId()) |
887 contact_info = (self.TagName, "contact", next.getlocalId()) |
888 variable = str(self.ExtractModifier(next, [(next.getvariable(), contact_info + ("reference",))], contact_info)) |
888 variable = str(self.ExtractModifier(next, [(next.getvariable(), contact_info + ("reference",))], contact_info)) |
889 result = self.GeneratePaths(next.connectionPointIn.getconnections(), body, order) |
889 result = self.GeneratePaths(next.connectionPointIn.getconnections(), body, order) |
890 if len(result) > 1: |
890 if len(result) > 1: |
1223 self.Program += JoinList([(", ", ())], transition_infos["from"]) |
1223 self.Program += JoinList([(", ", ())], transition_infos["from"]) |
1224 self.Program += [(")", ())] |
1224 self.Program += [(")", ())] |
1225 elif len(transition_infos["from"]) == 1: |
1225 elif len(transition_infos["from"]) == 1: |
1226 self.Program += transition_infos["from"][0] |
1226 self.Program += transition_infos["from"][0] |
1227 else: |
1227 else: |
1228 raise PLCGenException, "Transition with content \"%s\" not connected to a previous step in \"%s\" POU"%(transition_infos["content"], self.Name) |
1228 raise PLCGenException, _("Transition with content \"%s\" not connected to a previous step in \"%s\" POU")%(transition_infos["content"], self.Name) |
1229 self.Program += [(" TO ", ())] |
1229 self.Program += [(" TO ", ())] |
1230 if len(transition_infos["to"]) > 1: |
1230 if len(transition_infos["to"]) > 1: |
1231 self.Program += [("(", ())] |
1231 self.Program += [("(", ())] |
1232 self.Program += JoinList([(", ", ())], transition_infos["to"]) |
1232 self.Program += JoinList([(", ", ())], transition_infos["to"]) |
1233 self.Program += [(")", ())] |
1233 self.Program += [(")", ())] |
1234 elif len(transition_infos["to"]) == 1: |
1234 elif len(transition_infos["to"]) == 1: |
1235 self.Program += transition_infos["to"][0] |
1235 self.Program += transition_infos["to"][0] |
1236 else: |
1236 else: |
1237 raise PLCGenException, "Transition with content \"%s\" not connected to a next step in \"%s\" POU"%(transition_infos["content"], self.Name) |
1237 raise PLCGenException, _("Transition with content \"%s\" not connected to a next step in \"%s\" POU")%(transition_infos["content"], self.Name) |
1238 self.Program += transition_infos["content"] |
1238 self.Program += transition_infos["content"] |
1239 self.Program += [("%sEND_TRANSITION\n\n"%self.CurrentIndent, ())] |
1239 self.Program += [("%sEND_TRANSITION\n\n"%self.CurrentIndent, ())] |
1240 for [(step_name, step_infos)] in transition_infos["to"]: |
1240 for [(step_name, step_infos)] in transition_infos["to"]: |
1241 self.ComputeSFCStep(step_name) |
1241 self.ComputeSFCStep(step_name) |
1242 |
1242 |
1250 if self.ReturnType: |
1250 if self.ReturnType: |
1251 program += [(" : ", ()), |
1251 program += [(" : ", ()), |
1252 (self.ReturnType, (self.TagName, "return"))] |
1252 (self.ReturnType, (self.TagName, "return"))] |
1253 program += [("\n", ())] |
1253 program += [("\n", ())] |
1254 if len(self.Interface) == 0: |
1254 if len(self.Interface) == 0: |
1255 raise PLCGenException, "No variable defined in \"%s\" POU"%self.Name |
1255 raise PLCGenException, _("No variable defined in \"%s\" POU")%self.Name |
1256 if len(self.Program) == 0 : |
1256 if len(self.Program) == 0 : |
1257 raise PLCGenException, "No body defined in \"%s\" POU"%self.Name |
1257 raise PLCGenException, _("No body defined in \"%s\" POU")%self.Name |
1258 var_number = 0 |
1258 var_number = 0 |
1259 for list_type, retain, constant, located, variables in self.Interface: |
1259 for list_type, retain, constant, located, variables in self.Interface: |
1260 program += [(" %s"%list_type, ())] |
1260 program += [(" %s"%list_type, ())] |
1261 if retain: |
1261 if retain: |
1262 program += [(" RETAIN", (self.TagName, "variable", (var_number, var_number + len(variables)), "retain"))] |
1262 program += [(" RETAIN", (self.TagName, "variable", (var_number, var_number + len(variables)), "retain"))] |