--- a/objdictgen/gen_cfile.py Tue Apr 29 13:50:56 2008 +0200
+++ b/objdictgen/gen_cfile.py Tue Apr 29 13:54:23 2008 +0200
@@ -80,6 +80,16 @@
raise ValueError, """!!! %s isn't a valid type for CanFestival."""%typename
return typeinfos
+def ComputeValue(type, value):
+ if type == "visible_string":
+ return "\"%s\""%value, ""
+ elif type == "domain":
+ return "\"%s\""%''.join(["\\x%2.2x"%ord(char) for char in value]), ""
+ elif type.startswith("real"):
+ return "%f"%value, ""
+ else:
+ return "0x%X"%value, "\t/* %s */"%str(value)
+
def WriteFile(filepath, content):
cfile = open(filepath,"w")
cfile.write(content)
@@ -178,15 +188,7 @@
texts["suffixe"] = "[%d]"%typeinfos[1]
else:
texts["suffixe"] = ""
- if typeinfos[2] == "visible_string":
- texts["value"] = "\"%s\""%values
- texts["comment"] = ""
- elif typeinfos[2] == "domain":
- texts["value"] = "\"%s\""%''.join(["\\x%2.2x"%ord(char) for char in value])
- texts["comment"] = ""
- else:
- texts["value"] = "0x%X"%values
- texts["comment"] = "\t/* %s */"%str(values)
+ texts["value"], texts["comment"] = ComputeValue(typeinfos[2], values)
if index in variablelist:
texts["name"] = FormatName(subentry_infos["name"])
strDeclareHeader += "extern %(subIndexType)s %(name)s%(suffixe)s;\t\t/* Mapped at index 0x%(index)04X, subindex 0x00*/\n"%texts
@@ -222,34 +224,20 @@
mappedVariableContent += "%(subIndexType)s %(name)s[] =\t\t/* Mapped at index 0x%(index)04X, subindex 0x01 - 0x%(length)02X */\n {\n"%texts
for subIndex, value in enumerate(values):
sep = ","
- comment = ""
if subIndex > 0:
if subIndex == len(values)-1:
sep = ""
- if typeinfos[2] == "visible_string":
- value = "\"%s%s\""%(value, "\\0" * (default_string_size - len(value)))
- elif typeinfos[2] == "domain":
- value = "\"%s\""%''.join(["\\x%2.2x"%ord(char) for char in value])
- else:
- comment = "\t/* %s */"%str(value)
- value = "0x%X"%value
+ value, comment = ComputeValue(typeinfos[2], value)
mappedVariableContent += " %s%s%s\n"%(value, sep, comment)
mappedVariableContent += " };\n"
else:
strIndex += " %(subIndexType)s %(NodeName)s_obj%(index)04X[] = \n {\n"%texts
for subIndex, value in enumerate(values):
sep = ","
- comment = ""
if subIndex > 0:
if subIndex == len(values)-1:
sep = ""
- if typeinfos[2] == "visible_string":
- value = "\"%s%s\""%(value, "\\0" * (default_string_size - len(value)))
- elif typeinfos[2] == "domain":
- value = "\"%s\""%''.join(["\\x%2.2x"%ord(char) for char in value])
- else:
- comment = "\t/* %s */"%str(value)
- value = "0x%X"%value
+ value, comment = ComputeValue(typeinfos[2], value)
strIndex += " %s%s%s\n"%(value, sep, comment)
strIndex += " };\n"
else:
@@ -267,15 +255,7 @@
texts["suffixe"] = "[%d]"%typeinfos[1]
else:
texts["suffixe"] = ""
- if typeinfos[2] == "visible_string":
- texts["value"] = "\"%s%s\""%(value, "\\0" * (default_string_size - len(value)))
- texts["comment"] = ""
- elif typeinfos[2] == "domain":
- texts["value"] = "\"%s\""%''.join(["\\x%2.2x"%ord(char) for char in value])
- texts["comment"] = ""
- else:
- texts["value"] = "0x%X"%value
- texts["comment"] = "\t/* %s */"%str(value)
+ texts["value"], texts["comment"] = ComputeValue(typeinfos[2], value)
texts["name"] = FormatName(subentry_infos["name"])
if index in variablelist:
strDeclareHeader += "extern %(subIndexType)s %(parent)s_%(name)s%(suffixe)s;\t\t/* Mapped at index 0x%(index)04X, subindex 0x%(subIndex)02X */\n"%texts
--- a/objdictgen/node.py Tue Apr 29 13:50:56 2008 +0200
+++ b/objdictgen/node.py Tue Apr 29 13:54:23 2008 +0200
@@ -753,10 +753,42 @@
return True
elif 0 <= subIndex < len(self.UserMapping[index]["values"]) and values != None:
if "type" in values:
- if self.IsStringType(values["type"]) and not self.IsStringType(self.UserMapping[index]["values"][subIndex]["type"]):
- self.SetEntry(index, subIndex, "")
- elif not self.IsStringType(values["type"]) and self.IsStringType(self.UserMapping[index]["values"][subIndex]["type"]):
- self.SetEntry(index, subIndex, 0)
+ if self.UserMapping[index]["struct"] & OD_IdenticalSubindexes:
+ if self.IsStringType(self.UserMapping[index]["values"][subIndex]["type"]):
+ if self.IsRealType(values["type"]):
+ for i in xrange(len(self.Dictionary[index])):
+ self.SetEntry(index, i + 1, 0.)
+ elif not self.IsStringType(values["type"]):
+ for i in xrange(len(self.Dictionary[index])):
+ self.SetEntry(index, i + 1, 0)
+ elif self.IsRealType(self.UserMapping[index]["values"][subIndex]["type"]):
+ if self.IsStringType(values["type"]):
+ for i in xrange(len(self.Dictionary[index])):
+ self.SetEntry(index, i + 1, "")
+ elif not self.IsRealType(values["type"]):
+ for i in xrange(len(self.Dictionary[index])):
+ self.SetEntry(index, i + 1, 0)
+ elif self.IsStringType(values["type"]):
+ for i in xrange(len(self.Dictionary[index])):
+ self.SetEntry(index, i + 1, "")
+ elif self.IsRealType(values["type"]):
+ for i in xrange(len(self.Dictionary[index])):
+ self.SetEntry(index, i + 1, 0.)
+ else:
+ if self.IsStringType(self.UserMapping[index]["values"][subIndex]["type"]):
+ if self.IsRealType(values["type"]):
+ self.SetEntry(index, subIndex, 0.)
+ elif not self.IsStringType(values["type"]):
+ self.SetEntry(index, subIndex, 0)
+ elif self.IsRealType(self.UserMapping[index]["values"][subIndex]["type"]):
+ if self.IsStringType(values["type"]):
+ self.SetEntry(index, subIndex, "")
+ elif not self.IsRealType(values["type"]):
+ self.SetEntry(index, subIndex, 0)
+ elif self.IsStringType(values["type"]):
+ self.SetEntry(index, subIndex, "")
+ elif self.IsRealType(values["type"]):
+ self.SetEntry(index, subIndex, 0.)
self.UserMapping[index]["values"][subIndex].update(values)
return True
return False
@@ -1006,6 +1038,15 @@
return True
return False
+ def IsRealType(self, index):
+ if index in (0x8, 0x11):
+ return True
+ elif 0xA0 <= index < 0x100:
+ result = self.GetEntry(index, 1)
+ if result is not None and result in (0x8, 0x11):
+ return True
+ return False
+
#-------------------------------------------------------------------------------
# Type and Map Variable Lists
#-------------------------------------------------------------------------------
--- a/objdictgen/nodemanager.py Tue Apr 29 13:50:56 2008 +0200
+++ b/objdictgen/nodemanager.py Tue Apr 29 13:54:23 2008 +0200
@@ -675,6 +675,11 @@
node.SetEntry(index, subIndex, int(value))
except:
pass
+ elif editor == "float":
+ try:
+ node.SetEntry(index, subIndex, float(value))
+ except:
+ pass
elif editor == "domain":
try:
if len(value) % 2 != 0:
--- a/objdictgen/subindextable.py Tue Apr 29 13:50:56 2008 +0200
+++ b/objdictgen/subindextable.py Tue Apr 29 13:54:23 2008 +0200
@@ -176,11 +176,9 @@
renderer = wx.grid.GridCellNumberRenderer()
if colname == "value" and "min" in editors and "max" in editors:
editor.SetParameters("%s,%s"%(editors["min"],editors["max"]))
- elif editortype == "real":
- editor = wx.grid.GridCellFloatEditor()
- renderer = wx.grid.GridCellFloatRenderer()
- if colname == "value" and "min" in editors and "max" in editors:
- editor.SetParameters("%s,%s"%(editors["min"],editors["max"]))
+ elif editortype == "float":
+ editor = wx.grid.GridCellTextEditor()
+ renderer = wx.grid.GridCellStringRenderer()
elif editortype == "bool":
editor = wx.grid.GridCellChoiceEditor()
editor.SetParameters(BoolList)