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.

171 lines
5.9 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2010-2014 Jean-Pierre Charras jp.charras at wanadoo.fr
  5. * Copyright (C) 1992-2014 KiCad Developers, see change_log.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 class_X2_gerber_attributes.h
  26. */
  27. #ifndef _CLASS_X2_GERBER_ATTRIBUTE_H_
  28. #define _CLASS_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 files 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. * class X2_ATTRIBUTE
  46. * The attribute value consists of a number of substrings separated by a ,
  47. */
  48. class X2_ATTRIBUTE
  49. {
  50. protected:
  51. wxArrayString m_Prms; ///< the list of parameters (after TF) in gbr file
  52. ///< the first one is the attribute name,
  53. ///< if starting by '.'
  54. public:
  55. X2_ATTRIBUTE();
  56. ~X2_ATTRIBUTE();
  57. /**
  58. * @return the parameters list read in TF command.
  59. */
  60. wxArrayString& GetPrms() { return m_Prms; }
  61. /**
  62. * @return a parameter read in TF command.
  63. * @param aIdx = the index of the parameter
  64. * aIdx = 0 is the parameter read after the TF function
  65. * (the same as GetAttribute())
  66. */
  67. const wxString& GetPrm( int aIdx );
  68. /**
  69. * @return the attribute name (for instance .FileFunction)
  70. * which is given by TF command (i.e. the first parameter read).
  71. */
  72. const wxString& GetAttribute();
  73. /**
  74. * @return the number of parameters read in TF command.
  75. */
  76. int GetPrmCount() { return int( m_Prms.GetCount() ); }
  77. /**
  78. * parse a TF command terminated with a % and fill m_Prms
  79. * by the parameters found.
  80. * @param aFile = a FILE* ptr to the current Gerber file.
  81. * @param aBuffer = the buffer containing current Gerber data (can be null)
  82. * @param aBuffSize = the size of the buffer
  83. * @param aText = a pointer to the first char to read from Gerber data stored in aBuffer
  84. * After parsing, text points the last char of the command line ('%') (X2 mode)
  85. * or the end of line if the line does not contain '%' or aBuffer == NULL (X1 mode)
  86. * @return true if no error.
  87. */
  88. bool ParseAttribCmd( FILE* aFile, char *aBuffer, int aBuffSize, char*& aText );
  89. /**
  90. * Debug function: pring using wxLogMessage le list of parameters
  91. */
  92. void DbgListPrms();
  93. /**
  94. * return true if the attribute is .FileFunction
  95. */
  96. bool IsFileFunction()
  97. {
  98. return GetAttribute().IsSameAs( wxT(".FileFunction"), false );
  99. }
  100. /**
  101. * return true if the attribute is .MD5
  102. */
  103. bool IsFileMD5()
  104. {
  105. return GetAttribute().IsSameAs( wxT(".MD5"), false );
  106. }
  107. /**
  108. * return true if the attribute is .Part
  109. */
  110. bool IsFilePart()
  111. {
  112. return GetAttribute().IsSameAs( wxT(".Part"), false );
  113. }
  114. };
  115. /**
  116. * class X2_ATTRIBUTE_FILEFUNCTION ( from %TF.FileFunction in Gerber file)
  117. * Example file function:
  118. * %TF.FileFunction,Copper,L1,Top*%
  119. * - Type. Such as copper, solder mask etc.
  120. * - Position. Specifies where the file appears in the PCB layer structure.
  121. * Corresponding position substring:
  122. * Copper layer: L1, L2, L3...to indicate the layer position followed by Top, Inr or
  123. * Bot. L1 is always the top copper layer. E.g. L2,Inr.
  124. * Extra layer, e.g. solder mask: Top or Bot defines the attachment of the layer.
  125. * Drill/rout layer: E.g. 1,4 where 1 is the start and 4 is the end copper layer. The
  126. * pair 1,4 defines the span of the drill/rout file
  127. * Optional index. This can be used in instances where for example there are two solder
  128. * masks on the same side. The index counts from the PCB surface outwards.
  129. */
  130. class X2_ATTRIBUTE_FILEFUNCTION : public X2_ATTRIBUTE
  131. {
  132. int m_z_order; // the z order of the layer for a board
  133. int m_z_sub_order; // the z sub_order of the copper layer for a board
  134. public:
  135. X2_ATTRIBUTE_FILEFUNCTION( X2_ATTRIBUTE& aAttributeBase );
  136. const wxString& GetFileType(); ///< the type of layer (Copper , Soldermask ... )
  137. const wxString& GetBrdLayerId(); ///< the brd layer identifier: Top, Bot, Ln
  138. const wxString& GetLabel(); ///< the filefunction label, if any
  139. int GetZOrder() { return m_z_order; } ///< the Order of the bdr layer, from front (Top side) to back side
  140. int GetZSubOrder() { return m_z_sub_order; } ///< the Order of the bdr copper layer, from front (Top side) to back side
  141. private:
  142. /**
  143. * Initialize the z order priority of the current file, from its attributes
  144. */
  145. void set_Z_Order();
  146. };
  147. #endif // _CLASS_X2_GERBER_ATTRIBUTE_H_