Units for data entry


#1

I’m working on several scripts that will have units specified by the user. Am I missing any common measurement units or variations?

    'nm':1,
    'nano':1,
    'nanometer':1,
    'um':pcbnew.IU_PER_MM/1000.0,
    'micron':pcbnew.IU_PER_MM/1000.0,
    'micrometer':pcbnew.IU_PER_MM/1000.0,
    'mm':pcbnew.IU_PER_MM,
    'millimeter':pcbnew.IU_PER_MM,
    'milli':pcbnew.IU_PER_MM,
    'm':pcbnew.IU_PER_MM,
    'mil':pcbnew.IU_PER_MILS,
    'mils':pcbnew.IU_PER_MILS,
    'in':pcbnew.IU_PER_MILS*1000.0,
    'inch':pcbnew.IU_PER_MILS*1000.0,
    'inches':pcbnew.IU_PER_MILS*1000.0,
    "'":pcbnew.IU_PER_MILS*1000.0*12, # feet
    '"':pcbnew.IU_PER_MILS*1000.0, # inches
    
    # squared versions of measurements (three types: 2, **2, ^2)
    
    'nm2':1
    'nano2':1,
    'nanometer2':1,
    'um2':(pcbnew.IU_PER_MM/1000.0)**2,
    'micron2':(pcbnew.IU_PER_MM/1000.0)**2,
    'micrometer2':(pcbnew.IU_PER_MM/1000.0)**2,
    'mm2':(pcbnew.IU_PER_MM)**2,
    'millimeter2':(pcbnew.IU_PER_MM)**2,
    'milli2':(pcbnew.IU_PER_MM)**2,
    'm2':(pcbnew.IU_PER_MM)**2,
    'mil2':(pcbnew.IU_PER_MILS)**2,
    'mils2':(pcbnew.IU_PER_MILS)**2,
    'in2':(pcbnew.IU_PER_MILS*1000.0)**2,
    'inch2':(pcbnew.IU_PER_MILS*1000.0)**2,
    'inches2':(pcbnew.IU_PER_MILS*1000.0)**2,
    "'2":(pcbnew.IU_PER_MILS*1000.0*12)**2, # feet
    '"2':(pcbnew.IU_PER_MILS*1000.0)**2, # inches
    
    'nm**2':1
    'nano**2':1,
    'nanometer**2':1,
    'um**2':(pcbnew.IU_PER_MM/1000.0)**2,
    'micron**2':(pcbnew.IU_PER_MM/1000.0)**2,
    'micrometer**2':(pcbnew.IU_PER_MM/1000.0)**2,
    'mm**2':(pcbnew.IU_PER_MM)**2,
    'millimeter**2':(pcbnew.IU_PER_MM)**2,
    'milli**2':(pcbnew.IU_PER_MM)**2,
    'm**2':(pcbnew.IU_PER_MM)**2,
    'mil**2':(pcbnew.IU_PER_MILS)**2,
    'mils**2':(pcbnew.IU_PER_MILS)**2,
    'in**2':(pcbnew.IU_PER_MILS*1000.0)**2,
    'inch**2':(pcbnew.IU_PER_MILS*1000.0)**2,
    'inches**2':(pcbnew.IU_PER_MILS*1000.0)**2,
    "'**2":(pcbnew.IU_PER_MILS*1000.0*12)**2, # feet
    '"**2':(pcbnew.IU_PER_MILS*1000.0)**2, # inches
    
    'nm^2':1
    'nano^2':1,
    'nanometer^2':1,
    'um^2':(pcbnew.IU_PER_MM/1000.0)**2,
    'micron^2':(pcbnew.IU_PER_MM/1000.0)**2,
    'micrometer^2':(pcbnew.IU_PER_MM/1000.0)**2,
    'mm^2':(pcbnew.IU_PER_MM)**2,
    'millimeter^2':(pcbnew.IU_PER_MM)**2,
    'milli^2':(pcbnew.IU_PER_MM)**2,
    'm^2':(pcbnew.IU_PER_MM)**2,
    'mil^2':(pcbnew.IU_PER_MILS)**2,
    'mils^2':(pcbnew.IU_PER_MILS)**2,
    'in^2':(pcbnew.IU_PER_MILS*1000.0)**2,
    'inch^2':(pcbnew.IU_PER_MILS*1000.0)**2,
    'inches^2':(pcbnew.IU_PER_MILS*1000.0)**2,
    "'^2":(pcbnew.IU_PER_MILS*1000.0*12)**2, # feet
    '"^2':(pcbnew.IU_PER_MILS*1000.0)**2, # inches

#2

If you are working with physical units, you might want to check out the pint Python library.


#3

Thank you, devbisme!

pint looks very interesting! I’m trying to do only length and area conversions suitable with pcbnew, with no dependencies to install for the average KiCad user.

If I get to the point of figuring out how to teach others how to install dependencies, I’ll take a look at pint!


#4

If you are going so far as to implement three notations for nanometer and micrometer, you could as well implement ‘thou’ for 1 mil.


#5

Hi,

I do not know for what that is going to be used, but if you list Mils and Inches as well as Microns and Millimeters ¿ what about Centimeter ?

I just ask because 1 Inch equals 2.54cm :slight_smile:

regards Rainer


#6

Thanks ikletti and rsfoto! cm and thou are added!


#7

“m” is for meter, not for milli meter.
centimeter [cm] is often used by “common people” but not much by engineers. They tend to stick to exponents with multiples of 3.
And cm is in lower case. not Centi…

Also, have you considered a default unit for cases the user does not explicitly specify a unit?
The most logical is probably to copy the settings from “Set units to mm/Inch” in the left margin when in EEschem / PcbNew. Maybe “guess” them from the locale when it is for external tools


#8

Thank you! Yes, I forgot the *1000 for ‘m’. I know the “centi”, “milli”, and “nano” are not really proper (they’re only prefixes), but I’ve included them just in case. I changed the code to generate the squared values automatically. The non-squared list is now:

'':1,
'nm':1,
'nano':1,
'nanometer':1,
'nanometers':1,
'um':pcbnew.IU_PER_MM/1000.0,
'micron':pcbnew.IU_PER_MM/1000.0,
'microns':pcbnew.IU_PER_MM/1000.0,
'micrometer':pcbnew.IU_PER_MM/1000.0,
'micrometers':pcbnew.IU_PER_MM/1000.0,
'mm':pcbnew.IU_PER_MM,
'millimeter':pcbnew.IU_PER_MM,
'millimeters':pcbnew.IU_PER_MM,
'milli':pcbnew.IU_PER_MM,
'm':pcbnew.IU_PER_MM*1000,
'meter':pcbnew.IU_PER_MM*1000,
'meters':pcbnew.IU_PER_MM*1000,
'thou':pcbnew.IU_PER_MILS,
'mil':pcbnew.IU_PER_MILS,
'mils':pcbnew.IU_PER_MILS,
'cm':pcbnew.IU_PER_MM*10,
'centi':pcbnew.IU_PER_MM*10,
'centimeter':pcbnew.IU_PER_MM*10,
'centimeters':pcbnew.IU_PER_MM*10,
'in':pcbnew.IU_PER_MILS*1000.0,
'inch':pcbnew.IU_PER_MILS*1000.0,
'inches':pcbnew.IU_PER_MILS*1000.0,
"'":pcbnew.IU_PER_MILS*1000.0*12, # feet
'"':pcbnew.IU_PER_MILS*1000.0, # inches

#9

further food for thought:

eagle binary formats use 0.1 micron units

kicad legacy uses decimils, dmil, 0.1mil, and

pcb-rnd / gEDA PCB uses centimils, cmil, 0.01mil, for element dimensions in the absence of units in […] brackets, .

otherwise your list would cover most use cases.

pcb-rnd and gEDA PCB define these units in the units.h file:

http://igor2.repo.hu/cgi-bin/minisvn.cgi?cmd=cat&repo=pcb-rnd&path=trunk/src/unit.h

Cheers,

Erich.


#10

This will be used for data entry and file formats for dealing with dimensions in KiCad.


#11

Hmmm… This increases the ambiguity of the lonely “centi”, “nano”, and “milli”. I think I’ll remove those and maybe add the kicad legacy, and gEDA default format. The routine that will use this conversion will have a “default units” field and it’d be REALLY good to be able to specify those defaults with a unit. I’ll change the routine to accept a number as a default as well.


#12

The routine I am developing is nominally for design rule files. But I will likely use it for text box entries in KiPadCheck.

As also suggested, the default for text boxes will be derived from the “inch/mm” user selection.


#13

erichVK5, thanks for the link to pcb-rnd code! I’ve added “dmil” and “cmil” to the definitions.


#14

Thanks for all the feedback! It’s being incorporated into KiPadCheck.

The units list is now:

conversion = {
'':1,
'nm':1,
'nanometer':1,
'nanometers':1,
'um':pcbnew.IU_PER_MM/1000.0,
'micron':pcbnew.IU_PER_MM/1000.0,
'microns':pcbnew.IU_PER_MM/1000.0,
'micrometer':pcbnew.IU_PER_MM/1000.0,
'micrometers':pcbnew.IU_PER_MM/1000.0,
'decimicron':pcbnew.IU_PER_MM/10000.0,
'decimicrons':pcbnew.IU_PER_MM/10000.0,
'du':pcbnew.IU_PER_MM/10000.0,
'dus':pcbnew.IU_PER_MM/10000.0,
'dum':pcbnew.IU_PER_MM/10000.0,
'dums':pcbnew.IU_PER_MM/10000.0,
'mm':pcbnew.IU_PER_MM,
'millimeter':pcbnew.IU_PER_MM,
'millimeters':pcbnew.IU_PER_MM,
'm':pcbnew.IU_PER_MM*1000,
'meter':pcbnew.IU_PER_MM*1000,
'meters':pcbnew.IU_PER_MM*1000,
'km':pcbnew.IU_PER_MM*1000000,
'kilometer':pcbnew.IU_PER_MM*1000000,
'kilometers':pcbnew.IU_PER_MM*1000000,
'thou':pcbnew.IU_PER_MILS,
'mil':pcbnew.IU_PER_MILS,
'mils':pcbnew.IU_PER_MILS,
'dmil':pcbnew.IU_PER_MILS/10.0,
'dmils':pcbnew.IU_PER_MILS/10.0,
'decimil':pcbnew.IU_PER_MILS/10.0,
'decimils':pcbnew.IU_PER_MILS/10.0,
'cmil':pcbnew.IU_PER_MILS/100.0,
'cmils':pcbnew.IU_PER_MILS/100.0,
'centimil':pcbnew.IU_PER_MILS/100.0,
'centimils':pcbnew.IU_PER_MILS/100.0,
'cm':pcbnew.IU_PER_MM*10,
'centimeter':pcbnew.IU_PER_MM*10,
'centimeters':pcbnew.IU_PER_MM*10,
'in':pcbnew.IU_PER_MILS*1000.0,
'inch':pcbnew.IU_PER_MILS*1000.0,
'inches':pcbnew.IU_PER_MILS*1000.0,
'"':pcbnew.IU_PER_MILS*1000.0, # inches
"'":pcbnew.IU_PER_MILS*1000.0*12, # feet
'feet':pcbnew.IU_PER_MILS*1000.0*12,
'foot':pcbnew.IU_PER_MILS*1000.0*12,
}
# squared versions of measurements (three types: 2, **2, ^2)

KiPadCheck works with nightly, seeking feedback
#15

Metre is the correct spelling in many countries, hence “Metric”


#16

Is ‘metre’ also used with all the SI prefixes too
(nanometre, centimetre, millimetre)?


#17

I’ve added all units with ‘meter’ spelled ‘metre’ as well, including plurals.

Thanks!


#18

[quote=“HiGreg, post:17, topic:7281”]
I’ve added all units with ‘meter’ spelled ‘metre’ as well, including plurals.
[/quote]Isn’t this the job of a “translation package”?
I wouldn’t like it if this whole list gets sucked into a pull down menu and the menu won’t fit on the schreen because it has a gazillion options for the same.


#19

I don’t expect it to be a pull down. It is simply for text entry by users.


#20

You don’t expect it to be a pull down (or other) menu NOW, but code gets reused later in multiple ways.
And for text entry no sane user is going to type in words like “micrometer”.
I think that supporting the standarized SI units and a few basic imperoal ones should be enough, but it also seems like too much effort in too small a detail.