KiCad PCB EDA Suite
Loading...
Searching...
No Matches
pin_layout_cache.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) 2024 KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, you may find one here:
18 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19 * or you may search the http://www.gnu.org website for the version 2 license,
20 * or you may write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 */
23
24#pragma once
25
26#include <optional>
27
28#include <geometry/circle.h>
29#include <geometry/seg.h>
30#include <math/box2.h>
31#include <sch_pin.h>
32
33
35
51{
52public:
53 PIN_LAYOUT_CACHE( const SCH_PIN& aPin );
54
56 {
57 NAME = 1,
58 NUMBER = 2,
60
62 };
63
67 void MarkDirty( int aFlags );
68
69 void SetRenderParameters( int aNameThickness, int aNumberThickness, bool aShowElectricalType,
70 bool aShowAltIcons );
71
75 BOX2I GetPinBoundingBox( bool aIncludeLabelsOnInvisiblePins, bool aIncludeNameAndNumber,
76 bool aIncludeElectricalType );
77
82
87
92
98
99 struct TEXT_INFO
100 {
101 wxString m_Text;
108 };
109
115 std::optional<TEXT_INFO> GetPinNameInfo( int aShadowWidth );
116 std::optional<TEXT_INFO> GetPinNumberInfo( int aShadowWidth );
117 std::optional<TEXT_INFO> GetPinElectricalTypeInfo( int aShadowWidth );
118
119private:
120
121 bool isDirty( int aMask ) const
122 {
123 return m_dirtyFlags & aMask;
124 }
125
126 void setClean( int aMask )
127 {
128 m_dirtyFlags &= ~aMask;
129 }
130
135 {
137 int m_FontSize = 0;
139 };
140
141 static void recomputeExtentsCache( bool aDefinitelyDirty, KIFONT::FONT* aFont, int aSize,
142 const wxString& aText, const KIFONT::METRICS& aFontMetrics,
143 TEXT_EXTENTS_CACHE& aCache );
144
148 void recomputeCaches();
149
153 void transformBoxForPin( BOX2I& aBox ) const;
154
160 void transformTextForPin( TEXT_INFO& aTextInfo ) const;
161
165 int getPinTextOffset() const;
166
176
179
182
183 // The schematic settings if there are any
185
187
188 // Cached render parameters
193 bool m_showAltIcons = false;
194
195 // Various cache members
199};
std::optional< BOX2I > OPT_BOX2I
Definition: box2.h:926
Represent basic circle geometry with utility geometry functions.
Definition: circle.h:33
FONT is an abstract base class for both outline and stroke fonts.
Definition: font.h:131
A pin layout helper is a class that manages the layout of the parts of a pin on a schematic symbol:
OPT_BOX2I getUntransformedPinNameBox() const
Get the untransformd text box in the default orientation.
TEXT_EXTENTS_CACHE m_nameExtentsCache
void transformTextForPin(TEXT_INFO &aTextInfo) const
Transform text info to suit a pin's.
OPT_BOX2I GetAltIconBBox()
Get the box of the alt mode icon, if there is one.
void transformBoxForPin(BOX2I &aBox) const
Transform a box (in-place) to the pin's orientation.
void recomputeCaches()
Recompute all the caches that have become dirty.
const SCHEMATIC_SETTINGS * m_schSettings
OPT_BOX2I GetPinNumberBBox()
Get the bounding box of the pin number, if there is one.
TEXT_EXTENTS_CACHE m_typeExtentsCache
BOX2I GetPinBoundingBox(bool aIncludeLabelsOnInvisiblePins, bool aIncludeNameAndNumber, bool aIncludeElectricalType)
Get the bounding box of the pin itself.
TEXT_EXTENTS_CACHE m_numExtentsCache
void setClean(int aMask)
OPT_BOX2I getUntransformedPinTypeBox() const
std::optional< TEXT_INFO > GetPinNameInfo(int aShadowWidth)
Get the text info for the pin name.
static void recomputeExtentsCache(bool aDefinitelyDirty, KIFONT::FONT *aFont, int aSize, const wxString &aText, const KIFONT::METRICS &aFontMetrics, TEXT_EXTENTS_CACHE &aCache)
std::optional< TEXT_INFO > GetPinElectricalTypeInfo(int aShadowWidth)
bool isDirty(int aMask) const
CIRCLE GetDanglingIndicator() const
Gets the dangling indicator geometry for this pin, if the pin were to be dangling.
std::optional< TEXT_INFO > GetPinNumberInfo(int aShadowWidth)
OPT_BOX2I GetPinNameBBox()
Get the bounding box of the pin name, if there is one.
void MarkDirty(int aFlags)
Recompute all the layout information.
void SetRenderParameters(int aNameThickness, int aNumberThickness, bool aShowElectricalType, bool aShowAltIcons)
OPT_BOX2I getUntransformedAltIconBox() const
Pin type decoration if any.
int getPinTextOffset() const
Get the current pin text offset.
OPT_BOX2I getUntransformedDecorationBox() const
const SCH_PIN & m_pin
The pin in question.
OPT_BOX2I getUntransformedPinNumberBox() const
These are loaded from Eeschema settings but then overwritten by the project settings.
Cached extent of a text item.
GR_TEXT_H_ALIGN_T
GR_TEXT_V_ALIGN_T