Adding support for:
authorlbessard
Thu, 09 Apr 2009 15:31:56 +0200
changeset 340 5a305b7c6735
parent 339 d4977f6d1621
child 341 88030497e29e
Adding support for:
- find functions used in ST and IL for generating order
- compiling connector/continuation connector types generating
PLCGenerator.py
--- a/PLCGenerator.py	Thu Apr 09 15:30:05 2009 +0200
+++ b/PLCGenerator.py	Thu Apr 09 15:31:56 2009 +0200
@@ -25,6 +25,7 @@
 from plcopen import plcopen
 from plcopen.structures import *
 from types import *
+import re
 
 
 # Dictionary associating PLCOpen variable categories to the corresponding 
@@ -222,7 +223,7 @@
             pou = self.Project.getpou(pou_name)
             pou_type = pou.getpouType()
             # Verify that POU type exists
-            if pou_type in pouTypeNames:
+            if pouTypeNames.has_key(pou_type):
                 # Create a POU program generator
                 pou_program = PouProgramGenerator(self, pou.getname(), pouTypeNames[pou_type], self.Errors, self.Warnings)
                 program = pou_program.GenerateProgram(pou)
@@ -230,6 +231,13 @@
             else:
                 raise PLCGenException, "Undefined pou type \"%s\""%pou_type
     
+    # Generate a POU defined and used in text
+    def GeneratePouProgramInText(self, text):
+        for pou_name in self.PouComputed.keys():
+            model = re.compile("(?:^|[^0-9^A-Z])%s(?:$|[^0-9^A-Z])"%pou_name.upper())
+            if model.search(text) is not None:
+                self.GeneratePouProgram(pou_name)
+    
     # Generate a configuration from its model
     def GenerateConfiguration(self, configuration):
         tagname = self.Controler.ComputeConfigurationName(configuration.getname())
@@ -614,7 +622,7 @@
                         if isinstance(instance, (plcopen.fbdObjects_outVariable, plcopen.fbdObjects_inOutVariable)):
                             self.ConnectionTypes[instance.connectionPointIn] = var_type
                             connected = self.GetConnectedConnector(instance.connectionPointIn, body)
-                            if connected and connected not in self.ConnectionTypes:
+                            if connected and not self.ConnectionTypes.has_key(connected):
                                 for connection in self.ExtractRelatedConnections(connected):
                                     self.ConnectionTypes[connection] = var_type
                 elif isinstance(instance, (plcopen.ldObjects_contact, plcopen.ldObjects_coil)):
@@ -622,7 +630,7 @@
                         self.ConnectionTypes[connection] = "BOOL"
                     self.ConnectionTypes[instance.connectionPointIn] = "BOOL"
                     connected = self.GetConnectedConnector(instance.connectionPointIn, body)
-                    if connected and connected not in self.ConnectionTypes:
+                    if connected and not self.ConnectionTypes.has_key(connected):
                         for connection in self.ExtractRelatedConnections(connected):
                             self.ConnectionTypes[connection] = "BOOL"
                 elif isinstance(instance, plcopen.ldObjects_leftPowerRail):
@@ -633,16 +641,42 @@
                     for connection in instance.getconnectionPointIn():
                         self.ConnectionTypes[connection] = "BOOL"
                         connected = self.GetConnectedConnector(connection, body)
-                        if connected and connected not in self.ConnectionTypes:
+                        if connected and not self.ConnectionTypes.has_key(connected):
                             for connection in self.ExtractRelatedConnections(connected):
                                 self.ConnectionTypes[connection] = "BOOL"
                 elif isinstance(instance, plcopen.sfcObjects_transition):
                     content = instance.condition.getcontent()
                     if content["name"] == "connection" and len(content["value"]) == 1:
                         connected = self.GetLinkedConnector(content["value"][0], body)
-                        if connected and connected not in self.ConnectionTypes:
+                        if connected and not self.ConnectionTypes.has_key(connected):
                             for connection in self.ExtractRelatedConnections(connected):
                                 self.ConnectionTypes[connection] = "BOOL"
+                elif isinstance(instance, plcopen.commonObjects_continuation):
+                    name = instance.getname()
+                    connector = None
+                    for element in body.getcontentInstances():
+                        if isinstance(element, plcopen.commonObjects_connector) and element.getname() == name:
+                            if connector is not None:
+                                raise PLCGenException, "More than one connector found corresponding to \"%s\" continuation in \"%s\" POU"%(name, self.Name)
+                            connector = element
+                    if connector is not None:
+                        undefined = [instance.connectionPointOut, connector.connectionPointIn]
+                        connected = self.GetConnectedConnector(connector.connectionPointIn, body)
+                        if connected:
+                            undefined.append(connected)
+                        related = []
+                        for connection in undefined:
+                            if self.ConnectionTypes.has_key(connection):
+                                var_type = self.ConnectionTypes[connection]
+                            else:
+                                related.extend(self.ExtractRelatedConnections(connection))
+                        if var_type.startswith("ANY") and len(related) > 0:
+                            self.RelatedConnections.append(related)
+                        else:
+                            for connection in related:
+                                self.ConnectionTypes[connection] = var_type
+                    else:
+                        raise PLCGenException, "No connector found corresponding to \"%s\" continuation in \"%s\" POU"%(name, self.Name)
                 elif isinstance(instance, plcopen.fbdObjects_block):
                     block_infos = self.GetBlockType(instance.gettypeName())
                     undefined = {}
@@ -653,12 +687,12 @@
                                 self.ConnectionTypes[connection] = "BOOL"
                         else:
                             for oname, otype, oqualifier in block_infos["outputs"]:
-                                if output_name == oname and variable.connectionPointOut not in self.ConnectionTypes:
+                                if output_name == oname:
                                     if otype.startswith("ANY"):
-                                        if otype not in undefined:
+                                        if not undefined.has_key(otype):
                                             undefined[otype] = []
                                         undefined[otype].append(variable.connectionPointOut)
-                                    else:
+                                    elif not self.ConnectionTypes.has_key(variable.connectionPointOut):
                                         for connection in self.ExtractRelatedConnections(variable.connectionPointOut):
                                             self.ConnectionTypes[connection] = otype
                     for variable in instance.inputVariables.getvariable():
@@ -670,20 +704,20 @@
                             if input_name == iname:
                                 connected = self.GetConnectedConnector(variable.connectionPointIn, body)
                                 if itype.startswith("ANY"):
-                                    if itype not in undefined:
+                                    if not undefined.has_key(itype):
                                         undefined[itype] = []
                                     undefined[itype].append(variable.connectionPointIn)
                                     if connected:
                                         undefined[itype].append(connected)
                                 else:
                                     self.ConnectionTypes[variable.connectionPointIn] = itype
-                                    if connected and connected not in self.ConnectionTypes:
+                                    if connected and not self.ConnectionTypes.has_key(connected):
                                         for connection in self.ExtractRelatedConnections(connected):
                                             self.ConnectionTypes[connection] = itype
                     for var_type, connections in undefined.items():
                         related = []
                         for connection in connections:
-                            if connection in self.ConnectionTypes:
+                            if self.ConnectionTypes.has_key(connection):
                                 var_type = self.ConnectionTypes[connection]
                             else:
                                 related.extend(self.ExtractRelatedConnections(connection))
@@ -698,7 +732,9 @@
         body_content = body.getcontent()
         body_type = body_content["name"]
         if body_type in ["IL","ST"]:
-            self.Program = [(ReIndentText(body_content["value"].gettext(), len(self.CurrentIndent)), 
+            text = body_content["value"].gettext()
+            self.ParentGenerator.GeneratePouProgramInText(text.upper())
+            self.Program = [(ReIndentText(text, len(self.CurrentIndent)), 
                             (self.TagName, "body", len(self.CurrentIndent)))]
         elif body_type == "SFC":
             self.IndentRight()