Changes to python interface enabling net->pads access.
Added new file connectivity.i to expose CONNECTIVITY_DATA to python. enables access to d_pads from nets. Added typemap to board_connected_item.i. since board_connected_item doesn't use virtual inheritance, when returning a std::list of these items, the typemap populates the return list with the child types. This enables python scripts to use the full interface of those classes (pad, track, zone) Added typeinfo.i to enable passing a list of KICAD_T values to methods GetNetItems. This list acts as a query filter. typeinfo.i is included from pcbnew.i right after kicad.i (instead of in board.i like the others) typeinfo.h is already being included kicad.i so to ensure the typemap(s) are properly applied I put them next to each other. The two new files (typeinfo.i and connectivity.i) were added to pcbnew's CMakeLists.txt as dependencies.
This commit is contained in:
parent
b82bd8e0c5
commit
d16a5c1d6c
|
@ -438,6 +438,7 @@ if( KICAD_SCRIPTING ) # Generate pcbnew.py and pcbnew_wrap.cxx using swig
|
|||
DEPENDS swig/board_design_settings.i
|
||||
DEPENDS swig/board_item.i
|
||||
DEPENDS swig/board_item_container.i
|
||||
DEPENDS swig/connectivity.i
|
||||
DEPENDS swig/dimension.i
|
||||
DEPENDS swig/drawsegment.i
|
||||
DEPENDS swig/edge_mod.i
|
||||
|
@ -452,6 +453,7 @@ if( KICAD_SCRIPTING ) # Generate pcbnew.py and pcbnew_wrap.cxx using swig
|
|||
DEPENDS swig/text_mod.i
|
||||
DEPENDS swig/track.i
|
||||
DEPENDS swig/units.i
|
||||
DEPENDS swig/typeinfo.i
|
||||
DEPENDS swig/zone.i
|
||||
DEPENDS swig/zone_settings.i
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
*
|
||||
* Copyright (C) 2012 NBEE Embedded Systems, Miguel Angel Ajo <miguelangel@nbee.es>
|
||||
* Copyright (C) 2016 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
|
||||
* Copyright (C) 1992-2012 KiCad Developers, see AUTHORS.txt for contributors.
|
||||
* Copyright (C) 1992-2017 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
|
||||
|
@ -48,6 +48,7 @@ HANDLE_EXCEPTIONS(BOARD::TracksInNetBetweenPoints)
|
|||
%include board_item_container.i
|
||||
%include board_connected_item.i
|
||||
%include board_design_settings.i
|
||||
%include connectivity.i
|
||||
%include pad.i
|
||||
%include track.i
|
||||
%include zone.i
|
||||
|
|
|
@ -1,3 +1,27 @@
|
|||
/*
|
||||
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||
*
|
||||
* Copyright (C) 1992-2017 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
|
||||
*/
|
||||
|
||||
|
||||
|
||||
%include class_board_connected_item.h
|
||||
|
||||
|
@ -5,3 +29,46 @@
|
|||
#include <class_board_connected_item.h>
|
||||
%}
|
||||
|
||||
%typemap(out) std::list<BOARD_CONNECTED_ITEM*> {
|
||||
std::list<BOARD_CONNECTED_ITEM*> list = $1;
|
||||
std::list<BOARD_CONNECTED_ITEM*>::const_iterator iter;
|
||||
|
||||
PyObject * retval = $result = PyList_New(0);
|
||||
|
||||
for( iter=list.begin(); iter!=list.end(); iter++ ) {
|
||||
BOARD_CONNECTED_ITEM* aItem = *iter;
|
||||
PyObject* obj = 0x0;
|
||||
|
||||
switch( aItem->Type() ) {
|
||||
case PCB_PAD_T:
|
||||
obj = SWIG_NewPointerObj( SWIG_as_voidptr(aItem),
|
||||
SWIGTYPE_p_D_PAD,
|
||||
0 | 0 );
|
||||
break;
|
||||
|
||||
case PCB_TRACE_T:
|
||||
case PCB_VIA_T:
|
||||
obj = SWIG_NewPointerObj( SWIG_as_voidptr(aItem),
|
||||
SWIGTYPE_p_TRACK,
|
||||
0 | 0 );
|
||||
break;
|
||||
|
||||
case PCB_ZONE_AREA_T:
|
||||
obj = SWIG_NewPointerObj( SWIG_as_voidptr(aItem),
|
||||
SWIGTYPE_p_ZONE_CONTAINER,
|
||||
0 | 0 );
|
||||
break;
|
||||
|
||||
default:
|
||||
obj = SWIG_NewPointerObj( SWIG_as_voidptr(aItem),
|
||||
SWIGTYPE_p_BOARD_CONNECTED_ITEM,
|
||||
0 | 0 );
|
||||
break;
|
||||
}
|
||||
|
||||
assert( obj );
|
||||
PyList_Append (retval, obj );
|
||||
Py_DECREF( obj );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,39 @@
|
|||
/*
|
||||
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||
*
|
||||
* Copyright (C) 1992-2017 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
|
||||
*/
|
||||
|
||||
|
||||
// when you ask board for its connectivity, you get a shared_ptr
|
||||
%include <std_shared_ptr.i>
|
||||
|
||||
// this shared_ptr line has to be before include connectivity_data.h.
|
||||
%shared_ptr(CONNECTIVITY_DATA)
|
||||
|
||||
%include connectivity_data.h
|
||||
|
||||
|
||||
|
||||
|
||||
%{
|
||||
#include <connectivity_data.h>
|
||||
%}
|
||||
|
|
@ -2,7 +2,7 @@
|
|||
* 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.
|
||||
* Copyright (C) 1992-2017 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
|
||||
|
@ -38,6 +38,9 @@
|
|||
|
||||
%include kicad.i
|
||||
|
||||
// mostly for KICAD_T
|
||||
%include typeinfo.i
|
||||
|
||||
%include <convert_to_biu.h>
|
||||
|
||||
%{
|
||||
|
|
|
@ -0,0 +1,69 @@
|
|||
/*
|
||||
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||
*
|
||||
* Copyright (C) 1992-2017 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
|
||||
*/
|
||||
|
||||
|
||||
|
||||
%include core/typeinfo.h
|
||||
|
||||
%{
|
||||
#include <core/typeinfo.h>
|
||||
%}
|
||||
|
||||
// methods like CONNECTIVITY_DATA::GetNetItems take an array of KICAD_T values,
|
||||
// terminated by EOT. for example, class_board.cpp calls the method with this argument:
|
||||
// const KICAD_T types[] = { PCB_PAD_T, PCB_ZONE_AREA_T, EOT };
|
||||
// this typemap allows any of the following:
|
||||
// conn = board.GetConnectivity()
|
||||
// conn.GetNetItems(net.GetNet(), (pcbnew.PCB_PAD_T, pcbnew.PCB_TRACE_T))
|
||||
// conn.GetNetItems(net.GetNet(), [pcbnew.PCB_PAD_T, pcbnew.PCB_TRACE_T])
|
||||
// conn.GetNetItems(net.GetNet(), pcbnew.PCB_PAD_T)
|
||||
|
||||
|
||||
%typemap(in) KICAD_T [] ( KICAD_T retval[5] ){
|
||||
retval[0] = EOT;
|
||||
$1 = retval;
|
||||
|
||||
int type;
|
||||
int ecode = SWIG_AsVal_int( $input, &type );
|
||||
|
||||
if ( SWIG_IsOK( ecode ) ) {
|
||||
retval[0] = static_cast<KICAD_T>( type );
|
||||
retval[1] = EOT;
|
||||
} else if ( PySequence_Check( $input ) ) {
|
||||
// compare less than because we still need space for the EOT terminator
|
||||
assert( PySequence_Size( $input ) <=
|
||||
static_cast<int>( sizeof( retval )/sizeof( KICAD_T ) ) );
|
||||
for(int i=0; i<PySequence_Size( $input ); i++) {
|
||||
int ecode = SWIG_AsVal_int( PySequence_GetItem( $input, i ), &type );
|
||||
if ( !SWIG_IsOK( ecode ) ) {
|
||||
SWIG_exception_fail( SWIG_ArgError( ecode ),
|
||||
"expecting KICAD_T enum values" );
|
||||
}
|
||||
retval[i] = static_cast<KICAD_T>( type );
|
||||
retval[i+1] = EOT;
|
||||
}
|
||||
} else {
|
||||
SWIG_exception_fail( SWIG_ArgError( ecode ),
|
||||
"expecting KICAD_T enum value" );
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue