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.

232 lines
6.6 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. * @author Maciej Suminski <maciej.suminski@cern.ch>
  6. * @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License
  10. * as published by the Free Software Foundation; either version 2
  11. * of the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, you may find one here:
  20. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  21. * or you may search the http://www.gnu.org website for the version 2 license,
  22. * or you may write to the Free Software Foundation, Inc.,
  23. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  24. */
  25. #ifndef __CONNECTIVITY_H
  26. #define __CONNECTIVITY_H
  27. #include <core/typeinfo.h>
  28. #include <wx/string.h>
  29. #include <vector>
  30. #include <list>
  31. #include <memory>
  32. #include <math/vector2d.h>
  33. class CN_CLUSTER;
  34. class CN_CONNECTIVITY_ALGO;
  35. class CN_EDGE;
  36. class BOARD;
  37. class BOARD_CONNECTED_ITEM;
  38. class BOARD_ITEM;
  39. class ZONE_CONTAINER;
  40. class RN_DATA;
  41. class RN_NET;
  42. class TRACK;
  43. class D_PAD;
  44. struct CN_DISJOINT_NET_ENTRY
  45. {
  46. int net;
  47. BOARD_CONNECTED_ITEM *a, *b;
  48. VECTOR2I anchorA, anchorB;
  49. };
  50. struct RN_DYNAMIC_LINE
  51. {
  52. int netCode;
  53. VECTOR2I a, b;
  54. };
  55. // a wrapper class encompassing the connectivity computation algorithm and the
  56. class CONNECTIVITY_DATA
  57. {
  58. public:
  59. CONNECTIVITY_DATA();
  60. ~CONNECTIVITY_DATA();
  61. /**
  62. * Function Build()
  63. * Builds the connectivity database for the board aBoard.
  64. */
  65. void Build( BOARD* aBoard );
  66. /**
  67. * Function Build()
  68. * Builds the connectivity database for a set of items aItems.
  69. */
  70. void Build( const std::vector<BOARD_ITEM*>& aItems );
  71. /**
  72. * Function Add()
  73. * Adds an item to the connectivity data.
  74. * @param aItem is an item to be added.
  75. * @return True if operation succeeded.
  76. */
  77. bool Add( BOARD_ITEM* aItem );
  78. /**
  79. * Function Remove()
  80. * Removes an item from the connectivity data.
  81. * @param aItem is an item to be updated.
  82. * @return True if operation succeeded.
  83. */
  84. bool Remove( BOARD_ITEM* aItem );
  85. /**
  86. * Function Update()
  87. * Updates the connectivity data for an item.
  88. * @param aItem is an item to be updated.
  89. * @return True if operation succeeded.
  90. */
  91. bool Update( BOARD_ITEM* aItem );
  92. /**
  93. * Function Clear()
  94. * Erases the connectivity database.
  95. */
  96. void Clear();
  97. /**
  98. * Function GetNetCount()
  99. * Returns the total number of nets in the connectivity database.
  100. */
  101. int GetNetCount() const;
  102. /**
  103. * Function GetRatsnestForNet()
  104. * Returns the ratsnest, expressed as a set of graph edges for a given net.
  105. */
  106. RN_NET* GetRatsnestForNet( int aNet );
  107. /**
  108. * Function PropagateNets()
  109. * Propagates the net codes from the source pads to the tracks/vias.
  110. */
  111. void PropagateNets();
  112. bool CheckConnectivity( std::vector<CN_DISJOINT_NET_ENTRY>& aReport );
  113. /**
  114. * Function FindIsolatedCopperIslands()
  115. * Searches for copper islands in zone aZone that are not connected to any pad.
  116. * @param aZone zone to test
  117. * @param aIslands list of islands that have no connections (outline indices in the polygon set)
  118. */
  119. void FindIsolatedCopperIslands( ZONE_CONTAINER* aZone, std::vector<int>& aIslands );
  120. /**
  121. * Function RecalculateRatsnest()
  122. * Updates the ratsnest for the board.
  123. */
  124. void RecalculateRatsnest();
  125. /**
  126. * Function GetUnconnectedCount()
  127. * Returns the number of remaining edges in the ratsnest.
  128. */
  129. unsigned int GetUnconnectedCount() const;
  130. unsigned int GetNodeCount( int aNet = -1 ) const;
  131. unsigned int GetPadCount( int aNet = -1 ) const;
  132. const std::vector<TRACK*> GetConnectedTracks( const BOARD_CONNECTED_ITEM* aItem ) const;
  133. const std::vector<D_PAD*> GetConnectedPads( const BOARD_CONNECTED_ITEM* aItem ) const;
  134. const std::vector<BOARD_CONNECTED_ITEM*> GetConnectedItems( const BOARD_CONNECTED_ITEM* aItem, const VECTOR2I& aAnchor, KICAD_T aTypes[] );
  135. void GetUnconnectedEdges( std::vector<CN_EDGE>& aEdges ) const;
  136. /**
  137. * Function ClearDynamicRatsnest()
  138. * Erases the temporary dynamic ratsnest (i.e. the ratsnest lines that
  139. * pcbnew displays when moving an item/set of items)
  140. */
  141. void ClearDynamicRatsnest();
  142. /**
  143. * Hides the temporary dynamic ratsnest lines.
  144. */
  145. void HideDynamicRatsnest();
  146. /**
  147. * Function ComputeDynamicRatsnest()
  148. * Calculates the temporary dynamic ratsnest (i.e. the ratsnest lines that)
  149. * for the set of items aItems.
  150. */
  151. void ComputeDynamicRatsnest( const std::vector<BOARD_ITEM*>& aItems );
  152. const std::vector<RN_DYNAMIC_LINE>& GetDynamicRatsnest() const
  153. {
  154. return m_dynamicRatsnest;
  155. }
  156. /**
  157. * Function GetConnectedItems()
  158. * Returns a list of items connected to a source item aItem.
  159. * @param aItem is the reference item to find other connected items.
  160. * @param aTypes allows to filter by item types.
  161. */
  162. const std::list<BOARD_CONNECTED_ITEM*> GetConnectedItems( const BOARD_CONNECTED_ITEM* aItem,
  163. const KICAD_T aTypes[] ) const;
  164. /**
  165. * Function GetNetItems()
  166. * Returns the list of items that belong to a certain net.
  167. * @param aNetCode is the net code.
  168. * @param aTypes allows to filter by item types.
  169. */
  170. const std::list<BOARD_CONNECTED_ITEM*> GetNetItems( int aNetCode,
  171. const KICAD_T aTypes[] ) const;
  172. const std::vector<VECTOR2I> NearestUnconnectedTargets( const BOARD_CONNECTED_ITEM* aRef,
  173. const VECTOR2I& aPos,
  174. int aMaxCount = -1 );
  175. void BlockRatsnestItems( const std::vector<BOARD_ITEM*>& aItems );
  176. std::shared_ptr<CN_CONNECTIVITY_ALGO> GetConnectivityAlgo() const
  177. {
  178. return m_connAlgo;
  179. }
  180. void MarkItemNetAsDirty( BOARD_ITEM* aItem );
  181. private:
  182. void updateRatsnest();
  183. void addRatsnestCluster( std::shared_ptr<CN_CLUSTER> aCluster );
  184. std::unique_ptr<CONNECTIVITY_DATA> m_dynamicConnectivity;
  185. std::shared_ptr<CN_CONNECTIVITY_ALGO> m_connAlgo;
  186. std::vector<RN_DYNAMIC_LINE> m_dynamicRatsnest;
  187. std::vector<RN_NET*> m_nets;
  188. };
  189. #endif