From 29be200843d239bbf3bd9e384f1133d47fbc8343 Mon Sep 17 00:00:00 2001 From: Dick Hollenbeck Date: Wed, 21 Sep 2016 16:26:44 -0500 Subject: [PATCH] Add SWIG support for NETCLASSPTR. Reduce SWIG visibility from C++ headers. --- common/swig/ki_exception.i | 4 ++- include/ki_exception.h | 3 -- pcbnew/class_netinfo.h | 7 ----- pcbnew/swig/board.i | 9 ++++-- pcbnew/swig/board_item.i | 3 +- pcbnew/swig/netclass.i | 61 ++++++++++++++++++++++++++++++++++++++ pcbnew/swig/netinfo.i | 4 +++ 7 files changed, 76 insertions(+), 15 deletions(-) diff --git a/common/swig/ki_exception.i b/common/swig/ki_exception.i index 0a42cc8404..2f004520ed 100644 --- a/common/swig/ki_exception.i +++ b/common/swig/ki_exception.i @@ -24,13 +24,15 @@ %warnfilter(511) IO_ERROR; +%ignore PARSE_ERROR; +%ignore FUTURE_FORMAT_ERROR; %include ki_exception.h %{ #include %} -%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 diff --git a/include/ki_exception.h b/include/ki_exception.h index d9e9cd91e2..ec1556571b 100644 --- a/include/ki_exception.h +++ b/include/ki_exception.h @@ -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_ diff --git a/pcbnew/class_netinfo.h b/pcbnew/class_netinfo.h index ae4af1bc17..8470eeadf1 100644 --- a/pcbnew/class_netinfo.h +++ b/pcbnew/class_netinfo.h @@ -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 class iterator @@ -459,7 +456,6 @@ public: { return iterator( m_netMapping.end(), this ); } -#endif /** * Function GetSize @@ -478,8 +474,6 @@ private: std::map 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_ diff --git a/pcbnew/swig/board.i b/pcbnew/swig/board.i index 3fe241c53a..a566c686d5 100644 --- a/pcbnew/swig/board.i +++ b/pcbnew/swig/board.i @@ -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 %} } diff --git a/pcbnew/swig/board_item.i b/pcbnew/swig/board_item.i index 7f0d7a0feb..8439222452 100644 --- a/pcbnew/swig/board_item.i +++ b/pcbnew/swig/board_item.i @@ -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(self); } static PCB_TARGET* Cast_to_PCB_TARGET( BOARD_ITEM* self ) { return dynamic_cast(self); } %} - diff --git a/pcbnew/swig/netclass.i b/pcbnew/swig/netclass.i index 5e3a60a687..200c8ed08b 100644 --- a/pcbnew/swig/netclass.i +++ b/pcbnew/swig/netclass.i @@ -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 +{ +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 %} diff --git a/pcbnew/swig/netinfo.i b/pcbnew/swig/netinfo.i index 7d5a67044f..027cd1ee56 100644 --- a/pcbnew/swig/netinfo.i +++ b/pcbnew/swig/netinfo.i @@ -1,5 +1,9 @@ +%warnfilter(325) NETINFO_MAPPING; +%ignore NETINFO_MAPPING; // no code generation for this class + %include class_netinfo.h + %{ #include %}