2017-03-22 13:43:10 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KICAD, a free EDA CAD application.
|
|
|
|
*
|
2018-02-04 13:34:17 +00:00
|
|
|
* Copyright (C) 2016-2018 CERN
|
2022-02-13 00:29:12 +00:00
|
|
|
* Copyright (C) 2020-2022 KiCad Developers, see AUTHORS.txt for contributors.
|
2020-08-18 14:17:16 +00:00
|
|
|
*
|
2017-03-22 13:43:10 +00:00
|
|
|
* @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
|
|
|
|
*
|
|
|
|
* 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 Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
2018-10-12 06:17:15 +00:00
|
|
|
#include <connectivity/connectivity_algo.h>
|
2021-08-14 20:05:21 +00:00
|
|
|
#include <progress_reporter.h>
|
2018-05-21 00:06:01 +00:00
|
|
|
#include <geometry/geometry_utils.h>
|
2019-05-25 01:55:40 +00:00
|
|
|
#include <board_commit.h>
|
2017-11-23 16:20:27 +00:00
|
|
|
|
2021-06-01 05:17:57 +00:00
|
|
|
#include <wx/log.h>
|
|
|
|
|
2017-11-23 16:20:27 +00:00
|
|
|
#include <thread>
|
|
|
|
#include <mutex>
|
2018-10-27 01:00:43 +00:00
|
|
|
#include <algorithm>
|
|
|
|
#include <future>
|
2018-05-19 00:08:52 +00:00
|
|
|
|
2017-03-22 13:43:10 +00:00
|
|
|
#ifdef PROFILE
|
|
|
|
#include <profile.h>
|
|
|
|
#endif
|
|
|
|
|
2018-02-09 13:14:32 +00:00
|
|
|
|
2017-03-22 13:43:10 +00:00
|
|
|
bool CN_CONNECTIVITY_ALGO::Remove( BOARD_ITEM* aItem )
|
|
|
|
{
|
2017-06-23 11:56:28 +00:00
|
|
|
markItemNetAsDirty( aItem );
|
2017-03-22 13:43:10 +00:00
|
|
|
|
|
|
|
switch( aItem->Type() )
|
|
|
|
{
|
2020-11-13 12:21:02 +00:00
|
|
|
case PCB_FOOTPRINT_T:
|
2020-11-13 15:15:52 +00:00
|
|
|
for( PAD* pad : static_cast<FOOTPRINT*>( aItem )->Pads() )
|
2017-03-22 13:43:10 +00:00
|
|
|
{
|
2020-08-07 20:37:00 +00:00
|
|
|
m_itemMap[pad].MarkItemsAsInvalid();
|
|
|
|
m_itemMap.erase( pad );
|
2017-03-22 13:43:10 +00:00
|
|
|
}
|
|
|
|
|
2018-05-21 00:06:01 +00:00
|
|
|
m_itemList.SetDirty( true );
|
2017-03-22 13:43:10 +00:00
|
|
|
break;
|
2017-06-23 11:56:28 +00:00
|
|
|
|
2017-03-22 13:43:10 +00:00
|
|
|
case PCB_PAD_T:
|
2020-08-07 20:37:00 +00:00
|
|
|
m_itemMap[aItem].MarkItemsAsInvalid();
|
|
|
|
m_itemMap.erase( aItem );
|
2018-05-21 00:06:01 +00:00
|
|
|
m_itemList.SetDirty( true );
|
2017-03-22 13:43:10 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case PCB_TRACE_T:
|
2019-05-17 00:13:21 +00:00
|
|
|
case PCB_ARC_T:
|
2020-08-07 20:37:00 +00:00
|
|
|
m_itemMap[aItem].MarkItemsAsInvalid();
|
|
|
|
m_itemMap.erase( aItem );
|
2018-05-21 00:06:01 +00:00
|
|
|
m_itemList.SetDirty( true );
|
2017-03-22 13:43:10 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case PCB_VIA_T:
|
2020-08-07 20:37:00 +00:00
|
|
|
m_itemMap[aItem].MarkItemsAsInvalid();
|
|
|
|
m_itemMap.erase( aItem );
|
2018-05-21 00:06:01 +00:00
|
|
|
m_itemList.SetDirty( true );
|
2017-03-22 13:43:10 +00:00
|
|
|
break;
|
|
|
|
|
2020-11-11 23:05:59 +00:00
|
|
|
case PCB_ZONE_T:
|
2020-08-07 20:37:00 +00:00
|
|
|
m_itemMap[aItem].MarkItemsAsInvalid();
|
|
|
|
m_itemMap.erase ( aItem );
|
2018-07-06 21:55:25 +00:00
|
|
|
m_itemList.SetDirty( true );
|
2017-03-22 13:43:10 +00:00
|
|
|
break;
|
2017-06-23 11:56:28 +00:00
|
|
|
|
2017-03-22 13:43:10 +00:00
|
|
|
default:
|
2017-06-23 11:56:28 +00:00
|
|
|
return false;
|
2017-03-22 13:43:10 +00:00
|
|
|
}
|
|
|
|
|
2018-05-21 00:06:01 +00:00
|
|
|
// Once we delete an item, it may connect between lists, so mark both as potentially invalid
|
|
|
|
m_itemList.SetHasInvalid( true );
|
|
|
|
|
2017-03-22 13:43:10 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-06-23 11:56:28 +00:00
|
|
|
|
|
|
|
void CN_CONNECTIVITY_ALGO::markItemNetAsDirty( const BOARD_ITEM* aItem )
|
2017-03-22 13:43:10 +00:00
|
|
|
{
|
2017-06-23 11:56:28 +00:00
|
|
|
if( aItem->IsConnected() )
|
2017-03-22 13:43:10 +00:00
|
|
|
{
|
2022-02-13 11:54:41 +00:00
|
|
|
const BOARD_CONNECTED_ITEM* citem = static_cast<const BOARD_CONNECTED_ITEM*>( aItem );
|
2017-07-01 21:54:17 +00:00
|
|
|
MarkNetAsDirty( citem->GetNetCode() );
|
2017-06-23 11:56:28 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-11-13 12:21:02 +00:00
|
|
|
if( aItem->Type() == PCB_FOOTPRINT_T )
|
2017-03-22 13:43:10 +00:00
|
|
|
{
|
2020-11-13 15:15:52 +00:00
|
|
|
const FOOTPRINT* footprint = static_cast<const FOOTPRINT*>( aItem );
|
2017-06-23 11:56:28 +00:00
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
for( PAD* pad : footprint->Pads() )
|
2017-07-01 21:54:17 +00:00
|
|
|
MarkNetAsDirty( pad->GetNetCode() );
|
2017-03-22 13:43:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool CN_CONNECTIVITY_ALGO::Add( BOARD_ITEM* aItem )
|
2017-06-23 11:56:28 +00:00
|
|
|
{
|
2019-07-25 11:08:41 +00:00
|
|
|
if( !aItem->IsOnCopperLayer() )
|
2018-07-10 19:22:36 +00:00
|
|
|
return false;
|
|
|
|
|
2017-06-23 11:56:28 +00:00
|
|
|
switch( aItem->Type() )
|
|
|
|
{
|
2017-07-01 21:54:17 +00:00
|
|
|
case PCB_NETINFO_T:
|
2020-12-08 13:02:08 +00:00
|
|
|
MarkNetAsDirty( static_cast<NETINFO_ITEM*>( aItem )->GetNetCode() );
|
2020-11-13 12:21:02 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case PCB_FOOTPRINT_T:
|
2021-12-09 01:38:59 +00:00
|
|
|
{
|
|
|
|
if( static_cast<FOOTPRINT*>( aItem )->GetAttributes() & FP_JUST_ADDED )
|
|
|
|
return false;
|
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
for( PAD* pad : static_cast<FOOTPRINT*>( aItem )->Pads() )
|
2017-03-22 13:43:10 +00:00
|
|
|
{
|
2017-06-23 11:56:28 +00:00
|
|
|
if( m_itemMap.find( pad ) != m_itemMap.end() )
|
|
|
|
return false;
|
2017-03-22 13:43:10 +00:00
|
|
|
|
2018-05-21 00:06:01 +00:00
|
|
|
add( m_itemList, pad );
|
2017-06-23 11:56:28 +00:00
|
|
|
}
|
2017-03-22 13:43:10 +00:00
|
|
|
|
2017-06-23 11:56:28 +00:00
|
|
|
break;
|
2021-12-09 01:38:59 +00:00
|
|
|
}
|
2017-03-22 13:43:10 +00:00
|
|
|
|
2017-06-23 11:56:28 +00:00
|
|
|
case PCB_PAD_T:
|
2021-12-09 01:38:59 +00:00
|
|
|
{
|
|
|
|
if( FOOTPRINT* fp = dynamic_cast<FOOTPRINT*>( aItem->GetParentFootprint() ) )
|
|
|
|
{
|
|
|
|
if( fp->GetAttributes() & FP_JUST_ADDED )
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( m_itemMap.find( aItem ) != m_itemMap.end() )
|
2017-06-23 11:56:28 +00:00
|
|
|
return false;
|
2017-03-22 13:43:10 +00:00
|
|
|
|
2020-11-12 22:30:02 +00:00
|
|
|
add( m_itemList, static_cast<PAD*>( aItem ) );
|
2017-06-23 11:56:28 +00:00
|
|
|
break;
|
2021-12-09 01:38:59 +00:00
|
|
|
}
|
2017-03-22 13:43:10 +00:00
|
|
|
|
2017-06-23 11:56:28 +00:00
|
|
|
case PCB_TRACE_T:
|
2020-03-05 08:41:54 +00:00
|
|
|
if( m_itemMap.find( aItem ) != m_itemMap.end() )
|
2017-06-23 11:56:28 +00:00
|
|
|
return false;
|
2017-03-22 13:43:10 +00:00
|
|
|
|
2021-06-11 21:07:02 +00:00
|
|
|
add( m_itemList, static_cast<PCB_TRACK*>( aItem ) );
|
2017-06-23 11:56:28 +00:00
|
|
|
break;
|
2017-03-22 13:43:10 +00:00
|
|
|
|
2019-05-17 00:13:21 +00:00
|
|
|
case PCB_ARC_T:
|
2020-03-05 08:41:54 +00:00
|
|
|
if( m_itemMap.find( aItem ) != m_itemMap.end() )
|
2019-05-17 00:13:21 +00:00
|
|
|
return false;
|
|
|
|
|
2021-06-11 21:07:02 +00:00
|
|
|
add( m_itemList, static_cast<PCB_ARC*>( aItem ) );
|
2019-05-17 00:13:21 +00:00
|
|
|
break;
|
|
|
|
|
2017-06-23 11:56:28 +00:00
|
|
|
case PCB_VIA_T:
|
2020-03-05 08:41:54 +00:00
|
|
|
if( m_itemMap.find( aItem ) != m_itemMap.end() )
|
2017-06-23 11:56:28 +00:00
|
|
|
return false;
|
2017-03-22 13:43:10 +00:00
|
|
|
|
2021-06-11 21:07:02 +00:00
|
|
|
add( m_itemList, static_cast<PCB_VIA*>( aItem ) );
|
2017-06-23 11:56:28 +00:00
|
|
|
break;
|
2017-03-22 13:43:10 +00:00
|
|
|
|
2020-11-11 23:05:59 +00:00
|
|
|
case PCB_ZONE_T:
|
2017-06-23 11:56:28 +00:00
|
|
|
{
|
2020-11-11 23:05:59 +00:00
|
|
|
ZONE* zone = static_cast<ZONE*>( aItem );
|
2017-03-22 13:43:10 +00:00
|
|
|
|
2020-03-05 08:41:54 +00:00
|
|
|
if( m_itemMap.find( aItem ) != m_itemMap.end() )
|
2017-06-23 11:56:28 +00:00
|
|
|
return false;
|
2017-03-22 13:43:10 +00:00
|
|
|
|
2017-06-23 11:56:28 +00:00
|
|
|
m_itemMap[zone] = ITEM_MAP_ENTRY();
|
2017-03-22 13:43:10 +00:00
|
|
|
|
2020-06-24 02:19:08 +00:00
|
|
|
for( PCB_LAYER_ID layer : zone->GetLayerSet().Seq() )
|
2020-11-11 23:05:59 +00:00
|
|
|
{
|
|
|
|
for( CN_ITEM* zitem : m_itemList.Add( zone, layer ) )
|
2020-06-24 02:19:08 +00:00
|
|
|
m_itemMap[zone].Link( zitem );
|
2020-11-11 23:05:59 +00:00
|
|
|
}
|
2017-06-23 11:56:28 +00:00
|
|
|
}
|
2020-11-13 12:21:02 +00:00
|
|
|
break;
|
2017-03-22 13:43:10 +00:00
|
|
|
|
2017-06-23 11:56:28 +00:00
|
|
|
default:
|
|
|
|
return false;
|
2017-03-22 13:43:10 +00:00
|
|
|
}
|
|
|
|
|
2021-12-09 01:38:59 +00:00
|
|
|
markItemNetAsDirty( aItem );
|
|
|
|
|
2017-06-23 11:56:28 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-12-01 15:53:58 +00:00
|
|
|
|
2018-06-26 06:12:11 +00:00
|
|
|
void CN_CONNECTIVITY_ALGO::searchConnections()
|
2017-03-22 13:43:10 +00:00
|
|
|
{
|
2018-05-15 22:50:59 +00:00
|
|
|
#ifdef PROFILE
|
|
|
|
PROF_COUNTER garbage_collection( "garbage-collection" );
|
|
|
|
#endif
|
2017-06-23 11:56:28 +00:00
|
|
|
std::vector<CN_ITEM*> garbage;
|
|
|
|
garbage.reserve( 1024 );
|
2017-03-22 13:43:10 +00:00
|
|
|
|
2018-05-21 00:06:01 +00:00
|
|
|
m_itemList.RemoveInvalidItems( garbage );
|
2017-03-22 13:43:10 +00:00
|
|
|
|
2022-02-13 11:54:41 +00:00
|
|
|
for( CN_ITEM* item : garbage )
|
2017-03-22 13:43:10 +00:00
|
|
|
delete item;
|
|
|
|
|
|
|
|
#ifdef PROFILE
|
2018-05-15 22:50:59 +00:00
|
|
|
garbage_collection.Show();
|
2017-03-22 13:43:10 +00:00
|
|
|
PROF_COUNTER search_basic( "search-basic" );
|
|
|
|
#endif
|
|
|
|
|
2018-10-05 13:22:20 +00:00
|
|
|
std::vector<CN_ITEM*> dirtyItems;
|
|
|
|
std::copy_if( m_itemList.begin(), m_itemList.end(), std::back_inserter( dirtyItems ),
|
2020-10-26 12:50:12 +00:00
|
|
|
[] ( CN_ITEM* aItem )
|
|
|
|
{
|
|
|
|
return aItem->Dirty();
|
|
|
|
} );
|
2018-09-21 12:21:12 +00:00
|
|
|
|
2018-06-26 06:12:11 +00:00
|
|
|
if( m_progressReporter )
|
2017-03-22 13:43:10 +00:00
|
|
|
{
|
2018-10-05 13:22:20 +00:00
|
|
|
m_progressReporter->SetMaxProgress( dirtyItems.size() );
|
2020-10-26 12:54:30 +00:00
|
|
|
|
|
|
|
if( !m_progressReporter->KeepRefreshing() )
|
|
|
|
return;
|
2018-06-26 06:12:11 +00:00
|
|
|
}
|
|
|
|
|
2018-09-20 02:10:12 +00:00
|
|
|
if( m_itemList.IsDirty() )
|
2018-06-26 06:12:11 +00:00
|
|
|
{
|
2018-10-27 01:00:43 +00:00
|
|
|
size_t parallelThreadCount = std::min<size_t>( std::thread::hardware_concurrency(),
|
2020-10-26 12:50:12 +00:00
|
|
|
( dirtyItems.size() + 7 ) / 8 );
|
2018-10-27 01:00:43 +00:00
|
|
|
|
2018-10-05 13:22:20 +00:00
|
|
|
std::atomic<size_t> nextItem( 0 );
|
2018-10-27 01:00:43 +00:00
|
|
|
std::vector<std::future<size_t>> returns( parallelThreadCount );
|
2018-09-20 02:10:12 +00:00
|
|
|
|
2020-10-26 12:50:12 +00:00
|
|
|
auto conn_lambda =
|
|
|
|
[&nextItem, &dirtyItems]( CN_LIST* aItemList,
|
|
|
|
PROGRESS_REPORTER* aReporter) -> size_t
|
|
|
|
{
|
|
|
|
for( size_t i = nextItem++; i < dirtyItems.size(); i = nextItem++ )
|
|
|
|
{
|
|
|
|
CN_VISITOR visitor( dirtyItems[i] );
|
|
|
|
aItemList->FindNearby( dirtyItems[i], visitor );
|
2018-10-05 13:22:20 +00:00
|
|
|
|
2020-10-26 12:50:12 +00:00
|
|
|
if( aReporter )
|
2020-10-26 12:54:30 +00:00
|
|
|
{
|
|
|
|
if( aReporter->IsCancelled() )
|
|
|
|
break;
|
|
|
|
else
|
|
|
|
aReporter->AdvanceProgress();
|
|
|
|
}
|
2020-10-26 12:50:12 +00:00
|
|
|
}
|
2018-06-26 06:12:11 +00:00
|
|
|
|
2020-10-26 12:50:12 +00:00
|
|
|
return 1;
|
|
|
|
};
|
2018-09-20 02:10:12 +00:00
|
|
|
|
2018-10-25 11:20:12 +00:00
|
|
|
if( parallelThreadCount <= 1 )
|
2022-02-13 11:54:41 +00:00
|
|
|
{
|
2018-10-25 11:20:12 +00:00
|
|
|
conn_lambda( &m_itemList, m_progressReporter );
|
2022-02-13 11:54:41 +00:00
|
|
|
}
|
2018-10-25 11:20:12 +00:00
|
|
|
else
|
2018-09-20 02:10:12 +00:00
|
|
|
{
|
2018-10-25 11:20:12 +00:00
|
|
|
for( size_t ii = 0; ii < parallelThreadCount; ++ii )
|
2020-10-26 12:50:12 +00:00
|
|
|
{
|
|
|
|
returns[ii] = std::async( std::launch::async, conn_lambda, &m_itemList,
|
|
|
|
m_progressReporter );
|
|
|
|
}
|
2017-03-22 13:43:10 +00:00
|
|
|
|
2018-10-27 01:00:43 +00:00
|
|
|
for( size_t ii = 0; ii < parallelThreadCount; ++ii )
|
2018-10-25 11:20:12 +00:00
|
|
|
{
|
2018-11-06 04:11:12 +00:00
|
|
|
// Here we balance returns with a 100ms timeout to allow UI updating
|
2018-10-27 01:00:43 +00:00
|
|
|
std::future_status status;
|
|
|
|
do
|
|
|
|
{
|
|
|
|
if( m_progressReporter )
|
|
|
|
m_progressReporter->KeepRefreshing();
|
|
|
|
|
2018-11-06 04:11:12 +00:00
|
|
|
status = returns[ii].wait_for( std::chrono::milliseconds( 100 ) );
|
2018-10-27 01:00:43 +00:00
|
|
|
} while( status != std::future_status::ready );
|
2018-10-25 11:20:12 +00:00
|
|
|
}
|
2018-09-20 02:10:12 +00:00
|
|
|
}
|
2018-10-25 11:20:12 +00:00
|
|
|
|
|
|
|
if( m_progressReporter )
|
|
|
|
m_progressReporter->KeepRefreshing();
|
2017-03-22 13:43:10 +00:00
|
|
|
}
|
2018-09-20 02:10:12 +00:00
|
|
|
|
|
|
|
#ifdef PROFILE
|
|
|
|
search_basic.Show();
|
2018-06-26 06:12:11 +00:00
|
|
|
#endif
|
2017-03-22 13:43:10 +00:00
|
|
|
|
2018-06-26 06:12:11 +00:00
|
|
|
m_itemList.ClearDirtyFlags();
|
2017-03-22 13:43:10 +00:00
|
|
|
}
|
|
|
|
|
2017-06-23 11:56:28 +00:00
|
|
|
|
2017-03-22 13:43:10 +00:00
|
|
|
const CN_CONNECTIVITY_ALGO::CLUSTERS CN_CONNECTIVITY_ALGO::SearchClusters( CLUSTER_SEARCH_MODE aMode )
|
|
|
|
{
|
2018-07-06 21:55:25 +00:00
|
|
|
if( aMode == CSM_PROPAGATE )
|
2022-03-03 23:49:05 +00:00
|
|
|
return SearchClusters( aMode,
|
|
|
|
{ PCB_TRACE_T, PCB_ARC_T, PCB_PAD_T, PCB_VIA_T, PCB_FOOTPRINT_T }, -1 );
|
2018-07-06 21:55:25 +00:00
|
|
|
else
|
2022-03-03 23:49:05 +00:00
|
|
|
return SearchClusters( aMode,
|
|
|
|
{ PCB_TRACE_T, PCB_ARC_T, PCB_PAD_T, PCB_VIA_T, PCB_ZONE_T, PCB_FOOTPRINT_T }, -1 );
|
2017-03-22 13:43:10 +00:00
|
|
|
}
|
|
|
|
|
2017-06-23 11:56:28 +00:00
|
|
|
|
2022-02-06 17:26:30 +00:00
|
|
|
const CN_CONNECTIVITY_ALGO::CLUSTERS
|
2022-03-03 23:49:05 +00:00
|
|
|
CN_CONNECTIVITY_ALGO::SearchClusters( CLUSTER_SEARCH_MODE aMode, const std::initializer_list<KICAD_T>& aTypes,
|
2022-02-06 17:26:30 +00:00
|
|
|
int aSingleNet, CN_ITEM* rootItem )
|
2017-03-22 13:43:10 +00:00
|
|
|
{
|
|
|
|
bool withinAnyNet = ( aMode != CSM_PROPAGATE );
|
|
|
|
|
|
|
|
std::deque<CN_ITEM*> Q;
|
2020-07-27 16:33:01 +00:00
|
|
|
std::set<CN_ITEM*> item_set;
|
|
|
|
|
2017-03-22 13:43:10 +00:00
|
|
|
CLUSTERS clusters;
|
|
|
|
|
2018-10-12 12:57:56 +00:00
|
|
|
if( m_itemList.IsDirty() )
|
2018-06-26 06:12:11 +00:00
|
|
|
searchConnections();
|
2017-03-22 13:43:10 +00:00
|
|
|
|
2020-10-26 12:50:12 +00:00
|
|
|
auto addToSearchList =
|
2022-02-06 17:26:30 +00:00
|
|
|
[&item_set, withinAnyNet, aSingleNet, aTypes, rootItem ]( CN_ITEM *aItem )
|
2020-10-26 12:50:12 +00:00
|
|
|
{
|
|
|
|
if( withinAnyNet && aItem->Net() <= 0 )
|
|
|
|
return;
|
2017-03-22 13:43:10 +00:00
|
|
|
|
2020-10-26 12:50:12 +00:00
|
|
|
if( !aItem->Valid() )
|
|
|
|
return;
|
2017-03-22 13:43:10 +00:00
|
|
|
|
2020-10-26 12:50:12 +00:00
|
|
|
if( aSingleNet >=0 && aItem->Net() != aSingleNet )
|
|
|
|
return;
|
2017-03-22 13:43:10 +00:00
|
|
|
|
2020-10-26 12:50:12 +00:00
|
|
|
bool found = false;
|
2017-03-22 13:43:10 +00:00
|
|
|
|
2022-03-03 23:49:05 +00:00
|
|
|
for( KICAD_T type : aTypes )
|
2020-10-26 12:50:12 +00:00
|
|
|
{
|
2022-03-03 23:49:05 +00:00
|
|
|
if( aItem->Parent()->Type() == type )
|
2020-10-26 12:50:12 +00:00
|
|
|
{
|
|
|
|
found = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2017-03-22 13:43:10 +00:00
|
|
|
|
2022-02-06 17:26:30 +00:00
|
|
|
if( !found && aItem != rootItem )
|
2020-10-26 12:50:12 +00:00
|
|
|
return;
|
2017-03-22 13:43:10 +00:00
|
|
|
|
2020-10-26 12:50:12 +00:00
|
|
|
aItem->SetVisited( false );
|
2017-03-22 13:43:10 +00:00
|
|
|
|
2020-10-26 12:50:12 +00:00
|
|
|
item_set.insert( aItem );
|
|
|
|
};
|
2017-03-22 13:43:10 +00:00
|
|
|
|
2018-05-21 00:06:01 +00:00
|
|
|
std::for_each( m_itemList.begin(), m_itemList.end(), addToSearchList );
|
2017-03-22 13:43:10 +00:00
|
|
|
|
2020-10-26 12:54:30 +00:00
|
|
|
if( m_progressReporter && m_progressReporter->IsCancelled() )
|
|
|
|
return CLUSTERS();
|
|
|
|
|
2020-07-27 16:33:01 +00:00
|
|
|
while( !item_set.empty() )
|
2017-03-22 13:43:10 +00:00
|
|
|
{
|
2022-02-13 11:54:41 +00:00
|
|
|
std::shared_ptr<CN_CLUSTER> cluster = std::make_shared<CN_CLUSTER>();
|
|
|
|
CN_ITEM* root;
|
|
|
|
auto it = item_set.begin();
|
2017-03-22 13:43:10 +00:00
|
|
|
|
2020-07-27 16:33:01 +00:00
|
|
|
while( it != item_set.end() && (*it)->Visited() )
|
|
|
|
it = item_set.erase( item_set.begin() );
|
2017-03-22 13:43:10 +00:00
|
|
|
|
2020-07-27 16:33:01 +00:00
|
|
|
if( it == item_set.end() )
|
|
|
|
break;
|
|
|
|
|
|
|
|
root = *it;
|
2020-10-26 12:50:12 +00:00
|
|
|
root->SetVisited( true );
|
2017-03-22 13:43:10 +00:00
|
|
|
|
2020-07-27 16:33:01 +00:00
|
|
|
Q.clear();
|
2017-03-22 13:43:10 +00:00
|
|
|
Q.push_back( root );
|
|
|
|
|
|
|
|
while( Q.size() )
|
|
|
|
{
|
|
|
|
CN_ITEM* current = Q.front();
|
|
|
|
|
|
|
|
Q.pop_front();
|
|
|
|
cluster->Add( current );
|
|
|
|
|
2022-02-13 11:54:41 +00:00
|
|
|
for( CN_ITEM* n : current->ConnectedItems() )
|
2017-03-22 13:43:10 +00:00
|
|
|
{
|
2017-06-23 11:56:28 +00:00
|
|
|
if( withinAnyNet && n->Net() != root->Net() )
|
2017-03-22 13:43:10 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
if( !n->Visited() && n->Valid() )
|
|
|
|
{
|
|
|
|
n->SetVisited( true );
|
|
|
|
Q.push_back( n );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
clusters.push_back( cluster );
|
|
|
|
}
|
|
|
|
|
2020-10-26 12:54:30 +00:00
|
|
|
if( m_progressReporter && m_progressReporter->IsCancelled() )
|
|
|
|
return CLUSTERS();
|
2017-03-22 13:43:10 +00:00
|
|
|
|
2020-10-26 12:50:12 +00:00
|
|
|
std::sort( clusters.begin(), clusters.end(),
|
2022-02-13 11:54:41 +00:00
|
|
|
[]( const std::shared_ptr<CN_CLUSTER>& a, const std::shared_ptr<CN_CLUSTER>& b )
|
2020-10-26 12:50:12 +00:00
|
|
|
{
|
|
|
|
return a->OriginNet() < b->OriginNet();
|
|
|
|
} );
|
2017-03-22 13:43:10 +00:00
|
|
|
|
|
|
|
return clusters;
|
|
|
|
}
|
|
|
|
|
2017-06-23 11:56:28 +00:00
|
|
|
|
2020-09-23 10:46:41 +00:00
|
|
|
void CN_CONNECTIVITY_ALGO::Build( BOARD* aBoard, PROGRESS_REPORTER* aReporter )
|
|
|
|
{
|
2022-02-16 14:10:43 +00:00
|
|
|
// Generate CN_ZONE_LAYERs for each island on each layer of each zone
|
|
|
|
//
|
|
|
|
std::vector<CN_ZONE_LAYER*> zitems;
|
2020-09-23 10:46:41 +00:00
|
|
|
|
2022-02-16 14:10:43 +00:00
|
|
|
for( ZONE* zone : aBoard->Zones() )
|
|
|
|
{
|
|
|
|
if( zone->IsOnCopperLayer() )
|
|
|
|
{
|
|
|
|
m_itemMap[zone] = ITEM_MAP_ENTRY();
|
|
|
|
markItemNetAsDirty( zone );
|
|
|
|
|
|
|
|
for( PCB_LAYER_ID layer : zone->GetLayerSet().Seq() )
|
|
|
|
{
|
|
|
|
if( IsCopperLayer( layer ) )
|
|
|
|
{
|
|
|
|
for( int j = 0; j < zone->GetFilledPolysList( layer )->OutlineCount(); j++ )
|
|
|
|
zitems.push_back( new CN_ZONE_LAYER( zone, layer, j ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Setup progress metrics
|
|
|
|
//
|
|
|
|
int delta = 50; // Number of additions between 2 calls to the progress bar
|
|
|
|
double size = 0.0;
|
|
|
|
|
|
|
|
size += zitems.size(); // Once for building RTrees
|
|
|
|
size += zitems.size(); // Once for adding to connectivity
|
2020-09-23 10:46:41 +00:00
|
|
|
size += aBoard->Tracks().size();
|
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
for( FOOTPRINT* footprint : aBoard->Footprints() )
|
2020-11-12 23:50:33 +00:00
|
|
|
size += footprint->Pads().size();
|
2020-09-23 10:46:41 +00:00
|
|
|
|
2022-02-16 14:10:43 +00:00
|
|
|
size *= 1.5; // Our caller gets the other third of the progress bar
|
2020-09-23 10:46:41 +00:00
|
|
|
|
2022-02-16 14:10:43 +00:00
|
|
|
delta = std::max( delta, KiROUND( size / 10 ) );
|
2021-11-25 16:19:03 +00:00
|
|
|
|
2022-02-16 14:10:43 +00:00
|
|
|
auto report =
|
|
|
|
[&]( int progress )
|
|
|
|
{
|
|
|
|
if( aReporter && ( progress % delta ) == 0 )
|
|
|
|
{
|
|
|
|
aReporter->SetCurrentProgress( progress / size );
|
|
|
|
aReporter->KeepRefreshing( false );
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// Generate RTrees for CN_ZONE_LAYER items (in parallel)
|
|
|
|
//
|
|
|
|
std::atomic<size_t> next( 0 );
|
|
|
|
std::atomic<size_t> zitems_done( 0 );
|
|
|
|
std::atomic<size_t> threads_done( 0 );
|
|
|
|
size_t parallelThreadCount = std::max<size_t>( std::thread::hardware_concurrency(), 2 );
|
|
|
|
|
|
|
|
for( size_t ii = 0; ii < parallelThreadCount; ++ii )
|
2020-09-23 10:46:41 +00:00
|
|
|
{
|
2022-02-16 14:10:43 +00:00
|
|
|
std::thread t = std::thread(
|
|
|
|
[ &zitems, &zitems_done, &threads_done, &next ]( )
|
|
|
|
{
|
|
|
|
for( size_t i = next.fetch_add( 1 ); i < zitems.size(); i = next.fetch_add( 1 ) )
|
|
|
|
{
|
|
|
|
zitems[i]->BuildRTree();
|
|
|
|
zitems_done.fetch_add( 1 );
|
|
|
|
}
|
2022-02-14 17:19:28 +00:00
|
|
|
|
2022-02-16 14:10:43 +00:00
|
|
|
threads_done.fetch_add( 1 );
|
|
|
|
} );
|
|
|
|
|
|
|
|
t.detach();
|
|
|
|
}
|
|
|
|
|
|
|
|
while( threads_done < parallelThreadCount )
|
|
|
|
{
|
2022-02-14 17:19:28 +00:00
|
|
|
if( aReporter )
|
|
|
|
{
|
2022-02-16 14:10:43 +00:00
|
|
|
aReporter->SetCurrentProgress( zitems_done / size );
|
|
|
|
aReporter->KeepRefreshing();
|
2022-02-14 17:19:28 +00:00
|
|
|
}
|
2022-02-16 14:10:43 +00:00
|
|
|
|
|
|
|
std::this_thread::sleep_for( std::chrono::milliseconds( 100 ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add CN_ZONE_LAYERS, tracks, and pads to connectivity
|
|
|
|
//
|
|
|
|
int ii = zitems.size();
|
|
|
|
|
|
|
|
for( CN_ZONE_LAYER* zitem : zitems )
|
|
|
|
{
|
|
|
|
m_itemList.Add( zitem );
|
|
|
|
m_itemMap[ zitem->Parent() ].Link( zitem );
|
|
|
|
report( ++ii );
|
2020-09-23 10:46:41 +00:00
|
|
|
}
|
2017-03-22 13:43:10 +00:00
|
|
|
|
2021-06-11 21:07:02 +00:00
|
|
|
for( PCB_TRACK* tv : aBoard->Tracks() )
|
2020-09-23 10:46:41 +00:00
|
|
|
{
|
2017-03-22 13:43:10 +00:00
|
|
|
Add( tv );
|
2022-02-16 14:10:43 +00:00
|
|
|
report( ++ii );
|
2020-09-23 10:46:41 +00:00
|
|
|
}
|
2017-03-22 13:43:10 +00:00
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
for( FOOTPRINT* footprint : aBoard->Footprints() )
|
2017-06-23 11:56:28 +00:00
|
|
|
{
|
2020-11-12 22:30:02 +00:00
|
|
|
for( PAD* pad : footprint->Pads() )
|
2020-09-23 10:46:41 +00:00
|
|
|
{
|
2017-03-22 13:43:10 +00:00
|
|
|
Add( pad );
|
2022-02-16 14:10:43 +00:00
|
|
|
report( ++ii );
|
2020-09-23 10:46:41 +00:00
|
|
|
}
|
2017-06-23 11:56:28 +00:00
|
|
|
}
|
2022-02-14 17:19:28 +00:00
|
|
|
|
|
|
|
if( aReporter )
|
|
|
|
{
|
|
|
|
aReporter->SetCurrentProgress( (double) ii / (double) size );
|
|
|
|
aReporter->KeepRefreshing( false );
|
|
|
|
}
|
2017-03-22 13:43:10 +00:00
|
|
|
}
|
|
|
|
|
2017-06-23 11:56:28 +00:00
|
|
|
|
2022-02-16 12:00:18 +00:00
|
|
|
void CN_CONNECTIVITY_ALGO::LocalBuild( const std::vector<BOARD_ITEM*>& aItems )
|
2017-03-22 13:43:10 +00:00
|
|
|
{
|
2022-02-14 17:19:28 +00:00
|
|
|
for( BOARD_ITEM* item : aItems )
|
2017-03-22 13:43:10 +00:00
|
|
|
{
|
|
|
|
switch( item->Type() )
|
|
|
|
{
|
2022-02-16 12:00:18 +00:00
|
|
|
case PCB_TRACE_T:
|
|
|
|
case PCB_ARC_T:
|
|
|
|
case PCB_VIA_T:
|
|
|
|
case PCB_PAD_T:
|
|
|
|
case PCB_FOOTPRINT_T:
|
|
|
|
Add( item );
|
|
|
|
break;
|
2017-03-22 13:43:10 +00:00
|
|
|
|
2022-02-16 12:00:18 +00:00
|
|
|
default:
|
|
|
|
break;
|
2017-03-22 13:43:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-23 11:56:28 +00:00
|
|
|
|
2021-03-23 21:42:56 +00:00
|
|
|
void CN_CONNECTIVITY_ALGO::propagateConnections( BOARD_COMMIT* aCommit, PROPAGATE_MODE aMode )
|
2017-03-22 13:43:10 +00:00
|
|
|
{
|
2021-03-23 21:42:56 +00:00
|
|
|
bool skipConflicts = ( aMode == PROPAGATE_MODE::SKIP_CONFLICTS );
|
|
|
|
|
2022-02-04 22:44:59 +00:00
|
|
|
wxLogTrace( wxT( "CN" ), wxT( "propagateConnections: propagate skip conflicts? %d" ),
|
|
|
|
skipConflicts );
|
2021-03-23 21:42:56 +00:00
|
|
|
|
2022-02-14 17:19:28 +00:00
|
|
|
for( const std::shared_ptr<CN_CLUSTER>& cluster : m_connClusters )
|
2017-03-22 13:43:10 +00:00
|
|
|
{
|
2021-03-23 21:42:56 +00:00
|
|
|
if( skipConflicts && cluster->IsConflicting() )
|
|
|
|
{
|
2022-02-04 22:44:59 +00:00
|
|
|
wxLogTrace( wxT( "CN" ), wxT( "Conflicting nets in cluster %p; skipping update" ),
|
|
|
|
cluster.get() );
|
2021-03-23 21:42:56 +00:00
|
|
|
}
|
|
|
|
else if( cluster->IsOrphaned() )
|
2017-09-29 09:40:10 +00:00
|
|
|
{
|
2022-02-04 22:44:59 +00:00
|
|
|
wxLogTrace( wxT( "CN" ), wxT( "Skipping orphaned cluster %p [net: %s]" ),
|
|
|
|
cluster.get(),
|
|
|
|
(const char*) cluster->OriginNetName().c_str() );
|
2017-03-22 13:43:10 +00:00
|
|
|
}
|
|
|
|
else if( cluster->HasValidNet() )
|
|
|
|
{
|
2021-03-21 19:31:15 +00:00
|
|
|
if( cluster->IsConflicting() )
|
|
|
|
{
|
2022-02-04 22:44:59 +00:00
|
|
|
wxLogTrace( wxT( "CN" ), wxT( "Conflicting nets in cluster %p; chose %d (%s)" ),
|
|
|
|
cluster.get(),
|
|
|
|
cluster->OriginNet(),
|
|
|
|
cluster->OriginNetName() );
|
2021-03-21 19:31:15 +00:00
|
|
|
}
|
|
|
|
|
2017-03-22 13:43:10 +00:00
|
|
|
// normal cluster: just propagate from the pads
|
|
|
|
int n_changed = 0;
|
|
|
|
|
|
|
|
for( auto item : *cluster )
|
|
|
|
{
|
|
|
|
if( item->CanChangeNet() )
|
|
|
|
{
|
2017-07-21 09:40:26 +00:00
|
|
|
if( item->Valid() && item->Parent()->GetNetCode() != cluster->OriginNet() )
|
2017-07-02 21:05:23 +00:00
|
|
|
{
|
|
|
|
MarkNetAsDirty( item->Parent()->GetNetCode() );
|
|
|
|
MarkNetAsDirty( cluster->OriginNet() );
|
|
|
|
|
2019-05-25 01:55:40 +00:00
|
|
|
if( aCommit )
|
|
|
|
aCommit->Modify( item->Parent() );
|
|
|
|
|
2017-07-02 21:05:23 +00:00
|
|
|
item->Parent()->SetNetCode( cluster->OriginNet() );
|
|
|
|
n_changed++;
|
|
|
|
}
|
2017-03-22 13:43:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( n_changed )
|
2020-01-11 21:28:25 +00:00
|
|
|
{
|
2022-02-04 22:44:59 +00:00
|
|
|
wxLogTrace( wxT( "CN" ), wxT( "Cluster %p : net : %d %s" ),
|
|
|
|
cluster.get(),
|
|
|
|
cluster->OriginNet(),
|
|
|
|
(const char*) cluster->OriginNetName().c_str() );
|
2020-01-11 21:28:25 +00:00
|
|
|
}
|
2017-03-22 13:43:10 +00:00
|
|
|
else
|
2022-02-04 22:44:59 +00:00
|
|
|
wxLogTrace( wxT( "CN" ), wxT( "Cluster %p : nothing to propagate" ),
|
|
|
|
cluster.get() );
|
2017-03-22 13:43:10 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-02-04 22:44:59 +00:00
|
|
|
wxLogTrace( wxT( "CN" ), wxT( "Cluster %p : connected to unused net" ),
|
|
|
|
cluster.get() );
|
2017-03-22 13:43:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-03-23 21:42:56 +00:00
|
|
|
void CN_CONNECTIVITY_ALGO::PropagateNets( BOARD_COMMIT* aCommit, PROPAGATE_MODE aMode )
|
2017-03-22 13:43:10 +00:00
|
|
|
{
|
|
|
|
m_connClusters = SearchClusters( CSM_PROPAGATE );
|
2021-03-23 21:42:56 +00:00
|
|
|
propagateConnections( aCommit, aMode );
|
2017-03-22 13:43:10 +00:00
|
|
|
}
|
|
|
|
|
2017-12-01 15:53:58 +00:00
|
|
|
|
2020-11-11 23:05:59 +00:00
|
|
|
void CN_CONNECTIVITY_ALGO::FindIsolatedCopperIslands( ZONE* aZone, PCB_LAYER_ID aLayer,
|
2020-06-24 02:19:08 +00:00
|
|
|
std::vector<int>& aIslands )
|
2017-03-22 13:43:10 +00:00
|
|
|
{
|
2022-02-15 17:34:38 +00:00
|
|
|
if( aZone->GetFilledPolysList( aLayer )->IsEmpty() )
|
2017-03-22 13:43:10 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
aIslands.clear();
|
|
|
|
|
|
|
|
Remove( aZone );
|
|
|
|
Add( aZone );
|
|
|
|
|
|
|
|
m_connClusters = SearchClusters( CSM_CONNECTIVITY_CHECK );
|
|
|
|
|
2022-02-13 11:54:41 +00:00
|
|
|
for( const std::shared_ptr<CN_CLUSTER>& cluster : m_connClusters )
|
2017-06-23 11:56:28 +00:00
|
|
|
{
|
2017-03-22 13:43:10 +00:00
|
|
|
if( cluster->Contains( aZone ) && cluster->IsOrphaned() )
|
|
|
|
{
|
2022-02-13 11:54:41 +00:00
|
|
|
for( CN_ITEM* z : *cluster )
|
2017-03-22 13:43:10 +00:00
|
|
|
{
|
2020-06-24 02:19:08 +00:00
|
|
|
if( z->Parent() == aZone && z->Layer() == aLayer )
|
2020-09-23 19:02:21 +00:00
|
|
|
aIslands.push_back( static_cast<CN_ZONE_LAYER*>(z)->SubpolyIndex() );
|
2017-03-22 13:43:10 +00:00
|
|
|
}
|
|
|
|
}
|
2017-06-23 11:56:28 +00:00
|
|
|
}
|
2017-03-22 13:43:10 +00:00
|
|
|
|
2022-02-04 22:44:59 +00:00
|
|
|
wxLogTrace( wxT( "CN" ), wxT( "Found %u isolated islands\n" ), (unsigned) aIslands.size() );
|
2017-03-22 13:43:10 +00:00
|
|
|
}
|
|
|
|
|
2017-11-23 16:20:27 +00:00
|
|
|
void CN_CONNECTIVITY_ALGO::FindIsolatedCopperIslands( std::vector<CN_ZONE_ISOLATED_ISLAND_LIST>& aZones )
|
|
|
|
{
|
2022-02-15 15:19:39 +00:00
|
|
|
int delta = 10; // Number of additions between 2 calls to the progress bar
|
|
|
|
int ii = 0;
|
|
|
|
|
2022-02-13 00:29:12 +00:00
|
|
|
for( CN_ZONE_ISOLATED_ISLAND_LIST& z : aZones )
|
2018-06-26 06:12:11 +00:00
|
|
|
{
|
2020-07-01 02:21:59 +00:00
|
|
|
Remove( z.m_zone );
|
|
|
|
Add( z.m_zone );
|
2022-02-15 15:19:39 +00:00
|
|
|
ii++;
|
|
|
|
|
|
|
|
if( m_progressReporter && ( ii % delta ) == 0 )
|
|
|
|
{
|
|
|
|
m_progressReporter->SetCurrentProgress( (double) ii / (double) aZones.size() );
|
|
|
|
m_progressReporter->KeepRefreshing( false );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( m_progressReporter && m_progressReporter->IsCancelled() )
|
|
|
|
return;
|
2017-11-23 16:20:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
m_connClusters = SearchClusters( CSM_CONNECTIVITY_CHECK );
|
|
|
|
|
2020-10-26 12:50:12 +00:00
|
|
|
for( CN_ZONE_ISOLATED_ISLAND_LIST& zone : aZones )
|
2017-11-23 16:20:27 +00:00
|
|
|
{
|
2020-07-01 02:21:59 +00:00
|
|
|
for( PCB_LAYER_ID layer : zone.m_zone->GetLayerSet().Seq() )
|
2017-11-23 16:20:27 +00:00
|
|
|
{
|
2022-02-15 17:34:38 +00:00
|
|
|
if( zone.m_zone->GetFilledPolysList( layer )->IsEmpty() )
|
2020-07-01 02:21:59 +00:00
|
|
|
continue;
|
|
|
|
|
2022-02-13 11:54:41 +00:00
|
|
|
for( const std::shared_ptr<CN_CLUSTER>& cluster : m_connClusters )
|
2017-11-23 16:20:27 +00:00
|
|
|
{
|
2020-07-01 02:21:59 +00:00
|
|
|
if( cluster->Contains( zone.m_zone ) && cluster->IsOrphaned() )
|
2017-11-23 16:20:27 +00:00
|
|
|
{
|
2020-10-26 12:50:12 +00:00
|
|
|
for( CN_ITEM* z : *cluster )
|
2020-07-01 02:21:59 +00:00
|
|
|
{
|
|
|
|
if( z->Parent() == zone.m_zone && z->Layer() == layer )
|
|
|
|
{
|
|
|
|
zone.m_islands[layer].push_back(
|
2020-09-23 19:02:21 +00:00
|
|
|
static_cast<CN_ZONE_LAYER*>( z )->SubpolyIndex() );
|
2020-07-01 02:21:59 +00:00
|
|
|
}
|
|
|
|
}
|
2017-11-23 16:20:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-23 11:56:28 +00:00
|
|
|
|
2017-03-22 13:43:10 +00:00
|
|
|
const CN_CONNECTIVITY_ALGO::CLUSTERS& CN_CONNECTIVITY_ALGO::GetClusters()
|
|
|
|
{
|
|
|
|
m_ratsnestClusters = SearchClusters( CSM_RATSNEST );
|
|
|
|
return m_ratsnestClusters;
|
2017-06-23 11:56:28 +00:00
|
|
|
}
|
|
|
|
|
2017-03-22 13:43:10 +00:00
|
|
|
|
2017-07-01 21:54:17 +00:00
|
|
|
void CN_CONNECTIVITY_ALGO::MarkNetAsDirty( int aNet )
|
2017-03-22 13:43:10 +00:00
|
|
|
{
|
2017-07-01 21:54:17 +00:00
|
|
|
if( aNet < 0 )
|
2017-03-22 13:43:10 +00:00
|
|
|
return;
|
|
|
|
|
2017-06-23 17:22:44 +00:00
|
|
|
if( (int) m_dirtyNets.size() <= aNet )
|
2018-04-06 12:57:12 +00:00
|
|
|
{
|
|
|
|
int lastNet = m_dirtyNets.size() - 1;
|
|
|
|
|
|
|
|
if( lastNet < 0 )
|
|
|
|
lastNet = 0;
|
|
|
|
|
2017-06-23 11:56:28 +00:00
|
|
|
m_dirtyNets.resize( aNet + 1 );
|
|
|
|
|
2018-04-06 12:57:12 +00:00
|
|
|
for( int i = lastNet; i < aNet + 1; i++ )
|
|
|
|
m_dirtyNets[i] = true;
|
|
|
|
}
|
|
|
|
|
2017-06-23 11:56:28 +00:00
|
|
|
m_dirtyNets[aNet] = true;
|
2017-03-22 13:43:10 +00:00
|
|
|
}
|
|
|
|
|
2017-06-23 11:56:28 +00:00
|
|
|
|
2020-09-23 19:02:21 +00:00
|
|
|
void CN_VISITOR::checkZoneItemConnection( CN_ZONE_LAYER* aZoneLayer, CN_ITEM* aItem )
|
2018-05-21 00:06:01 +00:00
|
|
|
{
|
2020-09-23 19:02:21 +00:00
|
|
|
if( aZoneLayer->Net() != aItem->Net() && !aItem->CanChangeNet() )
|
2019-08-23 16:43:34 +00:00
|
|
|
return;
|
2018-05-21 00:06:01 +00:00
|
|
|
|
2022-02-14 13:34:45 +00:00
|
|
|
PCB_LAYER_ID layer = aZoneLayer->GetLayer();
|
|
|
|
|
|
|
|
if( !aItem->Parent()->IsOnLayer( layer ) )
|
|
|
|
return;
|
|
|
|
|
2022-02-15 18:15:22 +00:00
|
|
|
auto connect =
|
|
|
|
[&]()
|
|
|
|
{
|
|
|
|
aZoneLayer->Connect( aItem );
|
|
|
|
aItem->Connect( aZoneLayer );
|
|
|
|
};
|
|
|
|
|
|
|
|
// Try quick checks first...
|
|
|
|
for( int i = 0; i < aItem->AnchorCount(); ++i )
|
2020-09-23 19:02:21 +00:00
|
|
|
{
|
2022-02-15 18:15:22 +00:00
|
|
|
if( aZoneLayer->ContainsPoint( aItem->GetAnchor( i ) ) )
|
|
|
|
{
|
|
|
|
connect();
|
|
|
|
return;
|
|
|
|
}
|
2018-05-21 00:06:01 +00:00
|
|
|
}
|
2022-02-15 18:15:22 +00:00
|
|
|
|
2022-03-16 23:48:24 +00:00
|
|
|
if( aItem->Parent()->Type() == PCB_VIA_T || aItem->Parent()->Type() == PCB_PAD_T )
|
|
|
|
{
|
|
|
|
// As long as the pad/via crosses the zone layer, check for the full effective shape
|
|
|
|
// We check for the overlapping layers above
|
|
|
|
if( aZoneLayer->Collide( aItem->Parent()->GetEffectiveShape( layer, FLASHING::ALWAYS_FLASHED ).get() ) )
|
|
|
|
connect();
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-02-15 18:15:22 +00:00
|
|
|
if( aZoneLayer->Collide( aItem->Parent()->GetEffectiveShape( layer ).get() ) )
|
|
|
|
connect();
|
2018-05-21 00:06:01 +00:00
|
|
|
}
|
|
|
|
|
2020-09-23 19:02:21 +00:00
|
|
|
void CN_VISITOR::checkZoneZoneConnection( CN_ZONE_LAYER* aZoneLayerA, CN_ZONE_LAYER* aZoneLayerB )
|
2018-05-21 00:06:01 +00:00
|
|
|
{
|
2022-02-14 01:07:25 +00:00
|
|
|
const ZONE* zoneA = static_cast<const ZONE*>( aZoneLayerA->Parent() );
|
|
|
|
const ZONE* zoneB = static_cast<const ZONE*>( aZoneLayerB->Parent() );
|
|
|
|
|
2020-09-23 19:02:21 +00:00
|
|
|
if( aZoneLayerB->Net() != aZoneLayerA->Net() )
|
2018-05-21 00:06:01 +00:00
|
|
|
return; // we only test zones belonging to the same net
|
|
|
|
|
2020-09-23 19:02:21 +00:00
|
|
|
const BOX2I& boxA = aZoneLayerA->BBox();
|
|
|
|
const BOX2I& boxB = aZoneLayerB->BBox();
|
2020-08-07 22:57:59 +00:00
|
|
|
|
2022-02-14 13:34:45 +00:00
|
|
|
PCB_LAYER_ID layer = aZoneLayerA->GetLayer();
|
|
|
|
|
|
|
|
if( aZoneLayerB->GetLayer() != layer )
|
2022-02-13 00:29:12 +00:00
|
|
|
return;
|
2018-05-21 00:06:01 +00:00
|
|
|
|
2022-02-14 13:34:45 +00:00
|
|
|
if( !boxA.Intersects( boxB ) )
|
|
|
|
return;
|
2020-08-07 22:57:59 +00:00
|
|
|
|
2022-02-14 01:07:25 +00:00
|
|
|
const SHAPE_LINE_CHAIN& outline =
|
2022-02-15 17:34:38 +00:00
|
|
|
zoneA->GetFilledPolysList( layer )->COutline( aZoneLayerA->SubpolyIndex() );
|
2022-02-14 01:07:25 +00:00
|
|
|
|
|
|
|
for( int i = 0; i < outline.PointCount(); i++ )
|
|
|
|
{
|
|
|
|
if( !boxB.Contains( outline.CPoint( i ) ) )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if( aZoneLayerB->ContainsPoint( outline.CPoint( i ) ) )
|
|
|
|
{
|
|
|
|
aZoneLayerA->Connect( aZoneLayerB );
|
|
|
|
aZoneLayerB->Connect( aZoneLayerA );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const SHAPE_LINE_CHAIN& outline2 =
|
2022-02-15 17:34:38 +00:00
|
|
|
zoneB->GetFilledPolysList( layer )->COutline( aZoneLayerB->SubpolyIndex() );
|
2022-02-14 01:07:25 +00:00
|
|
|
|
|
|
|
for( int i = 0; i < outline2.PointCount(); i++ )
|
2020-09-23 19:02:21 +00:00
|
|
|
{
|
2022-02-14 01:07:25 +00:00
|
|
|
if( !boxA.Contains( outline2.CPoint( i ) ) )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if( aZoneLayerA->ContainsPoint( outline2.CPoint( i ) ) )
|
|
|
|
{
|
|
|
|
aZoneLayerA->Connect( aZoneLayerB );
|
|
|
|
aZoneLayerB->Connect( aZoneLayerA );
|
|
|
|
return;
|
|
|
|
}
|
2018-05-21 00:06:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool CN_VISITOR::operator()( CN_ITEM* aCandidate )
|
|
|
|
{
|
2020-07-25 11:58:17 +00:00
|
|
|
const BOARD_CONNECTED_ITEM* parentA = aCandidate->Parent();
|
|
|
|
const BOARD_CONNECTED_ITEM* parentB = m_item->Parent();
|
2018-05-21 00:06:01 +00:00
|
|
|
|
|
|
|
if( !aCandidate->Valid() || !m_item->Valid() )
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if( parentA == parentB )
|
|
|
|
return true;
|
|
|
|
|
2018-07-06 21:55:25 +00:00
|
|
|
// If both m_item and aCandidate are marked dirty, they will both be searched
|
|
|
|
// Since we are reciprocal in our connection, we arbitrarily pick one of the connections
|
|
|
|
// to conduct the expensive search
|
|
|
|
if( aCandidate->Dirty() && aCandidate < m_item )
|
|
|
|
return true;
|
|
|
|
|
2018-05-21 00:06:01 +00:00
|
|
|
// We should handle zone-zone connection separately
|
2020-11-11 23:05:59 +00:00
|
|
|
if ( parentA->Type() == PCB_ZONE_T && parentB->Type() == PCB_ZONE_T )
|
2018-05-21 00:06:01 +00:00
|
|
|
{
|
2020-09-23 19:02:21 +00:00
|
|
|
checkZoneZoneConnection( static_cast<CN_ZONE_LAYER*>( m_item ),
|
|
|
|
static_cast<CN_ZONE_LAYER*>( aCandidate ) );
|
2018-05-21 00:06:01 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-11-11 23:05:59 +00:00
|
|
|
if( parentA->Type() == PCB_ZONE_T )
|
2018-05-21 00:06:01 +00:00
|
|
|
{
|
2020-09-23 19:02:21 +00:00
|
|
|
checkZoneItemConnection( static_cast<CN_ZONE_LAYER*>( aCandidate ), m_item );
|
2018-05-21 00:06:01 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-11-11 23:05:59 +00:00
|
|
|
if( parentB->Type() == PCB_ZONE_T )
|
2018-05-21 00:06:01 +00:00
|
|
|
{
|
2020-09-23 19:02:21 +00:00
|
|
|
checkZoneItemConnection( static_cast<CN_ZONE_LAYER*>( m_item ), aCandidate );
|
2018-05-21 00:06:01 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2022-02-14 13:34:45 +00:00
|
|
|
LSET commonLayers = parentA->GetLayerSet() & parentB->GetLayerSet();
|
|
|
|
|
2022-02-11 00:28:21 +00:00
|
|
|
for( PCB_LAYER_ID layer : commonLayers.Seq() )
|
2019-09-19 19:43:24 +00:00
|
|
|
{
|
2022-03-16 23:48:24 +00:00
|
|
|
FLASHING flashingA = FLASHING::NEVER_FLASHED;
|
|
|
|
FLASHING flashingB = FLASHING::NEVER_FLASHED;
|
|
|
|
|
|
|
|
if( const PAD* pad = dyn_cast<const PAD*>( parentA ) )
|
|
|
|
{
|
|
|
|
if( !pad->GetRemoveUnconnected() || ( ( layer == F_Cu || layer == B_Cu ) && pad->GetKeepTopBottom() ) )
|
|
|
|
flashingA = FLASHING::ALWAYS_FLASHED;
|
|
|
|
}
|
|
|
|
else if( const PCB_VIA* via = dyn_cast<const PCB_VIA*>( parentA ) )
|
|
|
|
{
|
|
|
|
if( !via->GetRemoveUnconnected() || ( ( layer == F_Cu || layer == B_Cu ) && via->GetKeepTopBottom() ) )
|
|
|
|
flashingA = FLASHING::ALWAYS_FLASHED;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( const PAD* pad = dyn_cast<const PAD*>( parentB ) )
|
|
|
|
{
|
|
|
|
if( !pad->GetRemoveUnconnected() || ( ( layer == F_Cu || layer == B_Cu ) && pad->GetKeepTopBottom() ) )
|
|
|
|
flashingB = FLASHING::ALWAYS_FLASHED;
|
|
|
|
}
|
|
|
|
else if( const PCB_VIA* via = dyn_cast<const PCB_VIA*>( parentB ) )
|
|
|
|
{
|
|
|
|
if( !via->GetRemoveUnconnected() || ( ( layer == F_Cu || layer == B_Cu ) && via->GetKeepTopBottom() ) )
|
|
|
|
flashingB = FLASHING::ALWAYS_FLASHED;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( parentA->GetEffectiveShape( layer, flashingA )->Collide(
|
|
|
|
parentB->GetEffectiveShape( layer, flashingB ).get() ) )
|
2019-09-19 19:43:24 +00:00
|
|
|
{
|
|
|
|
m_item->Connect( aCandidate );
|
|
|
|
aCandidate->Connect( m_item );
|
|
|
|
return true;
|
|
|
|
}
|
2018-05-21 00:06:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2017-03-22 13:43:10 +00:00
|
|
|
void CN_CONNECTIVITY_ALGO::Clear()
|
|
|
|
{
|
|
|
|
m_ratsnestClusters.clear();
|
|
|
|
m_connClusters.clear();
|
|
|
|
m_itemMap.clear();
|
2018-05-21 00:06:01 +00:00
|
|
|
m_itemList.Clear();
|
2017-03-22 13:43:10 +00:00
|
|
|
|
|
|
|
}
|
2017-03-28 16:30:49 +00:00
|
|
|
|
2017-11-23 16:20:27 +00:00
|
|
|
void CN_CONNECTIVITY_ALGO::SetProgressReporter( PROGRESS_REPORTER* aReporter )
|
|
|
|
{
|
|
|
|
m_progressReporter = aReporter;
|
|
|
|
}
|