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.

287 lines
14 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 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 CLASS_NETCLASS_H
  26. #define CLASS_NETCLASS_H
  27. #include <optional>
  28. #include <gal/color4d.h>
  29. #include <kicommon.h>
  30. #include <macros_swig.h>
  31. #include <stroke_params.h>
  32. #include <api/serializable.h>
  33. using KIGFX::COLOR4D;
  34. DECL_SET_FOR_SWIG( STRINGSET, wxString )
  35. /**
  36. * A collection of nets and the parameters used to route or test these nets.
  37. */
  38. class KICOMMON_API NETCLASS : public SERIALIZABLE
  39. {
  40. public:
  41. static const char Default[]; ///< the name of the default NETCLASS
  42. /**
  43. * Create a NETCLASS instance with \a aName.
  44. * The units on the optional parameters are Internal Units (1 nm)
  45. * @param aName is the name of this new netclass.
  46. * @param aInitWithDefaults if true, initalise the netclass with default values
  47. */
  48. NETCLASS( const wxString& aName, bool aInitWithDefaults = true );
  49. ~NETCLASS(){};
  50. bool operator==( const NETCLASS& other ) const;
  51. wxString GetClass() const
  52. {
  53. return wxT( "NETCLASS" );
  54. }
  55. void Serialize( google::protobuf::Any &aContainer ) const override;
  56. bool Deserialize( const google::protobuf::Any &aContainer ) override;
  57. /// @brief Resets all parent fields to point to this netclass
  58. void ResetParents();
  59. /// @brief Resets all parameters (except Name and Description)
  60. void ResetParameters();
  61. /// @brief Gets the netclasses which make up this netclass
  62. // For a root netcless, this is the netclass this pointer, for aggregate netclasses is contains
  63. // all constituent netclasses, in order of priority.
  64. const std::vector<NETCLASS*>& GetConstituentNetclasses() const;
  65. /// @brief Sets the netclasses which make up this netclass
  66. void SetConstituentNetclasses( std::vector<NETCLASS*>&& constituents );
  67. /// @brief Determines if the given netclass name is a constituent of this (maybe aggregate)
  68. /// netclass
  69. bool ContainsNetclassWithName( const wxString& netclass ) const;
  70. /// @ brief Determines if this is marked as the default netclass
  71. bool IsDefault() const { return m_isDefault; }
  72. /// @brief Set the name of this netclass. Only relevant for root netclasses (i.e. those which
  73. /// are not an aggregate)
  74. void SetName( const wxString& aName )
  75. {
  76. m_Name = aName;
  77. if( aName == Default )
  78. m_isDefault = true;
  79. }
  80. /// @brief Gets the name of this (maybe aggregate) netclass in a format for internal usage or
  81. /// for export to external tools / netlists. WARNING: Do not use this to display a netclass
  82. /// name to a user. Use GetHumanReadableName instead.
  83. const wxString GetName() const;
  84. /// @brief Gets the consolidated name of this netclass (which may be an aggregate). This is
  85. /// intended for display to users (e.g. in infobars or messages). WARNING: Do not use this
  86. /// to compare equivalence, or to export to other tools)
  87. const wxString GetHumanReadableName() const;
  88. const wxString& GetDescription() const { return m_Description; }
  89. void SetDescription( const wxString& aDesc ) { m_Description = aDesc; }
  90. bool HasClearance() const { return (bool) m_Clearance; }
  91. int GetClearance() const { return m_Clearance.value_or(-1); }
  92. std::optional<int> GetClearanceOpt() const { return m_Clearance; }
  93. void SetClearance( int aClearance ) { m_Clearance = aClearance; }
  94. void SetClearance( std::optional<int> aClearance ) { m_Clearance = aClearance; }
  95. void SetClearanceParent( NETCLASS* parent) { m_clearanceParent = parent; }
  96. NETCLASS* GetClearanceParent() const { return m_clearanceParent; }
  97. bool HasTrackWidth() const { return (bool) m_TrackWidth; }
  98. int GetTrackWidth() const { return m_TrackWidth.value_or( -1 ); }
  99. std::optional<int> GetTrackWidthOpt() const { return m_TrackWidth; }
  100. void SetTrackWidth( int aWidth ) { m_TrackWidth = aWidth; }
  101. void SetTrackWidth( std::optional<int> aWidth ) { m_TrackWidth = aWidth; }
  102. void SetTrackWidthParent( NETCLASS* parent) { m_trackWidthParent = parent; }
  103. NETCLASS* GetTrackWidthParent() const { return m_trackWidthParent; }
  104. bool HasViaDiameter() const { return (bool) m_ViaDia; }
  105. int GetViaDiameter() const { return m_ViaDia.value_or( -1 ); }
  106. std::optional<int> GetViaDiameterOpt() const { return m_ViaDia; }
  107. void SetViaDiameter( int aDia ) { m_ViaDia = aDia; }
  108. void SetViaDiameter( std::optional<int> aDia ) { m_ViaDia = aDia; }
  109. void SetViaDiameterParent( NETCLASS* parent) { m_viaDiameterParent = parent; }
  110. NETCLASS* GetViaDiameterParent() const { return m_viaDiameterParent; }
  111. int HasViaDrill() const { return (bool) m_ViaDrill; }
  112. int GetViaDrill() const { return m_ViaDrill.value_or( -1 ); }
  113. std::optional<int> GetViaDrillOpt() const { return m_ViaDrill; }
  114. void SetViaDrill( int aSize ) { m_ViaDrill = aSize; }
  115. void SetViaDrill( std::optional<int> aSize ) { m_ViaDrill = aSize; }
  116. void SetViaDrillParent( NETCLASS* parent) { m_viaDrillParent = parent; }
  117. NETCLASS* GetViaDrillParent() const { return m_viaDrillParent; }
  118. bool HasuViaDiameter() const { return (bool) m_uViaDia; }
  119. int GetuViaDiameter() const { return m_uViaDia.value_or( -1 ); }
  120. std::optional<int> GetuViaDiameterOpt() const { return m_uViaDia; }
  121. void SetuViaDiameter( int aSize ) { m_uViaDia = aSize; }
  122. void SetuViaDiameter( std::optional<int> aSize ) { m_uViaDia = aSize; }
  123. void SetuViaDiameterParent( NETCLASS* parent) { m_uViaDiaParent = parent; }
  124. NETCLASS* GetuViaDiameterParent() const { return m_uViaDiaParent; }
  125. bool HasuViaDrill() const { return (bool) m_uViaDrill; }
  126. int GetuViaDrill() const { return m_uViaDrill.value_or( -1 ); }
  127. std::optional<int> GetuViaDrillOpt() const { return m_uViaDrill; }
  128. void SetuViaDrill( int aSize ) { m_uViaDrill = aSize; }
  129. void SetuViaDrill( std::optional<int> aSize ) { m_uViaDrill = aSize; }
  130. void SetuViaDrillParent( NETCLASS* parent) { m_uViaDrillParent = parent; }
  131. NETCLASS* GetuViaDrillParent() const { return m_uViaDrillParent; }
  132. bool HasDiffPairWidth() const { return (bool) m_diffPairWidth; }
  133. int GetDiffPairWidth() const { return m_diffPairWidth.value_or( -1 ); }
  134. std::optional<int> GetDiffPairWidthOpt() const { return m_diffPairWidth; }
  135. void SetDiffPairWidth( int aSize ) { m_diffPairWidth = aSize; }
  136. void SetDiffPairWidth( std::optional<int> aSize ) { m_diffPairWidth = aSize; }
  137. void SetDiffPairWidthParent( NETCLASS* parent) { m_diffPairWidthParent = parent; }
  138. NETCLASS* GetDiffPairWidthParent() const { return m_diffPairWidthParent; }
  139. bool HasDiffPairGap() const { return (bool) m_diffPairGap; }
  140. int GetDiffPairGap() const { return m_diffPairGap.value_or( -1 ); }
  141. std::optional<int> GetDiffPairGapOpt() const { return m_diffPairGap; }
  142. void SetDiffPairGap( int aSize ) { m_diffPairGap = aSize; }
  143. void SetDiffPairGap( std::optional<int> aSize ) { m_diffPairGap = aSize; }
  144. void SetDiffPairGapParent( NETCLASS* parent) { m_diffPairGapParent = parent; }
  145. NETCLASS* GetDiffPairGapParent() const { return m_diffPairGapParent; }
  146. bool HasDiffPairViaGap() const { return (bool) m_diffPairViaGap; }
  147. int GetDiffPairViaGap() const { return m_diffPairViaGap.value_or( -1 ); }
  148. std::optional<int> GetDiffPairViaGapOpt() const { return m_diffPairViaGap; }
  149. void SetDiffPairViaGap( int aSize ) { m_diffPairViaGap = aSize; }
  150. void SetDiffPairViaGap( std::optional<int> aSize ) { m_diffPairViaGap = aSize; }
  151. void SetDiffPairViaGapParent( NETCLASS* parent) { m_diffPairViaGapParent = parent; }
  152. NETCLASS* GetDiffPairViaGapParent() const { return m_diffPairViaGapParent; }
  153. bool HasPcbColor() const { return m_isDefault ? false : m_pcbColor != COLOR4D::UNSPECIFIED; }
  154. COLOR4D GetPcbColor( bool aIsForSave = false ) const
  155. {
  156. // If we are saving netclases, return the underlying color (which may be set from an old
  157. // schematic with a default color set - this allows us to roll back the no-default-colors
  158. // changes later if required)
  159. if( aIsForSave || !m_isDefault )
  160. return m_pcbColor;
  161. return COLOR4D::UNSPECIFIED;
  162. }
  163. void SetPcbColor( const COLOR4D& aColor ) { m_pcbColor = aColor; }
  164. void SetPcbColorParent( NETCLASS* parent) { m_pcbColorParent = parent; }
  165. NETCLASS* GetPcbColorParent() const { return m_pcbColorParent; }
  166. bool HasWireWidth() const { return (bool) m_wireWidth; }
  167. int GetWireWidth() const { return m_wireWidth.value_or( -1 ); }
  168. std::optional<int> GetWireWidthOpt() const { return m_wireWidth; }
  169. void SetWireWidth( int aWidth ) { m_wireWidth = aWidth; }
  170. void SetWireWidth( std::optional<int> aWidth ) { m_wireWidth = aWidth; }
  171. void SetWireWidthParent( NETCLASS* parent) { m_wireWidthParent = parent; }
  172. NETCLASS* GetWireWidthParent() const { return m_wireWidthParent; }
  173. bool HasBusWidth() const { return (bool) m_busWidth; }
  174. int GetBusWidth() const { return m_busWidth.value_or( -1 ); }
  175. std::optional<int> GetBusWidthOpt() const { return m_busWidth; }
  176. void SetBusWidth( int aWidth ) { m_busWidth = aWidth; }
  177. void SetBusWidth( std::optional<int> aWidth ) { m_busWidth = aWidth; }
  178. void SetBusWidthParent( NETCLASS* parent) { m_busWidthParent = parent; }
  179. NETCLASS* GetBusWidthParent() const { return m_busWidthParent; }
  180. COLOR4D GetSchematicColor( bool aIsForSave = false ) const
  181. {
  182. // If we are saving netclases, return the underlying color (which may be set from an old
  183. // schematic with a default color set - this allows us to roll back the no-default-colors
  184. // changes later if required)
  185. if( aIsForSave || !m_isDefault )
  186. return m_schematicColor;
  187. return COLOR4D::UNSPECIFIED;
  188. }
  189. void SetSchematicColor( COLOR4D aColor ) { m_schematicColor = aColor; }
  190. void SetSchematicColorParent( NETCLASS* parent) { m_schematicColorParent = parent; }
  191. NETCLASS* GetSchematicColorParent() const { return m_schematicColorParent; }
  192. bool HasLineStyle() const { return (bool) m_lineStyle; }
  193. int GetLineStyle() const { return m_lineStyle.value_or( 0 ); }
  194. std::optional<int> GetLineStyleOpt() const { return m_lineStyle; }
  195. void SetLineStyle( int aStyle ) { m_lineStyle = aStyle; }
  196. void SetLineStyle( std::optional<int> aStyle ) { m_lineStyle = aStyle; }
  197. void SetLineStyleParent( NETCLASS* parent) { m_lineStyleParent = parent; }
  198. NETCLASS* GetLineStyleParent() const { return m_lineStyleParent; }
  199. void SetPriority( int aPriority ) { m_Priority = aPriority; }
  200. int GetPriority() const { return m_Priority; }
  201. protected:
  202. bool m_isDefault; ///< Mark if this instance is the default netclass
  203. std::vector<NETCLASS*> m_constituents; ///< NETCLASSes contributing to an aggregate
  204. wxString m_Name; ///< Name of the net class
  205. int m_Priority; ///< The priority for multiple netclass resolution
  206. wxString m_Description; ///< what this NETCLASS is for.
  207. std::optional<int> m_Clearance; ///< clearance when routing
  208. std::optional<int> m_TrackWidth; ///< track width used to route nets
  209. std::optional<int> m_ViaDia; ///< via diameter
  210. std::optional<int> m_ViaDrill; ///< via drill hole diameter
  211. std::optional<int> m_uViaDia; ///< microvia diameter
  212. std::optional<int> m_uViaDrill; ///< microvia drill hole diameter
  213. std::optional<int> m_diffPairWidth;
  214. std::optional<int> m_diffPairGap;
  215. std::optional<int> m_diffPairViaGap;
  216. std::optional<int> m_wireWidth;
  217. std::optional<int> m_busWidth;
  218. COLOR4D m_schematicColor;
  219. std::optional<int> m_lineStyle;
  220. COLOR4D m_pcbColor; ///< Optional PCB color override for this netclass
  221. // The NETCLASS providing each parameter
  222. NETCLASS* m_clearanceParent;
  223. NETCLASS* m_trackWidthParent;
  224. NETCLASS* m_viaDiameterParent;
  225. NETCLASS* m_viaDrillParent;
  226. NETCLASS* m_uViaDiaParent;
  227. NETCLASS* m_uViaDrillParent;
  228. NETCLASS* m_diffPairWidthParent;
  229. NETCLASS* m_diffPairGapParent;
  230. NETCLASS* m_diffPairViaGapParent;
  231. NETCLASS* m_pcbColorParent;
  232. NETCLASS* m_wireWidthParent;
  233. NETCLASS* m_busWidthParent;
  234. NETCLASS* m_schematicColorParent;
  235. NETCLASS* m_lineStyleParent;
  236. };
  237. #endif // CLASS_NETCLASS_H