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 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>
43#include <callback_gal.h>
45#include <api/api_enums.h>
46#include <api/api_utils.h>
47#include <api/board/board_types.pb.h>
48
49
51 BOARD_ITEM( parent, idtype ),
53{
54 SetMultilineAllowed( true );
55}
56
57
59 BOARD_ITEM( aParent, idtype ),
61{
62 SetKeepUpright( true );
63
64 // N.B. Do not automatically set text effects
65 // These are optional in the file format and so need to be defaulted to off.
66
68
69 if( aParent )
70 {
71 SetTextPos( aParent->GetPosition() );
72
73 if( IsBackLayer( aParent->GetLayer() ) )
75 }
76}
77
78
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() );
98 boardText.set_knockout( IsKnockout() );
99 boardText.set_locked( IsLocked() ? types::LockedState::LS_LOCKED : types::LockedState::LS_UNLOCKED );
100
101 google::protobuf::Any any;
103 any.UnpackTo( boardText.mutable_text() );
104
105 // Some of the common Text message fields are not stored in EDA_TEXT
106 types::Text* text = boardText.mutable_text();
107
108 PackVector2( *text->mutable_position(), GetPosition() );
109
110 aContainer.PackFrom( boardText );
111}
112
113
114bool PCB_TEXT::Deserialize( const google::protobuf::Any& aContainer )
115{
116 using namespace kiapi::common;
117 kiapi::board::types::BoardText boardText;
118
119 if( !aContainer.UnpackTo( &boardText ) )
120 return false;
121
123 const_cast<KIID&>( m_Uuid ) = KIID( boardText.id().value() );
124 SetIsKnockout( boardText.knockout() );
125 SetLocked( boardText.locked() == types::LockedState::LS_LOCKED );
126
127 google::protobuf::Any any;
128 any.PackFrom( boardText.text() );
130
131 const types::Text& text = boardText.text();
132
133 SetPosition( UnpackVector2( text.position() ) );
134
135 return true;
136}
137
138
139wxString PCB_TEXT::GetShownText( bool aAllowExtraText, int aDepth ) const
140{
141 const FOOTPRINT* parentFootprint = GetParentFootprint();
142 const BOARD* board = GetBoard();
143
144 std::function<bool( wxString* )> resolver = [&]( wxString* token ) -> bool
145 {
146 if( token->IsSameAs( wxT( "LAYER" ) ) )
147 {
148 *token = GetLayerName();
149 return true;
150 }
151
152 if( parentFootprint && parentFootprint->ResolveTextVar( token, aDepth + 1 ) )
153 return true;
154
155 // board can be null in some cases when saving a footprint in FP editor
156 if( board && board->ResolveTextVar( token, aDepth + 1 ) )
157 return true;
158
159 return false;
160 };
161
162 wxString text = EDA_TEXT::GetShownText( aAllowExtraText, aDepth );
163
164 if( HasTextVars() )
165 text = ResolveTextVars( text, &resolver, aDepth );
166
167 // Convert escape markers back to literal ${} and @{} for final display
168 text.Replace( wxT( "<<<ESC_DOLLAR:" ), wxT( "${" ) );
169 text.Replace( wxT( "<<<ESC_AT:" ), wxT( "@{" ) );
170
171 return text;
172}
173
174
175bool PCB_TEXT::Matches( const EDA_SEARCH_DATA& aSearchData, void* aAuxData ) const
176{
177 return BOARD_ITEM::Matches( UnescapeString( GetText() ), aSearchData );
178}
179
180
182{
183 EDA_ANGLE rotation = GetTextAngle();
184
186 {
187 // Keep angle between ]-90..90] deg. Otherwise the text is not easy to read
188 while( rotation > ANGLE_90 )
189 rotation -= ANGLE_180;
190
191 while( rotation <= -ANGLE_90 )
192 rotation += ANGLE_180;
193 }
194 else
195 {
196 rotation.Normalize();
197 }
198
199 return rotation;
200}
201
202
204{
205 return GetBoundingBox();
206}
207
208
209std::vector<int> PCB_TEXT::ViewGetLayers() const
210{
213
214 return { GetLayer() };
215}
216
217
218double PCB_TEXT::ViewGetLOD( int aLayer, const KIGFX::VIEW* aView ) const
219{
220 if( !aView )
221 return LOD_SHOW;
222
223 KIGFX::PCB_PAINTER& painter = static_cast<KIGFX::PCB_PAINTER&>( *aView->GetPainter() );
224 KIGFX::PCB_RENDER_SETTINGS& renderSettings = *painter.GetSettings();
225
226 if( !aView->IsLayerVisible( GetLayer() ) )
227 return LOD_HIDE;
228
229 if( aLayer == LAYER_LOCKED_ITEM_SHADOW )
230 {
231 // Hide shadow on dimmed tracks
232 if( renderSettings.GetHighContrast() )
233 {
234 if( m_layer != renderSettings.GetPrimaryHighContrastLayer() )
235 return LOD_HIDE;
236 }
237 }
238
239 if( FOOTPRINT* parentFP = GetParentFootprint() )
240 {
241 // Handle Render tab switches
242 if( GetText() == wxT( "${VALUE}" ) )
243 {
244 if( !aView->IsLayerVisible( LAYER_FP_VALUES ) )
245 return LOD_HIDE;
246 }
247
248 if( GetText() == wxT( "${REFERENCE}" ) )
249 {
250 if( !aView->IsLayerVisible( LAYER_FP_REFERENCES ) )
251 return LOD_HIDE;
252 }
253
254 if( parentFP->GetLayer() == F_Cu && !aView->IsLayerVisible( LAYER_FOOTPRINTS_FR ) )
255 return LOD_HIDE;
256
257 if( parentFP->GetLayer() == B_Cu && !aView->IsLayerVisible( LAYER_FOOTPRINTS_BK ) )
258 return LOD_HIDE;
259
260 if( !aView->IsLayerVisible( LAYER_FP_TEXT ) )
261 return LOD_HIDE;
262 }
263
264 return LOD_SHOW;
265}
266
267
268void PCB_TEXT::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList )
269{
270 FOOTPRINT* parentFP = GetParentFootprint();
271
272 if( parentFP && aFrame->GetName() == PCB_EDIT_FRAME_NAME )
273 aList.emplace_back( _( "Footprint" ), parentFP->GetReference() );
274
275 // Don't use GetShownText() here; we want to show the user the variable references
276 if( parentFP )
277 aList.emplace_back( _( "Text" ), KIUI::EllipsizeStatusText( aFrame, GetText() ) );
278 else
279 aList.emplace_back( _( "PCB Text" ), KIUI::EllipsizeStatusText( aFrame, GetText() ) );
280
281 if( parentFP )
282 aList.emplace_back( _( "Type" ), GetTextTypeDescription() );
283
284 if( aFrame->GetName() == PCB_EDIT_FRAME_NAME && IsLocked() )
285 aList.emplace_back( _( "Status" ), _( "Locked" ) );
286
287 aList.emplace_back( _( "Layer" ), GetLayerName() );
288
289 aList.emplace_back( _( "Mirror" ), IsMirrored() ? _( "Yes" ) : _( "No" ) );
290
291 aList.emplace_back( _( "Angle" ), wxString::Format( wxT( "%g" ), GetTextAngle().AsDegrees() ) );
292
293 aList.emplace_back( _( "Font" ), GetFont() ? GetFont()->GetName() : _( "Default" ) );
294
295 if( GetTextThickness() )
296 aList.emplace_back( _( "Text Thickness" ), aFrame->MessageTextFromValue( GetEffectiveTextPenWidth() ) );
297 else
298 aList.emplace_back( _( "Text Thickness" ), _( "Auto" ) );
299
300 aList.emplace_back( _( "Width" ), aFrame->MessageTextFromValue( GetTextWidth() ) );
301 aList.emplace_back( _( "Height" ), aFrame->MessageTextFromValue( GetTextHeight() ) );
302}
303
304
309
310
311void PCB_TEXT::StyleFromSettings( const BOARD_DESIGN_SETTINGS& settings, bool aCheckSide )
312{
313 SetTextSize( settings.GetTextSize( GetLayer() ) );
315 SetItalic( settings.GetTextItalic( GetLayer() ) );
316
317 if( GetParentFootprint() )
318 SetKeepUpright( settings.GetTextUpright( GetLayer() ) );
319
320 if( aCheckSide )
321 {
322 if( BOARD* board = GetBoard() )
323 SetMirrored( board->IsBackLayer( GetLayer() ) );
324 else
326 }
327}
328
329
331{
332 if( !IsKeepUpright() )
333 return;
334
335 EDA_ANGLE newAngle = GetTextAngle();
336 newAngle.Normalize();
337
338 bool needsFlipped = newAngle >= ANGLE_180;
339
340 if( needsFlipped )
341 {
343 SetVertJustify( static_cast<GR_TEXT_V_ALIGN_T>( -GetVertJustify() ) );
344 newAngle += ANGLE_180;
345 newAngle.Normalize();
346 SetTextAngle( newAngle );
347 }
348}
349
350
352{
353 EDA_ANGLE angle = GetDrawRotation();
354 BOX2I rect = GetTextBox( nullptr );
355
356 if( IsKnockout() )
357 rect.Inflate( getKnockoutMargin() );
358
359 if( !angle.IsZero() )
360 rect = rect.GetBoundingBoxRotated( GetTextPos(), angle );
361
362 return rect;
363}
364
365
366bool PCB_TEXT::TextHitTest( const VECTOR2I& aPoint, int aAccuracy ) const
367{
368 int accuracy = aAccuracy;
369
370 if( IsKnockout() )
372
373 return EDA_TEXT::TextHitTest( aPoint, accuracy );
374}
375
376
377bool PCB_TEXT::TextHitTest( const BOX2I& aRect, bool aContains, int aAccuracy ) const
378{
379 BOX2I rect = aRect;
380
381 rect.Inflate( aAccuracy );
382
383 if( aContains )
384 return rect.Contains( GetBoundingBox() );
385
386 return rect.Intersects( GetBoundingBox() );
387}
388
389
390bool PCB_TEXT::TextHitTest( const SHAPE_LINE_CHAIN& aPoly, bool aContained ) const
391{
392 BOX2I rect = GetTextBox( nullptr );
393
394 if( IsKnockout() )
395 rect.Inflate( getKnockoutMargin() );
396
397 return KIGEOM::BoxHitTest( aPoly, rect, GetDrawRotation(), GetDrawPos(), aContained );
398}
399
400
401void PCB_TEXT::Rotate( const VECTOR2I& aRotCentre, const EDA_ANGLE& aAngle )
402{
403 VECTOR2I pt = GetTextPos();
404 RotatePoint( pt, aRotCentre, aAngle );
405 SetTextPos( pt );
406
407 EDA_ANGLE new_angle = GetTextAngle() + aAngle;
408 new_angle.Normalize();
409 SetTextAngle( new_angle );
410}
411
412
413void PCB_TEXT::Mirror( const VECTOR2I& aCentre, FLIP_DIRECTION aFlipDirection )
414{
415 // the position and justification are mirrored, but not the text itself
416
417 if( aFlipDirection == FLIP_DIRECTION::TOP_BOTTOM )
418 {
421
422 SetTextY( MIRRORVAL( GetTextPos().y, aCentre.y ) );
423 }
424 else
425 {
428
429 SetTextX( MIRRORVAL( GetTextPos().x, aCentre.x ) );
430 }
431}
432
433
434void PCB_TEXT::Flip( const VECTOR2I& aCentre, FLIP_DIRECTION aFlipDirection )
435{
436 if( aFlipDirection == FLIP_DIRECTION::LEFT_RIGHT )
437 {
438 SetTextX( MIRRORVAL( GetTextPos().x, aCentre.x ) );
440 }
441 else
442 {
443 SetTextY( MIRRORVAL( GetTextPos().y, aCentre.y ) );
445 }
446
448
449 if( IsSideSpecific() )
451}
452
453
455{
456 return _( "Text" );
457}
458
459
460wxString PCB_TEXT::GetItemDescription( UNITS_PROVIDER* aUnitsProvider, bool aFull ) const
461{
462 wxString content = aFull ? GetShownText( false ) : KIUI::EllipsizeMenuText( GetText() );
463
464 if( FOOTPRINT* parentFP = GetParentFootprint() )
465 {
466 wxString ref = parentFP->GetReference();
467 return wxString::Format( _( "Footprint text of %s (%s)" ), ref, content );
468 }
469
470 return wxString::Format( _( "PCB text '%s' on %s" ), content, GetLayerName() );
471}
472
473
475{
476 return BITMAPS::text;
477}
478
479
481{
482 return new PCB_TEXT( *this );
483}
484
485
487{
488 assert( aImage->Type() == PCB_TEXT_T );
489
490 std::swap( *( (PCB_TEXT*) this ), *( (PCB_TEXT*) aImage ) );
491}
492
493
494std::shared_ptr<SHAPE> PCB_TEXT::GetEffectiveShape( PCB_LAYER_ID aLayer, FLASHING aFlash ) const
495{
496 if( IsKnockout() )
497 {
498 SHAPE_POLY_SET poly;
499
501
502 return std::make_shared<SHAPE_POLY_SET>( std::move( poly ) );
503 }
504
505 return GetEffectiveTextShape();
506}
507
508
509SHAPE_POLY_SET PCB_TEXT::GetKnockoutCache( const KIFONT::FONT* aFont, const wxString& forResolvedText,
510 int aMaxError ) const
511{
513 EDA_ANGLE drawAngle = GetDrawRotation();
514 VECTOR2I drawPos = GetDrawPos();
515
516 if( m_knockout_cache.IsEmpty() || m_knockout_cache_text_attrs != attrs || m_knockout_cache_text != forResolvedText
517 || m_knockout_cache_angle != drawAngle )
518 {
519 m_knockout_cache.RemoveAllContours();
520
522 m_knockout_cache.Fracture();
523
525 m_knockout_cache_angle = drawAngle;
526 m_knockout_cache_text = forResolvedText;
527 m_knockout_cache_pos = drawPos;
528 }
529 else if( m_knockout_cache_pos != drawPos )
530 {
531 m_knockout_cache.Move( drawPos - m_knockout_cache_pos );
532 m_knockout_cache_pos = drawPos;
533 }
534
535 return m_knockout_cache;
536}
537
538
539void PCB_TEXT::buildBoundingHull( SHAPE_POLY_SET* aBuffer, const SHAPE_POLY_SET& aRenderedText, int aClearance ) const
540{
541 SHAPE_POLY_SET poly( aRenderedText );
542
543 poly.Rotate( -GetDrawRotation(), GetDrawPos() );
544
545 BOX2I rect = poly.BBox( aClearance );
546 VECTOR2I corners[4];
547
548 corners[0].x = rect.GetOrigin().x;
549 corners[0].y = rect.GetOrigin().y;
550 corners[1].y = corners[0].y;
551 corners[1].x = rect.GetRight();
552 corners[2].x = corners[1].x;
553 corners[2].y = rect.GetBottom();
554 corners[3].y = corners[2].y;
555 corners[3].x = corners[0].x;
556
557 aBuffer->NewOutline();
558
559 for( VECTOR2I& corner : corners )
560 {
561 RotatePoint( corner, GetDrawPos(), GetDrawRotation() );
562 aBuffer->Append( corner.x, corner.y );
563 }
564}
565
566
567void PCB_TEXT::TransformTextToPolySet( SHAPE_POLY_SET& aBuffer, int aClearance, int aMaxError,
568 ERROR_LOC aErrorLoc ) const
569{
571 KIFONT::FONT* font = GetDrawFont( nullptr );
572 int penWidth = GetEffectiveTextPenWidth();
574 wxString shownText = GetShownText( true );
575
576 attrs.m_Angle = GetDrawRotation();
577
578 // The polygonal shape of a text can have many basic shapes, so combining these shapes can
579 // be very useful to create a final shape with a lot less vertices to speedup calculations.
580 // Simplify shapes is not usually always efficient, but in this case it is.
581 SHAPE_POLY_SET textShape;
582
583 CALLBACK_GAL callback_gal(
584 empty_opts,
585 // Stroke callback
586 [&]( const VECTOR2I& aPt1, const VECTOR2I& aPt2 )
587 {
588 TransformOvalToPolygon( textShape, aPt1, aPt2, penWidth, aMaxError, aErrorLoc );
589 },
590 // Triangulation callback
591 [&]( const VECTOR2I& aPt1, const VECTOR2I& aPt2, const VECTOR2I& aPt3 )
592 {
593 textShape.NewOutline();
594
595 for( const VECTOR2I& point : { aPt1, aPt2, aPt3 } )
596 textShape.Append( point.x, point.y );
597 } );
598
599 if( auto* cache = GetRenderCache( font, shownText ) )
600 callback_gal.DrawGlyphs( *cache );
601 else
602 font->Draw( &callback_gal, shownText, GetTextPos(), attrs, GetFontMetrics() );
603
604 textShape.Simplify();
605
606 if( IsKnockout() )
607 {
608 SHAPE_POLY_SET finalPoly;
609 int margin = GetKnockoutTextMargin( attrs.m_Size, penWidth );
610
611 buildBoundingHull( &finalPoly, textShape, margin + aClearance );
612 finalPoly.BooleanSubtract( textShape );
613
614 aBuffer.Append( finalPoly );
615 }
616 else
617 {
618 if( aClearance > 0 || aErrorLoc == ERROR_OUTSIDE )
619 {
620 if( aErrorLoc == ERROR_OUTSIDE )
621 aClearance += aMaxError;
622
623 textShape.Inflate( aClearance, CORNER_STRATEGY::ROUND_ALL_CORNERS, aMaxError );
624 }
625
626 aBuffer.Append( textShape );
627 }
628}
629
630
631void PCB_TEXT::TransformShapeToPolygon( SHAPE_POLY_SET& aBuffer, PCB_LAYER_ID aLayer, int aClearance, int aMaxError,
632 ERROR_LOC aErrorLoc, bool aIgnoreLineWidth ) const
633{
634 SHAPE_POLY_SET poly;
635
636 TransformTextToPolySet( poly, 0, aMaxError, aErrorLoc );
637
638 buildBoundingHull( &aBuffer, poly, aClearance );
639}
640
641
642bool PCB_TEXT::operator==( const BOARD_ITEM& aBoardItem ) const
643{
644 if( aBoardItem.Type() != Type() )
645 return false;
646
647 const PCB_TEXT& other = static_cast<const PCB_TEXT&>( aBoardItem );
648
649 return *this == other;
650}
651
652
653bool PCB_TEXT::operator==( const PCB_TEXT& aOther ) const
654{
655 return EDA_TEXT::operator==( aOther );
656}
657
658
659double PCB_TEXT::Similarity( const BOARD_ITEM& aOther ) const
660{
661 if( aOther.Type() != Type() )
662 return 0.0;
663
664 const PCB_TEXT& other = static_cast<const PCB_TEXT&>( aOther );
665
666 return EDA_TEXT::Similarity( other );
667}
668
669
671{
672 wxString msg =
673#include "pcb_text_help_md.h"
674 ;
675
676 HTML_MESSAGE_BOX* dlg = new HTML_MESSAGE_BOX( aParentWindow, _( "Syntax Help" ) );
677 wxSize sz( 320, 320 );
678
679 dlg->SetMinSize( dlg->ConvertDialogToPixels( sz ) );
680 dlg->SetDialogSizeInDU( sz.x, sz.y );
681
682 wxString html_txt;
683 ConvertMarkdown2Html( wxGetTranslation( msg ), html_txt );
684 dlg->AddHTML_Text( html_txt );
685 dlg->ShowModeless();
686
687 return dlg;
688}
689
690
691static struct PCB_TEXT_DESC
692{
694 {
701
702 propMgr.Mask( TYPE_HASH( PCB_TEXT ), TYPE_HASH( EDA_TEXT ), _HKI( "Color" ) );
703
706 _HKI( "Text Properties" ) );
707
710 _HKI( "Text Properties" ) );
711
712 auto isFootprintText = []( INSPECTABLE* aItem ) -> bool
713 {
714 if( PCB_TEXT* text = dynamic_cast<PCB_TEXT*>( aItem ) )
715 return text->GetParentFootprint();
716
717 return false;
718 };
719
720 propMgr.OverrideAvailability( TYPE_HASH( PCB_TEXT ), TYPE_HASH( EDA_TEXT ), _HKI( "Keep Upright" ),
721 isFootprintText );
722
723 propMgr.Mask( TYPE_HASH( PCB_TEXT ), TYPE_HASH( EDA_TEXT ), _HKI( "Hyperlink" ) );
724 }
types::KiCadObjectType ToProtoEnum(KICAD_T aValue)
Definition api_enums.cpp:97
KICAD_T FromProtoEnum(types::KiCadObjectType aValue)
Definition api_enums.cpp:36
ERROR_LOC
When approximating an arc or circle, should the error be placed on the outside or inside of the curve...
@ ERROR_OUTSIDE
@ ERROR_INSIDE
constexpr EDA_IU_SCALE pcbIUScale
Definition base_units.h:112
BITMAPS
A list of all bitmap identifiers.
BOX2< VECTOR2I > BOX2I
Definition box2.h:922
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:83
BOARD_ITEM(BOARD_ITEM *aParent, KICAD_T idtype, PCB_LAYER_ID aLayer=F_Cu)
Definition board_item.h:85
virtual PCB_LAYER_ID GetLayer() const
Return the primary layer this item is on.
Definition board_item.h:236
void SetLocked(bool aLocked) override
Definition board_item.h:327
PCB_LAYER_ID m_layer
Definition board_item.h:458
virtual bool IsKnockout() const
Definition board_item.h:323
bool IsLocked() const override
virtual void SetIsKnockout(bool aKnockout)
Definition board_item.h:324
virtual void SetLayer(PCB_LAYER_ID aLayer)
Set the layer this item is on.
Definition board_item.h:284
virtual const BOARD * GetBoard() const
Return the BOARD in which this BOARD_ITEM resides, or NULL if none.
FOOTPRINT * GetParentFootprint() const
const KIFONT::METRICS & GetFontMetrics() const
bool IsSideSpecific() const
wxString GetLayerName() const
Return the name of the PCB layer on which the item resides.
int GetMaxError() const
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:322
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:229
bool IsZero() const
Definition eda_angle.h:136
The base class for create windows for drawing purpose.
const KIID m_Uuid
Definition eda_item.h:516
KICAD_T Type() const
Returns the type of object.
Definition eda_item.h:110
virtual bool Matches(const EDA_SEARCH_DATA &aSearchData, void *aAuxData) const
Compare the item against the search criteria in aSearchData.
Definition eda_item.h:401
EDA_ITEM(EDA_ITEM *parent, KICAD_T idType, bool isSCH_ITEM=false, bool isBOARD_ITEM=false)
Definition eda_item.cpp:39
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:267
void Serialize(google::protobuf::Any &aContainer) const override
Serializes this object to the given Any message.
Definition eda_text.cpp:198
const VECTOR2I & GetTextPos() const
Definition eda_text.h:273
const EDA_ANGLE & GetTextAngle() const
Definition eda_text.h:147
void SetTextSize(VECTOR2I aNewSize, bool aEnforceMinTextSize=true)
Definition eda_text.cpp:540
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:206
void SetTextPos(const VECTOR2I &aPoint)
Definition eda_text.cpp:584
void SetTextX(int aX)
Definition eda_text.cpp:590
bool Deserialize(const google::protobuf::Any &aContainer) override
Deserializes the given protobuf message into this object.
Definition eda_text.cpp:232
KIFONT::FONT * GetFont() const
Definition eda_text.h:247
void SetMirrored(bool isMirrored)
Definition eda_text.cpp:401
void SetTextY(int aY)
Definition eda_text.cpp:596
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:691
virtual VECTOR2I GetDrawPos() const
Definition eda_text.h:378
int GetTextWidth() const
Definition eda_text.h:264
BOX2I GetTextBox(const RENDER_SETTINGS *aSettings, int aLine=-1) const
Useful in multiline texts to calculate the full text or a line area (for zones filling,...
Definition eda_text.cpp:745
void SetVertJustify(GR_TEXT_V_ALIGN_T aType)
Definition eda_text.cpp:425
GR_TEXT_H_ALIGN_T GetHorizJustify() const
Definition eda_text.h:200
virtual KIFONT::FONT * GetDrawFont(const RENDER_SETTINGS *aSettings) const
Definition eda_text.cpp:655
bool HasTextVars() const
Indicates the ShownText has text var references which need to be processed.
Definition eda_text.h:117
EDA_TEXT(const EDA_IU_SCALE &aIuScale, const wxString &aText=wxEmptyString)
Definition eda_text.cpp:97
double Similarity(const EDA_TEXT &aOther) const
void SetTextThickness(int aWidth)
The TextThickness is that set by the user.
Definition eda_text.cpp:292
virtual bool TextHitTest(const VECTOR2I &aPoint, int aAccuracy=0) const
Test if aPoint is within the bounds of this object.
Definition eda_text.cpp:868
const TEXT_ATTRIBUTES & GetAttributes() const
Definition eda_text.h:231
bool IsMirrored() const
Definition eda_text.h:190
int GetEffectiveTextPenWidth(int aDefaultPenWidth=0) const
The EffectiveTextPenWidth uses the text thickness if > 1 or aDefaultPenWidth.
Definition eda_text.cpp:473
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.
void SetKeepUpright(bool aKeepUpright)
Definition eda_text.cpp:433
GR_TEXT_V_ALIGN_T GetVertJustify() const
Definition eda_text.h:203
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:307
int GetTextThickness() const
Definition eda_text.h:128
void SetItalic(bool aItalic)
Set the text to be italic - this will also update the font if needed.
Definition eda_text.cpp:315
bool operator==(const EDA_TEXT &aRhs) const
Definition eda_text.h:396
void SetMultilineAllowed(bool aAllow)
Definition eda_text.cpp:409
VECTOR2I GetTextSize() const
Definition eda_text.h:261
void SetHorizJustify(GR_TEXT_H_ALIGN_T aType)
Definition eda_text.cpp:417
bool ResolveTextVar(wxString *token, int aDepth=0) const
Resolve any references to system tokens supported by the component.
PCB_LAYER_ID GetLayer() const override
Return the primary layer this item is on.
Definition footprint.h:257
const wxString & GetReference() const
Definition footprint.h:661
VECTOR2I GetPosition() const override
Definition footprint.h:245
void SetDialogSizeInDU(int aWidth, int aHeight)
Set the dialog size, using a "logical" value.
void AddHTML_Text(const wxString &message)
Add HTML text (without any change) to message list.
void ShowModeless()
Show a modeless version of the dialog (without an OK button).
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.
virtual PCB_RENDER_SETTINGS * GetSettings() override
Return a pointer to current settings that are going to be used when drawing items.
PCB specific render settings.
Definition pcb_painter.h:82
PCB_LAYER_ID GetPrimaryHighContrastLayer() const
Return the board layer which is in high-contrast mode.
static constexpr double LOD_HIDE
Return this constant from ViewGetLOD() to hide the item unconditionally.
Definition view_item.h:180
static constexpr double LOD_SHOW
Return this constant from ViewGetLOD() to show the item unconditionally.
Definition view_item.h:185
Hold a (potentially large) number of VIEW_ITEMs and renders them on a graphics device provided by the...
Definition view.h:66
bool IsLayerVisible(int aLayer) const
Return information about visibility of a particular layer.
Definition view.h:422
PAINTER * GetPainter() const
Return the painter object used by the view for drawing #VIEW_ITEMS.
Definition view.h:220
Definition kiid.h:49
SHAPE_POLY_SET GetKnockoutCache(const KIFONT::FONT *aFont, const wxString &forResolvedText, int aMaxError) const
Definition pcb_text.cpp:509
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:268
void StyleFromSettings(const BOARD_DESIGN_SETTINGS &settings, bool aCheckSide) override
Definition pcb_text.cpp:311
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:659
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:631
wxString GetItemDescription(UNITS_PROVIDER *aUnitsProvider, bool aFull) const override
Return a user-visible description string of this item.
Definition pcb_text.cpp:460
const BOX2I ViewBBox() const override
Return the bounding box of the item covering all its layers.
Definition pcb_text.cpp:203
void Flip(const VECTOR2I &aCentre, FLIP_DIRECTION aFlipDirection) override
Flip this object, i.e.
Definition pcb_text.cpp:434
virtual void swapData(BOARD_ITEM *aImage) override
Definition pcb_text.cpp:486
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:494
void KeepUpright()
Called when rotating the parent footprint.
Definition pcb_text.cpp:330
bool Matches(const EDA_SEARCH_DATA &aSearchData, void *aAuxData) const override
Compare the item against the search criteria in aSearchData.
Definition pcb_text.cpp:175
EDA_ANGLE m_knockout_cache_angle
Definition pcb_text.h:192
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:139
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:413
double ViewGetLOD(int aLayer, const KIGFX::VIEW *aView) const override
Return the level of detail (LOD) of the item.
Definition pcb_text.cpp:218
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:50
wxString m_knockout_cache_text
Definition pcb_text.h:190
TEXT_ATTRIBUTES m_knockout_cache_text_attrs
Definition pcb_text.h:191
bool operator==(const PCB_TEXT &aOther) const
Definition pcb_text.cpp:653
int getKnockoutMargin() const
Definition pcb_text.cpp:305
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:567
SHAPE_POLY_SET m_knockout_cache
Definition pcb_text.h:194
const BOX2I GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
Definition pcb_text.cpp:351
virtual wxString GetTextTypeDescription() const
Definition pcb_text.cpp:454
std::vector< int > ViewGetLayers() const override
Definition pcb_text.cpp:209
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:539
bool TextHitTest(const VECTOR2I &aPoint, int aAccuracy=0) const override
Test if aPoint is within the bounds of this object.
Definition pcb_text.cpp:366
virtual void SetPosition(const VECTOR2I &aPos) override
Definition pcb_text.h:84
VECTOR2I m_knockout_cache_pos
Definition pcb_text.h:193
EDA_ITEM * Clone() const override
Create a duplicate of this item with linked list members set to NULL.
Definition pcb_text.cpp:480
static HTML_MESSAGE_BOX * ShowSyntaxHelp(wxWindow *aParentWindow)
Display a syntax help window for text variables and expressions.
Definition pcb_text.cpp:670
EDA_ANGLE GetDrawRotation() const override
Definition pcb_text.cpp:181
bool Deserialize(const google::protobuf::Any &aContainer) override
Deserializes the given protobuf message into this object.
Definition pcb_text.cpp:114
void Rotate(const VECTOR2I &aRotCentre, const EDA_ANGLE &aAngle) override
Rotate this object.
Definition pcb_text.cpp:401
BITMAPS GetMenuImage() const override
Return a pointer to an image to be used in menus.
Definition pcb_text.cpp:474
Provide class metadata.Helper macro to map type hashes to names.
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()
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 polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
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().
A type-safe container of any type.
Definition ki_any.h:93
wxString ResolveTextVars(const wxString &aSource, const std::function< bool(wxString *)> *aResolver, int &aDepth)
Multi-pass text variable expansion and math expression evaluation.
Definition common.cpp:247
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.
@ ROUND_ALL_CORNERS
All angles are rounded.
#define _(s)
static constexpr EDA_ANGLE ANGLE_90
Definition eda_angle.h:413
static constexpr EDA_ANGLE ANGLE_VERTICAL
Definition eda_angle.h:408
static constexpr EDA_ANGLE ANGLE_HORIZONTAL
Definition eda_angle.h:407
static constexpr EDA_ANGLE ANGLE_180
Definition eda_angle.h:415
#define PCB_EDIT_FRAME_NAME
static FILENAME_RESOLVER * resolver
a few functions useful in geometry calculations.
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:172
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:803
@ LAYER_LOCKED_ITEM_SHADOW
Shadow layer for locked items.
Definition layer_ids.h:307
@ LAYER_FOOTPRINTS_FR
Show footprints on front.
Definition layer_ids.h:259
@ LAYER_FP_REFERENCES
Show footprints references (when texts are visible).
Definition layer_ids.h:266
@ LAYER_FP_TEXT
Definition layer_ids.h:240
@ LAYER_FOOTPRINTS_BK
Show footprints on back.
Definition layer_ids.h:260
@ LAYER_FP_VALUES
Show footprints values (when texts are visible).
Definition layer_ids.h:263
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
@ LEFT_RIGHT
Flip left to right (around the Y axis)
Definition mirror.h:28
@ TOP_BOTTOM
Flip top to bottom (around the X axis)
Definition mirror.h:29
bool BoxHitTest(const VECTOR2I &aHitPoint, const BOX2I &aHittee, int aAccuracy)
Perform a point-to-box hit test.
KICOMMON_API wxString EllipsizeMenuText(const wxString &aString)
Ellipsize text (at the end) to be no more than 36 characters.
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.
KICOMMON_API VECTOR2I UnpackVector2(const types::Vector2 &aInput)
Definition api_utils.cpp:86
KICOMMON_API void PackVector2(types::Vector2 &aOutput, const VECTOR2I &aInput)
Definition api_utils.cpp:79
#define _HKI(x)
Definition page_info.cpp:44
static struct PCB_TEXT_DESC _PCB_TEXT_DESC
#define TYPE_HASH(x)
Definition property.h:74
#define REGISTER_TYPE(x)
wxString UnescapeString(const wxString &aSource)
void ConvertMarkdown2Html(const wxString &aMarkdownInput, wxString &aHtmlOutput)
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