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.

262 lines
9.4 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2016 Jean-Pierre Charras, jp.charras at wanadoo.fr
  5. * Copyright (C) 2016-2020 KiCad Developers, see AUTHORS.txt for contributors.
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License
  9. * as published by the Free Software Foundation; either version 2
  10. * of the License, or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, you may find one here:
  19. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  20. * or you may search the http://www.gnu.org website for the version 2 license,
  21. * or you may write to the Free Software Foundation, Inc.,
  22. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  23. */
  24. #ifndef GBR_NETLIST_METADATA_H
  25. #define GBR_NETLIST_METADATA_H
  26. /**
  27. * Information which can be added in a gerber P&P file as attribute of a component.
  28. *
  29. * This is only applicable to objects having the TA.AperFunction attribute "ComponentMain"
  30. * There are specific attributes defined attached to the component by the %TO command
  31. * %TO.CRot,<angle> The rotation angle of the component.
  32. * The rotation angle is consistent with the one for graphics objects.
  33. * Positive rotation is counter- clockwise as viewed from the top side, even if
  34. * the component is on the board side.
  35. * The base orientation of component - no rotation - on the top side is as in IPC-7351.
  36. * Components on the bottom side are of course mirrored.
  37. * The base orientation on the bottom side is the one on the top side
  38. * mirrored around the X axis.
  39. *
  40. * %TO.CMfr,<string> Manufacturer
  41. * %TO.CMPN,<string> Manufacturer part number
  42. * %TO.Cpkg,<string> Package, as per IPC-7351
  43. * %TO.CVal,<string> Value, a string. E.g. 220nF
  44. * %TO.CMnt,<string> Mount type: (SMD|TH|Other)
  45. * %TO.CFtp,<string> Footprint name, a string. E.g. LQFP-100_14x14mm_P0.5mm
  46. This is the footprint name coming from the CAD tool libraries.
  47. * %TO.CPgN,<string> Package name, like the JEDEC JEP95 standard.
  48. * %TO.CPgD,<string> Package description.
  49. * %TO.CHgt,<string> Height, a decimal, in the unit of the file.
  50. * %TO.CLbN,<string> Library name.
  51. * %TO.CLbD,<string> Library description.
  52. * %TO.Sup,<SN>,<SPN> SN is a field with the supplier name.
  53. * SPN is a field with the supplier part name.
  54. */
  55. class GBR_CMP_PNP_METADATA
  56. {
  57. public:
  58. enum MOUNT_TYPE
  59. {
  60. MOUNT_TYPE_UNSPECIFIED,
  61. MOUNT_TYPE_SMD,
  62. MOUNT_TYPE_TH
  63. };
  64. GBR_CMP_PNP_METADATA() :
  65. m_Orientation( 0.0 ),
  66. m_MountType( MOUNT_TYPE_UNSPECIFIED )
  67. {}
  68. void ClearData(); // Clear all strings
  69. /**
  70. * @return a string containing the formatted metadata in X2 syntax.
  71. */
  72. wxString FormatCmpPnPMetadata();
  73. double m_Orientation; // orientation in degree
  74. wxString m_Manufacturer; // Manufacturer name
  75. wxString m_MPN; // Manufacturer part number
  76. wxString m_Package; // Package, as per IPC-7351
  77. wxString m_Footprint; // Footprint name, from library
  78. wxString m_LibraryName; // Library name, containing the footprint
  79. wxString m_LibraryDescr; // Library description
  80. wxString m_Value; // Component value
  81. MOUNT_TYPE m_MountType; // SMD|TH|Other
  82. };
  83. /**
  84. * A Gerber data field.
  85. *
  86. * This is a Unicode string with some chars converted in escaped hexadecimal sequence
  87. * when creating the file. The following characters are always escaped because they
  88. * are separator in Gerber files: * , \ %. Non ASCII7 characters can be converted to
  89. * UTF8 or escaped.
  90. */
  91. class GBR_DATA_FIELD
  92. {
  93. public:
  94. GBR_DATA_FIELD() : m_useUTF8( false ), m_escapeString( false )
  95. {}
  96. void clear()
  97. {
  98. m_field.clear();
  99. m_useUTF8 = false;
  100. m_escapeString = false;
  101. }
  102. void Clear() { clear(); }
  103. const wxString& GetValue() const { return m_field; }
  104. void SetField( const wxString& aField, bool aUseUTF8, bool aEscapeString )
  105. {
  106. m_field = aField;
  107. m_useUTF8 = aUseUTF8;
  108. m_escapeString = aEscapeString;
  109. }
  110. bool IsEmpty() const { return m_field.IsEmpty(); }
  111. std::string GetGerberString() const;
  112. private:
  113. wxString m_field; ///< the Unicode text to print in Gbr file
  114. ///< (after escape and quoting)
  115. bool m_useUTF8; ///< true to use UTF8, false to escape non ASCII7 chars
  116. bool m_escapeString; ///< true to quote the field in gbr file
  117. };
  118. /**
  119. * Information which can be added in a gerber file as attribute of an object.
  120. *
  121. * The #GBR_INFO_TYPE types can be OR'ed to add 2 (or more) attributes. There are only 3
  122. * net attributes defined attached to an object by the %TO command:
  123. * - %TO.P
  124. * - %TO.N
  125. * - %TO.C
  126. *
  127. * The .P attribute can be used only for flashed pads (using the D03 command) and only for
  128. * external copper layers, if the component is on a external copper layer for other copper
  129. * layer items (pads on internal layers, tracks ... ), only .N and .C can be used.
  130. */
  131. class GBR_NETLIST_METADATA
  132. {
  133. public:
  134. // This enum enables the different net attributes attached to the object
  135. // the values can be ORed for items which can have more than one attribute
  136. // (A flashed pad has all allowed attributes)
  137. enum GBR_NETINFO_TYPE
  138. {
  139. GBR_NETINFO_UNSPECIFIED, ///< idle command (no command)
  140. GBR_NETINFO_PAD = 1, ///< print info associated to a flashed pad (TO.P attribute)
  141. GBR_NETINFO_NET = 2, ///< print info associated to a net (TO.N attribute)
  142. GBR_NETINFO_CMP = 4 ///< print info associated to a component (TO.C attribute)
  143. };
  144. GBR_NETLIST_METADATA(): m_NetAttribType( GBR_NETINFO_UNSPECIFIED ),
  145. m_NotInNet( false ), m_TryKeepPreviousAttributes( false )
  146. {
  147. }
  148. /**
  149. * Clear the extra data string printed at end of net attributes.
  150. */
  151. void ClearExtraData()
  152. {
  153. m_ExtraData.Clear();
  154. }
  155. /**
  156. * Set the extra data string printed at end of net attributes
  157. */
  158. void SetExtraData( const wxString& aExtraData)
  159. {
  160. m_ExtraData = aExtraData;
  161. }
  162. /**
  163. * Remove the net attribute specified by \a aName.
  164. *
  165. * If aName == NULL or empty, remove all attributes.
  166. *
  167. * @param aName is the name (.CN, .P .N or .C) of the attribute to remove.
  168. */
  169. void ClearAttribute( const wxString* aName )
  170. {
  171. if( m_NetAttribType == GBR_NETINFO_UNSPECIFIED )
  172. {
  173. m_Padname.clear();
  174. m_PadPinFunction.clear();
  175. m_Cmpref.clear();
  176. m_Netname.clear();
  177. return;
  178. }
  179. if( !aName || aName->IsEmpty() || *aName == wxT( ".CN" ) )
  180. {
  181. m_NetAttribType = GBR_NETINFO_UNSPECIFIED;
  182. m_Padname.clear();
  183. m_PadPinFunction.clear();
  184. m_Cmpref.clear();
  185. m_Netname.clear();
  186. return;
  187. }
  188. if( *aName == wxT( ".C" ) )
  189. {
  190. m_NetAttribType &= ~GBR_NETINFO_CMP;
  191. m_Cmpref.clear();
  192. return;
  193. }
  194. if( *aName == wxT( ".N" ) )
  195. {
  196. m_NetAttribType &= ~GBR_NETINFO_NET;
  197. m_Netname.clear();
  198. return;
  199. }
  200. if( *aName == wxT( ".P" ) )
  201. {
  202. m_NetAttribType &= ~GBR_NETINFO_PAD;
  203. m_Padname.clear();
  204. m_PadPinFunction.clear();
  205. return;
  206. }
  207. }
  208. // these members are used in the %TO object attributes command.
  209. int m_NetAttribType; ///< the type of net info
  210. ///< (used to define the gerber string to create)
  211. bool m_NotInNet; ///< true if a pad of a footprint cannot be connected
  212. ///< (for instance a mechanical NPTH, ot a not named pad)
  213. ///< in this case the pad net name is empty in gerber file
  214. GBR_DATA_FIELD m_Padname; ///< for a flashed pad: the pad name ((TO.P attribute)
  215. GBR_DATA_FIELD m_PadPinFunction; ///< for a pad: the pin function (defined in schematic)
  216. wxString m_Cmpref; ///< the component reference parent of the data
  217. wxString m_Netname; ///< for items associated to a net: the netname
  218. wxString m_ExtraData; ///< a string to print after %TO object attributes, if not empty
  219. ///< it is printed "as this"
  220. /**
  221. * If true, do not clear all attributes when a attribute has changed. This is useful
  222. * when some attributes need to be persistent. If false, attributes will be cleared
  223. * if only one attribute cleared. This is a more secure way to set attributes, when
  224. * all attribute changes are not safely managed.
  225. */
  226. bool m_TryKeepPreviousAttributes;
  227. };
  228. // Flashed pads use the full attribute set: this is a helper for flashed pads
  229. #define GBR_NETINFO_ALL \
  230. ( GBR_NETLIST_METADATA::GBR_NETINFO_PAD | GBR_NETLIST_METADATA::GBR_NETINFO_NET \
  231. | GBR_NETLIST_METADATA::GBR_NETINFO_CMP )
  232. #endif // GBR_NETLIST_METADATA_H