Eradicate a bunch of calls to dyn_cast.

Also deletes PAD::GetParent() which fails to look for parent footprint
through groups.
This commit is contained in:
Jeff Young 2023-06-24 19:54:50 +01:00
parent 300a60e88e
commit 493828cc6b
26 changed files with 192 additions and 230 deletions

View File

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

View File

@ -310,8 +310,9 @@ void EE_GRID_HELPER::computeAnchors( SCH_ITEM *aItem, const VECTOR2I &aRefPos, b
break;
}
if( SCH_LINE* line = dyn_cast<SCH_LINE*>( aItem ) )
if( aItem->Type() == SCH_LINE_T )
{
SCH_LINE* line = static_cast<SCH_LINE*>( aItem );
VECTOR2I pt = Align( aRefPos );
if( line->GetStartPoint().x == line->GetEndPoint().x )
@ -328,7 +329,6 @@ void EE_GRID_HELPER::computeAnchors( SCH_ITEM *aItem, const VECTOR2I &aRefPos, b
if( TestSegmentHit( possible, line->GetStartPoint(), line->GetEndPoint(), 0 ) )
addAnchor( possible, SNAPPABLE | HORIZONTAL, aItem );
}
}
}

View File

@ -869,25 +869,25 @@ bool CN_VISITOR::operator()( CN_ITEM* aCandidate )
FLASHING flashingA = FLASHING::NEVER_FLASHED;
FLASHING flashingB = FLASHING::NEVER_FLASHED;
if( const PAD* pad = dyn_cast<const PAD*>( parentA ) )
if( parentA->Type() == PCB_PAD_T )
{
if( !pad->ConditionallyFlashed( layer ) )
if( !static_cast<const PAD*>( parentA )->ConditionallyFlashed( layer ) )
flashingA = FLASHING::ALWAYS_FLASHED;
}
else if( const PCB_VIA* via = dyn_cast<const PCB_VIA*>( parentA ) )
else if( parentA->Type() == PCB_VIA_T )
{
if( !via->ConditionallyFlashed( layer ) )
if( !static_cast<const PCB_VIA*>( parentA )->ConditionallyFlashed( layer ) )
flashingA = FLASHING::ALWAYS_FLASHED;
}
if( const PAD* pad = dyn_cast<const PAD*>( parentB ) )
if( parentB->Type() == PCB_PAD_T )
{
if( !pad->ConditionallyFlashed( layer ) )
if( !static_cast<const PAD*>( parentB )->ConditionallyFlashed( layer ) )
flashingB = FLASHING::ALWAYS_FLASHED;
}
else if( const PCB_VIA* via = dyn_cast<const PCB_VIA*>( parentB ) )
else if( parentB->Type() == PCB_VIA_T )
{
if( !via->ConditionallyFlashed( layer ) )
if( !static_cast<const PCB_VIA*>( parentB )->ConditionallyFlashed( layer ) )
flashingB = FLASHING::ALWAYS_FLASHED;
}

View File

@ -909,9 +909,7 @@ CONNECTIVITY_DATA::GetConnectedItemsAtAnchor( const BOARD_CONNECTED_ITEM* aItem,
RN_NET* CONNECTIVITY_DATA::GetRatsnestForNet( int aNet )
{
if ( aNet < 0 || aNet >= (int) m_nets.size() )
{
return nullptr;
}
return m_nets[ aNet ];
}
@ -924,10 +922,9 @@ void CONNECTIVITY_DATA::MarkItemNetAsDirty( BOARD_ITEM *aItem )
for( PAD* pad : static_cast<FOOTPRINT*>( aItem )->Pads() )
m_connAlgo->MarkNetAsDirty( pad->GetNetCode() );
}
if (aItem->IsConnected() )
{
m_connAlgo->MarkNetAsDirty( static_cast<BOARD_CONNECTED_ITEM*>( aItem )->GetNetCode() );
}
}
@ -938,7 +935,8 @@ void CONNECTIVITY_DATA::SetProgressReporter( PROGRESS_REPORTER* aReporter )
}
const std::vector<CN_EDGE> CONNECTIVITY_DATA::GetRatsnestForItems( std::vector<BOARD_ITEM*> aItems )
const std::vector<CN_EDGE>
CONNECTIVITY_DATA::GetRatsnestForItems( const std::vector<BOARD_ITEM*>& aItems )
{
std::set<int> nets;
std::vector<CN_EDGE> edges;
@ -956,8 +954,10 @@ const std::vector<CN_EDGE> CONNECTIVITY_DATA::GetRatsnestForItems( std::vector<B
item_set.insert( pad );
}
}
else if( auto conn_item = dyn_cast<BOARD_CONNECTED_ITEM*>( item ) )
else if( item->IsConnected() )
{
BOARD_CONNECTED_ITEM* conn_item = static_cast<BOARD_CONNECTED_ITEM*>( item );
item_set.insert( conn_item );
nets.insert( conn_item->GetNetCode() );
}
@ -1002,7 +1002,8 @@ const std::vector<CN_EDGE> CONNECTIVITY_DATA::GetRatsnestForPad( const PAD* aPad
}
const std::vector<CN_EDGE> CONNECTIVITY_DATA::GetRatsnestForComponent( FOOTPRINT* aComponent, bool aSkipInternalConnections )
const std::vector<CN_EDGE> CONNECTIVITY_DATA::GetRatsnestForComponent( FOOTPRINT* aComponent,
bool aSkipInternalConnections )
{
std::set<int> nets;
std::set<const PAD*> pads;
@ -1014,14 +1015,12 @@ const std::vector<CN_EDGE> CONNECTIVITY_DATA::GetRatsnestForComponent( FOOTPRINT
pads.insert( pad );
}
for( const auto& netcode : nets )
for( int netcode : nets )
{
RN_NET* net = GetRatsnestForNet( netcode );
for( const CN_EDGE& edge : net->GetEdges() )
for( const CN_EDGE& edge : GetRatsnestForNet( netcode )->GetEdges() )
{
auto srcNode = edge.GetSourceNode();
auto dstNode = edge.GetTargetNode();
const std::shared_ptr<const CN_ANCHOR>& srcNode = edge.GetSourceNode();
const std::shared_ptr<const CN_ANCHOR>& dstNode = edge.GetTargetNode();
const PAD* srcParent = static_cast<const PAD*>( srcNode->Parent() );
const PAD* dstParent = static_cast<const PAD*>( dstNode->Parent() );
@ -1030,15 +1029,11 @@ const std::vector<CN_EDGE> CONNECTIVITY_DATA::GetRatsnestForComponent( FOOTPRINT
bool dstFound = ( pads.find(dstParent) != pads.end() );
if ( srcFound && dstFound && !aSkipInternalConnections )
{
edges.push_back( edge );
}
else if ( srcFound || dstFound )
{
edges.push_back( edge );
}
}
}
return edges;
}

View File

@ -271,7 +271,7 @@ public:
const std::map<int, wxString>& GetNetclassMap() const { return m_netclassMap; }
#ifndef SWIG
const std::vector<CN_EDGE> GetRatsnestForItems( const std::vector<BOARD_ITEM*> aItems );
const std::vector<CN_EDGE> GetRatsnestForItems( const std::vector<BOARD_ITEM*>& aItems );
const std::vector<CN_EDGE> GetRatsnestForPad( const PAD* aPad );

View File

@ -141,11 +141,12 @@ int FROM_TO_CACHE::cacheFromToPaths( const wxString& aFrom, const wxString& aTo
{
int count = 0;
wxString fromName = path.from->GetParent()->GetReference() + wxT( "-" )
+ path.from->GetNumber();
wxString fromName = path.from->GetParentFootprint()->GetReference()
+ wxT( "-" ) + path.from->GetNumber();
auto padCandidates = connectivity->GetConnectedItems( path.from,
{ PCB_PAD_T, PCB_ARC_T, PCB_VIA_T, PCB_TRACE_T } );
{ PCB_PAD_T, PCB_ARC_T, PCB_VIA_T,
PCB_TRACE_T } );
PAD* toPad = nullptr;
for( BOARD_CONNECTED_ITEM* pitem : padCandidates )
@ -158,8 +159,8 @@ int FROM_TO_CACHE::cacheFromToPaths( const wxString& aFrom, const wxString& aTo
const PAD *pad = static_cast<const PAD*>( pitem );
wxString toName = pad->GetParent()->GetReference() + wxT( "-" ) + pad->GetNumber();
wxString toName = pad->GetParentFootprint()->GetReference()
+ wxT( "-" ) + pad->GetNumber();
for( const FT_ENDPOINT& endpoint : m_ftEndpoints )
{

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2019 Alexander Shuklin, jasuramme@gmail.com
* Copyright (C) 2019-2022 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 2019-2023 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -282,8 +282,10 @@ void DIALOG_BOARD_STATISTICS::getDataFromPCB()
// Get via counts
for( PCB_TRACK* track : board->Tracks() )
{
if( PCB_VIA* via = dyn_cast<PCB_VIA*>( track ) )
if( track->Type() == PCB_VIA_T )
{
PCB_VIA* via = static_cast<PCB_VIA*>( track );
for( LINE_ITEM<VIATYPE>& line : m_viaTypes )
{
if( via->GetViaType() == line.attribute )

View File

@ -490,7 +490,7 @@ void DIALOG_PAD_PROPERTIES::initValues()
if( m_currentPad )
{
if( FOOTPRINT* footprint = m_currentPad->GetParent() )
if( FOOTPRINT* footprint = m_currentPad->GetParentFootprint() )
{
VECTOR2I relPos = m_currentPad->GetFPRelativePosition();

View File

@ -37,8 +37,6 @@
#include <board_commit.h>
#include <macros.h>
#include <wx/log.h>
DIALOG_TRACK_VIA_PROPERTIES::DIALOG_TRACK_VIA_PROPERTIES( PCB_BASE_FRAME* aParent,
const PCB_SELECTION& aItems,
BOARD_COMMIT& aCommit ) :
@ -502,7 +500,7 @@ bool DIALOG_TRACK_VIA_PROPERTIES::confirmPadChange( const std::vector<PAD*>& cha
{
PAD* pad = *changingPads.begin();
msg.Printf( _( "Changing the net will also update %s pad %s to %s." ),
pad->GetParent()->GetReference(),
pad->GetParentFootprint()->GetReference(),
pad->GetNumber(),
m_netSelector->GetValue() );
}
@ -511,9 +509,9 @@ bool DIALOG_TRACK_VIA_PROPERTIES::confirmPadChange( const std::vector<PAD*>& cha
PAD* pad1 = *changingPads.begin();
PAD* pad2 = *( ++changingPads.begin() );
msg.Printf( _( "Changing the net will also update %s pad %s and %s pad %s to %s." ),
pad1->GetParent()->GetReference(),
pad1->GetParentFootprint()->GetReference(),
pad1->GetNumber(),
pad2->GetParent()->GetReference(),
pad2->GetParentFootprint()->GetReference(),
pad2->GetNumber(),
m_netSelector->GetValue() );
}

View File

@ -205,8 +205,8 @@ bool padNeedsUpdate( const PAD* a, const PAD* b )
TEST( a->GetProperty(), b->GetProperty(), "" );
// The pad orientation, for historical reasons is the pad rotation + parent rotation.
TEST_D( ( a->GetOrientation() - a->GetParent()->GetOrientation() ).Normalize().AsDegrees(),
( b->GetOrientation() - b->GetParent()->GetOrientation() ).Normalize().AsDegrees(),
TEST_D( ( a->GetOrientation() - a->GetParentFootprint()->GetOrientation() ).Normalize().AsDegrees(),
( b->GetOrientation() - b->GetParentFootprint()->GetOrientation() ).Normalize().AsDegrees(),
"" );
TEST( a->GetSize(), b->GetSize(), "" );

View File

@ -1,7 +1,7 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2004-2022 KiCad Developers.
* Copyright (C) 2004-2023 KiCad Developers.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -38,12 +38,10 @@ class DRC_TEST_PROVIDER_TRACK_WIDTH : public DRC_TEST_PROVIDER
{
public:
DRC_TEST_PROVIDER_TRACK_WIDTH()
{
}
{}
virtual ~DRC_TEST_PROVIDER_TRACK_WIDTH()
{
}
{}
virtual bool Run() override;
@ -85,15 +83,19 @@ bool DRC_TEST_PROVIDER_TRACK_WIDTH::Run()
int actual;
VECTOR2I p0;
if( PCB_ARC* arc = dyn_cast<PCB_ARC*>( item ) )
if( item->Type() == PCB_ARC_T )
{
PCB_ARC* arc = static_cast<PCB_ARC*>( item );
actual = arc->GetWidth();
p0 = arc->GetStart();
}
else if( PCB_TRACK* trk = dyn_cast<PCB_TRACK*>( item ) )
else if( item->Type() == PCB_TRACE_T )
{
actual = trk->GetWidth();
p0 = ( trk->GetStart() + trk->GetEnd() ) / 2;
PCB_TRACK* track = static_cast<PCB_TRACK*>( item );
actual = track->GetWidth();
p0 = ( track->GetStart() + track->GetEnd() ) / 2;
}
else
{

View File

@ -1,7 +1,7 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2004-2022 KiCad Developers.
* Copyright (C) 2004-2023 KiCad Developers.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -38,12 +38,10 @@ class DRC_TEST_PROVIDER_VIA_DIAMETER : public DRC_TEST_PROVIDER
{
public:
DRC_TEST_PROVIDER_VIA_DIAMETER()
{
}
{}
virtual ~DRC_TEST_PROVIDER_VIA_DIAMETER()
{
}
{}
virtual bool Run() override;
@ -82,12 +80,11 @@ bool DRC_TEST_PROVIDER_VIA_DIAMETER::Run()
if( m_drcEngine->IsErrorLimitExceeded( DRCE_VIA_DIAMETER ) )
return false;
PCB_VIA* via = dyn_cast<PCB_VIA*>( item );
// fixme: move to pad stack check?
if( !via )
if( item->Type() != PCB_VIA_T )
return true;
PCB_VIA* via = static_cast<PCB_VIA*>( item );
// TODO: once we have padstacks this will need to run per-layer...
auto constraint = m_drcEngine->EvalRules( VIA_DIAMETER_CONSTRAINT, item, nullptr,
UNDEFINED_LAYER );

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2019 CERN
* Copyright (C) 2022 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 2022-2023 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -37,8 +37,6 @@
#include <ki_exception.h>
#include <locale_io.h>
#include <reporter.h>
#include <wx/log.h>
#include <exporters/board_exporter_base.h>
static double iu2hyp( double iu )
@ -431,7 +429,7 @@ bool HYPERLYNX_EXPORTER::writeNetObjects( const std::vector<BOARD_ITEM*>& aObjec
if( pstackIter != m_padMap.end() )
{
wxString ref = pad->GetParent()->GetReference();
wxString ref = pad->GetParentFootprint()->GetReference();
if( ref.IsEmpty() )
ref = wxT( "EMPTY" );

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2017 Jean_Pierre Charras <jp.charras at wanadoo.fr>
* Copyright (C) 1992-2021 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 1992-2023 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -224,7 +224,7 @@ int GERBER_WRITER::createDrillFile( wxString& aFullFilename, bool aIsNpth,
}
// Add object attribute: component reference to pads (mainly useful for users)
wxString ref = pad->GetParent()->GetReference();
wxString ref = pad->GetParentFootprint()->GetReference();
gbr_metadata.SetCmpReference( ref );
gbr_metadata.SetNetAttribType( GBR_NETLIST_METADATA::GBR_NETINFO_CMP );

View File

@ -229,7 +229,7 @@ LSET PAD::ApertureMask()
bool PAD::IsFlipped() const
{
FOOTPRINT* parent = GetParent();
FOOTPRINT* parent = GetParentFootprint();
return ( parent && parent->GetLayer() == B_Cu );
}
@ -805,8 +805,8 @@ int PAD::GetLocalClearanceOverrides( wxString* aSource ) const
return GetLocalClearance( aSource );
// A footprint can have a specific clearance value
if( GetParent() && GetParent()->GetLocalClearance() )
return GetParent()->GetLocalClearance( aSource );
if( GetParent() && GetParentFootprint()->GetLocalClearance() )
return GetParentFootprint()->GetLocalClearance( aSource );
return 0;
}
@ -857,9 +857,7 @@ int PAD::GetSolderMaskExpansion() const
int margin = m_localSolderMaskMargin;
FOOTPRINT* parentFootprint = GetParent();
if( parentFootprint )
if( FOOTPRINT* parentFootprint = GetParentFootprint() )
{
if( margin == 0 )
{
@ -900,9 +898,7 @@ VECTOR2I PAD::GetSolderPasteMargin() const
int margin = m_localSolderPasteMargin;
double mratio = m_localSolderPasteMarginRatio;
FOOTPRINT* parentFootprint = GetParent();
if( parentFootprint )
if( FOOTPRINT* parentFootprint = GetParentFootprint() )
{
if( margin == 0 )
margin = parentFootprint->GetLocalSolderPasteMargin();
@ -1255,18 +1251,18 @@ wxString PAD::GetItemDescription( UNITS_PROVIDER* aUnitsProvider ) const
{
return wxString::Format( _( "Pad %s of %s on %s" ),
GetNetnameMsg(),
GetParent()->GetReference(),
GetParentFootprint()->GetReference(),
layerMaskDescribe() );
}
else if( GetAttribute() == PAD_ATTRIB::NPTH )
{
return wxString::Format( _( "NPTH pad of %s" ), GetParent()->GetReference() );
return wxString::Format( _( "NPTH pad of %s" ), GetParentFootprint()->GetReference() );
}
else
{
return wxString::Format( _( "PTH pad %s of %s" ),
GetNetnameMsg(),
GetParent()->GetReference() );
GetParentFootprint()->GetReference() );
}
}
else
@ -1276,19 +1272,19 @@ wxString PAD::GetItemDescription( UNITS_PROVIDER* aUnitsProvider ) const
return wxString::Format( _( "Pad %s %s of %s on %s" ),
GetNumber(),
GetNetnameMsg(),
GetParent()->GetReference(),
GetParentFootprint()->GetReference(),
layerMaskDescribe() );
}
else if( GetAttribute() == PAD_ATTRIB::NPTH )
{
return wxString::Format( _( "NPTH of %s" ), GetParent()->GetReference() );
return wxString::Format( _( "NPTH of %s" ), GetParentFootprint()->GetReference() );
}
else
{
return wxString::Format( _( "PTH pad %s %s of %s" ),
GetNumber(),
GetNetnameMsg(),
GetParent()->GetReference() );
GetParentFootprint()->GetReference() );
}
}
}
@ -1369,17 +1365,6 @@ void PAD::ViewGetLayers( int aLayers[], int& aCount ) const
if( IsOnLayer( each_layer ) )
aLayers[aCount++] = each_layer;
}
#ifdef DEBUG
if( aCount == 0 ) // Should not occur
{
wxString msg;
msg.Printf( wxT( "footprint %s, pad %s: could not find valid layer for pad" ),
GetParent() ? GetParent()->GetReference() : wxString( wxT( "<null>" ) ),
GetNumber().IsEmpty() ? wxString(wxT( "(unnumbered)" ) ) : GetNumber() );
wxLogDebug( msg );
}
#endif
}
@ -1476,12 +1461,6 @@ const BOX2I PAD::ViewBBox() const
}
FOOTPRINT* PAD::GetParent() const
{
return dyn_cast<FOOTPRINT*>( m_parent );
}
void PAD::ImportSettingsFrom( const PAD& aMasterPad )
{
SetShape( aMasterPad.GetShape() );
@ -1499,10 +1478,10 @@ void PAD::ImportSettingsFrom( const PAD& aMasterPad )
EDA_ANGLE pad_rot = aMasterPad.GetOrientation();
if( aMasterPad.GetParent() )
pad_rot -= aMasterPad.GetParent()->GetOrientation();
pad_rot -= aMasterPad.GetParentFootprint()->GetOrientation();
if( GetParent() )
pad_rot += GetParent()->GetOrientation();
pad_rot += GetParentFootprint()->GetOrientation();
SetOrientation( pad_rot );

View File

@ -108,8 +108,6 @@ public:
return GetDrillSizeX() > 0 && GetDrillSizeY() > 0;
}
FOOTPRINT* GetParent() const;
wxString GetParentAsString() const;
bool IsLocked() const override;

View File

@ -33,7 +33,6 @@
#include <pcb_group.h>
#include <geometry/shape_segment.h>
#include <pcb_expr_evaluator.h>
#include <connectivity/connectivity_data.h>
#include <connectivity/connectivity_algo.h>
#include <connectivity/from_to_cache.h>
@ -873,10 +872,11 @@ static void isMicroVia( LIBEVAL::CONTEXT* aCtx, void* self )
result->Set( 0.0 );
aCtx->Push( result );
PCB_VIA* via = dyn_cast<PCB_VIA*>( item );
if( via && via->GetViaType() == VIATYPE::MICROVIA )
if( item && item->Type() == PCB_VIA_T
&& static_cast<PCB_VIA*>( item )->GetViaType() == VIATYPE::MICROVIA )
{
result->Set ( 1.0 );
}
}
@ -889,10 +889,11 @@ static void isBlindBuriedViaFunc( LIBEVAL::CONTEXT* aCtx, void* self )
result->Set( 0.0 );
aCtx->Push( result );
PCB_VIA* via = dyn_cast<PCB_VIA*>( item );
if( via && via->GetViaType() == VIATYPE::BLIND_BURIED )
if( item && item->Type() == PCB_VIA_T
&& static_cast<PCB_VIA*>( item )->GetViaType() == VIATYPE::MICROVIA )
{
result->Set ( 1.0 );
}
}

View File

@ -36,18 +36,14 @@
#include <geometry/shape_segment.h>
#include <pcb_base_frame.h>
#include <math/util.h> // for KiROUND
#include <board.h>
#include <board_design_settings.h>
#include <footprint.h>
#include <pcb_track.h>
#include <pcb_text.h>
#include <pad.h>
#include <zone.h>
#include <pcb_shape.h>
#include <pcb_target.h>
#include <pcb_dimension.h>
#include <pcbplot.h>
#include <plotters/plotter_dxf.h>
#include <plotters/plotter_hpgl.h>
@ -566,11 +562,11 @@ void PlotStandardLayer( BOARD* aBoard, PLOTTER* aPlotter, LSET aLayerMask,
for( const PCB_TRACK* track : aBoard->Tracks() )
{
const PCB_VIA* via = dyn_cast<const PCB_VIA*>( track );
if( !via )
if( track->Type() != PCB_VIA_T )
continue;
const PCB_VIA* via = static_cast<const PCB_VIA*>( track );
// vias are not plotted if not on selected layer, but if layer is SOLDERMASK_LAYER_BACK
// or SOLDERMASK_LAYER_FRONT, vias are drawn only if they are on the corresponding
// external copper layer
@ -782,9 +778,12 @@ void PlotLayerOutlines( BOARD* aBoard, PLOTTER* aPlotter, LSET aLayerMask,
// Plot vias holes
for( PCB_TRACK* track : aBoard->Tracks() )
{
const PCB_VIA* via = dyn_cast<const PCB_VIA*>( track );
if( track->Type() != PCB_VIA_T )
continue;
if( via && via->IsOnLayer( layer ) ) // via holes can be not through holes
const PCB_VIA* via = static_cast<const PCB_VIA*>( track );
if( via->IsOnLayer( layer ) ) // via holes can be not through holes
aPlotter->Circle( via->GetPosition(), via->GetDrillValue(), FILL_T::NO_FILL );
}
}
@ -906,10 +905,13 @@ void PlotSolderMaskLayer( BOARD *aBoard, PLOTTER* aPlotter, LSET aLayerMask,
// Plot (untented) vias
for( const PCB_TRACK* track : aBoard->Tracks() )
{
const PCB_VIA* via = dyn_cast<const PCB_VIA*>( track );
if( track->Type() != PCB_VIA_T )
continue;
const PCB_VIA* via = static_cast<const PCB_VIA*>( track );
// Note: IsOnLayer() checks relevant mask layers of untented vias
if( !via || !via->IsOnLayer( layer ) )
if( !via->IsOnLayer( layer ) )
continue;
int clearance = via->GetSolderMaskExpansion();

View File

@ -83,7 +83,7 @@ void BRDITEMS_PLOTTER::PlotPad( const PAD* aPad, const COLOR4D& aColor, OUTLINE_
// Not yet in use.
// bool isPadOnBoardTechLayers = ( aPad->GetLayerSet() & LSET::AllBoardTechMask() ).any();
metadata.SetCmpReference( aPad->GetParent()->GetReference() );
metadata.SetCmpReference( aPad->GetParentFootprint()->GetReference() );
if( plotOnCopperLayer )
{
@ -308,7 +308,7 @@ void BRDITEMS_PLOTTER::PlotFootprintTextItems( const FOOTPRINT* aFootprint )
for( BOARD_ITEM* item : aFootprint->GraphicalItems() )
{
textItem = dyn_cast<const PCB_TEXT*>( item );
textItem = dynamic_cast<const PCB_TEXT*>( item );
if( textItem )
texts.push_back( static_cast<PCB_TEXT*>( item ) );
@ -925,12 +925,12 @@ void BRDITEMS_PLOTTER::PlotDrillMarks()
if( GetPlotMode() == FILLED )
m_plotter->SetColor( WHITE );
for( PCB_TRACK* tracks : m_board->Tracks() )
for( PCB_TRACK* track : m_board->Tracks() )
{
const PCB_VIA* via = dyn_cast<const PCB_VIA*>( tracks );
if( track->Type() == PCB_VIA_T )
{
const PCB_VIA* via = static_cast<const PCB_VIA*>( track );
if( via )
{
plotOneDrillMark( PAD_DRILL_SHAPE_CIRCLE, via->GetStart(),
VECTOR2I( via->GetDrillValue(), 0 ), VECTOR2I( via->GetWidth(), 0 ),
ANGLE_0, smallDrill );

View File

@ -2465,7 +2465,7 @@ void EAGLE_PLUGIN::transferPad( const EPAD_COMMON& aEaglePad, PAD* aPad ) const
if( aEaglePad.thermals && !*aEaglePad.thermals )
aPad->SetZoneConnection( ZONE_CONNECTION::FULL );
FOOTPRINT* footprint = aPad->GetParent();
FOOTPRINT* footprint = aPad->GetParentFootprint();
wxCHECK( footprint, /* void */ );
RotatePoint( padPos, footprint->GetOrientation() );
aPad->SetPosition( padPos + footprint->GetPosition() );

View File

@ -57,9 +57,7 @@
#include <macros.h>
#include "pns_kicad_iface.h"
#include "pns_arc.h"
#include "pns_routing_settings.h"
#include "pns_sizes_settings.h"
#include "pns_item.h"
#include "pns_line.h"
@ -1950,7 +1948,7 @@ void PNS_KICAD_IFACE::Commit()
for( const auto& [ pad, fpOffset ] : m_fpOffsets )
{
VECTOR2I offset = fpOffset.p_new - fpOffset.p_old;
FOOTPRINT* footprint = pad->GetParent();
FOOTPRINT* footprint = pad->GetParentFootprint();
VECTOR2I p_orig = footprint->GetPosition();
VECTOR2I p_new = p_orig + offset;

View File

@ -2004,7 +2004,7 @@ bool DRAWING_TOOL::drawShape( const TOOL_EVENT& aTool, PCB_SHAPE** aGraphic,
}
else
{
PCB_SHAPE* snapItem = dyn_cast<PCB_SHAPE*>( grid.GetSnapped() );
PCB_SHAPE* snapItem = dynamic_cast<PCB_SHAPE*>( grid.GetSnapped() );
if( twoPointManager.GetOrigin() == twoPointManager.GetEnd()
|| ( evt->IsDblClick( BUT_LEFT ) && shape == SHAPE_T::SEGMENT )
@ -2493,8 +2493,8 @@ bool DRAWING_TOOL::getSourceZoneForAction( ZONE_MODE aMode, ZONE** aZone )
}
// we want a single zone
if( selection.Size() == 1 )
*aZone = dyn_cast<ZONE*>( selection[0] );
if( selection.Size() == 1 && selection[0]->Type() == PCB_ZONE_T )
*aZone = static_cast<ZONE*>( selection[0] );
// expected a zone, but didn't get one
if( !*aZone )
@ -2813,8 +2813,10 @@ int DRAWING_TOOL::DrawVia( const TOOL_EVENT& aEvent )
if( !( item->GetLayerSet() & lset ).any() )
continue;
if( PCB_TRACK* track = dyn_cast<PCB_TRACK*>( item ) )
if( item->Type() == PCB_TRACE_T || item->Type() == PCB_ARC_T )
{
PCB_TRACK* track = static_cast<PCB_TRACK*>( item );
if( TestSegmentHit( position, track->GetStart(), track->GetEnd(),
( track->GetWidth() + aVia->GetWidth() ) / 2 ) )
{

View File

@ -903,24 +903,14 @@ int EDIT_TOOL::FilletTracks( const TOOL_EVENT& aEvent )
bool didOneAttemptFail = false;
std::set<PCB_TRACK*> processedTracks;
for( EDA_ITEM* item : selection )
{
PCB_TRACK* track = dyn_cast<PCB_TRACK*>( item );
if( !track || track->Type() != PCB_TRACE_T || track->GetLength() == 0 )
{
continue;
}
auto processFilletOp =
[&]( bool aStartPoint )
[&]( PCB_TRACK* aTrack, bool aStartPoint )
{
std::shared_ptr<CONNECTIVITY_DATA> c = board()->GetConnectivity();
VECTOR2I anchor = aStartPoint ? track->GetStart()
: track->GetEnd();
VECTOR2I anchor = aStartPoint ? aTrack->GetStart() : aTrack->GetEnd();
std::vector<BOARD_CONNECTED_ITEM*> itemsOnAnchor;
itemsOnAnchor = c->GetConnectedItemsAtAnchor( track, anchor,
itemsOnAnchor = c->GetConnectedItemsAtAnchor( aTrack, anchor,
{ PCB_PAD_T, PCB_VIA_T,
PCB_TRACE_T, PCB_ARC_T } );
@ -928,7 +918,7 @@ int EDIT_TOOL::FilletTracks( const TOOL_EVENT& aEvent )
&& selection.Contains( itemsOnAnchor.at( 0 ) )
&& itemsOnAnchor.at( 0 )->Type() == PCB_TRACE_T )
{
PCB_TRACK* trackOther = dyn_cast<PCB_TRACK*>( itemsOnAnchor.at( 0 ) );
PCB_TRACK* trackOther = static_cast<PCB_TRACK*>( itemsOnAnchor.at( 0 ) );
// Make sure we don't fillet the same pair of tracks twice
if( processedTracks.find( trackOther ) == processedTracks.end() )
@ -936,10 +926,10 @@ int EDIT_TOOL::FilletTracks( const TOOL_EVENT& aEvent )
if( itemsOnAnchor.size() == 1 )
{
FILLET_OP filletOp;
filletOp.t1 = track;
filletOp.t1 = aTrack;
filletOp.t2 = trackOther;
filletOp.t1Start = aStartPoint;
filletOp.t2Start = track->IsPointOnEnds( filletOp.t2->GetStart() );
filletOp.t2Start = aTrack->IsPointOnEnds( filletOp.t2->GetStart() );
filletOperations.push_back( filletOp );
}
else
@ -952,11 +942,21 @@ int EDIT_TOOL::FilletTracks( const TOOL_EVENT& aEvent )
}
};
processFilletOp( true ); // on the start point of track
processFilletOp( false ); // on the end point of track
for( EDA_ITEM* item : selection )
{
if( item->Type() == PCB_TRACE_T )
{
PCB_TRACK* track = static_cast<PCB_TRACK*>( item );
if( track->GetLength() > 0 )
{
processFilletOp( track, true ); // on the start point of track
processFilletOp( track, false ); // on the end point of track
processedTracks.insert( track );
}
}
}
std::vector<BOARD_ITEM*> itemsToAddToSelection;
@ -1061,7 +1061,6 @@ int EDIT_TOOL::FilletLines( const TOOL_EVENT& aEvent )
PCB_SELECTION& selection = m_selectionTool->RequestSelection(
[]( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector, PCB_SELECTION_TOOL* sTool )
{
std::vector<VECTOR2I> pts;
// Iterate from the back so we don't have to worry about removals.

View File

@ -187,13 +187,10 @@ int PAD_TOOL::copyPadSettings( const TOOL_EVENT& aEvent )
static void doPushPadProperties( BOARD& board, const PAD& aSrcPad, BOARD_COMMIT& commit,
bool aSameFootprints,
bool aPadShapeFilter,
bool aPadOrientFilter,
bool aPadLayerFilter,
bool aPadTypeFilter )
bool aSameFootprints, bool aPadShapeFilter, bool aPadOrientFilter,
bool aPadLayerFilter, bool aPadTypeFilter )
{
const FOOTPRINT* refFootprint = aSrcPad.GetParent();
const FOOTPRINT* refFootprint = aSrcPad.GetParentFootprint();
EDA_ANGLE srcPadAngle = aSrcPad.GetOrientation() - refFootprint->GetOrientation();
@ -241,18 +238,13 @@ int PAD_TOOL::pushPadSettings( const TOOL_EVENT& aEvent )
{
PCB_SELECTION_TOOL* selTool = m_toolMgr->GetTool<PCB_SELECTION_TOOL>();
const PCB_SELECTION& selection = selTool->GetSelection();
PAD* srcPad;
if( selection.Size() == 1 && selection[0]->Type() == PCB_PAD_T )
srcPad = static_cast<PAD*>( selection[0] );
else
return 0;
FOOTPRINT* footprint = srcPad->GetParent();
if( !footprint )
return 0;
{
PAD* srcPad = static_cast<PAD*>( selection[0] );
if( FOOTPRINT* footprint = srcPad->GetParentFootprint() )
{
frame()->SetMsgPanel( footprint );
DIALOG_PUSH_PAD_PROPERTIES dlg( frame() );
@ -275,6 +267,8 @@ int PAD_TOOL::pushPadSettings( const TOOL_EVENT& aEvent )
m_toolMgr->ProcessEvent( EVENTS::SelectedItemsModified );
frame()->Refresh();
}
}
return 0;
}

View File

@ -1536,7 +1536,7 @@ int PCB_SELECTION_TOOL::grabUnconnected( const TOOL_EVENT& aEvent )
if( edge.GetLength() < currentDistance )
{
currentDistance = edge.GetLength();
nearest = static_cast<PAD*>( other->Parent() )->GetParent();
nearest = other->Parent()->GetParentFootprint();
}
}
@ -2730,28 +2730,26 @@ bool PCB_SELECTION_TOOL::selectionContains( const VECTOR2I& aPoint ) const
bool found = false;
std::function<void( PCB_GROUP* )> checkGroup;
checkGroup = [&]( PCB_GROUP* aGroup )
std::function<void( PCB_GROUP* )> checkGroup =
[&]( PCB_GROUP* aGroup )
{
aGroup->RunOnChildren(
[&]( BOARD_ITEM* aItem )
{
if( PCB_GROUP* group = dyn_cast<PCB_GROUP*>( aItem ) )
checkGroup( group );
if( aItem->Type() == PCB_GROUP_T )
checkGroup( static_cast<PCB_GROUP*>( aItem ) );
else if( aItem->HitTest( aPoint, margin ) )
found = true;
} );
};
if( PCB_GROUP* group = dyn_cast<PCB_GROUP*>( item ) )
{
checkGroup( group );
if( item->Type() == PCB_GROUP_T )
checkGroup( static_cast<PCB_GROUP*>( item ) );
if( found )
return true;
}
}
}
return false;
}

View File

@ -80,7 +80,7 @@ void PCB_TOOL_BASE::doInteractiveItemPlacement( const TOOL_EVENT& aTool,
if( newItem->Type() == PCB_FOOTPRINT_T )
{
FOOTPRINT* fp = dyn_cast<FOOTPRINT*>( newItem.get() );
FOOTPRINT* fp = static_cast<FOOTPRINT*>( newItem.get() );
// footprints have more drawable parts
fp->RunOnChildren( std::bind( &KIGFX::VIEW_GROUP::Add, &preview, _1 ) );