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.

254 lines
9.3 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 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. /** this class handle info which can be added in a gerber P&P file as attribute
  27. * of a component
  28. * Only applicable to objects having the TA.AperFunction attribute "ComponentMain"
  29. * There are specific attributes defined attached to the component by the %TO command
  30. * %TO.CRot,<angle> The rotation angle of the component.
  31. * The rotation angle is consistent with the one for graphics objects.
  32. * Positive rotation is counter- clockwise as viewed from the top side, even if
  33. * the component is on the board side.
  34. * The base orientation of component - no rotation - on the top side is as in IPC-7351.
  35. * Components on the bottom side are of course mirrored.
  36. * The base orientation on the bottom side is the one on the top side
  37. * mirrored around the X axis.
  38. * %TO.CMfr,<string> Manufacturer
  39. * %TO.CMPN,<string> Manufacturer part number
  40. * %TO.Cpkg,<string> Package, as per IPC-7351
  41. * %TO.CVal,<string> Value, a string. E.g. 220nF
  42. * %TO.CMnt,<string> Mount type: (SMD|TH|Other)
  43. * %TO.CFtp,<string> Footprint name, a string. E.g. LQFP-100_14x14mm_P0.5mm
  44. This is the footprint name coming from the CAD tool libraries.
  45. * %TO.CPgN,<string> Package name, like the JEDEC JEP95 standard.
  46. * %TO.CPgD,<string> Package description.
  47. * %TO.CHgt,<string> Height, a decimal, in the unit of the file.
  48. * %TO.CLbN,<string> Library name.
  49. * %TO.CLbD,<string> Library description.
  50. * %TO.Sup,<SN>,<SPN> SN is a field with the supppier name.
  51. * SPN is a field with the supppier part name
  52. */
  53. class GBR_CMP_PNP_METADATA
  54. {
  55. public:
  56. enum MOUNT_TYPE
  57. {
  58. MOUNT_TYPE_UNSPECIFIED,
  59. MOUNT_TYPE_SMD,
  60. MOUNT_TYPE_TH
  61. };
  62. double m_Orientation; // orientation in degree
  63. wxString m_Manufacturer; // Manufacturer name
  64. wxString m_MPN; // Manufacturer part number
  65. wxString m_Package; // Package, as per IPC-7351
  66. wxString m_Footprint; // Footprint name, from library
  67. wxString m_LibraryName; // Library name, containing the footprint
  68. wxString m_LibraryDescr; // Library description
  69. wxString m_Value; // Component value
  70. MOUNT_TYPE m_MountType; // SMD|TH|Other
  71. GBR_CMP_PNP_METADATA() :
  72. m_Orientation( 0.0 ), m_MountType( MOUNT_TYPE_UNSPECIFIED )
  73. {}
  74. void ClearData(); // Clear all strings
  75. /**
  76. * @return a string containing the formated metadata in X2 syntax.
  77. * one line by non empty data
  78. * the orientation is always generated
  79. */
  80. wxString FormatCmpPnPMetadata();
  81. };
  82. /**
  83. * This class handle a Gerber data field.
  84. * this is a unicode string with some chars converted in escaped Hexa sequence
  85. * when creating the file
  86. * Chars always escaped because they are separator in Gerber files: * , \ %
  87. * non ascii 7 chars can be converted to UTF8 or escaped.
  88. */
  89. class GBR_DATA_FIELD
  90. {
  91. public:
  92. GBR_DATA_FIELD() : m_useUTF8( false ), m_escapeString( false )
  93. {}
  94. void clear()
  95. {
  96. m_field.clear();
  97. m_useUTF8 = false;
  98. m_escapeString = false;
  99. }
  100. void Clear() { clear(); }
  101. const wxString& GetValue() { return m_field; }
  102. void SetField( const wxString& aField, bool aUseUTF8, bool aEscapeString )
  103. {
  104. m_field = aField;
  105. m_useUTF8 = aUseUTF8;
  106. m_escapeString = aEscapeString;
  107. }
  108. bool IsEmpty() { return m_field.IsEmpty(); }
  109. std::string GetGerberString();
  110. private:
  111. wxString m_field; ///< the unicade text to print in Gbr file
  112. ///< (after escape and quoting)
  113. bool m_useUTF8; ///< true to use UTF8, false to escape non ascii7 chars
  114. bool m_escapeString; ///< true to quote the field in gbr file
  115. };
  116. /** this class handle info which can be added in a gerber file as attribute
  117. * of an object
  118. * the GBR_INFO_TYPE types can be OR'ed to add 2 (or more) attributes
  119. * There are only 3 net attributes defined attached to an object by the %TO command
  120. * %TO.P
  121. * %TO.N
  122. * %TO.C
  123. * the .P attribute can be used only for flashed pads (using the D03 command)
  124. * and only for external copper layers, if the component is on a external copper layer
  125. * for other copper layer items (pads on internal layers, tracks ... ), only .N and .C
  126. * can be used
  127. */
  128. class GBR_NETLIST_METADATA
  129. {
  130. public:
  131. // This enum enables the different net attributes attache to the object
  132. // the values can be ORed for items which can have more than one attribute
  133. // (A flashed pad has all allowed attributes)
  134. enum GBR_NETINFO_TYPE
  135. {
  136. GBR_NETINFO_UNSPECIFIED, ///< idle command (no command)
  137. GBR_NETINFO_PAD = 1, ///< print info associated to a flashed pad (TO.P attribute)
  138. GBR_NETINFO_NET = 2, ///< print info associated to a net (TO.N attribute)
  139. GBR_NETINFO_CMP = 4 ///< print info associated to a component (TO.C attribute)
  140. };
  141. // these members are used in the %TO object attributes command.
  142. int m_NetAttribType; ///< the type of net info
  143. ///< (used to define the gerber string to create)
  144. bool m_NotInNet; ///< true if a pad of a footprint cannot be connected
  145. ///< (for instance a mechanical NPTH, ot a not named pad)
  146. ///< in this case the pad net name is empty in gerber file
  147. GBR_DATA_FIELD m_Padname; ///< for a flashed pad: the pad name ((TO.P attribute)
  148. GBR_DATA_FIELD m_PadPinFunction; ///< for a pad: the pin function (defined in schematic)
  149. wxString m_Cmpref; ///< the component reference parent of the data
  150. wxString m_Netname; ///< for items associated to a net: the netname
  151. wxString m_ExtraData; ///< a string to print after %TO object attributes, if not empty
  152. ///< it is printed "as this"
  153. /** If true, do not clear all attributes when a atribute has changed
  154. * Usefull when some attributes need to be persistant.
  155. * If false, attributes will be cleared if only one attribute cleared
  156. * This is a more secure way to set attributes, when all attribute changess are not safely managed
  157. */
  158. bool m_TryKeepPreviousAttributes;
  159. GBR_NETLIST_METADATA(): m_NetAttribType( GBR_NETINFO_UNSPECIFIED ),
  160. m_NotInNet( false ), m_TryKeepPreviousAttributes( false )
  161. {
  162. }
  163. /** Clear the extra data string printed at end of net attributes
  164. */
  165. void ClearExtraData()
  166. {
  167. m_ExtraData.Clear();
  168. }
  169. /** Set the extra data string printed at end of net attributes
  170. */
  171. void SetExtraData( const wxString& aExtraData)
  172. {
  173. m_ExtraData = aExtraData;
  174. }
  175. /**
  176. * remove the net attribute specified by aName
  177. * If aName == NULL or empty, remove all attributes
  178. * @param aName is the name (.CN, .P .N or .C) of the attribute to remove
  179. */
  180. void ClearAttribute( const wxString* aName )
  181. {
  182. if( m_NetAttribType == GBR_NETINFO_UNSPECIFIED )
  183. {
  184. m_Padname.clear();
  185. m_PadPinFunction.clear();
  186. m_Cmpref.clear();
  187. m_Netname.clear();
  188. return;
  189. }
  190. if( !aName || aName->IsEmpty() || *aName == ".CN" )
  191. {
  192. m_NetAttribType = GBR_NETINFO_UNSPECIFIED;
  193. m_Padname.clear();
  194. m_PadPinFunction.clear();
  195. m_Cmpref.clear();
  196. m_Netname.clear();
  197. return;
  198. }
  199. if( *aName == ".C" )
  200. {
  201. m_NetAttribType &= ~GBR_NETINFO_CMP;
  202. m_Cmpref.clear();
  203. return;
  204. }
  205. if( *aName == ".N" )
  206. {
  207. m_NetAttribType &= ~GBR_NETINFO_NET;
  208. m_Netname.clear();
  209. return;
  210. }
  211. if( *aName == ".P" )
  212. {
  213. m_NetAttribType &= ~GBR_NETINFO_PAD;
  214. m_Padname.clear();
  215. m_PadPinFunction.clear();
  216. return;
  217. }
  218. }
  219. };
  220. // Flashed pads use the full attribute set: this is a helper for flashed pads
  221. #define GBR_NETINFO_ALL (GBR_NETLIST_METADATA::GBR_NETINFO_PAD\
  222. | GBR_NETLIST_METADATA::GBR_NETINFO_NET\
  223. | GBR_NETLIST_METADATA::GBR_NETINFO_CMP )
  224. #endif // GBR_NETLIST_METADATA_H