Fixed bug when graphic element position and size and connection points are decimal
authorLaurent Bessard
Thu, 07 Nov 2013 00:31:46 +0100
changeset 1373 4278d5c1e414
parent 1372 ef26fcb7f5d4
child 1374 1eefc427419f
Fixed bug when graphic element position and size and connection points are decimal
PLCControler.py
xmlclass/xsdschema.py
--- a/PLCControler.py	Thu Nov 07 00:16:00 2013 +0100
+++ b/PLCControler.py	Thu Nov 07 00:31:46 2013 +0100
@@ -387,14 +387,14 @@
         self.SpecificValues = None
         
         self.CurrentInstance = _BlockInstanceInfos(
-            *(_translate_args([str] + [int] * 5, args) + 
+            *(_translate_args([str, int] + [float] * 4, args) + 
               [specific_values, [], []]))
         
         self.BlockInstances[self.CurrentInstance.id] = self.CurrentInstance
         
     def AddInstanceConnection(self, context, *args):
         connection_args = _translate_args(
-            [str, str, _BoolValue, str, int, int], args)
+            [str, str, _BoolValue, str, float, float], args)
         
         self.CurrentConnection = _InstanceConnectionInfos(
             *(connection_args[1:4] + [
@@ -415,7 +415,7 @@
     
     def AddLinkPoint(self, context, *args):
         self.CurrentLink.points.append(_Point(
-            *_translate_args([int, int], args)))
+            *_translate_args([float] * 2, args)))
     
     def AddAction(self, context, *args):
         if len(self.SpecificValues) == 0:
--- a/xmlclass/xsdschema.py	Thu Nov 07 00:16:00 2013 +0100
+++ b/xmlclass/xsdschema.py	Thu Nov 07 00:31:46 2013 +0100
@@ -44,14 +44,15 @@
         return text
     return generateXMLTextMethod
 
-def GenerateFloatXMLText(extra_values=[]):
+def GenerateFloatXMLText(extra_values=[], decimal=None):
+    float_format = ("{:.%dg}" % decimal).format if decimal is not None else str
     def generateXMLTextMethod(value, name=None, indent=0):
         text = ""
         if name is not None:
             ind1, ind2 = getIndent(indent, name)
             text += ind1 + "<%s>" % name
         if value in extra_values or value % 1 != 0 or isinstance(value, IntType):
-            text += str(value)
+            text += float_format(value)
         else:
             text += "%.0f" % value
         if name is not None:
@@ -2269,7 +2270,7 @@
         "basename": "decimal",
         "extract": GenerateFloatExtraction("decimal"),
         "facets": DECIMAL_FACETS,
-        "generate": GenerateFloatXMLText(),
+        "generate": GenerateFloatXMLText(decimal=3),
         "initial": lambda: 0.,
         "check": lambda x: isinstance(x, (IntType, FloatType))
     },