2021-01-27 22:15:38 +00:00
|
|
|
|
2018-10-12 21:29:16 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KICAD, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2016-2018 CERN
|
2021-01-27 22:15:38 +00:00
|
|
|
* Copyright (C) 2019-2021 KiCad Developers, see AUTHORS.txt for contributors.
|
2018-10-12 21:29:16 +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
|
|
|
|
*/
|
|
|
|
|
2020-10-24 12:53:11 +00:00
|
|
|
#include <core/kicad_algo.h>
|
2021-03-20 15:35:37 +00:00
|
|
|
#include <macros.h>
|
2018-10-12 21:29:16 +00:00
|
|
|
#include <connectivity/connectivity_items.h>
|
|
|
|
|
|
|
|
int CN_ITEM::AnchorCount() const
|
|
|
|
{
|
|
|
|
if( !m_valid )
|
|
|
|
return 0;
|
|
|
|
|
2019-08-23 16:43:34 +00:00
|
|
|
switch( m_parent->Type() )
|
|
|
|
{
|
|
|
|
case PCB_PAD_T:
|
|
|
|
return 5; // center, north, south, east and west
|
|
|
|
case PCB_TRACE_T:
|
2019-05-17 00:13:21 +00:00
|
|
|
case PCB_ARC_T:
|
|
|
|
return 2; // start and end
|
2019-08-23 16:43:34 +00:00
|
|
|
default:
|
|
|
|
return 1;
|
|
|
|
}
|
2018-10-12 21:29:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const VECTOR2I CN_ITEM::GetAnchor( int n ) const
|
|
|
|
{
|
2019-08-23 16:43:34 +00:00
|
|
|
VECTOR2I pt0;
|
|
|
|
|
2018-10-12 21:29:16 +00:00
|
|
|
if( !m_valid )
|
2019-08-23 16:43:34 +00:00
|
|
|
return pt0;
|
2018-10-12 21:29:16 +00:00
|
|
|
|
|
|
|
switch( m_parent->Type() )
|
|
|
|
{
|
2019-08-23 16:43:34 +00:00
|
|
|
case PCB_PAD_T:
|
|
|
|
{
|
2020-11-12 22:30:02 +00:00
|
|
|
PAD* pad = static_cast<PAD*>( m_parent );
|
2018-10-12 21:29:16 +00:00
|
|
|
|
2019-08-23 16:43:34 +00:00
|
|
|
if( n == 0 )
|
2019-09-19 20:49:12 +00:00
|
|
|
return VECTOR2I( pad->GetPosition() );
|
2018-10-12 21:29:16 +00:00
|
|
|
|
2019-09-19 20:49:12 +00:00
|
|
|
// ShapePos() is the geometric center (not anchor) for the pad
|
|
|
|
pt0 = pad->ShapePos();
|
2019-08-23 16:43:34 +00:00
|
|
|
VECTOR2I pt1 = pt0;
|
|
|
|
|
|
|
|
switch( pad->GetShape() )
|
|
|
|
{
|
2020-07-25 11:58:17 +00:00
|
|
|
case PAD_SHAPE_TRAPEZOID:
|
|
|
|
// Because the trap delta is applied as +1/2 at one end and -1/2 at the other,
|
|
|
|
// the midpoint is actually unchanged. Therefore all the cardinal points are
|
|
|
|
// the same as for a rectangle.
|
|
|
|
KI_FALLTHROUGH;
|
|
|
|
|
2019-08-23 16:43:34 +00:00
|
|
|
case PAD_SHAPE_RECT:
|
2019-10-31 19:36:54 +00:00
|
|
|
case PAD_SHAPE_CIRCLE:
|
2019-08-23 16:43:34 +00:00
|
|
|
case PAD_SHAPE_OVAL:
|
|
|
|
case PAD_SHAPE_ROUNDRECT:
|
|
|
|
case PAD_SHAPE_CHAMFERED_RECT:
|
2019-10-31 19:36:54 +00:00
|
|
|
switch( n )
|
|
|
|
{
|
|
|
|
case 1: pt1.y -= pad->GetSize().y / 2; break; // North
|
|
|
|
case 2: pt1.y += pad->GetSize().y / 2; break; // South
|
|
|
|
case 3: pt1.x -= pad->GetSize().x / 2; break; // East
|
|
|
|
case 4: pt1.x += pad->GetSize().x / 2; break; // West
|
|
|
|
default: break; // Wicked witch
|
|
|
|
}
|
|
|
|
|
|
|
|
if( pad->GetOrientation() )
|
|
|
|
RotatePoint( pt1, pad->ShapePos(), pad->GetOrientation() );
|
2019-08-23 16:43:34 +00:00
|
|
|
|
|
|
|
// Thermal spokes on circular pads form an 'X' instead of a '+'
|
2019-10-31 19:36:54 +00:00
|
|
|
if( pad->GetShape() == PAD_SHAPE_CIRCLE )
|
|
|
|
RotatePoint( pt1, pad->ShapePos(), 450 );
|
|
|
|
|
2019-08-23 16:43:34 +00:00
|
|
|
return pt1;
|
|
|
|
|
|
|
|
case PAD_SHAPE_CUSTOM:
|
|
|
|
{
|
2019-10-31 19:36:54 +00:00
|
|
|
switch( n )
|
|
|
|
{
|
2019-11-10 14:46:32 +00:00
|
|
|
case 1: pt1.y = INT_MIN / 2; break; // North
|
|
|
|
case 2: pt1.y = INT_MAX / 2; break; // South
|
|
|
|
case 3: pt1.x = INT_MIN / 2; break; // East
|
|
|
|
case 4: pt1.x = INT_MAX / 2; break; // West
|
|
|
|
default: break; // Wicked witch
|
2019-10-31 19:36:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( pad->GetOrientation() )
|
|
|
|
RotatePoint( pt1, pad->ShapePos(), pad->GetOrientation() );
|
|
|
|
|
2020-07-25 11:58:17 +00:00
|
|
|
const std::shared_ptr<SHAPE_POLY_SET>& padPolySet = pad->GetEffectivePolygon();
|
|
|
|
const SHAPE_LINE_CHAIN& padOutline = padPolySet->COutline( 0 );
|
|
|
|
SHAPE_LINE_CHAIN::INTERSECTIONS intersections;
|
2019-08-23 16:43:34 +00:00
|
|
|
|
|
|
|
padOutline.Intersect( SEG( pt0, pt1 ), intersections );
|
2018-10-12 21:29:16 +00:00
|
|
|
|
2019-08-23 16:43:34 +00:00
|
|
|
if( intersections.empty() )
|
|
|
|
{
|
2019-11-10 14:46:32 +00:00
|
|
|
// There should always be at least some copper outside the hole and/or
|
|
|
|
// shapePos center
|
2019-08-23 16:43:34 +00:00
|
|
|
assert( false );
|
|
|
|
return pt0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return intersections[ intersections.size() - 1 ].p;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
2018-10-12 21:29:16 +00:00
|
|
|
}
|
2019-08-23 16:43:34 +00:00
|
|
|
case PCB_TRACE_T:
|
2019-05-17 00:13:21 +00:00
|
|
|
case PCB_ARC_T:
|
2019-08-23 16:43:34 +00:00
|
|
|
if( n == 0 )
|
|
|
|
return static_cast<const TRACK*>( m_parent )->GetStart();
|
|
|
|
else
|
|
|
|
return static_cast<const TRACK*>( m_parent )->GetEnd();
|
|
|
|
|
|
|
|
case PCB_VIA_T:
|
|
|
|
return static_cast<const VIA*>( m_parent )->GetStart();
|
|
|
|
|
|
|
|
default:
|
|
|
|
assert( false );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return pt0;
|
2018-10-12 21:29:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CN_ITEM::Dump()
|
|
|
|
{
|
2020-08-18 14:17:16 +00:00
|
|
|
wxLogDebug(" valid: %d, connected: \n", !!Valid());
|
2018-10-12 21:29:16 +00:00
|
|
|
|
|
|
|
for( auto i : m_connected )
|
|
|
|
{
|
|
|
|
TRACK* t = static_cast<TRACK*>( i->Parent() );
|
2020-08-18 14:17:16 +00:00
|
|
|
wxLogDebug( " - %p %d\n", t, t->Type() );
|
2018-10-12 21:29:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-09-23 19:02:21 +00:00
|
|
|
int CN_ZONE_LAYER::AnchorCount() const
|
2018-10-12 21:29:16 +00:00
|
|
|
{
|
|
|
|
if( !Valid() )
|
|
|
|
return 0;
|
|
|
|
|
2020-11-11 23:05:59 +00:00
|
|
|
const ZONE* zone = static_cast<const ZONE*>( Parent() );
|
|
|
|
const SHAPE_LINE_CHAIN& outline = zone->GetFilledPolysList( m_layer ).COutline( m_subpolyIndex );
|
2018-10-12 21:29:16 +00:00
|
|
|
|
|
|
|
return outline.PointCount() ? 1 : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-09-23 19:02:21 +00:00
|
|
|
const VECTOR2I CN_ZONE_LAYER::GetAnchor( int n ) const
|
2018-10-12 21:29:16 +00:00
|
|
|
{
|
|
|
|
if( !Valid() )
|
|
|
|
return VECTOR2I();
|
|
|
|
|
2020-11-11 23:05:59 +00:00
|
|
|
const ZONE* zone = static_cast<const ZONE*>( Parent() );
|
|
|
|
const SHAPE_LINE_CHAIN& outline = zone->GetFilledPolysList( m_layer ).COutline( m_subpolyIndex );
|
2018-10-12 21:29:16 +00:00
|
|
|
|
|
|
|
return outline.CPoint( 0 );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CN_ITEM::RemoveInvalidRefs()
|
|
|
|
{
|
|
|
|
for( auto it = m_connected.begin(); it != m_connected.end(); )
|
|
|
|
{
|
|
|
|
if( !(*it)->Valid() )
|
|
|
|
it = m_connected.erase( it );
|
|
|
|
else
|
|
|
|
++it;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-12 22:30:02 +00:00
|
|
|
CN_ITEM* CN_LIST::Add( PAD* pad )
|
2018-10-12 06:47:33 +00:00
|
|
|
{
|
2019-07-25 11:08:41 +00:00
|
|
|
if( !pad->IsOnCopperLayer() )
|
|
|
|
return nullptr;
|
|
|
|
|
2018-10-12 06:47:33 +00:00
|
|
|
auto item = new CN_ITEM( pad, false, 1 );
|
|
|
|
item->AddAnchor( pad->ShapePos() );
|
|
|
|
item->SetLayers( LAYER_RANGE( F_Cu, B_Cu ) );
|
|
|
|
|
|
|
|
switch( pad->GetAttribute() )
|
|
|
|
{
|
|
|
|
case PAD_ATTRIB_SMD:
|
2020-09-30 15:38:35 +00:00
|
|
|
case PAD_ATTRIB_NPTH:
|
2018-10-12 06:47:33 +00:00
|
|
|
case PAD_ATTRIB_CONN:
|
|
|
|
{
|
|
|
|
LSET lmsk = pad->GetLayerSet();
|
|
|
|
|
|
|
|
for( int i = 0; i <= MAX_CU_LAYERS; i++ )
|
|
|
|
{
|
|
|
|
if( lmsk[i] )
|
|
|
|
{
|
|
|
|
item->SetLayer( i );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
addItemtoTree( item );
|
|
|
|
m_items.push_back( item );
|
|
|
|
SetDirty();
|
|
|
|
return item;
|
2019-07-25 11:08:41 +00:00
|
|
|
}
|
2018-10-12 06:47:33 +00:00
|
|
|
|
2019-05-17 00:13:21 +00:00
|
|
|
CN_ITEM* CN_LIST::Add( TRACK* track )
|
|
|
|
{
|
|
|
|
auto item = new CN_ITEM( track, true );
|
|
|
|
m_items.push_back( item );
|
|
|
|
item->AddAnchor( track->GetStart() );
|
|
|
|
item->AddAnchor( track->GetEnd() );
|
|
|
|
item->SetLayer( track->GetLayer() );
|
|
|
|
addItemtoTree( item );
|
|
|
|
SetDirty();
|
|
|
|
return item;
|
|
|
|
}
|
|
|
|
|
|
|
|
CN_ITEM* CN_LIST::Add( ARC* aArc )
|
|
|
|
{
|
|
|
|
auto item = new CN_ITEM( aArc, true );
|
|
|
|
m_items.push_back( item );
|
|
|
|
item->AddAnchor( aArc->GetStart() );
|
|
|
|
item->AddAnchor( aArc->GetEnd() );
|
|
|
|
item->SetLayer( aArc->GetLayer() );
|
|
|
|
addItemtoTree( item );
|
|
|
|
SetDirty();
|
|
|
|
return item;
|
|
|
|
}
|
2018-10-12 06:47:33 +00:00
|
|
|
|
|
|
|
CN_ITEM* CN_LIST::Add( VIA* via )
|
|
|
|
{
|
2020-12-20 21:29:43 +00:00
|
|
|
auto item = new CN_ITEM( via, !via->GetIsFree(), 1 );
|
2018-10-12 06:47:33 +00:00
|
|
|
|
|
|
|
m_items.push_back( item );
|
|
|
|
item->AddAnchor( via->GetStart() );
|
2020-08-14 03:14:23 +00:00
|
|
|
|
|
|
|
item->SetLayers( LAYER_RANGE( via->TopLayer(), via->BottomLayer() ) );
|
2018-10-12 06:47:33 +00:00
|
|
|
addItemtoTree( item );
|
|
|
|
SetDirty();
|
|
|
|
return item;
|
|
|
|
}
|
|
|
|
|
2020-11-11 23:05:59 +00:00
|
|
|
const std::vector<CN_ITEM*> CN_LIST::Add( ZONE* zone, PCB_LAYER_ID aLayer )
|
2018-10-12 06:47:33 +00:00
|
|
|
{
|
2020-06-24 02:19:08 +00:00
|
|
|
const auto& polys = zone->GetFilledPolysList( aLayer );
|
2018-10-12 06:47:33 +00:00
|
|
|
|
|
|
|
std::vector<CN_ITEM*> rv;
|
|
|
|
|
|
|
|
for( int j = 0; j < polys.OutlineCount(); j++ )
|
|
|
|
{
|
2020-09-23 19:02:21 +00:00
|
|
|
CN_ZONE_LAYER* zitem = new CN_ZONE_LAYER( zone, aLayer, false, j );
|
2020-06-24 02:19:08 +00:00
|
|
|
const auto& outline = zone->GetFilledPolysList( aLayer ).COutline( j );
|
2018-10-12 06:47:33 +00:00
|
|
|
|
|
|
|
for( int k = 0; k < outline.PointCount(); k++ )
|
|
|
|
zitem->AddAnchor( outline.CPoint( k ) );
|
|
|
|
|
|
|
|
m_items.push_back( zitem );
|
2020-06-24 02:19:08 +00:00
|
|
|
zitem->SetLayer( aLayer );
|
2018-10-12 06:47:33 +00:00
|
|
|
addItemtoTree( zitem );
|
|
|
|
rv.push_back( zitem );
|
|
|
|
SetDirty();
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2018-10-12 21:29:16 +00:00
|
|
|
|
|
|
|
void CN_LIST::RemoveInvalidItems( std::vector<CN_ITEM*>& aGarbage )
|
|
|
|
{
|
|
|
|
if( !m_hasInvalid )
|
|
|
|
return;
|
|
|
|
|
|
|
|
auto lastItem = std::remove_if(m_items.begin(), m_items.end(), [&aGarbage] ( CN_ITEM* item )
|
|
|
|
{
|
|
|
|
if( !item->Valid() )
|
|
|
|
{
|
|
|
|
aGarbage.push_back ( item );
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
} );
|
|
|
|
|
|
|
|
m_items.resize( lastItem - m_items.begin() );
|
|
|
|
|
|
|
|
for( auto item : m_items )
|
|
|
|
item->RemoveInvalidRefs();
|
|
|
|
|
|
|
|
for( auto item : aGarbage )
|
|
|
|
m_index.Remove( item );
|
|
|
|
|
|
|
|
m_hasInvalid = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
BOARD_CONNECTED_ITEM* CN_ANCHOR::Parent() const
|
|
|
|
{
|
|
|
|
assert( m_item->Valid() );
|
|
|
|
return m_item->Parent();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool CN_ANCHOR::Valid() const
|
|
|
|
{
|
|
|
|
if( !m_item )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return m_item->Valid();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool CN_ANCHOR::IsDangling() const
|
|
|
|
{
|
2020-08-05 20:15:27 +00:00
|
|
|
int accuracy = 0;
|
|
|
|
|
2018-10-12 21:29:16 +00:00
|
|
|
if( !m_cluster )
|
|
|
|
return true;
|
|
|
|
|
|
|
|
// the minimal number of items connected to item_ref
|
|
|
|
// at this anchor point to decide the anchor is *not* dangling
|
2018-11-27 05:04:14 +00:00
|
|
|
size_t minimal_count = 1;
|
|
|
|
size_t connected_count = m_item->ConnectedItems().size();
|
2018-10-12 21:29:16 +00:00
|
|
|
|
|
|
|
// a via can be removed if connected to only one other item.
|
2018-11-27 05:04:14 +00:00
|
|
|
if( Parent()->Type() == PCB_VIA_T )
|
|
|
|
return connected_count < 2;
|
2018-10-12 21:29:16 +00:00
|
|
|
|
2018-11-27 05:04:14 +00:00
|
|
|
if( m_item->AnchorCount() == 1 )
|
|
|
|
return connected_count < minimal_count;
|
2018-10-12 21:29:16 +00:00
|
|
|
|
2020-08-05 20:15:27 +00:00
|
|
|
if( Parent()->Type() == PCB_TRACE_T || Parent()->Type() == PCB_ARC_T )
|
|
|
|
accuracy = ( static_cast<const TRACK*>( Parent() )->GetWidth() + 1 )/ 2;
|
|
|
|
|
2019-06-28 13:14:17 +00:00
|
|
|
// Items with multiple anchors have usually items connected to each anchor.
|
|
|
|
// We want only the item count of this anchor point
|
|
|
|
connected_count = 0;
|
2018-11-27 05:04:14 +00:00
|
|
|
for( auto item : m_item->ConnectedItems() )
|
|
|
|
{
|
2020-11-11 23:05:59 +00:00
|
|
|
if( item->Parent()->Type() == PCB_ZONE_T )
|
2019-06-28 13:14:17 +00:00
|
|
|
{
|
2020-11-11 23:05:59 +00:00
|
|
|
ZONE* zone = static_cast<ZONE*>( item->Parent() );
|
2019-06-28 13:14:17 +00:00
|
|
|
|
2020-06-24 02:19:08 +00:00
|
|
|
if( zone->HitTestFilledArea( static_cast<PCB_LAYER_ID>( item->Layer() ),
|
2020-08-05 20:15:27 +00:00
|
|
|
wxPoint( Pos() ), accuracy ) )
|
2019-06-28 13:14:17 +00:00
|
|
|
connected_count++;
|
|
|
|
}
|
2020-08-05 20:15:27 +00:00
|
|
|
else if( item->Parent()->HitTest( wxPoint( Pos() ), accuracy ) )
|
2019-06-28 13:14:17 +00:00
|
|
|
connected_count++;
|
2018-10-12 21:29:16 +00:00
|
|
|
}
|
|
|
|
|
2018-11-27 05:04:14 +00:00
|
|
|
return connected_count < minimal_count;
|
2018-10-12 21:29:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-06-28 18:23:09 +00:00
|
|
|
int CN_ANCHOR::ConnectedItemsCount() const
|
|
|
|
{
|
|
|
|
if( !m_cluster )
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
int connected_count = 0;
|
|
|
|
|
2020-11-11 23:05:59 +00:00
|
|
|
for( CN_ITEM* item : m_item->ConnectedItems() )
|
2019-06-28 18:23:09 +00:00
|
|
|
{
|
2020-11-11 23:05:59 +00:00
|
|
|
if( item->Parent()->Type() == PCB_ZONE_T )
|
2019-06-28 18:23:09 +00:00
|
|
|
{
|
2020-11-11 23:05:59 +00:00
|
|
|
ZONE* zone = static_cast<ZONE*>( item->Parent() );
|
2019-06-28 18:23:09 +00:00
|
|
|
|
2020-06-24 02:19:08 +00:00
|
|
|
if( zone->HitTestFilledArea( static_cast<PCB_LAYER_ID>( item->Layer() ),
|
2020-11-11 23:05:59 +00:00
|
|
|
(wxPoint) Pos() ) )
|
2019-06-28 18:23:09 +00:00
|
|
|
connected_count++;
|
|
|
|
}
|
2020-11-11 23:05:59 +00:00
|
|
|
else if( item->Parent()->HitTest( (wxPoint) Pos() ) )
|
2019-06-28 18:23:09 +00:00
|
|
|
connected_count++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return connected_count;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-10-12 21:29:16 +00:00
|
|
|
CN_CLUSTER::CN_CLUSTER()
|
|
|
|
{
|
|
|
|
m_items.reserve( 64 );
|
|
|
|
m_originPad = nullptr;
|
|
|
|
m_originNet = -1;
|
|
|
|
m_conflicting = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
CN_CLUSTER::~CN_CLUSTER()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
wxString CN_CLUSTER::OriginNetName() const
|
|
|
|
{
|
|
|
|
if( !m_originPad || !m_originPad->Valid() )
|
|
|
|
return "<none>";
|
|
|
|
else
|
|
|
|
return m_originPad->Parent()->GetNetname();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool CN_CLUSTER::Contains( const CN_ITEM* aItem )
|
|
|
|
{
|
2020-09-26 13:42:40 +00:00
|
|
|
return alg::contains( m_items, aItem );
|
2018-10-12 21:29:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool CN_CLUSTER::Contains( const BOARD_CONNECTED_ITEM* aItem )
|
|
|
|
{
|
2020-10-26 12:50:12 +00:00
|
|
|
return std::find_if( m_items.begin(), m_items.end(),
|
|
|
|
[ &aItem ] ( const CN_ITEM* item )
|
|
|
|
{
|
|
|
|
return item->Valid() && item->Parent() == aItem;
|
|
|
|
} ) != m_items.end();
|
2018-10-12 21:29:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CN_CLUSTER::Dump()
|
|
|
|
{
|
|
|
|
for( auto item : m_items )
|
|
|
|
{
|
2020-10-26 12:50:12 +00:00
|
|
|
wxLogTrace( "CN", " - item : %p bitem : %p type : %d inet %s\n",
|
|
|
|
item,
|
|
|
|
item->Parent(),
|
|
|
|
item->Parent()->Type(),
|
|
|
|
(const char*) item->Parent()->GetNetname().c_str() );
|
|
|
|
wxLogTrace( "CN", "- item : %p bitem : %p type : %d inet %s\n",
|
|
|
|
item,
|
|
|
|
item->Parent(),
|
|
|
|
item->Parent()->Type(),
|
|
|
|
(const char*) item->Parent()->GetNetname().c_str() );
|
2018-10-12 21:29:16 +00:00
|
|
|
item->Dump();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CN_CLUSTER::Add( CN_ITEM* item )
|
|
|
|
{
|
|
|
|
m_items.push_back( item );
|
|
|
|
|
2021-03-21 19:31:15 +00:00
|
|
|
int netCode = item->Net();
|
|
|
|
|
|
|
|
if( netCode <= 0 )
|
2019-05-22 02:29:29 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
if( m_originNet <= 0 )
|
2018-10-12 21:29:16 +00:00
|
|
|
{
|
2021-03-21 19:31:15 +00:00
|
|
|
m_originNet = netCode;
|
2018-10-12 21:29:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( item->Parent()->Type() == PCB_PAD_T )
|
|
|
|
{
|
2021-03-21 19:31:15 +00:00
|
|
|
if( m_netRanks.count( netCode ) )
|
|
|
|
{
|
|
|
|
m_netRanks[netCode]++;
|
|
|
|
|
|
|
|
if( m_netRanks.count( m_originNet ) && m_netRanks[netCode] > m_netRanks[m_originNet] )
|
|
|
|
{
|
|
|
|
m_originPad = item;
|
|
|
|
m_originNet = netCode;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2018-10-12 21:29:16 +00:00
|
|
|
{
|
2021-03-21 19:31:15 +00:00
|
|
|
m_netRanks[netCode] = 1;
|
|
|
|
|
|
|
|
if( !m_originPad )
|
|
|
|
{
|
|
|
|
m_originPad = item;
|
|
|
|
m_originNet = netCode;
|
|
|
|
}
|
2018-10-12 21:29:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( m_originPad && item->Net() != m_originNet )
|
|
|
|
{
|
|
|
|
m_conflicting = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|