Fixed SFC block edition and SFC to SFC_textual code generating
authorLaurent Bessard
Fri, 30 Aug 2013 10:59:06 +0200
changeset 1298 f034fb2b1aab
parent 1297 cd639725fba5
child 1299 9ffc49bfdf9d
Fixed SFC block edition and SFC to SFC_textual code generating
PLCControler.py
PLCGenerator.py
plcopen/__init__.py
plcopen/plcopen.py
plcopen/structures.py
--- a/PLCControler.py	Fri Aug 30 09:18:41 2013 +0200
+++ b/PLCControler.py	Fri Aug 30 10:59:06 2013 +0200
@@ -29,7 +29,7 @@
 import datetime
 from time import localtime
 
-from plcopen import PLCOpenParser, LoadProject, SaveProject
+from plcopen import PLCOpenParser, LoadProject, SaveProject, QualifierList, rect
 from plcopen.structures import *
 from graphics.GraphicCommons import *
 from PLCGenerator import *
@@ -215,7 +215,7 @@
         self.ProgramFilePath = ""
             
     def GetQualifierTypes(self):
-        return plcopen.QualifierList
+        return QualifierList
 
     def GetProject(self, debug = False):
         if debug and self.CurrentCompiledProject is not None:
@@ -1195,13 +1195,13 @@
                     array_type, base_type_name, dimensions = var["Type"]
                     array = PLCOpenParser.CreateElement("array", "dataType")
                     for i, dimension in enumerate(dimensions):
-                        dimension_range = plcopen.rangeSigned()
-                        dimension_range.setlower(dimension[0])
-                        dimension_range.setupper(dimension[1])
+                        dimension_range = PLCOpenParser.CreateElement("range", "dimension")
                         if i == 0:
                             array.setdimension([dimension_range])
                         else:
                             array.appenddimension(dimension_range)
+                        dimension_range.setlower(dimension[0])
+                        dimension_range.setupper(dimension[1])
                     if base_type_name in self.GetBaseTypes():
                         array.baseType.setcontent(PLCOpenParser.CreateElement(
                             base_type_name.lower()
--- a/PLCGenerator.py	Fri Aug 30 09:18:41 2013 +0200
+++ b/PLCGenerator.py	Fri Aug 30 10:59:06 2013 +0200
@@ -554,7 +554,7 @@
     # Return connectors linked by a connection to the given connector
     def GetConnectedConnector(self, connector, body):
         links = connector.getconnections()
-        if links and len(links) == 1:
+        if links is not None and len(links) == 1:
             return self.GetLinkedConnector(links[0], body)
         return None        
 
@@ -720,17 +720,18 @@
                         if isinstance(instance, (OutVariableClass, InOutVariableClass)):
                             self.ConnectionTypes[instance.connectionPointIn] = var_type
                             connected = self.GetConnectedConnector(instance.connectionPointIn, body)
-                            if connected and not self.ConnectionTypes.has_key(connected):
-                                for connection in self.ExtractRelatedConnections(connected):
-                                    self.ConnectionTypes[connection] = var_type
+                            if connected is not None and not self.ConnectionTypes.has_key(connected):
+                                for related in self.ExtractRelatedConnections(connected):
+                                    self.ConnectionTypes[related] = var_type
                 elif isinstance(instance, (ContactClass, CoilClass)):
                     for connection in self.ExtractRelatedConnections(instance.connectionPointOut):
                         self.ConnectionTypes[connection] = "BOOL"
                     self.ConnectionTypes[instance.connectionPointIn] = "BOOL"
-                    connected = self.GetConnectedConnector(instance.connectionPointIn, body)
-                    if connected and not self.ConnectionTypes.has_key(connected):
-                        for connection in self.ExtractRelatedConnections(connected):
-                            self.ConnectionTypes[connection] = "BOOL"
+                    for link in instance.connectionPointIn.getconnections():
+                        connected = self.GetLinkedConnector(link, body)
+                        if connected is not None and not self.ConnectionTypes.has_key(connected):
+                            for related in self.ExtractRelatedConnections(connected):
+                                self.ConnectionTypes[related] = "BOOL"
                 elif isinstance(instance, LeftPowerRailClass):
                     for connection in instance.getconnectionPointOut():
                         for related in self.ExtractRelatedConnections(connection):
@@ -738,17 +739,20 @@
                 elif isinstance(instance, RightPowerRailClass):
                     for connection in instance.getconnectionPointIn():
                         self.ConnectionTypes[connection] = "BOOL"
-                        connected = self.GetConnectedConnector(connection, body)
-                        if connected and not self.ConnectionTypes.has_key(connected):
-                            for connection in self.ExtractRelatedConnections(connected):
-                                self.ConnectionTypes[connection] = "BOOL"
+                        for link in connection.getconnections():
+                            connected = self.GetLinkedConnector(link, body)
+                            if connected is not None and not self.ConnectionTypes.has_key(connected):
+                                for related in self.ExtractRelatedConnections(connected):
+                                    self.ConnectionTypes[related] = "BOOL"
                 elif isinstance(instance, TransitionClass):
                     content = instance.getconditionContent()
                     if content["type"] == "connection":
-                        connected = self.GetLinkedConnector(content["value"], body)
-                        if connected and not self.ConnectionTypes.has_key(connected):
-                            for connection in self.ExtractRelatedConnections(connected):
-                                self.ConnectionTypes[connection] = "BOOL"
+                        self.ConnectionTypes[content["value"]] = "BOOL"
+                        for link in content["value"].getconnections():
+                            connected = self.GetLinkedConnector(link, body)
+                            if connected is not None and not self.ConnectionTypes.has_key(connected):
+                                for related in self.ExtractRelatedConnections(connected):
+                                    self.ConnectionTypes[related] = "BOOL"
                 elif isinstance(instance, ContinuationClass):
                     name = instance.getname()
                     connector = None
@@ -761,7 +765,7 @@
                     if connector is not None:
                         undefined = [instance.connectionPointOut, connector.connectionPointIn]
                         connected = self.GetConnectedConnector(connector.connectionPointIn, body)
-                        if connected:
+                        if connected is not None:
                             undefined.append(connected)
                         related = []
                         for connection in undefined:
@@ -838,11 +842,11 @@
                             if not undefined.has_key(itype):
                                 undefined[itype] = []
                             undefined[itype].append(variable.connectionPointIn)
-                            if connected:
+                            if connected is not None:
                                 undefined[itype].append(connected)
                         else:
                             self.ConnectionTypes[variable.connectionPointIn] = itype
-                            if connected and not self.ConnectionTypes.has_key(connected):
+                            if connected is not None and not self.ConnectionTypes.has_key(connected):
                                 for connection in self.ExtractRelatedConnections(connected):
                                     self.ConnectionTypes[connection] = itype
         for var_type, connections in undefined.items():
@@ -879,7 +883,7 @@
                     self.GenerateSFCStepActions(instance, pou)
                 elif isinstance(instance, TransitionClass):
                     self.GenerateSFCTransition(instance, pou)
-                elif isinstance(instance, JumpClass):
+                elif isinstance(instance, JumpStepClass):
                     self.GenerateSFCJump(instance, pou)
             if len(self.InitialSteps) > 0 and len(self.SFCComputedBlocks) > 0:
                 action_name = "COMPUTE_FUNCTION_BLOCKS"
@@ -1108,7 +1112,7 @@
     
     def ExtractDivergenceInput(self, divergence, pou):
         connectionPointIn = divergence.getconnectionPointIn()
-        if connectionPointIn:
+        if connectionPointIn is not None:
             connections = connectionPointIn.getconnections()
             if connections is not None and len(connections) == 1:
                 instanceLocalId = connections[0].getrefLocalId()
@@ -1140,7 +1144,7 @@
                           "transitions" : [], 
                           "actions" : []}
             self.SFCNetworks["Steps"][step_name] = step_infos
-            if step.connectionPointIn:
+            if step.connectionPointIn is not None:
                 instances = []
                 connections = step.connectionPointIn.getconnections()
                 if connections is not None and len(connections) == 1:
@@ -1155,7 +1159,7 @@
                         instances.extend(self.ExtractConvergenceInputs(instance, pou))
                     elif isinstance(instance, SimultaneousDivergenceClass):
                         transition = self.ExtractDivergenceInput(instance, pou)
-                        if transition:
+                        if transition is not None:
                             if isinstance(transition, TransitionClass):
                                 instances.append(transition)
                             elif isinstance(transition, SelectionConvergenceClass):
@@ -1168,7 +1172,7 @@
     
     def GenerateSFCJump(self, jump, pou):
         jump_target = jump.gettargetName()
-        if jump.connectionPointIn:
+        if jump.connectionPointIn is not None:
             instances = []
             connections = jump.connectionPointIn.getconnections()
             if connections is not None and len(connections) == 1:
@@ -1183,7 +1187,7 @@
                     instances.extend(self.ExtractConvergenceInputs(instance, pou))
                 elif isinstance(instance, SimultaneousDivergenceClass):
                     transition = self.ExtractDivergenceInput(instance, pou)
-                    if transition:
+                    if transition is not None:
                         if isinstance(transition, TransitionClass):
                             instances.append(transition)
                         elif isinstance(transition, SelectionConvergenceClass):
@@ -1228,7 +1232,7 @@
     def GenerateSFCAction(self, action_name, pou):
         if action_name not in self.SFCNetworks["Actions"].keys():
             actionContent = pou.getaction(action_name)
-            if actionContent:
+            if actionContent is not None:
                 previous_tagname = self.TagName
                 self.TagName = self.ParentGenerator.Controler.ComputePouActionName(self.Name, action_name)
                 self.ComputeProgram(actionContent)
@@ -1250,7 +1254,7 @@
                     steps.append(instance)
                 elif isinstance(instance, SelectionDivergenceClass):
                     step = self.ExtractDivergenceInput(instance, pou)
-                    if step:
+                    if step is not None:
                         if isinstance(step, StepClass):
                             steps.append(step)
                         elif isinstance(step, SimultaneousConvergenceClass):
@@ -1260,7 +1264,8 @@
             transition_infos = {"id" : transition.getlocalId(), 
                                 "priority": transition.getpriority(), 
                                 "from": [], 
-                                "to" : []}
+                                "to" : [],
+                                "content": []}
             self.SFCNetworks["Transitions"][transition] = transition_infos
             transitionValues = transition.getconditionContent()
             if transitionValues["type"] == "inline":
@@ -1297,7 +1302,7 @@
                 body = pou.getbody()
                 if isinstance(body, ListType):
                     body = body[0]
-                connections = transition.getconnections()
+                connections = transitionValues["value"].getconnections()
                 if connections is not None:
                     expression = self.ComputeExpression(body, connections)
                     if expression is not None:
@@ -1351,7 +1356,7 @@
             action_content, action_info = self.SFCNetworks["Actions"].pop(action_name)
             self.Program += [("%sACTION "%self.CurrentIndent, ()),
                              (action_name, action_info),
-                             (" :\n", ())]
+                             (":\n", ())]
             self.Program += action_content
             self.Program += [("%sEND_ACTION\n\n"%self.CurrentIndent, ())]
     
--- a/plcopen/__init__.py	Fri Aug 30 09:18:41 2013 +0200
+++ b/plcopen/__init__.py	Fri Aug 30 10:59:06 2013 +0200
@@ -25,6 +25,6 @@
 # Package initialisation
 
 # plcopen module dynamically creates its classes
-from plcopen import PLCOpenParser, LoadProject, SaveProject, VarOrder, rect
+from plcopen import PLCOpenParser, LoadProject, SaveProject, VarOrder, QualifierList, rect
 
 from structures import *
--- a/plcopen/plcopen.py	Fri Aug 30 09:18:41 2013 +0200
+++ b/plcopen/plcopen.py	Fri Aug 30 10:59:06 2013 +0200
@@ -2325,11 +2325,11 @@
         specific_values = infos["specific_values"]
         specific_values["name"] = self.getname()
         specific_values["initial"] = self.getinitialStep()
-        if self.connectionPointIn:
+        if self.connectionPointIn is not None:
             infos["inputs"].append(_getconnectioninfos(self, self.connectionPointIn, True))
-        if self.connectionPointOut:
+        if self.connectionPointOut is not None:
             infos["outputs"].append(_getconnectioninfos(self, self.connectionPointOut))
-        if self.connectionPointOutAction:
+        if self.connectionPointOutAction is not None:
             specific_values["action"] = _getconnectioninfos(self, self.connectionPointOutAction)
         return infos
     setattr(cls, "getinfos", getinfos)
@@ -2368,16 +2368,16 @@
         condition = self.getconditionContent()
         specific_values["condition_type"] = condition["type"]
         if specific_values["condition_type"] == "connection":
-            specific_values["connection"] = _getconnectioninfos(self, condition, True)
+            specific_values["connection"] = _getconnectioninfos(self, condition["value"], True)
         else:
-            specific_values["condition"] = condition
+            specific_values["condition"] = condition["value"]
         infos["inputs"].append(_getconnectioninfos(self, self.connectionPointIn, True))
         infos["outputs"].append(_getconnectioninfos(self, self.connectionPointOut))
         return infos
     setattr(cls, "getinfos", getinfos)
 
     def setconditionContent(self, condition_type, value):
-        if not self.condition:
+        if self.condition is None:
             self.addcondition()
         if condition_type == "connection":
             condition = PLCOpenParser.CreateElement("connectionPointIn", "condition")
@@ -2392,7 +2392,7 @@
     setattr(cls, "setconditionContent", setconditionContent)
         
     def getconditionContent(self):
-        if self.condition:
+        if self.condition is not None:
             content = self.condition.getcontent()
             values = {"type" : content.getLocalTag()}
             if values["type"] == "reference":
@@ -2407,7 +2407,7 @@
     setattr(cls, "getconditionContent", getconditionContent)
 
     def getconditionConnection(self):
-        if self.condition:
+        if self.condition is not None:
             content = self.condition.getcontent()
             if content.getLocalTag() == "connection":
                 return content
@@ -2530,39 +2530,39 @@
     setattr(cls, "compatibility", compatibility)
     
     def setreferenceName(self, name):
-        if self.reference:
+        if self.reference is not None:
             self.reference.setname(name)
     setattr(cls, "setreferenceName", setreferenceName)
     
     def getreferenceName(self):
-        if self.reference:
+        if self.reference is not None:
             return self.reference.getname()
         return None
     setattr(cls, "getreferenceName", getreferenceName)
 
     def setinlineContent(self, content):
-        if self.inline:
-            self.inline.setcontent(PLCOpenParser.CreateElement("ST", "action"))
-            self.inline.setanyText(content)
+        if self.inline is not None:
+            self.inline.setcontent(PLCOpenParser.CreateElement("ST", "inline"))
+            self.inline.settext(content)
     setattr(cls, "setinlineContent", setinlineContent)
     
     def getinlineContent(self):
-        if self.inline:
-            return self.inline.getanyText()
+        if self.inline is not None:
+            return self.inline.gettext()
         return None
     setattr(cls, "getinlineContent", getinlineContent)
 
     def updateElementName(self, old_name, new_name):
-        if self.reference and self.reference.getname() == old_name:
+        if self.reference is not None and self.reference.getname() == old_name:
             self.reference.setname(new_name)
-        if self.inline:
+        if self.inline is not None:
             self.inline.updateElementName(old_name, new_name)
     setattr(cls, "updateElementName", updateElementName)
 
     def updateElementAddress(self, address_model, new_leading):
-        if self.reference:
+        if self.reference is not None:
             self.reference.setname(update_address(self.reference.getname(), address_model, new_leading))
-        if self.inline:
+        if self.inline is not None:
             self.inline.updateElementAddress(address_model, new_leading)
     setattr(cls, "updateElementAddress", updateElementAddress)
 
@@ -2597,7 +2597,8 @@
     def setactions(self, actions):
         self.action = []
         for params in actions:
-            action = PLCOpenParser.GetElementClass("action", "actionBlock")()
+            action = PLCOpenParser.CreateElement("action", "actionBlock")
+            self.appendaction(action)
             action.setqualifier(params["qualifier"])
             if params["type"] == "reference":
                 action.addreference()
@@ -2609,7 +2610,6 @@
                 action.setduration(params["duration"])
             if params.has_key("indicator"):
                 action.setindicator(params["indicator"])
-            self.action.append(action)
     setattr(cls, "setactions", setactions)
 
     def getactions(self):
@@ -2619,17 +2619,17 @@
             params["qualifier"] = action.getqualifier()
             if params["qualifier"] is None:
                 params["qualifier"] = "N"
-            if action.getreference():
+            if action.getreference() is not None:
                 params["type"] = "reference"
                 params["value"] = action.getreferenceName()
-            elif action.getinline():
+            elif action.getinline() is not None:
                 params["type"] = "inline"
                 params["value"] = action.getinlineContent()
             duration = action.getduration()
             if duration:
                 params["duration"] = duration
             indicator = action.getindicator()
-            if indicator:
+            if indicator is not None:
                 params["indicator"] = indicator
             actions.append(params)
         return actions
--- a/plcopen/structures.py	Fri Aug 30 09:18:41 2013 +0200
+++ b/plcopen/structures.py	Fri Aug 30 10:59:06 2013 +0200
@@ -158,7 +158,7 @@
             generator.Program += JoinList([(", ", ())], vars)
             generator.Program += [(");\n", ())]
     
-    if link:
+    if link is not None:
         connectionPoint = link.getposition()[-1]
         output_parameter = link.getformalParameter()
     else:
@@ -177,7 +177,7 @@
     else:
         for i, variable in enumerate(output_variables):
             blockPointx, blockPointy = variable.connectionPointOut.getrelPositionXY()
-            if (not connectionPoint or 
+            if (connectionPoint is None or 
                 block.getx() + blockPointx == connectionPoint.getx() and 
                 block.gety() + blockPointy == connectionPoint.gety()):
                 output_variable = variable