2017-03-22 13:43:10 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KICAD, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2013-2017 CERN
|
2019-01-18 03:17:34 +00:00
|
|
|
* Copyright (C) 2018-2019 KiCad Developers, see AUTHORS.txt for contributors.
|
2017-03-22 13:43:10 +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
|
|
|
|
*/
|
|
|
|
|
2017-11-15 17:33:06 +00:00
|
|
|
#ifndef __CONNECTIVITY_DATA_H
|
|
|
|
#define __CONNECTIVITY_DATA_H
|
2017-03-22 13:43:10 +00:00
|
|
|
|
|
|
|
#include <core/typeinfo.h>
|
|
|
|
|
|
|
|
#include <wx/string.h>
|
|
|
|
#include <vector>
|
|
|
|
#include <memory>
|
|
|
|
|
|
|
|
#include <math/vector2d.h>
|
2018-04-09 14:07:53 +00:00
|
|
|
#include <geometry/shape_poly_set.h>
|
|
|
|
#include <class_zone.h>
|
2017-03-22 13:43:10 +00:00
|
|
|
|
|
|
|
class CN_CLUSTER;
|
|
|
|
class CN_CONNECTIVITY_ALGO;
|
2017-03-22 15:47:15 +00:00
|
|
|
class CN_EDGE;
|
2017-03-22 13:43:10 +00:00
|
|
|
class BOARD;
|
2019-05-25 01:55:40 +00:00
|
|
|
class BOARD_COMMIT;
|
2017-03-22 13:43:10 +00:00
|
|
|
class BOARD_CONNECTED_ITEM;
|
|
|
|
class BOARD_ITEM;
|
|
|
|
class ZONE_CONTAINER;
|
|
|
|
class RN_DATA;
|
|
|
|
class RN_NET;
|
2017-03-22 13:51:07 +00:00
|
|
|
class TRACK;
|
|
|
|
class D_PAD;
|
2018-08-24 10:54:45 +00:00
|
|
|
class MODULE;
|
2017-11-23 16:20:27 +00:00
|
|
|
class PROGRESS_REPORTER;
|
2017-03-22 13:43:10 +00:00
|
|
|
|
|
|
|
struct CN_DISJOINT_NET_ENTRY
|
|
|
|
{
|
|
|
|
int net;
|
2017-06-30 11:40:20 +00:00
|
|
|
BOARD_CONNECTED_ITEM *a, *b;
|
2017-03-22 13:43:10 +00:00
|
|
|
VECTOR2I anchorA, anchorB;
|
|
|
|
};
|
|
|
|
|
2017-11-23 16:20:27 +00:00
|
|
|
struct CN_ZONE_ISOLATED_ISLAND_LIST
|
|
|
|
{
|
2018-04-09 14:07:53 +00:00
|
|
|
CN_ZONE_ISOLATED_ISLAND_LIST( ZONE_CONTAINER* aZone ) :
|
2019-03-21 14:27:05 +00:00
|
|
|
m_zone( aZone )
|
2018-04-09 14:07:53 +00:00
|
|
|
{}
|
|
|
|
|
|
|
|
ZONE_CONTAINER* m_zone;
|
|
|
|
std::vector<int> m_islands;
|
2017-11-23 16:20:27 +00:00
|
|
|
};
|
|
|
|
|
2017-03-22 13:43:10 +00:00
|
|
|
struct RN_DYNAMIC_LINE
|
|
|
|
{
|
|
|
|
int netCode;
|
|
|
|
VECTOR2I a, b;
|
|
|
|
};
|
|
|
|
|
|
|
|
// a wrapper class encompassing the connectivity computation algorithm and the
|
2018-12-20 05:15:53 +00:00
|
|
|
class CONNECTIVITY_DATA
|
2017-03-22 13:43:10 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
CONNECTIVITY_DATA();
|
|
|
|
~CONNECTIVITY_DATA();
|
|
|
|
|
2020-06-23 03:42:12 +00:00
|
|
|
CONNECTIVITY_DATA( const std::vector<BOARD_ITEM*>& aItems, bool aSkipItems = false );
|
2017-03-22 13:43:10 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Function Build()
|
|
|
|
* Builds the connectivity database for the board aBoard.
|
|
|
|
*/
|
|
|
|
void Build( BOARD* aBoard );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function Build()
|
|
|
|
* Builds the connectivity database for a set of items aItems.
|
|
|
|
*/
|
|
|
|
void Build( const std::vector<BOARD_ITEM*>& aItems );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function Add()
|
|
|
|
* Adds an item to the connectivity data.
|
|
|
|
* @param aItem is an item to be added.
|
|
|
|
* @return True if operation succeeded.
|
|
|
|
*/
|
|
|
|
bool Add( BOARD_ITEM* aItem );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function Remove()
|
|
|
|
* Removes an item from the connectivity data.
|
|
|
|
* @param aItem is an item to be updated.
|
|
|
|
* @return True if operation succeeded.
|
|
|
|
*/
|
|
|
|
bool Remove( BOARD_ITEM* aItem );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function Update()
|
|
|
|
* Updates the connectivity data for an item.
|
|
|
|
* @param aItem is an item to be updated.
|
|
|
|
* @return True if operation succeeded.
|
|
|
|
*/
|
|
|
|
bool Update( BOARD_ITEM* aItem );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function Clear()
|
|
|
|
* Erases the connectivity database.
|
|
|
|
*/
|
|
|
|
void Clear();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function GetNetCount()
|
|
|
|
* Returns the total number of nets in the connectivity database.
|
|
|
|
*/
|
|
|
|
int GetNetCount() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function GetRatsnestForNet()
|
|
|
|
* Returns the ratsnest, expressed as a set of graph edges for a given net.
|
|
|
|
*/
|
2017-06-29 22:45:50 +00:00
|
|
|
RN_NET* GetRatsnestForNet( int aNet );
|
2017-06-30 11:40:20 +00:00
|
|
|
|
2017-03-22 13:43:10 +00:00
|
|
|
/**
|
|
|
|
* Function PropagateNets()
|
|
|
|
* Propagates the net codes from the source pads to the tracks/vias.
|
|
|
|
*/
|
|
|
|
void PropagateNets();
|
|
|
|
|
2017-03-22 13:51:07 +00:00
|
|
|
bool CheckConnectivity( std::vector<CN_DISJOINT_NET_ENTRY>& aReport );
|
2017-03-22 13:43:10 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Function FindIsolatedCopperIslands()
|
|
|
|
* Searches for copper islands in zone aZone that are not connected to any pad.
|
|
|
|
* @param aZone zone to test
|
|
|
|
* @param aIslands list of islands that have no connections (outline indices in the polygon set)
|
|
|
|
*/
|
|
|
|
void FindIsolatedCopperIslands( ZONE_CONTAINER* aZone, std::vector<int>& aIslands );
|
2017-11-23 16:20:27 +00:00
|
|
|
void FindIsolatedCopperIslands( std::vector<CN_ZONE_ISOLATED_ISLAND_LIST>& aZones );
|
2017-03-22 13:43:10 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Function RecalculateRatsnest()
|
|
|
|
* Updates the ratsnest for the board.
|
2019-05-25 01:55:40 +00:00
|
|
|
* @param aCommit is used to save the undo state of items modified by this call
|
2017-03-22 13:43:10 +00:00
|
|
|
*/
|
2019-05-25 01:55:40 +00:00
|
|
|
void RecalculateRatsnest( BOARD_COMMIT* aCommit = nullptr );
|
2017-03-22 13:43:10 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Function GetUnconnectedCount()
|
|
|
|
* Returns the number of remaining edges in the ratsnest.
|
|
|
|
*/
|
|
|
|
unsigned int GetUnconnectedCount() const;
|
|
|
|
|
2017-03-22 13:51:07 +00:00
|
|
|
unsigned int GetNodeCount( int aNet = -1 ) const;
|
|
|
|
|
|
|
|
unsigned int GetPadCount( int aNet = -1 ) const;
|
|
|
|
|
2017-06-30 11:40:20 +00:00
|
|
|
const std::vector<TRACK*> GetConnectedTracks( const BOARD_CONNECTED_ITEM* aItem ) const;
|
2017-03-22 13:51:07 +00:00
|
|
|
|
2017-06-30 11:40:20 +00:00
|
|
|
const std::vector<D_PAD*> GetConnectedPads( const BOARD_CONNECTED_ITEM* aItem ) const;
|
2017-03-22 13:43:10 +00:00
|
|
|
|
2019-01-18 03:17:34 +00:00
|
|
|
const void GetConnectedPads( const BOARD_CONNECTED_ITEM* aItem, std::set<D_PAD*>* pads ) const;
|
2018-08-19 16:11:58 +00:00
|
|
|
|
2017-06-22 14:24:07 +00:00
|
|
|
const std::vector<BOARD_CONNECTED_ITEM*> GetConnectedItems( const BOARD_CONNECTED_ITEM* aItem, const VECTOR2I& aAnchor, KICAD_T aTypes[] );
|
|
|
|
|
2017-03-22 15:47:15 +00:00
|
|
|
void GetUnconnectedEdges( std::vector<CN_EDGE>& aEdges ) const;
|
|
|
|
|
2017-03-22 13:43:10 +00:00
|
|
|
/**
|
|
|
|
* Function ClearDynamicRatsnest()
|
2017-08-01 13:20:40 +00:00
|
|
|
* Erases the temporary dynamic ratsnest (i.e. the ratsnest lines that
|
|
|
|
* pcbnew displays when moving an item/set of items)
|
2017-03-22 13:43:10 +00:00
|
|
|
*/
|
|
|
|
void ClearDynamicRatsnest();
|
|
|
|
|
2017-08-01 13:20:40 +00:00
|
|
|
/**
|
|
|
|
* Hides the temporary dynamic ratsnest lines.
|
|
|
|
*/
|
|
|
|
void HideDynamicRatsnest();
|
|
|
|
|
2017-03-22 13:43:10 +00:00
|
|
|
/**
|
|
|
|
* Function ComputeDynamicRatsnest()
|
|
|
|
* Calculates the temporary dynamic ratsnest (i.e. the ratsnest lines that)
|
|
|
|
* for the set of items aItems.
|
|
|
|
*/
|
2017-06-23 11:56:28 +00:00
|
|
|
void ComputeDynamicRatsnest( const std::vector<BOARD_ITEM*>& aItems );
|
2017-03-22 13:43:10 +00:00
|
|
|
|
2017-06-23 12:20:08 +00:00
|
|
|
const std::vector<RN_DYNAMIC_LINE>& GetDynamicRatsnest() const
|
|
|
|
{
|
|
|
|
return m_dynamicRatsnest;
|
|
|
|
}
|
2017-03-22 13:43:10 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Function GetConnectedItems()
|
|
|
|
* Returns a list of items connected to a source item aItem.
|
|
|
|
* @param aItem is the reference item to find other connected items.
|
2018-07-08 12:12:38 +00:00
|
|
|
* @param aTypes allows one to filter by item types.
|
2017-03-22 13:43:10 +00:00
|
|
|
*/
|
2017-11-15 17:33:06 +00:00
|
|
|
const std::vector<BOARD_CONNECTED_ITEM*> GetConnectedItems( const BOARD_CONNECTED_ITEM* aItem,
|
2019-01-18 01:50:50 +00:00
|
|
|
const KICAD_T aTypes[], bool aIgnoreNetcodes = false ) const;
|
2017-03-22 13:43:10 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Function GetNetItems()
|
|
|
|
* Returns the list of items that belong to a certain net.
|
|
|
|
* @param aNetCode is the net code.
|
2018-07-08 12:12:38 +00:00
|
|
|
* @param aTypes allows one to filter by item types.
|
2017-03-22 13:43:10 +00:00
|
|
|
*/
|
2017-11-15 17:33:06 +00:00
|
|
|
const std::vector<BOARD_CONNECTED_ITEM*> GetNetItems( int aNetCode,
|
2017-03-22 13:43:10 +00:00
|
|
|
const KICAD_T aTypes[] ) const;
|
|
|
|
|
2017-03-22 13:51:07 +00:00
|
|
|
const std::vector<VECTOR2I> NearestUnconnectedTargets( const BOARD_CONNECTED_ITEM* aRef,
|
|
|
|
const VECTOR2I& aPos,
|
|
|
|
int aMaxCount = -1 );
|
|
|
|
|
|
|
|
void BlockRatsnestItems( const std::vector<BOARD_ITEM*>& aItems );
|
|
|
|
|
2017-05-04 22:43:43 +00:00
|
|
|
std::shared_ptr<CN_CONNECTIVITY_ALGO> GetConnectivityAlgo() const
|
|
|
|
{
|
2017-06-23 11:56:28 +00:00
|
|
|
return m_connAlgo;
|
2017-05-04 22:43:43 +00:00
|
|
|
}
|
|
|
|
|
2018-12-20 05:15:53 +00:00
|
|
|
std::mutex& GetLock()
|
|
|
|
{
|
|
|
|
return m_lock;
|
|
|
|
}
|
|
|
|
|
2017-07-02 00:05:42 +00:00
|
|
|
void MarkItemNetAsDirty( BOARD_ITEM* aItem );
|
2017-11-23 16:20:27 +00:00
|
|
|
void SetProgressReporter( PROGRESS_REPORTER* aReporter );
|
2018-08-24 11:05:18 +00:00
|
|
|
|
|
|
|
#ifndef SWIG
|
2020-06-23 03:42:12 +00:00
|
|
|
const std::vector<CN_EDGE> GetRatsnestForItems( const std::vector<BOARD_ITEM*> aItems );
|
|
|
|
|
2018-08-24 10:54:45 +00:00
|
|
|
const std::vector<CN_EDGE> GetRatsnestForComponent( MODULE* aComponent, bool aSkipInternalConnections = false );
|
2018-08-24 11:05:18 +00:00
|
|
|
#endif
|
2017-11-23 16:20:27 +00:00
|
|
|
|
2017-03-22 13:43:10 +00:00
|
|
|
private:
|
2018-08-24 10:54:45 +00:00
|
|
|
|
2017-03-22 13:43:10 +00:00
|
|
|
void updateRatsnest();
|
2017-09-23 09:20:10 +00:00
|
|
|
void addRatsnestCluster( const std::shared_ptr<CN_CLUSTER>& aCluster );
|
2017-03-22 13:43:10 +00:00
|
|
|
|
|
|
|
std::shared_ptr<CN_CONNECTIVITY_ALGO> m_connAlgo;
|
|
|
|
|
|
|
|
std::vector<RN_DYNAMIC_LINE> m_dynamicRatsnest;
|
|
|
|
std::vector<RN_NET*> m_nets;
|
2017-11-23 16:20:27 +00:00
|
|
|
|
|
|
|
PROGRESS_REPORTER* m_progressReporter;
|
2018-12-20 05:15:53 +00:00
|
|
|
|
2020-06-23 03:42:12 +00:00
|
|
|
bool m_skipRatsnest = false;
|
|
|
|
|
2018-12-20 05:15:53 +00:00
|
|
|
std::mutex m_lock;
|
2017-03-22 13:43:10 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|