Bug with in access value translation and modification on subindex 0 of PDOmapping entries fixed
authorlaurent
Tue, 15 Sep 2009 10:47:38 +0200
changeset 584 e23359f62023
parent 583 a2c74eca6bf2
child 585 d62424ba12bf
Bug with in access value translation and modification on subindex 0 of PDOmapping entries fixed
objdictgen/node.py
objdictgen/nodemanager.py
objdictgen/subindextable.py
--- a/objdictgen/node.py	Fri Aug 07 15:59:35 2009 +0200
+++ b/objdictgen/node.py	Tue Sep 15 10:47:38 2009 +0200
@@ -270,11 +270,11 @@
 """
 Return the name of an entry by searching in mappingdictionary 
 """
-def FindEntryName(index, mappingdictionary):
+def FindEntryName(index, mappingdictionary, compute=True):
     base_index = FindIndex(index, mappingdictionary)
     if base_index:
         infos = mappingdictionary[base_index]
-        if infos["struct"] & OD_IdenticalIndexes:
+        if infos["struct"] & OD_IdenticalIndexes and compute:
             return StringFormat(infos["name"], (index - base_index) / infos["incr"] + 1, 0)
         else:
             return infos["name"]
@@ -283,11 +283,11 @@
 """
 Return the informations of one entry by searching in mappingdictionary 
 """
-def FindEntryInfos(index, mappingdictionary):
+def FindEntryInfos(index, mappingdictionary, compute=True):
     base_index = FindIndex(index, mappingdictionary)
     if base_index:
         copy = mappingdictionary[base_index].copy()
-        if copy["struct"] & OD_IdenticalIndexes:
+        if copy["struct"] & OD_IdenticalIndexes and compute:
             copy["name"] = StringFormat(copy["name"], (index - base_index) / copy["incr"] + 1, 0)
         copy.pop("values")
         return copy
@@ -296,7 +296,7 @@
 """
 Return the informations of one subentry of an entry by searching in mappingdictionary 
 """
-def FindSubentryInfos(index, subIndex, mappingdictionary):
+def FindSubentryInfos(index, subIndex, mappingdictionary, compute=True):
     base_index = FindIndex(index, mappingdictionary)
     if base_index:
         struct = mappingdictionary[base_index]["struct"]
@@ -326,7 +326,7 @@
                         idx += 1
             elif subIndex == 0:
                 infos = mappingdictionary[base_index]["values"][0].copy()
-            if infos is not None:
+            if infos is not None and compute:
                 infos["name"] = StringFormat(infos["name"], (index - base_index) / incr + 1, subIndex)
             return infos
     return None
@@ -334,19 +334,26 @@
 """
 Return the list of variables that can be mapped defined in mappingdictionary 
 """
-def FindMapVariableList(mappingdictionary, Node):
+def FindMapVariableList(mappingdictionary, Node, compute=True):
     list = []
     for index in mappingdictionary.iterkeys():
         if Node.IsEntry(index):
             for subIndex, values in enumerate(mappingdictionary[index]["values"]):
                 if mappingdictionary[index]["values"][subIndex]["pdo"]:
                     infos = Node.GetEntryInfos(mappingdictionary[index]["values"][subIndex]["type"])
+                    name = mappingdictionary[index]["values"][subIndex]["name"]
                     if mappingdictionary[index]["struct"] & OD_IdenticalSubindexes:
                         values = Node.GetEntry(index)
                         for i in xrange(len(values) - 1):
-                            list.append((index, i + 1, infos["size"], StringFormat(mappingdictionary[index]["values"][subIndex]["name"],1,i+1)))
+                            computed_name = name
+                            if compute:
+                                computed_name = StringFormat(computed_name, 1, i + 1)
+                            list.append((index, i + 1, infos["size"], computed_name))
                     else:
-                        list.append((index, subIndex, infos["size"], mappingdictionary[index]["values"][subIndex]["name"]))
+                        computed_name = name
+                        if compute:
+                            computed_name = StringFormat(computed_name, 1, subIndex)
+                        list.append((index, subIndex, infos["size"], computed_name))
     return list
 
 """
@@ -948,39 +955,39 @@
         customisabletypes = self.GetCustomisableTypes()
         return values, customisabletypes[values[1]][1]
 
-    def GetEntryName(self, index):
+    def GetEntryName(self, index, compute=True):
         result = None
         mappings = self.GetMappings()
         i = 0
         while not result and i < len(mappings):
-            result = FindEntryName(index, mappings[i])
+            result = FindEntryName(index, mappings[i], compute)
             i += 1
         if result == None:
-            result = FindEntryName(index, MappingDictionary)
+            result = FindEntryName(index, MappingDictionary, compute)
         return result
     
-    def GetEntryInfos(self, index):
+    def GetEntryInfos(self, index, compute=True):
         result = None
         mappings = self.GetMappings()
         i = 0
         while not result and i < len(mappings):
-            result = FindEntryInfos(index, mappings[i])
+            result = FindEntryInfos(index, mappings[i], compute)
             i += 1
         if result == None:
-            result = FindEntryInfos(index, MappingDictionary)
+            result = FindEntryInfos(index, MappingDictionary, compute)
         return result
     
-    def GetSubentryInfos(self, index, subIndex):
+    def GetSubentryInfos(self, index, subIndex, compute=True):
         result = None
         mappings = self.GetMappings()
         i = 0
         while not result and i < len(mappings):
-            result = FindSubentryInfos(index, subIndex, mappings[i])
+            result = FindSubentryInfos(index, subIndex, mappings[i], compute)
             if result:
                 result["user_defined"] = i == len(mappings) - 1 and index >= 0x1000
             i += 1
         if result == None:
-            result = FindSubentryInfos(index, subIndex, MappingDictionary)
+            result = FindSubentryInfos(index, subIndex, MappingDictionary, compute)
             if result:
                 result["user_defined"] = False
         return result
@@ -1018,10 +1025,10 @@
             result = FindTypeDefaultValue(typeindex, MappingDictionary)
         return result
     
-    def GetMapVariableList(self):
-        list = FindMapVariableList(MappingDictionary, self)
+    def GetMapVariableList(self, compute=True):
+        list = FindMapVariableList(MappingDictionary, self, compute)
         for mapping in self.GetMappings():
-            list.extend(FindMapVariableList(mapping, self))
+            list.extend(FindMapVariableList(mapping, self, compute))
         list.sort()
         return list
     
@@ -1112,7 +1119,7 @@
     Return the list of variables that can be mapped for the current node
     """
     def GetMapList(self):
-        list = ["None"] + [self.GenerateMapName(name, index, subIndex) for index, subIndex, size, name in self.GetMapVariableList()]
+        list = [_("None")] + [self.GenerateMapName(name, index, subIndex) for index, subIndex, size, name in self.GetMapVariableList()]
         return ",".join(list)
 
 def BE_to_LE(value):
--- a/objdictgen/nodemanager.py	Fri Aug 07 15:59:35 2009 +0200
+++ b/objdictgen/nodemanager.py	Tue Sep 15 10:47:38 2009 +0200
@@ -744,9 +744,11 @@
                     value = dic[value]
                     if editor == "raccess" and not node.IsMappingEntry(index):
                         entry_infos = self.GetEntryInfos(index)
+                        subIndex0_infos = self.GetSubentryInfos(index, 0, False).copy()
+                        subIndex1_infos = self.GetSubentryInfos(index, 1, False).copy()
                         node.AddMappingEntry(index, name = entry_infos["name"], struct = 7)
-                        node.AddMappingEntry(index, 0, values = self.GetSubentryInfos(index, 0, False).copy())
-                        node.AddMappingEntry(index, 1, values = self.GetSubentryInfos(index, 1, False).copy())
+                        node.AddMappingEntry(index, 0, values = subIndex0_infos)
+                        node.AddMappingEntry(index, 1, values = subIndex1_infos)
                 node.SetMappingEntry(index, subIndex, values = {name : value})
             if not disable_buffer:
                 self.BufferCurrentNode()
@@ -1131,23 +1133,23 @@
         else:
             return None, None
 
-    def GetEntryName(self, index):
-        if self.CurrentNode:
-            return self.CurrentNode.GetEntryName(index)
-        else:
-            return FindEntryName(index, MappingDictionary)
-    
-    def GetEntryInfos(self, index):
-        if self.CurrentNode:
-            return self.CurrentNode.GetEntryInfos(index)
-        else:
-            return FindEntryInfos(index, MappingDictionary)
-    
-    def GetSubentryInfos(self, index, subindex):
-        if self.CurrentNode:
-            return self.CurrentNode.GetSubentryInfos(index, subindex)
-        else:
-            result = FindSubentryInfos(index, subindex, MappingDictionary)
+    def GetEntryName(self, index, compute=True):
+        if self.CurrentNode:
+            return self.CurrentNode.GetEntryName(index, compute)
+        else:
+            return FindEntryName(index, MappingDictionary, compute)
+    
+    def GetEntryInfos(self, index, compute=True):
+        if self.CurrentNode:
+            return self.CurrentNode.GetEntryInfos(index, compute)
+        else:
+            return FindEntryInfos(index, MappingDictionary, compute)
+    
+    def GetSubentryInfos(self, index, subindex, compute=True):
+        if self.CurrentNode:
+            return self.CurrentNode.GetSubentryInfos(index, subindex, compute)
+        else:
+            result = FindSubentryInfos(index, subindex, MappingDictionary, compute)
             if result:
                 result["user_defined"] = False
             return result
@@ -1170,9 +1172,9 @@
         else:
             return FindTypeDefaultValue(typeindex, MappingDictionary)
     
-    def GetMapVariableList(self):
-        if self.CurrentNode:
-            return self.CurrentNode.GetMapVariableList()
+    def GetMapVariableList(self, compute=True):
+        if self.CurrentNode:
+            return self.CurrentNode.GetMapVariableList(compute)
         else:
             return []
 
--- a/objdictgen/subindextable.py	Fri Aug 07 15:59:35 2009 +0200
+++ b/objdictgen/subindextable.py	Tue Sep 15 10:47:38 2009 +0200
@@ -37,20 +37,20 @@
     if write:
         return [_("Read Only"), _("Write Only"), _("Read/Write")]
     return [_("Read Only"), _("Read/Write")]
-AccessList = ",".join(GetAccessList())
-RAccessList = ",".join(GetAccessList(False))
+AccessList = ",".join(map(_, GetAccessList()))
+RAccessList = ",".join(map(_, GetAccessList(False)))
 ACCESS_LIST_DICT = dict([(_(access), access) for access in GetAccessList()])
 
 def GetBoolList():
     _ = lambda x : x
     return [_("True"), _("False")]
-BoolList = ",".join(GetBoolList())
+BoolList = ",".join(map(_, GetBoolList()))
 BOOL_LIST_DICT = dict([(_(bool), bool) for bool in GetBoolList()])
 
 def GetOptionList():
     _ = lambda x : x
     return [_("Yes"), _("No")]
-OptionList = ",".join(GetOptionList())
+OptionList = ",".join(map(_, GetOptionList()))
 OPTION_LIST_DICT = dict([(_(option), option) for option in GetOptionList()])
 
 [USER_TYPE, SDO_SERVER, SDO_CLIENT, 
@@ -137,11 +137,13 @@
     def GetRowLabelValues(self, row, translate=True):
         return row
 
-    def GetValue(self, row, col):
+    def GetValue(self, row, col, translate=True):
         if row < self.GetNumberRows():
             colname = self.GetColLabelValue(col, False)
             value = unicode(self.data[row].get(colname, ""))
-            if self.editors[row][colname] in ["access", "raccess", "bool", "option"]:
+            if translate and (colname == "access" or 
+                              self.editors[row][colname] in ["bool", "option"] or
+                              self.editors[row][colname] == "map" and value == "None"):
                 value = _(value)
             return value
             
@@ -155,12 +157,14 @@
     def SetValue(self, row, col, value):
         if col < len(self.colnames):
             colname = self.GetColLabelValue(col, False)
-            if self.editors[row][colname] in ["access", "raccess"]:
+            if colname == "access":
                 value = ACCESS_LIST_DICT[value]
             elif self.editors[row][colname] == "bool":
                 value = BOOL_LIST_DICT[value]
             elif self.editors[row][colname] == "option":
                 value = OPTION_LIST_DICT[value]
+            elif self.editors[row][colname] == "map" and value == _("None"):
+                value = "None"
             self.data[row][colname] = value
         
     def ResetView(self, grid):
@@ -679,8 +683,8 @@
             index = self.Table.GetCurrentIndex()
             subIndex = event.GetRow()
             col = event.GetCol()
-            name = self.Table.GetColLabelValue(col)
-            value = self.Table.GetValue(subIndex, col)
+            name = self.Table.GetColLabelValue(col, False)
+            value = self.Table.GetValue(subIndex, col, False)
             editor = self.Table.GetEditor(subIndex, col)
             self.Manager.SetCurrentEntry(index, subIndex, value, name, editor)
             self.ParentWindow.RefreshBufferState()