898 for instance in instances: |
898 for instance in instances: |
899 if isinstance(instance, (plcopen.fbdObjects_outVariable, plcopen.fbdObjects_inOutVariable)): |
899 if isinstance(instance, (plcopen.fbdObjects_outVariable, plcopen.fbdObjects_inOutVariable)): |
900 connections = instance.connectionPointIn.getconnections() |
900 connections = instance.connectionPointIn.getconnections() |
901 if connections is not None: |
901 if connections is not None: |
902 expression = self.ComputeExpression(body, connections) |
902 expression = self.ComputeExpression(body, connections) |
903 self.Program += [(self.CurrentIndent, ()), |
903 if expression is not None: |
904 (instance.getexpression(), (self.TagName, "io_variable", instance.getlocalId(), "expression")), |
904 self.Program += [(self.CurrentIndent, ()), |
905 (" := ", ())] |
905 (instance.getexpression(), (self.TagName, "io_variable", instance.getlocalId(), "expression")), |
906 self.Program += expression |
906 (" := ", ())] |
907 self.Program += [(";\n", ())] |
907 self.Program += expression |
|
908 self.Program += [(";\n", ())] |
908 elif isinstance(instance, plcopen.fbdObjects_block): |
909 elif isinstance(instance, plcopen.fbdObjects_block): |
909 block_type = instance.gettypeName() |
910 block_type = instance.gettypeName() |
910 self.ParentGenerator.GeneratePouProgram(block_type) |
911 self.ParentGenerator.GeneratePouProgram(block_type) |
911 block_infos = self.GetBlockType(block_type, tuple([self.ConnectionTypes.get(variable.connectionPointIn, "ANY") for variable in instance.inputVariables.getvariable() if variable.getformalParameter() != "EN"])) |
912 block_infos = self.GetBlockType(block_type, tuple([self.ConnectionTypes.get(variable.connectionPointIn, "ANY") for variable in instance.inputVariables.getvariable() if variable.getformalParameter() != "EN"])) |
912 if block_infos is None: |
913 if block_infos is None: |
918 except ValueError, e: |
919 except ValueError, e: |
919 raise PLCGenException, e.message |
920 raise PLCGenException, e.message |
920 elif isinstance(instance, plcopen.commonObjects_connector): |
921 elif isinstance(instance, plcopen.commonObjects_connector): |
921 connector = instance.getname() |
922 connector = instance.getname() |
922 if self.ComputedConnectors.get(connector, None): |
923 if self.ComputedConnectors.get(connector, None): |
923 continue |
924 continue |
924 self.ComputedConnectors[connector] = self.ComputeExpression(body, instance.connectionPointIn.getconnections()) |
925 expression = self.ComputeExpression(body, instance.connectionPointIn.getconnections()) |
|
926 if expression is not None: |
|
927 self.ComputedConnectors[connector] = expression |
925 elif isinstance(instance, plcopen.ldObjects_coil): |
928 elif isinstance(instance, plcopen.ldObjects_coil): |
926 connections = instance.connectionPointIn.getconnections() |
929 connections = instance.connectionPointIn.getconnections() |
927 if connections is not None: |
930 if connections is not None: |
928 coil_info = (self.TagName, "coil", instance.getlocalId()) |
931 coil_info = (self.TagName, "coil", instance.getlocalId()) |
929 expression = self.ExtractModifier(instance, self.ComputeExpression(body, connections), coil_info) |
932 expression = self.ComputeExpression(body, connections) |
930 self.Program += [(self.CurrentIndent, ())] |
933 if expression is not None: |
931 self.Program += [(instance.getvariable(), coil_info + ("reference",))] |
934 expression = self.ExtractModifier(instance, expression, coil_info) |
932 self.Program += [(" := ", ())] + expression + [(";\n", ())] |
935 self.Program += [(self.CurrentIndent, ())] |
|
936 self.Program += [(instance.getvariable(), coil_info + ("reference",))] |
|
937 self.Program += [(" := ", ())] + expression + [(";\n", ())] |
933 |
938 |
934 def FactorizePaths(self, paths): |
939 def FactorizePaths(self, paths): |
935 same_paths = {} |
940 same_paths = {} |
936 uncomputed_index = range(len(paths)) |
941 uncomputed_index = range(len(paths)) |
937 factorized_paths = [] |
942 factorized_paths = [] |
993 connector = instance |
998 connector = instance |
994 if connector is not None: |
999 if connector is not None: |
995 connections = connector.connectionPointIn.getconnections() |
1000 connections = connector.connectionPointIn.getconnections() |
996 if connections is not None: |
1001 if connections is not None: |
997 expression = self.ComputeExpression(body, connections, order) |
1002 expression = self.ComputeExpression(body, connections, order) |
998 self.ComputedConnectors[name] = expression |
1003 if expression is not None: |
999 paths.append(str(expression)) |
1004 self.ComputedConnectors[name] = expression |
|
1005 paths.append(str(expression)) |
1000 else: |
1006 else: |
1001 raise PLCGenException, _("No connector found corresponding to \"%s\" continuation in \"%s\" POU")%(name, self.Name) |
1007 raise PLCGenException, _("No connector found corresponding to \"%s\" continuation in \"%s\" POU")%(name, self.Name) |
1002 elif isinstance(next, plcopen.ldObjects_contact): |
1008 elif isinstance(next, plcopen.ldObjects_contact): |
1003 contact_info = (self.TagName, "contact", next.getlocalId()) |
1009 contact_info = (self.TagName, "contact", next.getlocalId()) |
1004 variable = str(self.ExtractModifier(next, [(next.getvariable(), contact_info + ("reference",))], contact_info)) |
1010 variable = str(self.ExtractModifier(next, [(next.getvariable(), contact_info + ("reference",))], contact_info)) |
1037 else: |
1043 else: |
1038 return eval(paths) |
1044 return eval(paths) |
1039 |
1045 |
1040 def ComputeExpression(self, body, connections, order = False, to_inout = False): |
1046 def ComputeExpression(self, body, connections, order = False, to_inout = False): |
1041 paths = self.GeneratePaths(connections, body, order, to_inout) |
1047 paths = self.GeneratePaths(connections, body, order, to_inout) |
|
1048 if len(paths) == 0: |
|
1049 return None |
1042 if len(paths) > 1: |
1050 if len(paths) > 1: |
1043 factorized_paths = self.FactorizePaths(paths) |
1051 factorized_paths = self.FactorizePaths(paths) |
1044 if len(factorized_paths) > 1: |
1052 if len(factorized_paths) > 1: |
1045 paths = tuple(factorized_paths) |
1053 paths = tuple(factorized_paths) |
1046 else: |
1054 else: |
1260 if isinstance(instance, plcopen.fbdObjects_outVariable) and instance.getexpression() == transitionValues["value"]\ |
1268 if isinstance(instance, plcopen.fbdObjects_outVariable) and instance.getexpression() == transitionValues["value"]\ |
1261 or isinstance(instance, plcopen.ldObjects_coil) and instance.getvariable() == transitionValues["value"]: |
1269 or isinstance(instance, plcopen.ldObjects_coil) and instance.getvariable() == transitionValues["value"]: |
1262 connections = instance.connectionPointIn.getconnections() |
1270 connections = instance.connectionPointIn.getconnections() |
1263 if connections is not None: |
1271 if connections is not None: |
1264 expression = self.ComputeExpression(transitionBody, connections) |
1272 expression = self.ComputeExpression(transitionBody, connections) |
1265 transition_infos["content"] = [("\n%s:= "%self.CurrentIndent, ())] + expression + [(";\n", ())] |
1273 if expression is not None: |
1266 self.SFCComputedBlocks += self.Program |
1274 transition_infos["content"] = [("\n%s:= "%self.CurrentIndent, ())] + expression + [(";\n", ())] |
1267 self.Program = [] |
1275 self.SFCComputedBlocks += self.Program |
|
1276 self.Program = [] |
1268 if not transition_infos.has_key("content"): |
1277 if not transition_infos.has_key("content"): |
1269 raise PLCGenException, _("Transition \"%s\" body must contain an output variable or coil referring to its name") % transitionValues["value"] |
1278 raise PLCGenException, _("Transition \"%s\" body must contain an output variable or coil referring to its name") % transitionValues["value"] |
1270 self.TagName = previous_tagname |
1279 self.TagName = previous_tagname |
1271 elif transitionValues["type"] == "connection": |
1280 elif transitionValues["type"] == "connection": |
1272 body = pou.getbody() |
1281 body = pou.getbody() |
1273 if isinstance(body, ListType): |
1282 if isinstance(body, ListType): |
1274 body = body[0] |
1283 body = body[0] |
1275 connections = transition.getconnections() |
1284 connections = transition.getconnections() |
1276 if connections is not None: |
1285 if connections is not None: |
1277 expression = self.ComputeExpression(body, connections) |
1286 expression = self.ComputeExpression(body, connections) |
1278 transition_infos["content"] = [("\n%s:= "%self.CurrentIndent, ())] + expression + [(";\n", ())] |
1287 if expression is not None: |
1279 self.SFCComputedBlocks += self.Program |
1288 transition_infos["content"] = [("\n%s:= "%self.CurrentIndent, ())] + expression + [(";\n", ())] |
1280 self.Program = [] |
1289 self.SFCComputedBlocks += self.Program |
|
1290 self.Program = [] |
1281 for step in steps: |
1291 for step in steps: |
1282 self.GenerateSFCStep(step, pou) |
1292 self.GenerateSFCStep(step, pou) |
1283 step_name = step.getname() |
1293 step_name = step.getname() |
1284 if step_name in self.SFCNetworks["Steps"].keys(): |
1294 if step_name in self.SFCNetworks["Steps"].keys(): |
1285 transition_infos["from"].append([(step_name, (self.TagName, "transition", transition.getlocalId(), "from", step.getlocalId()))]) |
1295 transition_infos["from"].append([(step_name, (self.TagName, "transition", transition.getlocalId(), "from", step.getlocalId()))]) |