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-2019 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 <wx/string.h>
33 #include <vector>
34 #include <memory>
35 
36 #include <math/vector2d.h>
38 #include <class_zone.h>
39 
40 class CN_CLUSTER;
42 class CN_EDGE;
43 class BOARD;
45 class BOARD_ITEM;
46 class ZONE_CONTAINER;
47 class RN_DATA;
48 class RN_NET;
49 class TRACK;
50 class D_PAD;
51 class MODULE;
52 class PROGRESS_REPORTER;
53 
55 {
56  int net;
59 };
60 
62 {
64  m_zone( aZone ),
65  m_lastPolys( aZone->GetFilledPolysList() )
66  {}
67 
70  std::vector<int> m_islands;
71 };
72 
74 {
75  int netCode;
77 };
78 
79 // a wrapper class encompassing the connectivity computation algorithm and the
81 {
82 public:
85 
86  CONNECTIVITY_DATA( const std::vector<BOARD_ITEM*>& aItems );
87 
92  void Build( BOARD* aBoard );
93 
98  void Build( const std::vector<BOARD_ITEM*>& aItems );
99 
106  bool Add( BOARD_ITEM* aItem );
107 
114  bool Remove( BOARD_ITEM* aItem );
115 
122  bool Update( BOARD_ITEM* aItem );
123 
128  void Clear();
129 
134  int GetNetCount() const;
135 
140  RN_NET* GetRatsnestForNet( int aNet );
141 
146  void PropagateNets();
147 
148  bool CheckConnectivity( std::vector<CN_DISJOINT_NET_ENTRY>& aReport );
149 
156  void FindIsolatedCopperIslands( ZONE_CONTAINER* aZone, std::vector<int>& aIslands );
157  void FindIsolatedCopperIslands( std::vector<CN_ZONE_ISOLATED_ISLAND_LIST>& aZones );
158 
163  void RecalculateRatsnest();
164 
169  unsigned int GetUnconnectedCount() const;
170 
171  unsigned int GetNodeCount( int aNet = -1 ) const;
172 
173  unsigned int GetPadCount( int aNet = -1 ) const;
174 
175  const std::vector<TRACK*> GetConnectedTracks( const BOARD_CONNECTED_ITEM* aItem ) const;
176 
177  const std::vector<D_PAD*> GetConnectedPads( const BOARD_CONNECTED_ITEM* aItem ) const;
178 
179  const void GetConnectedPads( const BOARD_CONNECTED_ITEM* aItem, std::set<D_PAD*>* pads ) const;
180 
181  const std::vector<BOARD_CONNECTED_ITEM*> GetConnectedItems( const BOARD_CONNECTED_ITEM* aItem, const VECTOR2I& aAnchor, KICAD_T aTypes[] );
182 
183  void GetUnconnectedEdges( std::vector<CN_EDGE>& aEdges ) const;
184 
190  void ClearDynamicRatsnest();
191 
195  void HideDynamicRatsnest();
196 
202  void ComputeDynamicRatsnest( const std::vector<BOARD_ITEM*>& aItems );
203 
204  const std::vector<RN_DYNAMIC_LINE>& GetDynamicRatsnest() const
205  {
206  return m_dynamicRatsnest;
207  }
208 
215  const std::vector<BOARD_CONNECTED_ITEM*> GetConnectedItems( const BOARD_CONNECTED_ITEM* aItem,
216  const KICAD_T aTypes[], bool aIgnoreNetcodes = false ) const;
217 
224  const std::vector<BOARD_CONNECTED_ITEM*> GetNetItems( int aNetCode,
225  const KICAD_T aTypes[] ) const;
226 
227  const std::vector<VECTOR2I> NearestUnconnectedTargets( const BOARD_CONNECTED_ITEM* aRef,
228  const VECTOR2I& aPos,
229  int aMaxCount = -1 );
230 
231  void BlockRatsnestItems( const std::vector<BOARD_ITEM*>& aItems );
232 
233  std::shared_ptr<CN_CONNECTIVITY_ALGO> GetConnectivityAlgo() const
234  {
235  return m_connAlgo;
236  }
237 
238  std::mutex& GetLock()
239  {
240  return m_lock;
241  }
242 
243  void MarkItemNetAsDirty( BOARD_ITEM* aItem );
244  void SetProgressReporter( PROGRESS_REPORTER* aReporter );
245 
246 #ifndef SWIG
247  const std::vector<CN_EDGE> GetRatsnestForComponent( MODULE* aComponent, bool aSkipInternalConnections = false );
248 #endif
249 
250 private:
251 
252  void updateRatsnest();
253  void addRatsnestCluster( const std::shared_ptr<CN_CLUSTER>& aCluster );
254 
255  std::shared_ptr<CN_CONNECTIVITY_ALGO> m_connAlgo;
256 
257  std::vector<RN_DYNAMIC_LINE> m_dynamicRatsnest;
258  std::vector<RN_NET*> m_nets;
259 
261 
262  std::mutex m_lock;
263 };
264 
265 #endif
const std::vector< TRACK * > GetConnectedTracks(const BOARD_CONNECTED_ITEM *aItem) const
void Clear()
Function Clear() Erases the connectivity database.
Class ZONE_CONTAINER handles a list of polygons defining a copper zone.
Definition: class_zone.h:59
unsigned int GetNodeCount(int aNet=-1) const
Class 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.
const std::vector< BOARD_CONNECTED_ITEM * > GetConnectedItems(const BOARD_CONNECTED_ITEM *aItem, const VECTOR2I &aAnchor, KICAD_T aTypes[])
Classes to handle copper zones.
void RecalculateRatsnest()
Function RecalculateRatsnest() Updates the ratsnest for the board.
void FindIsolatedCopperIslands(ZONE_CONTAINER *aZone, std::vector< int > &aIslands)
Function FindIsolatedCopperIslands() Searches for copper islands in zone aZone that are not connected...
const SHAPE_POLY_SET m_lastPolys
BOARD_CONNECTED_ITEM * b
Class BOARD_CONNECTED_ITEM is a base class derived from BOARD_ITEM for items that can be connected an...
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
void BlockRatsnestItems(const std::vector< BOARD_ITEM *> &aItems)
std::mutex & GetLock()
unsigned int GetPadCount(int aNet=-1) const
VECTOR2I anchorA
Class SHAPE_POLY_SET.
const std::vector< VECTOR2I > NearestUnconnectedTargets(const BOARD_CONNECTED_ITEM *aRef, const VECTOR2I &aPos, int aMaxCount=-1)
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.
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)
const std::vector< RN_DYNAMIC_LINE > & GetDynamicRatsnest() const
Class BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:171
const std::vector< CN_EDGE > GetRatsnestForComponent(MODULE *aComponent, bool aSkipInternalConnections=false)
void ComputeDynamicRatsnest(const std::vector< BOARD_ITEM *> &aItems)
Function ComputeDynamicRatsnest() Calculates the temporary dynamic ratsnest (i.e. ...
int net
int GetNetCount() const
Function GetNetCount() Returns the total number of nets in the connectivity database.
Class RN_NET Describes ratsnest for a single net.
Definition: ratsnest_data.h:59
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)