Skip to content

Commit

Permalink
Add SWIG support for NETCLASSPTR. Reduce SWIG visibility from C++ hea…
Browse files Browse the repository at this point in the history
…ders.
  • Loading branch information
liftoff-sr authored and stambaughw committed Sep 21, 2016
1 parent 85ef7ee commit 29be200
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 15 deletions.
4 changes: 3 additions & 1 deletion common/swig/ki_exception.i
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 0 additions & 3 deletions include/ki_exception.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ class IO_ERROR // : std::exception
};


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

#endif // SWIG

/** @} exception_types */

#endif // KI_EXCEPTION_H_
7 changes: 0 additions & 7 deletions pcbnew/class_netinfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -354,8 +354,6 @@ class NETINFO_ITEM : public BOARD_ITEM
};


#ifndef SWIG

class NETINFO_MAPPING
{
public:
Expand Down Expand Up @@ -391,7 +389,6 @@ class NETINFO_MAPPING
*/
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
Expand Down Expand Up @@ -459,7 +456,6 @@ class NETINFO_MAPPING
{
return iterator( m_netMapping.end(), this );
}
#endif

/**
* Function GetSize
Expand All @@ -478,8 +474,6 @@ class NETINFO_MAPPING
std::map<int, int> m_netMapping;
};

#endif // SWIG


#if 0
// waiting for swig to support std::unordered_map, see
Expand Down Expand Up @@ -712,5 +706,4 @@ enum StatusPcbFlags {
* ratsnest (used in module moves) */
};


#endif // CLASS_NETINFO_
9 changes: 6 additions & 3 deletions pcbnew/swig/board.i
Original file line number Diff line number Diff line change
Expand Up @@ -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
%}
}
3 changes: 2 additions & 1 deletion pcbnew/swig/board_item.i
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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); }
%}

61 changes: 61 additions & 0 deletions pcbnew/swig/netclass.i
Original file line number Diff line number Diff line change
@@ -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>
%}
4 changes: 4 additions & 0 deletions pcbnew/swig/netinfo.i
Original file line number Diff line number Diff line change
@@ -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>
%}
Expand Down

0 comments on commit 29be200

Please sign in to comment.