KiCad PCB EDA Suite
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages Concepts
pcb_text.cpp
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) 2012 Jean-Pierre Charras, jean-pierre.charras@ujf-grenoble.fr
5 * Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
6 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, you may find one here:
20 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
21 * or you may search the http://www.gnu.org website for the version 2 license,
22 * or you may write to the Free Software Foundation, Inc.,
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24 */
25
26#include <google/protobuf/any.pb.h>
27
28#include <advanced_config.h>
29#include <pcb_edit_frame.h>
30#include <base_units.h>
31#include <bitmaps.h>
32#include <board.h>
34#include <core/mirror.h>
35#include <footprint.h>
36#include <pcb_text.h>
37#include <pcb_painter.h>
38#include <trigo.h>
39#include <string_utils.h>
41#include <callback_gal.h>
43#include <api/api_enums.h>
44#include <api/api_utils.h>
45#include <api/board/board_types.pb.h>
46
47
49 BOARD_ITEM( parent, idtype ),
51{
52 SetMultilineAllowed( true );
53}
54
55
57 BOARD_ITEM( aParent, idtype ),
59{
60 SetKeepUpright( true );
61
62 // Set text thickness to a default value
65
66 if( aParent )
67 {
68 SetTextPos( aParent->GetPosition() );
69
70 // N.B. Do not automatically set text effects
71 // These are optional in the file format and so need to be defaulted
72 // to off.
73 if( IsBackLayer( aParent->GetLayer() ) )
75 }
76}
77
78
80{
81}
82
83
84void PCB_TEXT::CopyFrom( const BOARD_ITEM* aOther )
85{
86 wxCHECK( aOther && aOther->Type() == PCB_TEXT_T, /* void */ );
87 *this = *static_cast<const PCB_TEXT*>( aOther );
88}
89
90
91void PCB_TEXT::Serialize( google::protobuf::Any &aContainer ) const
92{
93 using namespace kiapi::common;
94 kiapi::board::types::BoardText boardText;
95
96 boardText.mutable_id()->set_value( m_Uuid.AsStdString() );
97 boardText.set_layer( ToProtoEnum<PCB_LAYER_ID, kiapi::board::types::BoardLayer>( GetLayer() ) );
98 boardText.set_knockout( IsKnockout() );
99 boardText.set_locked( IsLocked() ? types::LockedState::LS_LOCKED
100 : types::LockedState::LS_UNLOCKED );
101
102 google::protobuf::Any any;
103 EDA_TEXT::Serialize( any );
104 any.UnpackTo( boardText.mutable_text() );
105
106 // Some of the common Text message fields are not stored in EDA_TEXT
107 types::Text* text = boardText.mutable_text();
108
109 PackVector2( *text->mutable_position(), GetPosition() );
110
111 aContainer.PackFrom( boardText );
112}
113
114
115bool PCB_TEXT::Deserialize( const google::protobuf::Any &aContainer )
116{
117 using namespace kiapi::common;
118 kiapi::board::types::BoardText boardText;
119
120 if( !aContainer.UnpackTo( &boardText ) )
121 return false;
122
123 SetLayer( FromProtoEnum<PCB_LAYER_ID, kiapi::board::types::BoardLayer>( boardText.layer() ) );
124 const_cast<KIID&>( m_Uuid ) = KIID( boardText.id().value() );
125 SetIsKnockout( boardText.knockout() );
126 SetLocked( boardText.locked() == types::LockedState::LS_LOCKED );
127
128 google::protobuf::Any any;
129 any.PackFrom( boardText.text() );
131
132 const types::Text& text = boardText.text();
133
134 SetPosition( UnpackVector2( text.position() ) );
135
136 return true;
137}
138
139
140wxString PCB_TEXT::GetShownText( bool aAllowExtraText, int aDepth ) const
141{
142 const FOOTPRINT* parentFootprint = GetParentFootprint();
143 const BOARD* board = GetBoard();
144
145 std::function<bool( wxString* )> resolver =
146 [&]( wxString* token ) -> bool
147 {
148 if( parentFootprint && parentFootprint->ResolveTextVar( token, aDepth + 1 ) )
149 return true;
150
151 if( token->IsSameAs( wxT( "LAYER" ) ) )
152 {
153 *token = GetLayerName();
154 return true;
155 }
156
157 // board can be null in some cases when saving a footprint in FP editor
158 if( board && board->ResolveTextVar( token, aDepth + 1 ) )
159 return true;
160
161 return false;
162 };
163
164 wxString text = EDA_TEXT::GetShownText( aAllowExtraText, aDepth );
165
166 if( HasTextVars() )
167 {
168 if( aDepth < ADVANCED_CFG::GetCfg().m_ResolveTextRecursionDepth )
170 }
171
172 return text;
173}
174
175
176bool PCB_TEXT::Matches( const EDA_SEARCH_DATA& aSearchData, void* aAuxData ) const
177{
178 return BOARD_ITEM::Matches( UnescapeString( GetText() ), aSearchData );
179}
180
181
183{
184 EDA_ANGLE rotation = GetTextAngle();
185
187 {
188 // Keep angle between ]-90..90] deg. Otherwise the text is not easy to read
189 while( rotation > ANGLE_90 )
190 rotation -= ANGLE_180;
191
192 while( rotation <= -ANGLE_90 )
193 rotation += ANGLE_180;
194 }
195 else
196 {
197 rotation.Normalize();
198 }
199
200 return rotation;
201}
202
203
205{
206 return GetBoundingBox();
207}
208
209
210std::vector<int> PCB_TEXT::ViewGetLayers() const
211{
212 if( IsLocked() )
214
215 return { GetLayer() };
216}
217
218
219double PCB_TEXT::ViewGetLOD( int aLayer, const KIGFX::VIEW* aView ) const
220{
221 if( !aView )
222 return LOD_SHOW;
223
224 KIGFX::PCB_PAINTER& painter = static_cast<KIGFX::PCB_PAINTER&>( *aView->GetPainter() );
225 KIGFX::PCB_RENDER_SETTINGS& renderSettings = *painter.GetSettings();
226
227 if( !aView->IsLayerVisible( GetLayer() ) )
228 return LOD_HIDE;
229
230 if( aLayer == LAYER_LOCKED_ITEM_SHADOW )
231 {
232 // Hide shadow on dimmed tracks
233 if( renderSettings.GetHighContrast() )
234 {
235 if( m_layer != renderSettings.GetPrimaryHighContrastLayer() )
236 return LOD_HIDE;
237 }
238 }
239
240 if( FOOTPRINT* parentFP = GetParentFootprint() )
241 {
242 // Handle Render tab switches
243 if( GetText() == wxT( "${VALUE}" ) )
244 {
245 if( !aView->IsLayerVisible( LAYER_FP_VALUES ) )
246 return LOD_HIDE;
247 }
248
249 if( GetText() == wxT( "${REFERENCE}" ) )
250 {
251 if( !aView->IsLayerVisible( LAYER_FP_REFERENCES ) )
252 return LOD_HIDE;
253 }
254
255 if( parentFP->GetLayer() == F_Cu && !aView->IsLayerVisible( LAYER_FOOTPRINTS_FR ) )
256 return LOD_HIDE;
257
258 if( parentFP->GetLayer() == B_Cu && !aView->IsLayerVisible( LAYER_FOOTPRINTS_BK ) )
259 return LOD_HIDE;
260
261 if( !aView->IsLayerVisible( LAYER_FP_TEXT ) )
262 return LOD_HIDE;
263 }
264
265 return LOD_SHOW;
266}
267
268
269void PCB_TEXT::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList )
270{
271 FOOTPRINT* parentFP = GetParentFootprint();
272
273 if( parentFP && aFrame->GetName() == PCB_EDIT_FRAME_NAME )
274 aList.emplace_back( _( "Footprint" ), parentFP->GetReference() );
275
276 // Don't use GetShownText() here; we want to show the user the variable references
277 if( parentFP )
278 aList.emplace_back( _( "Text" ), KIUI::EllipsizeStatusText( aFrame, GetText() ) );
279 else
280 aList.emplace_back( _( "PCB Text" ), KIUI::EllipsizeStatusText( aFrame, GetText() ) );
281
282 if( parentFP )
283 aList.emplace_back( _( "Type" ), GetTextTypeDescription() );
284
285 if( aFrame->GetName() == PCB_EDIT_FRAME_NAME && IsLocked() )
286 aList.emplace_back( _( "Status" ), _( "Locked" ) );
287
288 aList.emplace_back( _( "Layer" ), GetLayerName() );
289
290 aList.emplace_back( _( "Mirror" ), IsMirrored() ? _( "Yes" ) : _( "No" ) );
291
292 aList.emplace_back( _( "Angle" ), wxString::Format( wxT( "%g" ), GetTextAngle().AsDegrees() ) );
293
294 aList.emplace_back( _( "Font" ), GetFont() ? GetFont()->GetName() : _( "Default" ) );
295 aList.emplace_back( _( "Thickness" ), aFrame->MessageTextFromValue( GetTextThickness() ) );
296 aList.emplace_back( _( "Width" ), aFrame->MessageTextFromValue( GetTextWidth() ) );
297 aList.emplace_back( _( "Height" ), aFrame->MessageTextFromValue( GetTextHeight() ) );
298}
299
300
302{
304}
305
306
308{
309 SetTextSize( settings.GetTextSize( GetLayer() ) );
311 SetItalic( settings.GetTextItalic( GetLayer() ) );
312 SetKeepUpright( settings.GetTextUpright( GetLayer() ) );
314}
315
316
318{
319 if( !IsKeepUpright() )
320 return;
321
322 EDA_ANGLE newAngle = GetTextAngle();
323 newAngle.Normalize();
324
325 bool needsFlipped = newAngle >= ANGLE_180;
326
327 if( needsFlipped )
328 {
330 SetVertJustify( static_cast<GR_TEXT_V_ALIGN_T>( -GetVertJustify() ) );
331 newAngle += ANGLE_180;
332 newAngle.Normalize();
333 SetTextAngle( newAngle );
334 }
335}
336
337
339{
340 EDA_ANGLE angle = GetDrawRotation();
341 BOX2I rect = GetTextBox();
342
343 if( IsKnockout() )
344 rect.Inflate( getKnockoutMargin() );
345
346 if( !angle.IsZero() )
347 rect = rect.GetBoundingBoxRotated( GetTextPos(), angle );
348
349 return rect;
350}
351
352
353bool PCB_TEXT::TextHitTest( const VECTOR2I& aPoint, int aAccuracy ) const
354{
355 int accuracy = aAccuracy;
356
357 if( IsKnockout() )
359
360 return EDA_TEXT::TextHitTest( aPoint, accuracy );
361}
362
363
364bool PCB_TEXT::TextHitTest( const BOX2I& aRect, bool aContains, int aAccuracy ) const
365{
366 BOX2I rect = aRect;
367
368 rect.Inflate( aAccuracy );
369
370 if( aContains )
371 return rect.Contains( GetBoundingBox() );
372
373 return rect.Intersects( GetBoundingBox() );
374}
375
376
377void PCB_TEXT::Rotate( const VECTOR2I& aRotCentre, const EDA_ANGLE& aAngle )
378{
379 VECTOR2I pt = GetTextPos();
380 RotatePoint( pt, aRotCentre, aAngle );
381 SetTextPos( pt );
382
383 EDA_ANGLE new_angle = GetTextAngle() + aAngle;
384 new_angle.Normalize();
385 SetTextAngle( new_angle );
386}
387
388
389void PCB_TEXT::Mirror( const VECTOR2I& aCentre, FLIP_DIRECTION aFlipDirection )
390{
391 // the position and justification are mirrored, but not the text itself
392
393 if( aFlipDirection == FLIP_DIRECTION::LEFT_RIGHT )
394 {
397
398 SetTextY( MIRRORVAL( GetTextPos().y, aCentre.y ) );
399 }
400 else
401 {
404
405 SetTextX( MIRRORVAL( GetTextPos().x, aCentre.x ) );
406 }
407}
408
409
410void PCB_TEXT::Flip( const VECTOR2I& aCentre, FLIP_DIRECTION aFlipDirection )
411{
412 if( aFlipDirection == FLIP_DIRECTION::LEFT_RIGHT )
413 {
414 SetTextX( MIRRORVAL( GetTextPos().x, aCentre.x ) );
416 }
417 else
418 {
419 SetTextY( MIRRORVAL( GetTextPos().y, aCentre.y ) );
421 }
422
424
425 if( IsSideSpecific() )
427}
428
429
431{
432 return _( "Text" );
433}
434
435
436wxString PCB_TEXT::GetItemDescription( UNITS_PROVIDER* aUnitsProvider, bool aFull ) const
437{
438 wxString content = aFull ? GetShownText( false ) : KIUI::EllipsizeMenuText( GetText() );
439
440 if( FOOTPRINT* parentFP = GetParentFootprint() )
441 {
442 wxString ref = parentFP->GetReference();
443 return wxString::Format( _( "Footprint text of %s (%s)" ), ref, content );
444 }
445
446 return wxString::Format( _( "PCB text '%s' on %s" ), content, GetLayerName() );
447}
448
449
451{
452 return BITMAPS::text;
453}
454
455
457{
458 return new PCB_TEXT( *this );
459}
460
461
463{
464 assert( aImage->Type() == PCB_TEXT_T );
465
466 std::swap( *((PCB_TEXT*) this), *((PCB_TEXT*) aImage) );
467}
468
469
470std::shared_ptr<SHAPE> PCB_TEXT::GetEffectiveShape( PCB_LAYER_ID aLayer, FLASHING aFlash ) const
471{
472 if( IsKnockout() )
473 {
474 SHAPE_POLY_SET poly;
475
476 TransformTextToPolySet( poly, 0, GetBoard()->GetDesignSettings().m_MaxError, ERROR_INSIDE );
477
478 return std::make_shared<SHAPE_POLY_SET>( poly );
479 }
480
481 return GetEffectiveTextShape();
482}
483
484
485void PCB_TEXT::buildBoundingHull( SHAPE_POLY_SET* aBuffer, const SHAPE_POLY_SET& aRenderedText,
486 int aClearance ) const
487{
488 SHAPE_POLY_SET poly( aRenderedText );
489
490 poly.Rotate( -GetDrawRotation(), GetDrawPos() );
491
492 BOX2I rect = poly.BBox( aClearance );
493 VECTOR2I corners[4];
494
495 corners[0].x = rect.GetOrigin().x;
496 corners[0].y = rect.GetOrigin().y;
497 corners[1].y = corners[0].y;
498 corners[1].x = rect.GetRight();
499 corners[2].x = corners[1].x;
500 corners[2].y = rect.GetBottom();
501 corners[3].y = corners[2].y;
502 corners[3].x = corners[0].x;
503
504 aBuffer->NewOutline();
505
506 for( VECTOR2I& corner : corners )
507 {
508 RotatePoint( corner, GetDrawPos(), GetDrawRotation() );
509 aBuffer->Append( corner.x, corner.y );
510 }
511}
512
513
514void PCB_TEXT::TransformTextToPolySet( SHAPE_POLY_SET& aBuffer, int aClearance, int aMaxError,
515 ERROR_LOC aErrorLoc ) const
516{
518 KIFONT::FONT* font = getDrawFont();
519 int penWidth = GetEffectiveTextPenWidth();
521 wxString shownText = GetShownText( true );
522
523 attrs.m_Angle = GetDrawRotation();
524
525 // The polygonal shape of a text can have many basic shapes, so combining these shapes can
526 // be very useful to create a final shape with a lot less vertices to speedup calculations.
527 // Simplify shapes is not usually always efficient, but in this case it is.
528 SHAPE_POLY_SET textShape;
529
530 CALLBACK_GAL callback_gal( empty_opts,
531 // Stroke callback
532 [&]( const VECTOR2I& aPt1, const VECTOR2I& aPt2 )
533 {
534 TransformOvalToPolygon( textShape, aPt1, aPt2, penWidth, aMaxError, aErrorLoc );
535 },
536 // Triangulation callback
537 [&]( const VECTOR2I& aPt1, const VECTOR2I& aPt2, const VECTOR2I& aPt3 )
538 {
539 textShape.NewOutline();
540
541 for( const VECTOR2I& point : { aPt1, aPt2, aPt3 } )
542 textShape.Append( point.x, point.y );
543 } );
544
545 if( auto* cache = GetRenderCache( font, shownText ) )
546 callback_gal.DrawGlyphs( *cache );
547 else
548 font->Draw( &callback_gal, shownText, GetTextPos(), attrs, GetFontMetrics() );
549
550 textShape.Simplify();
551
552 if( IsKnockout() )
553 {
554 SHAPE_POLY_SET finalPoly;
555 int margin = GetKnockoutTextMargin( attrs.m_Size, penWidth );
556
557 buildBoundingHull( &finalPoly, textShape, margin + aClearance );
558 finalPoly.BooleanSubtract( textShape );
559
560 aBuffer.Append( finalPoly );
561 }
562 else
563 {
564 if( aClearance > 0 || aErrorLoc == ERROR_OUTSIDE )
565 {
566 if( aErrorLoc == ERROR_OUTSIDE )
567 aClearance += aMaxError;
568
569 textShape.Inflate( aClearance, CORNER_STRATEGY::ROUND_ALL_CORNERS, aMaxError );
570 }
571
572 aBuffer.Append( textShape );
573 }
574}
575
576
578 int aClearance, int aMaxError, ERROR_LOC aErrorLoc,
579 bool aIgnoreLineWidth ) const
580{
581 SHAPE_POLY_SET poly;
582
583 TransformTextToPolySet( poly, 0, aMaxError, aErrorLoc );
584
585 buildBoundingHull( &aBuffer, poly, aClearance );
586}
587
588
589bool PCB_TEXT::operator==( const BOARD_ITEM& aBoardItem ) const
590{
591 if( aBoardItem.Type() != Type() )
592 return false;
593
594 const PCB_TEXT& other = static_cast<const PCB_TEXT&>( aBoardItem );
595
596 return *this == other;
597}
598
599
600bool PCB_TEXT::operator==( const PCB_TEXT& aOther ) const
601{
602 return EDA_TEXT::operator==( aOther );
603}
604
605
606double PCB_TEXT::Similarity( const BOARD_ITEM& aOther ) const
607{
608 if( aOther.Type() != Type() )
609 return 0.0;
610
611 const PCB_TEXT& other = static_cast<const PCB_TEXT&>( aOther );
612
613 return EDA_TEXT::Similarity( other );
614}
615
616
617static struct PCB_TEXT_DESC
618{
620 {
627
628 propMgr.Mask( TYPE_HASH( PCB_TEXT ), TYPE_HASH( EDA_TEXT ), _HKI( "Color" ) );
629
630 propMgr.AddProperty( new PROPERTY<PCB_TEXT, bool, BOARD_ITEM>( _HKI( "Knockout" ),
632 _HKI( "Text Properties" ) );
633
634 propMgr.AddProperty( new PROPERTY<PCB_TEXT, bool, EDA_TEXT>( _HKI( "Keep Upright" ),
636 _HKI( "Text Properties" ) );
637
638 auto isFootprintText =
639 []( INSPECTABLE* aItem ) -> bool
640 {
641 if( PCB_TEXT* text = dynamic_cast<PCB_TEXT*>( aItem ) )
642 return text->GetParentFootprint();
643
644 return false;
645 };
646
648 _HKI( "Keep Upright" ), isFootprintText );
649
650 propMgr.Mask( TYPE_HASH( PCB_TEXT ), TYPE_HASH( EDA_TEXT ), _HKI( "Hyperlink" ) );
651 }
ERROR_LOC
When approximating an arc or circle, should the error be placed on the outside or inside of the curve...
Definition: approximation.h:32
@ ERROR_OUTSIDE
Definition: approximation.h:33
@ ERROR_INSIDE
Definition: approximation.h:34
constexpr EDA_IU_SCALE pcbIUScale
Definition: base_units.h:108
BITMAPS
A list of all bitmap identifiers.
Definition: bitmaps_list.h:33
#define DEFAULT_TEXT_WIDTH
static const ADVANCED_CFG & GetCfg()
Get the singleton instance's config, which is shared by all consumers.
Container for design settings for a BOARD object.
bool GetTextUpright(PCB_LAYER_ID aLayer) const
int GetTextThickness(PCB_LAYER_ID aLayer) const
Return the default text thickness from the layer class for the given layer.
bool GetTextItalic(PCB_LAYER_ID aLayer) const
VECTOR2I GetTextSize(PCB_LAYER_ID aLayer) const
Return the default text size from the layer class for the given layer.
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:78
virtual PCB_LAYER_ID GetLayer() const
Return the primary layer this item is on.
Definition: board_item.h:235
virtual void SetLocked(bool aLocked)
Definition: board_item.h:326
PCB_LAYER_ID m_layer
Definition: board_item.h:451
virtual bool IsKnockout() const
Definition: board_item.h:322
virtual void SetIsKnockout(bool aKnockout)
Definition: board_item.h:323
virtual void SetLayer(PCB_LAYER_ID aLayer)
Set the layer this item is on.
Definition: board_item.h:286
virtual const BOARD * GetBoard() const
Return the BOARD in which this BOARD_ITEM resides, or NULL if none.
Definition: board_item.cpp:54
FOOTPRINT * GetParentFootprint() const
Definition: board_item.cpp:305
const KIFONT::METRICS & GetFontMetrics() const
Definition: board_item.cpp:107
virtual bool IsLocked() const
Definition: board_item.cpp:82
bool IsSideSpecific() const
Definition: board_item.cpp:156
wxString GetLayerName() const
Return the name of the PCB layer on which the item resides.
Definition: board_item.cpp:146
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:297
bool ResolveTextVar(wxString *token, int aDepth) const
Definition: board.cpp:434
constexpr BOX2< Vec > & Inflate(coord_type dx, coord_type dy)
Inflates the rectangle horizontally by dx and vertically by dy.
Definition: box2.h:558
constexpr bool Contains(const Vec &aPoint) const
Definition: box2.h:168
constexpr const Vec & GetOrigin() const
Definition: box2.h:210
const BOX2< Vec > GetBoundingBoxRotated(const VECTOR2I &aRotCenter, const EDA_ANGLE &aAngle) const
Useful to calculate bounding box of rotated items, when rotation is not cardinal.
Definition: box2.h:720
constexpr coord_type GetRight() const
Definition: box2.h:217
constexpr bool Intersects(const BOX2< Vec > &aRect) const
Definition: box2.h:311
constexpr coord_type GetBottom() const
Definition: box2.h:222
EDA_ANGLE Normalize()
Definition: eda_angle.h:221
bool IsZero() const
Definition: eda_angle.h:133
The base class for create windows for drawing purpose.
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:95
const KIID m_Uuid
Definition: eda_item.h:494
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:107
virtual bool Matches(const EDA_SEARCH_DATA &aSearchData, void *aAuxData) const
Compare the item against the search criteria in aSearchData.
Definition: eda_item.h:382
A mix-in class (via multiple inheritance) that handles texts such as labels, parts,...
Definition: eda_text.h:80
int GetTextHeight() const
Definition: eda_text.h:254
void Serialize(google::protobuf::Any &aContainer) const override
Serializes this object to the given Any message.
Definition: eda_text.cpp:187
const VECTOR2I & GetTextPos() const
Definition: eda_text.h:260
const EDA_ANGLE & GetTextAngle() const
Definition: eda_text.h:134
void SetTextSize(VECTOR2I aNewSize, bool aEnforceMinTextSize=true)
Definition: eda_text.cpp:526
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition: eda_text.h:98
bool IsKeepUpright() const
Definition: eda_text.h:193
void SetTextPos(const VECTOR2I &aPoint)
Definition: eda_text.cpp:571
void SetTextX(int aX)
Definition: eda_text.cpp:577
bool Deserialize(const google::protobuf::Any &aContainer) override
Deserializes the given protobuf message into this object.
Definition: eda_text.cpp:223
KIFONT::FONT * GetFont() const
Definition: eda_text.h:234
BOX2I GetTextBox(int aLine=-1) const
Useful in multiline texts to calculate the full text or a line area (for zones filling,...
Definition: eda_text.cpp:723
void SetMirrored(bool isMirrored)
Definition: eda_text.cpp:386
void SetTextY(int aY)
Definition: eda_text.cpp:583
std::vector< std::unique_ptr< KIFONT::GLYPH > > * GetRenderCache(const KIFONT::FONT *aFont, const wxString &forResolvedText, const VECTOR2I &aOffset={ 0, 0 }) const
Definition: eda_text.cpp:664
virtual VECTOR2I GetDrawPos() const
Definition: eda_text.h:366
int GetTextWidth() const
Definition: eda_text.h:251
void SetVertJustify(GR_TEXT_V_ALIGN_T aType)
Definition: eda_text.cpp:410
GR_TEXT_H_ALIGN_T GetHorizJustify() const
Definition: eda_text.h:187
bool HasTextVars() const
Indicates the ShownText has text var references which need to be processed.
Definition: eda_text.h:117
virtual KIFONT::FONT * getDrawFont() const
Definition: eda_text.cpp:634
double Similarity(const EDA_TEXT &aOther) const
Definition: eda_text.cpp:1279
void SetTextThickness(int aWidth)
The TextThickness is that set by the user.
Definition: eda_text.cpp:284
virtual bool TextHitTest(const VECTOR2I &aPoint, int aAccuracy=0) const
Test if aPoint is within the bounds of this object.
Definition: eda_text.cpp:853
const TEXT_ATTRIBUTES & GetAttributes() const
Definition: eda_text.h:218
bool IsMirrored() const
Definition: eda_text.h:177
int GetEffectiveTextPenWidth(int aDefaultPenWidth=0) const
The EffectiveTextPenWidth uses the text thickness if > 1 or aDefaultPenWidth.
Definition: eda_text.cpp:458
std::shared_ptr< SHAPE_COMPOUND > GetEffectiveTextShape(bool aTriangulate=true, const BOX2I &aBBox=BOX2I(), const EDA_ANGLE &aAngle=ANGLE_0) const
build a list of segments (SHAPE_SEGMENT) to describe a text shape.
Definition: eda_text.cpp:1120
void SetKeepUpright(bool aKeepUpright)
Definition: eda_text.cpp:418
GR_TEXT_V_ALIGN_T GetVertJustify() const
Definition: eda_text.h:190
virtual wxString GetShownText(bool aAllowExtraText, int aDepth=0) const
Return the string actually shown after processing of the base text.
Definition: eda_text.h:109
virtual void SetTextAngle(const EDA_ANGLE &aAngle)
Definition: eda_text.cpp:292
int GetTextThickness() const
Definition: eda_text.h:126
void SetItalic(bool aItalic)
Set the text to be italic - this will also update the font if needed.
Definition: eda_text.cpp:300
bool operator==(const EDA_TEXT &aRhs) const
Definition: eda_text.h:382
void SetMultilineAllowed(bool aAllow)
Definition: eda_text.cpp:394
VECTOR2I GetTextSize() const
Definition: eda_text.h:248
void SetHorizJustify(GR_TEXT_H_ALIGN_T aType)
Definition: eda_text.cpp:402
bool ResolveTextVar(wxString *token, int aDepth=0) const
Resolve any references to system tokens supported by the component.
Definition: footprint.cpp:992
PCB_LAYER_ID GetLayer() const override
Return the primary layer this item is on.
Definition: footprint.h:241
const wxString & GetReference() const
Definition: footprint.h:619
VECTOR2I GetPosition() const override
Definition: footprint.h:229
Class that other classes need to inherit from, in order to be inspectable.
Definition: inspectable.h:37
FONT is an abstract base class for both outline and stroke fonts.
Definition: font.h:131
void Draw(KIGFX::GAL *aGal, const wxString &aText, const VECTOR2I &aPosition, const VECTOR2I &aCursor, const TEXT_ATTRIBUTES &aAttributes, const METRICS &aFontMetrics) const
Draw a string.
Definition: font.cpp:250
virtual void DrawGlyphs(const std::vector< std::unique_ptr< KIFONT::GLYPH > > &aGlyphs)
Draw polygons representing font glyphs.
Contains methods for drawing PCB-specific items.
Definition: pcb_painter.h:181
virtual PCB_RENDER_SETTINGS * GetSettings() override
Return a pointer to current settings that are going to be used when drawing items.
Definition: pcb_painter.h:186
PCB specific render settings.
Definition: pcb_painter.h:79
PCB_LAYER_ID GetPrimaryHighContrastLayer() const
Return the board layer which is in high-contrast mode.
bool GetHighContrast() const
static constexpr double LOD_HIDE
Return this constant from ViewGetLOD() to hide the item unconditionally.
Definition: view_item.h:174
static constexpr double LOD_SHOW
Return this constant from ViewGetLOD() to show the item unconditionally.
Definition: view_item.h:179
Hold a (potentially large) number of VIEW_ITEMs and renders them on a graphics device provided by the...
Definition: view.h:67
bool IsLayerVisible(int aLayer) const
Return information about visibility of a particular layer.
Definition: view.h:418
PAINTER * GetPainter() const
Return the painter object used by the view for drawing #VIEW_ITEMS.
Definition: view.h:216
Definition: kiid.h:49
std::string AsStdString() const
Definition: kiid.cpp:252
void CopyFrom(const BOARD_ITEM *aOther) override
Definition: pcb_text.cpp:84
void GetMsgPanelInfo(EDA_DRAW_FRAME *aFrame, std::vector< MSG_PANEL_ITEM > &aList) override
Populate aList of MSG_PANEL_ITEM objects with it's internal state for display purposes.
Definition: pcb_text.cpp:269
double Similarity(const BOARD_ITEM &aBoardItem) const override
Return a measure of how likely the other object is to represent the same object.
Definition: pcb_text.cpp:606
void TransformShapeToPolygon(SHAPE_POLY_SET &aBuffer, PCB_LAYER_ID aLayer, int aClearance, int aMaxError, ERROR_LOC aErrorLoc, bool aIgnoreLineWidth=false) const override
Convert the item shape to a closed polygon.
Definition: pcb_text.cpp:577
wxString GetItemDescription(UNITS_PROVIDER *aUnitsProvider, bool aFull) const override
Return a user-visible description string of this item.
Definition: pcb_text.cpp:436
const BOX2I ViewBBox() const override
Return the bounding box of the item covering all its layers.
Definition: pcb_text.cpp:204
void Flip(const VECTOR2I &aCentre, FLIP_DIRECTION aFlipDirection) override
Flip this object, i.e.
Definition: pcb_text.cpp:410
virtual void swapData(BOARD_ITEM *aImage) override
Definition: pcb_text.cpp:462
virtual std::shared_ptr< SHAPE > GetEffectiveShape(PCB_LAYER_ID aLayer=UNDEFINED_LAYER, FLASHING aFlash=FLASHING::DEFAULT) const override
Some pad shapes can be complex (rounded/chamfered rectangle), even without considering custom shapes.
Definition: pcb_text.cpp:470
void KeepUpright()
Called when rotating the parent footprint.
Definition: pcb_text.cpp:317
bool Matches(const EDA_SEARCH_DATA &aSearchData, void *aAuxData) const override
Compare the item against the search criteria in aSearchData.
Definition: pcb_text.cpp:176
void Serialize(google::protobuf::Any &aContainer) const override
Serializes this object to the given Any message.
Definition: pcb_text.cpp:91
wxString GetShownText(bool aAllowExtraText, int aDepth=0) const override
Return the string actually shown after processing of the base text.
Definition: pcb_text.cpp:140
void Mirror(const VECTOR2I &aCentre, FLIP_DIRECTION aFlipDirection) override
Mirror this object relative to a given horizontal axis the layer is not changed.
Definition: pcb_text.cpp:389
double ViewGetLOD(int aLayer, const KIGFX::VIEW *aView) const override
Return the level of detail (LOD) of the item.
Definition: pcb_text.cpp:219
~PCB_TEXT()
Definition: pcb_text.cpp:79
virtual VECTOR2I GetPosition() const override
Definition: pcb_text.h:84
PCB_TEXT(BOARD_ITEM *parent, KICAD_T idtype=PCB_TEXT_T)
Definition: pcb_text.cpp:48
void StyleFromSettings(const BOARD_DESIGN_SETTINGS &settings) override
Definition: pcb_text.cpp:307
bool operator==(const PCB_TEXT &aOther) const
Definition: pcb_text.cpp:600
int getKnockoutMargin() const
Definition: pcb_text.cpp:301
void TransformTextToPolySet(SHAPE_POLY_SET &aBuffer, int aClearance, int aMaxError, ERROR_LOC aErrorLoc) const
Function TransformTextToPolySet Convert the text to a polygonSet describing the actual character stro...
Definition: pcb_text.cpp:514
const BOX2I GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
Definition: pcb_text.cpp:338
virtual wxString GetTextTypeDescription() const
Definition: pcb_text.cpp:430
std::vector< int > ViewGetLayers() const override
Definition: pcb_text.cpp:210
void buildBoundingHull(SHAPE_POLY_SET *aBuffer, const SHAPE_POLY_SET &aRenderedText, int aClearance) const
Build a nominally rectangular bounding box for the rendered text.
Definition: pcb_text.cpp:485
bool TextHitTest(const VECTOR2I &aPoint, int aAccuracy=0) const override
Test if aPoint is within the bounds of this object.
Definition: pcb_text.cpp:353
virtual void SetPosition(const VECTOR2I &aPos) override
Definition: pcb_text.h:89
EDA_ITEM * Clone() const override
Create a duplicate of this item with linked list members set to NULL.
Definition: pcb_text.cpp:456
EDA_ANGLE GetDrawRotation() const override
Definition: pcb_text.cpp:182
bool Deserialize(const google::protobuf::Any &aContainer) override
Deserializes the given protobuf message into this object.
Definition: pcb_text.cpp:115
void Rotate(const VECTOR2I &aRotCentre, const EDA_ANGLE &aAngle) override
Rotate this object.
Definition: pcb_text.cpp:377
BITMAPS GetMenuImage() const override
Return a pointer to an image to be used in menus.
Definition: pcb_text.cpp:450
Provide class metadata.Helper macro to map type hashes to names.
Definition: property_mgr.h:85
void InheritsAfter(TYPE_ID aDerived, TYPE_ID aBase)
Declare an inheritance relationship between types.
void Mask(TYPE_ID aDerived, TYPE_ID aBase, const wxString &aName)
Sets a base class property as masked in a derived class.
static PROPERTY_MANAGER & Instance()
Definition: property_mgr.h:87
PROPERTY_BASE & AddProperty(PROPERTY_BASE *aProperty, const wxString &aGroup=wxEmptyString)
Register a property.
void OverrideAvailability(TYPE_ID aDerived, TYPE_ID aBase, const wxString &aName, std::function< bool(INSPECTABLE *)> aFunc)
Sets an override availability functor for a base class property of a given derived class.
void AddTypeCast(TYPE_CAST_BASE *aCast)
Register a type converter.
Represent a set of closed polygons.
void Rotate(const EDA_ANGLE &aAngle, const VECTOR2I &aCenter={ 0, 0 }) override
Rotate all vertices by a given angle.
void Inflate(int aAmount, CORNER_STRATEGY aCornerStrategy, int aMaxError, bool aSimplify=false)
Perform outline inflation/deflation.
int Append(int x, int y, int aOutline=-1, int aHole=-1, bool aAllowDuplication=false)
Appends a vertex at the end of the given outline/hole (default: the last outline)
void Simplify()
Simplify the polyset (merges overlapping polys, eliminates degeneracy/self-intersections)
int NewOutline()
Creates a new empty polygon in the set and returns its index.
void BooleanSubtract(const SHAPE_POLY_SET &b)
Perform boolean polyset difference.
const BOX2I BBox(int aClearance=0) const override
Compute a bounding box of the shape, with a margin of aClearance a collision.
wxString MessageTextFromValue(double aValue, bool aAddUnitLabel=true, EDA_DATA_TYPE aType=EDA_DATA_TYPE::DISTANCE) const
A lower-precision version of StringFromValue().
wxString ExpandTextVars(const wxString &aSource, const PROJECT *aProject, int aFlags)
Definition: common.cpp:59
void TransformOvalToPolygon(SHAPE_POLY_SET &aBuffer, const VECTOR2I &aStart, const VECTOR2I &aEnd, int aWidth, int aError, ERROR_LOC aErrorLoc, int aMinSegCount=0)
Convert a oblong shape to a polygon, using multiple segments.
#define _HKI(x)
#define _(s)
static constexpr EDA_ANGLE ANGLE_90
Definition: eda_angle.h:403
static constexpr EDA_ANGLE ANGLE_VERTICAL
Definition: eda_angle.h:398
static constexpr EDA_ANGLE ANGLE_HORIZONTAL
Definition: eda_angle.h:397
static constexpr EDA_ANGLE ANGLE_180
Definition: eda_angle.h:405
#define PCB_EDIT_FRAME_NAME
static FILENAME_RESOLVER * resolver
Definition: export_idf.cpp:53
int GetKnockoutTextMargin(const VECTOR2I &aSize, int aThickness)
Return the margin for knocking out text.
Definition: gr_text.h:95
PCB_LAYER_ID FlipLayer(PCB_LAYER_ID aLayerId, int aCopperLayersCount)
Definition: layer_id.cpp:169
FLASHING
Enum used during connectivity building to ensure we do not query connectivity while building the data...
Definition: layer_ids.h:184
bool IsBackLayer(PCB_LAYER_ID aLayerId)
Layer classification: check if it's a back layer.
Definition: layer_ids.h:788
@ LAYER_LOCKED_ITEM_SHADOW
Shadow layer for locked items.
Definition: layer_ids.h:306
@ LAYER_FOOTPRINTS_FR
Show footprints on front.
Definition: layer_ids.h:258
@ LAYER_FP_REFERENCES
Show footprints references (when texts are visible).
Definition: layer_ids.h:265
@ LAYER_FP_TEXT
Definition: layer_ids.h:239
@ LAYER_FOOTPRINTS_BK
Show footprints on back.
Definition: layer_ids.h:259
@ LAYER_FP_VALUES
Show footprints values (when texts are visible).
Definition: layer_ids.h:262
PCB_LAYER_ID
A quick note on layer IDs:
Definition: layer_ids.h:60
@ B_Cu
Definition: layer_ids.h:65
@ F_SilkS
Definition: layer_ids.h:100
@ B_SilkS
Definition: layer_ids.h:101
@ F_Cu
Definition: layer_ids.h:64
constexpr T MIRRORVAL(T aPoint, T aMirrorRef)
Returns the mirror of aPoint relative to the aMirrorRef.
Definition: mirror.h:36
FLIP_DIRECTION
Definition: mirror.h:27
KICOMMON_API wxString EllipsizeMenuText(const wxString &aString)
Ellipsize text (at the end) to be no more than 36 characters.
Definition: ui_common.cpp:215
KICOMMON_API wxString EllipsizeStatusText(wxWindow *aWindow, const wxString &aString)
Ellipsize text (at the end) to be no more than 1/3 of the window width.
Definition: ui_common.cpp:197
static struct PCB_TEXT_DESC _PCB_TEXT_DESC
#define TYPE_HASH(x)
Definition: property.h:71
#define REGISTER_TYPE(x)
Definition: property_mgr.h:371
wxString UnescapeString(const wxString &aSource)
constexpr int mmToIU(double mm) const
Definition: base_units.h:88
const int accuracy
GR_TEXT_H_ALIGN_T
This is API surface mapped to common.types.HorizontalAlignment.
GR_TEXT_V_ALIGN_T
This is API surface mapped to common.types.VertialAlignment.
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.
Definition: trigo.cpp:229
KICAD_T
The set of class identification values stored in EDA_ITEM::m_structType.
Definition: typeinfo.h:78
@ PCB_TEXT_T
class PCB_TEXT, text on a layer
Definition: typeinfo.h:92
VECTOR2< int32_t > VECTOR2I
Definition: vector2d.h:695