objdictgen/nodemanager.py
changeset 205 dac0f9b4e3f8
parent 188 00245bc2e6fe
child 220 b7fb826c66d9
equal deleted inserted replaced
204:44ce74232ccb 205:dac0f9b4e3f8
    33 
    33 
    34 UndoBufferLength = 20
    34 UndoBufferLength = 20
    35 
    35 
    36 type_model = re.compile('([\_A-Z]*)([0-9]*)')
    36 type_model = re.compile('([\_A-Z]*)([0-9]*)')
    37 range_model = re.compile('([\_A-Z]*)([0-9]*)\[([\-0-9]*)-([\-0-9]*)\]')
    37 range_model = re.compile('([\_A-Z]*)([0-9]*)\[([\-0-9]*)-([\-0-9]*)\]')
    38 name_model = re.compile('(.*)\[(.*)\]')
    38 
    39 
    39 # ID for the file viewed
    40 def IsOfType(object, typedef):
    40 CurrentID = 0
    41     return type(object) == typedef
    41 
    42 
    42 # Returns a new id
    43 #-------------------------------------------------------------------------------
    43 def GetNewId():
    44 #                           Formating Name of an Entry
    44     global CurrentID
    45 #-------------------------------------------------------------------------------
    45     CurrentID += 1
    46 
    46     return CurrentID
    47 """
       
    48 Format the text given with the index and subindex defined
       
    49 """
       
    50 def StringFormat(text, idx, sub):
       
    51     result = name_model.match(text)
       
    52     if result:
       
    53         format = result.groups()
       
    54         return format[0]%eval(format[1])
       
    55     else:
       
    56         return text
       
    57 
       
    58 #-------------------------------------------------------------------------------
       
    59 #                         Search in a Mapping Dictionary
       
    60 #-------------------------------------------------------------------------------
       
    61 
       
    62 """
       
    63 Return the index of the informations in the Object Dictionary in case of identical
       
    64 indexes
       
    65 """
       
    66 def FindIndex(index, mappingdictionary):
       
    67     if index in mappingdictionary:
       
    68         return index
       
    69     else:
       
    70         listpluri = [idx for idx in mappingdictionary.keys() if mappingdictionary[idx]["struct"] & OD_IdenticalIndexes]
       
    71         listpluri.sort()
       
    72         for idx in listpluri:
       
    73             nb_max = mappingdictionary[idx]["nbmax"]
       
    74             incr = mappingdictionary[idx]["incr"]
       
    75             if idx < index < idx + incr * nb_max and (index - idx)%incr == 0:
       
    76                 return idx
       
    77     return None
       
    78 
       
    79 """
       
    80 Return the index of the typename given by searching in mappingdictionary 
       
    81 """
       
    82 def FindTypeIndex(typename, mappingdictionary):
       
    83     testdic = {}
       
    84     for index, values in mappingdictionary.iteritems():
       
    85         if index < 0x1000:
       
    86             testdic[values["name"]] = index
       
    87     if typename in testdic:
       
    88         return testdic[typename]
       
    89     return None
       
    90 
       
    91 """
       
    92 Return the name of the type by searching in mappingdictionary 
       
    93 """
       
    94 def FindTypeName(typeindex, mappingdictionary):
       
    95     if typeindex < 0x1000 and typeindex in mappingdictionary:
       
    96         return mappingdictionary[typeindex]["name"]
       
    97     return None
       
    98 
       
    99 """
       
   100 Return the default value of the type by searching in mappingdictionary 
       
   101 """
       
   102 def FindTypeDefaultValue(typeindex, mappingdictionary):
       
   103     if typeindex < 0x1000 and typeindex in mappingdictionary:
       
   104         return mappingdictionary[typeindex]["default"]
       
   105     return None
       
   106 
       
   107 """
       
   108 Return the list of types defined in mappingdictionary 
       
   109 """
       
   110 def FindTypeList(mappingdictionary):
       
   111     list = []
       
   112     for index in mappingdictionary.keys():
       
   113         if index < 0x1000:
       
   114             list.append((index, mappingdictionary[index]["name"]))
       
   115     return list
       
   116 
       
   117 """
       
   118 Return the name of an entry by searching in mappingdictionary 
       
   119 """
       
   120 def FindEntryName(index, mappingdictionary):
       
   121     base_index = FindIndex(index, mappingdictionary)
       
   122     if base_index:
       
   123         infos = mappingdictionary[base_index]
       
   124         if infos["struct"] & OD_IdenticalIndexes:
       
   125             return StringFormat(infos["name"], (index - base_index) / infos["incr"] + 1, 0)
       
   126         else:
       
   127             return infos["name"]
       
   128     return None
       
   129 
       
   130 """
       
   131 Return the informations of one entry by searching in mappingdictionary 
       
   132 """
       
   133 def FindEntryInfos(index, mappingdictionary):
       
   134     base_index = FindIndex(index, mappingdictionary)
       
   135     if base_index:
       
   136         copy = mappingdictionary[base_index].copy()
       
   137         if copy["struct"] & OD_IdenticalIndexes:
       
   138             copy["name"] = StringFormat(copy["name"], (index - base_index) / copy["incr"] + 1, 0)
       
   139         copy.pop("values")
       
   140         return copy
       
   141     return None
       
   142 
       
   143 """
       
   144 Return the informations of one subentry of an entry by searching in mappingdictionary 
       
   145 """
       
   146 def FindSubentryInfos(index, subIndex, mappingdictionary):
       
   147     base_index = FindIndex(index, mappingdictionary)
       
   148     if base_index:
       
   149         struct = mappingdictionary[base_index]["struct"]
       
   150         if struct & OD_Subindex:
       
   151             if struct & OD_IdenticalSubindexes:
       
   152                 if struct & OD_IdenticalIndexes:
       
   153                     incr = mappingdictionary[base_index]["incr"]
       
   154                 else:
       
   155                     incr = 1
       
   156                 if subIndex == 0:
       
   157                     return mappingdictionary[base_index]["values"][0].copy()
       
   158                 elif 0 < subIndex <= mappingdictionary[base_index]["values"][1]["nbmax"]:
       
   159                     copy = mappingdictionary[base_index]["values"][1].copy()
       
   160                     copy["name"] = StringFormat(copy["name"], (index - base_index) / incr + 1, subIndex)
       
   161                     return copy
       
   162             elif struct & OD_MultipleSubindexes and 0 <= subIndex < len(mappingdictionary[base_index]["values"]):
       
   163                 return mappingdictionary[base_index]["values"][subIndex].copy()
       
   164             elif subIndex == 0:
       
   165                 return mappingdictionary[base_index]["values"][0].copy()
       
   166     return None
       
   167 
       
   168 """
       
   169 Return the list of variables that can be mapped defined in mappingdictionary 
       
   170 """
       
   171 def FindMapVariableList(mappingdictionary, Manager):
       
   172     list = []
       
   173     for index in mappingdictionary.iterkeys():
       
   174         if Manager.IsCurrentEntry(index):
       
   175             for subIndex, values in enumerate(mappingdictionary[index]["values"]):
       
   176                 if mappingdictionary[index]["values"][subIndex]["pdo"]:
       
   177                     infos = Manager.GetEntryInfos(mappingdictionary[index]["values"][subIndex]["type"])
       
   178                     if mappingdictionary[index]["struct"] & OD_IdenticalSubindexes:
       
   179                         values = Manager.GetCurrentEntry(index)
       
   180                         for i in xrange(len(values) - 1):
       
   181                             list.append((index, i + 1, infos["size"], StringFormat(mappingdictionary[index]["values"][subIndex]["name"],1,i+1)))
       
   182                     else:
       
   183                         list.append((index, subIndex, infos["size"], mappingdictionary[index]["values"][subIndex]["name"]))
       
   184     return list
       
   185 
       
   186 """
       
   187 Return the list of mandatory indexes defined in mappingdictionary 
       
   188 """
       
   189 def FindMandatoryIndexes(mappingdictionary):
       
   190     list = []
       
   191     for index in mappingdictionary.iterkeys():
       
   192         if index >= 0x1000 and mappingdictionary[index]["need"]:
       
   193             list.append(index)
       
   194     return list
       
   195 
       
   196 
    47 
   197 """
    48 """
   198 Class implementing a buffer of changes made on the current editing Object Dictionary
    49 Class implementing a buffer of changes made on the current editing Object Dictionary
   199 """
    50 """
   200 
    51 
   299     """
   150     """
   300     Constructor
   151     Constructor
   301     """
   152     """
   302     def __init__(self, cwd):
   153     def __init__(self, cwd):
   303         self.LastNewIndex = 0
   154         self.LastNewIndex = 0
   304         self.FilePaths = []
   155         self.FilePaths = {}
   305         self.FileNames = []
   156         self.FileNames = {}
   306         self.NodeIndex = -1
   157         self.NodeIndex = None
   307         self.CurrentNode = None
   158         self.CurrentNode = None
   308         self.ScriptDirectory = cwd
   159         self.ScriptDirectory = cwd
   309         self.UndoBuffers = []
   160         self.UndoBuffers = {}
   310 
   161 
   311 #-------------------------------------------------------------------------------
   162 #-------------------------------------------------------------------------------
   312 #                         Type and Map Variable Lists
   163 #                         Type and Map Variable Lists
   313 #-------------------------------------------------------------------------------
   164 #-------------------------------------------------------------------------------
   314 
       
   315     """
       
   316     Generate the list of types defined for the current node
       
   317     """
       
   318     def GenerateTypeList(self):
       
   319         self.TypeList = ""
       
   320         self.TypeTranslation = {}
       
   321         list = self.GetTypeList()
       
   322         sep = ""
       
   323         for index, name in list:
       
   324             self.TypeList += "%s%s"%(sep,name)
       
   325             self.TypeTranslation[name] = index
       
   326             sep = ","
       
   327     
       
   328     """
       
   329     Generate the list of variables that can be mapped for the current node
       
   330     """
       
   331     def GenerateMapList(self):
       
   332         self.MapList = "None"
       
   333         self.NameTranslation = {"None" : "00000000"}
       
   334         self.MapTranslation = {"00000000" : "None"}
       
   335         list = self.GetMapVariableList()
       
   336         for index, subIndex, size, name in list:
       
   337             self.MapList += ",%s"%name
       
   338             map = "%04X%02X%02X"%(index,subIndex,size)
       
   339             self.NameTranslation[name] = map
       
   340             self.MapTranslation[map] = name
       
   341     
   165     
   342     """
   166     """
   343     Return the list of types defined for the current node
   167     Return the list of types defined for the current node
   344     """
   168     """
   345     def GetCurrentTypeList(self):
   169     def GetCurrentTypeList(self):
   346         return self.TypeList
   170         if self.CurrentNode:
       
   171             return self.CurrentNode.GetTypeList()
       
   172         else:
       
   173             return ""
   347 
   174 
   348     """
   175     """
   349     Return the list of variables that can be mapped for the current node
   176     Return the list of variables that can be mapped for the current node
   350     """
   177     """
   351     def GetCurrentMapList(self):
   178     def GetCurrentMapList(self):
   352         return self.MapList
   179         if self.CurrentNode:
       
   180             return self.CurrentNode.GetMapList()
       
   181         else:
       
   182             return ""
   353 
   183 
   354 #-------------------------------------------------------------------------------
   184 #-------------------------------------------------------------------------------
   355 #                        Create Load and Save Functions
   185 #                        Create Load and Save Functions
   356 #-------------------------------------------------------------------------------
   186 #-------------------------------------------------------------------------------
   357 
   187 
   395                 elif option == "SaveConfig":
   225                 elif option == "SaveConfig":
   396                     AddIndexList.extend([0x1010, 0x1011, 0x1020])
   226                     AddIndexList.extend([0x1010, 0x1011, 0x1020])
   397                 elif option == "StoreEDS":
   227                 elif option == "StoreEDS":
   398                     AddIndexList.extend([0x1021, 0x1022])
   228                     AddIndexList.extend([0x1021, 0x1022])
   399             # Add a new buffer 
   229             # Add a new buffer 
   400             self.AddNodeBuffer()
   230             index = self.AddNodeBuffer()
   401             self.SetCurrentFilePath("")
   231             self.SetCurrentFilePath("")
   402             # Add Mandatory indexes
   232             # Add Mandatory indexes
   403             self.ManageEntriesOfCurrent(AddIndexList, [])
   233             self.ManageEntriesOfCurrent(AddIndexList, [])
   404             # Regenerate lists
   234             return index
   405             self.GenerateTypeList()
       
   406             self.GenerateMapList()
       
   407             return True
       
   408         else:
   235         else:
   409             return result
   236             return result
   410     
   237     
   411     """
   238     """
   412     Load a profile in node
   239     Load a profile in node
   437         file = open(filepath, "r")
   264         file = open(filepath, "r")
   438         node = load(file)
   265         node = load(file)
   439         file.close()
   266         file.close()
   440         self.CurrentNode = node
   267         self.CurrentNode = node
   441         # Add a new buffer and defining current state
   268         # Add a new buffer and defining current state
   442         self.AddNodeBuffer(self.CurrentNode.Copy(), True)
   269         index = self.AddNodeBuffer(self.CurrentNode.Copy(), True)
   443         self.SetCurrentFilePath(filepath)
   270         self.SetCurrentFilePath(filepath)
   444         # Regenerate lists
   271         return index
   445         self.GenerateTypeList()
       
   446         self.GenerateMapList()
       
   447         return True
       
   448 
   272 
   449     """
   273     """
   450     Save current node in  a file
   274     Save current node in  a file
   451     """
   275     """
   452     def SaveCurrentInFile(self, filepath = None):
   276     def SaveCurrentInFile(self, filepath = None):
   477     """
   301     """
   478     Import an eds file and store it in a new buffer if no node edited
   302     Import an eds file and store it in a new buffer if no node edited
   479     """
   303     """
   480     def ImportCurrentFromEDSFile(self, filepath):
   304     def ImportCurrentFromEDSFile(self, filepath):
   481         # Generate node from definition in a xml file
   305         # Generate node from definition in a xml file
   482         result = eds_utils.GenerateNode(filepath, self, self.ScriptDirectory)
   306         result = eds_utils.GenerateNode(filepath, self.ScriptDirectory)
   483         if isinstance(result, Node):
   307         if isinstance(result, Node):
   484             self.CurrentNode = result
   308             self.CurrentNode = result
   485             self.GenerateTypeList()
       
   486             self.GenerateMapList()
       
   487             if len(self.UndoBuffers) == 0:
   309             if len(self.UndoBuffers) == 0:
   488                 self.AddNodeBuffer()
   310                 index = self.AddNodeBuffer()
   489                 self.SetCurrentFilePath("")
   311                 self.SetCurrentFilePath("")
   490             self.BufferCurrentNode()
   312             self.BufferCurrentNode()
   491             return None
   313             return index
   492         else:
   314         else:
   493             return result
   315             return result
   494     
   316     
   495     """
   317     """
   496     Export to an eds file and store it in a new buffer if no node edited
   318     Export to an eds file and store it in a new buffer if no node edited
   703                 infos = self.GetEntryInfos(index)
   525                 infos = self.GetEntryInfos(index)
   704                 if not infos["need"]:
   526                 if not infos["need"]:
   705                     self.CurrentNode.RemoveEntry(index, subIndex)
   527                     self.CurrentNode.RemoveEntry(index, subIndex)
   706             if index in Mappings[-1]:
   528             if index in Mappings[-1]:
   707                 self.CurrentNode.RemoveMappingEntry(index, subIndex)
   529                 self.CurrentNode.RemoveMappingEntry(index, subIndex)
   708             self.GenerateMapList()
       
   709 
   530 
   710     def AddMapVariableToCurrent(self, index, name, struct, number):
   531     def AddMapVariableToCurrent(self, index, name, struct, number):
   711         if 0x2000 <= index <= 0x5FFF:
   532         if 0x2000 <= index <= 0x5FFF:
   712             if not self.CurrentNode.IsEntry(index):
   533             if not self.CurrentNode.IsEntry(index):
   713                 self.CurrentNode.AddMappingEntry(index, name = name, struct = struct)
   534                 self.CurrentNode.AddMappingEntry(index, name = name, struct = struct)
   714                 if struct == var:
   535                 if struct == var:
   715                     values = {"name" : name, "type" : 5, "access" : "rw", "pdo" : True}
   536                     values = {"name" : name, "type" : 0x05, "access" : "rw", "pdo" : True}
   716                     self.CurrentNode.AddMappingEntry(index, 0, values = values)
   537                     self.CurrentNode.AddMappingEntry(index, 0, values = values)
   717                     self.CurrentNode.AddEntry(index, 0, 0)
   538                     self.CurrentNode.AddEntry(index, 0, 0)
   718                 else:
   539                 else:
   719                     values = {"name" : "Number of Entries", "type" : 2, "access" : "ro", "pdo" : False}
   540                     values = {"name" : "Number of Entries", "type" : 0x05, "access" : "ro", "pdo" : False}
   720                     self.CurrentNode.AddMappingEntry(index, 0, values = values)
   541                     self.CurrentNode.AddMappingEntry(index, 0, values = values)
   721                     if struct == rec:
   542                     if struct == rec:
   722                         values = {"name" : name + " %d[(sub)]", "type" : 5, "access" : "rw", "pdo" : True, "nbmax" : 0xFE}
   543                         values = {"name" : name + " %d[(sub)]", "type" : 0x05, "access" : "rw", "pdo" : True, "nbmax" : 0xFE}
   723                         self.CurrentNode.AddMappingEntry(index, 1, values = values)
   544                         self.CurrentNode.AddMappingEntry(index, 1, values = values)
   724                         for i in xrange(number):
   545                         for i in xrange(number):
   725                             self.CurrentNode.AddEntry(index, i + 1, 0)
   546                             self.CurrentNode.AddEntry(index, i + 1, 0)
   726                     else:
   547                     else:
   727                         for i in xrange(number):
   548                         for i in xrange(number):
   728                             values = {"name" : "Undefined", "type" : 5, "access" : "rw", "pdo" : True}
   549                             values = {"name" : "Undefined", "type" : 0x05, "access" : "rw", "pdo" : True}
   729                             self.CurrentNode.AddMappingEntry(index, i + 1, values = values)
   550                             self.CurrentNode.AddMappingEntry(index, i + 1, values = values)
   730                             self.CurrentNode.AddEntry(index, i + 1, 0)
   551                             self.CurrentNode.AddEntry(index, i + 1, 0)
   731                 self.GenerateMapList()
       
   732                 self.BufferCurrentNode()
   552                 self.BufferCurrentNode()
   733                 return None
   553                 return None
   734             else:
   554             else:
   735                 return "Index 0x%04X already defined!"%index
   555                 return "Index 0x%04X already defined!"%index
   736         else:
   556         else:
   745             name, valuetype = customisabletypes[type]
   565             name, valuetype = customisabletypes[type]
   746             size = self.GetEntryInfos(type)["size"]
   566             size = self.GetEntryInfos(type)["size"]
   747             default = self.GetTypeDefaultValue(type)
   567             default = self.GetTypeDefaultValue(type)
   748             if valuetype == 0:
   568             if valuetype == 0:
   749                 self.CurrentNode.AddMappingEntry(index, name = "%s[%d-%d]"%(name, min, max), struct = 3, size = size, default = default)
   569                 self.CurrentNode.AddMappingEntry(index, name = "%s[%d-%d]"%(name, min, max), struct = 3, size = size, default = default)
   750                 self.CurrentNode.AddMappingEntry(index, 0, values = {"name" : "Number of Entries", "type" : 0x02, "access" : "ro", "pdo" : False})
   570                 self.CurrentNode.AddMappingEntry(index, 0, values = {"name" : "Number of Entries", "type" : 0x05, "access" : "ro", "pdo" : False})
   751                 self.CurrentNode.AddMappingEntry(index, 1, values = {"name" : "Type", "type" : 0x02, "access" : "ro", "pdo" : False})
   571                 self.CurrentNode.AddMappingEntry(index, 1, values = {"name" : "Type", "type" : 0x05, "access" : "ro", "pdo" : False})
   752                 self.CurrentNode.AddMappingEntry(index, 2, values = {"name" : "Minimum Value", "type" : type, "access" : "ro", "pdo" : False})
   572                 self.CurrentNode.AddMappingEntry(index, 2, values = {"name" : "Minimum Value", "type" : type, "access" : "ro", "pdo" : False})
   753                 self.CurrentNode.AddMappingEntry(index, 3, values = {"name" : "Maximum Value", "type" : type, "access" : "ro", "pdo" : False})
   573                 self.CurrentNode.AddMappingEntry(index, 3, values = {"name" : "Maximum Value", "type" : type, "access" : "ro", "pdo" : False})
   754                 self.CurrentNode.AddEntry(index, 1, type)
   574                 self.CurrentNode.AddEntry(index, 1, type)
   755                 self.CurrentNode.AddEntry(index, 2, min)
   575                 self.CurrentNode.AddEntry(index, 2, min)
   756                 self.CurrentNode.AddEntry(index, 3, max)
   576                 self.CurrentNode.AddEntry(index, 3, max)
   757             elif valuetype == 1:
   577             elif valuetype == 1:
   758                 self.CurrentNode.AddMappingEntry(index, name = "%s%d"%(name, length), struct = 3, size = length * size, default = default)
   578                 self.CurrentNode.AddMappingEntry(index, name = "%s%d"%(name, length), struct = 3, size = length * size, default = default)
   759                 self.CurrentNode.AddMappingEntry(index, 0, values = {"name" : "Number of Entries", "type" : 0x02, "access" : "ro", "pdo" : False})
   579                 self.CurrentNode.AddMappingEntry(index, 0, values = {"name" : "Number of Entries", "type" : 0x05, "access" : "ro", "pdo" : False})
   760                 self.CurrentNode.AddMappingEntry(index, 1, values = {"name" : "Type", "type" : 0x02, "access" : "ro", "pdo" : False})
   580                 self.CurrentNode.AddMappingEntry(index, 1, values = {"name" : "Type", "type" : 0x05, "access" : "ro", "pdo" : False})
   761                 self.CurrentNode.AddMappingEntry(index, 2, values = {"name" : "Length", "type" : 0x02, "access" : "ro", "pdo" : False})
   581                 self.CurrentNode.AddMappingEntry(index, 2, values = {"name" : "Length", "type" : 0x05, "access" : "ro", "pdo" : False})
   762                 self.CurrentNode.AddEntry(index, 1, type)
   582                 self.CurrentNode.AddEntry(index, 1, type)
   763                 self.CurrentNode.AddEntry(index, 2, length)
   583                 self.CurrentNode.AddEntry(index, 2, length)
   764             self.GenerateTypeList()
       
   765             self.BufferCurrentNode()
   584             self.BufferCurrentNode()
   766             return None
   585             return None
   767         else:
   586         else:
   768             return "Too many User Types have already been defined!"
   587             return "Too many User Types have already been defined!"
   769 
   588 
   780 
   599 
   781     def SetCurrentEntry(self, index, subIndex, value, name, editor):
   600     def SetCurrentEntry(self, index, subIndex, value, name, editor):
   782         if self.CurrentNode and self.CurrentNode.IsEntry(index):
   601         if self.CurrentNode and self.CurrentNode.IsEntry(index):
   783             if name == "value":
   602             if name == "value":
   784                 if editor == "map":
   603                 if editor == "map":
   785                     try:
   604                     value = self.CurrentNode.GetMapValue(value)
   786                         value = int(self.NameTranslation[value], 16)
   605                     if value:
   787                         self.CurrentNode.SetEntry(index, subIndex, value)
   606                         self.CurrentNode.SetEntry(index, subIndex, value)
   788                     except:
       
   789                         pass
       
   790                 elif editor == "bool":
   607                 elif editor == "bool":
   791                     value = value == "True"
   608                     value = value == "True"
   792                     self.CurrentNode.SetEntry(index, subIndex, value)
   609                     self.CurrentNode.SetEntry(index, subIndex, value)
   793                 elif editor == "time":
   610                 elif editor == "time":
   794                     self.CurrentNode.SetEntry(index, subIndex, value)
   611                     self.CurrentNode.SetEntry(index, subIndex, value)
   828                     self.CurrentNode.SetParamsEntry(index, subIndex, save = value)
   645                     self.CurrentNode.SetParamsEntry(index, subIndex, save = value)
   829                 elif name == "comment":
   646                 elif name == "comment":
   830                     self.CurrentNode.SetParamsEntry(index, subIndex, comment = value)
   647                     self.CurrentNode.SetParamsEntry(index, subIndex, comment = value)
   831             else:
   648             else:
   832                 if editor == "type":
   649                 if editor == "type":
   833                     value = self.TypeTranslation[value]
   650                     value = self.GetTypeIndex(value)
   834                     size = self.GetEntryInfos(value)["size"]
   651                     size = self.GetEntryInfos(value)["size"]
   835                     self.CurrentNode.UpdateMapVariable(index, subIndex, size)
   652                     self.CurrentNode.UpdateMapVariable(index, subIndex, size)
   836                 elif editor in ["access","raccess"]:
   653                 elif editor in ["access","raccess"]:
   837                     dic = {}
   654                     dic = {}
   838                     for abbrev,access in AccessType.iteritems():
   655                     for abbrev,access in AccessType.iteritems():
   842                         entry_infos = self.GetEntryInfos(index)
   659                         entry_infos = self.GetEntryInfos(index)
   843                         self.CurrentNode.AddMappingEntry(index, name = entry_infos["name"], struct = 7)
   660                         self.CurrentNode.AddMappingEntry(index, name = entry_infos["name"], struct = 7)
   844                         self.CurrentNode.AddMappingEntry(index, 0, values = self.GetSubentryInfos(index, 0, False).copy())
   661                         self.CurrentNode.AddMappingEntry(index, 0, values = self.GetSubentryInfos(index, 0, False).copy())
   845                         self.CurrentNode.AddMappingEntry(index, 1, values = self.GetSubentryInfos(index, 1, False).copy())
   662                         self.CurrentNode.AddMappingEntry(index, 1, values = self.GetSubentryInfos(index, 1, False).copy())
   846                 self.CurrentNode.SetMappingEntry(index, subIndex, values = {name : value})
   663                 self.CurrentNode.SetMappingEntry(index, subIndex, values = {name : value})
   847                 if name == "name" or editor == "type":
       
   848                     self.GenerateMapList()
       
   849             self.BufferCurrentNode()
   664             self.BufferCurrentNode()
   850 
   665 
   851     def SetCurrentEntryName(self, index, name):
   666     def SetCurrentEntryName(self, index, name):
   852         self.CurrentNode.SetMappingEntry(index, name=name)
   667         self.CurrentNode.SetMappingEntry(index, name=name)
   853         self.BufferCurrentNode()
   668         self.BufferCurrentNode()
   890     def CurrentIsSaved(self):
   705     def CurrentIsSaved(self):
   891         return self.UndoBuffers[self.NodeIndex].IsCurrentSaved()
   706         return self.UndoBuffers[self.NodeIndex].IsCurrentSaved()
   892 
   707 
   893     def OneFileHasChanged(self):
   708     def OneFileHasChanged(self):
   894         result = False
   709         result = False
   895         for buffer in self.UndoBuffers:
   710         for buffer in self.UndoBuffers.values():
   896             result |= not buffer.IsCurrentSaved()
   711             result |= not buffer.IsCurrentSaved()
   897         return result
   712         return result
   898 
   713 
   899     def GetBufferNumber(self):
   714     def GetBufferNumber(self):
   900         return len(self.UndoBuffers)
   715         return len(self.UndoBuffers)
   904     
   719     
   905     def LoadCurrentNext(self):
   720     def LoadCurrentNext(self):
   906         self.CurrentNode = self.UndoBuffers[self.NodeIndex].Next().Copy()
   721         self.CurrentNode = self.UndoBuffers[self.NodeIndex].Next().Copy()
   907 
   722 
   908     def AddNodeBuffer(self, currentstate = None, issaved = False):
   723     def AddNodeBuffer(self, currentstate = None, issaved = False):
   909         self.NodeIndex = len(self.UndoBuffers)
   724         self.NodeIndex = GetNewId()
   910         self.UndoBuffers.append(UndoBuffer(currentstate, issaved))
   725         self.UndoBuffers[self.NodeIndex] = UndoBuffer(currentstate, issaved)
   911         self.FilePaths.append("")
   726         self.FilePaths[self.NodeIndex] = ""
   912         self.FileNames.append("")
   727         self.FileNames[self.NodeIndex] = ""
       
   728         return self.NodeIndex
   913 
   729 
   914     def ChangeCurrentNode(self, index):
   730     def ChangeCurrentNode(self, index):
   915         if index < len(self.UndoBuffers):
   731         if index in self.UndoBuffers.keys():
   916             self.NodeIndex = index
   732             self.NodeIndex = index
   917             self.CurrentNode = self.UndoBuffers[self.NodeIndex].Current().Copy()
   733             self.CurrentNode = self.UndoBuffers[self.NodeIndex].Current().Copy()
   918             self.GenerateTypeList()
       
   919             self.GenerateMapList()
       
   920     
   734     
   921     def RemoveNodeBuffer(self, index):
   735     def RemoveNodeBuffer(self, index):
   922         self.UndoBuffers.pop(index)
   736         self.UndoBuffers.pop(index)
   923         self.FilePaths.pop(index)
   737         self.FilePaths.pop(index)
   924         self.FileNames.pop(index)
   738         self.FileNames.pop(index)
   925         self.NodeIndex = min(self.NodeIndex, len(self.UndoBuffers) - 1)
       
   926         if len(self.UndoBuffers) > 0:
       
   927             self.CurrentNode = self.UndoBuffers[self.NodeIndex].Current().Copy()
       
   928             self.GenerateTypeList()
       
   929             self.GenerateMapList()
       
   930         else:
       
   931             self.CurrentNode = None
       
   932     
   739     
   933     def GetCurrentNodeIndex(self):
   740     def GetCurrentNodeIndex(self):
   934         return self.NodeIndex
   741         return self.NodeIndex
   935     
   742     
   936     def GetCurrentFilename(self):
   743     def GetCurrentFilename(self):
   937         return self.GetFilename(self.NodeIndex)
   744         return self.GetFilename(self.NodeIndex)
   938     
   745     
   939     def GetAllFilenames(self):
   746     def GetAllFilenames(self):
   940         filenames = []
   747         indexes = self.UndoBuffers.keys()
   941         for i in xrange(len(self.UndoBuffers)):
   748         indexes.sort()
   942             filenames.append(self.GetFilename(i))
   749         return [self.GetFilename(idx) for idx in indexes]
   943         return filenames
       
   944     
   750     
   945     def GetFilename(self, index):
   751     def GetFilename(self, index):
   946         if self.UndoBuffers[index].IsCurrentSaved():
   752         if self.UndoBuffers[index].IsCurrentSaved():
   947             return self.FileNames[index]
   753             return self.FileNames[index]
   948         else:
   754         else:
  1019         return False
   825         return False
  1020 
   826 
  1021 #-------------------------------------------------------------------------------
   827 #-------------------------------------------------------------------------------
  1022 #                         Node State and Values Functions
   828 #                         Node State and Values Functions
  1023 #-------------------------------------------------------------------------------
   829 #-------------------------------------------------------------------------------
       
   830     
       
   831     def GetCurrentNodeName(self):
       
   832         if self.CurrentNode:
       
   833             return self.CurrentNode.GetNodeName()
       
   834         else:
       
   835             return ""
       
   836 
       
   837     def GetCurrentNodeID(self):
       
   838         if self.CurrentNode:
       
   839             return self.CurrentNode.GetNodeID()
       
   840         else:
       
   841             return None
  1024 
   842 
  1025     def GetCurrentNodeInfos(self):
   843     def GetCurrentNodeInfos(self):
  1026         name = self.CurrentNode.GetNodeName()
   844         name = self.CurrentNode.GetNodeName()
  1027         id = self.CurrentNode.GetNodeID()
   845         id = self.CurrentNode.GetNodeID()
  1028         type = self.CurrentNode.GetNodeType()
   846         type = self.CurrentNode.GetNodeType()
  1090                 return entry_infos["callback"]
   908                 return entry_infos["callback"]
  1091             return self.CurrentNode.HasEntryCallbacks(index)
   909             return self.CurrentNode.HasEntryCallbacks(index)
  1092         return False
   910         return False
  1093     
   911     
  1094     def GetCurrentEntryValues(self, index):
   912     def GetCurrentEntryValues(self, index):
  1095         if self.CurrentNode and self.CurrentNode.IsEntry(index):
   913         if self.CurrentNode:
  1096             entry_infos = self.GetEntryInfos(index)
   914             return self.GetNodeEntryValues(self.CurrentNode, index)
       
   915     
       
   916     def GetNodeEntryValues(self, node, index):
       
   917         if node and node.IsEntry(index):
       
   918             entry_infos = node.GetEntryInfos(index)
  1097             data = []
   919             data = []
  1098             editors = []
   920             editors = []
  1099             values = self.CurrentNode.GetEntry(index)
   921             values = node.GetEntry(index)
  1100             params = self.CurrentNode.GetParamsEntry(index)
   922             params = node.GetParamsEntry(index)
  1101             if type(values) == ListType:
   923             if type(values) == ListType:
  1102                 for i, value in enumerate(values):
   924                 for i, value in enumerate(values):
  1103                     data.append({"value" : value})
   925                     data.append({"value" : value})
  1104                     data[-1].update(params[i])      
   926                     data[-1].update(params[i])      
  1105             else:
   927             else:
  1106                 data.append({"value" : values})
   928                 data.append({"value" : values})
  1107                 data[-1].update(params)
   929                 data[-1].update(params)
  1108             for i, dic in enumerate(data):
   930             for i, dic in enumerate(data):
  1109                 infos = self.GetSubentryInfos(index, i)
   931                 infos = node.GetSubentryInfos(index, i)
  1110                 dic["subindex"] = "0x%02X"%i
   932                 dic["subindex"] = "0x%02X"%i
  1111                 dic["name"] = infos["name"]
   933                 dic["name"] = infos["name"]
  1112                 dic["type"] = self.GetTypeName(infos["type"])
   934                 dic["type"] = node.GetTypeName(infos["type"])
  1113                 dic["access"] = AccessType[infos["access"]]
   935                 dic["access"] = AccessType[infos["access"]]
  1114                 dic["save"] = OptionType[dic["save"]]
   936                 dic["save"] = OptionType[dic["save"]]
  1115                 editor = {"subindex" : None, "save" : "option", "callback" : "option", "comment" : "string"}
   937                 editor = {"subindex" : None, "save" : "option", "callback" : "option", "comment" : "string"}
  1116                 if type(values) == ListType and i == 0:
   938                 if type(values) == ListType and i == 0:
  1117                     editor["name"] = None
   939                     editor["name"] = None
  1143                         editor["type"] = None
   965                         editor["type"] = None
  1144                         editor["access"] = None
   966                         editor["access"] = None
  1145                     if index < 0x260:
   967                     if index < 0x260:
  1146                         editor["value"] = None
   968                         editor["value"] = None
  1147                         if i == 1:
   969                         if i == 1:
  1148                             dic["value"] = self.GetTypeName(dic["value"])
   970                             dic["value"] = node.GetTypeName(dic["value"])
  1149                     elif 0x1600 <= index <= 0x17FF or 0x1A00 <= index <= 0x1C00:
   971                     elif 0x1600 <= index <= 0x17FF or 0x1A00 <= index <= 0x1C00:
  1150                         editor["value"] = "map"
   972                         editor["value"] = "map"
  1151                         dic["value"] = self.MapTranslation["%08X"%dic["value"]]
   973                         dic["value"] = node.GetMapName(dic["value"])
  1152                     else:
   974                     else:
  1153                         if dic["type"].startswith("VISIBLE_STRING"):
   975                         if dic["type"].startswith("VISIBLE_STRING"):
  1154                             editor["value"] = "string"
   976                             editor["value"] = "string"
  1155                         elif dic["type"] in ["TIME_OF_DAY","TIME_DIFFERENCE"]:
   977                         elif dic["type"] in ["TIME_OF_DAY","TIME_DIFFERENCE"]:
  1156                             editor["value"] = "time"
   978                             editor["value"] = "time"
  1181                                 editor["max"] = values[3]
  1003                                 editor["max"] = values[3]
  1182                 editors.append(editor)
  1004                 editors.append(editor)
  1183             return data, editors
  1005             return data, editors
  1184         else:
  1006         else:
  1185             return None
  1007             return None
  1186     
  1008 
  1187 #-------------------------------------------------------------------------------
  1009 #-------------------------------------------------------------------------------
  1188 #                         Node Informations Functions
  1010 #                         Node Informations Functions
  1189 #-------------------------------------------------------------------------------
  1011 #-------------------------------------------------------------------------------
  1190 
  1012 
  1191     def GetCustomisedTypeValues(self, index):
  1013     def GetCustomisedTypeValues(self, index):
  1192         values = self.CurrentNode.GetEntry(index)
  1014         if self.CurrentNode:
  1193         customisabletypes = self.GetCustomisableTypes()
  1015             values = self.CurrentNode.GetEntry(index)
  1194         return values, customisabletypes[values[1]][1]
  1016             customisabletypes = self.GetCustomisableTypes()
  1195 
  1017             return values, customisabletypes[values[1]][1]
  1196     def GetEntryName(self, index, node = None):
  1018         else:
  1197         result = None
  1019             return None, None
  1198         if node == None:
  1020 
  1199             node = self.CurrentNode
  1021     def GetEntryName(self, index):
  1200         NodeMappings = node.GetMappings()
  1022         if self.CurrentNode:
  1201         i = 0
  1023             return self.CurrentNode.GetEntryName(index)
  1202         while not result and i < len(NodeMappings):
  1024         else:
  1203             result = FindEntryName(index, NodeMappings[i])
  1025             return FindEntryName(index, MappingDictionary)
  1204             i += 1
  1026     
  1205         if result == None:
  1027     def GetEntryInfos(self, index):
  1206             result = FindEntryName(index, MappingDictionary)
  1028         if self.CurrentNode:
  1207         return result
  1029             return self.CurrentNode.GetEntryInfos(index)
  1208     
  1030         else:
  1209     def GetEntryInfos(self, index, node = None):
  1031             return FindEntryInfos(index, MappingDictionary)
  1210         result = None
  1032     
  1211         if node == None:
  1033     def GetSubentryInfos(self, index, subindex):
  1212             node = self.CurrentNode
  1034         if self.CurrentNode:
  1213         NodeMappings = node.GetMappings()
  1035             return self.CurrentNode.GetSubentryInfos(index, subindex)
  1214         i = 0
  1036         else:
  1215         while not result and i < len(NodeMappings):
  1037             result = FindSubentryInfos(index, subindex, MappingDictionary)
  1216             result = FindEntryInfos(index, NodeMappings[i])
       
  1217             i += 1
       
  1218         if result == None:
       
  1219             result = FindEntryInfos(index, MappingDictionary)
       
  1220         return result
       
  1221     
       
  1222     def GetSubentryInfos(self, index, subIndex, node = None):
       
  1223         result = None
       
  1224         if node == None:
       
  1225             node = self.CurrentNode
       
  1226         NodeMappings = node.GetMappings()
       
  1227         i = 0
       
  1228         while not result and i < len(NodeMappings):
       
  1229             result = FindSubentryInfos(index, subIndex, NodeMappings[i])
       
  1230             if result:
       
  1231                 result["user_defined"] = i == len(NodeMappings) - 1 and index >= 0x1000
       
  1232             i += 1
       
  1233         if result == None:    
       
  1234             result = FindSubentryInfos(index, subIndex, MappingDictionary)
       
  1235             if result:
  1038             if result:
  1236                 result["user_defined"] = False
  1039                 result["user_defined"] = False
  1237         return result
  1040             return result
  1238     
  1041     
  1239     def GetTypeIndex(self, typename, node = None):
  1042     def GetTypeIndex(self, typename):
  1240         result = None
  1043         if self.CurrentNode:
  1241         if node == None:
  1044             return self.CurrentNode.GetTypeIndex(typename)
  1242             node = self.CurrentNode
  1045         else:
  1243         NodeMappings = node.GetMappings()
  1046             return FindTypeIndex(typename, MappingDictionary)
  1244         i = 0
  1047     
  1245         while not result and i < len(NodeMappings):
  1048     def GetTypeName(self, typeindex):
  1246             result = FindTypeIndex(typename, NodeMappings[i])
  1049         if self.CurrentNode:
  1247             i += 1
  1050             return self.CurrentNode.GetTypeName(typeindex)
  1248         if result == None:
  1051         else:
  1249             result = FindTypeIndex(typename, MappingDictionary)
  1052             return FindTypeName(typeindex, MappingDictionary)
  1250         return result
  1053     
  1251     
  1054     def GetTypeDefaultValue(self, typeindex):
  1252     def GetTypeName(self, typeindex, node = None):
  1055         if self.CurrentNode:
  1253         result = None
  1056             return self.CurrentNode.GetTypeDefaultValue(typeindex)
  1254         if node == None:
  1057         else:
  1255             node = self.CurrentNode
  1058             return FindTypeDefaultValue(typeindex, MappingDictionary)
  1256         NodeMappings = node.GetMappings()
  1059     
  1257         i = 0
  1060     def GetMapVariableList(self):
  1258         while not result and i < len(NodeMappings):
  1061         if self.CurrentNode:
  1259             result = FindTypeName(typeindex, NodeMappings[i])
  1062             return self.CurrentNode.GetMapVariableList()
  1260             i += 1
  1063         else:
  1261         if result == None:
  1064             return []
  1262             result = FindTypeName(typeindex, MappingDictionary)
  1065 
  1263         return result
       
  1264     
       
  1265     def GetTypeDefaultValue(self, typeindex, node = None):
       
  1266         result = None
       
  1267         if node == None:
       
  1268             node = self.CurrentNode
       
  1269         if node:
       
  1270             NodeMappings = node.GetMappings()
       
  1271             i = 0
       
  1272             while not result and i < len(NodeMappings):
       
  1273                 result = FindTypeDefaultValue(typeindex, NodeMappings[i])
       
  1274                 i += 1
       
  1275         if result == None:
       
  1276             result = FindTypeDefaultValue(typeindex, MappingDictionary)
       
  1277         return result
       
  1278     
       
  1279     def GetTypeList(self, node = None):
       
  1280         list = FindTypeList(MappingDictionary)
       
  1281         if node == None:
       
  1282             node = self.CurrentNode
       
  1283         for NodeMapping in self.CurrentNode.GetMappings():
       
  1284             list.extend(FindTypeList(NodeMapping))
       
  1285         list.sort()
       
  1286         return list
       
  1287     
       
  1288     def GetMapVariableList(self, node = None):
       
  1289         list = FindMapVariableList(MappingDictionary, self)
       
  1290         if node == None:
       
  1291             node = self.CurrentNode
       
  1292         for NodeMapping in node.GetMappings():
       
  1293             list.extend(FindMapVariableList(NodeMapping, self))
       
  1294         list.sort()
       
  1295         return list
       
  1296     
       
  1297     def GetMandatoryIndexes(self, node = None):
  1066     def GetMandatoryIndexes(self, node = None):
  1298         list = FindMandatoryIndexes(MappingDictionary)
  1067         if self.CurrentNode:
  1299         if node == None:
  1068             return self.CurrentNode.GetMapVariableList()
  1300             node = self.CurrentNode
  1069         else:
  1301         for NodeMapping in node.GetMappings():
  1070             return FindMandatoryIndexes(MappingDictionary)
  1302             list.extend(FindMandatoryIndexes(NodeMapping))
       
  1303         return list
       
  1304     
  1071     
  1305     def GetCustomisableTypes(self):
  1072     def GetCustomisableTypes(self):
  1306         dic = {}
  1073         dic = {}
  1307         for index, valuetype in CustomisableTypes:
  1074         for index, valuetype in CustomisableTypes:
  1308             name = self.GetTypeName(index)
  1075             name = self.GetTypeName(index)