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.

204 lines
6.3 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2019-2020 CERN
  5. * Copyright (C) 2020-2021 KiCad Developers, see AUTHORS.txt for contributors.
  6. *
  7. * @author Tomasz Wlostowski <tomasz.wlostowski@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 __SCH_PAINTER_H
  27. #define __SCH_PAINTER_H
  28. #include <sch_symbol.h>
  29. #include <painter.h>
  30. class LIB_PIN;
  31. class LIB_SHAPE;
  32. class LIB_ITEM;
  33. class LIB_SYMBOL;
  34. class LIB_FIELD;
  35. class LIB_TEXT;
  36. class SCH_SYMBOL;
  37. class SCH_FIELD;
  38. class SCH_JUNCTION;
  39. class SCH_LABEL;
  40. class SCH_TEXT;
  41. class SCH_HIERLABEL;
  42. class SCH_GLOBALLABEL;
  43. class SCH_SHEET;
  44. class SCH_SHEET_PIN;
  45. class SCH_MARKER;
  46. class SCH_NO_CONNECT;
  47. class SCH_LINE;
  48. class SCH_BUS_ENTRY_BASE;
  49. class SCH_BITMAP;
  50. class SCHEMATIC;
  51. namespace KIGFX
  52. {
  53. class GAL;
  54. class SCH_PAINTER;
  55. /**
  56. * Store schematic specific render settings.
  57. */
  58. class SCH_RENDER_SETTINGS : public RENDER_SETTINGS
  59. {
  60. public:
  61. friend class SCH_PAINTER;
  62. SCH_RENDER_SETTINGS();
  63. void LoadColors( const COLOR_SETTINGS* aSettings ) override;
  64. /// @copydoc RENDER_SETTINGS::GetColor()
  65. virtual COLOR4D GetColor( const VIEW_ITEM* aItem, int aLayer ) const override;
  66. bool IsBackgroundDark() const override
  67. {
  68. auto luma = m_layerColors[ LAYER_SCHEMATIC_BACKGROUND ].GetBrightness();
  69. return luma < 0.5;
  70. }
  71. const COLOR4D& GetBackgroundColor() override
  72. {
  73. return m_layerColors[ LAYER_SCHEMATIC_BACKGROUND ];
  74. }
  75. void SetBackgroundColor( const COLOR4D& aColor ) override
  76. {
  77. m_layerColors[ LAYER_SCHEMATIC_BACKGROUND ] = aColor;
  78. }
  79. float GetDanglineSymbolThickness() const
  80. {
  81. return (float) m_defaultPenWidth / 3.0F;
  82. }
  83. const COLOR4D& GetGridColor() override { return m_layerColors[ LAYER_SCHEMATIC_GRID ]; }
  84. const COLOR4D& GetCursorColor() override { return m_layerColors[ LAYER_SCHEMATIC_CURSOR ]; }
  85. bool m_IsSymbolEditor;
  86. int m_ShowUnit; // Show all units if 0
  87. int m_ShowConvert; // Show all conversions if 0
  88. bool m_ShowHiddenText;
  89. bool m_ShowHiddenPins;
  90. bool m_ShowPinsElectricalType;
  91. bool m_ShowDisabled;
  92. bool m_ShowGraphicsDisabled;
  93. bool m_ShowUmbilicals;
  94. bool m_OverrideItemColors;
  95. double m_LabelSizeRatio; // Proportion of font size to label box
  96. double m_TextOffsetRatio; // Proportion of font size to offset text above/below
  97. // wires, buses, etc.
  98. int m_DefaultWireThickness;
  99. int m_DefaultBusThickness;
  100. int m_PinSymbolSize;
  101. int m_JunctionSize;
  102. };
  103. /**
  104. * Contains methods for drawing schematic-specific items.
  105. */
  106. class SCH_PAINTER : public PAINTER
  107. {
  108. public:
  109. SCH_PAINTER( GAL* aGal );
  110. /// @copydoc PAINTER::Draw()
  111. virtual bool Draw( const VIEW_ITEM*, int ) override;
  112. /// @copydoc PAINTER::GetSettings()
  113. virtual SCH_RENDER_SETTINGS* GetSettings() override
  114. {
  115. return &m_schSettings;
  116. }
  117. void SetSchematic( SCHEMATIC* aSchematic )
  118. {
  119. m_schematic = aSchematic;
  120. }
  121. private:
  122. void draw( LIB_PIN* aPin, int aLayer );
  123. void draw( const LIB_SHAPE* aCircle, int aLayer );
  124. void draw( const LIB_SYMBOL* aSymbol, int, bool aDrawFields = true, int aUnit = 0,
  125. int aConvert = 0 );
  126. void draw( const LIB_FIELD* aField, int aLayer );
  127. void draw( const LIB_TEXT* aText, int aLayer );
  128. void draw( SCH_SYMBOL* aSymbol, int aLayer );
  129. void draw( const SCH_JUNCTION* aJct, int aLayer );
  130. void draw( const SCH_FIELD* aField, int aLayer );
  131. void draw( const SCH_TEXT* aText, int aLayer );
  132. void draw( SCH_HIERLABEL* aLabel, int aLayer );
  133. void draw( SCH_GLOBALLABEL* aLabel, int aLayer );
  134. void draw( const SCH_SHEET* aSheet, int aLayer );
  135. void draw( const SCH_NO_CONNECT* aNC, int aLayer );
  136. void draw( const SCH_MARKER* aMarker, int aLayer );
  137. void draw( const SCH_BITMAP* aBitmap, int aLayer );
  138. void draw( const SCH_LINE* aLine, int aLayer );
  139. void draw( const SCH_BUS_ENTRY_BASE* aEntry, int aLayer );
  140. void drawPinDanglingSymbol( const VECTOR2I& aPos, bool aDrawingShadows );
  141. void drawDanglingSymbol( const wxPoint& aPos, int aWidth, bool aDrawingShadows );
  142. int internalPinDecoSize( const LIB_PIN &aPin );
  143. int externalPinDecoSize( const LIB_PIN &aPin );
  144. bool isUnitAndConversionShown( const LIB_ITEM* aItem ) const;
  145. float getShadowWidth() const;
  146. COLOR4D getRenderColor( const EDA_ITEM* aItem, int aLayer, bool aDrawingShadows ) const;
  147. float getLineWidth( const LIB_ITEM* aItem, bool aDrawingShadows ) const;
  148. float getLineWidth( const SCH_ITEM* aItem, bool aDrawingShadows ) const;
  149. float getTextThickness( const SCH_TEXT* aItem, bool aDrawingShadows ) const;
  150. float getTextThickness( const SCH_FIELD* aItem, bool aDrawingShadows ) const;
  151. float getTextThickness( const LIB_FIELD* aItem, bool aDrawingShadows ) const;
  152. float getTextThickness( const LIB_TEXT* aItem, bool aDrawingShadows ) const;
  153. bool setDeviceColors( const LIB_ITEM* aItem, int aLayer );
  154. void fillIfSelection( int aLayer );
  155. void triLine ( const VECTOR2D &a, const VECTOR2D &b, const VECTOR2D &c );
  156. void strokeText( const wxString& aText, const VECTOR2D& aPosition, double aRotationAngle );
  157. void boxText( const wxString& aText, const VECTOR2D& aPosition, double aAngle );
  158. private:
  159. SCH_RENDER_SETTINGS m_schSettings;
  160. SCHEMATIC* m_schematic;
  161. };
  162. }; // namespace KIGFX
  163. #endif // __SCH_PAINTER_H