[Feature] New format specifier '%w' for Dimension values

Discussions about the development of the TechDraw workbench
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
aapo
Posts: 612
Joined: Mon Oct 29, 2018 6:41 pm

[Feature] New format specifier '%w' for Dimension values

Post by aapo »

Hello!

I propose to add a new format specifier '%w' for Dimension values. It's a mixture between the standard formats '%f' and '%g', and it works like '%f', except that it removes trailing zeros like '%g', but without the other properties of '%g'. That way, it'd be possible to have, e.g., a dimension specifier '%.2w', which would print at most 2 decimals after dot, but cut away any trailing zeros. The problem with '%.2g' is that it gives 2 significant digits, not 2 digits after dot like '%.2f' (and the newly proposed '%.2w'). I use this kind of formatting style a lot (i.e. fixed number of decimals, but trailing zeros removed), so I wrote a small patch that adds this kind of new format specifier. The picture below shows the differences between the 3 formats, I hope it makes my explanation more clear! :D


20220122_FreeCAD_TechDraw_formatspec_w_p02.png
20220122_FreeCAD_TechDraw_formatspec_w_p02.png (22.98 KiB) Viewed 2601 times
Last edited by aapo on Fri Feb 18, 2022 2:12 pm, edited 2 times in total.
aapo
Posts: 612
Joined: Mon Oct 29, 2018 6:41 pm

Re: [Feature proposal] New format specifier '%w' for Dimension values

Post by aapo »

Here is the pull request, test away please! https://github.com/FreeCAD/FreeCAD/pull/5401
aapo
Posts: 612
Joined: Mon Oct 29, 2018 6:41 pm

Re: [Feature proposal] New format specifier '%w' for Dimension values

Post by aapo »

Here is a test case, where all dimension values have the same format specifier '%.2w'. Note that there are values like "50", "36.6", "0.5", which all have one or more trailing zeros removed.
20220122_FreeCAD_TechDraw_formatspec_w_p01.png
20220122_FreeCAD_TechDraw_formatspec_w_p01.png (134.41 KiB) Viewed 2581 times
balrobs
Posts: 449
Joined: Fri Apr 24, 2020 8:58 pm

Re: [Feature proposal] New format specifier '%w' for Dimension values

Post by balrobs »

IMHO this would be a handy feature!
Thanks for the pull request.
BTW your bear face gave me a good mood :D
User avatar
wandererfan
Veteran
Posts: 6238
Joined: Tue Nov 06, 2012 5:42 pm
Contact:

Re: [Feature proposal] New format specifier '%w' for Dimension values

Post by wandererfan »

aapo wrote: Thu Jan 20, 2022 4:26 pm Here is the pull request, test away please! https://github.com/FreeCAD/FreeCAD/pull/5401
git commit 253817e3

Thank you!
openBrain
Veteran
Posts: 9031
Joined: Fri Nov 09, 2018 5:38 pm
Contact:

Re: [Feature proposal] New format specifier '%w' for Dimension values

Post by openBrain »

Time for documentation guys. :D
aapo
Posts: 612
Joined: Mon Oct 29, 2018 6:41 pm

Re: [Feature proposal] New format specifier '%w' for Dimension values

Post by aapo »

wandererfan wrote: Fri Jan 21, 2022 4:31 pm git commit 253817e3

Thank you!
Thanks for merging! :)
aapo
Posts: 612
Joined: Mon Oct 29, 2018 6:41 pm

Re: [Feature proposal] New format specifier '%w' for Dimension values

Post by aapo »

openBrain wrote: Fri Jan 21, 2022 5:07 pm Time for documentation guys. :D
That's a good point. Where and how exactly should this be documented, is there a wiki or something I should add this?
openBrain
Veteran
Posts: 9031
Joined: Fri Nov 09, 2018 5:38 pm
Contact:

Re: [Feature proposal] New format specifier '%w' for Dimension values

Post by openBrain »

aapo wrote: Fri Jan 21, 2022 5:56 pm That's a good point. Where and how exactly should this be documented, is there a wiki or something I should add this?
https://wiki.freecadweb.org/TechDraw_Le ... Formatting looks like a good candidate to me. Especially because you introduced a specifier which isn't C standard, hence not covered by current doc. ;)
Post Reply