Dimension Decimal Places

Discussions about the development of the TechDraw workbench
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
HoWil
Veteran
Posts: 1279
Joined: Sun Jun 14, 2015 7:31 pm
Location: Austria

Re: Dimension Decimal Places

Post by HoWil »

wandererfan wrote: Tue Sep 26, 2017 4:41 pm How are your preferences set?
Sorry, did not realize that you introduced these settings as switches in the preferences :roll: . Very nice :!:
Many thanks for the very detailed explanation.
Best regards,
Wilfried
reox
Posts: 929
Joined: Sat Aug 13, 2016 10:06 am
Contact:

Re: Dimension Decimal Places

Post by reox »

I wonder why this does not work: https://stackoverflow.com/a/2440708/446140

I checked it by setting it for a dimension, but all I get is this:
2017-11-05-213831_667x383_scrot.png
2017-11-05-213831_667x383_scrot.png (10.8 KiB) Viewed 3710 times
In my opinion, %g would be veeeery convenient for many drawings! (And I just learned that this formatter even exists :shock: )
Attachments
test_dimension.fcstd
(21.02 KiB) Downloaded 267 times
User avatar
wandererfan
Veteran
Posts: 6326
Joined: Tue Nov 06, 2012 5:42 pm
Contact:

Re: Dimension Decimal Places

Post by wandererfan »

reox wrote: Sun Nov 05, 2017 8:40 pm I wonder why this does not work: https://stackoverflow.com/a/2440708/446140

I checked it by setting it for a dimension, but all I get is this:
2017-11-05-213831_667x383_scrot.png

In my opinion, %g would be veeeery convenient for many drawings! (And I just learned that this formatter even exists :shock: )
Because that tip is for python and TechDraw is programmed in C++? You can get your number back by changing the FormatSpec property back to "%.2f". FormatSpec was originally intended to create something like "TextBeforeValue 10.00 TextAfterValue".

What would "%g" give you? In C++ the "g" gives you scientific notation >>> 1.0E+1.
reox
Posts: 929
Joined: Sat Aug 13, 2016 10:06 am
Contact:

Re: Dimension Decimal Places

Post by reox »

yes and no, take a look here: https://en.wikipedia.org/wiki/Printf_fo ... Type_field
double in either normal or exponential notation, [...] This type differs slightly from fixed-point notation in that insignificant zeroes to the right of the decimal point are not included. Also, the decimal point is not included on whole numbers.
(a better explaination is here: http://en.cppreference.com/w/cpp/io/c/fprintf)

Take a look at this example:

Code: Select all

#include <stdio.h>

int main() {
    int x = 10;
    double z = 23.1;
    float y = 23.001;
    double bla = 42.23;
    double foo = 42.0;

    printf("10 --> %g\n", x);
    printf("23.001 --> %g\n", y);
    printf("23.1 --> %g\n", z);
    printf("42.23 --> %g\n", bla);
    printf("42.0 --> %g\n", foo);

    return 0;
}

Code: Select all

10 --> 6.95325e-310
23.001 --> 23.001
23.1 --> 23.1
42.23 --> 42.23
42.0 --> 42
using gcc (Debian 7.2.0-12) 7.2.1 20171025

In this example, only the integer got converted to exponential notation.
But this can be controlled via the precision. It basically gives a value how large the number can be until it is formatted as exponent.

Here is the magic in the techdraw code: https://github.com/FreeCAD/FreeCAD/blob ... n.cpp#L227
thus %.g / %.2g works very well, but everything without a dot fails...
Looks like the regex should be a little bit different maybe? The dot is conditional in this case, but the formatters for length are not.
2017-11-07-070630_581x396_scrot.png
2017-11-07-070630_581x396_scrot.png (30.1 KiB) Viewed 3664 times
I checked in a recent drawing, that %.5g would work very well. See this (very messy) drawing:
2017-11-07-071124_790x788_scrot.png
2017-11-07-071124_790x788_scrot.png (49.74 KiB) Viewed 3662 times
I'm using a macro now to set this value in my drawings - would be very nice to define a default. (I do not see an option in the preferences...)
User avatar
babaroga
Posts: 180
Joined: Sun Aug 14, 2016 6:52 pm
Location: Banja Luka, Republic of Srpska, Bosnia and Herzegovina

Re: Dimension Decimal Places

Post by babaroga »

Hey, %.5g really works nice. Possibility to choose default format will increase usability of TechDraw WB a lot.

Thank you for tip.
reox
Posts: 929
Joined: Sat Aug 13, 2016 10:06 am
Contact:

Re: Dimension Decimal Places

Post by reox »

For now, here is my macro:

Code: Select all

for v in App.activeDocument().findObjects("TechDraw::DrawViewDimension"):
	v.LineWidth = 0.25
	v.FormatSpec = u"%.5g"
I also reduce the line width, as the normal width is too large I think (should be 0,25 for group 0.5 and 0,35 for group 0.7)

a little bit OT here, but speaking of linewidth and so on: The heigth of text has also a norm (EN ISO 3098-0) and 4mm (the default) is not an option. 3.5mm is allowed and probably also prefered for A4 to A2 (not sure about that).
The size of the arrow should be the same as the text height too (the default is 5mm).
If you are going total fancy with the TechDraw Workbench, you could add the option to choose a linegroup (e.g. 0.5 or 0.7 as they are preferred) and the rest is automatically choosen - like text height, line width, arrow size etc...
User avatar
wandererfan
Veteran
Posts: 6326
Joined: Tue Nov 06, 2012 5:42 pm
Contact:

Re: Dimension Decimal Places

Post by wandererfan »

reox wrote: Tue Nov 07, 2017 5:58 am thus %.g / %.2g works very well, but everything without a dot fails...
Looks like the regex should be a little bit different maybe? The dot is conditional in this case, but the formatters for length are not.
should be fixed by git commit 9d038dd
User avatar
babaroga
Posts: 180
Joined: Sun Aug 14, 2016 6:52 pm
Location: Banja Luka, Republic of Srpska, Bosnia and Herzegovina

Re: Dimension Decimal Places

Post by babaroga »

Is there a way to make %g default?
User avatar
wandererfan
Veteran
Posts: 6326
Joined: Tue Nov 06, 2012 5:42 pm
Contact:

Re: Dimension Decimal Places

Post by wandererfan »

babaroga wrote: Mon Nov 13, 2017 4:17 pm Is there a way to make %g default?
No, but I guess it could be added as a setting in user.cfg. I'll add it to my list, but no promises on delivery date.
User avatar
-alex-
Veteran
Posts: 1861
Joined: Wed Feb 13, 2019 9:42 pm
Location: France

Re: Dimension Decimal Places

Post by -alex- »

Just for general information (I can't find any related topic mentioning about following point): I assume @wandererfan&friends did the job, now it's pretty easy to set the precision of dimensions in drawings.
Go to Tools->Parameter editor -> Preferences/Mod/TechDraw/Dimensions -> formatSpec

For now the default value is null, which leads to %.2f in dimensions of drawings (which gives 2 decimals, not significant zero included).
But if you want dimensions with only significant decimals by default just set formatSpec = %.g
BTW if you have 10,25 then you want to see 10,250: just set formatSpec = %.3f
Of course that's possible to modify formatSpec value for each dimension separately in formatSpec property of dimension object.
Post Reply