KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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-2023 KiCad Developers, see AUTHORS.txt for contributors.
6 * @author Maciej Suminski <[email protected]>
7 * @author Tomasz Wlostowski <[email protected]>
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
42class FROM_TO_CACHE;
43class CN_CLUSTER;
45class CN_EDGE;
46class BOARD;
47class BOARD_COMMIT;
49class BOARD_ITEM;
50class ZONE;
51class RN_DATA;
52class RN_NET;
53class PCB_TRACK;
54class PCB_VIA;
55class PAD;
56class FOOTPRINT;
58
59
61{
62 int net;
65};
66
67
69{
72};
73
74
79{
82};
83
84
85// a wrapper class encompassing the connectivity computation algorithm and the
87{
88public:
91
92 CONNECTIVITY_DATA( std::shared_ptr<CONNECTIVITY_DATA> aGlobalConnectivity,
93 const std::vector<BOARD_ITEM*>& aLocalItems, bool aSkipRatsnestUpdate = false );
94
99 bool Build( BOARD* aBoard, PROGRESS_REPORTER* aReporter = nullptr );
100
105 void Build( std::shared_ptr<CONNECTIVITY_DATA>& aGlobalConnectivity,
106 const std::vector<BOARD_ITEM*>& aLocalItems );
107
114 bool Add( BOARD_ITEM* aItem );
115
122 bool Remove( BOARD_ITEM* aItem );
123
130 bool Update( BOARD_ITEM* aItem );
131
139 void Move( const VECTOR2I& aDelta );
140
145 void ClearRatsnest();
146
151 int GetNetCount() const;
152
157 RN_NET* GetRatsnestForNet( int aNet );
158
164 void PropagateNets( BOARD_COMMIT* aCommit = nullptr );
165
170 void FillIsolatedIslandsMap( std::map<ZONE*, std::map<PCB_LAYER_ID, ISOLATED_ISLANDS>>& aMap,
171 bool aConnectivityAlreadyRebuilt = false );
172
178 void RecalculateRatsnest( BOARD_COMMIT* aCommit = nullptr );
179
184 unsigned int GetUnconnectedCount( bool aVisibileOnly ) const;
185
186 bool IsConnectedOnLayer( const BOARD_CONNECTED_ITEM* aItem, int aLayer,
187 const std::initializer_list<KICAD_T>& aTypes = {} ) const;
188
189 unsigned int GetNodeCount( int aNet = -1 ) const;
190
191 unsigned int GetPadCount( int aNet = -1 ) const;
192
193 const std::vector<PCB_TRACK*> GetConnectedTracks( const BOARD_CONNECTED_ITEM* aItem ) const;
194
195 const std::vector<PAD*> GetConnectedPads( const BOARD_CONNECTED_ITEM* aItem ) const;
196
197 void GetConnectedPads( const BOARD_CONNECTED_ITEM* aItem, std::set<PAD*>* pads ) const;
198
199 void GetConnectedPadsAndVias( const BOARD_CONNECTED_ITEM* aItem, std::vector<PAD*>* pads,
200 std::vector<PCB_VIA*>* vias );
201
212 const std::vector<BOARD_CONNECTED_ITEM*>
213 GetConnectedItemsAtAnchor( const BOARD_CONNECTED_ITEM* aItem, const VECTOR2I& aAnchor,
214 const std::initializer_list<KICAD_T>& aTypes,
215 const int& aMaxError = 0 ) const;
216
217 void RunOnUnconnectedEdges( std::function<bool( CN_EDGE& )> aFunc );
218
219 bool TestTrackEndpointDangling( PCB_TRACK* aTrack, bool aIgnoreTracksInPads,
220 VECTOR2I* aPos = nullptr ) const;
221
227 void ClearLocalRatsnest();
228
232 void HideLocalRatsnest();
233
238 void ComputeLocalRatsnest( const std::vector<BOARD_ITEM*>& aItems,
239 const CONNECTIVITY_DATA* aDynamicData,
240 VECTOR2I aInternalOffset = { 0, 0 } );
241
242 const std::vector<RN_DYNAMIC_LINE>& GetLocalRatsnest() const { return m_dynamicRatsnest; }
243
250 const std::vector<BOARD_CONNECTED_ITEM*>
252 const std::initializer_list<KICAD_T>& aTypes,
253 bool aIgnoreNetcodes = false ) const;
254
261 const std::vector<BOARD_CONNECTED_ITEM*>
262 GetNetItems( int aNetCode, const std::initializer_list<KICAD_T>& aTypes ) const;
263
264 void BlockRatsnestItems( const std::vector<BOARD_ITEM*>& aItems );
265
266 std::shared_ptr<CN_CONNECTIVITY_ALGO> GetConnectivityAlgo() const { return m_connAlgo; }
267
268 KISPINLOCK& GetLock() { return m_lock; }
269
270 void MarkItemNetAsDirty( BOARD_ITEM* aItem );
271 void RemoveInvalidRefs();
272
273 void SetProgressReporter( PROGRESS_REPORTER* aReporter );
274
275 const std::map<int, wxString>& GetNetclassMap() const { return m_netclassMap; }
276
277#ifndef SWIG
278 const std::vector<CN_EDGE> GetRatsnestForItems( const std::vector<BOARD_ITEM*>& aItems );
279
280 const std::vector<CN_EDGE> GetRatsnestForPad( const PAD* aPad );
281
282 const std::vector<CN_EDGE> GetRatsnestForComponent( FOOTPRINT* aComponent,
283 bool aSkipInternalConnections = false );
284#endif
285
286 std::shared_ptr<FROM_TO_CACHE> GetFromToCache() { return m_fromToCache; }
287
288private:
289
294 void internalRecalculateRatsnest( BOARD_COMMIT* aCommit = nullptr );
295 void updateRatsnest();
296
297 void addRatsnestCluster( const std::shared_ptr<CN_CLUSTER>& aCluster );
298
299private:
300 std::shared_ptr<CN_CONNECTIVITY_ALGO> m_connAlgo;
301
302 std::shared_ptr<FROM_TO_CACHE> m_fromToCache;
303 std::vector<RN_DYNAMIC_LINE> m_dynamicRatsnest;
304 std::vector<RN_NET*> m_nets;
305
308
310
312 std::map<int, wxString> m_netclassMap;
313
315};
316
317#endif
A base class derived from BOARD_ITEM for items that can be connected and have a net,...
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:77
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:276
CN_EDGE represents a point-to-point connection, whether realized or unrealized (ie: tracks etc.
void FillIsolatedIslandsMap(std::map< ZONE *, std::map< PCB_LAYER_ID, ISOLATED_ISLANDS > > &aMap, bool aConnectivityAlreadyRebuilt=false)
Fill the isolate islands list for each layer of each zone.
void RecalculateRatsnest(BOARD_COMMIT *aCommit=nullptr)
Function RecalculateRatsnest() Updates the ratsnest for the board.
const std::map< int, wxString > & GetNetclassMap() const
void ClearLocalRatsnest()
Function ClearLocalRatsnest() Erases the temporary, selection-based ratsnest (i.e.
PROGRESS_REPORTER * m_progressReporter
const std::vector< RN_DYNAMIC_LINE > & GetLocalRatsnest() const
unsigned int GetPadCount(int aNet=-1) const
const std::vector< BOARD_CONNECTED_ITEM * > GetConnectedItemsAtAnchor(const BOARD_CONNECTED_ITEM *aItem, const VECTOR2I &aAnchor, const std::initializer_list< KICAD_T > &aTypes, const int &aMaxError=0) const
Function GetConnectedItemsAtAnchor() Returns a list of items connected to a source item aItem at posi...
void MarkItemNetAsDirty(BOARD_ITEM *aItem)
void PropagateNets(BOARD_COMMIT *aCommit=nullptr)
Propagates the net codes from the source pads to the tracks/vias.
KISPINLOCK & GetLock()
void RunOnUnconnectedEdges(std::function< bool(CN_EDGE &)> aFunc)
std::vector< RN_DYNAMIC_LINE > m_dynamicRatsnest
bool m_skipRatsnestUpdate
Used to suppress ratsnest calculations on dynamic ratsnests.
const std::vector< CN_EDGE > GetRatsnestForPad(const PAD *aPad)
RN_NET * GetRatsnestForNet(int aNet)
Function GetRatsnestForNet() Returns the ratsnest, expressed as a set of graph edges for a given net.
void ClearRatsnest()
Function Clear() Erases the connectivity database.
bool Remove(BOARD_ITEM *aItem)
Function Remove() Removes an item from the connectivity data.
void GetConnectedPadsAndVias(const BOARD_CONNECTED_ITEM *aItem, std::vector< PAD * > *pads, std::vector< PCB_VIA * > *vias)
void ComputeLocalRatsnest(const std::vector< BOARD_ITEM * > &aItems, const CONNECTIVITY_DATA *aDynamicData, VECTOR2I aInternalOffset={ 0, 0 })
Function ComputeLocalRatsnest() Calculates the temporary (usually selection-based) ratsnest for the s...
bool TestTrackEndpointDangling(PCB_TRACK *aTrack, bool aIgnoreTracksInPads, VECTOR2I *aPos=nullptr) const
unsigned int GetNodeCount(int aNet=-1) const
void SetProgressReporter(PROGRESS_REPORTER *aReporter)
void BlockRatsnestItems(const std::vector< BOARD_ITEM * > &aItems)
bool IsConnectedOnLayer(const BOARD_CONNECTED_ITEM *aItem, int aLayer, const std::initializer_list< KICAD_T > &aTypes={}) const
const std::vector< PCB_TRACK * > GetConnectedTracks(const BOARD_CONNECTED_ITEM *aItem) const
std::map< int, wxString > m_netclassMap
Map of netcode -> netclass the net is a member of; used for ratsnest painting.
const std::vector< CN_EDGE > GetRatsnestForComponent(FOOTPRINT *aComponent, bool aSkipInternalConnections=false)
bool Add(BOARD_ITEM *aItem)
Function Add() Adds an item to the connectivity data.
const std::vector< BOARD_CONNECTED_ITEM * > GetConnectedItems(const BOARD_CONNECTED_ITEM *aItem, const std::initializer_list< KICAD_T > &aTypes, bool aIgnoreNetcodes=false) const
Function GetConnectedItems() Returns a list of items connected to a source item aItem.
std::shared_ptr< CN_CONNECTIVITY_ALGO > m_connAlgo
bool Build(BOARD *aBoard, PROGRESS_REPORTER *aReporter=nullptr)
Function Build() Builds the connectivity database for the board aBoard.
std::shared_ptr< FROM_TO_CACHE > m_fromToCache
const std::vector< PAD * > GetConnectedPads(const BOARD_CONNECTED_ITEM *aItem) const
const std::vector< BOARD_CONNECTED_ITEM * > GetNetItems(int aNetCode, const std::initializer_list< KICAD_T > &aTypes) const
Function GetNetItems() Returns the list of items that belong to a certain net.
unsigned int GetUnconnectedCount(bool aVisibileOnly) const
void internalRecalculateRatsnest(BOARD_COMMIT *aCommit=nullptr)
Updates the ratsnest for the board without locking the connectivity mutex.
void HideLocalRatsnest()
Hides the temporary, selection-based ratsnest lines.
const std::vector< CN_EDGE > GetRatsnestForItems(const std::vector< BOARD_ITEM * > &aItems)
void addRatsnestCluster(const std::shared_ptr< CN_CLUSTER > &aCluster)
std::vector< RN_NET * > m_nets
std::shared_ptr< FROM_TO_CACHE > GetFromToCache()
bool Update(BOARD_ITEM *aItem)
Function Update() Updates the connectivity data for an item.
void Move(const VECTOR2I &aDelta)
Moves the connectivity list anchors.
int GetNetCount() const
Function GetNetCount() Returns the total number of nets in the connectivity database.
std::shared_ptr< CN_CONNECTIVITY_ALGO > GetConnectivityAlgo() const
A trivial spinlock implementation with no optimization.
Definition: spinlock.h:30
Definition: pad.h:59
A progress reporter interface for use in multi-threaded environments.
Describe ratsnest for a single net.
Definition: ratsnest_data.h:63
Handle a list of polygons defining a copper zone.
Definition: zone.h:72
PROPAGATE_MODE
Controls how nets are propagated through clusters.
@ SKIP_CONFLICTS
Clusters with conflicting drivers are not updated (default)
@ RESOLVE_CONFLICTS
Clusters with conflicting drivers are updated to the most popular net.
BOARD_CONNECTED_ITEM * b
BOARD_CONNECTED_ITEM * a
int net
VECTOR2I anchorB
VECTOR2I anchorA