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