Materials dialogue problem

About the development of the FEM module/workbench.

Moderator: bernd

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

Re: Materials dialogue problem

Postby lambda » Mon Oct 16, 2017 7:32 pm

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
Posts: 840
Joined: Sun Jun 14, 2015 7:31 pm
Location: Austria

Re: Materials dialogue problem

Postby HoWil » Tue Oct 17, 2017 7:17 pm

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: 34
Joined: Sat Feb 25, 2017 3:10 pm
Contact:

Re: Materials dialogue problem

Postby lambda » Wed Oct 18, 2017 5:35 pm

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
Posts: 840
Joined: Sun Jun 14, 2015 7:31 pm
Location: Austria

Re: Materials dialogue problem

Postby HoWil » Wed Oct 18, 2017 6:08 pm

lambda wrote:
Wed Oct 18, 2017 5:35 pm
I will do
THX a lot :!:
lambda wrote:
Wed Oct 18, 2017 5:35 pm
but 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
Posts: 8468
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland

Re: Materials dialogue problem

Postby bernd » Wed Oct 18, 2017 6:10 pm

@HoWil:

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

Re: Materials dialogue problem

Postby lambda » Wed Oct 18, 2017 9:05 pm

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
Posts: 8468
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland

Re: Materials dialogue problem

Postby bernd » 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
HoWil
Posts: 840
Joined: Sun Jun 14, 2015 7:31 pm
Location: Austria

Re: Materials dialogue problem

Postby HoWil » Mon Oct 23, 2017 6:59 pm

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
Posts: 8468
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland

Re: Materials dialogue problem

Postby bernd » Mon Oct 23, 2017 9:23 pm

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

Re: Materials dialogue problem

Postby HoWil » Wed Oct 25, 2017 11:09 am

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