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 The 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, see <https://www.gnu.org/licenses/>.
21 */
22
23#ifndef __CONNECTIVITY_DATA_H
24#define __CONNECTIVITY_DATA_H
25
26#include <core/typeinfo.h>
27#include <core/spinlock.h>
28
29#include <memory>
30#include <mutex>
31#include <set>
32#include <vector>
33#include <wx/string.h>
34
35#include <math/vector2d.h>
36#include <zone.h>
37
38class FROM_TO_CACHE;
39class NET_SETTINGS;
40class CN_CLUSTER;
42class CN_EDGE;
43class BOARD;
44class BOARD_COMMIT;
46class BOARD_ITEM;
47class ZONE;
48class RN_DATA;
49class RN_NET;
50class PCB_ARC;
51class PCB_TRACK;
52class PCB_VIA;
53class PAD;
54class FOOTPRINT;
56
57
64
65
67{
70};
71
72
81
82
83// a wrapper class encompassing the connectivity computation algorithm and the
85{
86public:
89
90 CONNECTIVITY_DATA( std::shared_ptr<CONNECTIVITY_DATA> aGlobalConnectivity,
91 const std::vector<BOARD_ITEM*>& aLocalItems,
92 bool aSkipRatsnestUpdate = false );
93
97 bool Build( BOARD* aBoard, PROGRESS_REPORTER* aReporter = nullptr );
98
102 void Build( std::shared_ptr<CONNECTIVITY_DATA>& aGlobalConnectivity,
103 const std::vector<BOARD_ITEM*>& aLocalItems );
104
110 bool Add( BOARD_ITEM* aItem );
111
117 bool Remove( BOARD_ITEM* aItem );
118
124 bool Update( BOARD_ITEM* aItem );
125
133 void Move( const VECTOR2I& aDelta );
134
138 void ClearRatsnest();
139
143 int GetNetCount() const;
144
148 RN_NET* GetRatsnestForNet( int aNet );
149
154 void PropagateNets( BOARD_COMMIT* aCommit = nullptr );
155
160 void FillIsolatedIslandsMap( std::map<ZONE*, std::map<PCB_LAYER_ID, ISOLATED_ISLANDS>>& aMap,
161 bool aConnectivityAlreadyRebuilt = false );
162
167 void RecalculateRatsnest( BOARD_COMMIT* aCommit = nullptr );
168
173 unsigned int GetUnconnectedCount( bool aVisibleOnly ) const;
174
175 bool IsConnectedOnLayer( const BOARD_CONNECTED_ITEM* aItem, int aLayer,
176 const std::initializer_list<KICAD_T>& aTypes = {} ) const;
177
178 unsigned int GetNodeCount( int aNet = -1 ) const;
179
180 unsigned int GetPadCount( int aNet = -1 ) const;
181
182 const std::vector<PCB_TRACK*> GetConnectedTracks( const BOARD_CONNECTED_ITEM* aItem ) const;
183
184 const std::vector<PAD*> GetConnectedPads( const BOARD_CONNECTED_ITEM* aItem ) const;
185
186 void GetConnectedPads( const BOARD_CONNECTED_ITEM* aItem, std::set<PAD*>* pads ) const;
187
188 void GetConnectedPadsAndVias( const BOARD_CONNECTED_ITEM* aItem, std::vector<PAD*>* pads,
189 std::vector<PCB_VIA*>* vias );
190
195 void GetZoneIslandConnections( const ZONE* aZone, PCB_LAYER_ID aLayer,
196 std::vector<std::set<const BOARD_ITEM*>>* aIslands );
197
208 const std::vector<BOARD_CONNECTED_ITEM*>
209 GetConnectedItemsAtAnchor( const BOARD_CONNECTED_ITEM* aItem, const VECTOR2I& aAnchor,
210 const std::vector<KICAD_T>& aTypes, const int& aMaxError = 0 ) const;
211
212 void RunOnUnconnectedEdges( std::function<bool( CN_EDGE& )> aFunc );
213
214 bool TestTrackEndpointDangling( PCB_TRACK* aTrack, bool aIgnoreTracksInPads,
215 VECTOR2I* aPos = nullptr ) const;
216
221 void ClearLocalRatsnest();
222
226 void HideLocalRatsnest();
227
231 void ComputeLocalRatsnest( const std::vector<BOARD_ITEM*>& aItems,
232 const CONNECTIVITY_DATA* aDynamicData,
233 VECTOR2I aInternalOffset = { 0, 0 } );
234
235 const std::vector<RN_DYNAMIC_LINE>& GetLocalRatsnest() const { return m_dynamicRatsnest; }
236
242#define IGNORE_NETS 0x0001
243#define EXCLUDE_ZONES 0x0002
244 const std::vector<BOARD_CONNECTED_ITEM*> GetConnectedItems( const BOARD_CONNECTED_ITEM* aItem,
245 int aFlags = 0 ) const;
246
252 const std::vector<BOARD_CONNECTED_ITEM*>
253 GetNetItems( int aNetCode, const std::vector<KICAD_T>& aTypes ) const;
254
255 void BlockRatsnestItems( const std::vector<BOARD_ITEM*>& aItems );
256
257 std::shared_ptr<CN_CONNECTIVITY_ALGO> GetConnectivityAlgo() const { return m_connAlgo; }
258
259 KISPINLOCK& GetLock() { return m_lock; }
260
261 void MarkItemNetAsDirty( BOARD_ITEM* aItem );
262 void RemoveInvalidRefs();
263
264 void SetProgressReporter( PROGRESS_REPORTER* aReporter );
265
266 const NET_SETTINGS* GetNetSettings() const;
267
268 bool HasNetNameForNetCode( int nc ) const { return m_netcodeMap.count( nc ) > 0; }
269 const wxString& GetNetNameForNetCode( int nc ) const { return m_netcodeMap.at( nc ); }
270
272 void RefreshNetcodeMap( BOARD* aBoard );
273
274 const std::vector<CN_EDGE> GetRatsnestForItems( const std::vector<BOARD_ITEM*>& aItems );
275
276 const std::vector<CN_EDGE> GetRatsnestForPad( const PAD* aPad );
277
278 const std::vector<CN_EDGE> GetRatsnestForComponent( FOOTPRINT* aComponent,
279 bool aSkipInternalConnections = false );
280
281 std::shared_ptr<FROM_TO_CACHE> GetFromToCache() { return m_fromToCache; }
282
283private:
284
289 void internalRecalculateRatsnest( BOARD_COMMIT* aCommit = nullptr );
290 void updateRatsnest();
291
292 void addRatsnestCluster( const std::shared_ptr<CN_CLUSTER>& aCluster );
293
294private:
295 std::shared_ptr<CN_CONNECTIVITY_ALGO> m_connAlgo;
296
297 std::shared_ptr<FROM_TO_CACHE> m_fromToCache;
298 std::vector<RN_DYNAMIC_LINE> m_dynamicRatsnest;
299 std::vector<RN_NET*> m_nets;
300
303
305
307
309 std::weak_ptr<NET_SETTINGS> m_netSettings;
310
312 std::map<int, wxString> m_netcodeMap;
313};
314
315#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:84
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:410
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)
Update the ratsnest for the board.
void ClearLocalRatsnest()
Erase 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
void MarkItemNetAsDirty(BOARD_ITEM *aItem)
std::weak_ptr< NET_SETTINGS > m_netSettings
Used to get netclass data when drawing ratsnests.
const std::vector< BOARD_CONNECTED_ITEM * > GetConnectedItems(const BOARD_CONNECTED_ITEM *aItem, int aFlags=0) const
void PropagateNets(BOARD_COMMIT *aCommit=nullptr)
Propagate 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)
Return the ratsnest, expressed as a set of graph edges for a given net.
const std::vector< BOARD_CONNECTED_ITEM * > GetConnectedItemsAtAnchor(const BOARD_CONNECTED_ITEM *aItem, const VECTOR2I &aAnchor, const std::vector< KICAD_T > &aTypes, const int &aMaxError=0) const
Return a list of items connected to a source item aItem at position aAnchor with an optional maximum ...
const wxString & GetNetNameForNetCode(int nc) const
void ClearRatsnest()
Erases the connectivity database.
bool Remove(BOARD_ITEM *aItem)
Remove an item from the connectivity data.
void GetConnectedPadsAndVias(const BOARD_CONNECTED_ITEM *aItem, std::vector< PAD * > *pads, std::vector< PCB_VIA * > *vias)
const NET_SETTINGS * GetNetSettings() const
void ComputeLocalRatsnest(const std::vector< BOARD_ITEM * > &aItems, const CONNECTIVITY_DATA *aDynamicData, VECTOR2I aInternalOffset={ 0, 0 })
Calculate the temporary (usually selection-based) ratsnest for the set of aItems.
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
const std::vector< CN_EDGE > GetRatsnestForComponent(FOOTPRINT *aComponent, bool aSkipInternalConnections=false)
const std::vector< BOARD_CONNECTED_ITEM * > GetNetItems(int aNetCode, const std::vector< KICAD_T > &aTypes) const
Return the list of items that belong to a certain net.
bool Add(BOARD_ITEM *aItem)
Add an item to the connectivity data.
unsigned int GetUnconnectedCount(bool aVisibleOnly) const
std::shared_ptr< CN_CONNECTIVITY_ALGO > m_connAlgo
bool Build(BOARD *aBoard, PROGRESS_REPORTER *aReporter=nullptr)
Build 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
bool HasNetNameForNetCode(int nc) const
std::map< int, wxString > m_netcodeMap
Used to map netcode to net name.
void internalRecalculateRatsnest(BOARD_COMMIT *aCommit=nullptr)
Update the ratsnest for the board without locking the connectivity mutex.
void RefreshNetcodeMap(BOARD *aBoard)
Refresh the map of netcodes to net names.
void HideLocalRatsnest()
Hide 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)
Update the connectivity data for an item.
void Move(const VECTOR2I &aDelta)
Move the connectivity list anchors.
int GetNetCount() const
Return the total number of nets in the connectivity database.
void GetZoneIslandConnections(const ZONE *aZone, PCB_LAYER_ID aLayer, std::vector< std::set< const BOARD_ITEM * > > *aIslands)
Return, for each filled island of aZone on aLayer, the items that island touches.
std::shared_ptr< CN_CONNECTIVITY_ALGO > GetConnectivityAlgo() const
A trivial spinlock implementation with no optimization.
Definition spinlock.h:30
NET_SETTINGS stores various net-related settings in a project context.
Definition pad.h:61
A progress reporter interface for use in multi-threaded environments.
Describe ratsnest for a single net.
Handle a list of polygons defining a copper zone.
Definition zone.h:70
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.
PCB_LAYER_ID
A quick note on layer IDs:
Definition layer_ids.h:56
BOARD_CONNECTED_ITEM * b
BOARD_CONNECTED_ITEM * a
int net
VECTOR2I anchorB
VECTOR2I anchorA
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:708