KiCad PCB EDA Suite
drc_item.cpp
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) 2007 Dick Hollenbeck, dick@softplc.com
5  * Copyright (C) 2015-2018 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 
26 #include <fctsys.h>
27 #include <common.h>
28 
29 #include <pcbnew.h>
30 #include <drc.h>
31 #include <drc_item.h>
32 #include <class_board.h>
33 #include <base_units.h>
34 
35 
36 wxString DRC_ITEM::GetErrorText() const
37 {
38  switch( m_ErrorCode )
39  {
41  return wxString( _( "Unconnected items" ) );
43  return wxString( _( "Track too close to thru-hole" ) );
45  return wxString( _( "Track too close to pad" ) );
47  return wxString( _( "Track too close to via" ) );
48  case DRCE_VIA_NEAR_VIA:
49  return wxString( _( "Via too close to via" ) );
51  return wxString( _( "Via too close to track" ) );
52  case DRCE_TRACK_ENDS1:
53  case DRCE_TRACK_ENDS2:
54  case DRCE_TRACK_ENDS3:
55  case DRCE_TRACK_ENDS4:
56  case DRCE_ENDS_PROBLEM1:
57  case DRCE_ENDS_PROBLEM2:
58  case DRCE_ENDS_PROBLEM3:
59  case DRCE_ENDS_PROBLEM4:
60  case DRCE_ENDS_PROBLEM5:
61  return wxString( _( "Two track ends too close" ) );
63  return wxString( _( "Two parallel track segments too close" ) );
65  return wxString( _( "Tracks crossing" ) );
67  return wxString( _( "Track too close to copper area" ) );
68  case DRCE_PAD_NEAR_PAD1:
69  return wxString( _( "Pad too close to pad" ) );
71  return wxString( _( "Via hole > diameter" ) );
73  return wxString( _( "Micro Via: incorrect layer pairs (not adjacent)" ) );
75  return wxString( _( "Micro Via: not allowed" ) );
77  return wxString( _( "Buried Via: not allowed" ) );
79  return wxString( _( "Item on a disabled layer" ) );
81  return wxString( _( "Copper area inside copper area" ) );
83  return wxString( _( "Copper areas intersect or are too close" ) );
84 
86  return wxString( _( "Copper area belongs to a net which has no pads" ) );
87 
88  case DRCE_HOLE_NEAR_PAD:
89  return wxString( _( "Hole too close to pad" ) );
91  return wxString( _( "Hole too close to track" ) );
93  return wxString( _( "Track width too small" ) );
94  case DRCE_TOO_SMALL_VIA:
95  return wxString( _( "Via size too small" ) );
97  return wxString( _( "Micro via size too small" ) );
99  return wxString( _( "Via drill too small" ) );
101  return wxString( _( "Micro via drill too small" ) );
103  return wxString( _( "Drilled holes too close together" ) );
105  return wxString( _( "Track too close to board edge" ) );
107  return wxString( _( "Board outline does not form a closed polygon" ) );
108 
109  // use &lt; since this is text ultimately embedded in HTML
111  return wxString( _( "NetClass Track Width &lt; global limit" ) );
113  return wxString( _( "NetClass Clearance &lt; global limit" ) );
115  return wxString( _( "NetClass Via Dia &lt; global limit" ) );
117  return wxString( _( "NetClass Via Drill &lt; global limit" ) );
119  return wxString( _( "NetClass uVia Dia &lt; global limit" ) );
121  return wxString( _( "NetClass uVia Drill &lt; global limit" ) );
122 
124  return wxString( _( "Via inside keepout area" ) );
126  return wxString( _( "Track inside keepout area" ) );
128  return wxString( _( "Pad inside keepout area" ) );
129 
131  return wxString( _( "Via too close to copper item" ) );
133  return wxString( _( "Track too close to copper item" ) );
135  return wxString( _( "Pad too close to copper item" ) );
136 
138  return wxString( _( "Courtyards overlap" ) );
139 
141  return wxString( _( "Footprint has no courtyard defined" ) );
142 
144  return wxString( _( "Footprint has incorrect courtyard (not a closed shape)" ) );
145 
146  default:
147  return wxString::Format( _( "Unknown DRC error code %d" ), m_ErrorCode );
148  }
149 }
150 
151 
152 wxString DRC_ITEM::ShowCoord( EDA_UNITS_T aUnits, const wxPoint& aPos )
153 {
154  return wxString::Format( wxT( "@(%s, %s)" ),
155  MessageTextFromValue( aUnits, aPos.x ),
156  MessageTextFromValue( aUnits, aPos.y ) );
157 }
158 
159 
160 wxString DRC_ITEM::ShowHtml( EDA_UNITS_T aUnits ) const
161 {
162  wxString mainText = m_MainText;
163  // a wxHtmlWindows does not like < and > in the text to display
164  // because these chars have a special meaning in html
165  mainText.Replace( wxT("<"), wxT("&lt;") );
166  mainText.Replace( wxT(">"), wxT("&gt;") );
167 
168  wxString errText = GetErrorText();
169  errText.Replace( wxT("<"), wxT("&lt;") );
170  errText.Replace( wxT(">"), wxT("&gt;") );
171 
172 
173  if( m_noCoordinate )
174  {
175  // omit the coordinate, a NETCLASS has no location
176  return wxString::Format( wxT( "<b>%s</b><br>&nbsp;&nbsp; %s" ),
177  errText,
178  mainText );
179  }
180  else if( m_hasSecondItem )
181  {
182  wxString auxText = m_AuxiliaryText;
183  auxText.Replace( wxT("<"), wxT("&lt;") );
184  auxText.Replace( wxT(">"), wxT("&gt;") );
185 
186  // an html fragment for the entire message in the listbox. feel free
187  // to add color if you want:
188  return wxString::Format( wxT( "<b>%s</b><br>&nbsp;&nbsp; %s: %s<br>&nbsp;&nbsp; %s: %s" ),
189  errText,
190  ShowCoord( aUnits, m_MainPosition ),
191  mainText,
192  ShowCoord( aUnits, m_AuxiliaryPosition ),
193  auxText );
194  }
195  else
196  {
197  return wxString::Format( wxT( "<b>%s</b><br>&nbsp;&nbsp; %s: %s" ),
198  errText,
199  ShowCoord( aUnits, m_MainPosition ),
200  mainText );
201  }
202 }
203 
204 
205 wxString DRC_ITEM::ShowReport( EDA_UNITS_T aUnits ) const
206 {
207  if( m_hasSecondItem )
208  {
209  return wxString::Format( wxT( "ErrType(%d): %s\n %s: %s\n %s: %s\n" ),
210  m_ErrorCode,
211  GetErrorText(),
212  ShowCoord( aUnits, m_MainPosition ),
213  m_MainText,
214  ShowCoord( aUnits, m_AuxiliaryPosition ),
215  m_AuxiliaryText );
216  }
217  else
218  {
219  return wxString::Format( wxT( "ErrType(%d): %s\n %s: %s\n" ),
220  m_ErrorCode,
221  GetErrorText(),
222  ShowCoord( aUnits, m_MainPosition ),
223  m_MainText );
224  }
225 }
226 
227 
229 {
230  return aBoard->GetItem( m_mainItemWeakRef );
231 }
232 
233 
235 {
236  return aBoard->GetItem( m_auxItemWeakRef );
237 }
238 
#define DRCE_DISABLED_LAYER_ITEM
item on a disabled layer
Definition: drc.h:96
#define DRCE_TOO_SMALL_MICROVIA_DRILL
Too small micro via drill.
Definition: drc.h:76
#define DRCE_TOO_SMALL_VIA
Too small via size.
Definition: drc.h:73
BOARD_ITEM * GetAuxiliaryItem(BOARD *aBoard) const
Definition: drc_item.cpp:234
#define DRCE_PAD_NEAR_PAD1
pad too close to pad
Definition: drc.h:64
BOARD_ITEM * GetMainItem(BOARD *aBoard) const
Access to A and B items for BOARDs.
Definition: drc_item.cpp:228
Implementation of conversion functions that require both schematic and board internal units...
Class BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class...
wxString GetErrorText() const
Function GetErrorText returns the string form of a drc error code.
Definition: drc_item.cpp:36
#define DRCE_NETCLASS_TRACKWIDTH
netclass has TrackWidth < board.m_designSettings->m_TrackMinWidth
Definition: drc.h:77
#define DRCE_HOLE_NEAR_PAD
hole too close to pad
Definition: drc.h:70
bool m_hasSecondItem
Definition: drc_item.h:56
void * m_auxItemWeakRef
Definition: drc_item.h:61
Class BOARD to handle a board.
#define DRCE_TRACK_ENDS4
2 parallel track segments too close: fine end point test
Definition: drc.h:56
#define DRCE_DRILLED_HOLES_TOO_CLOSE
overlapping drilled holes break drill bits
Definition: drc.h:97
wxString ShowReport(EDA_UNITS_T aUnits) const
Function ShowReport translates this object into a text string suitable for saving to disk in a report...
Definition: drc_item.cpp:205
#define DRCE_VIA_INSIDE_KEEPOUT
Via in inside a keepout area.
Definition: drc.h:83
#define DRCE_TRACK_NEAR_PAD
pad too close to track
Definition: drc.h:49
wxPoint m_MainPosition
Definition: drc_item.h:54
#define DRCE_NETCLASS_CLEARANCE
netclass has Clearance < board.m_designSettings->m_TrackClearance
Definition: drc.h:78
wxPoint m_AuxiliaryPosition
Definition: drc_item.h:55
#define DRCE_ZONES_INTERSECT
copper area outlines intersect
Definition: drc.h:67
#define DRCE_VIA_NEAR_COPPER
via and copper graphic collide or are too close
Definition: drc.h:87
#define DRCE_UNCONNECTED_ITEMS
items are unconnected
Definition: drc.h:47
#define DRCE_TRACK_ENDS2
2 parallel track segments too close: fine start point test
Definition: drc.h:54
#define DRCE_SUSPICIOUS_NET_FOR_ZONE_OUTLINE
copper area has a net but no pads in nets, which is suspicious
Definition: drc.h:69
#define DRCE_MALFORMED_COURTYARD_IN_FOOTPRINT
footprint has a courtyard but malformed
Definition: drc.h:92
#define DRCE_TRACK_SEGMENTS_TOO_CLOSE
2 parallel track segments too close: segm ends between segref ends
Definition: drc.h:57
#define DRCE_MISSING_COURTYARD_IN_FOOTPRINT
footprint has no courtyard defined
Definition: drc.h:91
#define DRCE_BURIED_VIA_NOT_ALLOWED
buried vias are not allowed
Definition: drc.h:95
#define DRCE_TRACK_NEAR_VIA
track too close to via
Definition: drc.h:50
void * m_mainItemWeakRef
Definition: drc_item.h:60
#define DRCE_TOO_SMALL_MICROVIA
Too small micro via size.
Definition: drc.h:74
#define DRCE_PAD_INSIDE_KEEPOUT
Pad in inside a keepout area.
Definition: drc.h:85
wxString MessageTextFromValue(EDA_UNITS_T aUnits, int aValue, bool aUseMils)
Definition: base_units.cpp:125
#define DRCE_VIA_HOLE_BIGGER
via&#39;s hole is bigger than its diameter
Definition: drc.h:65
#define DRCE_TRACK_NEAR_COPPER
track & copper graphic collide or are too close
Definition: drc.h:86
#define DRCE_NETCLASS_uVIADRILLSIZE
netclass has ViaSize < board.m_designSettings->m_MicroViasMinDrill
Definition: drc.h:82
#define DRCE_NETCLASS_VIASIZE
netclass has ViaSize < board.m_designSettings->m_ViasMinSize
Definition: drc.h:79
wxString m_MainText
Definition: drc_item.h:52
#define DRCE_MICRO_VIA_INCORRECT_LAYER_PAIR
micro via&#39;s layer pair incorrect (layers must be adjacent)
Definition: drc.h:66
#define DRCE_TRACK_ENDS1
2 parallel track segments too close: fine start point test
Definition: drc.h:53
#define DRCE_TRACK_ENDS3
2 parallel track segments too close: fine end point test
Definition: drc.h:55
#define DRCE_ENDS_PROBLEM2
track ends are too close
Definition: drc.h:60
#define DRCE_TRACK_NEAR_ZONE
track & zone collide or are too close together
Definition: drc.h:89
#define DRCE_ENDS_PROBLEM3
track ends are too close
Definition: drc.h:61
#define DRCE_INVALID_OUTLINE
invalid board outline
Definition: drc.h:99
#define DRCE_OVERLAPPING_FOOTPRINTS
footprint courtyards overlap
Definition: drc.h:90
#define DRCE_NETCLASS_VIADRILLSIZE
netclass has ViaDrillSize < board.m_designSettings->m_ViasMinDrill
Definition: drc.h:80
#define DRCE_HOLE_NEAR_TRACK
hole too close to track
Definition: drc.h:71
static wxString ShowCoord(EDA_UNITS_T aUnits, const wxPoint &aPos)
Function ShowCoord formats a coordinate or position to text.
Definition: drc_item.cpp:152
wxString ShowHtml(EDA_UNITS_T aUnits) const
Function ShowHtml translates this object into a fragment of HTML suitable for the wxWidget&#39;s wxHtmlLi...
Definition: drc_item.cpp:160
#define DRCE_ENDS_PROBLEM4
track ends are too close
Definition: drc.h:62
#define DRCE_VIA_NEAR_VIA
via too close to via
Definition: drc.h:51
#define DRCE_TRACKS_CROSSING
tracks are crossing
Definition: drc.h:58
bool m_noCoordinate
Definition: drc_item.h:57
#define DRCE_ENDS_PROBLEM5
track ends are too close
Definition: drc.h:63
BOARD_ITEM * GetItem(void *aWeakReference)
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
Class BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:171
#define DRCE_TRACK_INSIDE_KEEPOUT
Track in inside a keepout area.
Definition: drc.h:84
#define DRCE_VIA_NEAR_TRACK
via too close to track
Definition: drc.h:52
#define DRCE_ZONES_TOO_CLOSE
copper area outlines are too close
Definition: drc.h:68
#define DRCE_PAD_NEAR_COPPER
pad and copper graphic collide or are too close
Definition: drc.h:88
The common library.
#define DRCE_TRACK_NEAR_EDGE
track too close to board edge
Definition: drc.h:98
#define DRCE_MICRO_VIA_NOT_ALLOWED
micro vias are not allowed
Definition: drc.h:94
wxString m_AuxiliaryText
Definition: drc_item.h:53
#define DRCE_ENDS_PROBLEM1
track ends are too close
Definition: drc.h:59
#define DRCE_NETCLASS_uVIASIZE
netclass has ViaSize < board.m_designSettings->m_MicroViasMinSize
Definition: drc.h:81
#define DRCE_TOO_SMALL_VIA_DRILL
Too small via drill.
Definition: drc.h:75
int m_ErrorCode
Definition: drc_item.h:51
#define DRCE_TRACK_NEAR_THROUGH_HOLE
thru hole is too close to track
Definition: drc.h:48
EDA_UNITS_T
Definition: common.h:160
#define DRCE_TOO_SMALL_TRACK_WIDTH
Too small track width.
Definition: drc.h:72