diff -r add8e391e00c -r 40b91ba978db PLCControler.py --- a/PLCControler.py Tue Nov 13 17:21:30 2007 +0100 +++ b/PLCControler.py Fri Nov 16 17:43:32 2007 +0100 @@ -167,8 +167,6 @@ self.FilePath = "" self.FileName = "" self.ProgramFilePath = "" - self.ElementsOpened = [] - self.CurrentElementEditing = None self.RefreshPouUsingTree() self.RefreshBlockTypes() @@ -382,15 +380,6 @@ #------------------------------------------------------------------------------- # Project Pous management functions #------------------------------------------------------------------------------- - - def RemoveElementEditing(self, index): - self.ElementsOpened.pop(index) - if self.CurrentElementEditing > index: - self.CurrentElementEditing -= 1 - if len(self.ElementsOpened) > 0: - self.CurrentElementEditing = max(0, min(self.CurrentElementEditing, len(self.ElementsOpened) - 1)) - else: - self.CurrentElementEditing = None # Add a Pou to Project def ProjectAddPou(self, pou_name, pou_type, body_type): @@ -404,12 +393,6 @@ # Remove a pou from project def ProjectRemovePou(self, pou_name): - # Search if the pou removed is currently opened - for i, element in enumerate(self.ElementsOpened): - words = element.split("::") - if words[0] == "P" and words[1] == pou_name: - self.RemoveElementEditing(i) - # Remove pou from project self.Project.removePou(pou_name) self.RefreshPouUsingTree() self.RefreshBlockTypes() @@ -424,11 +407,6 @@ # Remove a configuration from project def ProjectRemoveConfiguration(self, config_name): - # Search if the pou removed is currently opened - for i, element in enumerate(self.ElementsOpened): - words = element.split("::") - if words[0] == "C" and words[1] == config_name: - self.RemoveElementEditing(i) self.Project.removeConfiguration(config_name) self.BufferProject() @@ -441,11 +419,6 @@ # Remove a resource from a configuration of the project def ProjectRemoveConfigurationResource(self, config_name, resource_name): - # Search if the pou removed is currently opened - for i, element in enumerate(self.ElementsOpened): - words = element.split("::") - if words[0] == "R" and words[1] == config_name and words[2] == resource_name: - self.RemoveElementEditing(i) self.Project.removeConfigurationResource(config_name, resource_name) self.BufferProject() @@ -457,11 +430,6 @@ # Remove a Transition from a Project Pou def ProjectRemovePouTransition(self, pou_name, transition_name): - # Search if the pou removed is currently opened - for i, element in enumerate(self.ElementsOpened): - words = element.split("::") - if words[0] == "T" and words[1] == pou_name and words[2] == transition_name: - self.RemoveElementEditing(i) pou = self.Project.getPou(pou_name) pou.removeTransition(transition_name) self.BufferProject() @@ -488,16 +456,6 @@ # Found the pou corresponding to old name and change its name to new name pou = self.Project.getPou(old_name) pou.setName(new_name) - # If pou is currently opened, change its name in the list of opened pous - for idx, element in enumerate(self.ElementsOpened): - words = element.split("::") - if words[0] in ["P","T","A"] and words[1] == old_name: - if words[0] == "P": - self.ElementsOpened[idx] = self.ComputePouName(new_name) - elif words[0] == "T": - self.ElementsOpened[idx] = self.ComputePouTransitionName(new_name, words[2]) - else: - self.ElementsOpened[idx] = self.ComputePouActionName(new_name, words[2]) self.Project.updateElementName(old_name, new_name) self.RefreshPouUsingTree() self.RefreshBlockTypes() @@ -509,12 +467,6 @@ pou = self.Project.getPou(pou_name) transition = pou.getTransition(old_name) transition.setName(new_name) - # If pou transition is currently opened, change its name in the list of opened elements - old_computedname = self.ComputePouTransitionName(pou_name, old_name) - new_computedname = self.ComputePouTransitionName(pou_name, new_name) - if old_computedname in self.ElementsOpened: - idx = self.ElementsOpened.index(old_computedname) - self.ElementsOpened[idx] = new_computedname pou.updateElementName(old_name, new_name) self.BufferProject() @@ -524,12 +476,6 @@ pou = self.Project.getPou(pou_name) action = pou.getAction(old_name) action.setName(new_name) - # If pou action is currently opened, change its name in the list of opened elements - old_computedname = self.ComputePouActionName(pou_name, old_name) - new_computedname = self.ComputePouActionName(pou_name, new_name) - if old_computedname in self.ElementsOpened: - idx = self.ElementsOpened.index(old_computedname) - self.ElementsOpened[idx] = new_computedname pou.updateElementName(old_name, new_name) self.BufferProject() @@ -549,14 +495,6 @@ # Found the configuration corresponding to old name and change its name to new name configuration = self.Project.getConfiguration(old_name) configuration.setName(new_name) - # If configuration is currently opened, change its name in the list of opened elements - for idx, element in enumerate(self.ElementsOpened): - words = element.split("::") - if words[0] in ["C","R"] and words[1] == old_name: - if words[0] == "C": - self.ElementsOpened[idx] = self.ComputeConfigurationName(new_name) - else: - self.ElementsOpened[idx] = self.ComputeConfigurationResourceName(new_name, words[2]) self.BufferProject() # Change the name of a configuration resource @@ -564,12 +502,6 @@ # Found the resource corresponding to old name and change its name to new name resource = self.Project.getConfigurationResource(config_name) resource.setName(new_name) - # If resource is currently opened, change its name in the list of opened elements - old_computedname = self.ComputeConfigurationResourceName(config_name, old_name) - new_computedname = self.ComputeConfigurationResourceName(config_name, new_name) - if old_computedname in self.ElementsOpened: - idx = self.ElementsOpened.index(old_computedname) - self.ElementsOpened[idx] = new_computedname self.BufferProject() # Return the type of the pou given by its name @@ -829,8 +761,8 @@ if self.Project: self.Project.updateElementName(old_name, new_name) - def UpdateCurrentPouEditingUsedVariable(self, old_name, new_name): - pou = self.GetCurrentElementEditing() + def UpdateEditedElementUsedVariable(self, tagname, old_name, new_name): + pou = self.GetEditedElement(tagname) if pou: pou.updateElementName(old_name, new_name) @@ -885,63 +817,57 @@ BlockTypes[-1]["list"].append(block_infos) # Return Block types checking for recursion - def GetBlockTypes(self): - if self.CurrentElementEditing != None: - if self.Project: - current_name = self.ElementsOpened[self.CurrentElementEditing] - words = current_name.split("::") + def GetBlockTypes(self, tagname = ""): + if self.Project: + words = tagname.split("::") + if len(words) == 1: + name = current_name + else: + name = words[1] + type = self.GetPouType(name) + else: + name = "" + type = None + if type == "function": + blocktypes = [] + for category in BlockTypes[:-1] + PluginTypes: + cat = {"name" : category["name"], "list" : []} + for block in category["list"]: + if block["type"] == "function": + cat["list"].append(block) + if len(cat["list"]) > 0: + blocktypes.append(cat) + else: + blocktypes = [category for category in BlockTypes[:-1] + PluginTypes] + if self.Project: + blocktypes.append({"name" : "User-defined POUs", "list": []}) + for blocktype in BlockTypes[-1]["list"]: + if blocktype["name"] != name and not self.PouIsUsedBy(name, blocktype["name"]) and not (type == "function" and blocktype["type"] != "function"): + blocktypes[-1]["list"].append(blocktype) + return blocktypes + + # Return Function Block types checking for recursion + def GetFunctionBlockTypes(self, tagname = ""): + name = "" + type = None + if self.Project: + words = tagname.split("::") + if words[0] in ["P","T","A"]: if len(words) == 1: name = current_name else: name = words[1] type = self.GetPouType(name) - else: - name = "" - type = None - if type == "function": - blocktypes = [] - for category in BlockTypes[:-1] + PluginTypes: - cat = {"name" : category["name"], "list" : []} - for block in category["list"]: - if block["type"] == "function": - cat["list"].append(block) - if len(cat["list"]) > 0: - blocktypes.append(cat) - else: - blocktypes = [category for category in BlockTypes[:-1] + PluginTypes] - if self.Project: - blocktypes.append({"name" : "User-defined POUs", "list": []}) - for blocktype in BlockTypes[-1]["list"]: - if blocktype["name"] != name and not self.PouIsUsedBy(name, blocktype["name"]) and not (type == "function" and blocktype["type"] != "function"): - blocktypes[-1]["list"].append(blocktype) - return blocktypes - return [] - - # Return Function Block types checking for recursion - def GetFunctionBlockTypes(self): - if self.CurrentElementEditing != None: - name = "" - type = None - if self.Project: - current_name = self.ElementsOpened[self.CurrentElementEditing] - words = current_name.split("::") - if words[0] in ["P","T","A"]: - if len(words) == 1: - name = current_name - else: - name = words[1] - type = self.GetPouType(name) - blocktypes = [] - for category in BlockTypes[:-1]: - for block in category["list"]: - if block["type"] != "function": - blocktypes.append(block["name"]) - if self.Project: - for blocktype in BlockTypes[-1]["list"]: - if blocktype["name"] != name and not self.PouIsUsedBy(name, blocktype["name"]) and not (type == "function" and blocktype["type"] != "function"): - blocktypes.append(blocktype["name"]) - return blocktypes - return [] + blocktypes = [] + for category in BlockTypes[:-1]: + for block in category["list"]: + if block["type"] != "function": + blocktypes.append(block["name"]) + if self.Project: + for blocktype in BlockTypes[-1]["list"]: + if blocktype["name"] != name and not self.PouIsUsedBy(name, blocktype["name"]) and not (type == "function" and blocktype["type"] != "function"): + blocktypes.append(blocktype["name"]) + return blocktypes # Return Block types checking for recursion def GetBlockResource(self): @@ -957,20 +883,9 @@ return blocktypes #------------------------------------------------------------------------------- -# Project opened Pous management functions +# Project Element tag name computation functions #------------------------------------------------------------------------------- - # Return the list of pou names - def GetElementsOpenedNames(self): - names = [] - for pou_name in self.ElementsOpened: - words = pou_name.split("::") - if words[0] in ["P","C"]: - names.append(words[1]) - else: - names.append("%s-%s"%(words[1],words[2])) - return names - # Compute a pou transition name def ComputePouName(self, pou): return "P::%s" % pou @@ -991,238 +906,126 @@ def ComputeConfigurationResourceName(self, config, resource): return "R::%s::%s" % (config, resource) - # Open a pou by giving its name - def OpenElementEditing(self, name): - # If pou not opened yet - if name not in self.ElementsOpened: - # Add pou name to list of pou opened and make it current editing - self.ElementsOpened.append(name) - self.CurrentElementEditing = len(self.ElementsOpened) - 1 - return self.CurrentElementEditing - return None - - # Open a pou transition by giving pou and transition names - def OpenPouEditing(self, pou): - return self.OpenElementEditing(self.ComputePouName(pou)) - - # Open a pou transition by giving pou and transition names - def OpenPouTransitionEditing(self, pou, transition): - return self.OpenElementEditing(self.ComputePouTransitionName(pou, transition)) - - # Open a pou action by giving pou and action names - def OpenPouActionEditing(self, pou, action): - return self.OpenElementEditing(self.ComputePouActionName(pou, action)) - - # Open a configuration resource by giving configuration name - def OpenConfigurationEditing(self, config): - return self.OpenElementEditing(self.ComputeConfigurationName(config)) - - # Open a configuration resource by giving configuration and resource names - def OpenConfigurationResourceEditing(self, config, resource): - return self.OpenElementEditing(self.ComputeConfigurationResourceName(config, resource)) - - # Return if pou given by name is opened - def IsPouEditing(self, pou): - return self.ComputePouName(pou) in self.ElementsOpened - - # Return if pou transition given by pou and transition names is opened - def IsPouTransitionEditing(self, pou, transition): - return self.ComputePouTransitionName(pou, transition) in self.ElementsOpened - - # Return if pou action given by pou and action names is opened - def IsPouActionEditing(self, pou, action): - return self.ComputePouActionName(pou, action) in self.ElementsOpened - - # Return if pou action given by configuration name is opened - def IsConfigurationEditing(self, config): - return self.ComputeConfigurationName(config) in self.ElementsOpened - - # Return if pou action given by configuration and resource names is opened - def IsConfigurationResourceEditing(self, config, resource): - return self.ComputeConfigurationResourceName(config, resource) in self.ElementsOpened - - # Close current element editing - def CloseElementEditing(self): - # Remove pou from list of pou opened - self.ElementsOpened.pop(self.CurrentElementEditing) - # Update index of current element editing - if len(self.ElementsOpened) > 0: - self.CurrentElementEditing = min(self.CurrentElementEditing, len(self.ElementsOpened) - 1) - else: - self.CurrentElementEditing = None - - # Close current element editing - def CloseAllElements(self): - # Clear the pou opened list - self.ElementsOpened = [] - self.CurrentElementEditing = None - - # Change current element editing for pou given by name - def ChangeElementEditing(self, name): - # Verify that element is opened - if name in self.ElementsOpened: - # Change current element editing - self.CurrentElementEditing = self.ElementsOpened.index(name) - return self.CurrentElementEditing - return None - - # Change current element editing for pou given by pou name - def ChangePouEditing(self, pou): - return self.ChangeElementEditing(self.ComputePouName(pou)) - - # Change current element editing for transition given by pou and transition names - def ChangePouTransitionEditing(self, pou, transition): - return self.ChangeElementEditing(self.ComputePouTransitionName(pou, transition)) - - # Change current element editing for action given by pou and action names - def ChangePouActionEditing(self, pou, action): - return self.ChangeElementEditing(self.ComputePouActionName(pou, action)) - - # Change current element editing for configuration given by configuration name - def ChangeConfigurationEditing(self, config): - return self.ChangeElementEditing(self.ComputeConfigurationName(config)) - - # Change current element editing for resource given by configuration and resource names - def ChangeConfigurationResourceEditing(self, config, resource): - return self.ChangeElementEditing(self.ComputeConfigurationResourceName(config, resource)) - #------------------------------------------------------------------------------- # Project opened Pous management functions #------------------------------------------------------------------------------- - # Return current pou editing - def GetCurrentElementEditing(self): - # Verify that there's one editing and return it - if self.CurrentElementEditing != None: - name = self.ElementsOpened[self.CurrentElementEditing] - words = name.split("::") - if words[0] == "P": - return self.Project.getPou(words[1]) - if words[0] in ['T', 'A']: - pou = self.Project.getPou(words[1]) - if words[0] == 'T': - return pou.getTransition(words[2]) - elif words[0] == 'A': - return pou.getAction(words[2]) - elif words[0] == 'C': - return self.Project.getConfiguration(words[1]) - elif words[0] == 'R': - return self.Project.getConfigurationResource(words[1], words[2]) + # Return edited element + def GetEditedElement(self, tagname): + words = tagname.split("::") + if words[0] == "P": + return self.Project.getPou(words[1]) + if words[0] in ['T', 'A']: + pou = self.Project.getPou(words[1]) + if words[0] == 'T': + return pou.getTransition(words[2]) + elif words[0] == 'A': + return pou.getAction(words[2]) + elif words[0] == 'C': + return self.Project.getConfiguration(words[1]) + elif words[0] == 'R': + return self.Project.getConfigurationResource(words[1], words[2]) return None - # Return current pou editing name - def GetCurrentElementEditingName(self): - # Verify that there's one editing and return its name - if self.CurrentElementEditing != None: - name = self.ElementsOpened[self.CurrentElementEditing] - words = name.split("::") - if words[0] in ["P","C"]: - return words[1] + # Return edited element name + def GetEditedElementName(self, tagname): + words = tagname.split("::") + if words[0] in ["P","C"]: + return words[1] + else: + return words[2] + return None + + # Return edited element name and type + def GetEditedElementType(self, tagname): + words = tagname.split("::") + if words[0] in ["P","T","A"]: + return words[1], self.GetPouType(words[1]) + return None, None + + # Return language in which edited element is written + def GetEditedElementBodyType(self, tagname): + words = tagname.split("::") + if words[0] == "P": + return self.GetPouBodyType(words[1]) + elif words[0] == 'T': + return self.GetTransitionBodyType(words[1], words[2]) + elif words[0] == 'A': + return self.GetActionBodyType(words[1], words[2]) + return None + + # Return the edited element variables + def GetEditedElementInterfaceVars(self, tagname): + words = tagname.split("::") + if words[0] in ["P","T","A"]: + pou = self.Project.getPou(words[1]) + return self.GetPouInterfaceVars(pou) + return [] + + # Return the edited element return type + def GetEditedElementInterfaceReturnType(self, tagname): + words = tagname.split("::") + if words[0] == "P": + pou = self.Project.getPou(words[1]) + return self.GetPouInterfaceReturnType(pou) + elif words[0] == 'T': + return "BOOL" + return None + + # Change the edited element taxt + def SetEditedElementText(self, tagname, text): + element = self.GetEditedElement(tagname) + if element != None: + element.setText(text) + self.RefreshPouUsingTree() + + # Return the edited element text + def GetEditedElementText(self, tagname): + element = self.GetEditedElement(tagname) + if element != None: + return element.getText() + return "" + + # Return the edited element transitions + def GetEditedElementTransitions(self, tagname): + pou = self.GetEditedElement(tagname) + if pou != None and pou.getBodyType() == "SFC": + transitions = [] + for transition in pou.getTransitionList(): + transitions.append(transition.getName()) + return transitions + return [] + + # Return edited element transitions + def GetEditedElementActions(self, tagname): + pou = self.GetEditedElement(tagname) + if pou != None and pou.getBodyType() == "SFC": + actions = [] + for action in pou.getActionList(): + actions.append(action.getName()) + return actions + return [] + + # Return the names of the pou elements + def GetEditedElementVariables(self, tagname): + words = tagname.split("::") + if words[0] in ["P","T","A"]: + return self.GetProjectPouVariables(words[1]) + return [] + + # Return the current pou editing informations + def GetEditedElementInstanceInfos(self, tagname, id = None, exclude = []): + infos = {} + instance = None + element = self.GetEditedElement(tagname) + if element is not None: + # if id is defined + if id is not None: + instance = element.getInstance(id) else: - return words[2] - return None - - # Replace the index of current pou editing by the one given - def RefreshCurrentElementEditing(self, index): - self.CurrentElementEditing = index - - # Return current pou editing name and type - def GetCurrentElementEditingType(self): - if self.CurrentElementEditing != None: - name = self.ElementsOpened[self.CurrentElementEditing] - words = name.split("::") - if words[0] in ["P","T","A"]: - return words[1], self.GetPouType(words[1]) - return None, None - - # Return language in which current pou editing is written - def GetCurrentElementEditingBodyType(self): - if self.CurrentElementEditing != None: - name = self.ElementsOpened[self.CurrentElementEditing] - words = name.split("::") - if words[0] == "P": - return self.GetPouBodyType(words[1]) - elif words[0] == 'T': - return self.GetTransitionBodyType(words[1], words[2]) - elif words[0] == 'A': - return self.GetActionBodyType(words[1], words[2]) - return None - - # Return the variables of the current pou editing - def GetCurrentElementEditingInterfaceVars(self): - if self.CurrentElementEditing != None: - current_name = self.ElementsOpened[self.CurrentElementEditing] - words = current_name.split("::") - if words[0] in ["P","T","A"]: - pou = self.Project.getPou(words[1]) - return self.GetPouInterfaceVars(pou) - return [] - - # Return the return type of the current pou editing - def GetCurrentElementEditingInterfaceReturnType(self): - if self.CurrentElementEditing != None: - current_name = self.ElementsOpened[self.CurrentElementEditing] - words = current_name.split("::") - if words[0] == "P": - pou = self.Project.getPou(words[1]) - return self.GetPouInterfaceReturnType(pou) - elif words[0] == 'T': - return "BOOL" - return None - - # Change the text of the current pou editing - def SetCurrentElementEditingText(self, text): - if self.CurrentElementEditing != None: - self.GetCurrentElementEditing().setText(text) - self.RefreshPouUsingTree() - - # Return the current pou editing text - def GetCurrentElementEditingText(self): - if self.CurrentElementEditing != None: - return self.GetCurrentElementEditing().getText() - return "" - - # Return the current pou editing transitions - def GetCurrentElementEditingTransitions(self): - if self.CurrentElementEditing != None: - pou = self.GetCurrentElementEditing() - if pou.getBodyType() == "SFC": - transitions = [] - for transition in pou.getTransitionList(): - transitions.append(transition.getName()) - return transitions - return [] - - # Return the current pou editing transitions - def GetCurrentElementEditingActions(self): - if self.CurrentElementEditing != None: - pou = self.GetCurrentElementEditing() - if pou.getBodyType() == "SFC": - actions = [] - for action in pou.getActionList(): - actions.append(action.getName()) - return actions - return [] - - # Return the names of the pou elements - def GetCurrentElementEditingVariables(self): - if self.CurrentElementEditing != None: - current_name = self.ElementsOpened[self.CurrentElementEditing] - words = current_name.split("::") - if words[0] in ["P","T","A"]: - return self.GetProjectPouVariables(words[1]) - return [] - - # Return the current pou editing informations - def GetCurrentElementEditingInstanceInfos(self, id = None, exclude = []): - infos = {} - # if id is defined - if id != None: - instance = self.GetCurrentElementEditing().getInstance(id) - else: - instance = self.GetCurrentElementEditing().getRandomInstance(exclude) - if instance: - if id != None: + instance = element.getRandomInstance(exclude) + if instance is not None: + if id is not None: infos["id"] = id else: infos["id"] = instance.getLocalId() @@ -1261,7 +1064,7 @@ infos["connectors"]["outputs"].append(connector) elif isinstance(instance, plcopen.inVariable): infos["name"] = instance.getExpression() - infos["value_type"] = self.GetCurrentPouVarValueType(infos["name"]) + infos["value_type"] = self.GetEditedElementVarValueType(tagname, infos["name"]) infos["type"] = "input" executionOrder = instance.getExecutionOrderId() if executionOrder is not None: @@ -1274,7 +1077,7 @@ infos["connector"]["edge"] = instance.getConnectorEdge() elif isinstance(instance, plcopen.outVariable): infos["name"] = instance.getExpression() - infos["value_type"] = self.GetCurrentPouVarValueType(infos["name"]) + infos["value_type"] = self.GetEditedElementVarValueType(tagname, infos["name"]) infos["type"] = "output" executionOrder = instance.getExecutionOrderId() if executionOrder is not None: @@ -1293,7 +1096,7 @@ infos["connector"]["links"].append(dic) elif isinstance(instance, plcopen.inOutVariable): infos["name"] = instance.getExpression() - infos["value_type"] = self.GetCurrentPouVarValueType(infos["name"]) + infos["value_type"] = self.GetEditedElementVarValueType(tagname, infos["name"]) infos["type"] = "inout" executionOrder = instance.getExecutionOrderId() if executionOrder is not None: @@ -1510,16 +1313,19 @@ return infos return False - def ClearCurrentExecutionOrder(self): - self.GetCurrentElementEditing().resetExecutionOrder() - - def ResetCurrentExecutionOrder(self): - self.GetCurrentElementEditing().compileExecutionOrder() + def ClearEditedElementExecutionOrder(self, tagname): + element = self.GetEditedElement(tagname) + if element is not None: + element.resetExecutionOrder() + + def ResetEditedElementExecutionOrder(self, tagname): + element = self.GetEditedElement(tagname) + if element is not None: + element.compileExecutionOrder() # Return the variable type of the given pou - def GetCurrentPouVarValueType(self, varname): - current_name = self.ElementsOpened[self.CurrentElementEditing] - words = current_name.split("::") + def GetEditedElementVarValueType(self, tagname, varname): + words = tagname.split("::") if words[0] in ["P","T","A"]: pou = self.Project.getPou(words[1]) for type, varlist in pou.getVars(): @@ -1548,521 +1354,556 @@ connection.setConnectionParameter(idx, None) idx += 1 - def AddCurrentElementEditingBlock(self, id, blocktype, blockname = None): - block = plcopen.block() - block.setLocalId(id) - block.setTypeName(blocktype) - if blockname: - block.setInstanceName(blockname) - element = self.GetCurrentElementEditing() - blocktype_infos = GetBlockType(blocktype) - if blocktype_infos["type"] != "function": - if self.CurrentElementEditing != None: - name = self.ElementsOpened[self.CurrentElementEditing] - words = name.split("::") - if words[0] in ["P","T","A"]: - pou = self.Project.getPou(words[1]) - pou.addPouVar(blocktype, blockname) - element.addInstance("block", block) - self.RefreshPouUsingTree() - - def SetCurrentElementEditingBlockInfos(self, id, infos): - block = self.GetCurrentElementEditing().getInstance(id) - if "name" in infos or "type" in infos: - old_name = block.getInstanceName() - old_type = block.getTypeName() - new_name = infos.get("name", old_name) - new_type = infos.get("type", old_type) - self.GetCurrentElementEditing().changePouVar(old_type, old_name, new_type, new_name) - for param, value in infos.items(): - if param == "name": - block.setInstanceName(value) - elif param == "type": - block.setTypeName(value) - elif param == "executionOrder" and block.getExecutionOrderId() != value: - self.GetCurrentElementEditing().setElementExecutionOrder(block, value) - elif param == "height": - block.setHeight(value) - elif param == "width": - block.setWidth(value) - elif param == "x": - block.setX(value) - elif param == "y": - block.setY(value) - elif param == "connectors": - block.inputVariables.setVariable([]) - block.outputVariables.setVariable([]) - for connector in value["inputs"]: - variable = plcopen.inputVariables_variable() - variable.setFormalParameter(connector.GetName()) - if connector.IsNegated(): - variable.setNegated(True) - if connector.GetEdge() != "none": - variable.setConnectorEdge(connector.GetEdge()) - position = connector.GetRelPosition() - variable.connectionPointIn.setRelPosition(position.x, position.y) - self.SetConnectionWires(variable.connectionPointIn, connector) - block.inputVariables.appendVariable(variable) - for connector in value["outputs"]: - variable = plcopen.outputVariables_variable() - variable.setFormalParameter(connector.GetName()) - if connector.IsNegated(): - variable.setNegated(True) - if connector.GetEdge() != "none": - variable.setConnectorEdge(connector.GetEdge()) - position = connector.GetRelPosition() - variable.addConnectionPointOut() - variable.connectionPointOut.setRelPosition(position.x, position.y) - block.outputVariables.appendVariable(variable) - self.RefreshPouUsingTree() + def AddEditedElementBlock(self, tagname, id, blocktype, blockname = None): + element = self.GetEditedElement(tagname) + if element is not None: + block = plcopen.block() + block.setLocalId(id) + block.setTypeName(blocktype) + blocktype_infos = GetBlockType(blocktype) + if blocktype_infos["type"] != "function" and blockname is not None: + block.setInstanceName(blockname) + element.addPouVar(blocktype, blockname) + element.addInstance("block", block) + self.RefreshPouUsingTree() + + def SetEditedElementBlockInfos(self, tagname, id, infos): + element = self.GetEditedElement(tagname) + if element is not None: + block = element.getInstance(id) + if "name" in infos or "type" in infos: + old_name = block.getInstanceName() + old_type = block.getTypeName() + new_name = infos.get("name", old_name) + new_type = infos.get("type", old_type) + self.GetEditedElement(tagname).changePouVar(old_type, old_name, new_type, new_name) + for param, value in infos.items(): + if param == "name": + block.setInstanceName(value) + elif param == "type": + block.setTypeName(value) + elif param == "executionOrder" and block.getExecutionOrderId() != value: + self.GetEditedElement(tagname).setElementExecutionOrder(block, value) + elif param == "height": + block.setHeight(value) + elif param == "width": + block.setWidth(value) + elif param == "x": + block.setX(value) + elif param == "y": + block.setY(value) + elif param == "connectors": + block.inputVariables.setVariable([]) + block.outputVariables.setVariable([]) + for connector in value["inputs"]: + variable = plcopen.inputVariables_variable() + variable.setFormalParameter(connector.GetName()) + if connector.IsNegated(): + variable.setNegated(True) + if connector.GetEdge() != "none": + variable.setConnectorEdge(connector.GetEdge()) + position = connector.GetRelPosition() + variable.connectionPointIn.setRelPosition(position.x, position.y) + self.SetConnectionWires(variable.connectionPointIn, connector) + block.inputVariables.appendVariable(variable) + for connector in value["outputs"]: + variable = plcopen.outputVariables_variable() + variable.setFormalParameter(connector.GetName()) + if connector.IsNegated(): + variable.setNegated(True) + if connector.GetEdge() != "none": + variable.setConnectorEdge(connector.GetEdge()) + position = connector.GetRelPosition() + variable.addConnectionPointOut() + variable.connectionPointOut.setRelPosition(position.x, position.y) + block.outputVariables.appendVariable(variable) + self.RefreshPouUsingTree() - def AddCurrentElementEditingVariable(self, id, type): - if type == INPUT: - name = "inVariable" - variable = plcopen.inVariable() - elif type == OUTPUT: - name = "outVariable" - variable = plcopen.outVariable() - elif type == INOUT: - name = "inOutVariable" - variable = plcopen.inOutVariable() - variable.setLocalId(id) - self.GetCurrentElementEditing().addInstance(name, variable) + def AddEditedElementVariable(self, tagname, id, type): + element = self.GetEditedElement(tagname) + if element is not None: + if type == INPUT: + name = "inVariable" + variable = plcopen.inVariable() + elif type == OUTPUT: + name = "outVariable" + variable = plcopen.outVariable() + elif type == INOUT: + name = "inOutVariable" + variable = plcopen.inOutVariable() + variable.setLocalId(id) + element.addInstance(name, variable) - def SetCurrentElementEditingVariableInfos(self, id, infos): - variable = self.GetCurrentElementEditing().getInstance(id) - for param, value in infos.items(): - if param == "name": - variable.setExpression(value) - elif param == "executionOrder" and variable.getExecutionOrderId() != value: - self.GetCurrentElementEditing().setElementExecutionOrder(variable, value) - elif param == "height": - variable.setHeight(value) - elif param == "width": - variable.setWidth(value) - elif param == "x": - variable.setX(value) - elif param == "y": - variable.setY(value) - elif param == "connectors": - if isinstance(variable, plcopen.inVariable): - if value["output"].IsNegated(): - variable.setNegated(True) - if value["output"].GetEdge() != "none": - variable.setConnectorEdge(value["output"].GetEdge()) - position = value["output"].GetRelPosition() - variable.addConnectionPointOut() - variable.connectionPointOut.setRelPosition(position.x, position.y) - elif isinstance(variable, plcopen.outVariable): - if value["input"].IsNegated(): - variable.setNegated(True) - if value["input"].GetEdge() != "none": - variable.setConnectorEdge(value["input"].GetEdge()) - position = value["input"].GetRelPosition() - variable.addConnectionPointIn() - variable.connectionPointIn.setRelPosition(position.x, position.y) - self.SetConnectionWires(variable.connectionPointIn, value["input"]) - elif isinstance(variable, plcopen.inOutVariable): - if value["input"].IsNegated(): - variable.setNegatedIn(True) - if value["input"].GetEdge() != "none": - variable.setInputEdge(value["input"].GetEdge()) - if value["output"].IsNegated(): - variable.setNegatedOut(True) - if value["output"].GetEdge() != "none": - variable.setOutputEdge(value["output"].GetEdge()) - position = value["output"].GetRelPosition() - variable.addConnectionPointOut() - variable.connectionPointOut.setRelPosition(position.x, position.y) - position = value["input"].GetRelPosition() - variable.addConnectionPointIn() - variable.connectionPointIn.setRelPosition(position.x, position.y) - self.SetConnectionWires(variable.connectionPointIn, value["input"]) - - - def AddCurrentElementEditingConnection(self, id, type): - if type == CONNECTOR: - name = "connector" - connection = plcopen.connector() - elif type == CONTINUATION: - name = "continuation" - connection = plcopen.continuation() - connection.setLocalId(id) - self.GetCurrentElementEditing().addInstance(name, connection) + def SetEditedElementVariableInfos(self, tagname, id, infos): + element = self.GetEditedElement(tagname) + if element is not None: + variable = element.getInstance(id) + for param, value in infos.items(): + if param == "name": + variable.setExpression(value) + elif param == "executionOrder" and variable.getExecutionOrderId() != value: + self.GetEditedElement(tagname).setElementExecutionOrder(variable, value) + elif param == "height": + variable.setHeight(value) + elif param == "width": + variable.setWidth(value) + elif param == "x": + variable.setX(value) + elif param == "y": + variable.setY(value) + elif param == "connectors": + if isinstance(variable, plcopen.inVariable): + if value["output"].IsNegated(): + variable.setNegated(True) + if value["output"].GetEdge() != "none": + variable.setConnectorEdge(value["output"].GetEdge()) + position = value["output"].GetRelPosition() + variable.addConnectionPointOut() + variable.connectionPointOut.setRelPosition(position.x, position.y) + elif isinstance(variable, plcopen.outVariable): + if value["input"].IsNegated(): + variable.setNegated(True) + if value["input"].GetEdge() != "none": + variable.setConnectorEdge(value["input"].GetEdge()) + position = value["input"].GetRelPosition() + variable.addConnectionPointIn() + variable.connectionPointIn.setRelPosition(position.x, position.y) + self.SetConnectionWires(variable.connectionPointIn, value["input"]) + elif isinstance(variable, plcopen.inOutVariable): + if value["input"].IsNegated(): + variable.setNegatedIn(True) + if value["input"].GetEdge() != "none": + variable.setInputEdge(value["input"].GetEdge()) + if value["output"].IsNegated(): + variable.setNegatedOut(True) + if value["output"].GetEdge() != "none": + variable.setOutputEdge(value["output"].GetEdge()) + position = value["output"].GetRelPosition() + variable.addConnectionPointOut() + variable.connectionPointOut.setRelPosition(position.x, position.y) + position = value["input"].GetRelPosition() + variable.addConnectionPointIn() + variable.connectionPointIn.setRelPosition(position.x, position.y) + self.SetConnectionWires(variable.connectionPointIn, value["input"]) + + def AddEditedElementConnection(self, tagname, id, type): + element = self.GetEditedElement(tagname) + if element is not None: + if type == CONNECTOR: + name = "connector" + connection = plcopen.connector() + elif type == CONTINUATION: + name = "continuation" + connection = plcopen.continuation() + connection.setLocalId(id) + element.addInstance(name, connection) - def SetCurrentElementEditingConnectionInfos(self, id, infos): - connection = self.GetCurrentElementEditing().getInstance(id) - for param, value in infos.items(): - if param == "name": - connection.setName(value) - elif param == "height": - connection.setHeight(value) - elif param == "width": - connection.setWidth(value) - elif param == "x": - connection.setX(value) - elif param == "y": - connection.setY(value) - elif param == "connector": - position = value.GetRelPosition() - if isinstance(connection, plcopen.continuation): - connection.addConnectionPointOut() - connection.connectionPointOut.setRelPosition(position.x, position.y) - elif isinstance(connection, plcopen.connector): - connection.addConnectionPointIn() - connection.connectionPointIn.setRelPosition(position.x, position.y) - self.SetConnectionWires(connection.connectionPointIn, value) - - def AddCurrentElementEditingComment(self, id): - comment = plcopen.comment() - comment.setLocalId(id) - self.GetCurrentElementEditing().addInstance("comment", comment) - - def SetCurrentElementEditingCommentInfos(self, id, infos): - comment = self.GetCurrentElementEditing().getInstance(id) - for param, value in infos.items(): - if param == "content": - comment.setContentText(value) - elif param == "height": - comment.setHeight(value) - elif param == "width": - comment.setWidth(value) - elif param == "x": - comment.setX(value) - elif param == "y": - comment.setY(value) - - def AddCurrentElementEditingPowerRail(self, id, type): - if type == LEFTRAIL: - name = "leftPowerRail" - powerrail = plcopen.leftPowerRail() - elif type == RIGHTRAIL: - name = "rightPowerRail" - powerrail = plcopen.rightPowerRail() - powerrail.setLocalId(id) - self.GetCurrentElementEditing().addInstance(name, powerrail) - - def SetCurrentElementEditingPowerRailInfos(self, id, infos): - powerrail = self.GetCurrentElementEditing().getInstance(id) - for param, value in infos.items(): - if param == "height": - powerrail.setHeight(value) - elif param == "width": - powerrail.setWidth(value) - elif param == "x": - powerrail.setX(value) - elif param == "y": - powerrail.setY(value) - elif param == "connectors": - if isinstance(powerrail, plcopen.leftPowerRail): - powerrail.setConnectionPointOut([]) - for connector in value: - position = connector.GetRelPosition() - connection = plcopen.leftPowerRail_connectionPointOut() - connection.setRelPosition(position.x, position.y) - powerrail.connectionPointOut.append(connection) - elif isinstance(powerrail, plcopen.rightPowerRail): - powerrail.setConnectionPointIn([]) - for connector in value: - position = connector.GetRelPosition() - connection = plcopen.connectionPointIn() - connection.setRelPosition(position.x, position.y) - self.SetConnectionWires(connection, connector) - powerrail.connectionPointIn.append(connection) - - def AddCurrentElementEditingContact(self, id): - contact = plcopen.contact() - contact.setLocalId(id) - self.GetCurrentElementEditing().addInstance("contact", contact) - - def SetCurrentElementEditingContactInfos(self, id, infos): - contact = self.GetCurrentElementEditing().getInstance(id) - for param, value in infos.items(): - if param == "name": - contact.setVariable(value) - elif param == "type": - if value == CONTACT_NORMAL: - contact.setNegated(False) - contact.setContactEdge("none") - elif value == CONTACT_REVERSE: - contact.setNegated(True) - contact.setContactEdge("none") - elif value == CONTACT_RISING: - contact.setNegated(False) - contact.setContactEdge("rising") - elif value == CONTACT_FALLING: - contact.setNegated(False) - contact.setContactEdge("falling") - elif param == "height": - contact.setHeight(value) - elif param == "width": - contact.setWidth(value) - elif param == "x": - contact.setX(value) - elif param == "y": - contact.setY(value) - elif param == "connectors": - input_connector = value["input"] - position = input_connector.GetRelPosition() - contact.addConnectionPointIn() - contact.connectionPointIn.setRelPosition(position.x, position.y) - self.SetConnectionWires(contact.connectionPointIn, input_connector) - output_connector = value["output"] - position = output_connector.GetRelPosition() - contact.addConnectionPointOut() - contact.connectionPointOut.setRelPosition(position.x, position.y) - - def AddCurrentElementEditingCoil(self, id): - coil = plcopen.coil() - coil.setLocalId(id) - self.GetCurrentElementEditing().addInstance("coil", coil) - - def SetCurrentElementEditingCoilInfos(self, id, infos): - coil = self.GetCurrentElementEditing().getInstance(id) - for param, value in infos.items(): - if param == "name": - coil.setVariable(value) - elif param == "type": - if value == COIL_NORMAL: - coil.setNegated(False) - coil.setCoilStorage("none") - elif value == COIL_REVERSE: - coil.setNegated(True) - coil.setCoilStorage("none") - elif value == COIL_SET: - coil.setNegated(False) - coil.setCoilStorage("set") - elif value == COIL_RESET: - coil.setNegated(False) - coil.setCoilStorage("reset") - elif param == "height": - coil.setHeight(value) - elif param == "width": - coil.setWidth(value) - elif param == "x": - coil.setX(value) - elif param == "y": - coil.setY(value) - elif param == "connectors": - input_connector = value["input"] - position = input_connector.GetRelPosition() - coil.addConnectionPointIn() - coil.connectionPointIn.setRelPosition(position.x, position.y) - self.SetConnectionWires(coil.connectionPointIn, input_connector) - output_connector = value["output"] - position = output_connector.GetRelPosition() - coil.addConnectionPointOut() - coil.connectionPointOut.setRelPosition(position.x, position.y) - - def AddCurrentElementEditingStep(self, id): - step = plcopen.step() - step.setLocalId(id) - self.GetCurrentElementEditing().addInstance("step", step) - - def SetCurrentElementEditingStepInfos(self, id, infos): - step = self.GetCurrentElementEditing().getInstance(id) - for param, value in infos.items(): - if param == "name": - step.setName(value) - elif param == "initial": - step.setInitialStep(value) - elif param == "height": - step.setHeight(value) - elif param == "width": - step.setWidth(value) - elif param == "x": - step.setX(value) - elif param == "y": - step.setY(value) - elif param == "connectors": - input_connector = value["input"] - if input_connector: + def SetEditedElementConnectionInfos(self, tagname, id, infos): + element = self.GetEditedElement(tagname) + if element is not None: + connection = element.getInstance(id) + for param, value in infos.items(): + if param == "name": + connection.setName(value) + elif param == "height": + connection.setHeight(value) + elif param == "width": + connection.setWidth(value) + elif param == "x": + connection.setX(value) + elif param == "y": + connection.setY(value) + elif param == "connector": + position = value.GetRelPosition() + if isinstance(connection, plcopen.continuation): + connection.addConnectionPointOut() + connection.connectionPointOut.setRelPosition(position.x, position.y) + elif isinstance(connection, plcopen.connector): + connection.addConnectionPointIn() + connection.connectionPointIn.setRelPosition(position.x, position.y) + self.SetConnectionWires(connection.connectionPointIn, value) + + def AddEditedElementComment(self, tagname, id): + element = self.GetEditedElement(tagname) + if element is not None: + comment = plcopen.comment() + comment.setLocalId(id) + element.addInstance("comment", comment) + + def SetEditedElementCommentInfos(self, tagname, id, infos): + element = self.GetEditedElement(tagname) + if element is not None: + comment = element.getInstance(id) + for param, value in infos.items(): + if param == "content": + comment.setContentText(value) + elif param == "height": + comment.setHeight(value) + elif param == "width": + comment.setWidth(value) + elif param == "x": + comment.setX(value) + elif param == "y": + comment.setY(value) + + def AddEditedElementPowerRail(self, tagname, id, type): + element = self.GetEditedElement(tagname) + if element is not None: + if type == LEFTRAIL: + name = "leftPowerRail" + powerrail = plcopen.leftPowerRail() + elif type == RIGHTRAIL: + name = "rightPowerRail" + powerrail = plcopen.rightPowerRail() + powerrail.setLocalId(id) + element.addInstance(name, powerrail) + + def SetEditedElementPowerRailInfos(self, tagname, id, infos): + element = self.GetEditedElement(tagname) + if element is not None: + powerrail = element.getInstance(id) + for param, value in infos.items(): + if param == "height": + powerrail.setHeight(value) + elif param == "width": + powerrail.setWidth(value) + elif param == "x": + powerrail.setX(value) + elif param == "y": + powerrail.setY(value) + elif param == "connectors": + if isinstance(powerrail, plcopen.leftPowerRail): + powerrail.setConnectionPointOut([]) + for connector in value: + position = connector.GetRelPosition() + connection = plcopen.leftPowerRail_connectionPointOut() + connection.setRelPosition(position.x, position.y) + powerrail.connectionPointOut.append(connection) + elif isinstance(powerrail, plcopen.rightPowerRail): + powerrail.setConnectionPointIn([]) + for connector in value: + position = connector.GetRelPosition() + connection = plcopen.connectionPointIn() + connection.setRelPosition(position.x, position.y) + self.SetConnectionWires(connection, connector) + powerrail.connectionPointIn.append(connection) + + def AddEditedElementEditingContact(self, tagname, id): + element = self.GetEditedElement(tagname) + if element is not None: + contact = plcopen.contact() + contact.setLocalId(id) + element.addInstance("contact", contact) + + def SetEditedElementContactInfos(self, tagname, id, infos): + element = self.GetEditedElement(tagname) + if element is not None: + contact = element.getInstance(id) + for param, value in infos.items(): + if param == "name": + contact.setVariable(value) + elif param == "type": + if value == CONTACT_NORMAL: + contact.setNegated(False) + contact.setContactEdge("none") + elif value == CONTACT_REVERSE: + contact.setNegated(True) + contact.setContactEdge("none") + elif value == CONTACT_RISING: + contact.setNegated(False) + contact.setContactEdge("rising") + elif value == CONTACT_FALLING: + contact.setNegated(False) + contact.setContactEdge("falling") + elif param == "height": + contact.setHeight(value) + elif param == "width": + contact.setWidth(value) + elif param == "x": + contact.setX(value) + elif param == "y": + contact.setY(value) + elif param == "connectors": + input_connector = value["input"] position = input_connector.GetRelPosition() - step.addConnectionPointIn() - step.connectionPointIn.setRelPosition(position.x, position.y) - self.SetConnectionWires(step.connectionPointIn, input_connector) - else: - step.deleteConnectionPointIn() - output_connector = value["output"] - if output_connector: + contact.addConnectionPointIn() + contact.connectionPointIn.setRelPosition(position.x, position.y) + self.SetConnectionWires(contact.connectionPointIn, input_connector) + output_connector = value["output"] position = output_connector.GetRelPosition() - step.addConnectionPointOut() - step.connectionPointOut.setRelPosition(position.x, position.y) - else: - step.deleteConnectionPointOut() - action_connector = value["action"] - if action_connector: - position = action_connector.GetRelPosition() - step.addConnectionPointOutAction() - step.connectionPointOutAction.setRelPosition(position.x, position.y) - else: - step.deleteConnectionPointOutAction() - - def AddCurrentElementEditingTransition(self, id): - transition = plcopen.transition() - transition.setLocalId(id) - self.GetCurrentElementEditing().addInstance("transition", transition) - - def SetCurrentElementEditingTransitionInfos(self, id, infos): - transition = self.GetCurrentElementEditing().getInstance(id) - for param, value in infos.items(): - if param == "type" and value != "connection": - transition.setConditionContent(value, infos["condition"]) - elif param == "height": - transition.setHeight(value) - elif param == "width": - transition.setWidth(value) - elif param == "x": - transition.setX(value) - elif param == "y": - transition.setY(value) - elif param == "priority": - if value != 0: - transition.setPriority(value) - else: - transition.setPriority(None) - elif param == "connectors": - input_connector = value["input"] - position = input_connector.GetRelPosition() - transition.addConnectionPointIn() - transition.connectionPointIn.setRelPosition(position.x, position.y) - self.SetConnectionWires(transition.connectionPointIn, input_connector) - output_connector = value["output"] - position = output_connector.GetRelPosition() - transition.addConnectionPointOut() - transition.connectionPointOut.setRelPosition(position.x, position.y) - if infos.get("type", None) == "connection": - transition.setConditionContent("connection", None) - connection_connector = value["connection"] - self.SetConnectionWires(transition, connection_connector) - - def AddCurrentElementEditingDivergence(self, id, type): - if type == SELECTION_DIVERGENCE: - name = "selectionDivergence" - divergence = plcopen.selectionDivergence() - elif type == SELECTION_CONVERGENCE: - name = "selectionConvergence" - divergence = plcopen.selectionConvergence() - elif type == SIMULTANEOUS_DIVERGENCE: - name = "simultaneousDivergence" - divergence = plcopen.simultaneousDivergence() - elif type == SIMULTANEOUS_CONVERGENCE: - name = "simultaneousConvergence" - divergence = plcopen.simultaneousConvergence() - divergence.setLocalId(id) - self.GetCurrentElementEditing().addInstance(name, divergence) - - def SetCurrentElementEditingDivergenceInfos(self, id, infos): - divergence = self.GetCurrentElementEditing().getInstance(id) - for param, value in infos.items(): - if param == "height": - divergence.setHeight(value) - elif param == "width": - divergence.setWidth(value) - elif param == "x": - divergence.setX(value) - elif param == "y": - divergence.setY(value) - elif param == "connectors": - input_connectors = value["inputs"] - if isinstance(divergence, (plcopen.selectionDivergence, plcopen.simultaneousDivergence)): - position = input_connectors[0].GetRelPosition() - divergence.addConnectionPointIn() - divergence.connectionPointIn.setRelPosition(position.x, position.y) - self.SetConnectionWires(divergence.connectionPointIn, input_connectors[0]) - else: - divergence.setConnectionPointIn([]) - for input_connector in input_connectors: + contact.addConnectionPointOut() + contact.connectionPointOut.setRelPosition(position.x, position.y) + + def AddEditedElementCoil(self, tagname, id): + element = self.GetEditedElement(tagname) + if element is not None: + coil = plcopen.coil() + coil.setLocalId(id) + element.addInstance("coil", coil) + + def SetEditedElementCoilInfos(self, tagname, id, infos): + element = self.GetEditedElement(tagname) + if element is not None: + coil = element.getInstance(id) + for param, value in infos.items(): + if param == "name": + coil.setVariable(value) + elif param == "type": + if value == COIL_NORMAL: + coil.setNegated(False) + coil.setCoilStorage("none") + elif value == COIL_REVERSE: + coil.setNegated(True) + coil.setCoilStorage("none") + elif value == COIL_SET: + coil.setNegated(False) + coil.setCoilStorage("set") + elif value == COIL_RESET: + coil.setNegated(False) + coil.setCoilStorage("reset") + elif param == "height": + coil.setHeight(value) + elif param == "width": + coil.setWidth(value) + elif param == "x": + coil.setX(value) + elif param == "y": + coil.setY(value) + elif param == "connectors": + input_connector = value["input"] + position = input_connector.GetRelPosition() + coil.addConnectionPointIn() + coil.connectionPointIn.setRelPosition(position.x, position.y) + self.SetConnectionWires(coil.connectionPointIn, input_connector) + output_connector = value["output"] + position = output_connector.GetRelPosition() + coil.addConnectionPointOut() + coil.connectionPointOut.setRelPosition(position.x, position.y) + + def AddEditedElementStep(self, tagname, id): + element = self.GetEditedElement(tagname) + if element is not None: + step = plcopen.step() + step.setLocalId(id) + element.addInstance("step", step) + + def SetEditedElementStepInfos(self, tagname, id, infos): + element = self.GetEditedElement(tagname) + if element is not None: + step = element.getInstance(id) + for param, value in infos.items(): + if param == "name": + step.setName(value) + elif param == "initial": + step.setInitialStep(value) + elif param == "height": + step.setHeight(value) + elif param == "width": + step.setWidth(value) + elif param == "x": + step.setX(value) + elif param == "y": + step.setY(value) + elif param == "connectors": + input_connector = value["input"] + if input_connector: position = input_connector.GetRelPosition() - if isinstance(divergence, plcopen.selectionConvergence): - connection = plcopen.selectionConvergence_connectionPointIn() - else: - connection = plcopen.connectionPointIn() - connection.setRelPosition(position.x, position.y) - self.SetConnectionWires(connection, input_connector) - divergence.appendConnectionPointIn(connection) - output_connectors = value["outputs"] - if isinstance(divergence, (plcopen.selectionConvergence, plcopen.simultaneousConvergence)): - position = output_connectors[0].GetRelPosition() - divergence.addConnectionPointOut() - divergence.connectionPointOut.setRelPosition(position.x, position.y) - else: - divergence.setConnectionPointOut([]) - for output_connector in output_connectors: + step.addConnectionPointIn() + step.connectionPointIn.setRelPosition(position.x, position.y) + self.SetConnectionWires(step.connectionPointIn, input_connector) + else: + step.deleteConnectionPointIn() + output_connector = value["output"] + if output_connector: position = output_connector.GetRelPosition() - if isinstance(divergence, plcopen.selectionDivergence): - connection = plcopen.selectionDivergence_connectionPointOut() - else: - connection = plcopen.simultaneousDivergence_connectionPointOut() - connection.setRelPosition(position.x, position.y) - divergence.appendConnectionPointOut(connection) - - def AddCurrentElementEditingJump(self, id): - jump = plcopen.jumpStep() - jump.setLocalId(id) - self.GetCurrentElementEditing().addInstance("jumpStep", jump) - - def SetCurrentElementEditingJumpInfos(self, id, infos): - jump = self.GetCurrentElementEditing().getInstance(id) - for param, value in infos.items(): - if param == "target": - jump.setTargetName(value) - elif param == "height": - jump.setHeight(value) - elif param == "width": - jump.setWidth(value) - elif param == "x": - jump.setX(value) - elif param == "y": - jump.setY(value) - elif param == "connector": - position = value.GetRelPosition() - jump.addConnectionPointIn() - jump.connectionPointIn.setRelPosition(position.x, position.y) - self.SetConnectionWires(jump.connectionPointIn, value) + step.addConnectionPointOut() + step.connectionPointOut.setRelPosition(position.x, position.y) + else: + step.deleteConnectionPointOut() + action_connector = value["action"] + if action_connector: + position = action_connector.GetRelPosition() + step.addConnectionPointOutAction() + step.connectionPointOutAction.setRelPosition(position.x, position.y) + else: + step.deleteConnectionPointOutAction() + + def AddEditedElementTransition(self, tagname, id): + element = self.GetEditedElement(tagname) + if element is not None: + transition = plcopen.transition() + transition.setLocalId(id) + element.addInstance("transition", transition) + + def SetEditedElementTransitionInfos(self, tagname, id, infos): + element = self.GetEditedElement(tagname) + if element is not None: + transition = element.getInstance(id) + for param, value in infos.items(): + if param == "type" and value != "connection": + transition.setConditionContent(value, infos["condition"]) + elif param == "height": + transition.setHeight(value) + elif param == "width": + transition.setWidth(value) + elif param == "x": + transition.setX(value) + elif param == "y": + transition.setY(value) + elif param == "priority": + if value != 0: + transition.setPriority(value) + else: + transition.setPriority(None) + elif param == "connectors": + input_connector = value["input"] + position = input_connector.GetRelPosition() + transition.addConnectionPointIn() + transition.connectionPointIn.setRelPosition(position.x, position.y) + self.SetConnectionWires(transition.connectionPointIn, input_connector) + output_connector = value["output"] + position = output_connector.GetRelPosition() + transition.addConnectionPointOut() + transition.connectionPointOut.setRelPosition(position.x, position.y) + if infos.get("type", None) == "connection": + transition.setConditionContent("connection", None) + connection_connector = value["connection"] + self.SetConnectionWires(transition, connection_connector) + + def AddEditedElementDivergence(self, tagname, id, type): + element = self.GetEditedElement(tagname) + if element is not None: + if type == SELECTION_DIVERGENCE: + name = "selectionDivergence" + divergence = plcopen.selectionDivergence() + elif type == SELECTION_CONVERGENCE: + name = "selectionConvergence" + divergence = plcopen.selectionConvergence() + elif type == SIMULTANEOUS_DIVERGENCE: + name = "simultaneousDivergence" + divergence = plcopen.simultaneousDivergence() + elif type == SIMULTANEOUS_CONVERGENCE: + name = "simultaneousConvergence" + divergence = plcopen.simultaneousConvergence() + divergence.setLocalId(id) + element.addInstance(name, divergence) + + def SetEditedElementDivergenceInfos(self, tagname, id, infos): + element = self.GetEditedElement(tagname) + if element is not None: + divergence = element.getInstance(id) + for param, value in infos.items(): + if param == "height": + divergence.setHeight(value) + elif param == "width": + divergence.setWidth(value) + elif param == "x": + divergence.setX(value) + elif param == "y": + divergence.setY(value) + elif param == "connectors": + input_connectors = value["inputs"] + if isinstance(divergence, (plcopen.selectionDivergence, plcopen.simultaneousDivergence)): + position = input_connectors[0].GetRelPosition() + divergence.addConnectionPointIn() + divergence.connectionPointIn.setRelPosition(position.x, position.y) + self.SetConnectionWires(divergence.connectionPointIn, input_connectors[0]) + else: + divergence.setConnectionPointIn([]) + for input_connector in input_connectors: + position = input_connector.GetRelPosition() + if isinstance(divergence, plcopen.selectionConvergence): + connection = plcopen.selectionConvergence_connectionPointIn() + else: + connection = plcopen.connectionPointIn() + connection.setRelPosition(position.x, position.y) + self.SetConnectionWires(connection, input_connector) + divergence.appendConnectionPointIn(connection) + output_connectors = value["outputs"] + if isinstance(divergence, (plcopen.selectionConvergence, plcopen.simultaneousConvergence)): + position = output_connectors[0].GetRelPosition() + divergence.addConnectionPointOut() + divergence.connectionPointOut.setRelPosition(position.x, position.y) + else: + divergence.setConnectionPointOut([]) + for output_connector in output_connectors: + position = output_connector.GetRelPosition() + if isinstance(divergence, plcopen.selectionDivergence): + connection = plcopen.selectionDivergence_connectionPointOut() + else: + connection = plcopen.simultaneousDivergence_connectionPointOut() + connection.setRelPosition(position.x, position.y) + divergence.appendConnectionPointOut(connection) + + def AddEditedElementJump(self, tagname, id): + element = self.GetEditedElement(tagname) + if element is not None: + jump = plcopen.jumpStep() + jump.setLocalId(id) + element.addInstance("jumpStep", jump) + + def SetEditedElementJumpInfos(self, tagname, id, infos): + element = self.GetEditedElement(tagname) + if element is not None: + jump = element.getInstance(id) + for param, value in infos.items(): + if param == "target": + jump.setTargetName(value) + elif param == "height": + jump.setHeight(value) + elif param == "width": + jump.setWidth(value) + elif param == "x": + jump.setX(value) + elif param == "y": + jump.setY(value) + elif param == "connector": + position = value.GetRelPosition() + jump.addConnectionPointIn() + jump.connectionPointIn.setRelPosition(position.x, position.y) + self.SetConnectionWires(jump.connectionPointIn, value) - def AddCurrentElementEditingActionBlock(self, id): - actionBlock = plcopen.actionBlock() - actionBlock.setLocalId(id) - self.GetCurrentElementEditing().addInstance("actionBlock", actionBlock) - - def SetCurrentElementEditingActionBlockInfos(self, id, infos): - actionBlock = self.GetCurrentElementEditing().getInstance(id) - for param, value in infos.items(): - if param == "actions": - actionBlock.setActions(value) - elif param == "height": - actionBlock.setHeight(value) - elif param == "width": - actionBlock.setWidth(value) - elif param == "x": - actionBlock.setX(value) - elif param == "y": - actionBlock.setY(value) - elif param == "connector": - position = value.GetRelPosition() - actionBlock.addConnectionPointIn() - actionBlock.connectionPointIn.setRelPosition(position.x, position.y) - self.SetConnectionWires(actionBlock.connectionPointIn, value) - - def RemoveCurrentElementEditingInstance(self, id): - element = self.GetCurrentElementEditing() - instance = element.getInstance(id) - if isinstance(instance, plcopen.block): - blocktype = instance.getTypeName() - if self.CurrentElementEditing != None: - name = self.ElementsOpened[self.CurrentElementEditing] - words = name.split("::") - if words[0] in ["P","T","A"]: - pou = self.Project.getPou(words[1]) - pou.removePouVar(blocktype, instance.getInstanceName()) - element.removeInstance(id) - self.RefreshPouUsingTree() - - def GetCurrentResourceEditingVariables(self): + def AddEditedElementActionBlock(self, tagname, id): + element = self.GetEditedElement(tagname) + if element is not None: + actionBlock = plcopen.actionBlock() + actionBlock.setLocalId(id) + element.addInstance("actionBlock", actionBlock) + + def SetEditedElementActionBlockInfos(self, tagname, id, infos): + element = self.GetEditedElement(tagname) + if element is not None: + actionBlock = element.getInstance(id) + for param, value in infos.items(): + if param == "actions": + actionBlock.setActions(value) + elif param == "height": + actionBlock.setHeight(value) + elif param == "width": + actionBlock.setWidth(value) + elif param == "x": + actionBlock.setX(value) + elif param == "y": + actionBlock.setY(value) + elif param == "connector": + position = value.GetRelPosition() + actionBlock.addConnectionPointIn() + actionBlock.connectionPointIn.setRelPosition(position.x, position.y) + self.SetConnectionWires(actionBlock.connectionPointIn, value) + + def RemoveEditedElementInstance(self, tagname, id): + element = self.GetEditedElement(tagname) + if element is not None: + instance = element.getInstance(id) + if isinstance(instance, plcopen.block): + blocktype = instance.getTypeName() + element.removePouVar(blocktype, instance.getInstanceName()) + element.removeInstance(id) + self.RefreshPouUsingTree() + + def GetEditedResourceVariables(self, tagname): varlist = [] - name = self.ElementsOpened[self.CurrentElementEditing] - words = name.split("::") + words = tagname.split("::") for var in self.GetConfigurationGlobalVars(words[1]): if var["Type"] == "BOOL": varlist.append(var["Name"]) @@ -2071,85 +1912,87 @@ varlist.append(var["Name"]) return varlist - def SetCurrentResourceEditingInfos(self, tasks, instances): - resource = self.GetCurrentElementEditing() - resource.setTask([]) - resource.setPouInstance([]) - task_list = {} - for task in tasks: - new_task = plcopen.resource_task() - new_task.setName(task["Name"]) - if task["Single"] != "": - new_task.setSingle(task["Single"]) - result = duration_model.match(task["Interval"]).groups() - if reduce(lambda x, y: x or y != None, result): - values = [] - for value in result[:-1]: - if value != None: - values.append(int(value)) - else: - values.append(0) - values.append(int(float(result[-1]) * 1000)) - new_task.setInterval(time(*values)) - new_task.priority.setValue(int(task["Priority"])) - if task["Name"] != "": - task_list[task["Name"]] = new_task - resource.appendTask(new_task) - for instance in instances: - new_instance = plcopen.pouInstance() - new_instance.setName(instance["Name"]) - new_instance.setType(instance["Type"]) - if instance["Task"] != "": - task_list[instance["Task"]].appendPouInstance(new_instance) - else: - resource.appendPouInstance(new_instance) - - def GetCurrentResourceEditingInfos(self): - resource = self.GetCurrentElementEditing() - tasks = resource.getTask() - instances = resource.getPouInstance() - tasks_data = [] - instances_data = [] - for task in tasks: - new_task = {} - new_task["Name"] = task.getName() - single = task.getSingle() - if single: - new_task["Single"] = single - else: - new_task["Single"] = "" - interval = task.getInterval() - if interval: - text = "" - if interval.hour != 0: - text += "%dh"%interval.hour - if interval.minute != 0: - text += "%dm"%interval.minute - if interval.second != 0: - text += "%ds"%interval.second - if interval.microsecond != 0: - if interval.microsecond % 1000 != 0: - text += "%.3fms"%(float(interval.microsecond) / 1000) - else: - text += "%dms"%(interval.microsecond / 1000) - new_task["Interval"] = text - else: - new_task["Interval"] = "" - new_task["Priority"] = str(task.priority.getValue()) - tasks_data.append(new_task) - for instance in task.getPouInstance(): + def SetEditedResourceInfos(self, tasks, instances): + resource = self.GetEditedElement(tagname) + if resource is not None: + resource.setTask([]) + resource.setPouInstance([]) + task_list = {} + for task in tasks: + new_task = plcopen.resource_task() + new_task.setName(task["Name"]) + if task["Single"] != "": + new_task.setSingle(task["Single"]) + result = duration_model.match(task["Interval"]).groups() + if reduce(lambda x, y: x or y != None, result): + values = [] + for value in result[:-1]: + if value != None: + values.append(int(value)) + else: + values.append(0) + values.append(int(float(result[-1]) * 1000)) + new_task.setInterval(time(*values)) + new_task.priority.setValue(int(task["Priority"])) + if task["Name"] != "": + task_list[task["Name"]] = new_task + resource.appendTask(new_task) + for instance in instances: + new_instance = plcopen.pouInstance() + new_instance.setName(instance["Name"]) + new_instance.setType(instance["Type"]) + if instance["Task"] != "": + task_list[instance["Task"]].appendPouInstance(new_instance) + else: + resource.appendPouInstance(new_instance) + + def GetEditedResourceInfos(self, tagname): + resource = self.GetEditedElement(tagname) + if resource is not None: + tasks = resource.getTask() + instances = resource.getPouInstance() + tasks_data = [] + instances_data = [] + for task in tasks: + new_task = {} + new_task["Name"] = task.getName() + single = task.getSingle() + if single: + new_task["Single"] = single + else: + new_task["Single"] = "" + interval = task.getInterval() + if interval: + text = "" + if interval.hour != 0: + text += "%dh"%interval.hour + if interval.minute != 0: + text += "%dm"%interval.minute + if interval.second != 0: + text += "%ds"%interval.second + if interval.microsecond != 0: + if interval.microsecond % 1000 != 0: + text += "%.3fms"%(float(interval.microsecond) / 1000) + else: + text += "%dms"%(interval.microsecond / 1000) + new_task["Interval"] = text + else: + new_task["Interval"] = "" + new_task["Priority"] = str(task.priority.getValue()) + tasks_data.append(new_task) + for instance in task.getPouInstance(): + new_instance = {} + new_instance["Name"] = instance.getName() + new_instance["Type"] = instance.getType() + new_instance["Task"] = task.getName() + instances_data.append(new_instance) + for instance in instances: new_instance = {} new_instance["Name"] = instance.getName() new_instance["Type"] = instance.getType() - new_instance["Task"] = task.getName() + new_instance["Task"] = "" instances_data.append(new_instance) - for instance in instances: - new_instance = {} - new_instance["Name"] = instance.getName() - new_instance["Type"] = instance.getType() - new_instance["Task"] = "" - instances_data.append(new_instance) - return tasks_data, instances_data + return tasks_data, instances_data def OpenXMLFile(self, filepath): if self.VerifyXML: