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.

167 lines
4.8 KiB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2020 KiCad Developers, see change_log.txt for contributors.
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License
  8. * as published by the Free Software Foundation; either version 2
  9. * of the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, you may find one here:
  18. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  19. * or you may search the http://www.gnu.org website for the version 2 license,
  20. * or you may write to the Free Software Foundation, Inc.,
  21. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  22. */
  23. #ifndef DRC_RULE_PROTO_H
  24. #define DRC_RULE_PROTO_H
  25. #include <core/typeinfo.h>
  26. #include <layers_id_colors_and_visibility.h>
  27. #include <netclass.h>
  28. #include <libeval_compiler/libeval_compiler.h>
  29. class BOARD_ITEM;
  30. class PCB_EXPR_UCODE;
  31. class DRC_CONSTRAINT;
  32. class DRC_RULE_CONDITION;
  33. enum DRC_CONSTRAINT_TYPE_T
  34. {
  35. DRC_CONSTRAINT_TYPE_UNKNOWN = -1,
  36. DRC_CONSTRAINT_TYPE_CLEARANCE = 0,
  37. DRC_CONSTRAINT_TYPE_HOLE_CLEARANCE,
  38. DRC_CONSTRAINT_TYPE_EDGE_CLEARANCE,
  39. DRC_CONSTRAINT_TYPE_HOLE_SIZE,
  40. DRC_CONSTRAINT_TYPE_COURTYARD_CLEARANCE,
  41. DRC_CONSTRAINT_TYPE_SILK_TO_PAD,
  42. DRC_CONSTRAINT_TYPE_SILK_TO_SILK,
  43. DRC_CONSTRAINT_TYPE_TRACK_WIDTH,
  44. DRC_CONSTRAINT_TYPE_ANNULUS_WIDTH,
  45. DRC_CONSTRAINT_TYPE_DISALLOW,
  46. DRC_CONSTRAINT_TYPE_VIA_DIAMETER
  47. };
  48. enum DRC_DISALLOW_T
  49. {
  50. DRC_DISALLOW_VIAS = (1 << 0),
  51. DRC_DISALLOW_MICRO_VIAS = (1 << 1),
  52. DRC_DISALLOW_BB_VIAS = (1 << 2),
  53. DRC_DISALLOW_TRACKS = (1 << 3),
  54. DRC_DISALLOW_PADS = (1 << 4),
  55. DRC_DISALLOW_ZONES = (1 << 5),
  56. DRC_DISALLOW_TEXTS = (1 << 6),
  57. DRC_DISALLOW_GRAPHICS = (1 << 7),
  58. DRC_DISALLOW_HOLES = (1 << 8),
  59. DRC_DISALLOW_FOOTPRINTS = (1 << 9)
  60. };
  61. template<class T=int>
  62. class MINOPTMAX
  63. {
  64. public:
  65. T Min() const { assert( m_hasMin ); return m_min; };
  66. T Max() const { assert( m_hasMax ); return m_max; };
  67. T Opt() const { assert( m_hasOpt ); return m_opt; };
  68. bool HasMin() const { return m_hasMin; }
  69. bool HasMax() const { return m_hasMax; }
  70. bool HasOpt() const { return m_hasOpt; }
  71. void SetMin( T v ) { m_min = v; m_hasMin = true; }
  72. void SetMax( T v ) { m_max = v; m_hasMax = true; }
  73. void SetOpt( T v ) { m_opt = v; m_hasOpt = true; }
  74. private:
  75. T m_min;
  76. T m_opt;
  77. T m_max;
  78. bool m_hasMin = false;
  79. bool m_hasOpt = false;
  80. bool m_hasMax = false;
  81. };
  82. class DRC_RULE
  83. {
  84. public:
  85. DRC_RULE();
  86. virtual ~DRC_RULE();
  87. virtual bool AppliesTo( const BOARD_ITEM* a, const BOARD_ITEM* b = nullptr ) const
  88. {
  89. return true;
  90. };
  91. void AddConstraint( DRC_CONSTRAINT& aConstraint );
  92. public:
  93. bool m_Unary;
  94. bool m_Implicit;
  95. wxString m_Name;
  96. wxString m_LayerSource;
  97. LSET m_LayerCondition;
  98. DRC_RULE_CONDITION* m_Condition;
  99. std::vector<DRC_CONSTRAINT> m_Constraints;
  100. };
  101. class DRC_CONSTRAINT
  102. {
  103. public:
  104. DRC_CONSTRAINT( DRC_CONSTRAINT_TYPE_T aType = DRC_CONSTRAINT_TYPE_UNKNOWN,
  105. const wxString& aName = wxEmptyString ) :
  106. m_Type( aType ),
  107. m_DisallowFlags( 0 ),
  108. m_name( aName ),
  109. m_parentRule( nullptr )
  110. {
  111. }
  112. const MINOPTMAX<int>& GetValue() const { return m_Value; }
  113. MINOPTMAX<int>& Value() { return m_Value; }
  114. void SetParentRule( DRC_RULE *aParentRule ) { m_parentRule = aParentRule; }
  115. DRC_RULE* GetParentRule() const { return m_parentRule; }
  116. wxString GetName() const
  117. {
  118. if( m_parentRule )
  119. {
  120. if( m_parentRule->m_Implicit )
  121. return m_parentRule->m_Name;
  122. else
  123. return wxString::Format( _( "rule %s" ), m_parentRule->m_Name );
  124. }
  125. return m_name;
  126. }
  127. public:
  128. DRC_CONSTRAINT_TYPE_T m_Type;
  129. MINOPTMAX<int> m_Value;
  130. int m_DisallowFlags;
  131. private:
  132. wxString m_name; // For just-in-time constraints
  133. DRC_RULE* m_parentRule; // For constraints found in rules
  134. };
  135. const DRC_CONSTRAINT* GetConstraint( const BOARD_ITEM* aItem, const BOARD_ITEM* bItem,
  136. int aConstraint, PCB_LAYER_ID aLayer,
  137. wxString* aRuleName = nullptr );
  138. #endif // DRC_RULE_H