KiCad PCB EDA Suite
drc_erc_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 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 
25 /******************************************************************/
26 /* class_drc_erc_item.cpp - DRC_ITEM class functions for eeschema */
27 /******************************************************************/
28 #include <fctsys.h>
29 #include <common.h>
30 
31 #include <drc_item.h>
32 #include <erc.h>
33 #include <base_units.h>
34 
35 wxString DRC_ITEM::GetErrorText() const
36 {
37  switch( m_ErrorCode )
38  {
39  case ERCE_UNSPECIFIED:
40  return wxString( _("ERC err unspecified") );
42  return wxString( _("Duplicate sheet names within a given sheet") );
44  return wxString( _("Pin not connected (use a \"no connection\" flag to suppress this error)") );
46  return wxString( _("Pin connected to some others pins but no pin to drive it") );
48  return wxString( _("Conflict problem between pins. Severity: warning") );
50  return wxString( _("Conflict problem between pins. Severity: error") );
52  return wxString( _("Mismatch between hierarchical labels and pins sheets"));
54  return wxString( _("A pin with a \"no connection\" flag is connected"));
55  case ERCE_GLOBLABEL:
56  return wxString( _("Global label not connected to any other global label") );
58  return wxString( _("Labels are similar (lower/upper case difference only)") );
60  return wxString( _("Global labels are similar (lower/upper case difference only)") );
62  return wxString( _("Different footprint assigned in another unit of the same component") );
64  return wxString( _("Different net assigned to a shared pin in another unit of the same component" ) );
65 
66  default:
67  wxFAIL_MSG( "Missing ERC error description" );
68  return wxString( wxT("Unknown.") );
69  }
70 }
71 
72 wxString DRC_ITEM::ShowCoord( EDA_UNITS_T aUnits, const wxPoint& aPos )
73 {
74  return wxString::Format( "@(%s, %s)",
75  MessageTextFromValue( aUnits, aPos.x ),
76  MessageTextFromValue( aUnits, aPos.y ) );
77 }
78 
79 
80 wxString DRC_ITEM::ShowHtml( EDA_UNITS_T aUnits ) const
81 {
82  wxString mainText = m_MainText;
83  // a wxHtmlWindows does not like < and > in the text to display
84  // because these chars have a special meaning in html
85  mainText.Replace( wxT("<"), wxT("&lt;") );
86  mainText.Replace( wxT(">"), wxT("&gt;") );
87 
88  wxString errText = GetErrorText();
89  errText.Replace( wxT("<"), wxT("&lt;") );
90  errText.Replace( wxT(">"), wxT("&gt;") );
91 
92  wxColour hrefColour = wxSystemSettings::GetColour( wxSYS_COLOUR_HOTLIGHT );
93 
94  if( m_noCoordinate )
95  {
96  // omit the coordinate, a NETCLASS has no location
97  return wxString::Format( "<p><b>%s</b><br>&nbsp;&nbsp; %s", errText, mainText );
98  }
99  else if( m_hasSecondItem )
100  {
101  wxString auxText = m_AuxiliaryText;
102  auxText.Replace( wxT("<"), wxT("&lt;") );
103  auxText.Replace( wxT(">"), wxT("&gt;") );
104 
105  // an html fragment for the entire message in the listbox. feel free
106  // to add color if you want:
107  return wxString::Format( "<p><b>%s</b><br>&nbsp;&nbsp; <font color='%s'><a href=''>%s</a></font>: %s<br>&nbsp;&nbsp; %s: %s",
108  errText,
109  hrefColour.GetAsString( wxC2S_HTML_SYNTAX ),
110  ShowCoord( aUnits, m_MainPosition ),
111  mainText,
112  ShowCoord( aUnits, m_AuxiliaryPosition ),
113  auxText );
114  }
115  else
116  {
117  return wxString::Format( "<p><b>%s</b><br>&nbsp;&nbsp; <font color='%s'><a href=''>%s</a></font>: %s",
118  errText,
119  hrefColour.GetAsString( wxC2S_HTML_SYNTAX ),
120  ShowCoord( aUnits, m_MainPosition ),
121  mainText );
122  }
123 }
124 
125 
126 wxString DRC_ITEM::ShowReport( EDA_UNITS_T aUnits ) const
127 {
128  if( m_hasSecondItem )
129  {
130  return wxString::Format( wxT( "ErrType(%d): %s\n %s: %s\n %s: %s\n" ),
131  m_ErrorCode,
132  GetErrorText(),
133  ShowCoord( aUnits, m_MainPosition ),
134  m_MainText,
135  ShowCoord( aUnits, m_AuxiliaryPosition ),
136  m_AuxiliaryText );
137  }
138  else
139  {
140  return wxString::Format( wxT( "ErrType(%d): %s\n %s: %s\n" ),
141  m_ErrorCode,
142  GetErrorText(),
143  ShowCoord( aUnits, m_MainPosition ),
144  m_MainText );
145  }
146 }
147 
148 
#define ERCE_SIMILAR_LABELS
Definition: erc.h:61
#define ERCE_HIERACHICAL_LABEL
Definition: erc.h:58
Implementation of conversion functions that require both schematic and board internal units...
wxString GetErrorText() const
Function GetErrorText returns the string form of a drc error code.
Definition: drc_item.cpp:36
bool m_hasSecondItem
Definition: drc_item.h:56
#define ERCE_PIN_NOT_DRIVEN
Definition: erc.h:55
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
wxPoint m_MainPosition
Definition: drc_item.h:54
#define ERCE_PIN_NOT_CONNECTED
Definition: erc.h:54
wxPoint m_AuxiliaryPosition
Definition: drc_item.h:55
#define ERCE_DIFFERENT_UNIT_NET
Definition: erc.h:65
wxString MessageTextFromValue(EDA_UNITS_T aUnits, int aValue, bool aUseMils)
Definition: base_units.cpp:125
#define ERCE_SIMILAR_GLBL_LABELS
Definition: erc.h:62
#define ERCE_GLOBLABEL
Definition: erc.h:60
wxString m_MainText
Definition: drc_item.h:52
#define ERCE_DUPLICATE_SHEET_NAME
Definition: erc.h:53
#define ERCE_DIFFERENT_UNIT_FP
Definition: erc.h:63
#define ERCE_PIN_TO_PIN_ERROR
Definition: erc.h:57
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
bool m_noCoordinate
Definition: drc_item.h:57
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
The common library.
#define ERCE_NOCONNECT_CONNECTED
Definition: erc.h:59
#define ERCE_PIN_TO_PIN_WARNING
Definition: erc.h:56
#define ERCE_UNSPECIFIED
DRC error codes:
Definition: erc.h:52
wxString m_AuxiliaryText
Definition: drc_item.h:53
int m_ErrorCode
Definition: drc_item.h:51
EDA_UNITS_T
Definition: common.h:159