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;
@ -69,7 +71,9 @@ 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 LEADER* Cast_to_LEADER( BOARD_ITEM* );
static CENTER_DIMENSION* Cast_to_CENTER_DIMENSION( BOARD_ITEM* );
static MODULE* Cast_to_MODULE( BOARD_ITEM* ); static MODULE* Cast_to_MODULE( BOARD_ITEM* );
static PCB_GROUP* Cast_to_PCB_GROUP( BOARD_ITEM* ); static PCB_GROUP* Cast_to_PCB_GROUP( BOARD_ITEM* );
static TEXTE_MODULE* Cast_to_TEXTE_MODULE( BOARD_ITEM* ); static TEXTE_MODULE* Cast_to_TEXTE_MODULE( BOARD_ITEM* );
@ -90,7 +94,9 @@ 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 LEADER* Cast_to_LEADER( BOARD_ITEM* );
static CENTER_DIMENSION* Cast_to_CENTER_DIMENSION( BOARD_ITEM* );
static MODULE* Cast_to_MODULE( BOARD_ITEM* ); static MODULE* Cast_to_MODULE( BOARD_ITEM* );
static PCB_GROUP* Cast_to_PCB_GROUP( BOARD_ITEM* ); static PCB_GROUP* Cast_to_PCB_GROUP( BOARD_ITEM* );
static TEXTE_MODULE* Cast_to_TEXTE_MODULE( BOARD_ITEM* ); static TEXTE_MODULE* Cast_to_TEXTE_MODULE( 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()
@ -168,7 +178,9 @@ static PCB_TARGET* Cast_to_PCB_TARGET( BOARD_ITEM* );
// 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 LEADER* Cast_to_LEADER( BOARD_ITEM* self ) { return dynamic_cast<LEADER*>(self); }
static CENTER_DIMENSION* Cast_to_CENTER_DIMENSION( BOARD_ITEM* self ) { return dynamic_cast<CENTER_DIMENSION*>(self); }
static MODULE* Cast_to_MODULE( BOARD_ITEM* self ) { return dynamic_cast<MODULE*>(self); } static MODULE* Cast_to_MODULE( BOARD_ITEM* self ) { return dynamic_cast<MODULE*>(self); }
static PCB_GROUP* Cast_to_PCB_GROUP( BOARD_ITEM* self ) { return dynamic_cast<PCB_GROUP*>(self); } static PCB_GROUP* Cast_to_PCB_GROUP( BOARD_ITEM* self ) { return dynamic_cast<PCB_GROUP*>(self); }
static TEXTE_MODULE* Cast_to_TEXTE_MODULE( BOARD_ITEM* self ) { return dynamic_cast<TEXTE_MODULE*>(self); } static TEXTE_MODULE* Cast_to_TEXTE_MODULE( BOARD_ITEM* self ) { return dynamic_cast<TEXTE_MODULE*>(self); }