KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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, [email protected]
5 * Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <[email protected]>
6 * Copyright (C) 1992-2023 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
48using namespace kiapi::common;
49
50
52 BOARD_ITEM( parent, idtype ),
54{
55 SetMultilineAllowed( true );
56}
57
58
60 BOARD_ITEM( aParent, idtype ),
62{
63 SetKeepUpright( true );
64
65 // Set text thickness to a default value
68
69 if( aParent )
70 {
71 SetTextPos( aParent->GetPosition() );
72
73 // N.B. Do not automatically set text effects
74 // These are optional in the file format and so need to be defaulted
75 // to off.
76 if( IsBackLayer( aParent->GetLayer() ) )
78 }
79}
80
81
83{
84}
85
86
87void PCB_TEXT::Serialize( google::protobuf::Any &aContainer ) const
88{
89 kiapi::board::types::Text boardText;
90 boardText.set_layer( ToProtoEnum<PCB_LAYER_ID, kiapi::board::types::BoardLayer>( GetLayer() ) );
91
92 kiapi::common::types::Text& text = *boardText.mutable_text();
93
94 text.mutable_id()->set_value( m_Uuid.AsStdString() );
95 text.mutable_position()->set_x_nm( GetPosition().x );
96 text.mutable_position()->set_y_nm( GetPosition().y );
97 text.set_text( GetText().ToStdString() );
98 text.set_hyperlink( GetHyperlink().ToStdString() );
99 text.set_locked( IsLocked() ? types::LockedState::LS_LOCKED
100 : types::LockedState::LS_UNLOCKED );
101
102 kiapi::common::types::TextAttributes* attrs = text.mutable_attributes();
103
104 if( GetFont() )
105 attrs->set_font_name( GetFont()->GetName().ToStdString() );
106
107 attrs->set_horizontal_alignment(
108 ToProtoEnum<GR_TEXT_H_ALIGN_T, types::HorizontalAlignment>( GetHorizJustify() ) );
109
110 attrs->set_vertical_alignment(
111 ToProtoEnum<GR_TEXT_V_ALIGN_T, types::VerticalAlignment>( GetVertJustify() ) );
112
113 attrs->mutable_angle()->set_value_degrees( GetTextAngleDegrees() );
114 attrs->set_line_spacing( GetLineSpacing() );
115 attrs->mutable_stroke_width()->set_value_nm( GetTextThickness() );
116 attrs->set_italic( IsItalic() );
117 attrs->set_bold( IsBold() );
118 attrs->set_underlined( GetAttributes().m_Underlined );
119 attrs->set_visible( IsVisible() );
120 attrs->set_mirrored( IsMirrored() );
121 attrs->set_multiline( IsMultilineAllowed() );
122 attrs->set_keep_upright( IsKeepUpright() );
123 attrs->mutable_size()->set_x_nm( GetTextSize().x );
124 attrs->mutable_size()->set_y_nm( GetTextSize().y );
125
126 text.set_knockout( IsKnockout() );
127
128 aContainer.PackFrom( boardText );
129}
130
131
132bool PCB_TEXT::Deserialize( const google::protobuf::Any &aContainer )
133{
134 kiapi::board::types::Text textWrapper;
135
136 if( !aContainer.UnpackTo( &textWrapper ) )
137 return false;
138
139 SetLayer( FromProtoEnum<PCB_LAYER_ID, kiapi::board::types::BoardLayer>( textWrapper.layer() ) );
140
141 const kiapi::common::types::Text& text = textWrapper.text();
142
143 const_cast<KIID&>( m_Uuid ) = KIID( text.id().value() );
144 SetPosition( VECTOR2I( text.position().x_nm(), text.position().y_nm() ) );
145 SetLocked( text.locked() == kiapi::common::types::LockedState::LS_LOCKED );
146 SetText( wxString( text.text().c_str(), wxConvUTF8 ) );
147 SetHyperlink( wxString( text.hyperlink().c_str(), wxConvUTF8 ) );
148 SetIsKnockout( text.knockout() );
149
150 if( text.has_attributes() )
151 {
153
154 attrs.m_Bold = text.attributes().bold();
155 attrs.m_Italic = text.attributes().italic();
156 attrs.m_Underlined = text.attributes().underlined();
157 attrs.m_Visible = text.attributes().visible();
158 attrs.m_Mirrored = text.attributes().mirrored();
159 attrs.m_Multiline = text.attributes().multiline();
160 attrs.m_KeepUpright = text.attributes().keep_upright();
161 attrs.m_Size = VECTOR2I( text.attributes().size().x_nm(), text.attributes().size().y_nm() );
162
163 if( !text.attributes().font_name().empty() )
164 {
166 wxString( text.attributes().font_name().c_str(), wxConvUTF8 ), attrs.m_Bold,
167 attrs.m_Italic );
168 }
169
170 attrs.m_Angle = EDA_ANGLE( text.attributes().angle().value_degrees(), DEGREES_T );
171 attrs.m_LineSpacing = text.attributes().line_spacing();
172 attrs.m_StrokeWidth = text.attributes().stroke_width().value_nm();
173 attrs.m_Halign = FromProtoEnum<GR_TEXT_H_ALIGN_T, types::HorizontalAlignment>(
174 text.attributes().horizontal_alignment() );
175
176 attrs.m_Valign = FromProtoEnum<GR_TEXT_V_ALIGN_T, types::VerticalAlignment>(
177 text.attributes().vertical_alignment() );
178
179 SetAttributes( attrs );
180 }
181
182 return true;
183}
184
185
186wxString PCB_TEXT::GetShownText( bool aAllowExtraText, int aDepth ) const
187{
188 const FOOTPRINT* parentFootprint = GetParentFootprint();
189 const BOARD* board = GetBoard();
190
191 std::function<bool( wxString* )> resolver =
192 [&]( wxString* token ) -> bool
193 {
194 if( parentFootprint && parentFootprint->ResolveTextVar( token, aDepth + 1 ) )
195 return true;
196
197 if( token->IsSameAs( wxT( "LAYER" ) ) )
198 {
199 *token = GetLayerName();
200 return true;
201 }
202
203 if( board->ResolveTextVar( token, aDepth + 1 ) )
204 return true;
205
206 return false;
207 };
208
209 wxString text = EDA_TEXT::GetShownText( aAllowExtraText, aDepth );
210
211 if( HasTextVars() )
212 {
213 if( aDepth < ADVANCED_CFG::GetCfg().m_ResolveTextRecursionDepth )
215 }
216
217 return text;
218}
219
220
221bool PCB_TEXT::Matches( const EDA_SEARCH_DATA& aSearchData, void* aAuxData ) const
222{
223 return BOARD_ITEM::Matches( UnescapeString( GetText() ), aSearchData );
224}
225
226
228{
229 EDA_ANGLE rotation = GetTextAngle();
230
232 {
233 // Keep angle between ]-90..90] deg. Otherwise the text is not easy to read
234 while( rotation > ANGLE_90 )
235 rotation -= ANGLE_180;
236
237 while( rotation <= -ANGLE_90 )
238 rotation += ANGLE_180;
239 }
240 else
241 {
242 rotation.Normalize();
243 }
244
245 return rotation;
246}
247
248
250{
251 return GetBoundingBox();
252}
253
254
255void PCB_TEXT::ViewGetLayers( int aLayers[], int& aCount ) const
256{
257 aLayers[0] = GetLayer();
258
259 aCount = 1;
260
261 if( IsLocked() )
262 aLayers[ aCount++ ] = LAYER_LOCKED_ITEM_SHADOW;
263}
264
265
266double PCB_TEXT::ViewGetLOD( int aLayer, KIGFX::VIEW* aView ) const
267{
268 constexpr double HIDE = std::numeric_limits<double>::max();
269
270 if( !aView )
271 return 0.0;
272
273 KIGFX::PCB_PAINTER* painter = static_cast<KIGFX::PCB_PAINTER*>( aView->GetPainter() );
274 KIGFX::PCB_RENDER_SETTINGS* renderSettings = painter->GetSettings();
275
276 if( !aView->IsLayerVisible( GetLayer() ) )
277 return HIDE;
278
279 if( aLayer == LAYER_LOCKED_ITEM_SHADOW )
280 {
281 // Hide shadow on dimmed tracks
282 if( renderSettings->GetHighContrast() )
283 {
284 if( m_layer != renderSettings->GetPrimaryHighContrastLayer() )
285 return HIDE;
286 }
287 }
288
289 if( FOOTPRINT* parentFP = GetParentFootprint() )
290 {
291 // Handle Render tab switches
292 if( GetText() == wxT( "${VALUE}" ) )
293 {
294 if( !aView->IsLayerVisible( LAYER_FP_VALUES ) )
295 return HIDE;
296 }
297
298 if( GetText() == wxT( "${REFERENCE}" ) )
299 {
300 if( !aView->IsLayerVisible( LAYER_FP_REFERENCES ) )
301 return HIDE;
302 }
303
304 if( parentFP->GetLayer() == F_Cu && !aView->IsLayerVisible( LAYER_FOOTPRINTS_FR ) )
305 return HIDE;
306
307 if( parentFP->GetLayer() == B_Cu && !aView->IsLayerVisible( LAYER_FOOTPRINTS_BK ) )
308 return HIDE;
309
310 if( !aView->IsLayerVisible( LAYER_FP_TEXT ) )
311 return HIDE;
312 }
313
314 return 0.0;
315}
316
317
318void PCB_TEXT::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList )
319{
320 FOOTPRINT* parentFP = GetParentFootprint();
321
322 if( parentFP && aFrame->GetName() == PCB_EDIT_FRAME_NAME )
323 aList.emplace_back( _( "Footprint" ), parentFP->GetReference() );
324
325 // Don't use GetShownText() here; we want to show the user the variable references
326 if( parentFP )
327 aList.emplace_back( _( "Text" ), KIUI::EllipsizeStatusText( aFrame, GetText() ) );
328 else
329 aList.emplace_back( _( "PCB Text" ), KIUI::EllipsizeStatusText( aFrame, GetText() ) );
330
331 if( parentFP )
332 aList.emplace_back( _( "Type" ), GetTextTypeDescription() );
333
334 if( aFrame->GetName() == PCB_EDIT_FRAME_NAME && IsLocked() )
335 aList.emplace_back( _( "Status" ), _( "Locked" ) );
336
337 if( parentFP )
338 aList.emplace_back( _( "Display" ), IsVisible() ? _( "Yes" ) : _( "No" ) );
339
340 aList.emplace_back( _( "Layer" ), GetLayerName() );
341
342 aList.emplace_back( _( "Mirror" ), IsMirrored() ? _( "Yes" ) : _( "No" ) );
343
344 aList.emplace_back( _( "Angle" ), wxString::Format( wxT( "%g" ), GetTextAngle().AsDegrees() ) );
345
346 aList.emplace_back( _( "Font" ), GetFont() ? GetFont()->GetName() : _( "Default" ) );
347 aList.emplace_back( _( "Thickness" ), aFrame->MessageTextFromValue( GetTextThickness() ) );
348 aList.emplace_back( _( "Width" ), aFrame->MessageTextFromValue( GetTextWidth() ) );
349 aList.emplace_back( _( "Height" ), aFrame->MessageTextFromValue( GetTextHeight() ) );
350}
351
352
354{
356}
357
358
360{
361 SetTextSize( settings.GetTextSize( GetLayer() ) );
363 SetItalic( settings.GetTextItalic( GetLayer() ) );
364 SetKeepUpright( settings.GetTextUpright( GetLayer() ) );
366}
367
368
370{
371 if( !IsKeepUpright() )
372 return;
373
374 EDA_ANGLE newAngle = GetTextAngle();
375 newAngle.Normalize();
376
377 bool needsFlipped = newAngle >= ANGLE_180;
378
379 if( needsFlipped )
380 {
382 SetVertJustify( static_cast<GR_TEXT_V_ALIGN_T>( -GetVertJustify() ) );
384 }
385}
386
387
389{
390 EDA_ANGLE angle = GetDrawRotation();
391 BOX2I rect = GetTextBox();
392
393 if( IsKnockout() )
394 rect.Inflate( getKnockoutMargin() );
395
396 if( !angle.IsZero() )
397 rect = rect.GetBoundingBoxRotated( GetTextPos(), angle );
398
399 return rect;
400}
401
402
403bool PCB_TEXT::TextHitTest( const VECTOR2I& aPoint, int aAccuracy ) const
404{
405 int accuracy = aAccuracy;
406
407 if( IsKnockout() )
409
410 return EDA_TEXT::TextHitTest( aPoint, accuracy );
411}
412
413
414bool PCB_TEXT::TextHitTest( const BOX2I& aRect, bool aContains, int aAccuracy ) const
415{
416 BOX2I rect = aRect;
417
418 rect.Inflate( aAccuracy );
419
420 if( aContains )
421 return rect.Contains( GetBoundingBox() );
422
423 return rect.Intersects( GetBoundingBox() );
424}
425
426
427void PCB_TEXT::Rotate( const VECTOR2I& aRotCentre, const EDA_ANGLE& aAngle )
428{
429 VECTOR2I pt = GetTextPos();
430 RotatePoint( pt, aRotCentre, aAngle );
431 SetTextPos( pt );
432
433 EDA_ANGLE new_angle = GetTextAngle() + aAngle;
434 new_angle.Normalize180();
435 SetTextAngle( new_angle );
436}
437
438
439void PCB_TEXT::Mirror( const VECTOR2I& aCentre, FLIP_DIRECTION aFlipDirection )
440{
441 // the position and justification are mirrored, but not the text itself
442
443 if( aFlipDirection == FLIP_DIRECTION::LEFT_RIGHT )
444 {
447
448 SetTextY( MIRRORVAL( GetTextPos().y, aCentre.y ) );
449 }
450 else
451 {
454
455 SetTextX( MIRRORVAL( GetTextPos().x, aCentre.x ) );
456 }
457}
458
459
460void PCB_TEXT::Flip( const VECTOR2I& aCentre, FLIP_DIRECTION aFlipDirection )
461{
462 if( aFlipDirection == FLIP_DIRECTION::LEFT_RIGHT )
463 {
464 SetTextX( MIRRORVAL( GetTextPos().x, aCentre.x ) );
466 }
467 else
468 {
469 SetTextY( MIRRORVAL( GetTextPos().y, aCentre.y ) );
471 }
472
474
475 if( IsSideSpecific() )
477}
478
479
481{
482 return _( "Text" );
483}
484
485
486wxString PCB_TEXT::GetItemDescription( UNITS_PROVIDER* aUnitsProvider, bool aFull ) const
487{
488 wxString content = aFull ? GetShownText( false ) : KIUI::EllipsizeMenuText( GetText() );
489
490 if( FOOTPRINT* parentFP = GetParentFootprint() )
491 {
492 wxString ref = parentFP->GetReference();
493 return wxString::Format( _( "Footprint text of %s (%s)" ), ref, content );
494 }
495
496 return wxString::Format( _( "PCB text '%s' on %s" ), content, GetLayerName() );
497}
498
499
501{
502 return BITMAPS::text;
503}
504
505
507{
508 return new PCB_TEXT( *this );
509}
510
511
513{
514 assert( aImage->Type() == PCB_TEXT_T );
515
516 std::swap( *((PCB_TEXT*) this), *((PCB_TEXT*) aImage) );
517}
518
519
520std::shared_ptr<SHAPE> PCB_TEXT::GetEffectiveShape( PCB_LAYER_ID aLayer, FLASHING aFlash ) const
521{
522 if( IsKnockout() )
523 {
524 SHAPE_POLY_SET poly;
525
526 TransformTextToPolySet( poly, 0, GetBoard()->GetDesignSettings().m_MaxError, ERROR_INSIDE );
527
528 return std::make_shared<SHAPE_POLY_SET>( poly );
529 }
530
531 return GetEffectiveTextShape();
532}
533
534
535void PCB_TEXT::buildBoundingHull( SHAPE_POLY_SET* aBuffer, const SHAPE_POLY_SET& aRenderedText,
536 int aClearance ) const
537{
538 SHAPE_POLY_SET poly( aRenderedText );
539
540 poly.Rotate( -GetDrawRotation(), GetDrawPos() );
541
542 BOX2I rect = poly.BBox( aClearance );
543 VECTOR2I corners[4];
544
545 corners[0].x = rect.GetOrigin().x;
546 corners[0].y = rect.GetOrigin().y;
547 corners[1].y = corners[0].y;
548 corners[1].x = rect.GetRight();
549 corners[2].x = corners[1].x;
550 corners[2].y = rect.GetBottom();
551 corners[3].y = corners[2].y;
552 corners[3].x = corners[0].x;
553
554 aBuffer->NewOutline();
555
556 for( VECTOR2I& corner : corners )
557 {
558 RotatePoint( corner, GetDrawPos(), GetDrawRotation() );
559 aBuffer->Append( corner.x, corner.y );
560 }
561}
562
563
564void PCB_TEXT::TransformTextToPolySet( SHAPE_POLY_SET& aBuffer, int aClearance, int aMaxError,
565 ERROR_LOC aErrorLoc ) const
566{
568 KIFONT::FONT* font = getDrawFont();
569 int penWidth = GetEffectiveTextPenWidth();
571
572 attrs.m_Angle = GetDrawRotation();
573
574 // The polygonal shape of a text can have many basic shapes, so combining these shapes can
575 // be very useful to create a final shape with a lot less vertices to speedup calculations.
576 // Simplify shapes is not usually always efficient, but in this case it is.
577 SHAPE_POLY_SET textShape;
578
579 CALLBACK_GAL callback_gal( empty_opts,
580 // Stroke callback
581 [&]( const VECTOR2I& aPt1, const VECTOR2I& aPt2 )
582 {
583 TransformOvalToPolygon( textShape, aPt1, aPt2, penWidth, aMaxError, aErrorLoc );
584 },
585 // Triangulation callback
586 [&]( const VECTOR2I& aPt1, const VECTOR2I& aPt2, const VECTOR2I& aPt3 )
587 {
588 textShape.NewOutline();
589
590 for( const VECTOR2I& point : { aPt1, aPt2, aPt3 } )
591 textShape.Append( point.x, point.y );
592 } );
593
594 font->Draw( &callback_gal, GetShownText( true ), GetTextPos(), attrs, GetFontMetrics() );
596
597 if( IsKnockout() )
598 {
599 SHAPE_POLY_SET finalPoly;
600 int margin = GetKnockoutTextMargin( attrs.m_Size, penWidth );
601
602 buildBoundingHull( &finalPoly, textShape, margin + aClearance );
603 finalPoly.BooleanSubtract( textShape, SHAPE_POLY_SET::PM_FAST );
604
605 aBuffer.Append( finalPoly );
606 }
607 else
608 {
609 if( aClearance > 0 || aErrorLoc == ERROR_OUTSIDE )
610 {
611 if( aErrorLoc == ERROR_OUTSIDE )
612 aClearance += aMaxError;
613
614 textShape.Inflate( aClearance, CORNER_STRATEGY::ROUND_ALL_CORNERS, aMaxError );
615 }
616
617 aBuffer.Append( textShape );
618 }
619}
620
621
623 int aClearance, int aMaxError, ERROR_LOC aErrorLoc,
624 bool aIgnoreLineWidth ) const
625{
626 SHAPE_POLY_SET poly;
627
628 TransformTextToPolySet( poly, 0, aMaxError, aErrorLoc );
629
630 buildBoundingHull( &aBuffer, poly, aClearance );
631}
632
633
634bool PCB_TEXT::operator==( const BOARD_ITEM& aBoardItem ) const
635{
636 if( aBoardItem.Type() != Type() )
637 return false;
638
639 const PCB_TEXT& other = static_cast<const PCB_TEXT&>( aBoardItem );
640
641 return *this == other;
642}
643
644
645bool PCB_TEXT::operator==( const PCB_TEXT& aOther ) const
646{
647 return EDA_TEXT::operator==( aOther );
648}
649
650
651double PCB_TEXT::Similarity( const BOARD_ITEM& aOther ) const
652{
653 if( aOther.Type() != Type() )
654 return 0.0;
655
656 const PCB_TEXT& other = static_cast<const PCB_TEXT&>( aOther );
657
658 return EDA_TEXT::Similarity( other );
659}
660
661
662static struct PCB_TEXT_DESC
663{
665 {
672
673 propMgr.Mask( TYPE_HASH( PCB_TEXT ), TYPE_HASH( EDA_TEXT ), _HKI( "Color" ) );
674
675 propMgr.AddProperty( new PROPERTY<PCB_TEXT, bool, BOARD_ITEM>( _HKI( "Knockout" ),
677 _HKI( "Text Properties" ) );
678
679 propMgr.AddProperty( new PROPERTY<PCB_TEXT, bool, EDA_TEXT>( _HKI( "Keep Upright" ),
681 _HKI( "Text Properties" ) );
682
683 auto isFootprintText =
684 []( INSPECTABLE* aItem ) -> bool
685 {
686 if( PCB_TEXT* text = dynamic_cast<PCB_TEXT*>( aItem ) )
687 return text->GetParentFootprint();
688
689 return false;
690 };
691
693 _HKI( "Visible" ), isFootprintText );
694
696 _HKI( "Keep Upright" ), isFootprintText );
697
699 _HKI( "Hyperlink" ),
700 []( INSPECTABLE* aItem ) { return false; } );
701 }
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:79
virtual PCB_LAYER_ID GetLayer() const
Return the primary layer this item is on.
Definition: board_item.h:237
virtual void SetLocked(bool aLocked)
Definition: board_item.h:328
PCB_LAYER_ID m_layer
Definition: board_item.h:436
virtual bool IsKnockout() const
Definition: board_item.h:324
virtual void SetIsKnockout(bool aKnockout)
Definition: board_item.h:325
virtual void SetLayer(PCB_LAYER_ID aLayer)
Set the layer this item is on.
Definition: board_item.h:288
virtual const BOARD * GetBoard() const
Return the BOARD in which this BOARD_ITEM resides, or NULL if none.
Definition: board_item.cpp:47
FOOTPRINT * GetParentFootprint() const
Definition: board_item.cpp:299
const KIFONT::METRICS & GetFontMetrics() const
Definition: board_item.cpp:100
virtual bool IsLocked() const
Definition: board_item.cpp:75
bool IsSideSpecific() const
Definition: board_item.cpp:149
wxString GetLayerName() const
Return the name of the PCB layer on which the item resides.
Definition: board_item.cpp:139
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:290
bool ResolveTextVar(wxString *token, int aDepth) const
Definition: board.cpp:431
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
EDA_ANGLE Normalize180()
Definition: eda_angle.h:260
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:89
const KIID m_Uuid
Definition: eda_item.h:489
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:101
virtual bool Matches(const EDA_SEARCH_DATA &aSearchData, void *aAuxData) const
Compare the item against the search criteria in aSearchData.
Definition: eda_item.h:377
A mix-in class (via multiple inheritance) that handles texts such as labels, parts,...
Definition: eda_text.h:79
int GetTextHeight() const
Definition: eda_text.h:247
const VECTOR2I & GetTextPos() const
Definition: eda_text.h:253
bool IsItalic() const
Definition: eda_text.h:152
const EDA_ANGLE & GetTextAngle() const
Definition: eda_text.h:130
void SetTextSize(VECTOR2I aNewSize, bool aEnforceMinTextSize=true)
Definition: eda_text.cpp:404
bool IsMultilineAllowed() const
Definition: eda_text.h:180
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition: eda_text.h:94
bool IsKeepUpright() const
Definition: eda_text.h:189
virtual bool IsVisible() const
Definition: eda_text.h:170
void SetTextPos(const VECTOR2I &aPoint)
Definition: eda_text.cpp:449
void SetTextX(int aX)
Definition: eda_text.cpp:455
KIFONT::FONT * GetFont() const
Definition: eda_text.h:230
void SetAttributes(const EDA_TEXT &aSrc, bool aSetPosition=true)
Set the text attributes from another instance.
Definition: eda_text.cpp:322
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:601
void SetMirrored(bool isMirrored)
Definition: eda_text.cpp:282
void SetTextY(int aY)
Definition: eda_text.cpp:461
virtual VECTOR2I GetDrawPos() const
Definition: eda_text.h:360
int GetTextWidth() const
Definition: eda_text.h:244
void SetVertJustify(GR_TEXT_V_ALIGN_T aType)
Definition: eda_text.cpp:306
wxString GetHyperlink() const
Definition: eda_text.h:381
GR_TEXT_H_ALIGN_T GetHorizJustify() const
Definition: eda_text.h:183
bool HasTextVars() const
Indicates the ShownText has text var references which need to be processed.
Definition: eda_text.h:113
virtual KIFONT::FONT * getDrawFont() const
Definition: eda_text.cpp:512
double GetLineSpacing() const
Definition: eda_text.h:238
double Similarity(const EDA_TEXT &aOther) const
Definition: eda_text.cpp:1167
void SetTextThickness(int aWidth)
The TextThickness is that set by the user.
Definition: eda_text.cpp:196
virtual bool TextHitTest(const VECTOR2I &aPoint, int aAccuracy=0) const
Test if aPoint is within the bounds of this object.
Definition: eda_text.cpp:735
const TEXT_ATTRIBUTES & GetAttributes() const
Definition: eda_text.h:214
bool IsMirrored() const
Definition: eda_text.h:173
int GetEffectiveTextPenWidth(int aDefaultPenWidth=0) const
The EffectiveTextPenWidth uses the text thickness if > 1 or aDefaultPenWidth.
Definition: eda_text.cpp:354
double GetTextAngleDegrees() const
Definition: eda_text.h:137
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:1008
bool IsBold() const
Definition: eda_text.h:167
void SetHyperlink(wxString aLink)
Definition: eda_text.h:382
void SetKeepUpright(bool aKeepUpright)
Definition: eda_text.cpp:314
GR_TEXT_V_ALIGN_T GetVertJustify() const
Definition: eda_text.h:186
virtual wxString GetShownText(bool aAllowExtraText, int aDepth=0) const
Return the string actually shown after processing of the base text.
Definition: eda_text.h:105
virtual void SetText(const wxString &aText)
Definition: eda_text.cpp:182
virtual void SetTextAngle(const EDA_ANGLE &aAngle)
Definition: eda_text.cpp:204
int GetTextThickness() const
Definition: eda_text.h:122
void SetItalic(bool aItalic)
Set the text to be italic - this will also update the font if needed.
Definition: eda_text.cpp:212
bool operator==(const EDA_TEXT &aRhs) const
Definition: eda_text.h:376
void SetMultilineAllowed(bool aAllow)
Definition: eda_text.cpp:290
VECTOR2I GetTextSize() const
Definition: eda_text.h:241
void SetHorizJustify(GR_TEXT_H_ALIGN_T aType)
Definition: eda_text.cpp:298
bool ResolveTextVar(wxString *token, int aDepth=0) const
Resolve any references to system tokens supported by the component.
Definition: footprint.cpp:905
PCB_LAYER_ID GetLayer() const override
Return the primary layer this item is on.
Definition: footprint.h:236
const wxString & GetReference() const
Definition: footprint.h:602
VECTOR2I GetPosition() const override
Definition: footprint.h:224
Class that other classes need to inherit from, in order to be inspectable.
Definition: inspectable.h:36
FONT is an abstract base class for both outline and stroke fonts.
Definition: font.h:131
static FONT * GetFont(const wxString &aFontName=wxEmptyString, bool aBold=false, bool aItalic=false, const std::vector< wxString > *aEmbeddedFiles=nullptr, bool aForDrawingSheet=false)
Definition: font.cpp:146
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:258
Contains methods for drawing PCB-specific items.
Definition: pcb_painter.h:173
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:178
PCB specific render settings.
Definition: pcb_painter.h:78
PCB_LAYER_ID GetPrimaryHighContrastLayer() const
Return the board layer which is in high-contrast mode.
bool GetHighContrast() const
Hold a (potentially large) number of VIEW_ITEMs and renders them on a graphics device provided by the...
Definition: view.h:68
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:221
Definition: kiid.h:49
std::string AsStdString() const
Definition: kiid.cpp:244
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:318
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:651
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:622
wxString GetItemDescription(UNITS_PROVIDER *aUnitsProvider, bool aFull) const override
Return a user-visible description string of this item.
Definition: pcb_text.cpp:486
const BOX2I ViewBBox() const override
Return the bounding box of the item covering all its layers.
Definition: pcb_text.cpp:249
void Flip(const VECTOR2I &aCentre, FLIP_DIRECTION aFlipDirection) override
Flip this object, i.e.
Definition: pcb_text.cpp:460
virtual void swapData(BOARD_ITEM *aImage) override
Definition: pcb_text.cpp:512
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:520
void KeepUpright()
Called when rotating the parent footprint.
Definition: pcb_text.cpp:369
bool Matches(const EDA_SEARCH_DATA &aSearchData, void *aAuxData) const override
Compare the item against the search criteria in aSearchData.
Definition: pcb_text.cpp:221
void Serialize(google::protobuf::Any &aContainer) const override
Serializes this object to the given Any message.
Definition: pcb_text.cpp:87
wxString GetShownText(bool aAllowExtraText, int aDepth=0) const override
Return the string actually shown after processing of the base text.
Definition: pcb_text.cpp:186
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:439
~PCB_TEXT()
Definition: pcb_text.cpp:82
virtual VECTOR2I GetPosition() const override
Definition: pcb_text.h:82
PCB_TEXT(BOARD_ITEM *parent, KICAD_T idtype=PCB_TEXT_T)
Definition: pcb_text.cpp:51
double ViewGetLOD(int aLayer, KIGFX::VIEW *aView) const override
Return the level of detail (LOD) of the item.
Definition: pcb_text.cpp:266
void StyleFromSettings(const BOARD_DESIGN_SETTINGS &settings) override
Definition: pcb_text.cpp:359
bool operator==(const PCB_TEXT &aOther) const
Definition: pcb_text.cpp:645
int getKnockoutMargin() const
Definition: pcb_text.cpp:353
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:564
const BOX2I GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
Definition: pcb_text.cpp:388
virtual wxString GetTextTypeDescription() const
Definition: pcb_text.cpp:480
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:535
bool TextHitTest(const VECTOR2I &aPoint, int aAccuracy=0) const override
Test if aPoint is within the bounds of this object.
Definition: pcb_text.cpp:403
virtual void SetPosition(const VECTOR2I &aPos) override
Definition: pcb_text.h:87
EDA_ITEM * Clone() const override
Create a duplicate of this item with linked list members set to NULL.
Definition: pcb_text.cpp:506
EDA_ANGLE GetDrawRotation() const override
Definition: pcb_text.cpp:227
void ViewGetLayers(int aLayers[], int &aCount) const override
Definition: pcb_text.cpp:255
bool Deserialize(const google::protobuf::Any &aContainer) override
Deserializes the given protobuf message into this object.
Definition: pcb_text.cpp:132
void Rotate(const VECTOR2I &aRotCentre, const EDA_ANGLE &aAngle) override
Rotate this object.
Definition: pcb_text.cpp:427
BITMAPS GetMenuImage() const override
Return a pointer to an image to be used in menus.
Definition: pcb_text.cpp:500
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 BooleanSubtract(const SHAPE_POLY_SET &b, POLYGON_MODE aFastMode)
Perform boolean polyset difference For aFastMode meaning, see function booleanOp.
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(POLYGON_MODE aFastMode)
Simplify the polyset (merges overlapping polys, eliminates degeneracy/self-intersections) For aFastMo...
int NewOutline()
Creates a new empty polygon in the set and returns its index.
const BOX2I BBox(int aClearance=0) const override
Compute a bounding box of the shape, with a margin of aClearance a collision.
GR_TEXT_H_ALIGN_T m_Halign
GR_TEXT_V_ALIGN_T m_Valign
KIFONT::FONT * m_Font
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)
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
@ DEGREES_T
Definition: eda_angle.h:31
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)
Returns 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:211
FLASHING
Enum used during connectivity building to ensure we do not query connectivity while building the data...
Definition: layer_ids.h:147
bool IsBackLayer(PCB_LAYER_ID aLayerId)
Layer classification: check if it's a back layer.
Definition: layer_ids.h:645
@ LAYER_LOCKED_ITEM_SHADOW
shadow layer for locked items
Definition: layer_ids.h:241
@ LAYER_FOOTPRINTS_FR
show footprints on front
Definition: layer_ids.h:210
@ LAYER_FP_REFERENCES
show footprints references (when texts are visible)
Definition: layer_ids.h:213
@ LAYER_FP_TEXT
Definition: layer_ids.h:200
@ LAYER_FOOTPRINTS_BK
show footprints on back
Definition: layer_ids.h:211
@ LAYER_FP_VALUES
show footprints values (when texts are visible)
Definition: layer_ids.h:212
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:213
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:195
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
GR_TEXT_H_ALIGN_T
GR_TEXT_V_ALIGN_T
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:691