editors/SFCViewer.py
changeset 1584 431f4ef34bde
parent 1571 486f94a8032c
child 1730 64d8f52bc8c8
equal deleted inserted replaced
1583:d91356480df9 1584:431f4ef34bde
    29 from Viewer import *
    29 from Viewer import *
    30 from graphics.SFC_Objects import *
    30 from graphics.SFC_Objects import *
    31 from graphics.GraphicCommons import SELECTION_DIVERGENCE, \
    31 from graphics.GraphicCommons import SELECTION_DIVERGENCE, \
    32     SELECTION_CONVERGENCE, SIMULTANEOUS_DIVERGENCE, SIMULTANEOUS_CONVERGENCE, EAST, NORTH, WEST, SOUTH
    32     SELECTION_CONVERGENCE, SIMULTANEOUS_DIVERGENCE, SIMULTANEOUS_CONVERGENCE, EAST, NORTH, WEST, SOUTH
    33 
    33 
    34 type = [SELECTION_DIVERGENCE, SELECTION_CONVERGENCE, SIMULTANEOUS_DIVERGENCE, SIMULTANEOUS_CONVERGENCE]
       
    35 divergence = dict(zip(type,["SELECTION_DIVERGENCE", "SELECTION_CONVERGENCE",\
       
    36                             "SIMULTANEOUS_DIVERGENCE", "SIMULTANEOUS_CONVERGENCE"]))
       
    37 SFC_Objects = (SFC_Step, SFC_ActionBlock, SFC_Transition, SFC_Divergence, SFC_Jump)
    34 SFC_Objects = (SFC_Step, SFC_ActionBlock, SFC_Transition, SFC_Divergence, SFC_Jump)
    38 
    35 
    39 StandardRules = {
       
    40     # The key of this dict is a block that user try to connect,
       
    41     # and the value is a list of blocks, that can be connected with the current block.
       
    42     "SFC_Step" :                 ["SFC_ActionBlock",
       
    43                                   "SFC_Transition",
       
    44                                   "SELECTION_DIVERGENCE",
       
    45                                   "SIMULTANEOUS_CONVERGENCE"],
       
    46 
       
    47     "SFC_ActionBlock" :          ["SFC_Step"],
       
    48 
       
    49     "SFC_Transition" :           ["SFC_Step",
       
    50                                   "SELECTION_CONVERGENCE",
       
    51                                   "SIMULTANEOUS_DIVERGENCE",
       
    52                                   "SFC_Jump",
       
    53                                   "FBD_Block",
       
    54                                   "FBD_Variable"
       
    55                                   "LD_Contact",
       
    56                                   "LD_PowerRail",
       
    57                                   "LD_Coil"],
       
    58 
       
    59     "SELECTION_DIVERGENCE" :     ["SFC_Transition"],
       
    60 
       
    61     "SELECTION_CONVERGENCE" :    ["SFC_Step",
       
    62                                   "SFC_Jump"],
       
    63 
       
    64     "SIMULTANEOUS_DIVERGENCE" :  ["SFC_Step"],
       
    65 
       
    66     "SIMULTANEOUS_CONVERGENCE" : ["SFC_Transition"],
       
    67 
       
    68     "SFC_Jump" :                 [],
       
    69 
       
    70     "FBD_Block" :                ["SFC_Transition"],
       
    71 
       
    72     "FBD_Variable" :             ["SFC_Transition"],
       
    73 
       
    74     "LD_Contact" :               ["SFC_Transition"],
       
    75 
       
    76     "LD_PowerRail" :             ["SFC_Transition"],
       
    77 
       
    78     "LD_Coil" :                  ["SFC_Transition"]
       
    79                 }
       
    80 
    36 
    81 class SFC_Viewer(Viewer):
    37 class SFC_Viewer(Viewer):
    82     
    38     
       
    39     SFC_StandardRules = {
       
    40         # The key of this dict is a block that user try to connect,
       
    41         # and the value is a list of blocks, that can be connected with the current block
       
    42         # and with directions of connection
       
    43         "SFC_Step": [("SFC_ActionBlock", EAST),
       
    44                      ("SFC_Transition", SOUTH),
       
    45                      (SELECTION_DIVERGENCE, SOUTH),
       
    46                      (SIMULTANEOUS_CONVERGENCE, SOUTH)],
       
    47 
       
    48         "SFC_ActionBlock": [("SFC_Step", EAST)],
       
    49 
       
    50         "SFC_Transition": [("SFC_Step", SOUTH),
       
    51                            (SELECTION_CONVERGENCE, SOUTH),
       
    52                            (SIMULTANEOUS_DIVERGENCE, SOUTH),
       
    53                            ("SFC_Jump", SOUTH),
       
    54                            ("FBD_Block", EAST),
       
    55                            ("FBD_Variable", EAST),
       
    56                            ("FBD_Connector", EAST),
       
    57                            ("LD_Contact", EAST),
       
    58                            ("LD_PowerRail", EAST),
       
    59                            ("LD_Coil", EAST)],
       
    60 
       
    61         SELECTION_DIVERGENCE: [("SFC_Transition", SOUTH)],
       
    62 
       
    63         SELECTION_CONVERGENCE: [("SFC_Step", SOUTH),
       
    64                                   ("SFC_Jump", SOUTH)],
       
    65 
       
    66         SIMULTANEOUS_DIVERGENCE: [("SFC_Step", SOUTH)],
       
    67 
       
    68         SIMULTANEOUS_CONVERGENCE: [("SFC_Transition", SOUTH)],
       
    69 
       
    70         "SFC_Jump": [],
       
    71 
       
    72         "FBD_Block": [("SFC_Transition", WEST)],
       
    73 
       
    74         "FBD_Variable": [("SFC_Transition", WEST)],
       
    75 
       
    76         "FBD_Connector": [("SFC_Transition", WEST)],
       
    77 
       
    78         "LD_Contact": [("SFC_Transition", WEST)],
       
    79 
       
    80         "LD_PowerRail": [("SFC_Transition", WEST)],
       
    81 
       
    82         "LD_Coil": [("SFC_Transition", WEST)]
       
    83     }
       
    84 
    83     def __init__(self, parent, tagname, window, controler, debug = False, instancepath = ""):
    85     def __init__(self, parent, tagname, window, controler, debug = False, instancepath = ""):
    84         Viewer.__init__(self, parent, tagname, window, controler, debug, instancepath)
    86         Viewer.__init__(self, parent, tagname, window, controler, debug, instancepath)
    85         self.CurrentLanguage = "SFC"
    87         self.CurrentLanguage = "SFC"
    86     
    88     
    87     def ConnectConnectors(self, start, end):
    89     def ConnectConnectors(self, start, end):
   333         event.Skip()
   335         event.Skip()
   334 
   336 
   335     def GetBlockName(self, block):
   337     def GetBlockName(self, block):
   336         blockName = block.__class__.__name__
   338         blockName = block.__class__.__name__
   337         if blockName == "SFC_Divergence":
   339         if blockName == "SFC_Divergence":
   338             blockName = divergence[block.Type]
   340             blockName = block.Type
   339         return blockName
   341         return blockName
   340 
   342 
   341     # This method check the IEC 61131-3 compatibility between two SFC blocks
   343     # This method check the IEC 61131-3 compatibility between two SFC blocks
   342     def BlockCompatibility(self,startblock = None, endblock = None, direction = None):
   344     def BlockCompatibility(self,startblock = None, endblock = None, direction = None):
   343         if startblock!= None and endblock != None and (isinstance(startblock,SFC_Objects)\
   345         if startblock!= None and endblock != None and (isinstance(startblock,SFC_Objects)\
   344                                                                or isinstance(endblock,SFC_Objects)):
   346                                                                or isinstance(endblock,SFC_Objects)):
   345             # Full "StandardRules" table would be simmetrical and
   347             # Full "SFC_StandardRules" table would be symmetrical and
   346             # to avoid duplicate records and minimize the table only upper part is defined.
   348             # to avoid duplicate records and minimize the table only upper part is defined.
   347             if (direction == SOUTH or direction == EAST):
   349             if (direction == SOUTH or direction == EAST):
   348                 startblock, endblock = endblock, startblock
   350                 startblock, endblock = endblock, startblock
   349             start = self.GetBlockName(startblock)
   351             start = self.GetBlockName(startblock)
   350             end = self.GetBlockName(endblock)
   352             end = self.GetBlockName(endblock)
   351             return end in StandardRules[start]
   353             for val in self.SFC_StandardRules[start]:
       
   354                 if end in val:
       
   355                     return True
       
   356             return False
   352         return True
   357         return True
   353 
   358 
   354 #-------------------------------------------------------------------------------
   359 #-------------------------------------------------------------------------------
   355 #                          Keyboard event functions
   360 #                          Keyboard event functions
   356 #-------------------------------------------------------------------------------
   361 #-------------------------------------------------------------------------------