PLCControler.py
changeset 151 aaa80b48bead
parent 145 4fb225afddf4
child 154 203c4acdaf27
equal deleted inserted replaced
150:f7832baaad84 151:aaa80b48bead
    20 #
    20 #
    21 #You should have received a copy of the GNU General Public
    21 #You should have received a copy of the GNU General Public
    22 #License along with this library; if not, write to the Free Software
    22 #License along with this library; if not, write to the Free Software
    23 #Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    23 #Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    24 
    24 
    25 from minixsv import pyxsval
       
    26 from xml.dom import minidom
    25 from xml.dom import minidom
    27 from types import StringType, UnicodeType
    26 from types import StringType, UnicodeType
    28 import cPickle
    27 import cPickle
    29 import os,sys,re
    28 import os,sys,re
    30 from time import localtime
    29 from time import localtime
    40 [ITEM_UNEDITABLE, ITEM_PROJECT, ITEM_POU, ITEM_CLASS, ITEM_VARIABLE,
    39 [ITEM_UNEDITABLE, ITEM_PROJECT, ITEM_POU, ITEM_CLASS, ITEM_VARIABLE,
    41  ITEM_TRANSITION, ITEM_ACTION, ITEM_CONFIGURATION, ITEM_RESOURCE, 
    40  ITEM_TRANSITION, ITEM_ACTION, ITEM_CONFIGURATION, ITEM_RESOURCE, 
    42  ITEM_DATATYPE] = range(10)
    41  ITEM_DATATYPE] = range(10)
    43 
    42 
    44 ScriptDirectory = os.path.split(os.path.realpath(__file__))[0]
    43 ScriptDirectory = os.path.split(os.path.realpath(__file__))[0]
    45 
       
    46 """
       
    47 pyxsval is not complete and the parts that are not supported print some error
       
    48 reports. This class is used for not displaying them
       
    49 """
       
    50 class HolePseudoFile:
       
    51     """ Base class for file like objects to facilitate StdOut for the Shell."""
       
    52     def __init__(self, output = None):
       
    53         if output is None: output = []
       
    54         self.output = output
       
    55 
       
    56     def writelines(self, l):
       
    57         map(self.write, l)
       
    58 
       
    59     def write(self, s):
       
    60         pass
       
    61 
       
    62     def flush(self):
       
    63         pass
       
    64     
       
    65     def isatty(self):
       
    66         return false
       
    67 
    44 
    68 #-------------------------------------------------------------------------------
    45 #-------------------------------------------------------------------------------
    69 #                         Undo Buffer for PLCOpenEditor
    46 #                         Undo Buffer for PLCOpenEditor
    70 #-------------------------------------------------------------------------------
    47 #-------------------------------------------------------------------------------
    71 
    48 
   162         self.LastNewIndex = 0
   139         self.LastNewIndex = 0
   163         self.Reset()
   140         self.Reset()
   164     
   141     
   165     # Reset PLCControler internal variables
   142     # Reset PLCControler internal variables
   166     def Reset(self):
   143     def Reset(self):
   167         self.VerifyXML = False
       
   168         self.Project = None
   144         self.Project = None
   169         self.ProjectBuffer = None
   145         self.ProjectBuffer = None
   170         self.Buffering = False
   146         self.Buffering = False
   171         self.FilePath = ""
   147         self.FilePath = ""
   172         self.FileName = ""
   148         self.FileName = ""
   191     # Create a new project by replacing the current one
   167     # Create a new project by replacing the current one
   192     def CreateNewProject(self, properties):
   168     def CreateNewProject(self, properties):
   193         # Create the project
   169         # Create the project
   194         self.Project = plcopen.project()
   170         self.Project = plcopen.project()
   195         properties["creationDateTime"] = datetime(*localtime()[:6])
   171         properties["creationDateTime"] = datetime(*localtime()[:6])
   196         self.Project.setFileHeader(properties)
   172         self.Project.setfileHeader(properties)
   197         self.Project.setContentHeader(properties)
   173         self.Project.setcontentHeader(properties)
   198         self.SetFilePath("")
   174         self.SetFilePath("")
   199         # Initialize the project buffer
   175         # Initialize the project buffer
   200         self.ProjectBuffer = UndoBuffer(self.Copy(self.Project), False)
   176         self.ProjectBuffer = UndoBuffer(self.Copy(self.Project), False)
   201         self.Buffering = False
   177         self.Buffering = False
   202     
   178     
   203     # Return project data type names
   179     # Return project data type names
   204     def GetProjectDataTypeNames(self):
   180     def GetProjectDataTypeNames(self):
   205         if self.Project:
   181         if self.Project:
   206             return [datatype.getName() for datatype in self.Project.getDataTypes()]
   182             return [datatype.getname() for datatype in self.Project.getdataTypes()]
   207         return []
   183         return []
   208     
   184     
   209     # Return project pou names
   185     # Return project pou names
   210     def GetProjectPouNames(self):
   186     def GetProjectPouNames(self):
   211         if self.Project:
   187         if self.Project:
   212             return [pou.getName() for pou in self.Project.getPous()]
   188             return [pou.getname() for pou in self.Project.getpous()]
   213         return []
   189         return []
   214     
   190     
   215     # Return project pou names
   191     # Return project pou names
   216     def GetProjectConfigNames(self):
   192     def GetProjectConfigNames(self):
   217         if self.Project:
   193         if self.Project:
   218             return [config.getName() for config in self.Project.getConfigurations()]
   194             return [config.getName() for config in self.Project.getconfigurations()]
   219         return []
   195         return []
   220     
   196     
   221     # Return project pou variables
   197     # Return project pou variables
   222     def GetProjectPouVariables(self, pou_name=None):
   198     def GetProjectPouVariables(self, pou_name=None):
   223         variables = []
   199         variables = []
   224         for pou in self.Project.getPous():
   200         for pou in self.Project.getpous():
   225             if not pou_name or pou_name == pou.getName():
   201             if not pou_name or pou_name == pou.getname():
   226                 variables.extend([var["Name"] for var in self.GetPouInterfaceVars(pou)])
   202                 variables.extend([var["Name"] for var in self.GetPouInterfaceVars(pou)])
   227                 for transition in pou.getTransitionList():
   203                 for transition in pou.gettransitionList():
   228                     variables.append(transition.getName())
   204                     variables.append(transition.getname())
   229                 for action in pou.getActionList():
   205                 for action in pou.getactionList():
   230                     variables.append(action.getName())
   206                     variables.append(action.getname())
   231         return variables
   207         return variables
   232     
   208     
   233     # Return if project is saved
   209     # Return if project is saved
   234     def ProjectIsSaved(self):
   210     def ProjectIsSaved(self):
   235         return self.ProjectBuffer.IsCurrentSaved()
   211         return self.ProjectBuffer.IsCurrentSaved()
   259             self.FileName = os.path.splitext(os.path.basename(filepath))[0]
   235             self.FileName = os.path.splitext(os.path.basename(filepath))[0]
   260     
   236     
   261     # Change project properties
   237     # Change project properties
   262     def SetProjectProperties(self, name = None, properties = None):
   238     def SetProjectProperties(self, name = None, properties = None):
   263         if name != None:
   239         if name != None:
   264             self.Project.setName(name)
   240             self.Project.setname(name)
   265         if properties != None:
   241         if properties != None:
   266             self.Project.setFileHeader(properties)
   242             self.Project.setfileHeader(properties)
   267             self.Project.setContentHeader(properties)
   243             self.Project.setcontentHeader(properties)
   268         if name != None or properties != None:
   244         if name != None or properties != None:
   269             self.BufferProject()
   245             self.BufferProject()
   270             
   246             
   271     # Return project properties
   247     # Return project properties
   272     def GetProjectProperties(self):
   248     def GetProjectProperties(self):
   273         properties = self.Project.getFileHeader()
   249         properties = self.Project.getfileHeader()
   274         properties.update(self.Project.getContentHeader())
   250         properties.update(self.Project.getcontentHeader())
   275         return properties
   251         return properties
   276     
   252     
   277     # Return project informations
   253     # Return project informations
   278     def GetProjectInfos(self):
   254     def GetProjectInfos(self):
   279         if self.Project:
   255         if self.Project:
   280             infos = {"name": self.Project.getName(), "type": ITEM_PROJECT}
   256             infos = {"name": self.Project.getname(), "type": ITEM_PROJECT}
   281             datatypes = {"name": "Data Types", "type": ITEM_UNEDITABLE, "values":[]}
   257             datatypes = {"name": "Data Types", "type": ITEM_UNEDITABLE, "values":[]}
   282             for datatype in self.Project.getDataTypes():
   258             for datatype in self.Project.getdataTypes():
   283                 datatypes["values"].append({"name": datatype.getName(), "type": ITEM_DATATYPE, "values": []})
   259                 datatypes["values"].append({"name": datatype.getname(), "type": ITEM_DATATYPE, "values": []})
   284             pou_types = {"function": {"name": "Functions", "type": ITEM_UNEDITABLE, "values":[]},
   260             pou_types = {"function": {"name": "Functions", "type": ITEM_UNEDITABLE, "values":[]},
   285                          "functionBlock": {"name": "Function Blocks", "type": ITEM_UNEDITABLE, "values":[]},
   261                          "functionBlock": {"name": "Function Blocks", "type": ITEM_UNEDITABLE, "values":[]},
   286                          "program": {"name": "Programs", "type": ITEM_UNEDITABLE, "values":[]}}
   262                          "program": {"name": "Programs", "type": ITEM_UNEDITABLE, "values":[]}}
   287             for pou in self.Project.getPous():
   263             for pou in self.Project.getpous():
   288                 pou_type = pou.getPouType().getValue()
   264                 pou_type = pou.getpouType()
   289                 pou_infos = {"name": pou.getName(), "type": ITEM_POU}
   265                 pou_infos = {"name": pou.getname(), "type": ITEM_POU}
   290                 pou_values = []
   266                 pou_values = []
   291                 if pou.getBodyType() == "SFC":
   267                 if pou.getbodyType() == "SFC":
   292                     transitions = []
   268                     transitions = []
   293                     for transition in pou.getTransitionList():
   269                     for transition in pou.gettransitionList():
   294                         transitions.append({"name": transition.getName(), "type": ITEM_TRANSITION, "values": []})
   270                         transitions.append({"name": transition.getname(), "type": ITEM_TRANSITION, "values": []})
   295                     pou_values.append({"name": "Transitions", "type": ITEM_UNEDITABLE, "values": transitions})
   271                     pou_values.append({"name": "Transitions", "type": ITEM_UNEDITABLE, "values": transitions})
   296                     actions = []
   272                     actions = []
   297                     for action in pou.getActionList():
   273                     for action in pou.getactionList():
   298                         actions.append({"name": action.getName(), "type": ITEM_ACTION, "values": []})
   274                         actions.append({"name": action.getname(), "type": ITEM_ACTION, "values": []})
   299                     pou_values.append({"name": "Actions", "type": ITEM_UNEDITABLE, "values": actions})
   275                     pou_values.append({"name": "Actions", "type": ITEM_UNEDITABLE, "values": actions})
   300                 if pou_type in pou_types:
   276                 if pou_type in pou_types:
   301                     pou_infos["values"] = pou_values
   277                     pou_infos["values"] = pou_values
   302                     pou_types[pou_type]["values"].append(pou_infos)
   278                     pou_types[pou_type]["values"].append(pou_infos)
   303             configurations = {"name": "Configurations", "type": ITEM_UNEDITABLE, "values": []}
   279             configurations = {"name": "Configurations", "type": ITEM_UNEDITABLE, "values": []}
   304             for config in self.Project.getConfigurations():
   280             for config in self.Project.getconfigurations():
   305                 config_name = config.getName()
   281                 config_name = config.getname()
   306                 config_infos = {"name": config_name, "type": ITEM_CONFIGURATION, "values": []}
   282                 config_infos = {"name": config_name, "type": ITEM_CONFIGURATION, "values": []}
   307                 resources = {"name": "Resources", "type": ITEM_UNEDITABLE, "values": []}
   283                 resources = {"name": "Resources", "type": ITEM_UNEDITABLE, "values": []}
   308                 for resource in config.getResource():
   284                 for resource in config.getresource():
   309                     resource_name = resource.getName()
   285                     resource_name = resource.getname()
   310                     resource_infos = {"name": resource_name, "type": ITEM_RESOURCE, "values": []}
   286                     resource_infos = {"name": resource_name, "type": ITEM_RESOURCE, "values": []}
   311                     resources["values"].append(resource_infos)
   287                     resources["values"].append(resource_infos)
   312                 config_infos["values"] = [resources]
   288                 config_infos["values"] = [resources]
   313                 configurations["values"].append(config_infos)
   289                 configurations["values"].append(config_infos)
   314             infos["values"] = [{"name": "Properties", "type": ITEM_UNEDITABLE, "values": []},
   290             infos["values"] = [{"name": "Properties", "type": ITEM_UNEDITABLE, "values": []},
   320     # Refresh the tree of user-defined data type cross-use
   296     # Refresh the tree of user-defined data type cross-use
   321     def RefreshDataTypeUsingTree(self):
   297     def RefreshDataTypeUsingTree(self):
   322         # Reset the tree of user-defined pou cross-use
   298         # Reset the tree of user-defined pou cross-use
   323         self.DataTypeUsingTree = {}
   299         self.DataTypeUsingTree = {}
   324         if self.Project:
   300         if self.Project:
   325             datatypes = self.Project.getDataTypes()
   301             datatypes = self.Project.getdataTypes()
   326             # Reference all the user-defined data type names and initialize the tree of 
   302             # Reference all the user-defined data type names and initialize the tree of 
   327             # user-defined data type cross-use
   303             # user-defined data type cross-use
   328             datatypenames = [datatype.getName() for datatype in datatypes]
   304             datatypenames = [datatype.getname() for datatype in datatypes]
   329             for name in datatypenames:
   305             for name in datatypenames:
   330                 self.DataTypeUsingTree[name] = []
   306                 self.DataTypeUsingTree[name] = []
   331             # Analyze each data type
   307             # Analyze each data type
   332             for datatype in datatypes:
   308             for datatype in datatypes:
   333                 name = datatype.getName()
   309                 name = datatype.getname()
   334                 basetype_content = datatype.getBaseType().getContent()
   310                 basetype_content = datatype.getbaseType().getcontent()
   335                 if basetype_content["name"] == "derived":
   311                 if basetype_content["name"] == "derived":
   336                     basetype_name = basetype_content["value"].getName()
   312                     basetype_name = basetype_content["value"].getname()
   337                     if basetype_name in datatypenames and name not in self.DataTypeUsingTree[basetype_name]:
   313                     if basetype_name in datatypenames and name not in self.DataTypeUsingTree[basetype_name]:
   338                         self.DataTypeUsingTree[basetype_name].append(name)
   314                         self.DataTypeUsingTree[basetype_name].append(name)
   339                 elif basetype_content["name"] in ["subrangeSigned", "subrangeUnsigned", "array"]:
   315                 elif basetype_content["name"] in ["subrangeSigned", "subrangeUnsigned", "array"]:
   340                     base_type = basetype_content["value"].baseType.getContent()
   316                     base_type = basetype_content["value"].baseType.getcontent()
   341                     if base_type["value"] is not None:
   317                     if base_type["value"] is not None:
   342                         basetype_name = base_type["value"].getName()
   318                         basetype_name = base_type["value"].getname()
   343                         if basetype_name in datatypenames and name not in self.DataTypeUsingTree[basetype_name]:
   319                         if basetype_name in datatypenames and name not in self.DataTypeUsingTree[basetype_name]:
   344                             self.DataTypeUsingTree[basetype_name].append(name)
   320                             self.DataTypeUsingTree[basetype_name].append(name)
   345     
   321     
   346     # Refresh the tree of user-defined pou cross-use
   322     # Refresh the tree of user-defined pou cross-use
   347     def RefreshPouUsingTree(self):
   323     def RefreshPouUsingTree(self):
   348         # Reset the tree of user-defined pou cross-use
   324         # Reset the tree of user-defined pou cross-use
   349         self.PouUsingTree = {}
   325         self.PouUsingTree = {}
   350         if self.Project:
   326         if self.Project:
   351             pous = self.Project.getPous()
   327             pous = self.Project.getpous()
   352             # Reference all the user-defined pou names and initialize the tree of 
   328             # Reference all the user-defined pou names and initialize the tree of 
   353             # user-defined pou cross-use
   329             # user-defined pou cross-use
   354             pounames = [pou.getName() for pou in pous]
   330             pounames = [pou.getname() for pou in pous]
   355             for name in pounames:
   331             for name in pounames:
   356                 self.PouUsingTree[name] = []
   332                 self.PouUsingTree[name] = []
   357             # Analyze each pou 
   333             # Analyze each pou 
   358             for pou in pous:
   334             for pou in pous:
   359                 name = pou.getName()
   335                 name = pou.getname()
   360                 if pou.interface:
   336                 if pou.interface:
   361                     # Extract variables from every varLists
   337                     # Extract variables from every varLists
   362                     for type, varlist in pou.getVars():
   338                     for type, varlist in pou.getvars():
   363                         for var in varlist.getVariable():
   339                         for var in varlist.getvariable():
   364                             vartype_content = var.getType().getContent()
   340                             vartype_content = var.gettype().getcontent()
   365                             if vartype_content["name"] == "derived":
   341                             if vartype_content["name"] == "derived":
   366                                 typename = vartype_content["value"].getName()
   342                                 typename = vartype_content["value"].getname()
   367                                 if typename in pounames and name not in self.PouUsingTree[typename]:
   343                                 if typename in pounames and name not in self.PouUsingTree[typename]:
   368                                     self.PouUsingTree[typename].append(name)
   344                                     self.PouUsingTree[typename].append(name)
   369                 bodytype = pou.getBodyType()
   345                 bodytype = pou.getbodyType()
   370                 # If pou is written in a graphical language
   346                 # If pou is written in a graphical language
   371                 if bodytype in ["FBD","LD","SFC"]:
   347                 if bodytype in ["FBD","LD","SFC"]:
   372                     # Analyze each instance of the pou
   348                     # Analyze each instance of the pou
   373                     for instance in pou.getInstances():
   349                     for instance in pou.getinstances():
   374                         if isinstance(instance, plcopen.block):
   350                         if isinstance(instance, plcopen.fbdObjects_block):
   375                             typename = instance.getTypeName()
   351                             typename = instance.gettypeName()
   376                             # Update tree if there is a cross-use
   352                             # Update tree if there is a cross-use
   377                             if typename in pounames and name not in self.PouUsingTree[typename]:
   353                             if typename in pounames and name not in self.PouUsingTree[typename]:
   378                                  self.PouUsingTree[typename].append(name)
   354                                  self.PouUsingTree[typename].append(name)
   379                 # If pou is written in a textual language
   355                 # If pou is written in a textual language
   380                 elif bodytype in ["IL", "ST"]:
   356                 elif bodytype in ["IL", "ST"]:
   381                     text = pou.getText()
   357                     text = pou.gettext()
   382                     # Search if each pou is mentioned in the pou text
   358                     # Search if each pou is mentioned in the pou text
   383                     for typename in pounames:
   359                     for typename in pounames:
   384                         typename_model = re.compile("[ \t\n]%s[ \t\n]"%typename)
   360                         typename_model = re.compile("[ \t\n]%s[ \t\n]"%typename)
   385                         # Update tree if there is a cross-use
   361                         # Update tree if there is a cross-use
   386                         if typename != name and typename_model.search(text):
   362                         if typename != name and typename_model.search(text):
   448 #-------------------------------------------------------------------------------
   424 #-------------------------------------------------------------------------------
   449     
   425     
   450     # Add a Data Type to Project
   426     # Add a Data Type to Project
   451     def ProjectAddDataType(self, datatype_name):
   427     def ProjectAddDataType(self, datatype_name):
   452         # Add the pou to project
   428         # Add the pou to project
   453         self.Project.appendDataType(datatype_name)
   429         self.Project.appenddataType(datatype_name)
   454         self.RefreshDataTypeUsingTree()
   430         self.RefreshDataTypeUsingTree()
   455         self.RefreshDataTypes()
   431         self.RefreshDataTypes()
   456         self.BufferProject()
   432         self.BufferProject()
   457     
   433     
   458     # Remove a Data Type from project
   434     # Remove a Data Type from project
   459     def ProjectRemoveDataType(self, datatype_name):
   435     def ProjectRemoveDataType(self, datatype_name):
   460         self.Project.removeDataType(datatype_name)
   436         self.Project.removedataType(datatype_name)
   461         self.RefreshDataTypeUsingTree()
   437         self.RefreshDataTypeUsingTree()
   462         self.RefreshDataTypes()
   438         self.RefreshDataTypes()
   463         self.BufferProject()
   439         self.BufferProject()
   464     
   440     
   465     # Add a Pou to Project
   441     # Add a Pou to Project
   466     def ProjectAddPou(self, pou_name, pou_type, body_type):
   442     def ProjectAddPou(self, pou_name, pou_type, body_type):
   467         # Add the pou to project
   443         # Add the pou to project
   468         self.Project.appendPou(pou_name, pou_type, body_type)
   444         self.Project.appendpou(pou_name, pou_type, body_type)
   469         if pou_type == "function":
   445         if pou_type == "function":
   470             self.SetPouInterfaceReturnType(pou_name, "BOOL")
   446             self.SetPouInterfaceReturnType(pou_name, "BOOL")
   471         self.RefreshPouUsingTree()
   447         self.RefreshPouUsingTree()
   472         self.RefreshBlockTypes()
   448         self.RefreshBlockTypes()
   473         self.BufferProject()
   449         self.BufferProject()
   474     
   450     
   475     # Remove a Pou from project
   451     # Remove a Pou from project
   476     def ProjectRemovePou(self, pou_name):
   452     def ProjectRemovePou(self, pou_name):
   477         self.Project.removePou(pou_name)
   453         self.Project.removepou(pou_name)
   478         self.RefreshPouUsingTree()
   454         self.RefreshPouUsingTree()
   479         self.RefreshBlockTypes()
   455         self.RefreshBlockTypes()
   480         self.BufferProject()
   456         self.BufferProject()
   481     
   457     
   482     # Add a configuration to Project
   458     # Add a configuration to Project
   483     def ProjectAddConfiguration(self, config_name):
   459     def ProjectAddConfiguration(self, config_name):
   484         self.Project.addConfiguration(config_name)
   460         self.Project.addconfiguration(config_name)
   485         self.BufferProject()
   461         self.BufferProject()
   486     
   462     
   487     # Remove a configuration from project
   463     # Remove a configuration from project
   488     def ProjectRemoveConfiguration(self, config_name):
   464     def ProjectRemoveConfiguration(self, config_name):
   489         self.Project.removeConfiguration(config_name)
   465         self.Project.removeconfiguration(config_name)
   490         self.BufferProject()
   466         self.BufferProject()
   491     
   467     
   492     # Add a resource to a configuration of the Project
   468     # Add a resource to a configuration of the Project
   493     def ProjectAddConfigurationResource(self, config_name, resource_name):
   469     def ProjectAddConfigurationResource(self, config_name, resource_name):
   494         self.Project.addConfigurationResource(config_name, resource_name)
   470         self.Project.addconfigurationResource(config_name, resource_name)
   495         self.BufferProject()
   471         self.BufferProject()
   496     
   472     
   497     # Remove a resource from a configuration of the project
   473     # Remove a resource from a configuration of the project
   498     def ProjectRemoveConfigurationResource(self, config_name, resource_name):
   474     def ProjectRemoveConfigurationResource(self, config_name, resource_name):
   499         self.Project.removeConfigurationResource(config_name, resource_name)
   475         self.Project.removeconfigurationResource(config_name, resource_name)
   500         self.BufferProject()
   476         self.BufferProject()
   501     
   477     
   502     # Add a Transition to a Project Pou
   478     # Add a Transition to a Project Pou
   503     def ProjectAddPouTransition(self, pou_name, transition_name, transition_type):
   479     def ProjectAddPouTransition(self, pou_name, transition_name, transition_type):
   504         pou = self.Project.getPou(pou_name)
   480         pou = self.Project.getpou(pou_name)
   505         pou.addTransition(transition_name, transition_type)
   481         pou.addtransition(transition_name, transition_type)
   506         self.BufferProject()
   482         self.BufferProject()
   507     
   483     
   508     # Remove a Transition from a Project Pou
   484     # Remove a Transition from a Project Pou
   509     def ProjectRemovePouTransition(self, pou_name, transition_name):
   485     def ProjectRemovePouTransition(self, pou_name, transition_name):
   510         pou = self.Project.getPou(pou_name)
   486         pou = self.Project.getpou(pou_name)
   511         pou.removeTransition(transition_name)
   487         pou.removetransition(transition_name)
   512         self.BufferProject()
   488         self.BufferProject()
   513     
   489     
   514     # Add an Action to a Project Pou
   490     # Add an Action to a Project Pou
   515     def ProjectAddPouAction(self, pou_name, action_name, action_type):
   491     def ProjectAddPouAction(self, pou_name, action_name, action_type):
   516         pou = self.Project.getPou(pou_name)
   492         pou = self.Project.getpou(pou_name)
   517         pou.addAction(action_name, action_type)
   493         pou.addaction(action_name, action_type)
   518         self.BufferProject()
   494         self.BufferProject()
   519     
   495     
   520     # Remove an Action from a Project Pou
   496     # Remove an Action from a Project Pou
   521     def ProjectRemovePouAction(self, pou_name, action_name):
   497     def ProjectRemovePouAction(self, pou_name, action_name):
   522         # Search if the pou removed is currently opened
   498         # Search if the pou removed is currently opened
   523         for i, element in enumerate(self.ElementsOpened):
   499         for i, element in enumerate(self.ElementsOpened):
   524             words = element.split("::")
   500             words = element.split("::")
   525             if words[0] == "A" and words[1] == pou_name and words[2] == action_name:
   501             if words[0] == "A" and words[1] == pou_name and words[2] == action_name:
   526                 self.RemoveElementEditing(i)
   502                 self.RemoveElementEditing(i)
   527         pou = self.Project.getPou(pou_name)
   503         pou = self.Project.getpou(pou_name)
   528         pou.removeAction(action_name)
   504         pou.removeaction(action_name)
   529         self.BufferProject()
   505         self.BufferProject()
   530     
   506     
   531     # Change the name of a pou
   507     # Change the name of a pou
   532     def ChangeDataTypeName(self, old_name, new_name):
   508     def ChangeDataTypeName(self, old_name, new_name):
   533         # Found the pou corresponding to old name and change its name to new name
   509         # Found the pou corresponding to old name and change its name to new name
   534         datatype = self.Project.getDataType(old_name)
   510         datatype = self.Project.getdataType(old_name)
   535         datatype.setName(new_name)
   511         datatype.setname(new_name)
   536         self.Project.updateElementName(old_name, new_name)
   512         self.Project.updateElementName(old_name, new_name)
   537         self.BufferProject()
   513         self.BufferProject()
   538     
   514     
   539     # Change the name of a pou
   515     # Change the name of a pou
   540     def ChangePouName(self, old_name, new_name):
   516     def ChangePouName(self, old_name, new_name):
   541         # Found the pou corresponding to old name and change its name to new name
   517         # Found the pou corresponding to old name and change its name to new name
   542         pou = self.Project.getPou(old_name)
   518         pou = self.Project.getpou(old_name)
   543         pou.setName(new_name)
   519         pou.setname(new_name)
   544         self.Project.updateElementName(old_name, new_name)
   520         self.Project.updateElementName(old_name, new_name)
   545         self.RefreshPouUsingTree()
   521         self.RefreshPouUsingTree()
   546         self.RefreshBlockTypes()
   522         self.RefreshBlockTypes()
   547         self.BufferProject()
   523         self.BufferProject()
   548     
   524     
   549     # Change the name of a pou transition
   525     # Change the name of a pou transition
   550     def ChangePouTransitionName(self, pou_name, old_name, new_name):
   526     def ChangePouTransitionName(self, pou_name, old_name, new_name):
   551         # Found the pou transition corresponding to old name and change its name to new name
   527         # Found the pou transition corresponding to old name and change its name to new name
   552         pou = self.Project.getPou(pou_name)
   528         pou = self.Project.getpou(pou_name)
   553         transition = pou.getTransition(old_name)
   529         transition = pou.gettransition(old_name)
   554         transition.setName(new_name)
   530         transition.setname(new_name)
   555         pou.updateElementName(old_name, new_name)
   531         pou.updateElementName(old_name, new_name)
   556         self.BufferProject()
   532         self.BufferProject()
   557     
   533     
   558     # Change the name of a pou action
   534     # Change the name of a pou action
   559     def ChangePouActionName(self, pou_name, old_name, new_name):
   535     def ChangePouActionName(self, pou_name, old_name, new_name):
   560         # Found the pou action corresponding to old name and change its name to new name
   536         # Found the pou action corresponding to old name and change its name to new name
   561         pou = self.Project.getPou(pou_name)
   537         pou = self.Project.getpou(pou_name)
   562         action = pou.getAction(old_name)
   538         action = pou.getaction(old_name)
   563         action.setName(new_name)
   539         action.setname(new_name)
   564         pou.updateElementName(old_name, new_name)
   540         pou.updateElementName(old_name, new_name)
   565         self.BufferProject()
   541         self.BufferProject()
   566     
   542     
   567     # Change the name of a pou variable
   543     # Change the name of a pou variable
   568     def ChangePouVariableName(self, pou_name, old_name, new_name):
   544     def ChangePouVariableName(self, pou_name, old_name, new_name):
   569         # Found the pou action corresponding to old name and change its name to new name
   545         # Found the pou action corresponding to old name and change its name to new name
   570         pou = self.Project.getPou(pou_name)
   546         pou = self.Project.getpou(pou_name)
   571         for type, varlist in pou.getVars():
   547         for type, varlist in pou.getvars():
   572             for var in varlist.getVariable():
   548             for var in varlist.getvariable():
   573                 if var.getName() == old_name:
   549                 if var.getname() == old_name:
   574                     var.setName(new_name)
   550                     var.setname(new_name)
   575         self.RefreshBlockTypes()
   551         self.RefreshBlockTypes()
   576         self.BufferProject()
   552         self.BufferProject()
   577         
   553         
   578     # Change the name of a configuration
   554     # Change the name of a configuration
   579     def ChangeConfigurationName(self, old_name, new_name):
   555     def ChangeConfigurationName(self, old_name, new_name):
   580         # Found the configuration corresponding to old name and change its name to new name
   556         # Found the configuration corresponding to old name and change its name to new name
   581         configuration = self.Project.getConfiguration(old_name)
   557         configuration = self.Project.getconfiguration(old_name)
   582         configuration.setName(new_name)
   558         configuration.setname(new_name)
   583         self.BufferProject()
   559         self.BufferProject()
   584     
   560     
   585     # Change the name of a configuration resource
   561     # Change the name of a configuration resource
   586     def ChangeConfigurationResourceName(self, config_name, old_name, new_name):
   562     def ChangeConfigurationResourceName(self, config_name, old_name, new_name):
   587         # Found the resource corresponding to old name and change its name to new name
   563         # Found the resource corresponding to old name and change its name to new name
   588         resource = self.Project.getConfigurationResource(config_name)
   564         resource = self.Project.getconfigurationResource(config_name)
   589         resource.setName(new_name)
   565         resource.setName(new_name)
   590         self.BufferProject()
   566         self.BufferProject()
   591     
   567     
   592     # Return the type of the pou given by its name
   568     # Return the type of the pou given by its name
   593     def GetPouType(self, name):
   569     def GetPouType(self, name):
   594         # Found the pou correponding to name and return its type
   570         # Found the pou correponding to name and return its type
   595         pou = self.Project.getPou(name)
   571         pou = self.Project.getpou(name)
   596         return pou.pouType.getValue()
   572         return pou.getpouType()
   597     
   573     
   598     # Return pous with SFC language
   574     # Return pous with SFC language
   599     def GetSFCPous(self):
   575     def GetSFCPous(self):
   600         list = []
   576         list = []
   601         if self.Project:
   577         if self.Project:
   602             for pou in self.Project.getPous():
   578             for pou in self.Project.getpous():
   603                 if pou.getBodyType() == "SFC":
   579                 if pou.getBodyType() == "SFC":
   604                     list.append(pou.getName())
   580                     list.append(pou.getname())
   605         return list
   581         return list
   606     
   582     
   607     # Return the body language of the pou given by its name
   583     # Return the body language of the pou given by its name
   608     def GetPouBodyType(self, name):
   584     def GetPouBodyType(self, name):
   609         # Found the pou correponding to name and return its body language
   585         # Found the pou correponding to name and return its body language
   610         pou = self.Project.getPou(name)
   586         pou = self.Project.getpou(name)
   611         return pou.getBodyType()
   587         return pou.getbodyType()
   612     
   588     
   613     # Return the actions of a pou
   589     # Return the actions of a pou
   614     def GetPouTransitions(self, pou_name):
   590     def GetPouTransitions(self, pou_name):
   615         transitions = []
   591         transitions = []
   616         pou = self.Project.getPou(pou_name)
   592         pou = self.Project.getpou(pou_name)
   617         if pou.getBodyType() == "SFC":
   593         if pou.getbodyType() == "SFC":
   618             for transition in pou.getTransitionList():
   594             for transition in pou.gettransitionList():
   619                 transitions.append(transition.getName())
   595                 transitions.append(transition.getname())
   620         return transitions
   596         return transitions
   621     
   597     
   622     # Return the body language of the transition given by its name
   598     # Return the body language of the transition given by its name
   623     def GetTransitionBodyType(self, pou_name, pou_transition):
   599     def GetTransitionBodyType(self, pou_name, pou_transition):
   624         # Found the pou correponding to name and return its body language
   600         # Found the pou correponding to name and return its body language
   625         pou = self.Project.getPou(pou_name)
   601         pou = self.Project.getpou(pou_name)
   626         transition = pou.getTransition(pou_transition)
   602         transition = pou.gettransition(pou_transition)
   627         return transition.getBodyType()
   603         return transition.getbodyType()
   628     
   604     
   629     # Return the actions of a pou
   605     # Return the actions of a pou
   630     def GetPouActions(self, pou_name):
   606     def GetPouActions(self, pou_name):
   631         actions = []
   607         actions = []
   632         pou = self.Project.getPou(pou_name)
   608         pou = self.Project.getpou(pou_name)
   633         if pou.getBodyType() == "SFC":
   609         if pou.getbodyType() == "SFC":
   634             for action in pou.getActionList():
   610             for action in pou.getactionList():
   635                 actions.append(action.getName())
   611                 actions.append(action.getname())
   636         return actions
   612         return actions
   637     
   613     
   638     # Return the body language of the pou given by its name
   614     # Return the body language of the pou given by its name
   639     def GetActionBodyType(self, pou_name, pou_action):
   615     def GetActionBodyType(self, pou_name, pou_action):
   640         # Found the pou correponding to name and return its body language
   616         # Found the pou correponding to name and return its body language
   641         pou = self.Project.getPou(pou_name)
   617         pou = self.Project.getpou(pou_name)
   642         action = pou.getAction(pou_action)
   618         action = pou.getaction(pou_action)
   643         return action.getBodyType()
   619         return action.getbodyType()
   644     
   620     
   645     # Extract varlists from a list of vars
   621     # Extract varlists from a list of vars
   646     def ExtractVarLists(self, vars):
   622     def ExtractVarLists(self, vars):
   647         varlist_list = []
   623         varlist_list = []
   648         current_varlist = None
   624         current_varlist = None
   649         current_type = None
   625         current_type = None
   650         for var in vars:
   626         for var in vars:
   651             if current_type != (var["Class"], var["Retain"], var["Constant"], var["Location"] in ["", None]):
   627             if current_type != (var["Class"], var["Retain"], var["Constant"], var["Location"] in ["", None]):
   652                 current_type = (var["Class"], var["Retain"], var["Constant"], var["Location"] in ["", None])
   628                 current_type = (var["Class"], var["Retain"], var["Constant"], var["Location"] in ["", None])
   653                 current_varlist = plcopen.varList()
   629                 if var["Class"] == "Local":
       
   630                     current_varlist = plcopen.interface_localVars()
       
   631                 elif var["Class"] == "Global":
       
   632                     current_varlist = plcopen.interface_globalVars()
       
   633                 elif var["Class"] == "External":
       
   634                     current_varlist = plcopen.interface_externalVars()
       
   635                 elif var["Class"] == "Temp":
       
   636                     current_varlist = plcopen.interface_tempVars()
       
   637                 elif var["Class"] == "Input":
       
   638                     current_varlist = plcopen.interface_inputVars()
       
   639                 elif var["Class"] == "Output":
       
   640                     current_varlist = plcopen.interface_outputVars()
       
   641                 elif var["Class"] == "InOut":
       
   642                     current_varlist = plcopen.interface_inOutVars()
       
   643                 else:
       
   644                     current_varlist = plcopen.varList()
   654                 varlist_list.append((var["Class"], current_varlist))
   645                 varlist_list.append((var["Class"], current_varlist))
   655                 if var["Retain"] == "Yes":
   646                 if var["Retain"] == "Yes":
   656                     varlist.setRetain(True)
   647                     current_varlist.setretain(True)
   657                 if var["Constant"] == "Yes":
   648                 if var["Constant"] == "Yes":
   658                     varlist.setConstant(True)
   649                     current_varlist.setconstant(True)
   659             # Create variable and change its properties
   650             # Create variable and change its properties
   660             tempvar = plcopen.varListPlain_variable()
   651             tempvar = plcopen.varListPlain_variable()
   661             tempvar.setName(var["Name"])
   652             tempvar.setname(var["Name"])
   662             var_type = plcopen.dataType()
   653             var_type = plcopen.dataType()
   663             if var["Type"] not in var_type.getChoices():
   654             if var["Type"] in self.GetBaseTypes():
   664                 if var["Type"] == "STRING":
   655                 if var["Type"] == "STRING":
   665                     var_type.setContent("string", plcopen.string())
   656                     var_type.setcontent({"name" : "string", "value" : plcopen.elementaryTypes_string()})
   666                 elif var["Type"] == "WSTRING":
   657                 elif var["Type"] == "WSTRING":
   667                     var_type.setContent("wstring", plcopen.wstring())
   658                     var_type.setcontent({"name" : "wstring", "value" : plcopen.elementaryTypes_wstring()})
   668                 else:
   659                 else:
   669                     derived_type = plcopen.derived()
   660                     var_type.setcontent({"name" : var["Type"], "value" : None})
   670                     derived_type.setName(var["Type"])
       
   671                     var_type.setContent("derived", derived_type)
       
   672             else:
   661             else:
   673                 var_type.setContent(var["Type"], None)
   662                 derived_type = plcopen.derivedTypes_derived()
   674             tempvar.setType(var_type)
   663                 derived_type.setname(var["Type"])
       
   664                 var_type.setcontent({"name" : "derived", "value" : derived_type})
       
   665             tempvar.settype(var_type)
   675             if var["Initial Value"] != "":
   666             if var["Initial Value"] != "":
   676                 value = plcopen.value()
   667                 value = plcopen.value()
   677                 value.setValue(var["Initial Value"])
   668                 value.setvalue(var["Initial Value"])
   678                 tempvar.setInitialValue(value)
   669                 tempvar.setinitialValue(value)
   679             if var["Location"] != "":
   670             if var["Location"] != "":
   680                 tempvar.setAddress(var["Location"])
   671                 tempvar.setaddress(var["Location"])
   681             else:
   672             else:
   682                 tempvar.setAddress(None)
   673                 tempvar.setaddress(None)
   683             # Add variable to varList
   674             # Add variable to varList
   684             current_varlist.appendVariable(tempvar)
   675             current_varlist.appendvariable(tempvar)
   685         return varlist_list
   676         return varlist_list
   686 
   677 
   687     # Replace the configuration globalvars by those given
   678     # Replace the configuration globalvars by those given
   688     def SetConfigurationGlobalVars(self, name, vars):
   679     def SetConfigurationGlobalVars(self, name, vars):
   689         # Found the configuration corresponding to name
   680         # Found the configuration corresponding to name
   690         configuration = self.Project.getConfiguration(name)
   681         configuration = self.Project.getconfiguration(name)
   691         if configuration:
   682         if configuration:
   692             # Set configuration global vars
   683             # Set configuration global vars
   693             configuration.setGlobalVars([])
   684             configuration.setglobalVars([])
   694             for vartype, varlist in self.ExtractVarLists(vars):
   685             for vartype, varlist in self.ExtractVarLists(vars):
   695                 configuration.globalVars.append(varlist)
   686                 configuration.globalVars.append(varlist)
   696         self.RefreshBlockTypes()
   687         self.RefreshBlockTypes()
   697     
   688     
   698     # Return the configuration globalvars
   689     # Return the configuration globalvars
   699     def GetConfigurationGlobalVars(self, name):
   690     def GetConfigurationGlobalVars(self, name):
   700         vars = []
   691         vars = []
   701         # Found the configuration corresponding to name
   692         # Found the configuration corresponding to name
   702         configuration = self.Project.getConfiguration(name)
   693         configuration = self.Project.getconfiguration(name)
   703         if configuration:
   694         if configuration:
   704             # Extract variables from every varLists
   695             # Extract variables from every varLists
   705             for varlist in configuration.getGlobalVars():
   696             for varlist in configuration.getglobalVars():
   706                 for var in varlist.getVariable():
   697                 for var in varlist.getvariable():
   707                     tempvar = {"Name":var.getName(),"Class":"Global"}
   698                     tempvar = {"Name" : var.getname(), "Class" : "Global"}
   708                     vartype_content = var.getType().getContent()
   699                     vartype_content = var.gettype().getcontent()
   709                     if vartype_content["name"] == "derived":
   700                     if vartype_content["name"] == "derived":
   710                         tempvar["Type"] = vartype_content["value"].getName()
   701                         tempvar["Type"] = vartype_content["value"].getname()
   711                     elif vartype_content["name"] in ["string", "wstring"]:
   702                     elif vartype_content["name"] in ["string", "wstring"]:
   712                         tempvar["Type"] = vartype_content["name"].upper()
   703                         tempvar["Type"] = vartype_content["name"].upper()
   713                     else:
   704                     else:
   714                         tempvar["Type"] = vartype_content["name"]
   705                         tempvar["Type"] = vartype_content["name"]
   715                     tempvar["Edit"] = True
   706                     tempvar["Edit"] = True
   716                     initial = var.getInitialValue()
   707                     initial = var.getinitialValue()
   717                     if initial:
   708                     if initial:
   718                         tempvar["Initial Value"] = initial.getValue()
   709                         tempvar["Initial Value"] = initial.getvalue()
   719                     else:
   710                     else:
   720                         tempvar["Initial Value"] = ""
   711                         tempvar["Initial Value"] = ""
   721                     address = var.getAddress()
   712                     address = var.getaddress()
   722                     if address:
   713                     if address:
   723                         tempvar["Location"] = address
   714                         tempvar["Location"] = address
   724                     else:
   715                     else:
   725                         tempvar["Location"] = ""
   716                         tempvar["Location"] = ""
   726                     if varlist.getRetain():
   717                     if varlist.getretain():
   727                         tempvar["Retain"] = "Yes"
   718                         tempvar["Retain"] = "Yes"
   728                     else:
   719                     else:
   729                         tempvar["Retain"] = "No"
   720                         tempvar["Retain"] = "No"
   730                     if varlist.getConstant():
   721                     if varlist.getconstant():
   731                         tempvar["Constant"] = "Yes"
   722                         tempvar["Constant"] = "Yes"
   732                     else:
   723                     else:
   733                         tempvar["Constant"] = "No"
   724                         tempvar["Constant"] = "No"
   734                     vars.append(tempvar)
   725                     vars.append(tempvar)
   735         return vars
   726         return vars
   736 
   727 
   737     # Replace the resource globalvars by those given
   728     # Replace the resource globalvars by those given
   738     def SetConfigurationResourceGlobalVars(self, config_name, name, vars):
   729     def SetConfigurationResourceGlobalVars(self, config_name, name, vars):
   739         # Found the resource corresponding to name
   730         # Found the resource corresponding to name
   740         resource = self.Project.getConfigurationResource(config_name, name)
   731         resource = self.Project.getconfigurationResource(config_name, name)
   741         # Set resource global vars
   732         # Set resource global vars
   742         if resource:
   733         if resource:
   743             resource.setGlobalVars([])
   734             resource.setglobalVars([])
   744             for vartype, varlist in self.ExtractVarLists(vars):
   735             for vartype, varlist in self.ExtractVarLists(vars):
   745                 resource.globalVars.append(varlist)
   736                 resource.globalVars.append(varlist)
   746         self.RefreshBlockTypes()
   737         self.RefreshBlockTypes()
   747     
   738     
   748     # Return the resource globalvars
   739     # Return the resource globalvars
   749     def GetConfigurationResourceGlobalVars(self, config_name, name):
   740     def GetConfigurationResourceGlobalVars(self, config_name, name):
   750         vars = []
   741         vars = []
   751         # Found the resource corresponding to name
   742         # Found the resource corresponding to name
   752         resource = self.Project.getConfigurationResource(config_name, name)
   743         resource = self.Project.getconfigurationResource(config_name, name)
   753         if resource:
   744         if resource:
   754             # Extract variables from every varLists
   745             # Extract variables from every varLists
   755             for varlist in resource.getGlobalVars():
   746             for varlist in resource.getglobalVars():
   756                 for var in varlist.getVariable():
   747                 for var in varlist.getvariable():
   757                     tempvar = {"Name":var.getName(),"Class":"Global"}
   748                     tempvar = {"Name" : var.getname(), "Class" : "Global"}
   758                     vartype_content = var.getType().getContent()
   749                     vartype_content = var.gettype().getcontent()
   759                     if vartype_content["name"] == "derived":
   750                     if vartype_content["name"] == "derived":
   760                         tempvar["Type"] = vartype_content["value"].getName()
   751                         tempvar["Type"] = vartype_content["value"].getname()
   761                     elif vartype_content["name"] in ["string", "wstring"]:
   752                     elif vartype_content["name"] in ["string", "wstring"]:
   762                         tempvar["Type"] = vartype_content["name"].upper()
   753                         tempvar["Type"] = vartype_content["name"].upper()
   763                     else:
   754                     else:
   764                         tempvar["Type"] = vartype_content["name"]
   755                         tempvar["Type"] = vartype_content["name"]
   765                     tempvar["Edit"] = True
   756                     tempvar["Edit"] = True
   766                     initial = var.getInitialValue()
   757                     initial = var.getinitialValue()
   767                     if initial:
   758                     if initial:
   768                         tempvar["Initial Value"] = initial.getValue()
   759                         tempvar["Initial Value"] = initial.getvalue()
   769                     else:
   760                     else:
   770                         tempvar["Initial Value"] = ""
   761                         tempvar["Initial Value"] = ""
   771                     address = var.getAddress()
   762                     address = var.getaddress()
   772                     if address:
   763                     if address:
   773                         tempvar["Location"] = address
   764                         tempvar["Location"] = address
   774                     else:
   765                     else:
   775                         tempvar["Location"] = ""
   766                         tempvar["Location"] = ""
   776                     if varlist.getRetain():
   767                     if varlist.getretain():
   777                         tempvar["Retain"] = "Yes"
   768                         tempvar["Retain"] = "Yes"
   778                     else:
   769                     else:
   779                         tempvar["Retain"] = "No"
   770                         tempvar["Retain"] = "No"
   780                     if varlist.getConstant():
   771                     if varlist.getconstant():
   781                         tempvar["Constant"] = "Yes"
   772                         tempvar["Constant"] = "Yes"
   782                     else:
   773                     else:
   783                         tempvar["Constant"] = "No"
   774                         tempvar["Constant"] = "No"
   784                     vars.append(tempvar)
   775                     vars.append(tempvar)
   785         return vars
   776         return vars
   786     
   777     
   787     # Return the interface of the pou given by its name
   778     # Return the interface of the pou given by its name
   788     def GetPouInterfaceVarsByName(self, name):
   779     def GetPouInterfaceVarsByName(self, name):
   789         # Found the pou correponding to name and return the interface
   780         # Found the pou correponding to name and return the interface
   790         return self.GetPouInterfaceVars(self.Project.getPou(name))
   781         return self.GetPouInterfaceVars(self.Project.getpou(name))
   791     
   782     
   792     # Return the interface for the given pou
   783     # Return the interface for the given pou
   793     def GetPouInterfaceVars(self, pou):
   784     def GetPouInterfaceVars(self, pou):
   794         vars = []
   785         vars = []
   795         # Verify that the pou has an interface
   786         # Verify that the pou has an interface
   796         if pou.interface:
   787         if pou.interface:
   797             # Extract variables from every varLists
   788             # Extract variables from every varLists
   798             for type, varlist in pou.getVars():
   789             for type, varlist in pou.getvars():
   799                 for var in varlist.getVariable():
   790                 for var in varlist.getvariable():
   800                     tempvar = {"Name":var.getName(),"Class":type}
   791                     tempvar = {"Name" : var.getname(), "Class" : type}
   801                     vartype_content = var.getType().getContent()
   792                     vartype_content = var.gettype().getcontent()
   802                     if vartype_content["name"] == "derived":
   793                     if vartype_content["name"] == "derived":
   803                         tempvar["Type"] = vartype_content["value"].getName()
   794                         tempvar["Type"] = vartype_content["value"].getname()
   804                         tempvar["Edit"] = not pou.hasBlock(tempvar["Name"])
   795                         tempvar["Edit"] = not pou.hasblock(tempvar["Name"])
   805                     else:
   796                     else:
   806                         if vartype_content["name"] in ["string", "wstring"]:
   797                         if vartype_content["name"] in ["string", "wstring"]:
   807                             tempvar["Type"] = vartype_content["name"].upper()
   798                             tempvar["Type"] = vartype_content["name"].upper()
   808                         else:
   799                         else:
   809                             tempvar["Type"] = vartype_content["name"]
   800                             tempvar["Type"] = vartype_content["name"]
   810                         tempvar["Edit"] = True
   801                         tempvar["Edit"] = True
   811                     initial = var.getInitialValue()
   802                     initial = var.getinitialValue()
   812                     if initial:
   803                     if initial:
   813                         tempvar["Initial Value"] = initial.getValue()
   804                         tempvar["Initial Value"] = initial.getvalue()
   814                     else:
   805                     else:
   815                         tempvar["Initial Value"] = ""
   806                         tempvar["Initial Value"] = ""
   816                     address = var.getAddress()
   807                     address = var.getaddress()
   817                     if address:
   808                     if address:
   818                         tempvar["Location"] = address
   809                         tempvar["Location"] = address
   819                     else:
   810                     else:
   820                         tempvar["Location"] = ""
   811                         tempvar["Location"] = ""
   821                     if varlist.getRetain():
   812                     if varlist.getretain():
   822                         tempvar["Retain"] = "Yes"
   813                         tempvar["Retain"] = "Yes"
   823                     else:
   814                     else:
   824                         tempvar["Retain"] = "No"
   815                         tempvar["Retain"] = "No"
   825                     if varlist.getConstant():
   816                     if varlist.getconstant():
   826                         tempvar["Constant"] = "Yes"
   817                         tempvar["Constant"] = "Yes"
   827                     else:
   818                     else:
   828                         tempvar["Constant"] = "No"
   819                         tempvar["Constant"] = "No"
   829                     vars.append(tempvar)
   820                     vars.append(tempvar)
   830         return vars
   821         return vars
   831 
   822 
   832     # Replace the Pou interface by the one given
   823     # Replace the Pou interface by the one given
   833     def SetPouInterfaceVars(self, name, vars):
   824     def SetPouInterfaceVars(self, name, vars):
   834         # Found the pou corresponding to name and add interface if there isn't one yet
   825         # Found the pou corresponding to name and add interface if there isn't one yet
   835         pou = self.Project.getPou(name)
   826         pou = self.Project.getpou(name)
   836         if not pou.interface:
   827         if not pou.interface:
   837             pou.interface = plcopen.pou_interface()
   828             pou.interface = plcopen.pou_interface()
   838         # Set Pou interface
   829         # Set Pou interface
   839         pou.setVars(self.ExtractVarLists(vars))
   830         pou.setvars(self.ExtractVarLists(vars))
   840         self.RefreshPouUsingTree()
   831         self.RefreshPouUsingTree()
   841         self.RefreshBlockTypes()
   832         self.RefreshBlockTypes()
   842     
   833     
   843     # Replace the return type of the pou given by its name (only for functions)
   834     # Replace the return type of the pou given by its name (only for functions)
   844     def SetPouInterfaceReturnType(self, name, type):
   835     def SetPouInterfaceReturnType(self, name, type):
   845         pou = self.Project.getPou(name)
   836         pou = self.Project.getpou(name)
   846         if not pou.interface:
   837         if not pou.interface:
   847             pou.interface = plcopen.pou_interface()
   838             pou.interface = plcopen.pou_interface()
   848         # If there isn't any return type yet, add it
   839         # If there isn't any return type yet, add it
   849         return_type = pou.interface.getReturnType()
   840         return_type = pou.interface.getreturnType()
   850         if not return_type:
   841         if not return_type:
   851             return_type = plcopen.dataType()
   842             return_type = plcopen.dataType()
   852             pou.interface.setReturnType(return_type)
   843             pou.interface.setreturnType(return_type)
   853         # Change return type
   844         # Change return type
   854         if type in self.GetBaseTypes():
   845         if type in self.GetBaseTypes():
   855             return_type.setContent(type, None)
   846             if type == "STRING":
       
   847                 return_type.setcontent({"name" : "string", "value" : plcopen.elementaryTypes_string()})
       
   848             elif type == "WSTRING":
       
   849                 return_type.setcontent({"name" : "wstring", "value" : plcopen.elementaryTypes_wstring()})
       
   850             else:
       
   851                 return_type.setcontent({"name" : type, "value" : None})
   856         else:
   852         else:
   857             derived_type = plcopen.derived()
   853             derived_type = plcopen.derivedTypes_derived()
   858             derived_type.setName(type)
   854             derived_type.setname(type)
   859             return_type.setContent("derived", derived_type)
   855             return_type.setcontent({"name" : "derived", "value" : derived_type})
   860         self.RefreshBlockTypes()
   856         self.RefreshBlockTypes()
   861     
   857     
   862     def UpdateProjectUsedPous(self, old_name, new_name):
   858     def UpdateProjectUsedPous(self, old_name, new_name):
   863         if self.Project:
   859         if self.Project:
   864             self.Project.updateElementName(old_name, new_name)
   860             self.Project.updateElementName(old_name, new_name)
   869             pou.updateElementName(old_name, new_name)
   865             pou.updateElementName(old_name, new_name)
   870     
   866     
   871     # Return the return type of the pou given by its name
   867     # Return the return type of the pou given by its name
   872     def GetPouInterfaceReturnTypeByName(self, name):
   868     def GetPouInterfaceReturnTypeByName(self, name):
   873         # Found the pou correponding to name and return the return type
   869         # Found the pou correponding to name and return the return type
   874         return self.GetPouInterfaceReturnType(self.Project.getPou(name))
   870         return self.GetPouInterfaceReturnType(self.Project.getpou(name))
   875     
   871     
   876     # Return the return type of the given pou
   872     # Return the return type of the given pou
   877     def GetPouInterfaceReturnType(self, pou):
   873     def GetPouInterfaceReturnType(self, pou):
   878         # Verify that the pou has an interface
   874         # Verify that the pou has an interface
   879         if pou.interface:
   875         if pou.interface:
   880             # Return the return type if there is one
   876             # Return the return type if there is one
   881             return_type = pou.interface.getReturnType()
   877             return_type = pou.interface.getreturnType()
   882             if return_type:
   878             if return_type:
   883                 returntype_content = return_type.getContent()
   879                 returntype_content = return_type.getcontent()
   884                 if returntype_content["name"] == "derived":
   880                 if returntype_content["name"] == "derived":
   885                     return returntype_content["value"].getName()
   881                     return returntype_content["value"].getname()
   886                 elif returntype_content["name"] in ["string", "wstring"]:
   882                 elif returntype_content["name"] in ["string", "wstring"]:
   887                     return returntype_content["name"].upper()
   883                     return returntype_content["name"].upper()
   888                 else:
   884                 else:
   889                     return returntype_content["name"]
   885                     return returntype_content["name"]
   890         return None
   886         return None
   892     # Update data types with user-defined data types added
   888     # Update data types with user-defined data types added
   893     def RefreshDataTypes(self):
   889     def RefreshDataTypes(self):
   894         ResetTypeHierarchy()
   890         ResetTypeHierarchy()
   895         ResetEnumeratedDataValues()
   891         ResetEnumeratedDataValues()
   896         if self.Project:
   892         if self.Project:
   897             for datatype in self.Project.getDataTypes():
   893             for datatype in self.Project.getdataTypes():
   898                 name = datatype.getName()
   894                 name = datatype.getname()
   899                 basetype_content = datatype.getBaseType().getContent()
   895                 basetype_content = datatype.getbaseType().getcontent()
   900                 if basetype_content["value"] is None:
   896                 if basetype_content["value"] is None:
   901                     AddDataTypeHierarchy(name, basetype_content["name"])
   897                     AddDataTypeHierarchy(name, basetype_content["name"])
   902                 elif basetype_content["name"] in ["string", "wstring"]:
   898                 elif basetype_content["name"] in ["string", "wstring"]:
   903                     AddDataTypeHierarchy(name, basetype_content["name"].upper())
   899                     AddDataTypeHierarchy(name, basetype_content["name"].upper())
   904                 elif basetype_content["name"] == "derived":
   900                 elif basetype_content["name"] == "derived":
   905                     AddDataTypeHierarchy(name, basetype_content["value"].getName())
   901                     AddDataTypeHierarchy(name, basetype_content["value"].getname())
   906                 elif basetype_content["name"] in ["subrangeSigned", "subrangeUnsigned"]:
   902                 elif basetype_content["name"] in ["subrangeSigned", "subrangeUnsigned"]:
   907                     base_type = basetype_content["value"].baseType.getContent()
   903                     base_type = basetype_content["value"].baseType.getcontent()
   908                     if base_type["value"] is None:
   904                     if base_type["value"] is None:
   909                         AddDataTypeHierarchy(name, base_type["name"])
   905                         AddDataTypeHierarchy(name, base_type["name"])
   910                     else:
   906                     else:
   911                         AddDataTypeHierarchy(name, base_type["value"].getName())
   907                         AddDataTypeHierarchy(name, base_type["value"].getname())
   912                 else:
   908                 else:
   913                     if basetype_content["name"] == "enum":
   909                     if basetype_content["name"] == "enum":
   914                         values = []
   910                         values = []
   915                         for value in basetype_content["value"].values.getValue():
   911                         for value in basetype_content["value"].values.getvalue():
   916                             values.append(value.getName())
   912                             values.append(value.getname())
   917                         AddEnumeratedDataValues(values)
   913                         AddEnumeratedDataValues(values)
   918                     AddDataTypeHierarchy(name, "ANY_DERIVED")
   914                     AddDataTypeHierarchy(name, "ANY_DERIVED")
   919     
   915     
   920     # Update Block types with user-defined pou added
   916     # Update Block types with user-defined pou added
   921     def RefreshBlockTypes(self):
   917     def RefreshBlockTypes(self):
   922         if BlockTypes[-1]["name"] == "User-defined POUs":
   918         if BlockTypes[-1]["name"] == "User-defined POUs":
   923             BlockTypes[-1]["list"] = []
   919             BlockTypes[-1]["list"] = []
   924         else:
   920         else:
   925             BlockTypes.append({"name" : "User-defined POUs", "list": []})
   921             BlockTypes.append({"name" : "User-defined POUs", "list": []})
   926         if self.Project:
   922         if self.Project:
   927             for pou in self.Project.getPous():
   923             for pou in self.Project.getpous():
   928                 pou_name = pou.getName()
   924                 pou_name = pou.getname()
   929                 pou_type = pou.pouType.getValue()
   925                 pou_type = pou.getpouType()
   930                 if pou_type != "program":
   926                 if pou_type != "program":
   931                     block_infos = {"name" : pou_name, "type" : pou_type, "extensible" : False,
   927                     block_infos = {"name" : pou_name, "type" : pou_type, "extensible" : False,
   932                                    "inputs" : [], "outputs" : [], "comment" : "",
   928                                    "inputs" : [], "outputs" : [], "comment" : "",
   933                                    "generate" : generate_block, "initialise" : initialise_block }
   929                                    "generate" : generate_block, "initialise" : initialise_block }
   934                     if pou.getInterface():
   930                     if pou.getinterface():
   935                         for type, varlist in pou.getVars():
   931                         for type, varlist in pou.getvars():
   936                             if type == "InOut":
   932                             if type == "InOut":
   937                                 for var in varlist.getVariable():
   933                                 for var in varlist.getvariable():
   938                                     var_type = var.type.getContent()
   934                                     var_type = var.type.getcontent()
   939                                     if var_type["name"] == "derived":
   935                                     if var_type["name"] == "derived":
   940                                         block_infos["inputs"].append((var.getName(),var_type["value"].getName(),"none"))
   936                                         block_infos["inputs"].append((var.getname(), var_type["value"].getname(), "none"))
   941                                         block_infos["outputs"].append((var.getName(),var_type["value"].getName(),"none"))
   937                                         block_infos["outputs"].append((var.getname(), var_type["value"].getname(), "none"))
   942                                     elif var_type["name"] in ["string", "wstring"]:
   938                                     elif var_type["name"] in ["string", "wstring"]:
   943                                         block_infos["inputs"].append((var.getName(),var_type["name"].upper(),"none"))
   939                                         block_infos["inputs"].append((var.getname(), var_type["name"].upper(), "none"))
   944                                         block_infos["outputs"].append((var.getName(),var_type["name"].upper(),"none"))
   940                                         block_infos["outputs"].append((var.getname(), var_type["name"].upper(), "none"))
   945                                     else:
   941                                     else:
   946                                         block_infos["inputs"].append((var.getName(),var_type["name"],"none"))
   942                                         block_infos["inputs"].append((var.getname(), var_type["name"], "none"))
   947                                         block_infos["outputs"].append((var.getName(),var_type["name"],"none"))
   943                                         block_infos["outputs"].append((var.getname(), var_type["name"], "none"))
   948                             elif type == "Input":
   944                             elif type == "Input":
   949                                 for var in varlist.getVariable():
   945                                 for var in varlist.getvariable():
   950                                     var_type = var.type.getContent()
   946                                     var_type = var.type.getcontent()
   951                                     if var_type["name"] == "derived":
   947                                     if var_type["name"] == "derived":
   952                                         block_infos["inputs"].append((var.getName(),var_type["value"].getName(),"none"))
   948                                         block_infos["inputs"].append((var.getname(), var_type["value"].getname(), "none"))
   953                                     elif var_type["name"] in ["string", "wstring"]:
   949                                     elif var_type["name"] in ["string", "wstring"]:
   954                                         block_infos["inputs"].append((var.getName(),var_type["name"].upper(),"none"))
   950                                         block_infos["inputs"].append((var.getname(), var_type["name"].upper(), "none"))
   955                                     else:
   951                                     else:
   956                                         block_infos["inputs"].append((var.getName(),var_type["name"],"none"))
   952                                         block_infos["inputs"].append((var.getname(), var_type["name"], "none"))
   957                             elif type == "Output":
   953                             elif type == "Output":
   958                                 for var in varlist.getVariable():
   954                                 for var in varlist.getvariable():
   959                                     var_type = var.type.getContent()
   955                                     var_type = var.type.getcontent()
   960                                     if var_type["name"] == "derived":
   956                                     if var_type["name"] == "derived":
   961                                         block_infos["outputs"].append((var.getName(),var_type["value"].getName(),"none"))
   957                                         block_infos["outputs"].append((var.getname(), var_type["value"].getname(), "none"))
   962                                     elif var_type["name"] in ["string", "wstring"]:
   958                                     elif var_type["name"] in ["string", "wstring"]:
   963                                         block_infos["outputs"].append((var.getName(),var_type["name"].upper(),"none"))
   959                                         block_infos["outputs"].append((var.getname(), var_type["name"].upper(), "none"))
   964                                     else:
   960                                     else:
   965                                         block_infos["outputs"].append((var.getName(),var_type["name"],"none"))    
   961                                         block_infos["outputs"].append((var.getname(), var_type["name"], "none"))    
   966                         return_type = pou.interface.getReturnType()
   962                         return_type = pou.interface.getreturnType()
   967                         if return_type:
   963                         if return_type:
   968                             var_type = return_type.getContent()
   964                             var_type = return_type.getcontent()
   969                             if var_type["name"] == "derived":
   965                             if var_type["name"] == "derived":
   970                                 block_infos["outputs"].append(("",var_type["value"].getName(),"none"))
   966                                 block_infos["outputs"].append(("", var_type["value"].getname(), "none"))
   971                             elif var_type["name"] in ["string", "wstring"]:
   967                             elif var_type["name"] in ["string", "wstring"]:
   972                                 block_infos["outputs"].append(("",var_type["name"].upper(),"none"))
   968                                 block_infos["outputs"].append(("", var_type["name"].upper(), "none"))
   973                             else:
   969                             else:
   974                                 block_infos["outputs"].append(("",var_type["name"],"none"))
   970                                 block_infos["outputs"].append(("", var_type["name"], "none"))
   975                     if pou.getBodyType() in ["FBD","LD","SFC"]:
   971                     if pou.getbodyType() in ["FBD","LD","SFC"]:
   976                         for instance in pou.getInstances():
   972                         for instance in pou.getinstances():
   977                             if isinstance(instance, plcopen.comment):
   973                             if isinstance(instance, plcopen.commonObjects_comment):
   978                                 block_infos["comment"] = instance.getContentText()
   974                                 block_infos["comment"] = instance.getcontentText()
   979                     BlockTypes[-1]["list"].append(block_infos)
   975                     BlockTypes[-1]["list"].append(block_infos)
   980     
   976     
   981     # Return Block types checking for recursion
   977     # Return Block types checking for recursion
   982     def GetBlockTypes(self, tagname = ""):
   978     def GetBlockTypes(self, tagname = ""):
   983         name = ""
   979         name = ""
  1031         for category in BlockTypes[:-1]:
  1027         for category in BlockTypes[:-1]:
  1032             for blocktype in category["list"]:
  1028             for blocktype in category["list"]:
  1033                 if blocktype["type"] == "program":
  1029                 if blocktype["type"] == "program":
  1034                     blocktypes.append(blocktype["name"])
  1030                     blocktypes.append(blocktype["name"])
  1035         if self.Project:
  1031         if self.Project:
  1036             for pou in self.Project.getPous():
  1032             for pou in self.Project.getpous():
  1037                 if pou.pouType.getValue() == "program":
  1033                 if pou.getpouType() == "program":
  1038                     blocktypes.append(pou.getName())
  1034                     blocktypes.append(pou.getname())
  1039         return blocktypes
  1035         return blocktypes
  1040 
  1036 
  1041     # Return Data Types checking for recursion
  1037     # Return Data Types checking for recursion
  1042     def GetDataTypes(self, tagname = "", basetypes = True):
  1038     def GetDataTypes(self, tagname = "", basetypes = True):
  1043         if basetypes:
  1039         if basetypes:
  1048             words = tagname.split("::")
  1044             words = tagname.split("::")
  1049             if words[0] in ["D"]:
  1045             if words[0] in ["D"]:
  1050                 name = words[1]
  1046                 name = words[1]
  1051             else:
  1047             else:
  1052                 name = ""
  1048                 name = ""
  1053             for datatype in self.Project.getDataTypes():
  1049             for datatype in self.Project.getdataTypes():
  1054                 datatype_name = datatype.getName()
  1050                 datatype_name = datatype.getname()
  1055                 if datatype_name != name and not self.DataTypeIsUsedBy(name, datatype_name):
  1051                 if datatype_name != name and not self.DataTypeIsUsedBy(name, datatype_name):
  1056                     datatypes.append(datatype_name)
  1052                     datatypes.append(datatype_name)
  1057         return datatypes
  1053         return datatypes
  1058 
  1054 
  1059     # Return Base Types
  1055     # Return Base Types
  1103     # Return the data type informations
  1099     # Return the data type informations
  1104     def GetDataTypeInfos(self, tagname):
  1100     def GetDataTypeInfos(self, tagname):
  1105         words = tagname.split("::")
  1101         words = tagname.split("::")
  1106         if words[0] == "D":
  1102         if words[0] == "D":
  1107             infos = {}
  1103             infos = {}
  1108             datatype = self.Project.getDataType(words[1])
  1104             datatype = self.Project.getdataType(words[1])
  1109             basetype_content = datatype.baseType.getContent()
  1105             basetype_content = datatype.baseType.getcontent()
  1110             if basetype_content["value"] is None:
  1106             if basetype_content["value"] is None:
  1111                 infos["type"] = "Directly"
  1107                 infos["type"] = "Directly"
  1112                 infos["base_type"] = basetype_content["name"]
  1108                 infos["base_type"] = basetype_content["name"]
  1113             elif basetype_content["name"] == "derived":
  1109             elif basetype_content["name"] == "derived":
  1114                 infos["type"] = "Directly"
  1110                 infos["type"] = "Directly"
  1115                 infos["base_type"] = basetype_content["value"].getName()
  1111                 infos["base_type"] = basetype_content["value"].getname()
  1116             elif basetype_content["name"] in ["subrangeSigned", "subrangeUnsigned"]:
  1112             elif basetype_content["name"] in ["subrangeSigned", "subrangeUnsigned"]:
  1117                 infos["type"] = "Subrange"
  1113                 infos["type"] = "Subrange"
  1118                 infos["min"] = basetype_content["value"].range.getLower()
  1114                 infos["min"] = basetype_content["value"].range.getlower()
  1119                 infos["max"] = basetype_content["value"].range.getUpper()
  1115                 infos["max"] = basetype_content["value"].range.getupper()
  1120                 base_type = basetype_content["value"].baseType.getContent()
  1116                 base_type = basetype_content["value"].baseType.getcontent()
  1121                 if base_type["value"] is None:
  1117                 if base_type["value"] is None:
  1122                     infos["base_type"] = base_type["name"]
  1118                     infos["base_type"] = base_type["name"]
  1123                 else:
  1119                 else:
  1124                     infos["base_type"] = base_type["value"].getName()
  1120                     infos["base_type"] = base_type["value"].getname()
  1125             elif basetype_content["name"] == "enum":
  1121             elif basetype_content["name"] == "enum":
  1126                 infos["type"] = "Enumerated"
  1122                 infos["type"] = "Enumerated"
  1127                 infos["values"] = []
  1123                 infos["values"] = []
  1128                 for value in basetype_content["value"].values.getValue():
  1124                 for value in basetype_content["value"].values.getvalue():
  1129                     infos["values"].append(value.getName())
  1125                     infos["values"].append(value.getname())
  1130             elif basetype_content["name"] == "array":
  1126             elif basetype_content["name"] == "array":
  1131                 infos["type"] = "Array"
  1127                 infos["type"] = "Array"
  1132                 infos["dimensions"] = []
  1128                 infos["dimensions"] = []
  1133                 for dimension in basetype_content["value"].getDimension():
  1129                 for dimension in basetype_content["value"].getdimension():
  1134                     infos["dimensions"].append(str(dimension.getUpper()))
  1130                     infos["dimensions"].append(str(dimension.getupper()))
  1135                 base_type = basetype_content["value"].baseType.getContent()
  1131                 base_type = basetype_content["value"].baseType.getcontent()
  1136                 if base_type["value"] is None:
  1132                 if base_type["value"] is None:
  1137                     infos["base_type"] = base_type["name"]
  1133                     infos["base_type"] = base_type["name"]
  1138                 else:
  1134                 else:
  1139                     infos["base_type"] = base_type["value"].getName()
  1135                     infos["base_type"] = base_type["value"].getname()
  1140             if datatype.initialValue is not None:
  1136             if datatype.initialValue is not None:
  1141                 infos["initial"] = str(datatype.initialValue.getValue())
  1137                 infos["initial"] = str(datatype.initialValue.getvalue())
  1142             else:
  1138             else:
  1143                 infos["initial"] = ""
  1139                 infos["initial"] = ""
  1144             return infos
  1140             return infos
  1145         return None
  1141         return None
  1146     
  1142     
  1147     # Change the data type informations
  1143     # Change the data type informations
  1148     def SetDataTypeInfos(self, tagname, infos):
  1144     def SetDataTypeInfos(self, tagname, infos):
  1149         words = tagname.split("::")
  1145         words = tagname.split("::")
  1150         if words[0] == "D":
  1146         if words[0] == "D":
  1151             datatype = self.Project.getDataType(words[1])
  1147             datatype = self.Project.getdataType(words[1])
  1152             if infos["type"] == "Directly":
  1148             if infos["type"] == "Directly":
  1153                 if infos["base_type"] in self.GetBaseTypes():
  1149                 if infos["base_type"] in self.GetBaseTypes():
  1154                     if infos["base_type"] == "STRING":
  1150                     if infos["base_type"] == "STRING":
  1155                         datatype.baseType.setContent("string", plcopen.string())
  1151                         datatype.baseType.setcontent({"name" : "string", "value" : plcopen.elementaryTypes_string()})
  1156                     elif infos["base_type"] == "WSTRING":
  1152                     elif infos["base_type"] == "WSTRING":
  1157                         datatype.baseType.setContent("wstring", plcopen.wstring())
  1153                         datatype.baseType.setcontent({"name" : "wstring", "value" : plcopen.elementaryTypes_wstring()})
  1158                     else:
  1154                     else:
  1159                         datatype.baseType.setContent(infos["base_type"], None)
  1155                         datatype.baseType.setcontent({"name" : infos["base_type"], "value" : None})
  1160                 else:
  1156                 else:
  1161                     derived_datatype = plcopen.derived()
  1157                     derived_datatype = plcopen.derivedTypes_derived()
  1162                     derived_datatype.setName(infos["base_type"])
  1158                     derived_datatype.setname(infos["base_type"])
  1163                     datatype.baseType.setContent("derived", derived_datatype)
  1159                     datatype.baseType.setcontent({"name" : "derived", "value" : derived_datatype})
  1164             elif infos["type"] == "Subrange":
  1160             elif infos["type"] == "Subrange":
  1165                 if infos["base_type"] in GetSubTypes("ANY_UINT"):
  1161                 if infos["base_type"] in GetSubTypes("ANY_UINT"):
  1166                     subrange = plcopen.subrangeUnsigned()
  1162                     subrange = plcopen.derivedTypes_subrangeUnsigned()
  1167                     datatype.baseType.setContent("subrangeUnsigned", subrange)
  1163                     datatype.baseType.setcontent({"name" : "subrangeUnsigned", "value" : subrange})
  1168                 else:
  1164                 else:
  1169                     subrange = plcopen.subrangeSigned()
  1165                     subrange = plcopen.derivedTypes_subrangeSigned()
  1170                     datatype.baseType.setContent("subrangeSigned", subrange)
  1166                     datatype.baseType.setcontent({"name" : "subrangeSigned", "value" : subrange})
  1171                 subrange.range.setLower(infos["min"])
  1167                 subrange.range.setlower(infos["min"])
  1172                 subrange.range.setUpper(infos["max"])
  1168                 subrange.range.setupper(infos["max"])
  1173                 if infos["base_type"] in self.GetBaseTypes():
  1169                 if infos["base_type"] in self.GetBaseTypes():
  1174                     subrange.baseType.setContent(infos["base_type"], None)
  1170                     subrange.baseType.setcontent({"name" : infos["base_type"], "value" : None})
  1175                 else:
  1171                 else:
  1176                     derived_datatype = plcopen.derived()
  1172                     derived_datatype = plcopen.derivedTypes_derived()
  1177                     derived_datatype.setName(infos["base_type"])
  1173                     derived_datatype.setname(infos["base_type"])
  1178                     subrange.baseType.setContent("derived", derived_datatype)
  1174                     subrange.baseType.setcontent({"name" : "derived", "value" : derived_datatype})
  1179             elif infos["type"] == "Enumerated":
  1175             elif infos["type"] == "Enumerated":
  1180                 enumerated = plcopen.enum()
  1176                 enumerated = plcopen.derivedTypes_enum()
  1181                 for enum_value in infos["values"]:
  1177                 for i, enum_value in enumerate(infos["values"]):
  1182                     value = plcopen.values_value()
  1178                     value = plcopen.values_value()
  1183                     value.setName(enum_value)
  1179                     value.setname(enum_value)
  1184                     enumerated.values.appendValue(value)
  1180                     if i == 0:
  1185                 datatype.baseType.setContent("enum", enumerated)
  1181                         enumerated.values.setvalue([value])
       
  1182                     else:
       
  1183                         enumerated.values.appendvalue(value)
       
  1184                 datatype.baseType.setcontent({"name" : "enum", "value" : enumerated})
  1186             elif infos["type"] == "Array":
  1185             elif infos["type"] == "Array":
  1187                 array = plcopen.array()
  1186                 array = plcopen.derivedTypes_array()
  1188                 for dimension in infos["dimensions"]:
  1187                 for dimension in infos["dimensions"]:
  1189                     dimension_range = plcopen.rangeSigned()
  1188                     dimension_range = plcopen.rangeSigned()
  1190                     dimension_range.setLower(1)
  1189                     dimension_range.setlower(1)
  1191                     dimension_range.setUpper(int(dimension))
  1190                     dimension_range.setupper(int(dimension))
  1192                     array.appendDimension(dimension_range)
  1191                     array.appenddimension(dimension_range)
  1193                 if infos["base_type"] in self.GetBaseTypes():
  1192                 if infos["base_type"] in self.GetBaseTypes():
  1194                     if infos["base_type"] == "STRING":
  1193                     if infos["base_type"] == "STRING":
  1195                         array.baseType.setContent("string", plcopen.string())
  1194                         array.baseType.setcontent({"name" : "string", "value" : plcopen.elementaryTypes_string()})
  1196                     elif infos["base_type"] == "WSTRING":
  1195                     elif infos["base_type"] == "WSTRING":
  1197                         array.baseType.setContent("wstring", plcopen.wstring())
  1196                         array.baseType.setcontent({"name" : "wstring", "value" : plcopen.wstring()})
  1198                     else:
  1197                     else:
  1199                         array.baseType.setContent(infos["base_type"], None)
  1198                         array.baseType.setcontent({"name" : infos["base_type"], "value" : None})
  1200                 else:
  1199                 else:
  1201                     derived_datatype = plcopen.derived()
  1200                     derived_datatype = plcopen.derivedTypes_derived()
  1202                     derived_datatype.setName(infos["base_type"])
  1201                     derived_datatype.setname(infos["base_type"])
  1203                     array.baseType.setContent("derived", derived_datatype)
  1202                     array.baseType.setcontent({"name" : "derived", "value" : derived_datatype})
  1204                 datatype.baseType.setContent("array", array)
  1203                 datatype.baseType.setcontent({"name" : "array", "value" : array})
  1205             if infos["initial"] != "":
  1204             if infos["initial"] != "":
  1206                 if datatype.initialValue is None:
  1205                 if datatype.initialValue is None:
  1207                     datatype.initialValue = plcopen.value()
  1206                     datatype.initialValue = plcopen.value()
  1208                 datatype.initialValue.setValue(infos["initial"])
  1207                 datatype.initialValue.setvalue(infos["initial"])
  1209             else:
  1208             else:
  1210                 datatype.initialValue = None
  1209                 datatype.initialValue = None
  1211             self.RefreshDataTypeUsingTree()
  1210             self.RefreshDataTypeUsingTree()
  1212             self.RefreshDataTypes()
  1211             self.RefreshDataTypes()
  1213             self.BufferProject()
  1212             self.BufferProject()
  1218 
  1217 
  1219     # Return edited element
  1218     # Return edited element
  1220     def GetEditedElement(self, tagname):
  1219     def GetEditedElement(self, tagname):
  1221         words = tagname.split("::")
  1220         words = tagname.split("::")
  1222         if words[0] == "P":
  1221         if words[0] == "P":
  1223             return self.Project.getPou(words[1])
  1222             return self.Project.getpou(words[1])
  1224         if words[0] in ['T', 'A']:
  1223         if words[0] in ['T', 'A']:
  1225             pou = self.Project.getPou(words[1])
  1224             pou = self.Project.getpou(words[1])
  1226             if words[0] == 'T':
  1225             if words[0] == 'T':
  1227                 return pou.getTransition(words[2])
  1226                 return pou.gettransition(words[2])
  1228             elif words[0] == 'A':
  1227             elif words[0] == 'A':
  1229                 return pou.getAction(words[2])
  1228                 return pou.getaction(words[2])
  1230         elif words[0] == 'C':
  1229         elif words[0] == 'C':
  1231             return self.Project.getConfiguration(words[1])
  1230             return self.Project.getconfiguration(words[1])
  1232         elif words[0] == 'R':
  1231         elif words[0] == 'R':
  1233             return self.Project.getConfigurationResource(words[1], words[2])
  1232             return self.Project.getconfigurationResource(words[1], words[2])
  1234         return None
  1233         return None
  1235     
  1234     
  1236     # Return edited element name
  1235     # Return edited element name
  1237     def GetEditedElementName(self, tagname):
  1236     def GetEditedElementName(self, tagname):
  1238         words = tagname.split("::")
  1237         words = tagname.split("::")
  1262 
  1261 
  1263     # Return the edited element variables
  1262     # Return the edited element variables
  1264     def GetEditedElementInterfaceVars(self, tagname):
  1263     def GetEditedElementInterfaceVars(self, tagname):
  1265         words = tagname.split("::")
  1264         words = tagname.split("::")
  1266         if words[0] in ["P","T","A"]:
  1265         if words[0] in ["P","T","A"]:
  1267             pou = self.Project.getPou(words[1])
  1266             pou = self.Project.getpou(words[1])
  1268             return self.GetPouInterfaceVars(pou)
  1267             return self.GetPouInterfaceVars(pou)
  1269         return []
  1268         return []
  1270 
  1269 
  1271     # Return the edited element return type
  1270     # Return the edited element return type
  1272     def GetEditedElementInterfaceReturnType(self, tagname):
  1271     def GetEditedElementInterfaceReturnType(self, tagname):
  1273         words = tagname.split("::")
  1272         words = tagname.split("::")
  1274         if words[0] == "P":
  1273         if words[0] == "P":
  1275             pou = self.Project.getPou(words[1])
  1274             pou = self.Project.getpou(words[1])
  1276             return self.GetPouInterfaceReturnType(pou)
  1275             return self.GetPouInterfaceReturnType(pou)
  1277         elif words[0] == 'T':
  1276         elif words[0] == 'T':
  1278             return "BOOL"
  1277             return "BOOL"
  1279         return None
  1278         return None
  1280     
  1279     
  1281     # Change the edited element text
  1280     # Change the edited element text
  1282     def SetEditedElementText(self, tagname, text):
  1281     def SetEditedElementText(self, tagname, text):
  1283         element = self.GetEditedElement(tagname)
  1282         element = self.GetEditedElement(tagname)
  1284         if element != None:
  1283         if element != None:
  1285             element.setText(text)
  1284             element.settext(text)
  1286             self.RefreshPouUsingTree()
  1285             self.RefreshPouUsingTree()
  1287     
  1286     
  1288     # Return the edited element text
  1287     # Return the edited element text
  1289     def GetEditedElementText(self, tagname):
  1288     def GetEditedElementText(self, tagname):
  1290         element = self.GetEditedElement(tagname)
  1289         element = self.GetEditedElement(tagname)
  1291         if element != None:
  1290         if element != None:
  1292             return element.getText()
  1291             return element.gettext()
  1293         return ""
  1292         return ""
  1294 
  1293 
  1295     # Return the edited element transitions
  1294     # Return the edited element transitions
  1296     def GetEditedElementTransitions(self, tagname):
  1295     def GetEditedElementTransitions(self, tagname):
  1297         pou = self.GetEditedElement(tagname)
  1296         pou = self.GetEditedElement(tagname)
  1298         if pou != None and pou.getBodyType() == "SFC":
  1297         if pou != None and pou.getbodyType() == "SFC":
  1299             transitions = []
  1298             transitions = []
  1300             for transition in pou.getTransitionList():
  1299             for transition in pou.gettransitionList():
  1301                 transitions.append(transition.getName())
  1300                 transitions.append(transition.getname())
  1302             return transitions
  1301             return transitions
  1303         return []
  1302         return []
  1304 
  1303 
  1305     # Return edited element transitions
  1304     # Return edited element transitions
  1306     def GetEditedElementActions(self, tagname):
  1305     def GetEditedElementActions(self, tagname):
  1307         pou = self.GetEditedElement(tagname)
  1306         pou = self.GetEditedElement(tagname)
  1308         if pou != None and pou.getBodyType() == "SFC":
  1307         if pou != None and pou.getbodyType() == "SFC":
  1309             actions = []
  1308             actions = []
  1310             for action in pou.getActionList():
  1309             for action in pou.getactionList():
  1311                 actions.append(action.getName())
  1310                 actions.append(action.getname())
  1312             return actions
  1311             return actions
  1313         return []
  1312         return []
  1314 
  1313 
  1315     # Return the names of the pou elements
  1314     # Return the names of the pou elements
  1316     def GetEditedElementVariables(self, tagname):
  1315     def GetEditedElementVariables(self, tagname):
  1325         instance = None
  1324         instance = None
  1326         element = self.GetEditedElement(tagname)
  1325         element = self.GetEditedElement(tagname)
  1327         if element is not None:
  1326         if element is not None:
  1328             # if id is defined
  1327             # if id is defined
  1329             if id is not None:
  1328             if id is not None:
  1330                 instance = element.getInstance(id)
  1329                 instance = element.getinstance(id)
  1331             else:
  1330             else:
  1332                 instance = element.getRandomInstance(exclude)
  1331                 instance = element.getrandomInstance(exclude)
  1333         if instance is not None:
  1332         if instance is not None:
  1334             if id is not None:
  1333             if id is not None:
  1335                 infos["id"] = id
  1334                 infos["id"] = id
  1336             else:
  1335             else:
  1337                 infos["id"] = instance.getLocalId() 
  1336                 infos["id"] = instance.getlocalId() 
  1338             infos["x"] = instance.getX()
  1337             infos["x"] = instance.getx()
  1339             infos["y"] = instance.getY()
  1338             infos["y"] = instance.gety()
  1340             infos["height"] = instance.getHeight()
  1339             infos["height"] = instance.getheight()
  1341             infos["width"] = instance.getWidth()
  1340             infos["width"] = instance.getwidth()
  1342             if isinstance(instance, plcopen.block):
  1341             if isinstance(instance, plcopen.fbdObjects_block):
  1343                 infos["name"] = instance.getInstanceName()
  1342                 infos["name"] = instance.getinstanceName()
  1344                 infos["type"] = instance.getTypeName()
  1343                 infos["type"] = instance.gettypeName()
  1345                 executionOrder = instance.getExecutionOrderId()
  1344                 executionOrder = instance.getexecutionOrderId()
  1346                 if executionOrder is not None:
  1345                 if executionOrder is not None:
  1347                     infos["executionOrder"] = executionOrder
  1346                     infos["executionOrder"] = executionOrder
  1348                 else:
  1347                 else:
  1349                     infos["executionOrder"] = 0
  1348                     infos["executionOrder"] = 0
  1350                 infos["connectors"] = {"inputs":[],"outputs":[]}
  1349                 infos["connectors"] = {"inputs":[],"outputs":[]}
  1351                 for variable in instance.inputVariables.getVariable():
  1350                 for variable in instance.inputVariables.getvariable():
  1352                     connector = {}
  1351                     connector = {}
  1353                     connector["name"] = variable.getFormalParameter()
  1352                     connector["name"] = variable.getformalParameter()
  1354                     connector["position"] = variable.connectionPointIn.getRelPosition()
  1353                     connector["position"] = variable.connectionPointIn.getrelPositionXY()
  1355                     connector["negated"] = variable.getNegated()
  1354                     connector["negated"] = variable.getnegated()
  1356                     connector["edge"] = variable.getConnectorEdge()
  1355                     connector["edge"] = variable.getedge()
  1357                     connector["links"] = []
  1356                     connector["links"] = []
  1358                     connections = variable.connectionPointIn.getConnections()
  1357                     connections = variable.connectionPointIn.getconnections()
  1359                     if connections:
  1358                     if connections:
  1360                         for link in connections:
  1359                         for link in connections:
  1361                             dic = {"refLocalId":link.getRefLocalId(),"points":link.getPoints(),"formalParameter":link.getFormalParameter()}
  1360                             dic = {"refLocalId":link.getrefLocalId(),"points":link.getpoints(),"formalParameter":link.getformalParameter()}
  1362                             connector["links"].append(dic)
  1361                             connector["links"].append(dic)
  1363                     infos["connectors"]["inputs"].append(connector)
  1362                     infos["connectors"]["inputs"].append(connector)
  1364                 for variable in instance.outputVariables.getVariable():
  1363                 for variable in instance.outputVariables.getvariable():
  1365                     connector = {}
  1364                     connector = {}
  1366                     connector["name"] = variable.getFormalParameter()
  1365                     connector["name"] = variable.getformalParameter()
  1367                     connector["position"] = variable.connectionPointOut.getRelPosition()
  1366                     connector["position"] = variable.connectionPointOut.getrelPositionXY()
  1368                     connector["negated"] = variable.getNegated()
  1367                     connector["negated"] = variable.getnegated()
  1369                     connector["edge"] = variable.getConnectorEdge()
  1368                     connector["edge"] = variable.getedge()
  1370                     infos["connectors"]["outputs"].append(connector)
  1369                     infos["connectors"]["outputs"].append(connector)
  1371             elif isinstance(instance, plcopen.inVariable):
  1370             elif isinstance(instance, plcopen.fbdObjects_inVariable):
  1372                 infos["name"] = instance.getExpression()
  1371                 infos["name"] = instance.getexpression()
  1373                 infos["value_type"] = self.GetEditedElementVarValueType(tagname, infos["name"])
  1372                 infos["value_type"] = self.GetEditedElementVarValueType(tagname, infos["name"])
  1374                 infos["type"] = "input"
  1373                 infos["type"] = "input"
  1375                 executionOrder = instance.getExecutionOrderId()
  1374                 executionOrder = instance.getexecutionOrderId()
  1376                 if executionOrder is not None:
  1375                 if executionOrder is not None:
  1377                     infos["executionOrder"] = executionOrder
  1376                     infos["executionOrder"] = executionOrder
  1378                 else:
  1377                 else:
  1379                     infos["executionOrder"] = 0
  1378                     infos["executionOrder"] = 0
  1380                 infos["connector"] = {}
  1379                 infos["connector"] = {}
  1381                 infos["connector"]["position"] = instance.connectionPointOut.getRelPosition()
  1380                 infos["connector"]["position"] = instance.connectionPointOut.getrelPositionXY()
  1382                 infos["connector"]["negated"] = instance.getNegated()
  1381                 infos["connector"]["negated"] = instance.getnegated()
  1383                 infos["connector"]["edge"] = instance.getConnectorEdge()
  1382                 infos["connector"]["edge"] = instance.getedge()
  1384             elif isinstance(instance, plcopen.outVariable):
  1383             elif isinstance(instance, plcopen.fbdObjects_outVariable):
  1385                 infos["name"] = instance.getExpression()
  1384                 infos["name"] = instance.getexpression()
  1386                 infos["value_type"] = self.GetEditedElementVarValueType(tagname, infos["name"])
  1385                 infos["value_type"] = self.GetEditedElementVarValueType(tagname, infos["name"])
  1387                 infos["type"] = "output"
  1386                 infos["type"] = "output"
  1388                 executionOrder = instance.getExecutionOrderId()
  1387                 executionOrder = instance.getexecutionOrderId()
  1389                 if executionOrder is not None:
  1388                 if executionOrder is not None:
  1390                     infos["executionOrder"] = executionOrder
  1389                     infos["executionOrder"] = executionOrder
  1391                 else:
  1390                 else:
  1392                     infos["executionOrder"] = 0
  1391                     infos["executionOrder"] = 0
  1393                 infos["connector"] = {}
  1392                 infos["connector"] = {}
  1394                 infos["connector"]["position"] = instance.connectionPointIn.getRelPosition()
  1393                 infos["connector"]["position"] = instance.connectionPointIn.getrelPositionXY()
  1395                 infos["connector"]["negated"] = instance.getNegated()
  1394                 infos["connector"]["negated"] = instance.getnegated()
  1396                 infos["connector"]["edge"] = instance.getConnectorEdge()
  1395                 infos["connector"]["edge"] = instance.getedge()
  1397                 infos["connector"]["links"] = []
  1396                 infos["connector"]["links"] = []
  1398                 connections = instance.connectionPointIn.getConnections()
  1397                 connections = instance.connectionPointIn.getconnections()
  1399                 if connections:
  1398                 if connections:
  1400                     for link in connections:
  1399                     for link in connections:
  1401                         dic = {"refLocalId":link.getRefLocalId(),"points":link.getPoints(),"formalParameter":link.getFormalParameter()}
  1400                         dic = {"refLocalId":link.getrefLocalId(),"points":link.getpoints(),"formalParameter":link.getformalParameter()}
  1402                         infos["connector"]["links"].append(dic)
  1401                         infos["connector"]["links"].append(dic)
  1403             elif isinstance(instance, plcopen.inOutVariable):
  1402             elif isinstance(instance, plcopen.fbdObjects_inOutVariable):
  1404                 infos["name"] = instance.getExpression()
  1403                 infos["name"] = instance.getexpression()
  1405                 infos["value_type"] = self.GetEditedElementVarValueType(tagname, infos["name"])
  1404                 infos["value_type"] = self.GetEditedElementVarValueType(tagname, infos["name"])
  1406                 infos["type"] = "inout"
  1405                 infos["type"] = "inout"
  1407                 executionOrder = instance.getExecutionOrderId()
  1406                 executionOrder = instance.getexecutionOrderId()
  1408                 if executionOrder is not None:
  1407                 if executionOrder is not None:
  1409                     infos["executionOrder"] = executionOrder
  1408                     infos["executionOrder"] = executionOrder
  1410                 else:
  1409                 else:
  1411                     infos["executionOrder"] = 0
  1410                     infos["executionOrder"] = 0
  1412                 infos["connectors"] = {"input":{},"output":{}}
  1411                 infos["connectors"] = {"input":{},"output":{}}
  1413                 infos["connectors"]["output"]["position"] = instance.connectionPointOut.getRelPosition()
  1412                 infos["connectors"]["output"]["position"] = instance.connectionPointOut.getrelPositionXY()
  1414                 infos["connectors"]["output"]["negated"] = instance.getNegatedOut()
  1413                 infos["connectors"]["output"]["negated"] = instance.getnegatedOut()
  1415                 infos["connectors"]["output"]["edge"] = instance.getOutputEdge()
  1414                 infos["connectors"]["output"]["edge"] = instance.getedgeOut()
  1416                 infos["connectors"]["input"]["position"] = instance.connectionPointIn.getRelPosition()
  1415                 infos["connectors"]["input"]["position"] = instance.connectionPointIn.getrelPositionXY()
  1417                 infos["connectors"]["input"]["negated"] = instance.getNegatedIn()
  1416                 infos["connectors"]["input"]["negated"] = instance.getnegatedIn()
  1418                 infos["connectors"]["input"]["edge"] = instance.getInputEdge()
  1417                 infos["connectors"]["input"]["edge"] = instance.getedgeIn()
  1419                 infos["connectors"]["input"]["links"] = []
  1418                 infos["connectors"]["input"]["links"] = []
  1420                 connections = instance.connectionPointIn.getConnections()
  1419                 connections = instance.connectionPointIn.getconnections()
  1421                 if connections:
  1420                 if connections:
  1422                     for link in connections:
  1421                     for link in connections:
  1423                         dic = {"refLocalId":link.getRefLocalId(),"points":link.getPoints(),"formalParameter":link.getFormalParameter()}
  1422                         dic = {"refLocalId":link.getrefLocalId(),"points":link.getpoints(),"formalParameter":link.getformalParameter()}
  1424                         infos["connectors"]["input"]["links"].append(dic)
  1423                         infos["connectors"]["input"]["links"].append(dic)
  1425             elif isinstance(instance, plcopen.continuation):
  1424             elif isinstance(instance, plcopen.commonObjects_continuation):
  1426                 infos["name"] = instance.getName()
  1425                 infos["name"] = instance.getname()
  1427                 infos["type"] = "continuation"
  1426                 infos["type"] = "continuation"
  1428                 infos["connector"] = {}
  1427                 infos["connector"] = {}
  1429                 infos["connector"]["position"] = instance.connectionPointOut.getRelPosition()
  1428                 infos["connector"]["position"] = instance.connectionPointOut.getrelPositionXY()
  1430             elif isinstance(instance, plcopen.connector):
  1429             elif isinstance(instance, plcopen.commonObjects_connector):
  1431                 infos["name"] = instance.getName()
  1430                 infos["name"] = instance.getName()
  1432                 infos["type"] = "connection"
  1431                 infos["type"] = "connection"
  1433                 infos["connector"] = {}
  1432                 infos["connector"] = {}
  1434                 infos["connector"]["position"] = instance.connectionPointIn.getRelPosition()
  1433                 infos["connector"]["position"] = instance.connectionPointIn.getrelPositionXY()
  1435                 infos["connector"]["links"] = []
  1434                 infos["connector"]["links"] = []
  1436                 connections = instance.connectionPointIn.getConnections()
  1435                 connections = instance.connectionPointIn.getconnections()
  1437                 if connections:
  1436                 if connections:
  1438                     for link in connections:
  1437                     for link in connections:
  1439                         dic = {"refLocalId":link.getRefLocalId(),"points":link.getPoints(),"formalParameter":link.getFormalParameter()}
  1438                         dic = {"refLocalId":link.getrefLocalId(),"points":link.getpoints(),"formalParameter":link.getformalParameter()}
  1440                         infos["connector"]["links"].append(dic)
  1439                         infos["connector"]["links"].append(dic)
  1441             elif isinstance(instance, plcopen.comment):
  1440             elif isinstance(instance, plcopen.commonObjects_comment):
  1442                 infos["type"] = "comment"
  1441                 infos["type"] = "comment"
  1443                 infos["content"] = instance.getContentText()
  1442                 infos["content"] = instance.getcontentText()
  1444             elif isinstance(instance, plcopen.leftPowerRail):
  1443             elif isinstance(instance, plcopen.ldObjects_leftPowerRail):
  1445                 infos["type"] = "leftPowerRail"
  1444                 infos["type"] = "leftPowerRail"
  1446                 infos["connectors"] = []
  1445                 infos["connectors"] = []
  1447                 for connection in instance.getConnectionPointOut():
  1446                 for connection in instance.getconnectionPointOut():
  1448                     connector = {}
  1447                     connector = {}
  1449                     connector["position"] = connection.getRelPosition()
  1448                     connector["position"] = connection.getrelPositionXY()
  1450                     infos["connectors"].append(connector)
  1449                     infos["connectors"].append(connector)
  1451             elif isinstance(instance, plcopen.rightPowerRail):
  1450             elif isinstance(instance, plcopen.ldObjects_rightPowerRail):
  1452                 infos["type"] = "rightPowerRail"
  1451                 infos["type"] = "rightPowerRail"
  1453                 infos["connectors"] = []
  1452                 infos["connectors"] = []
  1454                 for connection in instance.getConnectionPointIn():
  1453                 for connection in instance.getconnectionPointIn():
  1455                     connector = {}
  1454                     connector = {}
  1456                     connector["position"] = connection.getRelPosition()
  1455                     connector["position"] = connection.getrelPositionXY()
  1457                     connector["links"] = []
  1456                     connector["links"] = []
  1458                     connections = connection.getConnections()
  1457                     connections = connection.getconnections()
  1459                     if connections:
  1458                     if connections:
  1460                         for link in connection.getConnections():
  1459                         for link in connection.getconnections():
  1461                             dic = {"refLocalId":link.getRefLocalId(),"points":link.getPoints(),"formalParameter":link.getFormalParameter()}
  1460                             dic = {"refLocalId":link.getrefLocalId(),"points":link.getpoints(),"formalParameter":link.getformalParameter()}
  1462                             connector["links"].append(dic)
  1461                             connector["links"].append(dic)
  1463                     infos["connectors"].append(connector)
  1462                     infos["connectors"].append(connector)
  1464             elif isinstance(instance, plcopen.contact):
  1463             elif isinstance(instance, plcopen.ldObjects_contact):
  1465                 infos["name"] = instance.getVariable()
  1464                 infos["name"] = instance.getvariable()
  1466                 infos["type"] = "contact"
  1465                 infos["type"] = "contact"
  1467                 executionOrder = instance.getExecutionOrderId()
  1466                 executionOrder = instance.getexecutionOrderId()
  1468                 if executionOrder is not None:
  1467                 if executionOrder is not None:
  1469                     infos["executionOrder"] = executionOrder
  1468                     infos["executionOrder"] = executionOrder
  1470                 else:
  1469                 else:
  1471                     infos["executionOrder"] = 0
  1470                     infos["executionOrder"] = 0
  1472                 infos["negated"] = instance.getNegated()
  1471                 infos["negated"] = instance.getnegated()
  1473                 infos["edge"] = instance.getContactEdge()
  1472                 infos["edge"] = instance.getedge()
  1474                 infos["connectors"] = {"input":{},"output":{}}
  1473                 infos["connectors"] = {"input":{},"output":{}}
  1475                 infos["connectors"]["input"]["position"] = instance.connectionPointIn.getRelPosition()
  1474                 infos["connectors"]["input"]["position"] = instance.connectionPointIn.getrelPositionXY()
  1476                 infos["connectors"]["input"]["links"] = []
  1475                 infos["connectors"]["input"]["links"] = []
  1477                 connections = instance.connectionPointIn.getConnections()
  1476                 connections = instance.connectionPointIn.getconnections()
  1478                 if connections:
  1477                 if connections:
  1479                     for link in connections:
  1478                     for link in connections:
  1480                         dic = {"refLocalId":link.getRefLocalId(),"points":link.getPoints(),"formalParameter":link.getFormalParameter()}
  1479                         dic = {"refLocalId":link.getrefLocalId(),"points":link.getpoints(),"formalParameter":link.getformalParameter()}
  1481                         infos["connectors"]["input"]["links"].append(dic)
  1480                         infos["connectors"]["input"]["links"].append(dic)
  1482                 infos["connectors"]["output"]["position"] = instance.connectionPointOut.getRelPosition()
  1481                 infos["connectors"]["output"]["position"] = instance.connectionPointOut.getrelPositionXY()
  1483             elif isinstance(instance, plcopen.coil):
  1482             elif isinstance(instance, plcopen.ldObjects_coil):
  1484                 infos["name"] = instance.getVariable()
  1483                 infos["name"] = instance.getvariable()
  1485                 infos["type"] = "coil"
  1484                 infos["type"] = "coil"
  1486                 executionOrder = instance.getExecutionOrderId()
  1485                 executionOrder = instance.getexecutionOrderId()
  1487                 if executionOrder is not None:
  1486                 if executionOrder is not None:
  1488                     infos["executionOrder"] = executionOrder
  1487                     infos["executionOrder"] = executionOrder
  1489                 else:
  1488                 else:
  1490                     infos["executionOrder"] = 0
  1489                     infos["executionOrder"] = 0
  1491                 infos["negated"] = instance.getNegated()
  1490                 infos["negated"] = instance.getnegated()
  1492                 infos["storage"] = instance.getCoilStorage()
  1491                 infos["storage"] = instance.getstorage()
  1493                 infos["connectors"] = {"input":{},"output":{}}
  1492                 infos["connectors"] = {"input":{},"output":{}}
  1494                 infos["connectors"]["input"]["position"] = instance.connectionPointIn.getRelPosition()
  1493                 infos["connectors"]["input"]["position"] = instance.connectionPointIn.getrelPositionXY()
  1495                 infos["connectors"]["input"]["links"] = []
  1494                 infos["connectors"]["input"]["links"] = []
  1496                 connections = instance.connectionPointIn.getConnections()
  1495                 connections = instance.connectionPointIn.getconnections()
  1497                 if connections:
  1496                 if connections:
  1498                     for link in connections:
  1497                     for link in connections:
  1499                         dic = {"refLocalId":link.getRefLocalId(),"points":link.getPoints(),"formalParameter":link.getFormalParameter()}
  1498                         dic = {"refLocalId":link.getrefLocalId(),"points":link.getpoints(),"formalParameter":link.getformalParameter()}
  1500                         infos["connectors"]["input"]["links"].append(dic)
  1499                         infos["connectors"]["input"]["links"].append(dic)
  1501                 infos["connectors"]["output"]["position"] = instance.connectionPointOut.getRelPosition()
  1500                 infos["connectors"]["output"]["position"] = instance.connectionPointOut.getrelPositionXY()
  1502             elif isinstance(instance, plcopen.step):
  1501             elif isinstance(instance, plcopen.sfcObjects_step):
  1503                 infos["name"] = instance.getName()
  1502                 infos["name"] = instance.getname()
  1504                 infos["type"] = "step"
  1503                 infos["type"] = "step"
  1505                 infos["initial"] = instance.getInitialStep()
  1504                 infos["initial"] = instance.getinitialStep()
  1506                 infos["connectors"] = {}
  1505                 infos["connectors"] = {}
  1507                 if instance.connectionPointIn:
  1506                 if instance.connectionPointIn:
  1508                     infos["connectors"]["input"] = {}
  1507                     infos["connectors"]["input"] = {}
  1509                     infos["connectors"]["input"]["position"] = instance.connectionPointIn.getRelPosition()
  1508                     infos["connectors"]["input"]["position"] = instance.connectionPointIn.getrelPositionXY()
  1510                     infos["connectors"]["input"]["links"] = []
  1509                     infos["connectors"]["input"]["links"] = []
  1511                     connections = instance.connectionPointIn.getConnections()
  1510                     connections = instance.connectionPointIn.getconnections()
  1512                     if connections:
  1511                     if connections:
  1513                         for link in connections:
  1512                         for link in connections:
  1514                             dic = {"refLocalId":link.getRefLocalId(),"points":link.getPoints(),"formalParameter":link.getFormalParameter()}
  1513                             dic = {"refLocalId":link.getrefLocalId(),"points":link.getpoints(),"formalParameter":link.getformalParameter()}
  1515                             infos["connectors"]["input"]["links"].append(dic)
  1514                             infos["connectors"]["input"]["links"].append(dic)
  1516                 if instance.connectionPointOut:
  1515                 if instance.connectionPointOut:
  1517                     infos["connectors"]["output"] = {"position" : instance.connectionPointOut.getRelPosition()}
  1516                     infos["connectors"]["output"] = {"position" : instance.connectionPointOut.getrelPositionXY()}
  1518                 if instance.connectionPointOutAction:
  1517                 if instance.connectionPointOutAction:
  1519                     infos["connectors"]["action"] = {"position" : instance.connectionPointOutAction.getRelPosition()}
  1518                     infos["connectors"]["action"] = {"position" : instance.connectionPointOutAction.getrelPositionXY()}
  1520             elif isinstance(instance, plcopen.transition):
  1519             elif isinstance(instance, plcopen.sfcObjects_transition):
  1521                 infos["type"] = "transition"
  1520                 infos["type"] = "transition"
  1522                 condition = instance.getConditionContent()
  1521                 condition = instance.getconditionContent()
  1523                 priority = instance.getPriority()
  1522                 priority = instance.getpriority()
  1524                 if priority == None:
  1523                 if priority == None:
  1525                     infos["priority"] = 0
  1524                     infos["priority"] = 0
  1526                 else:
  1525                 else:
  1527                     infos["priority"] = priority
  1526                     infos["priority"] = priority
  1528                 infos["condition_type"] = condition["type"]
  1527                 infos["condition_type"] = condition["type"]
  1529                 infos["connectors"] = {"input":{},"output":{}}
  1528                 infos["connectors"] = {"input":{},"output":{}}
  1530                 infos["connectors"]["input"]["position"] = instance.connectionPointIn.getRelPosition()
  1529                 infos["connectors"]["input"]["position"] = instance.connectionPointIn.getrelPositionXY()
  1531                 infos["connectors"]["input"]["links"] = []
  1530                 infos["connectors"]["input"]["links"] = []
  1532                 connections = instance.connectionPointIn.getConnections()
  1531                 connections = instance.connectionPointIn.getconnections()
  1533                 if connections:
  1532                 if connections:
  1534                     for link in connections:
  1533                     for link in connections:
  1535                         dic = {"refLocalId":link.getRefLocalId(),"points":link.getPoints(),"formalParameter":link.getFormalParameter()}
  1534                         dic = {"refLocalId":link.getrefLocalId(),"points":link.getpoints(),"formalParameter":link.getformalParameter()}
  1536                         infos["connectors"]["input"]["links"].append(dic)
  1535                         infos["connectors"]["input"]["links"].append(dic)
  1537                 infos["connectors"]["output"]["position"] = instance.connectionPointOut.getRelPosition()
  1536                 infos["connectors"]["output"]["position"] = instance.connectionPointOut.getrelPositionXY()
  1538                 if infos["condition_type"] == "connection":
  1537                 if infos["condition_type"] == "connection":
  1539                     infos["connectors"]["connection"] = {}
  1538                     infos["connectors"]["connection"] = {}
  1540                     infos["connectors"]["connection"]["links"] = []
  1539                     infos["connectors"]["connection"]["links"] = []
  1541                     connections = instance.getConnections()
  1540                     connections = instance.getconnections()
  1542                     if connections:
  1541                     if connections:
  1543                         for link in connections:
  1542                         for link in connections:
  1544                             dic = {"refLocalId":link.getRefLocalId(),"points":link.getPoints(),"formalParameter":link.getFormalParameter()}
  1543                             dic = {"refLocalId":link.getrefLocalId(),"points":link.getpoints(),"formalParameter":link.getformalParameter()}
  1545                             infos["connectors"]["connection"]["links"].append(dic)
  1544                             infos["connectors"]["connection"]["links"].append(dic)
  1546                     infos["condition"] = None
  1545                     infos["condition"] = None
  1547                 else:
  1546                 else:
  1548                     infos["condition"] = condition["value"]
  1547                     infos["condition"] = condition["value"]
  1549             elif isinstance(instance, (plcopen.selectionDivergence, plcopen.simultaneousDivergence)):
  1548             elif isinstance(instance, (plcopen.sfcObjects_selectionDivergence, plcopen.sfcObjects_simultaneousDivergence)):
  1550                 if isinstance(instance, plcopen.selectionDivergence):
  1549                 if isinstance(instance, plcopen.sfcObjects_selectionDivergence):
  1551                     infos["type"] = "selectionDivergence"
  1550                     infos["type"] = "selectionDivergence"
  1552                 else:
  1551                 else:
  1553                     infos["type"] = "simultaneousDivergence"
  1552                     infos["type"] = "simultaneousDivergence"
  1554                 infos["connectors"] = {"inputs":[],"outputs":[]}
  1553                 infos["connectors"] = {"inputs":[],"outputs":[]}
  1555                 connector = {}
  1554                 connector = {}
  1556                 connector["position"] = instance.connectionPointIn.getRelPosition()
  1555                 connector["position"] = instance.connectionPointIn.getrelPositionXY()
  1557                 connector["links"] = []
  1556                 connector["links"] = []
  1558                 connections = instance.connectionPointIn.getConnections()
  1557                 connections = instance.connectionPointIn.getconnections()
  1559                 if connections:
  1558                 if connections:
  1560                     for link in connections:
  1559                     for link in connections:
  1561                         dic = {"refLocalId":link.getRefLocalId(),"points":link.getPoints(),"formalParameter":link.getFormalParameter()}
  1560                         dic = {"refLocalId":link.getrefLocalId(),"points":link.getpoints(),"formalParameter":link.getformalParameter()}
  1562                         connector["links"].append(dic)
  1561                         connector["links"].append(dic)
  1563                 infos["connectors"]["inputs"].append(connector)
  1562                 infos["connectors"]["inputs"].append(connector)
  1564                 for sequence in instance.getConnectionPointOut():
  1563                 for sequence in instance.getconnectionPointOut():
  1565                     connector = {}
  1564                     connector = {}
  1566                     connector["position"] = sequence.getRelPosition()
  1565                     connector["position"] = sequence.getrelPositionXY()
  1567                     infos["connectors"]["outputs"].append(connector)
  1566                     infos["connectors"]["outputs"].append(connector)
  1568             elif isinstance(instance, (plcopen.selectionConvergence, plcopen.simultaneousConvergence)):
  1567             elif isinstance(instance, (plcopen.sfcObjects_selectionConvergence, plcopen.sfcObjects_simultaneousConvergence)):
  1569                 if isinstance(instance, plcopen.selectionConvergence):
  1568                 if isinstance(instance, plcopen.sfcObjects_selectionConvergence):
  1570                     infos["type"] = "selectionConvergence"
  1569                     infos["type"] = "selectionConvergence"
  1571                 else:
  1570                 else:
  1572                     infos["type"] = "simultaneousConvergence"
  1571                     infos["type"] = "simultaneousConvergence"
  1573                 infos["connectors"] = {"inputs":[],"outputs":[]}
  1572                 infos["connectors"] = {"inputs":[],"outputs":[]}
  1574                 for sequence in instance.getConnectionPointIn():
  1573                 for sequence in instance.getconnectionPointIn():
  1575                     connector = {}
  1574                     connector = {}
  1576                     connector["position"] = sequence.getRelPosition()
  1575                     connector["position"] = sequence.getrelPositionXY()
  1577                     connector["links"] = []
  1576                     connector["links"] = []
  1578                     connections = sequence.getConnections()
  1577                     connections = sequence.getconnections()
  1579                     if connections:
  1578                     if connections:
  1580                         for link in connections:
  1579                         for link in connections:
  1581                             dic = {"refLocalId":link.getRefLocalId(),"points":link.getPoints(),"formalParameter":link.getFormalParameter()}
  1580                             dic = {"refLocalId":link.getrefLocalId(),"points":link.getpoints(),"formalParameter":link.getformalParameter()}
  1582                             connector["links"].append(dic)
  1581                             connector["links"].append(dic)
  1583                     infos["connectors"]["inputs"].append(connector)
  1582                     infos["connectors"]["inputs"].append(connector)
  1584                 connector = {}
  1583                 connector = {}
  1585                 connector["position"] = instance.connectionPointOut.getRelPosition()
  1584                 connector["position"] = instance.connectionPointOut.getrelPositionXY()
  1586                 infos["connectors"]["outputs"].append(connector)
  1585                 infos["connectors"]["outputs"].append(connector)
  1587             elif isinstance(instance, plcopen.jumpStep):
  1586             elif isinstance(instance, plcopen.sfcObjects_jumpStep):
  1588                 infos["type"] = "jump"
  1587                 infos["type"] = "jump"
  1589                 infos["target"] = instance.getTargetName()
  1588                 infos["target"] = instance.gettargetName()
  1590                 infos["connector"] = {}
  1589                 infos["connector"] = {}
  1591                 infos["connector"]["position"] = instance.connectionPointIn.getRelPosition()
  1590                 infos["connector"]["position"] = instance.connectionPointIn.getrelPositionXY()
  1592                 infos["connector"]["links"] = []
  1591                 infos["connector"]["links"] = []
  1593                 connections = instance.connectionPointIn.getConnections()
  1592                 connections = instance.connectionPointIn.getconnections()
  1594                 if connections:
  1593                 if connections:
  1595                     for link in connections:
  1594                     for link in connections:
  1596                         dic = {"refLocalId":link.getRefLocalId(),"points":link.getPoints(),"formalParameter":link.getFormalParameter()}
  1595                         dic = {"refLocalId":link.getrefLocalId(),"points":link.getpoints(),"formalParameter":link.getformalParameter()}
  1597                         infos["connector"]["links"].append(dic)
  1596                         infos["connector"]["links"].append(dic)
  1598             elif isinstance(instance, plcopen.actionBlock):
  1597             elif isinstance(instance, plcopen.commonObjects_actionBlock):
  1599                 infos["type"] = "actionBlock"
  1598                 infos["type"] = "actionBlock"
  1600                 infos["actions"] = instance.getActions()
  1599                 infos["actions"] = instance.getactions()
  1601                 infos["connector"] = {}
  1600                 infos["connector"] = {}
  1602                 infos["connector"]["position"] = instance.connectionPointIn.getRelPosition()
  1601                 infos["connector"]["position"] = instance.connectionPointIn.getrelPositionXY()
  1603                 infos["connector"]["links"] = []
  1602                 infos["connector"]["links"] = []
  1604                 connections = instance.connectionPointIn.getConnections()
  1603                 connections = instance.connectionPointIn.getconnections()
  1605                 if connections:
  1604                 if connections:
  1606                     for link in connections:
  1605                     for link in connections:
  1607                         dic = {"refLocalId":link.getRefLocalId(),"points":link.getPoints(),"formalParameter":link.getFormalParameter()}
  1606                         dic = {"refLocalId":link.getrefLocalId(),"points":link.getpoints(),"formalParameter":link.getformalParameter()}
  1608                         infos["connector"]["links"].append(dic)
  1607                         infos["connector"]["links"].append(dic)
  1609             return infos
  1608             return infos
  1610         return False
  1609         return False
  1611     
  1610     
  1612     def ClearEditedElementExecutionOrder(self, tagname):
  1611     def ClearEditedElementExecutionOrder(self, tagname):
  1613         element = self.GetEditedElement(tagname)
  1612         element = self.GetEditedElement(tagname)
  1614         if element is not None:
  1613         if element is not None:
  1615             element.resetExecutionOrder()
  1614             element.resetexecutionOrder()
  1616     
  1615     
  1617     def ResetEditedElementExecutionOrder(self, tagname):
  1616     def ResetEditedElementExecutionOrder(self, tagname):
  1618         element = self.GetEditedElement(tagname)
  1617         element = self.GetEditedElement(tagname)
  1619         if element is not None:
  1618         if element is not None:
  1620             element.compileExecutionOrder()
  1619             element.compileexecutionOrder()
  1621     
  1620     
  1622     # Return the variable type of the given pou
  1621     # Return the variable type of the given pou
  1623     def GetEditedElementVarValueType(self, tagname, varname):
  1622     def GetEditedElementVarValueType(self, tagname, varname):
  1624         words = tagname.split("::")
  1623         words = tagname.split("::")
  1625         if words[0] in ["P","T","A"]:
  1624         if words[0] in ["P","T","A"]:
  1626             pou = self.Project.getPou(words[1])
  1625             pou = self.Project.getpou(words[1])
  1627             for type, varlist in pou.getVars():
  1626             for type, varlist in pou.getvars():
  1628                 for var in varlist.getVariable():
  1627                 for var in varlist.getvariable():
  1629                     if var.getName() == varname:
  1628                     if var.getname() == varname:
  1630                         vartype_content = var.getType().getContent()
  1629                         vartype_content = var.gettype().getcontent()
  1631                         if vartype_content["name"] == "derived":
  1630                         if vartype_content["name"] == "derived":
  1632                             return vartype_content["value"].getName()
  1631                             return vartype_content["value"].getname()
  1633                         elif vartype_content["name"] in ["string", "wstring"]:
  1632                         elif vartype_content["name"] in ["string", "wstring"]:
  1634                             return vartype_content["name"].upper()
  1633                             return vartype_content["name"].upper()
  1635                         else:
  1634                         else:
  1636                             return vartype_content["name"]
  1635                             return vartype_content["name"]
  1637         return None
  1636         return None
  1645                 result = wire.GetConnectedInfos(-1)
  1644                 result = wire.GetConnectedInfos(-1)
  1646             else:
  1645             else:
  1647                 result = wire.GetConnectedInfos(0)
  1646                 result = wire.GetConnectedInfos(0)
  1648             if result != None:
  1647             if result != None:
  1649                 refLocalId, formalParameter = result
  1648                 refLocalId, formalParameter = result
  1650                 connection.addConnection()
  1649                 connection.addconnection()
  1651                 connection.setConnectionId(idx, refLocalId)
  1650                 connection.setconnectionId(idx, refLocalId)
  1652                 connection.setConnectionPoints(idx, points)
  1651                 connection.setconnectionPoints(idx, points)
  1653                 if formalParameter != "":
  1652                 if formalParameter != "":
  1654                     connection.setConnectionParameter(idx, formalParameter)
  1653                     connection.setconnectionParameter(idx, formalParameter)
  1655                 else:
  1654                 else:
  1656                     connection.setConnectionParameter(idx, None)
  1655                     connection.setconnectionParameter(idx, None)
  1657                 idx += 1
  1656                 idx += 1
  1658     
  1657     
  1659     def AddEditedElementPouVar(self, tagname, type, name):
  1658     def AddEditedElementPouVar(self, tagname, type, name):
  1660         words = tagname.split("::")
  1659         words = tagname.split("::")
  1661         if words[0] in ['P', 'T', 'A']:
  1660         if words[0] in ['P', 'T', 'A']:
  1662             pou = self.Project.getPou(words[1])
  1661             pou = self.Project.getpou(words[1])
  1663             pou.addPouVar(type, name)
  1662             pou.addpouVar(type, name)
  1664             
  1663             
  1665     def ChangeEditedElementPouVar(self, tagname, old_type, old_name, new_type, new_name):
  1664     def ChangeEditedElementPouVar(self, tagname, old_type, old_name, new_type, new_name):
  1666         words = tagname.split("::")
  1665         words = tagname.split("::")
  1667         if words[0] in ['P', 'T', 'A']:
  1666         if words[0] in ['P', 'T', 'A']:
  1668             pou = self.Project.getPou(words[1])
  1667             pou = self.Project.getpou(words[1])
  1669             pou.changePouVar(old_type, old_name, new_type, new_name)
  1668             pou.changepouVar(old_type, old_name, new_type, new_name)
  1670     
  1669     
  1671     def AddEditedElementBlock(self, tagname, id, blocktype, blockname = None):
  1670     def AddEditedElementBlock(self, tagname, id, blocktype, blockname = None):
  1672         element = self.GetEditedElement(tagname)
  1671         element = self.GetEditedElement(tagname)
  1673         if element is not None:
  1672         if element is not None:
  1674             block = plcopen.block()
  1673             block = plcopen.fbdObjects_block()
  1675             block.setLocalId(id)
  1674             block.setlocalId(id)
  1676             block.setTypeName(blocktype)
  1675             block.settypeName(blocktype)
  1677             blocktype_infos = GetBlockType(blocktype)
  1676             blocktype_infos = GetBlockType(blocktype)
  1678             if blocktype_infos["type"] != "function" and blockname is not None:
  1677             if blocktype_infos["type"] != "function" and blockname is not None:
  1679                 block.setInstanceName(blockname)
  1678                 block.setinstanceName(blockname)
  1680                 self.AddEditedElementPouVar(tagname, blocktype, blockname)
  1679                 self.AddEditedElementPouVar(tagname, blocktype, blockname)
  1681             element.addInstance("block", block)
  1680             element.addinstance("block", block)
  1682             self.RefreshPouUsingTree()
  1681             self.RefreshPouUsingTree()
  1683     
  1682     
  1684     def SetEditedElementBlockInfos(self, tagname, id, infos):
  1683     def SetEditedElementBlockInfos(self, tagname, id, infos):
  1685         element = self.GetEditedElement(tagname)
  1684         element = self.GetEditedElement(tagname)
  1686         if element is not None:
  1685         if element is not None:
  1687             block = element.getInstance(id)
  1686             block = element.getinstance(id)
  1688             blocktype = infos.get("type", block.getTypeName())
  1687             blocktype = infos.get("type", block.gettypeName())
  1689             blocktype_infos = GetBlockType(blocktype)
  1688             blocktype_infos = GetBlockType(blocktype)
  1690             if blocktype_infos["type"] != "function":
  1689             if blocktype_infos["type"] != "function":
  1691                 if "name" in infos or "type" in infos:
  1690                 if "name" in infos or "type" in infos:
  1692                     old_name = block.getInstanceName()
  1691                     old_name = block.getinstanceName()
  1693                     old_type = block.getTypeName()
  1692                     old_type = block.gettypeName()
  1694                     new_name = infos.get("name", old_name)
  1693                     new_name = infos.get("name", old_name)
  1695                     new_type = infos.get("type", old_type)
  1694                     new_type = infos.get("type", old_type)
  1696                     self.ChangeEditedElementPouVar(tagname, old_type, old_name, new_type, new_name)
  1695                     self.ChangeEditedElementPouVar(tagname, old_type, old_name, new_type, new_name)
  1697             for param, value in infos.items():
  1696             for param, value in infos.items():
  1698                 if param == "name":
  1697                 if param == "name":
  1699                     block.setInstanceName(value)
  1698                     block.setinstanceName(value)
  1700                 elif param == "type":
  1699                 elif param == "type":
  1701                     block.setTypeName(value)
  1700                     block.settypeName(value)
  1702                 elif param == "executionOrder" and block.getExecutionOrderId() != value:
  1701                 elif param == "executionOrder" and block.getexecutionOrderId() != value:
  1703                     self.GetEditedElement(tagname).setElementExecutionOrder(block, value)
  1702                     self.GetEditedElement(tagname).setelementExecutionOrder(block, value)
  1704                 elif param == "height":
  1703                 elif param == "height":
  1705                     block.setHeight(value)
  1704                     block.setheight(value)
  1706                 elif param == "width":
  1705                 elif param == "width":
  1707                     block.setWidth(value)
  1706                     block.setwidth(value)
  1708                 elif param == "x":
  1707                 elif param == "x":
  1709                     block.setX(value)
  1708                     block.setx(value)
  1710                 elif param == "y":
  1709                 elif param == "y":
  1711                     block.setY(value)
  1710                     block.sety(value)
  1712                 elif param == "connectors":
  1711                 elif param == "connectors":
  1713                     block.inputVariables.setVariable([])
  1712                     block.inputVariables.setvariable([])
  1714                     block.outputVariables.setVariable([])
  1713                     block.outputVariables.setvariable([])
  1715                     for connector in value["inputs"]:
  1714                     for connector in value["inputs"]:
  1716                         variable = plcopen.inputVariables_variable()
  1715                         variable = plcopen.inputVariables_variable()
  1717                         variable.setFormalParameter(connector.GetName())
  1716                         variable.setformalParameter(connector.GetName())
  1718                         if connector.IsNegated():
  1717                         if connector.IsNegated():
  1719                             variable.setNegated(True)
  1718                             variable.setnegated(True)
  1720                         if connector.GetEdge() != "none":
  1719                         if connector.GetEdge() != "none":
  1721                             variable.setConnectorEdge(connector.GetEdge())
  1720                             variable.setedge(connector.GetEdge())
  1722                         position = connector.GetRelPosition()
  1721                         position = connector.GetRelPosition()
  1723                         variable.connectionPointIn.setRelPosition(position.x, position.y)
  1722                         variable.connectionPointIn.setrelPositionXY(position.x, position.y)
  1724                         self.SetConnectionWires(variable.connectionPointIn, connector)
  1723                         self.SetConnectionWires(variable.connectionPointIn, connector)
  1725                         block.inputVariables.appendVariable(variable)
  1724                         block.inputVariables.appendvariable(variable)
  1726                     for connector in value["outputs"]:
  1725                     for connector in value["outputs"]:
  1727                         variable = plcopen.outputVariables_variable()
  1726                         variable = plcopen.outputVariables_variable()
  1728                         variable.setFormalParameter(connector.GetName())
  1727                         variable.setformalParameter(connector.GetName())
  1729                         if connector.IsNegated():
  1728                         if connector.IsNegated():
  1730                             variable.setNegated(True)
  1729                             variable.setnegated(True)
  1731                         if connector.GetEdge() != "none":
  1730                         if connector.GetEdge() != "none":
  1732                             variable.setConnectorEdge(connector.GetEdge())
  1731                             variable.setedge(connector.GetEdge())
  1733                         position = connector.GetRelPosition()
  1732                         position = connector.GetRelPosition()
  1734                         variable.addConnectionPointOut()
  1733                         variable.addconnectionPointOut()
  1735                         variable.connectionPointOut.setRelPosition(position.x, position.y)
  1734                         variable.connectionPointOut.setrelPositionXY(position.x, position.y)
  1736                         block.outputVariables.appendVariable(variable)
  1735                         block.outputVariables.appendvariable(variable)
  1737             self.RefreshPouUsingTree()
  1736             self.RefreshPouUsingTree()
  1738         
  1737         
  1739     def AddEditedElementVariable(self, tagname, id, type):
  1738     def AddEditedElementVariable(self, tagname, id, type):
  1740         element = self.GetEditedElement(tagname)
  1739         element = self.GetEditedElement(tagname)
  1741         if element is not None:            
  1740         if element is not None:            
  1742             if type == INPUT:
  1741             if type == INPUT:
  1743                 name = "inVariable"
  1742                 name = "inVariable"
  1744                 variable = plcopen.inVariable()
  1743                 variable = plcopen.fbdObjects_inVariable()
  1745             elif type == OUTPUT:
  1744             elif type == OUTPUT:
  1746                 name = "outVariable"
  1745                 name = "outVariable"
  1747                 variable = plcopen.outVariable()
  1746                 variable = plcopen.fbdObjects_outVariable()
  1748             elif type == INOUT:
  1747             elif type == INOUT:
  1749                 name = "inOutVariable"
  1748                 name = "inOutVariable"
  1750                 variable = plcopen.inOutVariable()
  1749                 variable = plcopen.fbdObjects_inOutVariable()
  1751             variable.setLocalId(id)
  1750             variable.setlocalId(id)
  1752             element.addInstance(name, variable)
  1751             element.addinstance(name, variable)
  1753         
  1752         
  1754     def SetEditedElementVariableInfos(self, tagname, id, infos):
  1753     def SetEditedElementVariableInfos(self, tagname, id, infos):
  1755         element = self.GetEditedElement(tagname)
  1754         element = self.GetEditedElement(tagname)
  1756         if element is not None:
  1755         if element is not None:
  1757             variable = element.getInstance(id)
  1756             variable = element.getinstance(id)
  1758             for param, value in infos.items():
  1757             for param, value in infos.items():
  1759                 if param == "name":
  1758                 if param == "name":
  1760                     variable.setExpression(value)    
  1759                     variable.setexpression(value)    
  1761                 elif param == "executionOrder" and variable.getExecutionOrderId() != value:
  1760                 elif param == "executionOrder" and variable.getexecutionOrderId() != value:
  1762                     self.GetEditedElement(tagname).setElementExecutionOrder(variable, value)
  1761                     self.GetEditedElement(tagname).setelementExecutionOrder(variable, value)
  1763                 elif param == "height":
  1762                 elif param == "height":
  1764                     variable.setHeight(value)
  1763                     variable.setheight(value)
  1765                 elif param == "width":
  1764                 elif param == "width":
  1766                     variable.setWidth(value)
  1765                     variable.setwidth(value)
  1767                 elif param == "x":
  1766                 elif param == "x":
  1768                     variable.setX(value)
  1767                     variable.setx(value)
  1769                 elif param == "y":
  1768                 elif param == "y":
  1770                     variable.setY(value)
  1769                     variable.sety(value)
  1771                 elif param == "connectors":
  1770                 elif param == "connectors":
  1772                     if isinstance(variable, plcopen.inVariable):
  1771                     if isinstance(variable, plcopen.fbdObjects_inVariable):
  1773                         if value["output"].IsNegated():
  1772                         if value["output"].IsNegated():
  1774                             variable.setNegated(True)
  1773                             variable.setnegated(True)
  1775                         if value["output"].GetEdge() != "none":
  1774                         if value["output"].GetEdge() != "none":
  1776                             variable.setConnectorEdge(value["output"].GetEdge())
  1775                             variable.setedge(value["output"].GetEdge())
  1777                         position = value["output"].GetRelPosition()
  1776                         position = value["output"].GetRelPosition()
  1778                         variable.addConnectionPointOut()
  1777                         variable.addconnectionPointOut()
  1779                         variable.connectionPointOut.setRelPosition(position.x, position.y)
  1778                         variable.connectionPointOut.setrelPositionXY(position.x, position.y)
  1780                     elif isinstance(variable, plcopen.outVariable):
  1779                     elif isinstance(variable, plcopen.fbdObjects_outVariable):
  1781                         if value["input"].IsNegated():
  1780                         if value["input"].IsNegated():
  1782                             variable.setNegated(True)
  1781                             variable.setnegated(True)
  1783                         if value["input"].GetEdge() != "none":
  1782                         if value["input"].GetEdge() != "none":
  1784                             variable.setConnectorEdge(value["input"].GetEdge())
  1783                             variable.setedge(value["input"].GetEdge())
  1785                         position = value["input"].GetRelPosition()
  1784                         position = value["input"].GetRelPosition()
  1786                         variable.addConnectionPointIn()
  1785                         variable.addconnectionPointIn()
  1787                         variable.connectionPointIn.setRelPosition(position.x, position.y)
  1786                         variable.connectionPointIn.setrelPositionXY(position.x, position.y)
  1788                         self.SetConnectionWires(variable.connectionPointIn, value["input"])
  1787                         self.SetConnectionWires(variable.connectionPointIn, value["input"])
  1789                     elif isinstance(variable, plcopen.inOutVariable):
  1788                     elif isinstance(variable, plcopen.fbdObjects_inOutVariable):
  1790                         if value["input"].IsNegated():
  1789                         if value["input"].IsNegated():
  1791                             variable.setNegatedIn(True)
  1790                             variable.setnegatedIn(True)
  1792                         if value["input"].GetEdge() != "none":
  1791                         if value["input"].GetEdge() != "none":
  1793                             variable.setInputEdge(value["input"].GetEdge())
  1792                             variable.setedgeIn(value["input"].GetEdge())
  1794                         if value["output"].IsNegated():
  1793                         if value["output"].IsNegated():
  1795                             variable.setNegatedOut(True)
  1794                             variable.setnegatedOut(True)
  1796                         if value["output"].GetEdge() != "none":
  1795                         if value["output"].GetEdge() != "none":
  1797                             variable.setOutputEdge(value["output"].GetEdge())
  1796                             variable.setedgeOut(value["output"].GetEdge())
  1798                         position = value["output"].GetRelPosition()
  1797                         position = value["output"].GetRelPosition()
  1799                         variable.addConnectionPointOut()
  1798                         variable.addconnectionPointOut()
  1800                         variable.connectionPointOut.setRelPosition(position.x, position.y)
  1799                         variable.connectionPointOut.setrelPositionXY(position.x, position.y)
  1801                         position = value["input"].GetRelPosition()
  1800                         position = value["input"].GetRelPosition()
  1802                         variable.addConnectionPointIn()
  1801                         variable.addconnectionPointIn()
  1803                         variable.connectionPointIn.setRelPosition(position.x, position.y)
  1802                         variable.connectionPointIn.setrelPositionXY(position.x, position.y)
  1804                         self.SetConnectionWires(variable.connectionPointIn, value["input"])
  1803                         self.SetConnectionWires(variable.connectionPointIn, value["input"])
  1805 
  1804 
  1806     def AddEditedElementConnection(self, tagname, id, type):
  1805     def AddEditedElementConnection(self, tagname, id, type):
  1807         element = self.GetEditedElement(tagname)
  1806         element = self.GetEditedElement(tagname)
  1808         if element is not None:
  1807         if element is not None:
  1809             if type == CONNECTOR:
  1808             if type == CONNECTOR:
  1810                 name = "connector"
  1809                 name = "connector"
  1811                 connection = plcopen.connector()
  1810                 connection = plcopen.commonObjects_connector()
  1812             elif type == CONTINUATION:
  1811             elif type == CONTINUATION:
  1813                 name = "continuation"
  1812                 name = "continuation"
  1814                 connection = plcopen.continuation()
  1813                 connection = plcopen.commonObjects_continuation()
  1815             connection.setLocalId(id)
  1814             connection.setlocalId(id)
  1816             element.addInstance(name, connection)
  1815             element.addinstance(name, connection)
  1817         
  1816         
  1818     def SetEditedElementConnectionInfos(self, tagname, id, infos):
  1817     def SetEditedElementConnectionInfos(self, tagname, id, infos):
  1819         element = self.GetEditedElement(tagname)
  1818         element = self.GetEditedElement(tagname)
  1820         if element is not None:
  1819         if element is not None:
  1821             connection = element.getInstance(id)
  1820             connection = element.getinstance(id)
  1822             for param, value in infos.items():
  1821             for param, value in infos.items():
  1823                 if param == "name":
  1822                 if param == "name":
  1824                     connection.setName(value)    
  1823                     connection.setname(value)    
  1825                 elif param == "height":
  1824                 elif param == "height":
  1826                     connection.setHeight(value)
  1825                     connection.setheight(value)
  1827                 elif param == "width":
  1826                 elif param == "width":
  1828                     connection.setWidth(value)
  1827                     connection.setwidth(value)
  1829                 elif param == "x":
  1828                 elif param == "x":
  1830                     connection.setX(value)
  1829                     connection.setx(value)
  1831                 elif param == "y":
  1830                 elif param == "y":
  1832                     connection.setY(value)
  1831                     connection.sety(value)
  1833                 elif param == "connector":
  1832                 elif param == "connector":
  1834                     position = value.GetRelPosition()
  1833                     position = value.GetRelPosition()
  1835                     if isinstance(connection, plcopen.continuation):
  1834                     if isinstance(connection, plcopen.commonObjects_continuation):
  1836                         connection.addConnectionPointOut()
  1835                         connection.addconnectionPointOut()
  1837                         connection.connectionPointOut.setRelPosition(position.x, position.y)
  1836                         connection.connectionPointOut.setrelPositionXY(position.x, position.y)
  1838                     elif isinstance(connection, plcopen.connector):
  1837                     elif isinstance(connection, plcopen.commonObjects_connector):
  1839                         connection.addConnectionPointIn()
  1838                         connection.addconnectionPointIn()
  1840                         connection.connectionPointIn.setRelPosition(position.x, position.y)
  1839                         connection.connectionPointIn.setrelPositionXY(position.x, position.y)
  1841                         self.SetConnectionWires(connection.connectionPointIn, value)
  1840                         self.SetConnectionWires(connection.connectionPointIn, value)
  1842 
  1841 
  1843     def AddEditedElementComment(self, tagname, id):
  1842     def AddEditedElementComment(self, tagname, id):
  1844         element = self.GetEditedElement(tagname)
  1843         element = self.GetEditedElement(tagname)
  1845         if element is not None:
  1844         if element is not None:
  1846             comment = plcopen.comment()
  1845             comment = plcopen.commonObjects_comment()
  1847             comment.setLocalId(id)
  1846             comment.setlocalId(id)
  1848             element.addInstance("comment", comment)
  1847             element.addinstance("comment", comment)
  1849     
  1848     
  1850     def SetEditedElementCommentInfos(self, tagname, id, infos):
  1849     def SetEditedElementCommentInfos(self, tagname, id, infos):
  1851         element = self.GetEditedElement(tagname)
  1850         element = self.GetEditedElement(tagname)
  1852         if element is not None:
  1851         if element is not None:
  1853             comment = element.getInstance(id)
  1852             comment = element.getinstance(id)
  1854             for param, value in infos.items():
  1853             for param, value in infos.items():
  1855                 if param == "content":
  1854                 if param == "content":
  1856                     comment.setContentText(value)
  1855                     comment.setcontentText(value)
  1857                 elif param == "height":
  1856                 elif param == "height":
  1858                     comment.setHeight(value)
  1857                     comment.setheight(value)
  1859                 elif param == "width":
  1858                 elif param == "width":
  1860                     comment.setWidth(value)
  1859                     comment.setwidth(value)
  1861                 elif param == "x":
  1860                 elif param == "x":
  1862                     comment.setX(value)
  1861                     comment.setx(value)
  1863                 elif param == "y":
  1862                 elif param == "y":
  1864                     comment.setY(value)
  1863                     comment.sety(value)
  1865 
  1864 
  1866     def AddEditedElementPowerRail(self, tagname, id, type):
  1865     def AddEditedElementPowerRail(self, tagname, id, type):
  1867         element = self.GetEditedElement(tagname)
  1866         element = self.GetEditedElement(tagname)
  1868         if element is not None:
  1867         if element is not None:
  1869             if type == LEFTRAIL:
  1868             if type == LEFTRAIL:
  1870                 name = "leftPowerRail"
  1869                 name = "leftPowerRail"
  1871                 powerrail = plcopen.leftPowerRail()
  1870                 powerrail = plcopen.ldObjects_leftPowerRail()
  1872             elif type == RIGHTRAIL:
  1871             elif type == RIGHTRAIL:
  1873                 name = "rightPowerRail"
  1872                 name = "rightPowerRail"
  1874                 powerrail = plcopen.rightPowerRail()
  1873                 powerrail = plcopen.ldObjects_rightPowerRail()
  1875             powerrail.setLocalId(id)
  1874             powerrail.setlocalId(id)
  1876             element.addInstance(name, powerrail)
  1875             element.addinstance(name, powerrail)
  1877     
  1876     
  1878     def SetEditedElementPowerRailInfos(self, tagname, id, infos):
  1877     def SetEditedElementPowerRailInfos(self, tagname, id, infos):
  1879         element = self.GetEditedElement(tagname)
  1878         element = self.GetEditedElement(tagname)
  1880         if element is not None:
  1879         if element is not None:
  1881             powerrail = element.getInstance(id)
  1880             powerrail = element.getinstance(id)
  1882             for param, value in infos.items():
  1881             for param, value in infos.items():
  1883                 if param == "height":
  1882                 if param == "height":
  1884                     powerrail.setHeight(value)
  1883                     powerrail.setheight(value)
  1885                 elif param == "width":
  1884                 elif param == "width":
  1886                     powerrail.setWidth(value)
  1885                     powerrail.setwidth(value)
  1887                 elif param == "x":
  1886                 elif param == "x":
  1888                     powerrail.setX(value)
  1887                     powerrail.setx(value)
  1889                 elif param == "y":
  1888                 elif param == "y":
  1890                     powerrail.setY(value)
  1889                     powerrail.sety(value)
  1891                 elif param == "connectors":
  1890                 elif param == "connectors":
  1892                     if isinstance(powerrail, plcopen.leftPowerRail):
  1891                     if isinstance(powerrail, plcopen.ldObjects_leftPowerRail):
  1893                         powerrail.setConnectionPointOut([])
  1892                         powerrail.setconnectionPointOut([])
  1894                         for connector in value:
  1893                         for connector in value:
  1895                             position = connector.GetRelPosition()
  1894                             position = connector.GetRelPosition()
  1896                             connection = plcopen.leftPowerRail_connectionPointOut()
  1895                             connection = plcopen.leftPowerRail_connectionPointOut()
  1897                             connection.setRelPosition(position.x, position.y)
  1896                             connection.setrelPositionXY(position.x, position.y)
  1898                             powerrail.connectionPointOut.append(connection)
  1897                             powerrail.connectionPointOut.append(connection)
  1899                     elif isinstance(powerrail, plcopen.rightPowerRail):
  1898                     elif isinstance(powerrail, plcopen.ldObjects_rightPowerRail):
  1900                         powerrail.setConnectionPointIn([])
  1899                         powerrail.setconnectionPointIn([])
  1901                         for connector in value:
  1900                         for connector in value:
  1902                             position = connector.GetRelPosition()
  1901                             position = connector.GetRelPosition()
  1903                             connection = plcopen.connectionPointIn()
  1902                             connection = plcopen.connectionPointIn()
  1904                             connection.setRelPosition(position.x, position.y)
  1903                             connection.setrelPositionXY(position.x, position.y)
  1905                             self.SetConnectionWires(connection, connector)
  1904                             self.SetConnectionWires(connection, connector)
  1906                             powerrail.connectionPointIn.append(connection)
  1905                             powerrail.connectionPointIn.append(connection)
  1907 
  1906 
  1908     def AddEditedElementContact(self, tagname, id):
  1907     def AddEditedElementContact(self, tagname, id):
  1909         element = self.GetEditedElement(tagname)
  1908         element = self.GetEditedElement(tagname)
  1910         if element is not None:
  1909         if element is not None:
  1911             contact = plcopen.contact()
  1910             contact = plcopen.ldObjects_contact()
  1912             contact.setLocalId(id)
  1911             contact.setlocalId(id)
  1913             element.addInstance("contact", contact)
  1912             element.addinstance("contact", contact)
  1914 
  1913 
  1915     def SetEditedElementContactInfos(self, tagname, id, infos):
  1914     def SetEditedElementContactInfos(self, tagname, id, infos):
  1916         element = self.GetEditedElement(tagname)
  1915         element = self.GetEditedElement(tagname)
  1917         if element is not None:
  1916         if element is not None:
  1918             contact = element.getInstance(id)
  1917             contact = element.getinstance(id)
  1919             for param, value in infos.items():
  1918             for param, value in infos.items():
  1920                 if param == "name":
  1919                 if param == "name":
  1921                     contact.setVariable(value)
  1920                     contact.setvariable(value)
  1922                 elif param == "type":
  1921                 elif param == "type":
  1923                     if value == CONTACT_NORMAL:
  1922                     if value == CONTACT_NORMAL:
  1924                         contact.setNegated(False)
  1923                         contact.setnegated(False)
  1925                         contact.setContactEdge("none")
  1924                         contact.setedge("none")
  1926                     elif value == CONTACT_REVERSE:
  1925                     elif value == CONTACT_REVERSE:
  1927                         contact.setNegated(True)
  1926                         contact.setnegated(True)
  1928                         contact.setContactEdge("none")
  1927                         contact.setedge("none")
  1929                     elif value == CONTACT_RISING:
  1928                     elif value == CONTACT_RISING:
  1930                         contact.setNegated(False)
  1929                         contact.setnegated(False)
  1931                         contact.setContactEdge("rising")
  1930                         contact.setedge("rising")
  1932                     elif value == CONTACT_FALLING:
  1931                     elif value == CONTACT_FALLING:
  1933                         contact.setNegated(False)
  1932                         contact.setnegated(False)
  1934                         contact.setContactEdge("falling")
  1933                         contact.setedge("falling")
  1935                 elif param == "height":
  1934                 elif param == "height":
  1936                     contact.setHeight(value)
  1935                     contact.setheight(value)
  1937                 elif param == "width":
  1936                 elif param == "width":
  1938                     contact.setWidth(value)
  1937                     contact.setwidth(value)
  1939                 elif param == "x":
  1938                 elif param == "x":
  1940                     contact.setX(value)
  1939                     contact.setx(value)
  1941                 elif param == "y":
  1940                 elif param == "y":
  1942                     contact.setY(value)
  1941                     contact.sety(value)
  1943                 elif param == "connectors":
  1942                 elif param == "connectors":
  1944                     input_connector = value["input"]
  1943                     input_connector = value["input"]
  1945                     position = input_connector.GetRelPosition()
  1944                     position = input_connector.GetRelPosition()
  1946                     contact.addConnectionPointIn()
  1945                     contact.addconnectionPointIn()
  1947                     contact.connectionPointIn.setRelPosition(position.x, position.y)
  1946                     contact.connectionPointIn.setrelPositionXY(position.x, position.y)
  1948                     self.SetConnectionWires(contact.connectionPointIn, input_connector)
  1947                     self.SetConnectionWires(contact.connectionPointIn, input_connector)
  1949                     output_connector = value["output"]
  1948                     output_connector = value["output"]
  1950                     position = output_connector.GetRelPosition()
  1949                     position = output_connector.GetRelPosition()
  1951                     contact.addConnectionPointOut()
  1950                     contact.addconnectionPointOut()
  1952                     contact.connectionPointOut.setRelPosition(position.x, position.y)
  1951                     contact.connectionPointOut.setrelPositionXY(position.x, position.y)
  1953 
  1952 
  1954     def AddEditedElementCoil(self, tagname, id):
  1953     def AddEditedElementCoil(self, tagname, id):
  1955         element = self.GetEditedElement(tagname)
  1954         element = self.GetEditedElement(tagname)
  1956         if element is not None:
  1955         if element is not None:
  1957             coil = plcopen.coil()
  1956             coil = plcopen.ldObjects_coil()
  1958             coil.setLocalId(id)
  1957             coil.setlocalId(id)
  1959             element.addInstance("coil", coil)
  1958             element.addinstance("coil", coil)
  1960 
  1959 
  1961     def SetEditedElementCoilInfos(self, tagname, id, infos):
  1960     def SetEditedElementCoilInfos(self, tagname, id, infos):
  1962         element = self.GetEditedElement(tagname)
  1961         element = self.GetEditedElement(tagname)
  1963         if element is not None:
  1962         if element is not None:
  1964             coil = element.getInstance(id)
  1963             coil = element.getinstance(id)
  1965             for param, value in infos.items():
  1964             for param, value in infos.items():
  1966                 if param == "name":
  1965                 if param == "name":
  1967                     coil.setVariable(value)
  1966                     coil.setvariable(value)
  1968                 elif param == "type":
  1967                 elif param == "type":
  1969                     if value == COIL_NORMAL:
  1968                     if value == COIL_NORMAL:
  1970                         coil.setNegated(False)
  1969                         coil.setnegated(False)
  1971                         coil.setCoilStorage("none")
  1970                         coil.setstorage("none")
  1972                     elif value == COIL_REVERSE:
  1971                     elif value == COIL_REVERSE:
  1973                         coil.setNegated(True)
  1972                         coil.setnegated(True)
  1974                         coil.setCoilStorage("none")
  1973                         coil.setstorage("none")
  1975                     elif value == COIL_SET:
  1974                     elif value == COIL_SET:
  1976                         coil.setNegated(False)
  1975                         coil.setnegated(False)
  1977                         coil.setCoilStorage("set")
  1976                         coil.setstorage("set")
  1978                     elif value == COIL_RESET:
  1977                     elif value == COIL_RESET:
  1979                         coil.setNegated(False)
  1978                         coil.setnegated(False)
  1980                         coil.setCoilStorage("reset")
  1979                         coil.setstorage("reset")
  1981                 elif param == "height":
  1980                 elif param == "height":
  1982                     coil.setHeight(value)
  1981                     coil.setheight(value)
  1983                 elif param == "width":
  1982                 elif param == "width":
  1984                     coil.setWidth(value)
  1983                     coil.setwidth(value)
  1985                 elif param == "x":
  1984                 elif param == "x":
  1986                     coil.setX(value)
  1985                     coil.setx(value)
  1987                 elif param == "y":
  1986                 elif param == "y":
  1988                     coil.setY(value)
  1987                     coil.sety(value)
  1989                 elif param == "connectors":
  1988                 elif param == "connectors":
  1990                     input_connector = value["input"]
  1989                     input_connector = value["input"]
  1991                     position = input_connector.GetRelPosition()
  1990                     position = input_connector.GetRelPosition()
  1992                     coil.addConnectionPointIn()
  1991                     coil.addconnectionPointIn()
  1993                     coil.connectionPointIn.setRelPosition(position.x, position.y)
  1992                     coil.connectionPointIn.setrelPositionXY(position.x, position.y)
  1994                     self.SetConnectionWires(coil.connectionPointIn, input_connector)
  1993                     self.SetConnectionWires(coil.connectionPointIn, input_connector)
  1995                     output_connector = value["output"]
  1994                     output_connector = value["output"]
  1996                     position = output_connector.GetRelPosition()
  1995                     position = output_connector.GetRelPosition()
  1997                     coil.addConnectionPointOut()
  1996                     coil.addconnectionPointOut()
  1998                     coil.connectionPointOut.setRelPosition(position.x, position.y)
  1997                     coil.connectionPointOut.setrelPositionXY(position.x, position.y)
  1999 
  1998 
  2000     def AddEditedElementStep(self, tagname, id):
  1999     def AddEditedElementStep(self, tagname, id):
  2001         element = self.GetEditedElement(tagname)
  2000         element = self.GetEditedElement(tagname)
  2002         if element is not None:
  2001         if element is not None:
  2003             step = plcopen.step()
  2002             step = plcopen.sfcObjects_step()
  2004             step.setLocalId(id)
  2003             step.setlocalId(id)
  2005             element.addInstance("step", step)
  2004             element.addinstance("step", step)
  2006     
  2005     
  2007     def SetEditedElementStepInfos(self, tagname, id, infos):
  2006     def SetEditedElementStepInfos(self, tagname, id, infos):
  2008         element = self.GetEditedElement(tagname)
  2007         element = self.GetEditedElement(tagname)
  2009         if element is not None:
  2008         if element is not None:
  2010             step = element.getInstance(id)
  2009             step = element.getinstance(id)
  2011             for param, value in infos.items():
  2010             for param, value in infos.items():
  2012                 if param == "name":
  2011                 if param == "name":
  2013                     step.setName(value)
  2012                     step.setname(value)
  2014                 elif param == "initial":
  2013                 elif param == "initial":
  2015                     step.setInitialStep(value)
  2014                     step.setinitialStep(value)
  2016                 elif param == "height":
  2015                 elif param == "height":
  2017                     step.setHeight(value)
  2016                     step.setheight(value)
  2018                 elif param == "width":
  2017                 elif param == "width":
  2019                     step.setWidth(value)
  2018                     step.setwidth(value)
  2020                 elif param == "x":
  2019                 elif param == "x":
  2021                     step.setX(value)
  2020                     step.setx(value)
  2022                 elif param == "y":
  2021                 elif param == "y":
  2023                     step.setY(value)
  2022                     step.sety(value)
  2024                 elif param == "connectors":
  2023                 elif param == "connectors":
  2025                     input_connector = value["input"]
  2024                     input_connector = value["input"]
  2026                     if input_connector:
  2025                     if input_connector:
  2027                         position = input_connector.GetRelPosition()
  2026                         position = input_connector.GetRelPosition()
  2028                         step.addConnectionPointIn()
  2027                         step.addconnectionPointIn()
  2029                         step.connectionPointIn.setRelPosition(position.x, position.y)
  2028                         step.connectionPointIn.setrelPositionXY(position.x, position.y)
  2030                         self.SetConnectionWires(step.connectionPointIn, input_connector)
  2029                         self.SetConnectionWires(step.connectionPointIn, input_connector)
  2031                     else:
  2030                     else:
  2032                         step.deleteConnectionPointIn()
  2031                         step.deleteconnectionPointIn()
  2033                     output_connector = value["output"]
  2032                     output_connector = value["output"]
  2034                     if output_connector:
  2033                     if output_connector:
  2035                         position = output_connector.GetRelPosition()
  2034                         position = output_connector.GetRelPosition()
  2036                         step.addConnectionPointOut()
  2035                         step.addconnectionPointOut()
  2037                         step.connectionPointOut.setRelPosition(position.x, position.y)
  2036                         step.connectionPointOut.setrelPositionXY(position.x, position.y)
  2038                     else:
  2037                     else:
  2039                         step.deleteConnectionPointOut()
  2038                         step.deleteconnectionPointOut()
  2040                     action_connector = value["action"]
  2039                     action_connector = value["action"]
  2041                     if action_connector:
  2040                     if action_connector:
  2042                         position = action_connector.GetRelPosition()
  2041                         position = action_connector.GetRelPosition()
  2043                         step.addConnectionPointOutAction()
  2042                         step.addconnectionPointOutAction()
  2044                         step.connectionPointOutAction.setRelPosition(position.x, position.y)
  2043                         step.connectionPointOutAction.setrelPositionXY(position.x, position.y)
  2045                     else:
  2044                     else:
  2046                         step.deleteConnectionPointOutAction()
  2045                         step.deleteconnectionPointOutAction()
  2047     
  2046     
  2048     def AddEditedElementTransition(self, tagname, id):
  2047     def AddEditedElementTransition(self, tagname, id):
  2049         element = self.GetEditedElement(tagname)
  2048         element = self.GetEditedElement(tagname)
  2050         if element is not None:
  2049         if element is not None:
  2051             transition = plcopen.transition()
  2050             transition = plcopen.sfcObjects_transition()
  2052             transition.setLocalId(id)
  2051             transition.setlocalId(id)
  2053             element.addInstance("transition", transition)
  2052             element.addinstance("transition", transition)
  2054     
  2053     
  2055     def SetEditedElementTransitionInfos(self, tagname, id, infos):
  2054     def SetEditedElementTransitionInfos(self, tagname, id, infos):
  2056         element = self.GetEditedElement(tagname)
  2055         element = self.GetEditedElement(tagname)
  2057         if element is not None:
  2056         if element is not None:
  2058             transition = element.getInstance(id)
  2057             transition = element.getinstance(id)
  2059             for param, value in infos.items():
  2058             for param, value in infos.items():
  2060                 if param == "type" and value != "connection":
  2059                 if param == "type" and value != "connection":
  2061                     transition.setConditionContent(value, infos["condition"])
  2060                     transition.setconditionContent(value, infos["condition"])
  2062                 elif param == "height":
  2061                 elif param == "height":
  2063                     transition.setHeight(value)
  2062                     transition.setheight(value)
  2064                 elif param == "width":
  2063                 elif param == "width":
  2065                     transition.setWidth(value)
  2064                     transition.setwidth(value)
  2066                 elif param == "x":
  2065                 elif param == "x":
  2067                     transition.setX(value)
  2066                     transition.setx(value)
  2068                 elif param == "y":
  2067                 elif param == "y":
  2069                     transition.setY(value)
  2068                     transition.sety(value)
  2070                 elif param == "priority":
  2069                 elif param == "priority":
  2071                     if value != 0:
  2070                     if value != 0:
  2072                         transition.setPriority(value)
  2071                         transition.setpriority(value)
  2073                     else:
  2072                     else:
  2074                         transition.setPriority(None)
  2073                         transition.setpriority(None)
  2075                 elif param == "connectors":
  2074                 elif param == "connectors":
  2076                     input_connector = value["input"]
  2075                     input_connector = value["input"]
  2077                     position = input_connector.GetRelPosition()
  2076                     position = input_connector.GetRelPosition()
  2078                     transition.addConnectionPointIn()
  2077                     transition.addconnectionPointIn()
  2079                     transition.connectionPointIn.setRelPosition(position.x, position.y)
  2078                     transition.connectionPointIn.setrelPositionXY(position.x, position.y)
  2080                     self.SetConnectionWires(transition.connectionPointIn, input_connector)
  2079                     self.SetConnectionWires(transition.connectionPointIn, input_connector)
  2081                     output_connector = value["output"]
  2080                     output_connector = value["output"]
  2082                     position = output_connector.GetRelPosition()
  2081                     position = output_connector.GetRelPosition()
  2083                     transition.addConnectionPointOut()
  2082                     transition.addconnectionPointOut()
  2084                     transition.connectionPointOut.setRelPosition(position.x, position.y)
  2083                     transition.connectionPointOut.setrelPositionXY(position.x, position.y)
  2085                     if infos.get("type", None) == "connection":
  2084                     if infos.get("type", None) == "connection":
  2086                         transition.setConditionContent("connection", None)
  2085                         transition.setconditionContent("connection", None)
  2087                         connection_connector = value["connection"]
  2086                         connection_connector = value["connection"]
  2088                         self.SetConnectionWires(transition, connection_connector)
  2087                         self.SetConnectionWires(transition, connection_connector)
  2089     
  2088     
  2090     def AddEditedElementDivergence(self, tagname, id, type):
  2089     def AddEditedElementDivergence(self, tagname, id, type):
  2091         element = self.GetEditedElement(tagname)
  2090         element = self.GetEditedElement(tagname)
  2092         if element is not None:
  2091         if element is not None:
  2093             if type == SELECTION_DIVERGENCE:
  2092             if type == SELECTION_DIVERGENCE:
  2094                 name = "selectionDivergence"
  2093                 name = "selectionDivergence"
  2095                 divergence = plcopen.selectionDivergence()
  2094                 divergence = plcopen.sfcObjects_selectionDivergence()
  2096             elif type == SELECTION_CONVERGENCE:
  2095             elif type == SELECTION_CONVERGENCE:
  2097                 name = "selectionConvergence"
  2096                 name = "selectionConvergence"
  2098                 divergence = plcopen.selectionConvergence()
  2097                 divergence = plcopen.sfcObjects_selectionConvergence()
  2099             elif type == SIMULTANEOUS_DIVERGENCE:
  2098             elif type == SIMULTANEOUS_DIVERGENCE:
  2100                 name = "simultaneousDivergence"
  2099                 name = "simultaneousDivergence"
  2101                 divergence = plcopen.simultaneousDivergence()
  2100                 divergence = plcopen.sfcObjects_simultaneousDivergence()
  2102             elif type == SIMULTANEOUS_CONVERGENCE:
  2101             elif type == SIMULTANEOUS_CONVERGENCE:
  2103                 name = "simultaneousConvergence"
  2102                 name = "simultaneousConvergence"
  2104                 divergence = plcopen.simultaneousConvergence()
  2103                 divergence = plcopen.sfcObjects_simultaneousConvergence()
  2105             divergence.setLocalId(id)
  2104             divergence.setlocalId(id)
  2106             element.addInstance(name, divergence)
  2105             element.addinstance(name, divergence)
  2107     
  2106     
  2108     def SetEditedElementDivergenceInfos(self, tagname, id, infos):
  2107     def SetEditedElementDivergenceInfos(self, tagname, id, infos):
  2109         element = self.GetEditedElement(tagname)
  2108         element = self.GetEditedElement(tagname)
  2110         if element is not None:
  2109         if element is not None:
  2111             divergence = element.getInstance(id)
  2110             divergence = element.getinstance(id)
  2112             for param, value in infos.items():
  2111             for param, value in infos.items():
  2113                 if param == "height":
  2112                 if param == "height":
  2114                     divergence.setHeight(value)
  2113                     divergence.setheight(value)
  2115                 elif param == "width":
  2114                 elif param == "width":
  2116                     divergence.setWidth(value)
  2115                     divergence.setwidth(value)
  2117                 elif param == "x":
  2116                 elif param == "x":
  2118                     divergence.setX(value)
  2117                     divergence.setx(value)
  2119                 elif param == "y":
  2118                 elif param == "y":
  2120                     divergence.setY(value)
  2119                     divergence.sety(value)
  2121                 elif param == "connectors":
  2120                 elif param == "connectors":
  2122                     input_connectors = value["inputs"]
  2121                     input_connectors = value["inputs"]
  2123                     if isinstance(divergence, (plcopen.selectionDivergence, plcopen.simultaneousDivergence)):
  2122                     if isinstance(divergence, (plcopen.sfcObjects_selectionDivergence, plcopen.sfcObjects_simultaneousDivergence)):
  2124                         position = input_connectors[0].GetRelPosition()
  2123                         position = input_connectors[0].GetRelPosition()
  2125                         divergence.addConnectionPointIn()
  2124                         divergence.addconnectionPointIn()
  2126                         divergence.connectionPointIn.setRelPosition(position.x, position.y)
  2125                         divergence.connectionPointIn.setrelPositionXY(position.x, position.y)
  2127                         self.SetConnectionWires(divergence.connectionPointIn, input_connectors[0])
  2126                         self.SetConnectionWires(divergence.connectionPointIn, input_connectors[0])
  2128                     else:
  2127                     else:
  2129                         divergence.setConnectionPointIn([])
  2128                         divergence.setconnectionPointIn([])
  2130                         for input_connector in input_connectors:
  2129                         for input_connector in input_connectors:
  2131                             position = input_connector.GetRelPosition()
  2130                             position = input_connector.GetRelPosition()
  2132                             if isinstance(divergence, plcopen.selectionConvergence):
  2131                             if isinstance(divergence, plcopen.sfcObjects_selectionConvergence):
  2133                                 connection = plcopen.selectionConvergence_connectionPointIn()
  2132                                 connection = plcopen.selectionConvergence_connectionPointIn()
  2134                             else:
  2133                             else:
  2135                                 connection = plcopen.connectionPointIn()
  2134                                 connection = plcopen.connectionPointIn()
  2136                             connection.setRelPosition(position.x, position.y)
  2135                             connection.setrelPositionXY(position.x, position.y)
  2137                             self.SetConnectionWires(connection, input_connector)
  2136                             self.SetConnectionWires(connection, input_connector)
  2138                             divergence.appendConnectionPointIn(connection)
  2137                             divergence.appendconnectionPointIn(connection)
  2139                     output_connectors = value["outputs"]
  2138                     output_connectors = value["outputs"]
  2140                     if isinstance(divergence, (plcopen.selectionConvergence, plcopen.simultaneousConvergence)):
  2139                     if isinstance(divergence, (plcopen.sfcObjects_selectionConvergence, plcopen.sfcObjects_simultaneousConvergence)):
  2141                         position = output_connectors[0].GetRelPosition()
  2140                         position = output_connectors[0].GetRelPosition()
  2142                         divergence.addConnectionPointOut()
  2141                         divergence.addconnectionPointOut()
  2143                         divergence.connectionPointOut.setRelPosition(position.x, position.y)
  2142                         divergence.connectionPointOut.setrelPositionXY(position.x, position.y)
  2144                     else:
  2143                     else:
  2145                         divergence.setConnectionPointOut([])
  2144                         divergence.setconnectionPointOut([])
  2146                         for output_connector in output_connectors:
  2145                         for output_connector in output_connectors:
  2147                             position = output_connector.GetRelPosition()
  2146                             position = output_connector.GetRelPosition()
  2148                             if isinstance(divergence, plcopen.selectionDivergence):
  2147                             if isinstance(divergence, plcopen.sfcObjects_selectionDivergence):
  2149                                 connection = plcopen.selectionDivergence_connectionPointOut()
  2148                                 connection = plcopen.selectionDivergence_connectionPointOut()
  2150                             else:
  2149                             else:
  2151                                 connection = plcopen.simultaneousDivergence_connectionPointOut()
  2150                                 connection = plcopen.simultaneousDivergence_connectionPointOut()
  2152                             connection.setRelPosition(position.x, position.y)
  2151                             connection.setrelPositionXY(position.x, position.y)
  2153                             divergence.appendConnectionPointOut(connection)
  2152                             divergence.appendconnectionPointOut(connection)
  2154     
  2153     
  2155     def AddEditedElementJump(self, tagname, id):
  2154     def AddEditedElementJump(self, tagname, id):
  2156         element = self.GetEditedElement(tagname)
  2155         element = self.GetEditedElement(tagname)
  2157         if element is not None:
  2156         if element is not None:
  2158             jump = plcopen.jumpStep()
  2157             jump = plcopen.sfcObjects_jumpStep()
  2159             jump.setLocalId(id)
  2158             jump.setlocalId(id)
  2160             element.addInstance("jumpStep", jump)
  2159             element.addinstance("jumpStep", jump)
  2161     
  2160     
  2162     def SetEditedElementJumpInfos(self, tagname, id, infos):
  2161     def SetEditedElementJumpInfos(self, tagname, id, infos):
  2163         element = self.GetEditedElement(tagname)
  2162         element = self.GetEditedElement(tagname)
  2164         if element is not None:
  2163         if element is not None:
  2165             jump = element.getInstance(id)
  2164             jump = element.getinstance(id)
  2166             for param, value in infos.items():
  2165             for param, value in infos.items():
  2167                 if param == "target":
  2166                 if param == "target":
  2168                     jump.setTargetName(value)
  2167                     jump.settargetName(value)
  2169                 elif param == "height":
  2168                 elif param == "height":
  2170                     jump.setHeight(value)
  2169                     jump.setheight(value)
  2171                 elif param == "width":
  2170                 elif param == "width":
  2172                     jump.setWidth(value)
  2171                     jump.setwidth(value)
  2173                 elif param == "x":
  2172                 elif param == "x":
  2174                     jump.setX(value)
  2173                     jump.setx(value)
  2175                 elif param == "y":
  2174                 elif param == "y":
  2176                     jump.setY(value)
  2175                     jump.sety(value)
  2177                 elif param == "connector":
  2176                 elif param == "connector":
  2178                     position = value.GetRelPosition()
  2177                     position = value.GetRelPosition()
  2179                     jump.addConnectionPointIn()
  2178                     jump.addconnectionPointIn()
  2180                     jump.connectionPointIn.setRelPosition(position.x, position.y)
  2179                     jump.connectionPointIn.setrelPositionXY(position.x, position.y)
  2181                     self.SetConnectionWires(jump.connectionPointIn, value)
  2180                     self.SetConnectionWires(jump.connectionPointIn, value)
  2182  
  2181  
  2183     def AddEditedElementActionBlock(self, tagname, id):
  2182     def AddEditedElementActionBlock(self, tagname, id):
  2184         element = self.GetEditedElement(tagname)
  2183         element = self.GetEditedElement(tagname)
  2185         if element is not None:
  2184         if element is not None:
  2186             actionBlock = plcopen.actionBlock()
  2185             actionBlock = plcopen.commonObjects_actionBlock()
  2187             actionBlock.setLocalId(id)
  2186             actionBlock.setlocalId(id)
  2188             element.addInstance("actionBlock", actionBlock)
  2187             element.addinstance("actionBlock", actionBlock)
  2189     
  2188     
  2190     def SetEditedElementActionBlockInfos(self, tagname, id, infos):
  2189     def SetEditedElementActionBlockInfos(self, tagname, id, infos):
  2191         element = self.GetEditedElement(tagname)
  2190         element = self.GetEditedElement(tagname)
  2192         if element is not None:
  2191         if element is not None:
  2193             actionBlock = element.getInstance(id)
  2192             actionBlock = element.getinstance(id)
  2194             for param, value in infos.items():
  2193             for param, value in infos.items():
  2195                 if param == "actions":
  2194                 if param == "actions":
  2196                     actionBlock.setActions(value)
  2195                     actionBlock.setactions(value)
  2197                 elif param == "height":
  2196                 elif param == "height":
  2198                     actionBlock.setHeight(value)
  2197                     actionBlock.setheight(value)
  2199                 elif param == "width":
  2198                 elif param == "width":
  2200                     actionBlock.setWidth(value)
  2199                     actionBlock.setwidth(value)
  2201                 elif param == "x":
  2200                 elif param == "x":
  2202                     actionBlock.setX(value)
  2201                     actionBlock.setx(value)
  2203                 elif param == "y":
  2202                 elif param == "y":
  2204                     actionBlock.setY(value)
  2203                     actionBlock.sety(value)
  2205                 elif param == "connector":
  2204                 elif param == "connector":
  2206                     position = value.GetRelPosition()
  2205                     position = value.GetRelPosition()
  2207                     actionBlock.addConnectionPointIn()
  2206                     actionBlock.addconnectionPointIn()
  2208                     actionBlock.connectionPointIn.setRelPosition(position.x, position.y)
  2207                     actionBlock.connectionPointIn.setrelPositionXY(position.x, position.y)
  2209                     self.SetConnectionWires(actionBlock.connectionPointIn, value)
  2208                     self.SetConnectionWires(actionBlock.connectionPointIn, value)
  2210     
  2209     
  2211     def RemoveEditedElementInstance(self, tagname, id):
  2210     def RemoveEditedElementInstance(self, tagname, id):
  2212         element = self.GetEditedElement(tagname)
  2211         element = self.GetEditedElement(tagname)
  2213         if element is not None:
  2212         if element is not None:
  2214             instance = element.getInstance(id)
  2213             instance = element.getinstance(id)
  2215             if isinstance(instance, plcopen.block):
  2214             if isinstance(instance, plcopen.fbdObjects_block):
  2216                 blocktype = instance.getTypeName()
  2215                 blocktype = instance.gettypeName()
  2217                 element.removePouVar(blocktype, instance.getInstanceName())    
  2216                 element.removepouVar(blocktype, instance.getinstanceName())    
  2218             element.removeInstance(id)
  2217             element.removeinstance(id)
  2219             self.RefreshPouUsingTree()
  2218             self.RefreshPouUsingTree()
  2220 
  2219 
  2221     def GetEditedResourceVariables(self, tagname):
  2220     def GetEditedResourceVariables(self, tagname):
  2222         varlist = []
  2221         varlist = []
  2223         words = tagname.split("::")
  2222         words = tagname.split("::")
  2230         return varlist
  2229         return varlist
  2231 
  2230 
  2232     def SetEditedResourceInfos(self, tagname, tasks, instances):
  2231     def SetEditedResourceInfos(self, tagname, tasks, instances):
  2233         resource = self.GetEditedElement(tagname)
  2232         resource = self.GetEditedElement(tagname)
  2234         if resource is not None:
  2233         if resource is not None:
  2235             resource.setTask([])
  2234             resource.settask([])
  2236             resource.setPouInstance([])
  2235             resource.setpouInstance([])
  2237             task_list = {}
  2236             task_list = {}
  2238             for task in tasks:
  2237             for task in tasks:
  2239                 new_task = plcopen.resource_task()
  2238                 new_task = plcopen.resource_task()
  2240                 new_task.setName(task["Name"])
  2239                 new_task.setname(task["Name"])
  2241                 if task["Single"] != "":
  2240                 if task["Single"] != "":
  2242                     new_task.setSingle(task["Single"])
  2241                     new_task.setsingle(task["Single"])
  2243                 result = duration_model.match(task["Interval"]).groups()
  2242                 result = duration_model.match(task["Interval"]).groups()
  2244                 if reduce(lambda x, y: x or y != None, result):
  2243                 if reduce(lambda x, y: x or y != None, result):
  2245                     values = []
  2244                     values = []
  2246                     for value in result[:-1]:
  2245                     for value in result[:-1]:
  2247                         if value != None:
  2246                         if value != None:
  2248                             values.append(int(value))
  2247                             values.append(int(value))
  2249                         else:
  2248                         else:
  2250                             values.append(0)
  2249                             values.append(0)
  2251                     values.append(int(float(result[-1]) * 1000))
  2250                     values.append(int(float(result[-1]) * 1000))
  2252                     new_task.setInterval(time(*values))
  2251                     new_task.setinterval(time(*values))
  2253                 new_task.priority.setValue(int(task["Priority"]))
  2252                 new_task.setpriority(int(task["Priority"]))
  2254                 if task["Name"] != "":
  2253                 if task["Name"] != "":
  2255                     task_list[task["Name"]] = new_task
  2254                     task_list[task["Name"]] = new_task
  2256                 resource.appendTask(new_task)
  2255                 resource.appendtask(new_task)
  2257             for instance in instances:
  2256             for instance in instances:
  2258                 new_instance = plcopen.pouInstance()
  2257                 new_instance = plcopen.pouInstance()
  2259                 new_instance.setName(instance["Name"])
  2258                 new_instance.setname(instance["Name"])
  2260                 new_instance.setType(instance["Type"])
  2259                 new_instance.settype(instance["Type"])
  2261                 if instance["Task"] != "":
  2260                 if instance["Task"] != "":
  2262                     task_list[instance["Task"]].appendPouInstance(new_instance)
  2261                     task_list[instance["Task"]].appendpouInstance(new_instance)
  2263                 else:
  2262                 else:
  2264                     resource.appendPouInstance(new_instance)
  2263                     resource.appendpouInstance(new_instance)
  2265 
  2264 
  2266     def GetEditedResourceInfos(self, tagname):
  2265     def GetEditedResourceInfos(self, tagname):
  2267         resource = self.GetEditedElement(tagname)
  2266         resource = self.GetEditedElement(tagname)
  2268         if resource is not None:
  2267         if resource is not None:
  2269             tasks = resource.getTask()
  2268             tasks = resource.gettask()
  2270             instances = resource.getPouInstance()
  2269             instances = resource.getpouInstance()
  2271             tasks_data = []
  2270             tasks_data = []
  2272             instances_data = []
  2271             instances_data = []
  2273             for task in tasks:
  2272             for task in tasks:
  2274                 new_task = {}
  2273                 new_task = {}
  2275                 new_task["Name"] = task.getName()
  2274                 new_task["Name"] = task.getname()
  2276                 single = task.getSingle()
  2275                 single = task.getsingle()
  2277                 if single:
  2276                 if single:
  2278                     new_task["Single"] = single
  2277                     new_task["Single"] = single
  2279                 else:
  2278                 else:
  2280                     new_task["Single"] = ""
  2279                     new_task["Single"] = ""
  2281                 interval = task.getInterval()
  2280                 interval = task.getinterval()
  2282                 if interval:
  2281                 if interval:
  2283                     text = ""
  2282                     text = ""
  2284                     if interval.hour != 0:
  2283                     if interval.hour != 0:
  2285                         text += "%dh"%interval.hour
  2284                         text += "%dh"%interval.hour
  2286                     if interval.minute != 0:
  2285                     if interval.minute != 0:
  2293                         else:
  2292                         else:
  2294                             text += "%dms"%(interval.microsecond / 1000)
  2293                             text += "%dms"%(interval.microsecond / 1000)
  2295                     new_task["Interval"] = text
  2294                     new_task["Interval"] = text
  2296                 else:
  2295                 else:
  2297                     new_task["Interval"] = ""
  2296                     new_task["Interval"] = ""
  2298                 new_task["Priority"] = str(task.priority.getValue())
  2297                 new_task["Priority"] = str(task.getpriority())
  2299                 tasks_data.append(new_task)
  2298                 tasks_data.append(new_task)
  2300                 for instance in task.getPouInstance():
  2299                 for instance in task.getpouInstance():
  2301                     new_instance = {}
  2300                     new_instance = {}
  2302                     new_instance["Name"] = instance.getName()
  2301                     new_instance["Name"] = instance.getname()
  2303                     new_instance["Type"] = instance.getType()
  2302                     new_instance["Type"] = instance.gettype()
  2304                     new_instance["Task"] = task.getName()
  2303                     new_instance["Task"] = task.getname()
  2305                     instances_data.append(new_instance)
  2304                     instances_data.append(new_instance)
  2306             for instance in instances:
  2305             for instance in instances:
  2307                 new_instance = {}
  2306                 new_instance = {}
  2308                 new_instance["Name"] = instance.getName()
  2307                 new_instance["Name"] = instance.getname()
  2309                 new_instance["Type"] = instance.getType()
  2308                 new_instance["Type"] = instance.gettype()
  2310                 new_instance["Task"] = ""
  2309                 new_instance["Task"] = ""
  2311                 instances_data.append(new_instance)
  2310                 instances_data.append(new_instance)
  2312             return tasks_data, instances_data
  2311             return tasks_data, instances_data
  2313 
  2312 
  2314     def OpenXMLFile(self, filepath):
  2313     def OpenXMLFile(self, filepath):
  2315         if self.VerifyXML:
  2314         xmlfile = open(filepath, 'r')
  2316             if sys:
  2315         tree = minidom.parse(xmlfile)
  2317                 sys.stdout = HolePseudoFile()
  2316         xmlfile.close()
  2318             result = pyxsval.parseAndValidate(filepath, os.path.join(ScriptDirectory, "plcopen", "TC6_XML_V10_B.xsd"))
       
  2319             if sys:
       
  2320                 sys.stdout = sys.__stdout__
       
  2321             tree = result.getTree()
       
  2322         else:
       
  2323             xmlfile = open(filepath, 'r')
       
  2324             tree = minidom.parse(xmlfile)
       
  2325             xmlfile.close()
       
  2326         
  2317         
  2327         self.Project = plcopen.project()
  2318         self.Project = plcopen.project()
  2328         for child in tree.childNodes:
  2319         for child in tree.childNodes:
  2329             if child.nodeType == tree.ELEMENT_NODE and child.nodeName == "project":
  2320             if child.nodeType == tree.ELEMENT_NODE and child.nodeName == "project":
  2330                 self.Project.loadXMLTree(child)
  2321                 self.Project.loadXMLTree(child, ["xmlns", "xmlns:xhtml", "xmlns:xsi", "xsi:schemaLocation"])
  2331                 self.SetFilePath(filepath)
  2322                 self.SetFilePath(filepath)
  2332                 self.ProjectBuffer = UndoBuffer(self.Copy(self.Project), True)
  2323                 self.ProjectBuffer = UndoBuffer(self.Copy(self.Project), True)
  2333                 self.Buffering = False
  2324                 self.Buffering = False
  2334                 self.ElementsOpened = []
  2325                 self.ElementsOpened = []
  2335                 self.CurrentElementEditing = None
  2326                 self.CurrentElementEditing = None
  2342 
  2333 
  2343     def SaveXMLFile(self, filepath = None):
  2334     def SaveXMLFile(self, filepath = None):
  2344         if not filepath and self.FilePath == "":
  2335         if not filepath and self.FilePath == "":
  2345             return False
  2336             return False
  2346         else:
  2337         else:
  2347             contentheader = self.Project.getContentHeader()
  2338             contentheader = self.Project.getcontentHeader()
  2348             contentheader["modificationDateTime"] = datetime(*localtime()[:6])
  2339             contentheader["modificationDateTime"] = datetime(*localtime()[:6])
  2349             self.Project.setContentHeader(contentheader)
  2340             self.Project.setcontentHeader(contentheader)
  2350             
  2341             
  2351             text = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
  2342             text = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
  2352             extras = {"xmlns" : "http://www.plcopen.org/xml/tc6.xsd",
  2343             extras = {"xmlns" : "http://www.plcopen.org/xml/tc6.xsd",
  2353                       "xmlns:xhtml" : "http://www.w3.org/1999/xhtml",
  2344                       "xmlns:xhtml" : "http://www.w3.org/1999/xhtml",
  2354                       "xmlns:xsi" : "http://www.w3.org/2001/XMLSchema-instance",
  2345                       "xmlns:xsi" : "http://www.w3.org/2001/XMLSchema-instance",
  2355                       "xsi:schemaLocation" : "http://www.plcopen.org/xml/tc6.xsd http://www.plcopen.org/xml/tc6.xsd"}
  2346                       "xsi:schemaLocation" : "http://www.plcopen.org/xml/tc6.xsd http://www.plcopen.org/xml/tc6.xsd"}
  2356             text += self.Project.generateXMLText("project", 0, extras)
  2347             text += self.Project.generateXMLText("project", 0, extras)
  2357             
       
  2358             if self.VerifyXML:
       
  2359                 if sys:
       
  2360                     sys.stdout = HolePseudoFile()
       
  2361                 pyxsval.parseAndValidateString(text, open(os.path.join(ScriptDirectory, "plcopen", "TC6_XML_V10_B.xsd"),"r").read())
       
  2362                 if sys:
       
  2363                     sys.stdout = sys.__stdout__
       
  2364             
  2348             
  2365             if filepath:
  2349             if filepath:
  2366                 xmlfile = open(filepath,"w")
  2350                 xmlfile = open(filepath,"w")
  2367             else:
  2351             else:
  2368                 xmlfile = open(self.FilePath,"w")
  2352                 xmlfile = open(self.FilePath,"w")