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 
32 #include <memory>
33 #include <mutex>
34 #include <vector>
35 #include <wx/string.h>
36 
37 #include <math/vector2d.h>
39 #include <class_zone.h>
40 
41 class CN_CLUSTER;
43 class CN_EDGE;
44 class BOARD;
45 class BOARD_COMMIT;
47 class BOARD_ITEM;
48 class ZONE_CONTAINER;
49 class RN_DATA;
50 class RN_NET;
51 class TRACK;
52 class D_PAD;
53 class MODULE;
54 class PROGRESS_REPORTER;
55 
57 {
58  int net;
61 };
62 
67 {
69  m_zone( aZone )
70  {}
71 
73 
74  std::map<PCB_LAYER_ID, std::vector<int>> m_islands;
75 };
76 
78 {
79  int netCode;
81 };
82 
83 // a wrapper class encompassing the connectivity computation algorithm and the
85 {
86 public:
89 
90  CONNECTIVITY_DATA( const std::vector<BOARD_ITEM*>& aItems, bool aSkipItems = false );
91 
96  void Build( BOARD* aBoard );
97 
102  void Build( const std::vector<BOARD_ITEM*>& aItems );
103 
110  bool Add( BOARD_ITEM* aItem );
111 
118  bool Remove( BOARD_ITEM* aItem );
119 
126  bool Update( BOARD_ITEM* aItem );
127 
135  void Move( const VECTOR2I& aDelta );
136 
141  void Clear();
142 
147  int GetNetCount() const;
148 
153  RN_NET* GetRatsnestForNet( int aNet );
154 
159  void PropagateNets();
160 
161  bool CheckConnectivity( std::vector<CN_DISJOINT_NET_ENTRY>& aReport );
162 
169  void FindIsolatedCopperIslands( ZONE_CONTAINER* aZone, std::vector<int>& aIslands );
170  void FindIsolatedCopperIslands( std::vector<CN_ZONE_ISOLATED_ISLAND_LIST>& aZones );
171 
177  void RecalculateRatsnest( BOARD_COMMIT* aCommit = nullptr );
178 
183  unsigned int GetUnconnectedCount() const;
184 
185  bool IsConnectedOnLayer( const BOARD_CONNECTED_ITEM* aItem, int aLayer, std::vector<KICAD_T> aTypes = {} ) const;
186 
187  unsigned int GetNodeCount( int aNet = -1 ) const;
188 
189  unsigned int GetPadCount( int aNet = -1 ) const;
190 
191  const std::vector<TRACK*> GetConnectedTracks( const BOARD_CONNECTED_ITEM* aItem ) const;
192 
193  const std::vector<D_PAD*> GetConnectedPads( const BOARD_CONNECTED_ITEM* aItem ) const;
194 
195  void GetConnectedPads( const BOARD_CONNECTED_ITEM* aItem, std::set<D_PAD*>* pads ) const;
196 
197  const std::vector<BOARD_CONNECTED_ITEM*> GetConnectedItems( const BOARD_CONNECTED_ITEM* aItem, const VECTOR2I& aAnchor, KICAD_T aTypes[] );
198 
199  void GetUnconnectedEdges( std::vector<CN_EDGE>& aEdges ) const;
200 
201  bool TestTrackEndpointDangling( TRACK* aTrack, wxPoint* aPos = nullptr );
202 
208  void ClearDynamicRatsnest();
209 
213  void HideDynamicRatsnest();
214 
220  void ComputeDynamicRatsnest( const std::vector<BOARD_ITEM*>& aItems,
221  const CONNECTIVITY_DATA* aDynamicData );
222 
223  const std::vector<RN_DYNAMIC_LINE>& GetDynamicRatsnest() const
224  {
225  return m_dynamicRatsnest;
226  }
227 
234  const std::vector<BOARD_CONNECTED_ITEM*> GetConnectedItems( const BOARD_CONNECTED_ITEM* aItem,
235  const KICAD_T aTypes[], bool aIgnoreNetcodes = false ) const;
236 
243  const std::vector<BOARD_CONNECTED_ITEM*> GetNetItems( int aNetCode,
244  const KICAD_T aTypes[] ) const;
245 
246  void BlockRatsnestItems( const std::vector<BOARD_ITEM*>& aItems );
247 
248  std::shared_ptr<CN_CONNECTIVITY_ALGO> GetConnectivityAlgo() const
249  {
250  return m_connAlgo;
251  }
252 
253  std::mutex& GetLock()
254  {
255  return m_lock;
256  }
257 
258  void MarkItemNetAsDirty( BOARD_ITEM* aItem );
259  void SetProgressReporter( PROGRESS_REPORTER* aReporter );
260 
261  const std::map<int, wxString>& GetNetclassMap() const
262  {
263  return m_netclassMap;
264  }
265 
266 #ifndef SWIG
267  const std::vector<CN_EDGE> GetRatsnestForItems( const std::vector<BOARD_ITEM*> aItems );
268 
269  const std::vector<CN_EDGE> GetRatsnestForComponent( MODULE* aComponent, bool aSkipInternalConnections = false );
270 #endif
271 
272 private:
273 
274  void updateRatsnest();
275 
281  void updateItemPositions( const std::vector<BOARD_ITEM*>& aItems );
282  void addRatsnestCluster( const std::shared_ptr<CN_CLUSTER>& aCluster );
283 
284  std::shared_ptr<CN_CONNECTIVITY_ALGO> m_connAlgo;
285 
286  std::vector<RN_DYNAMIC_LINE> m_dynamicRatsnest;
287  std::vector<RN_NET*> m_nets;
288 
290 
291  bool m_skipRatsnest = false;
292 
293  std::mutex m_lock;
294 
296  std::map<int, wxString> m_netclassMap;
297 };
298 
299 #endif
const std::vector< TRACK * > GetConnectedTracks(const BOARD_CONNECTED_ITEM *aItem) const
void Clear()
Function Clear() Erases the connectivity database.
ZONE_CONTAINER handles a list of polygons defining a copper zone.
Definition: class_zone.h:61
bool IsConnectedOnLayer(const BOARD_CONNECTED_ITEM *aItem, int aLayer, std::vector< KICAD_T > aTypes={}) const
unsigned int GetNodeCount(int aNet=-1) const
bool TestTrackEndpointDangling(TRACK *aTrack, wxPoint *aPos=nullptr)
BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class,...
A progress reporter 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.
const std::vector< BOARD_CONNECTED_ITEM * > GetConnectedItems(const BOARD_CONNECTED_ITEM *aItem, const VECTOR2I &aAnchor, KICAD_T aTypes[])
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
void FindIsolatedCopperIslands(ZONE_CONTAINER *aZone, std::vector< int > &aIslands)
Function FindIsolatedCopperIslands() Searches for copper islands in zone aZone that are not connected...
BOARD_CONNECTED_ITEM * b
BOARD_CONNECTED_ITEM is a base class derived from BOARD_ITEM for items that can be connected and have...
std::vector< RN_DYNAMIC_LINE > m_dynamicRatsnest
VECTOR2I anchorB
KICAD_T
Enum KICAD_T is the set of class identification values, stored in EDA_ITEM::m_StructType.
Definition: typeinfo.h:78
const std::map< int, wxString > & GetNetclassMap() const
std::mutex & GetLock()
unsigned int GetPadCount(int aNet=-1) const
VECTOR2I anchorA
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.
void PropagateNets()
Function PropagateNets() Propagates the net codes from the source pads to the tracks/vias.
CN_ZONE_ISOLATED_ISLAND_LIST(ZONE_CONTAINER *aZone)
const std::vector< D_PAD * > GetConnectedPads(const BOARD_CONNECTED_ITEM *aItem) const
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)
void ComputeDynamicRatsnest(const std::vector< BOARD_ITEM * > &aItems, const CONNECTIVITY_DATA *aDynamicData)
Function ComputeDynamicRatsnest() Calculates the temporary dynamic ratsnest (i.e.
const std::vector< RN_DYNAMIC_LINE > & GetDynamicRatsnest() const
BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:178
const std::vector< CN_EDGE > GetRatsnestForComponent(MODULE *aComponent, bool aSkipInternalConnections=false)
int net
int GetNetCount() const
Function GetNetCount() Returns the total number of nets in the connectivity database.
RN_NET Describes ratsnest for a single net.
Definition: ratsnest_data.h:61
void Build(BOARD *aBoard)
Function Build() Builds the connectivity database for the board aBoard.
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)