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.

234 lines
7.7 KiB

12 years ago
12 years ago
5 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2012 Jean-Pierre Charras, jean-pierre.charras@ujf-grenoble.fr
  5. * Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
  6. * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
  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 BOARD_CONNECTED_ITEM_H
  26. #define BOARD_CONNECTED_ITEM_H
  27. #include <board_item.h>
  28. #include <teardrop/teardrop_parameters.h>
  29. class NETCLASS;
  30. class NETINFO_ITEM;
  31. class PAD;
  32. /**
  33. * A base class derived from #BOARD_ITEM for items that can be connected and have a net, a
  34. * netname, a clearance ...
  35. */
  36. class BOARD_CONNECTED_ITEM : public BOARD_ITEM
  37. {
  38. public:
  39. BOARD_CONNECTED_ITEM( BOARD_ITEM* aParent, KICAD_T idtype );
  40. // Do not create a copy constructor & operator=.
  41. // The ones generated by the compiler are adequate.
  42. static inline bool ClassOf( const EDA_ITEM* aItem )
  43. {
  44. if( aItem == nullptr )
  45. return false;
  46. switch( aItem->Type() )
  47. {
  48. case PCB_PAD_T:
  49. case PCB_TRACE_T:
  50. case PCB_ARC_T:
  51. case PCB_VIA_T:
  52. case PCB_ZONE_T:
  53. case PCB_SHAPE_T:
  54. return true;
  55. default:
  56. return false;
  57. }
  58. }
  59. ///< @copydoc BOARD_ITEM::IsConnected()
  60. bool IsConnected() const override
  61. {
  62. return true;
  63. }
  64. /**
  65. * Return #NET_INFO object for a given item.
  66. */
  67. NETINFO_ITEM* GetNet() const
  68. {
  69. return m_netinfo;
  70. }
  71. /**
  72. * Set a NET_INFO object for the item.
  73. */
  74. void SetNet( NETINFO_ITEM* aNetInfo )
  75. {
  76. m_netinfo = aNetInfo;
  77. }
  78. /**
  79. * @return the net code.
  80. */
  81. int GetNetCode() const;
  82. /**
  83. * Set net using a net code.
  84. *
  85. * @note Pads not on copper layers will have their net code always set to 0 (not connected).
  86. *
  87. * @param aNetCode is a net code for the new net. It has to exist in #NETINFO_LIST held
  88. * by #BOARD.
  89. * @param aNoAssert if true, do not assert that the net exists. Otherwise, item is assigned
  90. * to the unconnected net.
  91. * @return true on success, false if the net did not exist
  92. */
  93. bool SetNetCode( int aNetCode, bool aNoAssert );
  94. void SetNetCode( int aNetCode )
  95. {
  96. SetNetCode( aNetCode, false );
  97. }
  98. /**
  99. * @return the full netname.
  100. */
  101. wxString GetNetname() const;
  102. /**
  103. * @return the full netname or "<no net>" in square braces, followed by "(Not Found)" if the
  104. * netcode is undefined.
  105. */
  106. wxString GetNetnameMsg() const;
  107. /**
  108. * @return the short netname.
  109. */
  110. const wxString& GetShortNetname() const;
  111. /**
  112. * @return the unescaped short netname.
  113. */
  114. const wxString& GetDisplayNetname() const;
  115. /**
  116. * Return an item's "own" clearance in internal units.
  117. *
  118. * @param aLayer the layer in question.
  119. * @param aSource [out] optionally reports the source as a user-readable string.
  120. * @return the clearance in internal units.
  121. */
  122. virtual int GetOwnClearance( PCB_LAYER_ID aLayer, wxString* aSource = nullptr ) const;
  123. /**
  124. * Return any clearance overrides set in the "classic" (ie: pre-rule) system.
  125. *
  126. * @param aSource [out] optionally reports the source as a user-readable string.
  127. * @return the clearance in internal units.
  128. */
  129. virtual std::optional<int> GetClearanceOverrides( wxString* aSource ) const
  130. {
  131. return std::optional<int>();
  132. }
  133. /**
  134. * Return any local clearances set in the "classic" (ie: pre-rule) system.
  135. *
  136. * @return the clearance (if any is specified) in internal units.
  137. */
  138. virtual std::optional<int> GetLocalClearance() const
  139. {
  140. return std::optional<int>();
  141. }
  142. /**
  143. * Return any local clearances set in the "classic" (ie: pre-rule) system.
  144. *
  145. * @param aSource [out] optionally reports the source as a user-readable string.
  146. * @return the clearance (if any is specified) in internal units.
  147. */
  148. virtual std::optional<int> GetLocalClearance( wxString* aSource ) const
  149. {
  150. return std::optional<int>();
  151. }
  152. /**
  153. * Return the #NETCLASS for this item.
  154. *
  155. * @note Do **not** return a std::shared_ptr from this. It is used heavily in DRC, and the
  156. * std::shared_ptr stuff shows up large in performance profiling.
  157. */
  158. virtual NETCLASS* GetEffectiveNetClass() const;
  159. /**
  160. * Returns the name of the effective netclass. Primarily for the use of the property system.
  161. */
  162. wxString GetNetClassName() const;
  163. void SetLocalRatsnestVisible( bool aVisible ) { m_localRatsnestVisible = aVisible; }
  164. bool GetLocalRatsnestVisible() const { return m_localRatsnestVisible; }
  165. TEARDROP_PARAMETERS& GetTeardropParams() { return m_teardropParams; }
  166. const TEARDROP_PARAMETERS& GetTeardropParams() const { return m_teardropParams; }
  167. void SetTeardropsEnabled( bool aEnable ) { m_teardropParams.m_Enabled = aEnable; }
  168. bool GetTeardropsEnabled() const { return m_teardropParams.m_Enabled; }
  169. void SetTeardropBestLengthRatio( double aRatio ) { m_teardropParams.m_BestLengthRatio = aRatio; }
  170. double GetTeardropBestLengthRatio() const { return m_teardropParams.m_BestLengthRatio; }
  171. void SetTeardropMaxLength( int aMaxLength ) { m_teardropParams.m_TdMaxLen = aMaxLength; }
  172. int GetTeardropMaxLength() const { return m_teardropParams.m_TdMaxLen; }
  173. void SetTeardropBestWidthRatio( double aRatio ) { m_teardropParams.m_BestWidthRatio = aRatio; }
  174. double GetTeardropBestWidthRatio() const { return m_teardropParams.m_BestWidthRatio; }
  175. void SetTeardropMaxWidth( int aMaxWidth ) { m_teardropParams.m_TdMaxWidth = aMaxWidth; }
  176. int GetTeardropMaxWidth() const { return m_teardropParams.m_TdMaxWidth; }
  177. void SetTeardropCurved( bool aCurve ) { m_teardropParams.m_CurvedEdges = aCurve; }
  178. bool GetTeardropCurved() const { return m_teardropParams.m_CurvedEdges; }
  179. void SetTeardropPreferZoneConnections( bool aPrefer ) { m_teardropParams.m_TdOnPadsInZones = !aPrefer; }
  180. bool GetTeardropPreferZoneConnections() const { return !m_teardropParams.m_TdOnPadsInZones; }
  181. void SetTeardropAllowSpanTwoTracks( bool aAllow ) { m_teardropParams.m_AllowUseTwoTracks = aAllow; }
  182. bool GetTeardropAllowSpanTwoTracks() const { return m_teardropParams.m_AllowUseTwoTracks; }
  183. void SetTeardropMaxTrackWidth( double aRatio ) { m_teardropParams.m_WidthtoSizeFilterRatio = aRatio; }
  184. double GetTeardropMaxTrackWidth() const { return m_teardropParams.m_WidthtoSizeFilterRatio; }
  185. protected:
  186. /// Store all information about the net that item belongs to.
  187. NETINFO_ITEM* m_netinfo;
  188. /// Not all BOARD_CONNECTED_ITEMs support teardrops, but we want those that do to share a
  189. /// single section in the property inspector.
  190. TEARDROP_PARAMETERS m_teardropParams;
  191. private:
  192. bool m_localRatsnestVisible;
  193. };
  194. #endif // BOARD_CONNECTED_ITEM_H