Eradicate a bunch of calls to dyn_cast.

This commit is contained in:
Jeff Young 2023-06-24 18:19:44 +01:00
parent 994459fd47
commit 300a60e88e
9 changed files with 63 additions and 53 deletions

View File

@ -238,11 +238,12 @@ void BOARD_ADAPTER::createLayers( REPORTER* aStatusReporter )
if( !track->IsOnLayer( layer ) )
continue;
// Skip vias annulus when not connected on this layer (if removing is enabled)
const PCB_VIA *via = dyn_cast< const PCB_VIA*>( track );
if( via && IsCopperLayer( layer ) && !via->FlashLayer( layer ) )
// Skip vias annulus when not flashed on this layer
if( track->Type() == PCB_VIA_T
&& !static_cast<const PCB_VIA*>( track )->FlashLayer( layer ) )
{
continue;
}
// Add object item to layer container
createTrack( track, layerContainer );
@ -431,11 +432,12 @@ void BOARD_ADAPTER::createLayers( REPORTER* aStatusReporter )
if( !track->IsOnLayer( layer ) )
continue;
// Skip vias annulus when not connected on this layer (if removing is enabled)
const PCB_VIA *via = dyn_cast<const PCB_VIA*>( track );
if( via && !via->FlashLayer( layer ) && IsCopperLayer( layer ) )
// Skip vias annulus when not flashed on this layer
if( track->Type() == PCB_VIA_T
&& !static_cast<const PCB_VIA*>( track )->FlashLayer( layer ) )
{
continue;
}
// Add the track/via contour
track->TransformShapeToPolygon( *layerPoly, layer, 0, maxError, ERROR_INSIDE );

View File

@ -372,11 +372,13 @@ void SCH_COMMIT::Push( const wxString& aMessage, int aCommitFlags )
EDA_ITEM* SCH_COMMIT::parentObject( EDA_ITEM* aItem ) const
{
if( SCH_SYMBOL* parentSymbol = dyn_cast<SCH_SYMBOL*>( aItem->GetParent() ) )
return parentSymbol;
EDA_ITEM* parent = aItem->GetParent();
if( LIB_SYMBOL* parentSymbol = dyn_cast<LIB_SYMBOL*>( aItem->GetParent() ) )
return parentSymbol;
if( parent && parent->Type() == SCH_SYMBOL_T )
return parent;
if( parent && parent->Type() == LIB_SYMBOL_T )
return parent;
if( m_isLibEditor )
return static_cast<SYMBOL_EDIT_FRAME*>( m_toolMgr->GetToolHolder() )->GetCurSymbol();

View File

@ -1740,29 +1740,25 @@ void SCH_EDIT_FRAME::RecalculateConnections( SCH_COMMIT* aCommit, SCH_CLEANUP_FL
for( VECTOR2I& pt: pts )
{
for( SCH_ITEM* item : GetScreen()->Items().Overlapping(pt ) )
for( SCH_ITEM* item : GetScreen()->Items().Overlapping( pt ) )
{
if( !item->IsConnectable() )
continue;
if( SCH_LINE* line = dyn_cast<SCH_LINE*>( item ) )
if( item->Type() == SCH_LINE_T )
{
if( line->HitTest( pt ) )
{
if( item->HitTest( pt ) )
changed_items.insert( item );
continue;
}
}
if( SCH_SYMBOL* sym = dyn_cast<SCH_SYMBOL*>( item ) )
else if( item->Type() == SCH_SYMBOL_T )
{
std::vector<SCH_PIN*> pins = sym->GetPins();
changed_items.insert( pins.begin(), pins.end() );
continue;
}
SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
std::vector<SCH_PIN*> pins = symbol->GetPins();
if( item->IsConnected( pt ) )
changed_items.insert( item );
changed_items.insert( pins.begin(), pins.end() );
}
else if( item->IsConnectable() )
{
if( item->IsConnected( pt ) )
changed_items.insert( item );
}
}
}

View File

@ -284,8 +284,10 @@ void SCH_EDIT_FRAME::PutDataInPreviousState( PICKED_ITEMS_LIST* aList )
if( status == UNDO_REDO::NEWITEM )
{
// If we are removing the current sheet, get out first
if( SCH_SHEET* sheet = dyn_cast<SCH_SHEET*>( eda_item ) )
if( eda_item->Type() == SCH_SHEET_T )
{
SCH_SHEET* sheet = static_cast<SCH_SHEET*>( eda_item ) )
if( sheet->GetScreen() == GetScreen() )
GetToolManager()->RunAction( EE_ACTIONS::leaveSheet );
}

View File

@ -1371,7 +1371,7 @@ bool EE_SELECTION_TOOL::selectMultiple()
[&]( SCH_ITEM* aChild )
{
// Filter pins by unit
if( SCH_PIN* pin = dyn_cast<SCH_PIN*>( aChild ) )
if( SCH_PIN* pin = dynamic_cast<SCH_PIN*>( aChild ) )
{
int unit = pin->GetLibPin()->GetUnit();

View File

@ -2366,8 +2366,10 @@ int SCH_EDIT_TOOL::BreakWire( const TOOL_EVENT& aEvent )
for( EDA_ITEM* item : selection )
{
if( SCH_LINE* line = dyn_cast<SCH_LINE*>( item ) )
if( item->Type() == SCH_LINE_T )
{
SCH_LINE* line = static_cast<SCH_LINE*>( item );
if( !line->IsEndPoint( cursorPos ) )
lines.push_back( line );
}
@ -2535,21 +2537,23 @@ int SCH_EDIT_TOOL::SetAttribute( const TOOL_EVENT& aEvent )
for( EDA_ITEM* item : selection )
{
if( SCH_SYMBOL* sym = dyn_cast<SCH_SYMBOL*>( item ) )
if( item->Type() == SCH_SYMBOL_T )
{
commit.Modify( sym, m_frame->GetScreen() );
SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
commit.Modify( symbol, m_frame->GetScreen() );
if( aEvent.IsAction( &EE_ACTIONS::setDNP ) )
sym->SetDNP( true );
symbol->SetDNP( true );
if( aEvent.IsAction( &EE_ACTIONS::setExcludeFromSimulation ) )
sym->SetExcludeFromSim( true );
symbol->SetExcludeFromSim( true );
if( aEvent.IsAction( &EE_ACTIONS::setExcludeFromBOM ) )
sym->SetExcludedFromBOM( true );
symbol->SetExcludedFromBOM( true );
if( aEvent.IsAction( &EE_ACTIONS::setExcludeFromBoard ) )
sym->SetExcludedFromBoard( true );
symbol->SetExcludedFromBoard( true );
}
}
@ -2568,21 +2572,23 @@ int SCH_EDIT_TOOL::UnsetAttribute( const TOOL_EVENT& aEvent )
for( EDA_ITEM* item : selection )
{
if( SCH_SYMBOL* sym = dyn_cast<SCH_SYMBOL*>( item ) )
if( item->Type() == SCH_SYMBOL_T )
{
commit.Modify( sym, m_frame->GetScreen() );
SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
commit.Modify( symbol, m_frame->GetScreen() );
if( aEvent.IsAction( &EE_ACTIONS::unsetDNP ) )
sym->SetDNP( false );
symbol->SetDNP( false );
if( aEvent.IsAction( &EE_ACTIONS::unsetExcludeFromSimulation ) )
sym->SetExcludeFromSim( false );
symbol->SetExcludeFromSim( false );
if( aEvent.IsAction( &EE_ACTIONS::unsetExcludeFromBOM ) )
sym->SetExcludedFromBOM( false );
symbol->SetExcludedFromBOM( false );
if( aEvent.IsAction( &EE_ACTIONS::unsetExcludeFromBoard ) )
sym->SetExcludedFromBoard( false );
symbol->SetExcludedFromBoard( false );
}
}
@ -2601,21 +2607,23 @@ int SCH_EDIT_TOOL::ToggleAttribute( const TOOL_EVENT& aEvent )
for( EDA_ITEM* item : selection )
{
if( SCH_SYMBOL* sym = dyn_cast<SCH_SYMBOL*>( item ) )
if( item->Type() == SCH_SYMBOL_T )
{
commit.Modify( sym, m_frame->GetScreen() );
SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
commit.Modify( symbol, m_frame->GetScreen() );
if( aEvent.IsAction( &EE_ACTIONS::toggleDNP ) )
sym->SetDNP( !sym->GetDNP() );
symbol->SetDNP( !symbol->GetDNP() );
if( aEvent.IsAction( &EE_ACTIONS::toggleExcludeFromSimulation ) )
sym->SetExcludeFromSim( !sym->GetExcludeFromSim() );
symbol->SetExcludeFromSim( !symbol->GetExcludeFromSim() );
if( aEvent.IsAction( &EE_ACTIONS::toggleExcludeFromBOM ) )
sym->SetExcludedFromBOM( !sym->GetExcludedFromBOM() );
symbol->SetExcludedFromBOM( !symbol->GetExcludedFromBOM() );
if( aEvent.IsAction( &EE_ACTIONS::toggleExcludeFromBoard ) )
sym->SetExcludedFromBoard( !sym->GetExcludedFromBoard() );
symbol->SetExcludedFromBoard( !symbol->GetExcludedFromBoard() );
}
}

View File

@ -1908,7 +1908,7 @@ std::tuple<int, double, double> BOARD::GetTrackLength( const PCB_TRACK& aTrack )
if( !inPad )
length += segLen + segInPadLen;
}
else if( PAD* pad = dyn_cast<PAD*>( item ) )
else if( PAD* pad = dynamic_cast<PAD*>( item ) )
{
package_length += pad->GetPadToDieLength();
}

View File

@ -124,7 +124,7 @@ void CLIPBOARD_IO::SaveSelection( const PCB_SELECTION& aSelected, bool isFootpri
clone = static_cast<BOARD_ITEM*>( item->Clone() );
// If it is only a footprint, clear the nets from the pads
if( PAD* pad = dyn_cast<PAD*>( clone ) )
if( PAD* pad = dynamic_cast<PAD*>( clone ) )
pad->SetNetCode( 0 );
// Don't copy group membership information for the 1st level objects being copied

View File

@ -1388,7 +1388,7 @@ int BOARD_EDITOR_CONTROL::ZoneDuplicate( const TOOL_EVENT& aEvent )
if( selection.Size() != 1 )
return 0;
ZONE* oldZone = dyn_cast<ZONE*>( selection[0] );
ZONE* oldZone = dynamic_cast<ZONE*>( selection[0] );
if( !oldZone )
return 0;