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.

302 lines
9.0 KiB

  1. /**
  2. * @file class_netclass.h
  3. */
  4. /*
  5. * This program source code file is part of KiCad, a free EDA CAD application.
  6. *
  7. * Copyright (C) 2009 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
  8. * Copyright (C) 2009 Jean-Pierre Charras, jean-pierre.charras@inpg.fr
  9. * Copyright (C) 2009 KiCad Developers, see change_log.txt for contributors.
  10. *
  11. * This program is free software; you can redistribute it and/or
  12. * modify it under the terms of the GNU General Public License
  13. * as published by the Free Software Foundation; either version 2
  14. * of the License, or (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program; if not, you may find one here:
  23. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  24. * or you may search the http://www.gnu.org website for the version 2 license,
  25. * or you may write to the Free Software Foundation, Inc.,
  26. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  27. */
  28. #ifndef CLASS_NETCLASS_H
  29. #define CLASS_NETCLASS_H
  30. #include <macros.h>
  31. #include <set>
  32. #include <memory>
  33. #include <richio.h>
  34. class LINE_READER;
  35. class BOARD;
  36. class BOARD_DESIGN_SETTINGS;
  37. DECL_SET_FOR_SWIG( STRINGSET, wxString )
  38. /**
  39. * NETCLASS
  40. * handles a collection of nets and the parameters used to route or
  41. * test these nets.
  42. */
  43. class NETCLASS
  44. {
  45. protected:
  46. wxString m_Name; ///< Name of the net class
  47. wxString m_Description; ///< what this NETCLASS is for.
  48. STRINGSET m_Members; ///< names of NET members of this class
  49. /// The units on these parameters is Internal Units (1 nm)
  50. int m_Clearance; ///< clearance when routing
  51. int m_TrackWidth; ///< track width used to route NETs in this NETCLASS
  52. int m_ViaDia; ///< via diameter
  53. int m_ViaDrill; ///< via drill hole diameter
  54. int m_uViaDia; ///< microvia diameter
  55. int m_uViaDrill; ///< microvia drill hole diameter
  56. int m_diffPairWidth;
  57. int m_diffPairGap;
  58. int m_diffPairViaGap;
  59. public:
  60. static const char Default[]; ///< the name of the default NETCLASS
  61. /**
  62. * Constructor
  63. * stuffs a NETCLASS instance with aParent, aName, and optionally the initialParameters
  64. * @param aName = the name of this new netclass
  65. */
  66. NETCLASS( const wxString& aName );
  67. ~NETCLASS();
  68. wxString GetClass() const
  69. {
  70. return wxT( "NETCLASS" );
  71. }
  72. const wxString& GetName() const
  73. {
  74. return m_Name;
  75. }
  76. void SetName( const wxString& aName ) { m_Name = aName; }
  77. /**
  78. * Function GetCount
  79. * returns the number of nets in this NETCLASS, i.e. using these rules.
  80. */
  81. unsigned GetCount() const
  82. {
  83. return m_Members.size();
  84. }
  85. /**
  86. * Function Clear
  87. * empties the collection of members.
  88. */
  89. void Clear()
  90. {
  91. m_Members.clear();
  92. }
  93. /**
  94. * Function Add
  95. * adds \a aNetname to this NETCLASS if it is not already in this NETCLASS.
  96. * It is harmless to try and add a second identical name.
  97. */
  98. void Add( const wxString& aNetname )
  99. {
  100. m_Members.insert( aNetname );
  101. }
  102. typedef STRINGSET::iterator iterator;
  103. iterator begin() { return m_Members.begin(); }
  104. iterator end() { return m_Members.end(); }
  105. typedef STRINGSET::const_iterator const_iterator;
  106. const_iterator begin() const { return m_Members.begin(); }
  107. const_iterator end() const { return m_Members.end(); }
  108. /**
  109. * Function Remove
  110. * will remove NET name \a aName from the collection of members.
  111. */
  112. void Remove( iterator aName )
  113. {
  114. m_Members.erase( aName );
  115. }
  116. /**
  117. * Function Remove
  118. * will remove NET name \a aName from the collection of members.
  119. */
  120. void Remove( const wxString& aName )
  121. {
  122. m_Members.erase( aName );
  123. }
  124. STRINGSET& NetNames() { return m_Members; } ///< for SWIG
  125. const wxString& GetDescription() const { return m_Description; }
  126. void SetDescription( const wxString& aDesc ) { m_Description = aDesc; }
  127. int GetClearance() const { return m_Clearance; }
  128. void SetClearance( int aClearance ) { m_Clearance = aClearance; }
  129. int GetTrackWidth() const { return m_TrackWidth; }
  130. void SetTrackWidth( int aWidth ) { m_TrackWidth = aWidth; }
  131. int GetViaDiameter() const { return m_ViaDia; }
  132. void SetViaDiameter( int aDia ) { m_ViaDia = aDia; }
  133. int GetViaDrill() const { return m_ViaDrill; }
  134. void SetViaDrill( int aSize ) { m_ViaDrill = aSize; }
  135. int GetuViaDiameter() const { return m_uViaDia; }
  136. void SetuViaDiameter( int aSize ) { m_uViaDia = aSize; }
  137. int GetuViaDrill() const { return m_uViaDrill; }
  138. void SetuViaDrill( int aSize ) { m_uViaDrill = aSize; }
  139. int GetDiffPairWidth() const { return m_diffPairWidth; }
  140. void SetDiffPairWidth( int aSize ) { m_diffPairWidth = aSize; }
  141. int GetDiffPairGap() const { return m_diffPairGap; }
  142. void SetDiffPairGap( int aSize ) { m_diffPairGap = aSize; }
  143. int GetDiffPairViaGap() const { return m_diffPairViaGap; }
  144. void SetDiffPairViaGap( int aSize ) { m_diffPairViaGap = aSize; }
  145. /**
  146. * Function SetParams
  147. * will set all the parameters by copying them from \a defaults.
  148. * Parameters are the values like m_ViaSize, etc, but do not include m_Description.
  149. * @param aDefaults is another NETCLASS object to copy from.
  150. */
  151. void SetParams( const NETCLASS& aDefaults );
  152. /**
  153. * Function Format
  154. * outputs the net class to \a aFormatter in s-expression form.
  155. *
  156. * @param aFormatter The #OUTPUTFORMATTER object to write to.
  157. * @param aNestLevel The indentation next level.
  158. * @param aControlBits The control bit definition for object specific formatting.
  159. * @throw IO_ERROR on write error.
  160. */
  161. void Format( OUTPUTFORMATTER* aFormatter, int aNestLevel, int aControlBits ) const;
  162. #if defined(DEBUG)
  163. void Show( int nestLevel, std::ostream& os ) const;
  164. #endif
  165. };
  166. DECL_SPTR_FOR_SWIG( NETCLASSPTR, NETCLASS )
  167. DECL_MAP_FOR_SWIG( NETCLASS_MAP, wxString, NETCLASSPTR )
  168. /**
  169. * NETCLASSES
  170. * is a container for NETCLASS instances. It owns all its NETCLASSes
  171. * (=> it will delete them at time of destruction). This container will always have
  172. * a default NETCLASS with the name given by const NETCLASS::Default.
  173. */
  174. class NETCLASSES
  175. {
  176. private:
  177. /// all the NETCLASSes except the default one.
  178. NETCLASS_MAP m_NetClasses;
  179. /// the default NETCLASS
  180. NETCLASSPTR m_default;
  181. public:
  182. NETCLASSES();
  183. ~NETCLASSES();
  184. /**
  185. * Function Clear
  186. * destroys any contained NETCLASS instances except the Default one.
  187. */
  188. void Clear()
  189. {
  190. m_NetClasses.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. /**
  215. * Function Add
  216. * takes \a aNetclass and puts it into this NETCLASSES container.
  217. * @param aNetclass is netclass to add
  218. * @return true if the name within aNetclass is unique and it could be inserted OK,
  219. * else false because the name was not unique.
  220. */
  221. bool Add( const NETCLASSPTR& aNetclass );
  222. /**
  223. * Function Remove
  224. * removes a NETCLASS from this container but does not destroy/delete it.
  225. * @param aNetName is the name of the net to delete, and it may not be NETCLASS::Default.
  226. * @return NETCLASSPTR - the NETCLASS associated with aNetName if found and removed, else NULL.
  227. */
  228. NETCLASSPTR Remove( const wxString& aNetName );
  229. /**
  230. * Function Find
  231. * searches this container for a NETCLASS given by \a aName.
  232. * @param aName is the name of the NETCLASS to search for.
  233. * @return NETCLASSPTR - if found, else NULL.
  234. */
  235. NETCLASSPTR Find( const wxString& aName ) const;
  236. /// Provide public access to m_NetClasses so it gets swigged.
  237. NETCLASS_MAP& NetClasses() { return m_NetClasses; }
  238. };
  239. #endif // CLASS_NETCLASS_H