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.

203 lines
7.1 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2010-2018 Jean-Pierre Charras jp.charras at wanadoo.fr
  5. * Copyright (C) 1992-2021 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. /**
  25. * @file X2_gerber_attributes.h
  26. */
  27. #ifndef X2_GERBER_ATTRIBUTE_H
  28. #define X2_GERBER_ATTRIBUTE_H
  29. /*
  30. * Manage the gerber extensions (attributes) in the new X2 version
  31. * only few extensions are handled
  32. * See http://www.ucamco.com/files/downloads/file/81/the_gerber_file_format_specification.pdf
  33. *
  34. * gerber attributes in the new X2 version look like:
  35. * %TF.FileFunction,Copper,L1,Top*%
  36. *
  37. * Currently:
  38. * .FileFunction .FileFunction Identifies the file's function in the PCB.
  39. * Other Standard Attributes, not yet used in Gerbview:
  40. * .Part Identifies the part the file represents, e.g. a single PCB
  41. * .MD5 Sets the MD5 file signature or checksum.
  42. */
  43. #include <wx/arrstr.h>
  44. /**
  45. * The attribute value consists of a number of substrings separated by a comma
  46. */
  47. class X2_ATTRIBUTE
  48. {
  49. public:
  50. X2_ATTRIBUTE();
  51. ~X2_ATTRIBUTE();
  52. /**
  53. * @return the parameters list read in TF command.
  54. */
  55. wxArrayString& GetPrms() { return m_Prms; }
  56. /**
  57. * @return a parameter read in TF command.
  58. * @param aIdx = the index of the parameter
  59. * aIdx = 0 is the parameter read after the TF function
  60. * (the same as GetAttribute())
  61. */
  62. const wxString& GetPrm( int aIdx );
  63. /**
  64. * @return the attribute name (for instance .FileFunction)
  65. * which is given by TF command (i.e. the first parameter read).
  66. */
  67. const wxString& GetAttribute();
  68. /**
  69. * @return the number of parameters read in %TF
  70. * (or similar like %TA %TO ...) command.
  71. */
  72. int GetPrmCount() { return int( m_Prms.GetCount() ); }
  73. /**
  74. * Parse a TF command terminated with a % and fill m_Prms by the parameters found.
  75. *
  76. * @param aFile = a FILE* ptr to the current Gerber file.
  77. * @param aBuffer = the buffer containing current Gerber data (can be null)
  78. * @param aBuffSize = the size of the buffer
  79. * @param aText = a pointer to the first char to read from Gerber data stored in aBuffer
  80. * After parsing, text points the last char of the command line ('%') (X2 mode)
  81. * or the end of line if the line does not contain '%' or aBuffer == NULL (X1 mode)
  82. * @param aLineNum = a point to the current line number of aFile
  83. * @return true if no error.
  84. */
  85. bool ParseAttribCmd( FILE* aFile, char *aBuffer, int aBuffSize, char* &aText, int& aLineNum );
  86. /**
  87. * Debug function: print using wxLogMessage le list of parameters
  88. */
  89. void DbgListPrms();
  90. /**
  91. * Return true if the attribute is .FileFunction
  92. */
  93. bool IsFileFunction()
  94. {
  95. return GetAttribute().IsSameAs( wxT(".FileFunction"), false );
  96. }
  97. /**
  98. * Return true if the attribute is .MD5
  99. */
  100. bool IsFileMD5()
  101. {
  102. return GetAttribute().IsSameAs( wxT(".MD5"), false );
  103. }
  104. /**
  105. * Return true if the attribute is .Part
  106. */
  107. bool IsFilePart()
  108. {
  109. return GetAttribute().IsSameAs( wxT(".Part"), false );
  110. }
  111. protected:
  112. wxArrayString m_Prms; ///< the list of parameters (after TF) in gbr file
  113. ///< the first one is the attribute name,
  114. ///< if starting by '.'
  115. };
  116. /**
  117. * X2_ATTRIBUTE_FILEFUNCTION ( from %TF.FileFunction in Gerber file)
  118. * Example file function:
  119. * %TF.FileFunction,Copper,L1,Top*%
  120. * - Type. Such as copper, solder mask etc.
  121. * - Position. Specifies where the file appears in the PCB layer structure.
  122. * Corresponding position substring:
  123. * Copper layer: L1, L2, L3...to indicate the layer position followed by Top, Inr or
  124. * Bot. L1 is always the top copper layer. E.g. L2,Inr.
  125. * Extra layer, e.g. solder mask: Top or Bot - defines the attachment of the layer.
  126. * Drill/rout layer: E.g. 1,4 - where 1 is the start and 4 is the end copper layer. The
  127. * pair 1,4 defines the span of the drill/rout file
  128. * Optional index. This can be used in instances where for example there are two solder
  129. * masks on the same side. The index counts from the PCB surface outwards.
  130. */
  131. class X2_ATTRIBUTE_FILEFUNCTION : public X2_ATTRIBUTE
  132. {
  133. public:
  134. X2_ATTRIBUTE_FILEFUNCTION( X2_ATTRIBUTE& aAttributeBase );
  135. bool IsCopper(); ///< return true if the filefunction type is "Copper"
  136. /**
  137. * @return true if the filefunction type is "Plated" or "NotPlated"
  138. * therefore a drill file
  139. */
  140. bool IsDrillFile();
  141. const wxString& GetFileType(); ///< the type of layer (Copper, Soldermask ... )
  142. const wxString& GetBrdLayerId(); ///< the brd layer identifier: Ln, only for Copper type
  143. ///< or Top, Bot for other types
  144. /**
  145. * @return the brd layer pair identifier: n,m for drill files
  146. * (files with m_Prms.Item( 1 ) = "Plated" or "NotPlated")
  147. */
  148. const wxString GetDrillLayerPair();
  149. /**
  150. * @return the Layer Pair type for drill files
  151. * (PTH, NPTH, Blind or Buried)
  152. */
  153. const wxString& GetLPType();
  154. /**
  155. * @return the drill/routing type for drill files
  156. * (Drill, Route, Mixed)
  157. */
  158. const wxString& GetRouteType();
  159. const wxString& GetBrdLayerSide(); ///< the brd layer Pos: Top, Bot, Inr
  160. ///< same as GetBrdLayerId() for non copper type
  161. const wxString& GetLabel(); ///< the filefunction label, if any
  162. int GetZOrder() { return m_z_order; } ///< the Order of the board layer,
  163. ///< from front (Top) side to back (Bot) side
  164. int GetZSubOrder() { return m_z_sub_order; } ///< the Order of the bdr copper layer,
  165. ///< from front (Top) side to back (Bot) side
  166. private:
  167. /**
  168. * Initialize the z order priority of the current file, from its attributes
  169. */
  170. void set_Z_Order();
  171. int m_z_order; // the z order of the layer for a board
  172. int m_z_sub_order; // the z sub_order of the copper layer for a board
  173. };
  174. #endif // X2_GERBER_ATTRIBUTE_H