42 wxString number =
m_pin.GetShownNumber();
44 if( number.IsEmpty() || !
m_pin.GetParentSymbol()->GetShowPinNumbers() )
51 int length =
m_pin.GetLength();
52 int num_size =
m_pin.GetNumberTextSize();
56 info->m_Text = formatted;
57 info->m_TextSize = num_size;
64 auto estimateQABox = [&](
const wxString& txt,
int size,
bool isVertical ) ->
VECTOR2I
67 int w = (int) ( txt.Length() * size * 0.6 );
69 if( txt.Contains(
'\n' ) )
76 int lineSpacing =
KiROUND( size * 1.3 );
77 w = (int) lines.size() * lineSpacing;
79 for(
const wxString& l : lines )
80 maxLen = std::max( maxLen, l.Length() );
81 h = (int) ( maxLen * size * 0.6 );
85 int lineSpacing =
KiROUND( size * 1.3 );
86 h = (int) lines.size() * lineSpacing;
88 for(
const wxString& l : lines )
89 maxLen = std::max( maxLen, l.Length() );
90 w = (int) ( maxLen * size * 0.6 );
100 int maxHalfHeight = 0;
101 int maxHalfWidth = 0;
102 int maxFullHeight = 0;
108 wxString raw = p->GetShownNumber();
114 p->GetFontMetrics() );
116 VECTOR2I boxHoriz = estimateQABox( fmt, p->GetNumberTextSize(),
false );
117 maxHalfHeight = std::max( maxHalfHeight, boxHoriz.
y / 2 );
118 maxFullHeight = std::max( maxFullHeight, boxHoriz.
y );
122 VECTOR2I boxVert = estimateQABox( fmt, p->GetNumberTextSize(),
true );
123 maxHalfWidth = std::max( maxHalfWidth, boxVert.
x / 2 );
129 const int halfLength =
m_pin.GetLength() / 2;
133 VECTOR2I currentBox = estimateQABox( formatted,
info->m_TextSize, verticalOrient );
134 int currentHalfHeight = currentBox.
y / 2;
135 int currentHalfWidth = currentBox.
x / 2;
138 bool hasStackingNotation = number.Contains(
'[' ) || number.Contains(
',' );
145 bool showBothNameAndNumber = !
m_pin.GetShownName().IsEmpty()
151 int perpendicularOffset;
153 if( hasStackingNotation || formatted.Contains(
'\n' ) )
169 if( showBothNameAndNumber )
172 centerX = pinPos.
x + perpendicularOffset;
177 centerX = pinPos.
x - perpendicularOffset;
180 info->m_TextPosition.x = centerX;
183 info->m_TextPosition.y = pinPos.
y + halfLength;
185 info->m_TextPosition.y = pinPos.
y - halfLength;
194 bool showBothNameAndNumber = !
m_pin.GetShownName().IsEmpty()
200 if( showBothNameAndNumber )
214 info->m_TextPosition.x = pinPos.
x - halfLength;
216 info->m_TextPosition.x = pinPos.
x + halfLength;
218 info->m_TextPosition.y = centerY;
260 bool aShowElectricalType,
bool aShowAltIcons )
286 const wxString& aText,
291 if( !aDefinitelyDirty && aCache.
m_Font == aFont && aCache.
m_FontSize == aSize )
303 if( aText.StartsWith(
"[" ) && aText.EndsWith(
"]" ) && aText.Contains(
"\n" ) )
306 wxString content = aText.Mid( 1, aText.Length() - 2 );
310 if( lines.size() > 1 )
312 int lineSpacing =
KiROUND( aSize * 1.3 );
316 for(
const wxString& line : lines )
318 wxString trimmedLine = line;
319 trimmedLine.Trim(
true ).Trim(
false );
321 maxWidth = std::max( maxWidth, lineExtents.
x );
325 int totalHeight = aSize + ( lines.size() - 1 ) * lineSpacing;
328 int braceWidth = aSize / 3;
329 maxWidth += braceWidth * 2;
330 totalHeight += aSize / 3;
360 const wxString number =
m_pin.GetShownNumber();
366 const wxString
name =
m_pin.GetShownName();
371 double fontSize = std::max(
m_pin.GetNameTextSize() * 3 / 4,
schIUScale.mmToIU( 0.7 ) );
441 rotated.
x = -rotated.
x;
442 rotated.
y = -rotated.
y;
446 rotated = { baseLocal.
y, -baseLocal.
x };
450 rotated = { -baseLocal.
y, baseLocal.
x };
464 bool aIncludeNameAndNumber,
bool aIncludeElectricalType )
469 wxCHECK( libPin,
BOX2I() );
472 aIncludeElectricalType );
474 r = symbol->GetTransform().TransformCoordinate( r );
475 r.
Offset( symbol->GetPosition() );
481 bool includeName = aIncludeNameAndNumber && !
m_pin.GetShownName().IsEmpty();
482 bool includeNumber = aIncludeNameAndNumber && !
m_pin.GetShownNumber().IsEmpty();
483 bool includeType = aIncludeElectricalType;
485 if( !aIncludeLabelsOnInvisiblePins && !
m_pin.IsVisible() )
488 includeNumber =
false;
492 if(
const SYMBOL* parentSymbol =
m_pin.GetParentSymbol() )
494 if( !parentSymbol->GetShowPinNames() )
497 if( !parentSymbol->GetShowPinNumbers() )
498 includeNumber =
false;
503 const int pinLength =
m_pin.GetLength();
513 bbox.
Merge( pinBox );
518 bbox.
Merge( *decoBox );
525 bbox.
Merge( *nameBox );
530 bbox.
Merge( *altIconBox );
538 bbox.
Merge( *numBox );
546 bbox.
Merge( *typeBox );
552 if(
m_pin.IsDangling() )
582 const float offsetRatio =
590 int pinNameOffset = 0;
591 if(
const SYMBOL* parentSymbol =
m_pin.GetParentSymbol() )
593 if( parentSymbol->GetShowPinNames() )
594 pinNameOffset = parentSymbol->GetPinNameOffset();
605 const int pinLength =
m_pin.GetLength();
607 if( pinNameOffset > 0 )
630 int pinNameOffset = 0;
632 if(
const SYMBOL* parentSymbol =
m_pin.GetParentSymbol() )
634 if( parentSymbol->GetShowPinNames() )
635 pinNameOffset = parentSymbol->GetPinNameOffset();
638 const int pinLength =
m_pin.GetLength();
644 bool showBothNameAndNumber = ( pinNameOffset == 0
646 &&
m_pin.GetParentSymbol()->GetShowPinNames() );
649 if( showBothNameAndNumber )
662 box->
Move( { 0, textPos } );
692 const int iconSize = std::min(
m_pin.GetNameTextSize(),
schIUScale.mmToIU( 1.5 ) );
694 VECTOR2I c{ 0, ( nameBox->GetTop() + nameBox->GetBottom() ) / 2 };
695 if(
m_pin.GetParentSymbol()->GetPinNameOffset() > 0 )
698 c.x = nameBox->GetRight() + iconSize * 0.75;
702 c.x = nameBox->GetLeft() - iconSize * 0.75;
715 const auto makeInvertBox =
718 return BOX2I::ByCenter( { -decoSize, 0 }, { decoSize * 2, decoSize * 2 } );
721 const auto makeLowBox =
727 const auto makeClockBox =
730 return BOX2I::ByCorners( { 0, -intDecoSize }, { intDecoSize, intDecoSize } );
738 box = makeInvertBox();
742 box = makeClockBox();
746 box = makeInvertBox();
747 box->Merge( makeClockBox() );
757 box->Merge( makeClockBox() );
773 box->Move( {
m_pin.GetLength(), 0 } );
774 box->Inflate(
m_pin.GetPenWidth() / 2 );
829 if(
name.IsEmpty() || !
m_pin.GetParentSymbol()->GetShowPinNames() )
834 info->m_TextSize =
m_pin.GetNameTextSize();
838 bool nameInside =
m_pin.GetParentSymbol()->GetPinNameOffset() > 0;
843 VECTOR2I pos = {
m_pin.GetLength() +
m_pin.GetParentSymbol()->GetPinNameOffset(), 0 };
846 info->m_TextPosition = pos +
VECTOR2I{ -shadowOffset, 0 };
856 info->m_TextPosition = pos;
866 int maxHalfHeight = 0;
869 wxString n = p->GetShownName();
874 maxHalfHeight = std::max( maxHalfHeight, p->GetNameTextSize() / 2 );
879 const int halfLength =
m_pin.GetLength() / 2;
889 int centerX = pinPos.
x - perpendicularOffset;
890 info->m_TextPosition = { centerX, pinPos.
y };
893 info->m_TextPosition.y += halfLength;
895 info->m_TextPosition.y -= halfLength;
904 info->m_TextPosition = { pinPos.
x, pinPos.
y - ( maxHalfHeight +
clearance +
info->m_Thickness ) };
907 info->m_TextPosition.x -= halfLength;
909 info->m_TextPosition.x += halfLength;
924std::optional<PIN_LAYOUT_CACHE::TEXT_INFO>
933 info->m_Text =
m_pin.GetElectricalTypeName();
936 info->m_Thickness =
info->m_TextSize / 8;
945 if(
m_pin.IsDangling() )
constexpr EDA_IU_SCALE schIUScale
std::optional< BOX2I > OPT_BOX2I
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
constexpr BOX2< Vec > & Inflate(coord_type dx, coord_type dy)
Inflates the rectangle horizontally by dx and vertically by dy.
static constexpr BOX2< VECTOR2I > ByCorners(const VECTOR2I &aCorner1, const VECTOR2I &aCorner2)
constexpr BOX2< Vec > & Normalize()
Ensure that the height and width are positive.
static constexpr BOX2< VECTOR2I > ByCenter(const VECTOR2I &aCenter, const SizeVec &aSize)
constexpr BOX2< Vec > & Merge(const BOX2< Vec > &aRect)
Modify the position and size of the rectangle in order to contain aRect.
constexpr const Vec GetCenter() const
constexpr coord_type GetLeft() const
constexpr void Move(const Vec &aMoveVector)
Move the rectangle by the aMoveVector.
constexpr coord_type GetRight() const
constexpr coord_type GetTop() const
constexpr void Offset(coord_type dx, coord_type dy)
constexpr coord_type GetBottom() const
Represent basic circle geometry with utility geometry functions.
VECTOR2I Center
Public to make access simpler.
FONT is an abstract base class for both outline and stroke fonts.
static FONT * GetFont(const wxString &aFontName=wxEmptyString, bool aBold=false, bool aItalic=false, const std::vector< wxString > *aEmbeddedFiles=nullptr, bool aForDrawingSheet=false)
virtual bool IsOutline() const
VECTOR2I StringBoundaryLimits(const wxString &aText, const VECTOR2I &aSize, int aThickness, bool aBold, bool aItalic, const METRICS &aFontMetrics) const
Compute the boundary limits of aText (the bounding box of all shapes).
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.
PIN_LAYOUT_CACHE(const SCH_PIN &aPin)
bool m_showElectricalType
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
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
int getPinTextOffset() const
Get the current pin text offset.
OPT_BOX2I getUntransformedDecorationBox() const
Pin type decoration if any.
const SCH_PIN & m_pin
The pin in question.
OPT_BOX2I getUntransformedPinNumberBox() const
float m_shadowOffsetAdjust
These are loaded from Eeschema settings but then overwritten by the project settings.
Holds all the data relating to one schematic.
SCHEMATIC_SETTINGS & Settings() const
SCHEMATIC * Schematic() const
Search the item hierarchy to find a SCHEMATIC.
int GetNumberTextSize() const
int GetNameTextSize() const
const BOX2I GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
A base class for LIB_SYMBOL and SCH_SYMBOL.
int GetPinNameOffset() const
virtual std::vector< SCH_PIN * > GetPins() const =0
virtual bool GetShowPinNames() const
#define DEFAULT_TEXT_OFFSET_RATIO
Ratio of the font height to space around global labels.
static bool empty(const wxTextEntryBase *aCtrl)
static constexpr EDA_ANGLE ANGLE_90
static constexpr EDA_ANGLE ANGLE_VERTICAL
static constexpr EDA_ANGLE ANGLE_HORIZONTAL
TRANSFORM DefaultTransform
int GetPenSizeForNormal(int aTextSize)
static int externalPinDecoSize(const SCHEMATIC_SETTINGS *aSettings, const SCH_PIN &aPin)
static int internalPinDecoSize(const SCHEMATIC_SETTINGS *aSettings, const SCH_PIN &aPin)
wxString FormatStackedPinForDisplay(const wxString &aPinNumber, int aPinLength, int aTextSize, KIFONT::FONT *aFont, const KIFONT::METRICS &aFontMetrics)
PIN_ORIENTATION
The symbol library pin object orientations.
@ PIN_UP
The pin extends upwards from the connection point: Probably on the bottom side of the symbol.
@ PIN_RIGHT
The pin extends rightwards from the connection point.
@ PIN_LEFT
The pin extends leftwards from the connection point: Probably on the right side of the symbol.
@ PIN_DOWN
The pin extends downwards from the connection: Probably on the top side of the symbol.
#define TARGET_PIN_RADIUS
T * GetAppSettings(const char *aFilename)
Utility functions for working with shapes.
void wxStringSplit(const wxString &aText, wxArrayString &aStrings, wxChar aSplitter)
Split aString to a string list separated at aSplitter.
Cached extent of a text item.
GR_TEXT_H_ALIGN_T m_HAlign
constexpr GR_TEXT_H_ALIGN_T GetFlippedAlignment(GR_TEXT_H_ALIGN_T aAlign)
Get the reverse alignment: left-right are swapped, others are unchanged.
void RotatePoint(int *pX, int *pY, const EDA_ANGLE &aAngle)
Calculate the new point of coord coord pX, pY, for a rotation center 0, 0.
VECTOR2< int32_t > VECTOR2I
VECTOR2< double > VECTOR2D