You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

268 lines
7.7 KiB

  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. #ifndef __CONNECTIVITY_DATA_H
  27. #define __CONNECTIVITY_DATA_H
  28. #include <core/typeinfo.h>
  29. #include <memory>
  30. #include <mutex>
  31. #include <vector>
  32. #include <wx/string.h>
  33. #include <math/vector2d.h>
  34. #include <geometry/shape_poly_set.h>
  35. #include <class_zone.h>
  36. class CN_CLUSTER;
  37. class CN_CONNECTIVITY_ALGO;
  38. class CN_EDGE;
  39. class BOARD;
  40. class BOARD_COMMIT;
  41. class BOARD_CONNECTED_ITEM;
  42. class BOARD_ITEM;
  43. class ZONE_CONTAINER;
  44. class RN_DATA;
  45. class RN_NET;
  46. class TRACK;
  47. class D_PAD;
  48. class MODULE;
  49. class PROGRESS_REPORTER;
  50. struct CN_DISJOINT_NET_ENTRY
  51. {
  52. int net;
  53. BOARD_CONNECTED_ITEM *a, *b;
  54. VECTOR2I anchorA, anchorB;
  55. };
  56. struct CN_ZONE_ISOLATED_ISLAND_LIST
  57. {
  58. CN_ZONE_ISOLATED_ISLAND_LIST( ZONE_CONTAINER* aZone ) :
  59. m_zone( aZone )
  60. {}
  61. ZONE_CONTAINER* m_zone;
  62. std::vector<int> m_islands;
  63. };
  64. struct RN_DYNAMIC_LINE
  65. {
  66. int netCode;
  67. VECTOR2I a, b;
  68. };
  69. // a wrapper class encompassing the connectivity computation algorithm and the
  70. class CONNECTIVITY_DATA
  71. {
  72. public:
  73. CONNECTIVITY_DATA();
  74. ~CONNECTIVITY_DATA();
  75. CONNECTIVITY_DATA( const std::vector<BOARD_ITEM*>& aItems );
  76. /**
  77. * Function Build()
  78. * Builds the connectivity database for the board aBoard.
  79. */
  80. void Build( BOARD* aBoard );
  81. /**
  82. * Function Build()
  83. * Builds the connectivity database for a set of items aItems.
  84. */
  85. void Build( const std::vector<BOARD_ITEM*>& aItems );
  86. /**
  87. * Function Add()
  88. * Adds an item to the connectivity data.
  89. * @param aItem is an item to be added.
  90. * @return True if operation succeeded.
  91. */
  92. bool Add( BOARD_ITEM* aItem );
  93. /**
  94. * Function Remove()
  95. * Removes an item from the connectivity data.
  96. * @param aItem is an item to be updated.
  97. * @return True if operation succeeded.
  98. */
  99. bool Remove( BOARD_ITEM* aItem );
  100. /**
  101. * Function Update()
  102. * Updates the connectivity data for an item.
  103. * @param aItem is an item to be updated.
  104. * @return True if operation succeeded.
  105. */
  106. bool Update( BOARD_ITEM* aItem );
  107. /**
  108. * Function Clear()
  109. * Erases the connectivity database.
  110. */
  111. void Clear();
  112. /**
  113. * Function GetNetCount()
  114. * Returns the total number of nets in the connectivity database.
  115. */
  116. int GetNetCount() const;
  117. /**
  118. * Function GetRatsnestForNet()
  119. * Returns the ratsnest, expressed as a set of graph edges for a given net.
  120. */
  121. RN_NET* GetRatsnestForNet( int aNet );
  122. /**
  123. * Function PropagateNets()
  124. * Propagates the net codes from the source pads to the tracks/vias.
  125. */
  126. void PropagateNets();
  127. bool CheckConnectivity( std::vector<CN_DISJOINT_NET_ENTRY>& aReport );
  128. /**
  129. * Function FindIsolatedCopperIslands()
  130. * Searches for copper islands in zone aZone that are not connected to any pad.
  131. * @param aZone zone to test
  132. * @param aIslands list of islands that have no connections (outline indices in the polygon set)
  133. */
  134. void FindIsolatedCopperIslands( ZONE_CONTAINER* aZone, std::vector<int>& aIslands );
  135. void FindIsolatedCopperIslands( std::vector<CN_ZONE_ISOLATED_ISLAND_LIST>& aZones );
  136. /**
  137. * Function RecalculateRatsnest()
  138. * Updates the ratsnest for the board.
  139. * @param aCommit is used to save the undo state of items modified by this call
  140. */
  141. void RecalculateRatsnest( BOARD_COMMIT* aCommit = nullptr );
  142. /**
  143. * Function GetUnconnectedCount()
  144. * Returns the number of remaining edges in the ratsnest.
  145. */
  146. unsigned int GetUnconnectedCount() const;
  147. unsigned int GetNodeCount( int aNet = -1 ) const;
  148. unsigned int GetPadCount( int aNet = -1 ) const;
  149. const std::vector<TRACK*> GetConnectedTracks( const BOARD_CONNECTED_ITEM* aItem ) const;
  150. const std::vector<D_PAD*> GetConnectedPads( const BOARD_CONNECTED_ITEM* aItem ) const;
  151. const void GetConnectedPads( const BOARD_CONNECTED_ITEM* aItem, std::set<D_PAD*>* pads ) const;
  152. const std::vector<BOARD_CONNECTED_ITEM*> GetConnectedItems( const BOARD_CONNECTED_ITEM* aItem, const VECTOR2I& aAnchor, KICAD_T aTypes[] );
  153. void GetUnconnectedEdges( std::vector<CN_EDGE>& aEdges ) const;
  154. bool TestTrackEndpointDangling( TRACK* aTrack, wxPoint* aPos );
  155. /**
  156. * Function ClearDynamicRatsnest()
  157. * Erases the temporary dynamic ratsnest (i.e. the ratsnest lines that
  158. * pcbnew displays when moving an item/set of items)
  159. */
  160. void ClearDynamicRatsnest();
  161. /**
  162. * Hides the temporary dynamic ratsnest lines.
  163. */
  164. void HideDynamicRatsnest();
  165. /**
  166. * Function ComputeDynamicRatsnest()
  167. * Calculates the temporary dynamic ratsnest (i.e. the ratsnest lines that)
  168. * for the set of items aItems.
  169. */
  170. void ComputeDynamicRatsnest( const std::vector<BOARD_ITEM*>& aItems );
  171. const std::vector<RN_DYNAMIC_LINE>& GetDynamicRatsnest() const
  172. {
  173. return m_dynamicRatsnest;
  174. }
  175. /**
  176. * Function GetConnectedItems()
  177. * Returns a list of items connected to a source item aItem.
  178. * @param aItem is the reference item to find other connected items.
  179. * @param aTypes allows one to filter by item types.
  180. */
  181. const std::vector<BOARD_CONNECTED_ITEM*> GetConnectedItems( const BOARD_CONNECTED_ITEM* aItem,
  182. const KICAD_T aTypes[], bool aIgnoreNetcodes = false ) const;
  183. /**
  184. * Function GetNetItems()
  185. * Returns the list of items that belong to a certain net.
  186. * @param aNetCode is the net code.
  187. * @param aTypes allows one to filter by item types.
  188. */
  189. const std::vector<BOARD_CONNECTED_ITEM*> GetNetItems( int aNetCode,
  190. const KICAD_T aTypes[] ) const;
  191. const std::vector<VECTOR2I> NearestUnconnectedTargets( const BOARD_CONNECTED_ITEM* aRef,
  192. const VECTOR2I& aPos,
  193. int aMaxCount = -1 );
  194. void BlockRatsnestItems( const std::vector<BOARD_ITEM*>& aItems );
  195. std::shared_ptr<CN_CONNECTIVITY_ALGO> GetConnectivityAlgo() const
  196. {
  197. return m_connAlgo;
  198. }
  199. std::mutex& GetLock()
  200. {
  201. return m_lock;
  202. }
  203. void MarkItemNetAsDirty( BOARD_ITEM* aItem );
  204. void SetProgressReporter( PROGRESS_REPORTER* aReporter );
  205. #ifndef SWIG
  206. const std::vector<CN_EDGE> GetRatsnestForComponent( MODULE* aComponent, bool aSkipInternalConnections = false );
  207. #endif
  208. private:
  209. void updateRatsnest();
  210. void addRatsnestCluster( const std::shared_ptr<CN_CLUSTER>& aCluster );
  211. std::shared_ptr<CN_CONNECTIVITY_ALGO> m_connAlgo;
  212. std::vector<RN_DYNAMIC_LINE> m_dynamicRatsnest;
  213. std::vector<RN_NET*> m_nets;
  214. PROGRESS_REPORTER* m_progressReporter;
  215. std::mutex m_lock;
  216. };
  217. #endif