2018-10-12 21:29:16 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KICAD, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2013-2017 CERN
|
2023-05-03 09:44:59 +00:00
|
|
|
* Copyright (C) 2018-2023 KiCad Developers, see AUTHORS.txt for contributors.
|
2018-10-12 21:29:16 +00:00
|
|
|
*
|
|
|
|
* @author Maciej Suminski <maciej.suminski@cern.ch>
|
|
|
|
* @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-11-14 18:11:28 +00:00
|
|
|
#ifndef PCBNEW_CONNECTIVITY_ITEMS_H
|
|
|
|
#define PCBNEW_CONNECTIVITY_ITEMS_H
|
2018-10-12 21:29:16 +00:00
|
|
|
|
2020-11-12 20:19:22 +00:00
|
|
|
#include <board.h>
|
|
|
|
#include <pad.h>
|
|
|
|
#include <footprint.h>
|
2021-06-11 21:07:02 +00:00
|
|
|
#include <pcb_track.h>
|
2020-11-11 23:05:59 +00:00
|
|
|
#include <zone.h>
|
2018-10-12 21:29:16 +00:00
|
|
|
|
|
|
|
#include <geometry/shape_poly_set.h>
|
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
#include <algorithm>
|
|
|
|
#include <functional>
|
|
|
|
#include <vector>
|
|
|
|
#include <deque>
|
|
|
|
|
|
|
|
#include <connectivity/connectivity_rtree.h>
|
|
|
|
#include <connectivity/connectivity_data.h>
|
|
|
|
|
|
|
|
class CN_ITEM;
|
|
|
|
class CN_CLUSTER;
|
|
|
|
|
2021-11-30 14:19:39 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* CN_ANCHOR represents a physical location that can be connected: a pad or a track/arc/via
|
|
|
|
* endpoint.
|
|
|
|
*/
|
2018-10-12 21:29:16 +00:00
|
|
|
class CN_ANCHOR
|
|
|
|
{
|
|
|
|
public:
|
2023-05-03 09:44:59 +00:00
|
|
|
CN_ANCHOR( const VECTOR2I& aPos, CN_ITEM* aItem ) :
|
|
|
|
m_pos( aPos ),
|
|
|
|
m_item( aItem ),
|
|
|
|
m_tag( -1 ),
|
|
|
|
m_noline( false )
|
|
|
|
{ }
|
2018-10-12 21:29:16 +00:00
|
|
|
|
|
|
|
bool Valid() const;
|
|
|
|
|
2023-03-13 23:06:24 +00:00
|
|
|
bool Dirty() const;
|
|
|
|
|
2023-05-03 09:44:59 +00:00
|
|
|
CN_ITEM* Item() const { return m_item; }
|
|
|
|
void SetItem( CN_ITEM* aItem ) { m_item = aItem; }
|
2018-10-12 21:29:16 +00:00
|
|
|
|
|
|
|
BOARD_CONNECTED_ITEM* Parent() const;
|
|
|
|
|
2023-05-03 09:44:59 +00:00
|
|
|
const VECTOR2I& Pos() const { return m_pos; }
|
2018-10-12 21:29:16 +00:00
|
|
|
|
2020-08-15 00:33:27 +00:00
|
|
|
void Move( const VECTOR2I& aPos )
|
|
|
|
{
|
|
|
|
m_pos += aPos;
|
|
|
|
}
|
|
|
|
|
2023-05-19 02:05:12 +00:00
|
|
|
unsigned int Dist( const CN_ANCHOR& aSecond )
|
2020-06-18 02:25:46 +00:00
|
|
|
{
|
|
|
|
return ( m_pos - aSecond.Pos() ).EuclideanNorm();
|
|
|
|
}
|
|
|
|
|
2023-05-03 09:44:59 +00:00
|
|
|
///< @return tag, a common identifier for connected nodes.
|
|
|
|
int GetTag() const { return m_tag; }
|
|
|
|
void SetTag( int aTag ) { m_tag = aTag; }
|
2018-10-12 21:29:16 +00:00
|
|
|
|
2023-05-03 09:44:59 +00:00
|
|
|
///< @return true if this node can be a target for ratsnest lines.
|
|
|
|
const bool& GetNoLine() const { return m_noline; }
|
|
|
|
void SetNoLine( bool aEnable ) { m_noline = aEnable; }
|
2018-10-12 21:29:16 +00:00
|
|
|
|
2023-05-03 09:44:59 +00:00
|
|
|
const std::shared_ptr<CN_CLUSTER>& GetCluster() const { return m_cluster; }
|
|
|
|
void SetCluster( std::shared_ptr<CN_CLUSTER>& aCluster ) { m_cluster = aCluster; }
|
2018-10-12 21:29:16 +00:00
|
|
|
|
|
|
|
/**
|
2021-01-27 22:15:38 +00:00
|
|
|
* The anchor point is dangling if the parent is a track and this anchor point is not
|
2021-06-08 17:47:06 +00:00
|
|
|
* connected to another item ( track, vias pad or zone) or if the parent is a via and
|
2021-01-27 22:15:38 +00:00
|
|
|
* this anchor point is connected to only one track and not to another item.
|
|
|
|
*
|
|
|
|
* @return true if this anchor is dangling.
|
2018-10-12 21:29:16 +00:00
|
|
|
*/
|
|
|
|
bool IsDangling() const;
|
|
|
|
|
2019-06-28 18:23:09 +00:00
|
|
|
/**
|
2021-01-27 22:15:38 +00:00
|
|
|
* @return the count of tracks and vias connected to this anchor.
|
2019-06-28 18:23:09 +00:00
|
|
|
*/
|
|
|
|
int ConnectedItemsCount() const;
|
|
|
|
|
2018-10-12 21:29:16 +00:00
|
|
|
// Tag used for unconnected items.
|
|
|
|
static const int TAG_UNCONNECTED = -1;
|
|
|
|
|
|
|
|
private:
|
2023-05-03 09:44:59 +00:00
|
|
|
VECTOR2I m_pos; ///< Position of the anchor.
|
|
|
|
CN_ITEM* m_item; ///< Pad or track/arc/via owning the anchor.
|
|
|
|
int m_tag; ///< Tag for quick connection resolution.
|
|
|
|
bool m_noline; ///< Whether it the node can be a target for ratsnest lines.
|
2018-10-12 21:29:16 +00:00
|
|
|
|
2021-11-30 14:19:39 +00:00
|
|
|
std::shared_ptr<CN_CLUSTER> m_cluster; ///< Cluster to which the anchor belongs.
|
2018-10-12 21:29:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-11-30 14:19:39 +00:00
|
|
|
/**
|
|
|
|
* CN_ITEM represents a BOARD_CONNETED_ITEM in the connectivity system (ie: a pad, track/arc/via,
|
|
|
|
* or zone).
|
|
|
|
*/
|
2020-07-27 16:33:01 +00:00
|
|
|
class CN_ITEM
|
2018-10-12 21:29:16 +00:00
|
|
|
{
|
2018-11-27 05:04:14 +00:00
|
|
|
public:
|
2018-10-12 21:29:16 +00:00
|
|
|
void Dump();
|
|
|
|
|
|
|
|
CN_ITEM( BOARD_CONNECTED_ITEM* aParent, bool aCanChangeNet, int aAnchorCount = 2 )
|
|
|
|
{
|
|
|
|
m_parent = aParent;
|
|
|
|
m_canChangeNet = aCanChangeNet;
|
|
|
|
m_visited = false;
|
|
|
|
m_valid = true;
|
|
|
|
m_dirty = true;
|
2019-10-04 18:38:10 +00:00
|
|
|
m_anchors.reserve( std::max( 6, aAnchorCount ) );
|
2018-10-12 21:29:16 +00:00
|
|
|
m_layers = LAYER_RANGE( 0, PCB_LAYER_ID_COUNT );
|
2019-10-04 18:38:10 +00:00
|
|
|
m_connected.reserve( 8 );
|
2018-10-12 21:29:16 +00:00
|
|
|
}
|
|
|
|
|
2023-05-03 09:44:59 +00:00
|
|
|
virtual ~CN_ITEM()
|
|
|
|
{
|
|
|
|
for( const std::shared_ptr<CN_ANCHOR>& anchor : m_anchors )
|
|
|
|
anchor->SetItem( nullptr );
|
|
|
|
};
|
2018-10-12 21:29:16 +00:00
|
|
|
|
2022-11-21 21:51:28 +00:00
|
|
|
std::shared_ptr<CN_ANCHOR> AddAnchor( const VECTOR2I& aPos )
|
2018-10-12 21:29:16 +00:00
|
|
|
{
|
2019-10-04 18:38:10 +00:00
|
|
|
m_anchors.emplace_back( std::make_shared<CN_ANCHOR>( aPos, this ) );
|
2022-11-21 21:51:28 +00:00
|
|
|
return m_anchors.at( m_anchors.size() - 1 );
|
2018-10-12 21:29:16 +00:00
|
|
|
}
|
|
|
|
|
2022-02-13 11:54:41 +00:00
|
|
|
std::vector<std::shared_ptr<CN_ANCHOR>>& Anchors() { return m_anchors; }
|
2018-10-12 21:29:16 +00:00
|
|
|
|
2020-11-14 18:11:28 +00:00
|
|
|
void SetValid( bool aValid ) { m_valid = aValid; }
|
|
|
|
bool Valid() const { return m_valid; }
|
2018-10-12 21:29:16 +00:00
|
|
|
|
2020-11-14 18:11:28 +00:00
|
|
|
void SetDirty( bool aDirty ) { m_dirty = aDirty; }
|
|
|
|
bool Dirty() const { return m_dirty; }
|
2018-10-12 21:29:16 +00:00
|
|
|
|
|
|
|
/**
|
2021-01-27 22:15:38 +00:00
|
|
|
* Set the layers spanned by the item to aLayers.
|
2018-10-12 21:29:16 +00:00
|
|
|
*/
|
2021-11-30 14:19:39 +00:00
|
|
|
void SetLayers( const LAYER_RANGE& aLayers ) { m_layers = aLayers; }
|
2018-10-12 21:29:16 +00:00
|
|
|
|
|
|
|
/**
|
2021-01-27 22:15:38 +00:00
|
|
|
* Set the layers spanned by the item to a single layer aLayer.
|
2018-10-12 21:29:16 +00:00
|
|
|
*/
|
2021-11-30 14:19:39 +00:00
|
|
|
void SetLayer( int aLayer ) { m_layers = LAYER_RANGE( aLayer, aLayer ); }
|
2018-10-12 21:29:16 +00:00
|
|
|
|
|
|
|
/**
|
2021-01-27 22:15:38 +00:00
|
|
|
* Return the contiguous set of layers spanned by the item.
|
2018-10-12 21:29:16 +00:00
|
|
|
*/
|
2021-11-30 14:19:39 +00:00
|
|
|
const LAYER_RANGE& Layers() const { return m_layers; }
|
2018-10-12 21:29:16 +00:00
|
|
|
|
|
|
|
/**
|
2021-01-27 22:15:38 +00:00
|
|
|
* Return the item's layer, for single-layered items only.
|
2018-10-12 21:29:16 +00:00
|
|
|
*/
|
|
|
|
virtual int Layer() const
|
|
|
|
{
|
|
|
|
return Layers().Start();
|
|
|
|
}
|
|
|
|
|
|
|
|
const BOX2I& BBox()
|
|
|
|
{
|
|
|
|
if( m_dirty && m_valid )
|
2022-08-31 09:15:42 +00:00
|
|
|
m_bbox = m_parent->GetBoundingBox();
|
2021-11-30 14:19:39 +00:00
|
|
|
|
2018-10-12 21:29:16 +00:00
|
|
|
return m_bbox;
|
|
|
|
}
|
|
|
|
|
2021-11-30 14:19:39 +00:00
|
|
|
BOARD_CONNECTED_ITEM* Parent() const { return m_parent; }
|
2018-10-12 21:29:16 +00:00
|
|
|
|
2022-02-13 11:54:41 +00:00
|
|
|
const std::vector<CN_ITEM*>& ConnectedItems() const { return m_connected; }
|
2020-11-14 18:11:28 +00:00
|
|
|
void ClearConnections() { m_connected.clear(); }
|
2018-10-12 21:29:16 +00:00
|
|
|
|
2020-11-14 18:11:28 +00:00
|
|
|
void SetVisited( bool aVisited ) { m_visited = aVisited; }
|
|
|
|
bool Visited() const { return m_visited; }
|
2018-10-12 21:29:16 +00:00
|
|
|
|
2020-11-14 18:11:28 +00:00
|
|
|
bool CanChangeNet() const { return m_canChangeNet; }
|
2018-10-12 21:29:16 +00:00
|
|
|
|
2018-10-13 00:06:10 +00:00
|
|
|
void Connect( CN_ITEM* b )
|
2018-10-12 21:29:16 +00:00
|
|
|
{
|
2018-10-13 00:06:10 +00:00
|
|
|
std::lock_guard<std::mutex> lock( m_listLock );
|
2019-10-04 18:38:10 +00:00
|
|
|
|
|
|
|
auto i = std::lower_bound( m_connected.begin(), m_connected.end(), b );
|
|
|
|
|
|
|
|
if( i != m_connected.end() && *i == b )
|
|
|
|
return;
|
|
|
|
|
|
|
|
m_connected.insert( i, b );
|
2018-10-12 21:29:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void RemoveInvalidRefs();
|
|
|
|
|
2020-11-14 18:11:28 +00:00
|
|
|
virtual int AnchorCount() const;
|
|
|
|
virtual const VECTOR2I GetAnchor( int n ) const;
|
2018-10-12 21:29:16 +00:00
|
|
|
|
2020-04-12 18:59:13 +00:00
|
|
|
int Net() const
|
|
|
|
{
|
|
|
|
return ( !m_parent || !m_valid ) ? -1 : m_parent->GetNetCode();
|
|
|
|
}
|
2023-05-03 09:44:59 +00:00
|
|
|
|
2021-01-27 22:15:38 +00:00
|
|
|
protected:
|
|
|
|
bool m_dirty; ///< used to identify recently added item not yet
|
|
|
|
///< scanned into the connectivity search
|
|
|
|
LAYER_RANGE m_layers; ///< layer range over which the item exists
|
|
|
|
BOX2I m_bbox; ///< bounding box for the item
|
|
|
|
|
|
|
|
private:
|
2022-02-13 11:54:41 +00:00
|
|
|
BOARD_CONNECTED_ITEM* m_parent;
|
2021-01-27 22:15:38 +00:00
|
|
|
|
2022-02-13 11:54:41 +00:00
|
|
|
std::vector<CN_ITEM*> m_connected; ///< list of physically touching items
|
|
|
|
std::vector<std::shared_ptr<CN_ANCHOR>> m_anchors;
|
2021-01-27 22:15:38 +00:00
|
|
|
|
|
|
|
bool m_canChangeNet; ///< can the net propagator modify the netcode?
|
|
|
|
|
|
|
|
bool m_visited; ///< visited flag for the BFS scan
|
|
|
|
bool m_valid; ///< used to identify garbage items (we use lazy removal)
|
|
|
|
|
|
|
|
std::mutex m_listLock; ///< mutex protecting this item's connected_items set to
|
2018-10-12 21:29:16 +00:00
|
|
|
};
|
|
|
|
|
2021-11-30 14:19:39 +00:00
|
|
|
|
2023-05-03 09:44:59 +00:00
|
|
|
/*
|
|
|
|
* Represents a single outline of a zone fill on a particular layer. \a aSubpolyIndex indicates
|
|
|
|
* which outline in the fill's SHAPE_POLY_SET.
|
|
|
|
*/
|
2020-09-23 19:02:21 +00:00
|
|
|
class CN_ZONE_LAYER : public CN_ITEM
|
2018-10-12 21:29:16 +00:00
|
|
|
{
|
|
|
|
public:
|
2022-02-16 14:10:43 +00:00
|
|
|
CN_ZONE_LAYER( ZONE* aParent, PCB_LAYER_ID aLayer, int aSubpolyIndex ) :
|
|
|
|
CN_ITEM( aParent, false ),
|
2023-05-12 21:03:54 +00:00
|
|
|
m_zone( aParent ),
|
2020-11-14 18:11:28 +00:00
|
|
|
m_subpolyIndex( aSubpolyIndex ),
|
|
|
|
m_layer( aLayer )
|
2018-10-12 21:29:16 +00:00
|
|
|
{
|
2023-05-12 21:03:54 +00:00
|
|
|
m_fillPoly = aParent->GetFilledPolysList( aLayer );
|
2022-02-16 14:10:43 +00:00
|
|
|
SetLayers( aLayer );
|
|
|
|
}
|
2018-10-12 21:29:16 +00:00
|
|
|
|
2022-02-16 14:10:43 +00:00
|
|
|
void BuildRTree()
|
|
|
|
{
|
2023-05-12 21:03:54 +00:00
|
|
|
if( m_zone->IsTeardropArea() )
|
|
|
|
return;
|
|
|
|
|
|
|
|
for( unsigned int ii = 0; ii < m_fillPoly->TriangulatedPolyCount(); ++ii )
|
2022-02-13 00:29:12 +00:00
|
|
|
{
|
2023-05-12 21:03:54 +00:00
|
|
|
const auto* triangleSet = m_fillPoly->TriangulatedPolygon( ii );
|
2022-02-15 12:17:31 +00:00
|
|
|
|
2022-02-16 14:10:43 +00:00
|
|
|
if( triangleSet->GetSourceOutlineIndex() != m_subpolyIndex )
|
2022-02-15 12:17:31 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
for( const SHAPE_POLY_SET::TRIANGULATED_POLYGON::TRI& tri : triangleSet->Triangles() )
|
2022-02-13 00:29:12 +00:00
|
|
|
{
|
|
|
|
BOX2I bbox = tri.BBox();
|
|
|
|
const int mmin[2] = { bbox.GetX(), bbox.GetY() };
|
|
|
|
const int mmax[2] = { bbox.GetRight(), bbox.GetBottom() };
|
|
|
|
|
|
|
|
m_rTree.Insert( mmin, mmax, &tri );
|
|
|
|
}
|
|
|
|
}
|
2018-10-12 21:29:16 +00:00
|
|
|
}
|
|
|
|
|
2022-03-05 15:18:24 +00:00
|
|
|
int SubpolyIndex() const { return m_subpolyIndex; }
|
|
|
|
|
|
|
|
PCB_LAYER_ID GetLayer() const { return m_layer; }
|
2018-10-12 21:29:16 +00:00
|
|
|
|
2022-02-14 01:07:25 +00:00
|
|
|
bool ContainsPoint( const VECTOR2I& p ) const
|
|
|
|
{
|
2023-05-12 21:03:54 +00:00
|
|
|
if( m_zone->IsTeardropArea() )
|
|
|
|
return m_fillPoly->Outline( m_subpolyIndex ).Collide( p ) ;
|
|
|
|
|
2022-02-14 01:07:25 +00:00
|
|
|
int min[2] = { p.x, p.y };
|
|
|
|
int max[2] = { p.x, p.y };
|
|
|
|
bool collision = false;
|
|
|
|
|
|
|
|
auto visitor =
|
|
|
|
[&]( const SHAPE* aShape ) -> bool
|
|
|
|
{
|
|
|
|
if( aShape->Collide( p ) )
|
|
|
|
{
|
|
|
|
collision = true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
|
|
|
|
m_rTree.Search( min, max, visitor );
|
|
|
|
|
|
|
|
return collision;
|
|
|
|
}
|
|
|
|
|
2022-02-13 00:29:12 +00:00
|
|
|
PCB_LAYER_ID GetLayer() { return m_layer; }
|
2018-10-12 21:29:16 +00:00
|
|
|
|
2022-02-13 00:29:12 +00:00
|
|
|
virtual int AnchorCount() const override;
|
|
|
|
virtual const VECTOR2I GetAnchor( int n ) const override;
|
2018-10-12 21:29:16 +00:00
|
|
|
|
2022-09-30 19:04:54 +00:00
|
|
|
const SHAPE_LINE_CHAIN& GetOutline() const
|
|
|
|
{
|
2023-05-12 21:03:54 +00:00
|
|
|
return m_fillPoly->Outline( m_subpolyIndex );
|
2022-09-30 19:04:54 +00:00
|
|
|
}
|
|
|
|
|
2022-02-13 00:29:12 +00:00
|
|
|
bool Collide( SHAPE* aRefShape ) const
|
2018-10-12 21:29:16 +00:00
|
|
|
{
|
2023-05-12 21:03:54 +00:00
|
|
|
if( m_zone->IsTeardropArea() )
|
|
|
|
return m_fillPoly->Collide( aRefShape );
|
|
|
|
|
2022-02-13 00:29:12 +00:00
|
|
|
BOX2I bbox = aRefShape->BBox();
|
|
|
|
int min[2] = { bbox.GetX(), bbox.GetY() };
|
|
|
|
int max[2] = { bbox.GetRight(), bbox.GetBottom() };
|
|
|
|
bool collision = false;
|
2018-10-12 21:29:16 +00:00
|
|
|
|
2022-02-13 00:29:12 +00:00
|
|
|
auto visitor =
|
|
|
|
[&]( const SHAPE* aShape ) -> bool
|
|
|
|
{
|
|
|
|
if( aRefShape->Collide( aShape ) )
|
|
|
|
{
|
|
|
|
collision = true;
|
|
|
|
return false;
|
|
|
|
}
|
2018-10-12 21:29:16 +00:00
|
|
|
|
2022-02-13 00:29:12 +00:00
|
|
|
return true;
|
|
|
|
};
|
|
|
|
|
|
|
|
m_rTree.Search( min, max, visitor );
|
|
|
|
|
|
|
|
return collision;
|
|
|
|
}
|
2018-10-12 21:29:16 +00:00
|
|
|
|
2023-03-25 10:44:46 +00:00
|
|
|
bool HasSingleConnection();
|
|
|
|
|
2018-10-12 21:29:16 +00:00
|
|
|
private:
|
2023-05-12 21:03:54 +00:00
|
|
|
ZONE* m_zone;
|
2022-02-13 00:29:12 +00:00
|
|
|
int m_subpolyIndex;
|
|
|
|
PCB_LAYER_ID m_layer;
|
2023-05-12 21:03:54 +00:00
|
|
|
std::shared_ptr<SHAPE_POLY_SET> m_fillPoly;
|
2022-02-13 00:29:12 +00:00
|
|
|
RTree<const SHAPE*, int, 2, double> m_rTree;
|
2018-10-12 21:29:16 +00:00
|
|
|
};
|
|
|
|
|
2021-11-30 14:19:39 +00:00
|
|
|
|
2022-02-13 00:29:12 +00:00
|
|
|
|
|
|
|
|
2018-10-12 21:29:16 +00:00
|
|
|
class CN_LIST
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CN_LIST()
|
|
|
|
{
|
|
|
|
m_dirty = false;
|
|
|
|
m_hasInvalid = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Clear()
|
|
|
|
{
|
2021-11-30 14:19:39 +00:00
|
|
|
for( CN_ITEM* item : m_items )
|
2018-10-12 21:29:16 +00:00
|
|
|
delete item;
|
|
|
|
|
|
|
|
m_items.clear();
|
|
|
|
m_index.RemoveAll();
|
|
|
|
}
|
|
|
|
|
2023-05-03 09:44:59 +00:00
|
|
|
std::vector<CN_ITEM*>::iterator begin() { return m_items.begin(); };
|
|
|
|
std::vector<CN_ITEM*>::iterator end() { return m_items.end(); };
|
2018-10-12 21:29:16 +00:00
|
|
|
|
2023-05-03 09:44:59 +00:00
|
|
|
std::vector<CN_ITEM*>::const_iterator begin() const { return m_items.begin(); }
|
|
|
|
std::vector<CN_ITEM*>::const_iterator end() const { return m_items.end(); }
|
2020-04-12 19:10:57 +00:00
|
|
|
|
2018-10-12 21:29:16 +00:00
|
|
|
CN_ITEM* operator[] ( int aIndex ) { return m_items[aIndex]; }
|
|
|
|
|
|
|
|
template <class T>
|
2021-06-08 17:47:06 +00:00
|
|
|
void FindNearby( CN_ITEM* aItem, T aFunc )
|
2018-10-12 06:47:33 +00:00
|
|
|
{
|
|
|
|
m_index.Query( aItem->BBox(), aItem->Layers(), aFunc );
|
|
|
|
}
|
2018-10-12 21:29:16 +00:00
|
|
|
|
2020-11-14 18:11:28 +00:00
|
|
|
void SetHasInvalid( bool aInvalid = true ) { m_hasInvalid = aInvalid; }
|
2018-10-12 21:29:16 +00:00
|
|
|
|
2020-11-14 18:11:28 +00:00
|
|
|
void SetDirty( bool aDirty = true ) { m_dirty = aDirty; }
|
|
|
|
bool IsDirty() const { return m_dirty; }
|
2018-10-12 21:29:16 +00:00
|
|
|
|
|
|
|
void RemoveInvalidItems( std::vector<CN_ITEM*>& aGarbage );
|
|
|
|
|
|
|
|
void ClearDirtyFlags()
|
|
|
|
{
|
2022-08-15 17:47:23 +00:00
|
|
|
for( CN_ITEM* item : m_items )
|
2018-10-12 21:29:16 +00:00
|
|
|
item->SetDirty( false );
|
|
|
|
|
|
|
|
SetDirty( false );
|
|
|
|
}
|
|
|
|
|
2023-05-03 09:44:59 +00:00
|
|
|
int Size() const { return m_items.size(); }
|
2018-10-12 21:29:16 +00:00
|
|
|
|
2020-11-12 22:30:02 +00:00
|
|
|
CN_ITEM* Add( PAD* pad );
|
2021-06-11 21:07:02 +00:00
|
|
|
CN_ITEM* Add( PCB_TRACK* track );
|
|
|
|
CN_ITEM* Add( PCB_ARC* track );
|
|
|
|
CN_ITEM* Add( PCB_VIA* via );
|
2022-02-16 14:10:43 +00:00
|
|
|
CN_ITEM* Add( CN_ZONE_LAYER* zitem );
|
|
|
|
|
2020-11-11 23:05:59 +00:00
|
|
|
const std::vector<CN_ITEM*> Add( ZONE* zone, PCB_LAYER_ID aLayer );
|
2021-01-27 22:15:38 +00:00
|
|
|
|
2023-05-03 09:44:59 +00:00
|
|
|
protected:
|
|
|
|
void addItemtoTree( CN_ITEM* item )
|
|
|
|
{
|
|
|
|
m_index.Insert( item );
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
std::vector<CN_ITEM*> m_items;
|
|
|
|
|
2021-01-27 22:15:38 +00:00
|
|
|
private:
|
2023-05-03 09:44:59 +00:00
|
|
|
bool m_dirty;
|
|
|
|
bool m_hasInvalid;
|
|
|
|
CN_RTREE<CN_ITEM*> m_index;
|
2018-10-12 21:29:16 +00:00
|
|
|
};
|
|
|
|
|
2021-11-30 14:19:39 +00:00
|
|
|
|
2018-10-12 21:29:16 +00:00
|
|
|
class CN_CLUSTER
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CN_CLUSTER();
|
|
|
|
~CN_CLUSTER();
|
|
|
|
|
2020-11-14 18:11:28 +00:00
|
|
|
bool HasValidNet() const { return m_originNet > 0; }
|
|
|
|
int OriginNet() const { return m_originNet; }
|
2018-10-12 21:29:16 +00:00
|
|
|
|
|
|
|
wxString OriginNetName() const;
|
|
|
|
|
2021-01-27 22:15:38 +00:00
|
|
|
bool Contains( const CN_ITEM* aItem );
|
|
|
|
bool Contains( const BOARD_CONNECTED_ITEM* aItem );
|
|
|
|
void Dump();
|
2018-10-12 21:29:16 +00:00
|
|
|
|
2020-11-14 18:11:28 +00:00
|
|
|
int Size() const { return m_items.size(); }
|
2018-10-12 21:29:16 +00:00
|
|
|
|
2023-05-03 09:44:59 +00:00
|
|
|
bool IsOrphaned() const
|
|
|
|
{
|
|
|
|
return m_originPad == nullptr;
|
|
|
|
}
|
2018-10-12 21:29:16 +00:00
|
|
|
|
2020-11-14 18:11:28 +00:00
|
|
|
bool IsConflicting() const { return m_conflicting; }
|
2018-10-12 21:29:16 +00:00
|
|
|
|
|
|
|
void Add( CN_ITEM* item );
|
|
|
|
|
2023-05-03 09:44:59 +00:00
|
|
|
std::vector<CN_ITEM*>::iterator begin() { return m_items.begin(); };
|
|
|
|
std::vector<CN_ITEM*>::iterator end() { return m_items.end(); };
|
2018-10-12 21:29:16 +00:00
|
|
|
|
2023-05-03 09:44:59 +00:00
|
|
|
private:
|
|
|
|
bool m_conflicting;
|
|
|
|
int m_originNet;
|
|
|
|
CN_ITEM* m_originPad;
|
|
|
|
std::vector<CN_ITEM*> m_items;
|
|
|
|
std::unordered_map<int, int> m_netRanks;
|
2018-10-12 21:29:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-11-14 18:11:28 +00:00
|
|
|
#endif /* PCBNEW_CONNECTIVITY_ITEMS_H */
|