Fixing a number of dynamic_casts

Dynamic casts should only be used when we explicitly check for the
resulting pointer to be NULL.  Where we know the class is castable we
can use static_cast, save on overhead and ensure our resulting pointer
is non-null.
This commit is contained in:
Seth Hillbrand 2018-10-11 05:12:22 -07:00
parent ddea4e11d1
commit 4f672f0d39
4 changed files with 12 additions and 9 deletions

View File

@ -194,5 +194,8 @@ void AbortBlockCurrentCommand( EDA_DRAW_PANEL* aPanel, wxDC* aDC )
aPanel->GetParent()->DisplayToolMsg( wxEmptyString ); aPanel->GetParent()->DisplayToolMsg( wxEmptyString );
// ugly, but temporary // ugly, but temporary
dynamic_cast<EDA_DRAW_PANEL_GAL*>( aPanel )->SetDefaultCursor(); auto gal_panel = dynamic_cast<EDA_DRAW_PANEL_GAL*>( aPanel );
if( gal_panel )
gal_panel->SetDefaultCursor();
} }

View File

@ -546,7 +546,7 @@ void LIB_EDIT_FRAME::LoadSettings( wxConfigBase* aCfg )
} }
} }
auto painter = dynamic_cast<KIGFX::SCH_PAINTER*>( GetCanvas()->GetView()->GetPainter() ); auto painter = static_cast<KIGFX::SCH_PAINTER*>( GetCanvas()->GetView()->GetPainter() );
KIGFX::SCH_RENDER_SETTINGS* settings = painter->GetSettings(); KIGFX::SCH_RENDER_SETTINGS* settings = painter->GetSettings();
settings->m_ShowPinsElectricalType = m_showPinElectricalTypeName; settings->m_ShowPinsElectricalType = m_showPinElectricalTypeName;

View File

@ -76,7 +76,7 @@ void RotateListOfItems( PICKED_ITEMS_LIST& aItemsList, const wxPoint& rotationPo
{ {
for( unsigned ii = 0; ii < aItemsList.GetCount(); ii++ ) for( unsigned ii = 0; ii < aItemsList.GetCount(); ii++ )
{ {
SCH_ITEM* item = dynamic_cast<SCH_ITEM*>( aItemsList.GetPickedItem( ii ) ); SCH_ITEM* item = static_cast<SCH_ITEM*>( aItemsList.GetPickedItem( ii ) );
item->Rotate( rotationPoint ); // Place it in its new position. item->Rotate( rotationPoint ); // Place it in its new position.
item->ClearFlags(); item->ClearFlags();
} }
@ -87,7 +87,7 @@ void MirrorY( PICKED_ITEMS_LIST& aItemsList, const wxPoint& aMirrorPoint )
{ {
for( unsigned ii = 0; ii < aItemsList.GetCount(); ii++ ) for( unsigned ii = 0; ii < aItemsList.GetCount(); ii++ )
{ {
SCH_ITEM* item = dynamic_cast<SCH_ITEM*>( aItemsList.GetPickedItem( ii ) ); SCH_ITEM* item = static_cast<SCH_ITEM*>( aItemsList.GetPickedItem( ii ) );
item->MirrorY( aMirrorPoint.x ); // Place it in its new position. item->MirrorY( aMirrorPoint.x ); // Place it in its new position.
item->ClearFlags(); item->ClearFlags();
} }
@ -98,7 +98,7 @@ void MirrorX( PICKED_ITEMS_LIST& aItemsList, const wxPoint& aMirrorPoint )
{ {
for( unsigned ii = 0; ii < aItemsList.GetCount(); ii++ ) for( unsigned ii = 0; ii < aItemsList.GetCount(); ii++ )
{ {
SCH_ITEM* item = dynamic_cast<SCH_ITEM*>( aItemsList.GetPickedItem( ii ) ); SCH_ITEM* item = static_cast<SCH_ITEM*>( aItemsList.GetPickedItem( ii ) );
item->MirrorX( aMirrorPoint.y ); // Place it in its new position. item->MirrorX( aMirrorPoint.y ); // Place it in its new position.
item->ClearFlags(); item->ClearFlags();
} }
@ -113,7 +113,7 @@ void SCH_EDIT_FRAME::CheckListConnections( PICKED_ITEMS_LIST& aItemsList, bool a
GetSchematicConnections( connections ); GetSchematicConnections( connections );
for( unsigned ii = 0; ii < aItemsList.GetCount(); ii++ ) for( unsigned ii = 0; ii < aItemsList.GetCount(); ii++ )
{ {
SCH_ITEM* item = dynamic_cast<SCH_ITEM*>( aItemsList.GetPickedItem( ii ) ); SCH_ITEM* item = static_cast<SCH_ITEM*>( aItemsList.GetPickedItem( ii ) );
std::vector< wxPoint > new_pts; std::vector< wxPoint > new_pts;
if( !item->IsConnectable() ) if( !item->IsConnectable() )
@ -165,7 +165,7 @@ void SCH_EDIT_FRAME::DeleteItemsInList( PICKED_ITEMS_LIST& aItemsList, bool aApp
{ {
for( unsigned ii = 0; ii < aItemsList.GetCount(); ii++ ) for( unsigned ii = 0; ii < aItemsList.GetCount(); ii++ )
{ {
SCH_ITEM* item = dynamic_cast<SCH_ITEM*>( aItemsList.GetPickedItem( ii ) ); SCH_ITEM* item = static_cast<SCH_ITEM*>( aItemsList.GetPickedItem( ii ) );
if( item->GetFlags() & STRUCT_DELETED ) if( item->GetFlags() & STRUCT_DELETED )
continue; continue;
@ -235,7 +235,7 @@ void SCH_EDIT_FRAME::DuplicateItemsInList( SCH_SCREEN* screen, PICKED_ITEMS_LIST
for( unsigned ii = 0; ii < aItemsList.GetCount(); ii++ ) for( unsigned ii = 0; ii < aItemsList.GetCount(); ii++ )
{ {
olditem = dynamic_cast<SCH_ITEM*>( aItemsList.GetPickedItem( ii ) ); olditem = static_cast<SCH_ITEM*>( aItemsList.GetPickedItem( ii ) );
newitem = DuplicateStruct( olditem ); newitem = DuplicateStruct( olditem );
aItemsList.SetPickedItem( newitem, ii ); aItemsList.SetPickedItem( newitem, ii );

View File

@ -1005,7 +1005,7 @@ void PNS_KICAD_IFACE::SyncWorld( PNS::NODE *aWorld )
} }
else if( gitem->Type() == PCB_TEXT_T ) else if( gitem->Type() == PCB_TEXT_T )
{ {
syncTextItem( aWorld, dynamic_cast<TEXTE_PCB*>( gitem ), gitem->GetLayer() ); syncTextItem( aWorld, static_cast<TEXTE_PCB*>( gitem ), gitem->GetLayer() );
} }
} }