You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

248 lines
8.1 KiB

  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. #ifndef DRC_ITEM_H
  25. #define DRC_ITEM_H
  26. #include <macros.h>
  27. #include <base_struct.h>
  28. class MARKER_BASE;
  29. class BOARD;
  30. class BOARD_ITEM;
  31. /**
  32. * DRC_ITEM
  33. * is a holder for a DRC (in Pcbnew) or ERC (in Eeschema) error item.
  34. * It is generated when two objects are too close (DRC)
  35. * or two connected objects (pins) have incompatible electrical types (ERC).
  36. * There are holders for information on two items. The
  37. * information held is the board coordinate and the MenuText for each item.
  38. * Also held is the type of error by number and the location of the MARKER.
  39. * A function is provided to translate that number into text.
  40. * Some errors involve only one item (item with an incorrect param) so
  41. * m_hasSecondItem is set to false in this case.
  42. */
  43. class DRC_ITEM
  44. {
  45. protected:
  46. int m_ErrorCode; // the error code's numeric value
  47. wxString m_MainText; // text for the first BOARD_ITEM or SCH_ITEM
  48. wxString m_AuxiliaryText; // text for the second BOARD_ITEM or SCH_ITEM
  49. wxPoint m_MainPosition; // the location of the first (or main ) BOARD_ITEM or SCH_ITEM.
  50. wxPoint m_AuxiliaryPosition; // the location of the second BOARD_ITEM or SCH_ITEM
  51. bool m_hasSecondItem; // true when 2 items create a DRC/ERC error, false if only one item
  52. bool m_noCoordinate;
  53. MARKER_BASE* m_parent; // The marker this item belongs to, if any
  54. void* m_mainItemWeakRef; // search the current BOARD_ITEMs or SCH_ITEMs for a match
  55. void* m_auxItemWeakRef; // search the current BOARD_ITEMs or SCH_ITEMs for a match
  56. public:
  57. DRC_ITEM()
  58. {
  59. m_ErrorCode = 0;
  60. m_hasSecondItem = false;
  61. m_noCoordinate = false;
  62. m_parent = nullptr;
  63. m_mainItemWeakRef = nullptr;
  64. m_auxItemWeakRef = nullptr;
  65. }
  66. DRC_ITEM( EDA_UNITS aUnits, int aErrorCode, EDA_ITEM* aMainItem, const wxPoint& aMainPos,
  67. EDA_ITEM* bAuxiliaryItem, const wxPoint& bAuxiliaryPos )
  68. {
  69. SetData( aUnits, aErrorCode, aMainItem, aMainPos, bAuxiliaryItem, bAuxiliaryPos );
  70. }
  71. DRC_ITEM( EDA_UNITS aUnits, int aErrorCode, EDA_ITEM* aMainItem, const wxPoint& aMainPos )
  72. {
  73. SetData( aUnits, aErrorCode, aMainItem, aMainPos );
  74. }
  75. DRC_ITEM( int aErrorCode, const wxString& aMainText )
  76. {
  77. SetData( aErrorCode, aMainText, wxPoint() );
  78. SetShowNoCoordinate();
  79. }
  80. /**
  81. * Function SetData
  82. * initialize all data in item
  83. * @param aErrorCode = error code
  84. * @param aMainItem = the first (main) schematic or board item
  85. * @param bAuxiliaryItem = the second schematic or board item
  86. * @param aMainPos = position the first item and therefore of this issue
  87. * @param bAuxiliaryPos = position the second item
  88. */
  89. void SetData( EDA_UNITS aUnits, int aErrorCode, EDA_ITEM* aMainItem, const wxPoint& aMainPos,
  90. EDA_ITEM* bAuxiliaryItem = nullptr, const wxPoint& bAuxiliaryPos = wxPoint() )
  91. {
  92. m_ErrorCode = aErrorCode;
  93. m_MainText = aMainItem->GetSelectMenuText( aUnits );
  94. m_AuxiliaryText = wxEmptyString;
  95. m_MainPosition = aMainPos;
  96. m_AuxiliaryPosition = bAuxiliaryPos;
  97. m_hasSecondItem = bAuxiliaryItem != nullptr;
  98. m_noCoordinate = false;
  99. m_parent = nullptr;
  100. if( m_hasSecondItem )
  101. m_AuxiliaryText = bAuxiliaryItem->GetSelectMenuText( aUnits );
  102. // Weak references (void*). One must search the BOARD_ITEMS or SCH_ITEMS for a match.
  103. m_mainItemWeakRef = aMainItem;
  104. m_auxItemWeakRef = bAuxiliaryItem;
  105. }
  106. /**
  107. * Function SetData
  108. * initialize all data in item
  109. * @param aErrorCode = error code
  110. * @param aMainItem = the first (main) schematic or board item
  111. * @param bAuxiliaryItem = the second schematic or board item
  112. * @param aMainPos = position the first item and therefore of this issue
  113. * @param bAuxiliaryPos = position the second item
  114. */
  115. void SetData( int aErrorCode, const wxString& aMainText, const wxPoint& aMainPos,
  116. const wxString& bAuxiliaryText = wxEmptyString, const wxPoint& bAuxiliaryPos = wxPoint() )
  117. {
  118. m_ErrorCode = aErrorCode;
  119. m_MainText = aMainText;
  120. m_AuxiliaryText = bAuxiliaryText;
  121. m_MainPosition = aMainPos;
  122. m_AuxiliaryPosition = bAuxiliaryPos;
  123. m_hasSecondItem = bAuxiliaryText.Length();
  124. m_noCoordinate = false;
  125. m_parent = nullptr;
  126. m_mainItemWeakRef = nullptr;
  127. m_auxItemWeakRef = nullptr;
  128. }
  129. /**
  130. * Function SetAuxiliaryData
  131. * initialize data for the second (auxiliary) item
  132. * @param aAuxiliaryText = the second text (main text) concerning the second schematic or board item
  133. * @param aAuxiliaryPos = position the second item
  134. */
  135. void SetAuxiliaryData( const wxString& aAuxiliaryText, const wxPoint& aAuxiliaryPos )
  136. {
  137. m_AuxiliaryText = aAuxiliaryText;
  138. m_AuxiliaryPosition = aAuxiliaryPos;
  139. m_hasSecondItem = true;
  140. m_auxItemWeakRef = nullptr;
  141. }
  142. void SetParent( MARKER_BASE* aMarker ) { m_parent = aMarker; }
  143. MARKER_BASE* GetParent() const { return m_parent; }
  144. bool HasSecondItem() const { return m_hasSecondItem; }
  145. void SetShowNoCoordinate() { m_noCoordinate = true; }
  146. /**
  147. * Access to A and B texts
  148. */
  149. wxString GetMainText() const { return m_MainText; }
  150. wxString GetAuxiliaryText() const { return m_AuxiliaryText; }
  151. /**
  152. * Access to A and B items for BOARDs
  153. */
  154. BOARD_ITEM* GetMainItem( BOARD* aBoard ) const;
  155. BOARD_ITEM* GetAuxiliaryItem( BOARD* aBoard ) const;
  156. /**
  157. * Function ShowHtml
  158. * translates this object into a fragment of HTML suitable for the
  159. * wxWidget's wxHtmlListBox class.
  160. * @return wxString - the html text.
  161. */
  162. wxString ShowHtml( EDA_UNITS aUnits ) const;
  163. /**
  164. * Function ShowReport
  165. * translates this object into a text string suitable for saving
  166. * to disk in a report.
  167. * @return wxString - the simple multi-line report text.
  168. */
  169. wxString ShowReport( EDA_UNITS aUnits ) const;
  170. /**
  171. * Function GetErrorCode
  172. * returns the error code.
  173. */
  174. int GetErrorCode() const
  175. {
  176. return m_ErrorCode;
  177. }
  178. /**
  179. * Function GetErrorText
  180. * returns the string form of a drc error code.
  181. */
  182. wxString GetErrorText() const;
  183. const wxString& GetTextA() const
  184. {
  185. return m_MainText;
  186. }
  187. const wxString& GetTextB() const
  188. {
  189. return m_AuxiliaryText;
  190. }
  191. const wxPoint& GetPointA() const
  192. {
  193. return m_MainPosition;
  194. }
  195. const wxPoint& GetPointB() const
  196. {
  197. return m_AuxiliaryPosition;
  198. }
  199. /**
  200. * Function ShowCoord
  201. * formats a coordinate or position to text.
  202. * @param aPos The position to format
  203. * @return wxString - The formated string
  204. */
  205. static wxString ShowCoord( EDA_UNITS aUnits, const wxPoint& aPos );
  206. };
  207. #endif // DRC_ITEM_H