← Back to team overview

kicad-developers team mailing list archive

Re: more pythonic scripting API for pcbnew

 

On 16.01.2015 18:43, Miguel Ángel Ajo wrote:
> 
> The user shouldn’t need to know what an IU is unless he really wants, for some
> reason.
>
Hi Miguel,

Why make things complicated here? Given that the choice of IUs in pcbnew
is very reasonable and easy to understand, I see no reason for hiding
that knowledge from script writers. A nanometer after all, is just
one-millionth of a millimeter. No rocket science here...

On the other hand, we need to provide a sensible way of
inputting/presenting values with units. For hardcoded values, defining
units could be just multiplying by a fixed scalefactor:

from pcbnew import mm, inch, mils

#pcbnew.mm = 1000000
#pcbnew.inch = 25400000
#pcbnew.mils = 25400

p = Point(10 * mm, 12 * mm)

Concerning UI input/output (dialogs) - recently I had to do some dialogs
for P&S with lots of values in mm/inches, so to avoid repeatable unit
conversion code, I developed a class tiny called WX_UNIT_BINDER [1]. It
binds together a WX text control with an unit label:

class MyDialog : public dialog_generated_by_wxfb_base {
	WX_UNIT_BINDER m_myValueInUnits;
};

MyDialog::MyDialog() :
	m_myValueInUnits ( m_myValueText, m_myValueUnitLabel )
{
	m_myValueInUnits.SetValue ( value_in_iu_here )
	// x = m_myValueInUnits.GetValue();
}

All unit conversion is done inside the binder class, according to the
current units setting. All the user needs to do is to get/set the value
in IUs. Maybe a similar method could be used in the scripting API?

Cheers,
Tom

[1]
https://github.com/twlostow/kicad-dev/blob/tmp-crap/include/wx_unit_binder.h


Follow ups

References