kicad-developers team mailing list archive
-
kicad-developers team
-
Mailing list archive
-
Message #14890
Re: Track copy - to be or not to be… I'm panelizing, python coder.
W dniu 01.10.2014 21:08, jp charras pisze:
> Le 01/10/2014 20:42, Daniel Dawid Majewski a écrit :
>> On 01.10.2014 16:25, Wayne Stambaugh wrote:
>>> They do. It is automatically generated by the compiler just like the
>>> source code comment explains. Unless you need some special copy
>>> semantics (not just a direct copy of every class member which is what
>>> the compiler will generate), you do not need to write your own copy
>>> constructor.
>> Ok, so where are nested following python methods ?:
>> Copy(MODULE self, MODULE src)
>> Copy(ZONE_CONTAINER self, ZONE_CONTAINER src)
>> How I could make ?:
>> Copy(TRACK self, TRACK src)
>> Copy(VIA self, VIA src)
>
> Seems there is a mistake between a copy constructor and the Copy method
> which exists for some BOARD_ITEMS, but not all (because currently this
> method is not needed in C++ Kicad code for track/vias)
In panelization mainly exist need tor massive coping of every item, that is then
ploted to Gerber… ;)
>
> The Copy method copy only some values from an existing source to an
> existing target.
>
> The default copy constructor creates a clone (a new item) of an item.
> This is very different.
>
> I'll add a Copy method (mainly for python scripts) for tracks/vias soon.
You make me hopefully… ;)
>
> For now, to create a clone of a track/via using the default copy
> constructor, try to use something like :
> newtrack=oldtrack.__class__(oldtrack)
I tried, but it did not work.
I've made workaround. It works in current case, but I can't guarantee that all
necessary params of Track/Via are copied(paying particular attention to the
service of via layers, which I can't recognize - my habits stands closer to
legacy nibbles from https://github.com/alexer/pykicad…;):
def paramCopy(Item, newItem, strAttr):
getattr(newItem, 'Set'+strAttr)(getattr(Item, 'Get'+strAttr)())
attrVia = ('Position', 'Width')
attrTrack = ('Start', 'End', 'Width', 'Layer', 'NetCode')
newItem = Item.__class__(pcb)
if type(Item) is VIA:
for strAttr in attrVia:
paramCopy(Item, newItem, strAttr)
elif type(Item) is TRACK:
for strAttr in attrTrack:
paramCopy(Item, newItem, strAttr)
else:
newItem.Copy(Item)
pcb.Add(newItem)
So „Copy” methods will be the best way.
--
Best Regards,
LordBlick
References