← Back to team overview

kicad-developers team mailing list archive

Re: more pythonic scripting API for pcbnew

 

Hmm, I’m actually liking Tom’s suggestion, sounds quite natural to me.

pcb.create_module(ref=‘A1’, position=(10 * mm, 10 * mm))

but also accepting pcb.create_module(ref=‘B1’, position=Point(10 * mm, 10 * mm))  

I’d do the function parameter translation into Point automatically, even if I believe parameter
input should be easy, having a class for points or sizes makes them easier to manipulate,
for example if we wanted to rotate them:

point.rotate(2 * rad)

point.rotate(90 * deg, around=(5 * mm, 5 * mm))

or  

new_point = point.rotated(90 * deg)

--
Side note, not sure why I thought IUs were 10nm, but they are 1nm (and 10nm for gerbview, I suppose the
reason for the gerview change is being able to stack the biggest boards 10x10)
http://bazaar.launchpad.net/~kicad-product-committers/kicad/product/view/head:/include/convert_to_biu.h#L44


Miguel Ángel Ajo


On Saturday, 24 de January de 2015 at 22:37, tiger12506 wrote:

> I have no weight in the discussion, but I really like Tom's suggestion here.
>  
> It allows you to use them as if they were units. 10 * mm is almost  
> syntactically identical to 10mm.
> And they don't get in the way with a bunch of boilerplate, like some of  
> the other suggestions do.
>  
> ~JS
>  
> On 1/24/2015 3:55 PM, Tomasz Wlostowski wrote:
> > 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
> >  
> > _______________________________________________
> > Mailing list: https://launchpad.net/~kicad-developers
> > Post to : kicad-developers@xxxxxxxxxxxxxxxxxxx (mailto:kicad-developers@xxxxxxxxxxxxxxxxxxx)
> > Unsubscribe : https://launchpad.net/~kicad-developers
> > More help : https://help.launchpad.net/ListHelp
> >  
>  
>  
>  
> _______________________________________________
> Mailing list: https://launchpad.net/~kicad-developers
> Post to : kicad-developers@xxxxxxxxxxxxxxxxxxx (mailto:kicad-developers@xxxxxxxxxxxxxxxxxxx)
> Unsubscribe : https://launchpad.net/~kicad-developers
> More help : https://help.launchpad.net/ListHelp
>  
>  



Follow ups

References