Add method for MODULE in python that takes care of memory handling
This commit is contained in:
parent
b54acf607a
commit
485ec24f61
|
@ -1,21 +1,17 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
from pcbnew import *
|
||||
import pcbnew
|
||||
|
||||
pcb = BOARD()
|
||||
module = MODULE(pcb)
|
||||
module.SetReference("M1")
|
||||
|
||||
pad = D_PAD(module)
|
||||
module.m_Pads.PushBack(pad)
|
||||
pad.thisown=0
|
||||
module.Add(pad)
|
||||
|
||||
pcb.Add(module)
|
||||
|
||||
pcb.Save("/tmp/my2.brd")
|
||||
|
||||
|
||||
print map( lambda x: x.GetReference() , list(pcb.GetModules()))
|
||||
|
||||
print "Saved?"
|
||||
|
|
|
@ -0,0 +1,60 @@
|
|||
/*
|
||||
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||
*
|
||||
* Copyright (C) 2012 NBEE Embedded Systems, Miguel Angel Ajo <miguelangel@nbee.es>
|
||||
* Copyright (C) 1992-2012 KiCad Developers, see AUTHORS.txt for contributors.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, you may find one here:
|
||||
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
||||
* or you may search the http://www.gnu.org website for the version 2 license,
|
||||
* or you may write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file module.i
|
||||
* @brief Specific BOARD extensions and templates
|
||||
*/
|
||||
|
||||
|
||||
%extend MODULE
|
||||
{
|
||||
%pythoncode
|
||||
{
|
||||
|
||||
def GetPads(self): return self.m_Pads
|
||||
def GetDrawings(self): return self.m_Drawings
|
||||
|
||||
#def SaveToLibrary(self,filename):
|
||||
# return SaveModuleToLibrary(filename,self)
|
||||
|
||||
#
|
||||
# add function, clears the thisown to avoid python from deleting
|
||||
# the object in the garbage collector
|
||||
#
|
||||
|
||||
def Add(self,item):
|
||||
|
||||
itemC = item.Cast()
|
||||
|
||||
if type(itemC) is D_PAD:
|
||||
item.thisown=0
|
||||
self.m_Pads.PushBack(itemC)
|
||||
elif type(itemC) in [ TEXTE_PCB, DIMENSION, TEXTE_MODULE, DRAWSEGMENT]:
|
||||
item.thisown = 0
|
||||
self.m_Drawings.PushBack(item)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -104,4 +104,5 @@
|
|||
|
||||
|
||||
%include "board.i"
|
||||
%include "module.i"
|
||||
%include "units.i"
|
||||
|
|
Loading…
Reference in New Issue