KiCad PCB EDA Suite
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) 2018 KiCad Developers, see AUTHORS.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 DRC_ITEM_H
26 #define DRC_ITEM_H
27 
28 #include <macros.h>
29 #include <base_struct.h>
30 
31 class MARKER_BASE;
32 class BOARD;
33 class BOARD_ITEM;
34 
35 
48 class DRC_ITEM
49 {
50 protected:
51  int m_ErrorCode; // the error code's numeric value
52  wxString m_MainText; // text for the first BOARD_ITEM or SCH_ITEM
53  wxString m_AuxiliaryText; // text for the second BOARD_ITEM or SCH_ITEM
54  wxPoint m_MainPosition; // the location of the first (or main ) BOARD_ITEM or SCH_ITEM.
55  wxPoint m_AuxiliaryPosition; // the location of the second BOARD_ITEM or SCH_ITEM
56  bool m_hasSecondItem; // true when 2 items create a DRC/ERC error, false if only one item
58 
59  MARKER_BASE* m_parent; // The marker this item belongs to, if any
60  void* m_mainItemWeakRef; // search the current BOARD_ITEMs or SCH_ITEMs for a match
61  void* m_auxItemWeakRef; // search the current BOARD_ITEMs or SCH_ITEMs for a match
62 
63 public:
64 
66  {
67  m_ErrorCode = 0;
68  m_hasSecondItem = false;
69  m_noCoordinate = false;
70  m_parent = nullptr;
71  m_mainItemWeakRef = nullptr;
72  m_auxItemWeakRef = nullptr;
73  }
74 
75  DRC_ITEM( EDA_UNITS aUnits, int aErrorCode, EDA_ITEM* aMainItem, const wxPoint& aMainPos,
76  EDA_ITEM* bAuxiliaryItem, const wxPoint& bAuxiliaryPos )
77  {
78  SetData( aUnits, aErrorCode, aMainItem, aMainPos, bAuxiliaryItem, bAuxiliaryPos );
79  }
80 
81  DRC_ITEM( EDA_UNITS aUnits, int aErrorCode, EDA_ITEM* aMainItem, const wxPoint& aMainPos )
82  {
83  SetData( aUnits, aErrorCode, aMainItem, aMainPos );
84  }
85 
86 
87  DRC_ITEM( int aErrorCode, const wxString& aMainText )
88  {
89  SetData( aErrorCode, aMainText, wxPoint() );
91  }
92 
93 
103  void SetData( EDA_UNITS aUnits, int aErrorCode, EDA_ITEM* aMainItem, const wxPoint& aMainPos,
104  EDA_ITEM* bAuxiliaryItem = nullptr, const wxPoint& bAuxiliaryPos = wxPoint() )
105  {
106  m_ErrorCode = aErrorCode;
107  m_MainText = aMainItem->GetSelectMenuText( aUnits );
108  m_AuxiliaryText = wxEmptyString;
109  m_MainPosition = aMainPos;
110  m_AuxiliaryPosition = bAuxiliaryPos;
111  m_hasSecondItem = bAuxiliaryItem != nullptr;
112  m_noCoordinate = false;
113  m_parent = nullptr;
114 
115  if( m_hasSecondItem )
116  m_AuxiliaryText = bAuxiliaryItem->GetSelectMenuText( aUnits );
117 
118  // Weak references (void*). One must search the BOARD_ITEMS or SCH_ITEMS for a match.
119  m_mainItemWeakRef = aMainItem;
120  m_auxItemWeakRef = bAuxiliaryItem;
121  }
122 
132  void SetData( int aErrorCode, const wxString& aMainText, const wxPoint& aMainPos,
133  const wxString& bAuxiliaryText = wxEmptyString, const wxPoint& bAuxiliaryPos = wxPoint() )
134  {
135  m_ErrorCode = aErrorCode;
136  m_MainText = aMainText;
137  m_AuxiliaryText = bAuxiliaryText;
138  m_MainPosition = aMainPos;
139  m_AuxiliaryPosition = bAuxiliaryPos;
140  m_hasSecondItem = bAuxiliaryText.Length();
141  m_noCoordinate = false;
142  m_parent = nullptr;
143 
144  m_mainItemWeakRef = nullptr;
145  m_auxItemWeakRef = nullptr;
146  }
147 
154  void SetAuxiliaryData( const wxString& aAuxiliaryText, const wxPoint& aAuxiliaryPos )
155  {
156  m_AuxiliaryText = aAuxiliaryText;
157  m_AuxiliaryPosition = aAuxiliaryPos;
158  m_hasSecondItem = true;
159 
160  m_auxItemWeakRef = nullptr;
161  }
162 
163  void SetParent( MARKER_BASE* aMarker ) { m_parent = aMarker; }
164 
165  MARKER_BASE* GetParent() const { return m_parent; }
166 
167  bool HasSecondItem() const { return m_hasSecondItem; }
168 
170 
174  wxString GetMainText() const { return m_MainText; }
175  wxString GetAuxiliaryText() const { return m_AuxiliaryText; }
176 
180  BOARD_ITEM* GetMainItem( BOARD* aBoard ) const;
181  BOARD_ITEM* GetAuxiliaryItem( BOARD* aBoard ) const;
182 
189  wxString ShowHtml( EDA_UNITS aUnits ) const;
190 
197  wxString ShowReport( EDA_UNITS aUnits ) const;
198 
203  int GetErrorCode() const
204  {
205  return m_ErrorCode;
206  }
207 
212  wxString GetErrorText() const;
213 
214  const wxString& GetTextA() const
215  {
216  return m_MainText;
217  }
218 
219 
220  const wxString& GetTextB() const
221  {
222  return m_AuxiliaryText;
223  }
224 
225 
226  const wxPoint& GetPointA() const
227  {
228  return m_MainPosition;
229  }
230 
231 
232  const wxPoint& GetPointB() const
233  {
234  return m_AuxiliaryPosition;
235  }
236 
237 
244  static wxString ShowCoord( EDA_UNITS aUnits, const wxPoint& aPos );
245 };
246 
247 
248 #endif // DRC_ITEM_H
EDA_UNITS
Definition: common.h:72
wxString GetErrorText() const
Function GetErrorText returns the string form of a drc error code.
DRC_ITEM is a holder for a DRC (in Pcbnew) or ERC (in Eeschema) error item.
Definition: drc_item.h:48
void SetData(EDA_UNITS aUnits, int aErrorCode, EDA_ITEM *aMainItem, const wxPoint &aMainPos, EDA_ITEM *bAuxiliaryItem=nullptr, const wxPoint &bAuxiliaryPos=wxPoint())
Function SetData initialize all data in item.
Definition: drc_item.h:103
void SetData(int aErrorCode, const wxString &aMainText, const wxPoint &aMainPos, const wxString &bAuxiliaryText=wxEmptyString, const wxPoint &bAuxiliaryPos=wxPoint())
Function SetData initialize all data in item.
Definition: drc_item.h:132
BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class,...
bool m_hasSecondItem
Definition: drc_item.h:56
void * m_auxItemWeakRef
Definition: drc_item.h:61
void SetAuxiliaryData(const wxString &aAuxiliaryText, const wxPoint &aAuxiliaryPos)
Function SetAuxiliaryData initialize data for the second (auxiliary) item.
Definition: drc_item.h:154
BOARD_ITEM * GetAuxiliaryItem(BOARD *aBoard) const
Definition: drc_item.cpp:258
const wxPoint & GetPointB() const
Definition: drc_item.h:232
static wxString ShowCoord(EDA_UNITS aUnits, const wxPoint &aPos)
Function ShowCoord formats a coordinate or position to text.
wxString GetMainText() const
Access to A and B texts.
Definition: drc_item.h:174
void SetParent(MARKER_BASE *aMarker)
Definition: drc_item.h:163
MARKER_BASE * GetParent() const
Definition: drc_item.h:165
wxPoint m_MainPosition
Definition: drc_item.h:54
wxPoint m_AuxiliaryPosition
Definition: drc_item.h:55
This file contains miscellaneous commonly used macros and functions.
void * m_mainItemWeakRef
Definition: drc_item.h:60
int GetErrorCode() const
Function GetErrorCode returns the error code.
Definition: drc_item.h:203
wxString m_MainText
Definition: drc_item.h:52
const wxString & GetTextA() const
Definition: drc_item.h:214
DRC_ITEM()
Definition: drc_item.h:65
DRC_ITEM(EDA_UNITS aUnits, int aErrorCode, EDA_ITEM *aMainItem, const wxPoint &aMainPos)
Definition: drc_item.h:81
MARKER_BASE * m_parent
Definition: drc_item.h:59
BOARD_ITEM * GetMainItem(BOARD *aBoard) const
Access to A and B items for BOARDs.
Definition: drc_item.cpp:252
wxString ShowHtml(EDA_UNITS aUnits) const
Function ShowHtml translates this object into a fragment of HTML suitable for the wxWidget's wxHtmlLi...
DRC_ITEM(EDA_UNITS aUnits, int aErrorCode, EDA_ITEM *aMainItem, const wxPoint &aMainPos, EDA_ITEM *bAuxiliaryItem, const wxPoint &bAuxiliaryPos)
Definition: drc_item.h:75
const wxPoint & GetPointA() const
Definition: drc_item.h:226
bool HasSecondItem() const
Definition: drc_item.h:167
bool m_noCoordinate
Definition: drc_item.h:57
const wxString & GetTextB() const
Definition: drc_item.h:220
void SetShowNoCoordinate()
Definition: drc_item.h:169
BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:160
DRC_ITEM(int aErrorCode, const wxString &aMainText)
Definition: drc_item.h:87
virtual wxString GetSelectMenuText(EDA_UNITS aUnits) const
Function GetSelectMenuText returns the text to display to be used in the selection clarification cont...
EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boards.
Definition: base_struct.h:163
wxString m_AuxiliaryText
Definition: drc_item.h:53
wxString GetAuxiliaryText() const
Definition: drc_item.h:175
int m_ErrorCode
Definition: drc_item.h:51
wxString ShowReport(EDA_UNITS aUnits) const
Function ShowReport translates this object into a text string suitable for saving to disk in a report...