Mailing list archives : pcb-rnd

Date:Fri, 25 Nov 2022 05:59:24 +0100 (CET)
Subject:[pcb-rnd] new in librnd4: unit system extension
Hi all,
this email is about APIs and impelementation details; may be interesting 
for developers, safe to skip for users.
We have a sophisticated unit system in librnd. Parts of it was inherited 
from pcb. It's a table of units (e.g. mm, cm, mil, inch) grouped in unit 
families (e.g. imperial vs. metric) and conversion rates between them. 
Plus a printf wrapper so that we don't need to manually convert all the 
time but can use "%mm" or "%ml" for printing a coord value in millimeters 
or in mils.
This system was one of the essential infrastructures in librnd that worked 
fine with pcb-rnd and then with camv-rnd but then sch-rnd exposed its 
weaknesses. So in a sense the unit system is a good example on why I am 
doing the librnd4 upgrade, which is really a collection of very similar 
API changes for API weaknesses mostly pointed out by sch-rnd development 
this year.
The problem was that sch-rnd doesn't really use mm or mil or any physical 
unit for coords. It uses plain, unitless integers for coords. For GUI 
convenience we use the 'k' suffix for 1000, so the base grid of 1000, 
2000, 4000, etc. can be written as 1k, 2k, 4k.
librnd3's unit system doesn't support this, so sch-rnd up to now had to 
use plain integer spinboxes on the GUI and %ld in printf. This meant the 
GUI didn't really support entering numbers with the 'k' suffix and 
whenever we printed the numbers with the 'k' suffix that was a manual 
conversion before the printf.
In librnd4, I've revamped the unit system so it now supports the base unit 
tables as before, but it also provides the API for applications to 
register new unit families and new units in them. I've upgraded 
rnd_printf() so the app can exnted it with new format strings to print 
values with the new units. The get_value() calls we use when converting 
from string to numeric also handle app units. Finally, the Dynamic 
Attribute Dialog (DAD) system's spinbox API got a bit more flexible too, 
so it can present a spinbox for any unit family.
I've upgraded the dialog boxes in sch-rnd svn so they are all using the 
new 'k'-capable spinboxes.
Best regards,

Reply subtree:
5881 [pcb-rnd] new in librnd4: unit system extension from