So I'm plugin-ifying my python scripts (the mechanism is awesome). One of
the plugins deletes some stuff and that is causing trouble.



I'm not sure how to fix the root cause. Hence this mail.



The plugin just deletes Edge.Cuts[1]:
for d in board.GetDrawings():
            if (d.GetLayerName() == 'Edge.Cuts'):
                board.Remove(d)



in board_item_container.i, I see this (with stuff deleted):
%rename(RemoveNative)    BOARD_ITEM_CONTAINER::Remove;
    def Remove(self,item):
        self.RemoveNative(item)
        item.thisown=1


Setting thisown tells, python "you own it". Delete it when you're done.
Which it does.


The problem this causes is that the plugin mechanism saves a list of all
objects before running the plugin and then checks if any of them has a null
list after (ie is it still in the design).

Since the object has been deleted by python, the plugin stuff gets confused.


*So, the question is how to fix this?*


It appears that the plugin infrastructure will delete for you (that's what
I'm guessing), so the thisown setting shouldn't be done.


On the other hand, if running code from within a standalone script (ie from
regular python shell), now thisown'ing it would yield a memory leak.



Perhaps the plugin stuff should have some sort of flag indicating "you're
in a plugin". Then the thisown setting could be conditional.


But I'm just a spectator. *I'm happy to put in the time to fix this but
need guidance on what approach to take.*


Miles



[1] full plugin text
import pcbnew

class RemoveBoundaryPlugin(pcbnew.ActionPlugin):
    def defaults(self):
        self.name = "Remove boundary"
        self.category = "A descriptive category name"
        self.description = "This plugin reads a dxf file and converts it to
a zone"

    def Run(self):
        board = pcbnew.GetBoard()

        for d in board.GetDrawings():
            print("{}".format(str(d)))
            #print("on layer {} {} {}".format(d.GetLayerName(),
            #                                 str(d.GetStart()),
            #                                 str(d.GetEnd())))
            if (d.GetLayerName() == 'Edge.Cuts'):
                board.Remove(d)

RemoveBoundaryPlugin().register()
_______________________________________________
Mailing list: https://launchpad.net/~kicad-developers
Post to     : kicad-developers@lists.launchpad.net
Unsubscribe : https://launchpad.net/~kicad-developers
More help   : https://help.launchpad.net/ListHelp

Reply via email to