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.

140 lines
4.9 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 1992-2010 Jean-Pierre Charras <jp.charras at wanadoo.fr>
  5. * Copyright (C) 2010 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
  6. * Copyright (C) 1992-2023 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. /**
  26. * @file aperture_macro.h
  27. */
  28. #ifndef APERTURE_MACRO_H
  29. #define APERTURE_MACRO_H
  30. #include <vector>
  31. #include <set>
  32. #include <am_param.h>
  33. #include <am_primitive.h>
  34. class SHAPE_POLY_SET;
  35. /*
  36. * An aperture macro defines a complex shape and is a list of aperture primitives.
  37. * Each aperture primitive defines a simple shape (circle, rect, regular polygon...)
  38. * Inside a given aperture primitive, a fixed list of parameters defines info
  39. * about the shape: size, thickness, number of vertex ...
  40. *
  41. * Each parameter can be an immediate value or a deferred value.
  42. * When value is deferred, it is defined when the aperture macro is instanced by
  43. * an ADD macro command
  44. * Note also a deferred parameter can be defined in aperture macro,
  45. * but outside aperture primitives. Example
  46. * %AMRECTHERM*
  47. * $4=$3/2* parameter $4 is half value of parameter $3
  48. * 21,1,$1-$3,$2-$3,0-$1/2-$4,0-$2/2-$4,0*
  49. * For the aperture primitive, parameters $1 to $3 will be defined in ADD command,
  50. * and $4 is defined inside the macro
  51. *
  52. * Each basic shape can be a positive shape or a negative shape.
  53. * a negative shape is "local" to the whole shape.
  54. * It must be seen like a hole in the shape, and not like a standard negative object.
  55. */
  56. /**
  57. * Support the "aperture macro" defined within standard RS274X.
  58. */
  59. class APERTURE_MACRO
  60. {
  61. public:
  62. /**
  63. * Usually, parameters are defined inside the aperture primitive using immediate mode or
  64. * deferred mode.
  65. *
  66. * In deferred mode the value is defined in a DCODE that want to use the aperture macro.
  67. * Some parameters are defined outside the aperture primitive and are local to the aperture
  68. * macro.
  69. *
  70. * @return the value of a deferred parameter defined inside the aperture macro.
  71. * @param aDcode is the D_CODE that uses this aperture macro and define deferred parameters.
  72. * @param aParamId is the param id (defined by $3 or $5 ..) to evaluate.
  73. */
  74. double GetLocalParam( const D_CODE* aDcode, unsigned aParamId ) const;
  75. /**
  76. * Calculate the primitive shape for flashed items.
  77. *
  78. * When an item is flashed, this is the shape of the item.
  79. *
  80. * @param aParent is the parent #GERBER_DRAW_ITEM which is actually drawn.
  81. * @return the shape of the item.
  82. */
  83. SHAPE_POLY_SET* GetApertureMacroShape( const GERBER_DRAW_ITEM* aParent,
  84. const VECTOR2I& aShapePos );
  85. /**
  86. * The name of the aperture macro as defined like %AMVB_RECTANGLE* (name is VB_RECTANGLE)
  87. */
  88. wxString m_AmName;
  89. /**
  90. * A sequence of AM_PRIMITIVEs
  91. */
  92. std::vector<AM_PRIMITIVE> m_PrimitivesList;
  93. /* A deferred parameter can be defined in aperture macro,
  94. * but outside aperture primitives. Example
  95. * %AMRECTHERM*
  96. * $4=$3/2* parameter $4 is half value of parameter $3
  97. * m_localparamStack handle a list of local deferred parameters
  98. */
  99. AM_PARAMS m_LocalParamStack;
  100. private:
  101. SHAPE_POLY_SET m_shape; ///< The shape of the item, calculated by GetApertureMacroShape
  102. };
  103. /**
  104. * Used by std:set<APERTURE_MACRO> instantiation which uses APERTURE_MACRO.name as its key.
  105. */
  106. struct APERTURE_MACRO_less_than
  107. {
  108. // a "less than" test on two APERTURE_MACROs (.name wxStrings)
  109. bool operator()( const APERTURE_MACRO& am1, const APERTURE_MACRO& am2 ) const
  110. {
  111. return am1.m_AmName.Cmp( am2.m_AmName ) < 0; // case specific wxString compare
  112. }
  113. };
  114. /**
  115. * A sorted collection of APERTURE_MACROS whose key is the name field in the APERTURE_MACRO.
  116. */
  117. typedef std::set<APERTURE_MACRO, APERTURE_MACRO_less_than> APERTURE_MACRO_SET;
  118. typedef std::pair<APERTURE_MACRO_SET::iterator, bool> APERTURE_MACRO_SET_PAIR;
  119. #endif // ifndef APERTURE_MACRO_H