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 (C) 1992-2023 KiCad Developers, see AUTHORS.txt for contributors.
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, you may find one here:
20 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
21 * or you may search the http://www.gnu.org website for the version 2 license,
22 * or you may write to the Free Software Foundation, Inc.,
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24 */
25
26#include <base_units.h>
27#include <pgm_base.h>
28#include <sch_edit_frame.h>
29#include <sch_plotter.h>
30#include <widgets/msgpanel.h>
31#include <bitmaps.h>
32#include <string_utils.h>
33#include <sch_text.h>
34#include <schematic.h>
36#include <sch_painter.h>
37#include <default_values.h>
38#include <wx/debug.h>
39#include <wx/log.h>
43#include <core/mirror.h>
44#include <core/kicad_algo.h>
46#include <trigo.h>
47
48
49SCH_TEXT::SCH_TEXT( const VECTOR2I& aPos, const wxString& aText, SCH_LAYER_ID aLayer,
50 KICAD_T aType ) :
51 SCH_ITEM( nullptr, aType ),
52 EDA_TEXT( schIUScale, aText )
53{
54 m_layer = aLayer;
55
56 SetTextPos( aPos );
57 SetMultilineAllowed( true );
58
59 m_excludedFromSim = false;
60}
61
62
64 SCH_ITEM( aText ),
65 EDA_TEXT( aText )
66{
68}
69
70
72{
73 // Fudge factor to match KiCad 6
74 return VECTOR2I( 0, -2500 );
75}
76
77
79{
81 return;
82
83 VECTOR2I delta( 0, 0 );
84 BOX2I bbox = GetTextBox();
85
86 if( GetTextAngle().IsHorizontal() )
87 {
89 delta.x = bbox.GetWidth() / 2;
91 delta.x = - bbox.GetWidth() / 2;
92
94 delta.y = - bbox.GetHeight() / 2;
96 delta.y = bbox.GetHeight() / 2;
97 }
98 else
99 {
101 delta.y = bbox.GetWidth() / 2;
103 delta.y = - bbox.GetWidth() / 2;
104
106 delta.x = + bbox.GetHeight() / 2;
108 delta.x = - bbox.GetHeight() / 2;
109 }
110
111 if( inverse )
113 else
115}
116
117
119{
120 if( m_layer == LAYER_DEVICE )
121 {
122 NormalizeJustification( false );
123 int x = GetTextPos().x;
124
125 x -= aCenter;
126 x *= -1;
127 x += aCenter;
128
129 if( GetTextAngle().IsHorizontal() )
130 {
135 }
136 else
137 {
142 }
143
144 SetTextX( x );
146 }
147 else
148 {
150 FlipHJustify();
151
152 SetTextX( MIRRORVAL( GetTextPos().x, aCenter ) );
153 }
154}
155
156
157void SCH_TEXT::MirrorVertically( int aCenter )
158{
159 if( m_layer == LAYER_DEVICE )
160 {
161 NormalizeJustification( false );
162 int y = GetTextPos().y;
163
164 y -= aCenter;
165 y *= -1;
166 y += aCenter;
167
168 if( GetTextAngle().IsHorizontal() )
169 {
174 }
175 else
176 {
181 }
182
183 SetTextY( y );
185 }
186 else
187 {
189 FlipHJustify();
190
191 SetTextY( MIRRORVAL( GetTextPos().y, aCenter ) );
192 }
193}
194
195
196void SCH_TEXT::Rotate( const VECTOR2I& aCenter, bool aRotateCCW )
197{
198 VECTOR2I pt = GetTextPos();
199 RotatePoint( pt, aCenter, aRotateCCW ? ANGLE_90 : ANGLE_270 );
200 VECTOR2I offset = pt - GetTextPos();
201
202 Rotate90( false );
203
204 SetTextPos( GetTextPos() + offset );
205}
206
207
208void SCH_TEXT::Rotate90( bool aClockwise )
209{
210 if( ( GetTextAngle() == ANGLE_HORIZONTAL && aClockwise )
211 || ( GetTextAngle() == ANGLE_VERTICAL && !aClockwise ) )
212 {
213 FlipHJustify();
214 }
215
217}
218
219
220void SCH_TEXT::MirrorSpinStyle( bool aLeftRight )
221{
222 if( ( GetTextAngle() == ANGLE_HORIZONTAL && aLeftRight )
223 || ( GetTextAngle() == ANGLE_VERTICAL && !aLeftRight ) )
224 {
225 FlipHJustify();
226 }
227}
228
229
231{
232 SCH_ITEM::SwapFlags( aItem );
233
234 SCH_TEXT* item = static_cast<SCH_TEXT*>( aItem );
235
236 std::swap( m_layer, item->m_layer );
237
238 SwapText( *item );
239 SwapAttributes( *item );
240}
241
242
243bool SCH_TEXT::operator<( const SCH_ITEM& aItem ) const
244{
245 if( Type() != aItem.Type() )
246 return Type() < aItem.Type();
247
248 auto other = static_cast<const SCH_TEXT*>( &aItem );
249
250 if( GetLayer() != other->GetLayer() )
251 return GetLayer() < other->GetLayer();
252
253 if( GetPosition().x != other->GetPosition().x )
254 return GetPosition().x < other->GetPosition().x;
255
256 if( GetPosition().y != other->GetPosition().y )
257 return GetPosition().y < other->GetPosition().y;
258
259 if( GetExcludedFromSim() != other->GetExcludedFromSim() )
260 return GetExcludedFromSim() - other->GetExcludedFromSim();
261
262 return GetText() < other->GetText();
263}
264
265
266int SCH_TEXT::GetTextOffset( const RENDER_SETTINGS* aSettings ) const
267{
268 double ratio;
269
270 if( aSettings )
271 ratio = static_cast<const SCH_RENDER_SETTINGS*>( aSettings )->m_TextOffsetRatio;
272 else if( Schematic() )
274 else
275 ratio = DEFAULT_TEXT_OFFSET_RATIO; // For previews (such as in Preferences), etc.
276
277 return KiROUND( ratio * GetTextSize().y );
278}
279
280
282{
284}
285
286
288{
290
291 if( !font )
293
294 return font;
295}
296
297
298void SCH_TEXT::Print( const SCH_RENDER_SETTINGS* aSettings, int aUnit, int aBodyStyle,
299 const VECTOR2I& aOffset, bool aForceNoFill, bool aDimmed )
300{
302 COLOR4D bg = aSettings->GetBackgroundColor();
303 bool blackAndWhiteMode = GetGRForceBlackPenState();
304
305 if( blackAndWhiteMode || color == COLOR4D::UNSPECIFIED )
306 color = aSettings->GetLayerColor( m_layer );
307
308 if( bg == COLOR4D::UNSPECIFIED || GetGRForceBlackPenState() )
309 bg = COLOR4D::WHITE;
310
311 if( !IsVisible() )
312 bg = aSettings->GetLayerColor( LAYER_HIDDEN );
313
314 if( aDimmed )
315 {
316 color.Desaturate( );
317 color = color.Mix( bg, 0.5f );
318 }
319
320 KIFONT::FONT* font = GetFont();
321
322 if( !font )
323 font = KIFONT::FONT::GetFont( aSettings->GetDefaultFont(), IsBold(), IsItalic() );
324
325 if( m_layer == LAYER_DEVICE )
326 {
327 wxDC* DC = aSettings->GetPrintDC();
328 int penWidth = std::max( GetEffectiveTextPenWidth(), aSettings->GetDefaultPenWidth() );
329
330 // Calculate the text orientation, according to the symbol orientation/mirror (needed when
331 // draw text in schematic)
332 EDA_ANGLE orient = GetTextAngle();
333
334 if( aSettings->m_Transform.y1 ) // Rotate symbol 90 degrees.
335 {
336 if( orient == ANGLE_HORIZONTAL )
337 orient = ANGLE_VERTICAL;
338 else
339 orient = ANGLE_HORIZONTAL;
340 }
341
342 /*
343 * Calculate the text justification, according to the symbol orientation/mirror.
344 * This is a bit complicated due to cumulative calculations:
345 * - numerous cases (mirrored or not, rotation)
346 * - the GRText function will also recalculate H and V justifications according to the text
347 * orientation.
348 * - When a symbol is mirrored, the text is not mirrored and justifications are complicated
349 * to calculate so the more easily way is to use no justifications (centered text) and
350 * use GetBoundingBox to know the text coordinate considered as centered
351 */
352 BOX2I bBox = GetBoundingBox();
353 VECTOR2I txtpos = bBox.Centre();
354
355 // Calculate pos according to mirror/rotation.
356 txtpos = aSettings->m_Transform.TransformCoordinate( txtpos ) + aOffset;
357
358 GRPrintText( DC, txtpos, color, GetShownText( true ), orient, GetTextSize(),
360 IsBold(), font, GetFontMetrics() );
361 }
362 else
363 {
364 VECTOR2I text_offset = aOffset + GetSchematicTextOffset( aSettings );
365
366 // Adjust text drawn in an outline font to more closely mimic the positioning of
367 // SCH_FIELD text.
368 if( font->IsOutline() )
369 {
370 BOX2I firstLineBBox = GetTextBox( 0 );
371 int sizeDiff = firstLineBBox.GetHeight() - GetTextSize().y;
372 int adjust = KiROUND( sizeDiff * 0.4 );
373 VECTOR2I adjust_offset( 0, - adjust );
374
375 RotatePoint( adjust_offset, GetDrawRotation() );
376 text_offset += adjust_offset;
377 }
378
379 EDA_TEXT::Print( aSettings, text_offset, color );
380 }
381}
382
383
385{
386 BOX2I bbox = GetTextBox();
387
388 if( !GetTextAngle().IsZero() ) // Rotate bbox.
389 {
390 VECTOR2I pos = bbox.GetOrigin();
391 VECTOR2I end = bbox.GetEnd();
392
395
396 bbox.SetOrigin( pos );
397 bbox.SetEnd( end );
398 }
399
400 bbox.Normalize();
401 return bbox;
402}
403
404
405wxString SCH_TEXT::GetShownText( const SCH_SHEET_PATH* aPath, bool aAllowExtraText,
406 int aDepth ) const
407{
408 SCH_SHEET* sheet = nullptr;
409
410 if( aPath )
411 sheet = aPath->Last();
412 else if( SCHEMATIC* schematic = Schematic() )
413 sheet = schematic->CurrentSheet().Last();
414
415 std::function<bool( wxString* )> textResolver =
416 [&]( wxString* token ) -> bool
417 {
418 if( sheet )
419 {
420 if( sheet->ResolveTextVar( aPath, token, aDepth + 1 ) )
421 return true;
422 }
423
424 return false;
425 };
426
427 wxString text = EDA_TEXT::GetShownText( aAllowExtraText, aDepth );
428
429 if( text == wxS( "~" ) ) // Legacy placeholder for empty string
430 {
431 text = wxS( "" );
432 }
433 else if( HasTextVars() )
434 {
435 if( aDepth < 10 )
436 text = ExpandTextVars( text, &textResolver );
437 }
438
439 return text;
440}
441
442
444{
445 wxCHECK_MSG( IsHypertext(), /* void */,
446 wxT( "Calling a hypertext menu on a SCH_TEXT with no hyperlink?" ) );
447
449 navTool->HypertextCommand( m_hyperlink );
450}
451
452
453wxString SCH_TEXT::GetItemDescription( UNITS_PROVIDER* aUnitsProvider ) const
454{
455 return wxString::Format( _( "Graphic Text '%s'" ), KIUI::EllipsizeMenuText( GetText() ) );
456}
457
458
460{
461 return BITMAPS::text;
462}
463
464
465bool SCH_TEXT::HitTest( const VECTOR2I& aPosition, int aAccuracy ) const
466{
467 BOX2I bBox = GetBoundingBox();
468 bBox.Inflate( aAccuracy );
469 return bBox.Contains( aPosition );
470}
471
472
473bool SCH_TEXT::HitTest( const BOX2I& aRect, bool aContained, int aAccuracy ) const
474{
476 return false;
477
478 BOX2I rect = aRect;
479 BOX2I bBox = GetBoundingBox();
480
481 rect.Inflate( aAccuracy );
482
483 if( aContained )
484 return aRect.Contains( bBox );
485
486 return aRect.Intersects( bBox );
487}
488
489
490void SCH_TEXT::BeginEdit( const VECTOR2I& aPosition )
491{
492 SetTextPos( aPosition );
493}
494
495
496void SCH_TEXT::CalcEdit( const VECTOR2I& aPosition )
497{
498 SetTextPos( aPosition );
499}
500
501
502void SCH_TEXT::ViewGetLayers( int aLayers[], int& aCount ) const
503{
504 aCount = 2;
505 aLayers[0] = IsPrivate() ? LAYER_PRIVATE_NOTES : m_layer;
506 aLayers[1] = LAYER_SELECTION_SHADOWS;
507}
508
509
510void SCH_TEXT::Plot( PLOTTER* aPlotter, bool aBackground, const SCH_PLOT_OPTS& aPlotOpts,
511 int aUnit, int aBodyStyle, const VECTOR2I& aOffset, bool aDimmed )
512{
513 if( aBackground || IsPrivate() )
514 return;
515
516 SCH_RENDER_SETTINGS* renderSettings = getRenderSettings( aPlotter );
518 COLOR4D bg = renderSettings->GetBackgroundColor();
519
520 if( !aPlotter->GetColorMode() || color == COLOR4D::UNSPECIFIED )
521 {
522 SCH_CONNECTION* connection = Connection();
523
524 if( connection && connection->IsBus() )
525 color = renderSettings->GetLayerColor( LAYER_BUS );
526 else
527 color = renderSettings->GetLayerColor( m_layer );
528 }
529
530 if( !IsVisible() )
531 bg = renderSettings->GetLayerColor( LAYER_HIDDEN );
532 else if( bg == COLOR4D::UNSPECIFIED || !aPlotter->GetColorMode() )
533 bg = COLOR4D::WHITE;
534
535 if( aDimmed )
536 {
537 color.Desaturate( );
538 color = color.Mix( bg, 0.5f );
539 }
540
541 int penWidth = GetEffectiveTextPenWidth( renderSettings->GetDefaultPenWidth() );
542 penWidth = std::max( penWidth, renderSettings->GetMinPenWidth() );
543 aPlotter->SetCurrentLineWidth( penWidth );
544
545 KIFONT::FONT* font = GetFont();
546
547 if( !font )
548 font = KIFONT::FONT::GetFont( renderSettings->GetDefaultFont(), IsBold(), IsItalic() );
549
551 attrs.m_StrokeWidth = penWidth;
552
553 if( m_layer == LAYER_DEVICE )
554 {
555 BOX2I bBox = GetBoundingBox();
556
557 /*
558 * Calculate the text justification, according to the symbol orientation/mirror. This is
559 * a bit complicated due to cumulative calculations:
560 * - numerous cases (mirrored or not, rotation)
561 * - the plotter's Text() function will also recalculate H and V justifications according
562 * to the text orientation
563 * - when a symbol is mirrored the text is not, and justifications become a nightmare
564 *
565 * So the easier way is to use no justifications (centered text) and use GetBoundingBox to
566 * know the text coordinate considered as centered.
567 */
568 VECTOR2I txtpos = bBox.Centre();
571
572 // The text orientation may need to be flipped if the transformation matrix causes xy
573 // axes to be flipped.
574 if( ( renderSettings->m_Transform.x1 != 0 ) ^ ( GetTextAngle() != ANGLE_HORIZONTAL ) )
576 else
577 attrs.m_Angle = ANGLE_VERTICAL;
578
579 aPlotter->PlotText( renderSettings->TransformCoordinate( txtpos ) + aOffset, color,
580 GetText(), attrs, font, GetFontMetrics() );
581 }
582 else
583 {
585 VECTOR2I text_offset = GetSchematicTextOffset( aPlotter->RenderSettings() );
586
587 // Adjust text drawn in an outline font to more closely mimic the positioning of
588 // SCH_FIELD text.
589 if( font->IsOutline() )
590 {
591 BOX2I firstLineBBox = GetTextBox( 0 );
592 int sizeDiff = firstLineBBox.GetHeight() - GetTextSize().y;
593 int adjust = KiROUND( sizeDiff * 0.4 );
594 VECTOR2I adjust_offset( 0, - adjust );
595
596 RotatePoint( adjust_offset, GetDrawRotation() );
597 text_offset += adjust_offset;
598 }
599
600 std::vector<VECTOR2I> positions;
601 wxArrayString strings_list;
602 wxStringSplit( GetShownText( sheet, true ), strings_list, '\n' );
603 positions.reserve( strings_list.Count() );
604
605 GetLinePositions( positions, (int) strings_list.Count() );
606
607 attrs.m_Multiline = false;
608
609 for( unsigned ii = 0; ii < strings_list.Count(); ii++ )
610 {
611 VECTOR2I textpos = positions[ii] + text_offset;
612 wxString& txt = strings_list.Item( ii );
613 aPlotter->PlotText( textpos, color, txt, attrs, font, GetFontMetrics() );
614 }
615
616 if( HasHyperlink() )
617 aPlotter->HyperlinkBox( GetBoundingBox(), GetHyperlink() );
618 }
619}
620
621
622void SCH_TEXT::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList )
623{
624 wxString msg;
625
626 // Don't use GetShownText() here; we want to show the user the variable references
627 aList.emplace_back( _( "Text" ), KIUI::EllipsizeStatusText( aFrame, GetText() ) );
628
630 aList.emplace_back( _( "Exclude from" ), _( "Simulation" ) );
631
632 aList.emplace_back( _( "Font" ), GetFont() ? GetFont()->GetName() : _( "Default" ) );
633
634 wxString textStyle[] = { _( "Normal" ), _( "Italic" ), _( "Bold" ), _( "Bold Italic" ) };
635 int style = IsBold() && IsItalic() ? 3 : IsBold() ? 2 : IsItalic() ? 1 : 0;
636 aList.emplace_back( _( "Style" ), textStyle[style] );
637
638 aList.emplace_back( _( "Text Size" ), aFrame->MessageTextFromValue( GetTextWidth() ) );
639
640 switch( GetHorizJustify() )
641 {
642 case GR_TEXT_H_ALIGN_LEFT: msg = _( "Align left" ); break;
643 case GR_TEXT_H_ALIGN_CENTER: msg = _( "Align center" ); break;
644 case GR_TEXT_H_ALIGN_RIGHT: msg = _( "Align right" ); break;
646 }
647
648 if( m_layer == LAYER_DEVICE )
649 {
650 aList.emplace_back( _( "H Justification" ), msg );
651
652 switch ( GetVertJustify() )
653 {
654 case GR_TEXT_V_ALIGN_TOP: msg = _( "Top" ); break;
655 case GR_TEXT_V_ALIGN_CENTER: msg = _( "Center" ); break;
656 case GR_TEXT_V_ALIGN_BOTTOM: msg = _( "Bottom" ); break;
658 }
659
660 aList.emplace_back( _( "V Justification" ), msg );
661 }
662 else
663 {
664 aList.emplace_back( _( "Justification" ), msg );
665 }
666}
667
668bool SCH_TEXT::operator==( const SCH_ITEM& aOther ) const
669{
670 if( Type() != aOther.Type() )
671 return false;
672
673 const SCH_TEXT* other = static_cast<const SCH_TEXT*>( &aOther );
674
675 if( GetLayer() != other->GetLayer() )
676 return false;
677
678 if( GetExcludedFromSim() != other->GetExcludedFromSim() )
679 return false;
680
681 return EDA_TEXT::operator==( *other );
682}
683
684
685double SCH_TEXT::Similarity( const SCH_ITEM& aOther ) const
686{
687 if( m_Uuid == aOther.m_Uuid )
688 return 1.0;
689
690 if( Type() != aOther.Type() )
691 return 0.0;
692
693 const SCH_TEXT* other = static_cast<const SCH_TEXT*>( &aOther );
694
695 double retval = SimilarityBase( aOther );
696
697 if( GetLayer() != other->GetLayer() )
698 retval *= 0.9;
699
700 if( GetExcludedFromSim() != other->GetExcludedFromSim() )
701 retval *= 0.9;
702
703 retval *= EDA_TEXT::Similarity( *other );
704
705 return retval;
706}
707
708
709int SCH_TEXT::compare( const SCH_ITEM& aOther, int aCompareFlags ) const
710{
711 wxASSERT( aOther.Type() == SCH_TEXT_T );
712
713 int retv = SCH_ITEM::compare( aOther, aCompareFlags );
714
715 if( retv )
716 return retv;
717
718 const SCH_TEXT& tmp = static_cast<const SCH_TEXT&>( aOther );
719
720 int result = GetText().CmpNoCase( tmp.GetText() );
721
722 if( result != 0 )
723 return result;
724
725 if( GetTextPos().x != tmp.GetTextPos().x )
726 return GetTextPos().x - tmp.GetTextPos().x;
727
728 if( GetTextPos().y != tmp.GetTextPos().y )
729 return GetTextPos().y - tmp.GetTextPos().y;
730
731 if( GetTextWidth() != tmp.GetTextWidth() )
732 return GetTextWidth() - tmp.GetTextWidth();
733
734 if( GetTextHeight() != tmp.GetTextHeight() )
735 return GetTextHeight() - tmp.GetTextHeight();
736
737 return 0;
738}
739
740
741#if defined(DEBUG)
742
743void SCH_TEXT::Show( int nestLevel, std::ostream& os ) const
744{
745 // XML output:
746 wxString s = GetClass();
747
748 NestedSpace( nestLevel, os ) << '<' << s.Lower().mb_str()
749 << " layer=\"" << m_layer << '"'
750 << '>'
751 << TO_UTF8( GetText() )
752 << "</" << s.Lower().mb_str() << ">\n";
753}
754
755#endif
756
757
758static struct SCH_TEXT_DESC
759{
761 {
768
769 propMgr.Mask( TYPE_HASH( SCH_TEXT ), TYPE_HASH( EDA_TEXT ), _HKI( "Mirrored" ) );
770 propMgr.Mask( TYPE_HASH( SCH_TEXT ), TYPE_HASH( EDA_TEXT ), _HKI( "Visible" ) );
771 propMgr.Mask( TYPE_HASH( SCH_TEXT ), TYPE_HASH( EDA_TEXT ), _HKI( "Width" ) );
772 propMgr.Mask( TYPE_HASH( SCH_TEXT ), TYPE_HASH( EDA_TEXT ), _HKI( "Height" ) );
773 propMgr.Mask( TYPE_HASH( SCH_TEXT ), TYPE_HASH( EDA_TEXT ), _HKI( "Thickness" ) );
774
775 propMgr.AddProperty( new PROPERTY<SCH_TEXT, int>( _HKI( "Text Size" ),
776 &SCH_TEXT::SetSchTextSize, &SCH_TEXT::GetSchTextSize, PROPERTY_DISPLAY::PT_SIZE ),
777 _HKI( "Text Properties" ) );
778
779 // Orientation is exposed differently in schematic; mask the base for now
780 propMgr.Mask( TYPE_HASH( SCH_TEXT ), TYPE_HASH( EDA_TEXT ), _HKI( "Orientation" ) );
781 }
int color
Definition: DXF_plotter.cpp:58
constexpr EDA_IU_SCALE schIUScale
Definition: base_units.h:110
BITMAPS
A list of all bitmap identifiers.
Definition: bitmaps_list.h:33
void SetOrigin(const Vec &pos)
Definition: box2.h:227
BOX2< Vec > & Normalize()
Ensure that the height and width are positive.
Definition: box2.h:136
const Vec & GetOrigin() const
Definition: box2.h:200
size_type GetHeight() const
Definition: box2.h:205
bool Intersects(const BOX2< Vec > &aRect) const
Definition: box2.h:294
size_type GetWidth() const
Definition: box2.h:204
const Vec GetEnd() const
Definition: box2.h:202
bool Contains(const Vec &aPoint) const
Definition: box2.h:158
BOX2< Vec > & Inflate(coord_type dx, coord_type dy)
Inflates the rectangle horizontally by dx and vertically by dy.
Definition: box2.h:541
Vec Centre() const
Definition: box2.h:87
void SetEnd(coord_type x, coord_type y)
Definition: box2.h:280
The base class for create windows for drawing purpose.
const KIID m_Uuid
Definition: eda_item.h:485
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:100
EDA_ITEM_FLAGS m_flags
Definition: eda_item.h:490
A mix-in class (via multiple inheritance) that handles texts such as labels, parts,...
Definition: eda_text.h:83
int GetTextHeight() const
Definition: eda_text.h:228
const VECTOR2I & GetTextPos() const
Definition: eda_text.h:234
COLOR4D GetTextColor() const
Definition: eda_text.h:231
bool IsItalic() const
Definition: eda_text.h:144
const EDA_ANGLE & GetTextAngle() const
Definition: eda_text.h:134
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition: eda_text.h:98
virtual bool IsVisible() const
Definition: eda_text.h:151
void SetTextPos(const VECTOR2I &aPoint)
Definition: eda_text.cpp:417
void SetTextX(int aX)
Definition: eda_text.cpp:423
KIFONT::FONT * GetFont() const
Definition: eda_text.h:211
BOX2I GetTextBox(int aLine=-1) const
Useful in multiline texts to calculate the full text or a line area (for zones filling,...
Definition: eda_text.cpp:565
void SetTextY(int aY)
Definition: eda_text.cpp:429
virtual EDA_ANGLE GetDrawRotation() const
Definition: eda_text.h:340
wxString m_hyperlink
A hyperlink URL.
Definition: eda_text.h:415
int GetTextWidth() const
Definition: eda_text.h:225
virtual bool HasHyperlink() const
Definition: eda_text.h:360
void SetVertJustify(GR_TEXT_V_ALIGN_T aType)
Definition: eda_text.cpp:274
wxString GetHyperlink() const
Definition: eda_text.h:361
GR_TEXT_H_ALIGN_T GetHorizJustify() const
Definition: eda_text.h:164
bool HasTextVars() const
Indicates the ShownText has text var references which need to be processed.
Definition: eda_text.h:117
void GetLinePositions(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:748
double Similarity(const EDA_TEXT &aOther) const
Definition: eda_text.cpp:1144
void FlipHJustify()
Definition: eda_text.h:172
const TEXT_ATTRIBUTES & GetAttributes() const
Definition: eda_text.h:195
int GetEffectiveTextPenWidth(int aDefaultPenWidth=0) const
The EffectiveTextPenWidth uses the text thickness if > 1 or aDefaultPenWidth.
Definition: eda_text.cpp:322
void SwapAttributes(EDA_TEXT &aTradingPartner)
Swap the text attributes of the two involved instances.
Definition: eda_text.cpp:309
bool IsBold() const
Definition: eda_text.h:148
GR_TEXT_V_ALIGN_T GetVertJustify() const
Definition: eda_text.h:167
virtual wxString GetShownText(bool aAllowExtraText, int aDepth=0) const
Return the string actually shown after processing of the base text.
Definition: eda_text.h:109
virtual void SetTextAngle(const EDA_ANGLE &aAngle)
Definition: eda_text.cpp:203
void Print(const RENDER_SETTINGS *aSettings, const VECTOR2I &aOffset, const COLOR4D &aColor, OUTLINE_MODE aDisplay_mode=FILLED)
Print this text object to the device context aDC.
Definition: eda_text.cpp:724
void SwapText(EDA_TEXT &aTradingPartner)
Definition: eda_text.cpp:302
bool operator==(const EDA_TEXT &aRhs) const
Definition: eda_text.h:356
void SetMultilineAllowed(bool aAllow)
Definition: eda_text.cpp:258
VECTOR2I GetTextSize() const
Definition: eda_text.h:222
void SetHorizJustify(GR_TEXT_H_ALIGN_T aType)
Definition: eda_text.cpp:266
FONT is an abstract base class for both outline and stroke fonts.
Definition: font.h:131
static FONT * GetFont(const wxString &aFontName=wxEmptyString, bool aBold=false, bool aItalic=false)
Definition: font.cpp:146
virtual bool IsOutline() const
Definition: font.h:139
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:104
Container for all the knowledge about how graphical objects are drawn on any output surface/device.
int GetDefaultPenWidth() const
const wxString & GetDefaultFont() const
const COLOR4D & GetLayerColor(int aLayer) const
Return the color used to draw a layer.
wxDC * GetPrintDC() const
Base plotter engine class.
Definition: plotter.h:104
RENDER_SETTINGS * RenderSettings()
Definition: plotter.h:135
virtual void HyperlinkBox(const BOX2I &aBox, const wxString &aDestinationURL)
Create a clickable hyperlink with a rectangular click area.
Definition: plotter.h:453
bool GetColorMode() const
Definition: plotter.h:132
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, const KIFONT::METRICS &aFontMetrics, void *aData=nullptr)
Definition: plotter.cpp:753
Provide class metadata.Helper macro to map type hashes to names.
Definition: property_mgr.h:85
void InheritsAfter(TYPE_ID aDerived, TYPE_ID aBase)
Declare an inheritance relationship between types.
void Mask(TYPE_ID aDerived, TYPE_ID aBase, const wxString &aName)
Sets a base class property as masked in a derived class.
static PROPERTY_MANAGER & Instance()
Definition: property_mgr.h:87
PROPERTY_BASE & AddProperty(PROPERTY_BASE *aProperty, const wxString &aGroup=wxEmptyString)
Register a property.
void AddTypeCast(TYPE_CAST_BASE *aCast)
Register a type converter.
Holds all the data relating to one schematic.
Definition: schematic.h:75
SCH_SHEET_PATH & CurrentSheet() const override
Definition: schematic.h:136
SCHEMATIC_SETTINGS & Settings() const
Definition: schematic.cpp:287
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:174
const wxString & GetDefaultFont() const
Definition: sch_item.cpp:447
SCH_RENDER_SETTINGS * getRenderSettings(PLOTTER *aPlotter) const
Definition: sch_item.h:678
SCHEMATIC * Schematic() const
Searches the item hierarchy to find a SCHEMATIC.
Definition: sch_item.cpp:139
bool IsPrivate() const
Definition: sch_item.h:243
SCH_LAYER_ID GetLayer() const
Return the layer this item is on.
Definition: sch_item.h:289
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:408
void SwapFlags(SCH_ITEM *aItem)
Swap the non-temp and non-edit flags.
Definition: sch_item.cpp:343
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:210
const KIFONT::METRICS & GetFontMetrics() const
Definition: sch_item.cpp:455
SCH_LAYER_ID m_layer
Definition: sch_item.h:731
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:324
Handle actions specific to the schematic editor.
void HypertextCommand(const wxString &href)
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:57
bool ResolveTextVar(const SCH_SHEET_PATH *aPath, wxString *token, int aDepth=0) const
Resolve any references to system tokens supported by the sheet.
Definition: sch_sheet.cpp:237
void DoHypertextAction(EDA_DRAW_FRAME *aFrame) const override
Definition: sch_text.cpp:443
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:709
bool IsHypertext() const override
Allow items to support hypertext actions when hovered/clicked.
Definition: sch_text.h:78
BITMAPS GetMenuImage() const override
Return a pointer to an image to be used in menus.
Definition: sch_text.cpp:459
int GetSchTextSize() const
Definition: sch_text.h:75
bool m_excludedFromSim
Definition: sch_text.h:188
void MirrorVertically(int aCenter) override
Mirror item vertically about aCenter.
Definition: sch_text.cpp:157
void Rotate(const VECTOR2I &aCenter, bool aRotateCCW) override
Rotate the item around aCenter 90 degrees in the clockwise direction.
Definition: sch_text.cpp:196
void CalcEdit(const VECTOR2I &aPosition) override
Calculate the attributes of an item at aPosition when it is being edited.
Definition: sch_text.cpp:496
wxString GetClass() const override
Return the class name.
Definition: sch_text.h:52
void NormalizeJustification(bool inverse)
Definition: sch_text.cpp:78
bool operator<(const SCH_ITEM &aItem) const override
Definition: sch_text.cpp:243
VECTOR2I GetPosition() const override
Definition: sch_text.h:141
virtual void Rotate90(bool aClockwise)
Definition: sch_text.cpp:208
KIFONT::FONT * getDrawFont() const override
Definition: sch_text.cpp:287
void MirrorHorizontally(int aCenter) override
Mirror item horizontally about aCenter.
Definition: sch_text.cpp:118
void Print(const SCH_RENDER_SETTINGS *aSettings, int aUnit, int aBodyStyle, const VECTOR2I &offset, bool aForceNoFill, bool aDimmed) override
Print an item.
Definition: sch_text.cpp:298
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:685
void SwapData(SCH_ITEM *aItem) override
Swap the internal data structures aItem with the schematic item.
Definition: sch_text.cpp:230
const BOX2I GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
Definition: sch_text.cpp:384
int GetPenWidth() const override
Definition: sch_text.cpp:281
void SetSchTextSize(int aSize)
Definition: sch_text.h:76
virtual wxString GetShownText(const SCH_SHEET_PATH *aPath, bool aAllowExtraText, int aDepth=0) const
Definition: sch_text.cpp:405
void ViewGetLayers(int aLayers[], int &aCount) const override
Return the layers the item is drawn on (which may be more than its "home" layer)
Definition: sch_text.cpp:502
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:510
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:465
wxString GetItemDescription(UNITS_PROVIDER *aUnitsProvider) const override
Return a user-visible description string of this item.
Definition: sch_text.cpp:453
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:622
void BeginEdit(const VECTOR2I &aStartPoint) override
Begin drawing a symbol library draw item at aPosition.
Definition: sch_text.cpp:490
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:71
bool GetExcludedFromSim() const override
Definition: sch_text.h:86
virtual void MirrorSpinStyle(bool aLeftRight)
Definition: sch_text.cpp:220
bool operator==(const SCH_ITEM &aItem) const override
Definition: sch_text.cpp:668
int GetTextOffset(const RENDER_SETTINGS *aSettings=nullptr) const
Definition: sch_text.cpp:266
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:49
GR_TEXT_H_ALIGN_T m_Halign
GR_TEXT_V_ALIGN_T m_Valign
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
Definition: tools_holder.h:55
int y1
Definition: transform.h:49
VECTOR2I TransformCoordinate(const VECTOR2I &aPoint) const
Calculate a new coordinate according to the mirror/rotation transform.
Definition: transform.cpp:44
int x1
Definition: transform.h:48
wxString MessageTextFromValue(double aValue, bool aAddUnitLabel=true, EDA_DATA_TYPE aType=EDA_DATA_TYPE::DISTANCE) const
A lower-precision version of StringFromValue().
wxString ExpandTextVars(const wxString &aSource, const PROJECT *aProject)
Definition: common.cpp:58
#define DEFAULT_TEXT_OFFSET_RATIO
Ratio of the font height to space around global labels.
#define _HKI(x)
#define _(s)
static constexpr EDA_ANGLE ANGLE_90
Definition: eda_angle.h:437
static constexpr EDA_ANGLE ANGLE_VERTICAL
Definition: eda_angle.h:432
static constexpr EDA_ANGLE ANGLE_HORIZONTAL
Definition: eda_angle.h:431
static constexpr EDA_ANGLE ANGLE_270
Definition: eda_angle.h:440
#define STRUCT_DELETED
flag indication structures to be erased
#define SKIP_STRUCT
flag indicating that the structure should be ignored
bool GetGRForceBlackPenState(void)
Definition: gr_basic.cpp:165
void GRPrintText(wxDC *aDC, const VECTOR2I &aPos, const COLOR4D &aColor, const wxString &aText, const EDA_ANGLE &aOrient, const VECTOR2I &aSize, enum GR_TEXT_H_ALIGN_T aH_justify, enum GR_TEXT_V_ALIGN_T aV_justify, int aWidth, bool aItalic, bool aBold, KIFONT::FONT *aFont, const KIFONT::METRICS &aFontMetrics)
Print a graphic text through wxDC.
Definition: gr_text.cpp:142
SCH_LAYER_ID
Eeschema drawing layers.
Definition: layer_ids.h:353
@ LAYER_DEVICE
Definition: layer_ids.h:370
@ LAYER_HIDDEN
Definition: layer_ids.h:394
@ LAYER_PRIVATE_NOTES
Definition: layer_ids.h:372
@ LAYER_BUS
Definition: layer_ids.h:357
@ LAYER_SELECTION_SHADOWS
Definition: layer_ids.h:395
T MIRRORVAL(T aPoint, T aMirrorRef)
Returns the mirror of aPoint relative to the aMirrorRef.
Definition: mirror.h:31
Message panel definition file.
KICOMMON_API wxString EllipsizeMenuText(const wxString &aString)
Ellipsize text (at the end) to be no more than 36 characters.
Definition: ui_common.cpp:213
KICOMMON_API wxString EllipsizeStatusText(wxWindow *aWindow, const wxString &aString)
Ellipsize text (at the end) to be no more than 1/3 of the window width.
Definition: ui_common.cpp:195
see class PGM_BASE
#define TYPE_HASH(x)
Definition: property.h:71
#define REGISTER_TYPE(x)
Definition: property_mgr.h:366
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.
Definition: string_utils.h:391
constexpr 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:228
KICAD_T
The set of class identification values stored in EDA_ITEM::m_structType.
Definition: typeinfo.h:78
@ SCH_TEXT_T
Definition: typeinfo.h:151
#define INDETERMINATE_STATE
Used for holding indeterminate values, such as with multiple selections holding different values or c...
Definition: ui_common.h:45
constexpr ret_type KiROUND(fp_type v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: util.h:118
VECTOR2< int > VECTOR2I
Definition: vector2d.h:588