pcb

Comment 10 for bug 1806044

Revision history for this message
Chad Parker (parker-charles) wrote :

So, the output of the file is a mix of mils and inches. I think you were on the right track yesterday. The line:

ALLOW_ALL = ~ALLOW_DMIL

means that DMIL isn't generally allowed. I suspect that the reason for this is that when the feature was added (3a8891a6) they didn't want the "most natural unit" to suddenly start selecting and outputting dmil in places where it wasn't before. However, clearly this means that "most natural unit" doesn't work with dmil. "Most natural unit" uses the following line to generate its output (bom.c:617):

                case 'S': unit_str = CoordsToString(value, 1, spec->str, mask & ALLOW_ALL, suffix); break;

The value of "mask" is set by the earlier format to ALLOW_DMIL, so mask & ALLOW_ALL -> 0. So, CoordsToString gets told that no units are allowed, which by default it assumes to mean that ALLOW_ALL units are allowed, which excludes dmil.

I see a couple of possible solutions:

1. Change ALLOW_ALL to ~0 instead of ~ALLOW_DMIL.
This seems like a reasonable thing to do, except that it may cause other output to switch to dmil, which we don't generally want.

2. Change ALLOW_ALL to ~0 and add an ALLOW_COMMON = ~ALLOW_DMIL, update the 'S' specifier to use ALLOW_COMMON, and add a new format specifier that actually allows any unit to be used with a natural scaling.

3. Dynamically generate the format string in bom.c using the format specifier that the user requested.
I think this is the easiest. The line:
char fmt[256];

sprintf(fmt, "%%s,\"%%s\",\"%%s\",%%.2`m%c,%%.2`m%c,%%g,%%s\n", xy_unit->printf_code, xy_unit->printf_code);

at the top of PrintBOM does the trick, then use fmt as the format string in the pcb_fprintf call.

I've pushed a branch LP1806044 that takes care of this. It also adds some additional tests for various units.