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" ) );
104 
105  // use &lt; since this is text ultimately embedded in HTML
107  return wxString( _( "NetClass Track Width &lt; global limit" ) );
109  return wxString( _( "NetClass Clearance &lt; global limit" ) );
111  return wxString( _( "NetClass Via Dia &lt; global limit" ) );
113  return wxString( _( "NetClass Via Drill &lt; global limit" ) );
115  return wxString( _( "NetClass uVia Dia &lt; global limit" ) );
117  return wxString( _( "NetClass uVia Drill &lt; global limit" ) );
118 
120  return wxString( _( "Via inside keepout area" ) );
122  return wxString( _( "Track inside keepout area" ) );
124  return wxString( _( "Pad inside keepout area" ) );
125 
127  return wxString( _( "Via too close to copper item" ) );
129  return wxString( _( "Track too close to copper item" ) );
131  return wxString( _( "Pad too close to copper item" ) );
132 
134  return wxString( _( "Courtyards overlap" ) );
135 
137  return wxString( _( "Footprint has no courtyard defined" ) );
138 
140  return wxString( _( "Footprint has incorrect courtyard (not a closed shape)" ) );
141 
142  default:
143  return wxString::Format( _( "Unknown DRC error code %d" ), m_ErrorCode );
144  }
145 }
146 
147 
148 wxString DRC_ITEM::ShowCoord( EDA_UNITS_T aUnits, const wxPoint& aPos )
149 {
150  return wxString::Format( wxT( "@(%s, %s)" ),
151  MessageTextFromValue( aUnits, aPos.x ),
152  MessageTextFromValue( aUnits, aPos.y ) );
153 }
154 
155 
156 wxString DRC_ITEM::ShowHtml( EDA_UNITS_T aUnits ) const
157 {
158  wxString mainText = m_MainText;
159  // a wxHtmlWindows does not like < and > in the text to display
160  // because these chars have a special meaning in html
161  mainText.Replace( wxT("<"), wxT("&lt;") );
162  mainText.Replace( wxT(">"), wxT("&gt;") );
163 
164  wxString errText = GetErrorText();
165  errText.Replace( wxT("<"), wxT("&lt;") );
166  errText.Replace( wxT(">"), wxT("&gt;") );
167 
168 
169  if( m_noCoordinate )
170  {
171  // omit the coordinate, a NETCLASS has no location
172  return wxString::Format( wxT( "<b>%s</b><br>&nbsp;&nbsp; %s" ),
173  errText,
174  mainText );
175  }
176  else if( m_hasSecondItem )
177  {
178  wxString auxText = m_AuxiliaryText;
179  auxText.Replace( wxT("<"), wxT("&lt;") );
180  auxText.Replace( wxT(">"), wxT("&gt;") );
181 
182  // an html fragment for the entire message in the listbox. feel free
183  // to add color if you want:
184  return wxString::Format( wxT( "<b>%s</b><br>&nbsp;&nbsp; %s: %s<br>&nbsp;&nbsp; %s: %s" ),
185  errText,
186  ShowCoord( aUnits, m_MainPosition ),
187  mainText,
188  ShowCoord( aUnits, m_AuxiliaryPosition ),
189  auxText );
190  }
191  else
192  {
193  return wxString::Format( wxT( "<b>%s</b><br>&nbsp;&nbsp; %s: %s" ),
194  errText,
195  ShowCoord( aUnits, m_MainPosition ),
196  mainText );
197  }
198 }
199 
200 
201 wxString DRC_ITEM::ShowReport( EDA_UNITS_T aUnits ) const
202 {
203  if( m_hasSecondItem )
204  {
205  return wxString::Format( wxT( "ErrType(%d): %s\n %s: %s\n %s: %s\n" ),
206  m_ErrorCode,
207  GetErrorText(),
208  ShowCoord( aUnits, m_MainPosition ),
209  m_MainText,
210  ShowCoord( aUnits, m_AuxiliaryPosition ),
211  m_AuxiliaryText );
212  }
213  else
214  {
215  return wxString::Format( wxT( "ErrType(%d): %s\n %s: %s\n" ),
216  m_ErrorCode,
217  GetErrorText(),
218  ShowCoord( aUnits, m_MainPosition ),
219  m_MainText );
220  }
221 }
222 
223 
225 {
226  return aBoard->GetItem( m_mainItemWeakRef );
227 }
228 
229 
231 {
232  return aBoard->GetItem( m_auxItemWeakRef );
233 }
234 
#define DRCE_DISABLED_LAYER_ITEM
item on a disabled layer
Definition: drc.h:95
#define DRCE_TOO_SMALL_MICROVIA_DRILL
Too small micro via drill.
Definition: drc.h:75
#define DRCE_TOO_SMALL_VIA
Too small via size.
Definition: drc.h:72
BOARD_ITEM * GetAuxiliaryItem(BOARD *aBoard) const
Definition: drc_item.cpp:230
#define DRCE_PAD_NEAR_PAD1
pad too close to pad
Definition: drc.h:63
BOARD_ITEM * GetMainItem(BOARD *aBoard) const
Access to A and B items for BOARDs.
Definition: drc_item.cpp:224
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:76
#define DRCE_HOLE_NEAR_PAD
hole too close to pad
Definition: drc.h:69
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:55
#define DRCE_DRILLED_HOLES_TOO_CLOSE
overlapping drilled holes break drill bits
Definition: drc.h:96
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:201
#define DRCE_VIA_INSIDE_KEEPOUT
Via in inside a keepout area.
Definition: drc.h:82
#define DRCE_TRACK_NEAR_PAD
pad too close to track
Definition: drc.h:48
wxPoint m_MainPosition
Definition: drc_item.h:54
#define DRCE_NETCLASS_CLEARANCE
netclass has Clearance < board.m_designSettings->m_TrackClearance
Definition: drc.h:77
wxPoint m_AuxiliaryPosition
Definition: drc_item.h:55
#define DRCE_ZONES_INTERSECT
copper area outlines intersect
Definition: drc.h:66
#define DRCE_VIA_NEAR_COPPER
via and copper graphic collide or are too close
Definition: drc.h:86
#define DRCE_UNCONNECTED_ITEMS
items are unconnected
Definition: drc.h:46
#define DRCE_TRACK_ENDS2
2 parallel track segments too close: fine start point test
Definition: drc.h:53
#define DRCE_SUSPICIOUS_NET_FOR_ZONE_OUTLINE
copper area has a net but no pads in nets, which is suspicious
Definition: drc.h:68
#define DRCE_MALFORMED_COURTYARD_IN_FOOTPRINT
footprint has a courtyard but malformed
Definition: drc.h:91
#define DRCE_TRACK_SEGMENTS_TOO_CLOSE
2 parallel track segments too close: segm ends between segref ends
Definition: drc.h:56
#define DRCE_MISSING_COURTYARD_IN_FOOTPRINT
footprint has no courtyard defined
Definition: drc.h:90
#define DRCE_BURIED_VIA_NOT_ALLOWED
buried vias are not allowed
Definition: drc.h:94
#define DRCE_TRACK_NEAR_VIA
track too close to via
Definition: drc.h:49
void * m_mainItemWeakRef
Definition: drc_item.h:60
#define DRCE_TOO_SMALL_MICROVIA
Too small micro via size.
Definition: drc.h:73
#define DRCE_PAD_INSIDE_KEEPOUT
Pad in inside a keepout area.
Definition: drc.h:84
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:64
#define DRCE_TRACK_NEAR_COPPER
track & copper graphic collide or are too close
Definition: drc.h:85
#define DRCE_NETCLASS_uVIADRILLSIZE
netclass has ViaSize < board.m_designSettings->m_MicroViasMinDrill
Definition: drc.h:81
#define DRCE_NETCLASS_VIASIZE
netclass has ViaSize < board.m_designSettings->m_ViasMinSize
Definition: drc.h:78
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:65
#define DRCE_TRACK_ENDS1
2 parallel track segments too close: fine start point test
Definition: drc.h:52
#define DRCE_TRACK_ENDS3
2 parallel track segments too close: fine end point test
Definition: drc.h:54
#define DRCE_ENDS_PROBLEM2
track ends are too close
Definition: drc.h:59
#define DRCE_TRACK_NEAR_ZONE
track & zone collide or are too close together
Definition: drc.h:88
#define DRCE_ENDS_PROBLEM3
track ends are too close
Definition: drc.h:60
#define DRCE_OVERLAPPING_FOOTPRINTS
footprint courtyards overlap
Definition: drc.h:89
#define DRCE_NETCLASS_VIADRILLSIZE
netclass has ViaDrillSize < board.m_designSettings->m_ViasMinDrill
Definition: drc.h:79
#define DRCE_HOLE_NEAR_TRACK
hole too close to track
Definition: drc.h:70
static wxString ShowCoord(EDA_UNITS_T aUnits, const wxPoint &aPos)
Function ShowCoord formats a coordinate or position to text.
Definition: drc_item.cpp:148
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:156
#define DRCE_ENDS_PROBLEM4
track ends are too close
Definition: drc.h:61
#define DRCE_VIA_NEAR_VIA
via too close to via
Definition: drc.h:50
#define DRCE_TRACKS_CROSSING
tracks are crossing
Definition: drc.h:57
bool m_noCoordinate
Definition: drc_item.h:57
#define DRCE_ENDS_PROBLEM5
track ends are too close
Definition: drc.h:62
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:170
#define DRCE_TRACK_INSIDE_KEEPOUT
Track in inside a keepout area.
Definition: drc.h:83
#define DRCE_VIA_NEAR_TRACK
via too close to track
Definition: drc.h:51
#define DRCE_ZONES_TOO_CLOSE
copper area outlines are too close
Definition: drc.h:67
#define DRCE_PAD_NEAR_COPPER
pad and copper graphic collide or are too close
Definition: drc.h:87
The common library.
#define DRCE_MICRO_VIA_NOT_ALLOWED
micro vias are not allowed
Definition: drc.h:93
wxString m_AuxiliaryText
Definition: drc_item.h:53
#define DRCE_ENDS_PROBLEM1
track ends are too close
Definition: drc.h:58
#define DRCE_NETCLASS_uVIASIZE
netclass has ViaSize < board.m_designSettings->m_MicroViasMinSize
Definition: drc.h:80
#define DRCE_TOO_SMALL_VIA_DRILL
Too small via drill.
Definition: drc.h:74
int m_ErrorCode
Definition: drc_item.h:51
#define DRCE_TRACK_NEAR_THROUGH_HOLE
thru hole is too close to track
Definition: drc.h:47
EDA_UNITS_T
Definition: common.h:159
#define DRCE_TOO_SMALL_TRACK_WIDTH
Too small track width.
Definition: drc.h:71