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 
24 #ifndef DRC_RULE_PROTO_H
25 #define DRC_RULE_PROTO_H
26 
27 #include <core/typeinfo.h>
28 #include <core/optional.h>
29 #include <core/minoptmax.h>
30 #include <layer_ids.h>
31 #include <netclass.h>
32 #include <libeval_compiler/libeval_compiler.h>
33 #include <wx/intl.h>
34 
35 class BOARD_ITEM;
36 class PCB_EXPR_UCODE;
37 class DRC_CONSTRAINT;
38 class DRC_RULE_CONDITION;
39 
40 
41 enum DRC_CONSTRAINT_T
42 {
43     NULL_CONSTRAINT = 0,
44     CLEARANCE_CONSTRAINT,
45     HOLE_CLEARANCE_CONSTRAINT,
46     HOLE_TO_HOLE_CONSTRAINT,
47     EDGE_CLEARANCE_CONSTRAINT,
48     HOLE_SIZE_CONSTRAINT,
49     COURTYARD_CLEARANCE_CONSTRAINT,
50     SILK_CLEARANCE_CONSTRAINT,
51     TRACK_WIDTH_CONSTRAINT,
52     ANNULAR_WIDTH_CONSTRAINT,
53     DISALLOW_CONSTRAINT,
54     VIA_DIAMETER_CONSTRAINT,
55     LENGTH_CONSTRAINT,
56     SKEW_CONSTRAINT,
57     DIFF_PAIR_GAP_CONSTRAINT,
58     DIFF_PAIR_MAX_UNCOUPLED_CONSTRAINT,
59     DIFF_PAIR_INTRA_SKEW_CONSTRAINT,
60     VIA_COUNT_CONSTRAINT
61 };
62 
63 
64 enum DRC_DISALLOW_T
65 {
66     DRC_DISALLOW_VIAS        = (1 << 0),
67     DRC_DISALLOW_MICRO_VIAS  = (1 << 1),
68     DRC_DISALLOW_BB_VIAS     = (1 << 2),
69     DRC_DISALLOW_TRACKS      = (1 << 3),
70     DRC_DISALLOW_PADS        = (1 << 4),
71     DRC_DISALLOW_ZONES       = (1 << 5),
72     DRC_DISALLOW_TEXTS       = (1 << 6),
73     DRC_DISALLOW_GRAPHICS    = (1 << 7),
74     DRC_DISALLOW_HOLES       = (1 << 8),
75     DRC_DISALLOW_FOOTPRINTS  = (1 << 9)
76 };
77 
78 
79 class DRC_RULE
80 {
81 public:
82     DRC_RULE();
83     virtual ~DRC_RULE();
84 
85     virtual bool AppliesTo( const BOARD_ITEM* a, const BOARD_ITEM* b = nullptr ) const
86     {
87         return true;
88     };
89 
90     void AddConstraint( DRC_CONSTRAINT& aConstraint );
91     OPT<DRC_CONSTRAINT> FindConstraint( DRC_CONSTRAINT_T aType );
92 
93 public:
94     bool                        m_Unary;
95     bool                        m_Implicit;
96     wxString                    m_Name;
97     wxString                    m_LayerSource;
98     LSET                        m_LayerCondition;
99     DRC_RULE_CONDITION*         m_Condition;
100     std::vector<DRC_CONSTRAINT> m_Constraints;
101 };
102 
103 
104 class DRC_CONSTRAINT
105 {
106     public:
107     DRC_CONSTRAINT( DRC_CONSTRAINT_T aType = NULL_CONSTRAINT,
108                     const wxString& aName = wxEmptyString ) :
m_Type(aType)109             m_Type( aType ),
110             m_Value(),
111             m_DisallowFlags( 0 ),
112             m_name( aName ),
113             m_parentRule( nullptr )
114     {
115     }
116 
IsNull()117     bool IsNull() const
118     {
119         return m_Type == NULL_CONSTRAINT;
120     }
121 
GetValue()122     const MINOPTMAX<int>& GetValue() const { return m_Value; }
Value()123     MINOPTMAX<int>& Value() { return m_Value; }
124 
SetParentRule(DRC_RULE * aParentRule)125     void SetParentRule( DRC_RULE *aParentRule ) { m_parentRule = aParentRule; }
GetParentRule()126     DRC_RULE* GetParentRule() const { return m_parentRule; }
127 
SetName(const wxString & aName)128     void SetName( const wxString& aName ) { m_name = aName; }
129 
GetName()130     wxString GetName() const
131     {
132         if( m_parentRule )
133         {
134             if( m_parentRule->m_Implicit )
135                 return m_parentRule->m_Name;
136             else
137                 return wxString::Format( _( "rule %s" ), m_parentRule->m_Name );
138         }
139 
140         return m_name;
141     }
142 
143 public:
144     DRC_CONSTRAINT_T  m_Type;
145     MINOPTMAX<int>    m_Value;
146     int               m_DisallowFlags;
147 
148 private:
149     wxString          m_name;          // For just-in-time constraints
150     DRC_RULE*         m_parentRule;    // For constraints found in rules
151 };
152 
153 
154 const DRC_CONSTRAINT* GetConstraint( const BOARD_ITEM* aItem, const BOARD_ITEM* bItem,
155                                      int aConstraint, PCB_LAYER_ID aLayer,
156                                      wxString* aRuleName = nullptr );
157 
158 
159 #endif // DRC_RULE_H
160