KiCad PCB EDA Suite
Loading...
Searching...
No Matches
sch_field.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) 2015 Jean-Pierre Charras, jp.charras at wanadoo.fr
5 * Copyright (C) 2004-2023 KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, you may find one here:
19 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20 * or you may search the http://www.gnu.org website for the version 2 license,
21 * or you may write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23 */
24
25/*
26 * Fields are texts attached to a symbol, some of which have a special meaning.
27 * Fields 0 and 1 are very important: reference and value.
28 * Field 2 is used as default footprint name.
29 * Field 3 is used to point to a datasheet (usually a URL).
30 * Fields 4+ are user fields. They can be renamed and can appear in reports.
31 */
32
33#include <wx/log.h>
34#include <wx/menu.h>
35#include <base_units.h>
36#include <common.h> // for ExpandTextVars
37#include <eda_item.h>
38#include <sch_edit_frame.h>
39#include <plotters/plotter.h>
40#include <bitmaps.h>
41#include <core/kicad_algo.h>
42#include <core/mirror.h>
43#include <kiway.h>
44#include <general.h>
45#include <symbol_library.h>
46#include <sch_symbol.h>
47#include <sch_field.h>
48#include <sch_label.h>
49#include <schematic.h>
51#include <string_utils.h>
52#include <trace_helpers.h>
53#include <trigo.h>
54#include <eeschema_id.h>
55#include <tool/tool_manager.h>
57#include <font/outline_font.h>
58#include "sim/sim_lib_mgr.h"
59
60SCH_FIELD::SCH_FIELD( const VECTOR2I& aPos, int aFieldId, SCH_ITEM* aParent,
61 const wxString& aName ) :
62 SCH_ITEM( aParent, SCH_FIELD_T ),
63 EDA_TEXT( schIUScale, wxEmptyString ),
64 m_id( 0 ),
65 m_showName( false ),
66 m_allowAutoPlace( true ),
67 m_renderCacheValid( false ),
68 m_lastResolvedColor( COLOR4D::UNSPECIFIED )
69{
70 SetName( aName );
71 SetTextPos( aPos );
72 SetId( aFieldId ); // will also set the layer
73 SetVisible( false );
74}
75
76
77SCH_FIELD::SCH_FIELD( SCH_ITEM* aParent, int aFieldId, const wxString& aName ) :
78 SCH_FIELD( VECTOR2I(), aFieldId, aParent, aName )
79{
80}
81
82
84 SCH_ITEM( aField ),
85 EDA_TEXT( aField )
86{
87 m_id = aField.m_id;
88 m_name = aField.m_name;
89 m_showName = aField.m_showName;
92
93 m_renderCache.clear();
94
95 for( const std::unique_ptr<KIFONT::GLYPH>& glyph : aField.m_renderCache )
96 {
97 if( KIFONT::OUTLINE_GLYPH* outline = dynamic_cast<KIFONT::OUTLINE_GLYPH*>( glyph.get() ) )
98 m_renderCache.emplace_back( std::make_unique<KIFONT::OUTLINE_GLYPH>( *outline ) );
99 else if( KIFONT::STROKE_GLYPH* stroke = dynamic_cast<KIFONT::STROKE_GLYPH*>( glyph.get() ) )
100 m_renderCache.emplace_back( std::make_unique<KIFONT::STROKE_GLYPH>( *stroke ) );
101 }
102
105
107}
108
109
111{
112 EDA_TEXT::operator=( aField );
113
114 m_id = aField.m_id;
115 m_name = aField.m_name;
116 m_showName = aField.m_showName;
119
120 m_renderCache.clear();
121
122 for( const std::unique_ptr<KIFONT::GLYPH>& glyph : aField.m_renderCache )
123 {
124 if( KIFONT::OUTLINE_GLYPH* outline = dynamic_cast<KIFONT::OUTLINE_GLYPH*>( glyph.get() ) )
125 m_renderCache.emplace_back( std::make_unique<KIFONT::OUTLINE_GLYPH>( *outline ) );
126 else if( KIFONT::STROKE_GLYPH* stroke = dynamic_cast<KIFONT::STROKE_GLYPH*>( glyph.get() ) )
127 m_renderCache.emplace_back( std::make_unique<KIFONT::STROKE_GLYPH>( *stroke ) );
128 }
129
132
134
135 return *this;
136}
137
138
140{
141 return new SCH_FIELD( *this );
142}
143
144
145void SCH_FIELD::SetId( int aId )
146{
147 m_id = aId;
148
149 if( m_parent && m_parent->Type() == SCH_SHEET_T )
150 {
151 switch( m_id )
152 {
153 case SHEETNAME: SetLayer( LAYER_SHEETNAME ); break;
155 default: SetLayer( LAYER_SHEETFIELDS ); break;
156 }
157 }
158 else if( m_parent && m_parent->Type() == SCH_SYMBOL_T )
159 {
160 switch( m_id )
161 {
163 case VALUE_FIELD: SetLayer( LAYER_VALUEPART ); break;
164 default: SetLayer( LAYER_FIELDS ); break;
165 }
166 }
167 else if( m_parent && m_parent->IsType( { SCH_LABEL_LOCATE_ANY_T } ) )
168 {
169 // We can't use defined IDs for labels because there can be multiple net class
170 // assignments.
171
172 if( GetCanonicalName() == wxT( "Netclass" ) )
174 else if( GetCanonicalName() == wxT( "Intersheetrefs" ) )
176 else
178 }
179}
180
181
183{
185}
186
187
188wxString SCH_FIELD::GetShownText( const SCH_SHEET_PATH* aPath, bool aAllowExtraText,
189 int aDepth ) const
190{
191 std::function<bool( wxString* )> symbolResolver =
192 [&]( wxString* token ) -> bool
193 {
194 SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( m_parent );
195 return symbol->ResolveTextVar( aPath, token, aDepth + 1 );
196 };
197
198 std::function<bool( wxString* )> sheetResolver =
199 [&]( wxString* token ) -> bool
200 {
201 SCH_SHEET* sheet = static_cast<SCH_SHEET*>( m_parent );
202
203 SCH_SHEET_PATH path = *aPath;
204 path.push_back( sheet );
205
206 return sheet->ResolveTextVar( &path, token, aDepth + 1 );
207 };
208
209 std::function<bool( wxString* )> labelResolver =
210 [&]( wxString* token ) -> bool
211 {
212 SCH_LABEL_BASE* label = static_cast<SCH_LABEL_BASE*>( m_parent );
213 return label->ResolveTextVar( aPath, token, aDepth + 1 );
214 };
215
216 wxString text = EDA_TEXT::GetShownText( aAllowExtraText, aDepth );
217
218 if( IsNameShown() && aAllowExtraText )
219 text = GetShownName() << wxS( ": " ) << text;
220
221 if( text == wxS( "~" ) ) // Legacy placeholder for empty string
222 {
223 text = wxS( "" );
224 }
225 else if( HasTextVars() )
226 {
227 if( aDepth < 10 )
228 {
229 if( m_parent && m_parent->Type() == SCH_SYMBOL_T )
230 text = ExpandTextVars( text, &symbolResolver );
231 else if( m_parent && m_parent->Type() == SCH_SHEET_T )
232 text = ExpandTextVars( text, &sheetResolver );
233 else if( m_parent && m_parent->IsType( { SCH_LABEL_LOCATE_ANY_T } ) )
234 text = ExpandTextVars( text, &labelResolver );
235 else if( Schematic() )
237 }
238 }
239
240 // WARNING: the IDs of FIELDS and SHEETS overlap, so one must check *both* the
241 // id and the parent's type.
242
243 if( m_parent && m_parent->Type() == SCH_SYMBOL_T )
244 {
245 SCH_SYMBOL* parentSymbol = static_cast<SCH_SYMBOL*>( m_parent );
246
247 if( m_id == REFERENCE_FIELD )
248 {
249 // For more than one part per package, we must add the part selection
250 // A, B, ... or 1, 2, .. to the reference.
251 if( parentSymbol->GetUnitCount() > 1 )
252 text << parentSymbol->SubReference( parentSymbol->GetUnitSelection( aPath ) );
253 }
254 }
255 else if( m_parent && m_parent->Type() == SCH_SHEET_T )
256 {
257 if( m_id == SHEETFILENAME && aAllowExtraText && !IsNameShown() )
258 text = _( "File:" ) + wxS( " " ) + text;
259 }
260
261 return text;
262}
263
264
265wxString SCH_FIELD::GetShownText( bool aAllowExtraText, int aDepth ) const
266{
267 if( SCHEMATIC* schematic = Schematic() )
268 return GetShownText( &schematic->CurrentSheet(), aAllowExtraText, aDepth );
269 else
270 return EDA_TEXT::GetShownText( aAllowExtraText, aDepth );
271}
272
273
274
276{
278}
279
280
282{
284
285 if( !font )
287
288 return font;
289}
290
291
293{
296}
297
298
300{
302 m_renderCacheValid = false;
303}
304
305
306std::vector<std::unique_ptr<KIFONT::GLYPH>>*
307SCH_FIELD::GetRenderCache( const wxString& forResolvedText, const VECTOR2I& forPosition,
308 TEXT_ATTRIBUTES& aAttrs ) const
309{
310 KIFONT::FONT* font = GetFont();
311
312 if( !font )
314
315 if( font->IsOutline() )
316 {
317 KIFONT::OUTLINE_FONT* outlineFont = static_cast<KIFONT::OUTLINE_FONT*>( font );
318
319 if( m_renderCache.empty() || !m_renderCacheValid )
320 {
321 m_renderCache.clear();
322
323 outlineFont->GetLinesAsGlyphs( &m_renderCache, forResolvedText, forPosition, aAttrs,
324 GetFontMetrics() );
325
326 m_renderCachePos = forPosition;
327 m_renderCacheValid = true;
328 }
329
330 if( m_renderCachePos != forPosition )
331 {
332 VECTOR2I delta = forPosition - m_renderCachePos;
333
334 for( std::unique_ptr<KIFONT::GLYPH>& glyph : m_renderCache )
335 static_cast<KIFONT::OUTLINE_GLYPH*>( glyph.get() )->Move( delta );
336
337 m_renderCachePos = forPosition;
338 }
339
340 return &m_renderCache;
341 }
342
343 return nullptr;
344}
345
346
347void SCH_FIELD::Print( const RENDER_SETTINGS* aSettings, const VECTOR2I& aOffset )
348{
349 wxDC* DC = aSettings->GetPrintDC();
351 bool blackAndWhiteMode = GetGRForceBlackPenState();
352 VECTOR2I textpos;
353 int penWidth = GetEffectiveTextPenWidth( aSettings->GetDefaultPenWidth() );
354
355 if( ( !IsVisible() && !IsForceVisible() ) || GetShownText( true ).IsEmpty() )
356 return;
357
358 COLOR4D bg = aSettings->GetBackgroundColor();
359
360 if( bg == COLOR4D::UNSPECIFIED || GetGRForceBlackPenState() )
361 bg = COLOR4D::WHITE;
362
363 if( IsForceVisible() )
364 bg = aSettings->GetLayerColor( LAYER_HIDDEN );
365
366 if( !blackAndWhiteMode && GetTextColor() != COLOR4D::UNSPECIFIED )
368
369 // Calculate the text orientation according to the symbol orientation.
370 EDA_ANGLE orient = GetTextAngle();
371
372 if( m_parent && m_parent->Type() == SCH_SYMBOL_T )
373 {
374 SCH_SYMBOL* parentSymbol = static_cast<SCH_SYMBOL*>( m_parent );
375
376 if( parentSymbol && parentSymbol->GetTransform().y1 ) // Rotate symbol 90 degrees.
377 {
378 if( orient == ANGLE_HORIZONTAL )
379 orient = ANGLE_VERTICAL;
380 else
381 orient = ANGLE_HORIZONTAL;
382 }
383
384 if( parentSymbol && parentSymbol->GetDNP() )
385 {
386 color.Desaturate();
387 color = color.Mix( bg, 0.5f );
388 }
389 }
390
391 KIFONT::FONT* font = GetFont();
392
393 if( !font )
394 font = KIFONT::FONT::GetFont( aSettings->GetDefaultFont(), IsBold(), IsItalic() );
395
396 /*
397 * Calculate the text justification, according to the symbol orientation/mirror.
398 * This is a bit complicated due to cumulative calculations:
399 * - numerous cases (mirrored or not, rotation)
400 * - the GRText function will also recalculate H and V justifications according to the text
401 * orientation.
402 * - When a symbol is mirrored, the text is not mirrored and justifications are complicated
403 * to calculate so the more easily way is to use no justifications (centered text) and use
404 * GetBoundingBox to know the text coordinate considered as centered
405 */
406 textpos = GetBoundingBox().Centre() + aOffset;
407
408 if( GetParent() && GetParent()->Type() == SCH_GLOBAL_LABEL_T )
409 {
410 SCH_GLOBALLABEL* label = static_cast<SCH_GLOBALLABEL*>( GetParent() );
411 textpos += label->GetSchematicTextOffset( aSettings );
412 }
413
414 GRPrintText( DC, textpos, color, GetShownText( true ), orient, GetTextSize(),
416 font, GetFontMetrics() );
417}
418
419
420void SCH_FIELD::ImportValues( const LIB_FIELD& aSource )
421{
422 SetAttributes( aSource );
423 SetNameShown( aSource.IsNameShown() );
424 SetCanAutoplace( aSource.CanAutoplace() );
425}
426
427
429{
430 SCH_ITEM::SwapFlags( aItem );
431
432 wxCHECK_RET( ( aItem != nullptr ) && ( aItem->Type() == SCH_FIELD_T ),
433 wxT( "Cannot swap field data with invalid item." ) );
434
435 SCH_FIELD* item = (SCH_FIELD*) aItem;
436
437 std::swap( m_layer, item->m_layer );
438 std::swap( m_showName, item->m_showName );
439 std::swap( m_allowAutoPlace, item->m_allowAutoPlace );
440 std::swap( m_isNamedVariable, item->m_isNamedVariable );
441 SwapText( *item );
442 SwapAttributes( *item );
443
444 std::swap( m_lastResolvedColor, item->m_lastResolvedColor );
445}
446
447
449{
450 if( GetTextColor() != COLOR4D::UNSPECIFIED )
451 {
453 }
454 else
455 {
456 SCH_LABEL_BASE* parentLabel = dynamic_cast<SCH_LABEL_BASE*>( GetParent() );
457
458 if( parentLabel && !parentLabel->IsConnectivityDirty() )
459 m_lastResolvedColor = parentLabel->GetEffectiveNetClass()->GetSchematicColor();
460 else
462 }
463
464 return m_lastResolvedColor;
465}
466
467
468void SCH_FIELD::ViewGetLayers( int aLayers[], int& aCount ) const
469{
470 aCount = 2;
471
472 switch( m_id )
473 {
474 case REFERENCE_FIELD: aLayers[0] = LAYER_REFERENCEPART; break;
475 case VALUE_FIELD: aLayers[0] = LAYER_VALUEPART; break;
476 default: aLayers[0] = LAYER_FIELDS; break;
477 }
478
479 aLayers[1] = LAYER_SELECTION_SHADOWS;
480}
481
482
484{
485 // Calculate the text orientation according to the symbol orientation.
486 EDA_ANGLE orient = GetTextAngle();
487
488 if( m_parent && m_parent->Type() == SCH_SYMBOL_T )
489 {
490 SCH_SYMBOL* parentSymbol = static_cast<SCH_SYMBOL*>( m_parent );
491
492 if( parentSymbol && parentSymbol->GetTransform().y1 ) // Rotate symbol 90 degrees.
493 {
494 if( orient.IsHorizontal() )
495 orient = ANGLE_VERTICAL;
496 else
497 orient = ANGLE_HORIZONTAL;
498 }
499 }
500
501 return orient;
502}
503
504
506{
507 // Calculate the text bounding box:
508 BOX2I bbox = GetTextBox();
509
510 // Calculate the bounding box position relative to the parent:
511 VECTOR2I origin = GetParentPosition();
512 VECTOR2I pos = GetTextPos() - origin;
513 VECTOR2I begin = bbox.GetOrigin() - origin;
514 VECTOR2I end = bbox.GetEnd() - origin;
515 RotatePoint( begin, pos, GetTextAngle() );
516 RotatePoint( end, pos, GetTextAngle() );
517
518 // Now, apply the symbol transform (mirror/rot)
519 TRANSFORM transform;
520
521 if( m_parent && m_parent->Type() == SCH_SYMBOL_T )
522 {
523 SCH_SYMBOL* parentSymbol = static_cast<SCH_SYMBOL*>( m_parent );
524
525 // Due to the Y axis direction, we must mirror the bounding box,
526 // relative to the text position:
527 MIRROR( begin.y, pos.y );
528 MIRROR( end.y, pos.y );
529
530 transform = parentSymbol->GetTransform();
531 }
532 else
533 {
534 transform = TRANSFORM( 1, 0, 0, 1 ); // identity transform
535 }
536
537 bbox.SetOrigin( transform.TransformCoordinate( begin ) );
538 bbox.SetEnd( transform.TransformCoordinate( end ) );
539
540 bbox.Move( origin );
541 bbox.Normalize();
542
543 return bbox;
544}
545
546
548{
549 VECTOR2I render_center = GetBoundingBox().Centre();
550 VECTOR2I pos = GetPosition();
551
552 switch( GetHorizJustify() )
553 {
555 if( GetDrawRotation().IsVertical() )
556 return render_center.y > pos.y;
557 else
558 return render_center.x < pos.x;
560 if( GetDrawRotation().IsVertical() )
561 return render_center.y < pos.y;
562 else
563 return render_center.x > pos.x;
564 default:
565 return false;
566 }
567}
568
569
571{
572 switch( GetHorizJustify() )
573 {
578 default:
580 }
581}
582
583
585{
586 VECTOR2I render_center = GetBoundingBox().Centre();
587 VECTOR2I pos = GetPosition();
588
589 switch( GetVertJustify() )
590 {
592 if( GetDrawRotation().IsVertical() )
593 return render_center.x < pos.x;
594 else
595 return render_center.y < pos.y;
597 if( GetDrawRotation().IsVertical() )
598 return render_center.x > pos.x;
599 else
600 return render_center.y > pos.y;
601 default:
602 return false;
603 }
604}
605
606
608{
609 switch( GetVertJustify() )
610 {
615 default:
617 }
618}
619
620
621bool SCH_FIELD::Matches( const EDA_SEARCH_DATA& aSearchData, void* aAuxData ) const
622{
623 bool searchHiddenFields = false;
624 bool searchAndReplace = false;
625 bool replaceReferences = false;
626
627 try
628 {
629 const SCH_SEARCH_DATA& schSearchData = dynamic_cast<const SCH_SEARCH_DATA&>( aSearchData ); // downcast
630 searchHiddenFields = schSearchData.searchAllFields;
631 searchAndReplace = schSearchData.searchAndReplace;
632 replaceReferences = schSearchData.replaceReferences;
633 }
634 catch( const std::bad_cast& )
635 {
636 }
637
638 wxString text = UnescapeString( GetText() );
639
640 if( !IsVisible() && !searchHiddenFields )
641 return false;
642
644 {
645 if( searchAndReplace && !replaceReferences )
646 return false;
647
648 SCH_SYMBOL* parentSymbol = static_cast<SCH_SYMBOL*>( m_parent );
649 wxASSERT( aAuxData );
650
651 // Take sheet path into account which effects the reference field and the unit for
652 // symbols with multiple parts.
653 if( aAuxData )
654 {
655 SCH_SHEET_PATH* sheet = (SCH_SHEET_PATH*) aAuxData;
656 text = parentSymbol->GetRef( sheet );
657
658 if( SCH_ITEM::Matches( text, aSearchData ) )
659 return true;
660
661 if( parentSymbol->GetUnitCount() > 1 )
662 text << parentSymbol->SubReference( parentSymbol->GetUnitSelection( sheet ) );
663 }
664 }
665
666 return SCH_ITEM::Matches( text, aSearchData );
667}
668
669
671 wxStyledTextEvent &aEvent ) const
672{
673 SCH_ITEM* parent = dynamic_cast<SCH_ITEM*>( GetParent() );
674 SCHEMATIC* schematic = parent ? parent->Schematic() : nullptr;
675
676 if( !schematic )
677 return;
678
679 wxStyledTextCtrl* scintilla = aScintillaTricks->Scintilla();
680 int key = aEvent.GetKey();
681
682 wxArrayString autocompleteTokens;
683 int pos = scintilla->GetCurrentPos();
684 int start = scintilla->WordStartPosition( pos, true );
685 wxString partial;
686
687 // Multi-line fields are not allowed. So remove '\n' if entered.
688 if( key == '\n' )
689 {
690 wxString text = scintilla->GetText();
691 int currpos = scintilla->GetCurrentPos();
692 text.Replace( wxS( "\n" ), wxS( "" ) );
693 scintilla->SetText( text );
694 scintilla->GotoPos( currpos-1 );
695 return;
696 }
697
698 auto textVarRef =
699 [&]( int pt )
700 {
701 return pt >= 2
702 && scintilla->GetCharAt( pt - 2 ) == '$'
703 && scintilla->GetCharAt( pt - 1 ) == '{';
704 };
705
706 // Check for cross-reference
707 if( start > 1 && scintilla->GetCharAt( start - 1 ) == ':' )
708 {
709 int refStart = scintilla->WordStartPosition( start - 1, true );
710
711 if( textVarRef( refStart ) )
712 {
713 partial = scintilla->GetRange( start, pos );
714
715 wxString ref = scintilla->GetRange( refStart, start - 1 );
716
717 if( ref == wxS( "OP" ) )
718 {
719 // SPICE operating points use ':' syntax for ports
720 if( SCH_SYMBOL* symbol = dynamic_cast<SCH_SYMBOL*>( parent ) )
721 {
722 NULL_REPORTER devnull;
723 SCH_SHEET_PATH& sheet = schematic->CurrentSheet();
724 SIM_LIB_MGR mgr( &schematic->Prj() );
725 SIM_MODEL& model = mgr.CreateModel( &sheet, *symbol, devnull ).model;
726
727 for( wxString pin : model.GetPinNames() )
728 {
729 if( pin.StartsWith( '<' ) && pin.EndsWith( '>' ) )
730 autocompleteTokens.push_back( pin.Mid( 1, pin.Length() - 2 ) );
731 else
732 autocompleteTokens.push_back( pin );
733 }
734 }
735 }
736 else
737 {
738 SCH_SHEET_LIST sheets = schematic->GetSheets();
740 SCH_SYMBOL* refSymbol = nullptr;
741
742 sheets.GetSymbols( refs );
743
744 for( size_t jj = 0; jj < refs.GetCount(); jj++ )
745 {
746 if( refs[ jj ].GetSymbol()->GetRef( &refs[ jj ].GetSheetPath(), true ) == ref )
747 {
748 refSymbol = refs[ jj ].GetSymbol();
749 break;
750 }
751 }
752
753 if( refSymbol )
754 refSymbol->GetContextualTextVars( &autocompleteTokens );
755 }
756 }
757 }
758 else if( textVarRef( start ) )
759 {
760 partial = scintilla->GetTextRange( start, pos );
761
762 SCH_SYMBOL* symbol = dynamic_cast<SCH_SYMBOL*>( parent );
763 SCH_SHEET* sheet = dynamic_cast<SCH_SHEET*>( parent );
764 SCH_LABEL_BASE* label = dynamic_cast<SCH_LABEL_BASE*>( parent );
765
766 if( symbol )
767 {
768 symbol->GetContextualTextVars( &autocompleteTokens );
769
770 if( schematic->CurrentSheet().Last() )
771 schematic->CurrentSheet().Last()->GetContextualTextVars( &autocompleteTokens );
772 }
773
774 if( sheet )
775 sheet->GetContextualTextVars( &autocompleteTokens );
776
777 if( label )
778 label->GetContextualTextVars( &autocompleteTokens );
779
780 for( std::pair<wxString, wxString> entry : schematic->Prj().GetTextVars() )
781 autocompleteTokens.push_back( entry.first );
782 }
783
784 aScintillaTricks->DoAutocomplete( partial, autocompleteTokens );
785 scintilla->SetFocus();
786}
787
788
790{
791 if( m_parent && m_parent->Type() == SCH_SHEET_T )
792 {
793 // See comments in SCH_FIELD::Replace(), below.
794 if( m_id == SHEETFILENAME )
795 return false;
796 }
797 else if( m_parent && m_parent->Type() == SCH_GLOBAL_LABEL_T )
798 {
799 if( m_id == 0 /* IntersheetRefs */ )
800 return false;
801 }
802
803 return true;
804}
805
806
807bool SCH_FIELD::Replace( const EDA_SEARCH_DATA& aSearchData, void* aAuxData )
808{
809 bool replaceReferences = false;
810
811 try
812 {
813 const SCH_SEARCH_DATA& schSearchData = dynamic_cast<const SCH_SEARCH_DATA&>( aSearchData );
814 replaceReferences = schSearchData.replaceReferences;
815 }
816 catch( const std::bad_cast& )
817 {
818 }
819
820 wxString text;
821 bool isReplaced = false;
822
823 if( m_parent && m_parent->Type() == SCH_SYMBOL_T )
824 {
825 SCH_SYMBOL* parentSymbol = static_cast<SCH_SYMBOL*>( m_parent );
826
827 switch( m_id )
828 {
829 case REFERENCE_FIELD:
830 wxCHECK_MSG( aAuxData, false, wxT( "Need sheetpath to replace in refdes." ) );
831
832 if( !replaceReferences )
833 return false;
834
835 text = parentSymbol->GetRef( (SCH_SHEET_PATH*) aAuxData );
836 isReplaced = EDA_ITEM::Replace( aSearchData, text );
837
838 if( isReplaced )
839 parentSymbol->SetRef( (SCH_SHEET_PATH*) aAuxData, text );
840
841 break;
842
843 case VALUE_FIELD:
844 wxCHECK_MSG( aAuxData, false, wxT( "Need sheetpath to replace in value field." ) );
845
846 text = parentSymbol->GetField( VALUE_FIELD )->GetText();
847 isReplaced = EDA_ITEM::Replace( aSearchData, text );
848
849 if( isReplaced )
850 parentSymbol->SetValueFieldText( text );
851
852 break;
853
854 case FOOTPRINT_FIELD:
855 wxCHECK_MSG( aAuxData, false, wxT( "Need sheetpath to replace in footprint field." ) );
856
857 text = parentSymbol->GetField( FOOTPRINT_FIELD )->GetText();
858 isReplaced = EDA_ITEM::Replace( aSearchData, text );
859
860 if( isReplaced )
861 parentSymbol->SetFootprintFieldText( text );
862
863 break;
864
865 default:
866 isReplaced = EDA_TEXT::Replace( aSearchData );
867 }
868 }
869 else if( m_parent && m_parent->Type() == SCH_SHEET_T )
870 {
871 isReplaced = EDA_TEXT::Replace( aSearchData );
872
873 if( m_id == SHEETFILENAME && isReplaced )
874 {
875 // If we allowed this we'd have a bunch of work to do here, including warning
876 // about it not being undoable, checking for recursive hierarchies, reloading
877 // sheets, etc. See DIALOG_SHEET_PROPERTIES::TransferDataFromWindow().
878 }
879 }
880 else
881 {
882 isReplaced = EDA_TEXT::Replace( aSearchData );
883 }
884
885 return isReplaced;
886}
887
888
889void SCH_FIELD::Rotate( const VECTOR2I& aCenter )
890{
891 VECTOR2I pt = GetPosition();
892 RotatePoint( pt, aCenter, ANGLE_90 );
893 SetPosition( pt );
894}
895
896
897wxString SCH_FIELD::GetItemDescription( UNITS_PROVIDER* aUnitsProvider ) const
898{
899 return wxString::Format( "%s '%s'", GetName(), KIUI::EllipsizeMenuText( GetText() ) );
900}
901
902
903void SCH_FIELD::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList )
904{
905 wxString msg;
906
907 aList.emplace_back( _( "Symbol Field" ), UnescapeString( GetName() ) );
908
909 // Don't use GetShownText() here; we want to show the user the variable references
910 aList.emplace_back( _( "Text" ), KIUI::EllipsizeStatusText( aFrame, GetText() ) );
911
912 aList.emplace_back( _( "Visible" ), IsVisible() ? _( "Yes" ) : _( "No" ) );
913
914 aList.emplace_back( _( "Font" ), GetFont() ? GetFont()->GetName() : _( "Default" ) );
915
916 aList.emplace_back( _( "Style" ), GetTextStyleName() );
917
918 aList.emplace_back( _( "Text Size" ), aFrame->MessageTextFromValue( GetTextWidth() ) );
919
920 switch ( GetHorizJustify() )
921 {
922 case GR_TEXT_H_ALIGN_LEFT: msg = _( "Left" ); break;
923 case GR_TEXT_H_ALIGN_CENTER: msg = _( "Center" ); break;
924 case GR_TEXT_H_ALIGN_RIGHT: msg = _( "Right" ); break;
925 }
926
927 aList.emplace_back( _( "H Justification" ), msg );
928
929 switch ( GetVertJustify() )
930 {
931 case GR_TEXT_V_ALIGN_TOP: msg = _( "Top" ); break;
932 case GR_TEXT_V_ALIGN_CENTER: msg = _( "Center" ); break;
933 case GR_TEXT_V_ALIGN_BOTTOM: msg = _( "Bottom" ); break;
934 }
935
936 aList.emplace_back( _( "V Justification" ), msg );
937}
938
939
941{
942 constexpr int START_ID = 1;
943
944 if( IsHypertext() )
945 {
946 SCH_LABEL_BASE* label = static_cast<SCH_LABEL_BASE*>( m_parent );
947 std::vector<std::pair<wxString, wxString>> pages;
948 wxMenu menu;
949 wxString href;
950
951 label->GetIntersheetRefs( &pages );
952
953 for( int i = 0; i < (int) pages.size(); ++i )
954 {
955 menu.Append( i + START_ID, wxString::Format( _( "Go to Page %s (%s)" ),
956 pages[i].first,
957 pages[i].second ) );
958 }
959
960 menu.AppendSeparator();
961 menu.Append( 999 + START_ID, _( "Back to Previous Selected Sheet" ) );
962
963 int sel = aFrame->GetPopupMenuSelectionFromUser( menu ) - START_ID;
964
965 if( sel >= 0 && sel < (int) pages.size() )
966 href = wxT( "#" ) + pages[ sel ].first;
967 else if( sel == 999 )
969
970 if( !href.IsEmpty() )
971 {
973 navTool->HypertextCommand( href );
974 }
975 }
976}
977
978
979void SCH_FIELD::SetName( const wxString& aName )
980{
981 m_name = aName;
982 m_isNamedVariable = m_name.StartsWith( wxT( "${" ) );
983
985 EDA_TEXT::SetText( aName );
986}
987
988
989void SCH_FIELD::SetText( const wxString& aText )
990{
991 // Don't allow modification of text value when using named variables
992 // as field name.
994 return;
995
996 EDA_TEXT::SetText( aText );
997}
998
999
1000wxString SCH_FIELD::GetName( bool aUseDefaultName ) const
1001{
1002 if( m_parent && m_parent->Type() == SCH_SYMBOL_T )
1003 {
1004 if( m_id >= 0 && m_id < MANDATORY_FIELDS )
1005 return GetCanonicalFieldName( m_id );
1006 else if( m_name.IsEmpty() && aUseDefaultName )
1008 else
1009 return m_name;
1010 }
1011 else if( m_parent && m_parent->Type() == SCH_SHEET_T )
1012 {
1013 if( m_id >= 0 && m_id < SHEET_MANDATORY_FIELDS )
1015 else if( m_name.IsEmpty() && aUseDefaultName )
1017 else
1018 return m_name;
1019 }
1020 else if( m_parent && m_parent->IsType( { SCH_LABEL_LOCATE_ANY_T } ) )
1021 {
1022 return SCH_LABEL_BASE::GetDefaultFieldName( m_name, aUseDefaultName );
1023 }
1024 else
1025 {
1026 wxFAIL_MSG( "Unhandled field owner type." );
1027 return m_name;
1028 }
1029}
1030
1031
1033{
1034 if( m_parent && m_parent->Type() == SCH_SYMBOL_T )
1035 {
1036 if( m_id < MANDATORY_FIELDS )
1037 return GetCanonicalFieldName( m_id );
1038 else
1039 return m_name;
1040 }
1041 else if( m_parent && m_parent->Type() == SCH_SHEET_T )
1042 {
1043 switch( m_id )
1044 {
1045 case SHEETNAME: return wxT( "Sheetname" );
1046 case SHEETFILENAME: return wxT( "Sheetfile" );
1047 default: return m_name;
1048 }
1049 }
1050 else if( m_parent && m_parent->IsType( { SCH_LABEL_LOCATE_ANY_T } ) )
1051 {
1052 // These should be stored in canonical format, but just in case:
1053 if( m_name == _( "Net Class" ) || m_name == wxT( "Net Class" ) )
1054 return wxT( "Netclass" );
1055 else if( m_name == _( "Sheet References" )
1056 || m_name == wxT( "Sheet References" )
1057 || m_name == wxT( "Intersheet References" ) )
1058 return wxT( "Intersheetrefs" );
1059 else
1060 return m_name;
1061 }
1062 else
1063 {
1064 if( m_parent )
1065 {
1066 wxFAIL_MSG( wxString::Format( "Unhandled field owner type (id %d, parent type %d).",
1067 m_id, m_parent->Type() ) );
1068 }
1069
1070 return m_name;
1071 }
1072}
1073
1074
1076{
1077 if( m_parent && m_parent->Type() == SCH_SYMBOL_T )
1078 {
1079 switch( m_id )
1080 {
1081 case REFERENCE_FIELD: return BITMAPS::edit_comp_ref;
1082 case VALUE_FIELD: return BITMAPS::edit_comp_value;
1083 case FOOTPRINT_FIELD: return BITMAPS::edit_comp_footprint;
1084 default: return BITMAPS::text;
1085 }
1086 }
1087
1088 return BITMAPS::text;
1089}
1090
1091
1092bool SCH_FIELD::HitTest( const VECTOR2I& aPosition, int aAccuracy ) const
1093{
1094 // Do not hit test hidden or empty fields.
1095 if( !IsVisible() || GetShownText( true ).IsEmpty() )
1096 return false;
1097
1098 BOX2I rect = GetBoundingBox();
1099
1100 rect.Inflate( aAccuracy );
1101
1102 if( GetParent() && GetParent()->Type() == SCH_GLOBAL_LABEL_T )
1103 {
1104 SCH_GLOBALLABEL* label = static_cast<SCH_GLOBALLABEL*>( GetParent() );
1105 rect.Offset( label->GetSchematicTextOffset( nullptr ) );
1106 }
1107
1108 return rect.Contains( aPosition );
1109}
1110
1111
1112bool SCH_FIELD::HitTest( const BOX2I& aRect, bool aContained, int aAccuracy ) const
1113{
1114 // Do not hit test hidden fields.
1115 if( !IsVisible() || GetShownText( true ).IsEmpty() )
1116 return false;
1117
1118 BOX2I rect = aRect;
1119
1120 rect.Inflate( aAccuracy );
1121
1122 if( GetParent() && GetParent()->Type() == SCH_GLOBAL_LABEL_T )
1123 {
1124 SCH_GLOBALLABEL* label = static_cast<SCH_GLOBALLABEL*>( GetParent() );
1125 rect.Offset( label->GetSchematicTextOffset( nullptr ) );
1126 }
1127
1128 if( aContained )
1129 return rect.Contains( GetBoundingBox() );
1130
1131 return rect.Intersects( GetBoundingBox() );
1132}
1133
1134
1135void SCH_FIELD::Plot( PLOTTER* aPlotter, bool aBackground,
1136 const SCH_PLOT_SETTINGS& aPlotSettings ) const
1137{
1138 if( GetShownText( true ).IsEmpty() || aBackground )
1139 return;
1140
1141 RENDER_SETTINGS* settings = aPlotter->RenderSettings();
1142 COLOR4D color = settings->GetLayerColor( GetLayer() );
1143 int penWidth = GetEffectiveTextPenWidth( settings->GetDefaultPenWidth() );
1144
1145 COLOR4D bg = settings->GetBackgroundColor();;
1146
1147 if( bg == COLOR4D::UNSPECIFIED || !aPlotter->GetColorMode() )
1148 bg = COLOR4D::WHITE;
1149
1150 if( aPlotter->GetColorMode() && GetTextColor() != COLOR4D::UNSPECIFIED )
1151 color = GetTextColor();
1152
1153 penWidth = std::max( penWidth, settings->GetMinPenWidth() );
1154
1155 // clamp the pen width to be sure the text is readable
1156 penWidth = std::min( penWidth, std::min( GetTextSize().x, GetTextSize().y ) / 4 );
1157
1158 if( !IsVisible() )
1159 return;
1160
1161 // Calculate the text orientation, according to the symbol orientation/mirror
1162 EDA_ANGLE orient = GetTextAngle();
1163 VECTOR2I textpos = GetTextPos();
1165 GR_TEXT_V_ALIGN_T vjustify = GetVertJustify();
1166
1167 if( m_parent && m_parent->Type() == SCH_SYMBOL_T )
1168 {
1169 SCH_SYMBOL* parentSymbol = static_cast<SCH_SYMBOL*>( m_parent );
1170
1171 if( parentSymbol->GetDNP() )
1172 {
1173 color.Desaturate();
1174 color = color.Mix( bg, 0.5f );
1175 }
1176
1177 if( parentSymbol->GetTransform().y1 ) // Rotate symbol 90 deg.
1178 {
1179 if( orient.IsHorizontal() )
1180 orient = ANGLE_VERTICAL;
1181 else
1182 orient = ANGLE_HORIZONTAL;
1183 }
1184
1185 /*
1186 * Calculate the text justification, according to the symbol orientation/mirror. This is
1187 * a bit complicated due to cumulative calculations:
1188 * - numerous cases (mirrored or not, rotation)
1189 * - the plotter's Text() function will also recalculate H and V justifications according
1190 * to the text orientation
1191 * - when a symbol is mirrored the text is not, and justifications become a nightmare
1192 *
1193 * So the easier way is to use no justifications (centered text) and use GetBoundingBox to
1194 * know the text coordinate considered as centered.
1195 */
1196 hjustify = GR_TEXT_H_ALIGN_CENTER;
1197 vjustify = GR_TEXT_V_ALIGN_CENTER;
1198 textpos = GetBoundingBox().Centre();
1199 }
1200 else if( m_parent && m_parent->Type() == SCH_GLOBAL_LABEL_T )
1201 {
1202 SCH_GLOBALLABEL* label = static_cast<SCH_GLOBALLABEL*>( m_parent );
1203 textpos += label->GetSchematicTextOffset( settings );
1204 }
1205
1206 KIFONT::FONT* font = GetFont();
1207
1208 if( !font )
1209 font = KIFONT::FONT::GetFont( settings->GetDefaultFont(), IsBold(), IsItalic() );
1210
1212 attrs.m_StrokeWidth = penWidth;
1213 attrs.m_Halign = hjustify;
1214 attrs.m_Valign = vjustify;
1215 attrs.m_Angle = orient;
1216 attrs.m_Multiline = false;
1217
1218 aPlotter->PlotText( textpos, color, GetShownText( true ), attrs, font, GetFontMetrics() );
1219
1220 if( IsHypertext() )
1221 {
1222 SCH_LABEL_BASE* label = static_cast<SCH_LABEL_BASE*>( m_parent );
1223 std::vector<std::pair<wxString, wxString>> pages;
1224 std::vector<wxString> pageHrefs;
1225 BOX2I bbox = GetBoundingBox();
1226
1227 wxCHECK( label, /* void */ );
1228
1229 label->GetIntersheetRefs( &pages );
1230
1231 for( const std::pair<wxString, wxString>& page : pages )
1232 pageHrefs.push_back( wxT( "#" ) + page.first );
1233
1234 bbox.Offset( label->GetSchematicTextOffset( settings ) );
1235
1236 aPlotter->HyperlinkMenu( bbox, pageHrefs );
1237 }
1238}
1239
1240
1241void SCH_FIELD::SetPosition( const VECTOR2I& aPosition )
1242{
1243 // Actual positions are calculated by the rotation/mirror transform of the parent symbol
1244 // of the field. The inverse transform is used to calculate the position relative to the
1245 // parent symbol.
1246 if( m_parent && m_parent->Type() == SCH_SYMBOL_T )
1247 {
1248 SCH_SYMBOL* parentSymbol = static_cast<SCH_SYMBOL*>( m_parent );
1249 VECTOR2I relPos = aPosition - parentSymbol->GetPosition();
1250
1251 relPos = parentSymbol->GetTransform().InverseTransform().TransformCoordinate( relPos );
1252
1253 SetTextPos( relPos + parentSymbol->GetPosition() );
1254 return;
1255 }
1256
1257 SetTextPos( aPosition );
1258}
1259
1260
1262{
1263 if( m_parent && m_parent->Type() == SCH_SYMBOL_T )
1264 {
1265 SCH_SYMBOL* parentSymbol = static_cast<SCH_SYMBOL*>( m_parent );
1266 VECTOR2I relativePos = GetTextPos() - parentSymbol->GetPosition();
1267
1268 relativePos = parentSymbol->GetTransform().TransformCoordinate( relativePos );
1269
1270 return relativePos + parentSymbol->GetPosition();
1271 }
1272
1273 return GetTextPos();
1274}
1275
1276
1278{
1279 return m_parent ? m_parent->GetPosition() : VECTOR2I( 0, 0 );
1280}
1281
1282
1283bool SCH_FIELD::operator <( const SCH_ITEM& aItem ) const
1284{
1285 if( Type() != aItem.Type() )
1286 return Type() < aItem.Type();
1287
1288 auto field = static_cast<const SCH_FIELD*>( &aItem );
1289
1290 if( GetId() != field->GetId() )
1291 return GetId() < field->GetId();
1292
1293 if( GetText() != field->GetText() )
1294 return GetText() < field->GetText();
1295
1296 if( GetLibPosition().x != field->GetLibPosition().x )
1297 return GetLibPosition().x < field->GetLibPosition().x;
1298
1299 if( GetLibPosition().y != field->GetLibPosition().y )
1300 return GetLibPosition().y < field->GetLibPosition().y;
1301
1302 return GetName() < field->GetName();
1303}
1304
1305bool SCH_FIELD::operator==( const SCH_ITEM& aOther ) const
1306{
1307 if( Type() != aOther.Type() )
1308 return false;
1309
1310 const SCH_FIELD& field = static_cast<const SCH_FIELD&>( aOther );
1311
1312 if( GetId() != field.GetId() )
1313 return false;
1314
1315 if( GetPosition() != field.GetPosition() )
1316 return false;
1317
1318 if( IsNamedVariable() != field.IsNamedVariable() )
1319 return false;
1320
1321 if( IsNameShown() != field.IsNameShown() )
1322 return false;
1323
1324 if( CanAutoplace() != field.CanAutoplace() )
1325 return false;
1326
1327 if( GetText() != field.GetText() )
1328 return false;
1329
1330 return true;
1331}
1332
1333
1334double SCH_FIELD::Similarity( const SCH_ITEM& aOther ) const
1335{
1336 if( Type() != aOther.Type() )
1337 return 0.0;
1338
1339 if( m_Uuid == aOther.m_Uuid )
1340 return 1.0;
1341
1342 const SCH_FIELD& field = static_cast<const SCH_FIELD&>( aOther );
1343
1344 double retval = 0.99; // The UUIDs are different, so we start with non-identity
1345
1346 if( GetId() != field.GetId() )
1347 {
1348 // We don't allow swapping of mandatory fields, so these cannot be the same item
1349 if( GetId() < MANDATORY_FIELDS || field.GetId() < MANDATORY_FIELDS )
1350 return 0.0;
1351 else
1352 retval *= 0.5;
1353 }
1354
1355 if( GetPosition() != field.GetPosition() )
1356 retval *= 0.5;
1357
1358 if( IsNamedVariable() != field.IsNamedVariable() )
1359 retval *= 0.5;
1360
1361 if( IsNameShown() != field.IsNameShown() )
1362 retval *= 0.5;
1363
1364 if( CanAutoplace() != field.CanAutoplace() )
1365 retval *= 0.5;
1366
1367 if( GetText() != field.GetText() )
1368 retval *= Levenshtein( field );
1369
1370 return 1.0;
1371}
1372
1373
1374static struct SCH_FIELD_DESC
1375{
1377 {
1384
1385 propMgr.AddProperty( new PROPERTY<SCH_FIELD, bool>( _HKI( "Show Field Name" ),
1387
1388 propMgr.AddProperty( new PROPERTY<SCH_FIELD, bool>( _HKI( "Allow Autoplacement" ),
1390
1391 propMgr.Mask( TYPE_HASH( SCH_FIELD ), TYPE_HASH( EDA_TEXT ), _HKI( "Hyperlink" ) );
1392 propMgr.Mask( TYPE_HASH( SCH_FIELD ), TYPE_HASH( EDA_TEXT ), _HKI( "Thickness" ) );
1393 propMgr.Mask( TYPE_HASH( SCH_FIELD ), TYPE_HASH( EDA_TEXT ), _HKI( "Mirrored" ) );
1394 propMgr.Mask( TYPE_HASH( SCH_FIELD ), TYPE_HASH( EDA_TEXT ), _HKI( "Visible" ) );
1395 propMgr.Mask( TYPE_HASH( SCH_FIELD ), TYPE_HASH( EDA_TEXT ), _HKI( "Width" ) );
1396 propMgr.Mask( TYPE_HASH( SCH_FIELD ), TYPE_HASH( EDA_TEXT ), _HKI( "Height" ) );
1397
1398 propMgr.Mask( TYPE_HASH( SCH_FIELD ), TYPE_HASH( EDA_TEXT ), _HKI( "Orientation" ) );
1399
1400 auto isNotNamedVariable =
1401 []( INSPECTABLE* aItem ) -> bool
1402 {
1403 if( SCH_FIELD* field = dynamic_cast<SCH_FIELD*>( aItem ) )
1404 return !field->IsNamedVariable();
1405
1406 return true;
1407 };
1408
1410 isNotNamedVariable );
1411 }
int color
Definition: DXF_plotter.cpp:58
constexpr EDA_IU_SCALE schIUScale
Definition: base_units.h:111
BITMAPS
A list of all bitmap identifiers.
Definition: bitmaps_list.h:33
void SetOrigin(const Vec &pos)
Definition: box2.h:203
BOX2< Vec > & Normalize()
Ensure that the height and width are positive.
Definition: box2.h:120
const Vec & GetOrigin() const
Definition: box2.h:184
void Offset(coord_type dx, coord_type dy)
Definition: box2.h:225
bool Intersects(const BOX2< Vec > &aRect) const
Definition: box2.h:270
const Vec GetEnd() const
Definition: box2.h:186
void Move(const Vec &aMoveVector)
Move the rectangle by the aMoveVector.
Definition: box2.h:112
bool Contains(const Vec &aPoint) const
Definition: box2.h:142
BOX2< Vec > & Inflate(coord_type dx, coord_type dy)
Inflates the rectangle horizontally by dx and vertically by dy.
Definition: box2.h:507
Vec Centre() const
Definition: box2.h:71
void SetEnd(coord_type x, coord_type y)
Definition: box2.h:256
bool IsHorizontal() const
Definition: eda_angle.h:174
The base class for create windows for drawing purpose.
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:85
virtual VECTOR2I GetPosition() const
Definition: eda_item.h:239
const KIID m_Uuid
Definition: eda_item.h:482
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:97
virtual bool Matches(const EDA_SEARCH_DATA &aSearchData, void *aAuxData) const
Compare the item against the search criteria in aSearchData.
Definition: eda_item.h:372
virtual bool IsType(const std::vector< KICAD_T > &aScanTypes) const
Check whether the item is one of the listed types.
Definition: eda_item.h:172
EDA_ITEM * GetParent() const
Definition: eda_item.h:99
EDA_ITEM * m_parent
Linked list: Link (parent struct)
Definition: eda_item.h:485
bool IsForceVisible() const
Definition: eda_item.h:191
static bool Replace(const EDA_SEARCH_DATA &aSearchData, wxString &aText)
Perform a text replace on aText using the find and replace criteria in aSearchData on items that supp...
Definition: eda_item.cpp:186
A mix-in class (via multiple inheritance) that handles texts such as labels, parts,...
Definition: eda_text.h:80
BOX2I GetTextBox(int aLine=-1, bool aInvertY=false) const
Useful in multiline texts to calculate the full text or a line area (for zones filling,...
Definition: eda_text.cpp:549
const VECTOR2I & GetTextPos() const
Definition: eda_text.h:230
COLOR4D GetTextColor() const
Definition: eda_text.h:227
wxString GetTextStyleName() const
Definition: eda_text.cpp:794
bool IsItalic() const
Definition: eda_text.h:141
const EDA_ANGLE & GetTextAngle() const
Definition: eda_text.h:131
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition: eda_text.h:95
virtual bool IsVisible() const
Definition: eda_text.h:147
void SetTextPos(const VECTOR2I &aPoint)
Definition: eda_text.cpp:401
KIFONT::FONT * GetFont() const
Definition: eda_text.h:207
void SetAttributes(const EDA_TEXT &aSrc, bool aSetPosition=true)
Set the text attributes from another instance.
Definition: eda_text.cpp:276
EDA_TEXT & operator=(const EDA_TEXT &aItem)
Definition: eda_text.cpp:152
int GetTextWidth() const
Definition: eda_text.h:221
GR_TEXT_H_ALIGN_T GetHorizJustify() const
Definition: eda_text.h:160
bool Replace(const EDA_SEARCH_DATA &aSearchData)
Helper function used in search and replace dialog.
Definition: eda_text.cpp:329
bool HasTextVars() const
Indicates the ShownText has text var references which need to be processed.
Definition: eda_text.h:114
virtual void SetVisible(bool aVisible)
Definition: eda_text.cpp:229
virtual void ClearBoundingBoxCache()
Definition: eda_text.cpp:487
virtual void ClearRenderCache()
Definition: eda_text.cpp:481
const TEXT_ATTRIBUTES & GetAttributes() const
Definition: eda_text.h:191
int GetEffectiveTextPenWidth(int aDefaultPenWidth=0) const
The EffectiveTextPenWidth uses the text thickness if > 1 or aDefaultPenWidth.
Definition: eda_text.cpp:308
void SwapAttributes(EDA_TEXT &aTradingPartner)
Swap the text attributes of the two involved instances.
Definition: eda_text.cpp:295
bool IsBold() const
Definition: eda_text.h:144
GR_TEXT_V_ALIGN_T GetVertJustify() const
Definition: eda_text.h:163
virtual wxString GetShownText(bool aAllowExtraText, int aDepth=0) const
Return the string actually shown after processing of the base text.
Definition: eda_text.h:106
virtual void SetText(const wxString &aText)
Definition: eda_text.cpp:183
double Levenshtein(const EDA_TEXT &aOther) const
Return the levenstein distance between two texts.
Definition: eda_text.cpp:1072
void SwapText(EDA_TEXT &aTradingPartner)
Definition: eda_text.cpp:288
VECTOR2I GetTextSize() const
Definition: eda_text.h:218
Class that other classes need to inherit from, in order to be inspectable.
Definition: inspectable.h:36
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
Class OUTLINE_FONT implements outline font drawing.
Definition: outline_font.h:52
void GetLinesAsGlyphs(std::vector< std::unique_ptr< GLYPH > > *aGlyphs, const wxString &aText, const VECTOR2I &aPosition, const TEXT_ATTRIBUTES &aAttrs, const METRICS &aFontMetrics) const
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.
virtual const COLOR4D & GetBackgroundColor() const =0
Return current background color settings.
wxDC * GetPrintDC() const
Field object used in symbol libraries.
Definition: lib_field.h:62
bool CanAutoplace() const
Definition: lib_field.h:195
bool IsNameShown() const
Definition: lib_field.h:192
A singleton reporter that reports to nowhere.
Definition: reporter.h:223
Base plotter engine class.
Definition: plotter.h:104
RENDER_SETTINGS * RenderSettings()
Definition: plotter.h:135
bool GetColorMode() const
Definition: plotter.h:132
virtual void HyperlinkMenu(const BOX2I &aBox, const std::vector< wxString > &aDestURLs)
Create a clickable hyperlink menu with a rectangular click area.
Definition: plotter.h:463
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
virtual std::map< wxString, wxString > & GetTextVars() const
Definition: project.cpp:84
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 OverrideWriteability(TYPE_ID aDerived, TYPE_ID aBase, const wxString &aName, std::function< bool(INSPECTABLE *)> aFunc)
Sets an override writeability functor for a base class property of a given derived class.
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
SCH_SHEET_LIST GetSheets() const override
Builds and returns an updated schematic hierarchy TODO: can this be cached?
Definition: schematic.h:100
PROJECT & Prj() const override
Return a reference to the project this schematic is part of.
Definition: schematic.h:90
Instances are attached to a symbol or sheet and provide a place for the symbol's value,...
Definition: sch_field.h:52
void ClearRenderCache() override
Definition: sch_field.cpp:299
COLOR4D m_lastResolvedColor
Definition: sch_field.h:306
GR_TEXT_V_ALIGN_T GetEffectiveVertJustify() const
Definition: sch_field.cpp:607
const BOX2I GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
Definition: sch_field.cpp:505
std::vector< std::unique_ptr< KIFONT::GLYPH > > m_renderCache
Definition: sch_field.h:304
void ViewGetLayers(int aLayers[], int &aCount) const override
Return the all the layers within the VIEW the object is painted on.
Definition: sch_field.cpp:468
VECTOR2I GetPosition() const override
Definition: sch_field.cpp:1261
bool Replace(const EDA_SEARCH_DATA &aSearchData, void *aAuxData=nullptr) override
Perform a text replace using the find and replace criteria in aSearchData on items that support text ...
Definition: sch_field.cpp:807
bool m_showName
Render the field name in addition to its value.
Definition: sch_field.h:297
void Rotate(const VECTOR2I &aCenter) override
Rotate the item around aCenter 90 degrees in the clockwise direction.
Definition: sch_field.cpp:889
void Print(const RENDER_SETTINGS *aSettings, const VECTOR2I &aOffset) override
Print a schematic item.
Definition: sch_field.cpp:347
EDA_ITEM * Clone() const override
Create a duplicate of this item with linked list members set to NULL.
Definition: sch_field.cpp:139
BITMAPS GetMenuImage() const override
Return a pointer to an image to be used in menus.
Definition: sch_field.cpp:1075
bool IsNameShown() const
Definition: sch_field.h:184
bool IsHypertext() const override
Allow items to support hypertext actions when hovered/clicked.
Definition: sch_field.h:96
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_field.cpp:1334
bool HitTest(const VECTOR2I &aPosition, int aAccuracy=0) const override
Test if aPosition is inside or on the boundary of this item.
Definition: sch_field.cpp:1092
bool IsHorizJustifyFlipped() const
Return whether the field will be rendered with the horizontal justification inverted due to rotation ...
Definition: sch_field.cpp:547
bool IsVertJustifyFlipped() const
Definition: sch_field.cpp:584
wxString GetItemDescription(UNITS_PROVIDER *aUnitsProvider) const override
Return a user-visible description string of this item.
Definition: sch_field.cpp:897
EDA_ANGLE GetDrawRotation() const override
Adjusters to allow EDA_TEXT to draw/print/etc.
Definition: sch_field.cpp:483
bool Matches(const EDA_SEARCH_DATA &aSearchData, void *aAuxData) const override
Compare the item against the search criteria in aSearchData.
Definition: sch_field.cpp:621
void SetCanAutoplace(bool aCanPlace)
Definition: sch_field.h:196
bool m_isNamedVariable
If the field name is a variable name, e.g.
Definition: sch_field.h:299
void DoHypertextAction(EDA_DRAW_FRAME *aFrame) const override
Definition: sch_field.cpp:940
void Plot(PLOTTER *aPlotter, bool aBackground, const SCH_PLOT_SETTINGS &aPlotSettings) const override
Plot the schematic item to aPlotter.
Definition: sch_field.cpp:1135
int GetPenWidth() const override
Definition: sch_field.cpp:275
wxString GetCanonicalName() const
Get a non-language-specific name for a field which can be used for storage, variable look-up,...
Definition: sch_field.cpp:1032
COLOR4D GetFieldColor() const
Definition: sch_field.cpp:448
bool IsNamedVariable() const
Named variables are fields whose names are variables like ${VAR}.
Definition: sch_field.h:193
int GetId() const
Definition: sch_field.h:128
bool operator==(const SCH_ITEM &aItem) const override
Definition: sch_field.cpp:1305
SCH_FIELD & operator=(const SCH_FIELD &aField)
Definition: sch_field.cpp:110
bool operator<(const SCH_ITEM &aItem) const override
Definition: sch_field.cpp:1283
wxString GetShownName() const
Gets the fields name as displayed on the schematic or in the symbol fields table.
Definition: sch_field.cpp:182
VECTOR2I GetLibPosition() const
Definition: sch_field.h:262
bool IsEmpty()
Return true if both the name and value of the field are empty.
Definition: sch_field.h:147
SCH_FIELD(const VECTOR2I &aPos, int aFieldId, SCH_ITEM *aParent, const wxString &aName=wxEmptyString)
Definition: sch_field.cpp:60
bool m_renderCacheValid
Definition: sch_field.h:302
bool IsReplaceable() const override
Override this method in any derived object that supports test find and replace.
Definition: sch_field.cpp:789
GR_TEXT_H_ALIGN_T GetEffectiveHorizJustify() const
Definition: sch_field.cpp:570
wxString GetName(bool aUseDefaultName=true) const
Return the field name (not translated).
Definition: sch_field.cpp:1000
void SetPosition(const VECTOR2I &aPosition) override
Definition: sch_field.cpp:1241
void ImportValues(const LIB_FIELD &aSource)
Copy parameters from a LIB_FIELD source.
Definition: sch_field.cpp:420
void SwapData(SCH_ITEM *aItem) override
Swap the internal data structures aItem with the schematic item.
Definition: sch_field.cpp:428
void SetName(const wxString &aName)
Definition: sch_field.cpp:979
wxString GetShownText(const SCH_SHEET_PATH *aPath, bool aAllowExtraText, int aDepth=0) const
Definition: sch_field.cpp:188
void Move(const VECTOR2I &aMoveVector) override
Move the item by aMoveVector to a new position.
Definition: sch_field.h:220
VECTOR2I m_renderCachePos
Definition: sch_field.h:303
bool CanAutoplace() const
Definition: sch_field.h:195
std::vector< std::unique_ptr< KIFONT::GLYPH > > * GetRenderCache(const wxString &forResolvedText, const VECTOR2I &forPosition, TEXT_ATTRIBUTES &aAttrs) const
Definition: sch_field.cpp:307
void SetId(int aId)
Definition: sch_field.cpp:145
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_field.cpp:903
void ClearCaches() override
Definition: sch_field.cpp:292
void SetText(const wxString &aText) override
Definition: sch_field.cpp:989
VECTOR2I GetParentPosition() const
Definition: sch_field.cpp:1277
int m_id
Field index,.
Definition: sch_field.h:293
void OnScintillaCharAdded(SCINTILLA_TRICKS *aScintillaTricks, wxStyledTextEvent &aEvent) const
Definition: sch_field.cpp:670
wxString m_name
Definition: sch_field.h:295
void SetNameShown(bool aShown=true)
Definition: sch_field.h:185
KIFONT::FONT * getDrawFont() const override
Definition: sch_field.cpp:281
bool m_allowAutoPlace
This field can be autoplaced.
Definition: sch_field.h:298
VECTOR2I GetSchematicTextOffset(const RENDER_SETTINGS *aSettings) const override
This offset depends on the orientation, the type of text, and the area required to draw the associate...
Definition: sch_label.cpp:1725
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:151
const wxString & GetDefaultFont() const
Definition: sch_item.cpp:323
SCHEMATIC * Schematic() const
Searches the item hierarchy to find a SCHEMATIC.
Definition: sch_item.cpp:113
std::shared_ptr< NETCLASS > GetEffectiveNetClass(const SCH_SHEET_PATH *aSheet=nullptr) const
Definition: sch_item.cpp:176
void SetLayer(SCH_LAYER_ID aLayer)
Set the layer this item is on.
Definition: sch_item.h:265
SCH_LAYER_ID GetLayer() const
Return the layer this item is on.
Definition: sch_item.h:258
bool IsConnectivityDirty() const
Definition: sch_item.h:436
void SwapFlags(SCH_ITEM *aItem)
Swap the non-temp and non-edit flags.
Definition: sch_item.cpp:267
const KIFONT::METRICS & GetFontMetrics() const
Definition: sch_item.cpp:331
SCH_LAYER_ID m_layer
Definition: sch_item.h:521
void GetIntersheetRefs(std::vector< std::pair< wxString, wxString > > *pages)
Builds an array of { pageNumber, pageName } pairs.
Definition: sch_label.cpp:708
virtual bool ResolveTextVar(const SCH_SHEET_PATH *aPath, wxString *token, int aDepth) const
Resolve any references to system tokens supported by the label.
Definition: sch_label.cpp:756
static const wxString GetDefaultFieldName(const wxString &aName, bool aUseDefaultName)
Definition: sch_label.cpp:246
void GetContextualTextVars(wxArrayString *aVars) const
Return the list of system text vars & fields for this label.
Definition: sch_label.cpp:743
VECTOR2I GetSchematicTextOffset(const RENDER_SETTINGS *aSettings) const override
This offset depends on the orientation, the type of text, and the area required to draw the associate...
Definition: sch_label.cpp:391
Handle actions specific to the schematic editor.
static wxString g_BackLink
void HypertextCommand(const wxString &href)
Container to create a flattened list of symbols because in a complex hierarchy, a symbol can be used ...
size_t GetCount() const
A container for handling SCH_SHEET_PATH objects in a flattened hierarchy.
void GetSymbols(SCH_REFERENCE_LIST &aReferences, bool aIncludePowerSymbols=true, bool aForceIncludeOrphanSymbols=false) const
Add a SCH_REFERENCE object to aReferences for each symbol in the list of sheets.
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
void GetContextualTextVars(wxArrayString *aVars) const
Return the list of system text vars & fields for this sheet.
Definition: sch_sheet.cpp:202
static const wxString GetDefaultFieldName(int aFieldNdx, bool aTranslated=true)
Definition: sch_sheet.cpp:55
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
Schematic symbol object.
Definition: sch_symbol.h:81
int GetUnitCount() const
Return the number of units per package of the symbol.
Definition: sch_symbol.cpp:473
wxString SubReference(int aUnit, bool aAddSeparator=true) const
Definition: sch_symbol.cpp:857
void SetValueFieldText(const wxString &aValue)
Definition: sch_symbol.cpp:918
const wxString GetRef(const SCH_SHEET_PATH *aSheet, bool aIncludeUnit=false) const
Return the reference for the given sheet path.
Definition: sch_symbol.cpp:738
SCH_FIELD * GetField(MANDATORY_FIELD_T aFieldType)
Return a mandatory field in this symbol.
Definition: sch_symbol.cpp:940
void SetRef(const SCH_SHEET_PATH *aSheet, const wxString &aReference)
Set the reference for the given sheet path for this symbol.
Definition: sch_symbol.cpp:780
void SetFootprintFieldText(const wxString &aFootprint)
Definition: sch_symbol.cpp:934
VECTOR2I GetPosition() const override
Definition: sch_symbol.h:700
bool ResolveTextVar(const SCH_SHEET_PATH *aPath, wxString *token, int aDepth=0) const
Resolve any references to system tokens supported by the symbol.
void GetContextualTextVars(wxArrayString *aVars) const
Return the list of system text vars & fields for this symbol.
TRANSFORM & GetTransform()
Definition: sch_symbol.h:285
int GetUnitSelection(const SCH_SHEET_PATH *aSheet) const
Return the instance-specific unit selection for the given sheet path.
Definition: sch_symbol.cpp:866
bool GetDNP() const
Definition: sch_symbol.h:745
Add cut/copy/paste, dark theme, autocomplete and brace highlighting to a wxStyleTextCtrl instance.
wxStyledTextCtrl * Scintilla() const
void DoAutocomplete(const wxString &aPartial, const wxArrayString &aTokens)
SIM_MODEL & CreateModel(SIM_MODEL::TYPE aType, const std::vector< LIB_PIN * > &aPins, REPORTER &aReporter)
virtual std::vector< std::string > GetPinNames() const
Definition: sim_model.h:474
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
for transforming drawing coordinates for a wxDC device context.
Definition: transform.h:46
int y1
Definition: transform.h:49
TRANSFORM InverseTransform() const
Calculate the Inverse mirror/rotation transform.
Definition: transform.cpp:59
VECTOR2I TransformCoordinate(const VECTOR2I &aPoint) const
Calculate a new coordinate according to the mirror/rotation transform.
Definition: transform.cpp:44
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
wxString GetTextVars(const wxString &aSource)
Returns any variables unexpanded, e.g.
Definition: common.cpp:115
The common library.
#define _HKI(x)
#define _(s)
static constexpr EDA_ANGLE & ANGLE_HORIZONTAL
Definition: eda_angle.h:433
static constexpr EDA_ANGLE & ANGLE_VERTICAL
Definition: eda_angle.h:434
static constexpr EDA_ANGLE & ANGLE_90
Definition: eda_angle.h:439
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
PROJECT & Prj()
Definition: kicad.cpp:576
@ LAYER_SHEETNAME
Definition: layer_ids.h:368
@ LAYER_HIDDEN
Definition: layer_ids.h:386
@ LAYER_VALUEPART
Definition: layer_ids.h:358
@ LAYER_FIELDS
Definition: layer_ids.h:359
@ LAYER_SHEETFIELDS
Definition: layer_ids.h:370
@ LAYER_REFERENCEPART
Definition: layer_ids.h:357
@ LAYER_NETCLASS_REFS
Definition: layer_ids.h:361
@ LAYER_SELECTION_SHADOWS
Definition: layer_ids.h:387
@ LAYER_INTERSHEET_REFS
Definition: layer_ids.h:360
@ LAYER_SHEETFILENAME
Definition: layer_ids.h:369
void MIRROR(T &aPoint, const T &aMirrorRef)
Updates aPoint with the mirror of aPoint relative to the aMirrorRef.
Definition: mirror.h:40
wxString EllipsizeMenuText(const wxString &aString)
Ellipsize text (at the end) to be no more than 36 characters.
Definition: ui_common.cpp:210
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:192
#define TYPE_HASH(x)
Definition: property.h:64
#define REGISTER_TYPE(x)
Definition: property_mgr.h:366
static struct SCH_FIELD_DESC _SCH_FIELD_DESC
@ SHEET_MANDATORY_FIELDS
The first 2 are mandatory, and must be instantiated in SCH_SHEET.
Definition: sch_sheet.h:49
@ SHEETNAME
Definition: sch_sheet.h:45
@ SHEETFILENAME
Definition: sch_sheet.h:46
wxString UnescapeString(const wxString &aSource)
static const wxString GetDefaultFieldName(int aFieldNdx, bool aTranslateForHI=false)
Return a default symbol field name for field aFieldNdx for all components.
Definition for symbol library class.
wxString GetCanonicalFieldName(int idx)
@ FOOTPRINT_FIELD
Field Name Module PCB, i.e. "16DIP300".
@ VALUE_FIELD
Field Value of part, i.e. "3.3K".
@ MANDATORY_FIELDS
The first 5 are mandatory, and must be instantiated in SCH_COMPONENT and LIB_PART constructors.
@ REFERENCE_FIELD
Field Reference of part, i.e. "IC21".
constexpr int delta
GR_TEXT_H_ALIGN_T
@ GR_TEXT_H_ALIGN_CENTER
@ GR_TEXT_H_ALIGN_RIGHT
@ GR_TEXT_H_ALIGN_LEFT
GR_TEXT_V_ALIGN_T
@ GR_TEXT_V_ALIGN_BOTTOM
@ GR_TEXT_V_ALIGN_CENTER
@ GR_TEXT_V_ALIGN_TOP
wxLogTrace helper definitions.
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
@ SCH_SYMBOL_T
Definition: typeinfo.h:156
@ SCH_FIELD_T
Definition: typeinfo.h:155
@ SCH_SHEET_T
Definition: typeinfo.h:158
@ SCH_GLOBAL_LABEL_T
Definition: typeinfo.h:152
VECTOR2< int > VECTOR2I
Definition: vector2d.h:588