diff --git a/common/base_struct.cpp b/common/base_struct.cpp index 9b6273d2c0..ecb6c13d71 100644 --- a/common/base_struct.cpp +++ b/common/base_struct.cpp @@ -107,10 +107,10 @@ EDA_ITEM* EDA_ITEM::Clone() const } -SEARCH_RESULT EDA_ITEM::IterateForward( EDA_ITEM* listStart, - INSPECTOR* inspector, - const void* testData, - const KICAD_T scanTypes[] ) +SEARCH_RESULT EDA_ITEM::IterateForward( EDA_ITEM* listStart, + INSPECTOR inspector, + void* testData, + const KICAD_T scanTypes[] ) { EDA_ITEM* p = listStart; @@ -126,8 +126,7 @@ SEARCH_RESULT EDA_ITEM::IterateForward( EDA_ITEM* listStart, // see base_struct.h // many classes inherit this method, be careful: -SEARCH_RESULT EDA_ITEM::Visit( INSPECTOR* inspector, const void* testData, - const KICAD_T scanTypes[] ) +SEARCH_RESULT EDA_ITEM::Visit( INSPECTOR inspector, void* testData, const KICAD_T scanTypes[] ) { KICAD_T stype; @@ -140,7 +139,7 @@ SEARCH_RESULT EDA_ITEM::Visit( INSPECTOR* inspector, const void* testData, // If caller wants to inspect my type if( stype == Type() ) { - if( SEARCH_QUIT == inspector->Inspect( this, testData ) ) + if( SEARCH_QUIT == inspector( this, testData ) ) return SEARCH_QUIT; break; diff --git a/eeschema/lib_collectors.cpp b/eeschema/lib_collectors.cpp index 157c7abc97..60dd95c17a 100644 --- a/eeschema/lib_collectors.cpp +++ b/eeschema/lib_collectors.cpp @@ -92,7 +92,7 @@ const KICAD_T LIB_COLLECTOR::RotatableItems[] = { }; -SEARCH_RESULT LIB_COLLECTOR::Inspect( EDA_ITEM* aItem, const void* aTestData ) +SEARCH_RESULT LIB_COLLECTOR::Inspect( EDA_ITEM* aItem, void* testData ) { LIB_ITEM* item = (LIB_ITEM*) aItem; @@ -125,7 +125,7 @@ void LIB_COLLECTOR::Collect( LIB_ITEMS& aItems, const KICAD_T aFilterList[], for( size_t i = 0; i < aItems.size(); i++ ) { - if( SEARCH_QUIT == aItems[i].Visit( this, NULL, m_ScanTypes ) ) + if( SEARCH_QUIT == aItems[i].Visit( m_inspector, NULL, m_ScanTypes ) ) break; } } diff --git a/eeschema/lib_collectors.h b/eeschema/lib_collectors.h index e1b02a4aac..6f08341e2f 100644 --- a/eeschema/lib_collectors.h +++ b/eeschema/lib_collectors.h @@ -114,7 +114,7 @@ public: * @return SEARCH_RESULT #SEARCH_QUIT if the iterator is to stop the scan, * else #SEARCH_CONTINUE; */ - SEARCH_RESULT Inspect( EDA_ITEM* aItem, const void* aTestData = NULL ); + SEARCH_RESULT Inspect( EDA_ITEM* aItem, void* aTestData ) override; /** * Function Collect diff --git a/eeschema/lib_pin.h b/eeschema/lib_pin.h index 7c0bb4bf32..a40b0f70ae 100644 --- a/eeschema/lib_pin.h +++ b/eeschema/lib_pin.h @@ -93,7 +93,7 @@ class LIB_PIN : public LIB_ITEM const TRANSFORM& aTransform ); public: - LIB_PIN( LIB_PART* aParent ); + LIB_PIN( LIB_PART* aParent ); // Do not create a copy constructor. The one generated by the compiler is adequate. diff --git a/eeschema/sch_collectors.cpp b/eeschema/sch_collectors.cpp index bedfcaa7c9..a467d24b93 100644 --- a/eeschema/sch_collectors.cpp +++ b/eeschema/sch_collectors.cpp @@ -199,7 +199,7 @@ const KICAD_T SCH_COLLECTOR::OrientableItems[] = { }; -SEARCH_RESULT SCH_COLLECTOR::Inspect( EDA_ITEM* aItem, const void* aTestData ) +SEARCH_RESULT SCH_COLLECTOR::Inspect( EDA_ITEM* aItem, void* aTestData ) { if( aItem->Type() != LIB_PIN_T && !aItem->HitTest( m_RefPos ) ) return SEARCH_CONTINUE; @@ -239,7 +239,7 @@ void SCH_COLLECTOR::Collect( SCH_ITEM* aItem, const KICAD_T aFilterList[], // remember where the snapshot was taken from and pass refPos to the Inspect() function. SetRefPos( aPosition ); - EDA_ITEM::IterateForward( aItem, this, NULL, m_ScanTypes ); + EDA_ITEM::IterateForward( aItem, m_inspector, NULL, m_ScanTypes ); } @@ -474,7 +474,7 @@ bool SCH_FIND_COLLECTOR::ReplaceItem( SCH_SHEET_PATH* aSheetPath ) } -SEARCH_RESULT SCH_FIND_COLLECTOR::Inspect( EDA_ITEM* aItem, const void* aTestData ) +SEARCH_RESULT SCH_FIND_COLLECTOR::Inspect( EDA_ITEM* aItem, void* aTestData ) { wxPoint position; @@ -524,7 +524,7 @@ void SCH_FIND_COLLECTOR::Collect( SCH_FIND_REPLACE_DATA& aFindReplaceData, if( aSheetPath ) { m_sheetPath = aSheetPath; - EDA_ITEM::IterateForward( aSheetPath->LastDrawList(), this, NULL, m_ScanTypes ); + EDA_ITEM::IterateForward( aSheetPath->LastDrawList(), m_inspector, NULL, m_ScanTypes ); } else { @@ -533,7 +533,7 @@ void SCH_FIND_COLLECTOR::Collect( SCH_FIND_REPLACE_DATA& aFindReplaceData, for( unsigned i = 0; i < schematic.size(); i++ ) { m_sheetPath = &schematic[i]; - EDA_ITEM::IterateForward( m_sheetPath->LastDrawList(), this, NULL, m_ScanTypes ); + EDA_ITEM::IterateForward( m_sheetPath->LastDrawList(), m_inspector, NULL, m_ScanTypes ); } } @@ -550,7 +550,7 @@ void SCH_FIND_COLLECTOR::Collect( SCH_FIND_REPLACE_DATA& aFindReplaceData, } -SEARCH_RESULT SCH_TYPE_COLLECTOR::Inspect( EDA_ITEM* aItem, const void* aTestData ) +SEARCH_RESULT SCH_TYPE_COLLECTOR::Inspect( EDA_ITEM* aItem, void* testData ) { // The Vist() function only visits the testItem if its type was in the // the scanList, so therefore we can collect anything given to us here. @@ -566,5 +566,5 @@ void SCH_TYPE_COLLECTOR::Collect( SCH_ITEM* aItem, const KICAD_T aFilterList[] ) SetScanTypes( aFilterList ); - EDA_ITEM::IterateForward( aItem, this, NULL, m_ScanTypes ); + EDA_ITEM::IterateForward( aItem, m_inspector, NULL, m_ScanTypes ); } diff --git a/eeschema/sch_collectors.h b/eeschema/sch_collectors.h index 81f19a54bf..3485413cf0 100644 --- a/eeschema/sch_collectors.h +++ b/eeschema/sch_collectors.h @@ -135,7 +135,7 @@ public: return NULL; } - SEARCH_RESULT Inspect( EDA_ITEM* aItem, const void* aTestData = NULL ); + SEARCH_RESULT Inspect( EDA_ITEM* aItem, void* aTestData ) override; /** * Function Collect @@ -350,7 +350,7 @@ public: */ bool ReplaceItem( SCH_SHEET_PATH* aSheetPath = NULL ); - SEARCH_RESULT Inspect( EDA_ITEM* aItem, const void* aTestData = NULL ); + SEARCH_RESULT Inspect( EDA_ITEM* aItem, void* aTestData ) override; /** * Update the replace string without changing anything else. @@ -392,7 +392,7 @@ public: * @return SEARCH_RESULT - SEARCH_QUIT if the Iterator is to stop the scan, * else SCAN_CONTINUE; */ - SEARCH_RESULT Inspect( EDA_ITEM* testItem, const void* testData ); + SEARCH_RESULT Inspect( EDA_ITEM* testItem, void* testData ) override; /** * Function Collect diff --git a/eeschema/sch_component.cpp b/eeschema/sch_component.cpp index d9fc2988a7..097a4991ab 100644 --- a/eeschema/sch_component.cpp +++ b/eeschema/sch_component.cpp @@ -1812,7 +1812,7 @@ wxString SCH_COMPONENT::GetSelectMenuText() const } -SEARCH_RESULT SCH_COMPONENT::Visit( INSPECTOR* aInspector, const void* aTestData, +SEARCH_RESULT SCH_COMPONENT::Visit( INSPECTOR aInspector, void* aTestData, const KICAD_T aFilterTypes[] ) { KICAD_T stype; @@ -1822,7 +1822,7 @@ SEARCH_RESULT SCH_COMPONENT::Visit( INSPECTOR* aInspector, const void* aTestData // If caller wants to inspect component type or and component children types. if( stype == Type() ) { - if( SEARCH_QUIT == aInspector->Inspect( this, aTestData ) ) + if( SEARCH_QUIT == aInspector( this, aTestData ) ) return SEARCH_QUIT; } @@ -1832,23 +1832,23 @@ SEARCH_RESULT SCH_COMPONENT::Visit( INSPECTOR* aInspector, const void* aTestData // Test the bounding boxes of fields if they are visible and not empty. for( int ii = 0; ii < GetFieldCount(); ii++ ) { - if( SEARCH_QUIT == aInspector->Inspect( GetField( ii ), (void*) this ) ) + if( SEARCH_QUIT == aInspector( GetField( ii ), (void*) this ) ) return SEARCH_QUIT; } break; case SCH_FIELD_LOCATE_REFERENCE_T: - if( SEARCH_QUIT == aInspector->Inspect( GetField( REFERENCE ), (void*) this ) ) + if( SEARCH_QUIT == aInspector( GetField( REFERENCE ), (void*) this ) ) return SEARCH_QUIT; break; case SCH_FIELD_LOCATE_VALUE_T: - if( SEARCH_QUIT == aInspector->Inspect( GetField( VALUE ), (void*) this ) ) + if( SEARCH_QUIT == aInspector( GetField( VALUE ), (void*) this ) ) return SEARCH_QUIT; break; case SCH_FIELD_LOCATE_FOOTPRINT_T: - if( SEARCH_QUIT == aInspector->Inspect( GetField( FOOTPRINT ), (void*) this ) ) + if( SEARCH_QUIT == aInspector( GetField( FOOTPRINT ), (void*) this ) ) return SEARCH_QUIT; break; @@ -1862,7 +1862,7 @@ SEARCH_RESULT SCH_COMPONENT::Visit( INSPECTOR* aInspector, const void* aTestData for( size_t i = 0; i < pins.size(); i++ ) { - if( SEARCH_QUIT == aInspector->Inspect( pins[ i ], (void*) this ) ) + if( SEARCH_QUIT == aInspector( pins[ i ], (void*) this ) ) return SEARCH_QUIT; } } diff --git a/eeschema/sch_component.h b/eeschema/sch_component.h index adbd95449b..d2b87ae30d 100644 --- a/eeschema/sch_component.h +++ b/eeschema/sch_component.h @@ -512,8 +512,7 @@ public: void GetConnectionPoints( std::vector& aPoints ) const; - SEARCH_RESULT Visit( INSPECTOR* inspector, const void* testData, - const KICAD_T scanTypes[] ); + SEARCH_RESULT Visit( INSPECTOR inspector, void* testData, const KICAD_T scanTypes[] ) override; /** * Function GetDrawItem(). diff --git a/eeschema/sch_sheet.cpp b/eeschema/sch_sheet.cpp index f360974df2..e437ce4816 100644 --- a/eeschema/sch_sheet.cpp +++ b/eeschema/sch_sheet.cpp @@ -1042,8 +1042,7 @@ void SCH_SHEET::GetConnectionPoints( std::vector< wxPoint >& aPoints ) const } -SEARCH_RESULT SCH_SHEET::Visit( INSPECTOR* aInspector, const void* aTestData, - const KICAD_T aFilterTypes[] ) +SEARCH_RESULT SCH_SHEET::Visit( INSPECTOR aInspector, void* testData, const KICAD_T aFilterTypes[] ) { KICAD_T stype; @@ -1052,7 +1051,7 @@ SEARCH_RESULT SCH_SHEET::Visit( INSPECTOR* aInspector, const void* aTestData, // If caller wants to inspect my type if( stype == Type() ) { - if( SEARCH_QUIT == aInspector->Inspect( this, NULL ) ) + if( SEARCH_QUIT == aInspector( this, NULL ) ) return SEARCH_QUIT; } else if( stype == SCH_SHEET_PIN_T ) @@ -1060,7 +1059,7 @@ SEARCH_RESULT SCH_SHEET::Visit( INSPECTOR* aInspector, const void* aTestData, // Test the sheet labels. for( size_t i = 0; i < m_pins.size(); i++ ) { - if( SEARCH_QUIT == aInspector->Inspect( &m_pins[ i ], (void*) this ) ) + if( SEARCH_QUIT == aInspector( &m_pins[ i ], this ) ) return SEARCH_QUIT; } } diff --git a/eeschema/sch_sheet.h b/eeschema/sch_sheet.h index 7568ff50ee..8ae97fe64a 100644 --- a/eeschema/sch_sheet.h +++ b/eeschema/sch_sheet.h @@ -568,8 +568,7 @@ public: void GetConnectionPoints( std::vector< wxPoint >& aPoints ) const; - SEARCH_RESULT Visit( INSPECTOR* inspector, const void* testData, - const KICAD_T scanTypes[] ); + SEARCH_RESULT Visit( INSPECTOR inspector, void* testData, const KICAD_T scanTypes[] ) override; wxString GetSelectMenuText() const; diff --git a/include/base_struct.h b/include/base_struct.h index e6238f3159..0143567389 100644 --- a/include/base_struct.h +++ b/include/base_struct.h @@ -39,6 +39,7 @@ #include #include #include +#include #if defined(DEBUG) #include // needed for Show() @@ -83,35 +84,25 @@ class MSG_PANEL_ITEM; /** - * Class INSPECTOR - * is an abstract class that is used to inspect and possibly collect the + * Typedef INSPECTOR + * is used to inspect and possibly collect the * (search) results of Iterating over a list or tree of KICAD_T objects. - * Extend from this class and implement the Inspect function and provide for - * a way for the extension to collect the results of the search/scan data and - * provide them to the caller. + * Provide an implementation as needed to inspect EDA_ITEMs visited via + * the EDA_ITEM::Visit() and EDA_ITEM::IterateForward(). + *

+ * The lambda function is used within the EDA_ITEM::Iterate() function. + * It is used primarily for searching, but not limited to that. It can also + * collect or modify the scanned objects. + * + * @param aItem An EDA_ITEM to examine. + * @param aTestData is arbitrary data needed by the inspector to determine + * if the EDA_ITEM under test meets its match criteria. + * @return A #SEARCH_RESULT type #SEARCH_QUIT if the iterator function is to + * stop the scan, else #SEARCH_CONTINUE; */ -class INSPECTOR -{ -public: - virtual ~INSPECTOR() - { - } +typedef std::function< SEARCH_RESULT ( EDA_ITEM* aItem, void* aTestData ) > INSPECTOR_FUNC; - - /** - * Function Inspect - * is the examining function within the INSPECTOR which is passed to the - * EDA_ITEM::Iterate() function. It is used primarily for searching, but - * not limited to that. It can also collect or modify the scanned objects. - * - * @param aItem An EDA_ITEM to examine. - * @param aTestData is arbitrary data needed by the inspector to determine - * if the EDA_ITEM under test meets its match criteria. - * @return A #SEARCH_RESULT type #SEARCH_QUIT if the iterator function is to - * stop the scan, else #SEARCH_CONTINUE; - */ - virtual SEARCH_RESULT Inspect( EDA_ITEM* aItem, const void* aTestData ) = 0; -}; +typedef const INSPECTOR_FUNC& INSPECTOR; /// std::function passed to nested users by ref, avoids copying std::function // These define are used for the .m_Flags and .m_UndoRedoStatus member of the @@ -359,10 +350,10 @@ public: * @return SEARCH_RESULT SEARCH_QUIT if the called INSPECTOR returned * SEARCH_QUIT, else SCAN_CONTINUE; */ - static SEARCH_RESULT IterateForward( EDA_ITEM* listStart, - INSPECTOR* inspector, - const void* testData, - const KICAD_T scanTypes[] ); + static SEARCH_RESULT IterateForward( EDA_ITEM* listStart, + INSPECTOR inspector, + void* testData, + const KICAD_T scanTypes[] ); /** * Function Visit @@ -378,8 +369,7 @@ public: * @return SEARCH_RESULT SEARCH_QUIT if the Iterator is to stop the scan, * else SCAN_CONTINUE, and determined by the inspector. */ - virtual SEARCH_RESULT Visit( INSPECTOR* inspector, const void* testData, - const KICAD_T scanTypes[] ); + virtual SEARCH_RESULT Visit( INSPECTOR inspector, void* testData, const KICAD_T scanTypes[] ); /** * Function GetClass diff --git a/include/class_collector.h b/include/class_collector.h index d14abeb84f..173ca7d24b 100644 --- a/include/class_collector.h +++ b/include/class_collector.h @@ -52,9 +52,11 @@ class EDA_ITEM; * Later, after collection, the user can iterate through all the objects * in the remembered collection using GetCount() and the [int] operator. */ -class COLLECTOR : public INSPECTOR +class COLLECTOR { protected: + INSPECTOR_FUNC m_inspector; + /// Which object types to scan const KICAD_T* m_ScanTypes; @@ -71,7 +73,9 @@ protected: time_t m_TimeAtCollection; public: - COLLECTOR() + COLLECTOR() : + // Inspect() is virtual so calling it from a class common inspector preserves polymorphism. + m_inspector( [=] ( EDA_ITEM* aItem, void* aTestData ) { return Inspect( aItem, aTestData ); } ) { m_ScanTypes = 0; m_TimeAtCollection = 0; @@ -79,6 +83,8 @@ public: virtual ~COLLECTOR() {} + virtual SEARCH_RESULT Inspect( EDA_ITEM* aItem, void* aTestData ) = 0; + /** * Function IsValidIndex * tests if \a aIndex is with the limits of the list of collected items. @@ -276,8 +282,7 @@ public: Empty(); // empty the collection // visit the board with the INSPECTOR (me). - container->Visit( this, // INSPECTOR* inspector - NULL, // const void* testData, + container->Visit( inspector, &aRefPos, m_ScanTypes); SetTimeNow(); // when it was taken } diff --git a/pcbnew/class_board.cpp b/pcbnew/class_board.cpp index fc66e1941c..94157be4ab 100644 --- a/pcbnew/class_board.cpp +++ b/pcbnew/class_board.cpp @@ -146,21 +146,6 @@ void BOARD::SetPosition( const wxPoint& aPos ) void BOARD::Move( const wxPoint& aMoveVector ) // overload { - // Implement 'interface INSPECTOR' which is only INSPECTOR::Inspect(), - // here it does the moving. - struct MOVER : public INSPECTOR - { - SEARCH_RESULT Inspect( EDA_ITEM* item, const void* data ) - { - BOARD_ITEM* brd_item = (BOARD_ITEM*) item; - const wxPoint* vector = (const wxPoint*) data; - - brd_item->Move( *vector ); - - return SEARCH_CONTINUE; - } - } inspector; - // @todo : anything like this elsewhere? maybe put into GENERAL_COLLECTOR class. static const KICAD_T top_level_board_stuff[] = { PCB_MARKER_T, @@ -177,20 +162,25 @@ void BOARD::Move( const wxPoint& aMoveVector ) // overload EOT }; - // visit this BOARD with the above inspector, which moves all items. - Visit( &inspector, &aMoveVector, top_level_board_stuff ); + INSPECTOR_FUNC inspector = [&] ( EDA_ITEM* item, void* testData ) + { + BOARD_ITEM* brd_item = (BOARD_ITEM*) item; + + // aMoveVector was snapshotted, don't need "data". + brd_item->Move( aMoveVector ); + + return SEARCH_CONTINUE; + }; + + Visit( inspector, NULL, top_level_board_stuff ); } -void BOARD::chainMarkedSegments( wxPoint aPosition, const LSET& aLayerMask, TRACK_PTRS* aList ) +void BOARD::chainMarkedSegments( wxPoint aPosition, const LSET& aLayerSet, TRACK_PTRS* aList ) { - TRACK* segment; // The current segment being analyzed. - TRACK* via; // The via identified, eventually destroy - TRACK* candidate; // The end segment to destroy (or NULL = segment) - int NbSegm; - LSET layer_set = aLayerMask; + LSET layer_set = aLayerSet; - if( !m_Track ) + if( !m_Track ) // no tracks at all in board return; /* Set the BUSY flag of all connected segments, first search starting at @@ -218,7 +208,7 @@ void BOARD::chainMarkedSegments( wxPoint aPosition, const LSET& aLayerMask, TRAC * is found we do not know at this time the number of connected items * and we do not know if this via is on the track or finish the track */ - via = m_Track->GetVia( NULL, aPosition, layer_set ); + TRACK* via = m_Track->GetVia( NULL, aPosition, layer_set ); if( via ) { @@ -227,14 +217,15 @@ void BOARD::chainMarkedSegments( wxPoint aPosition, const LSET& aLayerMask, TRAC aList->push_back( via ); } - /* Now we search all segments connected to point aPosition - * if only 1 segment: this segment is candidate + int seg_count = 0; + TRACK* candidate = NULL; + + /* Search all segments connected to point aPosition. + * if only 1 segment at aPosition: then this segment is "candidate" * if > 1 segment: - * end of track (more than 2 segment connected at this location) + * then end of "track" (because more than 2 segments are connected at aPosition) */ - segment = m_Track; - candidate = NULL; - NbSegm = 0; + TRACK* segment = m_Track; while( ( segment = ::GetTrack( segment, NULL, aPosition, layer_set ) ) != NULL ) { @@ -244,20 +235,18 @@ void BOARD::chainMarkedSegments( wxPoint aPosition, const LSET& aLayerMask, TRAC continue; } - if( segment == via ) // just previously found: skip it + if( segment == via ) // just previously found: skip it { segment = segment->Next(); continue; } - NbSegm++; - - if( NbSegm == 1 ) // First time we found a connected item: segment is candidate + if( ++seg_count == 1 ) // if first connected item: then segment is candidate { candidate = segment; segment = segment->Next(); } - else // More than 1 segment connected -> this location is an end of the track + else // More than 1 segment connected -> location is end of track { return; } @@ -502,15 +491,15 @@ LSET BOARD::GetVisibleLayers() const } -void BOARD::SetEnabledLayers( LSET aLayerMask ) +void BOARD::SetEnabledLayers( LSET aLayerSet ) { - m_designSettings.SetEnabledLayers( aLayerMask ); + m_designSettings.SetEnabledLayers( aLayerSet ); } -void BOARD::SetVisibleLayers( LSET aLayerMask ) +void BOARD::SetVisibleLayers( LSET aLayerSet ) { - m_designSettings.SetVisibleLayers( aLayerMask ); + m_designSettings.SetVisibleLayers( aLayerSet ); } @@ -793,7 +782,6 @@ BOARD_ITEM* BOARD::Remove( BOARD_ITEM* aBoardItem ) break; } } - break; case PCB_MODULE_T: @@ -990,8 +978,7 @@ void BOARD::GetMsgPanelInfo( std::vector< MSG_PANEL_ITEM >& aList ) // virtual, see pcbstruct.h -SEARCH_RESULT BOARD::Visit( INSPECTOR* inspector, const void* testData, - const KICAD_T scanTypes[] ) +SEARCH_RESULT BOARD::Visit( INSPECTOR inspector, void* testData, const KICAD_T scanTypes[] ) { KICAD_T stype; SEARCH_RESULT result = SEARCH_CONTINUE; @@ -1009,7 +996,7 @@ SEARCH_RESULT BOARD::Visit( INSPECTOR* inspector, const void* testData, switch( stype ) { case PCB_T: - result = inspector->Inspect( this, testData ); // inspect me + result = inspector( this, testData ); // inspect me // skip over any types handled in the above call. ++p; break; @@ -1173,86 +1160,6 @@ SEARCH_RESULT BOARD::Visit( INSPECTOR* inspector, const void* testData, } -/* now using PcbGeneralLocateAndDisplay(), but this remains a useful example - * of how the INSPECTOR can be used in a lightweight way. - * // see pcbstruct.h - * BOARD_ITEM* BOARD::FindPadOrModule( const wxPoint& refPos, LAYER_NUM layer ) - * { - * class PadOrModule : public INSPECTOR - * { - * public: - * BOARD_ITEM* found; - * LAYER_NUM layer; - * int layer_mask; - * - * PadOrModule( LAYER_NUM alayer ) : - * found(0), layer(alayer), layer_mask( g_TabOneLayerMask[alayer] ) - * {} - * - * SEARCH_RESULT Inspect( EDA_ITEM* testItem, const void* testData - * ) - * { - * BOARD_ITEM* item = (BOARD_ITEM*) testItem; - * const wxPoint& refPos = *(const wxPoint*) testData; - * - * if( item->Type() == PCB_PAD_T ) - * { - * D_PAD* pad = (D_PAD*) item; - * if( pad->HitTest( refPos ) ) - * { - * if( layer_mask & pad->GetLayerSet() ) - * { - * found = item; - * return SEARCH_QUIT; - * } - * else if( !found ) - * { - * MODULE* parent = (MODULE*) pad->m_Parent; - * if( IsModuleLayerVisible( parent->GetLayer() ) ) - * found = item; - * } - * } - * } - * - * else if( item->Type() == PCB_MODULE_T ) - * { - * MODULE* module = (MODULE*) item; - * - * // consider only visible modules - * if( IsModuleLayerVisible( module->GetLayer() ) ) - * { - * if( module->HitTest( refPos ) ) - * { - * if( layer == module->GetLayer() ) - * { - * found = item; - * return SEARCH_QUIT; - * } - * - * // layer mismatch, save in case we don't find a - * // future layer match hit. - * if( !found ) - * found = item; - * } - * } - * } - * return SEARCH_CONTINUE; - * } - * }; - * - * PadOrModule inspector( layer ); - * - * // search only for PADs first, then MODULES, and preferably a layer match - * static const KICAD_T scanTypes[] = { PCB_PAD_T, PCB_MODULE_T, EOT }; - * - * // visit this BOARD with the above inspector - * Visit( &inspector, &refPos, scanTypes ); - * - * return inspector.found; - * } - */ - - NETINFO_ITEM* BOARD::FindNet( int aNetcode ) const { // the first valid netcode is 1 and the last is m_NetInfo.GetCount()-1. @@ -1276,36 +1183,29 @@ NETINFO_ITEM* BOARD::FindNet( const wxString& aNetname ) const MODULE* BOARD::FindModuleByReference( const wxString& aReference ) const { - struct FINDER : public INSPECTOR - { - MODULE* found; - - FINDER() : found( 0 ) {} - - // implement interface INSPECTOR - SEARCH_RESULT Inspect( EDA_ITEM* item, const void* data ) - { - MODULE* module = (MODULE*) item; - const wxString& ref = *(const wxString*) data; - - if( ref == module->GetReference() ) - { - found = module; - return SEARCH_QUIT; - } - - return SEARCH_CONTINUE; - } - } inspector; + MODULE* found = nullptr; // search only for MODULES static const KICAD_T scanTypes[] = { PCB_MODULE_T, EOT }; + INSPECTOR_FUNC inspector = [&] ( EDA_ITEM* item, void* testData ) + { + MODULE* module = (MODULE*) item; + + if( aReference == module->GetReference() ) + { + found = module; + return SEARCH_QUIT; + } + + return SEARCH_CONTINUE; + }; + // visit this BOARD with the above inspector BOARD* nonconstMe = (BOARD*) this; - nonconstMe->Visit( &inspector, &aReference, scanTypes ); + nonconstMe->Visit( inspector, NULL, scanTypes ); - return inspector.found; + return found; } @@ -1321,17 +1221,7 @@ MODULE* BOARD::FindModule( const wxString& aRefOrTimeStamp, bool aSearchByTimeSt } else { - -#if 0 // case independent compare, why? - for( MODULE* module = m_Modules; module; module = module->Next() ) - { - if( aRefOrTimeStamp.CmpNoCase( module->GetReference() ) == 0 ) - return module; - } -#else return FindModuleByReference( aRefOrTimeStamp ); -#endif - } return NULL; @@ -1495,14 +1385,14 @@ VIA* BOARD::GetViaByPosition( const wxPoint& aPosition, LAYER_ID aLayer) const } -D_PAD* BOARD::GetPad( const wxPoint& aPosition, LSET aLayerMask ) +D_PAD* BOARD::GetPad( const wxPoint& aPosition, LSET aLayerSet ) { - if( !aLayerMask.any() ) - aLayerMask = LSET::AllCuMask(); + if( !aLayerSet.any() ) + aLayerSet = LSET::AllCuMask(); for( MODULE* module = m_Modules; module; module = module->Next() ) { - D_PAD* pad = module->GetPad( aPosition, aLayerMask ); + D_PAD* pad = module->GetPad( aPosition, aLayerSet ); if( pad ) return pad; @@ -1516,11 +1406,11 @@ D_PAD* BOARD::GetPad( TRACK* aTrace, ENDPOINT_T aEndPoint ) { const wxPoint& aPosition = aTrace->GetEndPoint( aEndPoint ); - LSET aLayerMask( aTrace->GetLayer() ); + LSET lset( aTrace->GetLayer() ); for( MODULE* module = m_Modules; module; module = module->Next() ) { - D_PAD* pad = module->GetPad( aPosition, aLayerMask ); + D_PAD* pad = module->GetPad( aPosition, lset ); if( pad ) return pad; @@ -1530,7 +1420,7 @@ D_PAD* BOARD::GetPad( TRACK* aTrace, ENDPOINT_T aEndPoint ) } -D_PAD* BOARD::GetPadFast( const wxPoint& aPosition, LSET aLayerMask ) +D_PAD* BOARD::GetPadFast( const wxPoint& aPosition, LSET aLayerSet ) { for( unsigned i=0; iGetLayerSet() & aLayerMask ).any() ) + if( ( pad->GetLayerSet() & aLayerSet ).any() ) return pad; } @@ -1548,9 +1438,9 @@ D_PAD* BOARD::GetPadFast( const wxPoint& aPosition, LSET aLayerMask ) } -D_PAD* BOARD::GetPad( std::vector& aPadList, const wxPoint& aPosition, LSET aLayerMask ) +D_PAD* BOARD::GetPad( std::vector& aPadList, const wxPoint& aPosition, LSET aLayerSet ) { - // Search the aPoint coordinates in aPadList + // Search aPadList for aPosition // aPadList is sorted by X then Y values, and a fast binary search is used int idxmax = aPadList.size()-1; @@ -1572,7 +1462,7 @@ D_PAD* BOARD::GetPad( std::vector& aPadList, const wxPoint& aPosition, L if( pad->GetPosition() == aPosition ) // candidate found { // The pad must match the layer mask: - if( ( aLayerMask & pad->GetLayerSet() ).any() ) + if( ( aLayerSet & pad->GetLayerSet() ).any() ) return pad; // More than one pad can be at aPosition @@ -1586,7 +1476,7 @@ D_PAD* BOARD::GetPad( std::vector& aPadList, const wxPoint& aPosition, L if( pad->GetPosition() != aPosition ) break; - if( (aLayerMask & pad->GetLayerSet()) != 0 ) + if( ( aLayerSet & pad->GetLayerSet() ).any() ) return pad; } // search previous @@ -1597,7 +1487,7 @@ D_PAD* BOARD::GetPad( std::vector& aPadList, const wxPoint& aPosition, L if( pad->GetPosition() != aPosition ) break; - if( (aLayerMask & pad->GetLayerSet()) != 0 ) + if( ( aLayerSet & pad->GetLayerSet() ).any() ) return pad; } @@ -1605,9 +1495,9 @@ D_PAD* BOARD::GetPad( std::vector& aPadList, const wxPoint& aPosition, L return 0; } - if( pad->GetPosition().x == aPosition.x ) // Must search considering Y coordinate + if( pad->GetPosition().x == aPosition.x ) // Must search considering Y coordinate { - if(pad->GetPosition().y < aPosition.y) // Must search after this item + if( pad->GetPosition().y < aPosition.y ) // Must search after this item { idx += delta; @@ -1684,16 +1574,17 @@ void BOARD::PadDelete( D_PAD* aPad ) } -TRACK* BOARD::GetTrack( TRACK* aTrace, const wxPoint& aPosition, - LSET aLayerMask ) const +TRACK* BOARD::GetVisibleTrack( TRACK* aStartingTrace, const wxPoint& aPosition, + LSET aLayerSet ) const { - for( TRACK* track = aTrace; track; track = track->Next() ) + for( TRACK* track = aStartingTrace; track; track = track->Next() ) { LAYER_ID layer = track->GetLayer(); if( track->GetState( BUSY | IS_DELETED ) ) continue; + // track's layer is not visible if( m_designSettings.IsLayerVisible( layer ) == false ) continue; @@ -1704,8 +1595,8 @@ TRACK* BOARD::GetTrack( TRACK* aTrace, const wxPoint& aPosition, } else { - if( !aLayerMask[layer] ) - continue; // Segments on different layers. + if( !aLayerSet[layer] ) + continue; // track's layer is not in aLayerSet if( track->HitTest( aPosition ) ) return track; @@ -1737,11 +1628,12 @@ static void dump_tracks( const char* aName, const TRACK_PTRS& aList ) #endif + + TRACK* BOARD::MarkTrace( TRACK* aTrace, int* aCount, double* aTraceLength, double* aPadToDieLength, bool aReorder ) { - int NbSegmBusy; TRACK_PTRS trackList; if( aCount ) @@ -1894,15 +1786,15 @@ TRACK* BOARD::MarkTrace( TRACK* aTrace, int* aCount, * the NbSegmBusy-1 next items (NbSegmBusy when including firstTrack) * are the flagged segments */ - NbSegmBusy = 0; - TRACK* firstTrack; + int busy_count = 0; + TRACK* firstTrack; for( firstTrack = m_Track; firstTrack; firstTrack = firstTrack->Next() ) { // Search for the first flagged BUSY segments if( firstTrack->GetState( BUSY ) ) { - NbSegmBusy = 1; + busy_count = 1; break; } } @@ -1919,7 +1811,7 @@ TRACK* BOARD::MarkTrace( TRACK* aTrace, int* aCount, wxASSERT( list ); /* Rearrange the chain starting at firstTrack - * All others flagged items are moved from their position to the end + * All other BUSY flagged items are moved from their position to the end * of the flagged list */ TRACK* next; @@ -1930,7 +1822,7 @@ TRACK* BOARD::MarkTrace( TRACK* aTrace, int* aCount, if( track->GetState( BUSY ) ) // move it! { - NbSegmBusy++; + busy_count++; track->UnLink(); list->Insert( track, firstTrack->Next() ); @@ -1943,13 +1835,13 @@ TRACK* BOARD::MarkTrace( TRACK* aTrace, int* aCount, // that are on each end of the track, if any if( track->GetState( BEGIN_ONPAD ) ) { - D_PAD * pad = (D_PAD *) track->start; + D_PAD* pad = (D_PAD *) track->start; lenPadToDie += (double) pad->GetPadToDieLength(); } if( track->GetState( END_ONPAD ) ) { - D_PAD * pad = (D_PAD *) track->end; + D_PAD* pad = (D_PAD *) track->end; lenPadToDie += (double) pad->GetPadToDieLength(); } } @@ -1958,13 +1850,13 @@ TRACK* BOARD::MarkTrace( TRACK* aTrace, int* aCount, } else if( aTraceLength ) { - NbSegmBusy = 0; + busy_count = 0; for( TRACK* track = firstTrack; track; track = track->Next() ) { if( track->GetState( BUSY ) ) { - NbSegmBusy++; + busy_count++; track->SetState( BUSY, false ); full_len += track->GetLength(); @@ -1973,19 +1865,19 @@ TRACK* BOARD::MarkTrace( TRACK* aTrace, int* aCount, // that are on each end of the track, if any if( track->GetState( BEGIN_ONPAD ) ) { - D_PAD * pad = (D_PAD *) track->start; + D_PAD* pad = (D_PAD *) track->start; lenPadToDie += (double) pad->GetPadToDieLength(); } if( track->GetState( END_ONPAD ) ) { - D_PAD * pad = (D_PAD *) track->end; + D_PAD* pad = (D_PAD *) track->end; lenPadToDie += (double) pad->GetPadToDieLength(); } } } - DBG( printf( "%s: NbSegmBusy:%d\n", __func__, NbSegmBusy ); ) + DBG( printf( "%s: busy_count:%d\n", __func__, busy_count ); ) } if( aTraceLength ) @@ -1995,7 +1887,7 @@ TRACK* BOARD::MarkTrace( TRACK* aTrace, int* aCount, *aPadToDieLength = lenPadToDie; if( aCount ) - *aCount = NbSegmBusy; + *aCount = busy_count; return firstTrack; } @@ -2070,21 +1962,21 @@ MODULE* BOARD::GetFootprint( const wxPoint& aPosition, LAYER_ID aActiveLayer, } -BOARD_CONNECTED_ITEM* BOARD::GetLockPoint( const wxPoint& aPosition, LSET aLayerMask ) +BOARD_CONNECTED_ITEM* BOARD::GetLockPoint( const wxPoint& aPosition, LSET aLayerSet ) { for( MODULE* module = m_Modules; module; module = module->Next() ) { - D_PAD* pad = module->GetPad( aPosition, aLayerMask ); + D_PAD* pad = module->GetPad( aPosition, aLayerSet ); if( pad ) return pad; } // No pad has been located so check for a segment of the trace. - TRACK* segment = ::GetTrack( m_Track, NULL, aPosition, aLayerMask ); + TRACK* segment = ::GetTrack( m_Track, NULL, aPosition, aLayerSet ); - if( segment == NULL ) - segment = GetTrack( m_Track, aPosition, aLayerMask ); + if( !segment ) + segment = GetVisibleTrack( m_Track, aPosition, aLayerSet ); return segment; } diff --git a/pcbnew/class_board.h b/pcbnew/class_board.h index 5e3e5ed418..4e4c97c688 100644 --- a/pcbnew/class_board.h +++ b/pcbnew/class_board.h @@ -909,8 +909,7 @@ public: * @return SEARCH_RESULT - SEARCH_QUIT if the Iterator is to stop the scan, * else SCAN_CONTINUE, and determined by the inspector. */ - SEARCH_RESULT Visit( INSPECTOR* inspector, const void* testData, - const KICAD_T scanTypes[] ); + SEARCH_RESULT Visit( INSPECTOR inspector, void* testData, const KICAD_T scanTypes[] ) override; /** * Function FindModuleByReference @@ -1300,17 +1299,19 @@ public: void GetSortedPadListByXthenYCoord( std::vector& aVector, int aNetCode = -1 ); /** - * Function GetTrack - * find the segment of \a aTrace at \a aPosition on \a aLayer if \a Layer is visible. + * Function GetVisibleTrack + * finds the neighboring visible segment of \a aTrace at \a aPosition that is + * on a layer in \a aLayerSet. * Traces that are flagged as deleted or busy are ignored. * - * @param aTrace A pointer to the TRACK object to search. + * @param aStartingTrace is the first TRACK to test, testing continues to end of m_Track list from + * this starting point. * @param aPosition A wxPoint object containing the position to test. - * @param aLayerMask A layer or layers to mask the hit test. Use -1 to ignore - * layer mask. + * @param aLayerSet A set of layers; returned TRACK must be on one of these. + * May pass a full set to request any layer. * @return A TRACK object pointer if found otherwise NULL. */ - TRACK* GetTrack( TRACK* aTrace, const wxPoint& aPosition, LSET aLayerMask ) const; + TRACK* GetVisibleTrack( TRACK* aStartingTrace, const wxPoint& aPosition, LSET aLayerSet ) const; /** * Function MarkTrace diff --git a/pcbnew/class_module.cpp b/pcbnew/class_module.cpp index 21d25b1d0c..456aa0086c 100644 --- a/pcbnew/class_module.cpp +++ b/pcbnew/class_module.cpp @@ -761,8 +761,7 @@ void MODULE::Add3DModel( S3D_MASTER* a3DModel ) // see class_module.h -SEARCH_RESULT MODULE::Visit( INSPECTOR* inspector, const void* testData, - const KICAD_T scanTypes[] ) +SEARCH_RESULT MODULE::Visit( INSPECTOR inspector, void* testData, const KICAD_T scanTypes[] ) { KICAD_T stype; SEARCH_RESULT result = SEARCH_CONTINUE; @@ -780,7 +779,7 @@ SEARCH_RESULT MODULE::Visit( INSPECTOR* inspector, const void* testData, switch( stype ) { case PCB_MODULE_T: - result = inspector->Inspect( this, testData ); // inspect me + result = inspector( this, testData ); // inspect me ++p; break; @@ -790,12 +789,12 @@ SEARCH_RESULT MODULE::Visit( INSPECTOR* inspector, const void* testData, break; case PCB_MODULE_TEXT_T: - result = inspector->Inspect( m_Reference, testData ); + result = inspector( m_Reference, testData ); if( result == SEARCH_QUIT ) break; - result = inspector->Inspect( m_Value, testData ); + result = inspector( m_Value, testData ); if( result == SEARCH_QUIT ) break; diff --git a/pcbnew/class_module.h b/pcbnew/class_module.h index 1af049248a..255af845fc 100644 --- a/pcbnew/class_module.h +++ b/pcbnew/class_module.h @@ -531,8 +531,7 @@ public: */ void Add3DModel( S3D_MASTER* a3DModel ); - SEARCH_RESULT Visit( INSPECTOR* inspector, const void* testData, - const KICAD_T scanTypes[] ); + SEARCH_RESULT Visit( INSPECTOR inspector, void* testData, const KICAD_T scanTypes[] ) override; wxString GetClass() const { diff --git a/pcbnew/class_track.cpp b/pcbnew/class_track.cpp index 9e0654cd5a..a85c4cfb14 100644 --- a/pcbnew/class_track.cpp +++ b/pcbnew/class_track.cpp @@ -68,24 +68,24 @@ static bool ShowClearance( DISPLAY_OPTIONS* aDisplOpts, const TRACK* aTrack ) TRACK* GetTrack( TRACK* aStartTrace, const TRACK* aEndTrace, const wxPoint& aPosition, LSET aLayerMask ) { - for( TRACK *PtSegm = aStartTrace; PtSegm != NULL; PtSegm = PtSegm->Next() ) + for( TRACK* seg = aStartTrace; seg; seg = seg->Next() ) { - if( PtSegm->GetState( IS_DELETED | BUSY ) == 0 ) + if( seg->GetState( IS_DELETED | BUSY ) == 0 ) { - if( aPosition == PtSegm->GetStart() ) + if( aPosition == seg->GetStart() ) { - if( ( aLayerMask & PtSegm->GetLayerSet() ).any() ) - return PtSegm; + if( ( aLayerMask & seg->GetLayerSet() ).any() ) + return seg; } - if( aPosition == PtSegm->GetEnd() ) + if( aPosition == seg->GetEnd() ) { - if( ( aLayerMask & PtSegm->GetLayerSet() ).any() ) - return PtSegm; + if( ( aLayerMask & seg->GetLayerSet() ).any() ) + return seg; } } - if( PtSegm == aEndTrace ) + if( seg == aEndTrace ) break; } @@ -363,15 +363,14 @@ void VIA::Flip( const wxPoint& aCentre ) // see class_track.h -SEARCH_RESULT TRACK::Visit( INSPECTOR* inspector, const void* testData, - const KICAD_T scanTypes[] ) +SEARCH_RESULT TRACK::Visit( INSPECTOR inspector, void* testData, const KICAD_T scanTypes[] ) { KICAD_T stype = *scanTypes; // If caller wants to inspect my type if( stype == Type() ) { - if( SEARCH_QUIT == inspector->Inspect( this, testData ) ) + if( SEARCH_QUIT == inspector( this, testData ) ) return SEARCH_QUIT; } @@ -1365,7 +1364,7 @@ TRACK* TRACK::GetTrack( TRACK* aStartTrace, TRACK* aEndTrace, ENDPOINT_T aEndPoi while( nextSegment || previousSegment ) { - // Terminate the search in the direction if the netcode mismatches + // Terminate the search in the direction if the netcode mis-matches if( aSameNetOnly ) { if( nextSegment && (nextSegment->GetNetCode() != GetNetCode()) ) diff --git a/pcbnew/class_track.h b/pcbnew/class_track.h index be8c36352b..7316ecbbbe 100644 --- a/pcbnew/class_track.h +++ b/pcbnew/class_track.h @@ -215,9 +215,7 @@ public: */ wxString ShowWidth() const; - SEARCH_RESULT Visit( INSPECTOR* inspector, const void* testData, - const KICAD_T scanTypes[] ); - + SEARCH_RESULT Visit( INSPECTOR inspector, void* testData, const KICAD_T scanTypes[] ) override; virtual bool HitTest( const wxPoint& aPosition ) const; @@ -250,7 +248,7 @@ public: /** * Function GetTrack - * return the trace segment connected to the segment at \a aEndPoint from \a + * returns the trace segment connected to the segment at \a aEndPoint from \a * aStartTrace to \a aEndTrace. * * @param aStartTrace A pointer to the TRACK object to begin searching. diff --git a/pcbnew/collectors.cpp b/pcbnew/collectors.cpp index f58d4a3d02..5768b4ca5d 100644 --- a/pcbnew/collectors.cpp +++ b/pcbnew/collectors.cpp @@ -148,11 +148,11 @@ const KICAD_T GENERAL_COLLECTOR::Zones[] = { * that it finds and does not do any displaying. * * @param testItem An EDA_ITEM to examine. - * @param testData The const void* testData, not used here. + * @param testData not used here. * @return SEARCH_RESULT - SEARCH_QUIT if the Iterator is to stop the scan, * else SCAN_CONTINUE; */ -SEARCH_RESULT GENERAL_COLLECTOR::Inspect( EDA_ITEM* testItem, const void* testData ) +SEARCH_RESULT GENERAL_COLLECTOR::Inspect( EDA_ITEM* testItem, void* testData ) { BOARD_ITEM* item = (BOARD_ITEM*) testItem; MODULE* module = NULL; @@ -459,10 +459,7 @@ void GENERAL_COLLECTOR::Collect( BOARD_ITEM* aItem, const KICAD_T aScanList[], // the Inspect() function. SetRefPos( aRefPos ); - // visit the board or module with the INSPECTOR (me). - aItem->Visit( this, // INSPECTOR* inspector - NULL, // const void* testData, not used here - m_ScanTypes ); + aItem->Visit( m_inspector, NULL, m_ScanTypes ); SetTimeNow(); // when snapshot was taken @@ -478,7 +475,7 @@ void GENERAL_COLLECTOR::Collect( BOARD_ITEM* aItem, const KICAD_T aScanList[], // see collectors.h -SEARCH_RESULT PCB_TYPE_COLLECTOR::Inspect( EDA_ITEM* testItem, const void* testData ) +SEARCH_RESULT PCB_TYPE_COLLECTOR::Inspect( EDA_ITEM* testItem, void* testData ) { // The Vist() function only visits the testItem if its type was in the // the scanList, so therefore we can collect anything given to us here. @@ -492,10 +489,5 @@ void PCB_TYPE_COLLECTOR::Collect( BOARD_ITEM* aBoard, const KICAD_T aScanList[] { Empty(); // empty any existing collection - // visit the board with the INSPECTOR (me). - aBoard->Visit( this, // INSPECTOR* inspector - NULL, // const void* testData, - aScanList ); + aBoard->Visit( m_inspector, NULL, aScanList ); } - -//EOF diff --git a/pcbnew/collectors.h b/pcbnew/collectors.h index b2d5c9dc0a..88225584d5 100644 --- a/pcbnew/collectors.h +++ b/pcbnew/collectors.h @@ -337,14 +337,12 @@ public: return NULL; } - /** * Function GetPrimaryCount * @return int - The number if items which met the primary search criteria */ int GetPrimaryCount() { return m_PrimaryLength; } - /** * Function Inspect * is the examining function within the INSPECTOR which is passed to the @@ -355,8 +353,7 @@ public: * @return SEARCH_RESULT - SEARCH_QUIT if the Iterator is to stop the scan, * else SCAN_CONTINUE; */ - SEARCH_RESULT Inspect( EDA_ITEM* testItem, const void* testData ); - + SEARCH_RESULT Inspect( EDA_ITEM* testItem, void* testData ) override; /** * Function Collect @@ -595,7 +592,6 @@ public: */ class PCB_TYPE_COLLECTOR : public COLLECTOR { - public: /** @@ -612,7 +608,6 @@ public: return NULL; } - /** * Function Inspect * is the examining function within the INSPECTOR which is passed to the @@ -623,8 +618,7 @@ public: * @return SEARCH_RESULT - SEARCH_QUIT if the Iterator is to stop the scan, * else SCAN_CONTINUE; */ - SEARCH_RESULT Inspect( EDA_ITEM* testItem, const void* testData ); - + SEARCH_RESULT Inspect( EDA_ITEM* testItem, void* testData ) override; /** * Function Collect diff --git a/pcbnew/connect.h b/pcbnew/connect.h index 46868c878c..13c7f92ff8 100644 --- a/pcbnew/connect.h +++ b/pcbnew/connect.h @@ -69,7 +69,7 @@ public: * @return the parent track or via of this connected point, * or null if the parent is a pad */ - TRACK * GetTrack() const + TRACK* GetTrack() const { return m_item->Type() != PCB_PAD_T ? (TRACK*) m_item : NULL ; } diff --git a/pcbnew/magnetic_tracks_functions.cpp b/pcbnew/magnetic_tracks_functions.cpp index f124e9b083..2ffea624fd 100644 --- a/pcbnew/magnetic_tracks_functions.cpp +++ b/pcbnew/magnetic_tracks_functions.cpp @@ -214,9 +214,9 @@ bool Magnetize( PCB_EDIT_FRAME* frame, int aCurrentTool, wxSize aGridSize, if( !currTrack ) { - LSET layer_mask( layer ); + LSET layers( layer ); - TRACK* track = m_Pcb->GetTrack( m_Pcb->m_Track, pos, layer_mask ); + TRACK* track = m_Pcb->GetVisibleTrack( m_Pcb->m_Track, pos, layers ); if( !track || track->Type() != PCB_TRACE_T ) {