KiCad PCB EDA Suite
connectivity_data.h
Go to the documentation of this file.
1 /*
2  * This program source code file is part of KICAD, a free EDA CAD application.
3  *
4  * Copyright (C) 2013-2017 CERN
5  * Copyright (C) 2018-2020 KiCad Developers, see AUTHORS.txt for contributors.
6  * @author Maciej Suminski <maciej.suminski@cern.ch>
7  * @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
8  *
9  * This program is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public License
11  * as published by the Free Software Foundation; either version 2
12  * of the License, or (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, you may find one here:
21  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
22  * or you may search the http://www.gnu.org website for the version 2 license,
23  * or you may write to the Free Software Foundation, Inc.,
24  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
25  */
26 
27 #ifndef __CONNECTIVITY_DATA_H
28 #define __CONNECTIVITY_DATA_H
29 
30 #include <core/typeinfo.h>
31 #include <core/spinlock.h>
32 
33 #include <memory>
34 #include <mutex>
35 #include <vector>
36 #include <wx/string.h>
37 
38 #include <math/vector2d.h>
40 #include <zone.h>
41 
42 class FROM_TO_CACHE;
43 class CN_CLUSTER;
45 class CN_EDGE;
46 class BOARD;
47 class BOARD_COMMIT;
49 class BOARD_ITEM;
50 class ZONE;
51 class RN_DATA;
52 class RN_NET;
53 class PCB_TRACK;
54 class PAD;
55 class FOOTPRINT;
56 class PROGRESS_REPORTER;
57 
59 {
60  int net;
63 };
64 
69 {
71  m_zone( aZone )
72  {}
73 
75 
76  std::map<PCB_LAYER_ID, std::vector<int>> m_islands;
77 };
78 
80 {
81  int netCode;
83 };
84 
88 enum class PROPAGATE_MODE
89 {
92 };
93 
94 // a wrapper class encompassing the connectivity computation algorithm and the
96 {
97 public:
100 
101  CONNECTIVITY_DATA( const std::vector<BOARD_ITEM*>& aItems, bool aSkipItems = false );
102 
107  void Build( BOARD* aBoard, PROGRESS_REPORTER* aReporter = nullptr );
108 
113  void Build( const std::vector<BOARD_ITEM*>& aItems );
114 
121  bool Add( BOARD_ITEM* aItem );
122 
129  bool Remove( BOARD_ITEM* aItem );
130 
137  bool Update( BOARD_ITEM* aItem );
138 
146  void Move( const VECTOR2I& aDelta );
147 
152  void Clear();
153 
158  int GetNetCount() const;
159 
164  RN_NET* GetRatsnestForNet( int aNet );
165 
171  void PropagateNets( BOARD_COMMIT* aCommit = nullptr,
173 
174  bool CheckConnectivity( std::vector<CN_DISJOINT_NET_ENTRY>& aReport );
175 
182  void FindIsolatedCopperIslands( ZONE* aZone, std::vector<int>& aIslands );
183  void FindIsolatedCopperIslands( std::vector<CN_ZONE_ISOLATED_ISLAND_LIST>& aZones );
184 
190  void RecalculateRatsnest( BOARD_COMMIT* aCommit = nullptr );
191 
196  unsigned int GetUnconnectedCount() const;
197 
198  bool IsConnectedOnLayer( const BOARD_CONNECTED_ITEM* aItem,
199  int aLayer, std::vector<KICAD_T> aTypes = {} ) const;
200 
201  unsigned int GetNodeCount( int aNet = -1 ) const;
202 
203  unsigned int GetPadCount( int aNet = -1 ) const;
204 
205  const std::vector<PCB_TRACK*> GetConnectedTracks( const BOARD_CONNECTED_ITEM* aItem ) const;
206 
207  const std::vector<PAD*> GetConnectedPads( const BOARD_CONNECTED_ITEM* aItem ) const;
208 
209  void GetConnectedPads( const BOARD_CONNECTED_ITEM* aItem, std::set<PAD*>* pads ) const;
210 
221  const std::vector<BOARD_CONNECTED_ITEM*> GetConnectedItemsAtAnchor(
222  const BOARD_CONNECTED_ITEM* aItem,
223  const VECTOR2I& aAnchor,
224  const KICAD_T aTypes[],
225  const int& aMaxError = 0 ) const;
226 
227  void GetUnconnectedEdges( std::vector<CN_EDGE>& aEdges ) const;
228 
229  bool TestTrackEndpointDangling( PCB_TRACK* aTrack, wxPoint* aPos = nullptr );
230 
236  void ClearDynamicRatsnest();
237 
241  void HideDynamicRatsnest();
242 
248  void ComputeDynamicRatsnest( const std::vector<BOARD_ITEM*>& aItems,
249  const CONNECTIVITY_DATA* aDynamicData );
250 
251  const std::vector<RN_DYNAMIC_LINE>& GetDynamicRatsnest() const
252  {
253  return m_dynamicRatsnest;
254  }
255 
262  const std::vector<BOARD_CONNECTED_ITEM*> GetConnectedItems( const BOARD_CONNECTED_ITEM* aItem,
263  const KICAD_T aTypes[], bool aIgnoreNetcodes = false ) const;
264 
271  const std::vector<BOARD_CONNECTED_ITEM*> GetNetItems( int aNetCode,
272  const KICAD_T aTypes[] ) const;
273 
274  void BlockRatsnestItems( const std::vector<BOARD_ITEM*>& aItems );
275 
276  std::shared_ptr<CN_CONNECTIVITY_ALGO> GetConnectivityAlgo() const
277  {
278  return m_connAlgo;
279  }
280 
282  {
283  return m_lock;
284  }
285 
286  void MarkItemNetAsDirty( BOARD_ITEM* aItem );
287  void SetProgressReporter( PROGRESS_REPORTER* aReporter );
288 
289  const std::map<int, wxString>& GetNetclassMap() const
290  {
291  return m_netclassMap;
292  }
293 
294 #ifndef SWIG
295  const std::vector<CN_EDGE> GetRatsnestForItems( const std::vector<BOARD_ITEM*> aItems );
296 
297  const std::vector<CN_EDGE> GetRatsnestForComponent( FOOTPRINT* aComponent,
298  bool aSkipInternalConnections = false );
299 #endif
300 
301  std::shared_ptr<FROM_TO_CACHE> GetFromToCache()
302  {
303  return m_fromToCache;
304  }
305 
306 private:
307 
308  void updateRatsnest();
309 
315  void updateItemPositions( const std::vector<BOARD_ITEM*>& aItems );
316  void addRatsnestCluster( const std::shared_ptr<CN_CLUSTER>& aCluster );
317 
318  std::shared_ptr<CN_CONNECTIVITY_ALGO> m_connAlgo;
319  std::shared_ptr<FROM_TO_CACHE> m_fromToCache;
320  std::vector<RN_DYNAMIC_LINE> m_dynamicRatsnest;
321  std::vector<RN_NET*> m_nets;
322 
324 
325  bool m_skipRatsnest = false;
326 
328 
330  std::map<int, wxString> m_netclassMap;
331 };
332 
333 #endif
void Clear()
Function Clear() Erases the connectivity database.
const std::vector< CN_EDGE > GetRatsnestForComponent(FOOTPRINT *aComponent, bool aSkipInternalConnections=false)
bool IsConnectedOnLayer(const BOARD_CONNECTED_ITEM *aItem, int aLayer, std::vector< KICAD_T > aTypes={}) const
unsigned int GetNodeCount(int aNet=-1) const
PROPAGATE_MODE
Controls how nets are propagated through clusters.
const std::vector< PCB_TRACK * > GetConnectedTracks(const BOARD_CONNECTED_ITEM *aItem) const
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:49
A progress reporter interface for use in multi-threaded environments.
std::shared_ptr< CN_CONNECTIVITY_ALGO > m_connAlgo
PROGRESS_REPORTER * m_progressReporter
std::shared_ptr< CN_CONNECTIVITY_ALGO > GetConnectivityAlgo() const
bool Update(BOARD_ITEM *aItem)
Function Update() Updates the connectivity data for an item.
const std::vector< BOARD_CONNECTED_ITEM * > GetNetItems(int aNetCode, const KICAD_T aTypes[]) const
Function GetNetItems() Returns the list of items that belong to a certain net.
void RecalculateRatsnest(BOARD_COMMIT *aCommit=nullptr)
Function RecalculateRatsnest() Updates the ratsnest for the board.
std::shared_ptr< FROM_TO_CACHE > m_fromToCache
void PropagateNets(BOARD_COMMIT *aCommit=nullptr, PROPAGATE_MODE aMode=PROPAGATE_MODE::SKIP_CONFLICTS)
Propagates the net codes from the source pads to the tracks/vias.
void updateItemPositions(const std::vector< BOARD_ITEM * > &aItems)
Updates the item positions without modifying the dirtyNet flag.
std::map< PCB_LAYER_ID, std::vector< int > > m_islands
BOARD_CONNECTED_ITEM * b
A base class derived from BOARD_ITEM for items that can be connected and have a net,...
std::vector< RN_DYNAMIC_LINE > m_dynamicRatsnest
Clusters with conflicting drivers are not updated (default)
VECTOR2I anchorB
KICAD_T
The set of class identification values stored in EDA_ITEM::m_structType.
Definition: typeinfo.h:77
const std::map< int, wxString > & GetNetclassMap() const
unsigned int GetPadCount(int aNet=-1) const
std::shared_ptr< FROM_TO_CACHE > GetFromToCache()
void Build(BOARD *aBoard, PROGRESS_REPORTER *aReporter=nullptr)
Function Build() Builds the connectivity database for the board aBoard.
VECTOR2I anchorA
const std::vector< BOARD_CONNECTED_ITEM * > GetConnectedItemsAtAnchor(const BOARD_CONNECTED_ITEM *aItem, const VECTOR2I &aAnchor, const KICAD_T aTypes[], const int &aMaxError=0) const
Function GetConnectedItemsAtAnchor() Returns a list of items connected to a source item aItem at posi...
const std::vector< BOARD_CONNECTED_ITEM * > GetConnectedItems(const BOARD_CONNECTED_ITEM *aItem, const KICAD_T aTypes[], bool aIgnoreNetcodes=false) const
Function GetConnectedItems() Returns a list of items connected to a source item aItem.
std::map< int, wxString > m_netclassMap
Map of netcode -> netclass the net is a member of; used for ratsnest painting.
unsigned int GetUnconnectedCount() const
Function GetUnconnectedCount() Returns the number of remaining edges in the ratsnest.
Handle a list of polygons defining a copper zone.
Definition: zone.h:56
void ClearDynamicRatsnest()
Function ClearDynamicRatsnest() Erases the temporary dynamic ratsnest (i.e.
void SetProgressReporter(PROGRESS_REPORTER *aReporter)
bool Remove(BOARD_ITEM *aItem)
Function Remove() Removes an item from the connectivity data.
void MarkItemNetAsDirty(BOARD_ITEM *aItem)
std::vector< RN_NET * > m_nets
void GetUnconnectedEdges(std::vector< CN_EDGE > &aEdges) const
bool Add(BOARD_ITEM *aItem)
Function Add() Adds an item to the connectivity data.
void BlockRatsnestItems(const std::vector< BOARD_ITEM * > &aItems)
RN_NET * GetRatsnestForNet(int aNet)
Function GetRatsnestForNet() Returns the ratsnest, expressed as a set of graph edges for a given net.
BOARD_CONNECTED_ITEM * a
bool CheckConnectivity(std::vector< CN_DISJOINT_NET_ENTRY > &aReport)
A trivial spinlock implementation with no optimization.
Definition: spinlock.h:29
void ComputeDynamicRatsnest(const std::vector< BOARD_ITEM * > &aItems, const CONNECTIVITY_DATA *aDynamicData)
Function ComputeDynamicRatsnest() Calculates the temporary dynamic ratsnest (i.e.
void FindIsolatedCopperIslands(ZONE *aZone, std::vector< int > &aIslands)
Function FindIsolatedCopperIslands() Searches for copper islands in zone aZone that are not connected...
const std::vector< RN_DYNAMIC_LINE > & GetDynamicRatsnest() const
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:190
int net
int GetNetCount() const
Function GetNetCount() Returns the total number of nets in the connectivity database.
bool TestTrackEndpointDangling(PCB_TRACK *aTrack, wxPoint *aPos=nullptr)
Describe ratsnest for a single net.
Definition: ratsnest_data.h:61
const std::vector< PAD * > GetConnectedPads(const BOARD_CONNECTED_ITEM *aItem) const
Definition: pad.h:57
void HideDynamicRatsnest()
Hides the temporary dynamic ratsnest lines.
void addRatsnestCluster(const std::shared_ptr< CN_CLUSTER > &aCluster)
void Move(const VECTOR2I &aDelta)
Moves the connectivity list anchors.
A structure used for calculating isolated islands on a given zone across all its layers.
const std::vector< CN_EDGE > GetRatsnestForItems(const std::vector< BOARD_ITEM * > aItems)
KISPINLOCK & GetLock()