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