KiCad PCB EDA Suite
drc_rule.h
Go to the documentation of this file.
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>
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 
42 {
61 };
62 
63 
65 {
66  DRC_DISALLOW_VIAS = (1 << 0),
69  DRC_DISALLOW_TRACKS = (1 << 3),
70  DRC_DISALLOW_PADS = (1 << 4),
71  DRC_DISALLOW_ZONES = (1 << 5),
72  DRC_DISALLOW_TEXTS = (1 << 6),
74  DRC_DISALLOW_HOLES = (1 << 8),
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 );
92 
93 public:
94  bool m_Unary;
95  bool m_Implicit;
96  wxString m_Name;
97  wxString m_LayerSource;
100  std::vector<DRC_CONSTRAINT> m_Constraints;
101 };
102 
103 
105 {
106  public:
108  const wxString& aName = wxEmptyString ) :
109  m_Type( aType ),
110  m_Value(),
111  m_DisallowFlags( 0 ),
112  m_name( aName ),
113  m_parentRule( nullptr )
114  {
115  }
116 
117  bool IsNull() const
118  {
119  return m_Type == NULL_CONSTRAINT;
120  }
121 
122  const MINOPTMAX<int>& GetValue() const { return m_Value; }
123  MINOPTMAX<int>& Value() { return m_Value; }
124 
125  void SetParentRule( DRC_RULE *aParentRule ) { m_parentRule = aParentRule; }
126  DRC_RULE* GetParentRule() const { return m_parentRule; }
127 
128  void SetName( const wxString& aName ) { m_name = aName; }
129 
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:
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
OPT< DRC_CONSTRAINT > FindConstraint(DRC_CONSTRAINT_T aType)
Definition: drc_rule.cpp:53
virtual ~DRC_RULE()
Definition: drc_rule.cpp:40
const DRC_CONSTRAINT * GetConstraint(const BOARD_ITEM *aItem, const BOARD_ITEM *bItem, int aConstraint, PCB_LAYER_ID aLayer, wxString *aRuleName=nullptr)
virtual bool AppliesTo(const BOARD_ITEM *a, const BOARD_ITEM *b=nullptr) const
Definition: drc_rule.h:85
DRC_RULE * m_parentRule
Definition: drc_rule.h:150
DRC_RULE_CONDITION * m_Condition
Definition: drc_rule.h:99
bool m_Implicit
Definition: drc_rule.h:95
DRC_RULE()
Definition: drc_rule.cpp:31
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:80
MINOPTMAX< int > & Value()
Definition: drc_rule.h:123
wxString m_Name
Definition: drc_rule.h:96
DRC_DISALLOW_T
Definition: drc_rule.h:64
wxString GetName() const
Definition: drc_rule.h:130
void SetName(const wxString &aName)
Definition: drc_rule.h:128
DRC_CONSTRAINT_T
Definition: drc_rule.h:41
MINOPTMAX< int > m_Value
Definition: drc_rule.h:145
DRC_RULE * GetParentRule() const
Definition: drc_rule.h:126
LSET is a set of PCB_LAYER_IDs.
Definition: layer_ids.h:502
std::vector< DRC_CONSTRAINT > m_Constraints
Definition: drc_rule.h:100
wxString m_name
Definition: drc_rule.h:149
void SetParentRule(DRC_RULE *aParentRule)
Definition: drc_rule.h:125
#define _(s)
bool IsNull() const
Definition: drc_rule.h:117
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
wxString m_LayerSource
Definition: drc_rule.h:97
const MINOPTMAX< int > & GetValue() const
Definition: drc_rule.h:122
LSET m_LayerCondition
Definition: drc_rule.h:98
PCB_LAYER_ID
A quick note on layer IDs:
Definition: layer_ids.h:64
void AddConstraint(DRC_CONSTRAINT &aConstraint)
Definition: drc_rule.cpp:46
int m_DisallowFlags
Definition: drc_rule.h:146
boost::optional< T > OPT
Definition: optional.h:7
bool m_Unary
Definition: drc_rule.h:94
DRC_CONSTRAINT(DRC_CONSTRAINT_T aType=NULL_CONSTRAINT, const wxString &aName=wxEmptyString)
Definition: drc_rule.h:107
DRC_CONSTRAINT_T m_Type
Definition: drc_rule.h:144