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.

237 lines
7.2 KiB

12 years ago
12 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 (C) 1992-2012 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 <class_board_item.h>
  28. #include <netinfo.h>
  29. #include <reporter.h>
  30. #include <kicad_string.h>
  31. class NETCLASS;
  32. class TRACK;
  33. class D_PAD;
  34. /**
  35. * BOARD_CONNECTED_ITEM
  36. * is a base class derived from BOARD_ITEM for items that can be connected
  37. * and have a net, a netname, a clearance ...
  38. * mainly: tracks, pads and zones
  39. * Handle connection info
  40. */
  41. class BOARD_CONNECTED_ITEM : public BOARD_ITEM
  42. {
  43. public:
  44. BOARD_CONNECTED_ITEM( BOARD_ITEM* aParent, KICAD_T idtype );
  45. // Do not create a copy constructor & operator=.
  46. // The ones generated by the compiler are adequate.
  47. static inline bool ClassOf( const EDA_ITEM* aItem )
  48. {
  49. if( aItem == NULL )
  50. return false;
  51. switch( aItem->Type() )
  52. {
  53. case PCB_PAD_T:
  54. case PCB_TRACE_T:
  55. case PCB_ARC_T:
  56. case PCB_VIA_T:
  57. case PCB_ZONE_AREA_T:
  58. return true;
  59. default:
  60. return false;
  61. }
  62. }
  63. ///> @copydoc BOARD_ITEM::IsConnected()
  64. bool IsConnected() const override
  65. {
  66. return true;
  67. }
  68. /**
  69. * Function GetNet
  70. * Returns NET_INFO object for a given item.
  71. */
  72. NETINFO_ITEM* GetNet() const
  73. {
  74. return m_netinfo;
  75. }
  76. /**
  77. * Function SetNet
  78. * Sets a NET_INFO object for the item.
  79. */
  80. void SetNet( NETINFO_ITEM* aNetInfo )
  81. {
  82. m_netinfo = aNetInfo;
  83. }
  84. /**
  85. * Function GetNetCode
  86. * @return int - the net code.
  87. */
  88. int GetNetCode() const
  89. {
  90. return m_netinfo ? m_netinfo->GetNet() : -1;
  91. }
  92. /**
  93. * Sets net using a net code.
  94. * @param aNetCode is a net code for the new net. It has to exist in NETINFO_LIST held by BOARD.
  95. * @param aNoAssert if true, do not assert that the net exists.
  96. * Otherwise, item is assigned to the unconnected net.
  97. * @return true on success, false if the net did not exist
  98. * Note also items (in fact pads) not on copper layers will have
  99. * their net code always set to 0 (not connected)
  100. */
  101. bool SetNetCode( int aNetCode, bool aNoAssert );
  102. void SetNetCode( int aNetCode )
  103. {
  104. SetNetCode( aNetCode, false );
  105. }
  106. /**
  107. * Function GetNetname
  108. * @return wxString - the full netname
  109. */
  110. wxString GetNetname() const
  111. {
  112. return m_netinfo ? m_netinfo->GetNetname() : wxString();
  113. }
  114. /**
  115. * Function GetNetnameMsg
  116. * @return wxString - the full netname or "<no net>" in square braces, followed by
  117. * "(Not Found)" if the netcode is undefined.
  118. */
  119. wxString GetNetnameMsg() const
  120. {
  121. if( !GetBoard() )
  122. return wxT( "[** NO BOARD DEFINED **]" );
  123. wxString netname = GetNetname();
  124. if( !netname.length() )
  125. return wxT( "[<no net>]" );
  126. else if( GetNetCode() < 0 )
  127. return wxT( "[" + UnescapeString( netname ) + "](" + _( "Not Found" ) + ")" );
  128. else
  129. return wxT( "[" + UnescapeString( netname ) + "]" );
  130. }
  131. /**
  132. * Function GetShortNetname
  133. * @return wxString - the short netname
  134. */
  135. wxString GetShortNetname() const
  136. {
  137. return m_netinfo->GetShortNetname();
  138. }
  139. /**
  140. * Function GetClearance
  141. * returns the clearance in internal units. If \a aItem is not NULL then the
  142. * returned clearance is the greater of this object's NETCLASS clearance and
  143. * aItem's NETCLASS clearance. If \a aItem is NULL, then this objects clearance
  144. * is returned.
  145. * @param aLayer the layer in question
  146. * @param aItem is an optional BOARD_ITEM
  147. * @param aSource [out] optionally reports the source as a user-readable string
  148. * @return int - the clearance in internal units.
  149. */
  150. virtual int GetClearance( PCB_LAYER_ID aLayer, BOARD_ITEM* aItem = nullptr,
  151. wxString* aSource = nullptr ) const;
  152. /**
  153. * Function GetLocalClearanceOverrides
  154. * returns any local clearance overrides set in the "classic" (ie: pre-rule) system.
  155. * @param aSource [out] optionally reports the source as a user-readable string
  156. * @return int - the clearance in internal units.
  157. */
  158. virtual int GetLocalClearanceOverrides( wxString* aSource ) const { return 0; }
  159. /**
  160. * Function GetLocalClearance
  161. * returns any local clearances set in the "classic" (ie: pre-rule) system. These are
  162. * things like zone clearance which are NOT an override.
  163. * @param aSource [out] optionally reports the source as a user-readable string
  164. * @return int - the clearance in internal units.
  165. */
  166. virtual int GetLocalClearance( wxString* aSource ) const { return 0; }
  167. /**
  168. * Function GetNetClassPtr
  169. * returns the NETCLASS for this item.
  170. *
  171. * Note: do NOT return a std::shared_ptr from this. It is used heavily in DRC, and the
  172. * std::shared_ptr stuff shows up large in performance profiling.
  173. */
  174. NETCLASS* GetNetClass() const;
  175. /**
  176. * Function GetEffectiveNetclass
  177. * returns the NETCLASS for this item, or the default netclass if none is defined.
  178. *
  179. * Note: do NOT return a std::shared_ptr from this. It is used heavily in DRC, and the
  180. * std::shared_ptr stuff shows up large in performance profiling.
  181. */
  182. NETCLASS* GetEffectiveNetclass() const;
  183. /**
  184. * Function GetNetClassName
  185. * returns a pointer to the netclass of the zone.
  186. * If the net is not found (can happen when a netlist is reread,
  187. * and the net name does not exist, return the default net class
  188. * (should not return a null pointer).
  189. * @return the Net Class name of this item
  190. */
  191. wxString GetNetClassName() const;
  192. void SetLocalRatsnestVisible( bool aVisible )
  193. {
  194. m_localRatsnestVisible = aVisible;
  195. }
  196. bool GetLocalRatsnestVisible() const
  197. {
  198. return m_localRatsnestVisible;
  199. }
  200. protected:
  201. /// Stores all informations about the net that item belongs to
  202. NETINFO_ITEM* m_netinfo;
  203. private:
  204. bool m_localRatsnestVisible;
  205. };
  206. #endif // BOARD_CONNECTED_ITEM_H