74 "Output" : (plcopen.interface_outputVars, ITEM_VAR_OUTPUT), |
74 "Output" : (plcopen.interface_outputVars, ITEM_VAR_OUTPUT), |
75 "InOut" : (plcopen.interface_inOutVars, ITEM_VAR_INOUT) |
75 "InOut" : (plcopen.interface_inOutVars, ITEM_VAR_INOUT) |
76 } |
76 } |
77 |
77 |
78 ScriptDirectory = os.path.split(os.path.realpath(__file__))[0] |
78 ScriptDirectory = os.path.split(os.path.realpath(__file__))[0] |
|
79 |
|
80 def GetUneditableNames(): |
|
81 _ = lambda x:x |
|
82 return [_("User-defined POUs"), _("Functions"), _("Function Blocks"), |
|
83 _("Programs"), _("Data Types"), _("Transitions"), _("Actions"), |
|
84 _("Configurations"), _("Resources"), _("Properties")] |
|
85 UNEDITABLE_NAMES = GetUneditableNames() |
|
86 [USER_DEFINED_POUS, FUNCTIONS, FUNCTION_BLOCKS, PROGRAMS, |
|
87 DATA_TYPES, TRANSITIONS, ACTIONS, CONFIGURATIONS, |
|
88 RESOURCES, PROPERTIES] = UNEDITABLE_NAMES |
79 |
89 |
80 #------------------------------------------------------------------------------- |
90 #------------------------------------------------------------------------------- |
81 # Undo Buffer for PLCOpenEditor |
91 # Undo Buffer for PLCOpenEditor |
82 #------------------------------------------------------------------------------- |
92 #------------------------------------------------------------------------------- |
83 |
93 |
278 # Change file path and save file name or create a default one if file path not defined |
288 # Change file path and save file name or create a default one if file path not defined |
279 def SetFilePath(self, filepath): |
289 def SetFilePath(self, filepath): |
280 self.FilePath = filepath |
290 self.FilePath = filepath |
281 if filepath == "": |
291 if filepath == "": |
282 self.LastNewIndex += 1 |
292 self.LastNewIndex += 1 |
283 self.FileName = "Unnamed%d"%self.LastNewIndex |
293 self.FileName = _("Unnamed%d")%self.LastNewIndex |
284 else: |
294 else: |
285 self.FileName = os.path.splitext(os.path.basename(filepath))[0] |
295 self.FileName = os.path.splitext(os.path.basename(filepath))[0] |
286 |
296 |
287 # Change project properties |
297 # Change project properties |
288 def SetProjectProperties(self, name = None, properties = None): |
298 def SetProjectProperties(self, name = None, properties = None): |
307 # Return project informations |
317 # Return project informations |
308 def GetProjectInfos(self, debug = False): |
318 def GetProjectInfos(self, debug = False): |
309 project = self.GetProject(debug) |
319 project = self.GetProject(debug) |
310 if project is not None: |
320 if project is not None: |
311 infos = {"name": project.getname(), "type": ITEM_PROJECT} |
321 infos = {"name": project.getname(), "type": ITEM_PROJECT} |
312 datatypes = {"name": "Data Types", "type": ITEM_DATATYPES, "values":[]} |
322 datatypes = {"name": DATA_TYPES, "type": ITEM_DATATYPES, "values":[]} |
313 for datatype in project.getdataTypes(): |
323 for datatype in project.getdataTypes(): |
314 datatypes["values"].append({"name": datatype.getname(), "type": ITEM_DATATYPE, |
324 datatypes["values"].append({"name": datatype.getname(), "type": ITEM_DATATYPE, |
315 "tagname": self.ComputeDataTypeName(datatype.getname()), "values": []}) |
325 "tagname": self.ComputeDataTypeName(datatype.getname()), "values": []}) |
316 pou_types = {"function": {"name": "Functions", "type": ITEM_FUNCTION, "values":[]}, |
326 pou_types = {"function": {"name": FUNCTIONS, "type": ITEM_FUNCTION, "values":[]}, |
317 "functionBlock": {"name": "Function Blocks", "type": ITEM_FUNCTIONBLOCK, "values":[]}, |
327 "functionBlock": {"name": FUNCTION_BLOCKS, "type": ITEM_FUNCTIONBLOCK, "values":[]}, |
318 "program": {"name": "Programs", "type": ITEM_PROGRAM, "values":[]}} |
328 "program": {"name": PROGRAMS, "type": ITEM_PROGRAM, "values":[]}} |
319 for pou in project.getpous(): |
329 for pou in project.getpous(): |
320 pou_type = pou.getpouType() |
330 pou_type = pou.getpouType() |
321 pou_infos = {"name": pou.getname(), "type": ITEM_POU, |
331 pou_infos = {"name": pou.getname(), "type": ITEM_POU, |
322 "tagname": self.ComputePouName(pou.getname())} |
332 "tagname": self.ComputePouName(pou.getname())} |
323 pou_values = [] |
333 pou_values = [] |
325 transitions = [] |
335 transitions = [] |
326 for transition in pou.gettransitionList(): |
336 for transition in pou.gettransitionList(): |
327 transitions.append({"name": transition.getname(), "type": ITEM_TRANSITION, |
337 transitions.append({"name": transition.getname(), "type": ITEM_TRANSITION, |
328 "tagname": self.ComputePouTransitionName(pou.getname(), transition.getname()), |
338 "tagname": self.ComputePouTransitionName(pou.getname(), transition.getname()), |
329 "values": []}) |
339 "values": []}) |
330 pou_values.append({"name": "Transitions", "type": ITEM_TRANSITIONS, "values": transitions}) |
340 pou_values.append({"name": TRANSITIONS, "type": ITEM_TRANSITIONS, "values": transitions}) |
331 actions = [] |
341 actions = [] |
332 for action in pou.getactionList(): |
342 for action in pou.getactionList(): |
333 actions.append({"name": action.getname(), "type": ITEM_ACTION, |
343 actions.append({"name": action.getname(), "type": ITEM_ACTION, |
334 "tagname": self.ComputePouActionName(pou.getname(), action.getname()), |
344 "tagname": self.ComputePouActionName(pou.getname(), action.getname()), |
335 "values": []}) |
345 "values": []}) |
336 pou_values.append({"name": "Actions", "type": ITEM_ACTIONS, "values": actions}) |
346 pou_values.append({"name": ACTIONS, "type": ITEM_ACTIONS, "values": actions}) |
337 if pou_type in pou_types: |
347 if pou_type in pou_types: |
338 pou_infos["values"] = pou_values |
348 pou_infos["values"] = pou_values |
339 pou_types[pou_type]["values"].append(pou_infos) |
349 pou_types[pou_type]["values"].append(pou_infos) |
340 configurations = {"name": "Configurations", "type": ITEM_CONFIGURATIONS, "values": []} |
350 configurations = {"name": CONFIGURATIONS, "type": ITEM_CONFIGURATIONS, "values": []} |
341 for config in project.getconfigurations(): |
351 for config in project.getconfigurations(): |
342 config_name = config.getname() |
352 config_name = config.getname() |
343 config_infos = {"name": config_name, "type": ITEM_CONFIGURATION, |
353 config_infos = {"name": config_name, "type": ITEM_CONFIGURATION, |
344 "tagname": self.ComputeConfigurationName(config.getname()), |
354 "tagname": self.ComputeConfigurationName(config.getname()), |
345 "values": []} |
355 "values": []} |
346 resources = {"name": "Resources", "type": ITEM_RESOURCES, "values": []} |
356 resources = {"name": RESOURCES, "type": ITEM_RESOURCES, "values": []} |
347 for resource in config.getresource(): |
357 for resource in config.getresource(): |
348 resource_name = resource.getname() |
358 resource_name = resource.getname() |
349 resource_infos = {"name": resource_name, "type": ITEM_RESOURCE, |
359 resource_infos = {"name": resource_name, "type": ITEM_RESOURCE, |
350 "tagname": self.ComputeConfigurationResourceName(config.getname(), resource.getname()), |
360 "tagname": self.ComputeConfigurationResourceName(config.getname(), resource.getname()), |
351 "values": []} |
361 "values": []} |
352 resources["values"].append(resource_infos) |
362 resources["values"].append(resource_infos) |
353 config_infos["values"] = [resources] |
363 config_infos["values"] = [resources] |
354 configurations["values"].append(config_infos) |
364 configurations["values"].append(config_infos) |
355 infos["values"] = [{"name": "Properties", "type": ITEM_PROPERTIES, "values": []}, |
365 infos["values"] = [{"name": PROPERTIES, "type": ITEM_PROPERTIES, "values": []}, |
356 datatypes, pou_types["function"], pou_types["functionBlock"], |
366 datatypes, pou_types["function"], pou_types["functionBlock"], |
357 pou_types["program"], configurations] |
367 pou_types["program"], configurations] |
358 return infos |
368 return infos |
359 return None |
369 return None |
360 |
370 |
1163 blocktypes.append(cat) |
1173 blocktypes.append(cat) |
1164 else: |
1174 else: |
1165 blocktypes = [category for category in BlockTypes + self.PluginTypes] |
1175 blocktypes = [category for category in BlockTypes + self.PluginTypes] |
1166 project = self.GetProject(debug) |
1176 project = self.GetProject(debug) |
1167 if project is not None: |
1177 if project is not None: |
1168 blocktypes.append({"name" : "User-defined POUs", "list": project.GetCustomBlockTypes(name, type == "function" or words[0] == "T")}) |
1178 blocktypes.append({"name" : USER_DEFINED_POUS, "list": project.GetCustomBlockTypes(name, type == "function" or words[0] == "T")}) |
1169 return blocktypes |
1179 return blocktypes |
1170 |
1180 |
1171 # Return Function Block types checking for recursion |
1181 # Return Function Block types checking for recursion |
1172 def GetFunctionBlockTypes(self, tagname = "", debug = False): |
1182 def GetFunctionBlockTypes(self, tagname = "", debug = False): |
1173 blocktypes = [] |
1183 blocktypes = [] |