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.

171 lines
5.0 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2017 Jon Evans <jon@craftyjon.com>
  5. * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
  6. *
  7. * This program is free software: you can redistribute it and/or modify it
  8. * under the terms of the GNU General Public License as published by the
  9. * Free Software Foundation, either version 3 of the License, or (at your
  10. * option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License along
  18. * with this program. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20. #ifndef __GERBVIEW_PAINTER_H
  21. #define __GERBVIEW_PAINTER_H
  22. #include <layer_ids.h>
  23. #include <gal/painter.h>
  24. #include <dcode.h>
  25. #include <gbr_display_options.h>
  26. #include <geometry/shape_poly_set.h>
  27. #include <memory>
  28. class EDA_ITEM;
  29. class GERBER_DRAW_ITEM;
  30. class GERBER_FILE_IMAGE;
  31. namespace KIGFX
  32. {
  33. class GAL;
  34. /**
  35. * Store GerbView specific render settings.
  36. */
  37. class GERBVIEW_RENDER_SETTINGS : public RENDER_SETTINGS
  38. {
  39. public:
  40. friend class GERBVIEW_PAINTER;
  41. GERBVIEW_RENDER_SETTINGS();
  42. void LoadColors( const COLOR_SETTINGS* aSettings ) override;
  43. /// @copydoc RENDER_SETTINGS::GetColor()
  44. virtual COLOR4D GetColor( const VIEW_ITEM* aItem, int aLayer ) const override;
  45. /**
  46. * Return the color used to draw a layer.
  47. *
  48. * @param aLayer is the layer number.
  49. */
  50. inline const COLOR4D& GetLayerColor( int aLayer ) const
  51. {
  52. auto it = m_layerColors.find( aLayer );
  53. return it == m_layerColors.end() ? COLOR4D::WHITE : it->second;
  54. }
  55. /**
  56. * Change the color used to draw a layer.
  57. *
  58. * @param aLayer is the layer number.
  59. * @param aColor is the new color.
  60. */
  61. inline void SetLayerColor( int aLayer, const COLOR4D& aColor )
  62. {
  63. m_layerColors[aLayer] = aColor;
  64. update(); // recompute other shades of the color
  65. }
  66. const COLOR4D& GetBackgroundColor() const override
  67. {
  68. auto it = m_layerColors.find( LAYER_GERBVIEW_BACKGROUND );
  69. return it == m_layerColors.end() ? COLOR4D::BLACK : it->second;
  70. }
  71. void SetBackgroundColor( const COLOR4D& aColor ) override
  72. {
  73. m_layerColors[ LAYER_GERBVIEW_BACKGROUND ] = aColor;
  74. }
  75. const COLOR4D& GetGridColor() override { return m_layerColors[ LAYER_GERBVIEW_GRID ]; }
  76. const COLOR4D& GetCursorColor() override { return m_layerColors[ LAYER_CURSOR ]; }
  77. bool GetShowPageLimits() const override;
  78. /// Clear all highlight selections (dcode, net, component, attribute selection)
  79. void ClearHighlightSelections();
  80. /// If set to anything but an empty string, will highlight items with matching component
  81. wxString m_componentHighlightString;
  82. /// If set to anything but an empty string, will highlight items with matching net
  83. wxString m_netHighlightString;
  84. /// If set to anything but an empty string, will highlight items with matching attribute
  85. wxString m_attributeHighlightString;
  86. /// If set to anything but >0 (in fact 10 the min dcode value),
  87. /// will highlight items with matching dcode
  88. int m_dcodeHighlightValue;
  89. protected:
  90. /// Maximum font size for D-Codes and other strings
  91. static const double MAX_FONT_SIZE;
  92. };
  93. /**
  94. * Methods for drawing GerbView specific items.
  95. */
  96. class GERBVIEW_PAINTER : public PAINTER
  97. {
  98. public:
  99. GERBVIEW_PAINTER( GAL* aGal );
  100. /// @copydoc PAINTER::GetSettings()
  101. virtual GERBVIEW_RENDER_SETTINGS* GetSettings() override
  102. {
  103. return &m_gerbviewSettings;
  104. }
  105. /// @copydoc PAINTER::Draw()
  106. virtual bool Draw( const VIEW_ITEM* aItem, int aLayer ) override;
  107. protected:
  108. GERBVIEW_RENDER_SETTINGS m_gerbviewSettings;
  109. // Drawing functions
  110. void draw( /*const*/ GERBER_DRAW_ITEM* aVia, int aLayer );
  111. /**
  112. * Helper routine to draw a polygon.
  113. *
  114. * @param aParent Pointer to the draw item for AB Position calculation.
  115. * @param aPolygon the polygon to draw.
  116. * @param aFilled If true, draw the polygon as filled, otherwise only outline.
  117. * @param aShift If true, draw the polygon relative to the parent item position.
  118. */
  119. void drawPolygon( GERBER_DRAW_ITEM* aParent, const SHAPE_POLY_SET& aPolygon,
  120. bool aFilled, bool aShift = false );
  121. /// Helper to draw a flashed shape (aka spot)
  122. void drawFlashedShape( GERBER_DRAW_ITEM* aItem, bool aFilled );
  123. /// Helper to draw an aperture macro shape
  124. void drawApertureMacro( GERBER_DRAW_ITEM* aParent, bool aFilled );
  125. /**
  126. * Get the thickness to draw for a line (e.g. 0 thickness lines get a minimum value).
  127. *
  128. * @param aActualThickness line own thickness.
  129. * @return the thickness to draw.
  130. */
  131. int getLineThickness( int aActualThickness ) const;
  132. };
  133. } // namespace KIGFX
  134. #endif /* __GERBVIEW_PAINTER_H */