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 <tools/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 
147  return wxString( _( "Duplicate footprints" ) );
149  return wxString( _( "Missing footprint" ) );
151  return wxString( _( "Extra footprint" ) );
152 
153  case DRCE_SHORT:
154  return wxString( _( "Remove track shorting two nets" ) );
155  case DRCE_REDUNDANT_VIA:
156  return wxString( _( "Remove redundant via" ) );
158  return wxString( _( "Remove duplicate track" ) );
159  case DRCE_MERGE_TRACKS:
160  return wxString( _( "Merge co-linear tracks" ) );
161  case DRCE_DANGLING_TRACK:
162  return wxString( _( "Remove dangling track" ) );
163  case DRCE_DANGLING_VIA:
164  return wxString( _( "Remove dangling via" ) );
166  return wxString( _( "Remove zero-length track" ) );
167  case DRCE_TRACK_IN_PAD:
168  return wxString( _( "Remove track inside pad" ) );
169 
170  default:
171  return wxString::Format( _( "Unknown DRC error code %d" ), m_ErrorCode );
172  }
173 }
174 
175 
176 wxString DRC_ITEM::ShowCoord( EDA_UNITS_T aUnits, const wxPoint& aPos )
177 {
178  return wxString::Format( wxT( "@(%s, %s)" ),
179  MessageTextFromValue( aUnits, aPos.x ),
180  MessageTextFromValue( aUnits, aPos.y ) );
181 }
182 
183 
184 wxString DRC_ITEM::ShowHtml( EDA_UNITS_T aUnits ) const
185 {
186  wxString mainText = m_MainText;
187  // a wxHtmlWindows does not like < and > in the text to display
188  // because these chars have a special meaning in html
189  mainText.Replace( wxT("<"), wxT("&lt;") );
190  mainText.Replace( wxT(">"), wxT("&gt;") );
191 
192  wxString errText = GetErrorText();
193  errText.Replace( wxT("<"), wxT("&lt;") );
194  errText.Replace( wxT(">"), wxT("&gt;") );
195 
196 
197  if( m_noCoordinate )
198  {
199  // omit the coordinate, a NETCLASS has no location
200  return wxString::Format( wxT( "<b>%s</b><br>&nbsp;&nbsp; %s" ),
201  errText,
202  mainText );
203  }
204  else if( m_hasSecondItem )
205  {
206  wxString auxText = m_AuxiliaryText;
207  auxText.Replace( wxT("<"), wxT("&lt;") );
208  auxText.Replace( wxT(">"), wxT("&gt;") );
209 
210  // an html fragment for the entire message in the listbox. feel free
211  // to add color if you want:
212  return wxString::Format( wxT( "<b>%s</b><br>&nbsp;&nbsp; %s: %s<br>&nbsp;&nbsp; %s: %s" ),
213  errText,
214  ShowCoord( aUnits, m_MainPosition ),
215  mainText,
216  ShowCoord( aUnits, m_AuxiliaryPosition ),
217  auxText );
218  }
219  else
220  {
221  return wxString::Format( wxT( "<b>%s</b><br>&nbsp;&nbsp; %s: %s" ),
222  errText,
223  ShowCoord( aUnits, m_MainPosition ),
224  mainText );
225  }
226 }
227 
228 
229 wxString DRC_ITEM::ShowReport( EDA_UNITS_T aUnits ) const
230 {
231  if( m_hasSecondItem )
232  {
233  return wxString::Format( wxT( "ErrType(%d): %s\n %s: %s\n %s: %s\n" ),
234  m_ErrorCode,
235  GetErrorText(),
236  ShowCoord( aUnits, m_MainPosition ),
237  m_MainText,
238  ShowCoord( aUnits, m_AuxiliaryPosition ),
239  m_AuxiliaryText );
240  }
241  else
242  {
243  return wxString::Format( wxT( "ErrType(%d): %s\n %s: %s\n" ),
244  m_ErrorCode,
245  GetErrorText(),
246  ShowCoord( aUnits, m_MainPosition ),
247  m_MainText );
248  }
249 }
250 
251 
253 {
254  return aBoard->GetItem( m_mainItemWeakRef );
255 }
256 
257 
259 {
260  return aBoard->GetItem( m_auxItemWeakRef );
261 }
262 
#define DRCE_EXTRA_FOOTPRINT
netlist item not found for footprint
Definition: drc.h:102
#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
wxString GetErrorText() const
Function GetErrorText returns the string form of a drc error code.
Definition: drc_item.cpp:36
#define DRCE_MERGE_TRACKS
Definition: drc.h:107
#define DRCE_PAD_NEAR_PAD1
pad too close to pad
Definition: drc.h:64
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,...
#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
#define DRCE_DANGLING_VIA
Definition: drc.h:109
#define DRCE_DUPLICATE_TRACK
Definition: drc.h:106
#define DRCE_SHORT
Definition: drc.h:104
void * m_auxItemWeakRef
Definition: drc_item.h:61
BOARD_ITEM * GetAuxiliaryItem(BOARD *aBoard) const
Definition: drc_item.cpp:258
#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
#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
#define DRCE_MISSING_FOOTPRINT
footprint not found for netlist item
Definition: drc.h:100
wxPoint m_MainPosition
Definition: drc_item.h:54
#define DRCE_TRACK_IN_PAD
Definition: drc.h:111
#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'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
#define DRCE_DUPLICATE_FOOTPRINT
more than one footprints found for netlist item
Definition: drc.h:101
#define DRCE_ZERO_LENGTH_TRACK
Definition: drc.h:110
wxString m_MainText
Definition: drc_item.h:52
#define DRCE_MICRO_VIA_INCORRECT_LAYER_PAIR
micro via'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
BOARD_ITEM * GetMainItem(BOARD *aBoard) const
Access to A and B items for BOARDs.
Definition: drc_item.cpp:252
#define _(s)
static wxString ShowCoord(EDA_UNITS_T aUnits, const wxPoint &aPos)
Function ShowCoord formats a coordinate or position to text.
Definition: drc_item.cpp:176
#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:161
#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_REDUNDANT_VIA
Definition: drc.h:105
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:229
#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 ShowHtml(EDA_UNITS_T aUnits) const
Function ShowHtml translates this object into a fragment of HTML suitable for the wxWidget's wxHtmlLi...
Definition: drc_item.cpp:184
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:133
#define DRCE_TOO_SMALL_TRACK_WIDTH
Too small track width.
Definition: drc.h:72
#define DRCE_DANGLING_TRACK
Definition: drc.h:108