HoWil wrote: ↑Wed Oct 18, 2017 6:08 pm
as everywhere.
Actually, it is particularly bad for me at the moment.
Simply open the Fluild material dialogue with Air as depicted in my first post. Close it and reopen it again. Now check if the values have changed.
Look for changes like:
-Values grow each time you reopen ... 1.2 becomes 12 and 120
-Values are reset 0.02 becomes 0 or 1000
-Values are lost 0.054 becomes 0.05
The point would have been for you to tell us what you see (and in which locale) so that we can compare. Not to tell us where to look.
Anyway still hadn't time to test your changes, but got around to dissect the code a bit in the python console. Insights:
1. "{} {}".format(...) returns a standard string object, while Quantity.UserString returns an unicode string object. This might behave differently with respect to locales. However u"{} {}".format(...) (mind that 'u'!) also returns an unicode string object without any other changes in behaviour. So that would be the cleaner fix if this is actually the problem.
2. greping "{} {}".format(...) shows that the lines which you change are the only times where this construct is used in the entire code of FreeCAD. Looks quite fishy to me.
3. However, using Quantity.UserString as I suggested doesn't seem to work either. Actually, it seems that Quantity.UserString is where precision gets lost. See the transscript below.
4. I have the gut feeling that the code as is, is intended to work around the problem of Quantity.UserString, but accidentally dropped unicode support (no greek symbols anymore) and maybe has some sideeffects wrt locales. Your fix restores unicode support, but totally neutralized the workaround, because Quantity.UserString again is responsible for formatting. I hope that the proper Quantity-aware input widget from the wiki is solving this, but I don't know anything about this yet. - If you want a quick fix, I suggest to try prefixing the format string with 'u' as I have shown above.
Here is the transscript of my test session:
Code: Select all
>>> sh = FreeCAD.Units.Quantity(App.ActiveDocument.FluidMaterial.Material['SpecificHeat'])
>>> sh
1.005e+06 mm^2/(s^2*K)
>>> shnu = "J/kg/K"
>>> shwnu = sh.getValueAs(shnu)
>>> shwnu
1.005
>>> "{} {}".format(shwnu, shnu)
'1.005 J/kg/K'
>>> sh.UserString
u'1.00 J/kg/K'
>>> sh.getUserPreferred()
(u'1.00 J/kg/K', 1000000.0, u'J/kg/K')
>>> q = FreeCAD.Units.Quantity("{} {}".format(shwnu, shnu))
>>> q
1.005e+06 mm^2/(s^2*K)
>>> q.UserString
u'1.00 J/kg/K'
>>> u"{} {}".format(shwnu, shnu)
u'1.005 J/kg/K'