KiCad PCB EDA Suite
Loading...
Searching...
No Matches
sch_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) 2016 Jean-Pierre Charras, jp.charras at wanadoo.fr
5 * Copyright (C) 2015 Wayne Stambaugh <[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, see <https://www.gnu.org/licenses/>.
20 */
21
22#include "markup_parser.h"
23#include <google/protobuf/any.pb.h>
24
25#include <advanced_config.h>
26#include <api/api_utils.h>
27#include <api/schematic/schematic_types.pb.h>
28#include <base_units.h>
29#include <pgm_base.h>
30#include <sch_edit_frame.h>
31#include <sch_plotter.h>
32#include <widgets/msgpanel.h>
33#include <bitmaps.h>
34#include <string_utils.h>
36#include <sch_text.h>
37#include <schematic.h>
39#include <sch_painter.h>
40#include <default_values.h>
41#include <wx/debug.h>
42#include <wx/log.h>
46#include <core/mirror.h>
47#include <core/kicad_algo.h>
49#include <tool/tool_manager.h>
50#include <trigo.h>
51#include <markup_parser.h>
52#include <properties/property.h>
54
55
56SCH_TEXT::SCH_TEXT( const VECTOR2I& aPos, const wxString& aText, SCH_LAYER_ID aLayer, KICAD_T aType ) :
57 SCH_ITEM( nullptr, aType ),
58 EDA_TEXT( schIUScale, aText )
59{
60 m_layer = aLayer;
61
62 SetTextPos( aPos );
63 SetMultilineAllowed( true );
64
65 m_excludedFromSim = false;
66}
67
68
70 SCH_ITEM( aText ),
71 EDA_TEXT( aText )
72{
74}
75
76
77void SCH_TEXT::Serialize( google::protobuf::Any& aContainer ) const
78{
79 using namespace kiapi::common;
80
81 kiapi::schematic::types::SchematicText text;
82
83 text.mutable_id()->set_value( m_Uuid.AsStdString() );
84 text.set_locked( IsLocked() ? types::LockedState::LS_LOCKED : types::LockedState::LS_UNLOCKED );
85 text.set_exclude_from_sim( GetExcludedFromSim() );
86
87 EDA_TEXT::Serialize( *text.mutable_text(), schIUScale );
88
89 PackVector2( *text.mutable_text()->mutable_position(), GetPosition(), schIUScale );
90
91 PackCustomProperties( text.mutable_custom_properties(), *this );
92
93 if( !aContainer.PackFrom( text ) )
94 wxFAIL_MSG( wxT( "Failed to pack SCH_TEXT" ) );
95}
96
97
98bool SCH_TEXT::Deserialize( const google::protobuf::Any& aContainer )
99{
100 using namespace kiapi::common;
101
102 kiapi::schematic::types::SchematicText text;
103
104 if( !aContainer.UnpackTo( &text ) )
105 return false;
106
107 const_cast<KIID&>( m_Uuid ) = KIID( text.id().value() );
108 SetLocked( text.locked() == types::LockedState::LS_LOCKED );
109 SetExcludedFromSim( text.exclude_from_sim() );
110 UnpackCustomProperties( text.custom_properties(), *this );
111
112 if( !EDA_TEXT::Deserialize( text.text(), schIUScale ) )
113 return false;
114
115 SetPosition( UnpackVector2( text.text().position(), schIUScale ) );
116 return true;
117}
118
119
121{
122 // Fudge factor to match KiCad 6
123 return VECTOR2I( 0, -2500 );
124}
125
126
128{
130 return;
131
132 VECTOR2I delta( 0, 0 );
133 BOX2I bbox = GetTextBox( nullptr );
134
135 if( GetTextAngle().IsHorizontal() )
136 {
138 delta.x = bbox.GetWidth() / 2;
140 delta.x = -bbox.GetWidth() / 2;
141
143 delta.y = -bbox.GetHeight() / 2;
145 delta.y = bbox.GetHeight() / 2;
146 }
147 else
148 {
150 delta.y = bbox.GetWidth() / 2;
152 delta.y = -bbox.GetWidth() / 2;
153
155 delta.x = +bbox.GetHeight() / 2;
157 delta.x = -bbox.GetHeight() / 2;
158 }
159
160 if( inverse )
162 else
164}
165
166
168{
169 if( m_layer == LAYER_DEVICE )
170 {
171 NormalizeJustification( false );
172 int x = GetTextPos().x;
173
174 x -= aCenter;
175 x *= -1;
176 x += aCenter;
177
178 if( GetTextAngle().IsHorizontal() )
179 {
184 }
185 else
186 {
191 }
192
193 SetTextX( x );
195 }
196 else
197 {
199 FlipHJustify();
200
201 SetTextX( MIRRORVAL( GetTextPos().x, aCenter ) );
202 }
203}
204
205
206void SCH_TEXT::MirrorVertically( int aCenter )
207{
208 if( m_layer == LAYER_DEVICE )
209 {
210 NormalizeJustification( false );
211 int y = GetTextPos().y;
212
213 y -= aCenter;
214 y *= -1;
215 y += aCenter;
216
217 if( GetTextAngle().IsHorizontal() )
218 {
223 }
224 else
225 {
230 }
231
232 SetTextY( y );
234 }
235 else
236 {
238 FlipHJustify();
239
240 SetTextY( MIRRORVAL( GetTextPos().y, aCenter ) );
241 }
242}
243
244
245void SCH_TEXT::Rotate( const VECTOR2I& aCenter, bool aRotateCCW )
246{
247 VECTOR2I pt = GetTextPos();
248 RotatePoint( pt, aCenter, aRotateCCW ? ANGLE_90 : ANGLE_270 );
249 VECTOR2I offset = pt - GetTextPos();
250
251 Rotate90( !aRotateCCW );
252
253 SetTextPos( GetTextPos() + offset );
254}
255
256
257void SCH_TEXT::Rotate90( bool aClockwise )
258{
259 if( ( GetTextAngle() == ANGLE_HORIZONTAL && aClockwise ) || ( GetTextAngle() == ANGLE_VERTICAL && !aClockwise ) )
260 {
261 FlipHJustify();
262 }
263
265}
266
267
268void SCH_TEXT::MirrorSpinStyle( bool aLeftRight )
269{
270 if( ( GetTextAngle() == ANGLE_HORIZONTAL && aLeftRight ) || ( GetTextAngle() == ANGLE_VERTICAL && !aLeftRight ) )
271 {
272 FlipHJustify();
273 }
274}
275
276
278{
279 SCH_TEXT* item = static_cast<SCH_TEXT*>( aItem );
280
281 std::swap( m_excludedFromSim, item->m_excludedFromSim );
282
283 SwapText( *item );
284 SwapAttributes( *item );
285}
286
287
288bool SCH_TEXT::operator<( const SCH_ITEM& aItem ) const
289{
290 if( Type() != aItem.Type() )
291 return Type() < aItem.Type();
292
293 auto other = static_cast<const SCH_TEXT*>( &aItem );
294
295 if( GetLayer() != other->GetLayer() )
296 return GetLayer() < other->GetLayer();
297
298 if( GetPosition().x != other->GetPosition().x )
299 return GetPosition().x < other->GetPosition().x;
300
301 if( GetPosition().y != other->GetPosition().y )
302 return GetPosition().y < other->GetPosition().y;
303
304 if( GetExcludedFromSim() != other->GetExcludedFromSim() )
305 return GetExcludedFromSim();
306
307 return GetText() < other->GetText();
308}
309
310
311int SCH_TEXT::GetTextOffset( const RENDER_SETTINGS* aSettings ) const
312{
313 double ratio;
314
315 if( aSettings )
316 ratio = static_cast<const SCH_RENDER_SETTINGS*>( aSettings )->m_TextOffsetRatio;
317 else if( Schematic() )
319 else
320 ratio = DEFAULT_TEXT_OFFSET_RATIO; // For previews (such as in Preferences), etc.
321
322 return KiROUND( ratio * GetTextSize().y );
323}
324
325
327{
329}
330
331
333{
335
336 if( !font )
337 font = KIFONT::FONT::GetFont( GetDefaultFont( aSettings ), IsBold(), IsItalic() );
338
339 return font;
340}
341
342
344{
345 BOX2I bbox = GetTextBox( nullptr );
346
347 if( !GetTextAngle().IsZero() ) // Rotate bbox.
348 {
349 VECTOR2I pos = bbox.GetOrigin();
350 VECTOR2I end = bbox.GetEnd();
351
354
355 bbox.SetOrigin( pos );
356 bbox.SetEnd( end );
357 }
358
359 bbox.Normalize();
360 return bbox;
361}
362
363
364wxString SCH_TEXT::GetShownText( const SCH_SHEET_PATH* aPath, RESOLUTION_CONTEXT aContext, int aDepth ) const
365{
366 // Use local depth counter so each text element starts fresh
367 int depth = 0;
368
369 SCH_SHEET* sheet = nullptr;
370
371 if( aPath )
372 sheet = aPath->Last();
373 else if( SCHEMATIC* schematic = Schematic() )
374 sheet = schematic->CurrentSheet().Last();
375
376 std::function<bool( wxString* )> textResolver =
377 [&]( wxString* token ) -> bool
378 {
379 if( SCH_SYMBOL* sch_symbol = dynamic_cast<SCH_SYMBOL*>( m_parent ) )
380 {
381 if( sch_symbol->ResolveTextVar( aPath, token, depth + 1 ) )
382 return true;
383 }
384 else if( LIB_SYMBOL* lib_symbol = dynamic_cast<LIB_SYMBOL*>( m_parent ) )
385 {
386 if( lib_symbol->ResolveTextVar( token, depth + 1 ) )
387 return true;
388 }
389
390 if( sheet )
391 {
392 if( sheet->ResolveTextVar( aPath, token, depth + 1 ) )
393 return true;
394 }
395
396 return false;
397 };
398
399 wxString text = EDA_TEXT::GetShownText( aContext, depth );
400
401 if( HasTextVars() && aContext != RAW_VALUE )
402 {
403 text = ResolveTextVars( text, &textResolver, depth );
404 FinalizeTextVarExpansion( text, aContext );
405 }
406
407 return text;
408}
409
410
412{
413 return HasHyperlink() || containsURL();
414}
415
416
418{
419 return !m_activeUrl.IsEmpty();
420}
421
422
423void SCH_TEXT::DoHypertextAction( EDA_DRAW_FRAME* aFrame, const VECTOR2I& aMousePos ) const
424{
426
427 if( HasHyperlink() )
428 navTool->HypertextCommand( m_hyperlink );
429 else if( !m_activeUrl.IsEmpty() )
430 navTool->HypertextCommand( m_activeUrl );
431}
432
433
434wxString SCH_TEXT::GetItemDescription( UNITS_PROVIDER* aUnitsProvider, bool aFull ) const
435{
436 return wxString::Format( _( "Graphic Text '%s'" ), aFull ? GetShownText( FOR_GUI )
438}
439
440
442{
443 return BITMAPS::text;
444}
445
446
447bool SCH_TEXT::HitTest( const VECTOR2I& aPosition, int aAccuracy ) const
448{
449 BOX2I bBox = GetBoundingBox();
450 bBox.Inflate( aAccuracy );
451 return bBox.Contains( aPosition );
452}
453
454
455bool SCH_TEXT::HitTest( const BOX2I& aRect, bool aContained, int aAccuracy ) const
456{
458 return false;
459
460 BOX2I rect = aRect;
461 BOX2I bBox = GetBoundingBox();
462
463 rect.Inflate( aAccuracy );
464
465 if( aContained )
466 return aRect.Contains( bBox );
467
468 return aRect.Intersects( bBox );
469}
470
471
472bool SCH_TEXT::HitTest( const SHAPE_LINE_CHAIN& aPoly, bool aContained ) const
473{
475 return false;
476
477 return KIGEOM::BoxHitTest( aPoly, GetBoundingBox(), aContained );
478}
479
480
481void SCH_TEXT::BeginEdit( const VECTOR2I& aPosition )
482{
483 SetTextPos( aPosition );
484}
485
486
487void SCH_TEXT::CalcEdit( const VECTOR2I& aPosition )
488{
489 SetTextPos( aPosition );
490}
491
492
493std::vector<int> SCH_TEXT::ViewGetLayers() const
494{
495 if( IsPrivate() )
497
499}
500
501
503{
504 if( GetDrawFont( aRenderSettings )->IsOutline() )
505 {
506 BOX2I firstLineBBox = GetTextBox( aRenderSettings, 0 );
507 int sizeDiff = firstLineBBox.GetHeight() - GetTextSize().y;
508 int adjust = KiROUND( sizeDiff * 0.4 );
509 VECTOR2I adjust_offset( 0, -adjust );
510
511 RotatePoint( adjust_offset, GetDrawRotation() );
512 return adjust_offset;
513 }
514
515 return { 0, 0 };
516}
517
518
519void SCH_TEXT::Plot( PLOTTER* aPlotter, bool aBackground, const SCH_PLOT_OPTS& aPlotOpts, int aUnit, int aBodyStyle,
520 const VECTOR2I& aOffset, bool aDimmed )
521{
522 if( aBackground || IsPrivate() )
523 return;
524
525 SCH_RENDER_SETTINGS* renderSettings = getRenderSettings( aPlotter );
526 COLOR4D color = GetTextColor();
527 COLOR4D bg = renderSettings->GetBackgroundColor();
528
529 if( !aPlotter->GetColorMode() || color == COLOR4D::UNSPECIFIED )
530 {
531 SCH_CONNECTION* connection = Connection();
532
533 if( connection && connection->IsBus() )
534 color = renderSettings->GetLayerColor( LAYER_BUS );
535 else
536 color = renderSettings->GetLayerColor( m_layer );
537 }
538
539 if( !IsVisible() )
540 bg = renderSettings->GetLayerColor( LAYER_HIDDEN );
541 else if( bg == COLOR4D::UNSPECIFIED || !aPlotter->GetColorMode() )
542 bg = COLOR4D::WHITE;
543
544 if( color.m_text && Schematic() )
545 color = COLOR4D( ResolveText( *color.m_text, &Schematic()->CurrentSheet() ) );
546
547 if( aDimmed )
548 {
549 color.Desaturate();
550 color = color.Mix( bg, 0.5f );
551 }
552
553 int penWidth = GetEffectiveTextPenWidth( renderSettings->GetDefaultPenWidth() );
554 penWidth = std::max( penWidth, renderSettings->GetMinPenWidth() );
555 aPlotter->SetCurrentLineWidth( penWidth );
556
557 KIFONT::FONT* font = GetDrawFont( renderSettings );
559 attrs.m_StrokeWidth = penWidth;
560
561 if( m_layer == LAYER_DEVICE )
562 {
563 const TRANSFORM& t = renderSettings->m_Transform;
564
565 // The text orientation may need to be flipped if the transformation matrix causes xy
566 // axes to be flipped.
567 if( ( t.x1 != 0 ) ^ ( GetTextAngle() != ANGLE_HORIZONTAL ) )
569 else
570 attrs.m_Angle = ANGLE_VERTICAL;
571
572 bool origHoriz = ( GetTextAngle() == ANGLE_HORIZONTAL );
573 bool screenHoriz = ( attrs.m_Angle.GetAngle() == ANGLE_HORIZONTAL );
574
575 // Check if the text reading direction is reversed by the transform
576 // Flip H alignment when reversed
577 bool flipH;
578
579 if( origHoriz )
580 flipH = screenHoriz ? ( t.x1 < 0 ) : ( t.x2 > 0 );
581 else
582 flipH = screenHoriz ? ( t.y1 > 0 ) : ( t.y2 < 0 );
583
584 if( flipH )
585 {
586 if( attrs.m_Halign == GR_TEXT_H_ALIGN_LEFT )
588 else if( attrs.m_Halign == GR_TEXT_H_ALIGN_RIGHT )
590 }
591
592 // For mirrored transforms (det < 0), the multiline stacking direction may be reversed
593 // Flip V alignment to keep lines in the correct visual order
594 int det = t.x1 * t.y2 - t.x2 * t.y1;
595
596 if( det < 0 && ( origHoriz == ( t.x1 > 0 ) ) )
597 {
598 if( attrs.m_Valign == GR_TEXT_V_ALIGN_TOP )
600 else if( attrs.m_Valign == GR_TEXT_V_ALIGN_BOTTOM )
602 }
603
604 // Compute line positions
605 wxArrayString strings_list;
606 wxStringSplit( GetShownText( nullptr, FOR_CANVAS ), strings_list, '\n' );
607
608 int lineCount = (int) strings_list.Count();
609
610 VECTOR2I linePos = renderSettings->TransformCoordinate( GetDrawPos() ) + aOffset;
611 int interline = GetInterline( renderSettings );
612
613 if( lineCount > 1 )
614 {
615 int blockShift = 0;
616
617 if( attrs.m_Valign == GR_TEXT_V_ALIGN_CENTER )
618 blockShift = ( lineCount - 1 ) * interline / 2;
619 else if( attrs.m_Valign == GR_TEXT_V_ALIGN_BOTTOM )
620 blockShift = ( lineCount - 1 ) * interline;
621
622 if( screenHoriz )
623 linePos.y -= blockShift;
624 else
625 linePos.x -= blockShift;
626 }
627
628 // Set to false since each line is plotted separately with its own position
629 attrs.m_Multiline = false;
630
631 for( unsigned ii = 0; ii < strings_list.Count(); ii++ )
632 {
633 aPlotter->PlotText( linePos, color, strings_list.Item( ii ), attrs, font, GetFontMetrics() );
634
635 if( screenHoriz )
636 linePos.y += interline;
637 else
638 linePos.x += interline;
639 }
640 }
641 else
642 {
644 VECTOR2I text_offset = GetSchematicTextOffset( aPlotter->RenderSettings() );
645
646 text_offset += GetOffsetToMatchSCH_FIELD( renderSettings );
647
648 std::vector<VECTOR2I> positions;
649 wxArrayString strings_list;
650 wxStringSplit( GetShownText( sheet, FOR_CANVAS ), strings_list, '\n' );
651 positions.reserve( strings_list.Count() );
652
653 GetLinePositions( renderSettings, positions, (int) strings_list.Count() );
654
655 attrs.m_Multiline = false;
656
657 for( unsigned ii = 0; ii < strings_list.Count(); ii++ )
658 {
659 VECTOR2I textpos = positions[ii] + text_offset;
660 wxString& txt = strings_list.Item( ii );
661 aPlotter->PlotText( textpos, color, txt, attrs, font, GetFontMetrics() );
662 }
663
664 if( HasHyperlink() )
665 aPlotter->HyperlinkBox( GetBoundingBox(), GetHyperlink() );
666 }
667}
668
669
670void SCH_TEXT::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList )
671{
672 wxString msg;
673
674 // Don't use GetShownText() here; we want to show the user the variable references
675 aList.emplace_back( _( "Text" ), KIUI::EllipsizeStatusText( aFrame, GetText() ) );
676
677 SCH_ITEM::GetMsgPanelInfo( aFrame, aList );
678
680 aList.emplace_back( _( "Exclude from" ), _( "Simulation" ) );
681
682 aList.emplace_back( _( "Font" ), GetFont() ? GetFont()->GetName() : _( "Default" ) );
683
684 wxString textStyle[] = { _( "Normal" ), _( "Italic" ), _( "Bold" ), _( "Bold Italic" ) };
685 int style = IsBold() && IsItalic() ? 3 : IsBold() ? 2 : IsItalic() ? 1 : 0;
686 aList.emplace_back( _( "Style" ), textStyle[style] );
687
688 aList.emplace_back( _( "Text Size" ), aFrame->MessageTextFromValue( GetTextWidth() ) );
689
690 switch( GetHorizJustify() )
691 {
692 case GR_TEXT_H_ALIGN_LEFT: msg = _( "Align left" ); break;
693 case GR_TEXT_H_ALIGN_CENTER: msg = _( "Align center" ); break;
694 case GR_TEXT_H_ALIGN_RIGHT: msg = _( "Align right" ); break;
696 }
697
698 if( m_layer == LAYER_DEVICE )
699 {
700 aList.emplace_back( _( "H Justification" ), msg );
701
702 switch( GetVertJustify() )
703 {
704 case GR_TEXT_V_ALIGN_TOP: msg = _( "Top" ); break;
705 case GR_TEXT_V_ALIGN_CENTER: msg = _( "Center" ); break;
706 case GR_TEXT_V_ALIGN_BOTTOM: msg = _( "Bottom" ); break;
708 }
709
710 aList.emplace_back( _( "V Justification" ), msg );
711 }
712 else
713 {
714 aList.emplace_back( _( "Justification" ), msg );
715 }
716}
717
718
719bool SCH_TEXT::operator==( const SCH_ITEM& aOther ) const
720{
721 if( Type() != aOther.Type() )
722 return false;
723
724 const SCH_TEXT* other = static_cast<const SCH_TEXT*>( &aOther );
725
726 if( GetLayer() != other->GetLayer() )
727 return false;
728
729 if( GetExcludedFromSim() != other->GetExcludedFromSim() )
730 return false;
731
732 return EDA_TEXT::operator==( *other );
733}
734
735
736double SCH_TEXT::Similarity( const SCH_ITEM& aOther ) const
737{
738 if( m_Uuid == aOther.m_Uuid )
739 return 1.0;
740
741 if( Type() != aOther.Type() )
742 return 0.0;
743
744 const SCH_TEXT* other = static_cast<const SCH_TEXT*>( &aOther );
745
746 double retval = SimilarityBase( aOther );
747
748 if( GetLayer() != other->GetLayer() )
749 retval *= 0.9;
750
751 if( GetExcludedFromSim() != other->GetExcludedFromSim() )
752 retval *= 0.9;
753
754 retval *= EDA_TEXT::Similarity( *other );
755
756 return retval;
757}
758
759
760int SCH_TEXT::compare( const SCH_ITEM& aOther, int aCompareFlags ) const
761{
762 wxASSERT( aOther.Type() == SCH_TEXT_T );
763
764 int retv = SCH_ITEM::compare( aOther, aCompareFlags );
765
766 if( retv )
767 return retv;
768
769 const SCH_TEXT& tmp = static_cast<const SCH_TEXT&>( aOther );
770
771 int result = GetText().CmpNoCase( tmp.GetText() );
772
773 if( result != 0 )
774 return result;
775
776 if( GetTextPos().x != tmp.GetTextPos().x )
777 return GetTextPos().x - tmp.GetTextPos().x;
778
779 if( GetTextPos().y != tmp.GetTextPos().y )
780 return GetTextPos().y - tmp.GetTextPos().y;
781
782 if( GetTextWidth() != tmp.GetTextWidth() )
783 return GetTextWidth() - tmp.GetTextWidth();
784
785 if( GetTextHeight() != tmp.GetTextHeight() )
786 return GetTextHeight() - tmp.GetTextHeight();
787
788 return 0;
789}
790
791
792#if defined( DEBUG )
793
794void SCH_TEXT::Show( int nestLevel, std::ostream& os ) const
795{
796 // XML output:
797 wxString s = GetClass();
798
799 NestedSpace( nestLevel, os ) << '<' << s.Lower().mb_str() << " layer=\"" << m_layer << '"' << '>'
800 << TO_UTF8( GetText() ) << "</" << s.Lower().mb_str() << ">\n";
801}
802
803#endif
804
805
806static struct SCH_TEXT_DESC
807{
809 {
816
817 propMgr.Mask( TYPE_HASH( SCH_TEXT ), TYPE_HASH( EDA_TEXT ), _HKI( "Mirrored" ) );
818 propMgr.Mask( TYPE_HASH( SCH_TEXT ), TYPE_HASH( EDA_TEXT ), _HKI( "Width" ) );
819 propMgr.Mask( TYPE_HASH( SCH_TEXT ), TYPE_HASH( EDA_TEXT ), _HKI( "Height" ) );
820 propMgr.Mask( TYPE_HASH( SCH_TEXT ), TYPE_HASH( EDA_TEXT ), _HKI( "Thickness" ) );
821
822 propMgr.AddProperty( new PROPERTY<SCH_TEXT, int>( _HKI( "Text Size" ),
824 _HKI( "Text Properties" ) );
825
826 // Orientation is exposed differently in schematic; mask the base for now
827 propMgr.Mask( TYPE_HASH( SCH_TEXT ), TYPE_HASH( EDA_TEXT ), _HKI( "Orientation" ) );
828 }
constexpr EDA_IU_SCALE schIUScale
Definition base_units.h:130
BITMAPS
A list of all bitmap identifiers.
BOX2< VECTOR2I > BOX2I
Definition box2.h:917
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
Definition box2.h:985
constexpr BOX2< Vec > & Inflate(coord_type dx, coord_type dy)
Inflates the rectangle horizontally by dx and vertically by dy.
Definition box2.h:556
constexpr const Vec GetEnd() const
Definition box2.h:215
constexpr void SetOrigin(const Vec &pos)
Definition box2.h:240
constexpr BOX2< Vec > & Normalize()
Ensure that the height and width are positive.
Definition box2.h:149
constexpr size_type GetWidth() const
Definition box2.h:217
constexpr size_type GetHeight() const
Definition box2.h:218
constexpr bool Contains(const Vec &aPoint) const
Definition box2.h:171
constexpr const Vec & GetOrigin() const
Definition box2.h:213
constexpr void SetEnd(coord_type x, coord_type y)
Definition box2.h:300
constexpr bool Intersects(const BOX2< Vec > &aRect) const
Definition box2.h:314
static const COLOR4D WHITE
Definition color4d.h:403
static const COLOR4D UNSPECIFIED
For legacy support; used as a value to indicate color hasn't been set yet.
Definition color4d.h:400
The base class for create windows for drawing purpose.
const KIID m_Uuid
Definition eda_item.h:599
KICAD_T Type() const
Returns the type of object.
Definition eda_item.h:110
EDA_ITEM_FLAGS m_flags
Definition eda_item.h:608
EDA_ITEM * m_parent
Owner.
Definition eda_item.h:609
EDA_ANGLE GetAngle() const
Definition eda_angle.h:557
A mix-in class (via multiple inheritance) that handles texts such as labels, parts,...
Definition eda_text.h:94
void Serialize(google::protobuf::Any &aContainer) const override
Serializes this object to the given Any message.
Definition eda_text.cpp:170
virtual VECTOR2I GetTextSize() const
Definition eda_text.h:301
COLOR4D GetTextColor() const
Definition eda_text.h:310
virtual VECTOR2I GetTextPos() const
Definition eda_text.h:313
bool IsItalic() const
Definition eda_text.h:200
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition eda_text.h:118
virtual bool IsVisible() const
Definition eda_text.h:226
virtual void SetTextPos(const VECTOR2I &aPoint)
Definition eda_text.cpp:557
virtual void SetTextX(int aX)
Definition eda_text.cpp:564
virtual int GetTextHeight() const
Definition eda_text.h:307
bool Deserialize(const google::protobuf::Any &aContainer) override
Deserializes the given protobuf message into this object.
Definition eda_text.cpp:201
KIFONT::FONT * GetFont() const
Definition eda_text.h:286
virtual void SetTextY(int aY)
Definition eda_text.cpp:570
virtual EDA_ANGLE GetDrawRotation() const
Definition eda_text.h:425
virtual VECTOR2I GetDrawPos() const
Definition eda_text.h:426
wxString m_hyperlink
A hyperlink URL.
Definition eda_text.h:508
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:755
virtual bool HasHyperlink() const
Definition eda_text.h:448
virtual wxString GetShownText(RESOLUTION_CONTEXT aContext, int aDepth=0) const
Return the string actually shown after processing of the base text.
Definition eda_text.h:128
void SetVertJustify(GR_TEXT_V_ALIGN_T aType)
Definition eda_text.cpp:379
wxString GetHyperlink() const
Definition eda_text.h:449
virtual int GetTextWidth() const
Definition eda_text.h:304
GR_TEXT_H_ALIGN_T GetHorizJustify() const
Definition eda_text.h:239
bool HasTextVars() const
Indicates the ShownText has text var references which need to be processed.
Definition eda_text.h:139
bool containsURL() const
EDA_TEXT(const EDA_IU_SCALE &aIuScale, const wxString &aText=wxEmptyString)
Definition eda_text.cpp:98
wxString m_activeUrl
Definition eda_text.h:510
double Similarity(const EDA_TEXT &aOther) const
void FlipHJustify()
Definition eda_text.h:247
virtual EDA_ANGLE GetTextAngle() const
Definition eda_text.h:178
const TEXT_ATTRIBUTES & GetAttributes() const
Definition eda_text.h:270
int GetEffectiveTextPenWidth(int aDefaultPenWidth=0) const
The EffectiveTextPenWidth uses the text thickness if > 1 or aDefaultPenWidth.
Definition eda_text.cpp:428
void SwapAttributes(EDA_TEXT &aTradingPartner)
Swap the text attributes of the two involved instances.
Definition eda_text.cpp:415
void GetLinePositions(const RENDER_SETTINGS *aSettings, std::vector< VECTOR2I > &aPositions, int aLineCount) const
Populate aPositions with the position of each line of a multiline text, according to the vertical jus...
Definition eda_text.cpp:932
bool IsBold() const
Definition eda_text.h:215
GR_TEXT_V_ALIGN_T GetVertJustify() const
Definition eda_text.h:242
int GetInterline(const RENDER_SETTINGS *aSettings) const
Return the distance between two lines of text.
Definition eda_text.cpp:748
virtual void SetTextAngle(const EDA_ANGLE &aAngle)
Definition eda_text.cpp:269
void SwapText(EDA_TEXT &aTradingPartner)
Definition eda_text.cpp:407
bool operator==(const EDA_TEXT &aRhs) const
Definition eda_text.h:444
void SetMultilineAllowed(bool aAllow)
Definition eda_text.cpp:363
void SetHorizJustify(GR_TEXT_H_ALIGN_T aType)
Definition eda_text.cpp:371
FONT is an abstract base class for both outline and stroke fonts.
Definition font.h:94
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:144
A color representation with 4 components: red, green, blue, alpha.
Definition color4d.h:101
std::shared_ptr< wxString > m_text
Definition color4d.h:397
COLOR4D & Desaturate()
Removes color (in HSL model)
Definition color4d.cpp:530
COLOR4D Mix(const COLOR4D &aColor, double aFactor) const
Return a color that is mixed with the input by a factor.
Definition color4d.h:293
Container for all the knowledge about how graphical objects are drawn on any output surface/device.
const COLOR4D & GetLayerColor(int aLayer) const
Return the color used to draw a layer.
Definition kiid.h:46
Base plotter engine class.
Definition plotter.h:138
RENDER_SETTINGS * RenderSettings()
Definition plotter.h:169
virtual void HyperlinkBox(const BOX2I &aBox, const wxString &aDestinationURL)
Create a clickable hyperlink with a rectangular click area.
Definition plotter.h:527
bool GetColorMode() const
Definition plotter.h:166
virtual void SetCurrentLineWidth(int width, void *aData=nullptr)=0
Set the line width for the next drawing.
virtual void PlotText(const VECTOR2I &aPos, const COLOR4D &aColor, const wxString &aText, const TEXT_ATTRIBUTES &aAttributes, KIFONT::FONT *aFont=nullptr, const KIFONT::METRICS &aFontMetrics=KIFONT::METRICS::Default(), void *aData=nullptr)
Definition plotter.cpp:618
Provide class metadata.
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 AddTypeCast(TYPE_CAST_BASE *aCast)
Register a type converter.
Holds all the data relating to one schematic.
Definition schematic.h:155
SCHEMATIC_SETTINGS & Settings() const
SCH_SHEET_PATH & CurrentSheet() const
Definition schematic.h:399
Each graphical item can have a SCH_CONNECTION describing its logical connection (to a bus or net).
bool IsBus() const
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition sch_item.h:170
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.
void SetLocked(bool aLocked) override
Definition sch_item.h:262
const wxString & GetDefaultFont(const KIGFX::RENDER_SETTINGS *aSettings) const
SCH_RENDER_SETTINGS * getRenderSettings(PLOTTER *aPlotter) const
Definition sch_item.cpp:46
SCHEMATIC * Schematic() const
Search the item hierarchy to find a SCHEMATIC.
Definition sch_item.cpp:302
bool IsLocked() const override
Definition sch_item.cpp:179
friend class LIB_SYMBOL
Definition sch_item.h:822
bool IsPrivate() const
Definition sch_item.h:259
SCH_LAYER_ID GetLayer() const
Return the layer this item is on.
Definition sch_item.h:353
SCH_ITEM(EDA_ITEM *aParent, KICAD_T aType, int aUnit=0, int aBodyStyle=0)
Definition sch_item.cpp:65
SCH_CONNECTION * Connection(const SCH_SHEET_PATH *aSheet=nullptr) const
Retrieve the connection associated with this object in the given sheet.
Definition sch_item.cpp:580
wxString ResolveText(const wxString &aText, const SCH_SHEET_PATH *aPath, int aDepth=0) const
Definition sch_item.cpp:464
virtual int compare(const SCH_ITEM &aOther, int aCompareFlags=~COMPARE_FLAGS::UNIT) const
Provide the draw object specific comparison called by the == and < operators.
Definition sch_item.cpp:935
const KIFONT::METRICS & GetFontMetrics() const
SCH_LAYER_ID m_layer
Definition sch_item.h:843
double SimilarityBase(const SCH_ITEM &aItem) const
Calculate the boilerplate similarity for all LIB_ITEMs without preventing the use above of a pure vir...
Definition sch_item.h:403
Handle actions specific to the schematic editor.
void HypertextCommand(const wxString &aHref)
VECTOR2I TransformCoordinate(const VECTOR2I &aPoint) const
const KIGFX::COLOR4D & GetBackgroundColor() const override
Return current background color settings.
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
SCH_SHEET * Last() const
Return a pointer to the last SCH_SHEET of the list.
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition sch_sheet.h:50
bool ResolveTextVar(const SCH_SHEET_PATH *aPath, wxString *token, int aDepth=0) const
Resolve any references to system tokens supported by the sheet.
Schematic symbol object.
Definition sch_symbol.h:76
wxString GetItemDescription(UNITS_PROVIDER *aUnitsProvider, bool aFull) const override
Return a user-visible description string of this item.
Definition sch_text.cpp:434
int compare(const SCH_ITEM &aOther, int aCompareFlags=0) const override
Provide the draw object specific comparison called by the == and < operators.
Definition sch_text.cpp:760
BITMAPS GetMenuImage() const override
Return a pointer to an image to be used in menus.
Definition sch_text.cpp:441
int GetSchTextSize() const
Definition sch_text.h:73
void swapData(SCH_ITEM *aItem) override
Swap the internal data structures aItem with the schematic item.
Definition sch_text.cpp:277
bool Deserialize(const google::protobuf::Any &aContainer) override
Deserializes the given protobuf message into this object.
Definition sch_text.cpp:98
KIFONT::FONT * GetDrawFont(const RENDER_SETTINGS *aSettings) const override
Definition sch_text.cpp:332
bool m_excludedFromSim
Definition sch_text.h:193
void SetExcludedFromSim(bool aExclude, const SCH_SHEET_PATH *aInstance=nullptr, const wxString &aVariantName=wxEmptyString) override
Definition sch_text.h:80
bool GetExcludedFromSim(const SCH_SHEET_PATH *aInstance=nullptr, const wxString &aVariantName=wxEmptyString) const override
Definition sch_text.h:86
void DoHypertextAction(EDA_DRAW_FRAME *aFrame, const VECTOR2I &aMousePos) const override
Definition sch_text.cpp:423
void MirrorVertically(int aCenter) override
Mirror item vertically about aCenter.
Definition sch_text.cpp:206
void Rotate(const VECTOR2I &aCenter, bool aRotateCCW) override
Rotate the item around aCenter 90 degrees in the clockwise direction.
Definition sch_text.cpp:245
void CalcEdit(const VECTOR2I &aPosition) override
Calculate the attributes of an item at aPosition when it is being edited.
Definition sch_text.cpp:487
wxString GetClass() const override
Return the class name.
Definition sch_text.h:51
void NormalizeJustification(bool inverse)
Definition sch_text.cpp:127
bool operator<(const SCH_ITEM &aItem) const override
Definition sch_text.cpp:288
VECTOR2I GetPosition() const override
Definition sch_text.h:143
VECTOR2I GetOffsetToMatchSCH_FIELD(SCH_RENDER_SETTINGS *aRenderSettings) const
Definition sch_text.cpp:502
virtual void Rotate90(bool aClockwise)
Definition sch_text.cpp:257
void SetPosition(const VECTOR2I &aPosition) override
Definition sch_text.h:144
std::vector< int > ViewGetLayers() const override
Return the layers the item is drawn on (which may be more than its "home" layer)
Definition sch_text.cpp:493
void MirrorHorizontally(int aCenter) override
Mirror item horizontally about aCenter.
Definition sch_text.cpp:167
double Similarity(const SCH_ITEM &aItem) const override
Return a measure of how likely the other object is to represent the same object.
Definition sch_text.cpp:736
const BOX2I GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
Definition sch_text.cpp:343
int GetPenWidth() const override
Definition sch_text.cpp:326
bool HasHoveredHypertext() const override
Indicates that a hypertext link is currently active.
Definition sch_text.cpp:417
virtual wxString GetShownText(const SCH_SHEET_PATH *aPath, RESOLUTION_CONTEXT aContext, int aDepth=0) const
Definition sch_text.cpp:364
void SetSchTextSize(int aSize)
Definition sch_text.h:74
void Plot(PLOTTER *aPlotter, bool aBackground, const SCH_PLOT_OPTS &aPlotOpts, int aUnit, int aBodyStyle, const VECTOR2I &aOffset, bool aDimmed) override
Plot the item to aPlotter.
Definition sch_text.cpp:519
bool HitTest(const VECTOR2I &aPosition, int aAccuracy=0) const override
Test if aPosition is inside or on the boundary of this item.
Definition sch_text.cpp:447
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 sch_text.cpp:670
void BeginEdit(const VECTOR2I &aStartPoint) override
Begin drawing a symbol library draw item at aPosition.
Definition sch_text.cpp:481
virtual VECTOR2I GetSchematicTextOffset(const RENDER_SETTINGS *aSettings) const
This offset depends on the orientation, the type of text, and the area required to draw the associate...
Definition sch_text.cpp:120
void Serialize(google::protobuf::Any &aContainer) const override
Serializes this object to the given Any message.
Definition sch_text.cpp:77
virtual void MirrorSpinStyle(bool aLeftRight)
Definition sch_text.cpp:268
bool HasHypertext() const override
Indicates that the item has at least one hypertext action.
Definition sch_text.cpp:411
bool operator==(const SCH_ITEM &aItem) const override
Definition sch_text.cpp:719
int GetTextOffset(const RENDER_SETTINGS *aSettings=nullptr) const
Definition sch_text.cpp:311
SCH_TEXT(const VECTOR2I &aPos={ 0, 0 }, const wxString &aText=wxEmptyString, SCH_LAYER_ID aLayer=LAYER_NOTES, KICAD_T aType=SCH_TEXT_T)
Definition sch_text.cpp:56
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
EDA_ORIENTATION m_Angle
GR_TEXT_H_ALIGN_T m_Halign
GR_TEXT_V_ALIGN_T m_Valign
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
T * GetTool()
Return the tool of given type or nullptr if there is no such tool registered.
for transforming drawing coordinates for a wxDC device context.
Definition transform.h:42
wxString MessageTextFromValue(double aValue, bool aAddUnitLabel=true, EDA_DATA_TYPE aType=EDA_DATA_TYPE::DISTANCE) const
A lower-precision version of StringFromValue().
void FinalizeTextVarExpansion(wxString &aText, RESOLUTION_CONTEXT aContext)
Definition common.cpp:88
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:333
RESOLUTION_CONTEXT
Definition common.h:91
@ FOR_GUI
Definition common.h:93
@ FOR_CANVAS
Definition common.h:92
@ RAW_VALUE
Definition common.h:98
#define DEFAULT_TEXT_OFFSET_RATIO
Ratio of the font height to the baseline of the text above the wire.
#define _(s)
static constexpr EDA_ANGLE ANGLE_90
Definition eda_angle.h:474
static constexpr EDA_ANGLE ANGLE_VERTICAL
Definition eda_angle.h:469
static constexpr EDA_ANGLE ANGLE_HORIZONTAL
Definition eda_angle.h:468
static constexpr EDA_ANGLE ANGLE_270
Definition eda_angle.h:477
#define STRUCT_DELETED
flag indication structures to be erased
#define SKIP_STRUCT
flag indicating that the structure should be ignored
a few functions useful in geometry calculations.
SCH_LAYER_ID
Eeschema drawing layers.
Definition layer_ids.h:480
@ LAYER_DEVICE
Definition layer_ids.h:497
@ LAYER_HIDDEN
Definition layer_ids.h:523
@ LAYER_PRIVATE_NOTES
Definition layer_ids.h:499
@ LAYER_BUS
Definition layer_ids.h:484
@ LAYER_SELECTION_SHADOWS
Definition layer_ids.h:526
constexpr T MIRRORVAL(T aPoint, T aMirrorRef)
Returns the mirror of aPoint relative to the aMirrorRef.
Definition mirror.h:35
Message panel definition file.
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 void PackCustomProperties(google::protobuf::RepeatedPtrField< types::CustomProperty > *aOutput, const EDA_ITEM &aItem)
KICOMMON_API VECTOR2I UnpackVector2(const types::Vector2 &aInput, const EDA_IU_SCALE &aScale)
KICOMMON_API void PackVector2(types::Vector2 &aOutput, const VECTOR2I &aInput, const EDA_IU_SCALE &aScale)
KICOMMON_API void UnpackCustomProperties(const google::protobuf::RepeatedPtrField< types::CustomProperty > &aInput, EDA_ITEM &aItem)
#define _HKI(x)
Definition page_info.cpp:40
see class PGM_BASE
#define TYPE_HASH(x)
Macro to generate unique identifier for a type.
Definition property.h:74
@ PT_SIZE
Size expressed in distance units (mm/inch)
Definition property.h:63
#define REGISTER_TYPE(x)
Helper macro to map type hashes to names.
static struct SCH_TEXT_DESC _SCH_TEXT_DESC
void wxStringSplit(const wxString &aText, wxArrayString &aStrings, wxChar aSplitter)
Split aString to a string list separated at aSplitter.
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
VECTOR2I end
wxString result
Test unit parsing edge cases and error handling.
int delta
@ GR_TEXT_H_ALIGN_CENTER
@ GR_TEXT_H_ALIGN_RIGHT
@ GR_TEXT_H_ALIGN_LEFT
@ GR_TEXT_H_ALIGN_INDETERMINATE
@ GR_TEXT_V_ALIGN_BOTTOM
@ GR_TEXT_V_ALIGN_INDETERMINATE
@ GR_TEXT_V_ALIGN_CENTER
@ GR_TEXT_V_ALIGN_TOP
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:227
KICAD_T
The set of class identification values stored in EDA_ITEM::m_structType.
Definition typeinfo.h:70
@ SCH_TEXT_T
Definition typeinfo.h:147
#define INDETERMINATE_STATE
Used for holding indeterminate values, such as with multiple selections holding different values or c...
Definition ui_common.h:48
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:708
static PIECE rect(double aLeft, double aTop, double aRight, double aBottom, bool aMixed=false)