KiCad PCB EDA Suite
Loading...
Searching...
No Matches
sch_textbox.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 The KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, you may find one here:
18 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19 * or you may search the http://www.gnu.org website for the version 2 license,
20 * or you may write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 */
23
24#include <google/protobuf/any.pb.h>
25
26#include <advanced_config.h>
27#include <api/api_enums.h>
28#include <api/api_utils.h>
29#include <base_units.h>
30#include <pgm_base.h>
31#include <sch_edit_frame.h>
32#include <plotters/plotter.h>
33#include <widgets/msgpanel.h>
34#include <bitmaps.h>
35#include <string_utils.h>
36#include <schematic.h>
38#include <sch_painter.h>
39#include <wx/log.h>
42#include <trigo.h>
44#include <sch_textbox.h>
46#include <markup_parser.h>
47#include <properties/property.h>
49#include <api/schematic/schematic_types.pb.h>
50
51
52SCH_TEXTBOX::SCH_TEXTBOX( SCH_LAYER_ID aLayer, int aLineWidth, FILL_T aFillType, const wxString& aText,
53 KICAD_T aType ) :
54 SCH_SHAPE( SHAPE_T::RECTANGLE, aLayer, aLineWidth, aFillType, aType ),
55 EDA_TEXT( schIUScale, aText )
56{
57 m_layer = aLayer;
58
61 SetMultilineAllowed( true );
62
63 m_excludedFromSim = false;
64
65 int defaultMargin = GetLegacyTextMargin();
66 m_marginLeft = defaultMargin;
67 m_marginTop = defaultMargin;
68 m_marginRight = defaultMargin;
69 m_marginBottom = defaultMargin;
70}
71
72
83
84
85void SCH_TEXTBOX::Serialize( google::protobuf::Any& aContainer ) const
86{
87 using namespace kiapi::common;
88
89 kiapi::schematic::types::SchematicTextBox textBox;
90
91 textBox.mutable_id()->set_value( m_Uuid.AsStdString() );
92 textBox.set_locked( IsLocked() ? types::LockedState::LS_LOCKED : types::LockedState::LS_UNLOCKED );
93 textBox.set_exclude_from_sim( GetExcludedFromSim() );
94 PackDistance( *textBox.mutable_margin_left(), GetMarginLeft(), schIUScale );
95 PackDistance( *textBox.mutable_margin_top(), GetMarginTop(), schIUScale );
96 PackDistance( *textBox.mutable_margin_right(), GetMarginRight(), schIUScale );
97 PackDistance( *textBox.mutable_margin_bottom(), GetMarginBottom(), schIUScale );
98
99 types::TextBox& text = *textBox.mutable_textbox();
100 PackVector2( *text.mutable_top_left(), GetPosition(), schIUScale );
101 PackVector2( *text.mutable_bottom_right(), GetEnd(), schIUScale );
102 text.set_text( GetText().ToUTF8() );
103
104 types::TextAttributes* attrs = text.mutable_attributes();
105
106 if( GetFont() )
107 attrs->set_font_name( GetFont()->GetName().ToUTF8() );
108
111 attrs->mutable_angle()->set_value_degrees( GetTextAngleDegrees() );
112 attrs->set_line_spacing( GetLineSpacing() );
113 PackDistance( *attrs->mutable_stroke_width(), GetTextThickness(), schIUScale );
114 attrs->set_italic( IsItalic() );
115 attrs->set_bold( IsBold() );
116 attrs->set_underlined( GetAttributes().m_Underlined );
117 attrs->set_mirrored( IsMirrored() );
118 attrs->set_multiline( IsMultilineAllowed() );
119 attrs->set_keep_upright( IsKeepUpright() );
120 PackVector2( *attrs->mutable_size(), GetTextSize(), schIUScale );
121
123 PackColor( *attrs->mutable_color(), GetTextColor() );
124
125 types::StrokeAttributes* stroke = textBox.mutable_graphic_attributes()->mutable_stroke();
126 PackDistance( *stroke->mutable_width(), GetStroke().GetWidth(), schIUScale );
128
129 if( GetStroke().GetColor() != COLOR4D::UNSPECIFIED )
130 PackColor( *stroke->mutable_color(), GetStroke().GetColor() );
131
132 types::GraphicFillAttributes* fill = textBox.mutable_graphic_attributes()->mutable_fill();
134
136 PackColor( *fill->mutable_color(), GetFillColor() );
137
138 aContainer.PackFrom( textBox );
139}
140
141
142bool SCH_TEXTBOX::Deserialize( const google::protobuf::Any& aContainer )
143{
144 using namespace kiapi::common;
145
146 kiapi::schematic::types::SchematicTextBox textBox;
147
148 if( !aContainer.UnpackTo( &textBox ) )
149 return false;
150
151 const_cast<KIID&>( m_Uuid ) = KIID( textBox.id().value() );
152 SetLocked( textBox.locked() == types::LockedState::LS_LOCKED );
153 SetExcludedFromSim( textBox.exclude_from_sim() );
154 SetPosition( UnpackVector2( textBox.textbox().top_left(), schIUScale ) );
155 SetEnd( UnpackVector2( textBox.textbox().bottom_right(), schIUScale ) );
156 SetText( wxString::FromUTF8( textBox.textbox().text() ) );
157
158 if( textBox.has_margin_left() )
159 SetMarginLeft( UnpackDistance( textBox.margin_left(), schIUScale ) );
160
161 if( textBox.has_margin_top() )
162 SetMarginTop( UnpackDistance( textBox.margin_top(), schIUScale ) );
163
164 if( textBox.has_margin_right() )
165 SetMarginRight( UnpackDistance( textBox.margin_right(), schIUScale ) );
166
167 if( textBox.has_margin_bottom() )
168 SetMarginBottom( UnpackDistance( textBox.margin_bottom(), schIUScale ) );
169
170 if( textBox.textbox().has_attributes() )
171 {
173
174 attrs.m_Bold = textBox.textbox().attributes().bold();
175 attrs.m_Italic = textBox.textbox().attributes().italic();
176 attrs.m_Underlined = textBox.textbox().attributes().underlined();
177 attrs.m_Mirrored = textBox.textbox().attributes().mirrored();
178 attrs.m_Multiline = textBox.textbox().attributes().multiline();
179 attrs.m_KeepUpright = textBox.textbox().attributes().keep_upright();
180 attrs.m_Size = UnpackVector2( textBox.textbox().attributes().size(), schIUScale );
181
182 if( textBox.textbox().attributes().has_color() )
183 attrs.m_Color = UnpackColor( textBox.textbox().attributes().color() );
184 else
186
187 if( !textBox.textbox().attributes().font_name().empty() )
188 {
189 attrs.m_Font = KIFONT::FONT::GetFont( wxString::FromUTF8( textBox.textbox().attributes().font_name() ),
190 attrs.m_Bold, attrs.m_Italic );
191 }
192
193 attrs.m_Angle = EDA_ANGLE( textBox.textbox().attributes().angle().value_degrees(), DEGREES_T );
194 attrs.m_LineSpacing = textBox.textbox().attributes().line_spacing();
195 attrs.m_StrokeWidth = UnpackDistance( textBox.textbox().attributes().stroke_width(), schIUScale );
197 textBox.textbox().attributes().horizontal_alignment() );
199 textBox.textbox().attributes().vertical_alignment() );
200
201 SetAttributes( attrs );
202 }
203
204 if( textBox.has_graphic_attributes() )
205 {
206 if( textBox.graphic_attributes().stroke().has_color() )
207 m_stroke.SetColor( UnpackColor( textBox.graphic_attributes().stroke().color() ) );
208 else
209 m_stroke.SetColor( COLOR4D::UNSPECIFIED );
210
211 if( textBox.graphic_attributes().fill().has_color() )
212 SetFillColor( UnpackColor( textBox.graphic_attributes().fill().color() ) );
213 else
215
216 SetWidth( UnpackDistance( textBox.graphic_attributes().stroke().width(), schIUScale ) );
218 FromProtoEnum<LINE_STYLE, types::StrokeLineStyle>( textBox.graphic_attributes().stroke().style() ) );
219 SetFillMode( FromProtoEnum<FILL_T, types::GraphicFillType>( textBox.graphic_attributes().fill().fill_type() ) );
220 }
221
222 return true;
223}
224
225
227{
228 if( m_layer == LAYER_DEVICE )
229 return KiROUND( GetTextSize().y * 0.8 );
230 else
231 return KiROUND( GetStroke().GetWidth() / 2.0 ) + KiROUND( GetTextSize().y * 0.75 );
232}
233
234
236{
237 if( GetText().IsEmpty() )
238 return VECTOR2I( 0, 0 );
239
240 BOX2I textBox = GetTextBox( nullptr );
241
242 int textHeight = std::abs( textBox.GetHeight() );
243
244 if( GetTextAngle().IsVertical() )
245 {
246 textHeight += GetMarginLeft() + GetMarginRight();
247 return VECTOR2I( textHeight, 0 );
248 }
249
250 textHeight += GetMarginTop() + GetMarginBottom();
251 return VECTOR2I( 0, textHeight );
252}
253
254
256{
258
259 // Text is NOT really mirrored; it just has its justification flipped
261 {
266 }
267}
268
269
271{
273
274 // Text is NOT really mirrored; it just has its justification flipped
276 {
281 }
282}
283
284
285void SCH_TEXTBOX::Rotate( const VECTOR2I& aCenter, bool aRotateCCW )
286{
287 SCH_SHAPE::Rotate( aCenter, aRotateCCW );
289}
290
291
296
297
299{
300 BOX2I bbox = BOX2I( m_start, m_end - m_start );
301
302 bbox.Normalize();
303
304 VECTOR2I pos( bbox.GetLeft() + m_marginLeft, bbox.GetBottom() - m_marginBottom );
305
306 if( GetTextAngle().IsVertical() )
307 {
308 switch( GetHorizJustify() )
309 {
310 case GR_TEXT_H_ALIGN_LEFT: pos.y = bbox.GetBottom() - m_marginBottom; break;
311 case GR_TEXT_H_ALIGN_CENTER: pos.y = ( bbox.GetTop() + bbox.GetBottom() ) / 2; break;
312 case GR_TEXT_H_ALIGN_RIGHT: pos.y = bbox.GetTop() + m_marginTop; break;
313 case GR_TEXT_H_ALIGN_INDETERMINATE: wxFAIL_MSG( wxT( "Indeterminate state legal only in dialogs." ) ); break;
314 }
315
316 switch( GetVertJustify() )
317 {
318 case GR_TEXT_V_ALIGN_TOP: pos.x = bbox.GetLeft() + m_marginLeft; break;
319 case GR_TEXT_V_ALIGN_CENTER: pos.x = ( bbox.GetLeft() + bbox.GetRight() ) / 2; break;
320 case GR_TEXT_V_ALIGN_BOTTOM: pos.x = bbox.GetRight() - m_marginRight; break;
321 case GR_TEXT_V_ALIGN_INDETERMINATE: wxFAIL_MSG( wxT( "Indeterminate state legal only in dialogs." ) ); break;
322 }
323 }
324 else
325 {
326 switch( GetHorizJustify() )
327 {
328 case GR_TEXT_H_ALIGN_LEFT: pos.x = bbox.GetLeft() + m_marginLeft; break;
329 case GR_TEXT_H_ALIGN_CENTER: pos.x = ( bbox.GetLeft() + bbox.GetRight() ) / 2; break;
330 case GR_TEXT_H_ALIGN_RIGHT: pos.x = bbox.GetRight() - m_marginRight; break;
331 case GR_TEXT_H_ALIGN_INDETERMINATE: wxFAIL_MSG( wxT( "Indeterminate state legal only in dialogs." ) ); break;
332 }
333
334 switch( GetVertJustify() )
335 {
336 case GR_TEXT_V_ALIGN_TOP: pos.y = bbox.GetTop() + m_marginTop; break;
337 case GR_TEXT_V_ALIGN_CENTER: pos.y = ( bbox.GetTop() + bbox.GetBottom() ) / 2; break;
338 case GR_TEXT_V_ALIGN_BOTTOM: pos.y = bbox.GetBottom() - m_marginBottom; break;
339 case GR_TEXT_V_ALIGN_INDETERMINATE: wxFAIL_MSG( wxT( "Indeterminate state legal only in dialogs." ) ); break;
340 }
341 }
342
343 return pos;
344}
345
346
348{
349 SCH_SHAPE::swapData( aItem );
350
351 SCH_TEXTBOX* item = static_cast<SCH_TEXTBOX*>( aItem );
352
353 std::swap( m_marginLeft, item->m_marginLeft );
354 std::swap( m_marginTop, item->m_marginTop );
355 std::swap( m_marginRight, item->m_marginRight );
356 std::swap( m_marginBottom, item->m_marginBottom );
357
358 SwapText( *item );
359 SwapAttributes( *item );
360}
361
362
363bool SCH_TEXTBOX::operator<( const SCH_ITEM& aItem ) const
364{
365 if( Type() != aItem.Type() )
366 return Type() < aItem.Type();
367
368 auto other = static_cast<const SCH_TEXTBOX*>( &aItem );
369
370 if( GetLayer() != other->GetLayer() )
371 return GetLayer() < other->GetLayer();
372
373 if( GetPosition().x != other->GetPosition().x )
374 return GetPosition().x < other->GetPosition().x;
375
376 if( GetPosition().y != other->GetPosition().y )
377 return GetPosition().y < other->GetPosition().y;
378
379 if( GetMarginLeft() != other->GetMarginLeft() )
380 return GetMarginLeft() < other->GetMarginLeft();
381
382 if( GetMarginTop() != other->GetMarginTop() )
383 return GetMarginTop() < other->GetMarginTop();
384
385 if( GetMarginRight() != other->GetMarginRight() )
386 return GetMarginRight() < other->GetMarginRight();
387
388 if( GetMarginBottom() != other->GetMarginBottom() )
389 return GetMarginBottom() < other->GetMarginBottom();
390
391 if( GetExcludedFromSim() != other->GetExcludedFromSim() )
392 return GetExcludedFromSim() - other->GetExcludedFromSim();
393
394 return GetText() < other->GetText();
395}
396
397
399{
401
402 if( !font )
403 font = KIFONT::FONT::GetFont( GetDefaultFont( aSettings ), IsBold(), IsItalic() );
404
405 return font;
406}
407
408
409wxString SCH_TEXTBOX::GetShownText( const RENDER_SETTINGS* aSettings, const SCH_SHEET_PATH* aPath, bool aAllowExtraText,
410 int aDepth ) const
411{
412 // Use local depth counter so each text element starts fresh
413 int depth = 0;
414
415 SCH_SHEET* sheet = nullptr;
416
417 if( aPath )
418 sheet = aPath->Last();
419
420 std::function<bool( wxString* )> textResolver = [&]( wxString* token ) -> bool
421 {
422 if( sheet )
423 {
424 if( sheet->ResolveTextVar( aPath, token, depth + 1 ) )
425 return true;
426 }
427
428 return false;
429 };
430
431 wxString text = EDA_TEXT::GetShownText( aAllowExtraText, depth );
432
433 if( HasTextVars() )
434 text = ResolveTextVars( text, &textResolver, depth );
435
436 VECTOR2I size = GetEnd() - GetStart();
437 int colWidth;
438
439 if( GetTextAngle().IsVertical() )
440 colWidth = abs( size.y ) - ( GetMarginTop() + GetMarginBottom() );
441 else
442 colWidth = abs( size.x ) - ( GetMarginLeft() + GetMarginRight() );
443
444 GetDrawFont( aSettings )
446
447 // Convert escape markers back to literals for final display
448 text.Replace( wxT( "<<<ESC_DOLLAR:" ), wxT( "${" ) );
449 text.Replace( wxT( "<<<ESC_AT:" ), wxT( "@{" ) );
450
451 return text;
452}
453
454
455bool SCH_TEXTBOX::HitTest( const VECTOR2I& aPosition, int aAccuracy ) const
456{
457 BOX2I rect = GetBoundingBox();
458
459 rect.Inflate( aAccuracy );
460
461 return rect.Contains( aPosition );
462}
463
464
465bool SCH_TEXTBOX::HitTest( const BOX2I& aRect, bool aContained, int aAccuracy ) const
466{
467 BOX2I rect = aRect;
468
469 rect.Inflate( aAccuracy );
470
471 if( aContained )
472 return rect.Contains( GetBoundingBox() );
473
474 return rect.Intersects( GetBoundingBox() );
475}
476
477
478bool SCH_TEXTBOX::HitTest( const SHAPE_LINE_CHAIN& aPoly, bool aContained ) const
479{
480 return KIGEOM::BoxHitTest( aPoly, GetBoundingBox(), aContained );
481}
482
483
485{
486 return HasHyperlink() || containsURL();
487}
488
489
491{
492 return !m_activeUrl.IsEmpty();
493}
494
495
496void SCH_TEXTBOX::DoHypertextAction( EDA_DRAW_FRAME* aFrame, const VECTOR2I& aMousePos ) const
497{
499
500 if( HasHyperlink() )
501 navTool->HypertextCommand( m_hyperlink );
502 else if( !m_activeUrl.IsEmpty() )
503 navTool->HypertextCommand( m_activeUrl );
504}
505
506
507wxString SCH_TEXTBOX::GetItemDescription( UNITS_PROVIDER* aUnitsProvider, bool aFull ) const
508{
509 return wxString::Format( _( "Text box '%s'" ),
510 aFull ? GetShownText( false ) : KIUI::EllipsizeMenuText( GetText() ) );
511}
512
513
518
519
520void SCH_TEXTBOX::Plot( PLOTTER* aPlotter, bool aBackground, const SCH_PLOT_OPTS& aPlotOpts, int aUnit, int aBodyStyle,
521 const VECTOR2I& aOffset, bool aDimmed )
522{
523 if( IsPrivate() )
524 return;
525
526 SCH_SHAPE::Plot( aPlotter, aBackground, aPlotOpts, aUnit, aBodyStyle, aOffset, aDimmed );
527
528 if( aBackground )
529 return;
530
531 SCH_SHEET_PATH* sheet = Schematic() ? &Schematic()->CurrentSheet() : nullptr;
532 SCH_RENDER_SETTINGS* renderSettings = getRenderSettings( aPlotter );
533 int penWidth = GetEffectivePenWidth( renderSettings );
534 COLOR4D color = GetStroke().GetColor();
535 COLOR4D bg = renderSettings->GetBackgroundColor();
536
537 KIFONT::FONT* font = GetDrawFont( renderSettings );
538
539 color = GetTextColor();
540
541 if( !aPlotter->GetColorMode() || color == COLOR4D::UNSPECIFIED )
542 color = renderSettings->GetLayerColor( m_layer );
543
544 if( bg == COLOR4D::UNSPECIFIED || !aPlotter->GetColorMode() )
545 bg = COLOR4D::WHITE;
546
547 if( color.m_text && Schematic() )
548 color = COLOR4D( ResolveText( *color.m_text, &Schematic()->CurrentSheet() ) );
549
550 if( aDimmed )
551 {
552 color.Desaturate();
553 color = color.Mix( bg, 0.5f );
554 }
555
556 penWidth = GetEffectiveTextPenWidth( renderSettings->GetDefaultPenWidth() );
557 penWidth = std::max( penWidth, renderSettings->GetMinPenWidth() );
558 aPlotter->SetCurrentLineWidth( penWidth );
559
560 TEXT_ATTRIBUTES attrs;
561 std::vector<VECTOR2I> positions;
562 wxArrayString strings_list;
563
564 wxStringSplit( GetShownText( renderSettings, sheet, true ), strings_list, '\n' );
565 positions.reserve( strings_list.Count() );
566
567 if( renderSettings->m_Transform != TRANSFORM() || aOffset != VECTOR2I() )
568 {
569 SCH_TEXTBOX temp( *this );
570
571 if( renderSettings->m_Transform.y1 )
572 {
574 }
575
576 temp.SetStart( renderSettings->TransformCoordinate( m_start ) + aOffset );
577 temp.SetEnd( renderSettings->TransformCoordinate( m_end ) + aOffset );
578
579 attrs = temp.GetAttributes();
580 temp.GetLinePositions( renderSettings, positions, (int) strings_list.Count() );
581 }
582 else
583 {
584 attrs = GetAttributes();
585 GetLinePositions( renderSettings, positions, (int) strings_list.Count() );
586 }
587
588 attrs.m_StrokeWidth = penWidth;
589 attrs.m_Multiline = false;
590
591 for( unsigned ii = 0; ii < strings_list.Count(); ii++ )
592 {
593 aPlotter->PlotText( positions[ii], color, strings_list.Item( ii ), attrs, font, GetFontMetrics() );
594 }
595
596 if( HasHyperlink() )
597 aPlotter->HyperlinkBox( GetBoundingBox(), GetHyperlink() );
598}
599
600
601void SCH_TEXTBOX::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList )
602{
603 // Don't use GetShownText() here; we want to show the user the variable references
604 aList.emplace_back( _( "Text Box" ), KIUI::EllipsizeStatusText( aFrame, GetText() ) );
605
606 SCH_ITEM::GetMsgPanelInfo( aFrame, aList );
607
609 aList.emplace_back( _( "Exclude from" ), _( "Simulation" ) );
610
611 aList.emplace_back( _( "Font" ), GetFont() ? GetFont()->GetName() : _( "Default" ) );
612
613 wxString textStyle[] = { _( "Normal" ), _( "Italic" ), _( "Bold" ), _( "Bold Italic" ) };
614 int style = IsBold() && IsItalic() ? 3 : IsBold() ? 2 : IsItalic() ? 1 : 0;
615 aList.emplace_back( _( "Style" ), textStyle[style] );
616
617 aList.emplace_back( _( "Text Size" ), aFrame->MessageTextFromValue( GetTextWidth() ) );
618
619 aList.emplace_back( _( "Box Width" ), aFrame->MessageTextFromValue( std::abs( GetEnd().x - GetStart().x ) ) );
620
621 aList.emplace_back( _( "Box Height" ), aFrame->MessageTextFromValue( std::abs( GetEnd().y - GetStart().y ) ) );
622
623 m_stroke.GetMsgPanelInfo( aFrame, aList );
624}
625
626
627bool SCH_TEXTBOX::operator==( const SCH_ITEM& aOther ) const
628{
629 if( Type() != aOther.Type() )
630 return false;
631
632 const SCH_TEXTBOX& other = static_cast<const SCH_TEXTBOX&>( aOther );
633
635 return false;
636
637 if( GetMarginLeft() != other.GetMarginLeft() )
638 return false;
639
640 if( GetMarginTop() != other.GetMarginTop() )
641 return false;
642
643 if( GetMarginRight() != other.GetMarginRight() )
644 return false;
645
646 if( GetMarginBottom() != other.GetMarginBottom() )
647 return false;
648
649 return SCH_SHAPE::operator==( aOther ) && EDA_TEXT::operator==( other );
650}
651
652
653double SCH_TEXTBOX::Similarity( const SCH_ITEM& aOther ) const
654{
655 if( m_Uuid == aOther.m_Uuid )
656 return 1.0;
657
658 if( aOther.Type() != Type() )
659 return 0.0;
660
661 auto other = static_cast<const SCH_TEXTBOX&>( aOther );
662
663 double similarity = SimilarityBase( other );
664
665 if( m_excludedFromSim != other.m_excludedFromSim )
666 similarity *= 0.9;
667
668 if( GetMarginLeft() != other.GetMarginLeft() )
669 similarity *= 0.9;
670
671 if( GetMarginTop() != other.GetMarginTop() )
672 similarity *= 0.9;
673
674 if( GetMarginRight() != other.GetMarginRight() )
675 similarity *= 0.9;
676
677 if( GetMarginBottom() != other.GetMarginBottom() )
678 similarity *= 0.9;
679
680 similarity *= SCH_SHAPE::Similarity( aOther );
681 similarity *= EDA_TEXT::Similarity( other );
682
683 return similarity;
684}
685
686
687int SCH_TEXTBOX::compare( const SCH_ITEM& aOther, int aCompareFlags ) const
688{
689 wxASSERT( aOther.Type() == SCH_TEXTBOX_T );
690
691 int retv = SCH_SHAPE::compare( aOther, aCompareFlags );
692
693 if( retv )
694 return retv;
695
696 const SCH_TEXTBOX* tmp = static_cast<const SCH_TEXTBOX*>( &aOther );
697
698 int result = GetText().CmpNoCase( tmp->GetText() );
699
700 if( result != 0 )
701 return result;
702
703 if( GetTextWidth() != tmp->GetTextWidth() )
704 return GetTextWidth() - tmp->GetTextWidth();
705
706 if( GetTextHeight() != tmp->GetTextHeight() )
707 return GetTextHeight() - tmp->GetTextHeight();
708
709 if( IsBold() != tmp->IsBold() )
710 return IsBold() - tmp->IsBold();
711
712 if( IsItalic() != tmp->IsItalic() )
713 return IsItalic() - tmp->IsItalic();
714
715 if( GetHorizJustify() != tmp->GetHorizJustify() )
716 return (int) GetHorizJustify() - (int) tmp->GetHorizJustify();
717
718 if( GetTextAngle().AsTenthsOfADegree() != tmp->GetTextAngle().AsTenthsOfADegree() )
720
721 if( GetMarginLeft() != tmp->GetMarginLeft() )
722 return GetMarginLeft() - tmp->GetMarginLeft();
723
724 if( GetMarginTop() != tmp->GetMarginTop() )
725 return GetMarginTop() - tmp->GetMarginTop();
726
727 if( GetMarginRight() != tmp->GetMarginRight() )
728 return GetMarginRight() - tmp->GetMarginRight();
729
730 if( GetMarginBottom() != tmp->GetMarginBottom() )
731 return GetMarginBottom() - tmp->GetMarginBottom();
732
733 return 0;
734}
735
736
737static struct SCH_TEXTBOX_DESC
738{
740 {
743
750
751 propMgr.Mask( TYPE_HASH( SCH_TEXTBOX ), TYPE_HASH( EDA_SHAPE ), _HKI( "Shape" ) );
752 propMgr.Mask( TYPE_HASH( SCH_TEXTBOX ), TYPE_HASH( EDA_SHAPE ), _HKI( "Corner Radius" ) );
753
754 propMgr.Mask( TYPE_HASH( SCH_TEXTBOX ), TYPE_HASH( EDA_TEXT ), _HKI( "Width" ) );
755 propMgr.Mask( TYPE_HASH( SCH_TEXTBOX ), TYPE_HASH( EDA_TEXT ), _HKI( "Height" ) );
756 propMgr.Mask( TYPE_HASH( SCH_TEXTBOX ), TYPE_HASH( EDA_TEXT ), _HKI( "Thickness" ) );
757
758 const wxString marginProps = _( "Margins" );
759
762 marginProps );
765 marginProps );
768 marginProps );
771 marginProps );
772
775 _HKI( "Text Properties" ) );
776
777 propMgr.Mask( TYPE_HASH( SCH_TEXTBOX ), TYPE_HASH( EDA_TEXT ), _HKI( "Orientation" ) );
778 }
types::KiCadObjectType ToProtoEnum(KICAD_T aValue)
KICAD_T FromProtoEnum(types::KiCadObjectType aValue)
Definition api_enums.cpp:44
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 BOX2< Vec > & Normalize()
Ensure that the height and width are positive.
Definition box2.h:146
constexpr size_type GetHeight() const
Definition box2.h:215
constexpr coord_type GetLeft() const
Definition box2.h:228
constexpr bool Contains(const Vec &aPoint) const
Definition box2.h:168
constexpr coord_type GetRight() const
Definition box2.h:217
constexpr coord_type GetTop() const
Definition box2.h:229
constexpr bool Intersects(const BOX2< Vec > &aRect) const
Definition box2.h:311
constexpr coord_type GetBottom() const
Definition box2.h:222
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
int AsTenthsOfADegree() const
Definition eda_angle.h:118
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
FILL_T GetFillMode() const
Definition eda_shape.h:158
void SetLineStyle(const LINE_STYLE aStyle)
void SetFillColor(const COLOR4D &aColor)
Definition eda_shape.h:170
VECTOR2I m_start
Definition eda_shape.h:530
const VECTOR2I & GetEnd() const
Return the ending point of the graphic.
Definition eda_shape.h:232
void SetStart(const VECTOR2I &aStart)
Definition eda_shape.h:194
LINE_STYLE GetLineStyle() const
const VECTOR2I & GetStart() const
Return the starting point of the graphic.
Definition eda_shape.h:190
COLOR4D GetFillColor() const
Definition eda_shape.h:169
void SetEnd(const VECTOR2I &aEnd)
Definition eda_shape.h:236
VECTOR2I m_end
Definition eda_shape.h:531
virtual int GetWidth() const
Definition eda_shape.h:173
STROKE_PARAMS m_stroke
Definition eda_shape.h:519
void SetWidth(int aWidth)
void SetFillMode(FILL_T aFill)
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
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
bool IsMultilineAllowed() const
Definition eda_text.h:222
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition eda_text.h:114
bool IsKeepUpright() const
Definition eda_text.h:231
KIFONT::FONT * GetFont() const
Definition eda_text.h:272
void SetAttributes(const EDA_TEXT &aSrc, bool aSetPosition=true)
Set the text attributes from another instance.
Definition eda_text.cpp:432
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 GetLineSpacing() const
Definition eda_text.h:283
double Similarity(const EDA_TEXT &aOther) const
const TEXT_ATTRIBUTES & GetAttributes() const
Definition eda_text.h:256
bool IsMirrored() const
Definition eda_text.h:215
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
double GetTextAngleDegrees() const
Definition eda_text.h:179
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
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 SetText(const wxString &aText)
Definition eda_text.cpp:269
virtual void SetTextAngle(const EDA_ANGLE &aAngle)
Definition eda_text.cpp:298
int GetTextThickness() const
Definition eda_text.h:153
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
void LinebreakText(wxString &aText, int aColumnWidth, const VECTOR2I &aGlyphSize, int aThickness, bool aBold, bool aItalic) const
Insert characters into text to ensure that no lines are wider than aColumnWidth.
Definition font.cpp:609
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
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.
SCH_SHEET_PATH & CurrentSheet() const
Definition schematic.h:188
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
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
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
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
int GetEffectivePenWidth(const SCH_RENDER_SETTINGS *aSettings) const
Definition sch_item.cpp:792
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.
void SetPosition(const VECTOR2I &aPos) override
Definition sch_shape.h:89
void MirrorHorizontally(int aCenter) override
Mirror item horizontally about aCenter.
void swapData(SCH_ITEM *aItem) override
Swap the internal data structures aItem with the schematic item.
Definition sch_shape.cpp:92
double Similarity(const SCH_ITEM &aOther) const override
Return a measure of how likely the other object is to represent the same object.
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.
SCH_SHAPE(SHAPE_T aShape=SHAPE_T::UNDEFINED, SCH_LAYER_ID aLayer=LAYER_NOTES, int aLineWidth=0, FILL_T aFillType=FILL_T::NO_FILL, KICAD_T aType=SCH_SHAPE_T)
Definition sch_shape.cpp:42
const BOX2I GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
void MirrorVertically(int aCenter) override
Mirror item vertically about aCenter.
void Rotate(const VECTOR2I &aCenter, bool aRotateCCW) override
Rotate the item around aCenter 90 degrees in the clockwise direction.
bool operator==(const SCH_ITEM &aOther) const override
STROKE_PARAMS GetStroke() const override
Definition sch_shape.h:61
VECTOR2I GetPosition() const override
Definition sch_shape.h:88
int compare(const SCH_ITEM &aOther, int aCompareFlags=0) const override
Provide the draw object specific comparison called by the == and < operators.
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.
void SetMarginBottom(int aBottom)
Definition sch_textbox.h:71
int GetMarginBottom() const
Definition sch_textbox.h:76
void MirrorHorizontally(int aCenter) override
Mirror item horizontally about aCenter.
bool m_excludedFromSim
virtual wxString GetShownText(const RENDER_SETTINGS *aSettings, const SCH_SHEET_PATH *aPath, bool aAllowExtraText, int aDepth=0) const
bool operator==(const SCH_ITEM &aOther) const override
wxString GetItemDescription(UNITS_PROVIDER *aUnitsProvider, bool aFull) const override
Return a user-visible description string of this item.
bool HitTest(const VECTOR2I &aPosition, int aAccuracy=0) const override
Test if aPosition is inside or on the boundary of this item.
int GetLegacyTextMargin() const
int GetMarginLeft() const
Definition sch_textbox.h:73
int GetSchTextSize() const
Definition sch_textbox.h:78
bool GetExcludedFromSim(const SCH_SHEET_PATH *aInstance=nullptr, const wxString &aVariantName=wxEmptyString) const override
int compare(const SCH_ITEM &aOther, int aCompareFlags=0) const override
Provide the draw object specific comparison called by the == and < operators.
BITMAPS GetMenuImage() const override
Return a pointer to an image to be used in menus.
bool operator<(const SCH_ITEM &aItem) const override
bool Deserialize(const google::protobuf::Any &aContainer) override
Deserializes the given protobuf message into this object.
bool HasHypertext() const override
Indicates that the item has at least one hypertext action.
VECTOR2I GetDrawPos() const override
int GetMarginRight() const
Definition sch_textbox.h:75
void Rotate(const VECTOR2I &aCenter, bool aRotateCCW) override
Rotate the item around aCenter 90 degrees in the clockwise direction.
VECTOR2I GetMinSize() const
Return the minimum height needed to contain the textbox's wrapped text content plus margins.
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.
bool HasHoveredHypertext() const override
Indicates that a hypertext link is currently active.
int GetMarginTop() const
Definition sch_textbox.h:74
void Serialize(google::protobuf::Any &aContainer) const override
Serializes this object to the given Any message.
void GetMsgPanelInfo(EDA_DRAW_FRAME *aFrame, std::vector< MSG_PANEL_ITEM > &aList) override
Populate aList of MSG_PANEL_ITEM objects with it's internal state for display purposes.
void SetMarginLeft(int aLeft)
Definition sch_textbox.h:68
void swapData(SCH_ITEM *aItem) override
Swap the internal data structures aItem with the schematic item.
void DoHypertextAction(EDA_DRAW_FRAME *aFrame, const VECTOR2I &aMousePos) const override
virtual void Rotate90(bool aClockwise)
void SetMarginRight(int aRight)
Definition sch_textbox.h:70
void SetSchTextSize(int aSize)
Definition sch_textbox.h:79
KIFONT::FONT * GetDrawFont(const RENDER_SETTINGS *aSettings) const override
SCH_TEXTBOX(SCH_LAYER_ID aLayer=LAYER_NOTES, int aLineWidth=0, FILL_T aFillType=FILL_T::NO_FILL, const wxString &aText=wxEmptyString, KICAD_T aType=SCH_TEXTBOX_T)
double Similarity(const SCH_ITEM &aOther) const override
Return a measure of how likely the other object is to represent the same object.
void MirrorVertically(int aCenter) override
Mirror item vertically about aCenter.
void SetExcludedFromSim(bool aExclude, const SCH_SHEET_PATH *aInstance=nullptr, const wxString &aVariantName=wxEmptyString) override
void SetMarginTop(int aTop)
Definition sch_textbox.h:69
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
KIGFX::COLOR4D GetColor() const
KIGFX::COLOR4D m_Color
GR_TEXT_H_ALIGN_T m_Halign
GR_TEXT_V_ALIGN_T m_Valign
KIFONT::FONT * m_Font
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().
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 _(s)
@ DEGREES_T
Definition eda_angle.h:31
static constexpr EDA_ANGLE ANGLE_VERTICAL
Definition eda_angle.h:408
static constexpr EDA_ANGLE ANGLE_HORIZONTAL
Definition eda_angle.h:407
SHAPE_T
Definition eda_shape.h:46
FILL_T
Definition eda_shape.h:59
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
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 PackColor(types::Color &aOutput, const KIGFX::COLOR4D &aInput)
KICOMMON_API int UnpackDistance(const types::Distance &aInput, const EDA_IU_SCALE &aScale)
KICOMMON_API KIGFX::COLOR4D UnpackColor(const types::Color &aInput)
KICOMMON_API VECTOR2I UnpackVector2(const types::Vector2 &aInput, const EDA_IU_SCALE &aScale)
KICOMMON_API void PackDistance(types::Distance &aOutput, int aInput, const EDA_IU_SCALE &aScale)
KICOMMON_API void PackVector2(types::Vector2 &aOutput, const VECTOR2I &aInput, const EDA_IU_SCALE &aScale)
EDA_ANGLE abs(const EDA_ANGLE &aAngle)
Definition eda_angle.h:400
#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_TEXTBOX_DESC _SCH_TEXTBOX_DESC
void wxStringSplit(const wxString &aText, wxArrayString &aStrings, wxChar aSplitter)
Split aString to a string list separated at aSplitter.
wxString result
Test unit parsing edge cases and error handling.
@ 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
KICAD_T
The set of class identification values stored in EDA_ITEM::m_structType.
Definition typeinfo.h:75
@ SCH_TEXTBOX_T
Definition typeinfo.h:153
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:687