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.

272 lines
9.4 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2009-2014 Jean-Pierre Charras, jp.charras at wanadoo.fr
  5. * Copyright (C) 1992-2014 KiCad Developers, see CHANGELOG.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 MARKER_BASE_H
  25. #define MARKER_BASE_H
  26. #include <drc_item.h>
  27. #include <gr_basic.h>
  28. #include <eda_rect.h>
  29. class SHAPE_LINE_CHAIN;
  30. /* Marker are mainly used to show a DRC or ERC error or warning
  31. */
  32. class MARKER_BASE
  33. {
  34. public:
  35. enum TYPEMARKER { // Marker type: can be used to identify the purpose of the marker
  36. MARKER_UNSPEC,
  37. MARKER_ERC,
  38. MARKER_PCB,
  39. MARKER_SIMUL
  40. };
  41. enum MARKER_SEVERITY { // Severity of the marker: this is the level of error
  42. MARKER_SEVERITY_UNSPEC,
  43. MARKER_SEVERITY_INFO,
  44. MARKER_SEVERITY_WARNING,
  45. MARKER_SEVERITY_ERROR
  46. };
  47. wxPoint m_Pos; ///< position of the marker
  48. protected:
  49. int m_ScalingFactor; ///< Scaling factor to convert corners coordinates
  50. ///< to internat units coordinates
  51. TYPEMARKER m_MarkerType; ///< The type of marker (useful to filter markers)
  52. MARKER_SEVERITY m_ErrorLevel; ///< Specify the severity of the error
  53. COLOR4D m_Color; ///< color
  54. EDA_RECT m_ShapeBoundingBox; ///< Bounding box of the graphic symbol, relative
  55. ///< to the position of the shape, in marker shape units
  56. DRC_ITEM m_drc;
  57. void init();
  58. public:
  59. MARKER_BASE( int aScalingFactor );
  60. /**
  61. * Constructor
  62. * @param aErrorCode The categorizing identifier for an error
  63. * @param aMarkerPos The position of the MARKER on the BOARD
  64. * @param aItem The first of two objects
  65. * @param aPos The position of the first of two objects
  66. * @param bItem The second of the two conflicting objects
  67. * @param bPos The position of the second of two objects
  68. * @param aScalingFactor the scaling factor to convert the shape coordinates to IU coordinates
  69. */
  70. MARKER_BASE( EDA_UNITS_T aUnits, int aErrorCode, const wxPoint& aMarkerPos,
  71. EDA_ITEM* aItem, const wxPoint& aPos,
  72. EDA_ITEM* bItem, const wxPoint& bPos, int aScalingFactor );
  73. /**
  74. * Constructor
  75. * @param aErrorCode The categorizing identifier for an error
  76. * @param aMarkerPos The position of the MARKER on the BOARD
  77. * @param aText Text describing the first of two objects
  78. * @param aPos The position of the first of two objects
  79. * @param bText Text describing the second of the two conflicting objects
  80. * @param bPos The position of the second of two objects
  81. * @param aScalingFactor the scaling factor to convert the shape coordinates to IU coordinates
  82. */
  83. MARKER_BASE( int aErrorCode, const wxPoint& aMarkerPos,
  84. const wxString& aText, const wxPoint& aPos,
  85. const wxString& bText, const wxPoint& bPos, int aScalingFactor );
  86. /**
  87. * Constructor
  88. * @param aErrorCode The categorizing identifier for an error
  89. * @param aMarkerPos The position of the MARKER on the BOARD
  90. * @param aText Text describing the object
  91. * @param aPos The position of the object
  92. * @param aScalingFactor the scaling factor to convert the shape coordinates to IU coordinates
  93. */
  94. MARKER_BASE( int aErrorCode, const wxPoint& aMarkerPos,
  95. const wxString& aText, const wxPoint& aPos, int aScalingFactor );
  96. /**
  97. * Contructor
  98. * makes a copy of \a aMarker but does not copy the DRC_ITEM.
  99. *
  100. * @param aMarker The marker to copy.
  101. */
  102. MARKER_BASE( const MARKER_BASE& aMarker );
  103. ~MARKER_BASE();
  104. /** The scaling factor to convert polygonal shape coordinates to internal units
  105. */
  106. int MarkerScale() const { return m_ScalingFactor; }
  107. /** Returns the shape polygon in internal units in a SHAPE_LINE_CHAIN
  108. * the coordinates are relatives to the marker position (are not absolute)
  109. * @param aPolygon is the SHAPE_LINE_CHAIN to fill with the shape
  110. */
  111. void ShapeToPolygon( SHAPE_LINE_CHAIN& aPolygon) const;
  112. /** @return the shape corner list
  113. */
  114. const VECTOR2I* GetShapePolygon() const;
  115. /** @return the shape polygon corner aIdx
  116. */
  117. const VECTOR2I& GetShapePolygonCorner( int aIdx ) const;
  118. /** @return the default shape polygon corner count
  119. */
  120. int GetShapePolygonCornerCount() const;
  121. /**
  122. * Function DrawMarker
  123. * draws the shape is the polygon defined in m_Corners (array of wxPoints).
  124. */
  125. void DrawMarker( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aOffset );
  126. /**
  127. * Function GetPos
  128. * @return the position of this MARKER in internal units.
  129. */
  130. const wxPoint& GetPos() const
  131. {
  132. return m_Pos;
  133. }
  134. /**
  135. * Function SetColor
  136. * Set the color of this marker
  137. */
  138. void SetColor( COLOR4D aColor )
  139. {
  140. m_Color = aColor;
  141. }
  142. /**
  143. * accessors to set/get error levels (warning, error, fatal error..)
  144. */
  145. void SetErrorLevel( MARKER_SEVERITY aErrorLevel )
  146. {
  147. m_ErrorLevel = aErrorLevel;
  148. }
  149. MARKER_SEVERITY GetErrorLevel() const
  150. {
  151. return m_ErrorLevel;
  152. }
  153. /** accessors to set/get marker type (DRC, ERC, or other)
  154. */
  155. void SetMarkerType( enum TYPEMARKER aMarkerType )
  156. {
  157. m_MarkerType = aMarkerType;
  158. }
  159. enum TYPEMARKER GetMarkerType() const
  160. {
  161. return m_MarkerType;
  162. }
  163. /**
  164. * Function SetData
  165. * fills in all the reportable data associated with a MARKER.
  166. * @param aErrorCode The categorizing identifier for an error
  167. * @param aMarkerPos The position of the MARKER on the BOARD
  168. * @param aItem The first of two objects
  169. * @param aPos The position of the first of two objects
  170. * @param bItem The second of the two conflicting objects
  171. * @param bPos The position of the second of two objects
  172. */
  173. void SetData( EDA_UNITS_T aUnits, int aErrorCode, const wxPoint& aMarkerPos,
  174. EDA_ITEM* aItem, const wxPoint& aPos,
  175. EDA_ITEM* bItem = nullptr, const wxPoint& bPos = wxPoint() );
  176. /**
  177. * Function SetData
  178. * fills in all the reportable data associated with a MARKER.
  179. * @param aErrorCode The categorizing identifier for an error
  180. * @param aMarkerPos The position of the MARKER on the BOARD
  181. * @param aText Text describing the first of two objects
  182. * @param aPos The position of the first of two objects
  183. * @param bText Text describing the second of the two conflicting objects
  184. * @param bPos The position of the second of two objects
  185. */
  186. void SetData( int aErrorCode, const wxPoint& aMarkerPos,
  187. const wxString& aText, const wxPoint& aPos,
  188. const wxString& bText = wxEmptyString, const wxPoint& bPos = wxPoint() );
  189. /**
  190. * Function SetAuxiliaryData
  191. * initialize data for the second (auxiliary) item
  192. * @param aAuxiliaryText = the second text (main text) concerning the second schematic or
  193. * board item
  194. * @param aAuxiliaryPos = position the second item
  195. */
  196. void SetAuxiliaryData( const wxString& aAuxiliaryText, const wxPoint& aAuxiliaryPos )
  197. {
  198. m_drc.SetAuxiliaryData( aAuxiliaryText, aAuxiliaryPos );
  199. }
  200. void SetShowNoCoordinate()
  201. {
  202. m_drc.SetShowNoCoordinate();
  203. }
  204. /**
  205. * Function GetReporter
  206. * returns the DRC_ITEM held within this MARKER so that its
  207. * interface may be used.
  208. * @return const& DRC_ITEM
  209. */
  210. const DRC_ITEM& GetReporter() const
  211. {
  212. return m_drc;
  213. }
  214. /**
  215. * Function DisplayMarkerInfo
  216. * displays the full info of this marker, in a HTML window.
  217. */
  218. void DisplayMarkerInfo( EDA_DRAW_FRAME* aFrame );
  219. /**
  220. * Tests if the given wxPoint is within the bounds of this object.
  221. * @param aHitPosition is the wxPoint to test (in internal units)
  222. * @return bool - true if a hit, else false
  223. */
  224. bool HitTestMarker( const wxPoint& aHitPosition ) const;
  225. /**
  226. * Function GetBoundingBoxMarker
  227. * returns the orthogonal, bounding box of this object for display purposes.
  228. * This box should be an enclosing perimeter for visible components of this
  229. * object, and the units should be in the pcb or schematic coordinate system.
  230. * It is OK to overestimate the size by a few counts.
  231. */
  232. EDA_RECT GetBoundingBoxMarker() const;
  233. };
  234. #endif // MARKER_BASE_H