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.

168 lines
4.0 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2013-2016 CERN
  5. * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
  6. *
  7. * @author Maciej Suminski <maciej.suminski@cern.ch>
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License
  11. * as published by the Free Software Foundation; either version 2
  12. * of the License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, you may find one here:
  21. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  22. * or you may search the http://www.gnu.org website for the version 2 license,
  23. * or you may write to the Free Software Foundation, Inc.,
  24. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  25. */
  26. #ifndef __ORIGIN_VIEWITEM_H
  27. #define __ORIGIN_VIEWITEM_H
  28. #include <math/box2.h>
  29. #include <view/view.h>
  30. #include <layer_ids.h>
  31. #include <gal/color4d.h>
  32. #include <eda_item.h>
  33. /**
  34. * View item to draw an origin marker.
  35. */
  36. namespace KIGFX {
  37. class ORIGIN_VIEWITEM : public EDA_ITEM
  38. {
  39. public:
  40. /// Marker symbol styles.
  41. enum MARKER_STYLE
  42. {
  43. NO_GRAPHIC, CROSS, X, DOT, CIRCLE_CROSS, CIRCLE_X, CIRCLE_DOT, DASH_LINE
  44. };
  45. ORIGIN_VIEWITEM( const COLOR4D& aColor = COLOR4D( 1.0, 1.0, 1.0, 1.0 ),
  46. MARKER_STYLE aStyle = CIRCLE_X, int aSize = 16,
  47. const VECTOR2D& aPosition = VECTOR2D( 0, 0 ) );
  48. ORIGIN_VIEWITEM( const VECTOR2D& aPosition, EDA_ITEM_FLAGS flags );
  49. ORIGIN_VIEWITEM* Clone() const override;
  50. const BOX2I ViewBBox() const override;
  51. void ViewDraw( int aLayer, VIEW* aView ) const override;
  52. std::vector<int> ViewGetLayers() const override
  53. {
  54. return { LAYER_GP_OVERLAY };
  55. }
  56. #if defined(DEBUG)
  57. void Show( int x, std::ostream& st ) const override
  58. {
  59. }
  60. #endif
  61. /**
  62. * Get class name.
  63. *
  64. * @return string "ORIGIN_VIEWITEM"
  65. */
  66. wxString GetClass() const override
  67. {
  68. return wxT( "ORIGIN_VIEWITEM" );
  69. }
  70. /**
  71. * Set the draw at zero flag.
  72. *
  73. * When set the marker will be drawn when its position is 0,0. Otherwise it will not
  74. * be drawn when its position is 0,0.
  75. *
  76. * @param aDrawFlag The value to set the draw at zero flag.
  77. */
  78. inline void SetDrawAtZero( bool aDrawFlag )
  79. {
  80. m_drawAtZero = aDrawFlag;
  81. }
  82. void SetPosition( const VECTOR2I& aPosition ) override
  83. {
  84. m_position = VECTOR2D( aPosition );
  85. }
  86. VECTOR2I GetPosition() const override
  87. {
  88. return VECTOR2I( m_position.x, m_position.y );
  89. }
  90. inline void SetEndPosition( const VECTOR2D& aPosition )
  91. {
  92. m_end = aPosition;
  93. }
  94. inline const VECTOR2I GetEndPosition() const
  95. {
  96. return VECTOR2I( m_end.x, m_end.y );
  97. }
  98. inline void SetSize( int aSize )
  99. {
  100. m_size = aSize;
  101. }
  102. inline int GetSize() const
  103. {
  104. return m_size;
  105. }
  106. inline void SetColor( const KIGFX::COLOR4D& aColor )
  107. {
  108. m_color = aColor;
  109. }
  110. inline const KIGFX::COLOR4D& GetColor() const
  111. {
  112. return m_color;
  113. }
  114. inline void SetStyle( MARKER_STYLE aStyle )
  115. {
  116. m_style = aStyle;
  117. }
  118. inline MARKER_STYLE GetStyle() const
  119. {
  120. return m_style;
  121. }
  122. protected:
  123. /// Marker coordinates.
  124. VECTOR2D m_position;
  125. /// Marker end position for markers that stretch between points.
  126. VECTOR2D m_end;
  127. /// Marker size (in pixels).
  128. int m_size;
  129. /// Marker color.
  130. COLOR4D m_color;
  131. /// Marker symbol.
  132. MARKER_STYLE m_style;
  133. /// If set, the marker will be drawn even if its position is 0,0.
  134. bool m_drawAtZero;
  135. };
  136. } // namespace KIGFX
  137. #endif