From 493828cc6b524eb3e40e6295073a1654fe4d8871 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Sat, 24 Jun 2023 19:54:50 +0100 Subject: [PATCH] Eradicate a bunch of calls to dyn_cast. Also deletes PAD::GetParent() which fails to look for parent footprint through groups. --- eeschema/schematic_undo_redo.cpp | 4 +- eeschema/tools/ee_grid_helper.cpp | 6 +- pcbnew/connectivity/connectivity_algo.cpp | 16 ++-- pcbnew/connectivity/connectivity_data.cpp | 29 +++---- pcbnew/connectivity/connectivity_data.h | 2 +- pcbnew/connectivity/from_to_cache.cpp | 11 +-- pcbnew/dialogs/dialog_board_statistics.cpp | 6 +- pcbnew/dialogs/dialog_pad_properties.cpp | 2 +- .../dialogs/dialog_track_via_properties.cpp | 8 +- .../drc/drc_test_provider_library_parity.cpp | 4 +- pcbnew/drc/drc_test_provider_track_width.cpp | 22 ++--- pcbnew/drc/drc_test_provider_via_diameter.cpp | 15 ++-- pcbnew/exporters/export_hyperlynx.cpp | 6 +- pcbnew/exporters/gendrill_gerber_writer.cpp | 4 +- pcbnew/pad.cpp | 47 +++------- pcbnew/pad.h | 2 - pcbnew/pcb_expr_functions.cpp | 15 ++-- pcbnew/plot_board_layers.cpp | 24 ++--- pcbnew/plot_brditems_plotter.cpp | 12 +-- pcbnew/plugins/eagle/eagle_plugin.cpp | 2 +- pcbnew/router/pns_kicad_iface.cpp | 4 +- pcbnew/tools/drawing_tool.cpp | 10 ++- pcbnew/tools/edit_tool.cpp | 87 +++++++++---------- pcbnew/tools/pad_tool.cpp | 54 +++++------- pcbnew/tools/pcb_selection_tool.cpp | 28 +++--- pcbnew/tools/pcb_tool_base.cpp | 2 +- 26 files changed, 192 insertions(+), 230 deletions(-) diff --git a/eeschema/schematic_undo_redo.cpp b/eeschema/schematic_undo_redo.cpp index 866818b177..5f868858c4 100644 --- a/eeschema/schematic_undo_redo.cpp +++ b/eeschema/schematic_undo_redo.cpp @@ -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( eda_item ) ) - - if( sheet->GetScreen() == GetScreen() ) + if( static_cast( eda_item )->GetScreen() == GetScreen() ) GetToolManager()->RunAction( EE_ACTIONS::leaveSheet ); } diff --git a/eeschema/tools/ee_grid_helper.cpp b/eeschema/tools/ee_grid_helper.cpp index 39803319a2..f0472d49af 100644 --- a/eeschema/tools/ee_grid_helper.cpp +++ b/eeschema/tools/ee_grid_helper.cpp @@ -310,9 +310,10 @@ void EE_GRID_HELPER::computeAnchors( SCH_ITEM *aItem, const VECTOR2I &aRefPos, b break; } - if( SCH_LINE* line = dyn_cast( aItem ) ) + if( aItem->Type() == SCH_LINE_T ) { - VECTOR2I pt = Align( aRefPos ); + SCH_LINE* line = static_cast( 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 ); } - } } diff --git a/pcbnew/connectivity/connectivity_algo.cpp b/pcbnew/connectivity/connectivity_algo.cpp index 78af318093..39d2837cc6 100644 --- a/pcbnew/connectivity/connectivity_algo.cpp +++ b/pcbnew/connectivity/connectivity_algo.cpp @@ -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( parentA ) ) + if( parentA->Type() == PCB_PAD_T ) { - if( !pad->ConditionallyFlashed( layer ) ) + if( !static_cast( parentA )->ConditionallyFlashed( layer ) ) flashingA = FLASHING::ALWAYS_FLASHED; } - else if( const PCB_VIA* via = dyn_cast( parentA ) ) + else if( parentA->Type() == PCB_VIA_T ) { - if( !via->ConditionallyFlashed( layer ) ) + if( !static_cast( parentA )->ConditionallyFlashed( layer ) ) flashingA = FLASHING::ALWAYS_FLASHED; } - if( const PAD* pad = dyn_cast( parentB ) ) + if( parentB->Type() == PCB_PAD_T ) { - if( !pad->ConditionallyFlashed( layer ) ) + if( !static_cast( parentB )->ConditionallyFlashed( layer ) ) flashingB = FLASHING::ALWAYS_FLASHED; } - else if( const PCB_VIA* via = dyn_cast( parentB ) ) + else if( parentB->Type() == PCB_VIA_T ) { - if( !via->ConditionallyFlashed( layer ) ) + if( !static_cast( parentB )->ConditionallyFlashed( layer ) ) flashingB = FLASHING::ALWAYS_FLASHED; } diff --git a/pcbnew/connectivity/connectivity_data.cpp b/pcbnew/connectivity/connectivity_data.cpp index 5e4b4c25ca..06e65a1ec3 100644 --- a/pcbnew/connectivity/connectivity_data.cpp +++ b/pcbnew/connectivity/connectivity_data.cpp @@ -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( aItem )->Pads() ) m_connAlgo->MarkNetAsDirty( pad->GetNetCode() ); } + if (aItem->IsConnected() ) - { m_connAlgo->MarkNetAsDirty( static_cast( aItem )->GetNetCode() ); - } } @@ -938,7 +935,8 @@ void CONNECTIVITY_DATA::SetProgressReporter( PROGRESS_REPORTER* aReporter ) } -const std::vector CONNECTIVITY_DATA::GetRatsnestForItems( std::vector aItems ) +const std::vector +CONNECTIVITY_DATA::GetRatsnestForItems( const std::vector& aItems ) { std::set nets; std::vector edges; @@ -956,8 +954,10 @@ const std::vector CONNECTIVITY_DATA::GetRatsnestForItems( std::vector( item ) ) + else if( item->IsConnected() ) { + BOARD_CONNECTED_ITEM* conn_item = static_cast( item ); + item_set.insert( conn_item ); nets.insert( conn_item->GetNetCode() ); } @@ -1002,7 +1002,8 @@ const std::vector CONNECTIVITY_DATA::GetRatsnestForPad( const PAD* aPad } -const std::vector CONNECTIVITY_DATA::GetRatsnestForComponent( FOOTPRINT* aComponent, bool aSkipInternalConnections ) +const std::vector CONNECTIVITY_DATA::GetRatsnestForComponent( FOOTPRINT* aComponent, + bool aSkipInternalConnections ) { std::set nets; std::set pads; @@ -1014,14 +1015,12 @@ const std::vector 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& srcNode = edge.GetSourceNode(); + const std::shared_ptr& dstNode = edge.GetTargetNode(); const PAD* srcParent = static_cast( srcNode->Parent() ); const PAD* dstParent = static_cast( dstNode->Parent() ); @@ -1030,13 +1029,9 @@ const std::vector 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 ); - } } } diff --git a/pcbnew/connectivity/connectivity_data.h b/pcbnew/connectivity/connectivity_data.h index 7e178c8398..18feae6057 100644 --- a/pcbnew/connectivity/connectivity_data.h +++ b/pcbnew/connectivity/connectivity_data.h @@ -271,7 +271,7 @@ public: const std::map& GetNetclassMap() const { return m_netclassMap; } #ifndef SWIG - const std::vector GetRatsnestForItems( const std::vector aItems ); + const std::vector GetRatsnestForItems( const std::vector& aItems ); const std::vector GetRatsnestForPad( const PAD* aPad ); diff --git a/pcbnew/connectivity/from_to_cache.cpp b/pcbnew/connectivity/from_to_cache.cpp index 3b75cd1bf5..f27441942c 100644 --- a/pcbnew/connectivity/from_to_cache.cpp +++ b/pcbnew/connectivity/from_to_cache.cpp @@ -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( pitem ); - wxString toName = pad->GetParent()->GetReference() + wxT( "-" ) + pad->GetNumber(); - + wxString toName = pad->GetParentFootprint()->GetReference() + + wxT( "-" ) + pad->GetNumber(); for( const FT_ENDPOINT& endpoint : m_ftEndpoints ) { diff --git a/pcbnew/dialogs/dialog_board_statistics.cpp b/pcbnew/dialogs/dialog_board_statistics.cpp index d0cec90109..d313a88586 100644 --- a/pcbnew/dialogs/dialog_board_statistics.cpp +++ b/pcbnew/dialogs/dialog_board_statistics.cpp @@ -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( track ) ) + if( track->Type() == PCB_VIA_T ) { + PCB_VIA* via = static_cast( track ); + for( LINE_ITEM& line : m_viaTypes ) { if( via->GetViaType() == line.attribute ) diff --git a/pcbnew/dialogs/dialog_pad_properties.cpp b/pcbnew/dialogs/dialog_pad_properties.cpp index caba40655e..9d0dfffcde 100644 --- a/pcbnew/dialogs/dialog_pad_properties.cpp +++ b/pcbnew/dialogs/dialog_pad_properties.cpp @@ -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(); diff --git a/pcbnew/dialogs/dialog_track_via_properties.cpp b/pcbnew/dialogs/dialog_track_via_properties.cpp index 25b55c4dd9..2bb85fda86 100644 --- a/pcbnew/dialogs/dialog_track_via_properties.cpp +++ b/pcbnew/dialogs/dialog_track_via_properties.cpp @@ -37,8 +37,6 @@ #include #include -#include - 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& 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& 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() ); } diff --git a/pcbnew/drc/drc_test_provider_library_parity.cpp b/pcbnew/drc/drc_test_provider_library_parity.cpp index a920893a16..e2d00a8da7 100644 --- a/pcbnew/drc/drc_test_provider_library_parity.cpp +++ b/pcbnew/drc/drc_test_provider_library_parity.cpp @@ -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(), "" ); diff --git a/pcbnew/drc/drc_test_provider_track_width.cpp b/pcbnew/drc/drc_test_provider_track_width.cpp index 7e5ddaebcd..52a460137d 100644 --- a/pcbnew/drc/drc_test_provider_track_width.cpp +++ b/pcbnew/drc/drc_test_provider_track_width.cpp @@ -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; @@ -82,18 +80,22 @@ bool DRC_TEST_PROVIDER_TRACK_WIDTH::Run() if( m_drcEngine->IsErrorLimitExceeded( DRCE_TRACK_WIDTH ) ) return false; - int actual; + int actual; VECTOR2I p0; - if( PCB_ARC* arc = dyn_cast( item ) ) + if( item->Type() == PCB_ARC_T ) { + PCB_ARC* arc = static_cast( item ); + actual = arc->GetWidth(); p0 = arc->GetStart(); } - else if( PCB_TRACK* trk = dyn_cast( item ) ) + else if( item->Type() == PCB_TRACE_T ) { - actual = trk->GetWidth(); - p0 = ( trk->GetStart() + trk->GetEnd() ) / 2; + PCB_TRACK* track = static_cast( item ); + + actual = track->GetWidth(); + p0 = ( track->GetStart() + track->GetEnd() ) / 2; } else { diff --git a/pcbnew/drc/drc_test_provider_via_diameter.cpp b/pcbnew/drc/drc_test_provider_via_diameter.cpp index f81a569075..e94e5eb125 100644 --- a/pcbnew/drc/drc_test_provider_via_diameter.cpp +++ b/pcbnew/drc/drc_test_provider_via_diameter.cpp @@ -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( item ); - - // fixme: move to pad stack check? - if( !via ) + if( item->Type() != PCB_VIA_T ) return true; + PCB_VIA* via = static_cast( 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 ); diff --git a/pcbnew/exporters/export_hyperlynx.cpp b/pcbnew/exporters/export_hyperlynx.cpp index 1c1a233f3e..f122129c5b 100644 --- a/pcbnew/exporters/export_hyperlynx.cpp +++ b/pcbnew/exporters/export_hyperlynx.cpp @@ -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 #include #include -#include - #include static double iu2hyp( double iu ) @@ -431,7 +429,7 @@ bool HYPERLYNX_EXPORTER::writeNetObjects( const std::vector& aObjec if( pstackIter != m_padMap.end() ) { - wxString ref = pad->GetParent()->GetReference(); + wxString ref = pad->GetParentFootprint()->GetReference(); if( ref.IsEmpty() ) ref = wxT( "EMPTY" ); diff --git a/pcbnew/exporters/gendrill_gerber_writer.cpp b/pcbnew/exporters/gendrill_gerber_writer.cpp index 649bc822f2..cf8e6229df 100644 --- a/pcbnew/exporters/gendrill_gerber_writer.cpp +++ b/pcbnew/exporters/gendrill_gerber_writer.cpp @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2017 Jean_Pierre Charras - * 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 ); diff --git a/pcbnew/pad.cpp b/pcbnew/pad.cpp index 4dd112c845..cd6afec863 100644 --- a/pcbnew/pad.cpp +++ b/pcbnew/pad.cpp @@ -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( "" ) ), - 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( 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 ); diff --git a/pcbnew/pad.h b/pcbnew/pad.h index 8e10c2cbeb..7d8c76f59b 100644 --- a/pcbnew/pad.h +++ b/pcbnew/pad.h @@ -108,8 +108,6 @@ public: return GetDrillSizeX() > 0 && GetDrillSizeY() > 0; } - FOOTPRINT* GetParent() const; - wxString GetParentAsString() const; bool IsLocked() const override; diff --git a/pcbnew/pcb_expr_functions.cpp b/pcbnew/pcb_expr_functions.cpp index 2d047e76db..2692ff6be7 100644 --- a/pcbnew/pcb_expr_functions.cpp +++ b/pcbnew/pcb_expr_functions.cpp @@ -33,7 +33,6 @@ #include #include #include - #include #include #include @@ -873,10 +872,11 @@ static void isMicroVia( LIBEVAL::CONTEXT* aCtx, void* self ) result->Set( 0.0 ); aCtx->Push( result ); - PCB_VIA* via = dyn_cast( item ); - - if( via && via->GetViaType() == VIATYPE::MICROVIA ) + if( item && item->Type() == PCB_VIA_T + && static_cast( 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( item ); - - if( via && via->GetViaType() == VIATYPE::BLIND_BURIED ) + if( item && item->Type() == PCB_VIA_T + && static_cast( item )->GetViaType() == VIATYPE::MICROVIA ) + { result->Set ( 1.0 ); + } } diff --git a/pcbnew/plot_board_layers.cpp b/pcbnew/plot_board_layers.cpp index 7bf5f17a76..e3580530b6 100644 --- a/pcbnew/plot_board_layers.cpp +++ b/pcbnew/plot_board_layers.cpp @@ -36,18 +36,14 @@ #include #include #include // for KiROUND - #include -#include #include #include -#include #include #include #include #include #include - #include #include #include @@ -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( track ); - - if( !via ) + if( track->Type() != PCB_VIA_T ) continue; + const PCB_VIA* via = static_cast( 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( 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( 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( track ); + if( track->Type() != PCB_VIA_T ) + continue; + + const PCB_VIA* via = static_cast( track ); // Note: IsOnLayer() checks relevant mask layers of untented vias - if( !via || !via->IsOnLayer( layer ) ) + if( !via->IsOnLayer( layer ) ) continue; int clearance = via->GetSolderMaskExpansion(); diff --git a/pcbnew/plot_brditems_plotter.cpp b/pcbnew/plot_brditems_plotter.cpp index a3e654a47e..1057817c4e 100644 --- a/pcbnew/plot_brditems_plotter.cpp +++ b/pcbnew/plot_brditems_plotter.cpp @@ -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( item ); + textItem = dynamic_cast( item ); if( textItem ) texts.push_back( static_cast( 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( tracks ); - - if( via ) + if( track->Type() == PCB_VIA_T ) { + const PCB_VIA* via = static_cast( track ); + plotOneDrillMark( PAD_DRILL_SHAPE_CIRCLE, via->GetStart(), VECTOR2I( via->GetDrillValue(), 0 ), VECTOR2I( via->GetWidth(), 0 ), ANGLE_0, smallDrill ); diff --git a/pcbnew/plugins/eagle/eagle_plugin.cpp b/pcbnew/plugins/eagle/eagle_plugin.cpp index 2d1290522a..841b161934 100644 --- a/pcbnew/plugins/eagle/eagle_plugin.cpp +++ b/pcbnew/plugins/eagle/eagle_plugin.cpp @@ -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() ); diff --git a/pcbnew/router/pns_kicad_iface.cpp b/pcbnew/router/pns_kicad_iface.cpp index 0ebd492219..4c52d0208f 100644 --- a/pcbnew/router/pns_kicad_iface.cpp +++ b/pcbnew/router/pns_kicad_iface.cpp @@ -57,9 +57,7 @@ #include #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; diff --git a/pcbnew/tools/drawing_tool.cpp b/pcbnew/tools/drawing_tool.cpp index 5720aa2859..ec41852c2c 100644 --- a/pcbnew/tools/drawing_tool.cpp +++ b/pcbnew/tools/drawing_tool.cpp @@ -2004,7 +2004,7 @@ bool DRAWING_TOOL::drawShape( const TOOL_EVENT& aTool, PCB_SHAPE** aGraphic, } else { - PCB_SHAPE* snapItem = dyn_cast( grid.GetSnapped() ); + PCB_SHAPE* snapItem = dynamic_cast( 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( selection[0] ); + if( selection.Size() == 1 && selection[0]->Type() == PCB_ZONE_T ) + *aZone = static_cast( 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( item ) ) + if( item->Type() == PCB_TRACE_T || item->Type() == PCB_ARC_T ) { + PCB_TRACK* track = static_cast( item ); + if( TestSegmentHit( position, track->GetStart(), track->GetEnd(), ( track->GetWidth() + aVia->GetWidth() ) / 2 ) ) { diff --git a/pcbnew/tools/edit_tool.cpp b/pcbnew/tools/edit_tool.cpp index dbd77b3d85..03c8ee83b0 100644 --- a/pcbnew/tools/edit_tool.cpp +++ b/pcbnew/tools/edit_tool.cpp @@ -903,59 +903,59 @@ int EDIT_TOOL::FilletTracks( const TOOL_EVENT& aEvent ) bool didOneAttemptFail = false; std::set processedTracks; - for( EDA_ITEM* item : selection ) - { - PCB_TRACK* track = dyn_cast( item ); + auto processFilletOp = + [&]( PCB_TRACK* aTrack, bool aStartPoint ) + { + std::shared_ptr c = board()->GetConnectivity(); + VECTOR2I anchor = aStartPoint ? aTrack->GetStart() : aTrack->GetEnd(); + std::vector itemsOnAnchor; - if( !track || track->Type() != PCB_TRACE_T || track->GetLength() == 0 ) - { - continue; - } + itemsOnAnchor = c->GetConnectedItemsAtAnchor( aTrack, anchor, + { PCB_PAD_T, PCB_VIA_T, + PCB_TRACE_T, PCB_ARC_T } ); - auto processFilletOp = - [&]( bool aStartPoint ) + if( itemsOnAnchor.size() > 0 + && selection.Contains( itemsOnAnchor.at( 0 ) ) + && itemsOnAnchor.at( 0 )->Type() == PCB_TRACE_T ) { - std::shared_ptr c = board()->GetConnectivity(); - VECTOR2I anchor = aStartPoint ? track->GetStart() - : track->GetEnd(); - std::vector itemsOnAnchor; + PCB_TRACK* trackOther = static_cast( itemsOnAnchor.at( 0 ) ); - itemsOnAnchor = c->GetConnectedItemsAtAnchor( track, anchor, - { PCB_PAD_T, PCB_VIA_T, - PCB_TRACE_T, PCB_ARC_T } ); - - if( itemsOnAnchor.size() > 0 - && selection.Contains( itemsOnAnchor.at( 0 ) ) - && itemsOnAnchor.at( 0 )->Type() == PCB_TRACE_T ) + // Make sure we don't fillet the same pair of tracks twice + if( processedTracks.find( trackOther ) == processedTracks.end() ) { - PCB_TRACK* trackOther = dyn_cast( itemsOnAnchor.at( 0 ) ); - - // Make sure we don't fillet the same pair of tracks twice - if( processedTracks.find( trackOther ) == processedTracks.end() ) + if( itemsOnAnchor.size() == 1 ) { - if( itemsOnAnchor.size() == 1 ) - { - FILLET_OP filletOp; - filletOp.t1 = track; - filletOp.t2 = trackOther; - filletOp.t1Start = aStartPoint; - filletOp.t2Start = track->IsPointOnEnds( filletOp.t2->GetStart() ); - filletOperations.push_back( filletOp ); - } - else - { - // User requested to fillet these two tracks but not possible as - // there are other elements connected at that point - didOneAttemptFail = true; - } + FILLET_OP filletOp; + filletOp.t1 = aTrack; + filletOp.t2 = trackOther; + filletOp.t1Start = aStartPoint; + filletOp.t2Start = aTrack->IsPointOnEnds( filletOp.t2->GetStart() ); + filletOperations.push_back( filletOp ); + } + else + { + // User requested to fillet these two tracks but not possible as + // there are other elements connected at that point + didOneAttemptFail = true; } } - }; + } + }; - 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( item ); - processedTracks.insert( track ); + 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 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 pts; // Iterate from the back so we don't have to worry about removals. diff --git a/pcbnew/tools/pad_tool.cpp b/pcbnew/tools/pad_tool.cpp index 0f1b564f34..d11351e4fa 100644 --- a/pcbnew/tools/pad_tool.cpp +++ b/pcbnew/tools/pad_tool.cpp @@ -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,40 +238,37 @@ int PAD_TOOL::pushPadSettings( const TOOL_EVENT& aEvent ) { PCB_SELECTION_TOOL* selTool = m_toolMgr->GetTool(); const PCB_SELECTION& selection = selTool->GetSelection(); - PAD* srcPad; if( selection.Size() == 1 && selection[0]->Type() == PCB_PAD_T ) - srcPad = static_cast( selection[0] ); - else - return 0; + { + PAD* srcPad = static_cast( selection[0] ); - FOOTPRINT* footprint = srcPad->GetParent(); + if( FOOTPRINT* footprint = srcPad->GetParentFootprint() ) + { + frame()->SetMsgPanel( footprint ); - if( !footprint ) - return 0; + DIALOG_PUSH_PAD_PROPERTIES dlg( frame() ); + int dialogRet = dlg.ShowModal(); - frame()->SetMsgPanel( footprint ); + if( dialogRet == wxID_CANCEL ) + return 0; - DIALOG_PUSH_PAD_PROPERTIES dlg( frame() ); - int dialogRet = dlg.ShowModal(); + const bool edit_Same_Modules = (dialogRet == 1); - if( dialogRet == wxID_CANCEL ) - return 0; + BOARD_COMMIT commit( frame() ); - const bool edit_Same_Modules = (dialogRet == 1); + doPushPadProperties( *getModel(), *srcPad, commit, edit_Same_Modules, + DIALOG_PUSH_PAD_PROPERTIES::m_Pad_Shape_Filter, + DIALOG_PUSH_PAD_PROPERTIES::m_Pad_Orient_Filter, + DIALOG_PUSH_PAD_PROPERTIES::m_Pad_Layer_Filter, + DIALOG_PUSH_PAD_PROPERTIES::m_Pad_Type_Filter ); - BOARD_COMMIT commit( frame() ); + commit.Push( _( "Push Pad Settings" ) ); - doPushPadProperties( *getModel(), *srcPad, commit, edit_Same_Modules, - DIALOG_PUSH_PAD_PROPERTIES::m_Pad_Shape_Filter, - DIALOG_PUSH_PAD_PROPERTIES::m_Pad_Orient_Filter, - DIALOG_PUSH_PAD_PROPERTIES::m_Pad_Layer_Filter, - DIALOG_PUSH_PAD_PROPERTIES::m_Pad_Type_Filter ); - - commit.Push( _( "Push Pad Settings" ) ); - - m_toolMgr->ProcessEvent( EVENTS::SelectedItemsModified ); - frame()->Refresh(); + m_toolMgr->ProcessEvent( EVENTS::SelectedItemsModified ); + frame()->Refresh(); + } + } return 0; } diff --git a/pcbnew/tools/pcb_selection_tool.cpp b/pcbnew/tools/pcb_selection_tool.cpp index 4dd8ed7a55..e0cbe4cdf9 100644 --- a/pcbnew/tools/pcb_selection_tool.cpp +++ b/pcbnew/tools/pcb_selection_tool.cpp @@ -1536,7 +1536,7 @@ int PCB_SELECTION_TOOL::grabUnconnected( const TOOL_EVENT& aEvent ) if( edge.GetLength() < currentDistance ) { currentDistance = edge.GetLength(); - nearest = static_cast( other->Parent() )->GetParent(); + nearest = other->Parent()->GetParentFootprint(); } } @@ -2730,26 +2730,24 @@ bool PCB_SELECTION_TOOL::selectionContains( const VECTOR2I& aPoint ) const bool found = false; - std::function checkGroup; - checkGroup = [&]( PCB_GROUP* aGroup ) - { - aGroup->RunOnChildren( - [&]( BOARD_ITEM* aItem ) + std::function checkGroup = + [&]( PCB_GROUP* aGroup ) + { + aGroup->RunOnChildren( + [&]( BOARD_ITEM* aItem ) { - if( PCB_GROUP* group = dyn_cast( aItem ) ) - checkGroup( group ); + if( aItem->Type() == PCB_GROUP_T ) + checkGroup( static_cast( aItem ) ); else if( aItem->HitTest( aPoint, margin ) ) found = true; } ); - }; + }; - if( PCB_GROUP* group = dyn_cast( item ) ) - { - checkGroup( group ); + if( item->Type() == PCB_GROUP_T ) + checkGroup( static_cast( item ) ); - if( found ) - return true; - } + if( found ) + return true; } } diff --git a/pcbnew/tools/pcb_tool_base.cpp b/pcbnew/tools/pcb_tool_base.cpp index a7a056245d..599f6d98c0 100644 --- a/pcbnew/tools/pcb_tool_base.cpp +++ b/pcbnew/tools/pcb_tool_base.cpp @@ -80,7 +80,7 @@ void PCB_TOOL_BASE::doInteractiveItemPlacement( const TOOL_EVENT& aTool, if( newItem->Type() == PCB_FOOTPRINT_T ) { - FOOTPRINT* fp = dyn_cast( newItem.get() ); + FOOTPRINT* fp = static_cast( newItem.get() ); // footprints have more drawable parts fp->RunOnChildren( std::bind( &KIGFX::VIEW_GROUP::Add, &preview, _1 ) );