[fixed] [regression] number of decimals not taken into account

Discussions about the development of the TechDraw workbench
User avatar
uwestoehr
Posts: 1361
Joined: Sun Jan 27, 2019 3:21 am

[fixed] [regression] number of decimals not taken into account

Postby uwestoehr » Tue Mar 24, 2020 6:52 pm

- set in the TD preferences to use alternate decimals and set it to "3":
FreeCAD_YsEAf4mPEL.png
TD settings
FreeCAD_YsEAf4mPEL.png (2.14 KiB) Viewed 261 times
- add new dimensions

result: the dimension has 2 digits, not 3

- now set in the TD preferences to use "global decimals"
- set in the general preferences to use 3 decimal places

- add new dimensions

result: the dimension has 2 digits, not 3
This is a regression to prior versions of FC 0.19 (must have been introduced recently).

OS: Windows 10 (10.0)
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.19.20264 (Git)
Build type: Release
Branch: master
Hash: 107831e0a7769b4f09e2f8fdb0f8b59d100114dd
Python version: 3.6.8
Qt version: 5.12.1
Coin version: 4.0.0a
OCC version: 7.3.0
Locale: German/Germany (de_DE)
Last edited by uwestoehr on Sat Mar 28, 2020 1:20 pm, edited 1 time in total.
User avatar
wandererfan
Posts: 3640
Joined: Tue Nov 06, 2012 5:42 pm

Re: [regression] number of decimals not taken into account

Postby wandererfan » Tue Mar 24, 2020 10:15 pm

uwestoehr wrote:
Tue Mar 24, 2020 6:52 pm
result: the dimension has 2 digits, not 3
This is a regression to prior versions of FC 0.19 (must have been introduced recently).
What is the preference for "FormatSpec"? If that is set to 2 digits, then "Use global decimals" and "Alternate decimals" are ignored.
User avatar
uwestoehr
Posts: 1361
Joined: Sun Jan 27, 2019 3:21 am

Re: [regression] number of decimals not taken into account

Postby uwestoehr » Wed Mar 25, 2020 12:34 am

wandererfan wrote:
Tue Mar 24, 2020 10:15 pm
What is the preference for "FormatSpec"? If that is set to 2 digits, then "Use global decimals" and "Alternate decimals" are ignored.
But this contradicts the setting to use the global digits. I reset now me preferences and get this:
FreeCAD_X6TYEVihXF.png
initial prefs
FreeCAD_X6TYEVihXF.png (7.32 KiB) Viewed 222 times

So the default settings are to use the system-wide digits. I set them to 3 digits because I need this. Since this is a purpose decision, the TD prefs must take it into account and set the format accordingly.
I'll have a quick look if I could fix it.
User avatar
uwestoehr
Posts: 1361
Joined: Sun Jan 27, 2019 3:21 am

Re: [regression] number of decimals not taken into account

Postby uwestoehr » Wed Mar 25, 2020 2:43 am

uwestoehr wrote:
Wed Mar 25, 2020 12:34 am
I'll have a quick look if I could fix it.
Here's a PR: https://github.com/FreeCAD/FreeCAD/pull/3260
that does this:
QB0llxSAJG.gif
QB0llxSAJG.gif (39.14 KiB) Viewed 212 times

So if there is a dot in the format, the first char after the dot is updated to either the global decimals or the specified alternate decimals.
Moreover when the update is also done when the dialog is loaded. This is important because of the use changed the system-wide decimals, TD might not have been loaded and can therefor not use the new value. So at least when the user opens the preferences, it will update to use the system-wide decimals.

What in my opinion is still missing is that in DrawViewDimension, the format is not used if its decimal number differs from that of the system-wide settings. This should be the case because the system-wide or alternate setting must actually be used, if the user set to use it. This can be for the cost that the current format is not used, but not the other way round as it is at the moment.

Could you please have a look? and also if my PR makes sense to you?
User avatar
babaroga
Posts: 89
Joined: Sun Aug 14, 2016 6:52 pm
Location: Banja Luka, Republic of Srpska, Bosnia and Herzegovina

Re: [regression] number of decimals not taken into account

Postby babaroga » Wed Mar 25, 2020 12:19 pm

Hello,
In my usecase (furniture industry), I don't use fixed number of decimals.

So instead if %.2f i am using %.g. So if number is integer, it does not show any decimals.

So generally if I have some part wit eg. dimensions:
Screenshot_20200325_130725.png
Screenshot_20200325_130725.png (28.48 KiB) Viewed 163 times

... and I pad it to 10 mm, I get:

Screenshot_20200325_131110.png
Screenshot_20200325_131110.png (9.9 KiB) Viewed 163 times

So, maximum number of shown decimals is adjusted here:

Screenshot_20200325_131335.png
Screenshot_20200325_131335.png (67.33 KiB) Viewed 163 times

If you have more decimals than in this settings, they will be rounded. So, if there is eg. set 1 decimal, you will get:

Screenshot_20200325_131632.png
Screenshot_20200325_131632.png (9.33 KiB) Viewed 163 times

So, please, don't touch anything.
User avatar
uwestoehr
Posts: 1361
Joined: Sun Jan 27, 2019 3:21 am

Re: [regression] number of decimals not taken into account

Postby uwestoehr » Wed Mar 25, 2020 12:22 pm

uwestoehr wrote:
Wed Mar 25, 2020 2:43 am
Here's a PR: https://github.com/FreeCAD/FreeCAD/pull/3260
I see now an issue with my patch: I don't check if the first character after the dot is a number. This is necessary because the format could e.g. be "%.g".
-> I'll update the patch later today.
User avatar
uwestoehr
Posts: 1361
Joined: Sun Jan 27, 2019 3:21 am

Re: [regression] number of decimals not taken into account

Postby uwestoehr » Wed Mar 25, 2020 12:46 pm

babaroga wrote:
Wed Mar 25, 2020 12:19 pm
So instead if %.2f i am using %.g. So if number is integer, it does not show any decimals.
This could be a clean solution: TD uses "%.g" as default. If the user changes this format he knows what he is doing.

The issue is only that "%.g" takes always as many decimals as set system-wide. if the user set in the preferences to use e.g. 4 alternate decimals, "%.g" ignores this setting.

Wandererfan, do you see a method that "%.g" will take the alternate decimals as well? If yes, then "%.g" as default is in my opinion the clean solution.
User avatar
babaroga
Posts: 89
Joined: Sun Aug 14, 2016 6:52 pm
Location: Banja Luka, Republic of Srpska, Bosnia and Herzegovina

Re: [regression] number of decimals not taken into account

Postby babaroga » Wed Mar 25, 2020 1:11 pm

It can be option for %.g , or fixed number of decimals with %.[something]f.
Eg, checkbox "fixed number of decimals" switch default format to%.[something]f . I think similar solution is offered in AutoCAD.
User avatar
uwestoehr
Posts: 1361
Joined: Sun Jan 27, 2019 3:21 am

Re: [regression] number of decimals not taken into account

Postby uwestoehr » Thu Mar 26, 2020 1:18 am

uwestoehr wrote:
Wed Mar 25, 2020 12:46 pm
Wandererfan, do you see a method that "%.g" will take the alternate decimals as well? If yes, then "%.g" as default is in my opinion the clean solution.
If this is not possible that "%.g" would also take the alternate decimals, my updated PR: https://github.com/FreeCAD/FreeCAD/pull/3260
is the best solution because it assures that always the set number of decimals will be used (for the cost that the format is lost of course). But at the moment the default format is "%.2f" and is blocking any change in the number of decimals.
User avatar
wandererfan
Posts: 3640
Joined: Tue Nov 06, 2012 5:42 pm

Re: [regression] number of decimals not taken into account

Postby wandererfan » Thu Mar 26, 2020 12:32 pm

uwestoehr wrote:
Thu Mar 26, 2020 1:18 am
is the best solution because it assures that always the set number of decimals will be used (for the cost that the format is lost of course). But at the moment the default format is "%.2f" and is blocking any change in the number of decimals.
This is the solution I intend to use:
- move default format spec to Advanced property tab and initialize it to blank.
- if formatSpec preference is blank, use global decimals or alternate decimals as specified on Dimension tab to build the initial formatSpec for each dimension.
- if formatSpec preference is not blank, use the formatSpec as specified in the preference.

- for average users, there is a simple choice of A or B
- if a user is advanced enough to go looking for formatSpec and compose a printf format string, then they are assumed to know what they are doing, and we just use the specified string.