From aa2ad3b44c3e533cf00a5077db17fb0ee7e302eb Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Sat, 20 Aug 2022 10:27:35 +0100 Subject: [PATCH] Move KICAD_T[] to std::initializer_list. --- common/eda_item.cpp | 6 +- common/tool/selection.cpp | 9 +- common/tool/selection_conditions.cpp | 33 +-- eeschema/bus-wire-junction.cpp | 25 +- eeschema/dialogs/dialog_field_properties.cpp | 4 +- .../dialog_global_edit_text_and_graphics.cpp | 35 +-- eeschema/ee_collectors.cpp | 46 +--- eeschema/ee_collectors.h | 32 +-- eeschema/eeschema_config.cpp | 2 - eeschema/lib_symbol.cpp | 4 +- eeschema/lib_symbol.h | 5 +- eeschema/sch_base_frame.cpp | 29 +- eeschema/sch_base_frame.h | 13 +- eeschema/sch_edit_frame.cpp | 3 +- eeschema/sch_field.cpp | 21 +- eeschema/sch_field.h | 15 +- eeschema/sch_item.h | 10 +- eeschema/sch_label.cpp | 27 +- eeschema/sch_label.h | 5 +- eeschema/sch_line.h | 10 +- eeschema/sch_painter.cpp | 30 +- eeschema/sch_painter.h | 22 +- .../sch_plugins/eagle/sch_eagle_plugin.cpp | 5 +- eeschema/sch_screen.cpp | 22 +- eeschema/sch_sheet.cpp | 13 +- eeschema/sch_sheet.h | 5 +- eeschema/sch_symbol.cpp | 26 +- eeschema/sch_symbol.h | 3 +- eeschema/tools/ee_inspection_tool.cpp | 2 +- eeschema/tools/ee_point_editor.cpp | 19 +- eeschema/tools/ee_selection_tool.cpp | 117 ++++---- eeschema/tools/ee_selection_tool.h | 11 +- eeschema/tools/sch_drawing_tools.cpp | 2 +- eeschema/tools/sch_edit_tool.cpp | 104 +++---- eeschema/tools/sch_editor_control.cpp | 17 +- eeschema/tools/sch_line_wire_bus_tool.cpp | 19 +- eeschema/tools/sch_move_tool.cpp | 2 +- eeschema/tools/sch_navigate_tool.cpp | 4 +- eeschema/tools/symbol_editor_edit_tool.cpp | 13 +- eeschema/tools/symbol_editor_move_tool.cpp | 6 +- eeschema/tools/symbol_editor_pin_tool.cpp | 2 +- gerbview/gbr_layout.cpp | 35 +-- gerbview/gbr_layout.h | 5 +- gerbview/gerber_collectors.cpp | 19 +- gerbview/gerber_collectors.h | 45 +-- gerbview/gerber_draw_item.cpp | 30 +- gerbview/gerber_draw_item.h | 22 +- gerbview/gerber_file_image.cpp | 54 +--- gerbview/gerber_file_image.h | 109 +++----- gerbview/tools/gerbview_selection_tool.cpp | 2 +- include/collector.h | 29 +- include/eda_item.h | 49 ++-- include/pcb_group.h | 4 +- include/tool/selection_conditions.h | 59 +--- pagelayout_editor/tools/pl_point_editor.cpp | 4 +- pcbnew/board.cpp | 193 ++++--------- pcbnew/board.h | 20 +- pcbnew/collectors.cpp | 168 +++--------- pcbnew/collectors.h | 191 +++---------- pcbnew/connectivity/connectivity_algo.cpp | 10 +- pcbnew/connectivity/connectivity_data.cpp | 53 ++-- pcbnew/connectivity/connectivity_data.h | 47 ++-- pcbnew/convert_shape_list_to_polygon.cpp | 6 +- pcbnew/edit_track_width.cpp | 9 +- .../exporters/gendrill_file_writer_base.cpp | 20 +- pcbnew/footprint.cpp | 88 +++--- pcbnew/footprint.h | 3 +- pcbnew/fp_shape.h | 10 +- pcbnew/fp_text.h | 8 +- pcbnew/fp_textbox.h | 6 +- pcbnew/netinfo_item.cpp | 18 +- pcbnew/pad.h | 12 +- pcbnew/pcb_base_edit_frame.cpp | 11 +- pcbnew/pcb_dimension.h | 8 +- pcbnew/pcb_edit_frame.cpp | 10 +- pcbnew/pcb_group.cpp | 8 +- pcbnew/pcb_shape.h | 10 +- pcbnew/pcb_text.h | 6 +- pcbnew/pcb_textbox.h | 6 +- pcbnew/pcb_track.cpp | 15 +- pcbnew/pcb_track.h | 13 +- pcbnew/python/swig/board.i | 6 - pcbnew/router/pns_item.cpp | 4 +- pcbnew/router/router_tool.cpp | 4 +- .../specctra_export.cpp | 257 +++++++----------- .../specctra_import.cpp | 110 +++----- pcbnew/tools/board_editor_control.cpp | 24 +- pcbnew/tools/board_inspection_tool.cpp | 12 +- pcbnew/tools/convert_tool.cpp | 19 +- pcbnew/tools/drawing_stackup_table_tool.cpp | 98 +++---- pcbnew/tools/edit_tool.cpp | 43 +-- pcbnew/tools/pad_tool.cpp | 8 +- pcbnew/tools/pcb_selection_tool.cpp | 37 +-- 93 files changed, 1002 insertions(+), 1813 deletions(-) diff --git a/common/eda_item.cpp b/common/eda_item.cpp index 95cba1bbda..94d8f558bf 100644 --- a/common/eda_item.cpp +++ b/common/eda_item.cpp @@ -89,14 +89,14 @@ EDA_ITEM* EDA_ITEM::Clone() const // see base_struct.h // many classes inherit this method, be careful: -//TODO (snh): Fix this to use std::set instead of C-style vector -INSPECT_RESULT EDA_ITEM::Visit( INSPECTOR inspector, void* testData, const KICAD_T scanTypes[] ) +INSPECT_RESULT EDA_ITEM::Visit( INSPECTOR inspector, void* testData, + const std::initializer_list& aScanTypes ) { #if 0 && defined(DEBUG) std::cout << GetClass().mb_str() << ' '; #endif - if( IsType( scanTypes ) ) + if( IsType( aScanTypes ) ) { if( INSPECT_RESULT::QUIT == inspector( this, testData ) ) return INSPECT_RESULT::QUIT; diff --git a/common/tool/selection.cpp b/common/tool/selection.cpp index c72558c33f..b8c3586ce5 100644 --- a/common/tool/selection.cpp +++ b/common/tool/selection.cpp @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2013-2017 CERN - * Copyright (C) 2021 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2021-2022 KiCad Developers, see AUTHORS.txt for contributors. * @author Tomasz Wlostowski * @author Maciej Suminski * @@ -70,8 +70,7 @@ bool SELECTION::Contains( EDA_ITEM* aItem ) const /// Returns the center point of the selection area bounding box. VECTOR2I SELECTION::GetCenter() const { - KICAD_T textTypes[] = { SCH_TEXT_T, SCH_LABEL_LOCATE_ANY_T, EOT }; - bool hasOnlyText = true; + bool hasOnlyText = true; // If the selection contains only texts calculate the center as the mean of all positions // instead of using the center of the total bounding box. Otherwise rotating the selection will @@ -79,7 +78,7 @@ VECTOR2I SELECTION::GetCenter() const for( EDA_ITEM* item : m_items ) { - if( !item->IsType( textTypes ) ) + if( !item->IsType( { SCH_TEXT_T, SCH_LABEL_LOCATE_ANY_T } ) ) { hasOnlyText = false; break; @@ -101,7 +100,7 @@ VECTOR2I SELECTION::GetCenter() const for( EDA_ITEM* item : m_items ) { - if( !item->IsType( textTypes ) ) + if( !item->IsType( { SCH_TEXT_T, SCH_LABEL_LOCATE_ANY_T } ) ) bbox.Merge( item->GetBoundingBox() ); } diff --git a/common/tool/selection_conditions.cpp b/common/tool/selection_conditions.cpp index 407c90dc27..dd59402876 100644 --- a/common/tool/selection_conditions.cpp +++ b/common/tool/selection_conditions.cpp @@ -64,19 +64,13 @@ SELECTION_CONDITION SELECTION_CONDITIONS::HasType( KICAD_T aType ) } -SELECTION_CONDITION SELECTION_CONDITIONS::HasTypes( const KICAD_T aTypes[] ) +SELECTION_CONDITION SELECTION_CONDITIONS::HasTypes( const std::initializer_list& aTypes ) { return std::bind( &SELECTION_CONDITIONS::hasTypesFunc, _1, aTypes ); } -SELECTION_CONDITION SELECTION_CONDITIONS::OnlyType( KICAD_T aType ) -{ - return std::bind( &SELECTION_CONDITIONS::onlyTypeFunc, _1, aType ); -} - - -SELECTION_CONDITION SELECTION_CONDITIONS::OnlyTypes( const KICAD_T aTypes[] ) +SELECTION_CONDITION SELECTION_CONDITIONS::OnlyTypes( const std::initializer_list& aTypes ) { return std::bind( &SELECTION_CONDITIONS::onlyTypesFunc, _1, aTypes ); } @@ -115,7 +109,8 @@ bool SELECTION_CONDITIONS::hasTypeFunc( const SELECTION& aSelection, KICAD_T aTy } -bool SELECTION_CONDITIONS::hasTypesFunc( const SELECTION& aSelection, const KICAD_T aTypes[] ) +bool SELECTION_CONDITIONS::hasTypesFunc( const SELECTION& aSelection, + const std::initializer_list& aTypes ) { if( aSelection.Empty() ) return false; @@ -130,24 +125,8 @@ bool SELECTION_CONDITIONS::hasTypesFunc( const SELECTION& aSelection, const KICA } -bool SELECTION_CONDITIONS::onlyTypeFunc( const SELECTION& aSelection, KICAD_T aType ) -{ - if( aSelection.Empty() ) - return false; - - KICAD_T types[] = { aType, EOT }; - - for( const EDA_ITEM* item : aSelection ) - { - if( !item->IsType( types ) ) - return false; - } - - return true; -} - - -bool SELECTION_CONDITIONS::onlyTypesFunc( const SELECTION& aSelection, const KICAD_T aTypes[] ) +bool SELECTION_CONDITIONS::onlyTypesFunc( const SELECTION& aSelection, + const std::initializer_list& aTypes ) { if( aSelection.Empty() ) return false; diff --git a/eeschema/bus-wire-junction.cpp b/eeschema/bus-wire-junction.cpp index a14c890397..9369d1fca4 100644 --- a/eeschema/bus-wire-junction.cpp +++ b/eeschema/bus-wire-junction.cpp @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2004 Jean-Pierre Charras, jean-pierre.charras@gipsa-lab.inpg.fr - * Copyright (C) 2004-2021 KiCad Developers, see change_log.txt for contributors. + * Copyright (C) 2004-2022 KiCad Developers, see change_log.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 @@ -319,8 +319,6 @@ bool SCH_EDIT_FRAME::BreakSegment( SCH_LINE* aSegment, const VECTOR2I& aPoint, bool SCH_EDIT_FRAME::BreakSegments( const VECTOR2I& aPoint, SCH_SCREEN* aScreen ) { - static const KICAD_T wiresAndBuses[] = { SCH_ITEM_LOCATE_WIRE_T, SCH_ITEM_LOCATE_BUS_T, EOT }; - if( aScreen == nullptr ) aScreen = GetScreen(); @@ -329,12 +327,12 @@ bool SCH_EDIT_FRAME::BreakSegments( const VECTOR2I& aPoint, SCH_SCREEN* aScreen for( SCH_ITEM* item : aScreen->Items().Overlapping( SCH_LINE_T, aPoint ) ) { - if( item->IsType( wiresAndBuses ) ) + if( item->IsType( { SCH_ITEM_LOCATE_WIRE_T, SCH_ITEM_LOCATE_BUS_T } ) ) { SCH_LINE* wire = static_cast( item ); if( IsPointOnSegment( wire->GetStartPoint(), wire->GetEndPoint(), aPoint ) - && !wire->IsEndPoint( aPoint ) ) + && !wire->IsEndPoint( aPoint ) ) { wires.push_back( wire ); } @@ -380,13 +378,13 @@ void SCH_EDIT_FRAME::DeleteJunction( SCH_ITEM* aJunction, bool aAppend ) SCH_SCREEN* screen = GetScreen(); PICKED_ITEMS_LIST undoList; EE_SELECTION_TOOL* selectionTool = m_toolManager->GetTool(); - KICAD_T wiresAndBuses[] = { SCH_ITEM_LOCATE_WIRE_T, SCH_ITEM_LOCATE_BUS_T, EOT }; - auto remove_item = [ & ]( SCH_ITEM* aItem ) -> void - { - aItem->SetFlags( STRUCT_DELETED ); - undoList.PushItem( ITEM_PICKER( screen, aItem, UNDO_REDO::DELETED ) ); - }; + auto remove_item = + [&]( SCH_ITEM* aItem ) -> void + { + aItem->SetFlags( STRUCT_DELETED ); + undoList.PushItem( ITEM_PICKER( screen, aItem, UNDO_REDO::DELETED ) ); + }; remove_item( aJunction ); RemoveFromScreen( aJunction, screen ); @@ -399,9 +397,12 @@ void SCH_EDIT_FRAME::DeleteJunction( SCH_ITEM* aJunction, bool aAppend ) { SCH_LINE* line = static_cast( item ); - if( line->IsType( wiresAndBuses ) && line->IsEndPoint( aJunction->GetPosition() ) + if( line->IsType( { SCH_ITEM_LOCATE_WIRE_T, SCH_ITEM_LOCATE_BUS_T } ) + && line->IsEndPoint( aJunction->GetPosition() ) && !( line->GetEditFlags() & STRUCT_DELETED ) ) + { lines.push_back( line ); + } } alg::for_all_pairs( lines.begin(), lines.end(), diff --git a/eeschema/dialogs/dialog_field_properties.cpp b/eeschema/dialogs/dialog_field_properties.cpp index 73cfe2d852..91b10dabbf 100644 --- a/eeschema/dialogs/dialog_field_properties.cpp +++ b/eeschema/dialogs/dialog_field_properties.cpp @@ -461,8 +461,6 @@ DIALOG_SCH_FIELD_PROPERTIES::DIALOG_SCH_FIELD_PROPERTIES( SCH_BASE_FRAME* aParen DIALOG_FIELD_PROPERTIES( aParent, aTitle, aField ), m_field( aField ) { - static KICAD_T labelTypes[] = { SCH_LABEL_LOCATE_ANY_T, EOT }; - m_isSheetFilename = false; if( aField->GetParent() && aField->GetParent()->Type() == SCH_SYMBOL_T ) @@ -490,7 +488,7 @@ DIALOG_SCH_FIELD_PROPERTIES::DIALOG_SCH_FIELD_PROPERTIES( SCH_BASE_FRAME* aParen break; } } - else if( aField->GetParent() && aField->GetParent()->IsType( labelTypes ) ) + else if( aField->GetParent() && aField->GetParent()->IsType( { SCH_LABEL_LOCATE_ANY_T } ) ) { m_fieldId = LABELUSERFIELD_V; } diff --git a/eeschema/dialogs/dialog_global_edit_text_and_graphics.cpp b/eeschema/dialogs/dialog_global_edit_text_and_graphics.cpp index 46b0f18b80..3286969a6b 100644 --- a/eeschema/dialogs/dialog_global_edit_text_and_graphics.cpp +++ b/eeschema/dialogs/dialog_global_edit_text_and_graphics.cpp @@ -1,7 +1,7 @@ /* * This program source code file is part of KiCad, a free EDA CAD application. * - * Copyright (C) 2019-2021 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2019-2022 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 @@ -39,7 +39,6 @@ #include #include #include -#include "font/kicad_font_name.h" static bool g_modifyReferences; static bool g_modifyValues; @@ -423,18 +422,6 @@ void DIALOG_GLOBAL_EDIT_TEXT_AND_GRAPHICS::visitItem( const SCH_SHEET_PATH& aShe } } - static KICAD_T wireTypes[] = { SCH_ITEM_LOCATE_WIRE_T, - SCH_LABEL_LOCATE_WIRE_T, - EOT }; - static KICAD_T busTypes[] = { SCH_ITEM_LOCATE_BUS_T, - SCH_LABEL_LOCATE_BUS_T, - EOT }; - static KICAD_T schTextAndGraphics[] = { SCH_TEXT_T, - SCH_TEXTBOX_T, - SCH_ITEM_LOCATE_GRAPHIC_LINE_T, - SCH_SHAPE_T, - EOT }; - if( aItem->Type() == SCH_SYMBOL_T ) { SCH_SYMBOL* symbol = (SCH_SYMBOL*) aItem; @@ -520,16 +507,30 @@ void DIALOG_GLOBAL_EDIT_TEXT_AND_GRAPHICS::visitItem( const SCH_SHEET_PATH& aShe } } } - else if( m_wires->GetValue() && aItem->IsType( wireTypes ) ) + else if( m_wires->GetValue() && aItem->IsType( { SCH_ITEM_LOCATE_WIRE_T, + SCH_LABEL_LOCATE_WIRE_T } ) ) + { processItem( aSheetPath, aItem ); - else if( m_buses->GetValue() && aItem->IsType( busTypes ) ) + } + else if( m_buses->GetValue() && aItem->IsType( { SCH_ITEM_LOCATE_BUS_T, + SCH_LABEL_LOCATE_BUS_T } ) ) + { processItem( aSheetPath, aItem ); + } else if( m_globalLabels->GetValue() && aItem->Type() == SCH_GLOBAL_LABEL_T ) + { processItem( aSheetPath, aItem ); + } else if( m_hierLabels->GetValue() && aItem->Type() == SCH_HIER_LABEL_T ) + { processItem( aSheetPath, aItem ); - else if( m_schTextAndGraphics->GetValue() && aItem->IsType( schTextAndGraphics ) ) + } + else if( m_schTextAndGraphics->GetValue() && aItem->IsType( { SCH_TEXT_T, SCH_TEXTBOX_T, + SCH_ITEM_LOCATE_GRAPHIC_LINE_T, + SCH_SHAPE_T } ) ) + { processItem( aSheetPath, aItem ); + } } diff --git a/eeschema/ee_collectors.cpp b/eeschema/ee_collectors.cpp index f9d6a317db..e1afeae8ff 100644 --- a/eeschema/ee_collectors.cpp +++ b/eeschema/ee_collectors.cpp @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2011 Wayne Stambaugh - * Copyright (C) 2004-2021 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2004-2022 KiCad Developers, see AUTHORS.txt for contributors. * Copyright (C) 2019 CERN * * This program is free software; you can redistribute it and/or @@ -36,13 +36,7 @@ #include "sch_reference_list.h" -const KICAD_T EE_COLLECTOR::AllItems[] = { - SCH_LOCATE_ANY_T, - EOT -}; - - -const KICAD_T EE_COLLECTOR::EditableItems[] = { +const std::initializer_list EE_COLLECTOR::EditableItems = { SCH_SHAPE_T, SCH_TEXT_T, SCH_TEXTBOX_T, @@ -62,19 +56,7 @@ const KICAD_T EE_COLLECTOR::EditableItems[] = { }; -const KICAD_T EE_COLLECTOR::SymbolsOnly[] = { - SCH_SYMBOL_T, - EOT -}; - - -const KICAD_T EE_COLLECTOR::SheetsOnly[] = { - SCH_SHEET_T, - EOT -}; - - -const KICAD_T EE_COLLECTOR::MovableItems[] = +const std::initializer_list EE_COLLECTOR::MovableItems = { SCH_MARKER_T, SCH_JUNCTION_T, @@ -98,20 +80,10 @@ const KICAD_T EE_COLLECTOR::MovableItems[] = }; -const KICAD_T EE_COLLECTOR::WiresOnly[] = { - SCH_LINE_T, - EOT -}; - - -const KICAD_T EE_COLLECTOR::FieldOwners[] = { +const std::initializer_list EE_COLLECTOR::FieldOwners = { SCH_SYMBOL_T, SCH_SHEET_T, - SCH_LABEL_T, - SCH_GLOBAL_LABEL_T, - SCH_HIER_LABEL_T, - SCH_DIRECTIVE_LABEL_T, - EOT + SCH_LABEL_LOCATE_ANY_T }; @@ -146,8 +118,9 @@ INSPECT_RESULT EE_COLLECTOR::Inspect( EDA_ITEM* aItem, void* aTestData ) } -void EE_COLLECTOR::Collect( SCH_SCREEN* aScreen, const KICAD_T aFilterList[], const VECTOR2I& aPos, - int aUnit, int aConvert ) +void EE_COLLECTOR::Collect( SCH_SCREEN* aScreen, + const std::initializer_list& aFilterList, + const VECTOR2I& aPos, int aUnit, int aConvert ) { Empty(); // empty the collection just in case @@ -166,7 +139,8 @@ void EE_COLLECTOR::Collect( SCH_SCREEN* aScreen, const KICAD_T aFilterList[], co } -void EE_COLLECTOR::Collect( LIB_ITEMS_CONTAINER& aItems, const KICAD_T aFilterList[], +void EE_COLLECTOR::Collect( LIB_ITEMS_CONTAINER& aItems, + const std::initializer_list& aFilterList, const VECTOR2I& aPos, int aUnit, int aConvert ) { Empty(); // empty the collection just in case diff --git a/eeschema/ee_collectors.h b/eeschema/ee_collectors.h index afcb196461..3bbb1c95d7 100644 --- a/eeschema/ee_collectors.h +++ b/eeschema/ee_collectors.h @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2011 Wayne Stambaugh - * Copyright (C) 2011-2021 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2011-2022 KiCad Developers, see AUTHORS.txt for contributors. * Copyright (C) 2019 CERN * * This program is free software; you can redistribute it and/or @@ -39,15 +39,11 @@ class SCH_SYMBOL; class EE_COLLECTOR : public COLLECTOR { public: - static const KICAD_T AllItems[]; - static const KICAD_T EditableItems[]; - static const KICAD_T MovableItems[]; - static const KICAD_T SymbolsOnly[]; - static const KICAD_T SheetsOnly[]; - static const KICAD_T WiresOnly[]; - static const KICAD_T FieldOwners[]; + static const std::initializer_list EditableItems; + static const std::initializer_list MovableItems; + static const std::initializer_list FieldOwners; - EE_COLLECTOR( const KICAD_T* aScanTypes = EE_COLLECTOR::AllItems ) : + EE_COLLECTOR( const std::initializer_list& aScanTypes = { SCH_LOCATE_ANY_T } ) : m_Unit( 0 ), m_Convert( 0 ), m_ShowPinElectricalTypes( false ) @@ -75,29 +71,27 @@ public: * Scan a #EDA_ITEM using this class's Inspector method which does the collection. * * @param aScreen The eeschema screen to use for scanning - * @param aFilterList A list of #KICAD_T types with a terminating #EOT, that determines - * what is to be collected and the priority order of the resulting - * collection. + * @param aFilterList A list of #KICAD_T types that determines what is to be collected and + * the priority order of the resulting collection. * @param aPos are the coordinates to use in hit testing. * @param aUnit is the symbol unit filter (for symbol editor). * @param aConvert is the DeMorgan filter (for symbol editor) */ - void Collect( SCH_SCREEN* aScreen, const KICAD_T aFilterList[], const VECTOR2I& aPos, - int aUnit = 0, int aConvert = 0 ); + void Collect( SCH_SCREEN* aScreen, const std::initializer_list& aFilterList, + const VECTOR2I& aPos, int aUnit = 0, int aConvert = 0 ); /** * Scan an #EDA_ITEM using this class's Inspector method which does the collection. * * @param aItems is a LIB_SYMBOL multivector holding the symbol items. - * @param aFilterList is a list of #KICAD_T types with a terminating #EOT, that determines - * what is to be collected and the priority order of the resulting - * collection. + * @param aFilterList is a list of #KICAD_T types that determines what is to be collected + * and the priority order of the resulting collection. * @param aPos are the coordinates to use in hit testing. * @param aUnit is the symbol unit filter (for symbol editor). * @param aConvert is the DeMorgan filter (for symbol editor). */ - void Collect( LIB_ITEMS_CONTAINER& aItems, const KICAD_T aFilterList[], const VECTOR2I& aPos, - int aUnit = 0, int aConvert = 0 ); + void Collect( LIB_ITEMS_CONTAINER& aItems, const std::initializer_list& aFilterList, + const VECTOR2I& aPos, int aUnit = 0, int aConvert = 0 ); /** * Test if the collected items form a corner of two line segments. diff --git a/eeschema/eeschema_config.cpp b/eeschema/eeschema_config.cpp index b898586f88..3945888bce 100644 --- a/eeschema/eeschema_config.cpp +++ b/eeschema/eeschema_config.cpp @@ -56,7 +56,6 @@ bool SCH_EDIT_FRAME::LoadProjectSettings() GetRenderSettings()->m_LabelSizeRatio = settings.m_LabelSizeRatio; GetRenderSettings()->m_TextOffsetRatio = settings.m_TextOffsetRatio; GetRenderSettings()->m_PinSymbolSize = settings.m_PinSymbolSize; - GetRenderSettings()->m_JunctionSize = settings.m_JunctionSize; GetRenderSettings()->SetDashLengthRatio( settings.m_DashedLineDashRatio ); GetRenderSettings()->SetGapLengthRatio( settings.m_DashedLineGapRatio ); @@ -94,7 +93,6 @@ void SCH_EDIT_FRAME::ShowSchematicSetupDialog( const wxString& aInitialPage ) GetRenderSettings()->m_LabelSizeRatio = Schematic().Settings().m_LabelSizeRatio; GetRenderSettings()->m_TextOffsetRatio = Schematic().Settings().m_TextOffsetRatio; GetRenderSettings()->m_PinSymbolSize = Schematic().Settings().m_PinSymbolSize; - GetRenderSettings()->m_JunctionSize = Schematic().Settings().m_JunctionSize; GetRenderSettings()->SetDashLengthRatio( Schematic().Settings().m_DashedLineDashRatio ); GetRenderSettings()->SetGapLengthRatio( Schematic().Settings().m_DashedLineGapRatio ); diff --git a/eeschema/lib_symbol.cpp b/eeschema/lib_symbol.cpp index afa9ca75f5..13978bc9d2 100644 --- a/eeschema/lib_symbol.cpp +++ b/eeschema/lib_symbol.cpp @@ -1237,12 +1237,12 @@ LIB_ITEM* LIB_SYMBOL::LocateDrawItem( int aUnit, int aConvert, KICAD_T aType, INSPECT_RESULT LIB_SYMBOL::Visit( INSPECTOR aInspector, void* aTestData, - const KICAD_T aFilterTypes[] ) + const std::initializer_list& aScanTypes ) { // The part itself is never inspected, only its children for( LIB_ITEM& item : m_drawings ) { - if( item.IsType( aFilterTypes ) ) + if( item.IsType( aScanTypes ) ) { if( aInspector( &item, aTestData ) == INSPECT_RESULT::QUIT ) return INSPECT_RESULT::QUIT; diff --git a/eeschema/lib_symbol.h b/eeschema/lib_symbol.h index c7b335b6cf..eb71ff24d3 100644 --- a/eeschema/lib_symbol.h +++ b/eeschema/lib_symbol.h @@ -3,7 +3,7 @@ * * Copyright (C) 2004-2015 Jean-Pierre Charras, jp.charras at wanadoo.fr * Copyright (C) 2008 Wayne Stambaugh - * Copyright (C) 2004-2021 KiCad Developers, see change_log.txt for contributors. + * Copyright (C) 2004-2022 KiCad Developers, see change_log.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 @@ -502,7 +502,8 @@ public: LIB_ITEMS_CONTAINER& GetDrawItems() { return m_drawings; } const LIB_ITEMS_CONTAINER& GetDrawItems() const { return m_drawings; } - INSPECT_RESULT Visit( INSPECTOR inspector, void* testData, const KICAD_T scanTypes[] ) override; + INSPECT_RESULT Visit( INSPECTOR inspector, void* testData, + const std::initializer_list& aScanTypes ) override; /** * Set the units per symbol count. diff --git a/eeschema/sch_base_frame.cpp b/eeschema/sch_base_frame.cpp index b6186e97bf..3abb11cb88 100644 --- a/eeschema/sch_base_frame.cpp +++ b/eeschema/sch_base_frame.cpp @@ -106,11 +106,6 @@ SCH_BASE_FRAME::SCH_BASE_FRAME( KIWAY* aKiway, wxWindow* aParent, FRAME_T aWindo } -SCH_BASE_FRAME::~SCH_BASE_FRAME() -{ -} - - SCH_SCREEN* SCH_BASE_FRAME::GetScreen() const { return (SCH_SCREEN*) EDA_DRAW_FRAME::GetScreen(); @@ -187,10 +182,7 @@ void SCH_BASE_FRAME::UpdateStatusBar() MessageTextFromValue( GetUserUnits(), hypot( d.x, d.y ), false ) ); SetStatusText( line, 3 ); - // refresh grid display DisplayGridMsg(); - - // refresh units display DisplayUnitsMsg(); } @@ -255,17 +247,6 @@ void SCH_BASE_FRAME::RedrawScreen( const VECTOR2I& aCenterPoint, bool aWarpPoint } -void SCH_BASE_FRAME::CenterScreen( const VECTOR2I& aCenterPoint, bool aWarpPointer ) -{ - GetCanvas()->GetView()->SetCenter( aCenterPoint ); - - if( aWarpPointer ) - GetCanvas()->GetViewControls()->WarpMouseCursor( aCenterPoint, true ); - - GetCanvas()->Refresh(); -} - - void SCH_BASE_FRAME::HardRedraw() { if( GetCanvas() && GetCanvas()->GetView() ) @@ -342,15 +323,7 @@ void SCH_BASE_FRAME::UpdateItem( EDA_ITEM* aItem, bool isAddOrDelete, bool aUpda GetCanvas()->GetView()->Update( aItem ); // Some children are drawn from their parents. Mark them for re-paint. - static KICAD_T parentTypes[] = { SCH_SYMBOL_T, - SCH_SHEET_T, - SCH_LABEL_T, - SCH_GLOBAL_LABEL_T, - SCH_HIER_LABEL_T, - SCH_DIRECTIVE_LABEL_T, - EOT }; - - if( parent && parent->IsType( parentTypes ) ) + if( parent && parent->IsType( { SCH_SYMBOL_T, SCH_SHEET_T, SCH_LABEL_LOCATE_ANY_T } ) ) GetCanvas()->GetView()->Update( parent, KIGFX::REPAINT ); } diff --git a/eeschema/sch_base_frame.h b/eeschema/sch_base_frame.h index f567843f47..033b1a12cd 100644 --- a/eeschema/sch_base_frame.h +++ b/eeschema/sch_base_frame.h @@ -92,13 +92,12 @@ LIB_SYMBOL* SchGetLibSymbol( const LIB_ID& aLibId, SYMBOL_LIB_TABLE* aLibTable, class SCH_BASE_FRAME : public EDA_DRAW_FRAME { public: - SCH_BASE_FRAME( KIWAY* aKiway, wxWindow* aParent, - FRAME_T aWindowType, - const wxString& aTitle, - const wxPoint& aPosition, const wxSize& aSize, - long aStyle, const wxString & aFrameName ); + SCH_BASE_FRAME( KIWAY* aKiway, wxWindow* aParent, FRAME_T aWindowType, const wxString& aTitle, + const wxPoint& aPosition, const wxSize& aSize, long aStyle, + const wxString & aFrameName ); - virtual ~SCH_BASE_FRAME(); + virtual ~SCH_BASE_FRAME() + { } void createCanvas(); @@ -198,8 +197,6 @@ public: virtual void RedrawScreen( const VECTOR2I& aCenterPoint, bool aWarpPointer ); - virtual void CenterScreen( const VECTOR2I& aCenterPoint, bool aWarpPointer ); - void HardRedraw() override; /** diff --git a/eeschema/sch_edit_frame.cpp b/eeschema/sch_edit_frame.cpp index cbb397e4f7..c028098ed2 100644 --- a/eeschema/sch_edit_frame.cpp +++ b/eeschema/sch_edit_frame.cpp @@ -1353,8 +1353,7 @@ void SCH_EDIT_FRAME::AddItemToScreenAndUndoList( SCH_SCREEN* aScreen, SCH_ITEM* if( connected ) { - static KICAD_T autoRotatableLabelTypes[] = { SCH_GLOBAL_LABEL_T, SCH_HIER_LABEL_T }; - if( aItem->IsType( autoRotatableLabelTypes ) ) + if( aItem->IsType( { SCH_GLOBAL_LABEL_T, SCH_HIER_LABEL_T } ) ) { auto label = static_cast( aItem ); if( label->AutoRotateOnPlacement() ) diff --git a/eeschema/sch_field.cpp b/eeschema/sch_field.cpp index c0b1f96762..35c343214e 100644 --- a/eeschema/sch_field.cpp +++ b/eeschema/sch_field.cpp @@ -90,11 +90,6 @@ SCH_FIELD::SCH_FIELD( const SCH_FIELD& aField ) : } -SCH_FIELD::~SCH_FIELD() -{ -} - - SCH_FIELD& SCH_FIELD::operator=( const SCH_FIELD& aField ) { EDA_TEXT::operator=( aField ); @@ -125,8 +120,6 @@ EDA_ITEM* SCH_FIELD::Clone() const void SCH_FIELD::SetId( int aId ) { - KICAD_T labelTypes[] = { SCH_LABEL_LOCATE_ANY_T, EOT }; - m_id = aId; if( m_parent && m_parent->Type() == SCH_SHEET_T ) @@ -147,7 +140,7 @@ void SCH_FIELD::SetId( int aId ) default: SetLayer( LAYER_FIELDS ); break; } } - else if( m_parent && m_parent->IsType( labelTypes ) ) + else if( m_parent && m_parent->IsType( { SCH_LABEL_LOCATE_ANY_T } ) ) { // We can't use defined IDs for labels because there can be multiple net class // assignments. @@ -164,8 +157,6 @@ void SCH_FIELD::SetId( int aId ) wxString SCH_FIELD::GetShownText( int aDepth ) const { - KICAD_T labelTypes[] = { SCH_LABEL_LOCATE_ANY_T, EOT }; - std::function symbolResolver = [&]( wxString* token ) -> bool { @@ -223,7 +214,7 @@ wxString SCH_FIELD::GetShownText( int aDepth ) const text = ExpandTextVars( text, &symbolResolver, nullptr, project ); else if( m_parent && m_parent->Type() == SCH_SHEET_T ) text = ExpandTextVars( text, &sheetResolver, nullptr, project ); - else if( m_parent && m_parent->IsType( labelTypes ) ) + else if( m_parent && m_parent->IsType( { SCH_LABEL_LOCATE_ANY_T } ) ) text = ExpandTextVars( text, &labelResolver, nullptr, project ); else text = ExpandTextVars( text, project ); @@ -790,8 +781,6 @@ void SCH_FIELD::DoHypertextMenu( EDA_DRAW_FRAME* aFrame ) wxString SCH_FIELD::GetName( bool aUseDefaultName ) const { - KICAD_T labelTypes[] = { SCH_LABEL_LOCATE_ANY_T, EOT }; - if( m_parent && m_parent->Type() == SCH_SYMBOL_T ) { if( m_id >= 0 && m_id < MANDATORY_FIELDS ) @@ -810,7 +799,7 @@ wxString SCH_FIELD::GetName( bool aUseDefaultName ) const else return m_name; } - else if( m_parent && m_parent->IsType( labelTypes ) ) + else if( m_parent && m_parent->IsType( { SCH_LABEL_LOCATE_ANY_T } ) ) { return SCH_LABEL_BASE::GetDefaultFieldName( m_name, aUseDefaultName ); } @@ -824,8 +813,6 @@ wxString SCH_FIELD::GetName( bool aUseDefaultName ) const wxString SCH_FIELD::GetCanonicalName() const { - KICAD_T labelTypes[] = { SCH_LABEL_LOCATE_ANY_T, EOT }; - if( m_parent && m_parent->Type() == SCH_SYMBOL_T ) { switch( m_id ) @@ -846,7 +833,7 @@ wxString SCH_FIELD::GetCanonicalName() const default: return m_name; } } - else if( m_parent && m_parent->IsType( labelTypes ) ) + else if( m_parent && m_parent->IsType( { SCH_LABEL_LOCATE_ANY_T } ) ) { // These should be stored in canonical format, but just in case: if( m_name == _( "Net Class" ) ) diff --git a/eeschema/sch_field.h b/eeschema/sch_field.h index 33a537f4ac..b1efb11ccd 100644 --- a/eeschema/sch_field.h +++ b/eeschema/sch_field.h @@ -54,7 +54,8 @@ public: SCH_FIELD( const SCH_FIELD& aText ); - ~SCH_FIELD(); + ~SCH_FIELD() + { } SCH_FIELD& operator=( const SCH_FIELD& aField ); @@ -68,20 +69,20 @@ public: return wxT( "SCH_FIELD" ); } - bool IsType( const KICAD_T aScanTypes[] ) const override + bool IsType( const std::initializer_list& aScanTypes ) const override { if( SCH_ITEM::IsType( aScanTypes ) ) return true; - for( const KICAD_T* p = aScanTypes; *p != EOT; ++p ) + for( KICAD_T scanType : aScanTypes ) { - if( *p == SCH_FIELD_LOCATE_REFERENCE_T && m_id == REFERENCE_FIELD ) + if( scanType == SCH_FIELD_LOCATE_REFERENCE_T && m_id == REFERENCE_FIELD ) return true; - else if ( *p == SCH_FIELD_LOCATE_VALUE_T && m_id == VALUE_FIELD ) + else if ( scanType == SCH_FIELD_LOCATE_VALUE_T && m_id == VALUE_FIELD ) return true; - else if ( *p == SCH_FIELD_LOCATE_FOOTPRINT_T && m_id == FOOTPRINT_FIELD ) + else if ( scanType == SCH_FIELD_LOCATE_FOOTPRINT_T && m_id == FOOTPRINT_FIELD ) return true; - else if ( *p == SCH_FIELD_LOCATE_DATASHEET_T && m_id == DATASHEET_FIELD ) + else if ( scanType == SCH_FIELD_LOCATE_DATASHEET_T && m_id == DATASHEET_FIELD ) return true; } diff --git a/eeschema/sch_item.h b/eeschema/sch_item.h index 8ff242ed61..d59a9999dd 100644 --- a/eeschema/sch_item.h +++ b/eeschema/sch_item.h @@ -157,20 +157,20 @@ public: return wxT( "SCH_ITEM" ); } - bool IsType( const KICAD_T aScanTypes[] ) const override + bool IsType( const std::initializer_list& aScanTypes ) const override { if( EDA_ITEM::IsType( aScanTypes ) ) return true; - for( const KICAD_T* p = aScanTypes; *p != EOT; ++p ) + for( KICAD_T scanType : aScanTypes ) { - if( *p == SCH_ITEM_LOCATE_WIRE_T && m_layer == LAYER_WIRE ) + if( scanType == SCH_ITEM_LOCATE_WIRE_T && m_layer == LAYER_WIRE ) return true; - if ( *p == SCH_ITEM_LOCATE_BUS_T && m_layer == LAYER_BUS ) + if ( scanType == SCH_ITEM_LOCATE_BUS_T && m_layer == LAYER_BUS ) return true; - if ( *p == SCH_ITEM_LOCATE_GRAPHIC_LINE_T + if ( scanType == SCH_ITEM_LOCATE_GRAPHIC_LINE_T && Type() == SCH_LINE_T && m_layer == LAYER_NOTES ) { return true; diff --git a/eeschema/sch_label.cpp b/eeschema/sch_label.cpp index adc5e6cacd..1117d01700 100644 --- a/eeschema/sch_label.cpp +++ b/eeschema/sch_label.cpp @@ -190,17 +190,14 @@ const wxString SCH_LABEL_BASE::GetDefaultFieldName( const wxString& aName, bool } -bool SCH_LABEL_BASE::IsType( const KICAD_T aScanTypes[] ) const +bool SCH_LABEL_BASE::IsType( const std::initializer_list& aScanTypes ) const { - static KICAD_T wireTypes[] = { SCH_ITEM_LOCATE_WIRE_T, SCH_PIN_T, EOT }; - static KICAD_T busTypes[] = { SCH_ITEM_LOCATE_BUS_T, EOT }; - if( SCH_TEXT::IsType( aScanTypes ) ) return true; - for( const KICAD_T* p = aScanTypes; *p != EOT; ++p ) + for( KICAD_T scanType : aScanTypes ) { - if( *p == SCH_LABEL_LOCATE_ANY_T ) + if( scanType == SCH_LABEL_LOCATE_ANY_T ) return true; } @@ -213,22 +210,22 @@ bool SCH_LABEL_BASE::IsType( const KICAD_T aScanTypes[] ) const const SCH_ITEM_SET& item_set = m_connected_items.at( Schematic()->CurrentSheet() ); - for( const KICAD_T* p = aScanTypes; *p != EOT; ++p ) + for( KICAD_T scanType : aScanTypes ) { - if( *p == SCH_LABEL_LOCATE_WIRE_T ) + if( scanType == SCH_LABEL_LOCATE_WIRE_T ) { for( SCH_ITEM* connection : item_set ) { - if( connection->IsType( wireTypes ) ) + if( connection->IsType( { SCH_ITEM_LOCATE_WIRE_T, SCH_PIN_T } ) ) return true; } } - if ( *p == SCH_LABEL_LOCATE_BUS_T ) + if ( scanType == SCH_LABEL_LOCATE_BUS_T ) { for( SCH_ITEM* connection : item_set ) { - if( connection->IsType( busTypes ) ) + if( connection->IsType( { SCH_ITEM_LOCATE_BUS_T } ) ) return true; } } @@ -545,19 +542,19 @@ void SCH_LABEL_BASE::RunOnChildren( const std::function& aFun INSPECT_RESULT SCH_LABEL_BASE::Visit( INSPECTOR aInspector, void* testData, - const KICAD_T aFilterTypes[] ) + const std::initializer_list& aScanTypes ) { KICAD_T stype; - if( IsType( aFilterTypes ) ) + if( IsType( aScanTypes ) ) { if( INSPECT_RESULT::QUIT == aInspector( this, nullptr ) ) return INSPECT_RESULT::QUIT; } - for( const KICAD_T* p = aFilterTypes; (stype = *p) != EOT; ++p ) + for( KICAD_T scanType : aScanTypes ) { - if( stype == SCH_LOCATE_ANY_T || stype == SCH_FIELD_T ) + if( scanType == SCH_LOCATE_ANY_T || scanType == SCH_FIELD_T ) { for( SCH_FIELD& field : m_fields ) { diff --git a/eeschema/sch_label.h b/eeschema/sch_label.h index 7c9bf08039..c4c10cc06e 100644 --- a/eeschema/sch_label.h +++ b/eeschema/sch_label.h @@ -44,7 +44,7 @@ public: // Abstract class virtual wxString GetClass() const override = 0; - bool IsType( const KICAD_T aScanTypes[] ) const override; + bool IsType( const std::initializer_list& aScanTypes ) const override; void SwapData( SCH_ITEM* aItem ) override; @@ -119,7 +119,8 @@ public: void RunOnChildren( const std::function& aFunction ) override; - INSPECT_RESULT Visit( INSPECTOR inspector, void* testData, const KICAD_T scanTypes[] ) override; + INSPECT_RESULT Visit( INSPECTOR inspector, void* testData, + const std::initializer_list& scanTypes ) override; VECTOR2I GetSchematicTextOffset( const RENDER_SETTINGS* aSettings ) const override; diff --git a/eeschema/sch_line.h b/eeschema/sch_line.h index 60aa30f5c4..2247dee46d 100644 --- a/eeschema/sch_line.h +++ b/eeschema/sch_line.h @@ -67,20 +67,20 @@ public: */ wxString GetNetname(const SCH_SHEET_PATH &aSheet); - bool IsType( const KICAD_T aScanTypes[] ) const override + bool IsType( const std::initializer_list& aScanTypes ) const override { if( SCH_ITEM::IsType( aScanTypes ) ) return true; - for( const KICAD_T* p = aScanTypes; *p != EOT; ++p ) + for( KICAD_T scanType : aScanTypes ) { - if( *p == SCH_ITEM_LOCATE_WIRE_T && m_layer == LAYER_WIRE ) + if( scanType == SCH_ITEM_LOCATE_WIRE_T && m_layer == LAYER_WIRE ) return true; - if ( *p == SCH_ITEM_LOCATE_BUS_T && m_layer == LAYER_BUS ) + if ( scanType == SCH_ITEM_LOCATE_BUS_T && m_layer == LAYER_BUS ) return true; - if ( *p == SCH_ITEM_LOCATE_GRAPHIC_LINE_T && m_layer == LAYER_NOTES ) + if ( scanType == SCH_ITEM_LOCATE_GRAPHIC_LINE_T && m_layer == LAYER_NOTES ) return true; } diff --git a/eeschema/sch_painter.cpp b/eeschema/sch_painter.cpp index 06322c8d4a..be495109b0 100644 --- a/eeschema/sch_painter.cpp +++ b/eeschema/sch_painter.cpp @@ -74,19 +74,20 @@ EESCHEMA_SETTINGS* eeconfig() } -KICAD_T SCH_PAINTER::g_ScaledSelectionTypes[] = { SCH_MARKER_T, - SCH_JUNCTION_T, - SCH_NO_CONNECT_T, - SCH_BUS_WIRE_ENTRY_T, - SCH_BUS_BUS_ENTRY_T, - SCH_LINE_T, - LIB_SHAPE_T, SCH_SHAPE_T, - SCH_BITMAP_T, - SCH_DIRECTIVE_LABEL_T, - LIB_SYMBOL_T, SCH_SYMBOL_T, - SCH_SHEET_T, - LIB_PIN_T, SCH_PIN_T, - EOT }; +std::initializer_list SCH_PAINTER::g_ScaledSelectionTypes = { + SCH_MARKER_T, + SCH_JUNCTION_T, + SCH_NO_CONNECT_T, + SCH_BUS_WIRE_ENTRY_T, + SCH_BUS_BUS_ENTRY_T, + SCH_LINE_T, + LIB_SHAPE_T, SCH_SHAPE_T, + SCH_BITMAP_T, + SCH_DIRECTIVE_LABEL_T, + LIB_SYMBOL_T, SCH_SYMBOL_T, + SCH_SHEET_T, + LIB_PIN_T, SCH_PIN_T +}; SCH_RENDER_SETTINGS::SCH_RENDER_SETTINGS() : @@ -99,8 +100,7 @@ SCH_RENDER_SETTINGS::SCH_RENDER_SETTINGS() : m_OverrideItemColors( false ), m_LabelSizeRatio( DEFAULT_LABEL_SIZE_RATIO ), m_TextOffsetRatio( DEFAULT_TEXT_OFFSET_RATIO ), - m_PinSymbolSize( DEFAULT_TEXT_SIZE * IU_PER_MILS / 2 ), - m_JunctionSize( DEFAULT_JUNCTION_DIAM * IU_PER_MILS ) + m_PinSymbolSize( DEFAULT_TEXT_SIZE * IU_PER_MILS / 2 ) { SetDefaultPenWidth( DEFAULT_LINE_WIDTH_MILS * IU_PER_MILS ); SetDashLengthRatio( 12 ); // From ISO 128-2 diff --git a/eeschema/sch_painter.h b/eeschema/sch_painter.h index 7e8fd51ed6..4cfc6b6eab 100644 --- a/eeschema/sch_painter.h +++ b/eeschema/sch_painter.h @@ -122,9 +122,7 @@ public: double m_LabelSizeRatio; // Proportion of font size to label box double m_TextOffsetRatio; // Proportion of font size to offset text above/below // wires, buses, etc. - int m_PinSymbolSize; - int m_JunctionSize; }; @@ -140,15 +138,9 @@ public: virtual bool Draw( const VIEW_ITEM*, int ) override; /// @copydoc PAINTER::GetSettings() - virtual SCH_RENDER_SETTINGS* GetSettings() override - { - return &m_schSettings; - } + virtual SCH_RENDER_SETTINGS* GetSettings() override { return &m_schSettings; } - void SetSchematic( SCHEMATIC* aSchematic ) - { - m_schematic = aSchematic; - } + void SetSchematic( SCHEMATIC* aSchematic ) { m_schematic = aSchematic; } private: void draw( LIB_PIN* aPin, int aLayer ); @@ -195,21 +187,19 @@ private: bool setDeviceColors( const LIB_ITEM* aItem, int aLayer ); - void triLine ( const VECTOR2D &a, const VECTOR2D &b, const VECTOR2D &c ); + void triLine( const VECTOR2D &a, const VECTOR2D &b, const VECTOR2D &c ); void strokeText( const wxString& aText, const VECTOR2D& aPosition, const TEXT_ATTRIBUTES& aAttributes ); void bitmapText( const wxString& aText, const VECTOR2D& aPosition, const TEXT_ATTRIBUTES& aAttributes ); - void boxText( const wxString& aText, const VECTOR2D& aPosition, - const TEXT_ATTRIBUTES& aAttrs ); + void boxText( const wxString& aText, const VECTOR2D& aPosition, const TEXT_ATTRIBUTES& aAttrs ); public: - static KICAD_T g_ScaledSelectionTypes[]; + static std::initializer_list g_ScaledSelectionTypes; private: SCH_RENDER_SETTINGS m_schSettings; - - SCHEMATIC* m_schematic; + SCHEMATIC* m_schematic; }; }; // namespace KIGFX diff --git a/eeschema/sch_plugins/eagle/sch_eagle_plugin.cpp b/eeschema/sch_plugins/eagle/sch_eagle_plugin.cpp index 42e2bd1864..5fa9d58757 100644 --- a/eeschema/sch_plugins/eagle/sch_eagle_plugin.cpp +++ b/eeschema/sch_plugins/eagle/sch_eagle_plugin.cpp @@ -2355,12 +2355,11 @@ bool SCH_EAGLE_PLUGIN::CheckHeader( const wxString& aFileName ) void SCH_EAGLE_PLUGIN::moveLabels( SCH_LINE* aWire, const VECTOR2I& aNewEndPoint ) { - static KICAD_T labelTypes[] = { SCH_LABEL_LOCATE_ANY_T, EOT }; - SCH_SCREEN* screen = m_currentSheet->GetScreen(); + SCH_SCREEN* screen = m_currentSheet->GetScreen(); for( SCH_ITEM* item : screen->Items().Overlapping( aWire->GetBoundingBox() ) ) { - if( !item->IsType( labelTypes ) ) + if( !item->IsType( { SCH_LABEL_LOCATE_ANY_T } ) ) continue; if( TestSegmentHit( item->GetPosition(), aWire->GetStartPoint(), aWire->GetEndPoint(), 0 ) ) diff --git a/eeschema/sch_screen.cpp b/eeschema/sch_screen.cpp index 6359be3443..6a8e6dbda3 100644 --- a/eeschema/sch_screen.cpp +++ b/eeschema/sch_screen.cpp @@ -24,11 +24,6 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ -/** - * @file sch_screen.cpp - * @brief Implementation of SCH_SCREEN and SCH_SCREENS classes. - */ - #include #include @@ -92,7 +87,7 @@ SCH_SCREEN::~SCH_SCREEN() SCHEMATIC* SCH_SCREEN::Schematic() const { wxCHECK_MSG( GetParent() && GetParent()->Type() == SCHEMATIC_T, nullptr, - "SCH_SCREEN must have a SCHEMATIC parent!" ); + wxT( "SCH_SCREEN must have a SCHEMATIC parent!" ) ); return static_cast( GetParent() ); } @@ -123,8 +118,7 @@ void SCH_SCREEN::IncRefCount() void SCH_SCREEN::DecRefCount() { - wxCHECK_RET( m_refCount != 0, - wxT( "Screen reference count already zero. Bad programmer!" ) ); + wxCHECK_RET( m_refCount != 0, wxT( "Screen reference count already zero. Bad programmer!" ) ); m_refCount--; } @@ -1284,17 +1278,9 @@ void SCH_SCREEN::EnsureAlternateReferencesExist() void SCH_SCREEN::GetHierarchicalItems( std::vector* aItems ) const { - static KICAD_T hierarchicalTypes[] = { SCH_SYMBOL_T, - SCH_SHEET_T, - SCH_LABEL_T, - SCH_HIER_LABEL_T, - SCH_DIRECTIVE_LABEL_T, - SCH_GLOBAL_LABEL_T, - EOT }; - for( SCH_ITEM* item : Items() ) { - if( item->IsType( hierarchicalTypes ) ) + if( item->IsType( { SCH_SYMBOL_T, SCH_SHEET_T, SCH_LABEL_LOCATE_ANY_T } ) ) aItems->push_back( item ); } } @@ -1317,7 +1303,9 @@ void SCH_SCREEN::GetSheets( std::vector* aItems ) const return a->GetPosition().y < b->GetPosition().y; } else + { return a->GetPosition().x < b->GetPosition().x; + } } ); } diff --git a/eeschema/sch_sheet.cpp b/eeschema/sch_sheet.cpp index ee6dddded2..d41cdf0486 100644 --- a/eeschema/sch_sheet.cpp +++ b/eeschema/sch_sheet.cpp @@ -943,20 +943,19 @@ std::vector SCH_SHEET::GetConnectionPoints() const } -INSPECT_RESULT SCH_SHEET::Visit( INSPECTOR aInspector, void* testData, const KICAD_T aFilterTypes[] ) +INSPECT_RESULT SCH_SHEET::Visit( INSPECTOR aInspector, void* testData, + const std::initializer_list& aScanTypes ) { - KICAD_T stype; - - for( const KICAD_T* p = aFilterTypes; (stype = *p) != EOT; ++p ) + for( KICAD_T scanType : aScanTypes ) { // If caller wants to inspect my type - if( stype == SCH_LOCATE_ANY_T || stype == Type() ) + if( scanType == SCH_LOCATE_ANY_T || scanType == Type() ) { if( INSPECT_RESULT::QUIT == aInspector( this, nullptr ) ) return INSPECT_RESULT::QUIT; } - if( stype == SCH_LOCATE_ANY_T || stype == SCH_FIELD_T ) + if( scanType == SCH_LOCATE_ANY_T || scanType == SCH_FIELD_T ) { // Test the sheet fields. for( SCH_FIELD& field : m_fields ) @@ -966,7 +965,7 @@ INSPECT_RESULT SCH_SHEET::Visit( INSPECTOR aInspector, void* testData, const KIC } } - if( stype == SCH_LOCATE_ANY_T || stype == SCH_SHEET_PIN_T ) + if( scanType == SCH_LOCATE_ANY_T || scanType == SCH_SHEET_PIN_T ) { // Test the sheet labels. for( SCH_SHEET_PIN* sheetPin : m_pins ) diff --git a/eeschema/sch_sheet.h b/eeschema/sch_sheet.h index 8325ee42cc..b6627581c3 100644 --- a/eeschema/sch_sheet.h +++ b/eeschema/sch_sheet.h @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2015 Jean-Pierre Charras, jp.charras at wanadoo.fr - * Copyright (C) 1992-2021 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 1992-2022 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 @@ -350,7 +350,8 @@ public: std::vector GetConnectionPoints() const override; - INSPECT_RESULT Visit( INSPECTOR inspector, void* testData, const KICAD_T scanTypes[] ) override; + INSPECT_RESULT Visit( INSPECTOR inspector, void* testData, + const std::initializer_list& aScanTypes ) override; void RunOnChildren( const std::function& aFunction ) override; diff --git a/eeschema/sch_symbol.cpp b/eeschema/sch_symbol.cpp index 91904ab332..74a60d15ba 100644 --- a/eeschema/sch_symbol.cpp +++ b/eeschema/sch_symbol.cpp @@ -1724,21 +1724,19 @@ wxString SCH_SYMBOL::GetSelectMenuText( EDA_UNITS aUnits ) const INSPECT_RESULT SCH_SYMBOL::Visit( INSPECTOR aInspector, void* aTestData, - const KICAD_T aFilterTypes[] ) + const std::initializer_list& aScanTypes ) { - KICAD_T stype; - - for( const KICAD_T* p = aFilterTypes; (stype = *p) != EOT; ++p ) + for( KICAD_T scanType : aScanTypes ) { - if( stype == SCH_LOCATE_ANY_T - || ( stype == SCH_SYMBOL_T ) - || ( stype == SCH_SYMBOL_LOCATE_POWER_T && m_part && m_part->IsPower() ) ) + if( scanType == SCH_LOCATE_ANY_T + || ( scanType == SCH_SYMBOL_T ) + || ( scanType == SCH_SYMBOL_LOCATE_POWER_T && m_part && m_part->IsPower() ) ) { if( INSPECT_RESULT::QUIT == aInspector( this, aTestData ) ) return INSPECT_RESULT::QUIT; } - if( stype == SCH_LOCATE_ANY_T || stype == SCH_FIELD_T ) + if( scanType == SCH_LOCATE_ANY_T || scanType == SCH_FIELD_T ) { for( SCH_FIELD& field : m_fields ) { @@ -1747,32 +1745,32 @@ INSPECT_RESULT SCH_SYMBOL::Visit( INSPECTOR aInspector, void* aTestData, } } - if( stype == SCH_FIELD_LOCATE_REFERENCE_T ) + if( scanType == SCH_FIELD_LOCATE_REFERENCE_T ) { if( INSPECT_RESULT::QUIT == aInspector( GetField( REFERENCE_FIELD ), (void*) this ) ) return INSPECT_RESULT::QUIT; } - if( stype == SCH_FIELD_LOCATE_VALUE_T - || ( stype == SCH_SYMBOL_LOCATE_POWER_T && m_part && m_part->IsPower() ) ) + if( scanType == SCH_FIELD_LOCATE_VALUE_T + || ( scanType == SCH_SYMBOL_LOCATE_POWER_T && m_part && m_part->IsPower() ) ) { if( INSPECT_RESULT::QUIT == aInspector( GetField( VALUE_FIELD ), (void*) this ) ) return INSPECT_RESULT::QUIT; } - if( stype == SCH_FIELD_LOCATE_FOOTPRINT_T ) + if( scanType == SCH_FIELD_LOCATE_FOOTPRINT_T ) { if( INSPECT_RESULT::QUIT == aInspector( GetField( FOOTPRINT_FIELD ), (void*) this ) ) return INSPECT_RESULT::QUIT; } - if( stype == SCH_FIELD_LOCATE_DATASHEET_T ) + if( scanType == SCH_FIELD_LOCATE_DATASHEET_T ) { if( INSPECT_RESULT::QUIT == aInspector( GetField( DATASHEET_FIELD ), (void*) this ) ) return INSPECT_RESULT::QUIT; } - if( stype == SCH_LOCATE_ANY_T || stype == SCH_PIN_T ) + if( scanType == SCH_LOCATE_ANY_T || scanType == SCH_PIN_T ) { for( const std::unique_ptr& pin : m_pins ) { diff --git a/eeschema/sch_symbol.h b/eeschema/sch_symbol.h index 778fe073d1..d365f31d53 100644 --- a/eeschema/sch_symbol.h +++ b/eeschema/sch_symbol.h @@ -638,7 +638,8 @@ public: std::vector GetConnectionPoints() const override; - INSPECT_RESULT Visit( INSPECTOR inspector, void* testData, const KICAD_T scanTypes[] ) override; + INSPECT_RESULT Visit( INSPECTOR inspector, void* testData, + const std::initializer_list& aScanTypes ) override; /** * Return the symbol library item at \a aPosition that is part of this symbol. diff --git a/eeschema/tools/ee_inspection_tool.cpp b/eeschema/tools/ee_inspection_tool.cpp index 25d4f6e432..97c0d3e86f 100644 --- a/eeschema/tools/ee_inspection_tool.cpp +++ b/eeschema/tools/ee_inspection_tool.cpp @@ -283,7 +283,7 @@ int EE_INSPECTION_TOOL::ShowDatasheet( const TOOL_EVENT& aEvent ) } else if( m_frame->IsType( FRAME_SCH ) ) { - EE_SELECTION& selection = m_selectionTool->RequestSelection( EE_COLLECTOR::SymbolsOnly ); + EE_SELECTION& selection = m_selectionTool->RequestSelection( { SCH_SYMBOL_T } ); if( selection.Empty() ) return 0; diff --git a/eeschema/tools/ee_point_editor.cpp b/eeschema/tools/ee_point_editor.cpp index 1db4ca9d3a..7233cb67b7 100644 --- a/eeschema/tools/ee_point_editor.cpp +++ b/eeschema/tools/ee_point_editor.cpp @@ -406,17 +406,6 @@ void EE_POINT_EDITOR::updateEditedPoint( const TOOL_EVENT& aEvent ) int EE_POINT_EDITOR::Main( const TOOL_EVENT& aEvent ) { - static KICAD_T supportedTypes[] = { - LIB_SHAPE_T, - LIB_TEXTBOX_T, - SCH_SHAPE_T, - SCH_TEXTBOX_T, - SCH_SHEET_T, - SCH_ITEM_LOCATE_GRAPHIC_LINE_T, - SCH_BITMAP_T, - EOT - }; - if( !m_selectionTool ) return 0; @@ -430,8 +419,14 @@ int EE_POINT_EDITOR::Main( const TOOL_EVENT& aEvent ) const EE_SELECTION& selection = m_selectionTool->GetSelection(); - if( selection.Size() != 1 || !selection.Front()->IsType( supportedTypes ) ) + if( selection.Size() != 1 || !selection.Front()->IsType( { LIB_SHAPE_T, SCH_SHAPE_T, + LIB_TEXTBOX_T, SCH_TEXTBOX_T, + SCH_SHEET_T, + SCH_ITEM_LOCATE_GRAPHIC_LINE_T, + SCH_BITMAP_T } ) ) + { return 0; + } // Wait till drawing tool is done if( selection.Front()->IsNew() ) diff --git a/eeschema/tools/ee_selection_tool.cpp b/eeschema/tools/ee_selection_tool.cpp index e49bbd5998..d35be17454 100644 --- a/eeschema/tools/ee_selection_tool.cpp +++ b/eeschema/tools/ee_selection_tool.cpp @@ -144,6 +144,23 @@ EE_SELECTION_TOOL::~EE_SELECTION_TOOL() using E_C = EE_CONDITIONS; +static std::initializer_list connectedTypes = +{ + SCH_SYMBOL_LOCATE_POWER_T, + SCH_PIN_T, + SCH_ITEM_LOCATE_WIRE_T, + SCH_ITEM_LOCATE_BUS_T, + SCH_BUS_WIRE_ENTRY_T, + SCH_BUS_BUS_ENTRY_T, + SCH_LABEL_T, + SCH_HIER_LABEL_T, + SCH_GLOBAL_LABEL_T, + SCH_SHEET_PIN_T, + SCH_DIRECTIVE_LABEL_T, + SCH_JUNCTION_T +}; + + bool EE_SELECTION_TOOL::Init() { m_frame = getEditFrame(); @@ -162,25 +179,12 @@ bool EE_SELECTION_TOOL::Init() m_isSymbolViewer = symbolViewerFrame != nullptr; } - static KICAD_T wireOrBusTypes[] = { SCH_ITEM_LOCATE_WIRE_T, SCH_ITEM_LOCATE_BUS_T, EOT }; - static KICAD_T connectedTypes[] = { SCH_ITEM_LOCATE_WIRE_T, - SCH_ITEM_LOCATE_BUS_T, - SCH_GLOBAL_LABEL_T, - SCH_HIER_LABEL_T, - SCH_LABEL_T, - SCH_DIRECTIVE_LABEL_T, - SCH_SHEET_PIN_T, - SCH_PIN_T, - EOT }; - - static KICAD_T crossProbingTypes[] = { SCH_SYMBOL_T, SCH_PIN_T, SCH_SHEET_T, EOT }; - - auto wireSelection = E_C::Count( 1 ) && E_C::OnlyType( SCH_ITEM_LOCATE_WIRE_T ); - auto busSelection = E_C::Count( 1 ) && E_C::OnlyType( SCH_ITEM_LOCATE_BUS_T ); - auto wireOrBusSelection = E_C::Count( 1 ) && E_C::OnlyTypes( wireOrBusTypes ); + auto wireSelection = E_C::Count( 1 ) && E_C::OnlyTypes( { SCH_ITEM_LOCATE_WIRE_T } ); + auto busSelection = E_C::Count( 1 ) && E_C::OnlyTypes( { SCH_ITEM_LOCATE_BUS_T }); + auto wireOrBusSelection = E_C::Count( 1 ) && E_C::OnlyTypes( { SCH_ITEM_LOCATE_WIRE_T, SCH_ITEM_LOCATE_BUS_T } ); auto connectedSelection = E_C::Count( 1 ) && E_C::OnlyTypes( connectedTypes ); - auto sheetSelection = E_C::Count( 1 ) && E_C::OnlyType( SCH_SHEET_T ); - auto crossProbingSelection = E_C::MoreThan( 0 ) && E_C::HasTypes( crossProbingTypes ); + auto sheetSelection = E_C::Count( 1 ) && E_C::OnlyTypes( { SCH_SHEET_T } ); + auto crossProbingSelection = E_C::MoreThan( 0 ) && E_C::HasTypes( { SCH_SYMBOL_T, SCH_PIN_T, SCH_SHEET_T } ); auto schEditSheetPageNumberCondition = [&] ( const SELECTION& aSel ) @@ -188,7 +192,7 @@ bool EE_SELECTION_TOOL::Init() if( m_isSymbolEditor || m_isSymbolViewer ) return false; - return E_C::LessThan( 2 )( aSel ) && E_C::OnlyType( SCH_SHEET_T )( aSel ); + return E_C::LessThan( 2 )( aSel ) && E_C::OnlyTypes( { SCH_SHEET_T } )( aSel ); }; auto schEditCondition = @@ -304,24 +308,6 @@ void EE_SELECTION_TOOL::Reset( RESET_REASON aReason ) } -const KICAD_T movableSymbolItems[] = -{ - LIB_SHAPE_T, - LIB_TEXT_T, - LIB_TEXTBOX_T, - LIB_PIN_T, - LIB_FIELD_T, - EOT -}; - - -const KICAD_T movableSymbolAliasItems[] = -{ - LIB_FIELD_T, - EOT -}; - - int EE_SELECTION_TOOL::Main( const TOOL_EVENT& aEvent ) { m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::ARROW ); @@ -416,7 +402,7 @@ int EE_SELECTION_TOOL::Main( const TOOL_EVENT& aEvent ) if( m_selection.Empty() ) { ClearSelection(); - SelectPoint( evt->Position(), EE_COLLECTOR::AllItems, nullptr, &selCancelled ); + SelectPoint( evt->Position(), { SCH_LOCATE_ANY_T }, nullptr, &selCancelled ); m_selection.SetIsHover( true ); } // If the cursor has moved off the bounding box of the selection by more than @@ -432,7 +418,7 @@ int EE_SELECTION_TOOL::Main( const TOOL_EVENT& aEvent ) for( EDA_ITEM* item : saved_selection ) RemoveItemFromSel( item, true ); - SelectPoint( evt->Position(), EE_COLLECTOR::AllItems, nullptr, &selCancelled ); + SelectPoint( evt->Position(), { SCH_LOCATE_ANY_T }, nullptr, &selCancelled ); if( m_selection.Empty() ) { @@ -507,9 +493,17 @@ int EE_SELECTION_TOOL::Main( const TOOL_EVENT& aEvent ) if( m_isSymbolEditor ) { if( static_cast( m_frame )->IsSymbolAlias() ) - m_selection = RequestSelection( movableSymbolAliasItems ); + { + m_selection = RequestSelection( { LIB_FIELD_T } ); + } else - m_selection = RequestSelection( movableSymbolItems ); + { + m_selection = RequestSelection( { LIB_SHAPE_T, + LIB_TEXT_T, + LIB_TEXTBOX_T, + LIB_PIN_T, + LIB_FIELD_T } ); + } } else { @@ -747,7 +741,7 @@ int EE_SELECTION_TOOL::disambiguateCursor( const TOOL_EVENT& aEvent ) keyboardState.AltDown() ); m_skip_heuristics = true; - SelectPoint( m_originalCursor, EE_COLLECTOR::AllItems, nullptr, &m_canceledMenu, false, + SelectPoint( m_originalCursor, { SCH_LOCATE_ANY_T }, nullptr, &m_canceledMenu, false, m_additive, m_subtractive, m_exclusive_or ); m_skip_heuristics = false; @@ -783,7 +777,7 @@ EE_SELECTION& EE_SELECTION_TOOL::GetSelection() bool EE_SELECTION_TOOL::CollectHits( EE_COLLECTOR& aCollector, const VECTOR2I& aWhere, - const KICAD_T* aFilterList ) + const std::initializer_list& aFilterList ) { int pixelThreshold = KiROUND( getView()->ToWorld( HITTEST_THRESHOLD_PIXELS ) ); int gridThreshold = KiROUND( getView()->GetGAL()->GetGridSize().EuclideanNorm() / 2 ); @@ -938,7 +932,8 @@ bool EE_SELECTION_TOOL::selectPoint( EE_COLLECTOR& aCollector, const VECTOR2I& a } -bool EE_SELECTION_TOOL::SelectPoint( const VECTOR2I& aWhere, const KICAD_T* aFilterList, +bool EE_SELECTION_TOOL::SelectPoint( const VECTOR2I& aWhere, + const std::initializer_list& aFilterList, EDA_ITEM** aItem, bool* aSelectionCancelledFlag, bool aCheckLocked, bool aAdd, bool aSubtract, bool aExclusiveOr ) @@ -1147,7 +1142,8 @@ void EE_SELECTION_TOOL::GuessSelectionCandidates( EE_COLLECTOR& collector, const } -EE_SELECTION& EE_SELECTION_TOOL::RequestSelection( const KICAD_T aFilterList[] ) +EE_SELECTION& +EE_SELECTION_TOOL::RequestSelection( const std::initializer_list& aFilterList ) { if( m_selection.Empty() ) { @@ -1417,24 +1413,6 @@ bool EE_SELECTION_TOOL::selectMultiple() } -static KICAD_T nodeTypes[] = -{ - SCH_SYMBOL_LOCATE_POWER_T, - SCH_PIN_T, - SCH_ITEM_LOCATE_WIRE_T, - SCH_ITEM_LOCATE_BUS_T, - SCH_BUS_WIRE_ENTRY_T, - SCH_BUS_BUS_ENTRY_T, - SCH_LABEL_T, - SCH_HIER_LABEL_T, - SCH_GLOBAL_LABEL_T, - SCH_SHEET_PIN_T, - SCH_DIRECTIVE_LABEL_T, - SCH_JUNCTION_T, - EOT -}; - - EDA_ITEM* EE_SELECTION_TOOL::GetNode( VECTOR2I aPosition ) { EE_COLLECTOR collector; @@ -1447,7 +1425,7 @@ EDA_ITEM* EE_SELECTION_TOOL::GetNode( VECTOR2I aPosition ) for( int threshold : { 0, thresholdMax/4, thresholdMax/2, thresholdMax } ) { collector.m_Threshold = threshold; - collector.Collect( m_frame->GetScreen(), nodeTypes, aPosition ); + collector.Collect( m_frame->GetScreen(), connectedTypes, aPosition ); if( collector.GetCount() > 0 ) break; @@ -1461,7 +1439,7 @@ int EE_SELECTION_TOOL::SelectNode( const TOOL_EVENT& aEvent ) { VECTOR2I cursorPos = getViewControls()->GetCursorPosition( false ); - SelectPoint( cursorPos, nodeTypes ); + SelectPoint( cursorPos, connectedTypes ); return 0; } @@ -1469,9 +1447,7 @@ int EE_SELECTION_TOOL::SelectNode( const TOOL_EVENT& aEvent ) int EE_SELECTION_TOOL::SelectConnection( const TOOL_EVENT& aEvent ) { - static KICAD_T wiresAndBuses[] = { SCH_ITEM_LOCATE_WIRE_T, SCH_ITEM_LOCATE_BUS_T, EOT }; - - RequestSelection( wiresAndBuses ); + RequestSelection( { SCH_ITEM_LOCATE_WIRE_T, SCH_ITEM_LOCATE_BUS_T } ); if( m_selection.Empty() ) return 0; @@ -1484,8 +1460,11 @@ int EE_SELECTION_TOOL::SelectConnection( const TOOL_EVENT& aEvent ) for( SCH_ITEM* item : conns ) { - if( item->IsType( wiresAndBuses ) && !item->IsSelected() ) + if( item->IsType( { SCH_ITEM_LOCATE_WIRE_T, SCH_ITEM_LOCATE_BUS_T } ) + && !item->IsSelected() ) + { done = true; + } select( item ); } diff --git a/eeschema/tools/ee_selection_tool.h b/eeschema/tools/ee_selection_tool.h index 62e6d08448..fa6329cf1b 100644 --- a/eeschema/tools/ee_selection_tool.h +++ b/eeschema/tools/ee_selection_tool.h @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2019 CERN - * Copyright (C) 2019-2021 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2019-2022 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 @@ -82,13 +82,15 @@ public: * Return either an existing selection (filtered), or the selection at the current * cursor if the existing selection is empty. */ - EE_SELECTION& RequestSelection( const KICAD_T* aFilterList = EE_COLLECTOR::AllItems ); + EE_SELECTION& + RequestSelection( const std::initializer_list& aFilterList = { SCH_LOCATE_ANY_T } ); /** * This overload of SelectPoint will create an EE_COLLECTOR and collect hits at location aWhere * before calling the primary SelectPoint method. * * @param aWhere is the location where the item(s) should be collected + * @param aFilterList is a list of items that are acceptable for collection * @param aItem is set to the newly selected item if only one was selected, otherwise is * unchanged. * @param aSelectionCancelledFlag allows the function to inform its caller that a selection @@ -99,7 +101,8 @@ public: * @param aSubtract indicates if found item(s) should be subtracted from the selection * @param aExclusiveOr indicates if found item(s) should be toggle in the selection */ - bool SelectPoint( const VECTOR2I& aWhere, const KICAD_T* aFilterList = EE_COLLECTOR::AllItems, + bool SelectPoint( const VECTOR2I& aWhere, + const std::initializer_list& aFilterList = { SCH_LOCATE_ANY_T }, EDA_ITEM** aItem = nullptr, bool* aSelectionCancelledFlag = nullptr, bool aCheckLocked = false, bool aAdd = false, bool aSubtract = false, bool aExclusiveOr = false ); @@ -154,7 +157,7 @@ public: * @param aCheckLocked indicates if locked items should be excluded. */ bool CollectHits( EE_COLLECTOR& aCollector, const VECTOR2I& aWhere, - const KICAD_T* aFilterList = EE_COLLECTOR::AllItems ); + const std::initializer_list& aFilterList = { SCH_LOCATE_ANY_T } ); protected: SELECTION& selection() override { return m_selection; } diff --git a/eeschema/tools/sch_drawing_tools.cpp b/eeschema/tools/sch_drawing_tools.cpp index 46cbf67db2..c67b8a9ea5 100644 --- a/eeschema/tools/sch_drawing_tools.cpp +++ b/eeschema/tools/sch_drawing_tools.cpp @@ -1330,7 +1330,7 @@ int SCH_DRAWING_TOOLS::TwoClickPlace( const TOOL_EVENT& aEvent ) SCH_HIERLABEL* label = nullptr; SCH_SHEET* sheet = nullptr; - if( m_selectionTool->SelectPoint( cursorPos, EE_COLLECTOR::SheetsOnly, &i ) ) + if( m_selectionTool->SelectPoint( cursorPos, { SCH_SHEET_T }, &i ) ) sheet = dynamic_cast( i ); m_selectionTool->ClearSelection(); diff --git a/eeschema/tools/sch_edit_tool.cpp b/eeschema/tools/sch_edit_tool.cpp index 94bfcacae5..a7e17f8127 100644 --- a/eeschema/tools/sch_edit_tool.cpp +++ b/eeschema/tools/sch_edit_tool.cpp @@ -176,7 +176,7 @@ bool SCH_EDIT_TOOL::Init() return sheet->HasUndefinedPins(); }; - auto sheetSelection = E_C::Count( 1 ) && E_C::OnlyType( SCH_SHEET_T ); + auto sheetSelection = E_C::Count( 1 ) && E_C::OnlyTypes( { SCH_SHEET_T } ); auto haveHighlight = [&]( const SELECTION& sel ) @@ -325,44 +325,58 @@ bool SCH_EDIT_TOOL::Init() return false; }; - static KICAD_T allTextTypes[] = { SCH_LABEL_T, - SCH_DIRECTIVE_LABEL_T, - SCH_GLOBAL_LABEL_T, - SCH_HIER_LABEL_T, - SCH_TEXT_T, - SCH_TEXTBOX_T, - EOT }; + static std::initializer_list allTextTypes = { SCH_LABEL_LOCATE_ANY_T, + SCH_TEXT_T, + SCH_TEXTBOX_T }; auto toChangeCondition = ( E_C::OnlyTypes( allTextTypes ) ); - static KICAD_T toLabelTypes[] = { SCH_DIRECTIVE_LABEL_T, SCH_GLOBAL_LABEL_T, SCH_HIER_LABEL_T, SCH_TEXT_T, SCH_TEXTBOX_T, EOT }; - auto toLabelCondition = ( E_C::Count( 1 ) && E_C::OnlyTypes( toLabelTypes ) ) + auto toLabelCondition = ( E_C::Count( 1 ) && E_C::OnlyTypes( { SCH_DIRECTIVE_LABEL_T, + SCH_GLOBAL_LABEL_T, + SCH_HIER_LABEL_T, + SCH_TEXT_T, + SCH_TEXTBOX_T } ) ) || ( E_C::MoreThan( 1 ) && E_C::OnlyTypes( allTextTypes ) ); - static KICAD_T toCLabelTypes[] = { SCH_LABEL_T, SCH_HIER_LABEL_T, SCH_GLOBAL_LABEL_T, SCH_TEXT_T, SCH_TEXTBOX_T, EOT }; - auto toCLabelCondition = ( E_C::Count( 1 ) && E_C::OnlyTypes( toCLabelTypes ) ) + auto toCLabelCondition = ( E_C::Count( 1 ) && E_C::OnlyTypes( { SCH_LABEL_T, + SCH_HIER_LABEL_T, + SCH_GLOBAL_LABEL_T, + SCH_TEXT_T, + SCH_TEXTBOX_T } ) ) || ( E_C::MoreThan( 1 ) && E_C::OnlyTypes( allTextTypes ) ); - static KICAD_T toHLabelTypes[] = { SCH_LABEL_T, SCH_DIRECTIVE_LABEL_T, SCH_GLOBAL_LABEL_T, SCH_TEXT_T, SCH_TEXTBOX_T, EOT }; - auto toHLabelCondition = ( E_C::Count( 1 ) && E_C::OnlyTypes( toHLabelTypes ) ) + auto toHLabelCondition = ( E_C::Count( 1 ) && E_C::OnlyTypes( { SCH_LABEL_T, + SCH_DIRECTIVE_LABEL_T, + SCH_GLOBAL_LABEL_T, + SCH_TEXT_T, + SCH_TEXTBOX_T } ) ) || ( E_C::MoreThan( 1 ) && E_C::OnlyTypes( allTextTypes ) ); - static KICAD_T toGLabelTypes[] = { SCH_LABEL_T, SCH_DIRECTIVE_LABEL_T, SCH_HIER_LABEL_T, SCH_TEXT_T, SCH_TEXTBOX_T, EOT }; - auto toGLabelCondition = ( E_C::Count( 1 ) && E_C::OnlyTypes( toGLabelTypes ) ) + auto toGLabelCondition = ( E_C::Count( 1 ) && E_C::OnlyTypes( { SCH_LABEL_T, + SCH_DIRECTIVE_LABEL_T, + SCH_HIER_LABEL_T, + SCH_TEXT_T, + SCH_TEXTBOX_T } ) ) || ( E_C::MoreThan( 1 ) && E_C::OnlyTypes( allTextTypes ) ); - static KICAD_T toTextTypes[] = { SCH_LABEL_T, SCH_DIRECTIVE_LABEL_T, SCH_GLOBAL_LABEL_T, SCH_HIER_LABEL_T, SCH_TEXTBOX_T, EOT }; - auto toTextCondition = ( E_C::Count( 1 ) && E_C::OnlyTypes( toTextTypes ) ) + auto toTextCondition = ( E_C::Count( 1 ) && E_C::OnlyTypes( { SCH_LABEL_T, + SCH_DIRECTIVE_LABEL_T, + SCH_GLOBAL_LABEL_T, + SCH_HIER_LABEL_T, + SCH_TEXTBOX_T } ) ) || ( E_C::MoreThan( 1 ) && E_C::OnlyTypes( allTextTypes ) ); - static KICAD_T toTextBoxTypes[] = { SCH_LABEL_T, SCH_DIRECTIVE_LABEL_T, SCH_GLOBAL_LABEL_T, SCH_HIER_LABEL_T, SCH_TEXT_T, EOT }; - auto toTextBoxCondition = ( E_C::Count( 1 ) && E_C::OnlyTypes( toTextBoxTypes ) ) + auto toTextBoxCondition = ( E_C::Count( 1 ) && E_C::OnlyTypes( { SCH_LABEL_T, + SCH_DIRECTIVE_LABEL_T, + SCH_GLOBAL_LABEL_T, + SCH_HIER_LABEL_T, + SCH_TEXT_T } ) ) || ( E_C::MoreThan( 1 ) && E_C::OnlyTypes( allTextTypes ) ); - static KICAD_T entryTypes[] = { SCH_BUS_WIRE_ENTRY_T, SCH_BUS_BUS_ENTRY_T, EOT }; - auto entryCondition = E_C::MoreThan( 0 ) && E_C::OnlyTypes( entryTypes ); + auto entryCondition = E_C::MoreThan( 0 ) && E_C::OnlyTypes( { SCH_BUS_WIRE_ENTRY_T, + SCH_BUS_BUS_ENTRY_T} ); - auto singleSheetCondition = E_C::Count( 1 ) && E_C::OnlyType( SCH_SHEET_T ); + auto singleSheetCondition = E_C::Count( 1 ) && E_C::OnlyTypes( { SCH_SHEET_T } ); // // Add edit actions to the move tool menu @@ -509,7 +523,7 @@ bool SCH_EDIT_TOOL::Init() } -const KICAD_T rotatableItems[] = { +const std::initializer_list rotatableItems = { SCH_SHAPE_T, SCH_TEXT_T, SCH_TEXTBOX_T, @@ -526,8 +540,7 @@ const KICAD_T rotatableItems[] = { SCH_BUS_WIRE_ENTRY_T, SCH_LINE_T, SCH_JUNCTION_T, - SCH_NO_CONNECT_T, - EOT + SCH_NO_CONNECT_T }; @@ -1067,7 +1080,7 @@ int SCH_EDIT_TOOL::RepeatDrawItem( const TOOL_EVENT& aEvent ) } -static KICAD_T deletableItems[] = +static std::initializer_list deletableItems = { SCH_MARKER_T, SCH_JUNCTION_T, @@ -1086,8 +1099,7 @@ static KICAD_T deletableItems[] = SCH_SHEET_PIN_T, SCH_SYMBOL_T, SCH_FIELD_T, // Will be hidden - SCH_BITMAP_T, - EOT + SCH_BITMAP_T }; @@ -1298,19 +1310,14 @@ void SCH_EDIT_TOOL::editFieldText( SCH_FIELD* aField ) int SCH_EDIT_TOOL::EditField( const TOOL_EVENT& aEvent ) { - static KICAD_T Nothing[] = { EOT }; - static KICAD_T CmpOrReference[] = { SCH_FIELD_LOCATE_REFERENCE_T, SCH_SYMBOL_T, EOT }; - static KICAD_T CmpOrValue[] = { SCH_FIELD_LOCATE_VALUE_T, SCH_SYMBOL_T, EOT }; - static KICAD_T CmpOrFootprint[] = { SCH_FIELD_LOCATE_FOOTPRINT_T, SCH_SYMBOL_T, EOT }; - - KICAD_T* filter = Nothing; + std::initializer_list filter = {}; if( aEvent.IsAction( &EE_ACTIONS::editReference ) ) - filter = CmpOrReference; + filter = { SCH_FIELD_LOCATE_REFERENCE_T, SCH_SYMBOL_T }; else if( aEvent.IsAction( &EE_ACTIONS::editValue ) ) - filter = CmpOrValue; + filter = { SCH_FIELD_LOCATE_VALUE_T, SCH_SYMBOL_T }; else if( aEvent.IsAction( &EE_ACTIONS::editFootprint ) ) - filter = CmpOrFootprint; + filter = { SCH_FIELD_LOCATE_FOOTPRINT_T, SCH_SYMBOL_T }; EE_SELECTION& selection = m_selectionTool->RequestSelection( filter ); @@ -1405,7 +1412,7 @@ int SCH_EDIT_TOOL::AutoplaceFields( const TOOL_EVENT& aEvent ) int SCH_EDIT_TOOL::ChangeSymbols( const TOOL_EVENT& aEvent ) { SCH_SYMBOL* selectedSymbol = nullptr; - EE_SELECTION& selection = m_selectionTool->RequestSelection( EE_COLLECTOR::SymbolsOnly ); + EE_SELECTION& selection = m_selectionTool->RequestSelection( { SCH_SYMBOL_T } ); if( !selection.Empty() ) selectedSymbol = dynamic_cast( selection.Front() ); @@ -1428,7 +1435,7 @@ int SCH_EDIT_TOOL::ChangeSymbols( const TOOL_EVENT& aEvent ) int SCH_EDIT_TOOL::ConvertDeMorgan( const TOOL_EVENT& aEvent ) { - EE_SELECTION& selection = m_selectionTool->RequestSelection( EE_COLLECTOR::SymbolsOnly ); + EE_SELECTION& selection = m_selectionTool->RequestSelection( { SCH_SYMBOL_T } ); if( selection.Empty() ) return 0; @@ -1770,14 +1777,9 @@ int SCH_EDIT_TOOL::Properties( const TOOL_EVENT& aEvent ) int SCH_EDIT_TOOL::ChangeTextType( const TOOL_EVENT& aEvent ) { KICAD_T convertTo = aEvent.Parameter(); - KICAD_T allTextTypes[] = { SCH_LABEL_T, - SCH_GLOBAL_LABEL_T, - SCH_HIER_LABEL_T, - SCH_DIRECTIVE_LABEL_T, - SCH_TEXT_T, - SCH_TEXTBOX_T, - EOT }; - EE_SELECTION selection = m_selectionTool->RequestSelection( allTextTypes ); + EE_SELECTION selection = m_selectionTool->RequestSelection( { SCH_LABEL_LOCATE_ANY_T, + SCH_TEXT_T, + SCH_TEXTBOX_T } ); for( unsigned int i = 0; i < selection.GetSize(); ++i ) { @@ -2056,7 +2058,7 @@ int SCH_EDIT_TOOL::ChangeTextType( const TOOL_EVENT& aEvent ) int SCH_EDIT_TOOL::BreakWire( const TOOL_EVENT& aEvent ) { wxPoint cursorPos = (wxPoint) getViewControls()->GetCursorPosition( !aEvent.DisableGridSnapping() ); - EE_SELECTION& selection = m_selectionTool->RequestSelection( EE_COLLECTOR::WiresOnly ); + EE_SELECTION& selection = m_selectionTool->RequestSelection( { SCH_LINE_T } ); std::vector lines; @@ -2097,7 +2099,7 @@ int SCH_EDIT_TOOL::BreakWire( const TOOL_EVENT& aEvent ) int SCH_EDIT_TOOL::CleanupSheetPins( const TOOL_EVENT& aEvent ) { - EE_SELECTION& selection = m_selectionTool->RequestSelection( EE_COLLECTOR::SheetsOnly ); + EE_SELECTION& selection = m_selectionTool->RequestSelection( { SCH_SHEET_T } ); SCH_SHEET* sheet = (SCH_SHEET*) selection.Front(); if( !sheet || !sheet->HasUndefinedPins() ) @@ -2122,7 +2124,7 @@ int SCH_EDIT_TOOL::CleanupSheetPins( const TOOL_EVENT& aEvent ) int SCH_EDIT_TOOL::EditPageNumber( const TOOL_EVENT& aEvent ) { - EE_SELECTION& selection = m_selectionTool->RequestSelection( EE_COLLECTOR::SheetsOnly ); + EE_SELECTION& selection = m_selectionTool->RequestSelection( { SCH_SHEET_T } ); if( selection.GetSize() > 1 ) return 0; diff --git a/eeschema/tools/sch_editor_control.cpp b/eeschema/tools/sch_editor_control.cpp index 465367d1fc..ccdd07fa8f 100644 --- a/eeschema/tools/sch_editor_control.cpp +++ b/eeschema/tools/sch_editor_control.cpp @@ -729,13 +729,8 @@ void SCH_EDITOR_CONTROL::doCrossProbeSchToPcb( const TOOL_EVENT& aEvent, bool aF #ifdef KICAD_SPICE -static KICAD_T wires[] = { SCH_ITEM_LOCATE_WIRE_T, EOT }; -static KICAD_T wiresAndPins[] = { SCH_ITEM_LOCATE_WIRE_T, SCH_PIN_T, SCH_SHEET_PIN_T, EOT }; -static KICAD_T fieldsAndSymbols[] = { SCH_SYMBOL_T, SCH_FIELD_T, EOT }; - #define HITTEST_THRESHOLD_PIXELS 5 - int SCH_EDITOR_CONTROL::SimProbe( const TOOL_EVENT& aEvent ) { LOCALE_IO toggle; @@ -835,7 +830,7 @@ int SCH_EDITOR_CONTROL::SimProbe( const TOOL_EVENT& aEvent ) simFrame->AddCurrentPlot( name ); } } - else if( item->IsType( wires ) ) + else if( item->IsType( { SCH_ITEM_LOCATE_WIRE_T } ) ) { if( SCH_CONNECTION* conn = static_cast( item )->Connection() ) { @@ -854,7 +849,9 @@ int SCH_EDITOR_CONTROL::SimProbe( const TOOL_EVENT& aEvent ) { EE_COLLECTOR collector; collector.m_Threshold = KiROUND( getView()->ToWorld( HITTEST_THRESHOLD_PIXELS ) ); - collector.Collect( m_frame->GetScreen(), wiresAndPins, (wxPoint) aPos ); + collector.Collect( m_frame->GetScreen(), { SCH_ITEM_LOCATE_WIRE_T, + SCH_PIN_T, + SCH_SHEET_PIN_T }, aPos ); EE_SELECTION_TOOL* selectionTool = m_toolMgr->GetTool(); selectionTool->GuessSelectionCandidates( collector, aPos ); @@ -935,7 +932,7 @@ int SCH_EDITOR_CONTROL::SimTune( const TOOL_EVENT& aEvent ) { EE_SELECTION_TOOL* selTool = m_toolMgr->GetTool(); EDA_ITEM* item = nullptr; - selTool->SelectPoint( aPosition, fieldsAndSymbols, &item ); + selTool->SelectPoint( aPosition, { SCH_SYMBOL_T, SCH_FIELD_T }, &item ); if( !item ) return false; @@ -970,7 +967,7 @@ int SCH_EDITOR_CONTROL::SimTune( const TOOL_EVENT& aEvent ) { EE_COLLECTOR collector; collector.m_Threshold = KiROUND( getView()->ToWorld( HITTEST_THRESHOLD_PIXELS ) ); - collector.Collect( m_frame->GetScreen(), fieldsAndSymbols, (wxPoint) aPos ); + collector.Collect( m_frame->GetScreen(), { SCH_SYMBOL_T, SCH_FIELD_T }, aPos ); EE_SELECTION_TOOL* selectionTool = m_toolMgr->GetTool(); selectionTool->GuessSelectionCandidates( collector, aPos ); @@ -2000,7 +1997,7 @@ int SCH_EDITOR_CONTROL::Paste( const TOOL_EVENT& aEvent ) int SCH_EDITOR_CONTROL::EditWithSymbolEditor( const TOOL_EVENT& aEvent ) { EE_SELECTION_TOOL* selTool = m_toolMgr->GetTool(); - EE_SELECTION& selection = selTool->RequestSelection( EE_COLLECTOR::SymbolsOnly ); + EE_SELECTION& selection = selTool->RequestSelection( { SCH_SYMBOL_T } ); SCH_SYMBOL* symbol = nullptr; SYMBOL_EDIT_FRAME* symbolEditor; diff --git a/eeschema/tools/sch_line_wire_bus_tool.cpp b/eeschema/tools/sch_line_wire_bus_tool.cpp index 8edb8963c9..b68d7cec62 100644 --- a/eeschema/tools/sch_line_wire_bus_tool.cpp +++ b/eeschema/tools/sch_line_wire_bus_tool.cpp @@ -94,8 +94,7 @@ private: { SCH_EDIT_FRAME* frame = (SCH_EDIT_FRAME*) getToolManager()->GetToolHolder(); EE_SELECTION_TOOL* selTool = getToolManager()->GetTool(); - KICAD_T busType[] = { SCH_ITEM_LOCATE_BUS_T, EOT }; - EE_SELECTION& selection = selTool->RequestSelection( busType ); + EE_SELECTION& selection = selTool->RequestSelection( { SCH_ITEM_LOCATE_BUS_T } ); SCH_LINE* bus = (SCH_LINE*) selection.Front(); Clear(); @@ -106,7 +105,7 @@ private: frame->RecalculateConnections( NO_CLEANUP ); // Pick up the pointer again because it may have been changed by SchematicCleanUp - selection = selTool->RequestSelection( busType ); + selection = selTool->RequestSelection( { SCH_ITEM_LOCATE_BUS_T } ); bus = (SCH_LINE*) selection.Front(); } @@ -200,7 +199,7 @@ bool SCH_LINE_WIRE_BUS_TOOL::Init() }; auto busSelection = EE_CONDITIONS::MoreThan( 0 ) - && EE_CONDITIONS::OnlyType( SCH_ITEM_LOCATE_BUS_T ); + && EE_CONDITIONS::OnlyTypes( { SCH_ITEM_LOCATE_BUS_T } ); auto haveHighlight = [&]( const SELECTION& sel ) @@ -264,22 +263,22 @@ bool SCH_LINE_WIRE_BUS_TOOL::Init() bool SCH_LINE_WIRE_BUS_TOOL::IsDrawingLine( const SELECTION& aSelection ) { - static KICAD_T graphicLineType[] = { SCH_ITEM_LOCATE_GRAPHIC_LINE_T, EOT }; - return IsDrawingLineWireOrBus( aSelection ) && aSelection.Front()->IsType( graphicLineType ); + return IsDrawingLineWireOrBus( aSelection ) + && aSelection.Front()->IsType( { SCH_ITEM_LOCATE_GRAPHIC_LINE_T } ); } bool SCH_LINE_WIRE_BUS_TOOL::IsDrawingWire( const SELECTION& aSelection ) { - static KICAD_T wireType[] = { SCH_ITEM_LOCATE_WIRE_T, EOT }; - return IsDrawingLineWireOrBus( aSelection ) && aSelection.Front()->IsType( wireType ); + return IsDrawingLineWireOrBus( aSelection ) + && aSelection.Front()->IsType( { SCH_ITEM_LOCATE_WIRE_T } ); } bool SCH_LINE_WIRE_BUS_TOOL::IsDrawingBus( const SELECTION& aSelection ) { - static KICAD_T busType[] = { SCH_ITEM_LOCATE_BUS_T, EOT }; - return IsDrawingLineWireOrBus( aSelection ) && aSelection.Front()->IsType( busType ); + return IsDrawingLineWireOrBus( aSelection ) + && aSelection.Front()->IsType( { SCH_ITEM_LOCATE_BUS_T } ); } diff --git a/eeschema/tools/sch_move_tool.cpp b/eeschema/tools/sch_move_tool.cpp index 41e3e0a55d..8ea8cf6716 100644 --- a/eeschema/tools/sch_move_tool.cpp +++ b/eeschema/tools/sch_move_tool.cpp @@ -63,7 +63,7 @@ bool SCH_MOVE_TOOL::Init() auto moveCondition = []( const SELECTION& aSel ) { - if( aSel.Empty() || SELECTION_CONDITIONS::OnlyType( SCH_MARKER_T )( aSel ) ) + if( aSel.Empty() || SELECTION_CONDITIONS::OnlyTypes( { SCH_MARKER_T } )( aSel ) ) return false; if( SCH_LINE_WIRE_BUS_TOOL::IsDrawingLineWireOrBus( aSel ) ) diff --git a/eeschema/tools/sch_navigate_tool.cpp b/eeschema/tools/sch_navigate_tool.cpp index 8d4441a49d..1f9afdebbf 100644 --- a/eeschema/tools/sch_navigate_tool.cpp +++ b/eeschema/tools/sch_navigate_tool.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) 1992-2020 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 1992-2022 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 @@ -188,7 +188,7 @@ int SCH_NAVIGATE_TOOL::ChangeSheet( const TOOL_EVENT& aEvent ) int SCH_NAVIGATE_TOOL::EnterSheet( const TOOL_EVENT& aEvent ) { EE_SELECTION_TOOL* selTool = m_toolMgr->GetTool(); - const EE_SELECTION& selection = selTool->RequestSelection( EE_COLLECTOR::SheetsOnly ); + const EE_SELECTION& selection = selTool->RequestSelection( { SCH_SHEET_T } ); if( selection.GetSize() == 1 ) { diff --git a/eeschema/tools/symbol_editor_edit_tool.cpp b/eeschema/tools/symbol_editor_edit_tool.cpp index e55a61879c..ff0f94a021 100644 --- a/eeschema/tools/symbol_editor_edit_tool.cpp +++ b/eeschema/tools/symbol_editor_edit_tool.cpp @@ -239,14 +239,13 @@ int SYMBOL_EDITOR_EDIT_TOOL::Mirror( const TOOL_EVENT& aEvent ) } -static KICAD_T nonFields[] = +static std::initializer_list nonFields = { - LIB_SYMBOL_T, - LIB_SHAPE_T, - LIB_TEXT_T, - LIB_TEXTBOX_T, - LIB_PIN_T, - EOT + LIB_SYMBOL_T, + LIB_SHAPE_T, + LIB_TEXT_T, + LIB_TEXTBOX_T, + LIB_PIN_T }; diff --git a/eeschema/tools/symbol_editor_move_tool.cpp b/eeschema/tools/symbol_editor_move_tool.cpp index 33d174d1b0..1ce938ffa0 100644 --- a/eeschema/tools/symbol_editor_move_tool.cpp +++ b/eeschema/tools/symbol_editor_move_tool.cpp @@ -89,8 +89,6 @@ void SYMBOL_EDITOR_MOVE_TOOL::Reset( RESET_REASON aReason ) int SYMBOL_EDITOR_MOVE_TOOL::Main( const TOOL_EVENT& aEvent ) { - static KICAD_T fieldsOnly[] = { LIB_FIELD_T, EOT }; - KIGFX::VIEW_CONTROLS* controls = getViewControls(); m_anchorPos = { 0, 0 }; @@ -98,8 +96,8 @@ int SYMBOL_EDITOR_MOVE_TOOL::Main( const TOOL_EVENT& aEvent ) // Be sure that there is at least one item that we can move. If there's no selection try // looking for the stuff under mouse cursor (i.e. Kicad old-style hover selection). EE_SELECTION& selection = m_frame->IsSymbolAlias() - ? m_selectionTool->RequestSelection( fieldsOnly ) - : m_selectionTool->RequestSelection(); + ? m_selectionTool->RequestSelection( { LIB_FIELD_T } ) + : m_selectionTool->RequestSelection(); bool unselect = selection.IsHover(); if( !m_frame->IsSymbolEditable() || selection.Empty() ) diff --git a/eeschema/tools/symbol_editor_pin_tool.cpp b/eeschema/tools/symbol_editor_pin_tool.cpp index 705f810215..4956b05dfd 100644 --- a/eeschema/tools/symbol_editor_pin_tool.cpp +++ b/eeschema/tools/symbol_editor_pin_tool.cpp @@ -103,7 +103,7 @@ bool SYMBOL_EDITOR_PIN_TOOL::Init() return editor->IsSymbolEditable() && !editor->IsSymbolAlias(); }; - auto singlePinCondition = EE_CONDITIONS::Count( 1 ) && EE_CONDITIONS::OnlyType( LIB_PIN_T ); + auto singlePinCondition = EE_CONDITIONS::Count( 1 ) && EE_CONDITIONS::OnlyTypes( { LIB_PIN_T } ); CONDITIONAL_MENU& selToolMenu = m_selectionTool->GetToolMenu().GetMenu(); diff --git a/gerbview/gbr_layout.cpp b/gerbview/gbr_layout.cpp index 9606746d9c..51ff0adb0d 100644 --- a/gerbview/gbr_layout.cpp +++ b/gerbview/gbr_layout.cpp @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2012-2018 Jean-Pierre Charras jp.charras at wanadoo.fr - * Copyright (C) 1992-2021 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 1992-2022 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 @@ -75,24 +75,17 @@ EDA_RECT GBR_LAYOUT::ComputeBoundingBox() const } -INSPECT_RESULT GBR_LAYOUT::Visit( INSPECTOR inspector, void* testData, const KICAD_T scanTypes[] ) +INSPECT_RESULT GBR_LAYOUT::Visit( INSPECTOR inspector, void* testData, + const std::initializer_list& aScanTypes ) { - KICAD_T stype; - INSPECT_RESULT result = INSPECT_RESULT::CONTINUE; - const KICAD_T* p = scanTypes; - bool done = false; - #if 0 && defined(DEBUG) std::cout << GetClass().mb_str() << ' '; #endif - while( !done ) + for( KICAD_T scanType : aScanTypes ) { - stype = *p; - - switch( stype ) + if( scanType == GERBER_LAYOUT_T ) { - case GERBER_LAYOUT_T: for( unsigned layer = 0; layer < GetImagesList()->ImagesMaxCount(); ++layer ) { GERBER_FILE_IMAGE* gerber = GetImagesList()->GetGbrImage( layer ); @@ -100,23 +93,11 @@ INSPECT_RESULT GBR_LAYOUT::Visit( INSPECTOR inspector, void* testData, const KIC if( gerber == nullptr ) // Graphic layer not yet used continue; - result = gerber->Visit( inspector, testData, p ); - - if( result == INSPECT_RESULT::QUIT ) - break; + if( gerber->Visit( inspector, testData, { scanType } ) == INSPECT_RESULT::QUIT ) + return INSPECT_RESULT::QUIT; } - - ++p; - break; - - default: // catch EOT or ANY OTHER type here and return. - done = true; - break; } - - if( result == INSPECT_RESULT::QUIT ) - break; } - return result; + return INSPECT_RESULT::CONTINUE; } diff --git a/gerbview/gbr_layout.h b/gerbview/gbr_layout.h index 9fd994b119..21cd5280ff 100644 --- a/gerbview/gbr_layout.h +++ b/gerbview/gbr_layout.h @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2012-2014 Jean-Pierre Charras jp.charras at wanadoo.fr - * Copyright (C) 1992-2021 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 1992-2022 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 @@ -78,7 +78,8 @@ public: void SetBoundingBox( const EDA_RECT& aBox ) { m_BoundingBox = aBox; } ///< @copydoc EDA_ITEM::Visit() - INSPECT_RESULT Visit( INSPECTOR inspector, void* testData, const KICAD_T scanTypes[] ) override; + INSPECT_RESULT Visit( INSPECTOR inspector, void* testData, + const std::initializer_list& aScanTypes ) override; #if defined(DEBUG) void Show( int nestLevel, std::ostream& os ) const override { ShowDummy( os ); } diff --git a/gerbview/gerber_collectors.cpp b/gerbview/gerber_collectors.cpp index 7af974be3a..5ca08cdad9 100644 --- a/gerbview/gerber_collectors.cpp +++ b/gerbview/gerber_collectors.cpp @@ -1,7 +1,7 @@ /* * This program source code file is part of KiCad, a free EDA CAD application. * - * Copyright (C) 2017-2021 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2017-2022 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 as published by the @@ -19,13 +19,6 @@ #include "gerber_collectors.h" -const KICAD_T GERBER_COLLECTOR::AllItems[] = { - GERBER_LAYOUT_T, - GERBER_IMAGE_T, - GERBER_DRAW_ITEM_T, - EOT -}; - /** * The examining function within the INSPECTOR which is passed to the iterate function. @@ -43,14 +36,11 @@ INSPECT_RESULT GERBER_COLLECTOR::Inspect( EDA_ITEM* testItem, void* testData ) } -void GERBER_COLLECTOR::Collect( EDA_ITEM* aItem, const KICAD_T aScanList[], - const VECTOR2I& aRefPos /*, const COLLECTORS_GUIDE& aGuide*/ ) +void GERBER_COLLECTOR::Collect( EDA_ITEM* aItem, const std::initializer_list& aScanList, + const VECTOR2I& aRefPos ) { Empty(); // empty the collection, primary criteria list - // remember guide, pass it to Inspect() - //SetGuide( &aGuide ); - SetScanTypes( aScanList ); // remember where the snapshot was taken from and pass refPos to @@ -58,7 +48,4 @@ void GERBER_COLLECTOR::Collect( EDA_ITEM* aItem, const KICAD_T aScanList[], SetRefPos( aRefPos ); aItem->Visit( m_inspector, nullptr, m_scanTypes ); - - // record the length of the primary list before concatenating on to it. - m_PrimaryLength = m_list.size(); } diff --git a/gerbview/gerber_collectors.h b/gerbview/gerber_collectors.h index 2d5ec93fc5..9a77961497 100644 --- a/gerbview/gerber_collectors.h +++ b/gerbview/gerber_collectors.h @@ -1,7 +1,7 @@ /* * This program source code file is part of KiCad, a free EDA CAD application. * - * Copyright (C) 2017-2021 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2017-2022 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 as published by the @@ -28,20 +28,9 @@ class GERBER_COLLECTOR : public COLLECTOR { public: - /** - * A scan list for all selectable gerber items - */ - static const KICAD_T AllItems[]; - GERBER_COLLECTOR() { - m_PrimaryLength = 0; - SetScanTypes( AllItems ); - } - - void Empty2nd() - { - m_List2nd.clear(); + SetScanTypes( { GERBER_LAYOUT_T, GERBER_IMAGE_T, GERBER_DRAW_ITEM_T } ); } /** @@ -58,11 +47,6 @@ public: return nullptr; } - /** - * @return The number if items which met the primary search criteria. - */ - int GetPrimaryCount() { return m_PrimaryLength; } - /** * The examining function within the INSPECTOR which is passed to the Iterate function. * @@ -76,29 +60,12 @@ public: * Scan an EDA_ITEM using this class's Inspector method, which does the collection. * * @param aItem An EDA_ITEM to scan - * @param aScanList A list of KICAD_Ts with a terminating EOT, that specs - * what is to be collected and the priority order of the resultant - * collection in "m_list". + * @param aScanList A list of KICAD_Ts that specs what is to be collected and the priority + * order of the resultant collection in "m_list". * @param aRefPos A VECTOR2I to use in hit-testing. - * @param aGuide The COLLECTORS_GUIDE to use in collecting items. */ - void Collect( EDA_ITEM* aItem, const KICAD_T aScanList[], - const VECTOR2I& aRefPos /*, const COLLECTORS_GUIDE& aGuide */ ); - -protected: - /** - * A place to hold collected objects which don't match precisely the search - * criteria, but would be acceptable if nothing else is found. - * "2nd" choice, which will be appended to the end of COLLECTOR's prime - * "list" at the end of the search. - */ - std::vector m_List2nd; - - /** - * The number of items that were originally in the primary list before the - * m_List2nd was concatenated onto the end of it. - */ - int m_PrimaryLength; + void Collect( EDA_ITEM* aItem, const std::initializer_list& aScanList, + const VECTOR2I& aRefPos ); }; #endif diff --git a/gerbview/gerber_draw_item.cpp b/gerbview/gerber_draw_item.cpp index ddc0fe35f8..8d3130417e 100644 --- a/gerbview/gerber_draw_item.cpp +++ b/gerbview/gerber_draw_item.cpp @@ -402,18 +402,6 @@ const EDA_RECT GERBER_DRAW_ITEM::GetBoundingBox() const } -void GERBER_DRAW_ITEM::MoveAB( const VECTOR2I& aMoveVector ) -{ - VECTOR2I xymove = GetXYPosition( aMoveVector ); - - m_Start += xymove; - m_End += xymove; - m_ArcCentre += xymove; - - m_Polygon.Move( xymove ); -} - - void GERBER_DRAW_ITEM::MoveXY( const VECTOR2I& aMoveVector ) { m_Start += aMoveVector; @@ -997,15 +985,15 @@ double GERBER_DRAW_ITEM::ViewGetLOD( int aLayer, KIGFX::VIEW* aView ) const INSPECT_RESULT GERBER_DRAW_ITEM::Visit( INSPECTOR inspector, void* testData, - const KICAD_T scanTypes[] ) + const std::initializer_list& aScanTypes ) { - KICAD_T stype = *scanTypes; - - // If caller wants to inspect my type - if( stype == Type() ) + for( KICAD_T scanType : aScanTypes ) { - if( INSPECT_RESULT::QUIT == inspector( this, testData ) ) - return INSPECT_RESULT::QUIT; + if( scanType == Type() ) + { + if( INSPECT_RESULT::QUIT == inspector( this, testData ) ) + return INSPECT_RESULT::QUIT; + } } return INSPECT_RESULT::CONTINUE; @@ -1014,9 +1002,7 @@ INSPECT_RESULT GERBER_DRAW_ITEM::Visit( INSPECTOR inspector, void* testData, wxString GERBER_DRAW_ITEM::GetSelectMenuText( EDA_UNITS aUnits ) const { - wxString layerName; - - layerName = GERBER_FILE_IMAGE_LIST::GetImagesList().GetDisplayName( GetLayer(), true ); + wxString layerName = GERBER_FILE_IMAGE_LIST::GetImagesList().GetDisplayName( GetLayer(), true ); return wxString::Format( _( "%s (D%d) on layer %d: %s" ), ShowGBRShape(), diff --git a/gerbview/gerber_draw_item.h b/gerbview/gerber_draw_item.h index 5eaead8e75..5bf7a352b5 100644 --- a/gerbview/gerber_draw_item.h +++ b/gerbview/gerber_draw_item.h @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 1992-2016 - * Copyright (C) 1992-2021 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 1992-2022 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 @@ -75,10 +75,7 @@ public: */ int GetLayer() const; - bool GetLayerPolarity() const - { - return m_LayerNegative; - } + bool GetLayerPolarity() const { return m_LayerNegative; } /** * Return the best size and orientation to display the D_Code on screen. @@ -106,17 +103,7 @@ public: */ void SetLayerParameters(); - void SetLayerPolarity( bool aNegative) - { - m_LayerNegative = aNegative; - } - - /** - * Move this object. - * - * @param aMoveVector the move vector for this object. - */ - void MoveAB( const VECTOR2I& aMoveVector ); + void SetLayerPolarity( bool aNegative) { m_LayerNegative = aNegative; } /** * Move this object. @@ -231,7 +218,8 @@ public: double ViewGetLOD( int aLayer, KIGFX::VIEW* aView ) const override; ///< @copydoc EDA_ITEM::Visit() - INSPECT_RESULT Visit( INSPECTOR inspector, void* testData, const KICAD_T scanTypes[] ) override; + INSPECT_RESULT Visit( INSPECTOR inspector, void* testData, + const std::initializer_list& aScanTypes ) override; ///< @copydoc EDA_ITEM::GetSelectMenuText() virtual wxString GetSelectMenuText( EDA_UNITS aUnits ) const override; diff --git a/gerbview/gerber_file_image.cpp b/gerbview/gerber_file_image.cpp index 57758f1615..d700a0ee4a 100644 --- a/gerbview/gerber_file_image.cpp +++ b/gerbview/gerber_file_image.cpp @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 1992-2019 Jean-Pierre Charras jp.charras at wanadoo.fr - * Copyright (C) 1992-2021 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 1992-2022 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 @@ -84,7 +84,6 @@ GERBER_FILE_IMAGE::GERBER_FILE_IMAGE( int aLayer ) : EDA_ITEM( nullptr, GERBER_IMAGE_T ) { m_GraphicLayer = aLayer; // Graphic layer Number - m_IsVisible = true; // must be drawn m_PositiveDrawColor = WHITE; // The color used to draw positive items for this image m_Selected_Tool = 0; @@ -99,7 +98,6 @@ GERBER_FILE_IMAGE::GERBER_FILE_IMAGE( int aLayer ) : GERBER_FILE_IMAGE::~GERBER_FILE_IMAGE() { - for( GERBER_DRAW_ITEM* item : GetItems() ) delete item; @@ -269,21 +267,6 @@ int GERBER_FILE_IMAGE::GetDcodesCount() } -void GERBER_FILE_IMAGE::InitToolTable() -{ - for( int count = 0; count < TOOLS_MAX_COUNT; count++ ) - { - if( m_Aperture_List[count] == nullptr ) - continue; - - m_Aperture_List[count]->m_Num_Dcode = count + FIRST_DCODE; - m_Aperture_List[count]->Clear_D_CODE_Data(); - } - - m_aperture_macros.clear(); -} - - /** * Function StepAndRepeatItem * Gerber format has a command Step an Repeat @@ -405,38 +388,17 @@ void GERBER_FILE_IMAGE::RemoveAttribute( X2_ATTRIBUTE& aAttribute ) } -INSPECT_RESULT GERBER_FILE_IMAGE::Visit( INSPECTOR inspector, void* testData, const KICAD_T scanTypes[] ) +INSPECT_RESULT GERBER_FILE_IMAGE::Visit( INSPECTOR inspector, void* testData, + const std::initializer_list& aScanTypes ) { - KICAD_T stype; - INSPECT_RESULT result = INSPECT_RESULT::CONTINUE; - const KICAD_T* p = scanTypes; - bool done = false; - - while( !done ) + for( KICAD_T scanType : aScanTypes ) { - stype = *p; - - switch( stype ) + if( scanType == GERBER_DRAW_ITEM_T ) { - case GERBER_IMAGE_T: - case GERBER_LAYOUT_T: - ++p; - break; - - case GERBER_DRAW_ITEM_T: - result = IterateForward( GetItems(), inspector, testData, p ); - ++p; - break; - - case EOT: - default: // catch EOT or ANY OTHER type here and return. - done = true; - break; + if( IterateForward( GetItems(), inspector, testData, { scanType } ) == INSPECT_RESULT::QUIT ) + return INSPECT_RESULT::QUIT; } - - if( result == INSPECT_RESULT::QUIT ) - break; } - return result; + return INSPECT_RESULT::CONTINUE; } diff --git a/gerbview/gerber_file_image.h b/gerbview/gerber_file_image.h index ad3cda226f..db07706708 100644 --- a/gerbview/gerber_file_image.h +++ b/gerbview/gerber_file_image.h @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2010-2019 Jean-Pierre Charras jp.charras at wanadoo.fr - * Copyright (C) 1992-2021 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 1992-2022 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 @@ -212,8 +212,6 @@ public: m_messagesList.Add( aMessage ); } - void InitToolTable(); - /** * Return the current coordinate type pointed to by XnnYnn Text (XnnnnYmmmm). * @@ -299,7 +297,8 @@ public: void RemoveAttribute( X2_ATTRIBUTE& aAttribute ); ///< @copydoc EDA_ITEM::Visit() - INSPECT_RESULT Visit( INSPECTOR inspector, void* testData, const KICAD_T scanTypes[] ) override; + INSPECT_RESULT Visit( INSPECTOR inspector, void* testData, + const std::initializer_list& aScanTypes ) override; #if defined(DEBUG) @@ -356,78 +355,58 @@ private: * @param gerber_file Which file to read from for continuation. * @return true if a macro was read in successfully, else false. */ - bool ReadApertureMacro( char *aBuff, unsigned int aBuffSize, - char* & text, FILE * gerber_file ); + bool ReadApertureMacro( char *aBuff, unsigned int aBuffSize, char*& text, FILE* gerber_file ); // functions to execute G commands or D basic commands: bool Execute_G_Command( char*& text, int G_command ); bool Execute_DCODE_Command( char*& text, int D_command ); public: - bool m_InUse; // true if this image is currently in use - // (a file is loaded in it) + bool m_InUse; ///< true if this image is currently in use (a file + ///< is loaded in it) + ///< false if it must be not drawn + COLOR4D m_PositiveDrawColor; ///< The color used to draw positive items + wxString m_FileName; ///< Full File Name for this layer + wxString m_ImageName; ///< Image name, from IN * command - ///< True if the draw layer is visible and must be drawn. - bool m_IsVisible; - // false if it must be not drawn - COLOR4D m_PositiveDrawColor; // The color used to draw positive items - wxString m_FileName; // Full File Name for this layer - wxString m_ImageName; // Image name, from IN * command + bool m_IsX2_file; ///< True if a X2 gerber attribute was found in file + X2_ATTRIBUTE_FILEFUNCTION* m_FileFunction; ///< file function parameters, found in a %TF + ///< command or a G04 + wxString m_MD5_value; ///< MD5 value found in a %TF.MD5 command + wxString m_PartString; ///< string found in a %TF.Part command + int m_GraphicLayer; ///< Graphic layer Number + bool m_ImageNegative; ///< true = Negative image - ///< True if a X2 gerber attribute was found in file. - bool m_IsX2_file; - X2_ATTRIBUTE_FILEFUNCTION* m_FileFunction; // file function parameters, found in a - // %TF command or a G04 - wxString m_MD5_value; // MD5 value found in a %TF.MD5 command - wxString m_PartString; // string found in a %TF.Part command - int m_GraphicLayer; // Graphic layer Number - bool m_ImageNegative; // true = Negative image + bool m_ImageJustifyXCenter; ///< Image Justify Center on X axis (default = false) + bool m_ImageJustifyYCenter; ///< Image Justify Center on Y axis (default = false) + VECTOR2I m_ImageJustifyOffset; ///< Image Justify Offset on XY axis (default = 0,0) - ///< Image Justify Center on X axis (default = false). - bool m_ImageJustifyXCenter; + bool m_GerbMetric; ///< false = Inches, true = metric + bool m_Relative; ///< false = absolute Coord, true = relative Coord. + bool m_NoTrailingZeros; ///< true: remove tailing zeros. + VECTOR2I m_ImageOffset; ///< Coord Offset, from IO command + wxSize m_FmtScale; ///< Fmt 2.3: m_FmtScale = 3, fmt 3.4: m_FmtScale = 4 + wxSize m_FmtLen; ///< Nb chars per coord. ex fmt 2.3, m_FmtLen = 5 - ///< Image Justify Center on Y axis (default = false). - bool m_ImageJustifyYCenter; + int m_ImageRotation; ///< Image rotation (0, 90, 180, 270 only) in degrees + double m_LocalRotation; ///< Local rotation added to m_ImageRotation + ///< @note This value is stored in 0.1 degrees - ///< Image Justify Offset on XY axis (default = 0,0). - VECTOR2I m_ImageJustifyOffset; - bool m_GerbMetric; // false = Inches, true = metric - - ///< false = absolute Coord, true = relative Coord. - bool m_Relative; - bool m_NoTrailingZeros; // true: remove tailing zeros. - VECTOR2I m_ImageOffset; // Coord Offset, from IO command - - ///< Fmt 2.3: m_FmtScale = 3, fmt 3.4: m_FmtScale = 4. - wxSize m_FmtScale; - - ///< Nb chars per coord. ex fmt 2.3, m_FmtLen = 5. - wxSize m_FmtLen; - - ///< Image rotation (0, 90, 180, 270 only) in degrees. - int m_ImageRotation; - - ///< Local rotation in degrees added to m_ImageRotation. - ///< @note This value is stored in 0.1 degrees. - double m_LocalRotation; - VECTOR2I m_Offset; // Coord Offset, from OF command - VECTOR2I m_Scale; // scale (X and Y) of layer. - bool m_SwapAxis; // false (default) if A = X and B = Y - // true if A = Y, B = X - bool m_MirrorA; // true: mirror / axis A (X) - bool m_MirrorB; // true: mirror / axis B (Y) - int m_Iterpolation; // Linear, 90 arc, Circ. - int m_Current_Tool; // Current Tool (Dcode) number selected - - ///< Current or last pen state (0..9, set by Dn option with n < 10. - int m_Last_Pen_Command; - int m_CommandState; // state of gerber analysis command. - - ///< Line number of the gerber file while reading. - int m_LineNum; - VECTOR2I m_CurrentPos; // current specified coord for plot - VECTOR2I m_PreviousPos; // old current specified coord for plot - VECTOR2I m_IJPos; // IJ coord (for arcs & circles ) + VECTOR2I m_Offset; ///< Coord Offset, from OF command + VECTOR2I m_Scale; ///< scale (X and Y) of layer. + bool m_SwapAxis; ///< false if A = X and B = Y (default); true if + ///< A = Y, B = X + bool m_MirrorA; ///< true: mirror / axis A (X) + bool m_MirrorB; ///< true: mirror / axis B (Y) + int m_Iterpolation; ///< Linear, 90 arc, Circ. + int m_Current_Tool; ///< Current Tool (Dcode) number selected + int m_Last_Pen_Command; ///< Current or last pen state (0..9, set by Dn + ///< option with n < 10 + int m_CommandState; ///< state of gerber analysis command + int m_LineNum; ///< Line number of the gerber file while reading. + VECTOR2I m_CurrentPos; ///< current specified coord for plot + VECTOR2I m_PreviousPos; ///< old current specified coord for plot + VECTOR2I m_IJPos; ///< IJ coord (for arcs & circles ) ///< True if a IJ coord was read (for arcs & circles ). bool m_LastCoordIsIJPos; diff --git a/gerbview/tools/gerbview_selection_tool.cpp b/gerbview/tools/gerbview_selection_tool.cpp index 829dec2034..a3d8fcc748 100644 --- a/gerbview/tools/gerbview_selection_tool.cpp +++ b/gerbview/tools/gerbview_selection_tool.cpp @@ -223,7 +223,7 @@ bool GERBVIEW_SELECTION_TOOL::selectPoint( const VECTOR2I& aWhere ) GERBER_COLLECTOR collector; EDA_ITEM* model = getModel(); - collector.Collect( model, GERBER_COLLECTOR::AllItems, wxPoint( aWhere.x, aWhere.y ) ); + collector.Collect( model, { GERBER_LAYOUT_T, GERBER_IMAGE_T, GERBER_DRAW_ITEM_T }, aWhere ); // Remove unselectable items for( int i = collector.GetCount() - 1; i >= 0; --i ) diff --git a/include/collector.h b/include/collector.h index 3edc8cd772..731364e387 100644 --- a/include/collector.h +++ b/include/collector.h @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2007-2008 SoftPLC Corporation, Dick Hollenbeck - * Copyright (C) 2004-2021 KiCad Developers, see change_log.txt for contributors. + * Copyright (C) 2004-2022 KiCad Developers, see change_log.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 @@ -51,7 +51,7 @@ public: COLLECTOR() : m_Threshold( 0 ), m_MenuCancelled( false ), - m_scanTypes( nullptr ), + m_scanTypes( {} ), // Inspect() is virtual so calling it from a class common inspector preserves // polymorphism. m_inspector( [=]( EDA_ITEM* aItem, void* aTestData ) @@ -207,17 +207,13 @@ public: /** * Record the list of #KICAD_T types to consider for collection by the Inspect() function. * - * @param scanTypes An array of KICAD_T, terminated by EOT. No copy is - * is made of this array (so cannot come from caller's stack). + * @param aScanTypes A list of KICAD_Ts. */ - void SetScanTypes( const KICAD_T* scanTypes ) - { - m_scanTypes = scanTypes; - } + void SetScanTypes( const std::initializer_list& aTypes ) { m_scanTypes = aTypes; } - void SetRefPos( const VECTOR2I& aRefPos ) { m_refPos = aRefPos; } + void SetRefPos( const VECTOR2I& aRefPos ) { m_refPos = aRefPos; } - const EDA_RECT& GetBoundingBox() const { return m_refBox; } + const EDA_RECT& GetBoundingBox() const { return m_refBox; } /** * Count the number of items matching \a aType. @@ -244,13 +240,14 @@ public: bool m_MenuCancelled; // Indicates selection disambiguation menu was canceled protected: - std::vector m_list; // Primary list of most likely items - std::vector m_backupList; // Secondary list with items removed by heuristics + std::vector m_list; // Primary list of most likely items + std::vector m_backupList; // Secondary list with items removed by heuristics - const KICAD_T* m_scanTypes; - INSPECTOR_FUNC m_inspector; - VECTOR2I m_refPos; // Reference position used to generate the collection. - EDA_RECT m_refBox; // Selection rectangle used to generate the collection.}; + std::initializer_list m_scanTypes; + INSPECTOR_FUNC m_inspector; + + VECTOR2I m_refPos; // Reference pos used to generate the collection. + EDA_RECT m_refBox; // Selection rect used to generate the collection. }; #endif // COLLECTOR_H diff --git a/include/eda_item.h b/include/eda_item.h index 12b41f187c..bdd220c4e8 100644 --- a/include/eda_item.h +++ b/include/eda_item.h @@ -4,7 +4,7 @@ * Copyright (C) 2013-2015 Jean-Pierre Charras, jp.charras at wanadoo.fr * Copyright (C) 2008-2015 SoftPLC Corporation, Dick Hollenbeck * Copyright (C) 2008 Wayne Stambaugh - * Copyright (C) 2004-2020 KiCad Developers, see change_log.txt for contributors. + * Copyright (C) 2004-2022 KiCad Developers, see change_log.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 @@ -190,14 +190,11 @@ public: * @param aScanTypes List of item types * @return true if the item type is contained in the list aScanTypes */ - virtual bool IsType( const KICAD_T aScanTypes[] ) const + virtual bool IsType( const std::initializer_list& aScanTypes ) const { - if( aScanTypes[0] == SCH_LOCATE_ANY_T ) - return true; - - for( const KICAD_T* p = aScanTypes; *p != EOT; ++p ) + for( KICAD_T scanType : aScanTypes ) { - if( m_structType == *p ) + if( scanType == SCH_LOCATE_ANY_T || scanType == m_structType ) return true; } @@ -295,32 +292,34 @@ public: * May be re-implemented for each derived class in order to handle all the types given * by its member data. * - * Implementations should call inspector->Inspect() on types in scanTypes[], and may use + * Implementations should call inspector->Inspect() on types in aScanTypes, and may use * #IterateForward() to do so on lists of such data. * * @param inspector An #INSPECTOR instance to use in the inspection. * @param testData Arbitrary data used by the inspector. - * @param scanTypes Which# KICAD_T types are of interest and the order - * is significant too, terminated by EOT. + * @param aScanTypes Which #KICAD_T types are of interest and the order in which they should + * be processed. * @return #SEARCH_RESULT SEARCH_QUIT if the Iterator is to stop the scan, * else #SCAN_CONTINUE, and determined by the inspector. */ - virtual INSPECT_RESULT Visit( INSPECTOR inspector, void* testData, const KICAD_T scanTypes[] ); + virtual INSPECT_RESULT Visit( INSPECTOR inspector, void* testData, + const std::initializer_list& aScanTypes ); /** * This changes first parameter to avoid the DList and use the main queue instead. */ template< class T > - static INSPECT_RESULT IterateForward( std::deque& aList, - INSPECTOR inspector, - void* testData, - const KICAD_T scanTypes[] ) + static INSPECT_RESULT IterateForward( std::deque& aList, INSPECTOR inspector, void* testData, + const std::initializer_list& scanTypes ) { - for( auto it : aList ) + for( const auto& it : aList ) { - if( static_cast( it )->Visit( inspector, testData, scanTypes ) - == INSPECT_RESULT::QUIT ) + if( static_cast( it )->Visit( inspector, + testData, + scanTypes ) == INSPECT_RESULT::QUIT ) + { return INSPECT_RESULT::QUIT; + } } return INSPECT_RESULT::CONTINUE; @@ -330,14 +329,18 @@ public: * Change first parameter to avoid the DList and use std::vector instead. */ template - static INSPECT_RESULT IterateForward( - std::vector& aList, INSPECTOR inspector, void* testData, const KICAD_T scanTypes[] ) + static INSPECT_RESULT IterateForward( std::vector& aList, INSPECTOR inspector, + void* testData, + const std::initializer_list& scanTypes ) { - for( auto it : aList ) + for( const auto& it : aList ) { - if( static_cast( it )->Visit( inspector, testData, scanTypes ) - == INSPECT_RESULT::QUIT ) + if( static_cast( it )->Visit( inspector, + testData, + scanTypes ) == INSPECT_RESULT::QUIT ) + { return INSPECT_RESULT::QUIT; + } } return INSPECT_RESULT::CONTINUE; diff --git a/include/pcb_group.h b/include/pcb_group.h index d553301f72..40e2ae65c8 100644 --- a/include/pcb_group.h +++ b/include/pcb_group.h @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2020 Joshua Redstone redstone at gmail.com - * Copyright (C) 1992-2021 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 1992-2022 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 @@ -162,7 +162,7 @@ public: ///< @copydoc EDA_ITEM::Visit INSPECT_RESULT Visit( INSPECTOR aInspector, void* aTestData, - const KICAD_T aScanTypes[] ) override; + const std::initializer_list& aScanTypes ) override; ///< @copydoc VIEW_ITEM::ViewGetLayers void ViewGetLayers( int aLayers[], int& aCount ) const override; diff --git a/include/tool/selection_conditions.h b/include/tool/selection_conditions.h index 186c799237..37ebed57b7 100644 --- a/include/tool/selection_conditions.h +++ b/include/tool/selection_conditions.h @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2014 CERN - * Copyright (C) 2020 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2020-2022 KiCad Developers, see AUTHORS.txt for contributors. * * @author Maciej Suminski * @@ -70,55 +70,31 @@ class SELECTION_CONDITIONS public: /** * The default condition function (always returns true). - * - * @param aSelection is the selection to be tested. - * @return Always true. */ - static bool ShowAlways( const SELECTION& aSelection ) - { - return true; - } + static bool ShowAlways( const SELECTION& aSelection ) { return true; } /** * Always returns false. - * - * @param aSelection is the selection to be tested. - * @return Always false. */ - static bool ShowNever( const SELECTION& aSelection ) - { - return false; - } + static bool ShowNever( const SELECTION& aSelection ) { return false; } /** * Test if there are any items selected. - * - * @param aSelection is the selection to be tested. - * @return True if there is at least one item selected. */ static bool NotEmpty( const SELECTION& aSelection ); /** * Test if there are no items selected. - * - * @param aSelection is the selection to be tested. - * @return True if there are no items selected. */ static bool Empty( const SELECTION& aSelection ); /** * Test if there no items selected or being edited. - * - * @param aSelection is the selection to be tested. - * @return True if there are no items being edited or no items selected. */ static bool Idle( const SELECTION& aSelection ); /** * Test if all selected items are not being edited. - * - * @param aSelection is the selection to be tested. - * @return True if no selected items are being edited. */ static bool IdleSelection( const SELECTION& aSelection ); @@ -135,28 +111,18 @@ public: * Create a functor that tests if among the selected items there is at least one of a * given types. * - * @param aTypes is an array containing types that are searched. It has to be ended with - * #KICAD_T::EOT as end marker. + * @param aTypes is an array containing types that are searched. * @return Functor testing for presence of items of a given types. */ - static SELECTION_CONDITION HasTypes( const KICAD_T aTypes[] ); - - /** - * Create a functor that tests if the selected items are *only* of given type. - * - * @param aType is the type that is searched. - * @return Functor testing if selected items are exclusively of one type. - */ - static SELECTION_CONDITION OnlyType( KICAD_T aType ); + static SELECTION_CONDITION HasTypes( const std::initializer_list& aTypes ); /** * Create a functor that tests if the selected items are *only* of given types. * - * @param aTypes is an array containing types that are searched. It has to be ended with - * #KICAD_T::EOT as end marker. + * @param aTypes is an array containing types that are searched. * @return Functor testing if selected items are exclusively of the requested types. */ - static SELECTION_CONDITION OnlyTypes( const KICAD_T aTypes[] ); + static SELECTION_CONDITION OnlyTypes( const std::initializer_list& aTypes ); /** * Create a functor that tests if the number of selected items is equal to the value given as @@ -190,13 +156,12 @@ private: static bool hasTypeFunc( const SELECTION& aSelection, KICAD_T aType ); ///< Helper function used by HasTypes() - static bool hasTypesFunc( const SELECTION& aSelection, const KICAD_T aTypes[] ); - - ///< Helper function used by OnlyType() - static bool onlyTypeFunc( const SELECTION& aSelection, KICAD_T aType ); + static bool hasTypesFunc( const SELECTION& aSelection, + const std::initializer_list& aTypes ); ///< Helper function used by OnlyTypes() - static bool onlyTypesFunc( const SELECTION& aSelection, const KICAD_T aTypes[] ); + static bool onlyTypesFunc( const SELECTION& aSelection, + const std::initializer_list& aTypes ); ///< Helper function used by Count() static bool countFunc( const SELECTION& aSelection, int aNumber ); @@ -229,7 +194,7 @@ private: ///< Helper function used by operator|| static bool orBoolFunc( const SELECTION_CONDITION& aConditionA, - SELECTION_BOOL& aConditionB, const SELECTION& aSelection ) + SELECTION_BOOL& aConditionB, const SELECTION& aSelection ) { return aConditionA( aSelection ) || aConditionB( aSelection ); } diff --git a/pagelayout_editor/tools/pl_point_editor.cpp b/pagelayout_editor/tools/pl_point_editor.cpp index 4fc61785a6..161da8cf8d 100644 --- a/pagelayout_editor/tools/pl_point_editor.cpp +++ b/pagelayout_editor/tools/pl_point_editor.cpp @@ -148,12 +148,10 @@ void PL_POINT_EDITOR::updateEditedPoint( const TOOL_EVENT& aEvent ) int PL_POINT_EDITOR::Main( const TOOL_EVENT& aEvent ) { - static KICAD_T pointTypes[] = { WSG_LINE_T, WSG_RECT_T, EOT }; - KIGFX::VIEW_CONTROLS* controls = getViewControls(); const PL_SELECTION& selection = m_selectionTool->GetSelection(); - if( selection.Size() != 1 || !selection.Front()->IsType( pointTypes ) ) + if( selection.Size() != 1 || !selection.Front()->IsType( { WSG_LINE_T, WSG_RECT_T } ) ) return 0; EDA_ITEM* item = (EDA_ITEM*) selection.Front(); diff --git a/pcbnew/board.cpp b/pcbnew/board.cpp index 3f6b244d31..88e7d4769a 100644 --- a/pcbnew/board.cpp +++ b/pcbnew/board.cpp @@ -310,63 +310,17 @@ void BOARD::SetPosition( const VECTOR2I& aPos ) void BOARD::Move( const VECTOR2I& aMoveVector ) // overload { - // @todo : anything like this elsewhere? maybe put into GENERAL_COLLECTOR class. - static const KICAD_T top_level_board_stuff[] = { - PCB_MARKER_T, - PCB_BITMAP_T, - PCB_TEXT_T, - PCB_TEXTBOX_T, - PCB_SHAPE_T, - PCB_DIM_ALIGNED_T, - PCB_DIM_ORTHOGONAL_T, - PCB_DIM_CENTER_T, - PCB_DIM_RADIAL_T, - PCB_DIM_LEADER_T, - PCB_TARGET_T, - PCB_VIA_T, - PCB_TRACE_T, - PCB_ARC_T, - PCB_FOOTPRINT_T, - PCB_ZONE_T, - EOT - }; + INSPECTOR_FUNC inspector = + [&] ( EDA_ITEM* item, void* testData ) + { + // aMoveVector was snapshotted, don't need "data". + static_cast( item )->Move( aMoveVector ); + return INSPECT_RESULT::CONTINUE; + }; - INSPECTOR_FUNC inspector = [&] ( EDA_ITEM* item, void* testData ) - { - BOARD_ITEM* brd_item = (BOARD_ITEM*) item; - - // aMoveVector was snapshotted, don't need "data". - brd_item->Move( aMoveVector ); - - return INSPECT_RESULT::CONTINUE; - }; - - Visit( inspector, nullptr, top_level_board_stuff ); + Visit( inspector, nullptr, GENERAL_COLLECTOR::BoardLevelItems ); } - -TRACKS BOARD::TracksInNet( int aNetCode ) -{ - TRACKS ret; - - INSPECTOR_FUNC inspector = [aNetCode, &ret]( EDA_ITEM* item, void* testData ) - { - PCB_TRACK* t = static_cast( item ); - - if( t->GetNetCode() == aNetCode ) - ret.push_back( t ); - - return INSPECT_RESULT::CONTINUE; - }; - - // visit this BOARD's PCB_TRACKs and PCB_VIAs with above TRACK INSPECTOR which - // appends all in aNetCode to ret. - Visit( inspector, nullptr, GENERAL_COLLECTOR::Tracks ); - - return ret; -} - - bool BOARD::SetLayerDescr( PCB_LAYER_ID aIndex, const LAYER& aLayer ) { if( unsigned( aIndex ) < arrayDim( m_layers ) ) @@ -1272,27 +1226,25 @@ void BOARD::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector } -INSPECT_RESULT BOARD::Visit( INSPECTOR inspector, void* testData, const KICAD_T scanTypes[] ) +INSPECT_RESULT BOARD::Visit( INSPECTOR inspector, void* testData, + const std::initializer_list& scanTypes ) { - KICAD_T stype; - INSPECT_RESULT result = INSPECT_RESULT::CONTINUE; - const KICAD_T* p = scanTypes; - bool done = false; - #if 0 && defined(DEBUG) std::cout << GetClass().mb_str() << ' '; #endif - while( !done ) - { - stype = *p; + bool footprintsScanned = false; + bool drawingsScanned = false; + bool tracksScanned = false; - switch( stype ) + for( KICAD_T scanType : scanTypes ) + { + switch( scanType ) { case PCB_T: - result = inspector( this, testData ); // inspect me - // skip over any types handled in the above call. - ++p; + if( inspector( this, testData ) == INSPECT_RESULT::QUIT ) + return INSPECT_RESULT::QUIT; + break; /* @@ -1312,33 +1264,15 @@ INSPECT_RESULT BOARD::Visit( INSPECTOR inspector, void* testData, const KICAD_T case PCB_FP_DIM_RADIAL_T: case PCB_FP_DIM_ORTHOGONAL_T: case PCB_FP_ZONE_T: - - // this calls FOOTPRINT::Visit() on each footprint. - result = IterateForward( m_footprints, inspector, testData, p ); - - // skip over any types handled in the above call. - for( ; ; ) + if( !footprintsScanned ) { - switch( stype = *++p ) + if( IterateForward( m_footprints, inspector, testData, scanTypes ) + == INSPECT_RESULT::QUIT ) { - case PCB_FOOTPRINT_T: - case PCB_PAD_T: - case PCB_FP_TEXT_T: - case PCB_FP_TEXTBOX_T: - case PCB_FP_SHAPE_T: - case PCB_FP_DIM_ALIGNED_T: - case PCB_FP_DIM_LEADER_T: - case PCB_FP_DIM_CENTER_T: - case PCB_FP_DIM_RADIAL_T: - case PCB_FP_DIM_ORTHOGONAL_T: - case PCB_FP_ZONE_T: - continue; - - default: - ; + return INSPECT_RESULT::QUIT; } - break; + footprintsScanned = true; } break; @@ -1353,84 +1287,68 @@ INSPECT_RESULT BOARD::Visit( INSPECTOR inspector, void* testData, const KICAD_T case PCB_DIM_ORTHOGONAL_T: case PCB_DIM_LEADER_T: case PCB_TARGET_T: - result = IterateForward( m_drawings, inspector, testData, p ); - - // skip over any types handled in the above call. - for( ; ; ) + if( !drawingsScanned ) { - switch( stype = *++p ) + if( IterateForward( m_drawings, inspector, testData, scanTypes ) + == INSPECT_RESULT::QUIT ) { - case PCB_SHAPE_T: - case PCB_BITMAP_T: - case PCB_TEXT_T: - case PCB_TEXTBOX_T: - case PCB_DIM_ALIGNED_T: - case PCB_DIM_CENTER_T: - case PCB_DIM_RADIAL_T: - case PCB_DIM_ORTHOGONAL_T: - case PCB_DIM_LEADER_T: - case PCB_TARGET_T: - continue; - - default: - ; + return INSPECT_RESULT::QUIT; } - break; + drawingsScanned = true; } break; case PCB_VIA_T: - result = IterateForward( m_tracks, inspector, testData, p ); - ++p; - break; - case PCB_TRACE_T: case PCB_ARC_T: - result = IterateForward( m_tracks, inspector, testData, p ); - ++p; + if( !tracksScanned ) + { + if( IterateForward( m_tracks, inspector, testData, scanTypes ) + == INSPECT_RESULT::QUIT ) + { + return INSPECT_RESULT::QUIT; + } + + tracksScanned = true; + } + break; case PCB_MARKER_T: for( PCB_MARKER* marker : m_markers ) { - result = marker->Visit( inspector, testData, p ); - - if( result == INSPECT_RESULT::QUIT ) - break; + if( marker->Visit( inspector, testData, { scanType } ) == INSPECT_RESULT::QUIT ) + return INSPECT_RESULT::QUIT; } - ++p; break; case PCB_ZONE_T: for( ZONE* zone : m_zones) { - result = zone->Visit( inspector, testData, p ); - - if( result == INSPECT_RESULT::QUIT ) - break; + if( zone->Visit( inspector, testData, { scanType } ) == INSPECT_RESULT::QUIT ) + return INSPECT_RESULT::QUIT; } - ++p; break; case PCB_GROUP_T: - result = IterateForward( m_groups, inspector, testData, p ); - ++p; + if( IterateForward( m_groups, inspector, testData, { scanType } ) + == INSPECT_RESULT::QUIT ) + { + return INSPECT_RESULT::QUIT; + } + break; - default: // catch EOT or ANY OTHER type here and return. - done = true; + default: break; } - - if( result == INSPECT_RESULT::QUIT ) - break; } - return result; + return INSPECT_RESULT::CONTINUE; } @@ -1982,13 +1900,6 @@ const std::vector BOARD::AllConnectedItems() } -void BOARD::ClearAllNetCodes() -{ - for( BOARD_CONNECTED_ITEM* item : AllConnectedItems() ) - item->SetNetCode( 0 ); -} - - void BOARD::MapNets( const BOARD* aDestBoard ) { for( BOARD_CONNECTED_ITEM* item : AllConnectedItems() ) diff --git a/pcbnew/board.h b/pcbnew/board.h index 8c5e2f8250..870ac1b90f 100644 --- a/pcbnew/board.h +++ b/pcbnew/board.h @@ -806,12 +806,12 @@ public: * to do so on lists of such data. * @param inspector An INSPECTOR instance to use in the inspection. * @param testData Arbitrary data used by the inspector. - * @param scanTypes Which KICAD_T types are of interest and the order - * is significant too, terminated by EOT. + * @param scanTypes Which KICAD_T types are of interest and the order to process them in. * @return SEARCH_QUIT if the Iterator is to stop the scan, else SCAN_CONTINUE, and * determined by the inspector. */ - INSPECT_RESULT Visit( INSPECTOR inspector, void* testData, const KICAD_T scanTypes[] ) override; + INSPECT_RESULT Visit( INSPECTOR inspector, void* testData, + const std::initializer_list& scanTypes ) override; /** * Search for a FOOTPRINT within this board with the given reference designator. @@ -1010,15 +1010,6 @@ public: */ std::tuple GetTrackLength( const PCB_TRACK& aTrack ) const; - /** - * Collect all the TRACKs and VIAs that are members of a net given by aNetCode. - * Used from python. - * - * @param aNetCode gives the id of the net. - * @return list of track which are in the net identified by @a aNetCode. - */ - TRACKS TracksInNet( int aNetCode ); - /** * Get a footprint by its bounding rectangle at \a aPosition on \a aLayer. * @@ -1034,11 +1025,6 @@ public: FOOTPRINT* GetFootprint( const VECTOR2I& aPosition, PCB_LAYER_ID aActiveLayer, bool aVisibleOnly, bool aIgnoreLocked = false ) const; - /** - * Reset all items' netcodes to 0 (no net). - */ - void ClearAllNetCodes(); - /** * Map all nets in the given board to nets with the same name (if any) in the destination * board. This allows us to share layouts which came from the same hierarchical sheet in diff --git a/pcbnew/collectors.cpp b/pcbnew/collectors.cpp index 3476afb3de..4609a60dab 100644 --- a/pcbnew/collectors.cpp +++ b/pcbnew/collectors.cpp @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2007-2008 SoftPLC Corporation, Dick Hollenbeck - * Copyright (C) 2004-2021 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2004-2022 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,16 +37,8 @@ #include #include // for KiROUND -/* - * This module contains out of line member functions for classes given in - * collectors.h. Those classes augment the functionality of class PCB_EDIT_FRAME. - */ - -const KICAD_T GENERAL_COLLECTOR::AllBoardItems[] = { - // there are some restrictions on the order of items in the general case. - // all items in m_Drawings for instance should be contiguous. - // *** all items in a same list (shown here) must be contiguous **** +const std::initializer_list GENERAL_COLLECTOR::AllBoardItems = { PCB_MARKER_T, // in m_markers PCB_TEXT_T, // in m_drawings PCB_BITMAP_T, // in m_drawings @@ -66,12 +58,11 @@ const KICAD_T GENERAL_COLLECTOR::AllBoardItems[] = { PCB_FP_TEXTBOX_T, // in footprints PCB_FOOTPRINT_T, // in m_footprints PCB_GROUP_T, // in m_groups - PCB_ZONE_T, // in m_zones - EOT + PCB_ZONE_T // in m_zones }; -const KICAD_T GENERAL_COLLECTOR::BoardLevelItems[] = { +const std::initializer_list GENERAL_COLLECTOR::BoardLevelItems = { PCB_MARKER_T, PCB_BITMAP_T, PCB_TEXT_T, @@ -88,27 +79,11 @@ const KICAD_T GENERAL_COLLECTOR::BoardLevelItems[] = { PCB_TRACE_T, PCB_FOOTPRINT_T, PCB_GROUP_T, - PCB_ZONE_T, - EOT + PCB_ZONE_T }; -const KICAD_T GENERAL_COLLECTOR::Footprints[] = { - PCB_FOOTPRINT_T, - EOT -}; - - -const KICAD_T GENERAL_COLLECTOR::PadsOrTracks[] = { - PCB_PAD_T, - PCB_VIA_T, - PCB_TRACE_T, - PCB_ARC_T, - EOT -}; - - -const KICAD_T GENERAL_COLLECTOR::FootprintItems[] = { +const std::initializer_list GENERAL_COLLECTOR::FootprintItems = { PCB_FP_TEXT_T, PCB_FP_TEXTBOX_T, PCB_FP_SHAPE_T, @@ -120,57 +95,15 @@ const KICAD_T GENERAL_COLLECTOR::FootprintItems[] = { PCB_PAD_T, PCB_FP_ZONE_T, PCB_GROUP_T, - PCB_BITMAP_T, - EOT - }; - - -const KICAD_T GENERAL_COLLECTOR::Tracks[] = { - PCB_TRACE_T, - PCB_ARC_T, - PCB_VIA_T, - EOT + PCB_BITMAP_T }; -const KICAD_T GENERAL_COLLECTOR::LockableItems[] = { - PCB_FOOTPRINT_T, - PCB_GROUP_T, // Can a group be locked? - PCB_TRACE_T, - PCB_ARC_T, - PCB_VIA_T, - EOT -}; - - -const KICAD_T GENERAL_COLLECTOR::Zones[] = { - PCB_ZONE_T, - PCB_FP_ZONE_T, - EOT -}; - - -const KICAD_T GENERAL_COLLECTOR::Dimensions[] = { - PCB_DIM_ALIGNED_T, - PCB_DIM_LEADER_T, - PCB_DIM_ORTHOGONAL_T, - PCB_DIM_CENTER_T, - PCB_DIM_RADIAL_T, - PCB_FP_DIM_ALIGNED_T, - PCB_FP_DIM_LEADER_T, - PCB_FP_DIM_ORTHOGONAL_T, - PCB_FP_DIM_CENTER_T, - PCB_FP_DIM_RADIAL_T, - EOT -}; - - -const KICAD_T GENERAL_COLLECTOR::DraggableItems[] = { +const std::initializer_list GENERAL_COLLECTOR::DraggableItems = { PCB_TRACE_T, PCB_VIA_T, PCB_FOOTPRINT_T, - PCB_ARC_T, - EOT + PCB_ARC_T }; @@ -184,7 +117,6 @@ INSPECT_RESULT GENERAL_COLLECTOR::Inspect( EDA_ITEM* testItem, void* testData ) PCB_VIA* via = nullptr; PCB_MARKER* marker = nullptr; ZONE* zone = nullptr; - PCB_SHAPE* shape = nullptr; PCB_DIMENSION_BASE* dimension = nullptr; #if 0 // debugging @@ -291,7 +223,7 @@ INSPECT_RESULT GENERAL_COLLECTOR::Inspect( EDA_ITEM* testItem, void* testData ) case PCB_TRACE_T: case PCB_ARC_T: if( m_Guide->IgnoreTracks() ) - goto exit; + return INSPECT_RESULT::CONTINUE; break; @@ -307,10 +239,7 @@ INSPECT_RESULT GENERAL_COLLECTOR::Inspect( EDA_ITEM* testItem, void* testData ) case PCB_TEXT_T: case PCB_TEXTBOX_T: - break; - case PCB_SHAPE_T: - shape = static_cast( item ); break; case PCB_FP_DIM_ALIGNED_T: @@ -344,14 +273,14 @@ INSPECT_RESULT GENERAL_COLLECTOR::Inspect( EDA_ITEM* testItem, void* testData ) FP_TEXT *text = static_cast( item ); if( !text->IsVisible() ) - goto exit; + return INSPECT_RESULT::CONTINUE; } if( m_Guide->IgnoreFPTextOnBack() && IsBackLayer( layer ) ) - goto exit; + return INSPECT_RESULT::CONTINUE; if( m_Guide->IgnoreFPTextOnFront() && IsFrontLayer( layer ) ) - goto exit; + return INSPECT_RESULT::CONTINUE; /* * The three text types have different criteria: reference and value have their own @@ -368,19 +297,19 @@ INSPECT_RESULT GENERAL_COLLECTOR::Inspect( EDA_ITEM* testItem, void* testData ) { case FP_TEXT::TEXT_is_REFERENCE: if( m_Guide->IgnoreFPReferences() ) - goto exit; + return INSPECT_RESULT::CONTINUE; break; case FP_TEXT::TEXT_is_VALUE: if( m_Guide->IgnoreFPValues() ) - goto exit; + return INSPECT_RESULT::CONTINUE; break; case FP_TEXT::TEXT_is_DIVERS: if( !m_Guide->IsLayerVisible( layer ) ) - goto exit; + return INSPECT_RESULT::CONTINUE; break; } @@ -391,7 +320,6 @@ INSPECT_RESULT GENERAL_COLLECTOR::Inspect( EDA_ITEM* testItem, void* testData ) } case PCB_FP_SHAPE_T: - shape = static_cast( item ); break; case PCB_FOOTPRINT_T: @@ -415,10 +343,10 @@ INSPECT_RESULT GENERAL_COLLECTOR::Inspect( EDA_ITEM* testItem, void* testData ) if( footprint ) // true from case PCB_PAD_T, PCB_FP_TEXT_T, or PCB_FOOTPRINT_T { if( m_Guide->IgnoreFootprintsOnBack() && ( footprint->GetLayer() == B_Cu ) ) - goto exit; + return INSPECT_RESULT::CONTINUE; if( m_Guide->IgnoreFootprintsOnFront() && ( footprint->GetLayer() == F_Cu ) ) - goto exit; + return INSPECT_RESULT::CONTINUE; } // Pads are not sensitive to the layer visibility controls. @@ -427,15 +355,15 @@ INSPECT_RESULT GENERAL_COLLECTOR::Inspect( EDA_ITEM* testItem, void* testData ) if( pad ) { if( m_Guide->IgnorePads() ) - goto exit; + return INSPECT_RESULT::CONTINUE; if( ! pad_through ) { if( m_Guide->IgnorePadsOnFront() && pad->IsOnLayer(F_Cu ) ) - goto exit; + return INSPECT_RESULT::CONTINUE; if( m_Guide->IgnorePadsOnBack() && pad->IsOnLayer(B_Cu ) ) - goto exit; + return INSPECT_RESULT::CONTINUE; } } @@ -445,7 +373,7 @@ INSPECT_RESULT GENERAL_COLLECTOR::Inspect( EDA_ITEM* testItem, void* testData ) if( marker->HitTest( m_refPos ) ) Append( item ); - goto exit; + return INSPECT_RESULT::CONTINUE; } if( group ) @@ -454,7 +382,7 @@ INSPECT_RESULT GENERAL_COLLECTOR::Inspect( EDA_ITEM* testItem, void* testData ) if( group->HitTest( m_refPos ) ) Append( item ); - goto exit; + return INSPECT_RESULT::CONTINUE; } if( via ) @@ -465,7 +393,7 @@ INSPECT_RESULT GENERAL_COLLECTOR::Inspect( EDA_ITEM* testItem, void* testData ) || ( m_Guide->IgnoreBlindBuriedVias() && type == VIATYPE::BLIND_BURIED ) || ( m_Guide->IgnoreMicroVias() && type == VIATYPE::MICROVIA ) ) { - goto exit; + return INSPECT_RESULT::CONTINUE; } } @@ -485,7 +413,7 @@ INSPECT_RESULT GENERAL_COLLECTOR::Inspect( EDA_ITEM* testItem, void* testData ) || zone->HitTestForEdge( m_refPos, accuracy ) ) { Append( item ); - goto exit; + return INSPECT_RESULT::CONTINUE; } else if( !m_Guide->IgnoreZoneFills() ) { @@ -495,7 +423,7 @@ INSPECT_RESULT GENERAL_COLLECTOR::Inspect( EDA_ITEM* testItem, void* testData ) && zone->HitTestFilledArea( layer, m_refPos ) ) { Append( item ); - goto exit; + return INSPECT_RESULT::CONTINUE; } } } @@ -506,7 +434,7 @@ INSPECT_RESULT GENERAL_COLLECTOR::Inspect( EDA_ITEM* testItem, void* testData ) && footprint->HitTestAccurate( m_refPos, accuracy ) ) { Append( item ); - goto exit; + return INSPECT_RESULT::CONTINUE; } } else if( pad || via ) @@ -514,7 +442,7 @@ INSPECT_RESULT GENERAL_COLLECTOR::Inspect( EDA_ITEM* testItem, void* testData ) if( item->HitTest( m_refPos, accuracy ) ) { Append( item ); - goto exit; + return INSPECT_RESULT::CONTINUE; } } else @@ -533,14 +461,13 @@ INSPECT_RESULT GENERAL_COLLECTOR::Inspect( EDA_ITEM* testItem, void* testData ) if( item->HitTest( m_refPos, accuracy ) ) { Append( item ); - goto exit; + return INSPECT_RESULT::CONTINUE; } } } } - if( m_Guide->IncludeSecondary() - && ( !item->IsLocked() || !m_Guide->IgnoreLockedItems() ) ) + if( m_Guide->IncludeSecondary() && ( !item->IsLocked() || !m_Guide->IgnoreLockedItems() ) ) { // for now, "secondary" means "tolerate any visible layer". It has no effect on other // criteria, since there is a separate "ignore" control for those in the COLLECTORS_GUIDE @@ -558,7 +485,7 @@ INSPECT_RESULT GENERAL_COLLECTOR::Inspect( EDA_ITEM* testItem, void* testData ) || zone->HitTestForEdge( m_refPos, accuracy ) ) { Append2nd( item ); - goto exit; + return INSPECT_RESULT::CONTINUE; } else if( !m_Guide->IgnoreZoneFills() ) { @@ -568,7 +495,7 @@ INSPECT_RESULT GENERAL_COLLECTOR::Inspect( EDA_ITEM* testItem, void* testData ) && zone->HitTestFilledArea( layer, m_refPos ) ) { Append2nd( item ); - goto exit; + return INSPECT_RESULT::CONTINUE; } } } @@ -579,7 +506,7 @@ INSPECT_RESULT GENERAL_COLLECTOR::Inspect( EDA_ITEM* testItem, void* testData ) && footprint->HitTestAccurate( m_refPos, accuracy ) ) { Append2nd( item ); - goto exit; + return INSPECT_RESULT::CONTINUE; } } else if( pad || via ) @@ -587,7 +514,7 @@ INSPECT_RESULT GENERAL_COLLECTOR::Inspect( EDA_ITEM* testItem, void* testData ) if( item->HitTest( m_refPos, accuracy ) ) { Append2nd( item ); - goto exit; + return INSPECT_RESULT::CONTINUE; } } else @@ -606,18 +533,18 @@ INSPECT_RESULT GENERAL_COLLECTOR::Inspect( EDA_ITEM* testItem, void* testData ) if( item->HitTest( m_refPos, accuracy ) ) { Append2nd( item ); - goto exit; + return INSPECT_RESULT::CONTINUE; } } } } -exit: return INSPECT_RESULT::CONTINUE; // always when collecting } -void GENERAL_COLLECTOR::Collect( BOARD_ITEM* aItem, const KICAD_T aScanList[], +void GENERAL_COLLECTOR::Collect( BOARD_ITEM* aItem, + const std::initializer_list& aScanTypes, const VECTOR2I& aRefPos, const COLLECTORS_GUIDE& aGuide ) { Empty(); // empty the collection, primary criteria list @@ -626,7 +553,7 @@ void GENERAL_COLLECTOR::Collect( BOARD_ITEM* aItem, const KICAD_T aScanList[], // remember guide, pass it to Inspect() SetGuide( &aGuide ); - SetScanTypes( aScanList ); + SetScanTypes( aScanTypes ); // remember where the snapshot was taken from and pass refPos to // the Inspect() function. @@ -634,9 +561,6 @@ void GENERAL_COLLECTOR::Collect( BOARD_ITEM* aItem, const KICAD_T aScanList[], aItem->Visit( m_inspector, nullptr, m_scanTypes ); - // record the length of the primary list before concatenating on to it. - m_PrimaryLength = m_list.size(); - // append 2nd list onto end of the first list for( unsigned i = 0; i& aTypes ) { - Empty(); // empty any existing collection - - aBoard->Visit( m_inspector, nullptr, aScanList ); + Empty(); + aBoard->Visit( m_inspector, nullptr, aTypes ); } @@ -674,9 +597,8 @@ INSPECT_RESULT PCB_LAYER_COLLECTOR::Inspect( EDA_ITEM* testItem, void* testData } -void PCB_LAYER_COLLECTOR::Collect( BOARD_ITEM* aBoard, const KICAD_T aScanList[] ) +void PCB_LAYER_COLLECTOR::Collect( BOARD_ITEM* aBoard, const std::initializer_list& aTypes ) { Empty(); - - aBoard->Visit( m_inspector, nullptr, aScanList ); + aBoard->Visit( m_inspector, nullptr, aTypes ); } diff --git a/pcbnew/collectors.h b/pcbnew/collectors.h index 27e3af8538..3ecaa134eb 100644 --- a/pcbnew/collectors.h +++ b/pcbnew/collectors.h @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2007-2008 SoftPLC Corporation, Dick Hollenbeck - * Copyright (C) 2004-2021 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2004-2022 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 @@ -25,35 +25,27 @@ #ifndef COLLECTORS_H #define COLLECTORS_H - /* * This module contains a number of COLLECTOR implementations which are used * to augment the functionality of class PCB_EDIT_FRAME. */ - #include #include // LAYER_COUNT, layer defs #include #include - - /** - * An abstract base class whose derivatives may be passed to a GENERAL_COLLECTOR, - * telling GENERAL_COLLECTOR what should be collected (aside from HitTest()ing - * and KICAD_T scanTypes[], information which are provided to the GENERAL_COLLECTOR - * through attributes or arguments separately). + * An abstract base class whose derivatives may be passed to a GENERAL_COLLECTOR telling it what + * should be collected (aside from HitTest()ing and KICAD_T scanTypes, which are provided to the + * GENERAL_COLLECTOR through attributes or arguments separately). *

- * A justification for this class is to keep the structural storage details of - * the program's "global preferences" or "configuration options" out of - * GENERAL_COLLECTOR::Inspect(). This class carries all the necessary details - * in with it to the Inspect() call. The constructors or other functions of - * this class's derivatives are then the only place where knowledge of the - * specific structure of the global preference storage is needed. Thus, - * GENERAL_COLLECTOR::Inspect() can be kept as simple as possible, and insulated - * from changes in global preference storage (and even then it is - * not simple enough). + * A justification for this class is to keep the structural storage details of the program's + * "configuration options" out of GENERAL_COLLECTOR::Inspect(). This class carries all the + * necessary details with it into the Inspect() call. The constructors or other functions of this + * class's derivatives are then the only place where knowledge of the specific structure of the + * global preference storage is needed. Thus, GENERAL_COLLECTOR::Inspect() can be kept as simple + * as possible, and insulated from changes in global preference storage. *

* This class introduces the notion of layer locking. */ @@ -62,19 +54,8 @@ class COLLECTORS_GUIDE public: virtual ~COLLECTORS_GUIDE() {} - /** - * @return true if the given layer is visible, else false. - */ virtual bool IsLayerVisible( PCB_LAYER_ID layer ) const = 0; - - /** - * @return the preferred layer for HitTest()ing. - */ virtual PCB_LAYER_ID GetPreferredLayer() const = 0; - - /** - * @return true if should ignore locked items, else false. - */ virtual bool IgnoreLockedItems() const = 0; /** @@ -89,91 +70,29 @@ public: */ virtual bool IgnoreHiddenFPText() const = 0; - /** - * @return true if should ignore footprint text on back layers - */ virtual bool IgnoreFPTextOnBack() const = 0; - - /** - * @return true if should ignore footprint text on front layers. - */ virtual bool IgnoreFPTextOnFront() const = 0; - - /** - * @return true if should ignore FOOTPRINTs on Back Side. - */ virtual bool IgnoreFootprintsOnBack() const = 0; - - /** - * @return true if should ignore FOOTPRINTs on Front Side. - */ virtual bool IgnoreFootprintsOnFront() const = 0; - - /** - * @return true if should ignore Pads on Back Side. - */ virtual bool IgnorePadsOnBack() const = 0; - - /** - * @return true if should ignore PADSs on Front Side. - */ virtual bool IgnorePadsOnFront() const = 0; - - /** - * @return true if should ignore through-hole PADSs. - */ virtual bool IgnoreThroughHolePads() const = 0; - /** - * @return true if should ignore PADSs on Front side and Back side. - */ virtual bool IgnorePads() const { return IgnorePadsOnFront() && IgnorePadsOnBack() && IgnoreThroughHolePads(); } - /** - * @return true if should ignore footprint values. - */ virtual bool IgnoreFPValues() const = 0; - - /** - * @return true if should ignore footprint references. - */ virtual bool IgnoreFPReferences() const = 0; - /** - * @return true if should ignore through-hole vias - */ virtual bool IgnoreThroughVias() const = 0; - - /** - * @return true if should ignore blind/buried vias - */ virtual bool IgnoreBlindBuriedVias() const = 0; - - /** - * @return true if should ignore micro vias - */ virtual bool IgnoreMicroVias() const = 0; - - /** - * @return true if should ignore tracks - */ virtual bool IgnoreTracks() const = 0; - - /** - * @return true if should ignore the interiors of zones - */ virtual bool IgnoreZoneFills() const = 0; virtual double OnePixelInIU() const = 0; - - /** - * @return true if Inspect() should use BOARD_ITEM::HitTest() - * or false if Inspect() should use BOARD_ITEM::BoundsTest(). - virtual bool UseHitTesting() const = 0; - */ }; @@ -210,10 +129,9 @@ public: * Used when the right click button is pressed, or when the select tool is in effect. * This class can be used by window classes such as PCB_EDIT_FRAME. * - * Philosophy: this class knows nothing of the context in which a BOARD is used - * and that means it knows nothing about which layers are visible or current, - * but can handle those concerns by the SetPreferredLayer() function and the - * SetLayerSet() function. + * Philosophy: this class knows nothing of the context in which a BOARD is used and that means + * it knows nothing about which layers are visible or current, but can handle those concerns by + * the SetPreferredLayer() function and the SetLayerSet() function. */ class GENERAL_COLLECTOR : public PCB_COLLECTOR { @@ -231,69 +149,32 @@ protected: */ const COLLECTORS_GUIDE* m_Guide; - /** - * The number of items that were originally in the primary list before the - * m_List2nd was concatenated onto the end of it. - */ - int m_PrimaryLength; - public: /** * A scan list for all editable board items */ - static const KICAD_T AllBoardItems[]; - - /** - * A scan list for zones outlines only - */ - static const KICAD_T Zones[]; + static const std::initializer_list AllBoardItems; /** * A scan list for all primary board items, omitting items which are subordinate to * a FOOTPRINT, such as PAD and FP_TEXT. */ - static const KICAD_T BoardLevelItems[]; - - /** - * A scan list for only FOOTPRINTs - */ - static const KICAD_T Footprints[]; - - /** - * A scan list for PADs, TRACKs, or VIAs - */ - static const KICAD_T PadsOrTracks[]; + static const std::initializer_list BoardLevelItems; /** * A scan list for primary footprint items. */ - static const KICAD_T FootprintItems[]; - - /** - * A scan list for only TRACKs - */ - static const KICAD_T Tracks[]; - - /** - * A scan list for TRACKs, VIAs, FOOTPRINTs - */ - static const KICAD_T LockableItems[]; - - /** - * A scan list for dimensions - */ - static const KICAD_T Dimensions[]; + static const std::initializer_list FootprintItems; /** * A scan list for items that can be dragged */ - static const KICAD_T DraggableItems[]; + static const std::initializer_list DraggableItems; - GENERAL_COLLECTOR() + GENERAL_COLLECTOR() : + m_Guide( nullptr ) { - m_Guide = nullptr; - m_PrimaryLength = 0; SetScanTypes( AllBoardItems ); } @@ -316,20 +197,13 @@ public: const COLLECTORS_GUIDE* GetGuide() const { return m_Guide; } - /** - * @return The number of items which met the primary search criteria - */ - int GetPrimaryCount() { return m_PrimaryLength; } - /** * The examining function within the INSPECTOR which is passed to the Iterate function. - * * Search and collect all the objects which match the test data. * * @param testItem An EDA_ITEM to examine. * @param testData is not used in this class. - * @return SEARCH_RESULT - SEARCH_QUIT if the Iterator is to stop the scan, - * else SCAN_CONTINUE; + * @return SEARCH_QUIT if the Iterator is to stop the scan, else SCAN_CONTINUE */ INSPECT_RESULT Inspect( EDA_ITEM* testItem, void* testData ) override; @@ -337,14 +211,13 @@ public: * Scan a BOARD_ITEM using this class's Inspector method, which does the collection. * * @param aItem A BOARD_ITEM to scan, may be a BOARD or FOOTPRINT, or whatever. - * @param aScanList A list of KICAD_Ts with a terminating EOT, that specs - * what is to be collected and the priority order of the resultant - * collection in "m_list". + * @param aScanList A list of KICAD_Ts that specs what is to be collected and the priority + * order of the resultant collection in "m_list". * @param aRefPos A wxPoint to use in hit-testing. * @param aGuide The COLLECTORS_GUIDE to use in collecting items. */ - void Collect( BOARD_ITEM* aItem, const KICAD_T aScanList[], const VECTOR2I& aRefPos, - const COLLECTORS_GUIDE& aGuide ); + void Collect( BOARD_ITEM* aItem, const std::initializer_list& aScanList, + const VECTOR2I& aRefPos, const COLLECTORS_GUIDE& aGuide ); }; @@ -557,7 +430,7 @@ public: * * @param testItem An EDA_ITEM to examine. * @param testData is not used in this class. - * @return SEARCH_QUIT if the Iterator is to stop the scan, else SCAN_CONTINUE; + * @return SEARCH_QUIT if the Iterator is to stop the scan, else SCAN_CONTINUE */ INSPECT_RESULT Inspect( EDA_ITEM* testItem, void* testData ) override; @@ -565,9 +438,9 @@ public: * Collect #BOARD_ITEM objects using this class's Inspector method, which does the collection. * * @param aBoard The BOARD_ITEM to scan. - * @param aScanList The KICAD_Ts to gather up. + * @param aTypes The KICAD_Ts to gather up. */ - void Collect( BOARD_ITEM* aBoard, const KICAD_T aScanList[] ); + void Collect( BOARD_ITEM* aBoard, const std::initializer_list& aTypes ); }; @@ -581,8 +454,7 @@ class PCB_LAYER_COLLECTOR : public PCB_COLLECTOR public: PCB_LAYER_COLLECTOR( PCB_LAYER_ID aLayerId = UNDEFINED_LAYER ) : m_layer_id( aLayerId ) - { - } + { } void SetLayerId( PCB_LAYER_ID aLayerId ) { m_layer_id = aLayerId; } @@ -591,8 +463,7 @@ public: * * @param testItem An EDA_ITEM to examine. * @param testData is not used in this class. - * @return SEARCH_RESULT - SEARCH_QUIT if the Iterator is to stop the scan, - * else SCAN_CONTINUE; + * @return SEARCH_QUIT if the Iterator is to stop the scan, else SCAN_CONTINUE */ INSPECT_RESULT Inspect( EDA_ITEM* testItem, void* testData ) override; @@ -600,9 +471,9 @@ public: * Test a BOARD_ITEM using this class's Inspector method, which does the collection. * * @param aBoard The BOARD_ITEM to scan. - * @param aScanList The KICAD_Ts to gather up. + * @param aTypes The KICAD_Ts to gather up. */ - void Collect( BOARD_ITEM* aBoard, const KICAD_T aScanList[] ); + void Collect( BOARD_ITEM* aBoard, const std::initializer_list& aTypes ); private: PCB_LAYER_ID m_layer_id; diff --git a/pcbnew/connectivity/connectivity_algo.cpp b/pcbnew/connectivity/connectivity_algo.cpp index 40fb2a3fde..27eb4167d4 100644 --- a/pcbnew/connectivity/connectivity_algo.cpp +++ b/pcbnew/connectivity/connectivity_algo.cpp @@ -291,11 +291,17 @@ void CN_CONNECTIVITY_ALGO::searchConnections() const CN_CONNECTIVITY_ALGO::CLUSTERS CN_CONNECTIVITY_ALGO::SearchClusters( CLUSTER_SEARCH_MODE aMode ) { if( aMode == CSM_PROPAGATE ) + { return SearchClusters( aMode, - { PCB_TRACE_T, PCB_ARC_T, PCB_PAD_T, PCB_VIA_T, PCB_FOOTPRINT_T }, -1 ); + { PCB_TRACE_T, PCB_ARC_T, PCB_PAD_T, PCB_VIA_T, PCB_FOOTPRINT_T }, + -1 ); + } else + { return SearchClusters( aMode, - { PCB_TRACE_T, PCB_ARC_T, PCB_PAD_T, PCB_VIA_T, PCB_ZONE_T, PCB_FOOTPRINT_T }, -1 ); + { PCB_TRACE_T, PCB_ARC_T, PCB_PAD_T, PCB_VIA_T, PCB_ZONE_T, PCB_FOOTPRINT_T }, + -1 ); + } } diff --git a/pcbnew/connectivity/connectivity_data.cpp b/pcbnew/connectivity/connectivity_data.cpp index adb47f9f5b..4c285ddffb 100644 --- a/pcbnew/connectivity/connectivity_data.cpp +++ b/pcbnew/connectivity/connectivity_data.cpp @@ -489,7 +489,8 @@ void CONNECTIVITY_DATA::Clear() const std::vector CONNECTIVITY_DATA::GetConnectedItems( const BOARD_CONNECTED_ITEM *aItem, - const std::initializer_list& aTypes, bool aIgnoreNetcodes ) const + const std::initializer_list& aTypes, + bool aIgnoreNetcodes ) const { std::vector rv; CN_CONNECTIVITY_ALGO::CLUSTER_SEARCH_MODE searchMode; @@ -518,24 +519,26 @@ CONNECTIVITY_DATA::GetConnectedItems( const BOARD_CONNECTED_ITEM *aItem, } -const std::vector CONNECTIVITY_DATA::GetNetItems( int aNetCode, - const KICAD_T aTypes[] ) const +const std::vector +CONNECTIVITY_DATA::GetNetItems( int aNetCode, const std::initializer_list& aTypes ) const { std::vector items; items.reserve( 32 ); std::bitset type_bits; - for( unsigned int i = 0; aTypes[i] != EOT; ++i ) + for( KICAD_T scanType : aTypes ) { - wxASSERT( aTypes[i] < MAX_STRUCT_TYPE_ID ); - type_bits.set( aTypes[i] ); + wxASSERT( scanType < MAX_STRUCT_TYPE_ID ); + type_bits.set( scanType ); } - m_connAlgo->ForEachItem( [&]( CN_ITEM& aItem ) { - if( aItem.Valid() && ( aItem.Net() == aNetCode ) && type_bits[aItem.Parent()->Type()] ) - items.push_back( aItem.Parent() ); - } ); + m_connAlgo->ForEachItem( + [&]( CN_ITEM& aItem ) + { + if( aItem.Valid() && ( aItem.Net() == aNetCode ) && type_bits[aItem.Parent()->Type()] ) + items.push_back( aItem.Parent() ); + } ); std::sort( items.begin(), items.end() ); items.erase( std::unique( items.begin(), items.end() ), items.end() ); @@ -568,8 +571,8 @@ bool CONNECTIVITY_DATA::CheckConnectivity( std::vector& a } -const std::vector CONNECTIVITY_DATA::GetConnectedTracks( - const BOARD_CONNECTED_ITEM* aItem ) const +const std::vector +CONNECTIVITY_DATA::GetConnectedTracks( const BOARD_CONNECTED_ITEM* aItem ) const { auto& entry = m_connAlgo->ItemEntry( aItem ); @@ -584,7 +587,9 @@ const std::vector CONNECTIVITY_DATA::GetConnectedTracks( ( connected->Parent()->Type() == PCB_TRACE_T || connected->Parent()->Type() == PCB_VIA_T || connected->Parent()->Type() == PCB_ARC_T ) ) + { tracks.insert( static_cast ( connected->Parent() ) ); + } } } @@ -814,27 +819,27 @@ bool CONNECTIVITY_DATA::TestTrackEndpointDangling( PCB_TRACK* aTrack, VECTOR2I* } -const std::vector CONNECTIVITY_DATA::GetConnectedItemsAtAnchor( - const BOARD_CONNECTED_ITEM* aItem, - const VECTOR2I& aAnchor, - const KICAD_T aTypes[], - const int& aMaxError ) const +const std::vector +CONNECTIVITY_DATA::GetConnectedItemsAtAnchor( const BOARD_CONNECTED_ITEM* aItem, + const VECTOR2I& aAnchor, + const std::initializer_list& aTypes, + const int& aMaxError ) const { - auto& entry = m_connAlgo->ItemEntry( aItem ); - std::vector rv; - SEG::ecoord maxErrorSq = (SEG::ecoord) aMaxError * aMaxError; + CN_CONNECTIVITY_ALGO::ITEM_MAP_ENTRY& entry = m_connAlgo->ItemEntry( aItem ); + std::vector rv; + SEG::ecoord maxError_sq = (SEG::ecoord) aMaxError * aMaxError; for( CN_ITEM* cnItem : entry.GetItems() ) { for( CN_ITEM* connected : cnItem->ConnectedItems() ) { - for( std::shared_ptr& anchor : connected->Anchors() ) + for( const std::shared_ptr& anchor : connected->Anchors() ) { - if( ( anchor->Pos() - aAnchor ).SquaredEuclideanNorm() <= maxErrorSq ) + if( ( anchor->Pos() - aAnchor ).SquaredEuclideanNorm() <= maxError_sq ) { - for( int i = 0; aTypes[i] > 0; i++ ) + for( KICAD_T type : aTypes ) { - if( connected->Valid() && connected->Parent()->Type() == aTypes[i] ) + if( connected->Valid() && connected->Parent()->Type() == type ) { rv.push_back( connected->Parent() ); break; diff --git a/pcbnew/connectivity/connectivity_data.h b/pcbnew/connectivity/connectivity_data.h index 978068fe71..5f43acab99 100644 --- a/pcbnew/connectivity/connectivity_data.h +++ b/pcbnew/connectivity/connectivity_data.h @@ -201,8 +201,7 @@ public: */ unsigned int GetUnconnectedCount() const; - bool IsConnectedOnLayer( const BOARD_CONNECTED_ITEM* aItem, - int aLayer, + bool IsConnectedOnLayer( const BOARD_CONNECTED_ITEM* aItem, int aLayer, const std::initializer_list& aTypes = {}, bool aCheckOptionalFlashing = false ) const; @@ -226,11 +225,10 @@ public: * @param aMaxError Maximum distance of the found items' anchors to aAnchor in IU * @return */ - const std::vector GetConnectedItemsAtAnchor( - const BOARD_CONNECTED_ITEM* aItem, - const VECTOR2I& aAnchor, - const KICAD_T aTypes[], - const int& aMaxError = 0 ) const; + const std::vector + GetConnectedItemsAtAnchor( const BOARD_CONNECTED_ITEM* aItem, const VECTOR2I& aAnchor, + const std::initializer_list& aTypes, + const int& aMaxError = 0 ) const; void GetUnconnectedEdges( std::vector& aEdges ) const; @@ -257,10 +255,7 @@ public: const CONNECTIVITY_DATA* aDynamicData, VECTOR2I aInternalOffset = { 0, 0 } ); - const std::vector& GetDynamicRatsnest() const - { - return m_dynamicRatsnest; - } + const std::vector& GetDynamicRatsnest() const { return m_dynamicRatsnest; } /** * Function GetConnectedItems() @@ -268,8 +263,10 @@ public: * @param aItem is the reference item to find other connected items. * @param aTypes allows one to filter by item types. */ - const std::vector GetConnectedItems( const BOARD_CONNECTED_ITEM* aItem, - const std::initializer_list& aTypes, bool aIgnoreNetcodes = false ) const; + const std::vector + GetConnectedItems( const BOARD_CONNECTED_ITEM* aItem, + const std::initializer_list& aTypes, + bool aIgnoreNetcodes = false ) const; /** * Function GetNetItems() @@ -277,28 +274,19 @@ public: * @param aNetCode is the net code. * @param aTypes allows one to filter by item types. */ - const std::vector GetNetItems( int aNetCode, - const KICAD_T aTypes[] ) const; + const std::vector + GetNetItems( int aNetCode, const std::initializer_list& aTypes ) const; void BlockRatsnestItems( const std::vector& aItems ); - std::shared_ptr GetConnectivityAlgo() const - { - return m_connAlgo; - } + std::shared_ptr GetConnectivityAlgo() const { return m_connAlgo; } - KISPINLOCK& GetLock() - { - return m_lock; - } + KISPINLOCK& GetLock() { return m_lock; } void MarkItemNetAsDirty( BOARD_ITEM* aItem ); void SetProgressReporter( PROGRESS_REPORTER* aReporter ); - const std::map& GetNetclassMap() const - { - return m_netclassMap; - } + const std::map& GetNetclassMap() const { return m_netclassMap; } void AddExclusion( const KIID& aBoardItemId1, const KIID& aBoardItemId2 ); void RemoveExclusion( const KIID& aBoardItemId1, const KIID& aBoardItemId2 ); @@ -312,10 +300,7 @@ public: bool aSkipInternalConnections = false ); #endif - std::shared_ptr GetFromToCache() - { - return m_fromToCache; - } + std::shared_ptr GetFromToCache() { return m_fromToCache; } private: void updateRatsnest(); diff --git a/pcbnew/convert_shape_list_to_polygon.cpp b/pcbnew/convert_shape_list_to_polygon.cpp index 52d36ecfc4..58b187cc21 100644 --- a/pcbnew/convert_shape_list_to_polygon.cpp +++ b/pcbnew/convert_shape_list_to_polygon.cpp @@ -846,8 +846,7 @@ bool BuildBoardPolygonOutlines( BOARD* aBoard, SHAPE_POLY_SET& aOutlines, int aE bool success = false; // Get all the PCB and FP shapes into 'items', then keep only those on layer == Edge_Cuts. - static const KICAD_T scan_graphics[] = { PCB_SHAPE_T, PCB_FP_SHAPE_T, EOT }; - items.Collect( aBoard, scan_graphics ); + items.Collect( aBoard, { PCB_SHAPE_T, PCB_FP_SHAPE_T } ); // Make a working copy of aSegList, because the list is modified during calculations std::vector segList; @@ -1072,8 +1071,7 @@ bool BuildFootprintPolygonOutlines( BOARD* aBoard, SHAPE_POLY_SET& aOutlines, in bool success = false; // Get all the SHAPEs into 'items', then keep only those on layer == Edge_Cuts. - static const KICAD_T scan_graphics[] = { PCB_SHAPE_T, PCB_FP_SHAPE_T, EOT }; - items.Collect( aBoard, scan_graphics ); + items.Collect( aBoard, { PCB_SHAPE_T, PCB_FP_SHAPE_T } ); // Make a working copy of aSegList, because the list is modified during calculations std::vector segList; diff --git a/pcbnew/edit_track_width.cpp b/pcbnew/edit_track_width.cpp index 4b00c6c87c..0f1b0995b6 100644 --- a/pcbnew/edit_track_width.cpp +++ b/pcbnew/edit_track_width.cpp @@ -64,14 +64,11 @@ void PCB_EDIT_FRAME::SetTrackSegmentWidth( PCB_TRACK* aTrackItem, new_drill = GetDesignSettings().GetCurrentViaDrill(); } - // Old versions set a drill value <= 0, when the default netclass it used - // but it could be better to set the drill value to the actual value - // to avoid issues for existing vias, if the default drill value is modified - // in the netclass, and not in current vias. + // Old versions set a drill value <= 0, when the default netclass it used but it could + // be better to set the drill value to the actual value to avoid issues for existing vias, + // if the default drill value is modified in the netclass, and not in current vias. if( via->GetDrill() <= 0 ) // means default netclass drill value used - { initial_drill = -1; // Force drill vias re-initialization - } } if( initial_width != new_width || initial_drill != new_drill ) diff --git a/pcbnew/exporters/gendrill_file_writer_base.cpp b/pcbnew/exporters/gendrill_file_writer_base.cpp index 0237ef5dca..bea9a39e42 100644 --- a/pcbnew/exporters/gendrill_file_writer_base.cpp +++ b/pcbnew/exporters/gendrill_file_writer_base.cpp @@ -207,18 +207,12 @@ std::vector GENDRILL_WRITER_BASE::getUniqueLayerPairs() const { wxASSERT( m_pcb ); - static const KICAD_T interesting_stuff_to_collect[] = { - PCB_VIA_T, - EOT - }; - PCB_TYPE_COLLECTOR vias; - vias.Collect( m_pcb, interesting_stuff_to_collect ); + vias.Collect( m_pcb, { PCB_VIA_T } ); - std::set< DRILL_LAYER_PAIR > unique; - - DRILL_LAYER_PAIR layer_pair; + std::set unique; + DRILL_LAYER_PAIR layer_pair; for( int i = 0; i < vias.GetCount(); ++i ) { @@ -229,17 +223,15 @@ std::vector GENDRILL_WRITER_BASE::getUniqueLayerPairs() const // only make note of blind buried. // thru hole is placed unconditionally as first in fetched list. if( layer_pair != DRILL_LAYER_PAIR( F_Cu, B_Cu ) ) - { unique.insert( layer_pair ); - } } - std::vector ret; + std::vector ret; ret.emplace_back( F_Cu, B_Cu ); // always first in returned list - for( std::set::const_iterator it = unique.begin(); it != unique.end(); ++it ) - ret.push_back( *it ); + for( const DRILL_LAYER_PAIR& pair : unique ) + ret.push_back( pair ); return ret; } diff --git a/pcbnew/footprint.cpp b/pcbnew/footprint.cpp index 889eeebfa5..472aaf1e09 100644 --- a/pcbnew/footprint.cpp +++ b/pcbnew/footprint.cpp @@ -1241,50 +1241,51 @@ void FOOTPRINT::Add3DModel( FP_3DMODEL* a3DModel ) // see footprint.h -INSPECT_RESULT FOOTPRINT::Visit( INSPECTOR inspector, void* testData, const KICAD_T scanTypes[] ) +INSPECT_RESULT FOOTPRINT::Visit( INSPECTOR inspector, void* testData, + const std::initializer_list& aScanTypes ) { - KICAD_T stype; - INSPECT_RESULT result = INSPECT_RESULT::CONTINUE; - const KICAD_T* p = scanTypes; - bool done = false; - #if 0 && defined(DEBUG) std::cout << GetClass().mb_str() << ' '; #endif - while( !done ) - { - stype = *p; + bool drawingsScanned = false; - switch( stype ) + for( KICAD_T scanType : aScanTypes ) + { + switch( scanType ) { case PCB_FOOTPRINT_T: - result = inspector( this, testData ); // inspect me - ++p; + if( inspector( this, testData ) == INSPECT_RESULT::QUIT ) + return INSPECT_RESULT::QUIT; + break; case PCB_PAD_T: - result = IterateForward( m_pads, inspector, testData, p ); - ++p; + if( IterateForward( m_pads, inspector, testData, { scanType } ) + == INSPECT_RESULT::QUIT ) + { + return INSPECT_RESULT::QUIT; + } + break; case PCB_FP_ZONE_T: - result = IterateForward( m_fp_zones, inspector, testData, p ); - ++p; + if( IterateForward( m_fp_zones, inspector, testData, { scanType } ) + == INSPECT_RESULT::QUIT ) + { + return INSPECT_RESULT::QUIT; + } + break; case PCB_FP_TEXT_T: - result = inspector( m_reference, testData ); + if( inspector( m_reference, testData ) == INSPECT_RESULT::QUIT ) + return INSPECT_RESULT::QUIT; - if( result == INSPECT_RESULT::QUIT ) - break; + if( inspector( m_value, testData ) == INSPECT_RESULT::QUIT ) + return INSPECT_RESULT::QUIT; - result = inspector( m_value, testData ); - - if( result == INSPECT_RESULT::QUIT ) - break; - - // Intentionally fall through since m_Drawings can hold PCB_FP_SHAPE_T also + // Intentionally fall through since m_Drawings can hold PCB_FP_TEXT_T also KI_FALLTHROUGH; case PCB_FP_DIM_ALIGNED_T: @@ -1294,47 +1295,34 @@ INSPECT_RESULT FOOTPRINT::Visit( INSPECTOR inspector, void* testData, const KICA case PCB_FP_DIM_ORTHOGONAL_T: case PCB_FP_SHAPE_T: case PCB_FP_TEXTBOX_T: - result = IterateForward( m_drawings, inspector, testData, p ); - - // skip over any types handled in the above call. - for( ; ; ) + if( !drawingsScanned ) { - switch( stype = *++p ) + if( IterateForward( m_drawings, inspector, testData, aScanTypes ) + == INSPECT_RESULT::QUIT ) { - case PCB_FP_TEXT_T: - case PCB_FP_TEXTBOX_T: - case PCB_FP_SHAPE_T: - case PCB_FP_DIM_ALIGNED_T: - case PCB_FP_DIM_LEADER_T: - case PCB_FP_DIM_CENTER_T: - case PCB_FP_DIM_RADIAL_T: - case PCB_FP_DIM_ORTHOGONAL_T: - continue; - - default: - ; + return INSPECT_RESULT::QUIT; } - break; + drawingsScanned = true; } break; case PCB_GROUP_T: - result = IterateForward( m_fp_groups, inspector, testData, p ); - ++p; + if( IterateForward( m_fp_groups, inspector, testData, { scanType } ) + == INSPECT_RESULT::QUIT ) + { + return INSPECT_RESULT::QUIT; + } + break; default: - done = true; break; } - - if( result == INSPECT_RESULT::QUIT ) - break; } - return result; + return INSPECT_RESULT::CONTINUE; } diff --git a/pcbnew/footprint.h b/pcbnew/footprint.h index 71d006462d..01df2cf589 100644 --- a/pcbnew/footprint.h +++ b/pcbnew/footprint.h @@ -637,7 +637,8 @@ public: */ void Add3DModel( FP_3DMODEL* a3DModel ); - INSPECT_RESULT Visit( INSPECTOR inspector, void* testData, const KICAD_T scanTypes[] ) override; + INSPECT_RESULT Visit( INSPECTOR inspector, void* testData, + const std::initializer_list& aScanTypes ) override; wxString GetClass() const override { diff --git a/pcbnew/fp_shape.h b/pcbnew/fp_shape.h index 3677afc431..f1a7536c5d 100644 --- a/pcbnew/fp_shape.h +++ b/pcbnew/fp_shape.h @@ -3,7 +3,7 @@ * * Copyright (C) 2018 Jean-Pierre Charras, jp.charras at wanadoo.fr * Copyright (C) 2013 Wayne Stambaugh - * Copyright (C) 1992-2018 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 1992-2022 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 @@ -50,16 +50,16 @@ public: return aItem && PCB_FP_SHAPE_T == aItem->Type(); } - bool IsType( const KICAD_T aScanTypes[] ) const override + bool IsType( const std::initializer_list& aScanTypes ) const override { if( BOARD_ITEM::IsType( aScanTypes ) ) return true; - for( const KICAD_T* p = aScanTypes; *p != EOT; ++p ) + for( KICAD_T scanType : aScanTypes ) { - if( *p == PCB_LOCATE_GRAPHIC_T ) + if( scanType == PCB_LOCATE_GRAPHIC_T ) return true; - else if( *p == PCB_LOCATE_BOARD_EDGE_T ) + else if( scanType == PCB_LOCATE_BOARD_EDGE_T ) return m_layer == Edge_Cuts; } diff --git a/pcbnew/fp_text.h b/pcbnew/fp_text.h index 4cc19ac8a5..7ebfe9539f 100644 --- a/pcbnew/fp_text.h +++ b/pcbnew/fp_text.h @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2004 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com - * Copyright (C) 1992-2021 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 1992-2022 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 @@ -64,14 +64,14 @@ public: return aItem && aItem->Type() == PCB_FP_TEXT_T; } - bool IsType( const KICAD_T aScanTypes[] ) const override + bool IsType( const std::initializer_list& aScanTypes ) const override { if( BOARD_ITEM::IsType( aScanTypes ) ) return true; - for( const KICAD_T* p = aScanTypes; *p != EOT; ++p ) + for( KICAD_T scanType : aScanTypes ) { - if( *p == PCB_LOCATE_TEXT_T ) + if( scanType == PCB_LOCATE_TEXT_T ) return true; } diff --git a/pcbnew/fp_textbox.h b/pcbnew/fp_textbox.h index 8e837ccbda..d190d02664 100644 --- a/pcbnew/fp_textbox.h +++ b/pcbnew/fp_textbox.h @@ -50,14 +50,14 @@ public: return aItem && aItem->Type() == PCB_FP_TEXT_T; } - bool IsType( const KICAD_T aScanTypes[] ) const override + bool IsType( const std::initializer_list& aScanTypes ) const override { if( BOARD_ITEM::IsType( aScanTypes ) ) return true; - for( const KICAD_T* p = aScanTypes; *p != EOT; ++p ) + for( KICAD_T scanType : aScanTypes ) { - if( *p == PCB_LOCATE_TEXT_T ) + if( scanType == PCB_LOCATE_TEXT_T ) return true; } diff --git a/pcbnew/netinfo_item.cpp b/pcbnew/netinfo_item.cpp index 73bd18b579..e5a06293cd 100644 --- a/pcbnew/netinfo_item.cpp +++ b/pcbnew/netinfo_item.cpp @@ -151,20 +151,14 @@ bool NETINFO_ITEM::Matches( const wxFindReplaceData& aSearchData, void* aAuxData const EDA_RECT NETINFO_ITEM::GetBoundingBox() const { - constexpr KICAD_T types[] = { PCB_TRACE_T, PCB_ARC_T, PCB_VIA_T, PCB_ZONE_T, PCB_PAD_T, EOT }; - auto connectivity = GetBoard()->GetConnectivity(); + std::shared_ptr conn = GetBoard()->GetConnectivity(); + EDA_RECT bbox; - std::vector items = connectivity->GetNetItems( m_netCode, types ); - EDA_RECT bbox = EDA_RECT( VECTOR2I( 0, 0 ), VECTOR2I( 0, 0 ) ); - - if( items.size() >= 1 ) + for( BOARD_ITEM* item : conn->GetNetItems( m_netCode, { PCB_TRACE_T, PCB_ARC_T, PCB_VIA_T, + PCB_ZONE_T, PCB_PAD_T } ) ) { - bbox = items.at( 0 )->GetBoundingBox(); - - for( BOARD_CONNECTED_ITEM* item : items ) - { - bbox.Merge( item->GetBoundingBox() ); - } + bbox.Merge( item->GetBoundingBox() ); } + return bbox; } \ No newline at end of file diff --git a/pcbnew/pad.h b/pcbnew/pad.h index a9f17e7d97..a2224ce3f8 100644 --- a/pcbnew/pad.h +++ b/pcbnew/pad.h @@ -82,20 +82,20 @@ public: return aItem && PCB_PAD_T == aItem->Type(); } - bool IsType( const KICAD_T aScanTypes[] ) const override + bool IsType( const std::initializer_list& aScanTypes ) const override { if( BOARD_CONNECTED_ITEM::IsType( aScanTypes ) ) return true; - for( const KICAD_T* p = aScanTypes; *p != EOT; ++p ) + for( KICAD_T scanType : aScanTypes ) { - if( m_drill.x > 0 && m_drill.y > 0 ) + if( HasHole() ) { - if( *p == PCB_LOCATE_HOLE_T ) + if( scanType == PCB_LOCATE_HOLE_T ) return true; - else if( *p == PCB_LOCATE_PTH_T && m_attribute != PAD_ATTRIB::NPTH ) + else if( scanType == PCB_LOCATE_PTH_T && m_attribute != PAD_ATTRIB::NPTH ) return true; - else if( *p == PCB_LOCATE_NPTH_T && m_attribute == PAD_ATTRIB::NPTH ) + else if( scanType == PCB_LOCATE_NPTH_T && m_attribute == PAD_ATTRIB::NPTH ) return true; } } diff --git a/pcbnew/pcb_base_edit_frame.cpp b/pcbnew/pcb_base_edit_frame.cpp index 32e76ab2c1..f0c5a8b028 100644 --- a/pcbnew/pcb_base_edit_frame.cpp +++ b/pcbnew/pcb_base_edit_frame.cpp @@ -240,7 +240,16 @@ void PCB_BASE_EDIT_FRAME::unitsChangeRefresh() return INSPECT_RESULT::CONTINUE; }; - board->Visit( inspector, nullptr, GENERAL_COLLECTOR::Dimensions ); + board->Visit( inspector, nullptr, { PCB_DIM_ALIGNED_T, + PCB_DIM_LEADER_T, + PCB_DIM_ORTHOGONAL_T, + PCB_DIM_CENTER_T, + PCB_DIM_RADIAL_T, + PCB_FP_DIM_ALIGNED_T, + PCB_FP_DIM_LEADER_T, + PCB_FP_DIM_ORTHOGONAL_T, + PCB_FP_DIM_CENTER_T, + PCB_FP_DIM_RADIAL_T } ); if( selectedItemModified ) m_toolManager->PostEvent( EVENTS::SelectedItemsModified ); diff --git a/pcbnew/pcb_dimension.h b/pcbnew/pcb_dimension.h index 8696f7222f..23bfb849fb 100644 --- a/pcbnew/pcb_dimension.h +++ b/pcbnew/pcb_dimension.h @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2004 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com - * Copyright (C) 1992-2021 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 1992-2022 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 @@ -97,14 +97,14 @@ class PCB_DIMENSION_BASE : public BOARD_ITEM public: PCB_DIMENSION_BASE( BOARD_ITEM* aParent, KICAD_T aType = PCB_DIMENSION_T ); - bool IsType( const KICAD_T aScanTypes[] ) const override + bool IsType( const std::initializer_list& aScanTypes ) const override { if( BOARD_ITEM::IsType( aScanTypes ) ) return true; - for( const KICAD_T* p = aScanTypes; *p != EOT; ++p ) + for( KICAD_T scanType : aScanTypes ) { - if( *p == PCB_LOCATE_GRAPHIC_T ) + if( scanType == PCB_LOCATE_GRAPHIC_T ) return true; } diff --git a/pcbnew/pcb_edit_frame.cpp b/pcbnew/pcb_edit_frame.cpp index be2cf44043..f14cb0fdc1 100644 --- a/pcbnew/pcb_edit_frame.cpp +++ b/pcbnew/pcb_edit_frame.cpp @@ -773,18 +773,18 @@ void PCB_EDIT_FRAME::setupUIConditions() mgr->SetConditions( PCB_ACTIONS::highlightNetSelection, ENABLE( SELECTION_CONDITIONS::ShowAlways ) ); mgr->SetConditions( PCB_ACTIONS::selectNet, - ENABLE( SELECTION_CONDITIONS::OnlyTypes( GENERAL_COLLECTOR::Tracks ) ) ); + ENABLE( SELECTION_CONDITIONS::OnlyTypes( { PCB_TRACE_T, PCB_ARC_T, PCB_VIA_T } ) ) ); mgr->SetConditions( PCB_ACTIONS::deselectNet, - ENABLE( SELECTION_CONDITIONS::OnlyTypes( GENERAL_COLLECTOR::Tracks ) ) ); + ENABLE( SELECTION_CONDITIONS::OnlyTypes( { PCB_TRACE_T, PCB_ARC_T, PCB_VIA_T } ) ) ); mgr->SetConditions( PCB_ACTIONS::selectSameSheet, - ENABLE( SELECTION_CONDITIONS::OnlyType( PCB_FOOTPRINT_T ) ) ); + ENABLE( SELECTION_CONDITIONS::OnlyTypes( { PCB_FOOTPRINT_T } ) ) ); SELECTION_CONDITION singleZoneCond = SELECTION_CONDITIONS::Count( 1 ) - && SELECTION_CONDITIONS::OnlyTypes( GENERAL_COLLECTOR::Zones ); + && SELECTION_CONDITIONS::OnlyTypes( { PCB_ZONE_T, PCB_FP_ZONE_T } ); SELECTION_CONDITION zoneMergeCond = SELECTION_CONDITIONS::MoreThan( 1 ) - && SELECTION_CONDITIONS::OnlyTypes( GENERAL_COLLECTOR::Zones ); + && SELECTION_CONDITIONS::OnlyTypes( { PCB_ZONE_T, PCB_FP_ZONE_T } ); mgr->SetConditions( PCB_ACTIONS::zoneDuplicate, ENABLE( singleZoneCond ) ); mgr->SetConditions( PCB_ACTIONS::drawZoneCutout, ENABLE( singleZoneCond ) ); diff --git a/pcbnew/pcb_group.cpp b/pcbnew/pcb_group.cpp index eccc74aeea..2e34a92bb9 100644 --- a/pcbnew/pcb_group.cpp +++ b/pcbnew/pcb_group.cpp @@ -233,12 +233,12 @@ const EDA_RECT PCB_GROUP::GetBoundingBox() const } -INSPECT_RESULT PCB_GROUP::Visit( INSPECTOR aInspector, void* aTestData, const KICAD_T aScanTypes[] ) +INSPECT_RESULT PCB_GROUP::Visit( INSPECTOR aInspector, void* aTestData, + const std::initializer_list& aScanTypes ) { - for( const KICAD_T* stype = aScanTypes; *stype != EOT; ++stype ) + for( KICAD_T scanType : aScanTypes ) { - // If caller wants to inspect my type - if( *stype == Type() ) + if( scanType == Type() ) { if( INSPECT_RESULT::QUIT == aInspector( this, aTestData ) ) return INSPECT_RESULT::QUIT; diff --git a/pcbnew/pcb_shape.h b/pcbnew/pcb_shape.h index 93e7c6a603..71778fd102 100644 --- a/pcbnew/pcb_shape.h +++ b/pcbnew/pcb_shape.h @@ -57,23 +57,23 @@ public: return wxT( "PCB_SHAPE" ); } - bool IsType( const KICAD_T aScanTypes[] ) const override + bool IsType( const std::initializer_list& aScanTypes ) const override { if( BOARD_ITEM::IsType( aScanTypes ) ) return true; - for( const KICAD_T* p = aScanTypes; *p != EOT; ++p ) + for( KICAD_T scanType : aScanTypes ) { - if( *p == PCB_LOCATE_GRAPHIC_T ) + if( scanType == PCB_LOCATE_GRAPHIC_T ) return true; - else if( *p == PCB_LOCATE_BOARD_EDGE_T ) + else if( scanType == PCB_LOCATE_BOARD_EDGE_T ) return m_layer == Edge_Cuts; } return false; } - void SetPosition( const VECTOR2I& aPos ) override { setPosition( aPos ); } + void SetPosition( const VECTOR2I& aPos ) override { setPosition( aPos ); } VECTOR2I GetPosition() const override { return getPosition(); } VECTOR2I GetCenter() const override { return getCenter(); } diff --git a/pcbnew/pcb_text.h b/pcbnew/pcb_text.h index 141540e384..3a4d9a6dda 100644 --- a/pcbnew/pcb_text.h +++ b/pcbnew/pcb_text.h @@ -48,14 +48,14 @@ public: return aItem && PCB_TEXT_T == aItem->Type(); } - bool IsType( const KICAD_T aScanTypes[] ) const override + bool IsType( const std::initializer_list& aScanTypes ) const override { if( BOARD_ITEM::IsType( aScanTypes ) ) return true; - for( const KICAD_T* p = aScanTypes; *p != EOT; ++p ) + for( KICAD_T scanType : aScanTypes ) { - if( *p == PCB_LOCATE_TEXT_T ) + if( scanType == PCB_LOCATE_TEXT_T ) return true; } diff --git a/pcbnew/pcb_textbox.h b/pcbnew/pcb_textbox.h index 108b9e4e78..6c5aaedb14 100644 --- a/pcbnew/pcb_textbox.h +++ b/pcbnew/pcb_textbox.h @@ -48,14 +48,14 @@ public: return aItem && PCB_TEXTBOX_T == aItem->Type(); } - bool IsType( const KICAD_T aScanTypes[] ) const override + bool IsType( const std::initializer_list& aScanTypes ) const override { if( BOARD_ITEM::IsType( aScanTypes ) ) return true; - for( const KICAD_T* p = aScanTypes; *p != EOT; ++p ) + for( KICAD_T scanType : aScanTypes ) { - if( *p == PCB_LOCATE_TEXT_T ) + if( scanType == PCB_LOCATE_TEXT_T ) return true; } diff --git a/pcbnew/pcb_track.cpp b/pcbnew/pcb_track.cpp index a625b31a25..7e44d4ac3a 100644 --- a/pcbnew/pcb_track.cpp +++ b/pcbnew/pcb_track.cpp @@ -369,15 +369,16 @@ void PCB_VIA::Flip( const VECTOR2I& aCentre, bool aFlipLeftRight ) // see class_track.h -INSPECT_RESULT PCB_TRACK::Visit( INSPECTOR inspector, void* testData, const KICAD_T scanTypes[] ) +INSPECT_RESULT PCB_TRACK::Visit( INSPECTOR inspector, void* testData, + const std::initializer_list& aScanTypes ) { - KICAD_T stype = *scanTypes; - - // If caller wants to inspect my type - if( stype == Type() ) + for( KICAD_T scanType : aScanTypes ) { - if( INSPECT_RESULT::QUIT == inspector( this, testData ) ) - return INSPECT_RESULT::QUIT; + if( scanType == Type() ) + { + if( INSPECT_RESULT::QUIT == inspector( this, testData ) ) + return INSPECT_RESULT::QUIT; + } } return INSPECT_RESULT::CONTINUE; diff --git a/pcbnew/pcb_track.h b/pcbnew/pcb_track.h index 9cce10ca53..150da7869c 100644 --- a/pcbnew/pcb_track.h +++ b/pcbnew/pcb_track.h @@ -173,7 +173,8 @@ public: void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector& aList ) override; - INSPECT_RESULT Visit( INSPECTOR inspector, void* testData, const KICAD_T scanTypes[] ) override; + INSPECT_RESULT Visit( INSPECTOR inspector, void* testData, + const std::initializer_list& aScanTypes ) override; bool HitTest( const VECTOR2I& aPosition, int aAccuracy = 0 ) const override; bool HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy = 0 ) const override; @@ -335,18 +336,18 @@ public: // Do not create a copy constructor. The one generated by the compiler is adequate. - bool IsType( const KICAD_T aScanTypes[] ) const override + bool IsType( const std::initializer_list& aScanTypes ) const override { if( BOARD_CONNECTED_ITEM::IsType( aScanTypes ) ) return true; - for( const KICAD_T* p = aScanTypes; *p != EOT; ++p ) + for( KICAD_T scanType : aScanTypes ) { - if( *p == PCB_LOCATE_STDVIA_T && m_viaType == VIATYPE::THROUGH ) + if( scanType == PCB_LOCATE_STDVIA_T && m_viaType == VIATYPE::THROUGH ) return true; - else if( *p == PCB_LOCATE_UVIA_T && m_viaType == VIATYPE::MICROVIA ) + else if( scanType == PCB_LOCATE_UVIA_T && m_viaType == VIATYPE::MICROVIA ) return true; - else if( *p == PCB_LOCATE_BBVIA_T && m_viaType == VIATYPE::BLIND_BURIED ) + else if( scanType == PCB_LOCATE_BBVIA_T && m_viaType == VIATYPE::BLIND_BURIED ) return true; } diff --git a/pcbnew/python/swig/board.i b/pcbnew/python/swig/board.i index 5af76036f4..ccbe807388 100644 --- a/pcbnew/python/swig/board.i +++ b/pcbnew/python/swig/board.i @@ -143,12 +143,6 @@ HANDLE_EXCEPTIONS(BOARD::TracksInNetBetweenPoints) except: self.this = this - # Convert these to lists to keep users from using them to delete - # items in the iterable while looping over it - def GetFootprints(self): return list(self.Footprints()) - def GetDrawings(self): return list(self.Drawings()) - def GetTracks(self): return list(self.Tracks()) - def Save(self,filename): return SaveBoard(filename,self) diff --git a/pcbnew/router/pns_item.cpp b/pcbnew/router/pns_item.cpp index fb3c578049..ededff2dc6 100644 --- a/pcbnew/router/pns_item.cpp +++ b/pcbnew/router/pns_item.cpp @@ -58,9 +58,7 @@ bool ITEM::collideSimple( const ITEM* aOther, const NODE* aNode, bool aDifferent auto checkKeepout = []( const ZONE* aKeepout, const BOARD_ITEM* aOther ) { - constexpr KICAD_T TRACK_TYPES[] = { PCB_ARC_T, PCB_TRACE_T, EOT }; - - if( aKeepout->GetDoNotAllowTracks() && aOther->IsType( TRACK_TYPES ) ) + if( aKeepout->GetDoNotAllowTracks() && aOther->IsType( { PCB_ARC_T, PCB_TRACE_T } ) ) return true; if( aKeepout->GetDoNotAllowVias() && aOther->Type() == PCB_VIA_T ) diff --git a/pcbnew/router/router_tool.cpp b/pcbnew/router/router_tool.cpp index 728f4e078a..97ecffa8c8 100644 --- a/pcbnew/router/router_tool.cpp +++ b/pcbnew/router/router_tool.cpp @@ -1782,10 +1782,8 @@ bool ROUTER_TOOL::CanInlineDrag( int aDragMode ) // DragArcTrack(), so PCB_ARC_T should never occur here. if( item->IsType( GENERAL_COLLECTOR::DraggableItems ) ) { - static const KICAD_T footprints[] = { PCB_FOOTPRINT_T, EOT }; - // Footprints cannot be dragged freely. - if( item->IsType( footprints ) ) + if( item->IsType( { PCB_FOOTPRINT_T } ) ) return !( aDragMode & PNS::DM_FREE_ANGLE ); else return true; diff --git a/pcbnew/specctra_import_export/specctra_export.cpp b/pcbnew/specctra_import_export/specctra_export.cpp index c859a20811..afdb058b51 100644 --- a/pcbnew/specctra_import_export/specctra_export.cpp +++ b/pcbnew/specctra_import_export/specctra_export.cpp @@ -34,7 +34,6 @@ #include #include // DisplayError() #include // EDA_FileSelector() -#include // RotatePoint() #include #include #include // for KiROUND @@ -63,23 +62,19 @@ using namespace DSN; // comment the line #define EXPORT_CUSTOM_PADS_CONVEX_HULL to export CUSTOM pads exact shapes. -// Keep in mind shapes can be non convex polygons with holes (linked to outline) -// that can create issues. +// Shapes can be non convex polygons with holes (linked to outline) that can create issues. // Especially Freerouter does not handle them very well: // - too complex shapes are not accepted, especially shapes with holes (dsn files are not loaded). -// - and Freerouter actually uses something like a convex hull of the shape (that works not very -// well). +// - and Freerouter actually uses something like a convex hull of the shape (that works poorly). // I am guessing non convex polygons with holes linked could create issues with any Router. #define EXPORT_CUSTOM_PADS_CONVEX_HULL -// Add .1 mil to the requested clearances as a safety margin. -// There has been disagreement about interpretation of clearance in the past -// between KiCad and Freerouter, so keep this safetyMargin until the -// disagreement is resolved and stable. Freerouter seems to be moving -// (protected) traces upon loading the DSN file, and even though it seems to sometimes -// add its own 0.1 to the clearances, I believe this is happening after -// the load process (and moving traces) so I am of the opinion this is -// still needed. +// Add .1 mil to the requested clearances as a safety margin. There has been disagreement about +// interpretation of clearance in the past between KiCad and Freerouter, so keep this safetyMargin +// until the disagreement is resolved and stable. Freerouter seems to be moving (protected) +// traces upon loading the DSN file, and even though it seems to sometimes add its own 0.1 to the +// clearances, I believe this is happening after the load process (and moving traces) so I am of +// the opinion this is still needed. static const double safetyMargin = 0.1; @@ -102,20 +97,15 @@ bool PCB_EDIT_FRAME::ExportSpecctraFile( const wxString& aFullFilename ) errorText = ioe.What(); } - // The two calls to FOOTPRINT::Flip() in ExportBoardToSpecctraFile both set the - // modified flag, yet their actions cancel each other out, so it should - // be ok to clear the modify flag. + // The two calls to FOOTPRINT::Flip() in ExportBoardToSpecctraFile both set the modified flag, + // yet their actions cancel each other out, so it should be ok to clear the flag. if( !wasModified ) screen->SetContentModified( false ); if( ok ) - { SetStatusText( wxString( _( "BOARD exported OK." ) ) ); - } else - { DisplayErrorMessage( this, _( "Unable to export, please fix and try again" ), errorText ); - } return ok; } @@ -145,8 +135,8 @@ void ExportBoardToSpecctraFile( BOARD* aBoard, const wxString& aFullFilename ) db.ExportPCB( aFullFilename, true ); db.RevertFOOTPRINTs( aBoard ); - // if an exception is thrown by FromBOARD or ExportPCB(), then - // ~SPECCTRA_DB() will close the file. + // if an exception is thrown by FromBOARD() or ExportPCB(), then ~SPECCTRA_DB() will + // close the file. } catch( ... ) { @@ -158,15 +148,11 @@ void ExportBoardToSpecctraFile( BOARD* aBoard, const wxString& aFullFilename ) namespace DSN { -const KICAD_T SPECCTRA_DB::scanPADs[] = { PCB_PAD_T, EOT }; - -// "specctra reported units" are what we tell the external router that our -// exported lengths are in. - +// "specctra reported units" are what we tell the external router that our exported lengths are in /** - * Convert a distance from Pcbnew internal units to the reported Specctra DSN units - * in floating point format. + * Convert a distance from Pcbnew internal units to the reported Specctra DSN units in floating + * point format. */ static inline double scale( int kicadDist ) { @@ -305,8 +291,7 @@ PADSTACK* SPECCTRA_DB::makePADSTACK( BOARD* aBoard, PAD* aPad ) dsnOffset = mapPt( offset ); - // using '(' or ')' would cause padstack name to be quote wrapped, - // so use other brackets, and {} locks freerouter. + // using () would cause padstack name to be quoted, and {} locks freerouter, so use []. sprintf( offsetTxt, "[%.6g,%.6g]", dsnOffset.x, dsnOffset.y ); uniqifier += offsetTxt; @@ -619,7 +604,7 @@ IMAGE* SPECCTRA_DB::makeIMAGE( BOARD* aBoard, FOOTPRINT* aFootprint ) PCB_TYPE_COLLECTOR fpItems; // get all the FOOTPRINT's pads. - fpItems.Collect( aFootprint, scanPADs ); + fpItems.Collect( aFootprint, { PCB_PAD_T } ); IMAGE* image = new IMAGE( 0 ); @@ -710,10 +695,8 @@ IMAGE* SPECCTRA_DB::makeIMAGE( BOARD* aBoard, FOOTPRINT* aFootprint ) } } - static const KICAD_T scanEDGEs[] = { PCB_FP_SHAPE_T, EOT }; - // get all the FOOTPRINT's FP_SHAPEs and convert those to DSN outlines. - fpItems.Collect( aFootprint, scanEDGEs ); + fpItems.Collect( aFootprint, { PCB_FP_SHAPE_T } ); for( int i = 0; i < fpItems.GetCount(); ++i ) { @@ -1097,29 +1080,20 @@ typedef std::pair STRINGSET_PAIR; void SPECCTRA_DB::FromBOARD( BOARD* aBoard ) { - PCB_TYPE_COLLECTOR items; - - static const KICAD_T scanMODULEs[] = { PCB_FOOTPRINT_T, EOT }; - std::shared_ptr& netSettings = aBoard->GetDesignSettings().m_NetSettings; - // Not all boards are exportable. Check that all reference Ids are unique. - // Unless they are unique, we cannot import the session file which comes - // back to us later from the router. + // Not all boards are exportable. Check that all reference Ids are unique, or we won't be + // able to import the session file which comes back to us later from the router. { - items.Collect( aBoard, scanMODULEs ); + STRINGSET refs; // holds footprint reference designators - STRINGSET refs; // holds footprint reference designators - - for( int i=0; iFootprints() ) { - FOOTPRINT* footprint = (FOOTPRINT*) items[i]; - if( footprint->GetReference() == wxEmptyString ) { - THROW_IO_ERROR( wxString::Format( - _( "Symbol with value of '%s' has empty reference id." ), - footprint->GetValue() ) ); + THROW_IO_ERROR( wxString::Format( _( "Footprint with value of '%s' has an empty " + "reference designator." ), + footprint->GetValue() ) ); } // if we cannot insert OK, that means the reference has been seen before. @@ -1127,9 +1101,9 @@ void SPECCTRA_DB::FromBOARD( BOARD* aBoard ) if( !refpair.second ) // insert failed { - THROW_IO_ERROR( wxString::Format( - _( "Multiple symbols have identical reference IDs of '%s'." ), - footprint->GetReference() ) ); + THROW_IO_ERROR( wxString::Format( _( "Multiple footprints have the reference " + "designator '%s'." ), + footprint->GetReference() ) ); } } } @@ -1139,9 +1113,8 @@ void SPECCTRA_DB::FromBOARD( BOARD* aBoard ) //---------------------------------------------------- { - // specctra wants top physical layer first, then going down to the - // bottom most physical layer in physical sequence. - // @question : why does KiCad not display layers in that order? + // Specctra wants top physical layer first, then going down to the bottom most physical + // layer in physical sequence. buildLayerMaps( aBoard ); @@ -1185,9 +1158,8 @@ void SPECCTRA_DB::FromBOARD( BOARD* aBoard ) //----- & -------------------- { - // tell freerouter to use "tenths of micrometers", - // which is 100 nm resolution. Possibly more resolution is possible - // in freerouter, but it would need testing. + // Tell freerouter to use "tenths of micrometers", which is 100 nm resolution. Possibly + // more resolution is possible in freerouter, but it would need testing. m_pcb->unit->units = T_um; m_pcb->resolution->units = T_um; @@ -1196,9 +1168,8 @@ void SPECCTRA_DB::FromBOARD( BOARD* aBoard ) //----------------------------------------------- { - // Because fillBOUNDARY() can throw an exception, we link in an - // empty boundary so the BOUNDARY does not get lost in the event of - // of an exception. + // Because fillBOUNDARY() can throw an exception, we link in an empty boundary so the + // BOUNDARY does not get lost in the event of of an exception. BOUNDARY* boundary = new BOUNDARY( 0 ); m_pcb->structure->SetBOUNDARY( boundary ); @@ -1220,14 +1191,12 @@ void SPECCTRA_DB::FromBOARD( BOARD* aBoard ) sprintf( rule, "(clearance %.6g)", clearance + safetyMargin ); rules.push_back( rule ); - // On a high density board (a board with 4 mil tracks, 4 mil spacing) - // a typical solder mask clearance will be 2-3 mils. - // This exposes 2 to 3 mils of bare board around each pad, and would - // leave only 1 to 2 mils of solder mask between the solder mask's boundary - // to the edge of any trace within "clearance" of the pad. So we need at least - // 2 mils *extra* clearance for traces which would come near a pad on - // a different net. So if the baseline trace to trace clearance was say 4 mils, then - // the SMD to trace clearance should be at least 6 mils. + // On a high density board (4 mil tracks, 4 mil spacing) a typical solder mask clearance + // will be 2-3 mils. This exposes 2 to 3 mils of bare board around each pad, and would + // leave only 1 to 2 mils of solder mask between the solder mask's boundary and the edge of + // any trace within "clearance" of the pad. So we need at least 2 mils *extra* clearance + // for traces which would come near a pad on a different net. So if the baseline trace to + // trace clearance was 4 mils, then the SMD to trace clearance should be at least 6 mils. double default_smd = clearance + safetyMargin; if( default_smd <= 6.0 ) @@ -1237,9 +1206,9 @@ void SPECCTRA_DB::FromBOARD( BOARD* aBoard ) rules.push_back( rule ); - // Pad to pad spacing on a single SMT part can be closer than our - // clearance, we don't want freerouter complaining about that, so - // output a significantly smaller pad to pad clearance to freerouter. + // Pad to pad spacing on a single SMT part can be closer than our clearance. We don't want + // freerouter complaining about that, so output a significantly smaller pad to pad + // clearance to freerouter. clearance = scale( defaultClearance ) / 4; sprintf( rule, "(clearance %.6g (type smd_smd))", clearance ); @@ -1251,29 +1220,23 @@ void SPECCTRA_DB::FromBOARD( BOARD* aBoard ) { int netlessZones = 0; - static const KICAD_T scanZONEs[] = { PCB_ZONE_T, EOT }; - items.Collect( aBoard, scanZONEs ); - - for( int i = 0; i < items.GetCount(); ++i ) + for( ZONE* zone : aBoard->Zones() ) { - ZONE* item = (ZONE*) items[i]; - - if( item->GetIsRuleArea() ) + if( zone->GetIsRuleArea() ) continue; // Currently, we export only copper layers - if( ! IsCopperLayer( item->GetLayer() ) ) + if( ! IsCopperLayer( zone->GetLayer() ) ) continue; COPPER_PLANE* plane = new COPPER_PLANE( m_pcb->structure ); m_pcb->structure->planes.push_back( plane ); - PATH* mainPolygon = new PATH( plane, T_polygon ); + PATH* mainPolygon = new PATH( plane, T_polygon ); plane->SetShape( mainPolygon ); - - plane->name = TO_UTF8( item->GetNetname() ); + plane->name = TO_UTF8( zone->GetNetname() ); if( plane->name.size() == 0 ) { @@ -1293,14 +1256,14 @@ void SPECCTRA_DB::FromBOARD( BOARD* aBoard ) plane->name = no_net->net_id; } - mainPolygon->layer_id = m_layerIds[ m_kicadLayer2pcb[ item->GetLayer() ] ]; + mainPolygon->layer_id = m_layerIds[ m_kicadLayer2pcb[ zone->GetLayer() ] ]; // Handle the main outlines SHAPE_POLY_SET::ITERATOR iterator; wxPoint startpoint; bool is_first_point = true; - for( iterator = item->IterateWithHoles(); iterator; iterator++ ) + for( iterator = zone->IterateWithHoles(); iterator; iterator++ ) { wxPoint point( iterator->x, iterator->y ); @@ -1333,14 +1296,11 @@ void SPECCTRA_DB::FromBOARD( BOARD* aBoard ) { is_first_point = true; window = new WINDOW( plane ); - plane->AddWindow( window ); cutout = new PATH( window, T_polygon ); - window->SetShape( cutout ); - - cutout->layer_id = m_layerIds[ m_kicadLayer2pcb[ item->GetLayer() ] ]; + cutout->layer_id = m_layerIds[ m_kicadLayer2pcb[ zone->GetLayer() ] ]; } // If the point in this iteration is the last of the contour, the next iteration @@ -1369,32 +1329,26 @@ void SPECCTRA_DB::FromBOARD( BOARD* aBoard ) //------------------------------------- { - static const KICAD_T scanZONEs[] = { PCB_ZONE_T, EOT }; - items.Collect( aBoard, scanZONEs ); - - for( int i = 0; i < items.GetCount(); ++i ) + for( ZONE* zone : aBoard->Zones() ) { - ZONE* item = (ZONE*) items[i]; - - if( !item->GetIsRuleArea() ) + if( !zone->GetIsRuleArea() ) continue; - // keepout areas have a type. types are - // T_place_keepout, T_via_keepout, T_wire_keepout, + // Keepout areas have a type: T_place_keepout, T_via_keepout, T_wire_keepout, // T_bend_keepout, T_elongate_keepout, T_keepout. // Pcbnew knows only T_keepout, T_via_keepout and T_wire_keepout DSN_T keepout_type; - if( item->GetDoNotAllowVias() && item->GetDoNotAllowTracks() ) + if( zone->GetDoNotAllowVias() && zone->GetDoNotAllowTracks() ) keepout_type = T_keepout; - else if( item->GetDoNotAllowVias() ) + else if( zone->GetDoNotAllowVias() ) keepout_type = T_via_keepout; - else if( item->GetDoNotAllowTracks() ) + else if( zone->GetDoNotAllowTracks() ) keepout_type = T_wire_keepout; else keepout_type = T_keepout; - // Now, build keepout polygon on each copper layer where the item + // Now, build keepout polygon on each copper layer where the zone // keepout is living (keepout zones can live on many copper layers) const int copperCount = aBoard->GetCopperLayerCount(); @@ -1403,7 +1357,7 @@ void SPECCTRA_DB::FromBOARD( BOARD* aBoard ) if( layer == copperCount - 1 ) layer = B_Cu; - if( !item->IsOnLayer( PCB_LAYER_ID( layer ) ) ) + if( !zone->IsOnLayer( PCB_LAYER_ID( layer ) ) ) continue; KEEPOUT* keepout = new KEEPOUT( m_pcb->structure, keepout_type ); @@ -1419,7 +1373,7 @@ void SPECCTRA_DB::FromBOARD( BOARD* aBoard ) bool is_first_point = true; wxPoint startpoint; - for( iterator = item->IterateWithHoles(); iterator; iterator++ ) + for( iterator = zone->IterateWithHoles(); iterator; iterator++ ) { wxPoint point( iterator->x, iterator->y ); @@ -1454,10 +1408,8 @@ void SPECCTRA_DB::FromBOARD( BOARD* aBoard ) keepout->AddWindow( window ); cutout = new PATH( window, T_polygon ); - window->SetShape( cutout ); - - cutout->layer_id = m_layerIds[ m_kicadLayer2pcb[ item->GetLayer() ] ]; + cutout->layer_id = m_layerIds[ m_kicadLayer2pcb[ zone->GetLayer() ] ]; } isStartContour = iterator.IsEndContour(); @@ -1485,14 +1437,12 @@ void SPECCTRA_DB::FromBOARD( BOARD* aBoard ) //---------------------------- { - PIN_REF empty( m_pcb->network ); - - std::string componentId; - - // find the highest numbered netCode within the board. + PIN_REF empty( m_pcb->network ); + std::string componentId; int highestNetCode = 0; NETINFO_LIST& netInfo = aBoard->GetNetInfo(); + // find the highest numbered netCode within the board. for( NETINFO_LIST::iterator i = netInfo.begin(); i != netInfo.end(); ++i ) highestNetCode = std::max( highestNetCode, i->GetNetCode() ); @@ -1510,31 +1460,24 @@ void SPECCTRA_DB::FromBOARD( BOARD* aBoard ) m_nets[i->GetNetCode()]->net_id = TO_UTF8( i->GetNetname() ); } - items.Collect( aBoard, scanMODULEs ); - m_padstackset.clear(); - for( int m = 0; m < items.GetCount(); ++m ) + for( FOOTPRINT* footprint : aBoard->Footprints() ) { - FOOTPRINT* footprint = (FOOTPRINT*) items[m]; - - IMAGE* image = makeIMAGE( aBoard, footprint ); + IMAGE* image = makeIMAGE( aBoard, footprint ); componentId = TO_UTF8( footprint->GetReference() ); - // create a net list entry for all the actual pins in the image - // for the current footprint. location of this code is critical - // because we fabricated some pin names to ensure unique-ness - // of pin names within a footprint, do not move this code because - // the life of this 'IMAGE* image' is not necessarily long. The - // exported netlist will have some fabricated pin names in it. - // If you don't like fabricated pin names, then make sure all pads - // within your FOOTPRINTs are uniquely named! + // Create a net list entry for all the actual pins in the current footprint. + // Location of this code is critical because we fabricated some pin names to ensure + // unique-ness within a footprint, and the life of this 'IMAGE* image' is not + // necessarily long. The exported netlist will have some fabricated pin names in it. + // If you don't like fabricated pin names, then make sure all pads within your + // FOOTPRINTs are uniquely named! for( unsigned p = 0; p < image->pins.size(); ++p ) { - PIN* pin = &image->pins[p]; - - int netcode = pin->kiNetCode; + PIN* pin = &image->pins[p]; + int netcode = pin->kiNetCode; if( netcode > 0 ) { @@ -1560,7 +1503,6 @@ void SPECCTRA_DB::FromBOARD( BOARD* aBoard ) } COMPONENT* comp = m_pcb->placement->LookupCOMPONENT( image->GetImageId() ); - PLACE* place = new PLACE( comp ); comp->places.push_back( place ); @@ -1611,7 +1553,6 @@ void SPECCTRA_DB::FromBOARD( BOARD* aBoard ) // This is in lieu of either having each netclass via have its own layer pair in // the netclass dialog, or such control in the specctra export dialog. - m_top_via_layer = 0; // first specctra cu layer is number zero. m_bot_via_layer = aBoard->GetCopperLayerCount()-1; @@ -1647,12 +1588,7 @@ void SPECCTRA_DB::FromBOARD( BOARD* aBoard ) //---------------------------------------- { - // export all of them for now, later we'll decide what controls we need - // on this. - static const KICAD_T scanTRACKs[] = { PCB_TRACE_T, PCB_ARC_T, EOT }; - - items.Collect( aBoard, scanTRACKs ); - + // export all of them for now, later we'll decide what controls we need on this. std::string netname; WIRING* wiring = m_pcb->wiring; PATH* path = 0; @@ -1661,17 +1597,20 @@ void SPECCTRA_DB::FromBOARD( BOARD* aBoard ) int old_width = -1; int old_layer = UNDEFINED_LAYER; - for( int i = 0; i < items.GetCount(); ++i ) + for( PCB_TRACK* track : aBoard->Tracks() ) { - PCB_TRACK* track = static_cast( items[i] ); - int netcode = track->GetNetCode(); + if( !track->IsType( { PCB_TRACE_T, PCB_ARC_T } ) ) + continue; + + int netcode = track->GetNetCode(); if( netcode == 0 ) continue; - if( old_netcode != netcode || old_width != track->GetWidth() || - old_layer != track->GetLayer() || - ( path && path->points.back() != mapPt(track->GetStart() ) ) ) + if( old_netcode != netcode + || old_width != track->GetWidth() + || old_layer != track->GetLayer() + || ( path && path->points.back() != mapPt( track->GetStart() ) ) ) { old_width = track->GetWidth(); old_layer = track->GetLayer(); @@ -1698,12 +1637,9 @@ void SPECCTRA_DB::FromBOARD( BOARD* aBoard ) int pcbLayer = m_kicadLayer2pcb[kiLayer]; path = new PATH( wire ); - wire->SetShape( path ); - path->layer_id = m_layerIds[pcbLayer]; path->aperture_width = scale( old_width ); - path->AppendPoint( mapPt( track->GetStart() ) ); } @@ -1715,15 +1651,12 @@ void SPECCTRA_DB::FromBOARD( BOARD* aBoard ) //---------------------- { // Export all vias, once per unique size and drill diameter combo. - static const KICAD_T scanVIAs[] = { PCB_VIA_T, EOT }; - - items.Collect( aBoard, scanVIAs ); - - for( int i = 0; iTracks() ) { - PCB_VIA* via = static_cast( items[i] ); - wxASSERT( via->Type() == PCB_VIA_T ); + if( track->Type() != PCB_VIA_T ) + continue; + PCB_VIA* via = static_cast( track ); int netcode = via->GetNetCode(); if( netcode == 0 ) @@ -1735,9 +1668,7 @@ void SPECCTRA_DB::FromBOARD( BOARD* aBoard ) // if the one looked up is not our padstack, then delete our padstack // since it was a duplicate of one already registered. if( padstack != registered ) - { delete padstack; - } WIRE_VIA* dsnVia = new WIRE_VIA( m_pcb->wiring ); @@ -1760,18 +1691,16 @@ void SPECCTRA_DB::FromBOARD( BOARD* aBoard ) //------------------------------------------------------ { - // The pcb->library will output which is a combined - // list of part padstacks and via padstacks. specctra dsn uses the - // to say which of those padstacks are vias. + // The pcb->library will output which is a combined list of part + // padstacks and via padstacks. specctra dsn uses the to say which of + // those padstacks are vias. - // Output the vias in the padstack list here, by name only. This must - // be done after exporting existing vias as WIRE_VIAs. + // Output the vias in the padstack list here, by name only. This must be done after + // exporting existing vias as WIRE_VIAs. VIA* vias = m_pcb->structure->via; for( unsigned viaNdx = 0; viaNdx < m_pcb->library->vias.size(); ++viaNdx ) - { vias->AppendVia( m_pcb->library->vias[viaNdx].padstack_id.c_str() ); - } } //--------------------------------------------------------- diff --git a/pcbnew/specctra_import_export/specctra_import.cpp b/pcbnew/specctra_import_export/specctra_import.cpp index 891c77f802..d74f77433d 100644 --- a/pcbnew/specctra_import_export/specctra_import.cpp +++ b/pcbnew/specctra_import_export/specctra_import.cpp @@ -52,13 +52,11 @@ using namespace DSN; bool PCB_EDIT_FRAME::ImportSpecctraSession( const wxString& fullFileName ) { - // To avoid issues with undo/redo lists (dangling pointers) - // clear the lists + // To avoid issues with undo/redo lists (dangling pointers) clear the lists // todo: use undo/redo feature ClearUndoRedoList(); - // Remove existing tracks from view. They will be readded later after loading - // new tracks. + // Remove existing tracks from view. They will be readded later after loading new tracks. if( GetCanvas() ) // clear view: { for( PCB_TRACK* track : GetBoard()->Tracks() ) @@ -113,8 +111,7 @@ namespace DSN { * Function scale * converts a session file distance to KiCad units of deci-mils. * @param distance The session file length to convert. - * @param aResolution The session UNIT_RES which holds the engineering unit - * specifier + * @param aResolution The session UNIT_RES which holds the engineering unit specifier * @return int - The KiCad length in internal unit */ static int scale( double distance, UNIT_RES* aResolution ) @@ -125,26 +122,14 @@ static int scale( double distance, UNIT_RES* aResolution ) switch( aResolution->GetEngUnits() ) { default: - case T_inch: - factor = 25.4e6; // nanometers per inch - break; - case T_mil: - factor = 25.4e3; // nanometers per mil - break; - case T_cm: - factor = 1e7; // nanometers per cm - break; - case T_mm: - factor = 1e6; // nanometers per mm - break; - case T_um: - factor = 1e3; // nanometers per um - break; + case T_inch: factor = 25.4e6; break; // nanometers per inch + case T_mil: factor = 25.4e3; break; // nanometers per mil + case T_cm: factor = 1e7; break; // nanometers per cm + case T_mm: factor = 1e6; break; // nanometers per mm + case T_um: factor = 1e3; break; // nanometers per um } - int ret = KiROUND( factor * distance / resValue ); - - return ret; + return KiROUND( factor * distance / resValue ); } @@ -257,9 +242,12 @@ PCB_VIA* SPECCTRA_DB::makeVIA( WIRE_VIA*aVia, PADSTACK* aPadstack, const POINT& { shape = (SHAPE*) (*aPadstack)[0]; DSN_T type = shape->shape->Type(); + if( type != T_circle ) - THROW_IO_ERROR( - wxString::Format( _( "Unsupported via shape: %s" ), GetTokenString( type ) ) ); + { + THROW_IO_ERROR( wxString::Format( _( "Unsupported via shape: %s" ), + GetTokenString( type ) ) ); + } CIRCLE* circle = (CIRCLE*) shape->shape; int viaDiam = scale( circle->diameter, m_routeResolution ); @@ -282,9 +270,12 @@ PCB_VIA* SPECCTRA_DB::makeVIA( WIRE_VIA*aVia, PADSTACK* aPadstack, const POINT& { shape = (SHAPE*) (*aPadstack)[i]; DSN_T type = shape->shape->Type(); + if( type != T_circle ) - THROW_IO_ERROR( wxString::Format( - _( "Unsupported via shape: %s" ), GetTokenString( type ) ) ); + { + THROW_IO_ERROR( wxString::Format( _( "Unsupported via shape: %s" ), + GetTokenString( type ) ) ); + } CIRCLE* circle = (CIRCLE*) shape->shape; @@ -292,8 +283,8 @@ PCB_VIA* SPECCTRA_DB::makeVIA( WIRE_VIA*aVia, PADSTACK* aPadstack, const POINT& if( layerNdx == -1 ) { wxString layerName = FROM_UTF8( circle->layer_id.c_str() ); - THROW_IO_ERROR( wxString::Format( - _( "Session file uses invalid layer id \"%s\"" ), layerName ) ); + THROW_IO_ERROR( wxString::Format( _( "Session file uses invalid layer id '%s'" ), + layerName ) ); } if( layerNdx > topLayerNdx ) @@ -310,18 +301,18 @@ PCB_VIA* SPECCTRA_DB::makeVIA( WIRE_VIA*aVia, PADSTACK* aPadstack, const POINT& via->SetPosition( mapPt( aPoint, m_routeResolution ) ); via->SetDrill( drill_diam_iu ); - if( (topLayerNdx==0 && botLayerNdx==1) - || (topLayerNdx==copperLayerCount-2 && botLayerNdx==copperLayerCount-1)) + if( ( topLayerNdx == 0 && botLayerNdx == 1 ) + || ( topLayerNdx == copperLayerCount-2 && botLayerNdx == copperLayerCount-1 ) ) + { via->SetViaType( VIATYPE::MICROVIA ); + } else + { via->SetViaType( VIATYPE::BLIND_BURIED ); + } via->SetWidth( viaDiam ); - - PCB_LAYER_ID topLayer = m_pcbLayer2kicad[topLayerNdx]; - PCB_LAYER_ID botLayer = m_pcbLayer2kicad[botLayerNdx]; - - via->SetLayerPair( topLayer, botLayer ); + via->SetLayerPair( m_pcbLayer2kicad[ topLayerNdx ], m_pcbLayer2kicad[ botLayerNdx ] ); } wxASSERT( via ); @@ -356,8 +347,7 @@ void SPECCTRA_DB::FromSESSION( BOARD* aBoard ) if( !m_session->route->library ) THROW_IO_ERROR( _("Session file is missing the \"library_out\" section") ); - // delete all the old tracks and vias but save locked tracks/vias - // they will be re-added later + // delete the old tracks and vias but save locked tracks/vias; they will be re-added later std::vector locked; while( !aBoard->Tracks().empty() ) @@ -378,9 +368,7 @@ void SPECCTRA_DB::FromSESSION( BOARD* aBoard ) // Add locked tracks: because they are exported as Fix tracks, they are not // in .ses file. for( PCB_TRACK* track: locked ) - { aBoard->Add( track ); - } if( m_session->placement ) { @@ -388,6 +376,7 @@ void SPECCTRA_DB::FromSESSION( BOARD* aBoard ) // each COMPONENT, reposition and re-orient each component and put on // correct side of the board. COMPONENTS& components = m_session->placement->components; + for( COMPONENTS::iterator comp=components.begin(); comp!=components.end(); ++comp ) { PLACES& places = comp->places; @@ -462,13 +451,7 @@ void SPECCTRA_DB::FromSESSION( BOARD* aBoard ) NETINFO_ITEM* netinfo = aBoard->FindNet( netName ); if( netinfo ) - { netoutCode = netinfo->GetNetCode(); - } - else // else netCode remains 0 - { - // int breakhere = 1; - } } WIRES& wires = net->wires; @@ -479,17 +462,16 @@ void SPECCTRA_DB::FromSESSION( BOARD* aBoard ) if( shape != T_path ) { - /* shape == T_polygon is expected from freerouter if you have - a zone on a non "power" type layer, i.e. a T_signal layer - and the design does a round trip back in as session here. - We kept our own zones in the BOARD, so ignore this so called - 'wire'. + /* + * shape == T_polygon is expected from freerouter if you have a zone on a non- + * "power" type layer, i.e. a T_signal layer and the design does a round-trip + * back in as session here. We kept our own zones in the BOARD, so ignore this + * so called 'wire'. wxString netId = FROM_UTF8( wire->net_id.c_str() ); - THROW_IO_ERROR( wxString::Format( _("Unsupported wire shape: '%s' for net: '%s'"), + THROW_IO_ERROR( wxString::Format( _( "Unsupported wire shape: '%s' for net: '%s'" ), DLEX::GetTokenString(shape).GetData(), - netId.GetData() - ) ); + netId.GetData() ) ); */ } else @@ -506,6 +488,7 @@ void SPECCTRA_DB::FromSESSION( BOARD* aBoard ) WIRE_VIAS& wire_vias = net->wire_vias; LIBRARY& library = *m_session->route->library; + for( unsigned i=0; iGetNetCode(); - - // else netCode remains 0 } WIRE_VIA* wire_via = &wire_vias[i]; @@ -530,16 +511,11 @@ void SPECCTRA_DB::FromSESSION( BOARD* aBoard ) if( !padstack ) { // Dick Feb 29, 2008: - // Freerouter has a bug where it will not round trip all vias. - // Vias which have a (use_via) element will be round tripped. - // Vias which do not, don't come back in in the session library, - // even though they may be actually used in the pre-routed, - // protected wire_vias. So until that is fixed, create the - // padstack from its name as a work around. - - - // Could use a STRING_FORMATTER here and convert the entire - // wire_via to text and put that text into the exception. + // Freerouter has a bug where it will not round trip all vias. Vias which have + // a (use_via) element will be round tripped. Vias which do not, don't come back + // in in the session library, even though they may be actually used in the + // pre-routed, protected wire_vias. So until that is fixed, create the padstack + // from its name as a work around. wxString psid( FROM_UTF8( wire_via->GetPadstackId().c_str() ) ); THROW_IO_ERROR( wxString::Format( _( "A wire_via refers to missing padstack '%s'." ), diff --git a/pcbnew/tools/board_editor_control.cpp b/pcbnew/tools/board_editor_control.cpp index a95a7406c1..15cfc1a40b 100644 --- a/pcbnew/tools/board_editor_control.cpp +++ b/pcbnew/tools/board_editor_control.cpp @@ -211,7 +211,7 @@ bool BOARD_EDITOR_CONTROL::Init() menu.AddMenu( lockMenu.get(), SELECTION_CONDITIONS::NotEmpty, 100 ); - menu.AddMenu( zoneMenu.get(), SELECTION_CONDITIONS::OnlyType( PCB_ZONE_T ), 200 ); + menu.AddMenu( zoneMenu.get(), SELECTION_CONDITIONS::OnlyTypes( { PCB_ZONE_T } ), 200 ); } DRAWING_TOOL* drawingTool = m_toolMgr->GetTool(); @@ -680,16 +680,16 @@ int BOARD_EDITOR_CONTROL::TogglePythonConsole( const TOOL_EVENT& aEvent ) int BOARD_EDITOR_CONTROL::TrackWidthInc( const TOOL_EVENT& aEvent ) { BOARD_DESIGN_SETTINGS& designSettings = getModel()->GetDesignSettings(); - constexpr KICAD_T types[] = { PCB_TRACE_T, PCB_VIA_T, EOT }; PCB_SELECTION& selection = m_toolMgr->GetTool()->GetSelection(); - if( m_frame->ToolStackIsEmpty() && SELECTION_CONDITIONS::OnlyTypes( types )( selection ) ) + if( m_frame->ToolStackIsEmpty() + && SELECTION_CONDITIONS::OnlyTypes( { PCB_TRACE_T, PCB_ARC_T, PCB_VIA_T } )( selection ) ) { BOARD_COMMIT commit( this ); for( EDA_ITEM* item : selection ) { - if( item->Type() == PCB_TRACE_T ) + if( item->IsType( { PCB_TRACE_T, PCB_ARC_T } ) ) { PCB_TRACK* track = static_cast( item ); @@ -715,7 +715,7 @@ int BOARD_EDITOR_CONTROL::TrackWidthInc( const TOOL_EVENT& aEvent ) ROUTER_TOOL* routerTool = m_toolMgr->GetTool(); if( routerTool && routerTool->IsToolActive() - && routerTool->Router()->Mode() == PNS::PNS_MODE_ROUTE_DIFF_PAIR ) + && routerTool->Router()->Mode() == PNS::PNS_MODE_ROUTE_DIFF_PAIR ) { int widthIndex = designSettings.GetDiffPairIndex() + 1; @@ -760,16 +760,16 @@ int BOARD_EDITOR_CONTROL::TrackWidthInc( const TOOL_EVENT& aEvent ) int BOARD_EDITOR_CONTROL::TrackWidthDec( const TOOL_EVENT& aEvent ) { BOARD_DESIGN_SETTINGS& designSettings = getModel()->GetDesignSettings(); - constexpr KICAD_T types[] = { PCB_TRACE_T, PCB_VIA_T, EOT }; PCB_SELECTION& selection = m_toolMgr->GetTool()->GetSelection(); - if( m_frame->ToolStackIsEmpty() && SELECTION_CONDITIONS::OnlyTypes( types )( selection ) ) + if( m_frame->ToolStackIsEmpty() + && SELECTION_CONDITIONS::OnlyTypes( { PCB_TRACE_T, PCB_ARC_T, PCB_VIA_T } )( selection ) ) { BOARD_COMMIT commit( this ); for( EDA_ITEM* item : selection ) { - if( item->Type() == PCB_TRACE_T ) + if( item->IsType( { PCB_TRACE_T, PCB_ARC_T } ) ) { PCB_TRACK* track = static_cast( item ); @@ -840,10 +840,10 @@ int BOARD_EDITOR_CONTROL::TrackWidthDec( const TOOL_EVENT& aEvent ) int BOARD_EDITOR_CONTROL::ViaSizeInc( const TOOL_EVENT& aEvent ) { BOARD_DESIGN_SETTINGS& designSettings = getModel()->GetDesignSettings(); - constexpr KICAD_T types[] = { PCB_TRACE_T, PCB_VIA_T, EOT }; PCB_SELECTION& selection = m_toolMgr->GetTool()->GetSelection(); - if( m_frame->ToolStackIsEmpty() && SELECTION_CONDITIONS::OnlyTypes( types )( selection ) ) + if( m_frame->ToolStackIsEmpty() + && SELECTION_CONDITIONS::OnlyTypes( { PCB_TRACE_T, PCB_ARC_T, PCB_VIA_T } )( selection ) ) { BOARD_COMMIT commit( this ); @@ -889,10 +889,10 @@ int BOARD_EDITOR_CONTROL::ViaSizeInc( const TOOL_EVENT& aEvent ) int BOARD_EDITOR_CONTROL::ViaSizeDec( const TOOL_EVENT& aEvent ) { BOARD_DESIGN_SETTINGS& designSettings = getModel()->GetDesignSettings(); - constexpr KICAD_T types[] = { PCB_TRACE_T, PCB_VIA_T, EOT }; PCB_SELECTION& selection = m_toolMgr->GetTool()->GetSelection(); - if( m_frame->ToolStackIsEmpty() && SELECTION_CONDITIONS::OnlyTypes( types )( selection ) ) + if( m_frame->ToolStackIsEmpty() + && SELECTION_CONDITIONS::OnlyTypes( { PCB_TRACE_T, PCB_ARC_T, PCB_VIA_T } )( selection ) ) { BOARD_COMMIT commit( this ); diff --git a/pcbnew/tools/board_inspection_tool.cpp b/pcbnew/tools/board_inspection_tool.cpp index a3c25ac3b8..44137f76cf 100644 --- a/pcbnew/tools/board_inspection_tool.cpp +++ b/pcbnew/tools/board_inspection_tool.cpp @@ -79,8 +79,11 @@ bool BOARD_INSPECTION_TOOL::Init() auto netSubMenu = std::make_shared(); netSubMenu->SetTool( this ); - static KICAD_T connectedTypes[] = { PCB_TRACE_T, PCB_VIA_T, PCB_ARC_T, PCB_PAD_T, PCB_ZONE_T, - EOT }; + static std::initializer_list connectedTypes = { PCB_TRACE_T, + PCB_VIA_T, + PCB_ARC_T, + PCB_PAD_T, + PCB_ZONE_T }; CONDITIONAL_MENU& menu = selectionTool->GetToolMenu().GetMenu(); @@ -1342,10 +1345,11 @@ int BOARD_INSPECTION_TOOL::HighlightItem( const TOOL_EVENT& aEvent ) guide.SetPreferredLayer( activeLayer ); GENERAL_COLLECTOR collector; - collector.Collect( board, GENERAL_COLLECTOR::PadsOrTracks, aPosition, guide ); + collector.Collect( board, { PCB_PAD_T, PCB_VIA_T, PCB_TRACE_T, PCB_ARC_T }, aPosition, + guide ); if( collector.GetCount() == 0 ) - collector.Collect( board, GENERAL_COLLECTOR::Zones, aPosition, guide ); + collector.Collect( board, { PCB_ZONE_T, PCB_FP_ZONE_T }, aPosition, guide ); // Apply the active selection filter, except we want to allow picking locked items for // highlighting even if the user has disabled them for selection diff --git a/pcbnew/tools/convert_tool.cpp b/pcbnew/tools/convert_tool.cpp index 016f3dd39a..63fef2cdb4 100644 --- a/pcbnew/tools/convert_tool.cpp +++ b/pcbnew/tools/convert_tool.cpp @@ -150,27 +150,22 @@ bool CONVERT_TOOL::Init() m_menu->SetIcon( BITMAPS::convert ); m_menu->SetTitle( _( "Create from Selection" ) ); - static KICAD_T convertibleTracks[] = { PCB_TRACE_T, PCB_ARC_T, EOT }; - static KICAD_T zones[] = { PCB_ZONE_T, PCB_FP_ZONE_T, EOT }; - - auto graphicLines = P_S_C::OnlyGraphicShapeTypes( { SHAPE_T::SEGMENT, - SHAPE_T::RECT, - SHAPE_T::CIRCLE, - SHAPE_T::ARC } ) + auto graphicLines = P_S_C::OnlyGraphicShapeTypes( { SHAPE_T::SEGMENT, SHAPE_T::RECT, + SHAPE_T::CIRCLE, SHAPE_T::ARC } ) && P_S_C::SameLayer(); auto graphicToTrack = P_S_C::OnlyGraphicShapeTypes( { SHAPE_T::SEGMENT, SHAPE_T::ARC } ); - auto trackLines = S_C::MoreThan( 1 ) && S_C::OnlyTypes( convertibleTracks ) - && P_S_C::SameLayer(); + auto trackLines = S_C::MoreThan( 1 ) && S_C::OnlyTypes( { PCB_TRACE_T, PCB_ARC_T } ) + && P_S_C::SameLayer(); - auto anyLines = graphicLines || trackLines; - auto anyPolys = S_C::OnlyTypes( zones ) + auto anyLines = graphicLines || trackLines; + auto anyPolys = S_C::OnlyTypes( { PCB_ZONE_T, PCB_FP_ZONE_T } ) || P_S_C::OnlyGraphicShapeTypes( { SHAPE_T::POLY, SHAPE_T::RECT } ); auto lineToArc = S_C::Count( 1 ) && ( P_S_C::OnlyGraphicShapeTypes( { SHAPE_T::SEGMENT } ) - || S_C::OnlyType( PCB_TRACE_T ) ); + || S_C::OnlyTypes( { PCB_TRACE_T } ) ); auto showConvert = anyPolys || anyLines || lineToArc; auto canCreatePolyType = anyLines || anyPolys; diff --git a/pcbnew/tools/drawing_stackup_table_tool.cpp b/pcbnew/tools/drawing_stackup_table_tool.cpp index 7e4caff650..cf5e14df13 100644 --- a/pcbnew/tools/drawing_stackup_table_tool.cpp +++ b/pcbnew/tools/drawing_stackup_table_tool.cpp @@ -100,7 +100,6 @@ static std::vector initTextTable( std::vector= nbRows ) break; @@ -109,7 +108,6 @@ static std::vector initTextTable( std::vector height ? rowHeight[j] : height; colWidth[i] = colWidth[i] > width ? colWidth[i] : width; j++; - } i++; @@ -132,20 +130,16 @@ static std::vector initTextTable( std::vectorSetLayer( aLayer ); - line->SetStartX( origin.x ); - line->SetStartY( y ); - line->SetEndX( origin.x + width ); - line->SetEndY( y ); + line->SetStart( VECTOR2I( origin.x, y ) ); + line->SetEnd( VECTOR2I( origin.x + width, y ) ); y += rowHeight[i]; table.push_back( line ); } line = new PCB_SHAPE; line->SetLayer( aLayer ); - line->SetStartX( origin.x ); - line->SetStartY( y ); - line->SetEndX( origin.x + width ); - line->SetEndY( y ); + line->SetStart( VECTOR2I( origin.x, y ) ); + line->SetEnd( VECTOR2I( origin.x + width, y ) ); table.push_back( line ); int x = origin.x; @@ -153,20 +147,16 @@ static std::vector initTextTable( std::vectorSetLayer( aLayer ); - line->SetStartX( x ); - line->SetStartY( origin.y ); - line->SetEndX( x ); - line->SetEndY( origin.y + height ); + line->SetStart( VECTOR2I( x, origin.y ) ); + line->SetEnd( VECTOR2I( x, origin.y + height ) ); x += colWidth[i]; table.push_back( line ); } line = new PCB_SHAPE; line->SetLayer( aLayer ); - line->SetStartX( x ); - line->SetStartY( origin.y ); - line->SetEndX( x ); - line->SetEndY( origin.y + height ); + line->SetStart( VECTOR2I( x, origin.y ) ); + line->SetEnd( VECTOR2I( x, origin.y + height ) ); table.push_back( line ); } @@ -198,6 +188,7 @@ static std::vector initTextTable( std::vector DRAWING_TOOL::DrawSpecificationStackup( const VECTOR2I& ly_name = m_frame->GetBoard()->GetLayerName( stackup_item->GetBrdLayerId() ); if( ly_name.IsEmpty() && stackup_item->GetType() == BS_ITEM_TYPE_DIELECTRIC ) - ly_name = _( "Dielectric" ); + ly_name = _( "Dielectric" ); t->SetText( ly_name ); } @@ -536,7 +527,7 @@ std::vector DRAWING_TOOL::DrawBoardCharacteristics( const VECTOR2I& if( aDrawNow ) { - for( auto item : objects ) + for( BOARD_ITEM* item : objects ) commit.Add( item ); commit.Push( wxT( "Board Characteristics" ) ); @@ -699,18 +690,17 @@ int DRAWING_TOOL::PlaceCharacteristics( const TOOL_EVENT& aEvent ) { VECTOR2I tableSize; - LSET layerSet = ( layerSet.AllCuMask() | layerSet.AllTechMask() ); - layerSet = static_cast( layerSet.set( Edge_Cuts ).set( Margin ) ); - layerSet = static_cast( layerSet.reset( F_Fab ).reset( B_Fab ) ); + LSET layerSet = ( layerSet.AllCuMask() | layerSet.AllTechMask() ); + layerSet = layerSet.set( Edge_Cuts ).set( Margin ); + layerSet = layerSet.reset( F_Fab ).reset( B_Fab ); PCB_LAYER_ID layer = m_frame->GetActiveLayer(); if( ( layerSet & LSET( layer ) ).count() ) // if layer is a forbidden layer m_frame->SetActiveLayer( Cmts_User ); - std::vector table = DrawBoardCharacteristics( wxPoint( 0, 0 ), - m_frame->GetActiveLayer(), false, - &tableSize ); + std::vector table = DrawBoardCharacteristics( { 0, 0 }, m_frame->GetActiveLayer(), + false, &tableSize ); std::vector preview; std::vector items; @@ -719,25 +709,17 @@ int DRAWING_TOOL::PlaceCharacteristics( const TOOL_EVENT& aEvent ) PCB_SHAPE* line3 = new PCB_SHAPE; PCB_SHAPE* line4 = new PCB_SHAPE; - line1->SetStartX( 0 ); - line1->SetStartY( 0 ); - line1->SetEndX( tableSize.x ); - line1->SetEndY( 0 ); + line1->SetStart( VECTOR2I( 0, 0 ) ); + line1->SetEnd( VECTOR2I( tableSize.x, 0 ) ); - line2->SetStartX( 0 ); - line2->SetStartY( 0 ); - line2->SetEndX( 0 ); - line2->SetEndY( tableSize.y ); + line2->SetStart( VECTOR2I( 0, 0 ) ); + line2->SetEnd( VECTOR2I( 0, tableSize.y ) ); - line3->SetStartX( tableSize.x ); - line3->SetStartY( 0 ); - line3->SetEndX( tableSize.x ); - line3->SetEndY( tableSize.y ); + line3->SetStart( VECTOR2I( tableSize.x, 0 ) ); + line3->SetEnd( tableSize ); - line4->SetStartX( 0 ); - line4->SetStartY( tableSize.y ); - line4->SetEndX( tableSize.x ); - line4->SetEndY( tableSize.y ); + line4->SetStart( VECTOR2I( 0, tableSize.y ) ); + line4->SetEnd( tableSize ); line1->SetLayer( m_frame->GetActiveLayer() ); line2->SetLayer( m_frame->GetActiveLayer() ); @@ -770,9 +752,9 @@ int DRAWING_TOOL::PlaceStackup( const TOOL_EVENT& aEvent ) { VECTOR2I tableSize; - LSET layerSet = ( layerSet.AllCuMask() | layerSet.AllTechMask() ); - layerSet = static_cast( layerSet.set( Edge_Cuts ).set( Margin ) ); - layerSet = static_cast( layerSet.reset( F_Fab ).reset( B_Fab ) ); + LSET layerSet = ( layerSet.AllCuMask() | layerSet.AllTechMask() ); + layerSet = layerSet.set( Edge_Cuts ).set( Margin ); + layerSet = layerSet.reset( F_Fab ).reset( B_Fab ); PCB_LAYER_ID layer = m_frame->GetActiveLayer(); PCB_LAYER_ID savedLayer = layer; @@ -794,25 +776,17 @@ int DRAWING_TOOL::PlaceStackup( const TOOL_EVENT& aEvent ) PCB_SHAPE* line3 = new PCB_SHAPE; PCB_SHAPE* line4 = new PCB_SHAPE; - line1->SetStartX( 0 ); - line1->SetStartY( 0 ); - line1->SetEndX( tableSize.x ); - line1->SetEndY( 0 ); + line1->SetStart( VECTOR2I( 0, 0 ) ); + line1->SetEnd( VECTOR2I( tableSize.x, 0 ) ); - line2->SetStartX( 0 ); - line2->SetStartY( 0 ); - line2->SetEndX( 0 ); - line2->SetEndY( tableSize.y ); + line2->SetStart( VECTOR2I( 0, 0 ) ); + line2->SetEnd( VECTOR2I( 0, tableSize.y ) ); - line3->SetStartX( tableSize.x ); - line3->SetStartY( 0 ); - line3->SetEndX( tableSize.x ); - line3->SetEndY( tableSize.y ); + line3->SetStart( VECTOR2I( tableSize.x, 0 ) ); + line3->SetEnd( tableSize ); - line4->SetStartX( 0 ); - line4->SetStartY( tableSize.y ); - line4->SetEndX( tableSize.x ); - line4->SetEndY( tableSize.y ); + line4->SetStart( VECTOR2I( 0, tableSize.y ) ); + line4->SetEnd( tableSize ); line1->SetLayer( m_frame->GetActiveLayer() ); line2->SetLayer( m_frame->GetActiveLayer() ); @@ -825,7 +799,7 @@ int DRAWING_TOOL::PlaceStackup( const TOOL_EVENT& aEvent ) preview.push_back( line4 ); PCB_GROUP* group = new PCB_GROUP( m_board ); - group->SetName("group-boardStackUp"); + group->SetName( "group-boardStackUp" ); for( BOARD_ITEM* item : table ) group->AddItem( item ); diff --git a/pcbnew/tools/edit_tool.cpp b/pcbnew/tools/edit_tool.cpp index 8eb8c0c213..408998b00c 100644 --- a/pcbnew/tools/edit_tool.cpp +++ b/pcbnew/tools/edit_tool.cpp @@ -139,7 +139,7 @@ bool EDIT_TOOL::Init() return m_isFootprintEditor; }; - auto singleFootprintCondition = SELECTION_CONDITIONS::OnlyType( PCB_FOOTPRINT_T ) + auto singleFootprintCondition = SELECTION_CONDITIONS::OnlyTypes( { PCB_FOOTPRINT_T } ) && SELECTION_CONDITIONS::Count( 1 ); auto noActiveToolCondition = @@ -167,13 +167,13 @@ bool EDIT_TOOL::Init() menu.AddItem( PCB_ACTIONS::move, SELECTION_CONDITIONS::NotEmpty && notMovingCondition ); menu.AddItem( PCB_ACTIONS::breakTrack, SELECTION_CONDITIONS::Count( 1 ) - && SELECTION_CONDITIONS::OnlyTypes( GENERAL_COLLECTOR::Tracks ) ); + && SELECTION_CONDITIONS::OnlyTypes( { PCB_TRACE_T, PCB_ARC_T, PCB_VIA_T } ) ); menu.AddItem( PCB_ACTIONS::drag45Degree, SELECTION_CONDITIONS::Count( 1 ) && SELECTION_CONDITIONS::OnlyTypes( GENERAL_COLLECTOR::DraggableItems ) ); menu.AddItem( PCB_ACTIONS::dragFreeAngle, SELECTION_CONDITIONS::Count( 1 ) && SELECTION_CONDITIONS::OnlyTypes( GENERAL_COLLECTOR::DraggableItems ) - && !SELECTION_CONDITIONS::OnlyType( PCB_FOOTPRINT_T ) ); - menu.AddItem( PCB_ACTIONS::filletTracks, SELECTION_CONDITIONS::OnlyTypes( GENERAL_COLLECTOR::Tracks ) ); + && !SELECTION_CONDITIONS::OnlyTypes( { PCB_FOOTPRINT_T } ) ); + menu.AddItem( PCB_ACTIONS::filletTracks, SELECTION_CONDITIONS::OnlyTypes( { PCB_TRACE_T, PCB_ARC_T, PCB_VIA_T } ) ); menu.AddItem( PCB_ACTIONS::rotateCcw, SELECTION_CONDITIONS::NotEmpty ); menu.AddItem( PCB_ACTIONS::rotateCw, SELECTION_CONDITIONS::NotEmpty ); menu.AddItem( PCB_ACTIONS::flip, SELECTION_CONDITIONS::NotEmpty ); @@ -295,14 +295,16 @@ int EDIT_TOOL::Drag( const TOOL_EVENT& aEvent ) // drop a knee between two segments to a single segment if( aCollector.GetCount() == 2 && dynamic_cast( aCollector[0] ) ) { - static KICAD_T types[] = { PCB_VIA_T, PCB_TRACE_T, PCB_ARC_T, EOT }; - PCB_TRACK* a = static_cast( aCollector[0] ); PCB_TRACK* b = static_cast( aCollector[1] ); const auto& c = aCollector[0]->GetBoard()->GetConnectivity(); int dist = a->GetWidth() / 2; - auto connectedItems = c->GetConnectedItemsAtAnchor( a, aPt, types, dist ); + auto connectedItems = c->GetConnectedItemsAtAnchor( a, aPt, + { PCB_VIA_T, + PCB_TRACE_T, + PCB_ARC_T }, + dist ); if( alg::contains( connectedItems, b ) ) aCollector.Remove( b ); @@ -366,12 +368,10 @@ int EDIT_TOOL::DragArcTrack( const TOOL_EVENT& aEvent ) tanEnd.A = tanIntersect; tanEnd.B = theArc->GetEnd(); - KICAD_T track_types[] = { PCB_PAD_T, PCB_VIA_T, PCB_TRACE_T, PCB_ARC_T, EOT }; - auto getUniqueTrackAtAnchorCollinear = [&]( const VECTOR2I& aAnchor, const SEG& aCollinearSeg ) -> PCB_TRACK* { - auto conn = board()->GetConnectivity(); + std::shared_ptr conn = board()->GetConnectivity(); // Allow items at a distance within the width of the arc track int allowedDeviation = theArc->GetWidth(); @@ -380,7 +380,9 @@ int EDIT_TOOL::DragArcTrack( const TOOL_EVENT& aEvent ) for( int i = 0; i < 3; i++ ) { - itemsOnAnchor = conn->GetConnectedItemsAtAnchor( theArc, aAnchor, track_types, + itemsOnAnchor = conn->GetConnectedItemsAtAnchor( theArc, aAnchor, + { PCB_PAD_T, PCB_VIA_T, + PCB_TRACE_T, PCB_ARC_T }, allowedDeviation ); allowedDeviation /= 2; @@ -797,14 +799,13 @@ int EDIT_TOOL::FilletTracks( const TOOL_EVENT& aEvent ) }; std::vector filletOperations; - KICAD_T track_types[] = { PCB_PAD_T, PCB_VIA_T, PCB_TRACE_T, PCB_ARC_T, EOT }; bool operationPerformedOnAtLeastOne = false; bool didOneAttemptFail = false; std::set processedTracks; - for( auto it = selection.begin(); it != selection.end(); it++ ) + for( EDA_ITEM* item : selection ) { - PCB_TRACK* track = dyn_cast( *it ); + PCB_TRACK* track = dyn_cast( item ); if( !track || track->Type() != PCB_TRACE_T || track->GetLength() == 0 ) { @@ -814,10 +815,14 @@ int EDIT_TOOL::FilletTracks( const TOOL_EVENT& aEvent ) auto processFilletOp = [&]( bool aStartPoint ) { - std::shared_ptr connectivity = board()->GetConnectivity(); - VECTOR2I anchor = ( aStartPoint ) ? track->GetStart() : track->GetEnd(); - auto itemsOnAnchor = connectivity->GetConnectedItemsAtAnchor( track, anchor, - track_types ); + std::shared_ptr c = board()->GetConnectivity(); + VECTOR2I anchor = aStartPoint ? track->GetStart() + : track->GetEnd(); + std::vector itemsOnAnchor; + + 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 ) ) @@ -958,7 +963,7 @@ int EDIT_TOOL::Properties( const TOOL_EVENT& aEvent ) } ); // Tracks & vias are treated in a special way: - if( ( SELECTION_CONDITIONS::OnlyTypes( GENERAL_COLLECTOR::Tracks ) )( selection ) ) + if( ( SELECTION_CONDITIONS::OnlyTypes( { PCB_TRACE_T, PCB_ARC_T, PCB_VIA_T } ) )( selection ) ) { DIALOG_TRACK_VIA_PROPERTIES dlg( editFrame, selection, *m_commit ); dlg.ShowQuasiModal(); // QuasiModal required for NET_SELECTOR diff --git a/pcbnew/tools/pad_tool.cpp b/pcbnew/tools/pad_tool.cpp index 6cfffb7129..0fd9465393 100644 --- a/pcbnew/tools/pad_tool.cpp +++ b/pcbnew/tools/pad_tool.cpp @@ -85,7 +85,7 @@ bool PAD_TOOL::Init() SELECTION_CONDITION padSel = SELECTION_CONDITIONS::HasType( PCB_PAD_T ); SELECTION_CONDITION singlePadSel = SELECTION_CONDITIONS::Count( 1 ) && - SELECTION_CONDITIONS::OnlyType( PCB_PAD_T ); + SELECTION_CONDITIONS::OnlyTypes( { PCB_PAD_T } ); auto explodeCondition = [&]( const SELECTION& aSel ) @@ -279,9 +279,7 @@ int PAD_TOOL::EnumeratePads( const TOOL_EVENT& aEvent ) if( !board()->GetFirstFootprint() || board()->GetFirstFootprint()->Pads().empty() ) return 0; - GENERAL_COLLECTOR collector; - const KICAD_T types[] = { PCB_PAD_T, EOT }; - + GENERAL_COLLECTOR collector; GENERAL_COLLECTORS_GUIDE guide = frame()->GetCollectorsGuide(); guide.SetIgnoreMTextsMarkedNoShow( true ); guide.SetIgnoreMTextsOnBack( true ); @@ -384,7 +382,7 @@ int PAD_TOOL::EnumeratePads( const TOOL_EVENT& aEvent ) for( int j = 0; j < segments; ++j ) { wxPoint testpoint( cursorPos.x - j * line_step.x, cursorPos.y - j * line_step.y ); - collector.Collect( board(), types, testpoint, guide ); + collector.Collect( board(), { PCB_PAD_T }, testpoint, guide ); for( int i = 0; i < collector.GetCount(); ++i ) selectedPads.push_back( static_cast( collector[i] ) ); diff --git a/pcbnew/tools/pcb_selection_tool.cpp b/pcbnew/tools/pcb_selection_tool.cpp index b10362f11c..2e2c4fd84a 100644 --- a/pcbnew/tools/pcb_selection_tool.cpp +++ b/pcbnew/tools/pcb_selection_tool.cpp @@ -1344,10 +1344,9 @@ void PCB_SELECTION_TOOL::selectAllConnectedTracks( void PCB_SELECTION_TOOL::selectAllItemsOnNet( int aNetCode, bool aSelect ) { - constexpr KICAD_T types[] = { PCB_TRACE_T, PCB_ARC_T, PCB_VIA_T, EOT }; - auto connectivity = board()->GetConnectivity(); + std::shared_ptr conn = board()->GetConnectivity(); - for( BOARD_CONNECTED_ITEM* item : connectivity->GetNetItems( aNetCode, types ) ) + for( BOARD_ITEM* item : conn->GetNetItems( aNetCode, { PCB_TRACE_T, PCB_ARC_T, PCB_VIA_T } ) ) { if( itemPassesFilter( item, true ) ) aSelect ? select( item ) : unselect( item ); @@ -1469,20 +1468,17 @@ void PCB_SELECTION_TOOL::selectConnections( const std::vector& aIte // now we need to find all footprints that are connected to each of these nets then we need // to determine if these footprints are in the list of footprints - std::vector removeCodeList; - constexpr KICAD_T padType[] = { PCB_PAD_T, EOT }; + std::vector removeCodeList; + std::shared_ptr conn = board()->GetConnectivity(); for( int netCode : netcodeList ) { - for( BOARD_CONNECTED_ITEM* mitem : - board()->GetConnectivity()->GetNetItems( netCode, padType ) ) + for( BOARD_CONNECTED_ITEM* pad : conn->GetNetItems( netCode, { PCB_PAD_T } ) ) { - if( mitem->Type() == PCB_PAD_T - && !std::binary_search( padList.begin(), padList.end(), mitem ) ) + if( !std::binary_search( padList.begin(), padList.end(), pad ) ) { - // if we cannot find the pad in the padList then we can - // assume that that pad should not be used, therefore - // invalidate this netcode. + // if we cannot find the pad in the padList then we can assume that that pad + // should not be used, therefore invalidate this netcode. removeCodeList.push_back( netCode ); break; } @@ -1490,25 +1486,18 @@ void PCB_SELECTION_TOOL::selectConnections( const std::vector& aIte } for( int removeCode : removeCodeList ) - { netcodeList.remove( removeCode ); - } - std::vector localConnectionList; - constexpr KICAD_T trackViaType[] = { PCB_TRACE_T, PCB_ARC_T, PCB_VIA_T, EOT }; + std::unordered_set localConnectionList; for( int netCode : netcodeList ) { - for( BOARD_CONNECTED_ITEM* item : - board()->GetConnectivity()->GetNetItems( netCode, trackViaType ) ) - localConnectionList.push_back( item ); + for( BOARD_ITEM* item : conn->GetNetItems( netCode, { PCB_TRACE_T, PCB_ARC_T, PCB_VIA_T } ) ) + localConnectionList.insert( item ); } - for( BOARD_CONNECTED_ITEM* i : localConnectionList ) - { - if( i != nullptr ) - select( i ); - } + for( BOARD_ITEM* item : localConnectionList ) + select( item ); }