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.

303 lines
9.3 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2009 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
  5. * Copyright (C) 2009 Jean-Pierre Charras, jean-pierre.charras@inpg.fr
  6. * Copyright (C) 2009-2020 KiCad Developers, see change_log.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 CLASS_NETCLASS_H
  26. #define CLASS_NETCLASS_H
  27. #include <macros.h>
  28. #include <gal/color4d.h>
  29. class LINE_READER;
  30. class BOARD;
  31. class BOARD_DESIGN_SETTINGS;
  32. using KIGFX::COLOR4D;
  33. DECL_SET_FOR_SWIG( STRINGSET, wxString )
  34. /**
  35. * NETCLASS
  36. * handles a collection of nets and the parameters used to route or
  37. * test these nets.
  38. */
  39. class NETCLASS
  40. {
  41. protected:
  42. wxString m_Name; ///< Name of the net class
  43. wxString m_Description; ///< what this NETCLASS is for.
  44. STRINGSET m_Members; ///< names of NET members of this class
  45. /// The units on these parameters is Internal Units (1 nm)
  46. int m_Clearance; ///< clearance when routing
  47. int m_TrackWidth; ///< track width used to route NETs in this NETCLASS
  48. int m_ViaDia; ///< via diameter
  49. int m_ViaDrill; ///< via drill hole diameter
  50. int m_uViaDia; ///< microvia diameter
  51. int m_uViaDrill; ///< microvia drill hole diameter
  52. int m_diffPairWidth;
  53. int m_diffPairGap;
  54. int m_diffPairViaGap;
  55. int m_wireWidth;
  56. int m_busWidth;
  57. COLOR4D m_schematicColor;
  58. int m_lineStyle;
  59. COLOR4D m_PcbColor; ///< Optional color override for this netclass (PCB context)
  60. public:
  61. static const char Default[]; ///< the name of the default NETCLASS
  62. /**
  63. * Constructor
  64. * stuffs a NETCLASS instance with aParent, aName, and optionally the initialParameters
  65. * @param aName = the name of this new netclass
  66. */
  67. NETCLASS( const wxString& aName );
  68. ~NETCLASS();
  69. wxString GetClass() const
  70. {
  71. return wxT( "NETCLASS" );
  72. }
  73. const wxString& GetName() const { return m_Name; }
  74. void SetName( const wxString& aName ) { m_Name = aName; }
  75. /**
  76. * Function GetCount
  77. * returns the number of nets in this NETCLASS, i.e. using these rules.
  78. */
  79. unsigned GetCount() const
  80. {
  81. return m_Members.size();
  82. }
  83. /**
  84. * Function Clear
  85. * empties the collection of members.
  86. */
  87. void Clear()
  88. {
  89. m_Members.clear();
  90. }
  91. /**
  92. * Function Add
  93. * adds \a aNetname to this NETCLASS if it is not already in this NETCLASS.
  94. * It is harmless to try and add a second identical name.
  95. */
  96. void Add( const wxString& aNetname )
  97. {
  98. m_Members.insert( aNetname );
  99. }
  100. typedef STRINGSET::iterator iterator;
  101. iterator begin() { return m_Members.begin(); }
  102. iterator end() { return m_Members.end(); }
  103. typedef STRINGSET::const_iterator const_iterator;
  104. const_iterator begin() const { return m_Members.begin(); }
  105. const_iterator end() const { return m_Members.end(); }
  106. /**
  107. * Function Remove
  108. * will remove NET name \a aName from the collection of members.
  109. */
  110. void Remove( iterator aName )
  111. {
  112. m_Members.erase( aName );
  113. }
  114. /**
  115. * Function Remove
  116. * will remove NET name \a aName from the collection of members.
  117. */
  118. void Remove( const wxString& aName )
  119. {
  120. m_Members.erase( aName );
  121. }
  122. STRINGSET& NetNames() { return m_Members; } ///< for SWIG
  123. const wxString& GetDescription() const { return m_Description; }
  124. void SetDescription( const wxString& aDesc ) { m_Description = aDesc; }
  125. int GetClearance( wxString* aSource = nullptr ) const
  126. {
  127. if( aSource )
  128. *aSource = wxString::Format( _( "'%s' netclass" ), m_Name );
  129. return m_Clearance;
  130. }
  131. void SetClearance( int aClearance ) { m_Clearance = aClearance; }
  132. int GetTrackWidth() const { return m_TrackWidth; }
  133. void SetTrackWidth( int aWidth ) { m_TrackWidth = aWidth; }
  134. int GetViaDiameter() const { return m_ViaDia; }
  135. void SetViaDiameter( int aDia ) { m_ViaDia = aDia; }
  136. int GetViaDrill() const { return m_ViaDrill; }
  137. void SetViaDrill( int aSize ) { m_ViaDrill = aSize; }
  138. int GetuViaDiameter() const { return m_uViaDia; }
  139. void SetuViaDiameter( int aSize ) { m_uViaDia = aSize; }
  140. int GetuViaDrill() const { return m_uViaDrill; }
  141. void SetuViaDrill( int aSize ) { m_uViaDrill = aSize; }
  142. int GetDiffPairWidth() const { return m_diffPairWidth; }
  143. void SetDiffPairWidth( int aSize ) { m_diffPairWidth = aSize; }
  144. int GetDiffPairGap() const { return m_diffPairGap; }
  145. void SetDiffPairGap( int aSize ) { m_diffPairGap = aSize; }
  146. int GetDiffPairViaGap() const { return m_diffPairViaGap; }
  147. void SetDiffPairViaGap( int aSize ) { m_diffPairViaGap = aSize; }
  148. COLOR4D GetPcbColor() const { return m_PcbColor; }
  149. void SetPcbColor( const COLOR4D& aColor ) { m_PcbColor = aColor; }
  150. int GetWireWidth() const { return m_wireWidth; }
  151. void SetWireWidth( int aWidth ) { m_wireWidth = aWidth; }
  152. int GetBusWidth() const { return m_busWidth; }
  153. void SetBusWidth( int aWidth ) { m_busWidth = aWidth; }
  154. COLOR4D GetSchematicColor() const { return m_schematicColor; }
  155. void SetSchematicColor( COLOR4D aColor ) { m_schematicColor = aColor; }
  156. int GetLineStyle() const { return m_lineStyle; }
  157. void SetLineStyle( int aStyle ) { m_lineStyle = aStyle; }
  158. #if defined(DEBUG)
  159. void Show( int nestLevel, std::ostream& os ) const;
  160. #endif
  161. };
  162. DECL_SPTR_FOR_SWIG( NETCLASSPTR, NETCLASS )
  163. DECL_MAP_FOR_SWIG( NETCLASS_MAP, wxString, NETCLASSPTR )
  164. /**
  165. * NETCLASSES
  166. * is a container for NETCLASS instances. It owns all its NETCLASSes. This container will
  167. * always have a default NETCLASS with the name given by const NETCLASS::Default.
  168. */
  169. class NETCLASSES
  170. {
  171. private:
  172. NETCLASS_MAP m_NetClasses; // All the netclasses EXCEPT the default one
  173. NETCLASSPTR m_default;
  174. public:
  175. NETCLASSES();
  176. ~NETCLASSES();
  177. /**
  178. * Function Clear
  179. * destroys any contained NETCLASS instances except the Default one, and clears any
  180. * members from the Default one.
  181. */
  182. void Clear()
  183. {
  184. m_NetClasses.clear();
  185. m_default->Clear();
  186. }
  187. typedef NETCLASS_MAP::iterator iterator;
  188. iterator begin() { return m_NetClasses.begin(); }
  189. iterator end() { return m_NetClasses.end(); }
  190. typedef NETCLASS_MAP::const_iterator const_iterator;
  191. const_iterator begin() const { return m_NetClasses.begin(); }
  192. const_iterator end() const { return m_NetClasses.end(); }
  193. /**
  194. * Function GetCount
  195. * @return the number of netclasses, excluding the default one.
  196. */
  197. unsigned GetCount() const
  198. {
  199. return m_NetClasses.size();
  200. }
  201. /**
  202. * Function GetDefault
  203. * @return the default net class.
  204. */
  205. NETCLASSPTR GetDefault() const
  206. {
  207. return m_default;
  208. }
  209. NETCLASS* GetDefaultPtr() const
  210. {
  211. return m_default.get();
  212. }
  213. /**
  214. * Function Add
  215. * takes \a aNetclass and puts it into this NETCLASSES container.
  216. * @param aNetclass is netclass to add
  217. * @return true if the name within aNetclass is unique and it could be inserted OK,
  218. * else false because the name was not unique.
  219. */
  220. bool Add( const NETCLASSPTR& aNetclass );
  221. /**
  222. * Function Remove
  223. * removes a NETCLASS from this container but does not destroy/delete it.
  224. * @param aNetName is the name of the net to delete, and it may not be NETCLASS::Default.
  225. * @return NETCLASSPTR - the NETCLASS associated with aNetName if found and removed, else NULL.
  226. */
  227. NETCLASSPTR Remove( const wxString& aNetName );
  228. /**
  229. * Function Find
  230. * searches this container for a NETCLASS given by \a aName.
  231. * @param aName is the name of the NETCLASS to search for.
  232. * @return NETCLASSPTR - if found, else NULL.
  233. */
  234. NETCLASSPTR Find( const wxString& aName ) const;
  235. /// Provide public access to m_NetClasses so it gets swigged.
  236. NETCLASS_MAP& NetClasses() { return m_NetClasses; }
  237. };
  238. #endif // CLASS_NETCLASS_H