Move KICAD_T[] to std::initializer_list<KICAD_T>.

This commit is contained in:
Jeff Young 2022-08-20 10:27:35 +01:00
parent 66b8ecb467
commit aa2ad3b44c
93 changed files with 1002 additions and 1813 deletions

View File

@ -89,14 +89,14 @@ EDA_ITEM* EDA_ITEM::Clone() const
// see base_struct.h // see base_struct.h
// many classes inherit this method, be careful: // 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,
INSPECT_RESULT EDA_ITEM::Visit( INSPECTOR inspector, void* testData, const KICAD_T scanTypes[] ) const std::initializer_list<KICAD_T>& aScanTypes )
{ {
#if 0 && defined(DEBUG) #if 0 && defined(DEBUG)
std::cout << GetClass().mb_str() << ' '; std::cout << GetClass().mb_str() << ' ';
#endif #endif
if( IsType( scanTypes ) ) if( IsType( aScanTypes ) )
{ {
if( INSPECT_RESULT::QUIT == inspector( this, testData ) ) if( INSPECT_RESULT::QUIT == inspector( this, testData ) )
return INSPECT_RESULT::QUIT; return INSPECT_RESULT::QUIT;

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
* Copyright (C) 2013-2017 CERN * 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 <tomasz.wlostowski@cern.ch> * @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
* @author Maciej Suminski <maciej.suminski@cern.ch> * @author Maciej Suminski <maciej.suminski@cern.ch>
* *
@ -70,7 +70,6 @@ bool SELECTION::Contains( EDA_ITEM* aItem ) const
/// Returns the center point of the selection area bounding box. /// Returns the center point of the selection area bounding box.
VECTOR2I SELECTION::GetCenter() const 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 // If the selection contains only texts calculate the center as the mean of all positions
@ -79,7 +78,7 @@ VECTOR2I SELECTION::GetCenter() const
for( EDA_ITEM* item : m_items ) for( EDA_ITEM* item : m_items )
{ {
if( !item->IsType( textTypes ) ) if( !item->IsType( { SCH_TEXT_T, SCH_LABEL_LOCATE_ANY_T } ) )
{ {
hasOnlyText = false; hasOnlyText = false;
break; break;
@ -101,7 +100,7 @@ VECTOR2I SELECTION::GetCenter() const
for( EDA_ITEM* item : m_items ) 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() ); bbox.Merge( item->GetBoundingBox() );
} }

View File

@ -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<KICAD_T>& aTypes )
{ {
return std::bind( &SELECTION_CONDITIONS::hasTypesFunc, _1, aTypes ); return std::bind( &SELECTION_CONDITIONS::hasTypesFunc, _1, aTypes );
} }
SELECTION_CONDITION SELECTION_CONDITIONS::OnlyType( KICAD_T aType ) SELECTION_CONDITION SELECTION_CONDITIONS::OnlyTypes( const std::initializer_list<KICAD_T>& aTypes )
{
return std::bind( &SELECTION_CONDITIONS::onlyTypeFunc, _1, aType );
}
SELECTION_CONDITION SELECTION_CONDITIONS::OnlyTypes( const KICAD_T aTypes[] )
{ {
return std::bind( &SELECTION_CONDITIONS::onlyTypesFunc, _1, 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<KICAD_T>& aTypes )
{ {
if( aSelection.Empty() ) if( aSelection.Empty() )
return false; 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 ) bool SELECTION_CONDITIONS::onlyTypesFunc( const SELECTION& aSelection,
{ const std::initializer_list<KICAD_T>& aTypes )
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[] )
{ {
if( aSelection.Empty() ) if( aSelection.Empty() )
return false; return false;

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application. * 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 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 * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * 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 ) 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 ) if( aScreen == nullptr )
aScreen = GetScreen(); aScreen = GetScreen();
@ -329,7 +327,7 @@ bool SCH_EDIT_FRAME::BreakSegments( const VECTOR2I& aPoint, SCH_SCREEN* aScreen
for( SCH_ITEM* item : aScreen->Items().Overlapping( SCH_LINE_T, aPoint ) ) 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<SCH_LINE*>( item ); SCH_LINE* wire = static_cast<SCH_LINE*>( item );
@ -380,9 +378,9 @@ void SCH_EDIT_FRAME::DeleteJunction( SCH_ITEM* aJunction, bool aAppend )
SCH_SCREEN* screen = GetScreen(); SCH_SCREEN* screen = GetScreen();
PICKED_ITEMS_LIST undoList; PICKED_ITEMS_LIST undoList;
EE_SELECTION_TOOL* selectionTool = m_toolManager->GetTool<EE_SELECTION_TOOL>(); EE_SELECTION_TOOL* selectionTool = m_toolManager->GetTool<EE_SELECTION_TOOL>();
KICAD_T wiresAndBuses[] = { SCH_ITEM_LOCATE_WIRE_T, SCH_ITEM_LOCATE_BUS_T, EOT };
auto remove_item = [ & ]( SCH_ITEM* aItem ) -> void auto remove_item =
[&]( SCH_ITEM* aItem ) -> void
{ {
aItem->SetFlags( STRUCT_DELETED ); aItem->SetFlags( STRUCT_DELETED );
undoList.PushItem( ITEM_PICKER( screen, aItem, UNDO_REDO::DELETED ) ); undoList.PushItem( ITEM_PICKER( screen, aItem, UNDO_REDO::DELETED ) );
@ -399,10 +397,13 @@ void SCH_EDIT_FRAME::DeleteJunction( SCH_ITEM* aJunction, bool aAppend )
{ {
SCH_LINE* line = static_cast<SCH_LINE*>( item ); SCH_LINE* line = static_cast<SCH_LINE*>( 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 ) ) && !( line->GetEditFlags() & STRUCT_DELETED ) )
{
lines.push_back( line ); lines.push_back( line );
} }
}
alg::for_all_pairs( lines.begin(), lines.end(), alg::for_all_pairs( lines.begin(), lines.end(),
[&]( SCH_LINE* firstLine, SCH_LINE* secondLine ) [&]( SCH_LINE* firstLine, SCH_LINE* secondLine )

View File

@ -461,8 +461,6 @@ DIALOG_SCH_FIELD_PROPERTIES::DIALOG_SCH_FIELD_PROPERTIES( SCH_BASE_FRAME* aParen
DIALOG_FIELD_PROPERTIES( aParent, aTitle, aField ), DIALOG_FIELD_PROPERTIES( aParent, aTitle, aField ),
m_field( aField ) m_field( aField )
{ {
static KICAD_T labelTypes[] = { SCH_LABEL_LOCATE_ANY_T, EOT };
m_isSheetFilename = false; m_isSheetFilename = false;
if( aField->GetParent() && aField->GetParent()->Type() == SCH_SYMBOL_T ) 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; 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; m_fieldId = LABELUSERFIELD_V;
} }

View File

@ -1,7 +1,7 @@
/* /*
* This program source code file is part of KiCad, a free EDA CAD application. * 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 * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -39,7 +39,6 @@
#include <tools/sch_edit_tool.h> #include <tools/sch_edit_tool.h>
#include <widgets/unit_binder.h> #include <widgets/unit_binder.h>
#include <widgets/font_choice.h> #include <widgets/font_choice.h>
#include "font/kicad_font_name.h"
static bool g_modifyReferences; static bool g_modifyReferences;
static bool g_modifyValues; 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 ) if( aItem->Type() == SCH_SYMBOL_T )
{ {
SCH_SYMBOL* symbol = (SCH_SYMBOL*) aItem; SCH_SYMBOL* symbol = (SCH_SYMBOL*) aItem;
@ -520,17 +507,31 @@ 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 ); 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 ); processItem( aSheetPath, aItem );
}
else if( m_globalLabels->GetValue() && aItem->Type() == SCH_GLOBAL_LABEL_T ) else if( m_globalLabels->GetValue() && aItem->Type() == SCH_GLOBAL_LABEL_T )
{
processItem( aSheetPath, aItem ); processItem( aSheetPath, aItem );
}
else if( m_hierLabels->GetValue() && aItem->Type() == SCH_HIER_LABEL_T ) else if( m_hierLabels->GetValue() && aItem->Type() == SCH_HIER_LABEL_T )
{
processItem( aSheetPath, aItem ); 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 ); processItem( aSheetPath, aItem );
} }
}
bool DIALOG_GLOBAL_EDIT_TEXT_AND_GRAPHICS::TransferDataFromWindow() bool DIALOG_GLOBAL_EDIT_TEXT_AND_GRAPHICS::TransferDataFromWindow()

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
* Copyright (C) 2011 Wayne Stambaugh <stambaughw@gmail.com> * Copyright (C) 2011 Wayne Stambaugh <stambaughw@gmail.com>
* 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 * Copyright (C) 2019 CERN
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
@ -36,13 +36,7 @@
#include "sch_reference_list.h" #include "sch_reference_list.h"
const KICAD_T EE_COLLECTOR::AllItems[] = { const std::initializer_list<KICAD_T> EE_COLLECTOR::EditableItems = {
SCH_LOCATE_ANY_T,
EOT
};
const KICAD_T EE_COLLECTOR::EditableItems[] = {
SCH_SHAPE_T, SCH_SHAPE_T,
SCH_TEXT_T, SCH_TEXT_T,
SCH_TEXTBOX_T, SCH_TEXTBOX_T,
@ -62,19 +56,7 @@ const KICAD_T EE_COLLECTOR::EditableItems[] = {
}; };
const KICAD_T EE_COLLECTOR::SymbolsOnly[] = { const std::initializer_list<KICAD_T> EE_COLLECTOR::MovableItems =
SCH_SYMBOL_T,
EOT
};
const KICAD_T EE_COLLECTOR::SheetsOnly[] = {
SCH_SHEET_T,
EOT
};
const KICAD_T EE_COLLECTOR::MovableItems[] =
{ {
SCH_MARKER_T, SCH_MARKER_T,
SCH_JUNCTION_T, SCH_JUNCTION_T,
@ -98,20 +80,10 @@ const KICAD_T EE_COLLECTOR::MovableItems[] =
}; };
const KICAD_T EE_COLLECTOR::WiresOnly[] = { const std::initializer_list<KICAD_T> EE_COLLECTOR::FieldOwners = {
SCH_LINE_T,
EOT
};
const KICAD_T EE_COLLECTOR::FieldOwners[] = {
SCH_SYMBOL_T, SCH_SYMBOL_T,
SCH_SHEET_T, SCH_SHEET_T,
SCH_LABEL_T, SCH_LABEL_LOCATE_ANY_T
SCH_GLOBAL_LABEL_T,
SCH_HIER_LABEL_T,
SCH_DIRECTIVE_LABEL_T,
EOT
}; };
@ -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, void EE_COLLECTOR::Collect( SCH_SCREEN* aScreen,
int aUnit, int aConvert ) const std::initializer_list<KICAD_T>& aFilterList,
const VECTOR2I& aPos, int aUnit, int aConvert )
{ {
Empty(); // empty the collection just in case 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<KICAD_T>& aFilterList,
const VECTOR2I& aPos, int aUnit, int aConvert ) const VECTOR2I& aPos, int aUnit, int aConvert )
{ {
Empty(); // empty the collection just in case Empty(); // empty the collection just in case

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
* Copyright (C) 2011 Wayne Stambaugh <stambaughw@gmail.com> * Copyright (C) 2011 Wayne Stambaugh <stambaughw@gmail.com>
* 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 * Copyright (C) 2019 CERN
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
@ -39,15 +39,11 @@ class SCH_SYMBOL;
class EE_COLLECTOR : public COLLECTOR class EE_COLLECTOR : public COLLECTOR
{ {
public: public:
static const KICAD_T AllItems[]; static const std::initializer_list<KICAD_T> EditableItems;
static const KICAD_T EditableItems[]; static const std::initializer_list<KICAD_T> MovableItems;
static const KICAD_T MovableItems[]; static const std::initializer_list<KICAD_T> FieldOwners;
static const KICAD_T SymbolsOnly[];
static const KICAD_T SheetsOnly[];
static const KICAD_T WiresOnly[];
static const KICAD_T FieldOwners[];
EE_COLLECTOR( const KICAD_T* aScanTypes = EE_COLLECTOR::AllItems ) : EE_COLLECTOR( const std::initializer_list<KICAD_T>& aScanTypes = { SCH_LOCATE_ANY_T } ) :
m_Unit( 0 ), m_Unit( 0 ),
m_Convert( 0 ), m_Convert( 0 ),
m_ShowPinElectricalTypes( false ) m_ShowPinElectricalTypes( false )
@ -75,29 +71,27 @@ public:
* Scan a #EDA_ITEM using this class's Inspector method which does the collection. * Scan a #EDA_ITEM using this class's Inspector method which does the collection.
* *
* @param aScreen The eeschema screen to use for scanning * @param aScreen The eeschema screen to use for scanning
* @param aFilterList A list of #KICAD_T types with a terminating #EOT, that determines * @param aFilterList A list of #KICAD_T types that determines what is to be collected and
* what is to be collected and the priority order of the resulting * the priority order of the resulting collection.
* collection.
* @param aPos are the coordinates to use in hit testing. * @param aPos are the coordinates to use in hit testing.
* @param aUnit is the symbol unit filter (for symbol editor). * @param aUnit is the symbol unit filter (for symbol editor).
* @param aConvert is the DeMorgan 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, void Collect( SCH_SCREEN* aScreen, const std::initializer_list<KICAD_T>& aFilterList,
int aUnit = 0, int aConvert = 0 ); const VECTOR2I& aPos, int aUnit = 0, int aConvert = 0 );
/** /**
* Scan an #EDA_ITEM using this class's Inspector method which does the collection. * 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 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 * @param aFilterList is a list of #KICAD_T types that determines what is to be collected
* what is to be collected and the priority order of the resulting * and the priority order of the resulting collection.
* collection.
* @param aPos are the coordinates to use in hit testing. * @param aPos are the coordinates to use in hit testing.
* @param aUnit is the symbol unit filter (for symbol editor). * @param aUnit is the symbol unit filter (for symbol editor).
* @param aConvert is the DeMorgan 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, void Collect( LIB_ITEMS_CONTAINER& aItems, const std::initializer_list<KICAD_T>& aFilterList,
int aUnit = 0, int aConvert = 0 ); const VECTOR2I& aPos, int aUnit = 0, int aConvert = 0 );
/** /**
* Test if the collected items form a corner of two line segments. * Test if the collected items form a corner of two line segments.

View File

@ -56,7 +56,6 @@ bool SCH_EDIT_FRAME::LoadProjectSettings()
GetRenderSettings()->m_LabelSizeRatio = settings.m_LabelSizeRatio; GetRenderSettings()->m_LabelSizeRatio = settings.m_LabelSizeRatio;
GetRenderSettings()->m_TextOffsetRatio = settings.m_TextOffsetRatio; GetRenderSettings()->m_TextOffsetRatio = settings.m_TextOffsetRatio;
GetRenderSettings()->m_PinSymbolSize = settings.m_PinSymbolSize; GetRenderSettings()->m_PinSymbolSize = settings.m_PinSymbolSize;
GetRenderSettings()->m_JunctionSize = settings.m_JunctionSize;
GetRenderSettings()->SetDashLengthRatio( settings.m_DashedLineDashRatio ); GetRenderSettings()->SetDashLengthRatio( settings.m_DashedLineDashRatio );
GetRenderSettings()->SetGapLengthRatio( settings.m_DashedLineGapRatio ); 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_LabelSizeRatio = Schematic().Settings().m_LabelSizeRatio;
GetRenderSettings()->m_TextOffsetRatio = Schematic().Settings().m_TextOffsetRatio; GetRenderSettings()->m_TextOffsetRatio = Schematic().Settings().m_TextOffsetRatio;
GetRenderSettings()->m_PinSymbolSize = Schematic().Settings().m_PinSymbolSize; GetRenderSettings()->m_PinSymbolSize = Schematic().Settings().m_PinSymbolSize;
GetRenderSettings()->m_JunctionSize = Schematic().Settings().m_JunctionSize;
GetRenderSettings()->SetDashLengthRatio( Schematic().Settings().m_DashedLineDashRatio ); GetRenderSettings()->SetDashLengthRatio( Schematic().Settings().m_DashedLineDashRatio );
GetRenderSettings()->SetGapLengthRatio( Schematic().Settings().m_DashedLineGapRatio ); GetRenderSettings()->SetGapLengthRatio( Schematic().Settings().m_DashedLineGapRatio );

View File

@ -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, INSPECT_RESULT LIB_SYMBOL::Visit( INSPECTOR aInspector, void* aTestData,
const KICAD_T aFilterTypes[] ) const std::initializer_list<KICAD_T>& aScanTypes )
{ {
// The part itself is never inspected, only its children // The part itself is never inspected, only its children
for( LIB_ITEM& item : m_drawings ) for( LIB_ITEM& item : m_drawings )
{ {
if( item.IsType( aFilterTypes ) ) if( item.IsType( aScanTypes ) )
{ {
if( aInspector( &item, aTestData ) == INSPECT_RESULT::QUIT ) if( aInspector( &item, aTestData ) == INSPECT_RESULT::QUIT )
return INSPECT_RESULT::QUIT; return INSPECT_RESULT::QUIT;

View File

@ -3,7 +3,7 @@
* *
* Copyright (C) 2004-2015 Jean-Pierre Charras, jp.charras at wanadoo.fr * Copyright (C) 2004-2015 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 2008 Wayne Stambaugh <stambaughw@gmail.com> * Copyright (C) 2008 Wayne Stambaugh <stambaughw@gmail.com>
* 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 * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -502,7 +502,8 @@ public:
LIB_ITEMS_CONTAINER& GetDrawItems() { return m_drawings; } LIB_ITEMS_CONTAINER& GetDrawItems() { return m_drawings; }
const LIB_ITEMS_CONTAINER& GetDrawItems() const { 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<KICAD_T>& aScanTypes ) override;
/** /**
* Set the units per symbol count. * Set the units per symbol count.

View File

@ -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 SCH_SCREEN* SCH_BASE_FRAME::GetScreen() const
{ {
return (SCH_SCREEN*) EDA_DRAW_FRAME::GetScreen(); return (SCH_SCREEN*) EDA_DRAW_FRAME::GetScreen();
@ -187,10 +182,7 @@ void SCH_BASE_FRAME::UpdateStatusBar()
MessageTextFromValue( GetUserUnits(), hypot( d.x, d.y ), false ) ); MessageTextFromValue( GetUserUnits(), hypot( d.x, d.y ), false ) );
SetStatusText( line, 3 ); SetStatusText( line, 3 );
// refresh grid display
DisplayGridMsg(); DisplayGridMsg();
// refresh units display
DisplayUnitsMsg(); 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() void SCH_BASE_FRAME::HardRedraw()
{ {
if( GetCanvas() && GetCanvas()->GetView() ) if( GetCanvas() && GetCanvas()->GetView() )
@ -342,15 +323,7 @@ void SCH_BASE_FRAME::UpdateItem( EDA_ITEM* aItem, bool isAddOrDelete, bool aUpda
GetCanvas()->GetView()->Update( aItem ); GetCanvas()->GetView()->Update( aItem );
// Some children are drawn from their parents. Mark them for re-paint. // Some children are drawn from their parents. Mark them for re-paint.
static KICAD_T parentTypes[] = { SCH_SYMBOL_T, if( parent && parent->IsType( { SCH_SYMBOL_T, SCH_SHEET_T, SCH_LABEL_LOCATE_ANY_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 ) )
GetCanvas()->GetView()->Update( parent, KIGFX::REPAINT ); GetCanvas()->GetView()->Update( parent, KIGFX::REPAINT );
} }

View File

@ -92,13 +92,12 @@ LIB_SYMBOL* SchGetLibSymbol( const LIB_ID& aLibId, SYMBOL_LIB_TABLE* aLibTable,
class SCH_BASE_FRAME : public EDA_DRAW_FRAME class SCH_BASE_FRAME : public EDA_DRAW_FRAME
{ {
public: public:
SCH_BASE_FRAME( KIWAY* aKiway, wxWindow* aParent, SCH_BASE_FRAME( KIWAY* aKiway, wxWindow* aParent, FRAME_T aWindowType, const wxString& aTitle,
FRAME_T aWindowType, const wxPoint& aPosition, const wxSize& aSize, long aStyle,
const wxString& aTitle, const wxString & aFrameName );
const wxPoint& aPosition, const wxSize& aSize,
long aStyle, const wxString & aFrameName );
virtual ~SCH_BASE_FRAME(); virtual ~SCH_BASE_FRAME()
{ }
void createCanvas(); void createCanvas();
@ -198,8 +197,6 @@ public:
virtual void RedrawScreen( const VECTOR2I& aCenterPoint, bool aWarpPointer ); virtual void RedrawScreen( const VECTOR2I& aCenterPoint, bool aWarpPointer );
virtual void CenterScreen( const VECTOR2I& aCenterPoint, bool aWarpPointer );
void HardRedraw() override; void HardRedraw() override;
/** /**

View File

@ -1353,8 +1353,7 @@ void SCH_EDIT_FRAME::AddItemToScreenAndUndoList( SCH_SCREEN* aScreen, SCH_ITEM*
if( connected ) if( connected )
{ {
static KICAD_T autoRotatableLabelTypes[] = { SCH_GLOBAL_LABEL_T, SCH_HIER_LABEL_T }; if( aItem->IsType( { SCH_GLOBAL_LABEL_T, SCH_HIER_LABEL_T } ) )
if( aItem->IsType( autoRotatableLabelTypes ) )
{ {
auto label = static_cast<SCH_LABEL_BASE*>( aItem ); auto label = static_cast<SCH_LABEL_BASE*>( aItem );
if( label->AutoRotateOnPlacement() ) if( label->AutoRotateOnPlacement() )

View File

@ -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 ) SCH_FIELD& SCH_FIELD::operator=( const SCH_FIELD& aField )
{ {
EDA_TEXT::operator=( aField ); EDA_TEXT::operator=( aField );
@ -125,8 +120,6 @@ EDA_ITEM* SCH_FIELD::Clone() const
void SCH_FIELD::SetId( int aId ) void SCH_FIELD::SetId( int aId )
{ {
KICAD_T labelTypes[] = { SCH_LABEL_LOCATE_ANY_T, EOT };
m_id = aId; m_id = aId;
if( m_parent && m_parent->Type() == SCH_SHEET_T ) if( m_parent && m_parent->Type() == SCH_SHEET_T )
@ -147,7 +140,7 @@ void SCH_FIELD::SetId( int aId )
default: SetLayer( LAYER_FIELDS ); break; 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 // We can't use defined IDs for labels because there can be multiple net class
// assignments. // assignments.
@ -164,8 +157,6 @@ void SCH_FIELD::SetId( int aId )
wxString SCH_FIELD::GetShownText( int aDepth ) const wxString SCH_FIELD::GetShownText( int aDepth ) const
{ {
KICAD_T labelTypes[] = { SCH_LABEL_LOCATE_ANY_T, EOT };
std::function<bool( wxString* )> symbolResolver = std::function<bool( wxString* )> symbolResolver =
[&]( wxString* token ) -> bool [&]( wxString* token ) -> bool
{ {
@ -223,7 +214,7 @@ wxString SCH_FIELD::GetShownText( int aDepth ) const
text = ExpandTextVars( text, &symbolResolver, nullptr, project ); text = ExpandTextVars( text, &symbolResolver, nullptr, project );
else if( m_parent && m_parent->Type() == SCH_SHEET_T ) else if( m_parent && m_parent->Type() == SCH_SHEET_T )
text = ExpandTextVars( text, &sheetResolver, nullptr, project ); 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 ); text = ExpandTextVars( text, &labelResolver, nullptr, project );
else else
text = ExpandTextVars( text, project ); text = ExpandTextVars( text, project );
@ -790,8 +781,6 @@ void SCH_FIELD::DoHypertextMenu( EDA_DRAW_FRAME* aFrame )
wxString SCH_FIELD::GetName( bool aUseDefaultName ) const 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_parent && m_parent->Type() == SCH_SYMBOL_T )
{ {
if( m_id >= 0 && m_id < MANDATORY_FIELDS ) if( m_id >= 0 && m_id < MANDATORY_FIELDS )
@ -810,7 +799,7 @@ wxString SCH_FIELD::GetName( bool aUseDefaultName ) const
else else
return m_name; 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 ); return SCH_LABEL_BASE::GetDefaultFieldName( m_name, aUseDefaultName );
} }
@ -824,8 +813,6 @@ wxString SCH_FIELD::GetName( bool aUseDefaultName ) const
wxString SCH_FIELD::GetCanonicalName() const wxString SCH_FIELD::GetCanonicalName() const
{ {
KICAD_T labelTypes[] = { SCH_LABEL_LOCATE_ANY_T, EOT };
if( m_parent && m_parent->Type() == SCH_SYMBOL_T ) if( m_parent && m_parent->Type() == SCH_SYMBOL_T )
{ {
switch( m_id ) switch( m_id )
@ -846,7 +833,7 @@ wxString SCH_FIELD::GetCanonicalName() const
default: return m_name; 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: // These should be stored in canonical format, but just in case:
if( m_name == _( "Net Class" ) ) if( m_name == _( "Net Class" ) )

View File

@ -54,7 +54,8 @@ public:
SCH_FIELD( const SCH_FIELD& aText ); SCH_FIELD( const SCH_FIELD& aText );
~SCH_FIELD(); ~SCH_FIELD()
{ }
SCH_FIELD& operator=( const SCH_FIELD& aField ); SCH_FIELD& operator=( const SCH_FIELD& aField );
@ -68,20 +69,20 @@ public:
return wxT( "SCH_FIELD" ); return wxT( "SCH_FIELD" );
} }
bool IsType( const KICAD_T aScanTypes[] ) const override bool IsType( const std::initializer_list<KICAD_T>& aScanTypes ) const override
{ {
if( SCH_ITEM::IsType( aScanTypes ) ) if( SCH_ITEM::IsType( aScanTypes ) )
return true; 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; 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; 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; 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; return true;
} }

View File

@ -157,20 +157,20 @@ public:
return wxT( "SCH_ITEM" ); return wxT( "SCH_ITEM" );
} }
bool IsType( const KICAD_T aScanTypes[] ) const override bool IsType( const std::initializer_list<KICAD_T>& aScanTypes ) const override
{ {
if( EDA_ITEM::IsType( aScanTypes ) ) if( EDA_ITEM::IsType( aScanTypes ) )
return true; 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; 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; 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 ) && Type() == SCH_LINE_T && m_layer == LAYER_NOTES )
{ {
return true; return true;

View File

@ -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<KICAD_T>& 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 ) ) if( SCH_TEXT::IsType( aScanTypes ) )
return true; 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; 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() ); 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 ) for( SCH_ITEM* connection : item_set )
{ {
if( connection->IsType( wireTypes ) ) if( connection->IsType( { SCH_ITEM_LOCATE_WIRE_T, SCH_PIN_T } ) )
return true; return true;
} }
} }
if ( *p == SCH_LABEL_LOCATE_BUS_T ) if ( scanType == SCH_LABEL_LOCATE_BUS_T )
{ {
for( SCH_ITEM* connection : item_set ) for( SCH_ITEM* connection : item_set )
{ {
if( connection->IsType( busTypes ) ) if( connection->IsType( { SCH_ITEM_LOCATE_BUS_T } ) )
return true; return true;
} }
} }
@ -545,19 +542,19 @@ void SCH_LABEL_BASE::RunOnChildren( const std::function<void( SCH_ITEM* )>& aFun
INSPECT_RESULT SCH_LABEL_BASE::Visit( INSPECTOR aInspector, void* testData, INSPECT_RESULT SCH_LABEL_BASE::Visit( INSPECTOR aInspector, void* testData,
const KICAD_T aFilterTypes[] ) const std::initializer_list<KICAD_T>& aScanTypes )
{ {
KICAD_T stype; KICAD_T stype;
if( IsType( aFilterTypes ) ) if( IsType( aScanTypes ) )
{ {
if( INSPECT_RESULT::QUIT == aInspector( this, nullptr ) ) if( INSPECT_RESULT::QUIT == aInspector( this, nullptr ) )
return INSPECT_RESULT::QUIT; 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 ) for( SCH_FIELD& field : m_fields )
{ {

View File

@ -44,7 +44,7 @@ public:
// Abstract class // Abstract class
virtual wxString GetClass() const override = 0; virtual wxString GetClass() const override = 0;
bool IsType( const KICAD_T aScanTypes[] ) const override; bool IsType( const std::initializer_list<KICAD_T>& aScanTypes ) const override;
void SwapData( SCH_ITEM* aItem ) override; void SwapData( SCH_ITEM* aItem ) override;
@ -119,7 +119,8 @@ public:
void RunOnChildren( const std::function<void( SCH_ITEM* )>& aFunction ) override; void RunOnChildren( const std::function<void( SCH_ITEM* )>& 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<KICAD_T>& scanTypes ) override;
VECTOR2I GetSchematicTextOffset( const RENDER_SETTINGS* aSettings ) const override; VECTOR2I GetSchematicTextOffset( const RENDER_SETTINGS* aSettings ) const override;

View File

@ -67,20 +67,20 @@ public:
*/ */
wxString GetNetname(const SCH_SHEET_PATH &aSheet); wxString GetNetname(const SCH_SHEET_PATH &aSheet);
bool IsType( const KICAD_T aScanTypes[] ) const override bool IsType( const std::initializer_list<KICAD_T>& aScanTypes ) const override
{ {
if( SCH_ITEM::IsType( aScanTypes ) ) if( SCH_ITEM::IsType( aScanTypes ) )
return true; 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; 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; 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; return true;
} }

View File

@ -74,7 +74,8 @@ EESCHEMA_SETTINGS* eeconfig()
} }
KICAD_T SCH_PAINTER::g_ScaledSelectionTypes[] = { SCH_MARKER_T, std::initializer_list<KICAD_T> SCH_PAINTER::g_ScaledSelectionTypes = {
SCH_MARKER_T,
SCH_JUNCTION_T, SCH_JUNCTION_T,
SCH_NO_CONNECT_T, SCH_NO_CONNECT_T,
SCH_BUS_WIRE_ENTRY_T, SCH_BUS_WIRE_ENTRY_T,
@ -85,8 +86,8 @@ KICAD_T SCH_PAINTER::g_ScaledSelectionTypes[] = { SCH_MARKER_T,
SCH_DIRECTIVE_LABEL_T, SCH_DIRECTIVE_LABEL_T,
LIB_SYMBOL_T, SCH_SYMBOL_T, LIB_SYMBOL_T, SCH_SYMBOL_T,
SCH_SHEET_T, SCH_SHEET_T,
LIB_PIN_T, SCH_PIN_T, LIB_PIN_T, SCH_PIN_T
EOT }; };
SCH_RENDER_SETTINGS::SCH_RENDER_SETTINGS() : SCH_RENDER_SETTINGS::SCH_RENDER_SETTINGS() :
@ -99,8 +100,7 @@ SCH_RENDER_SETTINGS::SCH_RENDER_SETTINGS() :
m_OverrideItemColors( false ), m_OverrideItemColors( false ),
m_LabelSizeRatio( DEFAULT_LABEL_SIZE_RATIO ), m_LabelSizeRatio( DEFAULT_LABEL_SIZE_RATIO ),
m_TextOffsetRatio( DEFAULT_TEXT_OFFSET_RATIO ), m_TextOffsetRatio( DEFAULT_TEXT_OFFSET_RATIO ),
m_PinSymbolSize( DEFAULT_TEXT_SIZE * IU_PER_MILS / 2 ), m_PinSymbolSize( DEFAULT_TEXT_SIZE * IU_PER_MILS / 2 )
m_JunctionSize( DEFAULT_JUNCTION_DIAM * IU_PER_MILS )
{ {
SetDefaultPenWidth( DEFAULT_LINE_WIDTH_MILS * IU_PER_MILS ); SetDefaultPenWidth( DEFAULT_LINE_WIDTH_MILS * IU_PER_MILS );
SetDashLengthRatio( 12 ); // From ISO 128-2 SetDashLengthRatio( 12 ); // From ISO 128-2

View File

@ -122,9 +122,7 @@ public:
double m_LabelSizeRatio; // Proportion of font size to label box double m_LabelSizeRatio; // Proportion of font size to label box
double m_TextOffsetRatio; // Proportion of font size to offset text above/below double m_TextOffsetRatio; // Proportion of font size to offset text above/below
// wires, buses, etc. // wires, buses, etc.
int m_PinSymbolSize; int m_PinSymbolSize;
int m_JunctionSize;
}; };
@ -140,15 +138,9 @@ public:
virtual bool Draw( const VIEW_ITEM*, int ) override; virtual bool Draw( const VIEW_ITEM*, int ) override;
/// @copydoc PAINTER::GetSettings() /// @copydoc PAINTER::GetSettings()
virtual SCH_RENDER_SETTINGS* GetSettings() override virtual SCH_RENDER_SETTINGS* GetSettings() override { return &m_schSettings; }
{
return &m_schSettings;
}
void SetSchematic( SCHEMATIC* aSchematic ) void SetSchematic( SCHEMATIC* aSchematic ) { m_schematic = aSchematic; }
{
m_schematic = aSchematic;
}
private: private:
void draw( LIB_PIN* aPin, int aLayer ); void draw( LIB_PIN* aPin, int aLayer );
@ -200,15 +192,13 @@ private:
const TEXT_ATTRIBUTES& aAttributes ); const TEXT_ATTRIBUTES& aAttributes );
void bitmapText( const wxString& aText, const VECTOR2D& aPosition, void bitmapText( const wxString& aText, const VECTOR2D& aPosition,
const TEXT_ATTRIBUTES& aAttributes ); const TEXT_ATTRIBUTES& aAttributes );
void boxText( const wxString& aText, const VECTOR2D& aPosition, void boxText( const wxString& aText, const VECTOR2D& aPosition, const TEXT_ATTRIBUTES& aAttrs );
const TEXT_ATTRIBUTES& aAttrs );
public: public:
static KICAD_T g_ScaledSelectionTypes[]; static std::initializer_list<KICAD_T> g_ScaledSelectionTypes;
private: private:
SCH_RENDER_SETTINGS m_schSettings; SCH_RENDER_SETTINGS m_schSettings;
SCHEMATIC* m_schematic; SCHEMATIC* m_schematic;
}; };

View File

@ -2355,12 +2355,11 @@ bool SCH_EAGLE_PLUGIN::CheckHeader( const wxString& aFileName )
void SCH_EAGLE_PLUGIN::moveLabels( SCH_LINE* aWire, const VECTOR2I& aNewEndPoint ) 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() ) ) for( SCH_ITEM* item : screen->Items().Overlapping( aWire->GetBoundingBox() ) )
{ {
if( !item->IsType( labelTypes ) ) if( !item->IsType( { SCH_LABEL_LOCATE_ANY_T } ) )
continue; continue;
if( TestSegmentHit( item->GetPosition(), aWire->GetStartPoint(), aWire->GetEndPoint(), 0 ) ) if( TestSegmentHit( item->GetPosition(), aWire->GetStartPoint(), aWire->GetEndPoint(), 0 ) )

View File

@ -24,11 +24,6 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/ */
/**
* @file sch_screen.cpp
* @brief Implementation of SCH_SCREEN and SCH_SCREENS classes.
*/
#include <wx/filefn.h> #include <wx/filefn.h>
#include <eda_item.h> #include <eda_item.h>
@ -92,7 +87,7 @@ SCH_SCREEN::~SCH_SCREEN()
SCHEMATIC* SCH_SCREEN::Schematic() const SCHEMATIC* SCH_SCREEN::Schematic() const
{ {
wxCHECK_MSG( GetParent() && GetParent()->Type() == SCHEMATIC_T, nullptr, 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<SCHEMATIC*>( GetParent() ); return static_cast<SCHEMATIC*>( GetParent() );
} }
@ -123,8 +118,7 @@ void SCH_SCREEN::IncRefCount()
void SCH_SCREEN::DecRefCount() void SCH_SCREEN::DecRefCount()
{ {
wxCHECK_RET( m_refCount != 0, wxCHECK_RET( m_refCount != 0, wxT( "Screen reference count already zero. Bad programmer!" ) );
wxT( "Screen reference count already zero. Bad programmer!" ) );
m_refCount--; m_refCount--;
} }
@ -1284,17 +1278,9 @@ void SCH_SCREEN::EnsureAlternateReferencesExist()
void SCH_SCREEN::GetHierarchicalItems( std::vector<SCH_ITEM*>* aItems ) const void SCH_SCREEN::GetHierarchicalItems( std::vector<SCH_ITEM*>* 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() ) 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 ); aItems->push_back( item );
} }
} }
@ -1317,7 +1303,9 @@ void SCH_SCREEN::GetSheets( std::vector<SCH_ITEM*>* aItems ) const
return a->GetPosition().y < b->GetPosition().y; return a->GetPosition().y < b->GetPosition().y;
} }
else else
{
return a->GetPosition().x < b->GetPosition().x; return a->GetPosition().x < b->GetPosition().x;
}
} ); } );
} }

View File

@ -943,20 +943,19 @@ std::vector<VECTOR2I> 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<KICAD_T>& aScanTypes )
{ {
KICAD_T stype; for( KICAD_T scanType : aScanTypes )
for( const KICAD_T* p = aFilterTypes; (stype = *p) != EOT; ++p )
{ {
// If caller wants to inspect my type // 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 ) ) if( INSPECT_RESULT::QUIT == aInspector( this, nullptr ) )
return INSPECT_RESULT::QUIT; 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. // Test the sheet fields.
for( SCH_FIELD& field : m_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. // Test the sheet labels.
for( SCH_SHEET_PIN* sheetPin : m_pins ) for( SCH_SHEET_PIN* sheetPin : m_pins )

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application. * 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) 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 * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -350,7 +350,8 @@ public:
std::vector<VECTOR2I> GetConnectionPoints() const override; std::vector<VECTOR2I> 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<KICAD_T>& aScanTypes ) override;
void RunOnChildren( const std::function<void( SCH_ITEM* )>& aFunction ) override; void RunOnChildren( const std::function<void( SCH_ITEM* )>& aFunction ) override;

View File

@ -1724,21 +1724,19 @@ wxString SCH_SYMBOL::GetSelectMenuText( EDA_UNITS aUnits ) const
INSPECT_RESULT SCH_SYMBOL::Visit( INSPECTOR aInspector, void* aTestData, INSPECT_RESULT SCH_SYMBOL::Visit( INSPECTOR aInspector, void* aTestData,
const KICAD_T aFilterTypes[] ) const std::initializer_list<KICAD_T>& aScanTypes )
{ {
KICAD_T stype; for( KICAD_T scanType : aScanTypes )
for( const KICAD_T* p = aFilterTypes; (stype = *p) != EOT; ++p )
{ {
if( stype == SCH_LOCATE_ANY_T if( scanType == SCH_LOCATE_ANY_T
|| ( stype == SCH_SYMBOL_T ) || ( scanType == SCH_SYMBOL_T )
|| ( stype == SCH_SYMBOL_LOCATE_POWER_T && m_part && m_part->IsPower() ) ) || ( scanType == SCH_SYMBOL_LOCATE_POWER_T && m_part && m_part->IsPower() ) )
{ {
if( INSPECT_RESULT::QUIT == aInspector( this, aTestData ) ) if( INSPECT_RESULT::QUIT == aInspector( this, aTestData ) )
return INSPECT_RESULT::QUIT; 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 ) 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 ) ) if( INSPECT_RESULT::QUIT == aInspector( GetField( REFERENCE_FIELD ), (void*) this ) )
return INSPECT_RESULT::QUIT; return INSPECT_RESULT::QUIT;
} }
if( stype == SCH_FIELD_LOCATE_VALUE_T if( scanType == SCH_FIELD_LOCATE_VALUE_T
|| ( stype == SCH_SYMBOL_LOCATE_POWER_T && m_part && m_part->IsPower() ) ) || ( scanType == SCH_SYMBOL_LOCATE_POWER_T && m_part && m_part->IsPower() ) )
{ {
if( INSPECT_RESULT::QUIT == aInspector( GetField( VALUE_FIELD ), (void*) this ) ) if( INSPECT_RESULT::QUIT == aInspector( GetField( VALUE_FIELD ), (void*) this ) )
return INSPECT_RESULT::QUIT; 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 ) ) if( INSPECT_RESULT::QUIT == aInspector( GetField( FOOTPRINT_FIELD ), (void*) this ) )
return INSPECT_RESULT::QUIT; 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 ) ) if( INSPECT_RESULT::QUIT == aInspector( GetField( DATASHEET_FIELD ), (void*) this ) )
return INSPECT_RESULT::QUIT; 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<SCH_PIN>& pin : m_pins ) for( const std::unique_ptr<SCH_PIN>& pin : m_pins )
{ {

View File

@ -638,7 +638,8 @@ public:
std::vector<VECTOR2I> GetConnectionPoints() const override; std::vector<VECTOR2I> 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<KICAD_T>& aScanTypes ) override;
/** /**
* Return the symbol library item at \a aPosition that is part of this symbol. * Return the symbol library item at \a aPosition that is part of this symbol.

View File

@ -283,7 +283,7 @@ int EE_INSPECTION_TOOL::ShowDatasheet( const TOOL_EVENT& aEvent )
} }
else if( m_frame->IsType( FRAME_SCH ) ) 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() ) if( selection.Empty() )
return 0; return 0;

View File

@ -406,17 +406,6 @@ void EE_POINT_EDITOR::updateEditedPoint( const TOOL_EVENT& aEvent )
int EE_POINT_EDITOR::Main( 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 ) if( !m_selectionTool )
return 0; return 0;
@ -430,8 +419,14 @@ int EE_POINT_EDITOR::Main( const TOOL_EVENT& aEvent )
const EE_SELECTION& selection = m_selectionTool->GetSelection(); 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; return 0;
}
// Wait till drawing tool is done // Wait till drawing tool is done
if( selection.Front()->IsNew() ) if( selection.Front()->IsNew() )

View File

@ -144,6 +144,23 @@ EE_SELECTION_TOOL::~EE_SELECTION_TOOL()
using E_C = EE_CONDITIONS; using E_C = EE_CONDITIONS;
static std::initializer_list<KICAD_T> 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() bool EE_SELECTION_TOOL::Init()
{ {
m_frame = getEditFrame<SCH_BASE_FRAME>(); m_frame = getEditFrame<SCH_BASE_FRAME>();
@ -162,25 +179,12 @@ bool EE_SELECTION_TOOL::Init()
m_isSymbolViewer = symbolViewerFrame != nullptr; m_isSymbolViewer = symbolViewerFrame != nullptr;
} }
static KICAD_T wireOrBusTypes[] = { SCH_ITEM_LOCATE_WIRE_T, SCH_ITEM_LOCATE_BUS_T, EOT }; auto wireSelection = E_C::Count( 1 ) && E_C::OnlyTypes( { SCH_ITEM_LOCATE_WIRE_T } );
static KICAD_T connectedTypes[] = { SCH_ITEM_LOCATE_WIRE_T, auto busSelection = E_C::Count( 1 ) && E_C::OnlyTypes( { SCH_ITEM_LOCATE_BUS_T });
SCH_ITEM_LOCATE_BUS_T, auto wireOrBusSelection = E_C::Count( 1 ) && E_C::OnlyTypes( { 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 connectedSelection = E_C::Count( 1 ) && E_C::OnlyTypes( connectedTypes ); auto connectedSelection = E_C::Count( 1 ) && E_C::OnlyTypes( connectedTypes );
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 crossProbingSelection = E_C::MoreThan( 0 ) && E_C::HasTypes( crossProbingTypes ); auto crossProbingSelection = E_C::MoreThan( 0 ) && E_C::HasTypes( { SCH_SYMBOL_T, SCH_PIN_T, SCH_SHEET_T } );
auto schEditSheetPageNumberCondition = auto schEditSheetPageNumberCondition =
[&] ( const SELECTION& aSel ) [&] ( const SELECTION& aSel )
@ -188,7 +192,7 @@ bool EE_SELECTION_TOOL::Init()
if( m_isSymbolEditor || m_isSymbolViewer ) if( m_isSymbolEditor || m_isSymbolViewer )
return false; 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 = 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 ) int EE_SELECTION_TOOL::Main( const TOOL_EVENT& aEvent )
{ {
m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::ARROW ); m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::ARROW );
@ -416,7 +402,7 @@ int EE_SELECTION_TOOL::Main( const TOOL_EVENT& aEvent )
if( m_selection.Empty() ) if( m_selection.Empty() )
{ {
ClearSelection(); ClearSelection();
SelectPoint( evt->Position(), EE_COLLECTOR::AllItems, nullptr, &selCancelled ); SelectPoint( evt->Position(), { SCH_LOCATE_ANY_T }, nullptr, &selCancelled );
m_selection.SetIsHover( true ); m_selection.SetIsHover( true );
} }
// If the cursor has moved off the bounding box of the selection by more than // 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 ) for( EDA_ITEM* item : saved_selection )
RemoveItemFromSel( item, true ); RemoveItemFromSel( item, true );
SelectPoint( evt->Position(), EE_COLLECTOR::AllItems, nullptr, &selCancelled ); SelectPoint( evt->Position(), { SCH_LOCATE_ANY_T }, nullptr, &selCancelled );
if( m_selection.Empty() ) if( m_selection.Empty() )
{ {
@ -507,9 +493,17 @@ int EE_SELECTION_TOOL::Main( const TOOL_EVENT& aEvent )
if( m_isSymbolEditor ) if( m_isSymbolEditor )
{ {
if( static_cast<SYMBOL_EDIT_FRAME*>( m_frame )->IsSymbolAlias() ) if( static_cast<SYMBOL_EDIT_FRAME*>( m_frame )->IsSymbolAlias() )
m_selection = RequestSelection( movableSymbolAliasItems ); {
m_selection = RequestSelection( { LIB_FIELD_T } );
}
else else
m_selection = RequestSelection( movableSymbolItems ); {
m_selection = RequestSelection( { LIB_SHAPE_T,
LIB_TEXT_T,
LIB_TEXTBOX_T,
LIB_PIN_T,
LIB_FIELD_T } );
}
} }
else else
{ {
@ -747,7 +741,7 @@ int EE_SELECTION_TOOL::disambiguateCursor( const TOOL_EVENT& aEvent )
keyboardState.AltDown() ); keyboardState.AltDown() );
m_skip_heuristics = true; 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_additive, m_subtractive, m_exclusive_or );
m_skip_heuristics = false; 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, bool EE_SELECTION_TOOL::CollectHits( EE_COLLECTOR& aCollector, const VECTOR2I& aWhere,
const KICAD_T* aFilterList ) const std::initializer_list<KICAD_T>& aFilterList )
{ {
int pixelThreshold = KiROUND( getView()->ToWorld( HITTEST_THRESHOLD_PIXELS ) ); int pixelThreshold = KiROUND( getView()->ToWorld( HITTEST_THRESHOLD_PIXELS ) );
int gridThreshold = KiROUND( getView()->GetGAL()->GetGridSize().EuclideanNorm() / 2 ); 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<KICAD_T>& aFilterList,
EDA_ITEM** aItem, bool* aSelectionCancelledFlag, EDA_ITEM** aItem, bool* aSelectionCancelledFlag,
bool aCheckLocked, bool aAdd, bool aSubtract, bool aCheckLocked, bool aAdd, bool aSubtract,
bool aExclusiveOr ) 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<KICAD_T>& aFilterList )
{ {
if( m_selection.Empty() ) 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 ) EDA_ITEM* EE_SELECTION_TOOL::GetNode( VECTOR2I aPosition )
{ {
EE_COLLECTOR collector; EE_COLLECTOR collector;
@ -1447,7 +1425,7 @@ EDA_ITEM* EE_SELECTION_TOOL::GetNode( VECTOR2I aPosition )
for( int threshold : { 0, thresholdMax/4, thresholdMax/2, thresholdMax } ) for( int threshold : { 0, thresholdMax/4, thresholdMax/2, thresholdMax } )
{ {
collector.m_Threshold = threshold; collector.m_Threshold = threshold;
collector.Collect( m_frame->GetScreen(), nodeTypes, aPosition ); collector.Collect( m_frame->GetScreen(), connectedTypes, aPosition );
if( collector.GetCount() > 0 ) if( collector.GetCount() > 0 )
break; break;
@ -1461,7 +1439,7 @@ int EE_SELECTION_TOOL::SelectNode( const TOOL_EVENT& aEvent )
{ {
VECTOR2I cursorPos = getViewControls()->GetCursorPosition( false ); VECTOR2I cursorPos = getViewControls()->GetCursorPosition( false );
SelectPoint( cursorPos, nodeTypes ); SelectPoint( cursorPos, connectedTypes );
return 0; return 0;
} }
@ -1469,9 +1447,7 @@ int EE_SELECTION_TOOL::SelectNode( const TOOL_EVENT& aEvent )
int EE_SELECTION_TOOL::SelectConnection( 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( { SCH_ITEM_LOCATE_WIRE_T, SCH_ITEM_LOCATE_BUS_T } );
RequestSelection( wiresAndBuses );
if( m_selection.Empty() ) if( m_selection.Empty() )
return 0; return 0;
@ -1484,8 +1460,11 @@ int EE_SELECTION_TOOL::SelectConnection( const TOOL_EVENT& aEvent )
for( SCH_ITEM* item : conns ) 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; done = true;
}
select( item ); select( item );
} }

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
* Copyright (C) 2019 CERN * 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 * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * 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 * Return either an existing selection (filtered), or the selection at the current
* cursor if the existing selection is empty. * cursor if the existing selection is empty.
*/ */
EE_SELECTION& RequestSelection( const KICAD_T* aFilterList = EE_COLLECTOR::AllItems ); EE_SELECTION&
RequestSelection( const std::initializer_list<KICAD_T>& aFilterList = { SCH_LOCATE_ANY_T } );
/** /**
* This overload of SelectPoint will create an EE_COLLECTOR and collect hits at location aWhere * This overload of SelectPoint will create an EE_COLLECTOR and collect hits at location aWhere
* before calling the primary SelectPoint method. * before calling the primary SelectPoint method.
* *
* @param aWhere is the location where the item(s) should be collected * @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 * @param aItem is set to the newly selected item if only one was selected, otherwise is
* unchanged. * unchanged.
* @param aSelectionCancelledFlag allows the function to inform its caller that a selection * @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 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 * @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<KICAD_T>& aFilterList = { SCH_LOCATE_ANY_T },
EDA_ITEM** aItem = nullptr, bool* aSelectionCancelledFlag = nullptr, EDA_ITEM** aItem = nullptr, bool* aSelectionCancelledFlag = nullptr,
bool aCheckLocked = false, bool aAdd = false, bool aSubtract = false, bool aCheckLocked = false, bool aAdd = false, bool aSubtract = false,
bool aExclusiveOr = false ); bool aExclusiveOr = false );
@ -154,7 +157,7 @@ public:
* @param aCheckLocked indicates if locked items should be excluded. * @param aCheckLocked indicates if locked items should be excluded.
*/ */
bool CollectHits( EE_COLLECTOR& aCollector, const VECTOR2I& aWhere, bool CollectHits( EE_COLLECTOR& aCollector, const VECTOR2I& aWhere,
const KICAD_T* aFilterList = EE_COLLECTOR::AllItems ); const std::initializer_list<KICAD_T>& aFilterList = { SCH_LOCATE_ANY_T } );
protected: protected:
SELECTION& selection() override { return m_selection; } SELECTION& selection() override { return m_selection; }

View File

@ -1330,7 +1330,7 @@ int SCH_DRAWING_TOOLS::TwoClickPlace( const TOOL_EVENT& aEvent )
SCH_HIERLABEL* label = nullptr; SCH_HIERLABEL* label = nullptr;
SCH_SHEET* sheet = 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<SCH_SHEET*>( i ); sheet = dynamic_cast<SCH_SHEET*>( i );
m_selectionTool->ClearSelection(); m_selectionTool->ClearSelection();

View File

@ -176,7 +176,7 @@ bool SCH_EDIT_TOOL::Init()
return sheet->HasUndefinedPins(); 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 = auto haveHighlight =
[&]( const SELECTION& sel ) [&]( const SELECTION& sel )
@ -325,44 +325,58 @@ bool SCH_EDIT_TOOL::Init()
return false; return false;
}; };
static KICAD_T allTextTypes[] = { SCH_LABEL_T, static std::initializer_list<KICAD_T> allTextTypes = { SCH_LABEL_LOCATE_ANY_T,
SCH_DIRECTIVE_LABEL_T,
SCH_GLOBAL_LABEL_T,
SCH_HIER_LABEL_T,
SCH_TEXT_T, SCH_TEXT_T,
SCH_TEXTBOX_T, SCH_TEXTBOX_T };
EOT };
auto toChangeCondition = ( E_C::OnlyTypes( allTextTypes ) ); 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( { SCH_DIRECTIVE_LABEL_T,
auto toLabelCondition = ( E_C::Count( 1 ) && E_C::OnlyTypes( toLabelTypes ) ) SCH_GLOBAL_LABEL_T,
SCH_HIER_LABEL_T,
SCH_TEXT_T,
SCH_TEXTBOX_T } ) )
|| ( E_C::MoreThan( 1 ) && E_C::OnlyTypes( allTextTypes ) ); || ( 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( { SCH_LABEL_T,
auto toCLabelCondition = ( E_C::Count( 1 ) && E_C::OnlyTypes( toCLabelTypes ) ) SCH_HIER_LABEL_T,
SCH_GLOBAL_LABEL_T,
SCH_TEXT_T,
SCH_TEXTBOX_T } ) )
|| ( E_C::MoreThan( 1 ) && E_C::OnlyTypes( allTextTypes ) ); || ( 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( { SCH_LABEL_T,
auto toHLabelCondition = ( E_C::Count( 1 ) && E_C::OnlyTypes( toHLabelTypes ) ) SCH_DIRECTIVE_LABEL_T,
SCH_GLOBAL_LABEL_T,
SCH_TEXT_T,
SCH_TEXTBOX_T } ) )
|| ( E_C::MoreThan( 1 ) && E_C::OnlyTypes( allTextTypes ) ); || ( 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( { SCH_LABEL_T,
auto toGLabelCondition = ( E_C::Count( 1 ) && E_C::OnlyTypes( toGLabelTypes ) ) SCH_DIRECTIVE_LABEL_T,
SCH_HIER_LABEL_T,
SCH_TEXT_T,
SCH_TEXTBOX_T } ) )
|| ( E_C::MoreThan( 1 ) && E_C::OnlyTypes( allTextTypes ) ); || ( 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( { SCH_LABEL_T,
auto toTextCondition = ( E_C::Count( 1 ) && E_C::OnlyTypes( toTextTypes ) ) SCH_DIRECTIVE_LABEL_T,
SCH_GLOBAL_LABEL_T,
SCH_HIER_LABEL_T,
SCH_TEXTBOX_T } ) )
|| ( E_C::MoreThan( 1 ) && E_C::OnlyTypes( allTextTypes ) ); || ( 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( { SCH_LABEL_T,
auto toTextBoxCondition = ( E_C::Count( 1 ) && E_C::OnlyTypes( toTextBoxTypes ) ) SCH_DIRECTIVE_LABEL_T,
SCH_GLOBAL_LABEL_T,
SCH_HIER_LABEL_T,
SCH_TEXT_T } ) )
|| ( E_C::MoreThan( 1 ) && E_C::OnlyTypes( allTextTypes ) ); || ( 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( { SCH_BUS_WIRE_ENTRY_T,
auto entryCondition = E_C::MoreThan( 0 ) && E_C::OnlyTypes( entryTypes ); 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 // 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<KICAD_T> rotatableItems = {
SCH_SHAPE_T, SCH_SHAPE_T,
SCH_TEXT_T, SCH_TEXT_T,
SCH_TEXTBOX_T, SCH_TEXTBOX_T,
@ -526,8 +540,7 @@ const KICAD_T rotatableItems[] = {
SCH_BUS_WIRE_ENTRY_T, SCH_BUS_WIRE_ENTRY_T,
SCH_LINE_T, SCH_LINE_T,
SCH_JUNCTION_T, SCH_JUNCTION_T,
SCH_NO_CONNECT_T, SCH_NO_CONNECT_T
EOT
}; };
@ -1067,7 +1080,7 @@ int SCH_EDIT_TOOL::RepeatDrawItem( const TOOL_EVENT& aEvent )
} }
static KICAD_T deletableItems[] = static std::initializer_list<KICAD_T> deletableItems =
{ {
SCH_MARKER_T, SCH_MARKER_T,
SCH_JUNCTION_T, SCH_JUNCTION_T,
@ -1086,8 +1099,7 @@ static KICAD_T deletableItems[] =
SCH_SHEET_PIN_T, SCH_SHEET_PIN_T,
SCH_SYMBOL_T, SCH_SYMBOL_T,
SCH_FIELD_T, // Will be hidden SCH_FIELD_T, // Will be hidden
SCH_BITMAP_T, SCH_BITMAP_T
EOT
}; };
@ -1298,19 +1310,14 @@ void SCH_EDIT_TOOL::editFieldText( SCH_FIELD* aField )
int SCH_EDIT_TOOL::EditField( const TOOL_EVENT& aEvent ) int SCH_EDIT_TOOL::EditField( const TOOL_EVENT& aEvent )
{ {
static KICAD_T Nothing[] = { EOT }; std::initializer_list<KICAD_T> filter = {};
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;
if( aEvent.IsAction( &EE_ACTIONS::editReference ) ) if( aEvent.IsAction( &EE_ACTIONS::editReference ) )
filter = CmpOrReference; filter = { SCH_FIELD_LOCATE_REFERENCE_T, SCH_SYMBOL_T };
else if( aEvent.IsAction( &EE_ACTIONS::editValue ) ) 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 ) ) 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 ); 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 ) int SCH_EDIT_TOOL::ChangeSymbols( const TOOL_EVENT& aEvent )
{ {
SCH_SYMBOL* selectedSymbol = nullptr; 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() ) if( !selection.Empty() )
selectedSymbol = dynamic_cast<SCH_SYMBOL*>( selection.Front() ); selectedSymbol = dynamic_cast<SCH_SYMBOL*>( selection.Front() );
@ -1428,7 +1435,7 @@ int SCH_EDIT_TOOL::ChangeSymbols( const TOOL_EVENT& aEvent )
int SCH_EDIT_TOOL::ConvertDeMorgan( 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() ) if( selection.Empty() )
return 0; return 0;
@ -1770,14 +1777,9 @@ int SCH_EDIT_TOOL::Properties( const TOOL_EVENT& aEvent )
int SCH_EDIT_TOOL::ChangeTextType( const TOOL_EVENT& aEvent ) int SCH_EDIT_TOOL::ChangeTextType( const TOOL_EVENT& aEvent )
{ {
KICAD_T convertTo = aEvent.Parameter<KICAD_T>(); KICAD_T convertTo = aEvent.Parameter<KICAD_T>();
KICAD_T allTextTypes[] = { SCH_LABEL_T, EE_SELECTION selection = m_selectionTool->RequestSelection( { SCH_LABEL_LOCATE_ANY_T,
SCH_GLOBAL_LABEL_T,
SCH_HIER_LABEL_T,
SCH_DIRECTIVE_LABEL_T,
SCH_TEXT_T, SCH_TEXT_T,
SCH_TEXTBOX_T, SCH_TEXTBOX_T } );
EOT };
EE_SELECTION selection = m_selectionTool->RequestSelection( allTextTypes );
for( unsigned int i = 0; i < selection.GetSize(); ++i ) 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 ) int SCH_EDIT_TOOL::BreakWire( const TOOL_EVENT& aEvent )
{ {
wxPoint cursorPos = (wxPoint) getViewControls()->GetCursorPosition( !aEvent.DisableGridSnapping() ); 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<SCH_LINE*> lines; std::vector<SCH_LINE*> lines;
@ -2097,7 +2099,7 @@ int SCH_EDIT_TOOL::BreakWire( const TOOL_EVENT& aEvent )
int SCH_EDIT_TOOL::CleanupSheetPins( 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(); SCH_SHEET* sheet = (SCH_SHEET*) selection.Front();
if( !sheet || !sheet->HasUndefinedPins() ) 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 ) 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 ) if( selection.GetSize() > 1 )
return 0; return 0;

View File

@ -729,13 +729,8 @@ void SCH_EDITOR_CONTROL::doCrossProbeSchToPcb( const TOOL_EVENT& aEvent, bool aF
#ifdef KICAD_SPICE #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 #define HITTEST_THRESHOLD_PIXELS 5
int SCH_EDITOR_CONTROL::SimProbe( const TOOL_EVENT& aEvent ) int SCH_EDITOR_CONTROL::SimProbe( const TOOL_EVENT& aEvent )
{ {
LOCALE_IO toggle; LOCALE_IO toggle;
@ -835,7 +830,7 @@ int SCH_EDITOR_CONTROL::SimProbe( const TOOL_EVENT& aEvent )
simFrame->AddCurrentPlot( name ); simFrame->AddCurrentPlot( name );
} }
} }
else if( item->IsType( wires ) ) else if( item->IsType( { SCH_ITEM_LOCATE_WIRE_T } ) )
{ {
if( SCH_CONNECTION* conn = static_cast<SCH_ITEM*>( item )->Connection() ) if( SCH_CONNECTION* conn = static_cast<SCH_ITEM*>( item )->Connection() )
{ {
@ -854,7 +849,9 @@ int SCH_EDITOR_CONTROL::SimProbe( const TOOL_EVENT& aEvent )
{ {
EE_COLLECTOR collector; EE_COLLECTOR collector;
collector.m_Threshold = KiROUND( getView()->ToWorld( HITTEST_THRESHOLD_PIXELS ) ); 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<EE_SELECTION_TOOL>(); EE_SELECTION_TOOL* selectionTool = m_toolMgr->GetTool<EE_SELECTION_TOOL>();
selectionTool->GuessSelectionCandidates( collector, aPos ); selectionTool->GuessSelectionCandidates( collector, aPos );
@ -935,7 +932,7 @@ int SCH_EDITOR_CONTROL::SimTune( const TOOL_EVENT& aEvent )
{ {
EE_SELECTION_TOOL* selTool = m_toolMgr->GetTool<EE_SELECTION_TOOL>(); EE_SELECTION_TOOL* selTool = m_toolMgr->GetTool<EE_SELECTION_TOOL>();
EDA_ITEM* item = nullptr; EDA_ITEM* item = nullptr;
selTool->SelectPoint( aPosition, fieldsAndSymbols, &item ); selTool->SelectPoint( aPosition, { SCH_SYMBOL_T, SCH_FIELD_T }, &item );
if( !item ) if( !item )
return false; return false;
@ -970,7 +967,7 @@ int SCH_EDITOR_CONTROL::SimTune( const TOOL_EVENT& aEvent )
{ {
EE_COLLECTOR collector; EE_COLLECTOR collector;
collector.m_Threshold = KiROUND( getView()->ToWorld( HITTEST_THRESHOLD_PIXELS ) ); 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<EE_SELECTION_TOOL>(); EE_SELECTION_TOOL* selectionTool = m_toolMgr->GetTool<EE_SELECTION_TOOL>();
selectionTool->GuessSelectionCandidates( collector, aPos ); 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 ) int SCH_EDITOR_CONTROL::EditWithSymbolEditor( const TOOL_EVENT& aEvent )
{ {
EE_SELECTION_TOOL* selTool = m_toolMgr->GetTool<EE_SELECTION_TOOL>(); EE_SELECTION_TOOL* selTool = m_toolMgr->GetTool<EE_SELECTION_TOOL>();
EE_SELECTION& selection = selTool->RequestSelection( EE_COLLECTOR::SymbolsOnly ); EE_SELECTION& selection = selTool->RequestSelection( { SCH_SYMBOL_T } );
SCH_SYMBOL* symbol = nullptr; SCH_SYMBOL* symbol = nullptr;
SYMBOL_EDIT_FRAME* symbolEditor; SYMBOL_EDIT_FRAME* symbolEditor;

View File

@ -94,8 +94,7 @@ private:
{ {
SCH_EDIT_FRAME* frame = (SCH_EDIT_FRAME*) getToolManager()->GetToolHolder(); SCH_EDIT_FRAME* frame = (SCH_EDIT_FRAME*) getToolManager()->GetToolHolder();
EE_SELECTION_TOOL* selTool = getToolManager()->GetTool<EE_SELECTION_TOOL>(); EE_SELECTION_TOOL* selTool = getToolManager()->GetTool<EE_SELECTION_TOOL>();
KICAD_T busType[] = { SCH_ITEM_LOCATE_BUS_T, EOT }; EE_SELECTION& selection = selTool->RequestSelection( { SCH_ITEM_LOCATE_BUS_T } );
EE_SELECTION& selection = selTool->RequestSelection( busType );
SCH_LINE* bus = (SCH_LINE*) selection.Front(); SCH_LINE* bus = (SCH_LINE*) selection.Front();
Clear(); Clear();
@ -106,7 +105,7 @@ private:
frame->RecalculateConnections( NO_CLEANUP ); frame->RecalculateConnections( NO_CLEANUP );
// Pick up the pointer again because it may have been changed by SchematicCleanUp // 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(); bus = (SCH_LINE*) selection.Front();
} }
@ -200,7 +199,7 @@ bool SCH_LINE_WIRE_BUS_TOOL::Init()
}; };
auto busSelection = EE_CONDITIONS::MoreThan( 0 ) auto busSelection = EE_CONDITIONS::MoreThan( 0 )
&& EE_CONDITIONS::OnlyType( SCH_ITEM_LOCATE_BUS_T ); && EE_CONDITIONS::OnlyTypes( { SCH_ITEM_LOCATE_BUS_T } );
auto haveHighlight = auto haveHighlight =
[&]( const SELECTION& sel ) [&]( const SELECTION& sel )
@ -264,22 +263,22 @@ bool SCH_LINE_WIRE_BUS_TOOL::Init()
bool SCH_LINE_WIRE_BUS_TOOL::IsDrawingLine( const SELECTION& aSelection ) bool SCH_LINE_WIRE_BUS_TOOL::IsDrawingLine( const SELECTION& aSelection )
{ {
static KICAD_T graphicLineType[] = { SCH_ITEM_LOCATE_GRAPHIC_LINE_T, EOT }; return IsDrawingLineWireOrBus( aSelection )
return IsDrawingLineWireOrBus( aSelection ) && aSelection.Front()->IsType( graphicLineType ); && aSelection.Front()->IsType( { SCH_ITEM_LOCATE_GRAPHIC_LINE_T } );
} }
bool SCH_LINE_WIRE_BUS_TOOL::IsDrawingWire( const SELECTION& aSelection ) bool SCH_LINE_WIRE_BUS_TOOL::IsDrawingWire( const SELECTION& aSelection )
{ {
static KICAD_T wireType[] = { SCH_ITEM_LOCATE_WIRE_T, EOT }; return IsDrawingLineWireOrBus( aSelection )
return IsDrawingLineWireOrBus( aSelection ) && aSelection.Front()->IsType( wireType ); && aSelection.Front()->IsType( { SCH_ITEM_LOCATE_WIRE_T } );
} }
bool SCH_LINE_WIRE_BUS_TOOL::IsDrawingBus( const SELECTION& aSelection ) bool SCH_LINE_WIRE_BUS_TOOL::IsDrawingBus( const SELECTION& aSelection )
{ {
static KICAD_T busType[] = { SCH_ITEM_LOCATE_BUS_T, EOT }; return IsDrawingLineWireOrBus( aSelection )
return IsDrawingLineWireOrBus( aSelection ) && aSelection.Front()->IsType( busType ); && aSelection.Front()->IsType( { SCH_ITEM_LOCATE_BUS_T } );
} }

View File

@ -63,7 +63,7 @@ bool SCH_MOVE_TOOL::Init()
auto moveCondition = auto moveCondition =
[]( const SELECTION& aSel ) []( 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; return false;
if( SCH_LINE_WIRE_BUS_TOOL::IsDrawingLineWireOrBus( aSel ) ) if( SCH_LINE_WIRE_BUS_TOOL::IsDrawingLineWireOrBus( aSel ) )

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
* Copyright (C) 2019 CERN * 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 * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * 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 ) int SCH_NAVIGATE_TOOL::EnterSheet( const TOOL_EVENT& aEvent )
{ {
EE_SELECTION_TOOL* selTool = m_toolMgr->GetTool<EE_SELECTION_TOOL>(); EE_SELECTION_TOOL* selTool = m_toolMgr->GetTool<EE_SELECTION_TOOL>();
const EE_SELECTION& selection = selTool->RequestSelection( EE_COLLECTOR::SheetsOnly ); const EE_SELECTION& selection = selTool->RequestSelection( { SCH_SHEET_T } );
if( selection.GetSize() == 1 ) if( selection.GetSize() == 1 )
{ {

View File

@ -239,14 +239,13 @@ int SYMBOL_EDITOR_EDIT_TOOL::Mirror( const TOOL_EVENT& aEvent )
} }
static KICAD_T nonFields[] = static std::initializer_list<KICAD_T> nonFields =
{ {
LIB_SYMBOL_T, LIB_SYMBOL_T,
LIB_SHAPE_T, LIB_SHAPE_T,
LIB_TEXT_T, LIB_TEXT_T,
LIB_TEXTBOX_T, LIB_TEXTBOX_T,
LIB_PIN_T, LIB_PIN_T
EOT
}; };

View File

@ -89,8 +89,6 @@ void SYMBOL_EDITOR_MOVE_TOOL::Reset( RESET_REASON aReason )
int SYMBOL_EDITOR_MOVE_TOOL::Main( const TOOL_EVENT& aEvent ) int SYMBOL_EDITOR_MOVE_TOOL::Main( const TOOL_EVENT& aEvent )
{ {
static KICAD_T fieldsOnly[] = { LIB_FIELD_T, EOT };
KIGFX::VIEW_CONTROLS* controls = getViewControls(); KIGFX::VIEW_CONTROLS* controls = getViewControls();
m_anchorPos = { 0, 0 }; m_anchorPos = { 0, 0 };
@ -98,7 +96,7 @@ 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 // 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). // looking for the stuff under mouse cursor (i.e. Kicad old-style hover selection).
EE_SELECTION& selection = m_frame->IsSymbolAlias() EE_SELECTION& selection = m_frame->IsSymbolAlias()
? m_selectionTool->RequestSelection( fieldsOnly ) ? m_selectionTool->RequestSelection( { LIB_FIELD_T } )
: m_selectionTool->RequestSelection(); : m_selectionTool->RequestSelection();
bool unselect = selection.IsHover(); bool unselect = selection.IsHover();

View File

@ -103,7 +103,7 @@ bool SYMBOL_EDITOR_PIN_TOOL::Init()
return editor->IsSymbolEditable() && !editor->IsSymbolAlias(); 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(); CONDITIONAL_MENU& selToolMenu = m_selectionTool->GetToolMenu().GetMenu();

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application. * 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) 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 * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * 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<KICAD_T>& aScanTypes )
{ {
KICAD_T stype;
INSPECT_RESULT result = INSPECT_RESULT::CONTINUE;
const KICAD_T* p = scanTypes;
bool done = false;
#if 0 && defined(DEBUG) #if 0 && defined(DEBUG)
std::cout << GetClass().mb_str() << ' '; std::cout << GetClass().mb_str() << ' ';
#endif #endif
while( !done ) for( KICAD_T scanType : aScanTypes )
{ {
stype = *p; if( scanType == GERBER_LAYOUT_T )
switch( stype )
{ {
case GERBER_LAYOUT_T:
for( unsigned layer = 0; layer < GetImagesList()->ImagesMaxCount(); ++layer ) for( unsigned layer = 0; layer < GetImagesList()->ImagesMaxCount(); ++layer )
{ {
GERBER_FILE_IMAGE* gerber = GetImagesList()->GetGbrImage( 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 if( gerber == nullptr ) // Graphic layer not yet used
continue; continue;
result = gerber->Visit( inspector, testData, p ); if( gerber->Visit( inspector, testData, { scanType } ) == INSPECT_RESULT::QUIT )
return INSPECT_RESULT::QUIT;
if( result == INSPECT_RESULT::QUIT ) }
break; }
} }
++p; return INSPECT_RESULT::CONTINUE;
break;
default: // catch EOT or ANY OTHER type here and return.
done = true;
break;
}
if( result == INSPECT_RESULT::QUIT )
break;
}
return result;
} }

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application. * 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) 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 * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * 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; } void SetBoundingBox( const EDA_RECT& aBox ) { m_BoundingBox = aBox; }
///< @copydoc EDA_ITEM::Visit() ///< @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<KICAD_T>& aScanTypes ) override;
#if defined(DEBUG) #if defined(DEBUG)
void Show( int nestLevel, std::ostream& os ) const override { ShowDummy( os ); } void Show( int nestLevel, std::ostream& os ) const override { ShowDummy( os ); }

View File

@ -1,7 +1,7 @@
/* /*
* This program source code file is part of KiCad, a free EDA CAD application. * 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 * 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 * under the terms of the GNU General Public License as published by the
@ -19,13 +19,6 @@
#include "gerber_collectors.h" #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. * 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[], void GERBER_COLLECTOR::Collect( EDA_ITEM* aItem, const std::initializer_list<KICAD_T>& aScanList,
const VECTOR2I& aRefPos /*, const COLLECTORS_GUIDE& aGuide*/ ) const VECTOR2I& aRefPos )
{ {
Empty(); // empty the collection, primary criteria list Empty(); // empty the collection, primary criteria list
// remember guide, pass it to Inspect()
//SetGuide( &aGuide );
SetScanTypes( aScanList ); SetScanTypes( aScanList );
// remember where the snapshot was taken from and pass refPos to // 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 ); SetRefPos( aRefPos );
aItem->Visit( m_inspector, nullptr, m_scanTypes ); aItem->Visit( m_inspector, nullptr, m_scanTypes );
// record the length of the primary list before concatenating on to it.
m_PrimaryLength = m_list.size();
} }

View File

@ -1,7 +1,7 @@
/* /*
* This program source code file is part of KiCad, a free EDA CAD application. * 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 * 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 * under the terms of the GNU General Public License as published by the
@ -28,20 +28,9 @@
class GERBER_COLLECTOR : public COLLECTOR class GERBER_COLLECTOR : public COLLECTOR
{ {
public: public:
/**
* A scan list for all selectable gerber items
*/
static const KICAD_T AllItems[];
GERBER_COLLECTOR() GERBER_COLLECTOR()
{ {
m_PrimaryLength = 0; SetScanTypes( { GERBER_LAYOUT_T, GERBER_IMAGE_T, GERBER_DRAW_ITEM_T } );
SetScanTypes( AllItems );
}
void Empty2nd()
{
m_List2nd.clear();
} }
/** /**
@ -58,11 +47,6 @@ public:
return nullptr; 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. * 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. * Scan an EDA_ITEM using this class's Inspector method, which does the collection.
* *
* @param aItem An EDA_ITEM to scan * @param aItem An EDA_ITEM to scan
* @param aScanList A list of KICAD_Ts with a terminating EOT, that specs * @param aScanList A list of KICAD_Ts that specs what is to be collected and the priority
* what is to be collected and the priority order of the resultant * order of the resultant collection in "m_list".
* collection in "m_list".
* @param aRefPos A VECTOR2I to use in hit-testing. * @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[], void Collect( EDA_ITEM* aItem, const std::initializer_list<KICAD_T>& aScanList,
const VECTOR2I& aRefPos /*, const COLLECTORS_GUIDE& aGuide */ ); const VECTOR2I& aRefPos );
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<EDA_ITEM*> 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;
}; };
#endif #endif

View File

@ -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 ) void GERBER_DRAW_ITEM::MoveXY( const VECTOR2I& aMoveVector )
{ {
m_Start += aMoveVector; m_Start += aMoveVector;
@ -997,16 +985,16 @@ double GERBER_DRAW_ITEM::ViewGetLOD( int aLayer, KIGFX::VIEW* aView ) const
INSPECT_RESULT GERBER_DRAW_ITEM::Visit( INSPECTOR inspector, void* testData, INSPECT_RESULT GERBER_DRAW_ITEM::Visit( INSPECTOR inspector, void* testData,
const KICAD_T scanTypes[] ) const std::initializer_list<KICAD_T>& aScanTypes )
{ {
KICAD_T stype = *scanTypes; for( KICAD_T scanType : aScanTypes )
{
// If caller wants to inspect my type if( scanType == Type() )
if( stype == Type() )
{ {
if( INSPECT_RESULT::QUIT == inspector( this, testData ) ) if( INSPECT_RESULT::QUIT == inspector( this, testData ) )
return INSPECT_RESULT::QUIT; return INSPECT_RESULT::QUIT;
} }
}
return INSPECT_RESULT::CONTINUE; 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 GERBER_DRAW_ITEM::GetSelectMenuText( EDA_UNITS aUnits ) const
{ {
wxString layerName; wxString layerName = GERBER_FILE_IMAGE_LIST::GetImagesList().GetDisplayName( GetLayer(), true );
layerName = GERBER_FILE_IMAGE_LIST::GetImagesList().GetDisplayName( GetLayer(), true );
return wxString::Format( _( "%s (D%d) on layer %d: %s" ), return wxString::Format( _( "%s (D%d) on layer %d: %s" ),
ShowGBRShape(), ShowGBRShape(),

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
* Copyright (C) 1992-2016 <Jean-Pierre Charras> * Copyright (C) 1992-2016 <Jean-Pierre Charras>
* 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 * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -75,10 +75,7 @@ public:
*/ */
int GetLayer() const; int GetLayer() const;
bool GetLayerPolarity() const bool GetLayerPolarity() const { return m_LayerNegative; }
{
return m_LayerNegative;
}
/** /**
* Return the best size and orientation to display the D_Code on screen. * Return the best size and orientation to display the D_Code on screen.
@ -106,17 +103,7 @@ public:
*/ */
void SetLayerParameters(); void SetLayerParameters();
void SetLayerPolarity( bool aNegative) void SetLayerPolarity( bool aNegative) { m_LayerNegative = aNegative; }
{
m_LayerNegative = aNegative;
}
/**
* Move this object.
*
* @param aMoveVector the move vector for this object.
*/
void MoveAB( const VECTOR2I& aMoveVector );
/** /**
* Move this object. * Move this object.
@ -231,7 +218,8 @@ public:
double ViewGetLOD( int aLayer, KIGFX::VIEW* aView ) const override; double ViewGetLOD( int aLayer, KIGFX::VIEW* aView ) const override;
///< @copydoc EDA_ITEM::Visit() ///< @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<KICAD_T>& aScanTypes ) override;
///< @copydoc EDA_ITEM::GetSelectMenuText() ///< @copydoc EDA_ITEM::GetSelectMenuText()
virtual wxString GetSelectMenuText( EDA_UNITS aUnits ) const override; virtual wxString GetSelectMenuText( EDA_UNITS aUnits ) const override;

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application. * 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-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 * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * 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 ) EDA_ITEM( nullptr, GERBER_IMAGE_T )
{ {
m_GraphicLayer = aLayer; // Graphic layer Number 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_PositiveDrawColor = WHITE; // The color used to draw positive items for this image
m_Selected_Tool = 0; m_Selected_Tool = 0;
@ -99,7 +98,6 @@ GERBER_FILE_IMAGE::GERBER_FILE_IMAGE( int aLayer ) :
GERBER_FILE_IMAGE::~GERBER_FILE_IMAGE() GERBER_FILE_IMAGE::~GERBER_FILE_IMAGE()
{ {
for( GERBER_DRAW_ITEM* item : GetItems() ) for( GERBER_DRAW_ITEM* item : GetItems() )
delete item; 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 * Function StepAndRepeatItem
* Gerber format has a command Step an Repeat * 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<KICAD_T>& aScanTypes )
{ {
KICAD_T stype; for( KICAD_T scanType : aScanTypes )
INSPECT_RESULT result = INSPECT_RESULT::CONTINUE;
const KICAD_T* p = scanTypes;
bool done = false;
while( !done )
{ {
stype = *p; if( scanType == GERBER_DRAW_ITEM_T )
switch( stype )
{ {
case GERBER_IMAGE_T: if( IterateForward( GetItems(), inspector, testData, { scanType } ) == INSPECT_RESULT::QUIT )
case GERBER_LAYOUT_T: return INSPECT_RESULT::QUIT;
++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( result == INSPECT_RESULT::QUIT ) return INSPECT_RESULT::CONTINUE;
break;
}
return result;
} }

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application. * 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) 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 * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -212,8 +212,6 @@ public:
m_messagesList.Add( aMessage ); m_messagesList.Add( aMessage );
} }
void InitToolTable();
/** /**
* Return the current coordinate type pointed to by XnnYnn Text (XnnnnYmmmm). * Return the current coordinate type pointed to by XnnYnn Text (XnnnnYmmmm).
* *
@ -299,7 +297,8 @@ public:
void RemoveAttribute( X2_ATTRIBUTE& aAttribute ); void RemoveAttribute( X2_ATTRIBUTE& aAttribute );
///< @copydoc EDA_ITEM::Visit() ///< @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<KICAD_T>& aScanTypes ) override;
#if defined(DEBUG) #if defined(DEBUG)
@ -356,78 +355,58 @@ private:
* @param gerber_file Which file to read from for continuation. * @param gerber_file Which file to read from for continuation.
* @return true if a macro was read in successfully, else false. * @return true if a macro was read in successfully, else false.
*/ */
bool ReadApertureMacro( char *aBuff, unsigned int aBuffSize, bool ReadApertureMacro( char *aBuff, unsigned int aBuffSize, char*& text, FILE* gerber_file );
char* & text, FILE * gerber_file );
// functions to execute G commands or D basic commands: // functions to execute G commands or D basic commands:
bool Execute_G_Command( char*& text, int G_command ); bool Execute_G_Command( char*& text, int G_command );
bool Execute_DCODE_Command( char*& text, int D_command ); bool Execute_DCODE_Command( char*& text, int D_command );
public: public:
bool m_InUse; // true if this image is currently in use bool m_InUse; ///< true if this image is currently in use (a file
// (a file is loaded in it) ///< 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 <name>* command
///< True if the draw layer is visible and must be drawn. bool m_IsX2_file; ///< True if a X2 gerber attribute was found in file
bool m_IsVisible; X2_ATTRIBUTE_FILEFUNCTION* m_FileFunction; ///< file function parameters, found in a %TF
// false if it must be not drawn ///< command or a G04
COLOR4D m_PositiveDrawColor; // The color used to draw positive items wxString m_MD5_value; ///< MD5 value found in a %TF.MD5 command
wxString m_FileName; // Full File Name for this layer wxString m_PartString; ///< string found in a %TF.Part command
wxString m_ImageName; // Image name, from IN <name>* 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_ImageJustifyXCenter; ///< Image Justify Center on X axis (default = false)
bool m_IsX2_file; bool m_ImageJustifyYCenter; ///< Image Justify Center on Y axis (default = false)
X2_ATTRIBUTE_FILEFUNCTION* m_FileFunction; // file function parameters, found in a VECTOR2I m_ImageJustifyOffset; ///< Image Justify Offset on XY axis (default = 0,0)
// %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
///< Image Justify Center on X axis (default = false). bool m_GerbMetric; ///< false = Inches, true = metric
bool m_ImageJustifyXCenter; 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). int m_ImageRotation; ///< Image rotation (0, 90, 180, 270 only) in degrees
bool m_ImageJustifyYCenter; 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_Offset; ///< Coord Offset, from OF command
VECTOR2I m_ImageJustifyOffset; VECTOR2I m_Scale; ///< scale (X and Y) of layer.
bool m_GerbMetric; // false = Inches, true = metric bool m_SwapAxis; ///< false if A = X and B = Y (default); true if
///< A = Y, B = X
///< false = absolute Coord, true = relative Coord. bool m_MirrorA; ///< true: mirror / axis A (X)
bool m_Relative; bool m_MirrorB; ///< true: mirror / axis B (Y)
bool m_NoTrailingZeros; // true: remove tailing zeros. int m_Iterpolation; ///< Linear, 90 arc, Circ.
VECTOR2I m_ImageOffset; // Coord Offset, from IO command int m_Current_Tool; ///< Current Tool (Dcode) number selected
int m_Last_Pen_Command; ///< Current or last pen state (0..9, set by Dn
///< Fmt 2.3: m_FmtScale = 3, fmt 3.4: m_FmtScale = 4. ///< option with n < 10
wxSize m_FmtScale; int m_CommandState; ///< state of gerber analysis command
int m_LineNum; ///< Line number of the gerber file while reading.
///< Nb chars per coord. ex fmt 2.3, m_FmtLen = 5. VECTOR2I m_CurrentPos; ///< current specified coord for plot
wxSize m_FmtLen; VECTOR2I m_PreviousPos; ///< old current specified coord for plot
VECTOR2I m_IJPos; ///< IJ coord (for arcs & circles )
///< 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 )
///< True if a IJ coord was read (for arcs & circles ). ///< True if a IJ coord was read (for arcs & circles ).
bool m_LastCoordIsIJPos; bool m_LastCoordIsIJPos;

View File

@ -223,7 +223,7 @@ bool GERBVIEW_SELECTION_TOOL::selectPoint( const VECTOR2I& aWhere )
GERBER_COLLECTOR collector; GERBER_COLLECTOR collector;
EDA_ITEM* model = getModel<EDA_ITEM>(); EDA_ITEM* model = getModel<EDA_ITEM>();
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 // Remove unselectable items
for( int i = collector.GetCount() - 1; i >= 0; --i ) for( int i = collector.GetCount() - 1; i >= 0; --i )

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
* Copyright (C) 2007-2008 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com> * Copyright (C) 2007-2008 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
* 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 * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -51,7 +51,7 @@ public:
COLLECTOR() : COLLECTOR() :
m_Threshold( 0 ), m_Threshold( 0 ),
m_MenuCancelled( false ), m_MenuCancelled( false ),
m_scanTypes( nullptr ), m_scanTypes( {} ),
// Inspect() is virtual so calling it from a class common inspector preserves // Inspect() is virtual so calling it from a class common inspector preserves
// polymorphism. // polymorphism.
m_inspector( [=]( EDA_ITEM* aItem, void* aTestData ) m_inspector( [=]( EDA_ITEM* aItem, void* aTestData )
@ -207,13 +207,9 @@ public:
/** /**
* Record the list of #KICAD_T types to consider for collection by the Inspect() function. * 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 * @param aScanTypes A list of KICAD_Ts.
* is made of this array (so cannot come from caller's stack).
*/ */
void SetScanTypes( const KICAD_T* scanTypes ) void SetScanTypes( const std::initializer_list<KICAD_T>& aTypes ) { m_scanTypes = aTypes; }
{
m_scanTypes = scanTypes;
}
void SetRefPos( const VECTOR2I& aRefPos ) { m_refPos = aRefPos; } void SetRefPos( const VECTOR2I& aRefPos ) { m_refPos = aRefPos; }
@ -247,10 +243,11 @@ protected:
std::vector<EDA_ITEM*> m_list; // Primary list of most likely items std::vector<EDA_ITEM*> m_list; // Primary list of most likely items
std::vector<EDA_ITEM*> m_backupList; // Secondary list with items removed by heuristics std::vector<EDA_ITEM*> m_backupList; // Secondary list with items removed by heuristics
const KICAD_T* m_scanTypes; std::initializer_list<KICAD_T> m_scanTypes;
INSPECTOR_FUNC m_inspector; 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.}; VECTOR2I m_refPos; // Reference pos used to generate the collection.
EDA_RECT m_refBox; // Selection rect used to generate the collection.
}; };
#endif // COLLECTOR_H #endif // COLLECTOR_H

View File

@ -4,7 +4,7 @@
* Copyright (C) 2013-2015 Jean-Pierre Charras, jp.charras at wanadoo.fr * Copyright (C) 2013-2015 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 2008-2015 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com> * Copyright (C) 2008-2015 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
* Copyright (C) 2008 Wayne Stambaugh <stambaughw@gmail.com> * Copyright (C) 2008 Wayne Stambaugh <stambaughw@gmail.com>
* 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 * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -190,14 +190,11 @@ public:
* @param aScanTypes List of item types * @param aScanTypes List of item types
* @return true if the item type is contained in the list aScanTypes * @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<KICAD_T>& aScanTypes ) const
{ {
if( aScanTypes[0] == SCH_LOCATE_ANY_T ) for( KICAD_T scanType : aScanTypes )
return true;
for( const KICAD_T* p = aScanTypes; *p != EOT; ++p )
{ {
if( m_structType == *p ) if( scanType == SCH_LOCATE_ANY_T || scanType == m_structType )
return true; return true;
} }
@ -295,33 +292,35 @@ public:
* May be re-implemented for each derived class in order to handle all the types given * May be re-implemented for each derived class in order to handle all the types given
* by its member data. * 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. * #IterateForward() to do so on lists of such data.
* *
* @param inspector An #INSPECTOR instance to use in the inspection. * @param inspector An #INSPECTOR instance to use in the inspection.
* @param testData Arbitrary data used by the inspector. * @param testData Arbitrary data used by the inspector.
* @param scanTypes Which# KICAD_T types are of interest and the order * @param aScanTypes Which #KICAD_T types are of interest and the order in which they should
* is significant too, terminated by EOT. * be processed.
* @return #SEARCH_RESULT SEARCH_QUIT if the Iterator is to stop the scan, * @return #SEARCH_RESULT SEARCH_QUIT if the Iterator is to stop the scan,
* else #SCAN_CONTINUE, and determined by the inspector. * 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<KICAD_T>& aScanTypes );
/** /**
* This changes first parameter to avoid the DList and use the main queue instead. * This changes first parameter to avoid the DList and use the main queue instead.
*/ */
template< class T > template< class T >
static INSPECT_RESULT IterateForward( std::deque<T>& aList, static INSPECT_RESULT IterateForward( std::deque<T>& aList, INSPECTOR inspector, void* testData,
INSPECTOR inspector, const std::initializer_list<KICAD_T>& scanTypes )
void* testData,
const KICAD_T scanTypes[] )
{ {
for( auto it : aList ) for( const auto& it : aList )
{
if( static_cast<EDA_ITEM*>( it )->Visit( inspector,
testData,
scanTypes ) == INSPECT_RESULT::QUIT )
{ {
if( static_cast<EDA_ITEM*>( it )->Visit( inspector, testData, scanTypes )
== INSPECT_RESULT::QUIT )
return INSPECT_RESULT::QUIT; return INSPECT_RESULT::QUIT;
} }
}
return INSPECT_RESULT::CONTINUE; return INSPECT_RESULT::CONTINUE;
} }
@ -330,15 +329,19 @@ public:
* Change first parameter to avoid the DList and use std::vector instead. * Change first parameter to avoid the DList and use std::vector instead.
*/ */
template <class T> template <class T>
static INSPECT_RESULT IterateForward( static INSPECT_RESULT IterateForward( std::vector<T>& aList, INSPECTOR inspector,
std::vector<T>& aList, INSPECTOR inspector, void* testData, const KICAD_T scanTypes[] ) void* testData,
const std::initializer_list<KICAD_T>& scanTypes )
{ {
for( auto it : aList ) for( const auto& it : aList )
{
if( static_cast<EDA_ITEM*>( it )->Visit( inspector,
testData,
scanTypes ) == INSPECT_RESULT::QUIT )
{ {
if( static_cast<EDA_ITEM*>( it )->Visit( inspector, testData, scanTypes )
== INSPECT_RESULT::QUIT )
return INSPECT_RESULT::QUIT; return INSPECT_RESULT::QUIT;
} }
}
return INSPECT_RESULT::CONTINUE; return INSPECT_RESULT::CONTINUE;
} }

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application. * 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) 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 * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -162,7 +162,7 @@ public:
///< @copydoc EDA_ITEM::Visit ///< @copydoc EDA_ITEM::Visit
INSPECT_RESULT Visit( INSPECTOR aInspector, void* aTestData, INSPECT_RESULT Visit( INSPECTOR aInspector, void* aTestData,
const KICAD_T aScanTypes[] ) override; const std::initializer_list<KICAD_T>& aScanTypes ) override;
///< @copydoc VIEW_ITEM::ViewGetLayers ///< @copydoc VIEW_ITEM::ViewGetLayers
void ViewGetLayers( int aLayers[], int& aCount ) const override; void ViewGetLayers( int aLayers[], int& aCount ) const override;

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
* Copyright (C) 2014 CERN * 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 <maciej.suminski@cern.ch> * @author Maciej Suminski <maciej.suminski@cern.ch>
* *
@ -70,55 +70,31 @@ class SELECTION_CONDITIONS
public: public:
/** /**
* The default condition function (always returns true). * The default condition function (always returns true).
*
* @param aSelection is the selection to be tested.
* @return Always true.
*/ */
static bool ShowAlways( const SELECTION& aSelection ) static bool ShowAlways( const SELECTION& aSelection ) { return true; }
{
return true;
}
/** /**
* Always returns false. * Always returns false.
*
* @param aSelection is the selection to be tested.
* @return Always false.
*/ */
static bool ShowNever( const SELECTION& aSelection ) static bool ShowNever( const SELECTION& aSelection ) { return false; }
{
return false;
}
/** /**
* Test if there are any items selected. * 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 ); static bool NotEmpty( const SELECTION& aSelection );
/** /**
* Test if there are no items selected. * 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 ); static bool Empty( const SELECTION& aSelection );
/** /**
* Test if there no items selected or being edited. * 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 ); static bool Idle( const SELECTION& aSelection );
/** /**
* Test if all selected items are not being edited. * 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 ); 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 * Create a functor that tests if among the selected items there is at least one of a
* given types. * given types.
* *
* @param aTypes is an array containing types that are searched. It has to be ended with * @param aTypes is an array containing types that are searched.
* #KICAD_T::EOT as end marker.
* @return Functor testing for presence of items of a given types. * @return Functor testing for presence of items of a given types.
*/ */
static SELECTION_CONDITION HasTypes( const KICAD_T aTypes[] ); static SELECTION_CONDITION HasTypes( const std::initializer_list<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 );
/** /**
* Create a functor that tests if the selected items are *only* of given types. * 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 * @param aTypes is an array containing types that are searched.
* #KICAD_T::EOT as end marker.
* @return Functor testing if selected items are exclusively of the requested types. * @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<KICAD_T>& aTypes );
/** /**
* Create a functor that tests if the number of selected items is equal to the value given as * 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 ); static bool hasTypeFunc( const SELECTION& aSelection, KICAD_T aType );
///< Helper function used by HasTypes() ///< Helper function used by HasTypes()
static bool hasTypesFunc( const SELECTION& aSelection, const KICAD_T aTypes[] ); static bool hasTypesFunc( const SELECTION& aSelection,
const std::initializer_list<KICAD_T>& aTypes );
///< Helper function used by OnlyType()
static bool onlyTypeFunc( const SELECTION& aSelection, KICAD_T aType );
///< Helper function used by OnlyTypes() ///< 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<KICAD_T>& aTypes );
///< Helper function used by Count() ///< Helper function used by Count()
static bool countFunc( const SELECTION& aSelection, int aNumber ); static bool countFunc( const SELECTION& aSelection, int aNumber );

View File

@ -148,12 +148,10 @@ void PL_POINT_EDITOR::updateEditedPoint( const TOOL_EVENT& aEvent )
int PL_POINT_EDITOR::Main( 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(); KIGFX::VIEW_CONTROLS* controls = getViewControls();
const PL_SELECTION& selection = m_selectionTool->GetSelection(); 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; return 0;
EDA_ITEM* item = (EDA_ITEM*) selection.Front(); EDA_ITEM* item = (EDA_ITEM*) selection.Front();

View File

@ -310,63 +310,17 @@ void BOARD::SetPosition( const VECTOR2I& aPos )
void BOARD::Move( const VECTOR2I& aMoveVector ) // overload void BOARD::Move( const VECTOR2I& aMoveVector ) // overload
{ {
// @todo : anything like this elsewhere? maybe put into GENERAL_COLLECTOR class. INSPECTOR_FUNC inspector =
static const KICAD_T top_level_board_stuff[] = { [&] ( EDA_ITEM* item, void* testData )
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 )
{ {
BOARD_ITEM* brd_item = (BOARD_ITEM*) item;
// aMoveVector was snapshotted, don't need "data". // aMoveVector was snapshotted, don't need "data".
brd_item->Move( aMoveVector ); static_cast<BOARD_ITEM*>( item )->Move( aMoveVector );
return INSPECT_RESULT::CONTINUE; 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<PCB_TRACK*>( 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 ) bool BOARD::SetLayerDescr( PCB_LAYER_ID aIndex, const LAYER& aLayer )
{ {
if( unsigned( aIndex ) < arrayDim( m_layers ) ) if( unsigned( aIndex ) < arrayDim( m_layers ) )
@ -1272,27 +1226,25 @@ void BOARD::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>
} }
INSPECT_RESULT BOARD::Visit( INSPECTOR inspector, void* testData, const KICAD_T scanTypes[] ) INSPECT_RESULT BOARD::Visit( INSPECTOR inspector, void* testData,
const std::initializer_list<KICAD_T>& scanTypes )
{ {
KICAD_T stype;
INSPECT_RESULT result = INSPECT_RESULT::CONTINUE;
const KICAD_T* p = scanTypes;
bool done = false;
#if 0 && defined(DEBUG) #if 0 && defined(DEBUG)
std::cout << GetClass().mb_str() << ' '; std::cout << GetClass().mb_str() << ' ';
#endif #endif
while( !done ) bool footprintsScanned = false;
{ bool drawingsScanned = false;
stype = *p; bool tracksScanned = false;
switch( stype ) for( KICAD_T scanType : scanTypes )
{
switch( scanType )
{ {
case PCB_T: case PCB_T:
result = inspector( this, testData ); // inspect me if( inspector( this, testData ) == INSPECT_RESULT::QUIT )
// skip over any types handled in the above call. return INSPECT_RESULT::QUIT;
++p;
break; 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_RADIAL_T:
case PCB_FP_DIM_ORTHOGONAL_T: case PCB_FP_DIM_ORTHOGONAL_T:
case PCB_FP_ZONE_T: case PCB_FP_ZONE_T:
if( !footprintsScanned )
// this calls FOOTPRINT::Visit() on each footprint.
result = IterateForward<FOOTPRINT*>( m_footprints, inspector, testData, p );
// skip over any types handled in the above call.
for( ; ; )
{ {
switch( stype = *++p ) if( IterateForward<FOOTPRINT*>( m_footprints, inspector, testData, scanTypes )
== INSPECT_RESULT::QUIT )
{ {
case PCB_FOOTPRINT_T: return INSPECT_RESULT::QUIT;
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:
;
} }
break; footprintsScanned = true;
} }
break; break;
@ -1353,84 +1287,68 @@ INSPECT_RESULT BOARD::Visit( INSPECTOR inspector, void* testData, const KICAD_T
case PCB_DIM_ORTHOGONAL_T: case PCB_DIM_ORTHOGONAL_T:
case PCB_DIM_LEADER_T: case PCB_DIM_LEADER_T:
case PCB_TARGET_T: case PCB_TARGET_T:
result = IterateForward<BOARD_ITEM*>( m_drawings, inspector, testData, p ); if( !drawingsScanned )
// skip over any types handled in the above call.
for( ; ; )
{ {
switch( stype = *++p ) if( IterateForward<BOARD_ITEM*>( m_drawings, inspector, testData, scanTypes )
== INSPECT_RESULT::QUIT )
{ {
case PCB_SHAPE_T: return INSPECT_RESULT::QUIT;
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:
;
} }
break; drawingsScanned = true;
} }
break; break;
case PCB_VIA_T: case PCB_VIA_T:
result = IterateForward<PCB_TRACK*>( m_tracks, inspector, testData, p );
++p;
break;
case PCB_TRACE_T: case PCB_TRACE_T:
case PCB_ARC_T: case PCB_ARC_T:
result = IterateForward<PCB_TRACK*>( m_tracks, inspector, testData, p ); if( !tracksScanned )
++p; {
if( IterateForward<PCB_TRACK*>( m_tracks, inspector, testData, scanTypes )
== INSPECT_RESULT::QUIT )
{
return INSPECT_RESULT::QUIT;
}
tracksScanned = true;
}
break; break;
case PCB_MARKER_T: case PCB_MARKER_T:
for( PCB_MARKER* marker : m_markers ) for( PCB_MARKER* marker : m_markers )
{ {
result = marker->Visit( inspector, testData, p ); if( marker->Visit( inspector, testData, { scanType } ) == INSPECT_RESULT::QUIT )
return INSPECT_RESULT::QUIT;
if( result == INSPECT_RESULT::QUIT )
break;
} }
++p;
break; break;
case PCB_ZONE_T: case PCB_ZONE_T:
for( ZONE* zone : m_zones) for( ZONE* zone : m_zones)
{ {
result = zone->Visit( inspector, testData, p ); if( zone->Visit( inspector, testData, { scanType } ) == INSPECT_RESULT::QUIT )
return INSPECT_RESULT::QUIT;
if( result == INSPECT_RESULT::QUIT )
break;
} }
++p;
break; break;
case PCB_GROUP_T: case PCB_GROUP_T:
result = IterateForward<PCB_GROUP*>( m_groups, inspector, testData, p ); if( IterateForward<PCB_GROUP*>( m_groups, inspector, testData, { scanType } )
++p; == INSPECT_RESULT::QUIT )
break; {
return INSPECT_RESULT::QUIT;
default: // catch EOT or ANY OTHER type here and return.
done = true;
break;
} }
if( result == INSPECT_RESULT::QUIT ) break;
default:
break; break;
} }
}
return result; return INSPECT_RESULT::CONTINUE;
} }
@ -1982,13 +1900,6 @@ const std::vector<BOARD_CONNECTED_ITEM*> BOARD::AllConnectedItems()
} }
void BOARD::ClearAllNetCodes()
{
for( BOARD_CONNECTED_ITEM* item : AllConnectedItems() )
item->SetNetCode( 0 );
}
void BOARD::MapNets( const BOARD* aDestBoard ) void BOARD::MapNets( const BOARD* aDestBoard )
{ {
for( BOARD_CONNECTED_ITEM* item : AllConnectedItems() ) for( BOARD_CONNECTED_ITEM* item : AllConnectedItems() )

View File

@ -806,12 +806,12 @@ public:
* to do so on lists of such data. * to do so on lists of such data.
* @param inspector An INSPECTOR instance to use in the inspection. * @param inspector An INSPECTOR instance to use in the inspection.
* @param testData Arbitrary data used by the inspector. * @param testData Arbitrary data used by the inspector.
* @param scanTypes Which KICAD_T types are of interest and the order * @param scanTypes Which KICAD_T types are of interest and the order to process them in.
* is significant too, terminated by EOT.
* @return SEARCH_QUIT if the Iterator is to stop the scan, else SCAN_CONTINUE, and * @return SEARCH_QUIT if the Iterator is to stop the scan, else SCAN_CONTINUE, and
* determined by the inspector. * 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<KICAD_T>& scanTypes ) override;
/** /**
* Search for a FOOTPRINT within this board with the given reference designator. * Search for a FOOTPRINT within this board with the given reference designator.
@ -1010,15 +1010,6 @@ public:
*/ */
std::tuple<int, double, double> GetTrackLength( const PCB_TRACK& aTrack ) const; std::tuple<int, double, double> 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. * 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, FOOTPRINT* GetFootprint( const VECTOR2I& aPosition, PCB_LAYER_ID aActiveLayer,
bool aVisibleOnly, bool aIgnoreLocked = false ) const; 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 * 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 * board. This allows us to share layouts which came from the same hierarchical sheet in

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
* Copyright (C) 2007-2008 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com> * Copyright (C) 2007-2008 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
* 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 * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -37,16 +37,8 @@
#include <macros.h> #include <macros.h>
#include <math/util.h> // for KiROUND #include <math/util.h> // 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 std::initializer_list<KICAD_T> GENERAL_COLLECTOR::AllBoardItems = {
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 ****
PCB_MARKER_T, // in m_markers PCB_MARKER_T, // in m_markers
PCB_TEXT_T, // in m_drawings PCB_TEXT_T, // in m_drawings
PCB_BITMAP_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_FP_TEXTBOX_T, // in footprints
PCB_FOOTPRINT_T, // in m_footprints PCB_FOOTPRINT_T, // in m_footprints
PCB_GROUP_T, // in m_groups PCB_GROUP_T, // in m_groups
PCB_ZONE_T, // in m_zones PCB_ZONE_T // in m_zones
EOT
}; };
const KICAD_T GENERAL_COLLECTOR::BoardLevelItems[] = { const std::initializer_list<KICAD_T> GENERAL_COLLECTOR::BoardLevelItems = {
PCB_MARKER_T, PCB_MARKER_T,
PCB_BITMAP_T, PCB_BITMAP_T,
PCB_TEXT_T, PCB_TEXT_T,
@ -88,27 +79,11 @@ const KICAD_T GENERAL_COLLECTOR::BoardLevelItems[] = {
PCB_TRACE_T, PCB_TRACE_T,
PCB_FOOTPRINT_T, PCB_FOOTPRINT_T,
PCB_GROUP_T, PCB_GROUP_T,
PCB_ZONE_T, PCB_ZONE_T
EOT
}; };
const KICAD_T GENERAL_COLLECTOR::Footprints[] = { const std::initializer_list<KICAD_T> GENERAL_COLLECTOR::FootprintItems = {
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[] = {
PCB_FP_TEXT_T, PCB_FP_TEXT_T,
PCB_FP_TEXTBOX_T, PCB_FP_TEXTBOX_T,
PCB_FP_SHAPE_T, PCB_FP_SHAPE_T,
@ -120,57 +95,15 @@ const KICAD_T GENERAL_COLLECTOR::FootprintItems[] = {
PCB_PAD_T, PCB_PAD_T,
PCB_FP_ZONE_T, PCB_FP_ZONE_T,
PCB_GROUP_T, PCB_GROUP_T,
PCB_BITMAP_T, PCB_BITMAP_T
EOT
}; };
const KICAD_T GENERAL_COLLECTOR::Tracks[] = { const std::initializer_list<KICAD_T> GENERAL_COLLECTOR::DraggableItems = {
PCB_TRACE_T,
PCB_ARC_T,
PCB_VIA_T,
EOT
};
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[] = {
PCB_TRACE_T, PCB_TRACE_T,
PCB_VIA_T, PCB_VIA_T,
PCB_FOOTPRINT_T, PCB_FOOTPRINT_T,
PCB_ARC_T, PCB_ARC_T
EOT
}; };
@ -184,7 +117,6 @@ INSPECT_RESULT GENERAL_COLLECTOR::Inspect( EDA_ITEM* testItem, void* testData )
PCB_VIA* via = nullptr; PCB_VIA* via = nullptr;
PCB_MARKER* marker = nullptr; PCB_MARKER* marker = nullptr;
ZONE* zone = nullptr; ZONE* zone = nullptr;
PCB_SHAPE* shape = nullptr;
PCB_DIMENSION_BASE* dimension = nullptr; PCB_DIMENSION_BASE* dimension = nullptr;
#if 0 // debugging #if 0 // debugging
@ -291,7 +223,7 @@ INSPECT_RESULT GENERAL_COLLECTOR::Inspect( EDA_ITEM* testItem, void* testData )
case PCB_TRACE_T: case PCB_TRACE_T:
case PCB_ARC_T: case PCB_ARC_T:
if( m_Guide->IgnoreTracks() ) if( m_Guide->IgnoreTracks() )
goto exit; return INSPECT_RESULT::CONTINUE;
break; break;
@ -307,10 +239,7 @@ INSPECT_RESULT GENERAL_COLLECTOR::Inspect( EDA_ITEM* testItem, void* testData )
case PCB_TEXT_T: case PCB_TEXT_T:
case PCB_TEXTBOX_T: case PCB_TEXTBOX_T:
break;
case PCB_SHAPE_T: case PCB_SHAPE_T:
shape = static_cast<PCB_SHAPE*>( item );
break; break;
case PCB_FP_DIM_ALIGNED_T: 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<FP_TEXT*>( item ); FP_TEXT *text = static_cast<FP_TEXT*>( item );
if( !text->IsVisible() ) if( !text->IsVisible() )
goto exit; return INSPECT_RESULT::CONTINUE;
} }
if( m_Guide->IgnoreFPTextOnBack() && IsBackLayer( layer ) ) if( m_Guide->IgnoreFPTextOnBack() && IsBackLayer( layer ) )
goto exit; return INSPECT_RESULT::CONTINUE;
if( m_Guide->IgnoreFPTextOnFront() && IsFrontLayer( layer ) ) 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 * 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: case FP_TEXT::TEXT_is_REFERENCE:
if( m_Guide->IgnoreFPReferences() ) if( m_Guide->IgnoreFPReferences() )
goto exit; return INSPECT_RESULT::CONTINUE;
break; break;
case FP_TEXT::TEXT_is_VALUE: case FP_TEXT::TEXT_is_VALUE:
if( m_Guide->IgnoreFPValues() ) if( m_Guide->IgnoreFPValues() )
goto exit; return INSPECT_RESULT::CONTINUE;
break; break;
case FP_TEXT::TEXT_is_DIVERS: case FP_TEXT::TEXT_is_DIVERS:
if( !m_Guide->IsLayerVisible( layer ) ) if( !m_Guide->IsLayerVisible( layer ) )
goto exit; return INSPECT_RESULT::CONTINUE;
break; break;
} }
@ -391,7 +320,6 @@ INSPECT_RESULT GENERAL_COLLECTOR::Inspect( EDA_ITEM* testItem, void* testData )
} }
case PCB_FP_SHAPE_T: case PCB_FP_SHAPE_T:
shape = static_cast<FP_SHAPE*>( item );
break; break;
case PCB_FOOTPRINT_T: 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( footprint ) // true from case PCB_PAD_T, PCB_FP_TEXT_T, or PCB_FOOTPRINT_T
{ {
if( m_Guide->IgnoreFootprintsOnBack() && ( footprint->GetLayer() == B_Cu ) ) if( m_Guide->IgnoreFootprintsOnBack() && ( footprint->GetLayer() == B_Cu ) )
goto exit; return INSPECT_RESULT::CONTINUE;
if( m_Guide->IgnoreFootprintsOnFront() && ( footprint->GetLayer() == F_Cu ) ) if( m_Guide->IgnoreFootprintsOnFront() && ( footprint->GetLayer() == F_Cu ) )
goto exit; return INSPECT_RESULT::CONTINUE;
} }
// Pads are not sensitive to the layer visibility controls. // 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( pad )
{ {
if( m_Guide->IgnorePads() ) if( m_Guide->IgnorePads() )
goto exit; return INSPECT_RESULT::CONTINUE;
if( ! pad_through ) if( ! pad_through )
{ {
if( m_Guide->IgnorePadsOnFront() && pad->IsOnLayer(F_Cu ) ) if( m_Guide->IgnorePadsOnFront() && pad->IsOnLayer(F_Cu ) )
goto exit; return INSPECT_RESULT::CONTINUE;
if( m_Guide->IgnorePadsOnBack() && pad->IsOnLayer(B_Cu ) ) 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 ) ) if( marker->HitTest( m_refPos ) )
Append( item ); Append( item );
goto exit; return INSPECT_RESULT::CONTINUE;
} }
if( group ) if( group )
@ -454,7 +382,7 @@ INSPECT_RESULT GENERAL_COLLECTOR::Inspect( EDA_ITEM* testItem, void* testData )
if( group->HitTest( m_refPos ) ) if( group->HitTest( m_refPos ) )
Append( item ); Append( item );
goto exit; return INSPECT_RESULT::CONTINUE;
} }
if( via ) 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->IgnoreBlindBuriedVias() && type == VIATYPE::BLIND_BURIED )
|| ( m_Guide->IgnoreMicroVias() && type == VIATYPE::MICROVIA ) ) || ( 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 ) ) || zone->HitTestForEdge( m_refPos, accuracy ) )
{ {
Append( item ); Append( item );
goto exit; return INSPECT_RESULT::CONTINUE;
} }
else if( !m_Guide->IgnoreZoneFills() ) else if( !m_Guide->IgnoreZoneFills() )
{ {
@ -495,7 +423,7 @@ INSPECT_RESULT GENERAL_COLLECTOR::Inspect( EDA_ITEM* testItem, void* testData )
&& zone->HitTestFilledArea( layer, m_refPos ) ) && zone->HitTestFilledArea( layer, m_refPos ) )
{ {
Append( item ); 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 ) ) && footprint->HitTestAccurate( m_refPos, accuracy ) )
{ {
Append( item ); Append( item );
goto exit; return INSPECT_RESULT::CONTINUE;
} }
} }
else if( pad || via ) else if( pad || via )
@ -514,7 +442,7 @@ INSPECT_RESULT GENERAL_COLLECTOR::Inspect( EDA_ITEM* testItem, void* testData )
if( item->HitTest( m_refPos, accuracy ) ) if( item->HitTest( m_refPos, accuracy ) )
{ {
Append( item ); Append( item );
goto exit; return INSPECT_RESULT::CONTINUE;
} }
} }
else else
@ -533,14 +461,13 @@ INSPECT_RESULT GENERAL_COLLECTOR::Inspect( EDA_ITEM* testItem, void* testData )
if( item->HitTest( m_refPos, accuracy ) ) if( item->HitTest( m_refPos, accuracy ) )
{ {
Append( item ); Append( item );
goto exit; return INSPECT_RESULT::CONTINUE;
} }
} }
} }
} }
if( m_Guide->IncludeSecondary() if( m_Guide->IncludeSecondary() && ( !item->IsLocked() || !m_Guide->IgnoreLockedItems() ) )
&& ( !item->IsLocked() || !m_Guide->IgnoreLockedItems() ) )
{ {
// for now, "secondary" means "tolerate any visible layer". It has no effect on other // 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 // 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 ) ) || zone->HitTestForEdge( m_refPos, accuracy ) )
{ {
Append2nd( item ); Append2nd( item );
goto exit; return INSPECT_RESULT::CONTINUE;
} }
else if( !m_Guide->IgnoreZoneFills() ) else if( !m_Guide->IgnoreZoneFills() )
{ {
@ -568,7 +495,7 @@ INSPECT_RESULT GENERAL_COLLECTOR::Inspect( EDA_ITEM* testItem, void* testData )
&& zone->HitTestFilledArea( layer, m_refPos ) ) && zone->HitTestFilledArea( layer, m_refPos ) )
{ {
Append2nd( item ); 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 ) ) && footprint->HitTestAccurate( m_refPos, accuracy ) )
{ {
Append2nd( item ); Append2nd( item );
goto exit; return INSPECT_RESULT::CONTINUE;
} }
} }
else if( pad || via ) else if( pad || via )
@ -587,7 +514,7 @@ INSPECT_RESULT GENERAL_COLLECTOR::Inspect( EDA_ITEM* testItem, void* testData )
if( item->HitTest( m_refPos, accuracy ) ) if( item->HitTest( m_refPos, accuracy ) )
{ {
Append2nd( item ); Append2nd( item );
goto exit; return INSPECT_RESULT::CONTINUE;
} }
} }
else else
@ -606,18 +533,18 @@ INSPECT_RESULT GENERAL_COLLECTOR::Inspect( EDA_ITEM* testItem, void* testData )
if( item->HitTest( m_refPos, accuracy ) ) if( item->HitTest( m_refPos, accuracy ) )
{ {
Append2nd( item ); Append2nd( item );
goto exit; return INSPECT_RESULT::CONTINUE;
} }
} }
} }
} }
exit:
return INSPECT_RESULT::CONTINUE; // always when collecting 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<KICAD_T>& aScanTypes,
const VECTOR2I& aRefPos, const COLLECTORS_GUIDE& aGuide ) const VECTOR2I& aRefPos, const COLLECTORS_GUIDE& aGuide )
{ {
Empty(); // empty the collection, primary criteria list 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() // remember guide, pass it to Inspect()
SetGuide( &aGuide ); SetGuide( &aGuide );
SetScanTypes( aScanList ); SetScanTypes( aScanTypes );
// remember where the snapshot was taken from and pass refPos to // remember where the snapshot was taken from and pass refPos to
// the Inspect() function. // 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 ); 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 // append 2nd list onto end of the first list
for( unsigned i = 0; i<m_List2nd.size(); ++i ) for( unsigned i = 0; i<m_List2nd.size(); ++i )
Append( m_List2nd[i] ); Append( m_List2nd[i] );
@ -647,19 +571,18 @@ void GENERAL_COLLECTOR::Collect( BOARD_ITEM* aItem, const KICAD_T aScanList[],
INSPECT_RESULT PCB_TYPE_COLLECTOR::Inspect( EDA_ITEM* testItem, void* testData ) INSPECT_RESULT PCB_TYPE_COLLECTOR::Inspect( EDA_ITEM* testItem, void* testData )
{ {
// The Visit() function only visits the testItem if its type was in the // The Visit() function only visits the testItem if its type was in the the scanList,
// the scanList, so therefore we can collect anything given to us here. // so therefore we can collect anything given to us here.
Append( testItem ); Append( testItem );
return INSPECT_RESULT::CONTINUE; // always when collecting return INSPECT_RESULT::CONTINUE; // always when collecting
} }
void PCB_TYPE_COLLECTOR::Collect( BOARD_ITEM* aBoard, const KICAD_T aScanList[] ) void PCB_TYPE_COLLECTOR::Collect( BOARD_ITEM* aBoard, const std::initializer_list<KICAD_T>& aTypes )
{ {
Empty(); // empty any existing collection Empty();
aBoard->Visit( m_inspector, nullptr, aTypes );
aBoard->Visit( m_inspector, nullptr, aScanList );
} }
@ -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<KICAD_T>& aTypes )
{ {
Empty(); Empty();
aBoard->Visit( m_inspector, nullptr, aTypes );
aBoard->Visit( m_inspector, nullptr, aScanList );
} }

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
* Copyright (C) 2007-2008 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com> * Copyright (C) 2007-2008 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
* 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 * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -25,35 +25,27 @@
#ifndef COLLECTORS_H #ifndef COLLECTORS_H
#define COLLECTORS_H #define COLLECTORS_H
/* /*
* This module contains a number of COLLECTOR implementations which are used * This module contains a number of COLLECTOR implementations which are used
* to augment the functionality of class PCB_EDIT_FRAME. * to augment the functionality of class PCB_EDIT_FRAME.
*/ */
#include <collector.h> #include <collector.h>
#include <layer_ids.h> // LAYER_COUNT, layer defs #include <layer_ids.h> // LAYER_COUNT, layer defs
#include <view/view.h> #include <view/view.h>
#include <board_item.h> #include <board_item.h>
/** /**
* An abstract base class whose derivatives may be passed to a GENERAL_COLLECTOR, * An abstract base class whose derivatives may be passed to a GENERAL_COLLECTOR telling it what
* telling GENERAL_COLLECTOR what should be collected (aside from HitTest()ing * should be collected (aside from HitTest()ing and KICAD_T scanTypes, which are provided to the
* and KICAD_T scanTypes[], information which are provided to the GENERAL_COLLECTOR * GENERAL_COLLECTOR through attributes or arguments separately).
* through attributes or arguments separately).
* <p> * <p>
* A justification for this class is to keep the structural storage details of * A justification for this class is to keep the structural storage details of the program's
* the program's "global preferences" or "configuration options" out of * "configuration options" out of GENERAL_COLLECTOR::Inspect(). This class carries all the
* GENERAL_COLLECTOR::Inspect(). This class carries all the necessary details * necessary details with it into the Inspect() call. The constructors or other functions of this
* in with it to the Inspect() call. The constructors or other functions of * class's derivatives are then the only place where knowledge of the specific structure of the
* this class's derivatives are then the only place where knowledge of the * global preference storage is needed. Thus, GENERAL_COLLECTOR::Inspect() can be kept as simple
* specific structure of the global preference storage is needed. Thus, * as possible, and insulated from changes in global preference storage.
* 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).
* </p> * </p>
* This class introduces the notion of layer locking. * This class introduces the notion of layer locking.
*/ */
@ -62,19 +54,8 @@ class COLLECTORS_GUIDE
public: public:
virtual ~COLLECTORS_GUIDE() {} virtual ~COLLECTORS_GUIDE() {}
/**
* @return true if the given layer is visible, else false.
*/
virtual bool IsLayerVisible( PCB_LAYER_ID layer ) const = 0; virtual bool IsLayerVisible( PCB_LAYER_ID layer ) const = 0;
/**
* @return the preferred layer for HitTest()ing.
*/
virtual PCB_LAYER_ID GetPreferredLayer() const = 0; virtual PCB_LAYER_ID GetPreferredLayer() const = 0;
/**
* @return true if should ignore locked items, else false.
*/
virtual bool IgnoreLockedItems() const = 0; virtual bool IgnoreLockedItems() const = 0;
/** /**
@ -89,91 +70,29 @@ public:
*/ */
virtual bool IgnoreHiddenFPText() const = 0; virtual bool IgnoreHiddenFPText() const = 0;
/**
* @return true if should ignore footprint text on back layers
*/
virtual bool IgnoreFPTextOnBack() const = 0; virtual bool IgnoreFPTextOnBack() const = 0;
/**
* @return true if should ignore footprint text on front layers.
*/
virtual bool IgnoreFPTextOnFront() const = 0; virtual bool IgnoreFPTextOnFront() const = 0;
/**
* @return true if should ignore FOOTPRINTs on Back Side.
*/
virtual bool IgnoreFootprintsOnBack() const = 0; virtual bool IgnoreFootprintsOnBack() const = 0;
/**
* @return true if should ignore FOOTPRINTs on Front Side.
*/
virtual bool IgnoreFootprintsOnFront() const = 0; virtual bool IgnoreFootprintsOnFront() const = 0;
/**
* @return true if should ignore Pads on Back Side.
*/
virtual bool IgnorePadsOnBack() const = 0; virtual bool IgnorePadsOnBack() const = 0;
/**
* @return true if should ignore PADSs on Front Side.
*/
virtual bool IgnorePadsOnFront() const = 0; virtual bool IgnorePadsOnFront() const = 0;
/**
* @return true if should ignore through-hole PADSs.
*/
virtual bool IgnoreThroughHolePads() const = 0; virtual bool IgnoreThroughHolePads() const = 0;
/**
* @return true if should ignore PADSs on Front side and Back side.
*/
virtual bool IgnorePads() const virtual bool IgnorePads() const
{ {
return IgnorePadsOnFront() && IgnorePadsOnBack() && IgnoreThroughHolePads(); return IgnorePadsOnFront() && IgnorePadsOnBack() && IgnoreThroughHolePads();
} }
/**
* @return true if should ignore footprint values.
*/
virtual bool IgnoreFPValues() const = 0; virtual bool IgnoreFPValues() const = 0;
/**
* @return true if should ignore footprint references.
*/
virtual bool IgnoreFPReferences() const = 0; virtual bool IgnoreFPReferences() const = 0;
/**
* @return true if should ignore through-hole vias
*/
virtual bool IgnoreThroughVias() const = 0; virtual bool IgnoreThroughVias() const = 0;
/**
* @return true if should ignore blind/buried vias
*/
virtual bool IgnoreBlindBuriedVias() const = 0; virtual bool IgnoreBlindBuriedVias() const = 0;
/**
* @return true if should ignore micro vias
*/
virtual bool IgnoreMicroVias() const = 0; virtual bool IgnoreMicroVias() const = 0;
/**
* @return true if should ignore tracks
*/
virtual bool IgnoreTracks() const = 0; virtual bool IgnoreTracks() const = 0;
/**
* @return true if should ignore the interiors of zones
*/
virtual bool IgnoreZoneFills() const = 0; virtual bool IgnoreZoneFills() const = 0;
virtual double OnePixelInIU() 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. * 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. * 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 * Philosophy: this class knows nothing of the context in which a BOARD is used and that means
* and that means it knows nothing about which layers are visible or current, * it knows nothing about which layers are visible or current, but can handle those concerns by
* but can handle those concerns by the SetPreferredLayer() function and the * the SetPreferredLayer() function and the SetLayerSet() function.
* SetLayerSet() function.
*/ */
class GENERAL_COLLECTOR : public PCB_COLLECTOR class GENERAL_COLLECTOR : public PCB_COLLECTOR
{ {
@ -231,69 +149,32 @@ protected:
*/ */
const COLLECTORS_GUIDE* m_Guide; 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: public:
/** /**
* A scan list for all editable board items * A scan list for all editable board items
*/ */
static const KICAD_T AllBoardItems[]; static const std::initializer_list<KICAD_T> AllBoardItems;
/**
* A scan list for zones outlines only
*/
static const KICAD_T Zones[];
/** /**
* A scan list for all primary board items, omitting items which are subordinate to * A scan list for all primary board items, omitting items which are subordinate to
* a FOOTPRINT, such as PAD and FP_TEXT. * a FOOTPRINT, such as PAD and FP_TEXT.
*/ */
static const KICAD_T BoardLevelItems[]; static const std::initializer_list<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[];
/** /**
* A scan list for primary footprint items. * A scan list for primary footprint items.
*/ */
static const KICAD_T FootprintItems[]; static const std::initializer_list<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[];
/** /**
* A scan list for items that can be dragged * A scan list for items that can be dragged
*/ */
static const KICAD_T DraggableItems[]; static const std::initializer_list<KICAD_T> DraggableItems;
GENERAL_COLLECTOR() GENERAL_COLLECTOR() :
m_Guide( nullptr )
{ {
m_Guide = nullptr;
m_PrimaryLength = 0;
SetScanTypes( AllBoardItems ); SetScanTypes( AllBoardItems );
} }
@ -316,20 +197,13 @@ public:
const COLLECTORS_GUIDE* GetGuide() const { return m_Guide; } 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. * The examining function within the INSPECTOR which is passed to the Iterate function.
*
* Search and collect all the objects which match the test data. * Search and collect all the objects which match the test data.
* *
* @param testItem An EDA_ITEM to examine. * @param testItem An EDA_ITEM to examine.
* @param testData is not used in this class. * @param testData is not used in this class.
* @return SEARCH_RESULT - SEARCH_QUIT if the Iterator is to stop the scan, * @return SEARCH_QUIT if the Iterator is to stop the scan, else SCAN_CONTINUE
* else SCAN_CONTINUE;
*/ */
INSPECT_RESULT Inspect( EDA_ITEM* testItem, void* testData ) override; 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. * 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 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 * @param aScanList A list of KICAD_Ts that specs what is to be collected and the priority
* what is to be collected and the priority order of the resultant * order of the resultant collection in "m_list".
* collection in "m_list".
* @param aRefPos A wxPoint to use in hit-testing. * @param aRefPos A wxPoint to use in hit-testing.
* @param aGuide The COLLECTORS_GUIDE to use in collecting items. * @param aGuide The COLLECTORS_GUIDE to use in collecting items.
*/ */
void Collect( BOARD_ITEM* aItem, const KICAD_T aScanList[], const VECTOR2I& aRefPos, void Collect( BOARD_ITEM* aItem, const std::initializer_list<KICAD_T>& aScanList,
const COLLECTORS_GUIDE& aGuide ); const VECTOR2I& aRefPos, const COLLECTORS_GUIDE& aGuide );
}; };
@ -557,7 +430,7 @@ public:
* *
* @param testItem An EDA_ITEM to examine. * @param testItem An EDA_ITEM to examine.
* @param testData is not used in this class. * @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; 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. * Collect #BOARD_ITEM objects using this class's Inspector method, which does the collection.
* *
* @param aBoard The BOARD_ITEM to scan. * @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<KICAD_T>& aTypes );
}; };
@ -581,8 +454,7 @@ class PCB_LAYER_COLLECTOR : public PCB_COLLECTOR
public: public:
PCB_LAYER_COLLECTOR( PCB_LAYER_ID aLayerId = UNDEFINED_LAYER ) : PCB_LAYER_COLLECTOR( PCB_LAYER_ID aLayerId = UNDEFINED_LAYER ) :
m_layer_id( aLayerId ) m_layer_id( aLayerId )
{ { }
}
void SetLayerId( PCB_LAYER_ID aLayerId ) { 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 testItem An EDA_ITEM to examine.
* @param testData is not used in this class. * @param testData is not used in this class.
* @return SEARCH_RESULT - SEARCH_QUIT if the Iterator is to stop the scan, * @return SEARCH_QUIT if the Iterator is to stop the scan, else SCAN_CONTINUE
* else SCAN_CONTINUE;
*/ */
INSPECT_RESULT Inspect( EDA_ITEM* testItem, void* testData ) override; 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. * Test a BOARD_ITEM using this class's Inspector method, which does the collection.
* *
* @param aBoard The BOARD_ITEM to scan. * @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<KICAD_T>& aTypes );
private: private:
PCB_LAYER_ID m_layer_id; PCB_LAYER_ID m_layer_id;

View File

@ -291,11 +291,17 @@ void CN_CONNECTIVITY_ALGO::searchConnections()
const CN_CONNECTIVITY_ALGO::CLUSTERS CN_CONNECTIVITY_ALGO::SearchClusters( CLUSTER_SEARCH_MODE aMode ) const CN_CONNECTIVITY_ALGO::CLUSTERS CN_CONNECTIVITY_ALGO::SearchClusters( CLUSTER_SEARCH_MODE aMode )
{ {
if( aMode == CSM_PROPAGATE ) if( aMode == CSM_PROPAGATE )
{
return SearchClusters( aMode, 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 else
{
return SearchClusters( aMode, 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 );
}
} }

View File

@ -489,7 +489,8 @@ void CONNECTIVITY_DATA::Clear()
const std::vector<BOARD_CONNECTED_ITEM*> const std::vector<BOARD_CONNECTED_ITEM*>
CONNECTIVITY_DATA::GetConnectedItems( const BOARD_CONNECTED_ITEM *aItem, CONNECTIVITY_DATA::GetConnectedItems( const BOARD_CONNECTED_ITEM *aItem,
const std::initializer_list<KICAD_T>& aTypes, bool aIgnoreNetcodes ) const const std::initializer_list<KICAD_T>& aTypes,
bool aIgnoreNetcodes ) const
{ {
std::vector<BOARD_CONNECTED_ITEM*> rv; std::vector<BOARD_CONNECTED_ITEM*> rv;
CN_CONNECTIVITY_ALGO::CLUSTER_SEARCH_MODE searchMode; CN_CONNECTIVITY_ALGO::CLUSTER_SEARCH_MODE searchMode;
@ -518,21 +519,23 @@ CONNECTIVITY_DATA::GetConnectedItems( const BOARD_CONNECTED_ITEM *aItem,
} }
const std::vector<BOARD_CONNECTED_ITEM*> CONNECTIVITY_DATA::GetNetItems( int aNetCode, const std::vector<BOARD_CONNECTED_ITEM*>
const KICAD_T aTypes[] ) const CONNECTIVITY_DATA::GetNetItems( int aNetCode, const std::initializer_list<KICAD_T>& aTypes ) const
{ {
std::vector<BOARD_CONNECTED_ITEM*> items; std::vector<BOARD_CONNECTED_ITEM*> items;
items.reserve( 32 ); items.reserve( 32 );
std::bitset<MAX_STRUCT_TYPE_ID> type_bits; std::bitset<MAX_STRUCT_TYPE_ID> type_bits;
for( unsigned int i = 0; aTypes[i] != EOT; ++i ) for( KICAD_T scanType : aTypes )
{ {
wxASSERT( aTypes[i] < MAX_STRUCT_TYPE_ID ); wxASSERT( scanType < MAX_STRUCT_TYPE_ID );
type_bits.set( aTypes[i] ); type_bits.set( scanType );
} }
m_connAlgo->ForEachItem( [&]( CN_ITEM& aItem ) { m_connAlgo->ForEachItem(
[&]( CN_ITEM& aItem )
{
if( aItem.Valid() && ( aItem.Net() == aNetCode ) && type_bits[aItem.Parent()->Type()] ) if( aItem.Valid() && ( aItem.Net() == aNetCode ) && type_bits[aItem.Parent()->Type()] )
items.push_back( aItem.Parent() ); items.push_back( aItem.Parent() );
} ); } );
@ -568,8 +571,8 @@ bool CONNECTIVITY_DATA::CheckConnectivity( std::vector<CN_DISJOINT_NET_ENTRY>& a
} }
const std::vector<PCB_TRACK*> CONNECTIVITY_DATA::GetConnectedTracks( const std::vector<PCB_TRACK*>
const BOARD_CONNECTED_ITEM* aItem ) const CONNECTIVITY_DATA::GetConnectedTracks( const BOARD_CONNECTED_ITEM* aItem ) const
{ {
auto& entry = m_connAlgo->ItemEntry( aItem ); auto& entry = m_connAlgo->ItemEntry( aItem );
@ -584,9 +587,11 @@ const std::vector<PCB_TRACK*> CONNECTIVITY_DATA::GetConnectedTracks(
( connected->Parent()->Type() == PCB_TRACE_T || ( connected->Parent()->Type() == PCB_TRACE_T ||
connected->Parent()->Type() == PCB_VIA_T || connected->Parent()->Type() == PCB_VIA_T ||
connected->Parent()->Type() == PCB_ARC_T ) ) connected->Parent()->Type() == PCB_ARC_T ) )
{
tracks.insert( static_cast<PCB_TRACK*> ( connected->Parent() ) ); tracks.insert( static_cast<PCB_TRACK*> ( connected->Parent() ) );
} }
} }
}
std::copy( tracks.begin(), tracks.end(), std::back_inserter( rv ) ); std::copy( tracks.begin(), tracks.end(), std::back_inserter( rv ) );
return rv; return rv;
@ -814,27 +819,27 @@ bool CONNECTIVITY_DATA::TestTrackEndpointDangling( PCB_TRACK* aTrack, VECTOR2I*
} }
const std::vector<BOARD_CONNECTED_ITEM*> CONNECTIVITY_DATA::GetConnectedItemsAtAnchor( const std::vector<BOARD_CONNECTED_ITEM*>
const BOARD_CONNECTED_ITEM* aItem, CONNECTIVITY_DATA::GetConnectedItemsAtAnchor( const BOARD_CONNECTED_ITEM* aItem,
const VECTOR2I& aAnchor, const VECTOR2I& aAnchor,
const KICAD_T aTypes[], const std::initializer_list<KICAD_T>& aTypes,
const int& aMaxError ) const const int& aMaxError ) const
{ {
auto& entry = m_connAlgo->ItemEntry( aItem ); CN_CONNECTIVITY_ALGO::ITEM_MAP_ENTRY& entry = m_connAlgo->ItemEntry( aItem );
std::vector<BOARD_CONNECTED_ITEM*> rv; std::vector<BOARD_CONNECTED_ITEM*> rv;
SEG::ecoord maxErrorSq = (SEG::ecoord) aMaxError * aMaxError; SEG::ecoord maxError_sq = (SEG::ecoord) aMaxError * aMaxError;
for( CN_ITEM* cnItem : entry.GetItems() ) for( CN_ITEM* cnItem : entry.GetItems() )
{ {
for( CN_ITEM* connected : cnItem->ConnectedItems() ) for( CN_ITEM* connected : cnItem->ConnectedItems() )
{ {
for( std::shared_ptr<CN_ANCHOR>& anchor : connected->Anchors() ) for( const std::shared_ptr<CN_ANCHOR>& 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() ); rv.push_back( connected->Parent() );
break; break;

View File

@ -201,8 +201,7 @@ public:
*/ */
unsigned int GetUnconnectedCount() const; unsigned int GetUnconnectedCount() const;
bool IsConnectedOnLayer( const BOARD_CONNECTED_ITEM* aItem, bool IsConnectedOnLayer( const BOARD_CONNECTED_ITEM* aItem, int aLayer,
int aLayer,
const std::initializer_list<KICAD_T>& aTypes = {}, const std::initializer_list<KICAD_T>& aTypes = {},
bool aCheckOptionalFlashing = false ) const; bool aCheckOptionalFlashing = false ) const;
@ -226,10 +225,9 @@ public:
* @param aMaxError Maximum distance of the found items' anchors to aAnchor in IU * @param aMaxError Maximum distance of the found items' anchors to aAnchor in IU
* @return * @return
*/ */
const std::vector<BOARD_CONNECTED_ITEM*> GetConnectedItemsAtAnchor( const std::vector<BOARD_CONNECTED_ITEM*>
const BOARD_CONNECTED_ITEM* aItem, GetConnectedItemsAtAnchor( const BOARD_CONNECTED_ITEM* aItem, const VECTOR2I& aAnchor,
const VECTOR2I& aAnchor, const std::initializer_list<KICAD_T>& aTypes,
const KICAD_T aTypes[],
const int& aMaxError = 0 ) const; const int& aMaxError = 0 ) const;
void GetUnconnectedEdges( std::vector<CN_EDGE>& aEdges ) const; void GetUnconnectedEdges( std::vector<CN_EDGE>& aEdges ) const;
@ -257,10 +255,7 @@ public:
const CONNECTIVITY_DATA* aDynamicData, const CONNECTIVITY_DATA* aDynamicData,
VECTOR2I aInternalOffset = { 0, 0 } ); VECTOR2I aInternalOffset = { 0, 0 } );
const std::vector<RN_DYNAMIC_LINE>& GetDynamicRatsnest() const const std::vector<RN_DYNAMIC_LINE>& GetDynamicRatsnest() const { return m_dynamicRatsnest; }
{
return m_dynamicRatsnest;
}
/** /**
* Function GetConnectedItems() * Function GetConnectedItems()
@ -268,8 +263,10 @@ public:
* @param aItem is the reference item to find other connected items. * @param aItem is the reference item to find other connected items.
* @param aTypes allows one to filter by item types. * @param aTypes allows one to filter by item types.
*/ */
const std::vector<BOARD_CONNECTED_ITEM*> GetConnectedItems( const BOARD_CONNECTED_ITEM* aItem, const std::vector<BOARD_CONNECTED_ITEM*>
const std::initializer_list<KICAD_T>& aTypes, bool aIgnoreNetcodes = false ) const; GetConnectedItems( const BOARD_CONNECTED_ITEM* aItem,
const std::initializer_list<KICAD_T>& aTypes,
bool aIgnoreNetcodes = false ) const;
/** /**
* Function GetNetItems() * Function GetNetItems()
@ -277,28 +274,19 @@ public:
* @param aNetCode is the net code. * @param aNetCode is the net code.
* @param aTypes allows one to filter by item types. * @param aTypes allows one to filter by item types.
*/ */
const std::vector<BOARD_CONNECTED_ITEM*> GetNetItems( int aNetCode, const std::vector<BOARD_CONNECTED_ITEM*>
const KICAD_T aTypes[] ) const; GetNetItems( int aNetCode, const std::initializer_list<KICAD_T>& aTypes ) const;
void BlockRatsnestItems( const std::vector<BOARD_ITEM*>& aItems ); void BlockRatsnestItems( const std::vector<BOARD_ITEM*>& aItems );
std::shared_ptr<CN_CONNECTIVITY_ALGO> GetConnectivityAlgo() const std::shared_ptr<CN_CONNECTIVITY_ALGO> GetConnectivityAlgo() const { return m_connAlgo; }
{
return m_connAlgo;
}
KISPINLOCK& GetLock() KISPINLOCK& GetLock() { return m_lock; }
{
return m_lock;
}
void MarkItemNetAsDirty( BOARD_ITEM* aItem ); void MarkItemNetAsDirty( BOARD_ITEM* aItem );
void SetProgressReporter( PROGRESS_REPORTER* aReporter ); void SetProgressReporter( PROGRESS_REPORTER* aReporter );
const std::map<int, wxString>& GetNetclassMap() const const std::map<int, wxString>& GetNetclassMap() const { return m_netclassMap; }
{
return m_netclassMap;
}
void AddExclusion( const KIID& aBoardItemId1, const KIID& aBoardItemId2 ); void AddExclusion( const KIID& aBoardItemId1, const KIID& aBoardItemId2 );
void RemoveExclusion( const KIID& aBoardItemId1, const KIID& aBoardItemId2 ); void RemoveExclusion( const KIID& aBoardItemId1, const KIID& aBoardItemId2 );
@ -312,10 +300,7 @@ public:
bool aSkipInternalConnections = false ); bool aSkipInternalConnections = false );
#endif #endif
std::shared_ptr<FROM_TO_CACHE> GetFromToCache() std::shared_ptr<FROM_TO_CACHE> GetFromToCache() { return m_fromToCache; }
{
return m_fromToCache;
}
private: private:
void updateRatsnest(); void updateRatsnest();

View File

@ -846,8 +846,7 @@ bool BuildBoardPolygonOutlines( BOARD* aBoard, SHAPE_POLY_SET& aOutlines, int aE
bool success = false; bool success = false;
// Get all the PCB and FP shapes into 'items', then keep only those on layer == Edge_Cuts. // 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, { PCB_SHAPE_T, PCB_FP_SHAPE_T } );
items.Collect( aBoard, scan_graphics );
// Make a working copy of aSegList, because the list is modified during calculations // Make a working copy of aSegList, because the list is modified during calculations
std::vector<PCB_SHAPE*> segList; std::vector<PCB_SHAPE*> segList;
@ -1072,8 +1071,7 @@ bool BuildFootprintPolygonOutlines( BOARD* aBoard, SHAPE_POLY_SET& aOutlines, in
bool success = false; bool success = false;
// Get all the SHAPEs into 'items', then keep only those on layer == Edge_Cuts. // 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, { PCB_SHAPE_T, PCB_FP_SHAPE_T } );
items.Collect( aBoard, scan_graphics );
// Make a working copy of aSegList, because the list is modified during calculations // Make a working copy of aSegList, because the list is modified during calculations
std::vector<PCB_SHAPE*> segList; std::vector<PCB_SHAPE*> segList;

View File

@ -64,15 +64,12 @@ void PCB_EDIT_FRAME::SetTrackSegmentWidth( PCB_TRACK* aTrackItem,
new_drill = GetDesignSettings().GetCurrentViaDrill(); new_drill = GetDesignSettings().GetCurrentViaDrill();
} }
// Old versions set a drill value <= 0, when the default netclass it used // Old versions set a drill value <= 0, when the default netclass it used but it could
// but it could be better to set the drill value to the actual value // be better to set the drill value to the actual value to avoid issues for existing vias,
// to avoid issues for existing vias, if the default drill value is modified // if the default drill value is modified in the netclass, and not in current vias.
// in the netclass, and not in current vias.
if( via->GetDrill() <= 0 ) // means default netclass drill value used if( via->GetDrill() <= 0 ) // means default netclass drill value used
{
initial_drill = -1; // Force drill vias re-initialization initial_drill = -1; // Force drill vias re-initialization
} }
}
if( initial_width != new_width || initial_drill != new_drill ) if( initial_width != new_width || initial_drill != new_drill )
{ {

View File

@ -207,17 +207,11 @@ std::vector<DRILL_LAYER_PAIR> GENDRILL_WRITER_BASE::getUniqueLayerPairs() const
{ {
wxASSERT( m_pcb ); wxASSERT( m_pcb );
static const KICAD_T interesting_stuff_to_collect[] = {
PCB_VIA_T,
EOT
};
PCB_TYPE_COLLECTOR vias; 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; std::set<DRILL_LAYER_PAIR> unique;
DRILL_LAYER_PAIR layer_pair; DRILL_LAYER_PAIR layer_pair;
for( int i = 0; i < vias.GetCount(); ++i ) for( int i = 0; i < vias.GetCount(); ++i )
@ -229,17 +223,15 @@ std::vector<DRILL_LAYER_PAIR> GENDRILL_WRITER_BASE::getUniqueLayerPairs() const
// only make note of blind buried. // only make note of blind buried.
// thru hole is placed unconditionally as first in fetched list. // thru hole is placed unconditionally as first in fetched list.
if( layer_pair != DRILL_LAYER_PAIR( F_Cu, B_Cu ) ) if( layer_pair != DRILL_LAYER_PAIR( F_Cu, B_Cu ) )
{
unique.insert( layer_pair ); unique.insert( layer_pair );
} }
}
std::vector<DRILL_LAYER_PAIR> ret; std::vector<DRILL_LAYER_PAIR> ret;
ret.emplace_back( F_Cu, B_Cu ); // always first in returned list ret.emplace_back( F_Cu, B_Cu ); // always first in returned list
for( std::set<DRILL_LAYER_PAIR>::const_iterator it = unique.begin(); it != unique.end(); ++it ) for( const DRILL_LAYER_PAIR& pair : unique )
ret.push_back( *it ); ret.push_back( pair );
return ret; return ret;
} }

View File

@ -1241,50 +1241,51 @@ void FOOTPRINT::Add3DModel( FP_3DMODEL* a3DModel )
// see footprint.h // 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<KICAD_T>& aScanTypes )
{ {
KICAD_T stype;
INSPECT_RESULT result = INSPECT_RESULT::CONTINUE;
const KICAD_T* p = scanTypes;
bool done = false;
#if 0 && defined(DEBUG) #if 0 && defined(DEBUG)
std::cout << GetClass().mb_str() << ' '; std::cout << GetClass().mb_str() << ' ';
#endif #endif
while( !done ) bool drawingsScanned = false;
{
stype = *p;
switch( stype ) for( KICAD_T scanType : aScanTypes )
{
switch( scanType )
{ {
case PCB_FOOTPRINT_T: case PCB_FOOTPRINT_T:
result = inspector( this, testData ); // inspect me if( inspector( this, testData ) == INSPECT_RESULT::QUIT )
++p; return INSPECT_RESULT::QUIT;
break; break;
case PCB_PAD_T: case PCB_PAD_T:
result = IterateForward<PAD*>( m_pads, inspector, testData, p ); if( IterateForward<PAD*>( m_pads, inspector, testData, { scanType } )
++p; == INSPECT_RESULT::QUIT )
{
return INSPECT_RESULT::QUIT;
}
break; break;
case PCB_FP_ZONE_T: case PCB_FP_ZONE_T:
result = IterateForward<FP_ZONE*>( m_fp_zones, inspector, testData, p ); if( IterateForward<FP_ZONE*>( m_fp_zones, inspector, testData, { scanType } )
++p; == INSPECT_RESULT::QUIT )
{
return INSPECT_RESULT::QUIT;
}
break; break;
case PCB_FP_TEXT_T: 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 ) if( inspector( m_value, testData ) == INSPECT_RESULT::QUIT )
break; return INSPECT_RESULT::QUIT;
result = inspector( m_value, testData ); // Intentionally fall through since m_Drawings can hold PCB_FP_TEXT_T also
if( result == INSPECT_RESULT::QUIT )
break;
// Intentionally fall through since m_Drawings can hold PCB_FP_SHAPE_T also
KI_FALLTHROUGH; KI_FALLTHROUGH;
case PCB_FP_DIM_ALIGNED_T: 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_DIM_ORTHOGONAL_T:
case PCB_FP_SHAPE_T: case PCB_FP_SHAPE_T:
case PCB_FP_TEXTBOX_T: case PCB_FP_TEXTBOX_T:
result = IterateForward<BOARD_ITEM*>( m_drawings, inspector, testData, p ); if( !drawingsScanned )
// skip over any types handled in the above call.
for( ; ; )
{ {
switch( stype = *++p ) if( IterateForward<BOARD_ITEM*>( m_drawings, inspector, testData, aScanTypes )
== INSPECT_RESULT::QUIT )
{ {
case PCB_FP_TEXT_T: return INSPECT_RESULT::QUIT;
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:
;
} }
break; drawingsScanned = true;
} }
break; break;
case PCB_GROUP_T: case PCB_GROUP_T:
result = IterateForward<PCB_GROUP*>( m_fp_groups, inspector, testData, p ); if( IterateForward<PCB_GROUP*>( m_fp_groups, inspector, testData, { scanType } )
++p; == INSPECT_RESULT::QUIT )
{
return INSPECT_RESULT::QUIT;
}
break; break;
default: default:
done = true;
break; break;
} }
if( result == INSPECT_RESULT::QUIT )
break;
} }
return result; return INSPECT_RESULT::CONTINUE;
} }

View File

@ -637,7 +637,8 @@ public:
*/ */
void Add3DModel( FP_3DMODEL* a3DModel ); 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<KICAD_T>& aScanTypes ) override;
wxString GetClass() const override wxString GetClass() const override
{ {

View File

@ -3,7 +3,7 @@
* *
* Copyright (C) 2018 Jean-Pierre Charras, jp.charras at wanadoo.fr * Copyright (C) 2018 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 2013 Wayne Stambaugh <stambaughw@verizon.net> * Copyright (C) 2013 Wayne Stambaugh <stambaughw@verizon.net>
* 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 * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -50,16 +50,16 @@ public:
return aItem && PCB_FP_SHAPE_T == aItem->Type(); return aItem && PCB_FP_SHAPE_T == aItem->Type();
} }
bool IsType( const KICAD_T aScanTypes[] ) const override bool IsType( const std::initializer_list<KICAD_T>& aScanTypes ) const override
{ {
if( BOARD_ITEM::IsType( aScanTypes ) ) if( BOARD_ITEM::IsType( aScanTypes ) )
return true; 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; return true;
else if( *p == PCB_LOCATE_BOARD_EDGE_T ) else if( scanType == PCB_LOCATE_BOARD_EDGE_T )
return m_layer == Edge_Cuts; return m_layer == Edge_Cuts;
} }

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application. * 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) 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 * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -64,14 +64,14 @@ public:
return aItem && aItem->Type() == PCB_FP_TEXT_T; return aItem && aItem->Type() == PCB_FP_TEXT_T;
} }
bool IsType( const KICAD_T aScanTypes[] ) const override bool IsType( const std::initializer_list<KICAD_T>& aScanTypes ) const override
{ {
if( BOARD_ITEM::IsType( aScanTypes ) ) if( BOARD_ITEM::IsType( aScanTypes ) )
return true; 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; return true;
} }

View File

@ -50,14 +50,14 @@ public:
return aItem && aItem->Type() == PCB_FP_TEXT_T; return aItem && aItem->Type() == PCB_FP_TEXT_T;
} }
bool IsType( const KICAD_T aScanTypes[] ) const override bool IsType( const std::initializer_list<KICAD_T>& aScanTypes ) const override
{ {
if( BOARD_ITEM::IsType( aScanTypes ) ) if( BOARD_ITEM::IsType( aScanTypes ) )
return true; 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; return true;
} }

View File

@ -151,20 +151,14 @@ bool NETINFO_ITEM::Matches( const wxFindReplaceData& aSearchData, void* aAuxData
const EDA_RECT NETINFO_ITEM::GetBoundingBox() const 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 }; std::shared_ptr<CONNECTIVITY_DATA> conn = GetBoard()->GetConnectivity();
auto connectivity = GetBoard()->GetConnectivity(); EDA_RECT bbox;
std::vector<BOARD_CONNECTED_ITEM*> items = connectivity->GetNetItems( m_netCode, types ); for( BOARD_ITEM* item : conn->GetNetItems( m_netCode, { PCB_TRACE_T, PCB_ARC_T, PCB_VIA_T,
EDA_RECT bbox = EDA_RECT( VECTOR2I( 0, 0 ), VECTOR2I( 0, 0 ) ); PCB_ZONE_T, PCB_PAD_T } ) )
if( items.size() >= 1 )
{
bbox = items.at( 0 )->GetBoundingBox();
for( BOARD_CONNECTED_ITEM* item : items )
{ {
bbox.Merge( item->GetBoundingBox() ); bbox.Merge( item->GetBoundingBox() );
} }
}
return bbox; return bbox;
} }

View File

@ -82,20 +82,20 @@ public:
return aItem && PCB_PAD_T == aItem->Type(); return aItem && PCB_PAD_T == aItem->Type();
} }
bool IsType( const KICAD_T aScanTypes[] ) const override bool IsType( const std::initializer_list<KICAD_T>& aScanTypes ) const override
{ {
if( BOARD_CONNECTED_ITEM::IsType( aScanTypes ) ) if( BOARD_CONNECTED_ITEM::IsType( aScanTypes ) )
return true; 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; 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; 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; return true;
} }
} }

View File

@ -240,7 +240,16 @@ void PCB_BASE_EDIT_FRAME::unitsChangeRefresh()
return INSPECT_RESULT::CONTINUE; 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 ) if( selectedItemModified )
m_toolManager->PostEvent( EVENTS::SelectedItemsModified ); m_toolManager->PostEvent( EVENTS::SelectedItemsModified );

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application. * 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) 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 * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -97,14 +97,14 @@ class PCB_DIMENSION_BASE : public BOARD_ITEM
public: public:
PCB_DIMENSION_BASE( BOARD_ITEM* aParent, KICAD_T aType = PCB_DIMENSION_T ); 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<KICAD_T>& aScanTypes ) const override
{ {
if( BOARD_ITEM::IsType( aScanTypes ) ) if( BOARD_ITEM::IsType( aScanTypes ) )
return true; 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; return true;
} }

View File

@ -773,18 +773,18 @@ void PCB_EDIT_FRAME::setupUIConditions()
mgr->SetConditions( PCB_ACTIONS::highlightNetSelection, ENABLE( SELECTION_CONDITIONS::ShowAlways ) ); mgr->SetConditions( PCB_ACTIONS::highlightNetSelection, ENABLE( SELECTION_CONDITIONS::ShowAlways ) );
mgr->SetConditions( PCB_ACTIONS::selectNet, 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, 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, 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_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_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::zoneDuplicate, ENABLE( singleZoneCond ) );
mgr->SetConditions( PCB_ACTIONS::drawZoneCutout, ENABLE( singleZoneCond ) ); mgr->SetConditions( PCB_ACTIONS::drawZoneCutout, ENABLE( singleZoneCond ) );

View File

@ -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<KICAD_T>& aScanTypes )
{ {
for( const KICAD_T* stype = aScanTypes; *stype != EOT; ++stype ) for( KICAD_T scanType : aScanTypes )
{ {
// If caller wants to inspect my type if( scanType == Type() )
if( *stype == Type() )
{ {
if( INSPECT_RESULT::QUIT == aInspector( this, aTestData ) ) if( INSPECT_RESULT::QUIT == aInspector( this, aTestData ) )
return INSPECT_RESULT::QUIT; return INSPECT_RESULT::QUIT;

View File

@ -57,16 +57,16 @@ public:
return wxT( "PCB_SHAPE" ); return wxT( "PCB_SHAPE" );
} }
bool IsType( const KICAD_T aScanTypes[] ) const override bool IsType( const std::initializer_list<KICAD_T>& aScanTypes ) const override
{ {
if( BOARD_ITEM::IsType( aScanTypes ) ) if( BOARD_ITEM::IsType( aScanTypes ) )
return true; 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; return true;
else if( *p == PCB_LOCATE_BOARD_EDGE_T ) else if( scanType == PCB_LOCATE_BOARD_EDGE_T )
return m_layer == Edge_Cuts; return m_layer == Edge_Cuts;
} }

View File

@ -48,14 +48,14 @@ public:
return aItem && PCB_TEXT_T == aItem->Type(); return aItem && PCB_TEXT_T == aItem->Type();
} }
bool IsType( const KICAD_T aScanTypes[] ) const override bool IsType( const std::initializer_list<KICAD_T>& aScanTypes ) const override
{ {
if( BOARD_ITEM::IsType( aScanTypes ) ) if( BOARD_ITEM::IsType( aScanTypes ) )
return true; 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; return true;
} }

View File

@ -48,14 +48,14 @@ public:
return aItem && PCB_TEXTBOX_T == aItem->Type(); return aItem && PCB_TEXTBOX_T == aItem->Type();
} }
bool IsType( const KICAD_T aScanTypes[] ) const override bool IsType( const std::initializer_list<KICAD_T>& aScanTypes ) const override
{ {
if( BOARD_ITEM::IsType( aScanTypes ) ) if( BOARD_ITEM::IsType( aScanTypes ) )
return true; 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; return true;
} }

View File

@ -369,16 +369,17 @@ void PCB_VIA::Flip( const VECTOR2I& aCentre, bool aFlipLeftRight )
// see class_track.h // 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<KICAD_T>& aScanTypes )
{ {
KICAD_T stype = *scanTypes; for( KICAD_T scanType : aScanTypes )
{
// If caller wants to inspect my type if( scanType == Type() )
if( stype == Type() )
{ {
if( INSPECT_RESULT::QUIT == inspector( this, testData ) ) if( INSPECT_RESULT::QUIT == inspector( this, testData ) )
return INSPECT_RESULT::QUIT; return INSPECT_RESULT::QUIT;
} }
}
return INSPECT_RESULT::CONTINUE; return INSPECT_RESULT::CONTINUE;
} }

View File

@ -173,7 +173,8 @@ public:
void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList ) override; void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& 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<KICAD_T>& aScanTypes ) override;
bool HitTest( const VECTOR2I& aPosition, int aAccuracy = 0 ) const override; bool HitTest( const VECTOR2I& aPosition, int aAccuracy = 0 ) const override;
bool HitTest( const EDA_RECT& aRect, bool aContained, 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. // 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<KICAD_T>& aScanTypes ) const override
{ {
if( BOARD_CONNECTED_ITEM::IsType( aScanTypes ) ) if( BOARD_CONNECTED_ITEM::IsType( aScanTypes ) )
return true; 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; 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; 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; return true;
} }

View File

@ -143,12 +143,6 @@ HANDLE_EXCEPTIONS(BOARD::TracksInNetBetweenPoints)
except: except:
self.this = this 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): def Save(self,filename):
return SaveBoard(filename,self) return SaveBoard(filename,self)

View File

@ -58,9 +58,7 @@ bool ITEM::collideSimple( const ITEM* aOther, const NODE* aNode, bool aDifferent
auto checkKeepout = auto checkKeepout =
[]( const ZONE* aKeepout, const BOARD_ITEM* aOther ) []( const ZONE* aKeepout, const BOARD_ITEM* aOther )
{ {
constexpr KICAD_T TRACK_TYPES[] = { PCB_ARC_T, PCB_TRACE_T, EOT }; if( aKeepout->GetDoNotAllowTracks() && aOther->IsType( { PCB_ARC_T, PCB_TRACE_T } ) )
if( aKeepout->GetDoNotAllowTracks() && aOther->IsType( TRACK_TYPES ) )
return true; return true;
if( aKeepout->GetDoNotAllowVias() && aOther->Type() == PCB_VIA_T ) if( aKeepout->GetDoNotAllowVias() && aOther->Type() == PCB_VIA_T )

View File

@ -1782,10 +1782,8 @@ bool ROUTER_TOOL::CanInlineDrag( int aDragMode )
// DragArcTrack(), so PCB_ARC_T should never occur here. // DragArcTrack(), so PCB_ARC_T should never occur here.
if( item->IsType( GENERAL_COLLECTOR::DraggableItems ) ) if( item->IsType( GENERAL_COLLECTOR::DraggableItems ) )
{ {
static const KICAD_T footprints[] = { PCB_FOOTPRINT_T, EOT };
// Footprints cannot be dragged freely. // Footprints cannot be dragged freely.
if( item->IsType( footprints ) ) if( item->IsType( { PCB_FOOTPRINT_T } ) )
return !( aDragMode & PNS::DM_FREE_ANGLE ); return !( aDragMode & PNS::DM_FREE_ANGLE );
else else
return true; return true;

View File

@ -34,7 +34,6 @@
#include <pcb_edit_frame.h> #include <pcb_edit_frame.h>
#include <confirm.h> // DisplayError() #include <confirm.h> // DisplayError()
#include <gestfich.h> // EDA_FileSelector() #include <gestfich.h> // EDA_FileSelector()
#include <trigo.h> // RotatePoint()
#include <locale_io.h> #include <locale_io.h>
#include <macros.h> #include <macros.h>
#include <math/util.h> // for KiROUND #include <math/util.h> // for KiROUND
@ -63,23 +62,19 @@
using namespace DSN; using namespace DSN;
// comment the line #define EXPORT_CUSTOM_PADS_CONVEX_HULL to export CUSTOM pads exact shapes. // 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) // Shapes can be non convex polygons with holes (linked to outline) that can create issues.
// that can create issues.
// Especially Freerouter does not handle them very well: // Especially Freerouter does not handle them very well:
// - too complex shapes are not accepted, especially shapes with holes (dsn files are not loaded). // - 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 // - and Freerouter actually uses something like a convex hull of the shape (that works poorly).
// well).
// I am guessing non convex polygons with holes linked could create issues with any Router. // I am guessing non convex polygons with holes linked could create issues with any Router.
#define EXPORT_CUSTOM_PADS_CONVEX_HULL #define EXPORT_CUSTOM_PADS_CONVEX_HULL
// Add .1 mil to the requested clearances as a safety margin. // Add .1 mil to the requested clearances as a safety margin. There has been disagreement about
// There has been disagreement about interpretation of clearance in the past // interpretation of clearance in the past between KiCad and Freerouter, so keep this safetyMargin
// between KiCad and Freerouter, so keep this safetyMargin until the // until the disagreement is resolved and stable. Freerouter seems to be moving (protected)
// disagreement is resolved and stable. Freerouter seems to be moving // traces upon loading the DSN file, and even though it seems to sometimes add its own 0.1 to the
// (protected) traces upon loading the DSN file, and even though it seems to sometimes // clearances, I believe this is happening after the load process (and moving traces) so I am of
// add its own 0.1 to the clearances, I believe this is happening after // the opinion this is still needed.
// the load process (and moving traces) so I am of the opinion this is
// still needed.
static const double safetyMargin = 0.1; static const double safetyMargin = 0.1;
@ -102,20 +97,15 @@ bool PCB_EDIT_FRAME::ExportSpecctraFile( const wxString& aFullFilename )
errorText = ioe.What(); errorText = ioe.What();
} }
// The two calls to FOOTPRINT::Flip() in ExportBoardToSpecctraFile both set the // The two calls to FOOTPRINT::Flip() in ExportBoardToSpecctraFile both set the modified flag,
// modified flag, yet their actions cancel each other out, so it should // yet their actions cancel each other out, so it should be ok to clear the flag.
// be ok to clear the modify flag.
if( !wasModified ) if( !wasModified )
screen->SetContentModified( false ); screen->SetContentModified( false );
if( ok ) if( ok )
{
SetStatusText( wxString( _( "BOARD exported OK." ) ) ); SetStatusText( wxString( _( "BOARD exported OK." ) ) );
}
else else
{
DisplayErrorMessage( this, _( "Unable to export, please fix and try again" ), errorText ); DisplayErrorMessage( this, _( "Unable to export, please fix and try again" ), errorText );
}
return ok; return ok;
} }
@ -145,8 +135,8 @@ void ExportBoardToSpecctraFile( BOARD* aBoard, const wxString& aFullFilename )
db.ExportPCB( aFullFilename, true ); db.ExportPCB( aFullFilename, true );
db.RevertFOOTPRINTs( aBoard ); db.RevertFOOTPRINTs( aBoard );
// if an exception is thrown by FromBOARD or ExportPCB(), then // if an exception is thrown by FromBOARD() or ExportPCB(), then ~SPECCTRA_DB() will
// ~SPECCTRA_DB() will close the file. // close the file.
} }
catch( ... ) catch( ... )
{ {
@ -158,15 +148,11 @@ void ExportBoardToSpecctraFile( BOARD* aBoard, const wxString& aFullFilename )
namespace DSN { 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 * Convert a distance from Pcbnew internal units to the reported Specctra DSN units in floating
* in floating point format. * point format.
*/ */
static inline double scale( int kicadDist ) static inline double scale( int kicadDist )
{ {
@ -305,8 +291,7 @@ PADSTACK* SPECCTRA_DB::makePADSTACK( BOARD* aBoard, PAD* aPad )
dsnOffset = mapPt( offset ); dsnOffset = mapPt( offset );
// using '(' or ')' would cause padstack name to be quote wrapped, // using () would cause padstack name to be quoted, and {} locks freerouter, so use [].
// so use other brackets, and {} locks freerouter.
sprintf( offsetTxt, "[%.6g,%.6g]", dsnOffset.x, dsnOffset.y ); sprintf( offsetTxt, "[%.6g,%.6g]", dsnOffset.x, dsnOffset.y );
uniqifier += offsetTxt; uniqifier += offsetTxt;
@ -619,7 +604,7 @@ IMAGE* SPECCTRA_DB::makeIMAGE( BOARD* aBoard, FOOTPRINT* aFootprint )
PCB_TYPE_COLLECTOR fpItems; PCB_TYPE_COLLECTOR fpItems;
// get all the FOOTPRINT's pads. // get all the FOOTPRINT's pads.
fpItems.Collect( aFootprint, scanPADs ); fpItems.Collect( aFootprint, { PCB_PAD_T } );
IMAGE* image = new IMAGE( 0 ); 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. // 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 ) for( int i = 0; i < fpItems.GetCount(); ++i )
{ {
@ -1097,28 +1080,19 @@ typedef std::pair<STRINGSET::iterator, bool> STRINGSET_PAIR;
void SPECCTRA_DB::FromBOARD( BOARD* aBoard ) void SPECCTRA_DB::FromBOARD( BOARD* aBoard )
{ {
PCB_TYPE_COLLECTOR items;
static const KICAD_T scanMODULEs[] = { PCB_FOOTPRINT_T, EOT };
std::shared_ptr<NET_SETTINGS>& netSettings = aBoard->GetDesignSettings().m_NetSettings; std::shared_ptr<NET_SETTINGS>& netSettings = aBoard->GetDesignSettings().m_NetSettings;
// Not all boards are exportable. Check that all reference Ids are unique. // Not all boards are exportable. Check that all reference Ids are unique, or we won't be
// Unless they are unique, we cannot import the session file which comes // able to import the session file which comes back to us later from the router.
// 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; i<items.GetCount(); ++i ) for( FOOTPRINT* footprint : aBoard->Footprints() )
{ {
FOOTPRINT* footprint = (FOOTPRINT*) items[i];
if( footprint->GetReference() == wxEmptyString ) if( footprint->GetReference() == wxEmptyString )
{ {
THROW_IO_ERROR( wxString::Format( THROW_IO_ERROR( wxString::Format( _( "Footprint with value of '%s' has an empty "
_( "Symbol with value of '%s' has empty reference id." ), "reference designator." ),
footprint->GetValue() ) ); footprint->GetValue() ) );
} }
@ -1127,8 +1101,8 @@ void SPECCTRA_DB::FromBOARD( BOARD* aBoard )
if( !refpair.second ) // insert failed if( !refpair.second ) // insert failed
{ {
THROW_IO_ERROR( wxString::Format( THROW_IO_ERROR( wxString::Format( _( "Multiple footprints have the reference "
_( "Multiple symbols have identical reference IDs of '%s'." ), "designator '%s'." ),
footprint->GetReference() ) ); footprint->GetReference() ) );
} }
} }
@ -1139,9 +1113,8 @@ void SPECCTRA_DB::FromBOARD( BOARD* aBoard )
//-----<layer_descriptor>----------------------------------------------- //-----<layer_descriptor>-----------------------------------------------
{ {
// specctra wants top physical layer first, then going down to the // Specctra wants top physical layer first, then going down to the bottom most physical
// bottom most physical layer in physical sequence. // layer in physical sequence.
// @question : why does KiCad not display layers in that order?
buildLayerMaps( aBoard ); buildLayerMaps( aBoard );
@ -1185,9 +1158,8 @@ void SPECCTRA_DB::FromBOARD( BOARD* aBoard )
//-----<unit_descriptor> & <resolution_descriptor>-------------------- //-----<unit_descriptor> & <resolution_descriptor>--------------------
{ {
// tell freerouter to use "tenths of micrometers", // Tell freerouter to use "tenths of micrometers", which is 100 nm resolution. Possibly
// which is 100 nm resolution. Possibly more resolution is possible // more resolution is possible in freerouter, but it would need testing.
// in freerouter, but it would need testing.
m_pcb->unit->units = T_um; m_pcb->unit->units = T_um;
m_pcb->resolution->units = T_um; m_pcb->resolution->units = T_um;
@ -1196,9 +1168,8 @@ void SPECCTRA_DB::FromBOARD( BOARD* aBoard )
//-----<boundary_descriptor>------------------------------------------ //-----<boundary_descriptor>------------------------------------------
{ {
// Because fillBOUNDARY() can throw an exception, we link in an // Because fillBOUNDARY() can throw an exception, we link in an empty boundary so the
// empty boundary so the BOUNDARY does not get lost in the event of // BOUNDARY does not get lost in the event of of an exception.
// of an exception.
BOUNDARY* boundary = new BOUNDARY( 0 ); BOUNDARY* boundary = new BOUNDARY( 0 );
m_pcb->structure->SetBOUNDARY( boundary ); m_pcb->structure->SetBOUNDARY( boundary );
@ -1220,14 +1191,12 @@ void SPECCTRA_DB::FromBOARD( BOARD* aBoard )
sprintf( rule, "(clearance %.6g)", clearance + safetyMargin ); sprintf( rule, "(clearance %.6g)", clearance + safetyMargin );
rules.push_back( rule ); rules.push_back( rule );
// On a high density board (a board with 4 mil tracks, 4 mil spacing) // On a high density board (4 mil tracks, 4 mil spacing) a typical solder mask clearance
// a typical solder mask clearance will be 2-3 mils. // will be 2-3 mils. This exposes 2 to 3 mils of bare board around each pad, and would
// 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
// leave only 1 to 2 mils of solder mask between the solder mask's boundary // any trace within "clearance" of the pad. So we need at least 2 mils *extra* clearance
// to the edge of any trace within "clearance" of the pad. So we need at least // for traces which would come near a pad on a different net. So if the baseline trace to
// 2 mils *extra* clearance for traces which would come near a pad on // trace clearance was 4 mils, then the SMD to trace clearance should be at least 6 mils.
// 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.
double default_smd = clearance + safetyMargin; double default_smd = clearance + safetyMargin;
if( default_smd <= 6.0 ) if( default_smd <= 6.0 )
@ -1237,9 +1206,9 @@ void SPECCTRA_DB::FromBOARD( BOARD* aBoard )
rules.push_back( rule ); rules.push_back( rule );
// Pad to pad spacing on a single SMT part can be closer than our // Pad to pad spacing on a single SMT part can be closer than our clearance. We don't want
// clearance, we don't want freerouter complaining about that, so // freerouter complaining about that, so output a significantly smaller pad to pad
// output a significantly smaller pad to pad clearance to freerouter. // clearance to freerouter.
clearance = scale( defaultClearance ) / 4; clearance = scale( defaultClearance ) / 4;
sprintf( rule, "(clearance %.6g (type smd_smd))", clearance ); sprintf( rule, "(clearance %.6g (type smd_smd))", clearance );
@ -1251,18 +1220,13 @@ void SPECCTRA_DB::FromBOARD( BOARD* aBoard )
{ {
int netlessZones = 0; int netlessZones = 0;
static const KICAD_T scanZONEs[] = { PCB_ZONE_T, EOT }; for( ZONE* zone : aBoard->Zones() )
items.Collect( aBoard, scanZONEs );
for( int i = 0; i < items.GetCount(); ++i )
{ {
ZONE* item = (ZONE*) items[i]; if( zone->GetIsRuleArea() )
if( item->GetIsRuleArea() )
continue; continue;
// Currently, we export only copper layers // Currently, we export only copper layers
if( ! IsCopperLayer( item->GetLayer() ) ) if( ! IsCopperLayer( zone->GetLayer() ) )
continue; continue;
COPPER_PLANE* plane = new COPPER_PLANE( m_pcb->structure ); COPPER_PLANE* plane = new COPPER_PLANE( m_pcb->structure );
@ -1272,8 +1236,7 @@ void SPECCTRA_DB::FromBOARD( BOARD* aBoard )
PATH* mainPolygon = new PATH( plane, T_polygon ); PATH* mainPolygon = new PATH( plane, T_polygon );
plane->SetShape( mainPolygon ); plane->SetShape( mainPolygon );
plane->name = TO_UTF8( zone->GetNetname() );
plane->name = TO_UTF8( item->GetNetname() );
if( plane->name.size() == 0 ) if( plane->name.size() == 0 )
{ {
@ -1293,14 +1256,14 @@ void SPECCTRA_DB::FromBOARD( BOARD* aBoard )
plane->name = no_net->net_id; 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 // Handle the main outlines
SHAPE_POLY_SET::ITERATOR iterator; SHAPE_POLY_SET::ITERATOR iterator;
wxPoint startpoint; wxPoint startpoint;
bool is_first_point = true; bool is_first_point = true;
for( iterator = item->IterateWithHoles(); iterator; iterator++ ) for( iterator = zone->IterateWithHoles(); iterator; iterator++ )
{ {
wxPoint point( iterator->x, iterator->y ); wxPoint point( iterator->x, iterator->y );
@ -1333,14 +1296,11 @@ void SPECCTRA_DB::FromBOARD( BOARD* aBoard )
{ {
is_first_point = true; is_first_point = true;
window = new WINDOW( plane ); window = new WINDOW( plane );
plane->AddWindow( window ); plane->AddWindow( window );
cutout = new PATH( window, T_polygon ); cutout = new PATH( window, T_polygon );
window->SetShape( cutout ); window->SetShape( cutout );
cutout->layer_id = m_layerIds[ m_kicadLayer2pcb[ zone->GetLayer() ] ];
cutout->layer_id = m_layerIds[ m_kicadLayer2pcb[ item->GetLayer() ] ];
} }
// If the point in this iteration is the last of the contour, the next iteration // 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 )
//-----<zones flagged keepout areas become keepout>-------------------------------- //-----<zones flagged keepout areas become keepout>--------------------------------
{ {
static const KICAD_T scanZONEs[] = { PCB_ZONE_T, EOT }; for( ZONE* zone : aBoard->Zones() )
items.Collect( aBoard, scanZONEs );
for( int i = 0; i < items.GetCount(); ++i )
{ {
ZONE* item = (ZONE*) items[i]; if( !zone->GetIsRuleArea() )
if( !item->GetIsRuleArea() )
continue; continue;
// keepout areas have a type. types are // Keepout areas have a type: T_place_keepout, T_via_keepout, T_wire_keepout,
// T_place_keepout, T_via_keepout, T_wire_keepout,
// T_bend_keepout, T_elongate_keepout, T_keepout. // T_bend_keepout, T_elongate_keepout, T_keepout.
// Pcbnew knows only T_keepout, T_via_keepout and T_wire_keepout // Pcbnew knows only T_keepout, T_via_keepout and T_wire_keepout
DSN_T keepout_type; DSN_T keepout_type;
if( item->GetDoNotAllowVias() && item->GetDoNotAllowTracks() ) if( zone->GetDoNotAllowVias() && zone->GetDoNotAllowTracks() )
keepout_type = T_keepout; keepout_type = T_keepout;
else if( item->GetDoNotAllowVias() ) else if( zone->GetDoNotAllowVias() )
keepout_type = T_via_keepout; keepout_type = T_via_keepout;
else if( item->GetDoNotAllowTracks() ) else if( zone->GetDoNotAllowTracks() )
keepout_type = T_wire_keepout; keepout_type = T_wire_keepout;
else else
keepout_type = T_keepout; 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) // keepout is living (keepout zones can live on many copper layers)
const int copperCount = aBoard->GetCopperLayerCount(); const int copperCount = aBoard->GetCopperLayerCount();
@ -1403,7 +1357,7 @@ void SPECCTRA_DB::FromBOARD( BOARD* aBoard )
if( layer == copperCount - 1 ) if( layer == copperCount - 1 )
layer = B_Cu; layer = B_Cu;
if( !item->IsOnLayer( PCB_LAYER_ID( layer ) ) ) if( !zone->IsOnLayer( PCB_LAYER_ID( layer ) ) )
continue; continue;
KEEPOUT* keepout = new KEEPOUT( m_pcb->structure, keepout_type ); KEEPOUT* keepout = new KEEPOUT( m_pcb->structure, keepout_type );
@ -1419,7 +1373,7 @@ void SPECCTRA_DB::FromBOARD( BOARD* aBoard )
bool is_first_point = true; bool is_first_point = true;
wxPoint startpoint; wxPoint startpoint;
for( iterator = item->IterateWithHoles(); iterator; iterator++ ) for( iterator = zone->IterateWithHoles(); iterator; iterator++ )
{ {
wxPoint point( iterator->x, iterator->y ); wxPoint point( iterator->x, iterator->y );
@ -1454,10 +1408,8 @@ void SPECCTRA_DB::FromBOARD( BOARD* aBoard )
keepout->AddWindow( window ); keepout->AddWindow( window );
cutout = new PATH( window, T_polygon ); cutout = new PATH( window, T_polygon );
window->SetShape( cutout ); window->SetShape( cutout );
cutout->layer_id = m_layerIds[ m_kicadLayer2pcb[ zone->GetLayer() ] ];
cutout->layer_id = m_layerIds[ m_kicadLayer2pcb[ item->GetLayer() ] ];
} }
isStartContour = iterator.IsEndContour(); isStartContour = iterator.IsEndContour();
@ -1486,13 +1438,11 @@ void SPECCTRA_DB::FromBOARD( BOARD* aBoard )
//-----<build the images, components, and netlist>----------------------- //-----<build the images, components, and netlist>-----------------------
{ {
PIN_REF empty( m_pcb->network ); PIN_REF empty( m_pcb->network );
std::string componentId; std::string componentId;
// find the highest numbered netCode within the board.
int highestNetCode = 0; int highestNetCode = 0;
NETINFO_LIST& netInfo = aBoard->GetNetInfo(); NETINFO_LIST& netInfo = aBoard->GetNetInfo();
// find the highest numbered netCode within the board.
for( NETINFO_LIST::iterator i = netInfo.begin(); i != netInfo.end(); ++i ) for( NETINFO_LIST::iterator i = netInfo.begin(); i != netInfo.end(); ++i )
highestNetCode = std::max( highestNetCode, i->GetNetCode() ); highestNetCode = std::max( highestNetCode, i->GetNetCode() );
@ -1510,30 +1460,23 @@ void SPECCTRA_DB::FromBOARD( BOARD* aBoard )
m_nets[i->GetNetCode()]->net_id = TO_UTF8( i->GetNetname() ); m_nets[i->GetNetCode()]->net_id = TO_UTF8( i->GetNetname() );
} }
items.Collect( aBoard, scanMODULEs );
m_padstackset.clear(); 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() ); componentId = TO_UTF8( footprint->GetReference() );
// create a net list entry for all the actual pins in the image // Create a net list entry for all the actual pins in the current footprint.
// for the current footprint. location of this code is critical // Location of this code is critical because we fabricated some pin names to ensure
// because we fabricated some pin names to ensure unique-ness // unique-ness within a footprint, and the life of this 'IMAGE* image' is not
// of pin names within a footprint, do not move this code because // necessarily long. The exported netlist will have some fabricated pin names in it.
// the life of this 'IMAGE* image' is not necessarily long. The // If you don't like fabricated pin names, then make sure all pads within your
// exported netlist will have some fabricated pin names in it. // FOOTPRINTs are uniquely named!
// 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 ) for( unsigned p = 0; p < image->pins.size(); ++p )
{ {
PIN* pin = &image->pins[p]; PIN* pin = &image->pins[p];
int netcode = pin->kiNetCode; int netcode = pin->kiNetCode;
if( netcode > 0 ) if( netcode > 0 )
@ -1560,7 +1503,6 @@ void SPECCTRA_DB::FromBOARD( BOARD* aBoard )
} }
COMPONENT* comp = m_pcb->placement->LookupCOMPONENT( image->GetImageId() ); COMPONENT* comp = m_pcb->placement->LookupCOMPONENT( image->GetImageId() );
PLACE* place = new PLACE( comp ); PLACE* place = new PLACE( comp );
comp->places.push_back( place ); 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 // 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. // the netclass dialog, or such control in the specctra export dialog.
m_top_via_layer = 0; // first specctra cu layer is number zero. m_top_via_layer = 0; // first specctra cu layer is number zero.
m_bot_via_layer = aBoard->GetCopperLayerCount()-1; m_bot_via_layer = aBoard->GetCopperLayerCount()-1;
@ -1647,12 +1588,7 @@ void SPECCTRA_DB::FromBOARD( BOARD* aBoard )
//-----<create the wires from tracks>----------------------------------- //-----<create the wires from tracks>-----------------------------------
{ {
// export all of them for now, later we'll decide what controls we need // export all of them for now, later we'll decide what controls we need on this.
// on this.
static const KICAD_T scanTRACKs[] = { PCB_TRACE_T, PCB_ARC_T, EOT };
items.Collect( aBoard, scanTRACKs );
std::string netname; std::string netname;
WIRING* wiring = m_pcb->wiring; WIRING* wiring = m_pcb->wiring;
PATH* path = 0; PATH* path = 0;
@ -1661,17 +1597,20 @@ void SPECCTRA_DB::FromBOARD( BOARD* aBoard )
int old_width = -1; int old_width = -1;
int old_layer = UNDEFINED_LAYER; int old_layer = UNDEFINED_LAYER;
for( int i = 0; i < items.GetCount(); ++i ) for( PCB_TRACK* track : aBoard->Tracks() )
{ {
PCB_TRACK* track = static_cast<PCB_TRACK*>( items[i] ); if( !track->IsType( { PCB_TRACE_T, PCB_ARC_T } ) )
continue;
int netcode = track->GetNetCode(); int netcode = track->GetNetCode();
if( netcode == 0 ) if( netcode == 0 )
continue; continue;
if( old_netcode != netcode || old_width != track->GetWidth() || if( old_netcode != netcode
old_layer != track->GetLayer() || || old_width != track->GetWidth()
( path && path->points.back() != mapPt(track->GetStart() ) ) ) || old_layer != track->GetLayer()
|| ( path && path->points.back() != mapPt( track->GetStart() ) ) )
{ {
old_width = track->GetWidth(); old_width = track->GetWidth();
old_layer = track->GetLayer(); old_layer = track->GetLayer();
@ -1698,12 +1637,9 @@ void SPECCTRA_DB::FromBOARD( BOARD* aBoard )
int pcbLayer = m_kicadLayer2pcb[kiLayer]; int pcbLayer = m_kicadLayer2pcb[kiLayer];
path = new PATH( wire ); path = new PATH( wire );
wire->SetShape( path ); wire->SetShape( path );
path->layer_id = m_layerIds[pcbLayer]; path->layer_id = m_layerIds[pcbLayer];
path->aperture_width = scale( old_width ); path->aperture_width = scale( old_width );
path->AppendPoint( mapPt( track->GetStart() ) ); path->AppendPoint( mapPt( track->GetStart() ) );
} }
@ -1715,15 +1651,12 @@ void SPECCTRA_DB::FromBOARD( BOARD* aBoard )
//-----<export the existing real BOARD instantiated vias>----------------- //-----<export the existing real BOARD instantiated vias>-----------------
{ {
// Export all vias, once per unique size and drill diameter combo. // Export all vias, once per unique size and drill diameter combo.
static const KICAD_T scanVIAs[] = { PCB_VIA_T, EOT }; for( PCB_TRACK* track : aBoard->Tracks() )
items.Collect( aBoard, scanVIAs );
for( int i = 0; i<items.GetCount(); ++i )
{ {
PCB_VIA* via = static_cast<PCB_VIA*>( items[i] ); if( track->Type() != PCB_VIA_T )
wxASSERT( via->Type() == PCB_VIA_T ); continue;
PCB_VIA* via = static_cast<PCB_VIA*>( track );
int netcode = via->GetNetCode(); int netcode = via->GetNetCode();
if( netcode == 0 ) 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 // if the one looked up is not our padstack, then delete our padstack
// since it was a duplicate of one already registered. // since it was a duplicate of one already registered.
if( padstack != registered ) if( padstack != registered )
{
delete padstack; delete padstack;
}
WIRE_VIA* dsnVia = new WIRE_VIA( m_pcb->wiring ); WIRE_VIA* dsnVia = new WIRE_VIA( m_pcb->wiring );
@ -1760,19 +1691,17 @@ void SPECCTRA_DB::FromBOARD( BOARD* aBoard )
//-----<via_descriptor>------------------------------------------------- //-----<via_descriptor>-------------------------------------------------
{ {
// The pcb->library will output <padstack_descriptors> which is a combined // The pcb->library will output <padstack_descriptors> which is a combined list of part
// list of part padstacks and via padstacks. specctra dsn uses the // padstacks and via padstacks. specctra dsn uses the <via_descriptors> to say which of
// <via_descriptors> to say which of those padstacks are vias. // those padstacks are vias.
// Output the vias in the padstack list here, by name only. This must // Output the vias in the padstack list here, by name only. This must be done after
// be done after exporting existing vias as WIRE_VIAs. // exporting existing vias as WIRE_VIAs.
VIA* vias = m_pcb->structure->via; VIA* vias = m_pcb->structure->via;
for( unsigned viaNdx = 0; viaNdx < m_pcb->library->vias.size(); ++viaNdx ) for( unsigned viaNdx = 0; viaNdx < m_pcb->library->vias.size(); ++viaNdx )
{
vias->AppendVia( m_pcb->library->vias[viaNdx].padstack_id.c_str() ); vias->AppendVia( m_pcb->library->vias[viaNdx].padstack_id.c_str() );
} }
}
//-----<output NETCLASSs>---------------------------------------------------- //-----<output NETCLASSs>----------------------------------------------------

View File

@ -52,13 +52,11 @@ using namespace DSN;
bool PCB_EDIT_FRAME::ImportSpecctraSession( const wxString& fullFileName ) bool PCB_EDIT_FRAME::ImportSpecctraSession( const wxString& fullFileName )
{ {
// To avoid issues with undo/redo lists (dangling pointers) // To avoid issues with undo/redo lists (dangling pointers) clear the lists
// clear the lists
// todo: use undo/redo feature // todo: use undo/redo feature
ClearUndoRedoList(); ClearUndoRedoList();
// Remove existing tracks from view. They will be readded later after loading // Remove existing tracks from view. They will be readded later after loading new tracks.
// new tracks.
if( GetCanvas() ) // clear view: if( GetCanvas() ) // clear view:
{ {
for( PCB_TRACK* track : GetBoard()->Tracks() ) for( PCB_TRACK* track : GetBoard()->Tracks() )
@ -113,8 +111,7 @@ namespace DSN {
* Function scale * Function scale
* converts a session file distance to KiCad units of deci-mils. * converts a session file distance to KiCad units of deci-mils.
* @param distance The session file length to convert. * @param distance The session file length to convert.
* @param aResolution The session UNIT_RES which holds the engineering unit * @param aResolution The session UNIT_RES which holds the engineering unit specifier
* specifier
* @return int - The KiCad length in internal unit * @return int - The KiCad length in internal unit
*/ */
static int scale( double distance, UNIT_RES* aResolution ) static int scale( double distance, UNIT_RES* aResolution )
@ -125,26 +122,14 @@ static int scale( double distance, UNIT_RES* aResolution )
switch( aResolution->GetEngUnits() ) switch( aResolution->GetEngUnits() )
{ {
default: default:
case T_inch: case T_inch: factor = 25.4e6; break; // nanometers per inch
factor = 25.4e6; // nanometers per inch case T_mil: factor = 25.4e3; break; // nanometers per mil
break; case T_cm: factor = 1e7; break; // nanometers per cm
case T_mil: case T_mm: factor = 1e6; break; // nanometers per mm
factor = 25.4e3; // nanometers per mil case T_um: factor = 1e3; break; // nanometers per um
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;
} }
int ret = KiROUND( factor * distance / resValue ); return KiROUND( factor * distance / resValue );
return ret;
} }
@ -257,9 +242,12 @@ PCB_VIA* SPECCTRA_DB::makeVIA( WIRE_VIA*aVia, PADSTACK* aPadstack, const POINT&
{ {
shape = (SHAPE*) (*aPadstack)[0]; shape = (SHAPE*) (*aPadstack)[0];
DSN_T type = shape->shape->Type(); DSN_T type = shape->shape->Type();
if( type != T_circle ) 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; CIRCLE* circle = (CIRCLE*) shape->shape;
int viaDiam = scale( circle->diameter, m_routeResolution ); 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]; shape = (SHAPE*) (*aPadstack)[i];
DSN_T type = shape->shape->Type(); DSN_T type = shape->shape->Type();
if( type != T_circle ) 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; CIRCLE* circle = (CIRCLE*) shape->shape;
@ -292,8 +283,8 @@ PCB_VIA* SPECCTRA_DB::makeVIA( WIRE_VIA*aVia, PADSTACK* aPadstack, const POINT&
if( layerNdx == -1 ) if( layerNdx == -1 )
{ {
wxString layerName = FROM_UTF8( circle->layer_id.c_str() ); wxString layerName = FROM_UTF8( circle->layer_id.c_str() );
THROW_IO_ERROR( wxString::Format( THROW_IO_ERROR( wxString::Format( _( "Session file uses invalid layer id '%s'" ),
_( "Session file uses invalid layer id \"%s\"" ), layerName ) ); layerName ) );
} }
if( layerNdx > topLayerNdx ) if( layerNdx > topLayerNdx )
@ -312,16 +303,16 @@ PCB_VIA* SPECCTRA_DB::makeVIA( WIRE_VIA*aVia, PADSTACK* aPadstack, const POINT&
if( ( topLayerNdx == 0 && botLayerNdx == 1 ) if( ( topLayerNdx == 0 && botLayerNdx == 1 )
|| ( topLayerNdx == copperLayerCount-2 && botLayerNdx == copperLayerCount-1 ) ) || ( topLayerNdx == copperLayerCount-2 && botLayerNdx == copperLayerCount-1 ) )
{
via->SetViaType( VIATYPE::MICROVIA ); via->SetViaType( VIATYPE::MICROVIA );
}
else else
{
via->SetViaType( VIATYPE::BLIND_BURIED ); via->SetViaType( VIATYPE::BLIND_BURIED );
}
via->SetWidth( viaDiam ); via->SetWidth( viaDiam );
via->SetLayerPair( m_pcbLayer2kicad[ topLayerNdx ], m_pcbLayer2kicad[ botLayerNdx ] );
PCB_LAYER_ID topLayer = m_pcbLayer2kicad[topLayerNdx];
PCB_LAYER_ID botLayer = m_pcbLayer2kicad[botLayerNdx];
via->SetLayerPair( topLayer, botLayer );
} }
wxASSERT( via ); wxASSERT( via );
@ -356,8 +347,7 @@ void SPECCTRA_DB::FromSESSION( BOARD* aBoard )
if( !m_session->route->library ) if( !m_session->route->library )
THROW_IO_ERROR( _("Session file is missing the \"library_out\" section") ); THROW_IO_ERROR( _("Session file is missing the \"library_out\" section") );
// delete all the old tracks and vias but save locked tracks/vias // delete the old tracks and vias but save locked tracks/vias; they will be re-added later
// they will be re-added later
std::vector<PCB_TRACK*> locked; std::vector<PCB_TRACK*> locked;
while( !aBoard->Tracks().empty() ) 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 // Add locked tracks: because they are exported as Fix tracks, they are not
// in .ses file. // in .ses file.
for( PCB_TRACK* track: locked ) for( PCB_TRACK* track: locked )
{
aBoard->Add( track ); aBoard->Add( track );
}
if( m_session->placement ) 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 // each COMPONENT, reposition and re-orient each component and put on
// correct side of the board. // correct side of the board.
COMPONENTS& components = m_session->placement->components; COMPONENTS& components = m_session->placement->components;
for( COMPONENTS::iterator comp=components.begin(); comp!=components.end(); ++comp ) for( COMPONENTS::iterator comp=components.begin(); comp!=components.end(); ++comp )
{ {
PLACES& places = comp->places; PLACES& places = comp->places;
@ -462,14 +451,8 @@ void SPECCTRA_DB::FromSESSION( BOARD* aBoard )
NETINFO_ITEM* netinfo = aBoard->FindNet( netName ); NETINFO_ITEM* netinfo = aBoard->FindNet( netName );
if( netinfo ) if( netinfo )
{
netoutCode = netinfo->GetNetCode(); netoutCode = netinfo->GetNetCode();
} }
else // else netCode remains 0
{
// int breakhere = 1;
}
}
WIRES& wires = net->wires; WIRES& wires = net->wires;
for( unsigned i = 0; i<wires.size(); ++i ) for( unsigned i = 0; i<wires.size(); ++i )
@ -479,17 +462,16 @@ void SPECCTRA_DB::FromSESSION( BOARD* aBoard )
if( shape != T_path ) 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 * shape == T_polygon is expected from freerouter if you have a zone on a non-
and the design does a round trip back in as session here. * "power" type layer, i.e. a T_signal layer and the design does a round-trip
We kept our own zones in the BOARD, so ignore this so called * back in as session here. We kept our own zones in the BOARD, so ignore this
'wire'. * so called 'wire'.
wxString netId = FROM_UTF8( wire->net_id.c_str() ); 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(), DLEX::GetTokenString(shape).GetData(),
netId.GetData() netId.GetData() ) );
) );
*/ */
} }
else else
@ -506,6 +488,7 @@ void SPECCTRA_DB::FromSESSION( BOARD* aBoard )
WIRE_VIAS& wire_vias = net->wire_vias; WIRE_VIAS& wire_vias = net->wire_vias;
LIBRARY& library = *m_session->route->library; LIBRARY& library = *m_session->route->library;
for( unsigned i=0; i<wire_vias.size(); ++i ) for( unsigned i=0; i<wire_vias.size(); ++i )
{ {
int netCode = 0; int netCode = 0;
@ -518,8 +501,6 @@ void SPECCTRA_DB::FromSESSION( BOARD* aBoard )
if( netvia ) if( netvia )
netCode = netvia->GetNetCode(); netCode = netvia->GetNetCode();
// else netCode remains 0
} }
WIRE_VIA* wire_via = &wire_vias[i]; WIRE_VIA* wire_via = &wire_vias[i];
@ -530,16 +511,11 @@ void SPECCTRA_DB::FromSESSION( BOARD* aBoard )
if( !padstack ) if( !padstack )
{ {
// Dick Feb 29, 2008: // Dick Feb 29, 2008:
// Freerouter has a bug where it will not round trip all vias. // Freerouter has a bug where it will not round trip all vias. Vias which have
// Vias which have a (use_via) element will be round tripped. // a (use_via) element will be round tripped. Vias which do not, don't come back
// Vias which do not, don't come back in in the session library, // in in the session library, even though they may be actually used in the
// even though they may be actually used in the pre-routed, // pre-routed, protected wire_vias. So until that is fixed, create the padstack
// protected wire_vias. So until that is fixed, create the // from its name as a work around.
// 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.
wxString psid( FROM_UTF8( wire_via->GetPadstackId().c_str() ) ); wxString psid( FROM_UTF8( wire_via->GetPadstackId().c_str() ) );
THROW_IO_ERROR( wxString::Format( _( "A wire_via refers to missing padstack '%s'." ), THROW_IO_ERROR( wxString::Format( _( "A wire_via refers to missing padstack '%s'." ),

View File

@ -211,7 +211,7 @@ bool BOARD_EDITOR_CONTROL::Init()
menu.AddMenu( lockMenu.get(), SELECTION_CONDITIONS::NotEmpty, 100 ); 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<DRAWING_TOOL>(); DRAWING_TOOL* drawingTool = m_toolMgr->GetTool<DRAWING_TOOL>();
@ -680,16 +680,16 @@ int BOARD_EDITOR_CONTROL::TogglePythonConsole( const TOOL_EVENT& aEvent )
int BOARD_EDITOR_CONTROL::TrackWidthInc( const TOOL_EVENT& aEvent ) int BOARD_EDITOR_CONTROL::TrackWidthInc( const TOOL_EVENT& aEvent )
{ {
BOARD_DESIGN_SETTINGS& designSettings = getModel<BOARD>()->GetDesignSettings(); BOARD_DESIGN_SETTINGS& designSettings = getModel<BOARD>()->GetDesignSettings();
constexpr KICAD_T types[] = { PCB_TRACE_T, PCB_VIA_T, EOT };
PCB_SELECTION& selection = m_toolMgr->GetTool<PCB_SELECTION_TOOL>()->GetSelection(); PCB_SELECTION& selection = m_toolMgr->GetTool<PCB_SELECTION_TOOL>()->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 ); BOARD_COMMIT commit( this );
for( EDA_ITEM* item : selection ) 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<PCB_TRACK*>( item ); PCB_TRACK* track = static_cast<PCB_TRACK*>( item );
@ -760,16 +760,16 @@ int BOARD_EDITOR_CONTROL::TrackWidthInc( const TOOL_EVENT& aEvent )
int BOARD_EDITOR_CONTROL::TrackWidthDec( const TOOL_EVENT& aEvent ) int BOARD_EDITOR_CONTROL::TrackWidthDec( const TOOL_EVENT& aEvent )
{ {
BOARD_DESIGN_SETTINGS& designSettings = getModel<BOARD>()->GetDesignSettings(); BOARD_DESIGN_SETTINGS& designSettings = getModel<BOARD>()->GetDesignSettings();
constexpr KICAD_T types[] = { PCB_TRACE_T, PCB_VIA_T, EOT };
PCB_SELECTION& selection = m_toolMgr->GetTool<PCB_SELECTION_TOOL>()->GetSelection(); PCB_SELECTION& selection = m_toolMgr->GetTool<PCB_SELECTION_TOOL>()->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 ); BOARD_COMMIT commit( this );
for( EDA_ITEM* item : selection ) 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<PCB_TRACK*>( item ); PCB_TRACK* track = static_cast<PCB_TRACK*>( item );
@ -840,10 +840,10 @@ int BOARD_EDITOR_CONTROL::TrackWidthDec( const TOOL_EVENT& aEvent )
int BOARD_EDITOR_CONTROL::ViaSizeInc( const TOOL_EVENT& aEvent ) int BOARD_EDITOR_CONTROL::ViaSizeInc( const TOOL_EVENT& aEvent )
{ {
BOARD_DESIGN_SETTINGS& designSettings = getModel<BOARD>()->GetDesignSettings(); BOARD_DESIGN_SETTINGS& designSettings = getModel<BOARD>()->GetDesignSettings();
constexpr KICAD_T types[] = { PCB_TRACE_T, PCB_VIA_T, EOT };
PCB_SELECTION& selection = m_toolMgr->GetTool<PCB_SELECTION_TOOL>()->GetSelection(); PCB_SELECTION& selection = m_toolMgr->GetTool<PCB_SELECTION_TOOL>()->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 ); 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 ) int BOARD_EDITOR_CONTROL::ViaSizeDec( const TOOL_EVENT& aEvent )
{ {
BOARD_DESIGN_SETTINGS& designSettings = getModel<BOARD>()->GetDesignSettings(); BOARD_DESIGN_SETTINGS& designSettings = getModel<BOARD>()->GetDesignSettings();
constexpr KICAD_T types[] = { PCB_TRACE_T, PCB_VIA_T, EOT };
PCB_SELECTION& selection = m_toolMgr->GetTool<PCB_SELECTION_TOOL>()->GetSelection(); PCB_SELECTION& selection = m_toolMgr->GetTool<PCB_SELECTION_TOOL>()->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 ); BOARD_COMMIT commit( this );

View File

@ -79,8 +79,11 @@ bool BOARD_INSPECTION_TOOL::Init()
auto netSubMenu = std::make_shared<NET_CONTEXT_MENU>(); auto netSubMenu = std::make_shared<NET_CONTEXT_MENU>();
netSubMenu->SetTool( this ); netSubMenu->SetTool( this );
static KICAD_T connectedTypes[] = { PCB_TRACE_T, PCB_VIA_T, PCB_ARC_T, PCB_PAD_T, PCB_ZONE_T, static std::initializer_list<KICAD_T> connectedTypes = { PCB_TRACE_T,
EOT }; PCB_VIA_T,
PCB_ARC_T,
PCB_PAD_T,
PCB_ZONE_T };
CONDITIONAL_MENU& menu = selectionTool->GetToolMenu().GetMenu(); CONDITIONAL_MENU& menu = selectionTool->GetToolMenu().GetMenu();
@ -1342,10 +1345,11 @@ int BOARD_INSPECTION_TOOL::HighlightItem( const TOOL_EVENT& aEvent )
guide.SetPreferredLayer( activeLayer ); guide.SetPreferredLayer( activeLayer );
GENERAL_COLLECTOR collector; 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 ) 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 // Apply the active selection filter, except we want to allow picking locked items for
// highlighting even if the user has disabled them for selection // highlighting even if the user has disabled them for selection

View File

@ -150,27 +150,22 @@ bool CONVERT_TOOL::Init()
m_menu->SetIcon( BITMAPS::convert ); m_menu->SetIcon( BITMAPS::convert );
m_menu->SetTitle( _( "Create from Selection" ) ); m_menu->SetTitle( _( "Create from Selection" ) );
static KICAD_T convertibleTracks[] = { PCB_TRACE_T, PCB_ARC_T, EOT }; auto graphicLines = P_S_C::OnlyGraphicShapeTypes( { SHAPE_T::SEGMENT, SHAPE_T::RECT,
static KICAD_T zones[] = { PCB_ZONE_T, PCB_FP_ZONE_T, EOT }; 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(); && P_S_C::SameLayer();
auto graphicToTrack = P_S_C::OnlyGraphicShapeTypes( { SHAPE_T::SEGMENT, SHAPE_T::ARC } ); auto graphicToTrack = P_S_C::OnlyGraphicShapeTypes( { SHAPE_T::SEGMENT, SHAPE_T::ARC } );
auto trackLines = S_C::MoreThan( 1 ) && S_C::OnlyTypes( convertibleTracks ) auto trackLines = S_C::MoreThan( 1 ) && S_C::OnlyTypes( { PCB_TRACE_T, PCB_ARC_T } )
&& P_S_C::SameLayer(); && P_S_C::SameLayer();
auto anyLines = graphicLines || trackLines; auto anyLines = graphicLines || trackLines;
auto anyPolys = S_C::OnlyTypes( zones ) auto anyPolys = S_C::OnlyTypes( { PCB_ZONE_T, PCB_FP_ZONE_T } )
|| P_S_C::OnlyGraphicShapeTypes( { SHAPE_T::POLY, SHAPE_T::RECT } ); || P_S_C::OnlyGraphicShapeTypes( { SHAPE_T::POLY, SHAPE_T::RECT } );
auto lineToArc = S_C::Count( 1 ) auto lineToArc = S_C::Count( 1 )
&& ( P_S_C::OnlyGraphicShapeTypes( { SHAPE_T::SEGMENT } ) && ( 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 showConvert = anyPolys || anyLines || lineToArc;
auto canCreatePolyType = anyLines || anyPolys; auto canCreatePolyType = anyLines || anyPolys;

View File

@ -100,7 +100,6 @@ static std::vector<BOARD_ITEM*> initTextTable( std::vector<std::vector<PCB_TEXT*
for( const PCB_TEXT* cell : col ) for( const PCB_TEXT* cell : col )
{ {
if( j >= nbRows ) if( j >= nbRows )
break; break;
@ -109,7 +108,6 @@ static std::vector<BOARD_ITEM*> initTextTable( std::vector<std::vector<PCB_TEXT*
rowHeight[j] = rowHeight[j] > height ? rowHeight[j] : height; rowHeight[j] = rowHeight[j] > height ? rowHeight[j] : height;
colWidth[i] = colWidth[i] > width ? colWidth[i] : width; colWidth[i] = colWidth[i] > width ? colWidth[i] : width;
j++; j++;
} }
i++; i++;
@ -132,20 +130,16 @@ static std::vector<BOARD_ITEM*> initTextTable( std::vector<std::vector<PCB_TEXT*
{ {
line = new PCB_SHAPE; line = new PCB_SHAPE;
line->SetLayer( aLayer ); line->SetLayer( aLayer );
line->SetStartX( origin.x ); line->SetStart( VECTOR2I( origin.x, y ) );
line->SetStartY( y ); line->SetEnd( VECTOR2I( origin.x + width, y ) );
line->SetEndX( origin.x + width );
line->SetEndY( y );
y += rowHeight[i]; y += rowHeight[i];
table.push_back( line ); table.push_back( line );
} }
line = new PCB_SHAPE; line = new PCB_SHAPE;
line->SetLayer( aLayer ); line->SetLayer( aLayer );
line->SetStartX( origin.x ); line->SetStart( VECTOR2I( origin.x, y ) );
line->SetStartY( y ); line->SetEnd( VECTOR2I( origin.x + width, y ) );
line->SetEndX( origin.x + width );
line->SetEndY( y );
table.push_back( line ); table.push_back( line );
int x = origin.x; int x = origin.x;
@ -153,20 +147,16 @@ static std::vector<BOARD_ITEM*> initTextTable( std::vector<std::vector<PCB_TEXT*
{ {
line = new PCB_SHAPE; line = new PCB_SHAPE;
line->SetLayer( aLayer ); line->SetLayer( aLayer );
line->SetStartX( x ); line->SetStart( VECTOR2I( x, origin.y ) );
line->SetStartY( origin.y ); line->SetEnd( VECTOR2I( x, origin.y + height ) );
line->SetEndX( x );
line->SetEndY( origin.y + height );
x += colWidth[i]; x += colWidth[i];
table.push_back( line ); table.push_back( line );
} }
line = new PCB_SHAPE; line = new PCB_SHAPE;
line->SetLayer( aLayer ); line->SetLayer( aLayer );
line->SetStartX( x ); line->SetStart( VECTOR2I( x, origin.y ) );
line->SetStartY( origin.y ); line->SetEnd( VECTOR2I( x, origin.y + height ) );
line->SetEndX( x );
line->SetEndY( origin.y + height );
table.push_back( line ); table.push_back( line );
} }
@ -198,6 +188,7 @@ static std::vector<BOARD_ITEM*> initTextTable( std::vector<std::vector<PCB_TEXT*
pos.x = pos.x + colWidth[i]; pos.x = pos.x + colWidth[i];
i++; i++;
} }
return table; return table;
} }
@ -536,7 +527,7 @@ std::vector<BOARD_ITEM*> DRAWING_TOOL::DrawBoardCharacteristics( const VECTOR2I&
if( aDrawNow ) if( aDrawNow )
{ {
for( auto item : objects ) for( BOARD_ITEM* item : objects )
commit.Add( item ); commit.Add( item );
commit.Push( wxT( "Board Characteristics" ) ); commit.Push( wxT( "Board Characteristics" ) );
@ -700,17 +691,16 @@ int DRAWING_TOOL::PlaceCharacteristics( const TOOL_EVENT& aEvent )
VECTOR2I tableSize; VECTOR2I tableSize;
LSET layerSet = ( layerSet.AllCuMask() | layerSet.AllTechMask() ); LSET layerSet = ( layerSet.AllCuMask() | layerSet.AllTechMask() );
layerSet = static_cast<LSET>( layerSet.set( Edge_Cuts ).set( Margin ) ); layerSet = layerSet.set( Edge_Cuts ).set( Margin );
layerSet = static_cast<LSET>( layerSet.reset( F_Fab ).reset( B_Fab ) ); layerSet = layerSet.reset( F_Fab ).reset( B_Fab );
PCB_LAYER_ID layer = m_frame->GetActiveLayer(); PCB_LAYER_ID layer = m_frame->GetActiveLayer();
if( ( layerSet & LSET( layer ) ).count() ) // if layer is a forbidden layer if( ( layerSet & LSET( layer ) ).count() ) // if layer is a forbidden layer
m_frame->SetActiveLayer( Cmts_User ); m_frame->SetActiveLayer( Cmts_User );
std::vector<BOARD_ITEM*> table = DrawBoardCharacteristics( wxPoint( 0, 0 ), std::vector<BOARD_ITEM*> table = DrawBoardCharacteristics( { 0, 0 }, m_frame->GetActiveLayer(),
m_frame->GetActiveLayer(), false, false, &tableSize );
&tableSize );
std::vector<BOARD_ITEM*> preview; std::vector<BOARD_ITEM*> preview;
std::vector<BOARD_ITEM*> items; std::vector<BOARD_ITEM*> items;
@ -719,25 +709,17 @@ int DRAWING_TOOL::PlaceCharacteristics( const TOOL_EVENT& aEvent )
PCB_SHAPE* line3 = new PCB_SHAPE; PCB_SHAPE* line3 = new PCB_SHAPE;
PCB_SHAPE* line4 = new PCB_SHAPE; PCB_SHAPE* line4 = new PCB_SHAPE;
line1->SetStartX( 0 ); line1->SetStart( VECTOR2I( 0, 0 ) );
line1->SetStartY( 0 ); line1->SetEnd( VECTOR2I( tableSize.x, 0 ) );
line1->SetEndX( tableSize.x );
line1->SetEndY( 0 );
line2->SetStartX( 0 ); line2->SetStart( VECTOR2I( 0, 0 ) );
line2->SetStartY( 0 ); line2->SetEnd( VECTOR2I( 0, tableSize.y ) );
line2->SetEndX( 0 );
line2->SetEndY( tableSize.y );
line3->SetStartX( tableSize.x ); line3->SetStart( VECTOR2I( tableSize.x, 0 ) );
line3->SetStartY( 0 ); line3->SetEnd( tableSize );
line3->SetEndX( tableSize.x );
line3->SetEndY( tableSize.y );
line4->SetStartX( 0 ); line4->SetStart( VECTOR2I( 0, tableSize.y ) );
line4->SetStartY( tableSize.y ); line4->SetEnd( tableSize );
line4->SetEndX( tableSize.x );
line4->SetEndY( tableSize.y );
line1->SetLayer( m_frame->GetActiveLayer() ); line1->SetLayer( m_frame->GetActiveLayer() );
line2->SetLayer( m_frame->GetActiveLayer() ); line2->SetLayer( m_frame->GetActiveLayer() );
@ -771,8 +753,8 @@ int DRAWING_TOOL::PlaceStackup( const TOOL_EVENT& aEvent )
VECTOR2I tableSize; VECTOR2I tableSize;
LSET layerSet = ( layerSet.AllCuMask() | layerSet.AllTechMask() ); LSET layerSet = ( layerSet.AllCuMask() | layerSet.AllTechMask() );
layerSet = static_cast<LSET>( layerSet.set( Edge_Cuts ).set( Margin ) ); layerSet = layerSet.set( Edge_Cuts ).set( Margin );
layerSet = static_cast<LSET>( layerSet.reset( F_Fab ).reset( B_Fab ) ); layerSet = layerSet.reset( F_Fab ).reset( B_Fab );
PCB_LAYER_ID layer = m_frame->GetActiveLayer(); PCB_LAYER_ID layer = m_frame->GetActiveLayer();
PCB_LAYER_ID savedLayer = layer; 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* line3 = new PCB_SHAPE;
PCB_SHAPE* line4 = new PCB_SHAPE; PCB_SHAPE* line4 = new PCB_SHAPE;
line1->SetStartX( 0 ); line1->SetStart( VECTOR2I( 0, 0 ) );
line1->SetStartY( 0 ); line1->SetEnd( VECTOR2I( tableSize.x, 0 ) );
line1->SetEndX( tableSize.x );
line1->SetEndY( 0 );
line2->SetStartX( 0 ); line2->SetStart( VECTOR2I( 0, 0 ) );
line2->SetStartY( 0 ); line2->SetEnd( VECTOR2I( 0, tableSize.y ) );
line2->SetEndX( 0 );
line2->SetEndY( tableSize.y );
line3->SetStartX( tableSize.x ); line3->SetStart( VECTOR2I( tableSize.x, 0 ) );
line3->SetStartY( 0 ); line3->SetEnd( tableSize );
line3->SetEndX( tableSize.x );
line3->SetEndY( tableSize.y );
line4->SetStartX( 0 ); line4->SetStart( VECTOR2I( 0, tableSize.y ) );
line4->SetStartY( tableSize.y ); line4->SetEnd( tableSize );
line4->SetEndX( tableSize.x );
line4->SetEndY( tableSize.y );
line1->SetLayer( m_frame->GetActiveLayer() ); line1->SetLayer( m_frame->GetActiveLayer() );
line2->SetLayer( m_frame->GetActiveLayer() ); line2->SetLayer( m_frame->GetActiveLayer() );

View File

@ -139,7 +139,7 @@ bool EDIT_TOOL::Init()
return m_isFootprintEditor; return m_isFootprintEditor;
}; };
auto singleFootprintCondition = SELECTION_CONDITIONS::OnlyType( PCB_FOOTPRINT_T ) auto singleFootprintCondition = SELECTION_CONDITIONS::OnlyTypes( { PCB_FOOTPRINT_T } )
&& SELECTION_CONDITIONS::Count( 1 ); && SELECTION_CONDITIONS::Count( 1 );
auto noActiveToolCondition = auto noActiveToolCondition =
@ -167,13 +167,13 @@ bool EDIT_TOOL::Init()
menu.AddItem( PCB_ACTIONS::move, SELECTION_CONDITIONS::NotEmpty menu.AddItem( PCB_ACTIONS::move, SELECTION_CONDITIONS::NotEmpty
&& notMovingCondition ); && notMovingCondition );
menu.AddItem( PCB_ACTIONS::breakTrack, SELECTION_CONDITIONS::Count( 1 ) 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 ) menu.AddItem( PCB_ACTIONS::drag45Degree, SELECTION_CONDITIONS::Count( 1 )
&& SELECTION_CONDITIONS::OnlyTypes( GENERAL_COLLECTOR::DraggableItems ) ); && SELECTION_CONDITIONS::OnlyTypes( GENERAL_COLLECTOR::DraggableItems ) );
menu.AddItem( PCB_ACTIONS::dragFreeAngle, SELECTION_CONDITIONS::Count( 1 ) menu.AddItem( PCB_ACTIONS::dragFreeAngle, SELECTION_CONDITIONS::Count( 1 )
&& SELECTION_CONDITIONS::OnlyTypes( GENERAL_COLLECTOR::DraggableItems ) && SELECTION_CONDITIONS::OnlyTypes( GENERAL_COLLECTOR::DraggableItems )
&& !SELECTION_CONDITIONS::OnlyType( PCB_FOOTPRINT_T ) ); && !SELECTION_CONDITIONS::OnlyTypes( { PCB_FOOTPRINT_T } ) );
menu.AddItem( PCB_ACTIONS::filletTracks, SELECTION_CONDITIONS::OnlyTypes( GENERAL_COLLECTOR::Tracks ) ); 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::rotateCcw, SELECTION_CONDITIONS::NotEmpty );
menu.AddItem( PCB_ACTIONS::rotateCw, SELECTION_CONDITIONS::NotEmpty ); menu.AddItem( PCB_ACTIONS::rotateCw, SELECTION_CONDITIONS::NotEmpty );
menu.AddItem( PCB_ACTIONS::flip, 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 // drop a knee between two segments to a single segment
if( aCollector.GetCount() == 2 && dynamic_cast<PCB_TRACK*>( aCollector[0] ) ) if( aCollector.GetCount() == 2 && dynamic_cast<PCB_TRACK*>( aCollector[0] ) )
{ {
static KICAD_T types[] = { PCB_VIA_T, PCB_TRACE_T, PCB_ARC_T, EOT };
PCB_TRACK* a = static_cast<PCB_TRACK*>( aCollector[0] ); PCB_TRACK* a = static_cast<PCB_TRACK*>( aCollector[0] );
PCB_TRACK* b = static_cast<PCB_TRACK*>( aCollector[1] ); PCB_TRACK* b = static_cast<PCB_TRACK*>( aCollector[1] );
const auto& c = aCollector[0]->GetBoard()->GetConnectivity(); const auto& c = aCollector[0]->GetBoard()->GetConnectivity();
int dist = a->GetWidth() / 2; 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 ) ) if( alg::contains( connectedItems, b ) )
aCollector.Remove( b ); aCollector.Remove( b );
@ -366,12 +368,10 @@ int EDIT_TOOL::DragArcTrack( const TOOL_EVENT& aEvent )
tanEnd.A = tanIntersect; tanEnd.A = tanIntersect;
tanEnd.B = theArc->GetEnd(); tanEnd.B = theArc->GetEnd();
KICAD_T track_types[] = { PCB_PAD_T, PCB_VIA_T, PCB_TRACE_T, PCB_ARC_T, EOT };
auto getUniqueTrackAtAnchorCollinear = auto getUniqueTrackAtAnchorCollinear =
[&]( const VECTOR2I& aAnchor, const SEG& aCollinearSeg ) -> PCB_TRACK* [&]( const VECTOR2I& aAnchor, const SEG& aCollinearSeg ) -> PCB_TRACK*
{ {
auto conn = board()->GetConnectivity(); std::shared_ptr<CONNECTIVITY_DATA> conn = board()->GetConnectivity();
// Allow items at a distance within the width of the arc track // Allow items at a distance within the width of the arc track
int allowedDeviation = theArc->GetWidth(); int allowedDeviation = theArc->GetWidth();
@ -380,7 +380,9 @@ int EDIT_TOOL::DragArcTrack( const TOOL_EVENT& aEvent )
for( int i = 0; i < 3; i++ ) 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 );
allowedDeviation /= 2; allowedDeviation /= 2;
@ -797,14 +799,13 @@ int EDIT_TOOL::FilletTracks( const TOOL_EVENT& aEvent )
}; };
std::vector<FILLET_OP> filletOperations; std::vector<FILLET_OP> filletOperations;
KICAD_T track_types[] = { PCB_PAD_T, PCB_VIA_T, PCB_TRACE_T, PCB_ARC_T, EOT };
bool operationPerformedOnAtLeastOne = false; bool operationPerformedOnAtLeastOne = false;
bool didOneAttemptFail = false; bool didOneAttemptFail = false;
std::set<PCB_TRACK*> processedTracks; std::set<PCB_TRACK*> processedTracks;
for( auto it = selection.begin(); it != selection.end(); it++ ) for( EDA_ITEM* item : selection )
{ {
PCB_TRACK* track = dyn_cast<PCB_TRACK*>( *it ); PCB_TRACK* track = dyn_cast<PCB_TRACK*>( item );
if( !track || track->Type() != PCB_TRACE_T || track->GetLength() == 0 ) if( !track || track->Type() != PCB_TRACE_T || track->GetLength() == 0 )
{ {
@ -814,10 +815,14 @@ int EDIT_TOOL::FilletTracks( const TOOL_EVENT& aEvent )
auto processFilletOp = auto processFilletOp =
[&]( bool aStartPoint ) [&]( bool aStartPoint )
{ {
std::shared_ptr<CONNECTIVITY_DATA> connectivity = board()->GetConnectivity(); std::shared_ptr<CONNECTIVITY_DATA> c = board()->GetConnectivity();
VECTOR2I anchor = ( aStartPoint ) ? track->GetStart() : track->GetEnd(); VECTOR2I anchor = aStartPoint ? track->GetStart()
auto itemsOnAnchor = connectivity->GetConnectedItemsAtAnchor( track, anchor, : track->GetEnd();
track_types ); std::vector<BOARD_CONNECTED_ITEM*> itemsOnAnchor;
itemsOnAnchor = c->GetConnectedItemsAtAnchor( track, anchor,
{ PCB_PAD_T, PCB_VIA_T,
PCB_TRACE_T, PCB_ARC_T } );
if( itemsOnAnchor.size() > 0 if( itemsOnAnchor.size() > 0
&& selection.Contains( itemsOnAnchor.at( 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: // 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 ); DIALOG_TRACK_VIA_PROPERTIES dlg( editFrame, selection, *m_commit );
dlg.ShowQuasiModal(); // QuasiModal required for NET_SELECTOR dlg.ShowQuasiModal(); // QuasiModal required for NET_SELECTOR

View File

@ -85,7 +85,7 @@ bool PAD_TOOL::Init()
SELECTION_CONDITION padSel = SELECTION_CONDITIONS::HasType( PCB_PAD_T ); SELECTION_CONDITION padSel = SELECTION_CONDITIONS::HasType( PCB_PAD_T );
SELECTION_CONDITION singlePadSel = SELECTION_CONDITIONS::Count( 1 ) && SELECTION_CONDITION singlePadSel = SELECTION_CONDITIONS::Count( 1 ) &&
SELECTION_CONDITIONS::OnlyType( PCB_PAD_T ); SELECTION_CONDITIONS::OnlyTypes( { PCB_PAD_T } );
auto explodeCondition = auto explodeCondition =
[&]( const SELECTION& aSel ) [&]( const SELECTION& aSel )
@ -280,8 +280,6 @@ int PAD_TOOL::EnumeratePads( const TOOL_EVENT& aEvent )
return 0; return 0;
GENERAL_COLLECTOR collector; GENERAL_COLLECTOR collector;
const KICAD_T types[] = { PCB_PAD_T, EOT };
GENERAL_COLLECTORS_GUIDE guide = frame()->GetCollectorsGuide(); GENERAL_COLLECTORS_GUIDE guide = frame()->GetCollectorsGuide();
guide.SetIgnoreMTextsMarkedNoShow( true ); guide.SetIgnoreMTextsMarkedNoShow( true );
guide.SetIgnoreMTextsOnBack( true ); guide.SetIgnoreMTextsOnBack( true );
@ -384,7 +382,7 @@ int PAD_TOOL::EnumeratePads( const TOOL_EVENT& aEvent )
for( int j = 0; j < segments; ++j ) for( int j = 0; j < segments; ++j )
{ {
wxPoint testpoint( cursorPos.x - j * line_step.x, cursorPos.y - j * line_step.y ); 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 ) for( int i = 0; i < collector.GetCount(); ++i )
selectedPads.push_back( static_cast<PAD*>( collector[i] ) ); selectedPads.push_back( static_cast<PAD*>( collector[i] ) );

View File

@ -1344,10 +1344,9 @@ void PCB_SELECTION_TOOL::selectAllConnectedTracks(
void PCB_SELECTION_TOOL::selectAllItemsOnNet( int aNetCode, bool aSelect ) void PCB_SELECTION_TOOL::selectAllItemsOnNet( int aNetCode, bool aSelect )
{ {
constexpr KICAD_T types[] = { PCB_TRACE_T, PCB_ARC_T, PCB_VIA_T, EOT }; std::shared_ptr<CONNECTIVITY_DATA> conn = board()->GetConnectivity();
auto connectivity = 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 ) ) if( itemPassesFilter( item, true ) )
aSelect ? select( item ) : unselect( item ); aSelect ? select( item ) : unselect( item );
@ -1470,19 +1469,16 @@ void PCB_SELECTION_TOOL::selectConnections( const std::vector<BOARD_ITEM*>& aIte
// now we need to find all footprints that are connected to each of these nets then we need // 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 // to determine if these footprints are in the list of footprints
std::vector<int> removeCodeList; std::vector<int> removeCodeList;
constexpr KICAD_T padType[] = { PCB_PAD_T, EOT }; std::shared_ptr<CONNECTIVITY_DATA> conn = board()->GetConnectivity();
for( int netCode : netcodeList ) for( int netCode : netcodeList )
{ {
for( BOARD_CONNECTED_ITEM* mitem : for( BOARD_CONNECTED_ITEM* pad : conn->GetNetItems( netCode, { PCB_PAD_T } ) )
board()->GetConnectivity()->GetNetItems( netCode, padType ) )
{ {
if( mitem->Type() == PCB_PAD_T if( !std::binary_search( padList.begin(), padList.end(), pad ) )
&& !std::binary_search( padList.begin(), padList.end(), mitem ) )
{ {
// if we cannot find the pad in the padList then we can // if we cannot find the pad in the padList then we can assume that that pad
// assume that that pad should not be used, therefore // should not be used, therefore invalidate this netcode.
// invalidate this netcode.
removeCodeList.push_back( netCode ); removeCodeList.push_back( netCode );
break; break;
} }
@ -1490,25 +1486,18 @@ void PCB_SELECTION_TOOL::selectConnections( const std::vector<BOARD_ITEM*>& aIte
} }
for( int removeCode : removeCodeList ) for( int removeCode : removeCodeList )
{
netcodeList.remove( removeCode ); netcodeList.remove( removeCode );
}
std::vector<BOARD_CONNECTED_ITEM*> localConnectionList; std::unordered_set<BOARD_ITEM*> localConnectionList;
constexpr KICAD_T trackViaType[] = { PCB_TRACE_T, PCB_ARC_T, PCB_VIA_T, EOT };
for( int netCode : netcodeList ) for( int netCode : netcodeList )
{ {
for( BOARD_CONNECTED_ITEM* item : for( BOARD_ITEM* item : conn->GetNetItems( netCode, { PCB_TRACE_T, PCB_ARC_T, PCB_VIA_T } ) )
board()->GetConnectivity()->GetNetItems( netCode, trackViaType ) ) localConnectionList.insert( item );
localConnectionList.push_back( item );
} }
for( BOARD_CONNECTED_ITEM* i : localConnectionList ) for( BOARD_ITEM* item : localConnectionList )
{ select( item );
if( i != nullptr )
select( i );
}
} }