Add SWIG support for NETCLASSPTR. Reduce SWIG visibility from C++ headers.

This commit is contained in:
Dick Hollenbeck 2016-09-21 16:26:44 -05:00 committed by Wayne Stambaugh
parent 85ef7ee467
commit 29be200843
7 changed files with 76 additions and 15 deletions

View File

@ -24,13 +24,15 @@
%warnfilter(511) IO_ERROR;
%ignore PARSE_ERROR;
%ignore FUTURE_FORMAT_ERROR;
%include ki_exception.h
%{
#include <ki_exception.h>
%}
%include exception.i
%include exception.i // from SWIG
// Target a specific function with "C++ to python exception handling and
// translation code". Invoke this macro separately for each C++ function

View File

@ -84,7 +84,6 @@ protected:
};
#ifndef SWIG
/**
* Struct PARSE_ERROR
* contains a filename or source description, a problem input line, a line number,
@ -149,8 +148,6 @@ struct FUTURE_FORMAT_ERROR : public PARSE_ERROR
~FUTURE_FORMAT_ERROR() throw () {}
};
#endif // SWIG
/** @} exception_types */
#endif // KI_EXCEPTION_H_

View File

@ -354,8 +354,6 @@ public:
};
#ifndef SWIG
class NETINFO_MAPPING
{
public:
@ -391,7 +389,6 @@ public:
*/
int Translate( int aNetCode ) const;
#ifndef SWIG
///> Wrapper class, so you can iterate through NETINFO_ITEM*s, not
///> std::pair<int/wxString, NETINFO_ITEM*>
class iterator
@ -459,7 +456,6 @@ public:
{
return iterator( m_netMapping.end(), this );
}
#endif
/**
* Function GetSize
@ -478,8 +474,6 @@ private:
std::map<int, int> m_netMapping;
};
#endif // SWIG
#if 0
// waiting for swig to support std::unordered_map, see
@ -712,5 +706,4 @@ enum StatusPcbFlags {
* ratsnest (used in module moves) */
};
#endif // CLASS_NETINFO_

View File

@ -167,13 +167,16 @@ HANDLE_EXCEPTIONS(BOARD::TracksInNetBetweenPoints)
def GetAllNetClasses(self):
"""
Return a dictionary like object with net_class_name as key and NETCLASSPRT as value
Return a dictionary like object with net_class_name as key and NETCLASSPTR as value
GetNetClasses(BOARD self) -> { wxString net_class_name : NETCLASSPTR }
Include the "Default" netclass also.
"""
netclassmap = self.GetNetClasses().NetClasses()
# add the Default one too
netclassmap[ NETCLASS.Default ] = self.GetNetClasses().GetDefault()
# Add the Default one too, but this is probably modifying the dict (aka NETCLASS_MAP)
# in the BOARD. So change code here to create a dict copy first.
# netclassmap = dict(netclassmap)
netclassmap['Default'] = self.GetNetClasses().GetDefault()
return netclassmap
%}
}

View File

@ -64,6 +64,8 @@ class VIA;
class ZONE_CONTAINER;
class PCB_TARGET;
// Anthing targeted to the %wrapper section is extern "C" whereas code targeted
// to %header section is C++.
#ifdef __cplusplus
extern "C" {
#endif
@ -177,4 +179,3 @@ static VIA* Cast_to_VIA( BOARD_ITEM* self ) { return d
static ZONE_CONTAINER* Cast_to_ZONE_CONTAINER( BOARD_ITEM* self ) { return dynamic_cast<ZONE_CONTAINER*>(self); }
static PCB_TARGET* Cast_to_PCB_TARGET( BOARD_ITEM* self ) { return dynamic_cast<PCB_TARGET*>(self); }
%}

View File

@ -1,5 +1,66 @@
/*
NETCLASS is not exposed/generated via SWIG but rather class NETCLASSPTR is. This
is because we can never have a simple pointer to a NETCLASS, only can we have a
NETCLASSPTR. So we cannot build a python wrapper without using NETCLASSPTR to do
the pointing.
*/
%ignore NETCLASS; // no code generation for it
%include class_netclass.h
/*
Propagate important member functions from NETCLASS into SWIG's NETCLASSPTR. Do
this by dereferencing the pointer to the NETCLASSPTR proxy, then dereference the
std::share_ptr to get to the actual NETCLASS::member. Complete the member
function set if you see something missing from class NETCLASS that you need.
*/
//%extend NETCLASSPTR // would have thought the typedef in header above was golden here.
%extend std::shared_ptr<NETCLASS>
{
public:
STRINGSET& NetNames() { return (*self)->NetNames(); }
const wxString& GetName() { return (*self)->GetName(); }
unsigned GetCount() const { return (*self)->GetCount(); }
const wxString& GetDescription() const { return (*self)->GetDescription(); }
void SetDescription( const wxString& aDesc ) { (*self)->SetDescription( aDesc ); }
int GetClearance() const { return (*self)->GetClearance(); }
void SetClearance( int aClearance ) { (*self)->SetClearance( aClearance ); }
int GetTrackWidth() const { return (*self)->GetTrackWidth(); }
void SetTrackWidth( int aWidth ) { (*self)->SetTrackWidth( aWidth ); }
int GetViaDiameter() const { return (*self)->GetViaDiameter(); }
void SetViaDiameter( int aDia ) { (*self)->SetViaDiameter( aDia ); }
int GetViaDrill() const { return (*self)->GetViaDrill(); }
void SetViaDrill( int aSize ) { (*self)->SetViaDrill( aSize ); }
int GetuViaDiameter() const { return (*self)->GetuViaDiameter(); }
void SetuViaDiameter( int aSize ) { (*self)->SetuViaDiameter( aSize ); }
int GetuViaDrill() const { return (*self)->GetuViaDrill(); }
void SetuViaDrill( int aSize ) { (*self)->SetuViaDrill( aSize ); }
int GetDiffPairWidth() const { return (*self)->GetDiffPairWidth(); }
void SetDiffPairWidth( int aSize ) { (*self)->SetDiffPairWidth( aSize ); }
int GetDiffPairGap() const { return (*self)->GetDiffPairGap(); }
void SetDiffPairGap( int aSize ) { (*self)->SetDiffPairGap( aSize ); }
};
%{
#include <class_netclass.h>
%}

View File

@ -1,5 +1,9 @@
%warnfilter(325) NETINFO_MAPPING;
%ignore NETINFO_MAPPING; // no code generation for this class
%include class_netinfo.h
%{
#include <class_netinfo.h>
%}