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.

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