KiCad PCB EDA Suite
sch_painter.h
Go to the documentation of this file.
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 
27 #ifndef __SCH_PAINTER_H
28 #define __SCH_PAINTER_H
29 
30 #include <sch_symbol.h>
31 
32 #include <painter.h>
33 
34 
35 class LIB_RECTANGLE;
36 class LIB_PIN;
37 class LIB_CIRCLE;
38 class LIB_ITEM;
39 class LIB_PART;
40 class LIB_POLYLINE;
41 class LIB_ARC;
42 class LIB_FIELD;
43 class LIB_TEXT;
44 class LIB_BEZIER;
45 class SCH_COMPONENT;
46 class SCH_FIELD;
47 class SCH_JUNCTION;
48 class SCH_LABEL;
49 class SCH_TEXT;
50 class SCH_HIERLABEL;
51 class SCH_GLOBALLABEL;
52 class SCH_SHEET;
53 class SCH_SHEET_PIN;
54 class SCH_MARKER;
55 class SCH_NO_CONNECT;
56 class SCH_LINE;
57 class SCH_BUS_ENTRY_BASE;
58 class SCH_BITMAP;
59 class SCHEMATIC;
60 
61 namespace KIGFX
62 {
63 class GAL;
64 class SCH_PAINTER;
65 
66 
73 {
74 public:
75  friend class SCH_PAINTER;
76 
78 
79  void LoadColors( const COLOR_SETTINGS* aSettings ) override;
80 
82  virtual COLOR4D GetColor( const VIEW_ITEM* aItem, int aLayer ) const override;
83 
84  bool IsBackgroundDark() const override
85  {
87 
88  return luma < 0.5;
89  }
90 
91  const COLOR4D& GetBackgroundColor() override
92  {
94  }
95 
96  void SetBackgroundColor( const COLOR4D& aColor ) override
97  {
99  }
100 
102  {
103  return (float) m_defaultPenWidth / 3.0F;
104  }
105 
106  const COLOR4D& GetGridColor() override { return m_layerColors[ LAYER_SCHEMATIC_GRID ]; }
107 
109 
110  int m_ShowUnit; // Show all units if 0
111  int m_ShowConvert; // Show all conversions if 0
112 
119 
121 
122  double m_TextOffsetRatio; // Proportion of font size to offset text above/below
123  // wires, buses, etc.
124 
129 };
130 
131 
136 class SCH_PAINTER : public PAINTER
137 {
138 public:
139  SCH_PAINTER( GAL* aGal );
140 
142  virtual bool Draw( const VIEW_ITEM*, int ) override;
143 
145  virtual SCH_RENDER_SETTINGS* GetSettings() override
146  {
147  return &m_schSettings;
148  }
149 
150  void SetSchematic( SCHEMATIC* aSchematic )
151  {
152  m_schematic = aSchematic;
153  }
154 
155 private:
156  void draw( const LIB_RECTANGLE* aRect, int aLayer );
157  void draw( LIB_PIN* aPin, int aLayer );
158  void draw( const LIB_CIRCLE* aCircle, int aLayer );
159  void draw( const LIB_PART* aPart, int, bool aDrawFields = true, int aUnit = 0, int aConvert = 0 );
160  void draw( const LIB_ARC* aArc, int aLayer );
161  void draw( const LIB_POLYLINE* aLine, int aLayer );
162  void draw( const LIB_FIELD* aField, int aLayer );
163  void draw( const LIB_TEXT* aText, int aLayer );
164  void draw( const LIB_BEZIER* aCurve, int aLayer );
165  void draw( SCH_COMPONENT* aSymbol, int aLayer );
166  void draw( const SCH_JUNCTION* aJct, int aLayer );
167  void draw( const SCH_FIELD* aField, int aLayer );
168  void draw( const SCH_TEXT* aText, int aLayer );
169  void draw( SCH_HIERLABEL* aLabel, int aLayer );
170  void draw( SCH_GLOBALLABEL* aLabel, int aLayer );
171  void draw( const SCH_SHEET* aSheet, int aLayer );
172  void draw( const SCH_NO_CONNECT* aNC, int aLayer );
173  void draw( const SCH_MARKER* aMarker, int aLayer );
174  void draw( const SCH_BITMAP* aBitmap, int aLayer );
175  void draw( const SCH_LINE* aLine, int aLayer );
176  void draw( const SCH_BUS_ENTRY_BASE* aEntry, int aLayer );
177 
178  void drawPinDanglingSymbol( const VECTOR2I& aPos, bool aDrawingShadows );
179  void drawDanglingSymbol( const wxPoint& aPos, int aWidth, bool aDrawingShadows );
180 
181  int internalPinDecoSize( const LIB_PIN &aPin );
182  int externalPinDecoSize( const LIB_PIN &aPin );
183 
184  bool isUnitAndConversionShown( const LIB_ITEM* aItem ) const;
185 
186  float getShadowWidth() const;
187  COLOR4D getRenderColor( const EDA_ITEM* aItem, int aLayer, bool aDrawingShadows ) const;
188  float getLineWidth( const LIB_ITEM* aItem, bool aDrawingShadows ) const;
189  float getLineWidth( const SCH_ITEM* aItem, bool aDrawingShadows ) const;
190  float getTextThickness( const SCH_TEXT* aItem, bool aDrawingShadows ) const;
191  float getTextThickness( const SCH_FIELD* aItem, bool aDrawingShadows ) const;
192  float getTextThickness( const LIB_FIELD* aItem, bool aDrawingShadows ) const;
193  float getTextThickness( const LIB_TEXT* aItem, bool aDrawingShadows ) const;
194 
195  bool setDeviceColors( const LIB_ITEM* aItem, int aLayer );
196  void fillIfSelection( int aLayer );
197 
198  void triLine ( const VECTOR2D &a, const VECTOR2D &b, const VECTOR2D &c );
199  void strokeText( const wxString& aText, const VECTOR2D& aPosition, double aRotationAngle );
200 
202 
204 };
205 
206 }; // namespace KIGFX
207 
208 
209 #endif // __SCH_PAINTER_H
virtual bool Draw(const VIEW_ITEM *, int) override
Takes an instance of VIEW_ITEM and passes it to a function that knows how to draw the item.
SCH_PAINTER(GAL *aGal)
void draw(const LIB_RECTANGLE *aRect, int aLayer)
SCH_FIELD instances are attached to a component and provide a place for the component's value,...
Definition: sch_field.h:51
SCHEMATIC * m_schematic
Definition: sch_painter.h:203
void drawDanglingSymbol(const wxPoint &aPos, int aWidth, bool aDrawingShadows)
double GetBrightness() const
Returns the brightness value of the color ranged from 0.0 to 1.0.
Definition: color4d.h:322
The Cairo implementation of the graphics abstraction layer.
Definition: color4d.cpp:175
Container for all the knowledge about how graphical objects are drawn on any output surface/device.
Holds all the data relating to one schematic A schematic may consist of one or more sheets (and one r...
Definition: schematic.h:58
void drawPinDanglingSymbol(const VECTOR2I &aPos, bool aDrawingShadows)
COLOR4D m_layerColors[LAYER_ID_COUNT]
Define a symbol library graphical text item.
Definition: lib_text.h:40
Field object used in symbol libraries.
Definition: lib_field.h:59
float getTextThickness(const SCH_TEXT *aItem, bool aDrawingShadows) const
bool setDeviceColors(const LIB_ITEM *aItem, int aLayer)
bool isUnitAndConversionShown(const LIB_ITEM *aItem) const
void SetBackgroundColor(const COLOR4D &aColor) override
Set the background color.
Definition: sch_painter.h:96
const COLOR4D & GetGridColor() override
Return current grid color settings.
Definition: sch_painter.h:106
virtual COLOR4D GetColor(const VIEW_ITEM *aItem, int aLayer) const override
Returns the color that should be used to draw the specific VIEW_ITEM on the specific layer using curr...
An abstract base class for deriving all objects that can be added to a VIEW.
Definition: view_item.h:81
float getShadowWidth() const
void fillIfSelection(int aLayer)
The base class for drawable items used by schematic library components.
Definition: lib_item.h:62
Base class for a bus or wire entry.
Definition: sch_bus_entry.h:42
Contains all the knowledge about how to draw graphical object onto any particular output device.
Definition: painter.h:57
const COLOR4D & GetCursorColor() override
Return current cursor color settings.
Definition: sch_painter.h:108
SCH_PAINTER Contains methods for drawing schematic-specific items.
Definition: sch_painter.h:136
float GetDanglineSymbolThickness() const
Definition: sch_painter.h:101
Define a library symbol object.
Definition: lib_symbol.h:93
void strokeText(const wxString &aText, const VECTOR2D &aPosition, double aRotationAngle)
void triLine(const VECTOR2D &a, const VECTOR2D &b, const VECTOR2D &c)
Define a sheet pin (label) used in sheets to create hierarchical schematics.
Definition: sch_sheet.h:85
Object to handle a bitmap image that can be inserted in a schematic.
Definition: sch_bitmap.h:42
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition: sch_sheet.h:219
virtual SCH_RENDER_SETTINGS * GetSettings() override
Return a pointer to current settings that are going to be used when drawing items.
Definition: sch_painter.h:145
int externalPinDecoSize(const LIB_PIN &aPin)
void LoadColors(const COLOR_SETTINGS *aSettings) override
Definition: sch_painter.cpp:92
const COLOR4D & GetBackgroundColor() override
Return current background color settings.
Definition: sch_painter.h:91
Segment description base class to describe items which have 2 end points (track, wire,...
Definition: sch_line.h:37
int internalPinDecoSize(const LIB_PIN &aPin)
Schematic symbol object.
Definition: sch_symbol.h:79
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:149
bool IsBackgroundDark() const override
Definition: sch_painter.h:84
COLOR4D getRenderColor(const EDA_ITEM *aItem, int aLayer, bool aDrawingShadows) const
SCH_RENDER_SETTINGS Stores schematic-specific render settings.
Definition: sch_painter.h:72
Color settings are a bit different than most of the settings objects in that there can be more than o...
float getLineWidth(const LIB_ITEM *aItem, bool aDrawingShadows) const
void SetSchematic(SCHEMATIC *aSchematic)
Definition: sch_painter.h:150
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:196
SCH_RENDER_SETTINGS m_schSettings
Definition: sch_painter.h:201
Abstract interface for drawing on a 2D-surface.
Define a bezier curve graphic body item.
Definition: lib_bezier.h:34
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:98