Fix pcbnew api for DIMENSIONs

DIMENSION is now an abstract class and we should cast to
concrete implementations instead.

Also change broken 'return none' to throwing an exception
which will give feedback about what is not supported by
the API instead of silently returning a non-object.
This commit is contained in:
qu1ck 2020-09-17 22:27:06 -07:00 committed by Jon Evans
parent ef48dba7ff
commit 5e0d79449e
1 changed files with 58 additions and 46 deletions

View File

@ -48,7 +48,9 @@
%{ %{
class TEXTE_PCB; class TEXTE_PCB;
class DIMENSION; class ALIGNED_DIMENSION;
class LEADER;
class CENTER_DIMENSION;
class MODULE; class MODULE;
class PCB_GROUP; class PCB_GROUP;
class TEXTE_MODULE; class TEXTE_MODULE;
@ -68,20 +70,22 @@ class PCB_TARGET;
extern "C" { extern "C" {
#endif #endif
static TEXTE_PCB* Cast_to_TEXTE_PCB( BOARD_ITEM* ); static TEXTE_PCB* Cast_to_TEXTE_PCB( BOARD_ITEM* );
static DIMENSION* Cast_to_DIMENSION( BOARD_ITEM* ); static ALIGNED_DIMENSION* Cast_to_ALIGNED_DIMENSION( BOARD_ITEM* );
static MODULE* Cast_to_MODULE( BOARD_ITEM* ); static LEADER* Cast_to_LEADER( BOARD_ITEM* );
static PCB_GROUP* Cast_to_PCB_GROUP( BOARD_ITEM* ); static CENTER_DIMENSION* Cast_to_CENTER_DIMENSION( BOARD_ITEM* );
static TEXTE_MODULE* Cast_to_TEXTE_MODULE( BOARD_ITEM* ); static MODULE* Cast_to_MODULE( BOARD_ITEM* );
static DRAWSEGMENT* Cast_to_DRAWSEGMENT( BOARD_ITEM* ); static PCB_GROUP* Cast_to_PCB_GROUP( BOARD_ITEM* );
static MARKER_PCB* Cast_to_MARKER_PCB( BOARD_ITEM* ); static TEXTE_MODULE* Cast_to_TEXTE_MODULE( BOARD_ITEM* );
static BOARD* Cast_to_BOARD( BOARD_ITEM* ); static DRAWSEGMENT* Cast_to_DRAWSEGMENT( BOARD_ITEM* );
static EDGE_MODULE* Cast_to_EDGE_MODULE( BOARD_ITEM* ); static MARKER_PCB* Cast_to_MARKER_PCB( BOARD_ITEM* );
static D_PAD* Cast_to_D_PAD( BOARD_ITEM* ); static BOARD* Cast_to_BOARD( BOARD_ITEM* );
static TRACK* Cast_to_TRACK( BOARD_ITEM* ); static EDGE_MODULE* Cast_to_EDGE_MODULE( BOARD_ITEM* );
static VIA* Cast_to_VIA( BOARD_ITEM* ); static D_PAD* Cast_to_D_PAD( BOARD_ITEM* );
static ZONE_CONTAINER* Cast_to_ZONE_CONTAINER( BOARD_ITEM* ); static TRACK* Cast_to_TRACK( BOARD_ITEM* );
static PCB_TARGET* Cast_to_PCB_TARGET( BOARD_ITEM* ); static VIA* Cast_to_VIA( BOARD_ITEM* );
static ZONE_CONTAINER* Cast_to_ZONE_CONTAINER( BOARD_ITEM* );
static PCB_TARGET* Cast_to_PCB_TARGET( BOARD_ITEM* );
#ifdef __cplusplus #ifdef __cplusplus
} // extern "C" } // extern "C"
@ -89,20 +93,22 @@ static PCB_TARGET* Cast_to_PCB_TARGET( BOARD_ITEM* );
%} %}
static TEXTE_PCB* Cast_to_TEXTE_PCB( BOARD_ITEM* ); static TEXTE_PCB* Cast_to_TEXTE_PCB( BOARD_ITEM* );
static DIMENSION* Cast_to_DIMENSION( BOARD_ITEM* ); static ALIGNED_DIMENSION* Cast_to_ALIGNED_DIMENSION( BOARD_ITEM* );
static MODULE* Cast_to_MODULE( BOARD_ITEM* ); static LEADER* Cast_to_LEADER( BOARD_ITEM* );
static PCB_GROUP* Cast_to_PCB_GROUP( BOARD_ITEM* ); static CENTER_DIMENSION* Cast_to_CENTER_DIMENSION( BOARD_ITEM* );
static TEXTE_MODULE* Cast_to_TEXTE_MODULE( BOARD_ITEM* ); static MODULE* Cast_to_MODULE( BOARD_ITEM* );
static DRAWSEGMENT* Cast_to_DRAWSEGMENT( BOARD_ITEM* ); static PCB_GROUP* Cast_to_PCB_GROUP( BOARD_ITEM* );
static MARKER_PCB* Cast_to_MARKER_PCB( BOARD_ITEM* ); static TEXTE_MODULE* Cast_to_TEXTE_MODULE( BOARD_ITEM* );
static BOARD* Cast_to_BOARD( BOARD_ITEM* ); static DRAWSEGMENT* Cast_to_DRAWSEGMENT( BOARD_ITEM* );
static EDGE_MODULE* Cast_to_EDGE_MODULE( BOARD_ITEM* ); static MARKER_PCB* Cast_to_MARKER_PCB( BOARD_ITEM* );
static D_PAD* Cast_to_D_PAD( BOARD_ITEM* ); static BOARD* Cast_to_BOARD( BOARD_ITEM* );
static TRACK* Cast_to_TRACK( BOARD_ITEM* ); static EDGE_MODULE* Cast_to_EDGE_MODULE( BOARD_ITEM* );
static VIA* Cast_to_VIA( BOARD_ITEM* ); static D_PAD* Cast_to_D_PAD( BOARD_ITEM* );
static ZONE_CONTAINER* Cast_to_ZONE_CONTAINER( BOARD_ITEM* ); static TRACK* Cast_to_TRACK( BOARD_ITEM* );
static PCB_TARGET* Cast_to_PCB_TARGET( BOARD_ITEM* ); static VIA* Cast_to_VIA( BOARD_ITEM* );
static ZONE_CONTAINER* Cast_to_ZONE_CONTAINER( BOARD_ITEM* );
static PCB_TARGET* Cast_to_PCB_TARGET( BOARD_ITEM* );
%extend BOARD_ITEM %extend BOARD_ITEM
@ -117,8 +123,12 @@ static PCB_TARGET* Cast_to_PCB_TARGET( BOARD_ITEM* );
return Cast_to_TEXTE_PCB(self) return Cast_to_TEXTE_PCB(self)
elif ct=="BOARD": elif ct=="BOARD":
return Cast_to_BOARD(self) return Cast_to_BOARD(self)
elif ct=="DIMENSION": elif ct=="ALIGNED_DIMENSION":
return Cast_to_DIMENSION(self) return Cast_to_ALIGNED_DIMENSION(self)
elif ct=="LEADER":
return Cast_to_LEADER(self)
elif ct=="CENTER_DIMENSION":
return Cast_to_CENTER_DIMENSION(self)
elif ct=="DRAWSEGMENT": elif ct=="DRAWSEGMENT":
return Cast_to_DRAWSEGMENT(self) return Cast_to_DRAWSEGMENT(self)
elif ct=="MGRAPHIC": elif ct=="MGRAPHIC":
@ -140,7 +150,7 @@ static PCB_TARGET* Cast_to_PCB_TARGET( BOARD_ITEM* );
elif ct=="ZONE_CONTAINER": elif ct=="ZONE_CONTAINER":
return Cast_to_ZONE_CONTAINER(self) return Cast_to_ZONE_CONTAINER(self)
else: else:
return none raise TypeError("Unsupported drawing class: %s" % ct)
def Duplicate(self): def Duplicate(self):
ct = self.GetClass() ct = self.GetClass()
@ -167,18 +177,20 @@ static PCB_TARGET* Cast_to_PCB_TARGET( BOARD_ITEM* );
// classes and therefore will C++ compile due to the respective headers which will go into // classes and therefore will C++ compile due to the respective headers which will go into
// the %header section. See section 5.6.2 of SWIG 3.0 documentation. // the %header section. See section 5.6.2 of SWIG 3.0 documentation.
%wrapper %{ %wrapper %{
static TEXTE_PCB* Cast_to_TEXTE_PCB( BOARD_ITEM* self ) { return dynamic_cast<TEXTE_PCB*>(self); } static TEXTE_PCB* Cast_to_TEXTE_PCB( BOARD_ITEM* self ) { return dynamic_cast<TEXTE_PCB*>(self); }
static DIMENSION* Cast_to_DIMENSION( BOARD_ITEM* self ) { return dynamic_cast<DIMENSION*>(self); } static ALIGNED_DIMENSION* Cast_to_ALIGNED_DIMENSION( BOARD_ITEM* self ) { return dynamic_cast<ALIGNED_DIMENSION*>(self); }
static MODULE* Cast_to_MODULE( BOARD_ITEM* self ) { return dynamic_cast<MODULE*>(self); } static LEADER* Cast_to_LEADER( BOARD_ITEM* self ) { return dynamic_cast<LEADER*>(self); }
static PCB_GROUP* Cast_to_PCB_GROUP( BOARD_ITEM* self ) { return dynamic_cast<PCB_GROUP*>(self); } static CENTER_DIMENSION* Cast_to_CENTER_DIMENSION( BOARD_ITEM* self ) { return dynamic_cast<CENTER_DIMENSION*>(self); }
static TEXTE_MODULE* Cast_to_TEXTE_MODULE( BOARD_ITEM* self ) { return dynamic_cast<TEXTE_MODULE*>(self); } static MODULE* Cast_to_MODULE( BOARD_ITEM* self ) { return dynamic_cast<MODULE*>(self); }
static DRAWSEGMENT* Cast_to_DRAWSEGMENT( BOARD_ITEM* self ) { return dynamic_cast<DRAWSEGMENT*>(self); } static PCB_GROUP* Cast_to_PCB_GROUP( BOARD_ITEM* self ) { return dynamic_cast<PCB_GROUP*>(self); }
static MARKER_PCB* Cast_to_MARKER_PCB( BOARD_ITEM* self ) { return dynamic_cast<MARKER_PCB*>(self); } static TEXTE_MODULE* Cast_to_TEXTE_MODULE( BOARD_ITEM* self ) { return dynamic_cast<TEXTE_MODULE*>(self); }
static BOARD* Cast_to_BOARD( BOARD_ITEM* self ) { return dynamic_cast<BOARD*>(self); } static DRAWSEGMENT* Cast_to_DRAWSEGMENT( BOARD_ITEM* self ) { return dynamic_cast<DRAWSEGMENT*>(self); }
static EDGE_MODULE* Cast_to_EDGE_MODULE( BOARD_ITEM* self ) { return dynamic_cast<EDGE_MODULE*>(self); } static MARKER_PCB* Cast_to_MARKER_PCB( BOARD_ITEM* self ) { return dynamic_cast<MARKER_PCB*>(self); }
static D_PAD* Cast_to_D_PAD( BOARD_ITEM* self ) { return dynamic_cast<D_PAD*>(self); } static BOARD* Cast_to_BOARD( BOARD_ITEM* self ) { return dynamic_cast<BOARD*>(self); }
static TRACK* Cast_to_TRACK( BOARD_ITEM* self ) { return dynamic_cast<TRACK*>(self); } static EDGE_MODULE* Cast_to_EDGE_MODULE( BOARD_ITEM* self ) { return dynamic_cast<EDGE_MODULE*>(self); }
static VIA* Cast_to_VIA( BOARD_ITEM* self ) { return dynamic_cast<VIA*>(self); } static D_PAD* Cast_to_D_PAD( BOARD_ITEM* self ) { return dynamic_cast<D_PAD*>(self); }
static ZONE_CONTAINER* Cast_to_ZONE_CONTAINER( BOARD_ITEM* self ) { return dynamic_cast<ZONE_CONTAINER*>(self); } static TRACK* Cast_to_TRACK( BOARD_ITEM* self ) { return dynamic_cast<TRACK*>(self); }
static PCB_TARGET* Cast_to_PCB_TARGET( BOARD_ITEM* self ) { return dynamic_cast<PCB_TARGET*>(self); } static VIA* Cast_to_VIA( BOARD_ITEM* self ) { return dynamic_cast<VIA*>(self); }
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); }
%} %}