PLCControler.py
changeset 121 40b91ba978db
parent 118 0c53d6a36013
child 125 394d9f168258
equal deleted inserted replaced
120:add8e391e00c 121:40b91ba978db
   165         self.ProjectBuffer = None
   165         self.ProjectBuffer = None
   166         self.Buffering = False
   166         self.Buffering = False
   167         self.FilePath = ""
   167         self.FilePath = ""
   168         self.FileName = ""
   168         self.FileName = ""
   169         self.ProgramFilePath = ""
   169         self.ProgramFilePath = ""
   170         self.ElementsOpened = []
       
   171         self.CurrentElementEditing = None
       
   172         self.RefreshPouUsingTree()
   170         self.RefreshPouUsingTree()
   173         self.RefreshBlockTypes()
   171         self.RefreshBlockTypes()
   174 
   172 
   175     def GetQualifierTypes(self):
   173     def GetQualifierTypes(self):
   176         return plcopen.QualifierList
   174         return plcopen.QualifierList
   380         return False
   378         return False
   381 
   379 
   382 #-------------------------------------------------------------------------------
   380 #-------------------------------------------------------------------------------
   383 #                        Project Pous management functions
   381 #                        Project Pous management functions
   384 #-------------------------------------------------------------------------------
   382 #-------------------------------------------------------------------------------
   385     
       
   386     def RemoveElementEditing(self, index):
       
   387         self.ElementsOpened.pop(index)
       
   388         if self.CurrentElementEditing > index:
       
   389             self.CurrentElementEditing -= 1
       
   390         if len(self.ElementsOpened) > 0:
       
   391             self.CurrentElementEditing = max(0, min(self.CurrentElementEditing, len(self.ElementsOpened) - 1))
       
   392         else:
       
   393             self.CurrentElementEditing = None
       
   394         
   383         
   395     # Add a Pou to Project
   384     # Add a Pou to Project
   396     def ProjectAddPou(self, pou_name, pou_type, body_type):
   385     def ProjectAddPou(self, pou_name, pou_type, body_type):
   397         # Add the pou to project
   386         # Add the pou to project
   398         self.Project.appendPou(pou_name, pou_type, body_type)
   387         self.Project.appendPou(pou_name, pou_type, body_type)
   402         self.RefreshBlockTypes()
   391         self.RefreshBlockTypes()
   403         self.BufferProject()
   392         self.BufferProject()
   404     
   393     
   405     # Remove a pou from project
   394     # Remove a pou from project
   406     def ProjectRemovePou(self, pou_name):
   395     def ProjectRemovePou(self, pou_name):
   407         # Search if the pou removed is currently opened
       
   408         for i, element in enumerate(self.ElementsOpened):
       
   409             words = element.split("::")
       
   410             if words[0] == "P" and words[1] == pou_name:
       
   411                 self.RemoveElementEditing(i)
       
   412         # Remove pou from project
       
   413         self.Project.removePou(pou_name)
   396         self.Project.removePou(pou_name)
   414         self.RefreshPouUsingTree()
   397         self.RefreshPouUsingTree()
   415         self.RefreshBlockTypes()
   398         self.RefreshBlockTypes()
   416         self.BufferProject()
   399         self.BufferProject()
   417     
   400     
   422         self.RefreshBlockTypes()
   405         self.RefreshBlockTypes()
   423         self.BufferProject()
   406         self.BufferProject()
   424     
   407     
   425     # Remove a configuration from project
   408     # Remove a configuration from project
   426     def ProjectRemoveConfiguration(self, config_name):
   409     def ProjectRemoveConfiguration(self, config_name):
   427         # Search if the pou removed is currently opened
       
   428         for i, element in enumerate(self.ElementsOpened):
       
   429             words = element.split("::")
       
   430             if words[0] == "C" and words[1] == config_name:
       
   431                 self.RemoveElementEditing(i)
       
   432         self.Project.removeConfiguration(config_name)
   410         self.Project.removeConfiguration(config_name)
   433         self.BufferProject()
   411         self.BufferProject()
   434     
   412     
   435     # Add a resource to a configuration of the Project
   413     # Add a resource to a configuration of the Project
   436     def ProjectAddConfigurationResource(self, config_name, resource_name):
   414     def ProjectAddConfigurationResource(self, config_name, resource_name):
   439         self.RefreshBlockTypes()
   417         self.RefreshBlockTypes()
   440         self.BufferProject()
   418         self.BufferProject()
   441     
   419     
   442     # Remove a resource from a configuration of the project
   420     # Remove a resource from a configuration of the project
   443     def ProjectRemoveConfigurationResource(self, config_name, resource_name):
   421     def ProjectRemoveConfigurationResource(self, config_name, resource_name):
   444         # Search if the pou removed is currently opened
       
   445         for i, element in enumerate(self.ElementsOpened):
       
   446             words = element.split("::")
       
   447             if words[0] == "R" and words[1] == config_name and words[2] == resource_name:
       
   448                 self.RemoveElementEditing(i)
       
   449         self.Project.removeConfigurationResource(config_name, resource_name)
   422         self.Project.removeConfigurationResource(config_name, resource_name)
   450         self.BufferProject()
   423         self.BufferProject()
   451     
   424     
   452     # Add a Transition to a Project Pou
   425     # Add a Transition to a Project Pou
   453     def ProjectAddPouTransition(self, pou_name, transition_name, transition_type):
   426     def ProjectAddPouTransition(self, pou_name, transition_name, transition_type):
   455         pou.addTransition(transition_name, transition_type)
   428         pou.addTransition(transition_name, transition_type)
   456         self.BufferProject()
   429         self.BufferProject()
   457     
   430     
   458     # Remove a Transition from a Project Pou
   431     # Remove a Transition from a Project Pou
   459     def ProjectRemovePouTransition(self, pou_name, transition_name):
   432     def ProjectRemovePouTransition(self, pou_name, transition_name):
   460         # Search if the pou removed is currently opened
       
   461         for i, element in enumerate(self.ElementsOpened):
       
   462             words = element.split("::")
       
   463             if words[0] == "T" and words[1] == pou_name and words[2] == transition_name:
       
   464                 self.RemoveElementEditing(i)
       
   465         pou = self.Project.getPou(pou_name)
   433         pou = self.Project.getPou(pou_name)
   466         pou.removeTransition(transition_name)
   434         pou.removeTransition(transition_name)
   467         self.BufferProject()
   435         self.BufferProject()
   468     
   436     
   469     # Add an Action to a Project Pou
   437     # Add an Action to a Project Pou
   486     # Change the name of a pou
   454     # Change the name of a pou
   487     def ChangePouName(self, old_name, new_name):
   455     def ChangePouName(self, old_name, new_name):
   488         # Found the pou corresponding to old name and change its name to new name
   456         # Found the pou corresponding to old name and change its name to new name
   489         pou = self.Project.getPou(old_name)
   457         pou = self.Project.getPou(old_name)
   490         pou.setName(new_name)
   458         pou.setName(new_name)
   491         # If pou is currently opened, change its name in the list of opened pous
       
   492         for idx, element in enumerate(self.ElementsOpened):
       
   493             words = element.split("::")
       
   494             if words[0] in ["P","T","A"] and words[1] == old_name:
       
   495                 if words[0] == "P":
       
   496                     self.ElementsOpened[idx] = self.ComputePouName(new_name)
       
   497                 elif words[0] == "T":
       
   498                     self.ElementsOpened[idx] = self.ComputePouTransitionName(new_name, words[2])
       
   499                 else:
       
   500                     self.ElementsOpened[idx] = self.ComputePouActionName(new_name, words[2])
       
   501         self.Project.updateElementName(old_name, new_name)
   459         self.Project.updateElementName(old_name, new_name)
   502         self.RefreshPouUsingTree()
   460         self.RefreshPouUsingTree()
   503         self.RefreshBlockTypes()
   461         self.RefreshBlockTypes()
   504         self.BufferProject()
   462         self.BufferProject()
   505     
   463     
   507     def ChangePouTransitionName(self, pou_name, old_name, new_name):
   465     def ChangePouTransitionName(self, pou_name, old_name, new_name):
   508         # Found the pou transition corresponding to old name and change its name to new name
   466         # Found the pou transition corresponding to old name and change its name to new name
   509         pou = self.Project.getPou(pou_name)
   467         pou = self.Project.getPou(pou_name)
   510         transition = pou.getTransition(old_name)
   468         transition = pou.getTransition(old_name)
   511         transition.setName(new_name)
   469         transition.setName(new_name)
   512         # If pou transition is currently opened, change its name in the list of opened elements
       
   513         old_computedname = self.ComputePouTransitionName(pou_name, old_name)
       
   514         new_computedname = self.ComputePouTransitionName(pou_name, new_name)
       
   515         if old_computedname in self.ElementsOpened:
       
   516             idx = self.ElementsOpened.index(old_computedname)
       
   517             self.ElementsOpened[idx] = new_computedname
       
   518         pou.updateElementName(old_name, new_name)
   470         pou.updateElementName(old_name, new_name)
   519         self.BufferProject()
   471         self.BufferProject()
   520     
   472     
   521     # Change the name of a pou action
   473     # Change the name of a pou action
   522     def ChangePouActionName(self, pou_name, old_name, new_name):
   474     def ChangePouActionName(self, pou_name, old_name, new_name):
   523         # Found the pou action corresponding to old name and change its name to new name
   475         # Found the pou action corresponding to old name and change its name to new name
   524         pou = self.Project.getPou(pou_name)
   476         pou = self.Project.getPou(pou_name)
   525         action = pou.getAction(old_name)
   477         action = pou.getAction(old_name)
   526         action.setName(new_name)
   478         action.setName(new_name)
   527         # If pou action is currently opened, change its name in the list of opened elements
       
   528         old_computedname = self.ComputePouActionName(pou_name, old_name)
       
   529         new_computedname = self.ComputePouActionName(pou_name, new_name)
       
   530         if old_computedname in self.ElementsOpened:
       
   531             idx = self.ElementsOpened.index(old_computedname)
       
   532             self.ElementsOpened[idx] = new_computedname
       
   533         pou.updateElementName(old_name, new_name)
   479         pou.updateElementName(old_name, new_name)
   534         self.BufferProject()
   480         self.BufferProject()
   535     
   481     
   536     # Change the name of a pou variable
   482     # Change the name of a pou variable
   537     def ChangePouVariableName(self, pou_name, old_name, new_name):
   483     def ChangePouVariableName(self, pou_name, old_name, new_name):
   547     # Change the name of a configuration
   493     # Change the name of a configuration
   548     def ChangeConfigurationName(self, old_name, new_name):
   494     def ChangeConfigurationName(self, old_name, new_name):
   549         # Found the configuration corresponding to old name and change its name to new name
   495         # Found the configuration corresponding to old name and change its name to new name
   550         configuration = self.Project.getConfiguration(old_name)
   496         configuration = self.Project.getConfiguration(old_name)
   551         configuration.setName(new_name)
   497         configuration.setName(new_name)
   552         # If configuration is currently opened, change its name in the list of opened elements
       
   553         for idx, element in enumerate(self.ElementsOpened):
       
   554             words = element.split("::")
       
   555             if words[0] in ["C","R"] and words[1] == old_name:
       
   556                 if words[0] == "C":
       
   557                     self.ElementsOpened[idx] = self.ComputeConfigurationName(new_name)
       
   558                 else:
       
   559                     self.ElementsOpened[idx] = self.ComputeConfigurationResourceName(new_name, words[2])
       
   560         self.BufferProject()
   498         self.BufferProject()
   561     
   499     
   562     # Change the name of a configuration resource
   500     # Change the name of a configuration resource
   563     def ChangeConfigurationResourceName(self, config_name, old_name, new_name):
   501     def ChangeConfigurationResourceName(self, config_name, old_name, new_name):
   564         # Found the resource corresponding to old name and change its name to new name
   502         # Found the resource corresponding to old name and change its name to new name
   565         resource = self.Project.getConfigurationResource(config_name)
   503         resource = self.Project.getConfigurationResource(config_name)
   566         resource.setName(new_name)
   504         resource.setName(new_name)
   567         # If resource is currently opened, change its name in the list of opened elements
       
   568         old_computedname = self.ComputeConfigurationResourceName(config_name, old_name)
       
   569         new_computedname = self.ComputeConfigurationResourceName(config_name, new_name)
       
   570         if old_computedname in self.ElementsOpened:
       
   571             idx = self.ElementsOpened.index(old_computedname)
       
   572             self.ElementsOpened[idx] = new_computedname
       
   573         self.BufferProject()
   505         self.BufferProject()
   574     
   506     
   575     # Return the type of the pou given by its name
   507     # Return the type of the pou given by its name
   576     def GetPouType(self, name):
   508     def GetPouType(self, name):
   577         # Found the pou correponding to name and return its type
   509         # Found the pou correponding to name and return its type
   827     
   759     
   828     def UpdateProjectUsedPous(self, old_name, new_name):
   760     def UpdateProjectUsedPous(self, old_name, new_name):
   829         if self.Project:
   761         if self.Project:
   830             self.Project.updateElementName(old_name, new_name)
   762             self.Project.updateElementName(old_name, new_name)
   831     
   763     
   832     def UpdateCurrentPouEditingUsedVariable(self, old_name, new_name):
   764     def UpdateEditedElementUsedVariable(self, tagname, old_name, new_name):
   833         pou = self.GetCurrentElementEditing()
   765         pou = self.GetEditedElement(tagname)
   834         if pou:
   766         if pou:
   835             pou.updateElementName(old_name, new_name)
   767             pou.updateElementName(old_name, new_name)
   836     
   768     
   837     # Return the return type of the pou given by its name
   769     # Return the return type of the pou given by its name
   838     def GetPouInterfaceReturnTypeByName(self, name):
   770     def GetPouInterfaceReturnTypeByName(self, name):
   883                             if isinstance(instance, plcopen.comment):
   815                             if isinstance(instance, plcopen.comment):
   884                                 block_infos["comment"] = instance.getContentText()
   816                                 block_infos["comment"] = instance.getContentText()
   885                     BlockTypes[-1]["list"].append(block_infos)
   817                     BlockTypes[-1]["list"].append(block_infos)
   886     
   818     
   887     # Return Block types checking for recursion
   819     # Return Block types checking for recursion
   888     def GetBlockTypes(self):
   820     def GetBlockTypes(self, tagname = ""):
   889         if self.CurrentElementEditing != None:
   821         if self.Project:
   890             if self.Project:
   822             words = tagname.split("::")
   891                 current_name = self.ElementsOpened[self.CurrentElementEditing]
   823             if len(words) == 1:
   892                 words = current_name.split("::")
   824                 name = current_name
       
   825             else:
       
   826                 name = words[1]
       
   827             type = self.GetPouType(name)
       
   828         else:
       
   829             name = ""
       
   830             type = None
       
   831         if type == "function":
       
   832             blocktypes = []
       
   833             for category in BlockTypes[:-1] + PluginTypes:
       
   834                 cat = {"name" : category["name"], "list" : []}
       
   835                 for block in category["list"]:
       
   836                     if block["type"] == "function":
       
   837                         cat["list"].append(block)
       
   838                 if len(cat["list"]) > 0:
       
   839                     blocktypes.append(cat)
       
   840         else:
       
   841             blocktypes = [category for category in BlockTypes[:-1] + PluginTypes]
       
   842         if self.Project:
       
   843             blocktypes.append({"name" : "User-defined POUs", "list": []})
       
   844             for blocktype in BlockTypes[-1]["list"]:
       
   845                 if blocktype["name"] != name and not self.PouIsUsedBy(name, blocktype["name"]) and not (type == "function" and blocktype["type"] != "function"):
       
   846                     blocktypes[-1]["list"].append(blocktype)
       
   847         return blocktypes
       
   848 
       
   849     # Return Function Block types checking for recursion
       
   850     def GetFunctionBlockTypes(self, tagname = ""):
       
   851         name = ""
       
   852         type = None
       
   853         if self.Project:
       
   854             words = tagname.split("::")
       
   855             if words[0] in ["P","T","A"]:
   893                 if len(words) == 1:
   856                 if len(words) == 1:
   894                     name = current_name
   857                     name = current_name
   895                 else:
   858                 else:
   896                     name = words[1]
   859                     name = words[1]
   897                 type = self.GetPouType(name)
   860                 type = self.GetPouType(name)
   898             else:
   861         blocktypes = []
   899                 name = ""
   862         for category in BlockTypes[:-1]:
   900                 type = None
   863             for block in category["list"]:
   901             if type == "function":
   864                 if block["type"] != "function":
   902                 blocktypes = []
   865                     blocktypes.append(block["name"])
   903                 for category in BlockTypes[:-1] + PluginTypes:
   866         if self.Project:
   904                     cat = {"name" : category["name"], "list" : []}
   867             for blocktype in BlockTypes[-1]["list"]:
   905                     for block in category["list"]:
   868                 if blocktype["name"] != name and not self.PouIsUsedBy(name, blocktype["name"]) and not (type == "function" and blocktype["type"] != "function"):
   906                         if block["type"] == "function":
   869                     blocktypes.append(blocktype["name"])
   907                             cat["list"].append(block)
   870         return blocktypes
   908                     if len(cat["list"]) > 0:
       
   909                         blocktypes.append(cat)
       
   910             else:
       
   911                 blocktypes = [category for category in BlockTypes[:-1] + PluginTypes]
       
   912             if self.Project:
       
   913                 blocktypes.append({"name" : "User-defined POUs", "list": []})
       
   914                 for blocktype in BlockTypes[-1]["list"]:
       
   915                     if blocktype["name"] != name and not self.PouIsUsedBy(name, blocktype["name"]) and not (type == "function" and blocktype["type"] != "function"):
       
   916                         blocktypes[-1]["list"].append(blocktype)
       
   917             return blocktypes
       
   918         return []
       
   919 
       
   920     # Return Function Block types checking for recursion
       
   921     def GetFunctionBlockTypes(self):
       
   922         if self.CurrentElementEditing != None:
       
   923             name = ""
       
   924             type = None
       
   925             if self.Project:
       
   926                 current_name = self.ElementsOpened[self.CurrentElementEditing]
       
   927                 words = current_name.split("::")
       
   928                 if words[0] in ["P","T","A"]:
       
   929                     if len(words) == 1:
       
   930                         name = current_name
       
   931                     else:
       
   932                         name = words[1]
       
   933                     type = self.GetPouType(name)
       
   934             blocktypes = []
       
   935             for category in BlockTypes[:-1]:
       
   936                 for block in category["list"]:
       
   937                     if block["type"] != "function":
       
   938                         blocktypes.append(block["name"])
       
   939             if self.Project:
       
   940                 for blocktype in BlockTypes[-1]["list"]:
       
   941                     if blocktype["name"] != name and not self.PouIsUsedBy(name, blocktype["name"]) and not (type == "function" and blocktype["type"] != "function"):
       
   942                         blocktypes.append(blocktype["name"])
       
   943             return blocktypes
       
   944         return []
       
   945 
   871 
   946     # Return Block types checking for recursion
   872     # Return Block types checking for recursion
   947     def GetBlockResource(self):
   873     def GetBlockResource(self):
   948         blocktypes = []
   874         blocktypes = []
   949         for category in BlockTypes[:-1]:
   875         for category in BlockTypes[:-1]:
   955                 if pou.pouType.getValue() == "program":
   881                 if pou.pouType.getValue() == "program":
   956                     blocktypes.append(pou.getName())
   882                     blocktypes.append(pou.getName())
   957         return blocktypes
   883         return blocktypes
   958 
   884 
   959 #-------------------------------------------------------------------------------
   885 #-------------------------------------------------------------------------------
   960 #                       Project opened Pous management functions
   886 #                   Project Element tag name computation functions
   961 #-------------------------------------------------------------------------------
   887 #-------------------------------------------------------------------------------
   962     
       
   963     # Return the list of pou names
       
   964     def GetElementsOpenedNames(self):
       
   965         names = []
       
   966         for pou_name in self.ElementsOpened:
       
   967             words = pou_name.split("::")
       
   968             if words[0] in ["P","C"]:
       
   969                 names.append(words[1])
       
   970             else:
       
   971                 names.append("%s-%s"%(words[1],words[2]))
       
   972         return names
       
   973     
   888     
   974     # Compute a pou transition name
   889     # Compute a pou transition name
   975     def ComputePouName(self, pou):
   890     def ComputePouName(self, pou):
   976         return "P::%s" % pou
   891         return "P::%s" % pou
   977     
   892     
   989 
   904 
   990     # Compute a pou  name
   905     # Compute a pou  name
   991     def ComputeConfigurationResourceName(self, config, resource):
   906     def ComputeConfigurationResourceName(self, config, resource):
   992         return "R::%s::%s" % (config, resource)
   907         return "R::%s::%s" % (config, resource)
   993     
   908     
   994     # Open a pou by giving its name
       
   995     def OpenElementEditing(self, name):
       
   996         # If pou not opened yet
       
   997         if name not in self.ElementsOpened:
       
   998             # Add pou name to list of pou opened and make it current editing
       
   999             self.ElementsOpened.append(name)
       
  1000             self.CurrentElementEditing = len(self.ElementsOpened) - 1
       
  1001             return self.CurrentElementEditing
       
  1002         return None
       
  1003 
       
  1004     # Open a pou transition by giving pou and transition names
       
  1005     def OpenPouEditing(self, pou):
       
  1006         return self.OpenElementEditing(self.ComputePouName(pou))
       
  1007 
       
  1008     # Open a pou transition by giving pou and transition names
       
  1009     def OpenPouTransitionEditing(self, pou, transition):
       
  1010         return self.OpenElementEditing(self.ComputePouTransitionName(pou, transition))
       
  1011 
       
  1012     # Open a pou action by giving pou and action names
       
  1013     def OpenPouActionEditing(self, pou, action):
       
  1014         return self.OpenElementEditing(self.ComputePouActionName(pou, action))
       
  1015 
       
  1016     # Open a configuration resource by giving configuration name
       
  1017     def OpenConfigurationEditing(self, config):
       
  1018         return self.OpenElementEditing(self.ComputeConfigurationName(config))
       
  1019 
       
  1020     # Open a configuration resource by giving configuration and resource names
       
  1021     def OpenConfigurationResourceEditing(self, config, resource):
       
  1022         return self.OpenElementEditing(self.ComputeConfigurationResourceName(config, resource))
       
  1023 
       
  1024     # Return if pou given by name is opened
       
  1025     def IsPouEditing(self, pou):
       
  1026         return self.ComputePouName(pou) in self.ElementsOpened
       
  1027 
       
  1028     # Return if pou transition given by pou and transition names is opened
       
  1029     def IsPouTransitionEditing(self, pou, transition):
       
  1030         return self.ComputePouTransitionName(pou, transition) in self.ElementsOpened
       
  1031 
       
  1032     # Return if pou action given by pou and action names is opened
       
  1033     def IsPouActionEditing(self, pou, action):
       
  1034         return self.ComputePouActionName(pou, action) in self.ElementsOpened
       
  1035 
       
  1036     # Return if pou action given by configuration name is opened
       
  1037     def IsConfigurationEditing(self, config):
       
  1038         return self.ComputeConfigurationName(config) in self.ElementsOpened
       
  1039 
       
  1040     # Return if pou action given by configuration and resource names is opened
       
  1041     def IsConfigurationResourceEditing(self, config, resource):
       
  1042         return self.ComputeConfigurationResourceName(config, resource) in self.ElementsOpened
       
  1043 
       
  1044     # Close current element editing
       
  1045     def CloseElementEditing(self):
       
  1046         # Remove pou from list of pou opened
       
  1047         self.ElementsOpened.pop(self.CurrentElementEditing)
       
  1048         # Update index of current element editing
       
  1049         if len(self.ElementsOpened) > 0:
       
  1050             self.CurrentElementEditing = min(self.CurrentElementEditing, len(self.ElementsOpened) - 1)
       
  1051         else:
       
  1052             self.CurrentElementEditing = None
       
  1053 
       
  1054     # Close current element editing
       
  1055     def CloseAllElements(self):
       
  1056         # Clear the pou opened list
       
  1057         self.ElementsOpened = []
       
  1058         self.CurrentElementEditing = None
       
  1059 
       
  1060     # Change current element editing for pou given by name
       
  1061     def ChangeElementEditing(self, name):
       
  1062         # Verify that element is opened
       
  1063         if name in self.ElementsOpened:
       
  1064             # Change current element editing
       
  1065             self.CurrentElementEditing = self.ElementsOpened.index(name)
       
  1066             return self.CurrentElementEditing
       
  1067         return None
       
  1068     
       
  1069     # Change current element editing for pou given by pou name
       
  1070     def ChangePouEditing(self, pou):
       
  1071         return self.ChangeElementEditing(self.ComputePouName(pou))
       
  1072 
       
  1073     # Change current element editing for transition given by pou and transition names
       
  1074     def ChangePouTransitionEditing(self, pou, transition):
       
  1075         return self.ChangeElementEditing(self.ComputePouTransitionName(pou, transition))
       
  1076 
       
  1077     # Change current element editing for action given by pou and action names
       
  1078     def ChangePouActionEditing(self, pou, action):
       
  1079         return self.ChangeElementEditing(self.ComputePouActionName(pou, action))
       
  1080 
       
  1081     # Change current element editing for configuration given by configuration name
       
  1082     def ChangeConfigurationEditing(self, config):
       
  1083         return self.ChangeElementEditing(self.ComputeConfigurationName(config))
       
  1084 
       
  1085     # Change current element editing for resource given by configuration and resource names
       
  1086     def ChangeConfigurationResourceEditing(self, config, resource):
       
  1087         return self.ChangeElementEditing(self.ComputeConfigurationResourceName(config, resource))
       
  1088 
       
  1089 #-------------------------------------------------------------------------------
   909 #-------------------------------------------------------------------------------
  1090 #                       Project opened Pous management functions
   910 #                       Project opened Pous management functions
  1091 #-------------------------------------------------------------------------------
   911 #-------------------------------------------------------------------------------
  1092 
   912 
  1093     # Return current pou editing
   913     # Return edited element
  1094     def GetCurrentElementEditing(self):
   914     def GetEditedElement(self, tagname):
  1095         # Verify that there's one editing and return it
   915         words = tagname.split("::")
  1096         if self.CurrentElementEditing != None:
   916         if words[0] == "P":
  1097             name = self.ElementsOpened[self.CurrentElementEditing]
   917             return self.Project.getPou(words[1])
  1098             words = name.split("::")
   918         if words[0] in ['T', 'A']:
  1099             if words[0] == "P":
   919             pou = self.Project.getPou(words[1])
  1100                 return self.Project.getPou(words[1])
   920             if words[0] == 'T':
  1101             if words[0] in ['T', 'A']:
   921                 return pou.getTransition(words[2])
  1102                 pou = self.Project.getPou(words[1])
   922             elif words[0] == 'A':
  1103                 if words[0] == 'T':
   923                 return pou.getAction(words[2])
  1104                     return pou.getTransition(words[2])
   924         elif words[0] == 'C':
  1105                 elif words[0] == 'A':
   925             return self.Project.getConfiguration(words[1])
  1106                     return pou.getAction(words[2])
   926         elif words[0] == 'R':
  1107             elif words[0] == 'C':
   927             return self.Project.getConfigurationResource(words[1], words[2])
  1108                 return self.Project.getConfiguration(words[1])
       
  1109             elif words[0] == 'R':
       
  1110                 return self.Project.getConfigurationResource(words[1], words[2])
       
  1111         return None
   928         return None
  1112     
   929     
  1113     # Return current pou editing name
   930     # Return edited element name
  1114     def GetCurrentElementEditingName(self):
   931     def GetEditedElementName(self, tagname):
  1115         # Verify that there's one editing and return its name
   932         words = tagname.split("::")
  1116         if self.CurrentElementEditing != None:
   933         if words[0] in ["P","C"]:
  1117             name = self.ElementsOpened[self.CurrentElementEditing]
   934             return words[1]
  1118             words = name.split("::")
   935         else:
  1119             if words[0] in ["P","C"]:
   936             return words[2]
  1120                 return words[1]
   937         return None
       
   938     
       
   939     # Return edited element name and type
       
   940     def GetEditedElementType(self, tagname):
       
   941         words = tagname.split("::")
       
   942         if words[0] in ["P","T","A"]:
       
   943             return words[1], self.GetPouType(words[1])
       
   944         return None, None
       
   945 
       
   946     # Return language in which edited element is written
       
   947     def GetEditedElementBodyType(self, tagname):
       
   948         words = tagname.split("::")
       
   949         if words[0] == "P":
       
   950             return self.GetPouBodyType(words[1])
       
   951         elif words[0] == 'T':
       
   952             return self.GetTransitionBodyType(words[1], words[2])
       
   953         elif words[0] == 'A':
       
   954             return self.GetActionBodyType(words[1], words[2])
       
   955         return None
       
   956 
       
   957     # Return the edited element variables
       
   958     def GetEditedElementInterfaceVars(self, tagname):
       
   959         words = tagname.split("::")
       
   960         if words[0] in ["P","T","A"]:
       
   961             pou = self.Project.getPou(words[1])
       
   962             return self.GetPouInterfaceVars(pou)
       
   963         return []
       
   964 
       
   965     # Return the edited element return type
       
   966     def GetEditedElementInterfaceReturnType(self, tagname):
       
   967         words = tagname.split("::")
       
   968         if words[0] == "P":
       
   969             pou = self.Project.getPou(words[1])
       
   970             return self.GetPouInterfaceReturnType(pou)
       
   971         elif words[0] == 'T':
       
   972             return "BOOL"
       
   973         return None
       
   974     
       
   975     # Change the edited element taxt
       
   976     def SetEditedElementText(self, tagname, text):
       
   977         element = self.GetEditedElement(tagname)
       
   978         if element != None:
       
   979             element.setText(text)
       
   980             self.RefreshPouUsingTree()
       
   981     
       
   982     # Return the edited element text
       
   983     def GetEditedElementText(self, tagname):
       
   984         element = self.GetEditedElement(tagname)
       
   985         if element != None:
       
   986             return element.getText()
       
   987         return ""
       
   988 
       
   989     # Return the edited element transitions
       
   990     def GetEditedElementTransitions(self, tagname):
       
   991         pou = self.GetEditedElement(tagname)
       
   992         if pou != None and pou.getBodyType() == "SFC":
       
   993             transitions = []
       
   994             for transition in pou.getTransitionList():
       
   995                 transitions.append(transition.getName())
       
   996             return transitions
       
   997         return []
       
   998 
       
   999     # Return edited element transitions
       
  1000     def GetEditedElementActions(self, tagname):
       
  1001         pou = self.GetEditedElement(tagname)
       
  1002         if pou != None and pou.getBodyType() == "SFC":
       
  1003             actions = []
       
  1004             for action in pou.getActionList():
       
  1005                 actions.append(action.getName())
       
  1006             return actions
       
  1007         return []
       
  1008 
       
  1009     # Return the names of the pou elements
       
  1010     def GetEditedElementVariables(self, tagname):
       
  1011         words = tagname.split("::")
       
  1012         if words[0] in ["P","T","A"]:
       
  1013             return self.GetProjectPouVariables(words[1])
       
  1014         return []
       
  1015 
       
  1016     # Return the current pou editing informations
       
  1017     def GetEditedElementInstanceInfos(self, tagname, id = None, exclude = []):
       
  1018         infos = {}
       
  1019         instance = None
       
  1020         element = self.GetEditedElement(tagname)
       
  1021         if element is not None:
       
  1022             # if id is defined
       
  1023             if id is not None:
       
  1024                 instance = element.getInstance(id)
  1121             else:
  1025             else:
  1122                 return words[2]
  1026                 instance = element.getRandomInstance(exclude)
  1123         return None
  1027         if instance is not None:
  1124     
  1028             if id is not None:
  1125     # Replace the index of current pou editing by the one given
       
  1126     def RefreshCurrentElementEditing(self, index):
       
  1127         self.CurrentElementEditing = index
       
  1128 
       
  1129     # Return current pou editing name and type
       
  1130     def GetCurrentElementEditingType(self):
       
  1131         if self.CurrentElementEditing != None:
       
  1132             name = self.ElementsOpened[self.CurrentElementEditing]
       
  1133             words = name.split("::")
       
  1134             if words[0] in ["P","T","A"]:
       
  1135                 return words[1], self.GetPouType(words[1])
       
  1136         return None, None
       
  1137 
       
  1138     # Return language in which current pou editing is written
       
  1139     def GetCurrentElementEditingBodyType(self):
       
  1140         if self.CurrentElementEditing != None:
       
  1141             name = self.ElementsOpened[self.CurrentElementEditing]
       
  1142             words = name.split("::")
       
  1143             if words[0] == "P":
       
  1144                 return self.GetPouBodyType(words[1])
       
  1145             elif words[0] == 'T':
       
  1146                 return self.GetTransitionBodyType(words[1], words[2])
       
  1147             elif words[0] == 'A':
       
  1148                 return self.GetActionBodyType(words[1], words[2])
       
  1149         return None
       
  1150 
       
  1151     # Return the variables of the current pou editing
       
  1152     def GetCurrentElementEditingInterfaceVars(self):
       
  1153         if self.CurrentElementEditing != None:
       
  1154             current_name = self.ElementsOpened[self.CurrentElementEditing]
       
  1155             words = current_name.split("::")
       
  1156             if words[0] in ["P","T","A"]:
       
  1157                 pou = self.Project.getPou(words[1])
       
  1158                 return self.GetPouInterfaceVars(pou)
       
  1159         return []
       
  1160 
       
  1161     # Return the return type of the current pou editing
       
  1162     def GetCurrentElementEditingInterfaceReturnType(self):
       
  1163         if self.CurrentElementEditing != None:
       
  1164             current_name = self.ElementsOpened[self.CurrentElementEditing]
       
  1165             words = current_name.split("::")
       
  1166             if words[0] == "P":
       
  1167                 pou = self.Project.getPou(words[1])
       
  1168                 return self.GetPouInterfaceReturnType(pou)
       
  1169             elif words[0] == 'T':
       
  1170                 return "BOOL"
       
  1171         return None
       
  1172     
       
  1173     # Change the text of the current pou editing
       
  1174     def SetCurrentElementEditingText(self, text):
       
  1175         if self.CurrentElementEditing != None:
       
  1176             self.GetCurrentElementEditing().setText(text)
       
  1177             self.RefreshPouUsingTree()
       
  1178     
       
  1179     # Return the current pou editing text
       
  1180     def GetCurrentElementEditingText(self):
       
  1181         if self.CurrentElementEditing != None:
       
  1182             return self.GetCurrentElementEditing().getText()
       
  1183         return ""
       
  1184 
       
  1185     # Return the current pou editing transitions
       
  1186     def GetCurrentElementEditingTransitions(self):
       
  1187         if self.CurrentElementEditing != None:
       
  1188             pou = self.GetCurrentElementEditing()
       
  1189             if pou.getBodyType() == "SFC":
       
  1190                 transitions = []
       
  1191                 for transition in pou.getTransitionList():
       
  1192                     transitions.append(transition.getName())
       
  1193                 return transitions
       
  1194         return []
       
  1195 
       
  1196     # Return the current pou editing transitions
       
  1197     def GetCurrentElementEditingActions(self):
       
  1198         if self.CurrentElementEditing != None:
       
  1199             pou = self.GetCurrentElementEditing()
       
  1200             if pou.getBodyType() == "SFC":
       
  1201                 actions = []
       
  1202                 for action in pou.getActionList():
       
  1203                     actions.append(action.getName())
       
  1204                 return actions
       
  1205         return []
       
  1206 
       
  1207     # Return the names of the pou elements
       
  1208     def GetCurrentElementEditingVariables(self):
       
  1209         if self.CurrentElementEditing != None:
       
  1210             current_name = self.ElementsOpened[self.CurrentElementEditing]
       
  1211             words = current_name.split("::")
       
  1212             if words[0] in ["P","T","A"]:
       
  1213                 return self.GetProjectPouVariables(words[1])
       
  1214         return []
       
  1215 
       
  1216     # Return the current pou editing informations
       
  1217     def GetCurrentElementEditingInstanceInfos(self, id = None, exclude = []):
       
  1218         infos = {}
       
  1219         # if id is defined
       
  1220         if id != None:
       
  1221             instance = self.GetCurrentElementEditing().getInstance(id)
       
  1222         else:
       
  1223             instance = self.GetCurrentElementEditing().getRandomInstance(exclude)
       
  1224         if instance:
       
  1225             if id != None:
       
  1226                 infos["id"] = id
  1029                 infos["id"] = id
  1227             else:
  1030             else:
  1228                 infos["id"] = instance.getLocalId() 
  1031                 infos["id"] = instance.getLocalId() 
  1229             infos["x"] = instance.getX()
  1032             infos["x"] = instance.getX()
  1230             infos["y"] = instance.getY()
  1033             infos["y"] = instance.getY()
  1259                     connector["negated"] = variable.getNegated()
  1062                     connector["negated"] = variable.getNegated()
  1260                     connector["edge"] = variable.getConnectorEdge()
  1063                     connector["edge"] = variable.getConnectorEdge()
  1261                     infos["connectors"]["outputs"].append(connector)
  1064                     infos["connectors"]["outputs"].append(connector)
  1262             elif isinstance(instance, plcopen.inVariable):
  1065             elif isinstance(instance, plcopen.inVariable):
  1263                 infos["name"] = instance.getExpression()
  1066                 infos["name"] = instance.getExpression()
  1264                 infos["value_type"] = self.GetCurrentPouVarValueType(infos["name"])
  1067                 infos["value_type"] = self.GetEditedElementVarValueType(tagname, infos["name"])
  1265                 infos["type"] = "input"
  1068                 infos["type"] = "input"
  1266                 executionOrder = instance.getExecutionOrderId()
  1069                 executionOrder = instance.getExecutionOrderId()
  1267                 if executionOrder is not None:
  1070                 if executionOrder is not None:
  1268                     infos["executionOrder"] = executionOrder
  1071                     infos["executionOrder"] = executionOrder
  1269                 else:
  1072                 else:
  1272                 infos["connector"]["position"] = instance.connectionPointOut.getRelPosition()
  1075                 infos["connector"]["position"] = instance.connectionPointOut.getRelPosition()
  1273                 infos["connector"]["negated"] = instance.getNegated()
  1076                 infos["connector"]["negated"] = instance.getNegated()
  1274                 infos["connector"]["edge"] = instance.getConnectorEdge()
  1077                 infos["connector"]["edge"] = instance.getConnectorEdge()
  1275             elif isinstance(instance, plcopen.outVariable):
  1078             elif isinstance(instance, plcopen.outVariable):
  1276                 infos["name"] = instance.getExpression()
  1079                 infos["name"] = instance.getExpression()
  1277                 infos["value_type"] = self.GetCurrentPouVarValueType(infos["name"])
  1080                 infos["value_type"] = self.GetEditedElementVarValueType(tagname, infos["name"])
  1278                 infos["type"] = "output"
  1081                 infos["type"] = "output"
  1279                 executionOrder = instance.getExecutionOrderId()
  1082                 executionOrder = instance.getExecutionOrderId()
  1280                 if executionOrder is not None:
  1083                 if executionOrder is not None:
  1281                     infos["executionOrder"] = executionOrder
  1084                     infos["executionOrder"] = executionOrder
  1282                 else:
  1085                 else:
  1291                     for link in connections:
  1094                     for link in connections:
  1292                         dic = {"refLocalId":link.getRefLocalId(),"points":link.getPoints(),"formalParameter":link.getFormalParameter()}
  1095                         dic = {"refLocalId":link.getRefLocalId(),"points":link.getPoints(),"formalParameter":link.getFormalParameter()}
  1293                         infos["connector"]["links"].append(dic)
  1096                         infos["connector"]["links"].append(dic)
  1294             elif isinstance(instance, plcopen.inOutVariable):
  1097             elif isinstance(instance, plcopen.inOutVariable):
  1295                 infos["name"] = instance.getExpression()
  1098                 infos["name"] = instance.getExpression()
  1296                 infos["value_type"] = self.GetCurrentPouVarValueType(infos["name"])
  1099                 infos["value_type"] = self.GetEditedElementVarValueType(tagname, infos["name"])
  1297                 infos["type"] = "inout"
  1100                 infos["type"] = "inout"
  1298                 executionOrder = instance.getExecutionOrderId()
  1101                 executionOrder = instance.getExecutionOrderId()
  1299                 if executionOrder is not None:
  1102                 if executionOrder is not None:
  1300                     infos["executionOrder"] = executionOrder
  1103                     infos["executionOrder"] = executionOrder
  1301                 else:
  1104                 else:
  1508                         dic = {"refLocalId":link.getRefLocalId(),"points":link.getPoints(),"formalParameter":link.getFormalParameter()}
  1311                         dic = {"refLocalId":link.getRefLocalId(),"points":link.getPoints(),"formalParameter":link.getFormalParameter()}
  1509                         infos["connector"]["links"].append(dic)
  1312                         infos["connector"]["links"].append(dic)
  1510             return infos
  1313             return infos
  1511         return False
  1314         return False
  1512     
  1315     
  1513     def ClearCurrentExecutionOrder(self):
  1316     def ClearEditedElementExecutionOrder(self, tagname):
  1514         self.GetCurrentElementEditing().resetExecutionOrder()
  1317         element = self.GetEditedElement(tagname)
  1515     
  1318         if element is not None:
  1516     def ResetCurrentExecutionOrder(self):
  1319             element.resetExecutionOrder()
  1517         self.GetCurrentElementEditing().compileExecutionOrder()
  1320     
       
  1321     def ResetEditedElementExecutionOrder(self, tagname):
       
  1322         element = self.GetEditedElement(tagname)
       
  1323         if element is not None:
       
  1324             element.compileExecutionOrder()
  1518     
  1325     
  1519     # Return the variable type of the given pou
  1326     # Return the variable type of the given pou
  1520     def GetCurrentPouVarValueType(self, varname):
  1327     def GetEditedElementVarValueType(self, tagname, varname):
  1521         current_name = self.ElementsOpened[self.CurrentElementEditing]
  1328         words = tagname.split("::")
  1522         words = current_name.split("::")
       
  1523         if words[0] in ["P","T","A"]:
  1329         if words[0] in ["P","T","A"]:
  1524             pou = self.Project.getPou(words[1])
  1330             pou = self.Project.getPou(words[1])
  1525             for type, varlist in pou.getVars():
  1331             for type, varlist in pou.getVars():
  1526                 for var in varlist.getVariable():
  1332                 for var in varlist.getVariable():
  1527                     if var.getName() == varname:
  1333                     if var.getName() == varname:
  1546                     connection.setConnectionParameter(idx, formalParameter)
  1352                     connection.setConnectionParameter(idx, formalParameter)
  1547                 else:
  1353                 else:
  1548                     connection.setConnectionParameter(idx, None)
  1354                     connection.setConnectionParameter(idx, None)
  1549                 idx += 1
  1355                 idx += 1
  1550     
  1356     
  1551     def AddCurrentElementEditingBlock(self, id, blocktype, blockname = None):
  1357     def AddEditedElementBlock(self, tagname, id, blocktype, blockname = None):
  1552         block = plcopen.block()
  1358         element = self.GetEditedElement(tagname)
  1553         block.setLocalId(id)
  1359         if element is not None:
  1554         block.setTypeName(blocktype)
  1360             block = plcopen.block()
  1555         if blockname:
  1361             block.setLocalId(id)
  1556             block.setInstanceName(blockname)
  1362             block.setTypeName(blocktype)
  1557         element = self.GetCurrentElementEditing()
  1363             blocktype_infos = GetBlockType(blocktype)
  1558         blocktype_infos = GetBlockType(blocktype)
  1364             if blocktype_infos["type"] != "function" and blockname is not None:
  1559         if blocktype_infos["type"] != "function":
  1365                 block.setInstanceName(blockname)
  1560             if self.CurrentElementEditing != None:
  1366                 element.addPouVar(blocktype, blockname)    
  1561                 name = self.ElementsOpened[self.CurrentElementEditing]
  1367             element.addInstance("block", block)
  1562                 words = name.split("::")
  1368             self.RefreshPouUsingTree()
  1563                 if words[0] in ["P","T","A"]:
  1369     
  1564                     pou = self.Project.getPou(words[1])
  1370     def SetEditedElementBlockInfos(self, tagname, id, infos):
  1565                     pou.addPouVar(blocktype, blockname)    
  1371         element = self.GetEditedElement(tagname)
  1566         element.addInstance("block", block)
  1372         if element is not None:
  1567         self.RefreshPouUsingTree()
  1373             block = element.getInstance(id)
  1568     
  1374             if "name" in infos or "type" in infos:
  1569     def SetCurrentElementEditingBlockInfos(self, id, infos):
  1375                 old_name = block.getInstanceName()
  1570         block = self.GetCurrentElementEditing().getInstance(id)
  1376                 old_type = block.getTypeName()
  1571         if "name" in infos or "type" in infos:
  1377                 new_name = infos.get("name", old_name)
  1572             old_name = block.getInstanceName()
  1378                 new_type = infos.get("type", old_type)
  1573             old_type = block.getTypeName()
  1379                 self.GetEditedElement(tagname).changePouVar(old_type, old_name, new_type, new_name)
  1574             new_name = infos.get("name", old_name)
  1380             for param, value in infos.items():
  1575             new_type = infos.get("type", old_type)
  1381                 if param == "name":
  1576             self.GetCurrentElementEditing().changePouVar(old_type, old_name, new_type, new_name)
  1382                     block.setInstanceName(value)
  1577         for param, value in infos.items():
  1383                 elif param == "type":
  1578             if param == "name":
  1384                     block.setTypeName(value)
  1579                 block.setInstanceName(value)
  1385                 elif param == "executionOrder" and block.getExecutionOrderId() != value:
  1580             elif param == "type":
  1386                     self.GetEditedElement(tagname).setElementExecutionOrder(block, value)
  1581                 block.setTypeName(value)
  1387                 elif param == "height":
  1582             elif param == "executionOrder" and block.getExecutionOrderId() != value:
  1388                     block.setHeight(value)
  1583                 self.GetCurrentElementEditing().setElementExecutionOrder(block, value)
  1389                 elif param == "width":
  1584             elif param == "height":
  1390                     block.setWidth(value)
  1585                 block.setHeight(value)
  1391                 elif param == "x":
  1586             elif param == "width":
  1392                     block.setX(value)
  1587                 block.setWidth(value)
  1393                 elif param == "y":
  1588             elif param == "x":
  1394                     block.setY(value)
  1589                 block.setX(value)
  1395                 elif param == "connectors":
  1590             elif param == "y":
  1396                     block.inputVariables.setVariable([])
  1591                 block.setY(value)
  1397                     block.outputVariables.setVariable([])
  1592             elif param == "connectors":
  1398                     for connector in value["inputs"]:
  1593                 block.inputVariables.setVariable([])
  1399                         variable = plcopen.inputVariables_variable()
  1594                 block.outputVariables.setVariable([])
  1400                         variable.setFormalParameter(connector.GetName())
  1595                 for connector in value["inputs"]:
  1401                         if connector.IsNegated():
  1596                     variable = plcopen.inputVariables_variable()
  1402                             variable.setNegated(True)
  1597                     variable.setFormalParameter(connector.GetName())
  1403                         if connector.GetEdge() != "none":
  1598                     if connector.IsNegated():
  1404                             variable.setConnectorEdge(connector.GetEdge())
  1599                         variable.setNegated(True)
  1405                         position = connector.GetRelPosition()
  1600                     if connector.GetEdge() != "none":
  1406                         variable.connectionPointIn.setRelPosition(position.x, position.y)
  1601                         variable.setConnectorEdge(connector.GetEdge())
  1407                         self.SetConnectionWires(variable.connectionPointIn, connector)
  1602                     position = connector.GetRelPosition()
  1408                         block.inputVariables.appendVariable(variable)
  1603                     variable.connectionPointIn.setRelPosition(position.x, position.y)
  1409                     for connector in value["outputs"]:
  1604                     self.SetConnectionWires(variable.connectionPointIn, connector)
  1410                         variable = plcopen.outputVariables_variable()
  1605                     block.inputVariables.appendVariable(variable)
  1411                         variable.setFormalParameter(connector.GetName())
  1606                 for connector in value["outputs"]:
  1412                         if connector.IsNegated():
  1607                     variable = plcopen.outputVariables_variable()
  1413                             variable.setNegated(True)
  1608                     variable.setFormalParameter(connector.GetName())
  1414                         if connector.GetEdge() != "none":
  1609                     if connector.IsNegated():
  1415                             variable.setConnectorEdge(connector.GetEdge())
  1610                         variable.setNegated(True)
  1416                         position = connector.GetRelPosition()
  1611                     if connector.GetEdge() != "none":
  1417                         variable.addConnectionPointOut()
  1612                         variable.setConnectorEdge(connector.GetEdge())
  1418                         variable.connectionPointOut.setRelPosition(position.x, position.y)
  1613                     position = connector.GetRelPosition()
  1419                         block.outputVariables.appendVariable(variable)
  1614                     variable.addConnectionPointOut()
  1420             self.RefreshPouUsingTree()
  1615                     variable.connectionPointOut.setRelPosition(position.x, position.y)
       
  1616                     block.outputVariables.appendVariable(variable)
       
  1617         self.RefreshPouUsingTree()
       
  1618         
  1421         
  1619     def AddCurrentElementEditingVariable(self, id, type):
  1422     def AddEditedElementVariable(self, tagname, id, type):
  1620         if type == INPUT:
  1423         element = self.GetEditedElement(tagname)
  1621             name = "inVariable"
  1424         if element is not None:            
  1622             variable = plcopen.inVariable()
  1425             if type == INPUT:
  1623         elif type == OUTPUT:
  1426                 name = "inVariable"
  1624             name = "outVariable"
  1427                 variable = plcopen.inVariable()
  1625             variable = plcopen.outVariable()
  1428             elif type == OUTPUT:
  1626         elif type == INOUT:
  1429                 name = "outVariable"
  1627             name = "inOutVariable"
  1430                 variable = plcopen.outVariable()
  1628             variable = plcopen.inOutVariable()
  1431             elif type == INOUT:
  1629         variable.setLocalId(id)
  1432                 name = "inOutVariable"
  1630         self.GetCurrentElementEditing().addInstance(name, variable)
  1433                 variable = plcopen.inOutVariable()
       
  1434             variable.setLocalId(id)
       
  1435             element.addInstance(name, variable)
  1631         
  1436         
  1632     def SetCurrentElementEditingVariableInfos(self, id, infos):
  1437     def SetEditedElementVariableInfos(self, tagname, id, infos):
  1633         variable = self.GetCurrentElementEditing().getInstance(id)
  1438         element = self.GetEditedElement(tagname)
  1634         for param, value in infos.items():
  1439         if element is not None:
  1635             if param == "name":
  1440             variable = element.getInstance(id)
  1636                 variable.setExpression(value)    
  1441             for param, value in infos.items():
  1637             elif param == "executionOrder" and variable.getExecutionOrderId() != value:
  1442                 if param == "name":
  1638                 self.GetCurrentElementEditing().setElementExecutionOrder(variable, value)
  1443                     variable.setExpression(value)    
  1639             elif param == "height":
  1444                 elif param == "executionOrder" and variable.getExecutionOrderId() != value:
  1640                 variable.setHeight(value)
  1445                     self.GetEditedElement(tagname).setElementExecutionOrder(variable, value)
  1641             elif param == "width":
  1446                 elif param == "height":
  1642                 variable.setWidth(value)
  1447                     variable.setHeight(value)
  1643             elif param == "x":
  1448                 elif param == "width":
  1644                 variable.setX(value)
  1449                     variable.setWidth(value)
  1645             elif param == "y":
  1450                 elif param == "x":
  1646                 variable.setY(value)
  1451                     variable.setX(value)
  1647             elif param == "connectors":
  1452                 elif param == "y":
  1648                 if isinstance(variable, plcopen.inVariable):
  1453                     variable.setY(value)
  1649                     if value["output"].IsNegated():
  1454                 elif param == "connectors":
  1650                         variable.setNegated(True)
  1455                     if isinstance(variable, plcopen.inVariable):
  1651                     if value["output"].GetEdge() != "none":
  1456                         if value["output"].IsNegated():
  1652                         variable.setConnectorEdge(value["output"].GetEdge())
  1457                             variable.setNegated(True)
  1653                     position = value["output"].GetRelPosition()
  1458                         if value["output"].GetEdge() != "none":
  1654                     variable.addConnectionPointOut()
  1459                             variable.setConnectorEdge(value["output"].GetEdge())
  1655                     variable.connectionPointOut.setRelPosition(position.x, position.y)
  1460                         position = value["output"].GetRelPosition()
  1656                 elif isinstance(variable, plcopen.outVariable):
  1461                         variable.addConnectionPointOut()
  1657                     if value["input"].IsNegated():
  1462                         variable.connectionPointOut.setRelPosition(position.x, position.y)
  1658                         variable.setNegated(True)
  1463                     elif isinstance(variable, plcopen.outVariable):
  1659                     if value["input"].GetEdge() != "none":
  1464                         if value["input"].IsNegated():
  1660                         variable.setConnectorEdge(value["input"].GetEdge())
  1465                             variable.setNegated(True)
  1661                     position = value["input"].GetRelPosition()
  1466                         if value["input"].GetEdge() != "none":
  1662                     variable.addConnectionPointIn()
  1467                             variable.setConnectorEdge(value["input"].GetEdge())
  1663                     variable.connectionPointIn.setRelPosition(position.x, position.y)
  1468                         position = value["input"].GetRelPosition()
  1664                     self.SetConnectionWires(variable.connectionPointIn, value["input"])
  1469                         variable.addConnectionPointIn()
  1665                 elif isinstance(variable, plcopen.inOutVariable):
  1470                         variable.connectionPointIn.setRelPosition(position.x, position.y)
  1666                     if value["input"].IsNegated():
  1471                         self.SetConnectionWires(variable.connectionPointIn, value["input"])
  1667                         variable.setNegatedIn(True)
  1472                     elif isinstance(variable, plcopen.inOutVariable):
  1668                     if value["input"].GetEdge() != "none":
  1473                         if value["input"].IsNegated():
  1669                         variable.setInputEdge(value["input"].GetEdge())
  1474                             variable.setNegatedIn(True)
  1670                     if value["output"].IsNegated():
  1475                         if value["input"].GetEdge() != "none":
  1671                         variable.setNegatedOut(True)
  1476                             variable.setInputEdge(value["input"].GetEdge())
  1672                     if value["output"].GetEdge() != "none":
  1477                         if value["output"].IsNegated():
  1673                         variable.setOutputEdge(value["output"].GetEdge())
  1478                             variable.setNegatedOut(True)
  1674                     position = value["output"].GetRelPosition()
  1479                         if value["output"].GetEdge() != "none":
  1675                     variable.addConnectionPointOut()
  1480                             variable.setOutputEdge(value["output"].GetEdge())
  1676                     variable.connectionPointOut.setRelPosition(position.x, position.y)
  1481                         position = value["output"].GetRelPosition()
  1677                     position = value["input"].GetRelPosition()
  1482                         variable.addConnectionPointOut()
  1678                     variable.addConnectionPointIn()
  1483                         variable.connectionPointOut.setRelPosition(position.x, position.y)
  1679                     variable.connectionPointIn.setRelPosition(position.x, position.y)
  1484                         position = value["input"].GetRelPosition()
  1680                     self.SetConnectionWires(variable.connectionPointIn, value["input"])
  1485                         variable.addConnectionPointIn()
  1681 
  1486                         variable.connectionPointIn.setRelPosition(position.x, position.y)
  1682 
  1487                         self.SetConnectionWires(variable.connectionPointIn, value["input"])
  1683     def AddCurrentElementEditingConnection(self, id, type):
  1488 
  1684         if type == CONNECTOR:
  1489     def AddEditedElementConnection(self, tagname, id, type):
  1685             name = "connector"
  1490         element = self.GetEditedElement(tagname)
  1686             connection = plcopen.connector()
  1491         if element is not None:
  1687         elif type == CONTINUATION:
  1492             if type == CONNECTOR:
  1688             name = "continuation"
  1493                 name = "connector"
  1689             connection = plcopen.continuation()
  1494                 connection = plcopen.connector()
  1690         connection.setLocalId(id)
  1495             elif type == CONTINUATION:
  1691         self.GetCurrentElementEditing().addInstance(name, connection)
  1496                 name = "continuation"
       
  1497                 connection = plcopen.continuation()
       
  1498             connection.setLocalId(id)
       
  1499             element.addInstance(name, connection)
  1692         
  1500         
  1693     def SetCurrentElementEditingConnectionInfos(self, id, infos):
  1501     def SetEditedElementConnectionInfos(self, tagname, id, infos):
  1694         connection = self.GetCurrentElementEditing().getInstance(id)
  1502         element = self.GetEditedElement(tagname)
  1695         for param, value in infos.items():
  1503         if element is not None:
  1696             if param == "name":
  1504             connection = element.getInstance(id)
  1697                 connection.setName(value)    
  1505             for param, value in infos.items():
  1698             elif param == "height":
  1506                 if param == "name":
  1699                 connection.setHeight(value)
  1507                     connection.setName(value)    
  1700             elif param == "width":
  1508                 elif param == "height":
  1701                 connection.setWidth(value)
  1509                     connection.setHeight(value)
  1702             elif param == "x":
  1510                 elif param == "width":
  1703                 connection.setX(value)
  1511                     connection.setWidth(value)
  1704             elif param == "y":
  1512                 elif param == "x":
  1705                 connection.setY(value)
  1513                     connection.setX(value)
  1706             elif param == "connector":
  1514                 elif param == "y":
  1707                 position = value.GetRelPosition()
  1515                     connection.setY(value)
  1708                 if isinstance(connection, plcopen.continuation):
  1516                 elif param == "connector":
  1709                     connection.addConnectionPointOut()
  1517                     position = value.GetRelPosition()
  1710                     connection.connectionPointOut.setRelPosition(position.x, position.y)
  1518                     if isinstance(connection, plcopen.continuation):
  1711                 elif isinstance(connection, plcopen.connector):
  1519                         connection.addConnectionPointOut()
  1712                     connection.addConnectionPointIn()
  1520                         connection.connectionPointOut.setRelPosition(position.x, position.y)
  1713                     connection.connectionPointIn.setRelPosition(position.x, position.y)
  1521                     elif isinstance(connection, plcopen.connector):
  1714                     self.SetConnectionWires(connection.connectionPointIn, value)
  1522                         connection.addConnectionPointIn()
  1715 
  1523                         connection.connectionPointIn.setRelPosition(position.x, position.y)
  1716     def AddCurrentElementEditingComment(self, id):
  1524                         self.SetConnectionWires(connection.connectionPointIn, value)
  1717         comment = plcopen.comment()
  1525 
  1718         comment.setLocalId(id)
  1526     def AddEditedElementComment(self, tagname, id):
  1719         self.GetCurrentElementEditing().addInstance("comment", comment)
  1527         element = self.GetEditedElement(tagname)
  1720     
  1528         if element is not None:
  1721     def SetCurrentElementEditingCommentInfos(self, id, infos):
  1529             comment = plcopen.comment()
  1722         comment = self.GetCurrentElementEditing().getInstance(id)
  1530             comment.setLocalId(id)
  1723         for param, value in infos.items():
  1531             element.addInstance("comment", comment)
  1724             if param == "content":
  1532     
  1725                 comment.setContentText(value)
  1533     def SetEditedElementCommentInfos(self, tagname, id, infos):
  1726             elif param == "height":
  1534         element = self.GetEditedElement(tagname)
  1727                 comment.setHeight(value)
  1535         if element is not None:
  1728             elif param == "width":
  1536             comment = element.getInstance(id)
  1729                 comment.setWidth(value)
  1537             for param, value in infos.items():
  1730             elif param == "x":
  1538                 if param == "content":
  1731                 comment.setX(value)
  1539                     comment.setContentText(value)
  1732             elif param == "y":
  1540                 elif param == "height":
  1733                 comment.setY(value)
  1541                     comment.setHeight(value)
  1734 
  1542                 elif param == "width":
  1735     def AddCurrentElementEditingPowerRail(self, id, type):
  1543                     comment.setWidth(value)
  1736         if type == LEFTRAIL:
  1544                 elif param == "x":
  1737             name = "leftPowerRail"
  1545                     comment.setX(value)
  1738             powerrail = plcopen.leftPowerRail()
  1546                 elif param == "y":
  1739         elif type == RIGHTRAIL:
  1547                     comment.setY(value)
  1740             name = "rightPowerRail"
  1548 
  1741             powerrail = plcopen.rightPowerRail()
  1549     def AddEditedElementPowerRail(self, tagname, id, type):
  1742         powerrail.setLocalId(id)
  1550         element = self.GetEditedElement(tagname)
  1743         self.GetCurrentElementEditing().addInstance(name, powerrail)
  1551         if element is not None:
  1744     
  1552             if type == LEFTRAIL:
  1745     def SetCurrentElementEditingPowerRailInfos(self, id, infos):
  1553                 name = "leftPowerRail"
  1746         powerrail = self.GetCurrentElementEditing().getInstance(id)
  1554                 powerrail = plcopen.leftPowerRail()
  1747         for param, value in infos.items():
  1555             elif type == RIGHTRAIL:
  1748             if param == "height":
  1556                 name = "rightPowerRail"
  1749                 powerrail.setHeight(value)
  1557                 powerrail = plcopen.rightPowerRail()
  1750             elif param == "width":
  1558             powerrail.setLocalId(id)
  1751                 powerrail.setWidth(value)
  1559             element.addInstance(name, powerrail)
  1752             elif param == "x":
  1560     
  1753                 powerrail.setX(value)
  1561     def SetEditedElementPowerRailInfos(self, tagname, id, infos):
  1754             elif param == "y":
  1562         element = self.GetEditedElement(tagname)
  1755                 powerrail.setY(value)
  1563         if element is not None:
  1756             elif param == "connectors":
  1564             powerrail = element.getInstance(id)
  1757                 if isinstance(powerrail, plcopen.leftPowerRail):
  1565             for param, value in infos.items():
  1758                     powerrail.setConnectionPointOut([])
  1566                 if param == "height":
  1759                     for connector in value:
  1567                     powerrail.setHeight(value)
  1760                         position = connector.GetRelPosition()
  1568                 elif param == "width":
  1761                         connection = plcopen.leftPowerRail_connectionPointOut()
  1569                     powerrail.setWidth(value)
  1762                         connection.setRelPosition(position.x, position.y)
  1570                 elif param == "x":
  1763                         powerrail.connectionPointOut.append(connection)
  1571                     powerrail.setX(value)
  1764                 elif isinstance(powerrail, plcopen.rightPowerRail):
  1572                 elif param == "y":
  1765                     powerrail.setConnectionPointIn([])
  1573                     powerrail.setY(value)
  1766                     for connector in value:
  1574                 elif param == "connectors":
  1767                         position = connector.GetRelPosition()
  1575                     if isinstance(powerrail, plcopen.leftPowerRail):
  1768                         connection = plcopen.connectionPointIn()
  1576                         powerrail.setConnectionPointOut([])
  1769                         connection.setRelPosition(position.x, position.y)
  1577                         for connector in value:
  1770                         self.SetConnectionWires(connection, connector)
  1578                             position = connector.GetRelPosition()
  1771                         powerrail.connectionPointIn.append(connection)
  1579                             connection = plcopen.leftPowerRail_connectionPointOut()
  1772 
  1580                             connection.setRelPosition(position.x, position.y)
  1773     def AddCurrentElementEditingContact(self, id):
  1581                             powerrail.connectionPointOut.append(connection)
  1774         contact = plcopen.contact()
  1582                     elif isinstance(powerrail, plcopen.rightPowerRail):
  1775         contact.setLocalId(id)
  1583                         powerrail.setConnectionPointIn([])
  1776         self.GetCurrentElementEditing().addInstance("contact", contact)
  1584                         for connector in value:
  1777 
  1585                             position = connector.GetRelPosition()
  1778     def SetCurrentElementEditingContactInfos(self, id, infos):
  1586                             connection = plcopen.connectionPointIn()
  1779         contact = self.GetCurrentElementEditing().getInstance(id)
  1587                             connection.setRelPosition(position.x, position.y)
  1780         for param, value in infos.items():
  1588                             self.SetConnectionWires(connection, connector)
  1781             if param == "name":
  1589                             powerrail.connectionPointIn.append(connection)
  1782                 contact.setVariable(value)
  1590 
  1783             elif param == "type":
  1591     def AddEditedElementEditingContact(self, tagname, id):
  1784                 if value == CONTACT_NORMAL:
  1592         element = self.GetEditedElement(tagname)
  1785                     contact.setNegated(False)
  1593         if element is not None:
  1786                     contact.setContactEdge("none")
  1594             contact = plcopen.contact()
  1787                 elif value == CONTACT_REVERSE:
  1595             contact.setLocalId(id)
  1788                     contact.setNegated(True)
  1596             element.addInstance("contact", contact)
  1789                     contact.setContactEdge("none")
  1597 
  1790                 elif value == CONTACT_RISING:
  1598     def SetEditedElementContactInfos(self, tagname, id, infos):
  1791                     contact.setNegated(False)
  1599         element = self.GetEditedElement(tagname)
  1792                     contact.setContactEdge("rising")
  1600         if element is not None:
  1793                 elif value == CONTACT_FALLING:
  1601             contact = element.getInstance(id)
  1794                     contact.setNegated(False)
  1602             for param, value in infos.items():
  1795                     contact.setContactEdge("falling")
  1603                 if param == "name":
  1796             elif param == "height":
  1604                     contact.setVariable(value)
  1797                 contact.setHeight(value)
  1605                 elif param == "type":
  1798             elif param == "width":
  1606                     if value == CONTACT_NORMAL:
  1799                 contact.setWidth(value)
  1607                         contact.setNegated(False)
  1800             elif param == "x":
  1608                         contact.setContactEdge("none")
  1801                 contact.setX(value)
  1609                     elif value == CONTACT_REVERSE:
  1802             elif param == "y":
  1610                         contact.setNegated(True)
  1803                 contact.setY(value)
  1611                         contact.setContactEdge("none")
  1804             elif param == "connectors":
  1612                     elif value == CONTACT_RISING:
  1805                 input_connector = value["input"]
  1613                         contact.setNegated(False)
  1806                 position = input_connector.GetRelPosition()
  1614                         contact.setContactEdge("rising")
  1807                 contact.addConnectionPointIn()
  1615                     elif value == CONTACT_FALLING:
  1808                 contact.connectionPointIn.setRelPosition(position.x, position.y)
  1616                         contact.setNegated(False)
  1809                 self.SetConnectionWires(contact.connectionPointIn, input_connector)
  1617                         contact.setContactEdge("falling")
  1810                 output_connector = value["output"]
  1618                 elif param == "height":
  1811                 position = output_connector.GetRelPosition()
  1619                     contact.setHeight(value)
  1812                 contact.addConnectionPointOut()
  1620                 elif param == "width":
  1813                 contact.connectionPointOut.setRelPosition(position.x, position.y)
  1621                     contact.setWidth(value)
  1814 
  1622                 elif param == "x":
  1815     def AddCurrentElementEditingCoil(self, id):
  1623                     contact.setX(value)
  1816         coil = plcopen.coil()
  1624                 elif param == "y":
  1817         coil.setLocalId(id)
  1625                     contact.setY(value)
  1818         self.GetCurrentElementEditing().addInstance("coil", coil)
  1626                 elif param == "connectors":
  1819 
  1627                     input_connector = value["input"]
  1820     def SetCurrentElementEditingCoilInfos(self, id, infos):
       
  1821         coil = self.GetCurrentElementEditing().getInstance(id)
       
  1822         for param, value in infos.items():
       
  1823             if param == "name":
       
  1824                 coil.setVariable(value)
       
  1825             elif param == "type":
       
  1826                 if value == COIL_NORMAL:
       
  1827                     coil.setNegated(False)
       
  1828                     coil.setCoilStorage("none")
       
  1829                 elif value == COIL_REVERSE:
       
  1830                     coil.setNegated(True)
       
  1831                     coil.setCoilStorage("none")
       
  1832                 elif value == COIL_SET:
       
  1833                     coil.setNegated(False)
       
  1834                     coil.setCoilStorage("set")
       
  1835                 elif value == COIL_RESET:
       
  1836                     coil.setNegated(False)
       
  1837                     coil.setCoilStorage("reset")
       
  1838             elif param == "height":
       
  1839                 coil.setHeight(value)
       
  1840             elif param == "width":
       
  1841                 coil.setWidth(value)
       
  1842             elif param == "x":
       
  1843                 coil.setX(value)
       
  1844             elif param == "y":
       
  1845                 coil.setY(value)
       
  1846             elif param == "connectors":
       
  1847                 input_connector = value["input"]
       
  1848                 position = input_connector.GetRelPosition()
       
  1849                 coil.addConnectionPointIn()
       
  1850                 coil.connectionPointIn.setRelPosition(position.x, position.y)
       
  1851                 self.SetConnectionWires(coil.connectionPointIn, input_connector)
       
  1852                 output_connector = value["output"]
       
  1853                 position = output_connector.GetRelPosition()
       
  1854                 coil.addConnectionPointOut()
       
  1855                 coil.connectionPointOut.setRelPosition(position.x, position.y)
       
  1856 
       
  1857     def AddCurrentElementEditingStep(self, id):
       
  1858         step = plcopen.step()
       
  1859         step.setLocalId(id)
       
  1860         self.GetCurrentElementEditing().addInstance("step", step)
       
  1861     
       
  1862     def SetCurrentElementEditingStepInfos(self, id, infos):
       
  1863         step = self.GetCurrentElementEditing().getInstance(id)
       
  1864         for param, value in infos.items():
       
  1865             if param == "name":
       
  1866                 step.setName(value)
       
  1867             elif param == "initial":
       
  1868                 step.setInitialStep(value)
       
  1869             elif param == "height":
       
  1870                 step.setHeight(value)
       
  1871             elif param == "width":
       
  1872                 step.setWidth(value)
       
  1873             elif param == "x":
       
  1874                 step.setX(value)
       
  1875             elif param == "y":
       
  1876                 step.setY(value)
       
  1877             elif param == "connectors":
       
  1878                 input_connector = value["input"]
       
  1879                 if input_connector:
       
  1880                     position = input_connector.GetRelPosition()
  1628                     position = input_connector.GetRelPosition()
  1881                     step.addConnectionPointIn()
  1629                     contact.addConnectionPointIn()
  1882                     step.connectionPointIn.setRelPosition(position.x, position.y)
  1630                     contact.connectionPointIn.setRelPosition(position.x, position.y)
  1883                     self.SetConnectionWires(step.connectionPointIn, input_connector)
  1631                     self.SetConnectionWires(contact.connectionPointIn, input_connector)
  1884                 else:
  1632                     output_connector = value["output"]
  1885                     step.deleteConnectionPointIn()
       
  1886                 output_connector = value["output"]
       
  1887                 if output_connector:
       
  1888                     position = output_connector.GetRelPosition()
  1633                     position = output_connector.GetRelPosition()
  1889                     step.addConnectionPointOut()
  1634                     contact.addConnectionPointOut()
  1890                     step.connectionPointOut.setRelPosition(position.x, position.y)
  1635                     contact.connectionPointOut.setRelPosition(position.x, position.y)
  1891                 else:
  1636 
  1892                     step.deleteConnectionPointOut()
  1637     def AddEditedElementCoil(self, tagname, id):
  1893                 action_connector = value["action"]
  1638         element = self.GetEditedElement(tagname)
  1894                 if action_connector:
  1639         if element is not None:
  1895                     position = action_connector.GetRelPosition()
  1640             coil = plcopen.coil()
  1896                     step.addConnectionPointOutAction()
  1641             coil.setLocalId(id)
  1897                     step.connectionPointOutAction.setRelPosition(position.x, position.y)
  1642             element.addInstance("coil", coil)
  1898                 else:
  1643 
  1899                     step.deleteConnectionPointOutAction()
  1644     def SetEditedElementCoilInfos(self, tagname, id, infos):
  1900     
  1645         element = self.GetEditedElement(tagname)
  1901     def AddCurrentElementEditingTransition(self, id):
  1646         if element is not None:
  1902         transition = plcopen.transition()
  1647             coil = element.getInstance(id)
  1903         transition.setLocalId(id)
  1648             for param, value in infos.items():
  1904         self.GetCurrentElementEditing().addInstance("transition", transition)
  1649                 if param == "name":
  1905     
  1650                     coil.setVariable(value)
  1906     def SetCurrentElementEditingTransitionInfos(self, id, infos):
  1651                 elif param == "type":
  1907         transition = self.GetCurrentElementEditing().getInstance(id)
  1652                     if value == COIL_NORMAL:
  1908         for param, value in infos.items():
  1653                         coil.setNegated(False)
  1909             if param == "type" and value != "connection":
  1654                         coil.setCoilStorage("none")
  1910                 transition.setConditionContent(value, infos["condition"])
  1655                     elif value == COIL_REVERSE:
  1911             elif param == "height":
  1656                         coil.setNegated(True)
  1912                 transition.setHeight(value)
  1657                         coil.setCoilStorage("none")
  1913             elif param == "width":
  1658                     elif value == COIL_SET:
  1914                 transition.setWidth(value)
  1659                         coil.setNegated(False)
  1915             elif param == "x":
  1660                         coil.setCoilStorage("set")
  1916                 transition.setX(value)
  1661                     elif value == COIL_RESET:
  1917             elif param == "y":
  1662                         coil.setNegated(False)
  1918                 transition.setY(value)
  1663                         coil.setCoilStorage("reset")
  1919             elif param == "priority":
  1664                 elif param == "height":
  1920                 if value != 0:
  1665                     coil.setHeight(value)
  1921                     transition.setPriority(value)
  1666                 elif param == "width":
  1922                 else:
  1667                     coil.setWidth(value)
  1923                     transition.setPriority(None)
  1668                 elif param == "x":
  1924             elif param == "connectors":
  1669                     coil.setX(value)
  1925                 input_connector = value["input"]
  1670                 elif param == "y":
  1926                 position = input_connector.GetRelPosition()
  1671                     coil.setY(value)
  1927                 transition.addConnectionPointIn()
  1672                 elif param == "connectors":
  1928                 transition.connectionPointIn.setRelPosition(position.x, position.y)
  1673                     input_connector = value["input"]
  1929                 self.SetConnectionWires(transition.connectionPointIn, input_connector)
  1674                     position = input_connector.GetRelPosition()
  1930                 output_connector = value["output"]
  1675                     coil.addConnectionPointIn()
  1931                 position = output_connector.GetRelPosition()
  1676                     coil.connectionPointIn.setRelPosition(position.x, position.y)
  1932                 transition.addConnectionPointOut()
  1677                     self.SetConnectionWires(coil.connectionPointIn, input_connector)
  1933                 transition.connectionPointOut.setRelPosition(position.x, position.y)
  1678                     output_connector = value["output"]
  1934                 if infos.get("type", None) == "connection":
  1679                     position = output_connector.GetRelPosition()
  1935                     transition.setConditionContent("connection", None)
  1680                     coil.addConnectionPointOut()
  1936                     connection_connector = value["connection"]
  1681                     coil.connectionPointOut.setRelPosition(position.x, position.y)
  1937                     self.SetConnectionWires(transition, connection_connector)
  1682 
  1938     
  1683     def AddEditedElementStep(self, tagname, id):
  1939     def AddCurrentElementEditingDivergence(self, id, type):
  1684         element = self.GetEditedElement(tagname)
  1940         if type == SELECTION_DIVERGENCE:
  1685         if element is not None:
  1941             name = "selectionDivergence"
  1686             step = plcopen.step()
  1942             divergence = plcopen.selectionDivergence()
  1687             step.setLocalId(id)
  1943         elif type == SELECTION_CONVERGENCE:
  1688             element.addInstance("step", step)
  1944             name = "selectionConvergence"
  1689     
  1945             divergence = plcopen.selectionConvergence()
  1690     def SetEditedElementStepInfos(self, tagname, id, infos):
  1946         elif type == SIMULTANEOUS_DIVERGENCE:
  1691         element = self.GetEditedElement(tagname)
  1947             name = "simultaneousDivergence"
  1692         if element is not None:
  1948             divergence = plcopen.simultaneousDivergence()
  1693             step = element.getInstance(id)
  1949         elif type == SIMULTANEOUS_CONVERGENCE:
  1694             for param, value in infos.items():
  1950             name = "simultaneousConvergence"
  1695                 if param == "name":
  1951             divergence = plcopen.simultaneousConvergence()
  1696                     step.setName(value)
  1952         divergence.setLocalId(id)
  1697                 elif param == "initial":
  1953         self.GetCurrentElementEditing().addInstance(name, divergence)
  1698                     step.setInitialStep(value)
  1954     
  1699                 elif param == "height":
  1955     def SetCurrentElementEditingDivergenceInfos(self, id, infos):
  1700                     step.setHeight(value)
  1956         divergence = self.GetCurrentElementEditing().getInstance(id)
  1701                 elif param == "width":
  1957         for param, value in infos.items():
  1702                     step.setWidth(value)
  1958             if param == "height":
  1703                 elif param == "x":
  1959                 divergence.setHeight(value)
  1704                     step.setX(value)
  1960             elif param == "width":
  1705                 elif param == "y":
  1961                 divergence.setWidth(value)
  1706                     step.setY(value)
  1962             elif param == "x":
  1707                 elif param == "connectors":
  1963                 divergence.setX(value)
  1708                     input_connector = value["input"]
  1964             elif param == "y":
  1709                     if input_connector:
  1965                 divergence.setY(value)
       
  1966             elif param == "connectors":
       
  1967                 input_connectors = value["inputs"]
       
  1968                 if isinstance(divergence, (plcopen.selectionDivergence, plcopen.simultaneousDivergence)):
       
  1969                     position = input_connectors[0].GetRelPosition()
       
  1970                     divergence.addConnectionPointIn()
       
  1971                     divergence.connectionPointIn.setRelPosition(position.x, position.y)
       
  1972                     self.SetConnectionWires(divergence.connectionPointIn, input_connectors[0])
       
  1973                 else:
       
  1974                     divergence.setConnectionPointIn([])
       
  1975                     for input_connector in input_connectors:
       
  1976                         position = input_connector.GetRelPosition()
  1710                         position = input_connector.GetRelPosition()
  1977                         if isinstance(divergence, plcopen.selectionConvergence):
  1711                         step.addConnectionPointIn()
  1978                             connection = plcopen.selectionConvergence_connectionPointIn()
  1712                         step.connectionPointIn.setRelPosition(position.x, position.y)
  1979                         else:
  1713                         self.SetConnectionWires(step.connectionPointIn, input_connector)
  1980                             connection = plcopen.connectionPointIn()
  1714                     else:
  1981                         connection.setRelPosition(position.x, position.y)
  1715                         step.deleteConnectionPointIn()
  1982                         self.SetConnectionWires(connection, input_connector)
  1716                     output_connector = value["output"]
  1983                         divergence.appendConnectionPointIn(connection)
  1717                     if output_connector:
  1984                 output_connectors = value["outputs"]
       
  1985                 if isinstance(divergence, (plcopen.selectionConvergence, plcopen.simultaneousConvergence)):
       
  1986                     position = output_connectors[0].GetRelPosition()
       
  1987                     divergence.addConnectionPointOut()
       
  1988                     divergence.connectionPointOut.setRelPosition(position.x, position.y)
       
  1989                 else:
       
  1990                     divergence.setConnectionPointOut([])
       
  1991                     for output_connector in output_connectors:
       
  1992                         position = output_connector.GetRelPosition()
  1718                         position = output_connector.GetRelPosition()
  1993                         if isinstance(divergence, plcopen.selectionDivergence):
  1719                         step.addConnectionPointOut()
  1994                             connection = plcopen.selectionDivergence_connectionPointOut()
  1720                         step.connectionPointOut.setRelPosition(position.x, position.y)
  1995                         else:
  1721                     else:
  1996                             connection = plcopen.simultaneousDivergence_connectionPointOut()
  1722                         step.deleteConnectionPointOut()
  1997                         connection.setRelPosition(position.x, position.y)
  1723                     action_connector = value["action"]
  1998                         divergence.appendConnectionPointOut(connection)
  1724                     if action_connector:
  1999     
  1725                         position = action_connector.GetRelPosition()
  2000     def AddCurrentElementEditingJump(self, id):
  1726                         step.addConnectionPointOutAction()
  2001         jump = plcopen.jumpStep()
  1727                         step.connectionPointOutAction.setRelPosition(position.x, position.y)
  2002         jump.setLocalId(id)
  1728                     else:
  2003         self.GetCurrentElementEditing().addInstance("jumpStep", jump)
  1729                         step.deleteConnectionPointOutAction()
  2004     
  1730     
  2005     def SetCurrentElementEditingJumpInfos(self, id, infos):
  1731     def AddEditedElementTransition(self, tagname, id):
  2006         jump = self.GetCurrentElementEditing().getInstance(id)
  1732         element = self.GetEditedElement(tagname)
  2007         for param, value in infos.items():
  1733         if element is not None:
  2008             if param == "target":
  1734             transition = plcopen.transition()
  2009                 jump.setTargetName(value)
  1735             transition.setLocalId(id)
  2010             elif param == "height":
  1736             element.addInstance("transition", transition)
  2011                 jump.setHeight(value)
  1737     
  2012             elif param == "width":
  1738     def SetEditedElementTransitionInfos(self, tagname, id, infos):
  2013                 jump.setWidth(value)
  1739         element = self.GetEditedElement(tagname)
  2014             elif param == "x":
  1740         if element is not None:
  2015                 jump.setX(value)
  1741             transition = element.getInstance(id)
  2016             elif param == "y":
  1742             for param, value in infos.items():
  2017                 jump.setY(value)
  1743                 if param == "type" and value != "connection":
  2018             elif param == "connector":
  1744                     transition.setConditionContent(value, infos["condition"])
  2019                 position = value.GetRelPosition()
  1745                 elif param == "height":
  2020                 jump.addConnectionPointIn()
  1746                     transition.setHeight(value)
  2021                 jump.connectionPointIn.setRelPosition(position.x, position.y)
  1747                 elif param == "width":
  2022                 self.SetConnectionWires(jump.connectionPointIn, value)
  1748                     transition.setWidth(value)
       
  1749                 elif param == "x":
       
  1750                     transition.setX(value)
       
  1751                 elif param == "y":
       
  1752                     transition.setY(value)
       
  1753                 elif param == "priority":
       
  1754                     if value != 0:
       
  1755                         transition.setPriority(value)
       
  1756                     else:
       
  1757                         transition.setPriority(None)
       
  1758                 elif param == "connectors":
       
  1759                     input_connector = value["input"]
       
  1760                     position = input_connector.GetRelPosition()
       
  1761                     transition.addConnectionPointIn()
       
  1762                     transition.connectionPointIn.setRelPosition(position.x, position.y)
       
  1763                     self.SetConnectionWires(transition.connectionPointIn, input_connector)
       
  1764                     output_connector = value["output"]
       
  1765                     position = output_connector.GetRelPosition()
       
  1766                     transition.addConnectionPointOut()
       
  1767                     transition.connectionPointOut.setRelPosition(position.x, position.y)
       
  1768                     if infos.get("type", None) == "connection":
       
  1769                         transition.setConditionContent("connection", None)
       
  1770                         connection_connector = value["connection"]
       
  1771                         self.SetConnectionWires(transition, connection_connector)
       
  1772     
       
  1773     def AddEditedElementDivergence(self, tagname, id, type):
       
  1774         element = self.GetEditedElement(tagname)
       
  1775         if element is not None:
       
  1776             if type == SELECTION_DIVERGENCE:
       
  1777                 name = "selectionDivergence"
       
  1778                 divergence = plcopen.selectionDivergence()
       
  1779             elif type == SELECTION_CONVERGENCE:
       
  1780                 name = "selectionConvergence"
       
  1781                 divergence = plcopen.selectionConvergence()
       
  1782             elif type == SIMULTANEOUS_DIVERGENCE:
       
  1783                 name = "simultaneousDivergence"
       
  1784                 divergence = plcopen.simultaneousDivergence()
       
  1785             elif type == SIMULTANEOUS_CONVERGENCE:
       
  1786                 name = "simultaneousConvergence"
       
  1787                 divergence = plcopen.simultaneousConvergence()
       
  1788             divergence.setLocalId(id)
       
  1789             element.addInstance(name, divergence)
       
  1790     
       
  1791     def SetEditedElementDivergenceInfos(self, tagname, id, infos):
       
  1792         element = self.GetEditedElement(tagname)
       
  1793         if element is not None:
       
  1794             divergence = element.getInstance(id)
       
  1795             for param, value in infos.items():
       
  1796                 if param == "height":
       
  1797                     divergence.setHeight(value)
       
  1798                 elif param == "width":
       
  1799                     divergence.setWidth(value)
       
  1800                 elif param == "x":
       
  1801                     divergence.setX(value)
       
  1802                 elif param == "y":
       
  1803                     divergence.setY(value)
       
  1804                 elif param == "connectors":
       
  1805                     input_connectors = value["inputs"]
       
  1806                     if isinstance(divergence, (plcopen.selectionDivergence, plcopen.simultaneousDivergence)):
       
  1807                         position = input_connectors[0].GetRelPosition()
       
  1808                         divergence.addConnectionPointIn()
       
  1809                         divergence.connectionPointIn.setRelPosition(position.x, position.y)
       
  1810                         self.SetConnectionWires(divergence.connectionPointIn, input_connectors[0])
       
  1811                     else:
       
  1812                         divergence.setConnectionPointIn([])
       
  1813                         for input_connector in input_connectors:
       
  1814                             position = input_connector.GetRelPosition()
       
  1815                             if isinstance(divergence, plcopen.selectionConvergence):
       
  1816                                 connection = plcopen.selectionConvergence_connectionPointIn()
       
  1817                             else:
       
  1818                                 connection = plcopen.connectionPointIn()
       
  1819                             connection.setRelPosition(position.x, position.y)
       
  1820                             self.SetConnectionWires(connection, input_connector)
       
  1821                             divergence.appendConnectionPointIn(connection)
       
  1822                     output_connectors = value["outputs"]
       
  1823                     if isinstance(divergence, (plcopen.selectionConvergence, plcopen.simultaneousConvergence)):
       
  1824                         position = output_connectors[0].GetRelPosition()
       
  1825                         divergence.addConnectionPointOut()
       
  1826                         divergence.connectionPointOut.setRelPosition(position.x, position.y)
       
  1827                     else:
       
  1828                         divergence.setConnectionPointOut([])
       
  1829                         for output_connector in output_connectors:
       
  1830                             position = output_connector.GetRelPosition()
       
  1831                             if isinstance(divergence, plcopen.selectionDivergence):
       
  1832                                 connection = plcopen.selectionDivergence_connectionPointOut()
       
  1833                             else:
       
  1834                                 connection = plcopen.simultaneousDivergence_connectionPointOut()
       
  1835                             connection.setRelPosition(position.x, position.y)
       
  1836                             divergence.appendConnectionPointOut(connection)
       
  1837     
       
  1838     def AddEditedElementJump(self, tagname, id):
       
  1839         element = self.GetEditedElement(tagname)
       
  1840         if element is not None:
       
  1841             jump = plcopen.jumpStep()
       
  1842             jump.setLocalId(id)
       
  1843             element.addInstance("jumpStep", jump)
       
  1844     
       
  1845     def SetEditedElementJumpInfos(self, tagname, id, infos):
       
  1846         element = self.GetEditedElement(tagname)
       
  1847         if element is not None:
       
  1848             jump = element.getInstance(id)
       
  1849             for param, value in infos.items():
       
  1850                 if param == "target":
       
  1851                     jump.setTargetName(value)
       
  1852                 elif param == "height":
       
  1853                     jump.setHeight(value)
       
  1854                 elif param == "width":
       
  1855                     jump.setWidth(value)
       
  1856                 elif param == "x":
       
  1857                     jump.setX(value)
       
  1858                 elif param == "y":
       
  1859                     jump.setY(value)
       
  1860                 elif param == "connector":
       
  1861                     position = value.GetRelPosition()
       
  1862                     jump.addConnectionPointIn()
       
  1863                     jump.connectionPointIn.setRelPosition(position.x, position.y)
       
  1864                     self.SetConnectionWires(jump.connectionPointIn, value)
  2023  
  1865  
  2024     def AddCurrentElementEditingActionBlock(self, id):
  1866     def AddEditedElementActionBlock(self, tagname, id):
  2025         actionBlock = plcopen.actionBlock()
  1867         element = self.GetEditedElement(tagname)
  2026         actionBlock.setLocalId(id)
  1868         if element is not None:
  2027         self.GetCurrentElementEditing().addInstance("actionBlock", actionBlock)
  1869             actionBlock = plcopen.actionBlock()
  2028     
  1870             actionBlock.setLocalId(id)
  2029     def SetCurrentElementEditingActionBlockInfos(self, id, infos):
  1871             element.addInstance("actionBlock", actionBlock)
  2030         actionBlock = self.GetCurrentElementEditing().getInstance(id)
  1872     
  2031         for param, value in infos.items():
  1873     def SetEditedElementActionBlockInfos(self, tagname, id, infos):
  2032             if param == "actions":
  1874         element = self.GetEditedElement(tagname)
  2033                 actionBlock.setActions(value)
  1875         if element is not None:
  2034             elif param == "height":
  1876             actionBlock = element.getInstance(id)
  2035                 actionBlock.setHeight(value)
  1877             for param, value in infos.items():
  2036             elif param == "width":
  1878                 if param == "actions":
  2037                 actionBlock.setWidth(value)
  1879                     actionBlock.setActions(value)
  2038             elif param == "x":
  1880                 elif param == "height":
  2039                 actionBlock.setX(value)
  1881                     actionBlock.setHeight(value)
  2040             elif param == "y":
  1882                 elif param == "width":
  2041                 actionBlock.setY(value)
  1883                     actionBlock.setWidth(value)
  2042             elif param == "connector":
  1884                 elif param == "x":
  2043                 position = value.GetRelPosition()
  1885                     actionBlock.setX(value)
  2044                 actionBlock.addConnectionPointIn()
  1886                 elif param == "y":
  2045                 actionBlock.connectionPointIn.setRelPosition(position.x, position.y)
  1887                     actionBlock.setY(value)
  2046                 self.SetConnectionWires(actionBlock.connectionPointIn, value)
  1888                 elif param == "connector":
  2047     
  1889                     position = value.GetRelPosition()
  2048     def RemoveCurrentElementEditingInstance(self, id):
  1890                     actionBlock.addConnectionPointIn()
  2049         element = self.GetCurrentElementEditing()
  1891                     actionBlock.connectionPointIn.setRelPosition(position.x, position.y)
  2050         instance = element.getInstance(id)
  1892                     self.SetConnectionWires(actionBlock.connectionPointIn, value)
  2051         if isinstance(instance, plcopen.block):
  1893     
  2052             blocktype = instance.getTypeName()
  1894     def RemoveEditedElementInstance(self, tagname, id):
  2053             if self.CurrentElementEditing != None:
  1895         element = self.GetEditedElement(tagname)
  2054                 name = self.ElementsOpened[self.CurrentElementEditing]
  1896         if element is not None:
  2055                 words = name.split("::")
  1897             instance = element.getInstance(id)
  2056                 if words[0] in ["P","T","A"]:
  1898             if isinstance(instance, plcopen.block):
  2057                     pou = self.Project.getPou(words[1])
  1899                 blocktype = instance.getTypeName()
  2058                     pou.removePouVar(blocktype, instance.getInstanceName())    
  1900                 element.removePouVar(blocktype, instance.getInstanceName())    
  2059         element.removeInstance(id)
  1901             element.removeInstance(id)
  2060         self.RefreshPouUsingTree()
  1902             self.RefreshPouUsingTree()
  2061 
  1903 
  2062     def GetCurrentResourceEditingVariables(self):
  1904     def GetEditedResourceVariables(self, tagname):
  2063         varlist = []
  1905         varlist = []
  2064         name = self.ElementsOpened[self.CurrentElementEditing]
  1906         words = tagname.split("::")
  2065         words = name.split("::")
       
  2066         for var in self.GetConfigurationGlobalVars(words[1]):
  1907         for var in self.GetConfigurationGlobalVars(words[1]):
  2067             if var["Type"] == "BOOL":
  1908             if var["Type"] == "BOOL":
  2068                 varlist.append(var["Name"])
  1909                 varlist.append(var["Name"])
  2069         for var in self.GetConfigurationResourceGlobalVars(words[1], words[2]):
  1910         for var in self.GetConfigurationResourceGlobalVars(words[1], words[2]):
  2070             if var["Type"] == "BOOL":
  1911             if var["Type"] == "BOOL":
  2071                 varlist.append(var["Name"])
  1912                 varlist.append(var["Name"])
  2072         return varlist
  1913         return varlist
  2073 
  1914 
  2074     def SetCurrentResourceEditingInfos(self, tasks, instances):
  1915     def SetEditedResourceInfos(self, tasks, instances):
  2075         resource = self.GetCurrentElementEditing()
  1916         resource = self.GetEditedElement(tagname)
  2076         resource.setTask([])
  1917         if resource is not None:
  2077         resource.setPouInstance([])
  1918             resource.setTask([])
  2078         task_list = {}
  1919             resource.setPouInstance([])
  2079         for task in tasks:
  1920             task_list = {}
  2080             new_task = plcopen.resource_task()
  1921             for task in tasks:
  2081             new_task.setName(task["Name"])
  1922                 new_task = plcopen.resource_task()
  2082             if task["Single"] != "":
  1923                 new_task.setName(task["Name"])
  2083                 new_task.setSingle(task["Single"])
  1924                 if task["Single"] != "":
  2084             result = duration_model.match(task["Interval"]).groups()
  1925                     new_task.setSingle(task["Single"])
  2085             if reduce(lambda x, y: x or y != None, result):
  1926                 result = duration_model.match(task["Interval"]).groups()
  2086                 values = []
  1927                 if reduce(lambda x, y: x or y != None, result):
  2087                 for value in result[:-1]:
  1928                     values = []
  2088                     if value != None:
  1929                     for value in result[:-1]:
  2089                         values.append(int(value))
  1930                         if value != None:
  2090                     else:
  1931                             values.append(int(value))
  2091                         values.append(0)
  1932                         else:
  2092                 values.append(int(float(result[-1]) * 1000))
  1933                             values.append(0)
  2093                 new_task.setInterval(time(*values))
  1934                     values.append(int(float(result[-1]) * 1000))
  2094             new_task.priority.setValue(int(task["Priority"]))
  1935                     new_task.setInterval(time(*values))
  2095             if task["Name"] != "":
  1936                 new_task.priority.setValue(int(task["Priority"]))
  2096                 task_list[task["Name"]] = new_task
  1937                 if task["Name"] != "":
  2097             resource.appendTask(new_task)
  1938                     task_list[task["Name"]] = new_task
  2098         for instance in instances:
  1939                 resource.appendTask(new_task)
  2099             new_instance = plcopen.pouInstance()
  1940             for instance in instances:
  2100             new_instance.setName(instance["Name"])
  1941                 new_instance = plcopen.pouInstance()
  2101             new_instance.setType(instance["Type"])
  1942                 new_instance.setName(instance["Name"])
  2102             if instance["Task"] != "":
  1943                 new_instance.setType(instance["Type"])
  2103                 task_list[instance["Task"]].appendPouInstance(new_instance)
  1944                 if instance["Task"] != "":
  2104             else:
  1945                     task_list[instance["Task"]].appendPouInstance(new_instance)
  2105                 resource.appendPouInstance(new_instance)
  1946                 else:
  2106 
  1947                     resource.appendPouInstance(new_instance)
  2107     def GetCurrentResourceEditingInfos(self):
  1948 
  2108         resource = self.GetCurrentElementEditing()
  1949     def GetEditedResourceInfos(self, tagname):
  2109         tasks = resource.getTask()
  1950         resource = self.GetEditedElement(tagname)
  2110         instances = resource.getPouInstance()
  1951         if resource is not None:
  2111         tasks_data = []
  1952             tasks = resource.getTask()
  2112         instances_data = []
  1953             instances = resource.getPouInstance()
  2113         for task in tasks:
  1954             tasks_data = []
  2114             new_task = {}
  1955             instances_data = []
  2115             new_task["Name"] = task.getName()
  1956             for task in tasks:
  2116             single = task.getSingle()
  1957                 new_task = {}
  2117             if single:
  1958                 new_task["Name"] = task.getName()
  2118                 new_task["Single"] = single
  1959                 single = task.getSingle()
  2119             else:
  1960                 if single:
  2120                 new_task["Single"] = ""
  1961                     new_task["Single"] = single
  2121             interval = task.getInterval()
  1962                 else:
  2122             if interval:
  1963                     new_task["Single"] = ""
  2123                 text = ""
  1964                 interval = task.getInterval()
  2124                 if interval.hour != 0:
  1965                 if interval:
  2125                     text += "%dh"%interval.hour
  1966                     text = ""
  2126                 if interval.minute != 0:
  1967                     if interval.hour != 0:
  2127                     text += "%dm"%interval.minute
  1968                         text += "%dh"%interval.hour
  2128                 if interval.second != 0:
  1969                     if interval.minute != 0:
  2129                     text += "%ds"%interval.second
  1970                         text += "%dm"%interval.minute
  2130                 if interval.microsecond != 0:
  1971                     if interval.second != 0:
  2131                     if interval.microsecond % 1000 != 0:
  1972                         text += "%ds"%interval.second
  2132                         text += "%.3fms"%(float(interval.microsecond) / 1000)
  1973                     if interval.microsecond != 0:
  2133                     else:
  1974                         if interval.microsecond % 1000 != 0:
  2134                         text += "%dms"%(interval.microsecond / 1000)
  1975                             text += "%.3fms"%(float(interval.microsecond) / 1000)
  2135                 new_task["Interval"] = text
  1976                         else:
  2136             else:
  1977                             text += "%dms"%(interval.microsecond / 1000)
  2137                 new_task["Interval"] = ""
  1978                     new_task["Interval"] = text
  2138             new_task["Priority"] = str(task.priority.getValue())
  1979                 else:
  2139             tasks_data.append(new_task)
  1980                     new_task["Interval"] = ""
  2140             for instance in task.getPouInstance():
  1981                 new_task["Priority"] = str(task.priority.getValue())
       
  1982                 tasks_data.append(new_task)
       
  1983                 for instance in task.getPouInstance():
       
  1984                     new_instance = {}
       
  1985                     new_instance["Name"] = instance.getName()
       
  1986                     new_instance["Type"] = instance.getType()
       
  1987                     new_instance["Task"] = task.getName()
       
  1988                     instances_data.append(new_instance)
       
  1989             for instance in instances:
  2141                 new_instance = {}
  1990                 new_instance = {}
  2142                 new_instance["Name"] = instance.getName()
  1991                 new_instance["Name"] = instance.getName()
  2143                 new_instance["Type"] = instance.getType()
  1992                 new_instance["Type"] = instance.getType()
  2144                 new_instance["Task"] = task.getName()
  1993                 new_instance["Task"] = ""
  2145                 instances_data.append(new_instance)
  1994                 instances_data.append(new_instance)
  2146         for instance in instances:
  1995             return tasks_data, instances_data
  2147             new_instance = {}
       
  2148             new_instance["Name"] = instance.getName()
       
  2149             new_instance["Type"] = instance.getType()
       
  2150             new_instance["Task"] = ""
       
  2151             instances_data.append(new_instance)
       
  2152         return tasks_data, instances_data
       
  2153 
  1996 
  2154     def OpenXMLFile(self, filepath):
  1997     def OpenXMLFile(self, filepath):
  2155         if self.VerifyXML:
  1998         if self.VerifyXML:
  2156             if sys:
  1999             if sys:
  2157                 sys.stdout = HolePseudoFile()
  2000                 sys.stdout = HolePseudoFile()