Cleanup some dead code and make better use of iterators.

Also applies coding style around auto and lambdas.
This commit is contained in:
Jeff Young 2020-08-27 00:52:12 +01:00
parent 8b7c0cbe04
commit 9e12ea9bb6
18 changed files with 187 additions and 429 deletions

View File

@ -646,10 +646,8 @@ void BOARD_ADAPTER::createLayers( REPORTER* aStatusReporter )
std::vector<std::pair<const ZONE_CONTAINER*, PCB_LAYER_ID>> zones;
for( int i = 0; i < m_board->GetAreaCount(); i++ )
for( ZONE_CONTAINER* zone : m_board->Zones() )
{
const ZONE_CONTAINER* zone = m_board->GetArea( i );
for( PCB_LAYER_ID layer : zone->GetLayerSet().Seq() )
zones.emplace_back( std::make_pair( zone, layer ) );
}
@ -938,23 +936,15 @@ void BOARD_ADAPTER::createLayers( REPORTER* aStatusReporter )
// Draw non copper zones
if( GetFlag( FL_ZONE ) )
{
for( int ii = 0; ii < m_board->GetAreaCount(); ++ii )
for( ZONE_CONTAINER* zone : m_board->Zones() )
{
ZONE_CONTAINER* zone = m_board->GetArea( ii );
if( !zone->IsOnLayer( curr_layer_id ) )
continue;
if( zone->IsOnLayer( curr_layer_id ) )
AddSolidAreasShapesToContainer( zone, layerContainer, curr_layer_id );
}
for( int ii = 0; ii < m_board->GetAreaCount(); ++ii )
for( ZONE_CONTAINER* zone : m_board->Zones() )
{
ZONE_CONTAINER* zone = m_board->GetArea( ii );
if( !zone->IsOnLayer( curr_layer_id ) )
continue;
if( zone->IsOnLayer( curr_layer_id ) )
zone->TransformSolidAreasShapesToPolygon( curr_layer_id, *layerPoly );
}
}

View File

@ -24,11 +24,8 @@
*/
#include <fctsys.h>
#include <pcbnew.h>
#include <class_board.h>
#include <class_board_item.h>
#include <connectivity/connectivity_data.h>
using namespace std::placeholders;
@ -50,11 +47,6 @@ bool BOARD_CONNECTED_ITEM::SetNetCode( int aNetCode, bool aNoAssert )
// set the m_netinfo to the dummy NETINFO_LIST::ORPHANED
BOARD* board = GetBoard();
//auto connectivity = board ? board->GetConnectivity() : nullptr;
//bool addRatsnest = false;
//if( connectivity )
//addRatsnest = connectivity->Remove( this );
if( ( aNetCode >= 0 ) && board )
m_netinfo = board->FindNet( aNetCode );
@ -64,10 +56,6 @@ bool BOARD_CONNECTED_ITEM::SetNetCode( int aNetCode, bool aNoAssert )
if( !aNoAssert )
wxASSERT( m_netinfo );
// Add only if it was previously added to the ratsnest
//if( addRatsnest )
// connectivity->Add( this );
return ( m_netinfo != NULL );
}

View File

@ -86,10 +86,8 @@ void BOARD::ConvertBrdLayerToPolygonalContours( PCB_LAYER_ID aLayer, SHAPE_POLY_
}
// convert copper zones
for( int ii = 0; ii < GetAreaCount(); ii++ )
for( ZONE_CONTAINER* zone : Zones() )
{
ZONE_CONTAINER* zone = GetArea( ii );
if( zone->GetLayerSet().test( aLayer ) )
zone->TransformSolidAreasShapesToPolygon( aLayer, aOutlines );
}

View File

@ -102,30 +102,25 @@ BOARD::BOARD() :
BOARD::~BOARD()
{
while( m_ZoneDescriptorList.size() )
{
ZONE_CONTAINER* area_to_remove = m_ZoneDescriptorList[0];
Delete( area_to_remove );
}
// Clean up the owned elements
DeleteMARKERs();
DeleteZONEOutlines();
// Delete the modules
for( auto m : m_modules )
for( ZONE_CONTAINER* zone : m_zones )
delete zone;
m_zones.clear();
for( MODULE* m : m_modules )
delete m;
m_modules.clear();
// Delete the tracks
for( auto t : m_tracks )
for( TRACK* t : m_tracks )
delete t;
m_tracks.clear();
// Delete the drawings
for (auto d : m_drawings )
for ( BOARD_ITEM* d : m_drawings )
delete d;
m_drawings.clear();
@ -246,7 +241,7 @@ TRACKS BOARD::TracksInNet( int aNetCode )
{
TRACKS ret;
INSPECTOR_FUNC inspector = [aNetCode,&ret] ( EDA_ITEM* item, void* testData )
INSPECTOR_FUNC inspector = [aNetCode, &ret]( EDA_ITEM* item, void* testData )
{
TRACK* t = (TRACK*) item;
@ -283,19 +278,15 @@ const PCB_LAYER_ID BOARD::GetLayerID( const wxString& aLayerName ) const
for( LAYER_NUM layer = 0; layer < PCB_LAYER_ID_COUNT; ++layer )
{
if ( IsCopperLayer( layer ) && ( m_Layer[ layer ].m_name == aLayerName ) )
{
return ToLAYER_ID( layer );
}
}
// Otherwise fall back to the system standard layer names
for( LAYER_NUM layer = 0; layer < PCB_LAYER_ID_COUNT; ++layer )
{
if( GetStandardLayerName( ToLAYER_ID( layer ) ) == aLayerName )
{
return ToLAYER_ID( layer );
}
}
return UNDEFINED_LAYER;
}
@ -376,29 +367,14 @@ bool BOARD::SetLayerType( PCB_LAYER_ID aLayer, LAYER_T aLayerType )
const char* LAYER::ShowType( LAYER_T aType )
{
const char* cp;
switch( aType )
{
default:
case LT_SIGNAL:
cp = "signal";
break;
case LT_POWER:
cp = "power";
break;
case LT_MIXED:
cp = "mixed";
break;
case LT_JUMPER:
cp = "jumper";
break;
case LT_SIGNAL: return "signal";
case LT_POWER: return "power";
case LT_MIXED: return "mixed";
case LT_JUMPER: return "jumper";
}
return cp;
}
@ -507,20 +483,17 @@ void BOARD::SetElementVisibility( GAL_LAYER_ID aLayer, bool isEnabled )
// because we have a tool to show/hide ratsnest relative to a pad or a module
// so the hide/show option is a per item selection
for( auto track : Tracks() )
for( TRACK* track : Tracks() )
track->SetLocalRatsnestVisible( isEnabled );
for( auto mod : Modules() )
for( MODULE* mod : Modules() )
{
for( auto pad : mod->Pads() )
for( D_PAD* pad : mod->Pads() )
pad->SetLocalRatsnestVisible( isEnabled );
}
for( int i = 0; i<GetAreaCount(); i++ )
{
auto zone = GetArea( i );
for( ZONE_CONTAINER* zone : Zones() )
zone->SetLocalRatsnestVisible( isEnabled );
}
break;
}
@ -574,7 +547,7 @@ void BOARD::Add( BOARD_ITEM* aBoardItem, ADD_MODE aMode )
// this one uses a vector
case PCB_ZONE_AREA_T:
m_ZoneDescriptorList.push_back( (ZONE_CONTAINER*) aBoardItem );
m_zones.push_back( (ZONE_CONTAINER*) aBoardItem );
break;
case PCB_TRACE_T:
@ -649,35 +622,27 @@ void BOARD::Remove( BOARD_ITEM* aBoardItem )
}
case PCB_MARKER_T:
// find the item in the vector, then remove it
for( unsigned i = 0; i<m_markers.size(); ++i )
m_markers.erase( std::remove_if( m_markers.begin(), m_markers.end(),
[aBoardItem]( BOARD_ITEM* aItem )
{
if( m_markers[i] == (MARKER_PCB*) aBoardItem )
{
m_markers.erase( m_markers.begin() + i );
break;
}
}
return aItem == aBoardItem;
} ) );
break;
case PCB_GROUP_T:
m_groups.erase( std::remove_if( m_groups.begin(), m_groups.end(),
[aBoardItem]( BOARD_ITEM* aItem ){ return aItem == aBoardItem; } ) );
[aBoardItem]( BOARD_ITEM* aItem )
{
return aItem == aBoardItem;
} ) );
break;
case PCB_ZONE_AREA_T: // this one uses a vector
// find the item in the vector, then delete then erase it.
for( unsigned i = 0; i<m_ZoneDescriptorList.size(); ++i )
case PCB_ZONE_AREA_T:
m_zones.erase( std::remove_if( m_zones.begin(), m_zones.end(),
[aBoardItem]( BOARD_ITEM* aItem )
{
if( m_ZoneDescriptorList[i] == (ZONE_CONTAINER*) aBoardItem )
{
m_ZoneDescriptorList.erase( m_ZoneDescriptorList.begin() + i );
break;
}
}
return aItem == aBoardItem;
} ) );
break;
case PCB_MODULE_T:
@ -758,24 +723,16 @@ void BOARD::DeleteMARKERs( bool aWarningsAndErrors, bool aExclusions )
}
void BOARD::DeleteZONEOutlines()
{
// the vector does not know how to delete the ZONE Outlines, it holds pointers
for( ZONE_CONTAINER* zone : m_ZoneDescriptorList )
delete zone;
m_ZoneDescriptorList.clear();
}
BOARD_ITEM* BOARD::GetItem( const KIID& aID )
{
if( aID == niluuid )
return nullptr;
for( TRACK* track : Tracks() )
{
if( track->m_Uuid == aID )
return track;
}
for( MODULE* module : Modules() )
{
@ -783,8 +740,10 @@ BOARD_ITEM* BOARD::GetItem( const KIID& aID )
return module;
for( D_PAD* pad : module->Pads() )
{
if( pad->m_Uuid == aID )
return pad;
}
if( module->Reference().m_Uuid == aID )
return &module->Reference();
@ -793,25 +752,35 @@ BOARD_ITEM* BOARD::GetItem( const KIID& aID )
return &module->Value();
for( BOARD_ITEM* drawing : module->GraphicalItems() )
{
if( drawing->m_Uuid == aID )
return drawing;
}
}
for( ZONE_CONTAINER* zone : Zones() )
{
if( zone->m_Uuid == aID )
return zone;
}
for( BOARD_ITEM* drawing : Drawings() )
{
if( drawing->m_Uuid == aID )
return drawing;
}
for( ZONE_CONTAINER* zone : Zones() )
if( zone->m_Uuid == aID )
return zone;
for( BOARD_ITEM* drawing : Drawings() )
if( drawing->m_Uuid == aID )
return drawing;
for( MARKER_PCB* marker : m_markers )
{
if( marker->m_Uuid == aID )
return marker;
}
for( PCB_GROUP* group : m_groups )
{
if( group->m_Uuid == aID )
return group;
}
if( m_Uuid == aID )
return this;
@ -857,9 +826,10 @@ void BOARD::FillItemMap( std::map<KIID, EDA_ITEM*>& aMap )
unsigned BOARD::GetNodesCount( int aNet )
{
unsigned retval = 0;
for( auto mod : Modules() )
for( MODULE* mod : Modules() )
{
for( auto pad : mod->Pads() )
for( D_PAD* pad : mod->Pads() )
{
if( ( aNet == -1 && pad->GetNetCode() > 0 ) || aNet == pad->GetNetCode() )
retval++;
@ -884,7 +854,7 @@ EDA_RECT BOARD::ComputeBoundingBox( bool aBoardEdgesOnly ) const
&& PgmOrNull() && !PgmOrNull()->m_Printing;
// Check segments, dimensions, texts, and fiducials
for( auto item : m_drawings )
for( BOARD_ITEM* item : m_drawings )
{
if( aBoardEdgesOnly && ( item->GetLayer() != Edge_Cuts ) )
continue;
@ -894,14 +864,14 @@ EDA_RECT BOARD::ComputeBoundingBox( bool aBoardEdgesOnly ) const
}
// Check modules
for( auto module : m_modules )
for( MODULE* module : m_modules )
{
if( !( module->GetLayerSet() & visible ).any() )
continue;
if( aBoardEdgesOnly )
{
for( const auto edge : module->GraphicalItems() )
for( const BOARD_ITEM* edge : module->GraphicalItems() )
{
if( edge->GetLayer() == Edge_Cuts )
area.Merge( edge->GetBoundingBox() );
@ -916,14 +886,14 @@ EDA_RECT BOARD::ComputeBoundingBox( bool aBoardEdgesOnly ) const
if( !aBoardEdgesOnly )
{
// Check tracks
for( auto track : m_tracks )
for( TRACK* track : m_tracks )
{
if( ( track->GetLayerSet() & visible ).any() )
area.Merge( track->GetBoundingBox() );
}
// Check zones
for( auto aZone : m_ZoneDescriptorList )
for( ZONE_CONTAINER* aZone : m_zones )
{
if( ( aZone->GetLayerSet() & visible ).any() )
area.Merge( aZone->GetBoundingBox() );
@ -940,7 +910,7 @@ void BOARD::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>
int viasCount = 0;
int trackSegmentsCount = 0;
for( auto item : m_tracks )
for( TRACK* item : m_tracks )
{
if( item->Type() == PCB_VIA_T )
viasCount++;
@ -1052,51 +1022,8 @@ SEARCH_RESULT BOARD::Visit( INSPECTOR inspector, void* testData, const KICAD_T s
break;
}
;
break;
#if 0 // both these are on same list, so we must scan it twice in order
// to get VIA priority, using new #else code below.
// But we are not using separate lists for TRACKs and VIA, because
// items are ordered (sorted) in the linked
// list by netcode AND by physical distance:
// when created, if a track or via is connected to an existing track or
// via, it is put in linked list after this existing track or via
// So usually, connected tracks or vias are grouped in this list
// So the algorithm (used in ratsnest computations) which computes the
// track connectivity is faster (more than 100 time regarding to
// a non ordered list) because when it searches for a connection, first
// it tests the near (near in term of linked list) 50 items
// from the current item (track or via) in test.
// Usually, because of this sort, a connected item (if exists) is
// found.
// If not found (and only in this case) an exhaustive (and time
// consuming) search is made, but this case is statistically rare.
case PCB_VIA_T:
case PCB_TRACE_T:
case PCB_ARC_T:
result = IterateForward( m_Track, inspector, testData, p );
// skip over any types handled in the above call.
for( ; ; )
{
switch( stype = *++p )
{
case PCB_VIA_T:
case PCB_TRACE_T:
case PCB_ARC_T:
continue;
default:
;
}
break;
}
break;
#else
case PCB_VIA_T:
result = IterateForward<TRACK*>( m_tracks, inspector, testData, p );
++p;
@ -1107,14 +1034,11 @@ SEARCH_RESULT BOARD::Visit( INSPECTOR inspector, void* testData, const KICAD_T s
result = IterateForward<TRACK*>( m_tracks, inspector, testData, p );
++p;
break;
#endif
case PCB_MARKER_T:
// MARKER_PCBS are in the m_markers std::vector
for( unsigned i = 0; i<m_markers.size(); ++i )
for( MARKER_PCB* marker : m_markers )
{
result = m_markers[i]->Visit( inspector, testData, p );
result = marker->Visit( inspector, testData, p );
if( result == SEARCH_RESULT::QUIT )
break;
@ -1124,11 +1048,9 @@ SEARCH_RESULT BOARD::Visit( INSPECTOR inspector, void* testData, const KICAD_T s
break;
case PCB_ZONE_AREA_T:
// PCB_ZONE_AREA_T are in the m_ZoneDescriptorList std::vector
for( unsigned i = 0; i< m_ZoneDescriptorList.size(); ++i )
for( ZONE_CONTAINER* zone : m_zones)
{
result = m_ZoneDescriptorList[i]->Visit( inspector, testData, p );
result = zone->Visit( inspector, testData, p );
if( result == SEARCH_RESULT::QUIT )
break;
@ -1183,7 +1105,7 @@ MODULE* BOARD::FindModuleByReference( const wxString& aReference ) const
// search only for MODULES
static const KICAD_T scanTypes[] = { PCB_MODULE_T, EOT };
INSPECTOR_FUNC inspector = [&] ( EDA_ITEM* item, void* testData )
INSPECTOR_FUNC inspector = [&]( EDA_ITEM* item, void* testData )
{
MODULE* module = (MODULE*) item;
@ -1356,30 +1278,28 @@ int BOARD::SetAreasNetCodesFromNetNames()
{
int error_count = 0;
for( int ii = 0; ii < GetAreaCount(); ii++ )
for( ZONE_CONTAINER* zone : Zones() )
{
ZONE_CONTAINER* it = GetArea( ii );
if( !it->IsOnCopperLayer() )
if( !zone->IsOnCopperLayer() )
{
it->SetNetCode( NETINFO_LIST::UNCONNECTED );
zone->SetNetCode( NETINFO_LIST::UNCONNECTED );
continue;
}
if( it->GetNetCode() != 0 ) // i.e. if this zone is connected to a net
if( zone->GetNetCode() != 0 ) // i.e. if this zone is connected to a net
{
const NETINFO_ITEM* net = it->GetNet();
const NETINFO_ITEM* net = zone->GetNet();
if( net )
{
it->SetNetCode( net->GetNet() );
zone->SetNetCode( net->GetNet() );
}
else
{
error_count++;
// keep Net Name and set m_NetCode to -1 : error flag.
it->SetNetCode( -1 );
zone->SetNetCode( -1 );
}
}
}
@ -1683,21 +1603,17 @@ std::list<ZONE_CONTAINER*> BOARD::GetZoneList( bool aIncludeZonesInFootprints )
{
std::list<ZONE_CONTAINER*> zones;
for( int ii = 0; ii < GetAreaCount(); ii++ )
{
zones.push_back( GetArea( ii ) );
}
for( ZONE_CONTAINER* zone : Zones() )
zones.push_back( zone );
if( aIncludeZonesInFootprints )
{
for( MODULE* mod : m_modules )
{
for( MODULE_ZONE_CONTAINER* zone : mod->Zones() )
{
zones.push_back( zone );
}
}
}
return zones;
}
@ -1706,10 +1622,17 @@ std::list<ZONE_CONTAINER*> BOARD::GetZoneList( bool aIncludeZonesInFootprints )
ZONE_CONTAINER* BOARD::AddArea( PICKED_ITEMS_LIST* aNewZonesList, int aNetcode, PCB_LAYER_ID aLayer,
wxPoint aStartPointPosition, ZONE_BORDER_DISPLAY_STYLE aHatch )
{
ZONE_CONTAINER* new_area = InsertArea( aNetcode,
m_ZoneDescriptorList.size( ) - 1,
aLayer, aStartPointPosition.x,
aStartPointPosition.y, aHatch );
ZONE_CONTAINER* new_area = new ZONE_CONTAINER( this );
new_area->SetNetCode( aNetcode );
new_area->SetLayer( aLayer );
m_zones.push_back( new_area );
new_area->SetHatchStyle( (ZONE_BORDER_DISPLAY_STYLE) aHatch );
// Add the first corner to the new zone
new_area->AppendCorner( aStartPointPosition, -1 );
if( aNewZonesList )
{
@ -1739,32 +1662,10 @@ void BOARD::RemoveArea( PICKED_ITEMS_LIST* aDeletedList, ZONE_CONTAINER* area_to
}
ZONE_CONTAINER* BOARD::InsertArea( int aNetcode, int aAreaIdx, PCB_LAYER_ID aLayer, int aCornerX,
int aCornerY, ZONE_BORDER_DISPLAY_STYLE aHatch )
{
ZONE_CONTAINER* new_area = new ZONE_CONTAINER( this );
new_area->SetNetCode( aNetcode );
new_area->SetLayer( aLayer );
if( aAreaIdx < (int) ( m_ZoneDescriptorList.size() - 1 ) )
m_ZoneDescriptorList.insert( m_ZoneDescriptorList.begin() + aAreaIdx + 1, new_area );
else
m_ZoneDescriptorList.push_back( new_area );
new_area->SetHatchStyle( (ZONE_BORDER_DISPLAY_STYLE) aHatch );
// Add the first corner to the new zone
new_area->AppendCorner( wxPoint( aCornerX, aCornerY ), -1 );
return new_area;
}
bool BOARD::NormalizeAreaPolygon( PICKED_ITEMS_LIST * aNewZonesList, ZONE_CONTAINER* aCurrArea )
{
// mark all areas as unmodified except this one, if modified
for( ZONE_CONTAINER* zone : m_ZoneDescriptorList )
for( ZONE_CONTAINER* zone : m_zones )
zone->SetLocalFlags( 0 );
aCurrArea->SetLocalFlags( 1 );
@ -1851,58 +1752,28 @@ unsigned BOARD::GetPadCount()
{
unsigned retval = 0;
for( auto mod : Modules() )
for( MODULE* mod : Modules() )
retval += mod->Pads().size();
return retval;
}
/**
* Function GetPad
* @return D_PAD* - at the \a aIndex
*/
D_PAD* BOARD::GetPad( unsigned aIndex ) const
{
unsigned count = 0;
for( auto mod : m_modules )
{
for( auto pad : mod->Pads() )
{
if( count == aIndex )
return pad;
count++;
}
}
return nullptr;
}
const std::vector<BOARD_CONNECTED_ITEM*> BOARD::AllConnectedItems()
{
std::vector<BOARD_CONNECTED_ITEM*> items;
for( auto track : Tracks() )
{
for( TRACK* track : Tracks() )
items.push_back( track );
}
for( auto mod : Modules() )
{
for( auto pad : mod->Pads() )
for( MODULE* mod : Modules() )
{
for( D_PAD* pad : mod->Pads() )
items.push_back( pad );
}
}
for( int i = 0; i<GetAreaCount(); i++ )
{
auto zone = GetArea( i );
for( ZONE_CONTAINER* zone : Zones() )
items.push_back( zone );
}
return items;
}
@ -2006,6 +1877,7 @@ PCB_GROUP* BOARD::TopLevelGroup( BOARD_ITEM* item, PCB_GROUP* scope )
for( PCB_GROUP* group : m_groups )
{
BOARD_ITEM* toFind = ( candidate == NULL ) ? item : candidate;
if( group->GetItems().find( toFind ) != group->GetItems().end() )
{
if( scope == group && candidate != NULL )

View File

@ -186,7 +186,7 @@ private:
MODULES m_modules;
TRACKS m_tracks;
GROUPS m_groups;
ZONE_CONTAINERS m_ZoneDescriptorList;
ZONE_CONTAINERS m_zones;
LAYER m_Layer[PCB_LAYER_ID_COUNT];
@ -251,7 +251,8 @@ public:
DRAWINGS& Drawings() { return m_drawings; }
ZONE_CONTAINERS& Zones() { return m_ZoneDescriptorList; }
ZONE_CONTAINERS& Zones() { return m_zones; }
const ZONE_CONTAINERS& Zones() const { return m_zones; }
MARKERS& Markers() { return m_markers; }
@ -290,8 +291,7 @@ public:
bool IsEmpty() const
{
return m_drawings.empty() && m_modules.empty() && m_tracks.empty() &&
m_ZoneDescriptorList.empty();
return m_drawings.empty() && m_modules.empty() && m_tracks.empty() && m_zones.empty();
}
void Move( const wxPoint& aMoveVector ) override;
@ -353,12 +353,6 @@ public:
void DeleteMARKERs( bool aWarningsAndErrors, bool aExclusions );
/**
* Function DeleteZONEOutlines
* deletes ALL zone outlines from the board.
*/
void DeleteZONEOutlines();
PROJECT* GetProject() const { return m_project; }
/**
@ -681,12 +675,6 @@ public:
*/
unsigned GetPadCount();
/**
* Function GetPad
* @return D_PAD* - at the \a aIndex
*/
D_PAD* GetPad( unsigned aIndex ) const;
/**
* Function GetPads
* returns a reference to a list of all the pads. The returned list is not
@ -870,7 +858,7 @@ public:
* @return : error count
* For non copper areas, netcode is set to 0
*/
int SetAreasNetCodesFromNetNames( void );
int SetAreasNetCodesFromNetNames();
/**
* Function GetArea
@ -880,29 +868,12 @@ public:
*/
ZONE_CONTAINER* GetArea( int index ) const
{
if( (unsigned) index < m_ZoneDescriptorList.size() )
return m_ZoneDescriptorList[index];
if( (unsigned) index < m_zones.size() )
return m_zones[index];
return NULL;
}
/**
* Function GetAreaIndex
* returns the Area Index for the given Zone Container.
* @param aArea :The ZONE_CONTAINER to find.
* @return an Area Index in m_ZoneDescriptorList or -1 if non found.
*/
int GetAreaIndex( const ZONE_CONTAINER* aArea ) const
{
for( int ii = 0; ii < GetAreaCount(); ii++ ) // Search for aArea in list
{
if( aArea == GetArea( ii ) ) // Found !
return ii;
}
return -1;
}
/**
* Function GetZoneList
* @return a std::list of pointers to all board zones (possibly including zones in footprints)
@ -915,7 +886,7 @@ public:
*/
int GetAreaCount() const
{
return static_cast<int>( m_ZoneDescriptorList.size() );
return static_cast<int>( m_zones.size() );
}
/* Functions used in test, merge and cut outlines */
@ -934,19 +905,6 @@ public:
ZONE_CONTAINER* AddArea( PICKED_ITEMS_LIST* aNewZonesList, int aNetcode, PCB_LAYER_ID aLayer,
wxPoint aStartPointPosition, ZONE_BORDER_DISPLAY_STYLE aHatch );
/**
* Add a copper area to net, inserting after m_ZoneDescriptorList[aAreaIdx]
* @param aNetcode is the netcode of the new copper zone
* @param aAreaIdx is the netcode of the new copper zone
* @param aLayer is the copper layer id of the new copper zone
* @param aCornerX,aCornerY is the coordinate of the first corner
* (a zone cannot have a empty outline)
* @param aHatch is the hatch option
* @return pointer to the new area
*/
ZONE_CONTAINER* InsertArea( int aNetcode, int aAreaIdx, PCB_LAYER_ID aLayer, int aCornerX,
int aCornerY, ZONE_BORDER_DISPLAY_STYLE aHatch );
/**
* Function NormalizeAreaPolygon
* Process an area that has been modified, by normalizing its polygon against itself.
@ -1004,7 +962,6 @@ public:
/**
* Function TestAreaIntersection
* Test for intersection of 2 copper areas
* area_to_test must be after area_ref in m_ZoneDescriptorList
* @param area_ref = area reference
* @param area_to_test = area to compare for intersection calculations
* @return : false if no intersection, true if intersection

View File

@ -47,18 +47,18 @@ const KICAD_T GENERAL_COLLECTOR::AllBoardItems[] = {
// 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_TEXT_T, // in m_Drawings
PCB_LINE_T, // in m_Drawings
PCB_DIMENSION_T, // in m_Drawings
PCB_TARGET_T, // in m_Drawings
PCB_VIA_T, // in m_Tracks
PCB_TRACE_T, // in m_Tracks
PCB_ARC_T, // in m_Tracks
PCB_TEXT_T, // in m_drawings
PCB_LINE_T, // in m_drawings
PCB_DIMENSION_T, // in m_drawings
PCB_TARGET_T, // in m_drawings
PCB_VIA_T, // in m_tracks
PCB_TRACE_T, // in m_tracks
PCB_ARC_T, // in m_tracks
PCB_PAD_T, // in modules
PCB_MODULE_TEXT_T, // in modules
PCB_MODULE_T, // in m_Modules
PCB_GROUP_T, // in m_Groups ?
PCB_ZONE_AREA_T, // in m_ZoneDescriptorList
PCB_MODULE_T, // in m_modules
PCB_GROUP_T, // in m_groups
PCB_ZONE_AREA_T, // in m_zones
EOT
};

View File

@ -394,24 +394,17 @@ const CN_CONNECTIVITY_ALGO::CLUSTERS CN_CONNECTIVITY_ALGO::SearchClusters( CLUST
void CN_CONNECTIVITY_ALGO::Build( BOARD* aBoard )
{
for( int i = 0; i<aBoard->GetAreaCount(); i++ )
{
auto zone = aBoard->GetArea( i );
for( ZONE_CONTAINER* zone : aBoard->Zones() )
Add( zone );
}
for( auto tv : aBoard->Tracks() )
for( TRACK* tv : aBoard->Tracks() )
Add( tv );
for( auto mod : aBoard->Modules() )
for( MODULE* mod : aBoard->Modules() )
{
for( auto pad : mod->Pads() )
for( D_PAD* pad : mod->Pads() )
Add( pad );
}
/*wxLogTrace( "CN", "zones : %lu, pads : %lu vias : %lu tracks : %lu\n",
m_zoneList.Size(), m_padList.Size(),
m_viaList.Size(), m_trackList.Size() );*/
}

View File

@ -503,10 +503,8 @@ void DIALOG_COPPER_ZONE::ExportSetupToOtherCopperZones( wxCommandEvent& event )
// Export settings ( but layer and netcode ) to others copper zones
BOARD* pcb = m_Parent->GetBoard();
for( int ii = 0; ii < pcb->GetAreaCount(); ii++ )
for( ZONE_CONTAINER* zone : pcb->Zones() )
{
ZONE_CONTAINER* zone = pcb->GetArea( ii );
// Cannot export settings from a copper zone
// to a zone keepout:
if( zone->GetIsKeepout() )

View File

@ -563,10 +563,8 @@ const std::vector<BOARD_ITEM*> HYPERLYNX_EXPORTER::collectNetObjects( int netcod
rv.push_back( item );
}
for( int i = 0; i < m_board->GetAreaCount(); i++ )
for( ZONE_CONTAINER* zone : m_board->Zones() )
{
ZONE_CONTAINER* zone = m_board->GetArea( i );
if( check( zone ) )
rv.push_back( zone );
}

View File

@ -1024,10 +1024,8 @@ static void export_vrml_tracks( MODEL_VRML& aModel, BOARD* pcb )
static void export_vrml_zones( MODEL_VRML& aModel, BOARD* aPcb, COMMIT* aCommit )
{
for( int ii = 0; ii < aPcb->GetAreaCount(); ii++ )
for( ZONE_CONTAINER* zone : aPcb->Zones() )
{
ZONE_CONTAINER* zone = aPcb->GetArea( ii );
for( PCB_LAYER_ID layer : zone->GetLayerSet().Seq() )
{
VRML_LAYER* vl;

View File

@ -516,10 +516,8 @@ void GERBER_JOBFILE_WRITER::addJSONDesignRules()
minclearanceOuter = INT_MAX;
minclearanceInner = INT_MAX;
for( int ii = 0; ii < m_pcb->GetAreaCount(); ii++ )
for( ZONE_CONTAINER* zone : m_pcb->Zones() )
{
ZONE_CONTAINER* zone = m_pcb->GetArea( ii );
if( zone->GetIsKeepout() || !zone->IsOnCopperLayer() )
continue;

View File

@ -22,10 +22,10 @@
*/
#include <fctsys.h>
#include <gr_basic.h>
#include <common.h>
#include <macros.h>
#include <pcbnew.h>
//#include <gr_basic.h>
//#include <common.h>
//#include <macros.h>
//#include <pcbnew.h>
#include <class_board.h>
#include <class_module.h>
#include <class_pad.h>
@ -170,6 +170,7 @@ void NETINFO_LIST::Show() const
{
int i = 0;
NETNAMES_MAP::const_iterator it, itEnd;
for( it = m_netNames.begin(), itEnd = m_netNames.end(); it != itEnd; ++it )
{
wxLogDebug( "[%d]: netcode:%d netname:<%s>\n",
@ -183,7 +184,8 @@ void NETINFO_LIST::Show() const
int NETINFO_LIST::getFreeNetCode()
{
do {
do
{
if( m_newNetCode < 0 )
m_newNetCode = 0;
} while( m_netCodes.count( ++m_newNetCode ) != 0 );
@ -213,21 +215,19 @@ void NETINFO_MAPPING::Update()
nets.insert( 0 );
// Zones
for( int i = 0; i < m_board->GetAreaCount(); ++i )
nets.insert( m_board->GetArea( i )->GetNetCode() );
for( ZONE_CONTAINER* zone : m_board->Zones() )
nets.insert( zone->GetNetCode() );
// Tracks
for( auto track : m_board->Tracks() )
for( TRACK* track : m_board->Tracks() )
nets.insert( track->GetNetCode() );
// Modules/pads
for( auto module : m_board->Modules() )
{
for( auto pad : module->Pads() )
for( MODULE* module : m_board->Modules() )
{
for( D_PAD* pad : module->Pads() )
nets.insert( pad->GetNetCode() );
}
}
// Prepare the new mapping
m_netMapping.clear();
@ -235,8 +235,9 @@ void NETINFO_MAPPING::Update()
// Now the nets variable stores all the used net codes (not only for pads) and we are ready to
// assign new consecutive net numbers
int newNetCode = 0;
for( std::set<int>::const_iterator it = nets.begin(), itEnd = nets.end(); it != itEnd; ++it )
m_netMapping[*it] = newNetCode++;
for( auto net : nets )
m_netMapping[net] = newNetCode++;
}

View File

@ -481,10 +481,8 @@ bool BOARD_NETLIST_UPDATER::updateComponentPadConnections( MODULE* aPcbComponent
void BOARD_NETLIST_UPDATER::cacheCopperZoneConnections()
{
for( int ii = 0; ii < m_board->GetAreaCount(); ii++ )
for( ZONE_CONTAINER* zone : m_board->Zones() )
{
ZONE_CONTAINER* zone = m_board->GetArea( ii );
if( !zone->IsOnCopperLayer() || zone->GetIsKeepout() )
continue;
@ -556,10 +554,8 @@ bool BOARD_NETLIST_UPDATER::updateCopperZoneNets( NETLIST& aNetlist )
}
// Test copper zones to detect "dead" nets (nets without any pad):
for( int i = 0; i < m_board->GetAreaCount(); i++ )
for( ZONE_CONTAINER* zone : m_board->Zones() )
{
ZONE_CONTAINER* zone = m_board->GetArea( i );
if( !zone->IsOnCopperLayer() || zone->GetIsKeepout() )
continue;

View File

@ -1,7 +1,7 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2017 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 2017-2020 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -21,22 +21,12 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
/**
* @file pcbnew_action_plugins.cpp
* @brief Class PCBNEW_PYTHON_ACTION_PLUGINS
*/
#include "pcbnew_action_plugins.h"
#include <board_commit.h>
#include <class_board.h>
#include <class_drawsegment.h>
#include <class_module.h>
#include <class_track.h>
#include <class_zone.h>
#include <cstdio>
#include <macros.h>
#include <menus_helpers.h>
#include <pcbnew_id.h>
#include <pcbnew_settings.h>
#include <python_scripting.h>
#include <tool/action_menu.h>
@ -220,30 +210,30 @@ void PCB_EDIT_FRAME::RunActionPlugin( ACTION_PLUGIN* aActionPlugin )
itemsList.m_Status = UNDO_REDO::CHANGED;
// Append tracks:
for( auto item : currentPcb->Tracks() )
for( TRACK* item : currentPcb->Tracks() )
{
ITEM_PICKER picker( nullptr, item, UNDO_REDO::CHANGED );
itemsList.PushItem( picker );
}
// Append modules:
for( auto item : currentPcb->Modules() )
for( MODULE* item : currentPcb->Modules() )
{
ITEM_PICKER picker( nullptr, item, UNDO_REDO::CHANGED );
itemsList.PushItem( picker );
}
// Append drawings
for( auto item : currentPcb->Drawings() )
for( BOARD_ITEM* item : currentPcb->Drawings() )
{
ITEM_PICKER picker( nullptr, item, UNDO_REDO::CHANGED );
itemsList.PushItem( picker );
}
// Append zones outlines
for( int ii = 0; ii < currentPcb->GetAreaCount(); ii++ )
for( ZONE_CONTAINER* zone : currentPcb->Zones() )
{
ITEM_PICKER picker( nullptr, (EDA_ITEM*) currentPcb->GetArea( ii ), UNDO_REDO::CHANGED );
ITEM_PICKER picker( nullptr, zone, UNDO_REDO::CHANGED );
itemsList.PushItem( picker );
}
@ -278,6 +268,7 @@ void PCB_EDIT_FRAME::RunActionPlugin( ACTION_PLUGIN* aActionPlugin )
// The list of existing items after running the action script
std::set<BOARD_ITEM*> currItemList;
// Append tracks:
for( TRACK* item : currentPcb->Tracks() )
currItemList.insert( item );
@ -291,8 +282,8 @@ void PCB_EDIT_FRAME::RunActionPlugin( ACTION_PLUGIN* aActionPlugin )
currItemList.insert( item );
// Append zones outlines
for( int ii = 0; ii < currentPcb->GetAreaCount(); ii++ )
currItemList.insert( currentPcb->GetArea( ii ) );
for( ZONE_CONTAINER* zone : currentPcb->Zones() )
currItemList.insert( zone );
// Found deleted modules
for( unsigned int i = 0; i < oldBuffer->GetCount(); i++ )
@ -340,11 +331,11 @@ void PCB_EDIT_FRAME::RunActionPlugin( ACTION_PLUGIN* aActionPlugin )
}
}
for( int ii = 0; ii < currentPcb->GetAreaCount(); ii++ )
for( ZONE_CONTAINER* zone : currentPcb->Zones() )
{
if( !oldBuffer->ContainsItem( (EDA_ITEM*) currentPcb->GetArea( ii ) ) )
if( !oldBuffer->ContainsItem( zone ) )
{
ITEM_PICKER picker( nullptr, (EDA_ITEM*) currentPcb->GetArea( ii ), UNDO_REDO::NEWITEM );
ITEM_PICKER picker( nullptr, zone, UNDO_REDO::NEWITEM );
oldBuffer->PushItem( picker );
}
}
@ -387,13 +378,12 @@ void PCB_EDIT_FRAME::buildActionPluginMenus( ACTION_MENU* actionMenu )
void PCB_EDIT_FRAME::AddActionPluginTools()
{
bool need_separator = true;
const auto& orderedPlugins = GetOrderedActionPlugins();
const std::vector<ACTION_PLUGIN*>& orderedPlugins = GetOrderedActionPlugins();
for( const auto& ap : orderedPlugins )
for( ACTION_PLUGIN* ap : orderedPlugins )
{
if( GetActionPluginButtonVisible( ap->GetPluginPath(), ap->GetShowToolbarButton() ) )
{
if( need_separator )
{
m_mainToolBar->AddScaledSeparator( this );

View File

@ -199,8 +199,8 @@ int PCBNEW_CONTROL::ZoneDisplayMode( const TOOL_EVENT& aEvent )
m_frame->SetDisplayOptions( opts );
for( int i = 0; i < board()->GetAreaCount(); ++i )
view()->Update( board()->GetArea( i ), KIGFX::GEOMETRY );
for( ZONE_CONTAINER* zone : board()->Zones() )
view()->Update( zone, KIGFX::GEOMETRY );
canvas()->Refresh();

View File

@ -98,11 +98,8 @@ void PCB_EDIT_FRAME::Edit_Zone_Params( ZONE_CONTAINER* aZone )
wxBusyCursor dummy;
// Undraw old zone outlines
for( int ii = 0; ii < GetBoard()->GetAreaCount(); ii++ )
{
ZONE_CONTAINER* edge_zone = GetBoard()->GetArea( ii );
GetCanvas()->GetView()->Update( edge_zone );
}
for( ZONE_CONTAINER* zone : GetBoard()->Zones() )
GetCanvas()->GetView()->Update( zone );
zoneInfo.ExportSetting( *aZone );

View File

@ -31,17 +31,8 @@
*/
#include <fctsys.h>
#include <common.h>
#include <confirm.h>
#include <undo_redo_container.h>
#include <class_board.h>
#include <class_zone.h>
#include <class_marker_pcb.h>
#include <pcbnew.h>
#include <drc/drc.h>
#include <math_for_graphics.h>
bool BOARD::OnAreaPolygonModified( PICKED_ITEMS_LIST* aModifiedZonesList,
@ -59,13 +50,9 @@ bool BOARD::OnAreaPolygonModified( PICKED_ITEMS_LIST* aModifiedZonesList,
// Test for bad areas: all zones must have more than 2 corners:
// Note: should not happen, but just in case.
for( unsigned ii = 0; ii < m_ZoneDescriptorList.size(); )
for( ZONE_CONTAINER* zone : m_zones )
{
ZONE_CONTAINER* zone = m_ZoneDescriptorList[ii];
if( zone->GetNumCorners() >= 3 )
ii++;
else // Remove zone because it is incorrect:
if( zone->GetNumCorners() < 3 )
RemoveArea( aModifiedZonesList, zone );
}
@ -76,15 +63,15 @@ bool BOARD::OnAreaPolygonModified( PICKED_ITEMS_LIST* aModifiedZonesList,
bool BOARD::CombineAllAreasInNet( PICKED_ITEMS_LIST* aDeletedList, int aNetCode,
bool aUseLocalFlags )
{
if( m_ZoneDescriptorList.size() <= 1 )
if( m_zones.size() <= 1 )
return false;
bool modified = false;
// Loop through all combinations
for( unsigned ia1 = 0; ia1 < m_ZoneDescriptorList.size() - 1; ia1++ )
for( unsigned ia1 = 0; ia1 < m_zones.size() - 1; ia1++ )
{
ZONE_CONTAINER* curr_area = m_ZoneDescriptorList[ia1];
ZONE_CONTAINER* curr_area = m_zones[ia1];
if( curr_area->GetNetCode() != aNetCode )
continue;
@ -93,9 +80,9 @@ bool BOARD::CombineAllAreasInNet( PICKED_ITEMS_LIST* aDeletedList, int aNetCode,
BOX2I b1 = curr_area->Outline()->BBox();
bool mod_ia1 = false;
for( unsigned ia2 = m_ZoneDescriptorList.size() - 1; ia2 > ia1; ia2-- )
for( unsigned ia2 = m_zones.size() - 1; ia2 > ia1; ia2-- )
{
ZONE_CONTAINER* area2 = m_ZoneDescriptorList[ia2];
ZONE_CONTAINER* area2 = m_zones[ia2];
if( area2->GetNetCode() != aNetCode )
continue;
@ -141,10 +128,8 @@ bool BOARD::CombineAllAreasInNet( PICKED_ITEMS_LIST* aDeletedList, int aNetCode,
bool BOARD::TestAreaIntersections( ZONE_CONTAINER* area_to_test )
{
for( unsigned ia2 = 0; ia2 < m_ZoneDescriptorList.size(); ia2++ )
for( ZONE_CONTAINER* area2 : m_zones)
{
ZONE_CONTAINER* area2 = m_ZoneDescriptorList[ia2];
if( area_to_test->GetNetCode() != area2->GetNetCode() )
continue;
@ -289,7 +274,7 @@ bool BOARD::CombineAreas( PICKED_ITEMS_LIST* aDeletedList, ZONE_CONTAINER* area_
// but we should never have more than 2 polys
if( mergedOutlines.OutlineCount() > 2 )
{
wxLogMessage(wxT("BOARD::CombineAreas error: more than 2 polys after merging") );
wxLogMessage( "BOARD::CombineAreas error: more than 2 polys after merging" );
return false;
}

View File

@ -668,7 +668,6 @@ void test::DRC_TEST_PROVIDER_COPPER_CLEARANCE::testZones()
for( int ii = 0; ii < m_board->GetAreaCount(); ii++ )
{
ZONE_CONTAINER* zone = m_board->GetArea( ii );
ZONE_CONTAINER* zoneRef = m_board->GetArea( ii );
zoneRef->BuildSmoothedPoly( smoothed_polys[ii], zoneRef->GetLayer() );