2017-03-22 13:43:10 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KICAD, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2017 CERN
|
|
|
|
* @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-09-20 02:10:12 +00:00
|
|
|
|
2017-03-22 13:43:10 +00:00
|
|
|
#ifdef PROFILE
|
|
|
|
#include <profile.h>
|
|
|
|
#endif
|
|
|
|
|
2018-09-20 02:10:12 +00:00
|
|
|
#include <thread>
|
2018-10-12 12:54:21 +00:00
|
|
|
#include <algorithm>
|
2018-10-25 11:20:12 +00:00
|
|
|
#include <future>
|
2018-09-20 02:10:12 +00:00
|
|
|
|
2018-10-12 06:17:15 +00:00
|
|
|
#include <connectivity/connectivity_data.h>
|
|
|
|
#include <connectivity/connectivity_algo.h>
|
2017-03-22 13:43:10 +00:00
|
|
|
#include <ratsnest_data.h>
|
|
|
|
|
|
|
|
CONNECTIVITY_DATA::CONNECTIVITY_DATA()
|
|
|
|
{
|
|
|
|
m_connAlgo.reset( new CN_CONNECTIVITY_ALGO );
|
2018-01-06 05:02:28 +00:00
|
|
|
m_progressReporter = nullptr;
|
2017-03-22 13:43:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-10-24 14:40:59 +00:00
|
|
|
CONNECTIVITY_DATA::CONNECTIVITY_DATA( const std::vector<BOARD_ITEM*>& aItems )
|
|
|
|
{
|
|
|
|
Build( aItems );
|
|
|
|
m_progressReporter = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-03-22 13:43:10 +00:00
|
|
|
CONNECTIVITY_DATA::~CONNECTIVITY_DATA()
|
|
|
|
{
|
|
|
|
Clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool CONNECTIVITY_DATA::Add( BOARD_ITEM* aItem )
|
|
|
|
{
|
|
|
|
m_connAlgo->Add( aItem );
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool CONNECTIVITY_DATA::Remove( BOARD_ITEM* aItem )
|
|
|
|
{
|
|
|
|
m_connAlgo->Remove( aItem );
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool CONNECTIVITY_DATA::Update( BOARD_ITEM* aItem )
|
|
|
|
{
|
|
|
|
m_connAlgo->Remove( aItem );
|
|
|
|
m_connAlgo->Add( aItem );
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CONNECTIVITY_DATA::Build( BOARD* aBoard )
|
|
|
|
{
|
|
|
|
m_connAlgo.reset( new CN_CONNECTIVITY_ALGO );
|
|
|
|
m_connAlgo->Build( aBoard );
|
|
|
|
RecalculateRatsnest();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CONNECTIVITY_DATA::Build( const std::vector<BOARD_ITEM*>& aItems )
|
|
|
|
{
|
|
|
|
m_connAlgo.reset( new CN_CONNECTIVITY_ALGO );
|
|
|
|
m_connAlgo->Build( aItems );
|
|
|
|
|
|
|
|
RecalculateRatsnest();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CONNECTIVITY_DATA::updateRatsnest()
|
|
|
|
{
|
|
|
|
#ifdef PROFILE
|
|
|
|
PROF_COUNTER rnUpdate( "update-ratsnest" );
|
|
|
|
#endif
|
2018-10-18 00:05:30 +00:00
|
|
|
std::vector<RN_NET*> dirty_nets;
|
2017-03-22 13:43:10 +00:00
|
|
|
|
2018-10-21 14:31:07 +00:00
|
|
|
// Start with net 1 as net 0 is reserved for not-connected
|
2018-10-25 11:20:12 +00:00
|
|
|
// Nets without nodes are also ignored
|
2018-10-18 00:05:30 +00:00
|
|
|
std::copy_if( m_nets.begin() + 1, m_nets.end(), std::back_inserter( dirty_nets ),
|
2018-10-25 11:20:12 +00:00
|
|
|
[] ( RN_NET* aNet ) { return aNet->IsDirty() && aNet->GetNodeCount() > 0; } );
|
|
|
|
|
|
|
|
// We don't want to spin up a new thread for fewer than 8 nets (overhead costs)
|
|
|
|
size_t parallelThreadCount = std::min<size_t>( std::thread::hardware_concurrency(),
|
|
|
|
( dirty_nets.size() + 7 ) / 8 );
|
2017-03-22 13:43:10 +00:00
|
|
|
|
2018-10-21 14:31:07 +00:00
|
|
|
std::atomic<size_t> nextNet( 0 );
|
2018-10-25 11:20:12 +00:00
|
|
|
std::vector<std::future<size_t>> returns( parallelThreadCount );
|
2018-09-20 02:10:12 +00:00
|
|
|
|
2018-10-25 11:20:12 +00:00
|
|
|
auto update_lambda = [&nextNet, &dirty_nets]() -> size_t
|
2018-10-21 14:31:07 +00:00
|
|
|
{
|
2018-10-24 12:19:13 +00:00
|
|
|
for( size_t i = nextNet++; i < dirty_nets.size(); i = nextNet++ )
|
2018-10-21 14:31:07 +00:00
|
|
|
dirty_nets[i]->Update();
|
2018-09-20 02:10:12 +00:00
|
|
|
|
2018-10-25 11:20:12 +00:00
|
|
|
return 1;
|
2018-10-21 14:31:07 +00:00
|
|
|
};
|
2018-09-20 02:10:12 +00:00
|
|
|
|
2018-10-05 12:15:50 +00:00
|
|
|
if( parallelThreadCount == 1 )
|
|
|
|
update_lambda();
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for( size_t ii = 0; ii < parallelThreadCount; ++ii )
|
2018-10-27 05:30:06 +00:00
|
|
|
returns[ii] = std::async( std::launch::async, update_lambda );
|
2018-09-20 02:10:12 +00:00
|
|
|
|
2018-10-25 11:20:12 +00:00
|
|
|
// Finalize the ratsnest threads
|
|
|
|
for( size_t ii = 0; ii < parallelThreadCount; ++ii )
|
|
|
|
returns[ii].wait();
|
|
|
|
}
|
2017-06-23 11:56:28 +00:00
|
|
|
|
2017-03-22 13:43:10 +00:00
|
|
|
#ifdef PROFILE
|
|
|
|
rnUpdate.Show();
|
|
|
|
#endif /* PROFILE */
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-09-23 09:20:10 +00:00
|
|
|
void CONNECTIVITY_DATA::addRatsnestCluster( const std::shared_ptr<CN_CLUSTER>& aCluster )
|
2017-03-22 13:43:10 +00:00
|
|
|
{
|
|
|
|
auto rnNet = m_nets[ aCluster->OriginNet() ];
|
|
|
|
|
|
|
|
rnNet->AddCluster( aCluster );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CONNECTIVITY_DATA::RecalculateRatsnest()
|
|
|
|
{
|
2017-04-18 15:32:05 +00:00
|
|
|
m_connAlgo->PropagateNets();
|
|
|
|
|
2017-03-22 13:43:10 +00:00
|
|
|
int lastNet = m_connAlgo->NetCount();
|
|
|
|
|
|
|
|
if( lastNet >= (int) m_nets.size() )
|
|
|
|
{
|
|
|
|
unsigned int prevSize = m_nets.size();
|
|
|
|
m_nets.resize( lastNet + 1 );
|
|
|
|
|
|
|
|
for( unsigned int i = prevSize; i < m_nets.size(); i++ )
|
|
|
|
m_nets[i] = new RN_NET;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto clusters = m_connAlgo->GetClusters();
|
|
|
|
|
|
|
|
int dirtyNets = 0;
|
|
|
|
|
|
|
|
for( int net = 0; net < lastNet; net++ )
|
2017-06-30 11:40:20 +00:00
|
|
|
{
|
2017-03-22 13:43:10 +00:00
|
|
|
if( m_connAlgo->IsNetDirty( net ) )
|
|
|
|
{
|
|
|
|
m_nets[net]->Clear();
|
|
|
|
dirtyNets++;
|
|
|
|
}
|
2017-06-30 11:40:20 +00:00
|
|
|
}
|
2017-03-22 13:51:07 +00:00
|
|
|
|
2017-03-22 13:43:10 +00:00
|
|
|
for( auto c : clusters )
|
|
|
|
{
|
|
|
|
int net = c->OriginNet();
|
|
|
|
|
|
|
|
if( m_connAlgo->IsNetDirty( net ) )
|
|
|
|
{
|
|
|
|
addRatsnestCluster( c );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
m_connAlgo->ClearDirtyFlags();
|
|
|
|
|
|
|
|
updateRatsnest();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-03-22 13:51:07 +00:00
|
|
|
void CONNECTIVITY_DATA::BlockRatsnestItems( const std::vector<BOARD_ITEM*>& aItems )
|
2017-03-22 13:43:10 +00:00
|
|
|
{
|
|
|
|
std::vector<BOARD_CONNECTED_ITEM*> citems;
|
|
|
|
|
|
|
|
for( auto item : aItems )
|
|
|
|
{
|
|
|
|
if( item->Type() == PCB_MODULE_T )
|
|
|
|
{
|
2017-04-25 09:06:24 +00:00
|
|
|
for( auto pad : static_cast<MODULE*>(item)->Pads() )
|
2017-03-22 13:43:10 +00:00
|
|
|
citems.push_back( pad );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
citems.push_back( static_cast<BOARD_CONNECTED_ITEM*>(item) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for( auto item : citems )
|
|
|
|
{
|
2017-09-28 16:38:54 +00:00
|
|
|
if ( m_connAlgo->ItemExists( item ) )
|
2017-03-22 13:43:10 +00:00
|
|
|
{
|
2017-09-28 16:38:54 +00:00
|
|
|
auto& entry = m_connAlgo->ItemEntry( item );
|
|
|
|
|
|
|
|
for( auto cnItem : entry.GetItems() )
|
|
|
|
{
|
|
|
|
for( auto anchor : cnItem->Anchors() )
|
|
|
|
anchor->SetNoLine( true );
|
|
|
|
}
|
2017-03-22 13:43:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int CONNECTIVITY_DATA::GetNetCount() const
|
|
|
|
{
|
|
|
|
return m_connAlgo->NetCount();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CONNECTIVITY_DATA::FindIsolatedCopperIslands( ZONE_CONTAINER* aZone,
|
|
|
|
std::vector<int>& aIslands )
|
|
|
|
{
|
|
|
|
m_connAlgo->FindIsolatedCopperIslands( aZone, aIslands );
|
|
|
|
}
|
|
|
|
|
2017-11-23 16:20:27 +00:00
|
|
|
void CONNECTIVITY_DATA::FindIsolatedCopperIslands( std::vector<CN_ZONE_ISOLATED_ISLAND_LIST>& aZones )
|
|
|
|
{
|
|
|
|
m_connAlgo->FindIsolatedCopperIslands( aZones );
|
|
|
|
}
|
2017-03-22 13:43:10 +00:00
|
|
|
|
2018-06-25 14:29:20 +00:00
|
|
|
|
2017-03-22 13:43:10 +00:00
|
|
|
void CONNECTIVITY_DATA::ComputeDynamicRatsnest( const std::vector<BOARD_ITEM*>& aItems )
|
|
|
|
{
|
2018-10-24 14:40:59 +00:00
|
|
|
m_dynamicRatsnest.clear();
|
|
|
|
|
2018-10-12 12:54:21 +00:00
|
|
|
if( std::none_of( aItems.begin(), aItems.end(), []( const BOARD_ITEM* aItem )
|
|
|
|
{ return( aItem->Type() == PCB_TRACE_T || aItem->Type() == PCB_PAD_T ||
|
2018-10-24 14:40:59 +00:00
|
|
|
aItem->Type() == PCB_ZONE_AREA_T || aItem->Type() == PCB_MODULE_T ||
|
|
|
|
aItem->Type() == PCB_VIA_T ); } ) )
|
2018-06-25 14:29:20 +00:00
|
|
|
{
|
|
|
|
return ;
|
|
|
|
}
|
|
|
|
|
2018-10-24 14:40:59 +00:00
|
|
|
CONNECTIVITY_DATA connData( aItems );
|
2017-03-22 13:51:07 +00:00
|
|
|
BlockRatsnestItems( aItems );
|
2017-03-22 13:43:10 +00:00
|
|
|
|
2018-10-24 14:40:59 +00:00
|
|
|
for( unsigned int nc = 1; nc < connData.m_nets.size(); nc++ )
|
2017-03-22 13:43:10 +00:00
|
|
|
{
|
2018-10-24 14:40:59 +00:00
|
|
|
auto dynNet = connData.m_nets[nc];
|
2017-03-22 13:43:10 +00:00
|
|
|
|
|
|
|
if( dynNet->GetNodeCount() != 0 )
|
|
|
|
{
|
|
|
|
auto ourNet = m_nets[nc];
|
|
|
|
CN_ANCHOR_PTR nodeA, nodeB;
|
|
|
|
|
|
|
|
if( ourNet->NearestBicoloredPair( *dynNet, nodeA, nodeB ) )
|
|
|
|
{
|
|
|
|
RN_DYNAMIC_LINE l;
|
|
|
|
l.a = nodeA->Pos();
|
|
|
|
l.b = nodeB->Pos();
|
|
|
|
l.netCode = nc;
|
|
|
|
|
|
|
|
m_dynamicRatsnest.push_back( l );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-24 14:40:59 +00:00
|
|
|
for( auto net : connData.m_nets )
|
2017-03-22 13:43:10 +00:00
|
|
|
{
|
|
|
|
if( !net )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
const auto& edges = net->GetUnconnected();
|
|
|
|
|
|
|
|
if( edges.empty() )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
for( const auto& edge : edges )
|
|
|
|
{
|
|
|
|
const auto& nodeA = edge.GetSourceNode();
|
|
|
|
const auto& nodeB = edge.GetTargetNode();
|
|
|
|
RN_DYNAMIC_LINE l;
|
|
|
|
|
|
|
|
l.a = nodeA->Pos();
|
|
|
|
l.b = nodeB->Pos();
|
|
|
|
l.netCode = 0;
|
|
|
|
m_dynamicRatsnest.push_back( l );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CONNECTIVITY_DATA::ClearDynamicRatsnest()
|
|
|
|
{
|
2017-09-23 09:20:10 +00:00
|
|
|
m_connAlgo->ForEachAnchor( [] ( CN_ANCHOR& anchor ) { anchor.SetNoLine( false ); } );
|
2017-08-01 13:20:40 +00:00
|
|
|
HideDynamicRatsnest();
|
|
|
|
}
|
|
|
|
|
2017-03-28 16:30:49 +00:00
|
|
|
|
2017-08-01 13:20:40 +00:00
|
|
|
void CONNECTIVITY_DATA::HideDynamicRatsnest()
|
|
|
|
{
|
2017-03-22 13:43:10 +00:00
|
|
|
m_dynamicRatsnest.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CONNECTIVITY_DATA::PropagateNets()
|
|
|
|
{
|
|
|
|
m_connAlgo->PropagateNets();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
unsigned int CONNECTIVITY_DATA::GetUnconnectedCount() const
|
|
|
|
{
|
|
|
|
unsigned int unconnected = 0;
|
|
|
|
|
|
|
|
for( auto net : m_nets )
|
|
|
|
{
|
|
|
|
if( !net )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
const auto& edges = net->GetUnconnected();
|
|
|
|
|
|
|
|
if( edges.empty() )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
unconnected += edges.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
return unconnected;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CONNECTIVITY_DATA::Clear()
|
|
|
|
{
|
|
|
|
for( auto net : m_nets )
|
|
|
|
delete net;
|
|
|
|
|
|
|
|
m_nets.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-11-15 17:33:06 +00:00
|
|
|
const std::vector<BOARD_CONNECTED_ITEM*> CONNECTIVITY_DATA::GetConnectedItems(
|
2017-03-22 13:43:10 +00:00
|
|
|
const BOARD_CONNECTED_ITEM* aItem,
|
|
|
|
const KICAD_T aTypes[] ) const
|
|
|
|
{
|
2017-11-15 17:33:06 +00:00
|
|
|
std::vector<BOARD_CONNECTED_ITEM*> rv;
|
2017-03-22 13:51:07 +00:00
|
|
|
const auto clusters = m_connAlgo->SearchClusters( CN_CONNECTIVITY_ALGO::CSM_CONNECTIVITY_CHECK,
|
|
|
|
aTypes, aItem->GetNetCode() );
|
2017-03-22 13:43:10 +00:00
|
|
|
|
2017-03-22 13:51:07 +00:00
|
|
|
for( auto cl : clusters )
|
2017-06-23 11:56:28 +00:00
|
|
|
{
|
2017-03-22 13:51:07 +00:00
|
|
|
if( cl->Contains( aItem ) )
|
2017-03-22 13:43:10 +00:00
|
|
|
{
|
2017-03-22 13:51:07 +00:00
|
|
|
for( const auto item : *cl )
|
2017-07-21 09:40:26 +00:00
|
|
|
{
|
|
|
|
if( item->Valid() )
|
|
|
|
rv.push_back( item->Parent() );
|
|
|
|
}
|
2017-03-22 13:43:10 +00:00
|
|
|
}
|
2017-06-23 11:56:28 +00:00
|
|
|
}
|
2017-03-22 13:51:07 +00:00
|
|
|
|
2017-03-22 13:43:10 +00:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-11-15 17:33:06 +00:00
|
|
|
const std::vector<BOARD_CONNECTED_ITEM*> CONNECTIVITY_DATA::GetNetItems( int aNetCode,
|
2017-03-22 13:43:10 +00:00
|
|
|
const KICAD_T aTypes[] ) const
|
|
|
|
{
|
2017-06-23 11:56:28 +00:00
|
|
|
std::set<BOARD_CONNECTED_ITEM*> items;
|
2017-11-15 17:33:06 +00:00
|
|
|
std::vector<BOARD_CONNECTED_ITEM*> rv;
|
2017-05-04 22:43:43 +00:00
|
|
|
|
2017-09-23 09:20:10 +00:00
|
|
|
m_connAlgo->ForEachItem( [&items, aNetCode, &aTypes] ( CN_ITEM& aItem )
|
2017-07-17 08:19:36 +00:00
|
|
|
{
|
2017-09-23 09:20:10 +00:00
|
|
|
if( aItem.Valid() && ( aItem.Net() == aNetCode ) )
|
2017-07-17 08:19:36 +00:00
|
|
|
{
|
2017-09-23 09:20:10 +00:00
|
|
|
KICAD_T itemType = aItem.Parent()->Type();
|
2017-07-17 08:19:36 +00:00
|
|
|
|
|
|
|
for( int i = 0; aTypes[i] > 0; ++i )
|
|
|
|
{
|
|
|
|
wxASSERT( aTypes[i] < MAX_STRUCT_TYPE_ID );
|
|
|
|
|
|
|
|
if( itemType == aTypes[i] )
|
|
|
|
{
|
2017-09-23 09:20:10 +00:00
|
|
|
items.insert( aItem.Parent() );
|
2017-07-17 08:19:36 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-05-04 22:43:43 +00:00
|
|
|
} );
|
2017-03-22 13:59:30 +00:00
|
|
|
|
2017-11-15 17:33:06 +00:00
|
|
|
std::copy( items.begin(), items.end(), std::back_inserter( rv ) );
|
2017-05-04 22:43:43 +00:00
|
|
|
|
|
|
|
return rv;
|
2017-03-22 13:43:10 +00:00
|
|
|
}
|
|
|
|
|
2017-03-22 13:51:07 +00:00
|
|
|
|
2017-03-22 13:43:10 +00:00
|
|
|
bool CONNECTIVITY_DATA::CheckConnectivity( std::vector<CN_DISJOINT_NET_ENTRY>& aReport )
|
|
|
|
{
|
|
|
|
RecalculateRatsnest();
|
|
|
|
|
2017-03-22 13:51:07 +00:00
|
|
|
for( auto net : m_nets )
|
2017-03-22 13:43:10 +00:00
|
|
|
{
|
2017-03-22 13:51:07 +00:00
|
|
|
if( net )
|
2017-03-22 13:43:10 +00:00
|
|
|
{
|
2017-03-22 13:51:07 +00:00
|
|
|
for( const auto& edge : net->GetEdges() )
|
2017-03-22 13:43:10 +00:00
|
|
|
{
|
|
|
|
CN_DISJOINT_NET_ENTRY ent;
|
|
|
|
ent.net = edge.GetSourceNode()->Parent()->GetNetCode();
|
2017-03-22 13:51:07 +00:00
|
|
|
ent.a = edge.GetSourceNode()->Parent();
|
|
|
|
ent.b = edge.GetTargetNode()->Parent();
|
2017-03-22 13:43:10 +00:00
|
|
|
ent.anchorA = edge.GetSourceNode()->Pos();
|
|
|
|
ent.anchorB = edge.GetTargetNode()->Pos();
|
|
|
|
aReport.push_back( ent );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-03-22 13:51:07 +00:00
|
|
|
|
2017-03-22 13:43:10 +00:00
|
|
|
return aReport.empty();
|
|
|
|
}
|
2017-03-22 13:51:07 +00:00
|
|
|
|
|
|
|
|
2017-06-23 11:56:28 +00:00
|
|
|
const std::vector<TRACK*> CONNECTIVITY_DATA::GetConnectedTracks( const BOARD_CONNECTED_ITEM* aItem )
|
2017-03-22 13:51:07 +00:00
|
|
|
const
|
|
|
|
{
|
|
|
|
auto& entry = m_connAlgo->ItemEntry( aItem );
|
|
|
|
|
|
|
|
std::set<TRACK*> tracks;
|
|
|
|
std::vector<TRACK*> rv;
|
|
|
|
|
|
|
|
for( auto citem : entry.GetItems() )
|
|
|
|
{
|
|
|
|
for( auto connected : citem->ConnectedItems() )
|
|
|
|
{
|
2017-07-21 09:40:26 +00:00
|
|
|
if( connected->Valid() && ( connected->Parent()->Type() == PCB_TRACE_T || connected->Parent()->Type() == PCB_VIA_T ) )
|
2017-03-22 13:51:07 +00:00
|
|
|
tracks.insert( static_cast<TRACK*> ( connected->Parent() ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
std::copy( tracks.begin(), tracks.end(), std::back_inserter( rv ) );
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-08-19 16:11:58 +00:00
|
|
|
const void CONNECTIVITY_DATA::GetConnectedPads( const BOARD_CONNECTED_ITEM* aItem,
|
|
|
|
std::set<D_PAD*>* pads ) const
|
2017-03-22 13:51:07 +00:00
|
|
|
{
|
2018-08-19 16:11:58 +00:00
|
|
|
for( auto citem : m_connAlgo->ItemEntry( aItem ).GetItems() )
|
2017-03-22 13:51:07 +00:00
|
|
|
{
|
|
|
|
for( auto connected : citem->ConnectedItems() )
|
|
|
|
{
|
2017-06-22 14:24:07 +00:00
|
|
|
if( connected->Valid() && connected->Parent()->Type() == PCB_PAD_T )
|
2018-08-19 16:11:58 +00:00
|
|
|
pads->insert( static_cast<D_PAD*> ( connected->Parent() ) );
|
2017-03-22 13:51:07 +00:00
|
|
|
}
|
|
|
|
}
|
2018-08-19 16:11:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const std::vector<D_PAD*> CONNECTIVITY_DATA::GetConnectedPads( const BOARD_CONNECTED_ITEM* aItem )
|
|
|
|
const
|
|
|
|
{
|
|
|
|
std::set<D_PAD*> pads;
|
|
|
|
std::vector<D_PAD*> rv;
|
|
|
|
|
|
|
|
GetConnectedPads( aItem, &pads );
|
2017-03-22 13:51:07 +00:00
|
|
|
|
|
|
|
std::copy( pads.begin(), pads.end(), std::back_inserter( rv ) );
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
unsigned int CONNECTIVITY_DATA::GetNodeCount( int aNet ) const
|
|
|
|
{
|
2017-06-23 12:41:51 +00:00
|
|
|
int sum = 0;
|
|
|
|
|
2017-06-30 11:40:20 +00:00
|
|
|
if( aNet < 0 ) // Node count for all nets
|
2017-06-23 12:41:51 +00:00
|
|
|
{
|
2017-06-23 17:22:44 +00:00
|
|
|
for( const auto& net : m_nets )
|
2017-06-23 12:41:51 +00:00
|
|
|
sum += net->GetNodeCount();
|
|
|
|
}
|
2017-06-23 17:22:44 +00:00
|
|
|
else if( aNet < (int) m_nets.size() )
|
2017-06-23 12:41:51 +00:00
|
|
|
{
|
|
|
|
sum = m_nets[aNet]->GetNodeCount();
|
|
|
|
}
|
|
|
|
|
|
|
|
return sum;
|
2017-03-22 13:51:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
unsigned int CONNECTIVITY_DATA::GetPadCount( int aNet ) const
|
|
|
|
{
|
2017-04-18 15:32:05 +00:00
|
|
|
int n = 0;
|
|
|
|
|
2018-05-21 00:06:01 +00:00
|
|
|
for( auto pad : m_connAlgo->ItemList() )
|
2017-04-18 15:32:05 +00:00
|
|
|
{
|
2018-05-21 00:06:01 +00:00
|
|
|
if( !pad->Valid() || pad->Parent()->Type() != PCB_PAD_T)
|
2017-07-21 09:40:26 +00:00
|
|
|
continue;
|
|
|
|
|
2017-04-18 15:32:05 +00:00
|
|
|
auto dpad = static_cast<D_PAD*>( pad->Parent() );
|
2017-06-23 11:56:28 +00:00
|
|
|
|
|
|
|
if( aNet < 0 || aNet == dpad->GetNetCode() )
|
2017-04-18 15:32:05 +00:00
|
|
|
{
|
|
|
|
n++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return n;
|
2017-03-22 13:51:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const std::vector<VECTOR2I> CONNECTIVITY_DATA::NearestUnconnectedTargets(
|
|
|
|
const BOARD_CONNECTED_ITEM* aRef,
|
|
|
|
const VECTOR2I& aPos,
|
|
|
|
int aNet )
|
|
|
|
{
|
|
|
|
CN_CLUSTER_PTR refCluster;
|
|
|
|
int refNet = -1;
|
|
|
|
|
|
|
|
if( aRef )
|
|
|
|
refNet = aRef->GetNetCode();
|
|
|
|
|
|
|
|
if( aNet >= 0 )
|
|
|
|
refNet = aNet;
|
|
|
|
|
|
|
|
if( aRef )
|
|
|
|
{
|
|
|
|
for( auto cl : m_connAlgo->GetClusters() )
|
|
|
|
{
|
|
|
|
if( cl->Contains( aRef ) )
|
|
|
|
{
|
|
|
|
refCluster = cl;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
std::set <VECTOR2I> anchors;
|
|
|
|
|
|
|
|
for( auto cl : m_connAlgo->GetClusters() )
|
|
|
|
{
|
|
|
|
if( cl != refCluster )
|
|
|
|
{
|
|
|
|
for( auto item : *cl )
|
|
|
|
{
|
2017-07-21 09:40:26 +00:00
|
|
|
if( item->Valid() && item->Parent()->GetNetCode() == refNet
|
2017-03-22 13:51:07 +00:00
|
|
|
&& item->Parent()->Type() != PCB_ZONE_AREA_T )
|
2017-06-23 11:56:28 +00:00
|
|
|
{
|
2017-03-22 13:51:07 +00:00
|
|
|
for( auto anchor : item->Anchors() )
|
|
|
|
{
|
|
|
|
anchors.insert( anchor->Pos() );
|
|
|
|
}
|
2017-06-23 11:56:28 +00:00
|
|
|
}
|
2017-03-22 13:51:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
std::vector<VECTOR2I> rv;
|
|
|
|
|
|
|
|
std::copy( anchors.begin(), anchors.end(), std::back_inserter( rv ) );
|
|
|
|
std::sort( rv.begin(), rv.end(), [aPos] ( const VECTOR2I& a, const VECTOR2I& b )
|
|
|
|
{
|
|
|
|
auto da = (a - aPos).EuclideanNorm();
|
|
|
|
auto db = (b - aPos).EuclideanNorm();
|
|
|
|
|
|
|
|
return da < db;
|
|
|
|
} );
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
2017-03-22 15:47:15 +00:00
|
|
|
|
2017-06-23 11:56:28 +00:00
|
|
|
|
2017-03-22 15:47:15 +00:00
|
|
|
void CONNECTIVITY_DATA::GetUnconnectedEdges( std::vector<CN_EDGE>& aEdges) const
|
|
|
|
{
|
2017-06-23 11:56:28 +00:00
|
|
|
for( auto rnNet : m_nets )
|
2017-03-22 15:47:15 +00:00
|
|
|
{
|
2017-06-23 11:56:28 +00:00
|
|
|
if( rnNet )
|
2017-03-22 15:47:15 +00:00
|
|
|
{
|
|
|
|
for( auto edge : rnNet->GetEdges() )
|
|
|
|
{
|
|
|
|
aEdges.push_back( edge );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-06-22 14:24:07 +00:00
|
|
|
|
2017-06-23 11:56:28 +00:00
|
|
|
|
|
|
|
const std::vector<BOARD_CONNECTED_ITEM*> CONNECTIVITY_DATA::GetConnectedItems(
|
|
|
|
const BOARD_CONNECTED_ITEM* aItem, const VECTOR2I& aAnchor, KICAD_T aTypes[] )
|
2017-06-22 14:24:07 +00:00
|
|
|
{
|
|
|
|
auto& entry = m_connAlgo->ItemEntry( aItem );
|
|
|
|
std::vector<BOARD_CONNECTED_ITEM* > rv;
|
|
|
|
|
|
|
|
for( auto cnItem : entry.GetItems() )
|
|
|
|
{
|
|
|
|
for( auto anchor : cnItem->Anchors() )
|
|
|
|
{
|
2017-06-23 11:56:28 +00:00
|
|
|
if( anchor->Pos() == aAnchor )
|
2017-06-22 14:24:07 +00:00
|
|
|
{
|
|
|
|
for( int i = 0; aTypes[i] > 0; i++ )
|
|
|
|
{
|
2017-07-21 09:40:26 +00:00
|
|
|
if( cnItem->Valid() && cnItem->Parent()->Type() == aTypes[i] )
|
2017-06-22 14:24:07 +00:00
|
|
|
{
|
|
|
|
rv.push_back( cnItem->Parent() );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
2017-06-29 22:45:50 +00:00
|
|
|
|
2017-07-17 08:21:36 +00:00
|
|
|
|
2017-06-29 22:45:50 +00:00
|
|
|
RN_NET* CONNECTIVITY_DATA::GetRatsnestForNet( int aNet )
|
|
|
|
{
|
2017-07-17 08:21:36 +00:00
|
|
|
if ( aNet < 0 || aNet >= (int) m_nets.size() )
|
2017-06-29 22:45:50 +00:00
|
|
|
{
|
|
|
|
return nullptr;
|
|
|
|
}
|
2017-07-17 08:21:36 +00:00
|
|
|
|
2017-06-29 22:45:50 +00:00
|
|
|
return m_nets[ aNet ];
|
|
|
|
}
|
2017-07-02 00:05:42 +00:00
|
|
|
|
2017-07-17 08:21:36 +00:00
|
|
|
|
2017-07-02 00:05:42 +00:00
|
|
|
void CONNECTIVITY_DATA::MarkItemNetAsDirty( BOARD_ITEM *aItem )
|
|
|
|
{
|
|
|
|
if (aItem->Type() == PCB_MODULE_T)
|
|
|
|
{
|
|
|
|
for ( auto pad : static_cast<MODULE*>( aItem )->Pads() )
|
|
|
|
{
|
|
|
|
m_connAlgo->MarkNetAsDirty( pad->GetNetCode() );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (aItem->IsConnected() )
|
|
|
|
{
|
|
|
|
m_connAlgo->MarkNetAsDirty( static_cast<BOARD_CONNECTED_ITEM*>( aItem )->GetNetCode() );
|
|
|
|
}
|
|
|
|
}
|
2017-11-23 16:20:27 +00:00
|
|
|
|
2018-08-24 10:54:45 +00:00
|
|
|
|
2017-11-23 16:20:27 +00:00
|
|
|
void CONNECTIVITY_DATA::SetProgressReporter( PROGRESS_REPORTER* aReporter )
|
|
|
|
{
|
|
|
|
m_progressReporter = aReporter;
|
|
|
|
m_connAlgo->SetProgressReporter( m_progressReporter );
|
|
|
|
}
|
2018-08-24 10:54:45 +00:00
|
|
|
|
|
|
|
|
|
|
|
const std::vector<CN_EDGE> CONNECTIVITY_DATA::GetRatsnestForComponent( MODULE* aComponent, bool aSkipInternalConnections )
|
|
|
|
{
|
|
|
|
std::set<int> nets;
|
|
|
|
std::set<D_PAD*> pads;
|
|
|
|
std::vector<CN_EDGE> edges;
|
|
|
|
|
|
|
|
for( auto pad : aComponent->Pads() )
|
|
|
|
{
|
|
|
|
nets.insert( pad->GetNetCode() );
|
|
|
|
pads.insert( pad );
|
|
|
|
}
|
|
|
|
|
|
|
|
for ( auto netcode : nets )
|
|
|
|
{
|
|
|
|
auto net = GetRatsnestForNet( netcode );
|
|
|
|
|
|
|
|
for ( auto edge : net->GetEdges() )
|
|
|
|
{
|
|
|
|
auto srcNode = edge.GetSourceNode();
|
|
|
|
auto dstNode = edge.GetTargetNode();
|
|
|
|
|
|
|
|
auto srcParent = static_cast<D_PAD*>( srcNode->Parent() );
|
|
|
|
auto dstParent = static_cast<D_PAD*>( dstNode->Parent() );
|
|
|
|
|
|
|
|
bool srcFound = ( pads.find(srcParent) != pads.end() );
|
|
|
|
bool dstFound = ( pads.find(dstParent) != pads.end() );
|
|
|
|
|
|
|
|
if ( srcFound && dstFound && !aSkipInternalConnections )
|
|
|
|
{
|
|
|
|
edges.push_back( edge );
|
|
|
|
}
|
|
|
|
else if ( srcFound || dstFound )
|
|
|
|
{
|
|
|
|
edges.push_back( edge );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return edges;
|
|
|
|
}
|