KiCad PCB EDA Suite
class_drc_item.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) 2007 Dick Hollenbeck, dick@softplc.com
5  * Copyright (C) 2007 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 #ifndef _CLASS_DRC_ITEM_H
26 #define _CLASS_DRC_ITEM_H
27 
28 #include <macros.h>
29 
30 
43 class DRC_ITEM
44 {
45 protected:
47  wxString m_MainText;
48  wxString m_AuxiliaryText;
53 
54 public:
55 
57  {
58  m_ErrorCode = 0;
59  m_hasSecondItem = false;
60  m_noCoordinate = false;
61  }
62 
63  DRC_ITEM( int aErrorCode,
64  const wxString& aMainText, const wxString& bAuxiliaryText,
65  const wxPoint& aMainPos, const wxPoint& bAuxiliaryPos )
66  {
67  SetData( aErrorCode,
68  aMainText, bAuxiliaryText,
69  aMainPos, bAuxiliaryPos );
70  }
71 
72  DRC_ITEM( int aErrorCode,
73  const wxString& aText, const wxPoint& aPos )
74  {
75  SetData( aErrorCode, aText, aPos );
76  }
77 
78 
86  void SetData( int aErrorCode,
87  const wxString& aMainText, const wxPoint& aMainPos )
88  {
89  SetData( aErrorCode,
90  aMainText, aMainText,
91  aMainPos, aMainPos );
92  m_hasSecondItem = false;
93  }
94 
104  void SetData( int aErrorCode,
105  const wxString& aMainText, const wxString& bAuxiliaryText,
106  const wxPoint& aMainPos, const wxPoint& bAuxiliaryPos )
107  {
108  m_ErrorCode = aErrorCode;
109  m_MainText = aMainText;
110  m_AuxiliaryText = bAuxiliaryText;
111  m_MainPosition = aMainPos;
112  m_AuxiliaryPosition = bAuxiliaryPos;
113  m_hasSecondItem = true;
114  m_noCoordinate = false;
115  }
116 
123  void SetAuxiliaryData( const wxString& aAuxiliaryText, const wxPoint& aAuxiliaryPos )
124  {
125  m_AuxiliaryText = aAuxiliaryText;
126  m_AuxiliaryPosition = aAuxiliaryPos;
127  m_hasSecondItem = true;
128  }
129 
130 
131  bool HasSecondItem() const { return m_hasSecondItem; }
132 
133  void SetShowNoCoordinate() { m_noCoordinate = true; }
134 
137  wxString GetMainText() const { return m_MainText; }
138  wxString GetAuxiliaryText() const { return m_AuxiliaryText; }
139 
140 
147  wxString ShowHtml() const
148  {
149  wxString ret;
150  wxString mainText = m_MainText;
151  // a wxHtmlWindows does not like < and > in the text to display
152  // because these chars have a special meaning in html
153  mainText.Replace( wxT("<"), wxT("&lt;") );
154  mainText.Replace( wxT(">"), wxT("&gt;") );
155 
156  wxString errText = GetErrorText();
157  errText.Replace( wxT("<"), wxT("&lt;") );
158  errText.Replace( wxT(">"), wxT("&gt;") );
159 
160 
161  if( m_noCoordinate )
162  {
163  // omit the coordinate, a NETCLASS has no location
164  ret.Printf( _( "ErrType(%d): <b>%s</b><ul><li> %s </li></ul>" ),
165  m_ErrorCode,
166  GetChars( errText ),
167  GetChars( mainText ) );
168  }
169  else if( m_hasSecondItem )
170  {
171  wxString auxText = m_AuxiliaryText;
172  auxText.Replace( wxT("<"), wxT("&lt;") );
173  auxText.Replace( wxT(">"), wxT("&gt;") );
174 
175  // an html fragment for the entire message in the listbox. feel free
176  // to add color if you want:
177  ret.Printf( _( "ErrType(%d): <b>%s</b><ul><li> %s: %s </li><li> %s: %s </li></ul>" ),
178  m_ErrorCode,
179  GetChars( errText ),
180  GetChars( ShowCoord( m_MainPosition )), GetChars( mainText ),
181  GetChars( ShowCoord( m_AuxiliaryPosition )), GetChars( auxText ) );
182  }
183  else
184  {
185  ret.Printf( _( "ErrType(%d): <b>%s</b><ul><li> %s: %s </li></ul>" ),
186  m_ErrorCode,
187  GetChars( errText ),
188  GetChars( ShowCoord( m_MainPosition ) ), GetChars( mainText ) );
189  }
190 
191  return ret;
192  }
193 
194 
201  wxString ShowReport() const
202  {
203  wxString ret;
204 
205  if( m_hasSecondItem )
206  {
207  ret.Printf( wxT( "ErrType(%d): %s\n %s: %s\n %s: %s\n" ),
208  m_ErrorCode,
209  GetChars( GetErrorText() ),
210  GetChars( ShowCoord( m_MainPosition ) ), GetChars( m_MainText ),
211  GetChars( ShowCoord( m_AuxiliaryPosition ) ), GetChars( m_AuxiliaryText ) );
212  }
213  else
214  {
215  ret.Printf( wxT( "ErrType(%d): %s\n %s: %s\n" ),
216  m_ErrorCode,
217  GetChars( GetErrorText() ),
218  GetChars( ShowCoord( m_MainPosition ) ), GetChars( m_MainText ) );
219  }
220 
221  return ret;
222  }
223 
224 
229  int GetErrorCode() const
230  {
231  return m_ErrorCode;
232  }
233 
238  wxString GetErrorText() const;
239 
240  const wxString& GetTextA() const
241  {
242  return m_MainText;
243  }
244 
245 
246  const wxString& GetTextB() const
247  {
248  return m_AuxiliaryText;
249  }
250 
251 
252  const wxPoint& GetPointA() const
253  {
254  return m_MainPosition;
255  }
256 
257 
258  const wxPoint& GetPointB() const
259  {
260  return m_AuxiliaryPosition;
261  }
262 
263 
270  static wxString ShowCoord( const wxPoint& aPos );
271 };
272 
273 
274 #endif // _CLASS_DRC_ITEM_H
Class DRC_ITEM is a holder for a DRC (in Pcbnew) or ERC (in Eeschema) error item. ...
bool HasSecondItem() const
wxString GetErrorText() const
Function GetErrorText returns the string form of a drc error code.
bool m_hasSecondItem
true when 2 items create a DRC/ERC error, false if only one item
int GetErrorCode() const
Function GetErrorCode returns the error code.
void SetAuxiliaryData(const wxString &aAuxiliaryText, const wxPoint &aAuxiliaryPos)
Function SetAuxiliaryData initialize data for the second (auxiliary) item.
wxString ShowReport() const
Function ShowReport translates this object into a text string suitable for saving to disk in a report...
void SetData(int aErrorCode, const wxString &aMainText, const wxString &bAuxiliaryText, const wxPoint &aMainPos, const wxPoint &bAuxiliaryPos)
Function SetData initialize all data in item.
wxString GetMainText() const
acces to A and B texts
const wxPoint & GetPointB() const
wxPoint m_MainPosition
the location of the first (or main ) BOARD_ITEM or SCH_ITEM. This is also the position of the marker ...
wxPoint m_AuxiliaryPosition
the location of the second BOARD_ITEM or SCH_ITEM
DRC_ITEM(int aErrorCode, const wxString &aText, const wxPoint &aPos)
This file contains miscellaneous commonly used macros and functions.
DRC_ITEM(int aErrorCode, const wxString &aMainText, const wxString &bAuxiliaryText, const wxPoint &aMainPos, const wxPoint &bAuxiliaryPos)
void SetData(int aErrorCode, const wxString &aMainText, const wxPoint &aMainPos)
Function SetData initialize all data in item.
wxString m_MainText
text for the first BOARD_ITEM or SCH_ITEM
wxString GetAuxiliaryText() const
const wxString & GetTextA() const
bool m_noCoordinate
void SetShowNoCoordinate()
static const wxChar * GetChars(const wxString &s)
Function GetChars returns a wxChar* to the actual wxChar* data within a wxString, and is helpful for ...
Definition: macros.h:92
const wxPoint & GetPointA() const
wxString ShowHtml() const
Function ShowHtml translates this object into a fragment of HTML suitable for the wxWidget's wxHtmlLi...
const wxString & GetTextB() const
wxString m_AuxiliaryText
text for the second BOARD_ITEM or SCH_ITEM
static wxString ShowCoord(const wxPoint &aPos)
Function ShowCoord formats a coordinate or position to text.
int m_ErrorCode
the error code's numeric value