Materials dialogue problem

About the development of the FEM module/workbench.

Moderator: bernd

lambda
Posts: 91
Joined: Sat Feb 25, 2017 3:10 pm
Contact:

Re: Materials dialogue problem

Post by lambda »

Hi,

I haven't had time to test you changes yet. However some remarks from just looking at code that I mostly don't understand:

1. I think the code you propose is just a complicated version of saying

Code: Select all

        if 'Density' in matmap:
            density = FreeCAD.Units.Quantity(matmap['Density'])
            self.form.input_fd_density.setText(density.UserString)
2. I guess this could fix a locale issue if there is one or any other issue with formating - I'm not fluent in python enough to predict what the old code actually did without trying. However given our conversation above it is unclear to me, what the issues actually are.
3. The wiki suggests that the dialog should use https://www.freecadweb.org/wiki/InputField instead of a text field. Maybe that option should be explored also.

HTH,
Harald
HoWil
Veteran
Posts: 1279
Joined: Sun Jun 14, 2015 7:31 pm
Location: Austria

Re: Materials dialogue problem

Post by HoWil »

bernd wrote: Ping
Could you please test this. Its really important for me.

@Harald: Yes, it is for sure not implemented optimally. I am a skript kiddy just copy pasting stuff I find somewhere :D . But it works :!:
@Bernd: Do you know a bit more about the mentioned InputFields (instead of text-fields)? I thought all fields with units are InputFields?

BR,
HoWil
lambda
Posts: 91
Joined: Sat Feb 25, 2017 3:10 pm
Contact:

Re: Materials dialogue problem

Post by lambda »

HoWil wrote: Tue Oct 17, 2017 7:17 pm Could you please test this. Its really important for me.
I will do, but I'm on a tight schedule at the moment and have a hard time fitting FLOSS work into the breaks between my job. However it would help a lot, if you could describe which tests you did already yourself and what the results have been.

Harald
HoWil
Veteran
Posts: 1279
Joined: Sun Jun 14, 2015 7:31 pm
Location: Austria

Re: Materials dialogue problem

Post by HoWil »

lambda wrote: Wed Oct 18, 2017 5:35 pm I will do
THX a lot :!:
lambda wrote: Wed Oct 18, 2017 5:35 pmbut I'm on a tight schedule at the moment and have a hard time fitting FLOSS work into the breaks between my job.
8-) as everywhere. :o
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
BR
HoWil
User avatar
bernd
Veteran
Posts: 12851
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: Materials dialogue problem

Post by bernd »

@HoWil:

as soon as the unit test for elmer is finished I will have a look at this here too.
lambda
Posts: 91
Joined: Sat Feb 25, 2017 3:10 pm
Contact:

Re: Materials dialogue problem

Post by lambda »

HoWil wrote: Wed Oct 18, 2017 6:08 pm 8-) as everywhere. :o
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'
User avatar
bernd
Veteran
Posts: 12851
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: Materials dialogue problem

Post by bernd »

@HoWil:

Does your commit fixes one of the problems described here? https://github.com/berndhahnebach/FreeC ... t/c8262347
HoWil
Veteran
Posts: 1279
Joined: Sun Jun 14, 2015 7:31 pm
Location: Austria

Re: Materials dialogue problem

Post by HoWil »

bernd wrote: Thu Oct 19, 2017 6:16 pm @HoWil:

Does your commit fixes one of the problems described here? https://github.com/berndhahnebach/FreeC ... t/c8262347
Yes, the above linked commit does solve the units problem in the material dialog (discussed/described in this post here) for me.
If nobody else does experience new problems, then it should be fixed.
BR
Howil
User avatar
bernd
Veteran
Posts: 12851
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: Materials dialogue problem

Post by bernd »

Cool, have you read my pm in the regard of commiter mail?
HoWil
Veteran
Posts: 1279
Joined: Sun Jun 14, 2015 7:31 pm
Location: Austria

Re: Materials dialogue problem

Post by HoWil »

bernd wrote: Mon Oct 23, 2017 9:23 pm Cool, have you read my pm in the regard of commiter mail?
Yes, will change that this evening or tomorrow.
BR
Wilfried
Post Reply