PLCControler.py
changeset 184 d3e6484ebe85
parent 173 3f99b76ecfe7
child 188 d64037e17075
equal deleted inserted replaced
183:99d77995b4ea 184:d3e6484ebe85
    34 from graphics.GraphicCommons import *
    34 from graphics.GraphicCommons import *
    35 from PLCGenerator import *
    35 from PLCGenerator import *
    36 
    36 
    37 duration_model = re.compile("(?:([0-9]{1,2})h)?(?:([0-9]{1,2})m(?!s))?(?:([0-9]{1,2})s)?(?:([0-9]{1,3}(?:.[0-9]*)?)ms)?")
    37 duration_model = re.compile("(?:([0-9]{1,2})h)?(?:([0-9]{1,2})m(?!s))?(?:([0-9]{1,2})s)?(?:([0-9]{1,3}(?:.[0-9]*)?)ms)?")
    38 
    38 
    39 [ITEM_UNEDITABLE, ITEM_PROJECT, ITEM_POU, ITEM_CLASS, ITEM_VARIABLE,
    39 ITEMS_EDITABLE = [ITEM_PROJECT,
    40  ITEM_TRANSITION, ITEM_ACTION, ITEM_CONFIGURATION, ITEM_RESOURCE, 
    40                     ITEM_POU,
    41  ITEM_DATATYPE] = range(10)
    41                     ITEM_VARIABLE,
       
    42                     ITEM_TRANSITION,
       
    43                     ITEM_ACTION,
       
    44                     ITEM_CONFIGURATION,
       
    45                     ITEM_RESOURCE,
       
    46                     ITEM_DATATYPE] = range(8)
       
    47 
       
    48 ITEMS_UNEDITABLE=[ITEM_DATATYPES,
       
    49                   ITEM_FUNCTION,
       
    50                   ITEM_FUNCTIONBLOCK,
       
    51                   ITEM_PROGRAM,
       
    52                   ITEM_TRANSITIONS,
       
    53                   ITEM_ACTIONS,
       
    54                   ITEM_CONFIGURATIONS,
       
    55                   ITEM_RESOURCES,
       
    56                   ITEM_PROPERTIES,
       
    57                   ]=range(9,18)
    42 
    58 
    43 ScriptDirectory = os.path.split(os.path.realpath(__file__))[0]
    59 ScriptDirectory = os.path.split(os.path.realpath(__file__))[0]
    44 
    60 
    45 #-------------------------------------------------------------------------------
    61 #-------------------------------------------------------------------------------
    46 #                         Undo Buffer for PLCOpenEditor
    62 #                         Undo Buffer for PLCOpenEditor
   252     
   268     
   253     # Return project informations
   269     # Return project informations
   254     def GetProjectInfos(self):
   270     def GetProjectInfos(self):
   255         if self.Project:
   271         if self.Project:
   256             infos = {"name": self.Project.getname(), "type": ITEM_PROJECT}
   272             infos = {"name": self.Project.getname(), "type": ITEM_PROJECT}
   257             datatypes = {"name": "Data Types", "type": ITEM_UNEDITABLE, "values":[]}
   273             datatypes = {"name": "Data Types", "type": ITEM_DATATYPES, "values":[]}
   258             for datatype in self.Project.getdataTypes():
   274             for datatype in self.Project.getdataTypes():
   259                 datatypes["values"].append({"name": datatype.getname(), "type": ITEM_DATATYPE, "values": []})
   275                 datatypes["values"].append({"name": datatype.getname(), "type": ITEM_DATATYPE, "values": []})
   260             pou_types = {"function": {"name": "Functions", "type": ITEM_UNEDITABLE, "values":[]},
   276             pou_types = {"function": {"name": "Functions", "type": ITEM_FUNCTION, "values":[]},
   261                          "functionBlock": {"name": "Function Blocks", "type": ITEM_UNEDITABLE, "values":[]},
   277                          "functionBlock": {"name": "Function Blocks", "type": ITEM_FUNCTIONBLOCK, "values":[]},
   262                          "program": {"name": "Programs", "type": ITEM_UNEDITABLE, "values":[]}}
   278                          "program": {"name": "Programs", "type": ITEM_PROGRAM, "values":[]}}
   263             for pou in self.Project.getpous():
   279             for pou in self.Project.getpous():
   264                 pou_type = pou.getpouType()
   280                 pou_type = pou.getpouType()
   265                 pou_infos = {"name": pou.getname(), "type": ITEM_POU}
   281                 pou_infos = {"name": pou.getname(), "type": ITEM_POU}
   266                 pou_values = []
   282                 pou_values = []
   267                 if pou.getbodyType() == "SFC":
   283                 if pou.getbodyType() == "SFC":
   268                     transitions = []
   284                     transitions = []
   269                     for transition in pou.gettransitionList():
   285                     for transition in pou.gettransitionList():
   270                         transitions.append({"name": transition.getname(), "type": ITEM_TRANSITION, "values": []})
   286                         transitions.append({"name": transition.getname(), "type": ITEM_TRANSITION, "values": []})
   271                     pou_values.append({"name": "Transitions", "type": ITEM_UNEDITABLE, "values": transitions})
   287                     pou_values.append({"name": "Transitions", "type": ITEM_TRANSITIONS, "values": transitions})
   272                     actions = []
   288                     actions = []
   273                     for action in pou.getactionList():
   289                     for action in pou.getactionList():
   274                         actions.append({"name": action.getname(), "type": ITEM_ACTION, "values": []})
   290                         actions.append({"name": action.getname(), "type": ITEM_ACTION, "values": []})
   275                     pou_values.append({"name": "Actions", "type": ITEM_UNEDITABLE, "values": actions})
   291                     pou_values.append({"name": "Actions", "type": ITEM_ACTIONS, "values": actions})
   276                 if pou_type in pou_types:
   292                 if pou_type in pou_types:
   277                     pou_infos["values"] = pou_values
   293                     pou_infos["values"] = pou_values
   278                     pou_types[pou_type]["values"].append(pou_infos)
   294                     pou_types[pou_type]["values"].append(pou_infos)
   279             configurations = {"name": "Configurations", "type": ITEM_UNEDITABLE, "values": []}
   295             configurations = {"name": "Configurations", "type": ITEM_CONFIGURATIONS, "values": []}
   280             for config in self.Project.getconfigurations():
   296             for config in self.Project.getconfigurations():
   281                 config_name = config.getname()
   297                 config_name = config.getname()
   282                 config_infos = {"name": config_name, "type": ITEM_CONFIGURATION, "values": []}
   298                 config_infos = {"name": config_name, "type": ITEM_CONFIGURATION, "values": []}
   283                 resources = {"name": "Resources", "type": ITEM_UNEDITABLE, "values": []}
   299                 resources = {"name": "Resources", "type": ITEM_RESOURCES, "values": []}
   284                 for resource in config.getresource():
   300                 for resource in config.getresource():
   285                     resource_name = resource.getname()
   301                     resource_name = resource.getname()
   286                     resource_infos = {"name": resource_name, "type": ITEM_RESOURCE, "values": []}
   302                     resource_infos = {"name": resource_name, "type": ITEM_RESOURCE, "values": []}
   287                     resources["values"].append(resource_infos)
   303                     resources["values"].append(resource_infos)
   288                 config_infos["values"] = [resources]
   304                 config_infos["values"] = [resources]
   289                 configurations["values"].append(config_infos)
   305                 configurations["values"].append(config_infos)
   290             infos["values"] = [{"name": "Properties", "type": ITEM_UNEDITABLE, "values": []},
   306             infos["values"] = [{"name": "Properties", "type": ITEM_PROPERTIES, "values": []},
   291                                datatypes, pou_types["function"], pou_types["functionBlock"], 
   307                                datatypes, pou_types["function"], pou_types["functionBlock"], 
   292                                pou_types["program"], configurations]
   308                                pou_types["program"], configurations]
   293             return infos
   309             return infos
   294         return None
   310         return None
   295 
   311