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 The 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#include <wx/log.h>
26#include <wx/menu.h>
27
28#include <advanced_config.h>
29#include <base_units.h>
30#include <common.h> // for ExpandTextVars
31#include <sch_edit_frame.h>
32#include <plotters/plotter.h>
33#include <bitmaps.h>
34#include <kiway.h>
36#include <string_utils.h>
38#include <trace_helpers.h>
39#include <tool/tool_manager.h>
41#include <font/outline_font.h>
42#include "sim/sim_lib_mgr.h"
43
44static const std::vector<KICAD_T> labelTypes = { SCH_LABEL_LOCATE_ANY_T };
45
46
48 SCH_ITEM( nullptr, SCH_FIELD_T ),
49 EDA_TEXT( schIUScale, wxEmptyString ),
50 m_id( FIELD_T::USER ),
51 m_ordinal( 0 ),
52 m_showName( false ),
53 m_allowAutoPlace( true ),
54 m_isGeneratedField( false ),
55 m_autoAdded( false ),
56 m_showInChooser( true ),
57 m_renderCacheValid( false ),
59{
60}
61
62
63SCH_FIELD::SCH_FIELD( SCH_ITEM* aParent, FIELD_T aFieldId, const wxString& aName ) :
64 SCH_FIELD()
65{
66 m_parent = aParent;
67
68 if( !aName.IsEmpty() )
69 SetName( aName );
70 else
72
73 setId( aFieldId ); // will also set the layer
74 SetVisible( true );
75
76 if( aParent && aParent->Schematic() )
77 {
78 SCHEMATIC_SETTINGS& settings = aParent->Schematic()->Settings();
80 }
81
82 if( aFieldId == FIELD_T::USER && aParent )
83 {
84 if( aParent->Type() == SCH_SYMBOL_T )
85 m_ordinal = static_cast<SCH_SYMBOL*>( aParent )->GetNextFieldOrdinal();
86 else if( aParent->Type() == LIB_SYMBOL_T )
87 m_ordinal = static_cast<LIB_SYMBOL*>( aParent )->GetNextFieldOrdinal();
88 else if( aParent->Type() == SCH_SHEET_T )
89 m_ordinal = static_cast<SCH_SHEET*>( aParent )->GetNextFieldOrdinal();
90 else if( SCH_LABEL_BASE* label = dynamic_cast<SCH_LABEL_BASE*>( aParent ) )
91 m_ordinal = label->GetNextFieldOrdinal();
92 }
93}
94
95
97 SCH_FIELD( aParent, FIELD_T::USER, wxEmptyString )
98{
99 SCH_ITEM::operator=( *aText );
100 EDA_TEXT::operator=( *aText );
101}
102
103
105 SCH_ITEM( aField ),
106 EDA_TEXT( aField )
107{
108 m_private = aField.m_private;
109 setId( aField.m_id ); // will also set the layer
110 m_ordinal = aField.m_ordinal;
111 m_name = aField.m_name;
112 m_showName = aField.m_showName;
115 m_autoAdded = aField.m_autoAdded;
117
118 m_renderCache.clear();
119
120 for( const std::unique_ptr<KIFONT::GLYPH>& glyph : aField.m_renderCache )
121 {
122 if( KIFONT::OUTLINE_GLYPH* outline = dynamic_cast<KIFONT::OUTLINE_GLYPH*>( glyph.get() ) )
123 m_renderCache.emplace_back( std::make_unique<KIFONT::OUTLINE_GLYPH>( *outline ) );
124 else if( KIFONT::STROKE_GLYPH* stroke = dynamic_cast<KIFONT::STROKE_GLYPH*>( glyph.get() ) )
125 m_renderCache.emplace_back( std::make_unique<KIFONT::STROKE_GLYPH>( *stroke ) );
126 }
127
130
132}
133
134
136{
137 EDA_TEXT::operator=( aField );
138
139 m_private = aField.m_private;
140 setId( aField.m_id ); // will also set the layer
141 m_ordinal = aField.m_ordinal;
142 m_name = aField.m_name;
143 m_showName = aField.m_showName;
146
147 m_renderCache.clear();
148
149 for( const std::unique_ptr<KIFONT::GLYPH>& glyph : aField.m_renderCache )
150 {
151 if( KIFONT::OUTLINE_GLYPH* outline = dynamic_cast<KIFONT::OUTLINE_GLYPH*>( glyph.get() ) )
152 m_renderCache.emplace_back( std::make_unique<KIFONT::OUTLINE_GLYPH>( *outline ) );
153 else if( KIFONT::STROKE_GLYPH* stroke = dynamic_cast<KIFONT::STROKE_GLYPH*>( glyph.get() ) )
154 m_renderCache.emplace_back( std::make_unique<KIFONT::STROKE_GLYPH>( *stroke ) );
155 }
156
159
161
162 return *this;
163}
164
165
167{
168 return new SCH_FIELD( *this );
169}
170
171
172void SCH_FIELD::Copy( SCH_FIELD* aTarget ) const
173{
174 *aTarget = *this;
175}
176
177
179{
180 m_id = aId;
182}
183
184
189
190
191wxString SCH_FIELD::GetShownText( const SCH_SHEET_PATH* aPath, bool aAllowExtraText, int aDepth ) const
192{
193 // Use local depth counter so each text element starts fresh
194 int depth = 0;
195
196 std::function<bool( wxString* )> libSymbolResolver = [&]( wxString* token ) -> bool
197 {
198 LIB_SYMBOL* symbol = static_cast<LIB_SYMBOL*>( m_parent );
199 return symbol->ResolveTextVar( token, depth + 1 );
200 };
201
202 std::function<bool( wxString* )> symbolResolver = [&]( wxString* token ) -> bool
203 {
204 SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( m_parent );
205 return symbol->ResolveTextVar( aPath, token, depth + 1 );
206 };
207
208 std::function<bool( wxString* )> schematicResolver = [&]( wxString* token ) -> bool
209 {
210 if( !aPath )
211 return false;
212
213 if( SCHEMATIC* schematic = Schematic() )
214 return schematic->ResolveTextVar( aPath, token, depth + 1 );
215
216 return false;
217 };
218
219 std::function<bool( wxString* )> sheetResolver = [&]( wxString* token ) -> bool
220 {
221 if( !aPath )
222 return false;
223
224 SCH_SHEET* sheet = static_cast<SCH_SHEET*>( m_parent );
225
226 SCHEMATIC* schematic = Schematic();
227 SCH_SHEET_PATH path = *aPath;
228 path.push_back( sheet );
229
230 bool retval = sheet->ResolveTextVar( &path, token, depth + 1 );
231
232 if( schematic )
233 retval |= schematic->ResolveTextVar( &path, token, depth + 1 );
234
235 return retval;
236 };
237
238 std::function<bool( wxString* )> labelResolver = [&]( wxString* token ) -> bool
239 {
240 if( !aPath )
241 return false;
242
243 SCH_LABEL_BASE* label = static_cast<SCH_LABEL_BASE*>( m_parent );
244 return label->ResolveTextVar( aPath, token, depth + 1 );
245 };
246
247 wxString variantName;
248
249 if( SCHEMATIC* schematic = Schematic() )
250 variantName = schematic->GetCurrentVariant();
251
252 wxString text = getUnescapedText( aPath, variantName );
253
254 if( IsNameShown() && aAllowExtraText )
255 text = GetShownName() << wxS( ": " ) << text;
256
257 if( HasTextVars() )
258 {
259 // Create a unified resolver that delegates to the appropriate resolver based on parent type
260 std::function<bool( wxString* )> fieldResolver = [&]( wxString* token ) -> bool
261 {
262 bool resolved = false;
263
264 if( m_parent && m_parent->Type() == LIB_SYMBOL_T )
265 resolved = libSymbolResolver( token );
266 else if( m_parent && m_parent->Type() == SCH_SYMBOL_T )
267 resolved = symbolResolver( token );
268 else if( m_parent && m_parent->Type() == SCH_SHEET_T )
269 resolved = sheetResolver( token );
270 else if( m_parent && m_parent->IsType( labelTypes ) )
271 resolved = labelResolver( token );
272 else if( Schematic() )
273 {
274 // Project-level and schematic-level variables
275 resolved = Schematic()->Project().TextVarResolver( token );
276 resolved |= schematicResolver( token );
277 }
278
279 return resolved;
280 };
281
282 text = ResolveTextVars( text, &fieldResolver, depth );
283 }
284
285 if( m_id == FIELD_T::SHEET_FILENAME && aAllowExtraText && !IsNameShown() )
286 text = _( "File:" ) + wxS( " " ) + text;
287
288 // Convert escape markers back to literals for final display
289 text.Replace( wxT( "<<<ESC_DOLLAR:" ), wxT( "${" ) );
290 text.Replace( wxT( "<<<ESC_AT:" ), wxT( "@{" ) );
291
292 return text;
293}
294
295
296wxString SCH_FIELD::GetShownText( bool aAllowExtraText, int aDepth ) const
297{
298 if( SCHEMATIC* schematic = Schematic() )
299 {
300 const SCH_SHEET_PATH& currentSheet = schematic->CurrentSheet();
301 wxLogTrace( traceSchFieldRendering,
302 "GetShownText (no path arg): field=%s, current sheet path='%s', size=%zu, empty=%d", GetName(),
303 currentSheet.Path().AsString(), currentSheet.size(), currentSheet.empty() ? 1 : 0 );
304 return GetShownText( &currentSheet, aAllowExtraText, aDepth );
305 }
306 else
307 return GetShownText( nullptr, aAllowExtraText, aDepth );
308}
309
310
311wxString SCH_FIELD::GetFullText( int unit ) const
312{
313 if( GetId() != FIELD_T::REFERENCE )
314 return GetText();
315
316 wxString text = GetText();
317 text << wxT( "?" );
318
319 if( GetParentSymbol() && GetParentSymbol()->IsMultiUnit() )
320 text << LIB_SYMBOL::LetterSubReference( unit, 'A' );
321
322 return text;
323}
324
325
327{
329}
330
331
333{
335
336 if( !font )
337 font = KIFONT::FONT::GetFont( GetDefaultFont( aSettings ), IsBold(), IsItalic() );
338
339 return font;
340}
341
342
348
349
355
356
357std::vector<std::unique_ptr<KIFONT::GLYPH>>*
358SCH_FIELD::GetRenderCache( const wxString& forResolvedText, const VECTOR2I& forPosition, TEXT_ATTRIBUTES& aAttrs ) const
359{
360 KIFONT::FONT* font = GetDrawFont( nullptr );
361
362 if( font->IsOutline() )
363 {
364 KIFONT::OUTLINE_FONT* outlineFont = static_cast<KIFONT::OUTLINE_FONT*>( font );
365
366 if( m_renderCache.empty() || !m_renderCacheValid )
367 {
368 m_renderCache.clear();
369
370 outlineFont->GetLinesAsGlyphs( &m_renderCache, forResolvedText, forPosition, aAttrs, GetFontMetrics() );
371
372 m_renderCachePos = forPosition;
373 m_renderCacheValid = true;
374 }
375
376 if( m_renderCachePos != forPosition )
377 {
378 VECTOR2I delta = forPosition - m_renderCachePos;
379
380 for( std::unique_ptr<KIFONT::GLYPH>& glyph : m_renderCache )
381 {
382 if( glyph->IsOutline() )
383 static_cast<KIFONT::OUTLINE_GLYPH*>( glyph.get() )->Move( delta );
384 else
385 static_cast<KIFONT::STROKE_GLYPH*>( glyph.get() )->Move( delta );
386 }
387
388 m_renderCachePos = forPosition;
389 }
390
391 return &m_renderCache;
392 }
393
394 return nullptr;
395}
396
397
398void SCH_FIELD::ImportValues( const SCH_FIELD& aSource )
399{
400 SetAttributes( aSource );
401 SetVisible( aSource.IsVisible() );
402 SetNameShown( aSource.IsNameShown() );
403 SetCanAutoplace( aSource.CanAutoplace() );
404}
405
406
408{
409 wxCHECK_RET( aItem && aItem->Type() == SCH_FIELD_T, wxT( "Cannot swap with invalid item." ) );
410
411 SCH_FIELD* item = static_cast<SCH_FIELD*>( aItem );
412
413 std::swap( m_showName, item->m_showName );
414 std::swap( m_allowAutoPlace, item->m_allowAutoPlace );
415 std::swap( m_isGeneratedField, item->m_isGeneratedField );
416 SwapText( *item );
417 SwapAttributes( *item );
418
419 std::swap( m_lastResolvedColor, item->m_lastResolvedColor );
420}
421
422
424{
426 {
428 }
429 else
430 {
431 SCH_LABEL_BASE* parentLabel = dynamic_cast<SCH_LABEL_BASE*>( GetParent() );
432
433 if( parentLabel && !parentLabel->IsConnectivityDirty() )
435 else
437 }
438
439 return m_lastResolvedColor;
440}
441
442
443std::vector<int> SCH_FIELD::ViewGetLayers() const
444{
446}
447
448
450{
451 if( m_parent && m_parent->Type() == SCH_LABEL_T )
452 {
453 if( GetCanonicalName() == wxT( "Netclass" ) || GetCanonicalName() == wxT( "Component Class" ) )
454 {
455 return LAYER_NETCLASS_REFS;
456 }
457 }
458
459 switch( m_id )
460 {
462 case FIELD_T::VALUE: return LAYER_VALUEPART;
467 default: return LAYER_FIELDS;
468 }
469}
470
471
473{
474 // Calculate the text orientation according to the symbol orientation.
475 EDA_ANGLE orient = GetTextAngle();
476
477 if( m_parent && m_parent->Type() == SCH_SYMBOL_T )
478 {
479 SCH_SYMBOL* parentSymbol = static_cast<SCH_SYMBOL*>( m_parent );
480
481 if( parentSymbol && parentSymbol->GetTransform().y1 ) // Rotate symbol 90 degrees.
482 {
483 if( orient.IsHorizontal() )
484 orient = ANGLE_VERTICAL;
485 else
486 orient = ANGLE_HORIZONTAL;
487 }
488 }
489
490 return orient;
491}
492
493
495{
496 BOX2I bbox = GetTextBox( nullptr );
497
498 // Calculate the bounding box position relative to the parent:
499 VECTOR2I origin = GetParentPosition();
500 VECTOR2I pos = GetTextPos() - origin;
501 VECTOR2I begin = bbox.GetOrigin() - origin;
502 VECTOR2I end = bbox.GetEnd() - origin;
503 RotatePoint( begin, pos, GetTextAngle() );
504 RotatePoint( end, pos, GetTextAngle() );
505
506 // Now, apply the symbol transform (mirror/rot)
507 TRANSFORM transform;
508
509 if( m_parent && m_parent->Type() == SCH_SYMBOL_T )
510 transform = static_cast<SCH_SYMBOL*>( m_parent )->GetTransform();
511
512 bbox.SetOrigin( transform.TransformCoordinate( begin ) );
513 bbox.SetEnd( transform.TransformCoordinate( end ) );
514
515 bbox.Move( origin );
516 bbox.Normalize();
517
518 return bbox;
519}
520
521
523{
524 VECTOR2I render_center = GetBoundingBox().Centre();
525 VECTOR2I pos = GetPosition();
526
527 switch( GetHorizJustify() )
528 {
530 if( GetDrawRotation().IsVertical() )
531 return render_center.y > pos.y;
532 else
533 return render_center.x < pos.x;
535 if( GetDrawRotation().IsVertical() )
536 return render_center.y < pos.y;
537 else
538 return render_center.x > pos.x;
539 default: return false;
540 }
541}
542
543
545{
546 GR_TEXT_H_ALIGN_T actualJustify;
547
548 switch( aJustify )
549 {
552 break;
555 break;
556 default: actualJustify = aJustify;
557 }
558
559 SetHorizJustify( actualJustify );
560}
561
562
572
573
575{
576 VECTOR2I render_center = GetBoundingBox().Centre();
577 VECTOR2I pos = GetPosition();
578
579 switch( GetVertJustify() )
580 {
582 if( GetDrawRotation().IsVertical() )
583 return render_center.x < pos.x;
584 else
585 return render_center.y < pos.y;
587 if( GetDrawRotation().IsVertical() )
588 return render_center.x > pos.x;
589 else
590 return render_center.y > pos.y;
591 default: return false;
592 }
593}
594
595
597{
598 GR_TEXT_V_ALIGN_T actualJustify;
599
600 switch( aJustify )
601 {
604 break;
607 break;
608 default: actualJustify = aJustify;
609 }
610
611 SetVertJustify( actualJustify );
612}
613
614
624
625
626bool SCH_FIELD::Matches( const EDA_SEARCH_DATA& aSearchData, void* aAuxData ) const
627{
628 bool searchHiddenFields = aSearchData.searchAllFields;
629 bool searchAndReplace = aSearchData.searchAndReplace;
630 bool replaceReferences = false;
631
632 try
633 {
634 // downcast
635 const SCH_SEARCH_DATA& schSearchData = dynamic_cast<const SCH_SEARCH_DATA&>( aSearchData );
636 replaceReferences = schSearchData.replaceReferences;
637 }
638 catch( const std::bad_cast& )
639 {
640 }
641
642 wxString text = UnescapeString( GetText() );
643
644 if( !IsVisible() && !searchHiddenFields )
645 return false;
646
647 if( m_id == FIELD_T::REFERENCE )
648 {
649 if( searchAndReplace && !replaceReferences )
650 return false;
651
652 SCH_SYMBOL* parentSymbol = dyn_cast<SCH_SYMBOL*>( m_parent );
653
654 // The parent might be a LIB_SYMBOL, in which case, we don't
655 // have a sheet path to resolve the reference.
656 if( !parentSymbol )
657 return false;
658
659 if( parentSymbol->Matches( aSearchData, aAuxData ) )
660 return true;
661
662 wxASSERT( aAuxData );
663
664 // Take sheet path into account which effects the reference field and the unit for
665 // symbols with multiple parts.
666 if( aAuxData )
667 {
668 SCH_SHEET_PATH* sheet = (SCH_SHEET_PATH*) aAuxData;
669 text = parentSymbol->GetRef( sheet );
670
671 if( SCH_ITEM::Matches( text, aSearchData ) )
672 return true;
673
674 if( parentSymbol->GetUnitCount() > 1 )
675 text << parentSymbol->SubReference( parentSymbol->GetUnitSelection( sheet ) );
676 }
677 }
678
679 return SCH_ITEM::Matches( text, aSearchData );
680}
681
682
683void SCH_FIELD::OnScintillaCharAdded( SCINTILLA_TRICKS* aScintillaTricks, wxStyledTextEvent& aEvent ) const
684{
685 SCH_ITEM* parent = dynamic_cast<SCH_ITEM*>( GetParent() );
686 SCHEMATIC* schematic = parent ? parent->Schematic() : nullptr;
687
688 if( !schematic )
689 return;
690
691 wxStyledTextCtrl* scintilla = aScintillaTricks->Scintilla();
692 int key = aEvent.GetKey();
693
694 wxArrayString autocompleteTokens;
695 int pos = scintilla->GetCurrentPos();
696 int start = scintilla->WordStartPosition( pos, true );
697 wxString partial;
698
699 // Multi-line fields are not allowed. So remove '\n' if entered.
700 if( key == '\n' )
701 {
702 wxString text = scintilla->GetText();
703 int currpos = scintilla->GetCurrentPos();
704 text.Replace( wxS( "\n" ), wxS( "" ) );
705 scintilla->SetText( text );
706 scintilla->GotoPos( currpos - 1 );
707 return;
708 }
709
710 auto textVarRef = [&]( int pt )
711 {
712 return pt >= 2 && scintilla->GetCharAt( pt - 2 ) == '$' && scintilla->GetCharAt( pt - 1 ) == '{';
713 };
714
715 // Check for cross-reference
716 if( start > 1 && scintilla->GetCharAt( start - 1 ) == ':' )
717 {
718 int refStart = scintilla->WordStartPosition( start - 1, true );
719
720 if( textVarRef( refStart ) )
721 {
722 partial = scintilla->GetRange( start, pos );
723
724 wxString ref = scintilla->GetRange( refStart, start - 1 );
725
726 if( ref == wxS( "OP" ) )
727 {
728 // SPICE operating points use ':' syntax for ports
729 if( SCH_SYMBOL* symbol = dynamic_cast<SCH_SYMBOL*>( parent ) )
730 {
731 NULL_REPORTER devnull;
732 SCH_SHEET_PATH& sheet = schematic->CurrentSheet();
733 SIM_LIB_MGR mgr( &schematic->Project() );
734
735 std::vector<EMBEDDED_FILES*> embeddedFilesStack;
736 embeddedFilesStack.push_back( schematic->GetEmbeddedFiles() );
737
738 if( EMBEDDED_FILES* symbolEmbeddedFiles = symbol->GetEmbeddedFiles() )
739 {
740 embeddedFilesStack.push_back( symbolEmbeddedFiles );
741 symbol->GetLibSymbolRef()->AppendParentEmbeddedFiles( embeddedFilesStack );
742 }
743
744 mgr.SetFilesStack( std::move( embeddedFilesStack ) );
745
746 SIM_MODEL& model = mgr.CreateModel( &sheet, *symbol, true, 0, devnull ).model;
747
748 for( wxString pin : model.GetPinNames() )
749 {
750 if( pin.StartsWith( '<' ) && pin.EndsWith( '>' ) )
751 autocompleteTokens.push_back( pin.Mid( 1, pin.Length() - 2 ) );
752 else
753 autocompleteTokens.push_back( pin );
754 }
755
756 // add the synthetic port for power measurements
757 autocompleteTokens.push_back( wxT( "power" ) );
758 }
759 }
760 else
761 {
763 SCH_SYMBOL* refSymbol = nullptr;
764
765 schematic->Hierarchy().GetSymbols( refs );
766
767 for( size_t jj = 0; jj < refs.GetCount(); jj++ )
768 {
769 if( refs[jj].GetSymbol()->GetRef( &refs[jj].GetSheetPath(), true ) == ref )
770 {
771 refSymbol = refs[jj].GetSymbol();
772 break;
773 }
774 }
775
776 if( refSymbol )
777 refSymbol->GetContextualTextVars( &autocompleteTokens );
778 }
779 }
780 }
781 else if( textVarRef( start ) )
782 {
783 partial = scintilla->GetTextRange( start, pos );
784
785 SCH_SYMBOL* symbol = dynamic_cast<SCH_SYMBOL*>( parent );
786 SCH_SHEET* sheet = dynamic_cast<SCH_SHEET*>( parent );
787 SCH_LABEL_BASE* label = dynamic_cast<SCH_LABEL_BASE*>( parent );
788
789 if( symbol )
790 {
791 symbol->GetContextualTextVars( &autocompleteTokens );
792
793 if( schematic->CurrentSheet().Last() )
794 schematic->CurrentSheet().Last()->GetContextualTextVars( &autocompleteTokens );
795 }
796
797 if( sheet )
798 sheet->GetContextualTextVars( &autocompleteTokens );
799
800 if( label )
801 label->GetContextualTextVars( &autocompleteTokens );
802
803 for( std::pair<wxString, wxString> entry : schematic->Project().GetTextVars() )
804 autocompleteTokens.push_back( entry.first );
805 }
806
807 aScintillaTricks->DoAutocomplete( partial, autocompleteTokens );
808 scintilla->SetFocus();
809}
810
811
813{
814 // See comments in SCH_FIELD::Replace(), below.
816 return false;
817
818 return true;
819}
820
821
822bool SCH_FIELD::Replace( const EDA_SEARCH_DATA& aSearchData, void* aAuxData )
823{
824 bool replaceReferences = false;
825
826 try
827 {
828 const SCH_SEARCH_DATA& schSearchData = dynamic_cast<const SCH_SEARCH_DATA&>( aSearchData );
829 replaceReferences = schSearchData.replaceReferences;
830 }
831 catch( const std::bad_cast& )
832 {
833 }
834
835 wxString text;
836 bool isReplaced = false;
837
838 if( m_id == FIELD_T::REFERENCE && m_parent && m_parent->Type() == SCH_SYMBOL_T )
839 {
840 SCH_SYMBOL* parentSymbol = static_cast<SCH_SYMBOL*>( m_parent );
841
842 if( !replaceReferences )
843 return false;
844
845 wxCHECK_MSG( aAuxData, false, wxT( "Need sheetpath to replace in refdes." ) );
846
847 text = parentSymbol->GetRef( (SCH_SHEET_PATH*) aAuxData );
848 isReplaced = EDA_ITEM::Replace( aSearchData, text );
849
850 if( isReplaced )
851 parentSymbol->SetRef( (SCH_SHEET_PATH*) aAuxData, text );
852 }
853 else
854 {
855 isReplaced = EDA_TEXT::Replace( aSearchData );
856
857 if( m_id == FIELD_T::SHEET_FILENAME && isReplaced )
858 {
859 // If we allowed this we'd have a bunch of work to do here, including warning
860 // about it not being undoable, checking for recursive hierarchies, reloading
861 // sheets, etc. See DIALOG_SHEET_PROPERTIES::TransferDataFromWindow().
862 }
863 }
864
865 return isReplaced;
866}
867
868
869void SCH_FIELD::Rotate( const VECTOR2I& aCenter, bool aRotateCCW )
870{
872
873 if( GetTextAngle().IsVertical() )
874 {
875 switch( horizJustify )
876 {
878 if( aRotateCCW )
880
881 break;
882
884 if( aRotateCCW )
886
887 break;
888
891 }
892
894 }
895 else if( GetTextAngle().IsHorizontal() )
896 {
897 switch( horizJustify )
898 {
900 if( !aRotateCCW )
902
903 break;
904
906 if( !aRotateCCW )
908
909 break;
910
913 }
914
916 }
917 else
918 {
919 wxFAIL_MSG( wxString::Format( wxT( "SCH_FIELD text angle is not horizontal or vertical: %f" ),
920 GetTextAngle().AsDegrees() ) );
921 }
922
923 VECTOR2I pt = GetPosition();
924 RotatePoint( pt, aCenter, aRotateCCW ? ANGLE_90 : ANGLE_270 );
925 SetPosition( pt );
926}
927
928
930{
931 int x = GetTextPos().x;
932
933 x -= aCenter;
934 x *= -1;
935 x += aCenter;
936
937 SetTextX( x );
938}
939
940
942{
943 int y = GetTextPos().y;
944
945 y -= aCenter;
946 y *= -1;
947 y += aCenter;
948
949 SetTextY( y );
950}
951
952
953void SCH_FIELD::BeginEdit( const VECTOR2I& aPosition )
954{
955 SetTextPos( aPosition );
956}
957
958
959void SCH_FIELD::CalcEdit( const VECTOR2I& aPosition )
960{
961 SetTextPos( aPosition );
962}
963
964
965wxString SCH_FIELD::GetItemDescription( UNITS_PROVIDER* aUnitsProvider, bool aFull ) const
966{
967 wxString content = aFull ? GetShownText( false ) : KIUI::EllipsizeMenuText( GetText() );
968
969 if( content.IsEmpty() )
970 {
971 return wxString::Format( _( "Field %s (empty)" ), UnescapeString( GetName() ) );
972 }
973 else
974 {
975 return wxString::Format( _( "Field %s '%s'" ), UnescapeString( GetName() ), content );
976 }
977}
978
979
980void SCH_FIELD::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList )
981{
982 wxString msg;
983
984 aList.emplace_back( _( "Symbol Field" ), UnescapeString( GetName() ) );
985
986 // Don't use GetShownText() here; we want to show the user the variable references
987 aList.emplace_back( _( "Text" ), KIUI::EllipsizeStatusText( aFrame, GetText() ) );
988
989 aList.emplace_back( _( "Visible" ), IsVisible() ? _( "Yes" ) : _( "No" ) );
990
991 aList.emplace_back( _( "Font" ), GetFont() ? GetFont()->GetName() : _( "Default" ) );
992
993 aList.emplace_back( _( "Style" ), GetTextStyleName() );
994
995 aList.emplace_back( _( "Text Size" ), aFrame->MessageTextFromValue( GetTextWidth() ) );
996
997 switch( GetHorizJustify() )
998 {
999 case GR_TEXT_H_ALIGN_LEFT: msg = _( "Left" ); break;
1000 case GR_TEXT_H_ALIGN_CENTER: msg = _( "Center" ); break;
1001 case GR_TEXT_H_ALIGN_RIGHT: msg = _( "Right" ); break;
1003 }
1004
1005 aList.emplace_back( _( "H Justification" ), msg );
1006
1007 switch( GetVertJustify() )
1008 {
1009 case GR_TEXT_V_ALIGN_TOP: msg = _( "Top" ); break;
1010 case GR_TEXT_V_ALIGN_CENTER: msg = _( "Center" ); break;
1011 case GR_TEXT_V_ALIGN_BOTTOM: msg = _( "Bottom" ); break;
1013 }
1014
1015 aList.emplace_back( _( "V Justification" ), msg );
1016}
1017
1018
1020{
1022 return true;
1023
1025 return true;
1026
1027 return IsURL( GetShownText( false ) );
1028}
1029
1030
1032{
1033 constexpr int START_ID = 1;
1034
1035 if( IsHypertext() )
1036 {
1037 wxString href;
1038
1040 {
1041 SCH_LABEL_BASE* label = static_cast<SCH_LABEL_BASE*>( m_parent );
1042 SCH_SHEET_PATH* sheet = &label->Schematic()->CurrentSheet();
1043 wxMenu menu;
1044
1045 std::vector<std::pair<wxString, wxString>> pages;
1046
1047 label->GetIntersheetRefs( sheet, &pages );
1048
1049 for( int i = 0; i < (int) pages.size(); ++i )
1050 {
1051 menu.Append( i + START_ID,
1052 wxString::Format( _( "Go to Page %s (%s)" ), pages[i].first, pages[i].second ) );
1053 }
1054
1055 menu.AppendSeparator();
1056 menu.Append( 999 + START_ID, _( "Back to Previous Selected Sheet" ) );
1057
1058 int sel = aFrame->GetPopupMenuSelectionFromUser( menu ) - START_ID;
1059
1060 if( sel >= 0 && sel < (int) pages.size() )
1061 href = wxT( "#" ) + pages[sel].first;
1062 else if( sel == 999 )
1064 }
1065 else if( IsURL( GetShownText( false ) ) || m_name == SIM_LIBRARY::LIBRARY_FIELD )
1066 {
1067 href = GetShownText( false );
1068 }
1069
1070 if( !href.IsEmpty() )
1071 {
1073 navTool->HypertextCommand( href );
1074 }
1075 }
1076}
1077
1078
1079void SCH_FIELD::SetName( const wxString& aName )
1080{
1081 m_name = aName;
1083
1084 if( m_isGeneratedField )
1085 EDA_TEXT::SetText( aName );
1086}
1087
1088
1089void SCH_FIELD::SetText( const wxString& aText )
1090{
1091 // Don't allow modification of text value of generated fields.
1092 if( m_isGeneratedField )
1093 return;
1094
1095 // Mandatory fields should not have leading or trailing whitespace.
1096 if( IsMandatory() )
1097 EDA_TEXT::SetText( aText.Strip( wxString::both ) );
1098 else
1099 EDA_TEXT::SetText( aText );
1100}
1101
1102
1103wxString SCH_FIELD::GetName( bool aUseDefaultName ) const
1104{
1105 if( m_parent && m_parent->IsType( labelTypes ) )
1106 return SCH_LABEL_BASE::GetDefaultFieldName( m_name, aUseDefaultName );
1107
1108 if( IsMandatory() )
1109 return GetCanonicalFieldName( m_id );
1110 else if( m_name.IsEmpty() && aUseDefaultName )
1112 else
1113 return m_name;
1114}
1115
1116
1118{
1119 if( m_parent && m_parent->IsType( labelTypes ) )
1120 {
1121 // These should be stored in canonical format, but just in case:
1122 if( m_name == _( "Net Class" ) || m_name == wxT( "Net Class" ) )
1123 return wxT( "Netclass" );
1124 }
1125
1126 if( IsMandatory() )
1127 return GetCanonicalFieldName( m_id );
1128
1129 return m_name;
1130}
1131
1132
1134{
1135 if( m_parent && ( m_parent->Type() == SCH_SYMBOL_T || m_parent->Type() == LIB_SYMBOL_T ) )
1136 {
1137 switch( m_id )
1138 {
1142 default: return BITMAPS::text;
1143 }
1144 }
1145
1146 return BITMAPS::text;
1147}
1148
1149
1150bool SCH_FIELD::HitTest( const VECTOR2I& aPosition, int aAccuracy ) const
1151{
1152 if( GetShownText( true ).IsEmpty() )
1153 return false;
1154
1155 BOX2I rect = GetBoundingBox();
1156
1157 // Text in symbol editor can have additional chars (ie: reference designators U? or U?A)
1158 if( m_parent && m_parent->Type() == LIB_SYMBOL_T )
1159 {
1160 SCH_FIELD temp( *this );
1161 temp.SetText( GetFullText() );
1162 rect = temp.GetBoundingBox();
1163 }
1164
1165 rect.Inflate( aAccuracy );
1166
1167 if( m_parent && m_parent->Type() == SCH_GLOBAL_LABEL_T )
1168 {
1169 SCH_GLOBALLABEL* label = static_cast<SCH_GLOBALLABEL*>( GetParent() );
1170 rect.Offset( label->GetSchematicTextOffset( nullptr ) );
1171 }
1172
1173 return rect.Contains( aPosition );
1174}
1175
1176
1177bool SCH_FIELD::HitTest( const BOX2I& aRect, bool aContained, int aAccuracy ) const
1178{
1179 if( GetShownText( true ).IsEmpty() )
1180 return false;
1181
1182 if( m_flags & ( STRUCT_DELETED | SKIP_STRUCT ) )
1183 return false;
1184
1185 BOX2I rect = aRect;
1186
1187 rect.Inflate( aAccuracy );
1188
1189 if( GetParent() && GetParent()->Type() == SCH_GLOBAL_LABEL_T )
1190 {
1191 SCH_GLOBALLABEL* label = static_cast<SCH_GLOBALLABEL*>( GetParent() );
1192 rect.Offset( label->GetSchematicTextOffset( nullptr ) );
1193 }
1194
1195 if( aContained )
1196 return rect.Contains( GetBoundingBox() );
1197
1198 return rect.Intersects( GetBoundingBox() );
1199}
1200
1201
1202bool SCH_FIELD::HitTest( const SHAPE_LINE_CHAIN& aPoly, bool aContained ) const
1203{
1204 if( GetShownText( true ).IsEmpty() )
1205 return false;
1206
1207 if( m_flags & ( STRUCT_DELETED | SKIP_STRUCT ) )
1208 return false;
1209
1210 BOX2I bbox = GetBoundingBox();
1211
1212 if( GetParent() && GetParent()->Type() == SCH_GLOBAL_LABEL_T )
1213 {
1214 SCH_GLOBALLABEL* label = static_cast<SCH_GLOBALLABEL*>( GetParent() );
1215 bbox.Offset( label->GetSchematicTextOffset( nullptr ) );
1216 }
1217
1218 return KIGEOM::BoxHitTest( aPoly, bbox, aContained );
1219}
1220
1221
1222void SCH_FIELD::Plot( PLOTTER* aPlotter, bool aBackground, const SCH_PLOT_OPTS& aPlotOpts, int aUnit, int aBodyStyle,
1223 const VECTOR2I& aOffset, bool aDimmed )
1224{
1225 wxString text;
1226
1227 if( Schematic() )
1228 text = GetShownText( &Schematic()->CurrentSheet(), true );
1229 else
1230 text = GetShownText( true );
1231
1232 if( ( !IsVisible() && !IsForceVisible() ) || text.IsEmpty() || aBackground )
1233 return;
1234
1235 SCH_RENDER_SETTINGS* renderSettings = getRenderSettings( aPlotter );
1236 COLOR4D color = renderSettings->GetLayerColor( GetLayer() );
1237 int penWidth = GetEffectiveTextPenWidth( renderSettings->GetDefaultPenWidth() );
1238
1239 COLOR4D bg = renderSettings->GetBackgroundColor();
1240 ;
1241
1242 if( bg == COLOR4D::UNSPECIFIED || !aPlotter->GetColorMode() )
1243 bg = COLOR4D::WHITE;
1244
1245 if( aPlotter->GetColorMode() && GetTextColor() != COLOR4D::UNSPECIFIED )
1246 color = GetTextColor();
1247
1248 if( aDimmed )
1249 {
1250 color.Desaturate();
1251 color = color.Mix( bg, 0.5f );
1252 }
1253
1254 penWidth = std::max( penWidth, renderSettings->GetMinPenWidth() );
1255
1256 // clamp the pen width to be sure the text is readable
1257 penWidth = std::min( penWidth, std::min( GetTextSize().x, GetTextSize().y ) / 4 );
1258
1259 if( !IsVisible() && !renderSettings->m_ShowHiddenFields )
1260 return;
1261
1262 // Calculate the text orientation, according to the symbol orientation/mirror
1263 EDA_ANGLE orient = GetTextAngle();
1264 VECTOR2I textpos = GetTextPos();
1266 GR_TEXT_V_ALIGN_T vjustify = GetVertJustify();
1267
1268 if( renderSettings->m_Transform.y1 ) // Rotate symbol 90 deg.
1269 {
1270 if( orient.IsHorizontal() )
1271 orient = ANGLE_VERTICAL;
1272 else
1273 orient = ANGLE_HORIZONTAL;
1274 }
1275
1276 if( m_parent && m_parent->Type() == SCH_SYMBOL_T )
1277 {
1278 /*
1279 * Calculate the text justification, according to the symbol orientation/mirror. This is
1280 * a bit complicated due to cumulative calculations:
1281 * - numerous cases (mirrored or not, rotation)
1282 * - the plotter's Text() function will also recalculate H and V justifications according
1283 * to the text orientation
1284 * - when a symbol is mirrored the text is not, and justifications become a nightmare
1285 *
1286 * So the easier way is to use no justifications (centered text) and use GetBoundingBox
1287 * to know the text coordinate considered as centered.
1288 */
1289 hjustify = GR_TEXT_H_ALIGN_CENTER;
1290 vjustify = GR_TEXT_V_ALIGN_CENTER;
1291 textpos = GetBoundingBox().Centre();
1292 }
1293 else if( m_parent && m_parent->Type() == SCH_GLOBAL_LABEL_T )
1294 {
1295 SCH_GLOBALLABEL* label = static_cast<SCH_GLOBALLABEL*>( m_parent );
1296 textpos += label->GetSchematicTextOffset( renderSettings );
1297 }
1298 else if( m_parent && m_parent->Type() == SCH_DIRECTIVE_LABEL_T )
1299 {
1300 SCH_DIRECTIVE_LABEL* label = static_cast<SCH_DIRECTIVE_LABEL*>( m_parent );
1301 std::shared_ptr<NETCLASS> nc = label->GetEffectiveNetClass();
1302
1303 if( nc && ( nc->GetSchematicColor() != COLOR4D::UNSPECIFIED ) && aPlotter->GetColorMode() )
1304 color = nc->GetSchematicColor();
1305 }
1306
1307 KIFONT::FONT* font = GetDrawFont( renderSettings );
1309 attrs.m_StrokeWidth = penWidth;
1310 attrs.m_Halign = hjustify;
1311 attrs.m_Valign = vjustify;
1312 attrs.m_Angle = orient;
1313 attrs.m_Multiline = false;
1314
1315 aPlotter->PlotText( textpos, color, text, attrs, font, GetFontMetrics() );
1316
1318 {
1319 if( SCH_LABEL_BASE* label = dynamic_cast<SCH_LABEL_BASE*>( m_parent ) )
1320 {
1321 std::vector<std::pair<wxString, wxString>> pages;
1322 std::vector<wxString> pageHrefs;
1323
1324 label->GetIntersheetRefs( &Schematic()->CurrentSheet(), &pages );
1325
1326 for( const auto& [pageNumber, sheetName] : pages )
1327 pageHrefs.push_back( wxT( "#" ) + pageNumber );
1328
1329 BOX2I bbox = GetBoundingBox();
1330 bbox.Offset( label->GetSchematicTextOffset( renderSettings ) );
1331
1332 aPlotter->HyperlinkMenu( bbox, pageHrefs );
1333 }
1334 }
1335}
1336
1337
1338void SCH_FIELD::SetPosition( const VECTOR2I& aPosition )
1339{
1340 // Actual positions are calculated by the rotation/mirror transform of the parent symbol
1341 // of the field. The inverse transform is used to calculate the position relative to the
1342 // parent symbol.
1343 if( m_parent && m_parent->Type() == SCH_SYMBOL_T )
1344 {
1345 SCH_SYMBOL* parentSymbol = static_cast<SCH_SYMBOL*>( m_parent );
1346 VECTOR2I relPos = aPosition - parentSymbol->GetPosition();
1347
1348 relPos = parentSymbol->GetTransform().InverseTransform().TransformCoordinate( relPos );
1349
1350 SetTextPos( relPos + parentSymbol->GetPosition() );
1351 return;
1352 }
1353
1354 SetTextPos( aPosition );
1355}
1356
1357
1359{
1360 if( m_parent && m_parent->Type() == SCH_SYMBOL_T )
1361 {
1362 SCH_SYMBOL* parentSymbol = static_cast<SCH_SYMBOL*>( m_parent );
1363 VECTOR2I relativePos = GetTextPos() - parentSymbol->GetPosition();
1364
1365 relativePos = parentSymbol->GetTransform().TransformCoordinate( relativePos );
1366
1367 return relativePos + parentSymbol->GetPosition();
1368 }
1369
1370 return GetTextPos();
1371}
1372
1373
1375{
1376 return m_parent ? m_parent->GetPosition() : VECTOR2I( 0, 0 );
1377}
1378
1379
1386
1387
1388bool SCH_FIELD::operator<( const SCH_ITEM& aItem ) const
1389{
1390 if( Type() != aItem.Type() )
1391 return Type() < aItem.Type();
1392
1393 auto field = static_cast<const SCH_FIELD*>( &aItem );
1394
1395 if( GetId() != field->GetId() )
1396 return GetId() < field->GetId();
1397
1398 if( GetText() != field->GetText() )
1399 return GetText() < field->GetText();
1400
1401 if( GetLibPosition().x != field->GetLibPosition().x )
1402 return GetLibPosition().x < field->GetLibPosition().x;
1403
1404 if( GetLibPosition().y != field->GetLibPosition().y )
1405 return GetLibPosition().y < field->GetLibPosition().y;
1406
1407 return GetName() < field->GetName();
1408}
1409
1410
1411bool SCH_FIELD::operator==( const SCH_ITEM& aOther ) const
1412{
1413 if( Type() != aOther.Type() )
1414 return false;
1415
1416 const SCH_FIELD& field = static_cast<const SCH_FIELD&>( aOther );
1417
1418 return *this == field;
1419}
1420
1421
1422bool SCH_FIELD::operator==( const SCH_FIELD& aOther ) const
1423{
1424 // Identical fields of different symbols are not equal.
1425 if( !GetParentSymbol() || !aOther.GetParentSymbol()
1426 || GetParentSymbol()->m_Uuid != aOther.GetParentSymbol()->m_Uuid )
1427 {
1428 return false;
1429 }
1430
1431 if( IsMandatory() != aOther.IsMandatory() )
1432 return false;
1433
1434 if( IsMandatory() )
1435 {
1436 if( GetId() != aOther.GetId() )
1437 return false;
1438 }
1439 else
1440 {
1441 if( GetOrdinal() != aOther.GetOrdinal() )
1442 return false;
1443 }
1444
1445 if( GetPosition() != aOther.GetPosition() )
1446 return false;
1447
1448 if( IsGeneratedField() != aOther.IsGeneratedField() )
1449 return false;
1450
1451 if( IsNameShown() != aOther.IsNameShown() )
1452 return false;
1453
1454 if( CanAutoplace() != aOther.CanAutoplace() )
1455 return false;
1456
1457 return EDA_TEXT::operator==( aOther );
1458}
1459
1460
1461double SCH_FIELD::Similarity( const SCH_ITEM& aOther ) const
1462{
1463 if( Type() != aOther.Type() )
1464 return 0.0;
1465
1466 if( m_Uuid == aOther.m_Uuid )
1467 return 1.0;
1468
1469 const SCH_FIELD& field = static_cast<const SCH_FIELD&>( aOther );
1470
1471 double similarity = 0.99; // The UUIDs are different, so we start with non-identity
1472
1473 if( GetId() != field.GetId() )
1474 {
1475 // We don't allow swapping of mandatory fields, so these cannot be the same item
1476 if( IsMandatory() || field.IsMandatory() )
1477 return 0.0;
1478 else
1479 similarity *= 0.5;
1480 }
1481
1482 similarity *= SimilarityBase( aOther );
1483
1484 similarity *= EDA_TEXT::Similarity( field );
1485
1486 if( GetPosition() != field.GetPosition() )
1487 similarity *= 0.5;
1488
1489 if( IsGeneratedField() != field.IsGeneratedField() )
1490 similarity *= 0.5;
1491
1492 if( IsNameShown() != field.IsNameShown() )
1493 similarity *= 0.5;
1494
1495 if( CanAutoplace() != field.CanAutoplace() )
1496 similarity *= 0.5;
1497
1498 return similarity;
1499}
1500
1501
1502int SCH_FIELD::compare( const SCH_ITEM& aOther, int aCompareFlags ) const
1503{
1504 wxASSERT( aOther.Type() == SCH_FIELD_T );
1505
1506 int compareFlags = aCompareFlags;
1507
1508 // For ERC tests, the field position has no matter, so do not test it
1509 if( aCompareFlags & SCH_ITEM::COMPARE_FLAGS::ERC )
1511
1512 int retv = SCH_ITEM::compare( aOther, compareFlags );
1513
1514 if( retv )
1515 return retv;
1516
1517 const SCH_FIELD* tmp = static_cast<const SCH_FIELD*>( &aOther );
1518
1519 // Equality test will vary depending whether or not the field is mandatory. Otherwise,
1520 // sorting is done by ordinal.
1521 if( aCompareFlags & SCH_ITEM::COMPARE_FLAGS::EQUALITY )
1522 {
1523 // Mandatory fields have fixed ordinals and their names can vary due to translated field
1524 // names. Optional fields have fixed names and their ordinals can vary.
1525 if( IsMandatory() )
1526 {
1527 if( m_id != tmp->m_id )
1528 return (int) m_id - (int) tmp->m_id;
1529 }
1530 else
1531 {
1532 retv = m_name.Cmp( tmp->m_name );
1533
1534 if( retv )
1535 return retv;
1536 }
1537 }
1538 else // assume we're sorting
1539 {
1540 if( m_id != tmp->m_id )
1541 return (int) m_id - (int) tmp->m_id;
1542 }
1543
1544 bool ignoreFieldText = false;
1545
1546 if( m_id == FIELD_T::REFERENCE && !( aCompareFlags & SCH_ITEM::COMPARE_FLAGS::EQUALITY ) )
1547 ignoreFieldText = true;
1548
1549 if( m_id == FIELD_T::VALUE && ( aCompareFlags & SCH_ITEM::COMPARE_FLAGS::ERC ) )
1550 ignoreFieldText = true;
1551
1552 if( !ignoreFieldText )
1553 {
1554 retv = GetText().CmpNoCase( tmp->GetText() );
1555
1556 if( retv != 0 )
1557 return retv;
1558 }
1559
1560 if( aCompareFlags & SCH_ITEM::COMPARE_FLAGS::EQUALITY )
1561 {
1562 if( GetTextPos().x != tmp->GetTextPos().x )
1563 return GetTextPos().x - tmp->GetTextPos().x;
1564
1565 if( GetTextPos().y != tmp->GetTextPos().y )
1566 return GetTextPos().y - tmp->GetTextPos().y;
1567 }
1568
1569 // For ERC tests, the field size has no matter, so do not test it
1570 if( !( aCompareFlags & SCH_ITEM::COMPARE_FLAGS::ERC ) )
1571 {
1572 if( GetTextWidth() != tmp->GetTextWidth() )
1573 return GetTextWidth() - tmp->GetTextWidth();
1574
1575 if( GetTextHeight() != tmp->GetTextHeight() )
1576 return GetTextHeight() - tmp->GetTextHeight();
1577 }
1578
1579 return 0;
1580}
1581
1582
1583wxString SCH_FIELD::getUnescapedText( const SCH_SHEET_PATH* aPath, const wxString& aVariantName ) const
1584{
1585 // This is the default variant field text for all fields except the reference field.
1586 wxString retv = EDA_TEXT::GetShownText( false );
1587
1588 wxLogTrace( traceSchFieldRendering,
1589 "getUnescapedText: field=%s, parent=%p, aPath=%p, path_empty=%d, initial_text='%s'", GetName(),
1590 m_parent, aPath, aPath ? ( aPath->empty() ? 1 : 0 ) : -1, retv );
1591
1592 // Special handling for parent object field instance and variant information.
1593 // Only use the path if it's non-empty; an empty path can't match any instances
1594 if( m_parent && aPath && !aPath->empty() )
1595 {
1596 wxLogTrace( traceSchFieldRendering, " Path is valid and non-empty, parent type=%d", m_parent->Type() );
1597
1598 switch( m_parent->Type() )
1599 {
1600 case SCH_SYMBOL_T:
1601 {
1602 if( const SCH_SYMBOL* symbol = static_cast<const SCH_SYMBOL*>( m_parent ) )
1603 {
1604 if( m_id == FIELD_T::REFERENCE )
1605 {
1606 wxLogTrace( traceSchFieldRendering, " Calling GetRef for symbol %s on path %s",
1607 symbol->m_Uuid.AsString(), aPath->Path().AsString() );
1608
1609 retv = symbol->GetRef( aPath, true );
1610
1611 wxLogTrace( traceSchFieldRendering, " GetRef returned: '%s'", retv );
1612 }
1613 else if( !aVariantName.IsEmpty() )
1614 {
1615 // If the variant is not found, fall back to default variant above.
1616 if( std::optional<SCH_SYMBOL_VARIANT> variant = symbol->GetVariant( *aPath, aVariantName ) )
1617 {
1618 // If the field name does not exist in the variant, fall back to the default variant above.
1619 if( variant->m_Fields.contains( GetName() ) )
1620 retv = variant->m_Fields[GetName()];
1621 }
1622 }
1623 }
1624
1625 break;
1626 }
1627
1628 case SCH_SHEET_T: break;
1629
1630 default: break;
1631 }
1632 }
1633
1634 return retv;
1635}
1636
1637
1638static struct SCH_FIELD_DESC
1639{
1641 {
1642 // These are defined in EDA_TEXT as well but initialization order is
1643 // not defined, so this needs to be conditional. Defining in both
1644 // places leads to duplicate symbols.
1646
1647 if( h_inst.Choices().GetCount() == 0 )
1648 {
1649 h_inst.Map( GR_TEXT_H_ALIGN_LEFT, _HKI( "Left" ) );
1650 h_inst.Map( GR_TEXT_H_ALIGN_CENTER, _HKI( "Center" ) );
1651 h_inst.Map( GR_TEXT_H_ALIGN_RIGHT, _HKI( "Right" ) );
1652 }
1653
1655
1656 if( v_inst.Choices().GetCount() == 0 )
1657 {
1658 v_inst.Map( GR_TEXT_V_ALIGN_TOP, _HKI( "Top" ) );
1659 v_inst.Map( GR_TEXT_V_ALIGN_CENTER, _HKI( "Center" ) );
1660 v_inst.Map( GR_TEXT_V_ALIGN_BOTTOM, _HKI( "Bottom" ) );
1661 }
1662
1669
1670 const wxString textProps = _HKI( "Text Properties" );
1671
1672 auto horiz = new PROPERTY_ENUM<SCH_FIELD, GR_TEXT_H_ALIGN_T>( _HKI( "Horizontal Justification" ),
1675
1676 propMgr.ReplaceProperty( TYPE_HASH( EDA_TEXT ), _HKI( "Horizontal Justification" ), horiz, textProps );
1677
1678 auto vert = new PROPERTY_ENUM<SCH_FIELD, GR_TEXT_V_ALIGN_T>( _HKI( "Vertical Justification" ),
1681
1682 propMgr.ReplaceProperty( TYPE_HASH( EDA_TEXT ), _HKI( "Vertical Justification" ), vert, textProps );
1683
1684 propMgr.AddProperty( new PROPERTY<SCH_FIELD, bool>( _HKI( "Show Field Name" ), &SCH_FIELD::SetNameShown,
1686
1687 propMgr.AddProperty( new PROPERTY<SCH_FIELD, bool>( _HKI( "Allow Autoplacement" ), &SCH_FIELD::SetCanAutoplace,
1689
1690 propMgr.Mask( TYPE_HASH( SCH_FIELD ), TYPE_HASH( EDA_TEXT ), _HKI( "Hyperlink" ) );
1691 propMgr.Mask( TYPE_HASH( SCH_FIELD ), TYPE_HASH( EDA_TEXT ), _HKI( "Thickness" ) );
1692 propMgr.Mask( TYPE_HASH( SCH_FIELD ), TYPE_HASH( EDA_TEXT ), _HKI( "Mirrored" ) );
1693 propMgr.Mask( TYPE_HASH( SCH_FIELD ), TYPE_HASH( EDA_TEXT ), _HKI( "Width" ) );
1694 propMgr.Mask( TYPE_HASH( SCH_FIELD ), TYPE_HASH( EDA_TEXT ), _HKI( "Height" ) );
1695
1696
1699 _HKI( "Text Properties" ) );
1700
1701 propMgr.Mask( TYPE_HASH( SCH_FIELD ), TYPE_HASH( EDA_TEXT ), _HKI( "Orientation" ) );
1702
1703 auto isNotGeneratedField = []( INSPECTABLE* aItem ) -> bool
1704 {
1705 if( SCH_FIELD* field = dynamic_cast<SCH_FIELD*>( aItem ) )
1706 return !field->IsGeneratedField();
1707
1708 return true;
1709 };
1710
1712 isNotGeneratedField );
1713
1714
1715 auto isNonMandatoryField = []( INSPECTABLE* aItem ) -> bool
1716 {
1717 if( SCH_FIELD* field = dynamic_cast<SCH_FIELD*>( aItem ) )
1718 return !field->IsMandatory();
1719
1720 return false;
1721 };
1722
1723 propMgr.OverrideAvailability( TYPE_HASH( SCH_FIELD ), TYPE_HASH( SCH_ITEM ), _HKI( "Private" ),
1724 isNonMandatoryField );
1725 }
1727
1728
constexpr EDA_IU_SCALE schIUScale
Definition base_units.h:114
BITMAPS
A list of all bitmap identifiers.
@ edit_comp_value
@ edit_comp_footprint
BOX2< VECTOR2I > BOX2I
Definition box2.h:922
constexpr BOX2< Vec > & Inflate(coord_type dx, coord_type dy)
Inflates the rectangle horizontally by dx and vertically by dy.
Definition box2.h:558
constexpr const Vec GetEnd() const
Definition box2.h:212
constexpr void SetOrigin(const Vec &pos)
Definition box2.h:237
constexpr BOX2< Vec > & Normalize()
Ensure that the height and width are positive.
Definition box2.h:146
constexpr Vec Centre() const
Definition box2.h:97
constexpr bool Contains(const Vec &aPoint) const
Definition box2.h:168
constexpr void Move(const Vec &aMoveVector)
Move the rectangle by the aMoveVector.
Definition box2.h:138
constexpr const Vec & GetOrigin() const
Definition box2.h:210
constexpr void SetEnd(coord_type x, coord_type y)
Definition box2.h:297
constexpr void Offset(coord_type dx, coord_type dy)
Definition box2.h:259
constexpr bool Intersects(const BOX2< Vec > &aRect) const
Definition box2.h:311
static const COLOR4D WHITE
Definition color4d.h:402
static const COLOR4D UNSPECIFIED
For legacy support; used as a value to indicate color hasn't been set yet.
Definition color4d.h:399
bool IsHorizontal() const
Definition eda_angle.h:142
The base class for create windows for drawing purpose.
const KIID m_Uuid
Definition eda_item.h:516
KICAD_T Type() const
Returns the type of object.
Definition eda_item.h:110
EDA_ITEM_FLAGS m_flags
Definition eda_item.h:527
virtual bool Matches(const EDA_SEARCH_DATA &aSearchData, void *aAuxData) const
Compare the item against the search criteria in aSearchData.
Definition eda_item.h:401
EDA_ITEM * GetParent() const
Definition eda_item.h:112
EDA_ITEM * m_parent
Owner.
Definition eda_item.h:528
bool IsForceVisible() const
Definition eda_item.h:211
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:236
EDA_ITEM(EDA_ITEM *parent, KICAD_T idType, bool isSCH_ITEM=false, bool isBOARD_ITEM=false)
Definition eda_item.cpp:39
A mix-in class (via multiple inheritance) that handles texts such as labels, parts,...
Definition eda_text.h:80
int GetTextHeight() const
Definition eda_text.h:267
const VECTOR2I & GetTextPos() const
Definition eda_text.h:273
COLOR4D GetTextColor() const
Definition eda_text.h:270
wxString GetTextStyleName() const
Definition eda_text.cpp:965
bool IsItalic() const
Definition eda_text.h:169
const EDA_ANGLE & GetTextAngle() const
Definition eda_text.h:147
void SetTextSize(VECTOR2I aNewSize, bool aEnforceMinTextSize=true)
Definition eda_text.cpp:540
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition eda_text.h:98
virtual bool IsVisible() const
Definition eda_text.h:187
void SetTextPos(const VECTOR2I &aPoint)
Definition eda_text.cpp:584
void SetTextX(int aX)
Definition eda_text.cpp:590
KIFONT::FONT * GetFont() const
Definition eda_text.h:247
void SetAttributes(const EDA_TEXT &aSrc, bool aSetPosition=true)
Set the text attributes from another instance.
Definition eda_text.cpp:441
void SetTextY(int aY)
Definition eda_text.cpp:596
EDA_TEXT & operator=(const EDA_TEXT &aItem)
Definition eda_text.cpp:159
int GetTextWidth() const
Definition eda_text.h:264
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:745
void SetVertJustify(GR_TEXT_V_ALIGN_T aType)
Definition eda_text.cpp:425
GR_TEXT_H_ALIGN_T GetHorizJustify() const
Definition eda_text.h:200
bool Replace(const EDA_SEARCH_DATA &aSearchData)
Helper function used in search and replace dialog.
Definition eda_text.cpp:494
bool HasTextVars() const
Indicates the ShownText has text var references which need to be processed.
Definition eda_text.h:117
virtual void SetVisible(bool aVisible)
Definition eda_text.cpp:394
EDA_TEXT(const EDA_IU_SCALE &aIuScale, const wxString &aText=wxEmptyString)
Definition eda_text.cpp:97
virtual void ClearBoundingBoxCache()
Definition eda_text.cpp:683
double Similarity(const EDA_TEXT &aOther) const
virtual void ClearRenderCache()
Definition eda_text.cpp:677
const TEXT_ATTRIBUTES & GetAttributes() const
Definition eda_text.h:231
int GetEffectiveTextPenWidth(int aDefaultPenWidth=0) const
The EffectiveTextPenWidth uses the text thickness if > 1 or aDefaultPenWidth.
Definition eda_text.cpp:473
void SwapAttributes(EDA_TEXT &aTradingPartner)
Swap the text attributes of the two involved instances.
Definition eda_text.cpp:460
bool IsBold() const
Definition eda_text.h:184
GR_TEXT_V_ALIGN_T GetVertJustify() const
Definition eda_text.h:203
virtual wxString GetShownText(bool aAllowExtraText, int aDepth=0) const
Return the string actually shown after processing of the base text.
Definition eda_text.h:109
virtual void SetText(const wxString &aText)
Definition eda_text.cpp:278
virtual void SetTextAngle(const EDA_ANGLE &aAngle)
Definition eda_text.cpp:307
void SwapText(EDA_TEXT &aTradingPartner)
Definition eda_text.cpp:453
bool operator==(const EDA_TEXT &aRhs) const
Definition eda_text.h:396
VECTOR2I GetTextSize() const
Definition eda_text.h:261
void SetHorizJustify(GR_TEXT_H_ALIGN_T aType)
Definition eda_text.cpp:417
static ENUM_MAP< T > & Instance()
Definition property.h:721
Class that other classes need to inherit from, in order to be inspectable.
Definition inspectable.h:37
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, const std::vector< wxString > *aEmbeddedFiles=nullptr, bool aForDrawingSheet=false)
Definition font.cpp:147
virtual bool IsOutline() const
Definition font.h:139
Class OUTLINE_FONT implements outline font drawing.
void GetLinesAsGlyphs(std::vector< std::unique_ptr< GLYPH > > *aGlyphs, const wxString &aText, const VECTOR2I &aPosition, const TEXT_ATTRIBUTES &aAttrs, const METRICS &aFontMetrics) const
void Move(const VECTOR2I &aOffset)
Definition glyph.cpp:114
A color representation with 4 components: red, green, blue, alpha.
Definition color4d.h:105
COLOR4D & Desaturate()
Removes color (in HSL model)
Definition color4d.cpp:511
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.
wxString AsString() const
Definition kiid.cpp:356
bool ResolveTextVar(wxString *token, int aDepth=0) const
Resolve any references to system tokens supported by the symbol.
static wxString LetterSubReference(int aUnit, wxChar aInitialLetter)
COLOR4D GetSchematicColor(bool aIsForSave=false) const
Definition netclass.h:219
A singleton reporter that reports to nowhere.
Definition reporter.h:216
Base plotter engine class.
Definition plotter.h:136
bool GetColorMode() const
Definition plotter.h:164
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
virtual void HyperlinkMenu(const BOX2I &aBox, const std::vector< wxString > &aDestURLs)
Create a clickable hyperlink menu with a rectangular click area.
Definition plotter.h:517
virtual bool TextVarResolver(wxString *aToken) const
Definition project.cpp:84
virtual std::map< wxString, wxString > & GetTextVars() const
Definition project.cpp:116
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 OverrideAvailability(TYPE_ID aDerived, TYPE_ID aBase, const wxString &aName, std::function< bool(INSPECTABLE *)> aFunc)
Sets an override availability functor for a base class property of a given derived class.
PROPERTY_BASE & ReplaceProperty(size_t aBase, const wxString &aName, PROPERTY_BASE *aNew, const wxString &aGroup=wxEmptyString)
Replace an existing property for a specific type.
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.
These are loaded from Eeschema settings but then overwritten by the project settings.
Holds all the data relating to one schematic.
Definition schematic.h:88
SCHEMATIC_SETTINGS & Settings() const
SCH_SHEET_LIST Hierarchy() const
Return the full schematic flattened hierarchical sheet list.
PROJECT & Project() const
Return a reference to the project this schematic is part of.
Definition schematic.h:103
EMBEDDED_FILES * GetEmbeddedFiles() override
bool ResolveTextVar(const SCH_SHEET_PATH *aSheetPath, wxString *token, int aDepth) const
SCH_SHEET_PATH & CurrentSheet() const
Definition schematic.h:186
void ClearRenderCache() override
int compare(const SCH_ITEM &aOther, int aCompareFlags=0) const override
Provide the draw object specific comparison called by the == and < operators.
COLOR4D m_lastResolvedColor
Definition sch_field.h:347
GR_TEXT_V_ALIGN_T GetEffectiveVertJustify() const
bool IsMandatory() const
wxString GetItemDescription(UNITS_PROVIDER *aUnitsProvider, bool aFull) const override
Return a user-visible description string of this item.
void Rotate(const VECTOR2I &aCenter, bool aRotateCCW) override
Rotate the item around aCenter 90 degrees in the clockwise direction.
wxString GetFullText(int unit=1) const
Return the text of a field.
const BOX2I GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
std::vector< std::unique_ptr< KIFONT::GLYPH > > m_renderCache
Definition sch_field.h:345
void swapData(SCH_ITEM *aItem) override
Swap the internal data structures aItem with the schematic item.
VECTOR2I GetPosition() const override
void SetEffectiveHorizJustify(GR_TEXT_H_ALIGN_T)
int GetSchTextSize() const
Definition sch_field.h:162
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 ...
bool m_showName
Render the field name in addition to its value.
Definition sch_field.h:335
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.
EDA_ITEM * Clone() const override
Create a duplicate of this item with linked list members set to NULL.
BITMAPS GetMenuImage() const override
Return a pointer to an image to be used in menus.
bool IsNameShown() const
Definition sch_field.h:201
bool IsHypertext() const override
Allow items to support hypertext actions when hovered/clicked.
bool m_autoAdded
Was this field automatically added to a LIB_SYMBOL?
Definition sch_field.h:340
double Similarity(const SCH_ITEM &aItem) const override
Return a measure of how likely the other object is to represent the same object.
bool IsGeneratedField() const
Generated fields are fields whose names are variables like ${VAR}.
Definition sch_field.h:210
bool HitTest(const VECTOR2I &aPosition, int aAccuracy=0) const override
Test if aPosition is inside or on the boundary of this item.
SCH_LAYER_ID GetDefaultLayer() const
bool IsHorizJustifyFlipped() const
Return whether the field will be rendered with the horizontal justification inverted due to rotation ...
bool IsVertJustifyFlipped() const
EDA_ANGLE GetDrawRotation() const override
Adjusters to allow EDA_TEXT to draw/print/etc.
void SetEffectiveVertJustify(GR_TEXT_V_ALIGN_T)
void CalcEdit(const VECTOR2I &aPosition) override
Calculate the attributes of an item at aPosition when it is being edited.
bool Matches(const EDA_SEARCH_DATA &aSearchData, void *aAuxData) const override
Compare the item against the search criteria in aSearchData.
void MirrorVertically(int aCenter) override
Mirror item vertically about aCenter.
FIELD_T GetId() const
Definition sch_field.h:116
void SetCanAutoplace(bool aCanPlace)
Definition sch_field.h:213
void DoHypertextAction(EDA_DRAW_FRAME *aFrame) const override
int GetPenWidth() const override
wxString GetCanonicalName() const
Get a non-language-specific name for a field which can be used for storage, variable look-up,...
bool m_isGeneratedField
If the field name is a variable name (e.g.
Definition sch_field.h:337
int m_ordinal
Sort order for non-mandatory fields.
Definition sch_field.h:332
COLOR4D GetFieldColor() const
wxString getUnescapedText(const SCH_SHEET_PATH *aPath=nullptr, const wxString &aVariantName=wxEmptyString) const
bool operator==(const SCH_ITEM &aItem) const override
SCH_FIELD & operator=(const SCH_FIELD &aField)
void ImportValues(const SCH_FIELD &aSource)
Copy parameters from a SCH_FIELD source.
bool operator<(const SCH_ITEM &aItem) const override
FIELD_T m_id
Field id,.
Definition sch_field.h:331
wxString GetShownName() const
Get the field's name as displayed on the schematic or in the symbol fields table.
VECTOR2I GetLibPosition() const
Definition sch_field.h:259
void setId(FIELD_T aId)
int GetOrdinal() const
Definition sch_field.h:118
bool IsEmpty()
Return true if both the name and value of the field are empty.
Definition sch_field.h:154
bool m_renderCacheValid
Definition sch_field.h:343
KIFONT::FONT * GetDrawFont(const RENDER_SETTINGS *aSettings) const override
void BeginEdit(const VECTOR2I &aStartPoint) override
Begin drawing a symbol library draw item at aPosition.
bool IsReplaceable() const override
Override this method in any derived object that supports test find and replace.
void SetSchTextSize(int aSize)
Definition sch_field.h:163
GR_TEXT_H_ALIGN_T GetEffectiveHorizJustify() const
std::vector< int > ViewGetLayers() const override
Return the all the layers within the VIEW the object is painted on.
wxString GetName(bool aUseDefaultName=true) const
Return the field name (not translated).
void SetPosition(const VECTOR2I &aPosition) override
void SetName(const wxString &aName)
wxString GetShownText(const SCH_SHEET_PATH *aPath, bool aAllowExtraText, int aDepth=0) const
VECTOR2I m_renderCachePos
Definition sch_field.h:344
bool CanAutoplace() const
Definition sch_field.h:212
std::vector< std::unique_ptr< KIFONT::GLYPH > > * GetRenderCache(const wxString &forResolvedText, const VECTOR2I &forPosition, TEXT_ATTRIBUTES &aAttrs) const
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 ClearCaches() override
void SetText(const wxString &aText) override
VECTOR2I GetParentPosition() const
bool m_showInChooser
This field is available as a data column for the chooser.
Definition sch_field.h:341
void OnScintillaCharAdded(SCINTILLA_TRICKS *aScintillaTricks, wxStyledTextEvent &aEvent) const
wxString m_name
Definition sch_field.h:333
void SetNameShown(bool aShown=true)
Definition sch_field.h:202
void MirrorHorizontally(int aCenter) override
Mirror item horizontally about aCenter.
void Copy(SCH_FIELD *aTarget) const
Copy parameters of this field to another field.
bool m_allowAutoPlace
This field can be autoplaced.
Definition sch_field.h:336
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...
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition sch_item.h:167
SCH_ITEM & operator=(const SCH_ITEM &aPin)
Definition sch_item.cpp:75
SCH_RENDER_SETTINGS * getRenderSettings(PLOTTER *aPlotter) const
Definition sch_item.h:702
const SYMBOL * GetParentSymbol() const
Definition sch_item.cpp:250
SCHEMATIC * Schematic() const
Search the item hierarchy to find a SCHEMATIC.
Definition sch_item.cpp:244
friend class LIB_SYMBOL
Definition sch_item.h:773
@ SKIP_TST_POS
Definition sch_item.h:685
std::shared_ptr< NETCLASS > GetEffectiveNetClass(const SCH_SHEET_PATH *aSheet=nullptr) const
Definition sch_item.cpp:388
void SetLayer(SCH_LAYER_ID aLayer)
Definition sch_item.h:322
SCH_LAYER_ID GetLayer() const
Return the layer this item is on.
Definition sch_item.h:321
virtual int compare(const SCH_ITEM &aOther, int aCompareFlags=0) const
Provide the draw object specific comparison called by the == and < operators.
Definition sch_item.cpp:577
const wxString & GetDefaultFont(const RENDER_SETTINGS *aSettings) const
Definition sch_item.cpp:625
bool IsConnectivityDirty() const
Definition sch_item.h:568
SCH_ITEM(EDA_ITEM *aParent, KICAD_T aType, int aUnit=0, int aBodyStyle=0)
Definition sch_item.cpp:51
bool m_private
Definition sch_item.h:756
const KIFONT::METRICS & GetFontMetrics() const
Definition sch_item.cpp:638
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:360
void GetIntersheetRefs(const SCH_SHEET_PATH *aPath, std::vector< std::pair< wxString, wxString > > *pages)
Build an array of { pageNumber, pageName } pairs.
virtual bool ResolveTextVar(const SCH_SHEET_PATH *aPath, wxString *token, int aDepth) const
Resolve any references to system tokens supported by the label.
static const wxString GetDefaultFieldName(const wxString &aName, bool aUseDefaultName)
void GetContextualTextVars(wxArrayString *aVars) const
Return the list of system text vars & fields for this label.
Handle actions specific to the schematic editor.
static wxString g_BackLink
void HypertextCommand(const wxString &aHref)
Container to create a flattened list of symbols because in a complex hierarchy, a symbol can be used ...
const KIGFX::COLOR4D & GetBackgroundColor() const override
Return current background color settings.
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...
bool empty() const
Forwarded method from std::vector.
KIID_PATH Path() const
Get the sheet path as an KIID_PATH.
SCH_SHEET * Last() const
Return a pointer to the last SCH_SHEET of the list.
size_t size() const
Forwarded method from std::vector.
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition sch_sheet.h:47
void GetContextualTextVars(wxArrayString *aVars) const
Return the list of system text vars & fields for this sheet.
bool ResolveTextVar(const SCH_SHEET_PATH *aPath, wxString *token, int aDepth=0) const
Resolve any references to system tokens supported by the sheet.
Schematic symbol object.
Definition sch_symbol.h:76
wxString SubReference(int aUnit, bool aAddSeparator=true) const
bool Matches(const EDA_SEARCH_DATA &aSearchData, void *aAuxData) const override
Compare the item against the search criteria in aSearchData.
void SetRef(const SCH_SHEET_PATH *aSheet, const wxString &aReference)
Set the reference for the given sheet path for this symbol.
VECTOR2I GetPosition() const override
Definition sch_symbol.h:811
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.
int GetUnitSelection(const SCH_SHEET_PATH *aSheet) const
Return the instance-specific unit selection for the given sheet path.
int GetUnitCount() const override
Return the number of units per package of the symbol.
const wxString GetRef(const SCH_SHEET_PATH *aSheet, bool aIncludeUnit=false) const override
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)
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
void Move(const VECTOR2I &aVector) override
static constexpr auto LIBRARY_FIELD
Definition sim_library.h:35
SIM_MODEL & CreateModel(SIM_MODEL::TYPE aType, const std::vector< SCH_PIN * > &aPins, REPORTER &aReporter)
void SetFilesStack(std::vector< EMBEDDED_FILES * > aFilesStack)
Definition sim_lib_mgr.h:48
const TRANSFORM & GetTransform() const
Definition symbol.h:220
GR_TEXT_H_ALIGN_T m_Halign
GR_TEXT_V_ALIGN_T m_Valign
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
for transforming drawing coordinates for a wxDC device context.
Definition transform.h:46
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 GetGeneratedFieldDisplayName(const wxString &aSource)
Returns any variables unexpanded, e.g.
Definition common.cpp:274
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:247
The common library.
#define _(s)
static constexpr EDA_ANGLE ANGLE_90
Definition eda_angle.h:413
static constexpr EDA_ANGLE ANGLE_VERTICAL
Definition eda_angle.h:408
static constexpr EDA_ANGLE ANGLE_HORIZONTAL
Definition eda_angle.h:407
static constexpr EDA_ANGLE ANGLE_270
Definition eda_angle.h:416
#define STRUCT_DELETED
flag indication structures to be erased
#define SKIP_STRUCT
flag indicating that the structure should be ignored
a few functions useful in geometry calculations.
const wxChar *const traceSchFieldRendering
Flag to enable debug output of schematic field rendering and positioning.
@ USER
The main config directory (e.g. ~/.config/kicad/)
SCH_LAYER_ID
Eeschema drawing layers.
Definition layer_ids.h:449
@ LAYER_SHEETNAME
Definition layer_ids.h:472
@ LAYER_VALUEPART
Definition layer_ids.h:461
@ LAYER_FIELDS
Definition layer_ids.h:462
@ LAYER_SHEETFIELDS
Definition layer_ids.h:474
@ LAYER_REFERENCEPART
Definition layer_ids.h:460
@ LAYER_NETCLASS_REFS
Definition layer_ids.h:464
@ LAYER_SELECTION_SHADOWS
Definition layer_ids.h:495
@ LAYER_INTERSHEET_REFS
Definition layer_ids.h:463
@ LAYER_SHEETFILENAME
Definition layer_ids.h:473
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.
#define _HKI(x)
Definition page_info.cpp:44
static GR_TEXT_H_ALIGN_T horizJustify(const char *horizontal)
#define TYPE_HASH(x)
Definition property.h:74
#define DECLARE_ENUM_TO_WXANY(type)
Definition property.h:787
@ PT_SIZE
Size expressed in distance units (mm/inch)
Definition property.h:63
#define REGISTER_TYPE(x)
static const std::vector< KICAD_T > labelTypes
Definition sch_field.cpp:44
static struct SCH_FIELD_DESC _SCH_FIELD_DESC
wxString UnescapeString(const wxString &aSource)
bool IsURL(wxString aStr)
Performs a URL sniff-test on a string.
wxString GetDefaultFieldName(FIELD_T aFieldId, bool aTranslateForHI)
Return a default symbol field name for a mandatory field type.
#define DO_TRANSLATE
FIELD_T
The set of all field indices assuming an array like sequence that a SCH_COMPONENT or LIB_PART can hol...
@ USER
The field ID hasn't been set yet; field is invalid.
@ INTERSHEET_REFS
Global label cross-reference page numbers.
@ DESCRIPTION
Field Description of part, i.e. "1/4W 1% Metal Film Resistor".
@ FOOTPRINT
Field Name Module PCB, i.e. "16DIP300".
@ DATASHEET
name of datasheet
@ REFERENCE
Field Reference of part, i.e. "IC21".
@ VALUE
Field Value of part, i.e. "3.3K".
wxString GetCanonicalFieldName(FIELD_T aFieldType)
std::string path
KIBIS_MODEL * model
KIBIS_PIN * pin
VECTOR2I end
int delta
GR_TEXT_H_ALIGN_T
This is API surface mapped to common.types.HorizontalAlignment.
@ GR_TEXT_H_ALIGN_CENTER
@ GR_TEXT_H_ALIGN_RIGHT
@ GR_TEXT_H_ALIGN_LEFT
@ GR_TEXT_H_ALIGN_INDETERMINATE
GR_TEXT_V_ALIGN_T
This is API surface mapped to common.types.VertialAlignment.
@ GR_TEXT_V_ALIGN_BOTTOM
@ GR_TEXT_V_ALIGN_INDETERMINATE
@ 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:229
@ LIB_SYMBOL_T
Definition typeinfo.h:152
@ SCH_SYMBOL_T
Definition typeinfo.h:176
@ SCH_FIELD_T
Definition typeinfo.h:154
@ SCH_DIRECTIVE_LABEL_T
Definition typeinfo.h:175
@ SCH_LABEL_T
Definition typeinfo.h:171
@ SCH_SHEET_T
Definition typeinfo.h:179
@ SCH_LABEL_LOCATE_ANY_T
Definition typeinfo.h:195
@ SCH_GLOBAL_LABEL_T
Definition typeinfo.h:172
Casted dyn_cast(From aObject)
A lightweight dynamic downcast.
Definition typeinfo.h:61
#define INDETERMINATE_STATE
Used for holding indeterminate values, such as with multiple selections holding different values or c...
Definition ui_common.h:46
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:695