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_T 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 
91  void SetData( EDA_UNITS_T aUnits, int aErrorCode, EDA_ITEM* aMainItem, const wxPoint& aMainPos,
92  EDA_ITEM* bAuxiliaryItem = nullptr, const wxPoint& bAuxiliaryPos = wxPoint() )
93  {
94  m_ErrorCode = aErrorCode;
95  m_MainText = aMainItem->GetSelectMenuText( aUnits );
96  m_AuxiliaryText = wxEmptyString;
97  m_MainPosition = aMainPos;
98  m_AuxiliaryPosition = bAuxiliaryPos;
99  m_hasSecondItem = bAuxiliaryItem != nullptr;
100  m_noCoordinate = false;
101  m_parent = nullptr;
102 
103  if( m_hasSecondItem )
104  m_AuxiliaryText = bAuxiliaryItem->GetSelectMenuText( aUnits );
105 
106  // Weak references (void*). One must search the BOARD_ITEMS or SCH_ITEMS for a match.
107  m_mainItemWeakRef = aMainItem;
108  m_auxItemWeakRef = bAuxiliaryItem;
109  }
110 
120  void SetData( int aErrorCode, const wxString& aMainText, const wxPoint& aMainPos,
121  const wxString& bAuxiliaryText = wxEmptyString, const wxPoint& bAuxiliaryPos = wxPoint() )
122  {
123  m_ErrorCode = aErrorCode;
124  m_MainText = aMainText;
125  m_AuxiliaryText = bAuxiliaryText;
126  m_MainPosition = aMainPos;
127  m_AuxiliaryPosition = bAuxiliaryPos;
128  m_hasSecondItem = bAuxiliaryText.Length();
129  m_noCoordinate = false;
130  m_parent = nullptr;
131 
132  m_mainItemWeakRef = nullptr;
133  m_auxItemWeakRef = nullptr;
134  }
135 
142  void SetAuxiliaryData( const wxString& aAuxiliaryText, const wxPoint& aAuxiliaryPos )
143  {
144  m_AuxiliaryText = aAuxiliaryText;
145  m_AuxiliaryPosition = aAuxiliaryPos;
146  m_hasSecondItem = true;
147 
148  m_auxItemWeakRef = nullptr;
149  }
150 
151  void SetParent( MARKER_BASE* aMarker ) { m_parent = aMarker; }
152 
153  MARKER_BASE* GetParent() const { return m_parent; }
154 
155  bool HasSecondItem() const { return m_hasSecondItem; }
156 
157  void SetShowNoCoordinate() { m_noCoordinate = true; }
158 
162  wxString GetMainText() const { return m_MainText; }
163  wxString GetAuxiliaryText() const { return m_AuxiliaryText; }
164 
168  BOARD_ITEM* GetMainItem( BOARD* aBoard ) const;
169  BOARD_ITEM* GetAuxiliaryItem( BOARD* aBoard ) const;
170 
177  wxString ShowHtml( EDA_UNITS_T aUnits ) const;
178 
185  wxString ShowReport( EDA_UNITS_T aUnits ) const;
186 
191  int GetErrorCode() const
192  {
193  return m_ErrorCode;
194  }
195 
200  wxString GetErrorText() const;
201 
202  const wxString& GetTextA() const
203  {
204  return m_MainText;
205  }
206 
207 
208  const wxString& GetTextB() const
209  {
210  return m_AuxiliaryText;
211  }
212 
213 
214  const wxPoint& GetPointA() const
215  {
216  return m_MainPosition;
217  }
218 
219 
220  const wxPoint& GetPointB() const
221  {
222  return m_AuxiliaryPosition;
223  }
224 
225 
232  static wxString ShowCoord( EDA_UNITS_T aUnits, const wxPoint& aPos );
233 };
234 
235 
236 #endif // DRC_ITEM_H
BOARD_ITEM * GetAuxiliaryItem(BOARD *aBoard) const
Definition: drc_item.cpp:230
Class DRC_ITEM is a holder for a DRC (in Pcbnew) or ERC (in Eeschema) error item. ...
Definition: drc_item.h:48
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:120
bool HasSecondItem() const
Definition: drc_item.h:155
BOARD_ITEM * GetMainItem(BOARD *aBoard) const
Access to A and B items for BOARDs.
Definition: drc_item.cpp:224
MARKER_BASE * GetParent() const
Definition: drc_item.h:153
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
bool m_hasSecondItem
Definition: drc_item.h:56
int GetErrorCode() const
Function GetErrorCode returns the error code.
Definition: drc_item.h:191
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:142
wxString GetMainText() const
Access to A and B texts.
Definition: drc_item.h:162
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
void SetParent(MARKER_BASE *aMarker)
Definition: drc_item.h:151
const wxPoint & GetPointB() const
Definition: drc_item.h:220
wxPoint m_MainPosition
Definition: drc_item.h:54
wxPoint m_AuxiliaryPosition
Definition: drc_item.h:55
virtual wxString GetSelectMenuText(EDA_UNITS_T aUnits) const
Function GetSelectMenuText returns the text to display to be used in the selection clarification cont...
This file contains miscellaneous commonly used macros and functions.
void * m_mainItemWeakRef
Definition: drc_item.h:60
void SetData(EDA_UNITS_T 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:91
wxString m_MainText
Definition: drc_item.h:52
DRC_ITEM()
Definition: drc_item.h:65
MARKER_BASE * m_parent
Definition: drc_item.h:59
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 GetAuxiliaryText() const
Definition: drc_item.h:163
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
const wxString & GetTextA() const
Definition: drc_item.h:202
bool m_noCoordinate
Definition: drc_item.h:57
void SetShowNoCoordinate()
Definition: drc_item.h:157
const wxPoint & GetPointA() const
Definition: drc_item.h:214
Class BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:170
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:154
Basic classes for most KiCad items.
const wxString & GetTextB() const
Definition: drc_item.h:208
wxString m_AuxiliaryText
Definition: drc_item.h:53
int m_ErrorCode
Definition: drc_item.h:51
EDA_UNITS_T
Definition: common.h:159
DRC_ITEM(EDA_UNITS_T aUnits, int aErrorCode, EDA_ITEM *aMainItem, const wxPoint &aMainPos, EDA_ITEM *bAuxiliaryItem, const wxPoint &bAuxiliaryPos)
Definition: drc_item.h:75